diff --git a/stella/src/common/BankRomCheat.cxx b/stella/src/common/BankRomCheat.cxx new file mode 100644 index 000000000..22dd0dcf5 --- /dev/null +++ b/stella/src/common/BankRomCheat.cxx @@ -0,0 +1,43 @@ + +// FIXME - don't use the debugger for this, since it may not be included +//#include "Debugger.hxx" +#include "BankRomCheat.hxx" + +BankRomCheat::BankRomCheat(OSystem *os, string code) { + myOSystem = os; + _enabled = false; + + if(code.length() == 7) + code = "0" + code; + + bank = unhex(code.substr(0, 2)); + address = 0xf000 + unhex(code.substr(2, 3)); + value = unhex(code.substr(5, 2)); + count = unhex(code.substr(7, 1)) + 1; +} + +BankRomCheat::~BankRomCheat() { +} + +bool BankRomCheat::enabled() { return _enabled; } + +bool BankRomCheat::enable() { + int oldBank = myOSystem->console().cartridge().bank(); + myOSystem->console().cartridge().bank(bank); + for(int i=0; iconsole().cartridge().peek(address + i); + myOSystem->console().cartridge().patch(address + i, value); + } + myOSystem->console().cartridge().bank(oldBank); + return _enabled = true; +} + +bool BankRomCheat::disable() { + int oldBank = myOSystem->console().cartridge().bank(); + myOSystem->console().cartridge().bank(bank); + for(int i=0; iconsole().cartridge().patch(address + i, savedRom[i]); + } + myOSystem->console().cartridge().bank(oldBank); + return _enabled = false; +} diff --git a/stella/src/common/BankRomCheat.hxx b/stella/src/common/BankRomCheat.hxx new file mode 100644 index 000000000..043ccd34b --- /dev/null +++ b/stella/src/common/BankRomCheat.hxx @@ -0,0 +1,28 @@ + +#ifndef BANK_ROM_CHEAT_HXX +#define BANK_ROM_CHEAT_HXX + +#include "OSystem.hxx" +#include "Cheat.hxx" + +class BankRomCheat : public Cheat { + public: + BankRomCheat(OSystem *os, string code); + ~BankRomCheat(); + + virtual bool enabled(); + virtual bool enable(); + virtual bool disable(); + + + private: + bool _enabled; + uInt8 savedRom[16]; + uInt16 address; + uInt8 value; + uInt8 count; + int bank; + OSystem *myOSystem; +}; + +#endif diff --git a/stella/src/common/Cheat.cxx b/stella/src/common/Cheat.cxx index 821801ba6..b9be6ebbf 100644 --- a/stella/src/common/Cheat.cxx +++ b/stella/src/common/Cheat.cxx @@ -1,6 +1,7 @@ #include "Cheat.hxx" #include "CheetahCheat.hxx" +#include "BankRomCheat.hxx" uInt16 Cheat::unhex(string hex) { int ret = 0; @@ -26,6 +27,10 @@ Cheat* Cheat::parse(OSystem *osystem, string code) { return 0; switch(code.size()) { + case 7: + case 8: + return new BankRomCheat(osystem, code); + case 6: return new CheetahCheat(osystem, code); diff --git a/stella/src/common/module.mk b/stella/src/common/module.mk index 6428bf23f..9d9de17d8 100644 --- a/stella/src/common/module.mk +++ b/stella/src/common/module.mk @@ -3,6 +3,7 @@ MODULE := src/common MODULE_OBJS := \ src/common/Cheat.o \ src/common/CheetahCheat.o \ + src/common/BankRomCheat.o \ src/common/mainSDL.o \ src/common/SoundNull.o \ src/common/SoundSDL.o \