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 28
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 #115 from negativeExponent/mesenx
mappers
- Loading branch information
Showing
9 changed files
with
624 additions
and
0 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
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 "MMC3.h" | ||
|
||
class MMC3_455: public MMC3 | ||
{ | ||
private: | ||
uint8_t _exRegs[2]; | ||
|
||
protected: | ||
void InitMapper() override | ||
{ | ||
_exRegs[0] = 0; | ||
_exRegs[1] = 1; | ||
|
||
AddRegisterRange(0x4100, 0x5FFF, MemoryOperation::Write); | ||
|
||
MMC3::InitMapper(); | ||
MMC3::WriteRegister(0xA001, 0x80); | ||
} | ||
|
||
void Reset(bool softReset) override | ||
{ | ||
_exRegs[0] = 0; | ||
_exRegs[1] = 1; | ||
|
||
MMC3::UpdateState(); | ||
} | ||
|
||
|
||
void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override | ||
{ | ||
uint16_t base = (((_exRegs[1] >> 2) & 0x10) | ((_exRegs[0] << 1) & 0x08) | ((_exRegs[1] >> 2) & 0x07)) << 4; | ||
uint16_t mask = 0xFF >> !(_exRegs[0] & 0x02); | ||
|
||
MMC3::SelectCHRPage(slot, (base & ~mask) | (page & mask)); | ||
} | ||
|
||
void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override | ||
{ | ||
uint16_t base = (((_exRegs[1] >> 2) & 0x10) | ((_exRegs[0] << 1) & 0x08) | ((_exRegs[1] >> 2) & 0x07)) << 1; | ||
uint16_t mask = 0x1F >> !(_exRegs[0] & 0x01); | ||
|
||
if(_exRegs[1] & 0x01) { | ||
uint8_t nrom = _exRegs[1] & 0x02; | ||
base = (slot & 0x02) ? (base | nrom) : (base & ~nrom); | ||
mask = 0x01; | ||
page = slot & 0x01; | ||
} | ||
|
||
MMC3::SelectPRGPage(slot, (base & ~mask) | (page & mask)); | ||
} | ||
|
||
void WriteRegister(uint16_t addr, uint8_t value) override | ||
{ | ||
if(addr < 0x8000) { | ||
if((GetState().RegA001 & 0x80) && (addr & 0x100)) { | ||
_exRegs[0] = (addr & 0xFF); | ||
_exRegs[1] = value; | ||
MMC3::UpdatePrgMapping(); | ||
MMC3::UpdateChrMapping(); | ||
} | ||
} else { | ||
MMC3::WriteRegister(addr, value); | ||
} | ||
} | ||
|
||
void StreamState(bool saving) override | ||
{ | ||
MMC3::StreamState(saving); | ||
Stream(_exRegs[0], _exRegs[1]); | ||
} | ||
}; |
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,57 @@ | ||
#pragma once | ||
|
||
#include "stdafx.h" | ||
#include "MMC3.h" | ||
|
||
class MMC3_456: public MMC3 | ||
{ | ||
private: | ||
uint8_t _outerBank; | ||
|
||
protected: | ||
void InitMapper() override | ||
{ | ||
_outerBank = 0; | ||
|
||
AddRegisterRange(0x4100, 0x5FFF, MemoryOperation::Write); | ||
|
||
MMC3::InitMapper(); | ||
} | ||
|
||
void Reset(bool softReset) override | ||
{ | ||
_outerBank = 0; | ||
|
||
MMC3::UpdateState(); | ||
} | ||
|
||
|
||
void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override | ||
{ | ||
MMC3::SelectCHRPage(slot, (_outerBank << 7) | (page & 0x7F)); | ||
} | ||
|
||
void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override | ||
{ | ||
MMC3::SelectPRGPage(slot, (_outerBank << 4) | (page & 0x0F)); | ||
} | ||
|
||
void WriteRegister(uint16_t addr, uint8_t value) override | ||
{ | ||
if(addr < 0x8000) { | ||
if(CanWriteToWorkRam()) { | ||
_outerBank = value; | ||
MMC3::UpdatePrgMapping(); | ||
MMC3::UpdateChrMapping(); | ||
} | ||
} else { | ||
MMC3::WriteRegister(addr, value); | ||
} | ||
} | ||
|
||
void StreamState(bool saving) override | ||
{ | ||
MMC3::StreamState(saving); | ||
Stream(_outerBank); | ||
} | ||
}; |
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,60 @@ | ||
#pragma once | ||
|
||
#include "stdafx.h" | ||
#include "MMC3.h" | ||
|
||
class MMC3_457: public MMC3 | ||
{ | ||
private: | ||
uint8_t _outerBank; | ||
|
||
protected: | ||
void InitMapper() override | ||
{ | ||
_outerBank = 0; | ||
|
||
AddRegisterRange(0x6000, 0x7FFF, MemoryOperation::Write); | ||
|
||
MMC3::InitMapper(); | ||
} | ||
|
||
void Reset(bool softReset) override | ||
{ | ||
_outerBank = 0; | ||
|
||
MMC3::UpdateState(); | ||
} | ||
|
||
|
||
void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override | ||
{ | ||
uint8_t mask = 0xFF >> !(_outerBank & 0x08); | ||
MMC3::SelectCHRPage(slot, ((_outerBank << 7) & ~mask) | (page & mask)); | ||
} | ||
|
||
void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override | ||
{ | ||
uint8_t mask = 0x1F >> !(_outerBank & 0x08); | ||
MMC3::SelectPRGPage(slot, ((_outerBank << 4) & ~mask) | (page & mask)); | ||
} | ||
|
||
void WriteRegister(uint16_t addr, uint8_t value) override | ||
{ | ||
if(addr < 0x8000) { | ||
WritePrgRam(addr, value); | ||
if(CanWriteToWorkRam()) { | ||
_outerBank = value; | ||
MMC3::UpdatePrgMapping(); | ||
MMC3::UpdateChrMapping(); | ||
} | ||
} else { | ||
MMC3::WriteRegister(addr, value); | ||
} | ||
} | ||
|
||
void StreamState(bool saving) override | ||
{ | ||
MMC3::StreamState(saving); | ||
Stream(_outerBank); | ||
} | ||
}; |
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,71 @@ | ||
#pragma once | ||
#include "MMC3.h" | ||
|
||
class MMC3_458 : public MMC3 | ||
{ | ||
private: | ||
uint8_t _exReg; | ||
|
||
protected: | ||
uint32_t GetDipSwitchCount() override { return 2; } | ||
bool AllowRegisterRead() override { return true; } | ||
|
||
void InitMapper() override | ||
{ | ||
_exReg = 0; | ||
MMC3::InitMapper(); | ||
|
||
AddRegisterRange(0x6000, 0x7FFF, MemoryOperation::Write); | ||
} | ||
|
||
void Reset(bool softReset) override | ||
{ | ||
_exReg = 0; | ||
|
||
MMC3::UpdateState(); | ||
} | ||
|
||
void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override | ||
{ | ||
MMC3::SelectCHRPage(slot, ((_exReg << 4) & ~0x7F) | (page & 0x7F)); | ||
} | ||
|
||
void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override | ||
{ | ||
uint16_t base = _exReg & 0x0F; | ||
uint16_t nrom = (_romInfo.SubMapperID == 1) ? ((_exReg & 0x02) >> 3) : ((_exReg & 0x10) >> 4); | ||
|
||
page = (slot & 1); | ||
page |= ((slot & 0x02) ? (base | nrom) : (base & ~nrom)) << 1; | ||
|
||
MMC3::SelectPRGPage(slot, page); | ||
} | ||
|
||
uint8_t ReadRegister(uint16_t addr) override | ||
{ | ||
uint8_t dipValue = GetDipSwitches() & 0x03; | ||
|
||
if((_exReg & 0x20) && dipValue) { | ||
addr = (addr & ~0x03) | dipValue; | ||
} | ||
|
||
return InternalReadRam(addr); | ||
} | ||
|
||
void WriteRegister(uint16_t addr, uint8_t value) override | ||
{ | ||
if(addr < 0x8000) { | ||
_exReg = addr & 0xFF; | ||
MMC3::UpdatePrgMapping(); | ||
MMC3::UpdateChrMapping(); | ||
} else { | ||
MMC3::WriteRegister(addr, value); | ||
} | ||
} | ||
|
||
void StreamState(bool saving) override | ||
{ | ||
MMC3::StreamState(saving); | ||
Stream(_exReg); | ||
} | ||
}; |
Oops, something went wrong.