This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
forked from SourMesen/Mesen
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from negativeExponent/mesenx
corrections and some more mappers
- Loading branch information
Showing
14 changed files
with
309 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.