Skip to content

Commit

Permalink
fc: add prg ram to uxrom and cnrom mappers (ares-emulator#1557)
Browse files Browse the repository at this point in the history
Some homebrew/aftermarket software calls for UXROM w/ PRG (NV)RAM. The
licensed title Hayauchi Super Igo pairs CNROM with SRAM.
  • Loading branch information
invertego authored Jul 8, 2024
1 parent 2b0738e commit 3de728f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions ares/fc/cartridge/board/hvc-cnrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct HVC_CNROM : Interface {
}

Memory::Readable<n8> programROM;
Memory::Writable<n8> programRAM;
Memory::Readable<n8> characterROM;
Memory::Writable<n8> characterRAM;

Expand All @@ -20,23 +21,29 @@ struct HVC_CNROM : Interface {

auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(programRAM, "save.ram");
Interface::load(characterROM, "character.rom");
Interface::load(characterRAM, "character.ram");
mirror = pak->attribute("mirror") == "vertical";
key = pak->attribute("chip/key").natural();
}

auto save() -> void override {
Interface::save(programRAM, "save.ram");
Interface::save(characterRAM, "character.ram");
}

auto readPRG(n32 address, n8 data) -> n8 override {
if(address < 0x8000) return data;
if(address < 0x6000) return data;
if(address < 0x8000 && !programRAM) return data;
if(address < 0x8000) return programRAM.read(address);
return programROM.read((n15)address);
}

auto writePRG(n32 address, n8 data) -> void override {
if(address < 0x8000) return;
if(address < 0x6000) return;
if(address < 0x8000 && !programRAM) return;
if(address < 0x8000) return programRAM.write(address, data);
characterBank = data & programROM.read((n15)address);
characterEnable = (data == key);
}
Expand Down Expand Up @@ -70,6 +77,7 @@ struct HVC_CNROM : Interface {
}

auto serialize(serializer& s) -> void override {
s(programRAM);
s(characterRAM);
s(mirror);
s(key);
Expand Down
12 changes: 10 additions & 2 deletions ares/fc/cartridge/board/hvc-uxrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct HVC_UxROM : Interface {
}

Memory::Readable<n8> programROM;
Memory::Writable<n8> programRAM;
Memory::Readable<n8> characterROM;
Memory::Writable<n8> characterRAM;

Expand All @@ -22,17 +23,21 @@ struct HVC_UxROM : Interface {

auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(programRAM, "save.ram");
Interface::load(characterROM, "character.rom");
Interface::load(characterRAM, "character.ram");
mirror = pak->attribute("mirror") == "vertical";
}

auto save() -> void override {
Interface::save(programRAM, "save.ram");
Interface::save(characterRAM, "character.ram");
}

auto readPRG(n32 address, n8 data) -> n8 override {
if(address < 0x8000) return data;
if(address < 0x6000) return data;
if(address < 0x8000 && !programRAM) return data;
if(address < 0x8000) return programRAM.read(address);
n8 bank;
switch(address >> 14 & 1) {
case 0: bank = (revision == Revision::UNROMA ? (n8)0x00 : programBank); break;
Expand All @@ -42,7 +47,9 @@ struct HVC_UxROM : Interface {
}

auto writePRG(n32 address, n8 data) -> void override {
if(address < 0x8000) return;
if(address < 0x6000) return;
if(address < 0x8000 && !programRAM) return;
if(address < 0x8000) return programRAM.write(address, data);
programBank = data;
if(revision == Revision::UN1ROM) programBank >>= 2;
}
Expand All @@ -69,6 +76,7 @@ struct HVC_UxROM : Interface {
}

auto serialize(serializer& s) -> void override {
s(programRAM);
s(characterRAM);
s(mirror);
s(programBank);
Expand Down
2 changes: 1 addition & 1 deletion ares/fc/system/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const string SerializerVersion = "v147";
static const string SerializerVersion = "v148";

auto System::serialize(bool synchronize) -> serializer {
if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize);
Expand Down

0 comments on commit 3de728f

Please sign in to comment.