Skip to content

Commit

Permalink
MMC3 test
Browse files Browse the repository at this point in the history
  • Loading branch information
BrokeStudio committed Oct 10, 2024
1 parent 22bbae5 commit e4c5164
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions Core/NES/Mappers/Nintendo/MMC3.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MMC3 : public BaseMapper

struct Mmc3State
{
uint8_t Reg5000;
uint8_t Reg8000;
uint8_t RegA000;
uint8_t RegA001;
Expand All @@ -35,6 +36,8 @@ class MMC3 : public BaseMapper
uint8_t _chrMode = 0;
uint8_t _registers[8] = {};

uint16_t RegisterStartAddress() override { return 0x5000; }

uint8_t GetCurrentRegister()
{
return _currentRegister;
Expand All @@ -52,6 +55,7 @@ class MMC3 : public BaseMapper

void ResetMmc3()
{
_state.Reg5000 = 0;
_state.Reg8000 = GetPowerOnByte();
_state.RegA000 = GetPowerOnByte();
_state.RegA001 = GetPowerOnByte();
Expand Down Expand Up @@ -115,16 +119,30 @@ class MMC3 : public BaseMapper

virtual void UpdatePrgMapping()
{

uint8_t M2 = -2;
uint8_t M1 = -1;
uint8_t R6 = _registers[6];
uint8_t R7 = _registers[7];

if(_state.Reg5000 & 0x80) {
uint8_t B5 = (_state.Reg5000 & 0x01) << 5;
M2 = 0x1E | B5;
M1 = 0x1F | B5;
R6 = (R6 & 0x1F) | B5;
R7 = (R7 & 0x1F) | B5;
}

if(_prgMode == 0) {
SelectPrgPage(0, _registers[6]);
SelectPrgPage(1, _registers[7]);
SelectPrgPage(2, -2);
SelectPrgPage(3, -1);
SelectPrgPage(0, R6);
SelectPrgPage(1, R7);
SelectPrgPage(2, M2);
SelectPrgPage(3, M1);
} else if(_prgMode == 1) {
SelectPrgPage(0, -2);
SelectPrgPage(1, _registers[7]);
SelectPrgPage(2, _registers[6]);
SelectPrgPage(3, -1);
SelectPrgPage(0, M2);
SelectPrgPage(1, R7);
SelectPrgPage(2, R6);
SelectPrgPage(3, M1);
}
}

Expand Down Expand Up @@ -206,6 +224,13 @@ class MMC3 : public BaseMapper

void WriteRegister(uint16_t addr, uint8_t value) override
{

if(addr == 0x5000) {
_state.Reg5000 = value & 0x81;
UpdateState();
return;
}

switch(addr & 0xE001) {
case 0x8000:
_state.Reg8000 = value;
Expand Down Expand Up @@ -249,6 +274,12 @@ class MMC3 : public BaseMapper
_irqEnabled = true;
break;
}

if(addr >= 0x6000) {
AddressInfo absAddr = GetAbsoluteAddress(addr);
WritePrgRam(addr, value);
}

}

virtual void TriggerIrq()
Expand Down

0 comments on commit e4c5164

Please sign in to comment.