From 43653c53af208e1fc76f239ef868a38bde991639 Mon Sep 17 00:00:00 2001 From: urchlay Date: Sat, 30 Jul 2005 22:08:25 +0000 Subject: [PATCH] Support for Bob Colbert's Cheetah cheat codes, either in the debugger or on the command line. See http://members.cox.net/rcolbert/ for details. Cheetah codes are cool, but all they can do is modify ROM. We'll also be adding some sort of extended Stella cheat code support to allow modifying RAM, either once or once per frame, like the Game Genie does on an NES. Most likely the actual codes will resemble Bob's codes, but with extra digits. Unfortunately there won't be an easy way for the real Cheetah to support these extended codes :( git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@704 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/debugger/Debugger.cxx | 9 +++- stella/src/debugger/DebuggerParser.cxx | 60 +++++++++++++++++++++++++- stella/src/debugger/DebuggerParser.hxx | 3 +- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index 7e610c7da..ddb9c3421 100644 --- a/stella/src/debugger/Debugger.cxx +++ b/stella/src/debugger/Debugger.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Debugger.cxx,v 1.78 2005-07-30 16:25:45 urchlay Exp $ +// $Id: Debugger.cxx,v 1.79 2005-07-30 22:08:24 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -154,6 +154,13 @@ void Debugger::initialize() string initBreak = myOSystem->settings().getString("break"); if(initBreak != "") run("break " + initBreak); myOSystem->settings().setString("break", "", false); + + // set up any cheeetah code that was on the command line + // (and remove the key from the settings, so they won't get set again) + string cheetah = myOSystem->settings().getString("cheetah"); + if(cheetah != "") run("cheetah " + cheetah); + myOSystem->settings().setString("cheetah", "", false); + autoExec(); } diff --git a/stella/src/debugger/DebuggerParser.cxx b/stella/src/debugger/DebuggerParser.cxx index 0ffd56119..574418ab9 100644 --- a/stella/src/debugger/DebuggerParser.cxx +++ b/stella/src/debugger/DebuggerParser.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: DebuggerParser.cxx,v 1.73 2005-07-30 16:25:48 urchlay Exp $ +// $Id: DebuggerParser.cxx,v 1.74 2005-07-30 22:08:24 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -77,6 +77,15 @@ Command DebuggerParser::commands[] = { &DebuggerParser::executeC }, + { + "cheetah", + "Use Cheetah cheat code (see http://members.cox.net/rcolbert/)", + false, + // lame: accept 0-4 args instead of inventing a kARG_MULTI_LABEL type + { kARG_LABEL, kARG_LABEL, kARG_LABEL, kARG_LABEL, kARG_END_ARGS }, + &DebuggerParser::executeCheetah + }, + { "clearbreaks", "Clear all breakpoints", @@ -1285,6 +1294,55 @@ void DebuggerParser::executeC() { debugger->cpuDebug().setC(args[0]); } +// "cheetah" +// (see http://members.cox.net/rcolbert/chtdox.htm) +void DebuggerParser::executeCheetah() { + if(argCount == 0) { + commandResult = red("Missing cheat code"); + return; + } + + for(int arg = 0; arg < argCount; arg++) { + string& cheat = argStrings[arg]; + + if(cheat.size() != 6) { + commandResult += red(cheat + ": Invalid Cheetah code (must be 6 hex digits)"); + return; + } + + for(int i=0; i<6; i++) { + if(conv_hex_digit(cheat[i]) < 0) { + commandResult += red(cheat + ": Invalid hex digit in Cheetah code"); + return; + } + } + + int addr = 0; + for(int i=0; i<3; i++) { + addr = addr * 16 + conv_hex_digit(cheat[i]); + } + addr += 0xf000; + + int value = 0; + for(int i=3; i<5; i++) { + value = value * 16 + conv_hex_digit(cheat[i]); + } + + int count = conv_hex_digit(cheat[5]) + 1; + + for(int i=0; ipatchROM(addr + i, value); + + commandResult += cheat; + commandResult += ": "; + commandResult += debugger->valueToString(count); + commandResult += " address"; + if(count != 1) commandResult += "es"; + commandResult += " modified."; + if(arg != argCount - 1) commandResult += "\n"; + } +} + // "clearbreaks" void DebuggerParser::executeClearbreaks() { debugger->clearAllBreakPoints(); diff --git a/stella/src/debugger/DebuggerParser.hxx b/stella/src/debugger/DebuggerParser.hxx index 8fd9e4218..e3ff5f81a 100644 --- a/stella/src/debugger/DebuggerParser.hxx +++ b/stella/src/debugger/DebuggerParser.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: DebuggerParser.hxx,v 1.39 2005-07-30 16:25:48 urchlay Exp $ +// $Id: DebuggerParser.hxx,v 1.40 2005-07-30 22:08:25 urchlay Exp $ //============================================================================ #ifndef DEBUGGER_PARSER_HXX @@ -100,6 +100,7 @@ class DebuggerParser void executeBreak(); void executeBreakif(); void executeC(); + void executeCheetah(); void executeClearbreaks(); void executeCleartraps(); void executeClearwatches();