Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapper updates #25

Merged
merged 34 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
911fc8b
Merge pull request #81 from mkwong98/Sync2
NovaSquirrel Mar 21, 2022
6c3bb8a
Add Mapper 334
negativeExponent Mar 18, 2022
51d7a84
Add Mapper 353
negativeExponent Mar 18, 2022
e7ba864
Add Mappers 364 and 370
negativeExponent Mar 18, 2022
772b72b
Mapper 45: Update support for larger PRG size
negativeExponent Mar 18, 2022
0e4e956
Add Mapper 372
negativeExponent Mar 19, 2022
03958e6
Add Mappers 267 and 377
negativeExponent Mar 19, 2022
2030f03
Add Mappers 376
negativeExponent Mar 19, 2022
1ed4480
Add Mappers 383
negativeExponent Mar 19, 2022
918c2ea
Add Mappers 391
negativeExponent Mar 19, 2022
d1c4e09
Add Mappers 393
negativeExponent Mar 19, 2022
5dbfc99
Mapper 393: Fix savestate
negativeExponent Mar 19, 2022
4ee92ba
Add Mappers 395
negativeExponent Mar 19, 2022
9282188
Add Mappers 401
negativeExponent Mar 20, 2022
e7f2261
Add Mappers 410
negativeExponent Mar 20, 2022
525b3d0
Mapper 372: Fixed excessive CHR banking
negativeExponent Mar 20, 2022
3af9fdd
Add Mappers 411
negativeExponent Mar 20, 2022
7d6e90b
Add Mappers 412
negativeExponent Mar 20, 2022
14b6440
Add Mappers 430
negativeExponent Mar 20, 2022
490074f
Add Mappers 432 and 441
negativeExponent Mar 20, 2022
29dcfb5
Mapper 391: Fix savestate
negativeExponent Mar 20, 2022
db038e1
Add Mapper 445
negativeExponent Mar 20, 2022
29a274e
Add Mapper 444
negativeExponent Mar 21, 2022
f8ffc45
Merge pull request #82 from negativeExponent/mmc3
NovaSquirrel Mar 21, 2022
2d255c8
Mapper 227: Add dipswitch and CHR-RAM protect
negativeExponent Mar 23, 2022
fe7e9ce
Mapper 242: Updated support for newer carts
negativeExponent Mar 23, 2022
3fdb613
Add Mappers 375, 380, 449
negativeExponent Mar 23, 2022
8b27368
Silence warnings about missing override keyword
negativeExponent Mar 23, 2022
4405c19
Assign Mapper 55 to UNIF MARIO1-MALEE
negativeExponent Mar 23, 2022
0608661
Mapper 91: Add outer bank register support
negativeExponent Mar 24, 2022
f71c642
Mapper 219: Add outer bank register
negativeExponent Mar 24, 2022
33b699d
Add Mapper 319
negativeExponent Mar 25, 2022
366b6a0
Mapper 235: Simplify and add UNROM mode
negativeExponent Mar 26, 2022
bb451ef
Merge pull request #83 from negativeExponent/mesenx_mappers
NovaSquirrel Mar 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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