From 234c494c3edfe6fb997d0a2bca28353160a85ad5 Mon Sep 17 00:00:00 2001 From: Sour Date: Sun, 8 Dec 2019 11:54:19 -0500 Subject: [PATCH] Debugger: SA1 - Fixed display for BWRAM --- Core/CpuBwRamHandler.h | 4 ++-- Core/Cx4.cpp | 2 +- Core/Cx4.h | 2 +- Core/Gsu.cpp | 2 +- Core/Gsu.h | 2 +- Core/GsuRamHandler.h | 2 +- Core/GsuRomHandler.h | 2 +- Core/IMemoryHandler.h | 2 +- Core/MemoryMappings.cpp | 2 +- Core/NecDsp.cpp | 2 +- Core/NecDsp.h | 2 +- Core/Obc1.cpp | 2 +- Core/Obc1.h | 2 +- Core/RamHandler.h | 2 +- Core/RegisterHandlerA.h | 2 +- Core/RegisterHandlerB.cpp | 2 +- Core/RegisterHandlerB.h | 2 +- Core/Sa1.cpp | 6 ++---- Core/Sa1.h | 2 +- Core/Sa1BwRamHandler.h | 35 ++++++++++++++++++++--------------- Core/Sa1IRamHandler.h | 21 +++++++++++++-------- Core/Sa1VectorHandler.h | 4 ++-- Core/Sdd1.cpp | 2 +- Core/Sdd1.h | 2 +- Core/Sdd1Mmc.cpp | 2 +- Core/Sdd1Mmc.h | 2 +- 26 files changed, 60 insertions(+), 52 deletions(-) diff --git a/Core/CpuBwRamHandler.h b/Core/CpuBwRamHandler.h index 5a25a58..bef9c9e 100644 --- a/Core/CpuBwRamHandler.h +++ b/Core/CpuBwRamHandler.h @@ -36,9 +36,9 @@ public: return Read(addr); } - void PeekBlock(uint8_t *output) override + void PeekBlock(uint32_t addr, uint8_t *output) override { - _handler->PeekBlock(output); + _handler->PeekBlock(addr, output); } void Write(uint32_t addr, uint8_t value) override diff --git a/Core/Cx4.cpp b/Core/Cx4.cpp index 61211cb..8088a3c 100644 --- a/Core/Cx4.cpp +++ b/Core/Cx4.cpp @@ -445,7 +445,7 @@ uint8_t Cx4::Peek(uint32_t addr) return 0; } -void Cx4::PeekBlock(uint8_t* output) +void Cx4::PeekBlock(uint32_t addr, uint8_t* output) { memset(output, 0, 0x1000); } diff --git a/Core/Cx4.h b/Core/Cx4.h index 994268e..1e61f90 100644 --- a/Core/Cx4.h +++ b/Core/Cx4.h @@ -122,7 +122,7 @@ public: void Serialize(Serializer &s) override; uint8_t Peek(uint32_t addr) override; - void PeekBlock(uint8_t* output) override; + void PeekBlock(uint32_t addr, uint8_t* output) override; AddressInfo GetAbsoluteAddress(uint32_t address) override; uint8_t* DebugGetDataRam(); diff --git a/Core/Gsu.cpp b/Core/Gsu.cpp index 2487df2..6bf355b 100644 --- a/Core/Gsu.cpp +++ b/Core/Gsu.cpp @@ -583,7 +583,7 @@ uint8_t Gsu::Peek(uint32_t addr) return 0; } -void Gsu::PeekBlock(uint8_t *output) +void Gsu::PeekBlock(uint32_t addr, uint8_t *output) { memset(output, 0, 0x1000); } diff --git a/Core/Gsu.h b/Core/Gsu.h index 7299968..eefab1b 100644 --- a/Core/Gsu.h +++ b/Core/Gsu.h @@ -159,7 +159,7 @@ public: uint8_t Read(uint32_t addr) override; uint8_t Peek(uint32_t addr) override; - void PeekBlock(uint8_t *output) override; + void PeekBlock(uint32_t addr, uint8_t *output) override; void Write(uint32_t addr, uint8_t value) override; AddressInfo GetAbsoluteAddress(uint32_t address) override; diff --git a/Core/GsuRamHandler.h b/Core/GsuRamHandler.h index 9503aba..4fd8556 100644 --- a/Core/GsuRamHandler.h +++ b/Core/GsuRamHandler.h @@ -32,7 +32,7 @@ public: return Read(addr); } - void PeekBlock(uint8_t *output) override + void PeekBlock(uint32_t addr, uint8_t *output) override { for(int i = 0; i < 0x1000; i++) { output[i] = Read(i); diff --git a/Core/GsuRomHandler.h b/Core/GsuRomHandler.h index 7896de7..3752b88 100644 --- a/Core/GsuRomHandler.h +++ b/Core/GsuRomHandler.h @@ -43,7 +43,7 @@ public: return Read(addr); } - void PeekBlock(uint8_t *output) override + void PeekBlock(uint32_t addr, uint8_t *output) override { for(int i = 0; i < 0x1000; i++) { output[i] = Read(i); diff --git a/Core/IMemoryHandler.h b/Core/IMemoryHandler.h index d2a3433..00cfe40 100644 --- a/Core/IMemoryHandler.h +++ b/Core/IMemoryHandler.h @@ -10,7 +10,7 @@ protected: public: virtual uint8_t Read(uint32_t addr) = 0; virtual uint8_t Peek(uint32_t addr) = 0; - virtual void PeekBlock(uint8_t *output) = 0; + virtual void PeekBlock(uint32_t addr, uint8_t *output) = 0; virtual void Write(uint32_t addr, uint8_t value) = 0; __forceinline SnesMemoryType GetMemoryType() diff --git a/Core/MemoryMappings.cpp b/Core/MemoryMappings.cpp index 934032c..a07774b 100644 --- a/Core/MemoryMappings.cpp +++ b/Core/MemoryMappings.cpp @@ -78,7 +78,7 @@ void MemoryMappings::PeekBlock(uint32_t addr, uint8_t *dest) { IMemoryHandler* handler = GetHandler(addr); if(handler) { - handler->PeekBlock(dest); + handler->PeekBlock(addr & ~0xFFF, dest); } else { memset(dest, 0, 0x1000); } diff --git a/Core/NecDsp.cpp b/Core/NecDsp.cpp index 5e39265..79dc648 100644 --- a/Core/NecDsp.cpp +++ b/Core/NecDsp.cpp @@ -223,7 +223,7 @@ uint8_t NecDsp::Peek(uint32_t addr) return 0; } -void NecDsp::PeekBlock(uint8_t *output) +void NecDsp::PeekBlock(uint32_t addr, uint8_t *output) { memset(output, 0, 0x1000); } diff --git a/Core/NecDsp.h b/Core/NecDsp.h index fdb0ec3..ce18f43 100644 --- a/Core/NecDsp.h +++ b/Core/NecDsp.h @@ -63,7 +63,7 @@ public: void Write(uint32_t addr, uint8_t value) override; uint8_t Peek(uint32_t addr) override; - void PeekBlock(uint8_t * output) override; + void PeekBlock(uint32_t addr, uint8_t * output) override; AddressInfo GetAbsoluteAddress(uint32_t address) override; uint8_t* DebugGetProgramRom(); diff --git a/Core/Obc1.cpp b/Core/Obc1.cpp index f76e092..3b2cf2d 100644 --- a/Core/Obc1.cpp +++ b/Core/Obc1.cpp @@ -87,7 +87,7 @@ uint8_t Obc1::Peek(uint32_t addr) return 0; } -void Obc1::PeekBlock(uint8_t *output) +void Obc1::PeekBlock(uint32_t addr, uint8_t *output) { memset(output, 0, 0x1000); } diff --git a/Core/Obc1.h b/Core/Obc1.h index 13728b2..189417f 100644 --- a/Core/Obc1.h +++ b/Core/Obc1.h @@ -28,6 +28,6 @@ public: void Serialize(Serializer & s) override; uint8_t Peek(uint32_t addr) override; - void PeekBlock(uint8_t * output) override; + void PeekBlock(uint32_t addr, uint8_t * output) override; AddressInfo GetAbsoluteAddress(uint32_t address) override; }; \ No newline at end of file diff --git a/Core/RamHandler.h b/Core/RamHandler.h index 5cacdce..e798526 100644 --- a/Core/RamHandler.h +++ b/Core/RamHandler.h @@ -34,7 +34,7 @@ public: return _ram[addr & _mask]; } - void PeekBlock(uint8_t *output) override + void PeekBlock(uint32_t addr, uint8_t *output) override { if(_mask != 0xFFF) { for(int i = 0; i < 0x1000; i++) { diff --git a/Core/RegisterHandlerA.h b/Core/RegisterHandlerA.h index 9cbf636..e374539 100644 --- a/Core/RegisterHandlerA.h +++ b/Core/RegisterHandlerA.h @@ -45,7 +45,7 @@ public: } } - void PeekBlock(uint8_t *output) override + void PeekBlock(uint32_t addr, uint8_t *output) override { //Avoid side effects for now memset(output, 0, 0x1000); diff --git a/Core/RegisterHandlerB.cpp b/Core/RegisterHandlerB.cpp index fe67ce2..a7a9c5d 100644 --- a/Core/RegisterHandlerB.cpp +++ b/Core/RegisterHandlerB.cpp @@ -48,7 +48,7 @@ uint8_t RegisterHandlerB::Peek(uint32_t addr) return 0; } -void RegisterHandlerB::PeekBlock(uint8_t *output) +void RegisterHandlerB::PeekBlock(uint32_t addr, uint8_t *output) { //Avoid side effects for now memset(output, 0, 0x1000); diff --git a/Core/RegisterHandlerB.h b/Core/RegisterHandlerB.h index ca37c98..ba48b6f 100644 --- a/Core/RegisterHandlerB.h +++ b/Core/RegisterHandlerB.h @@ -28,7 +28,7 @@ public: uint8_t Read(uint32_t addr) override; uint8_t Peek(uint32_t addr) override; - void PeekBlock(uint8_t *output) override; + void PeekBlock(uint32_t addr, uint8_t *output) override; void Write(uint32_t addr, uint8_t value) override; AddressInfo GetAbsoluteAddress(uint32_t address) override; diff --git a/Core/Sa1.cpp b/Core/Sa1.cpp index 2fcb565..171615c 100644 --- a/Core/Sa1.cpp +++ b/Core/Sa1.cpp @@ -467,11 +467,9 @@ uint8_t Sa1::Peek(uint32_t addr) return 0; } -void Sa1::PeekBlock(uint8_t *output) +void Sa1::PeekBlock(uint32_t addr, uint8_t *output) { - for(int i = 0; i < 0x1000; i++) { - output[i] = Peek(i); - } + memset(output, 0, 0x1000); } void Sa1::Write(uint32_t addr, uint8_t value) diff --git a/Core/Sa1.h b/Core/Sa1.h index e657bbf..46de790 100644 --- a/Core/Sa1.h +++ b/Core/Sa1.h @@ -74,7 +74,7 @@ public: void Serialize(Serializer & s) override; uint8_t Read(uint32_t addr) override; uint8_t Peek(uint32_t addr) override; - void PeekBlock(uint8_t * output) override; + void PeekBlock(uint32_t addr, uint8_t *output) override; void Write(uint32_t addr, uint8_t value) override; AddressInfo GetAbsoluteAddress(uint32_t address) override; diff --git a/Core/Sa1BwRamHandler.h b/Core/Sa1BwRamHandler.h index a3fb385..e119a1d 100644 --- a/Core/Sa1BwRamHandler.h +++ b/Core/Sa1BwRamHandler.h @@ -20,15 +20,7 @@ private: return ((_state->Sa1BwBank * 0x2000) | (addr & 0x1FFF)); } -public: - Sa1BwRamHandler(uint8_t* bwRam, uint32_t bwRamSize, Sa1State* state) - { - _ram = bwRam; - _mask = bwRamSize - 1; - _state = state; - } - - uint8_t Read(uint32_t addr) override + __forceinline uint8_t InternalRead(uint32_t addr) { if((addr & 0x600000) == 0x600000) { return ReadBitmapMode(addr - 0x600000); @@ -44,15 +36,28 @@ public: } } - uint8_t Peek(uint32_t addr) override +public: + Sa1BwRamHandler(uint8_t* bwRam, uint32_t bwRamSize, Sa1State* state) { - return Read(addr); + _ram = bwRam; + _mask = bwRamSize - 1; + _state = state; } - void PeekBlock(uint8_t *output) override + uint8_t Read(uint32_t addr) override + { + return InternalRead(addr); + } + + uint8_t Peek(uint32_t addr) override + { + return InternalRead(addr); + } + + void PeekBlock(uint32_t addr, uint8_t *output) override { for(int i = 0; i < 0x1000; i++) { - output[i] = Read(i); + output[i] = InternalRead(addr + i); } } @@ -96,9 +101,9 @@ public: { AddressInfo info; if((addr & 0x600000) == 0x600000) { - info.Address = addr - 0x600000; + info.Address = ((addr - 0x600000) >> (_state->BwRam2BppMode ? 2 : 1)) & _mask; } else { - addr = GetBwRamAddress(addr); + addr = GetBwRamAddress(addr) & _mask; } info.Type = SnesMemoryType::SaveRam; return info; diff --git a/Core/Sa1IRamHandler.h b/Core/Sa1IRamHandler.h index 945933f..b04540c 100644 --- a/Core/Sa1IRamHandler.h +++ b/Core/Sa1IRamHandler.h @@ -8,6 +8,15 @@ class Sa1IRamHandler : public IMemoryHandler private: uint8_t * _ram; + __forceinline uint8_t InternalRead(uint32_t addr) + { + if(addr & 0x800) { + return 0; + } else { + return _ram[addr & 0x7FF]; + } + } + public: Sa1IRamHandler(uint8_t *ram) { @@ -17,22 +26,18 @@ public: uint8_t Read(uint32_t addr) override { - if(addr & 0x800) { - return 0; - } else { - return _ram[addr & 0x7FF]; - } + return InternalRead(addr); } uint8_t Peek(uint32_t addr) override { - return Read(addr); + return InternalRead(addr); } - void PeekBlock(uint8_t *output) override + void PeekBlock(uint32_t addr, uint8_t *output) override { for(int i = 0; i < 0x1000; i++) { - output[i] = Read(i); + output[i] = InternalRead(i); } } diff --git a/Core/Sa1VectorHandler.h b/Core/Sa1VectorHandler.h index f374520..77d7eeb 100644 --- a/Core/Sa1VectorHandler.h +++ b/Core/Sa1VectorHandler.h @@ -58,9 +58,9 @@ public: return Read(addr); } - void PeekBlock(uint8_t *output) override + void PeekBlock(uint32_t addr, uint8_t *output) override { - _handler->PeekBlock(output); + _handler->PeekBlock(addr, output); } void Write(uint32_t addr, uint8_t value) override diff --git a/Core/Sdd1.cpp b/Core/Sdd1.cpp index 3e6d34c..5df252f 100644 --- a/Core/Sdd1.cpp +++ b/Core/Sdd1.cpp @@ -109,7 +109,7 @@ uint8_t Sdd1::Peek(uint32_t addr) return 0; } -void Sdd1::PeekBlock(uint8_t* output) +void Sdd1::PeekBlock(uint32_t addr, uint8_t* output) { memset(output, 0, 0x1000); } diff --git a/Core/Sdd1.h b/Core/Sdd1.h index 163c030..b2bc379 100644 --- a/Core/Sdd1.h +++ b/Core/Sdd1.h @@ -19,7 +19,7 @@ public: void Serialize(Serializer &s) override; uint8_t Read(uint32_t addr) override; uint8_t Peek(uint32_t addr) override; - void PeekBlock(uint8_t* output) override; + void PeekBlock(uint32_t addr, uint8_t* output) override; void Write(uint32_t addr, uint8_t value) override; AddressInfo GetAbsoluteAddress(uint32_t address) override; void Reset() override; diff --git a/Core/Sdd1Mmc.cpp b/Core/Sdd1Mmc.cpp index 789afcd..8102960 100644 --- a/Core/Sdd1Mmc.cpp +++ b/Core/Sdd1Mmc.cpp @@ -68,7 +68,7 @@ uint8_t Sdd1Mmc::Peek(uint32_t addr) return 0; } -void Sdd1Mmc::PeekBlock(uint8_t *output) +void Sdd1Mmc::PeekBlock(uint32_t addr, uint8_t *output) { memset(output, 0, 0x1000); } diff --git a/Core/Sdd1Mmc.h b/Core/Sdd1Mmc.h index db6185d..2b843de 100644 --- a/Core/Sdd1Mmc.h +++ b/Core/Sdd1Mmc.h @@ -25,7 +25,7 @@ public: // Inherited via IMemoryHandler virtual uint8_t Read(uint32_t addr) override; virtual uint8_t Peek(uint32_t addr) override; - virtual void PeekBlock(uint8_t * output) override; + virtual void PeekBlock(uint32_t addr, uint8_t * output) override; virtual void Write(uint32_t addr, uint8_t value) override; virtual AddressInfo GetAbsoluteAddress(uint32_t address) override;