From 98387c6c8028237d70ab7fe65988b5c6a206a81e Mon Sep 17 00:00:00 2001 From: urchlay Date: Mon, 26 Sep 2005 03:09:37 +0000 Subject: [PATCH] Implemented stella-extended 7- and 8-digit cheat codes. These are like Cheetah codes prefixed with a 1- or 2-digit bank number. Try "1236ea1" in Battlezone: it should give infinite lives. "01236ea1" is the same thing with a 2-digit bank number ("01" instead of "1", same bank). git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@796 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/common/BankRomCheat.cxx | 43 ++++++++++++++++++++++++++++++ stella/src/common/BankRomCheat.hxx | 28 +++++++++++++++++++ stella/src/common/Cheat.cxx | 5 ++++ stella/src/common/module.mk | 1 + 4 files changed, 77 insertions(+) create mode 100644 stella/src/common/BankRomCheat.cxx create mode 100644 stella/src/common/BankRomCheat.hxx 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 \