Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #25 from NovaSquirrel/master
Browse files Browse the repository at this point in the history
Mapper updates
  • Loading branch information
mkwong98 authored Apr 2, 2022
2 parents 9721f59 + bb451ef commit 640d6b3
Show file tree
Hide file tree
Showing 36 changed files with 1,929 additions and 132 deletions.
53 changes: 21 additions & 32 deletions Core/Bmc235.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

class Bmc235 : public BaseMapper
{
private:
bool _openBus = false;
protected:
virtual uint16_t GetPRGPageSize() override { return 0x4000; }
virtual uint16_t GetCHRPageSize() override { return 0x2000; }

uint8_t _unrom;

void InitMapper() override
{
SelectPrgPage2x(0, 0);
Expand All @@ -19,45 +19,34 @@ class Bmc235 : public BaseMapper
void Reset(bool softReset) override
{
SelectPrgPage2x(0, 0);
_openBus = false;
}

void StreamState(bool saving) override
{
BaseMapper::StreamState(saving);
Stream(_openBus);
if(!saving && _openBus) {
RemoveCpuMemoryMapping(0x8000, 0xFFFF);
if(_prgSize & 0x20000) {
if(softReset) {
_unrom = !_unrom;
} else {
_unrom = false;
}
}
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
SetMirroringType((addr & 0x0400) ? MirroringType::ScreenAOnly : (addr & 0x2000) ? MirroringType::Horizontal : MirroringType::Vertical);
uint8_t bank = (addr >> 3) & 0x60 | (addr & 0x1F);

const uint8_t config[4][4][2] = {
{ { 0x00, 0 }, { 0x00, 1 }, { 0x00, 1 }, { 0x00, 1 } },
{ { 0x00, 0 }, { 0x00, 1 }, { 0x20, 0 }, { 0x00, 1 } },
{ { 0x00, 0 }, { 0x00, 1 }, { 0x20, 0 }, { 0x40, 0 } },
{ { 0x00, 0 }, { 0x20, 0 }, { 0x40, 0 }, { 0x60, 0 } }
};
if(_unrom) {
SetMirroringType(MirroringType::Vertical);
SelectPRGPage(0, GetPRGPageCount() & 0xC0 | value & 0x07);
SelectPRGPage(1, GetPRGPageCount() & 0xC0 | 0x07);
return;
}

uint8_t mode;
switch(GetPRGPageCount()) {
case 64: mode = 0; break;
case 128: mode = 1; break;
case 256: mode = 2; break;
default: mode = 3; break;
};
if(bank >= (GetPRGPageCount() >> 1)) {
RemoveCpuMemoryMapping(0x8000, 0xFFFF);
return;
}

uint8_t bank = config[mode][addr >> 8 & 0x03][0] | (addr & 0x1F);
SetMirroringType((addr & 0x0400) ? MirroringType::ScreenAOnly : (addr & 0x2000) ? MirroringType::Horizontal : MirroringType::Vertical);

_openBus = false;
if(config[mode][addr >> 8 & 0x03][1]) {
//Open bus
_openBus = true;
RemoveCpuMemoryMapping(0x8000, 0xFFFF);
} else if(addr & 0x800) {
if(addr & 0x800) {
bank = (bank << 1) | (addr >> 12 & 0x01);
SelectPRGPage(0, bank);
SelectPRGPage(1, bank);
Expand Down
25 changes: 25 additions & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@
<ClInclude Include="Mapper253.h" />
<ClInclude Include="Mapper43.h" />
<ClInclude Include="Mapper83.h" />
<ClInclude Include="Mapper319.h" />
<ClInclude Include="MMC3_123.h" />
<ClInclude Include="MMC3_126.h" />
<ClInclude Include="MMC3_134.h" />
Expand All @@ -784,6 +785,9 @@
<ClInclude Include="Mapper42.h" />
<ClInclude Include="Mapper50.h" />
<ClInclude Include="Mapper60.h" />
<ClInclude Include="Mapper375.h" />
<ClInclude Include="Mapper380.h" />
<ClInclude Include="Mapper449.h" />
<ClInclude Include="MMC1_155.h" />
<ClInclude Include="MMC3_114.h" />
<ClInclude Include="MMC3_121.h" />
Expand All @@ -796,8 +800,29 @@
<ClInclude Include="MMC3_249.h" />
<ClInclude Include="MMC3_250.h" />
<ClInclude Include="MMC3_254.h" />
<ClInclude Include="MMC3_267.h" />
<ClInclude Include="MMC3_45.h" />
<ClInclude Include="MMC3_334.h" />
<ClInclude Include="MMC3_353.h" />
<ClInclude Include="MMC3_364.h" />
<ClInclude Include="MMC3_370.h" />
<ClInclude Include="MMC3_372.h" />
<ClInclude Include="MMC3_376.h" />
<ClInclude Include="MMC3_377.h" />
<ClInclude Include="MMC3_383.h" />
<ClInclude Include="MMC3_391.h" />
<ClInclude Include="MMC3_393.h" />
<ClInclude Include="MMC3_395.h" />
<ClInclude Include="MMC3_401.h" />
<ClInclude Include="MMC3_410.h" />
<ClInclude Include="MMC3_411.h" />
<ClInclude Include="MMC3_412.h" />
<ClInclude Include="MMC3_422.h" />
<ClInclude Include="MMC3_430.h" />
<ClInclude Include="MMC3_432.h" />
<ClInclude Include="MMC3_441.h" />
<ClInclude Include="MMC3_444.h" />
<ClInclude Include="MMC3_445.h" />
<ClInclude Include="MMC3_534.h" />
<ClInclude Include="Mapper57.h" />
<ClInclude Include="Mapper61.h" />
Expand Down
75 changes: 75 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@
<ClInclude Include="Mapper246.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper319.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Sunsoft89.h">
<Filter>Nes\Mappers\Sunsoft</Filter>
</ClInclude>
Expand Down Expand Up @@ -1429,6 +1432,15 @@
<ClInclude Include="Mapper116.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper375.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper380.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper449.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="MMC3_208.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
Expand Down Expand Up @@ -1459,6 +1471,69 @@
<ClInclude Include="MMC3_224.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_334.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_353.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_364.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_370.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_372.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_383.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_391.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_393.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_395.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_401.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_410.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_411.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_412.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_267.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_430.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_376.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_377.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_432.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_441.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_444.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_445.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="FamicomBox.h">
<Filter>Nes\Mappers\Unif</Filter>
</ClInclude>
Expand Down
96 changes: 58 additions & 38 deletions Core/MMC3_219.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,79 @@ class MMC3_219 : public MMC3
void InitMapper() override
{
MMC3::InitMapper();
SelectPrgPage4x(0, -4);
SelectChrPage8x(0, 0);
_exRegs[0] = _exRegs[1] = _exRegs[2] = 0;
AddRegisterRange(0x5000, 0x5FFF);
}

void UpdatePrgMapping() override
void Reset(bool softreset) override
{
_exRegs[0] = _exRegs[2] = 0x00;
_exRegs[1] = 0x03;
MMC3::UpdateState();
}

void UpdateChrMapping() override
void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
MMC3::SelectCHRPage(slot, (_exRegs[1] << 7) | (page & 0x7F));
}

void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
MMC3::SelectPRGPage(slot, (_exRegs[1] << 4) | (page & 0x0F));
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0xA000) {
if(addr < 0x8000) {
switch(addr & 0x01) {
case 0: _exRegs[1] = (_exRegs[1] & ~0x01) | ((value >> 3) & 0x01); break;
case 1: _exRegs[1] = (_exRegs[1] & ~0x02) | ((value >> 4) & 0x02); break;
}
MMC3::UpdatePrgMapping();
MMC3::UpdateChrMapping();
} else if(addr < 0xA000) {
switch(addr & 0xE003) {
case 0x8000:
_exRegs[0] = 0;
_exRegs[1] = value;
break;
case 0x8000:
MMC3::WriteRegister(addr, value);
break;

case 0x8002:
_exRegs[0] = value;
MMC3::WriteRegister(addr, value);
break;

case 0x8001:
if(_exRegs[0] >= 0x23 && _exRegs[0] <= 0x26) {
case 0x8001:
if(_exRegs[0] & 0x20) { // Extended Mode
uint8_t bankRegister = MMC3::GetState().Reg8000;
if((bankRegister >= 0x25) && (bankRegister <= 0x26)) {
uint8_t prgBank = ((value & 0x20) >> 5) | ((value & 0x10) >> 3) | ((value & 0x08) >> 1) | ((value & 0x04) << 1);
SelectPRGPage(0x26 - _exRegs[0], prgBank);
}

switch(_exRegs[1]) {
case 0x08: case 0x0A: case 0x0E: case 0x12: case 0x16: case 0x1A: case 0x1E:
_exRegs[2] = value << 4;
break;
MMC3::_registers[6 | (bankRegister & 0x01)] = prgBank;
MMC3::UpdatePrgMapping();
} else if((bankRegister >= 0x08) && (bankRegister <= 0x1F)) {
switch(bankRegister) {
case 0x08: case 0x0A: case 0x0E: case 0x12: case 0x16: case 0x1A: case 0x1E:
_exRegs[2] = value << 4;
break;

case 0x09: SelectCHRPage(0, _exRegs[2] | (value >> 1 & 0x0E)); break;
case 0x0B: SelectCHRPage(1, _exRegs[2] | (value >> 1 | 0x1)); break;
case 0x0C:
case 0x0D: SelectCHRPage(2, _exRegs[2] | (value >> 1 & 0xE)); break;
case 0x0F: SelectCHRPage(3, _exRegs[2] | (value >> 1 | 0x1)); break;
case 0x10:
case 0x11: SelectCHRPage(4, _exRegs[2] | (value >> 1 & 0xF)); break;
case 0x14:
case 0x15: SelectCHRPage(5, _exRegs[2] | (value >> 1 & 0xF)); break;
case 0x18:
case 0x19: SelectCHRPage(6, _exRegs[2] | (value >> 1 & 0xF)); break;
case 0x1C:
case 0x1D: SelectCHRPage(7, _exRegs[2] | (value >> 1 & 0xF)); break;
case 0x09: MMC3::_registers[0] = _exRegs[2] | (value >> 1 & 0x0E); break;
case 0x0B: MMC3::_registers[0] = _exRegs[2] | (value >> 1 | 0x1); break;
case 0x0C:
case 0x0D: MMC3::_registers[1] = _exRegs[2] | (value >> 1 & 0xE); break;
case 0x0F: MMC3::_registers[1] = _exRegs[2] | (value >> 1 | 0x1); break;
case 0x10:
case 0x11: MMC3::_registers[2] = _exRegs[2] | (value >> 1 & 0xF); break;
case 0x14:
case 0x15: MMC3::_registers[3] = _exRegs[2] | (value >> 1 & 0xF); break;
case 0x18:
case 0x19: MMC3::_registers[4] = _exRegs[2] | (value >> 1 & 0xF); break;
case 0x1C:
case 0x1D: MMC3::_registers[5] = _exRegs[2] | (value >> 1 & 0xF); break;
}
MMC3::UpdateChrMapping();
}
break;

case 0x8002:
_exRegs[0] = value;
_exRegs[1] = 0;
break;
} else { // Normal MMC3
MMC3::WriteRegister(addr, value);
}
break;
}
} else {
MMC3::WriteRegister(addr, value);
Expand Down
52 changes: 52 additions & 0 deletions Core/MMC3_267.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once
#include "stdafx.h"
#include "MMC3.h"

class MMC3_267 : public MMC3
{
private:
uint8_t _outerBank = 0;

protected:
virtual uint16_t RegisterStartAddress() override { return 0x6000; }
virtual uint16_t RegisterEndAddress() override { return 0xFFFF; }

virtual void Reset(bool softreset) override
{
_outerBank = 0;
MMC3::UpdateState();
}

virtual void StreamState(bool saving) override
{
MMC3::StreamState(saving);
Stream(_outerBank);
}

virtual void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
page &= 0x7F;
page |= (((_outerBank >> 2) & 0x08) | (_outerBank & 0x06)) << 6;
MMC3::SelectCHRPage(slot, page, memoryType);
}

virtual void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
page &= 0x1F;
page |= (((_outerBank >> 2) & 0x08) | (_outerBank & 0x06)) << 4;
MMC3::SelectPRGPage(slot, page, memoryType);
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
if(!(_outerBank & 0x80)) {
_outerBank = value;
MMC3::UpdatePrgMapping();
MMC3::UpdateChrMapping();
}
} else {
MMC3::WriteRegister(addr, value);
}
}
};
Loading

0 comments on commit 640d6b3

Please sign in to comment.