From 1edf83b3c518a37b7823800824fef79bc6aebb21 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Sat, 11 Jan 2025 03:15:50 +0000 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Darren Thompson --- ares/n64/aleck64/aleck64.hpp | 2 ++ ares/n64/aleck64/io.cpp | 19 ++++++++++++++++--- ares/n64/memory/bus.hpp | 12 +++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ares/n64/aleck64/aleck64.hpp b/ares/n64/aleck64/aleck64.hpp index f632c8d1f..55ed29bfc 100644 --- a/ares/n64/aleck64/aleck64.hpp +++ b/ares/n64/aleck64/aleck64.hpp @@ -8,6 +8,7 @@ struct Aleck64 : Memory::RCP { template auto writeBurst(u32 address, u32 *value, const char *peripheral) -> void { + address = address & 0x00ff'ffff; if (address >= size) return; Memory::Writable::write(address | 0x00, value[0]); Memory::Writable::write(address | 0x04, value[1]); @@ -23,6 +24,7 @@ struct Aleck64 : Memory::RCP { template auto readBurst(u32 address, u32 *value, const char *peripheral) -> void { + address = address & 0x00ff'ffff if (address >= size) { value[0] = value[1] = value[2] = value[3] = 0; if (Size == ICache) diff --git a/ares/n64/aleck64/io.cpp b/ares/n64/aleck64/io.cpp index 6c4f66eb4..40708d617 100644 --- a/ares/n64/aleck64/io.cpp +++ b/ares/n64/aleck64/io.cpp @@ -1,6 +1,6 @@ auto Aleck64::readWord(u32 address, Thread& thread) -> u32 { if(address <= 0xc07f'ffff) { - return sdram.read(address); + return sdram.read(address & 0x00ff'ffff); } controls.poll(); @@ -9,6 +9,7 @@ auto Aleck64::readWord(u32 address, Thread& thread) -> u32 { case 0xc080'0000: return readPort1(); case 0xc080'0004: return readPort2(); case 0xc080'0008: return readPort3(); + case 0xc080'0100: return readPort4(); // can just be a stub for now, game is happy without it } } @@ -18,12 +19,13 @@ auto Aleck64::readWord(u32 address, Thread& thread) -> u32 { auto Aleck64::writeWord(u32 address, u32 data, Thread& thread) -> void { if(address <= 0xc07f'ffff) { - return sdram.write(address, data); + return sdram.write(address & 0x00ff'ffff, data); } if(address <= 0xc080'0fff) { switch (address & 0xffff'fffc) { case 0xc080'0008: return writePort3(data); + case 0xc080'0100: return writePort4(data); } } @@ -56,4 +58,15 @@ auto Aleck64::writePort3(n32 data) -> void { if(gameConfig) return gameConfig->writeExpansionPort(data); //debug(unusual, "[Aleck64::writePort3] ", hex(data, 8L)); print("[Aleck64::writePort3] ", hex(data, 8L), "\n"); -} \ No newline at end of file +} + +auto Aleck64::readPort4() -> u32 { + //debug(unimplemented, "[Aleck64::readPort4]"); + print("[Aleck64::readPort4]\n"); + return 0x0; +} + +auto Aleck64::writePort4(n32 data) -> void { + // debug(unimplemented, "[Aleck64::writePort3] ", hex(data, 8L)); + print("[Aleck64::writePort4] ", hex(data, 8L), "\n"); +} diff --git a/ares/n64/memory/bus.hpp b/ares/n64/memory/bus.hpp index d09fdf263..7d44126ac 100644 --- a/ares/n64/memory/bus.hpp +++ b/ares/n64/memory/bus.hpp @@ -20,7 +20,10 @@ inline auto Bus::read(u32 address, Thread& thread, const char *peripheral) -> u6 if(address <= 0x1fbf'ffff) return pi.read(address, thread); if(address <= 0x1fcf'ffff) return si.read(address, thread); if(address <= 0x7fff'ffff) return pi.read(address, thread); - if(Model::Aleck64()) return aleck64.read(address, thread); + if(Model::Aleck64()) { + if(address <= 0xbfff'ffff) return freezeUnmapped(address), 0; + if(address <= 0xc0800'fff) return aleck64.read(address, thread); + } return freezeUnmapped(address), 0; } @@ -46,7 +49,7 @@ inline auto Bus::readBurst(u32 address, u32 *data, Thread& thread) -> void { if(Model::Aleck64()) { if(address <= 0xbfff'ffff) return freezeUncached(address); - if(address <= 0xc07f'ffff) return aleck64.sdram.writeBurst(address, data, "CPU"); + if(address <= 0xc07f'ffff) return aleck64.sdram.readBurst(address, data, "CPU"); } return freezeUncached(address); @@ -77,7 +80,10 @@ inline auto Bus::write(u32 address, u64 data, Thread& thread, const char *periph if(address <= 0x1fbf'ffff) return pi.write(address, data, thread); if(address <= 0x1fcf'ffff) return si.write(address, data, thread); if(address <= 0x7fff'ffff) return pi.write(address, data, thread); - if(Model::Aleck64()) return aleck64.write(address, data, thread); + if(Model::Aleck64()) { + if(address <= 0xbfff'ffff) return freezeUnmapped(address); + if(address <= 0xc0800'fff) return aleck64.write(address, data, thread); + } return freezeUnmapped(address); }