From e708dc478117d0073e9ab14429a638b960002e66 Mon Sep 17 00:00:00 2001 From: devinacker Date: Sun, 10 Jun 2018 22:55:22 -0400 Subject: [PATCH] improve handling of cheats to handle things other than WRAM (closes #97) note: mirroring detection for cheats doesn't work for two addresses in the same 64kb bank i.e. the lowest 16 bits of both addresses must still be the same --- README.md | 7 ------- bsnes/snes/cheat/cheat-inline.hpp | 2 +- bsnes/snes/cheat/cheat.cpp | 29 +++-------------------------- bsnes/snes/cheat/cheat.hpp | 7 +++---- bsnes/snes/memory/memory-inline.hpp | 2 +- 5 files changed, 8 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 01d93be..00447d6 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,6 @@ Non-debugging features: - IPS and BPS soft patching - Multiple emulation improvements backported from bsnes/higan (mostly via bsnes-classic) -## Coming soon - -- On-the-fly ROM saving and reloading from the memory editor for quick hacking and testing -- More keyboard shortcuts for menus, etc. -- Automatic saving/loading breakpoints between sessions -- Similar addressing improvements for cheats - ## Building on Windows - Get mingw-w64 (http://mingw-w64.yaxm.org/doku.php/download) diff --git a/bsnes/snes/cheat/cheat-inline.hpp b/bsnes/snes/cheat/cheat-inline.hpp index a80f47f..9ef28cb 100644 --- a/bsnes/snes/cheat/cheat-inline.hpp +++ b/bsnes/snes/cheat/cheat-inline.hpp @@ -1,2 +1,2 @@ bool Cheat::active() const { return cheat_enabled; } -bool Cheat::exists(unsigned addr) const { return bitmask[addr >> 3] & 1 << (addr & 7); } +bool Cheat::exists(uint16 addr) const { return bitmask[addr >> 3] & 1 << (addr & 7); } diff --git a/bsnes/snes/cheat/cheat.cpp b/bsnes/snes/cheat/cheat.cpp index 40fdf7c..51de966 100644 --- a/bsnes/snes/cheat/cheat.cpp +++ b/bsnes/snes/cheat/cheat.cpp @@ -25,34 +25,21 @@ void Cheat::synchronize() { for(unsigned n = 0; n < code.addr.size(); n++) { code_enabled = true; - unsigned addr = mirror(code.addr[n]); + uint16 addr = code.addr[n]; bitmask[addr >> 3] |= 1 << (addr & 7); - if((addr & 0xffe000) == 0x7e0000) { - //mirror $7e:0000-1fff to $00-3f|80-bf:0000-1fff - unsigned mirroraddr; - for(unsigned x = 0; x <= 0x3f; x++) { - mirroraddr = ((0x00 + x) << 16) + (addr & 0x1fff); - bitmask[mirroraddr >> 3] |= 1 << (mirroraddr & 7); - - mirroraddr = ((0x80 + x) << 16) + (addr & 0x1fff); - bitmask[mirroraddr >> 3] |= 1 << (mirroraddr & 7); - } - } } } cheat_enabled = system_enabled && code_enabled; } -bool Cheat::read(unsigned addr, uint8 &data) const { - addr = mirror(addr); - +bool Cheat::read(unsigned addr, uint8 &data, Bus &bus) const { for(unsigned i = 0; i < size(); i++) { const CheatCode &code = operator[](i); if(code.enabled == false) continue; for(unsigned n = 0; n < code.addr.size(); n++) { - if(addr == mirror(code.addr[n])) { + if(bus.is_mirror(addr, code.addr[n])) { data = code.data[n]; return true; } @@ -149,16 +136,6 @@ bool Cheat::encode(string &s, unsigned addr, uint8 data, Type type) { } } -//======== -//internal -//======== - -unsigned Cheat::mirror(unsigned addr) const { - //$00-3f|80-bf:0000-1fff -> $7e:0000-1fff - if((addr & 0x40e000) == 0x000000) return (0x7e0000 + (addr & 0x1fff)); - return addr; -} - //========= //CheatCode //========= diff --git a/bsnes/snes/cheat/cheat.hpp b/bsnes/snes/cheat/cheat.hpp index ac4b43e..d13de53 100644 --- a/bsnes/snes/cheat/cheat.hpp +++ b/bsnes/snes/cheat/cheat.hpp @@ -14,10 +14,10 @@ public: bool enabled() const; void enable(bool); void synchronize(); - bool read(unsigned, uint8&) const; + bool read(unsigned, uint8&, Bus&) const; inline bool active() const; - inline bool exists(unsigned addr) const; + inline bool exists(uint16 addr) const; Cheat(); @@ -25,11 +25,10 @@ public: static bool encode(string&, unsigned, uint8, Type); private: - uint8 bitmask[0x200000]; + uint8 bitmask[0x2000]; bool system_enabled; bool code_enabled; bool cheat_enabled; - unsigned mirror(unsigned) const; }; extern Cheat cheat; diff --git a/bsnes/snes/memory/memory-inline.hpp b/bsnes/snes/memory/memory-inline.hpp index 8bbcd7c..215b369 100644 --- a/bsnes/snes/memory/memory-inline.hpp +++ b/bsnes/snes/memory/memory-inline.hpp @@ -63,7 +63,7 @@ uint8 Bus::read(uint24 addr) { #if defined(CHEAT_SYSTEM) if(cheat.active() && cheat.exists(addr)) { uint8 r; - if(cheat.read(addr, r)) return r; + if(cheat.read(addr, r, *this)) return r; } #endif Page &p = page[addr >> 8];