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 #112 from negativeExponent/mesenx
Browse files Browse the repository at this point in the history
corrections and some more mappers
  • Loading branch information
NovaSquirrel authored Jul 21, 2022
2 parents 6de70d9 + 00b8478 commit 5b61ee4
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 11 deletions.
51 changes: 51 additions & 0 deletions Core/BmcDs07.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once
#include "stdafx.h"
#include "BaseMapper.h"

class BmcDs07 : public BaseMapper
{
private:
uint8_t _regs[2];
uint8_t _latch;

protected:
uint16_t GetPRGPageSize() override { return 0x4000; }
uint16_t GetCHRPageSize() override { return 0x2000; }
uint16_t RegisterStartAddress() { return 0x6000; }
uint16_t RegisterEndAddress() { return 0xFFFF; }

void InitMapper() override
{
_regs[0] = _regs[1] = -1;
_latch = 0;
UpdateState();
}

void StreamState(bool saving) override
{
BaseMapper::StreamState(saving);
Stream(_regs[0], _regs[1], _latch);
}

void UpdateState()
{
uint8_t base = (_regs[0] & 0xF0) >> 1;
SelectPRGPage(0, base | (_latch & 0x07));
SelectPRGPage(1, base | 0x07);
SetMirroringType((_latch & 0x80) ? MirroringType::Horizontal : MirroringType::Vertical);
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
_regs[addr & 0x01] = value;
} else {
if((_regs[0] & 0x80) == 0) {
_latch = (_latch & 0xF8) | (value & 0x07);
} else {
_latch = value;
}
}
UpdateState();
}
};
4 changes: 4 additions & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@
<ClInclude Include="BmcTj03.h" />
<ClInclude Include="BmcCtc09.h" />
<ClInclude Include="BmcCtc12in1.h" />
<ClInclude Include="BmcDs07.h" />
<ClInclude Include="Bmc891227.h" />
<ClInclude Include="Ctc15.h" />
<ClInclude Include="CityFighter.h" />
Expand Down Expand Up @@ -851,6 +852,8 @@
<ClInclude Include="MMC3_410.h" />
<ClInclude Include="MMC3_411.h" />
<ClInclude Include="MMC3_412.h" />
<ClInclude Include="MMC3_420.h" />
<ClInclude Include="MMC3_428.h" />
<ClInclude Include="MMC3_422.h" />
<ClInclude Include="MMC3_430.h" />
<ClInclude Include="MMC3_432.h" />
Expand All @@ -859,6 +862,7 @@
<ClInclude Include="MMC3_445.h" />
<ClInclude Include="MMC3_534.h" />
<ClInclude Include="MMC3_516.h" />
<ClInclude Include="MMC3_512.h" />
<ClInclude Include="Mapper57.h" />
<ClInclude Include="Mapper61.h" />
<ClInclude Include="Mapper62.h" />
Expand Down
12 changes: 12 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,9 @@
<ClInclude Include="BmcCtc09.h">
<Filter>Nes\Mappers</Filter>
</ClInclude>
<ClInclude Include="BmcDs07.h">
<Filter>Nes\Mappers</Filter>
</ClInclude>
<ClInclude Include="BmcK3036.h">
<Filter>Nes\Mappers</Filter>
</ClInclude>
Expand All @@ -811,15 +814,24 @@
<ClInclude Include="MMC3_245.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_420.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_422.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_428.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_534.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_516.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="MMC3_512.h">
<Filter>Nes\Mappers\MMC</Filter>
</ClInclude>
<ClInclude Include="Waixing178.h">
<Filter>Nes\Mappers\Waixing</Filter>
</ClInclude>
Expand Down
2 changes: 1 addition & 1 deletion Core/MMC1_297.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MMC1_297 : public MMC1

void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
BaseMapper::SelectPRGPage(slot, (_mode << 3) & 0x08 | (page & 0x07));
BaseMapper::SelectPRGPage(slot, ((_mode << 3) & 0x08) | (page & 0x07));
}

void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
Expand Down
6 changes: 3 additions & 3 deletions Core/MMC3_269.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ class MMC3_269 : public MMC3

case 2:
_chrMask = 0xFF >> (~value & 0xF);
_outerChr = _outerChr & ~0x0F00 | ((value & 0xF0) << 4);
_outerChr = (_outerChr & ~0x0F00) | ((value & 0xF0) << 4);
break;

case 3:
_prgMask = ~value & 0x3F;
_outerPrg = _outerPrg & ~0x0100 | ((value & 0x40) << 2);
_outerChr = _outerChr & ~0x1000 | ((value & 0x40) << 6);
_outerPrg = (_outerPrg & ~0x0100) | ((value & 0x40) << 2);
_outerChr = (_outerChr & ~0x1000) | ((value & 0x40) << 6);
_locked = (value & 0x80) == 0x80;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions Core/MMC3_369.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MMC3_369 : public MMC3
Stream(_outerBankReg, _smb2jBank, _m2Counter);
}

void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default)
void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
switch (_outerBankReg) {
case 0x00:
Expand All @@ -68,7 +68,7 @@ class MMC3_369 : public MMC3
}
}

void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom)
void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
switch (_outerBankReg) {
case 0x00:
Expand Down
73 changes: 73 additions & 0 deletions Core/MMC3_420.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once
#include "stdafx.h"
#include "MMC3.h"

class MMC3_420 : public MMC3
{
private:
uint8_t _exRegs[4];

protected:
virtual void InitMapper() override
{
AddRegisterRange(0x6000, 0x7FFF, MemoryOperation::Write);
MMC3::InitMapper();
}

virtual void Reset(bool softReset) override
{
memset(_exRegs, 0, sizeof(_exRegs));

if(!softReset) {
MMC3::ResetMmc3();
}

MMC3::UpdateState();
}

virtual void StreamState(bool saving) override
{
MMC3::StreamState(saving);
Stream(_exRegs[0], _exRegs[1], _exRegs[2], _exRegs[3]);

if (!saving) {
MMC3::UpdateState();
}
}

virtual void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
uint16_t mask = 0xFF >> ((_exRegs[1] & 0x80) >> 7);
uint16_t base = ((_exRegs[1] << 1) & 0x100) | ((_exRegs[1] << 5) & 0x80);

MMC3::SelectCHRPage(slot, base | (page & mask), memoryType);
}

virtual void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
uint16_t mask;
uint16_t base;
if(_exRegs[0] & 0x80) {
base = ((_exRegs[0] >> 1) & 0x07 | ((_exRegs[3] >> 2) & 0x08)) << 2;
page = slot;
mask = 0x03;
} else {
mask = 0x3F >> (((_exRegs[3] & 0x20) >> 5) | ((_exRegs[0] & 0x20) >> 4));
base = ((_exRegs[3] << 3) & 0x20);
}

MMC3::SelectPRGPage(slot, base | (page & mask), memoryType);
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
WritePrgRam(addr, value);
_exRegs[addr & 3] = value;
MMC3::UpdatePrgMapping();
MMC3::UpdateChrMapping();
} else {
MMC3::WriteRegister(addr, value);
}
}
};
74 changes: 74 additions & 0 deletions Core/MMC3_512.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once
#include "stdafx.h"
#include "MMC3.h"

class MMC3_512 : public MMC3
{
private:
uint8_t _reg = 0;

protected:
virtual uint32_t GetChrRamSize() override { return 0x2000; }
virtual uint16_t GetChrRamPageSize() override { return 0x0400; }

virtual uint32_t GetWorkRamSize() override { return 0x2000; }
virtual uint32_t GetWorkRamPageSize() override { return 0x2000; }
virtual bool ForceWorkRamSize() override { return true; }

virtual void InitMapper() override
{
AddRegisterRange(0x4100, 0x4FFF, MemoryOperation::Write);
MMC3::InitMapper();
}

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

virtual void UpdateMirroring() override
{
if(_reg == 0x01) {
SetPpuMemoryMapping(0x2000, 0x2FFF, 1 << 2, ChrMemoryType::ChrRam, MemoryAccessType::ReadWrite);
} else {
MMC3::UpdateMirroring();
}
}

virtual void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
if(_reg & 0x02) {
memoryType = ChrMemoryType::ChrRam;
page &= 0x03;
}

MMC3::SelectCHRPage(slot, page, memoryType);
}

virtual void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
MMC3::SelectPRGPage(slot, page & 0x3F, memoryType);
}

virtual void UpdateState() override
{
MMC3::UpdateState();

// Always enable WRAM
SetCpuMemoryMapping(0x6000, 0x7FFF, 0, HasBattery() ? PrgMemoryType::SaveRam : PrgMemoryType::WorkRam, MemoryAccessType::ReadWrite);
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000){
if(addr & 0x100) {
_reg = value & 0x03;
UpdateChrMapping();
UpdateMirroring();
}
} else {
MMC3::WriteRegister(addr, value);
}
}
};
2 changes: 1 addition & 1 deletion Core/Mapper400.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Mapper400 : public BaseMapper

_regs[0] = 0x80;

AddRegisterRange(0x7800, 0x7FFFF, MemoryOperation::Write);
AddRegisterRange(0x7800, 0x7FFF, MemoryOperation::Write);

WriteRegister(0xC000, 0);
}
Expand Down
74 changes: 74 additions & 0 deletions Core/Mapper428.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once
#include "stdafx.h"
#include "BaseMapper.h"

class Mapper428 : public BaseMapper
{
private:
uint8_t _regs[4];
uint8_t _chrLatch;

protected:
uint32_t GetDipSwitchCount() override { return 2; }
uint16_t GetPRGPageSize() override { return 0x4000; }
uint16_t GetCHRPageSize() override { return 0x2000; }

uint16_t RegisterStartAddress() { return 0x6000; }
uint16_t RegisterEndAddress() { return 0xFFFF; }
bool AllowRegisterRead() override { return true; }

void InitMapper() override
{
RemoveRegisterRange(0x8000, 0xFFFF, MemoryOperation::Read);

_chrLatch = 0;
memset(_regs, 0, sizeof(_regs));
UpdateState();
}

void StreamState(bool saving) override
{
BaseMapper::StreamState(saving);
Stream(_regs[0], _regs[1], _regs[2], _regs[3], _chrLatch);

if(!saving) {
UpdateState();
}
}

void Reset(bool softReset) override
{
BaseMapper::Reset(softReset);

_chrLatch = 0;
memset(_regs, 0, sizeof(_regs));
UpdateState();
}

void UpdateState()
{
if (_regs[1] & 0x10) {
SelectPrgPage2x(0, (_regs[1] >> 5) & 0xFE);
} else {
SelectPRGPage(0, _regs[1] >> 5);
SelectPRGPage(1, _regs[1] >> 5);
}
SelectCHRPage(0, ((_regs[1] & 0x07) & ~(_regs[2] >> 6)) | (_chrLatch & (_regs[2] >> 6)));
SetMirroringType((_regs[1] & 0x08) ? MirroringType::Horizontal : MirroringType::Vertical);
}

uint8_t ReadRegister(uint16_t addr) override
{
return (_console->GetMemoryManager()->GetOpenBus() & 0xFC) | (GetDipSwitches() & 0x03);
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
_regs[addr & 0x03] = value;
} else {
_chrLatch = value;
}
UpdateState();
}
};
2 changes: 1 addition & 1 deletion Core/Mapper533.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Mapper533 : public BaseMapper
uint16_t GetPRGPageSize() override { return 0x8000; }
uint16_t GetCHRPageSize() override { return 0x2000; }

bool AllowRegisterRead() { return true; }
bool AllowRegisterRead() override { return true; }

void InitMapper() override
{
Expand Down
Loading

0 comments on commit 5b61ee4

Please sign in to comment.