Added new Cheat infrastructure. Ram-based cheats are now supported.

Currently they must be 4 hex characters long, and do not support
compare before writing (direct-write, not compare-write).  These
codes are also executed per-frame.

Changed 'cheetah' commandline/debugger argument to 'cheat', and any type
of cheat may be specified here.  Currently supported are 4 char RAM,
6 char Cheetah, and 8 char Stella extended Cheetah.

Still TODO is add load/save of cheats, add one-shot and compare-write
cheats, and finally add a dialog to do all this from within Stella.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@874 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-11-11 21:44:19 +00:00
parent d76d9247c2
commit 429cc63d1d
21 changed files with 581 additions and 184 deletions

23
stella/configure vendored
View File

@ -24,6 +24,7 @@ _build_sound=yes
_build_developer=yes
_build_snapshot=yes
_build_joystick=yes
_build_cheats=yes
_build_static=no
# more defaults
@ -259,6 +260,8 @@ Optional Features:
--disable-snapshot
--enable-joystick enable/disable joystick support [enabled]
--disable-joystick
--enable-cheats enable/disable cheatcode support [enabled]
--disable-cheats
--enable-shared build shared binary [enabled]
--enable-static build static binary (if possible) [disabled]
--disable-static
@ -302,6 +305,8 @@ for ac_option in $@; do
--disable-snapshot) _build_snapshot=no ;;
--enable-joystick) _build_joystick=yes ;;
--disable-joystick) _build_joystick=no ;;
--enable-cheats) _build_cheats=yes ;;
--disable-cheats) _build_cheats=no ;;
--enable-zlib) _zlib=yes ;;
--disable-zlib) _zlib=no ;;
--enable-png) _png=yes ;;
@ -683,6 +688,14 @@ else
echo
fi
if test "$_build_cheats" = yes ; then
echo_n " Cheatcode support enabled"
echo
else
echo_n " Cheatcode support disabled"
echo
fi
if test "$_build_static" = yes ; then
echo_n " Static binary enabled"
echo
@ -705,6 +718,7 @@ GUI="$SRC/gui"
DBG="$SRC/debugger"
DBGGUI="$SRC/debugger/gui"
YACC="$SRC/yacc"
CHEAT="$SRC/cheat"
INCLUDES="-I$CORE -I$CORE/m6502/src -I$CORE/m6502/src/bspf/src -I$COMMON -I$GUI"
@ -798,6 +812,13 @@ if test "$_build_joystick" = yes ; then
DEFINES="$DEFINES -DJOYSTICK_SUPPORT"
fi
if test "$_build_cheats" = yes ; then
DEFINES="$DEFINES -DCHEATCODE_SUPPORT"
MODULES="$MODULES $CHEAT"
INCLUDES="$INCLUDES -I$CHEAT"
fi
# 20051003 bkw: fix static Linux build.
# No guarantee this will work for anyone other than me, and no
# guarantee it's needed by anyone but me (and Steve)...
@ -851,7 +872,7 @@ if test $_host_os = "psp" ; then
cat >> config.mak << EOF
PSP-STRIP := $PSP_STRIP
PSP-FIX := $PSP_FIX
PSP-FIX := $PSP_FIX
PACK-PBP := $PACK_PBP
MKSFO := $MKSFO
PSP-MOUNTPOINT := $PSP_MOUNTPOINT

View File

@ -13,24 +13,22 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: BankRomCheat.cxx,v 1.2 2005-09-26 19:10:37 stephena Exp $
// $Id: BankRomCheat.cxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
//============================================================================
#include "BankRomCheat.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BankRomCheat::BankRomCheat(OSystem *os, string code)
BankRomCheat::BankRomCheat(OSystem* os, const string& name, const string& code)
: Cheat(os, name, code)
{
myOSystem = os;
_enabled = false;
if(myCode.length() == 7)
myCode = "0" + code;
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;
bank = unhex(myCode.substr(0, 2));
address = 0xf000 + unhex(myCode.substr(2, 3));
value = unhex(myCode.substr(5, 2));
count = unhex(myCode.substr(7, 1)) + 1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -38,26 +36,11 @@ 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; i<count; i++)
{
savedRom[i] = myOSystem->console().cartridge().peek(address + i);
myOSystem->console().cartridge().patch(address + i, value);
}
myOSystem->console().cartridge().bank(oldBank);
return _enabled = true;
evaluate();
return myEnabled;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -70,5 +53,24 @@ bool BankRomCheat::disable()
myOSystem->console().cartridge().bank(oldBank);
return _enabled = false;
return myEnabled = false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BankRomCheat::evaluate()
{
if(!myEnabled)
{
int oldBank = myOSystem->console().cartridge().bank();
myOSystem->console().cartridge().bank(bank);
for(int i=0; i<count; i++)
{
savedRom[i] = myOSystem->console().cartridge().peek(address + i);
myOSystem->console().cartridge().patch(address + i, value);
}
myOSystem->console().cartridge().bank(oldBank);
myEnabled = true;
}
}

View File

@ -13,29 +13,26 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: BankRomCheat.hxx,v 1.2 2005-09-28 19:59:24 stephena Exp $
// $Id: BankRomCheat.hxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
//============================================================================
#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(OSystem* os, const string& name, const string& code);
~BankRomCheat();
virtual bool enabled();
virtual bool enable();
virtual bool disable();
private:
OSystem* myOSystem;
virtual void evaluate();
bool _enabled;
private:
uInt8 savedRom[16];
uInt16 address;
uInt8 value;

View File

@ -0,0 +1,72 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Cheat.hxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
//============================================================================
#ifndef CHEAT_HXX
#define CHEAT_HXX
#include "OSystem.hxx"
#include "bspf.hxx"
class Cheat
{
public:
Cheat(OSystem* osystem, const string& name, const string& code)
: myOSystem(osystem),
myName(name),
myCode(code),
myEnabled(false) { }
virtual ~Cheat() { }
bool enabled() const { return myEnabled; }
const string& name() const { return myName; }
const string& code() const { return myCode; }
virtual bool enable() = 0;
virtual bool disable() = 0;
virtual void evaluate() = 0;
protected:
static uInt16 unhex(const string& hex)
{
int ret = 0;
for(unsigned int i=0; i<hex.size(); i++) {
char c = hex[i];
ret *= 16;
if(c >= '0' && c <= '9')
ret += c - '0';
else if(c >= 'A' && c <= 'F')
ret += c - 'A' + 10;
else
ret += c - 'a' + 10;
}
return ret;
}
protected:
OSystem* myOSystem;
string myName;
string myCode;
bool myEnabled;
};
#endif

View File

@ -0,0 +1,155 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CheatManager.cxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
//============================================================================
#include "OSystem.hxx"
#include "Cheat.hxx"
#include "CheetahCheat.hxx"
#include "BankRomCheat.hxx"
#include "RamCheat.hxx"
#include "CheatManager.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CheatManager::CheatManager(OSystem* osystem)
: myOSystem(osystem)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CheatManager::~CheatManager()
{
// Don't delete the items from per-frame list, since it will be done in
// the following loop
myPerFrameList.clear();
for(unsigned int i = 0; i < myCheatList.size(); i++)
{
cerr << myCheatList[i]->name() << ": " << myCheatList[i]->code() << endl;
delete myCheatList[i];
}
myCheatList.clear();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const Cheat* CheatManager::add(const string& name, const string& code,
bool enable)
{
for(unsigned int i = 0; i < code.size(); i++)
if(!isxdigit(code[i]))
return NULL;
Cheat* cheat = (Cheat*) NULL;
// Check if already present
bool duplicate = false;
for(unsigned int i = 0; i < myCheatList.size(); i++)
{
if(myCheatList[i]->code() == code)
{
cheat = myCheatList[i];
duplicate = true;
cerr << "Duplicate found: " << cheat->name() << ":" << cheat->code() << endl;
break;
}
}
// Only create new cheat when necessary
if(!duplicate)
{
switch(code.size())
{
case 4:
cheat = new RamCheat(myOSystem, name, code);
break;
case 6:
cheat = new CheetahCheat(myOSystem, name, code);
break;
case 8:
cheat = new BankRomCheat(myOSystem, name, code);
break;
}
// Add the cheat to the main cheat list
if(cheat)
myCheatList.push_back(cheat);
}
if(cheat)
{
// And enable/disable it (the cheat knows how to enable or disable itself)
if(enable)
cheat->enable();
else
cheat->disable();
}
return cheat;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheatManager::addPerFrame(Cheat* cheat, bool enable)
{
if(!cheat)
return;
// Make sure there are no duplicates
bool found = false;
unsigned int i = 0;
for(i = 0; i < myPerFrameList.size(); i++)
{
if(myPerFrameList[i]->code() == cheat->code())
{
found = true;
break;
}
}
if(enable)
if(!found)
myPerFrameList.push_back(cheat);
else
if(found)
myPerFrameList.remove_at(i);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheatManager::parse(const string& cheats)
{
// FIXME - deal with comma-separated cheats
cerr << "parsing cheats: " << cheats << endl;
add("TEST", cheats, true);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheatManager::enable(const string& code, bool enable)
{
for(unsigned int i = 0; i < myCheatList.size(); i++)
{
if(myCheatList[i]->code() == code)
{
if(enable)
myCheatList[i]->enable();
else
myCheatList[i]->disable();
break;
}
}
}

View File

@ -0,0 +1,97 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CheatManager.hxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
//============================================================================
#ifndef CHEAT_MANAGER_HXX
#define CHEAT_MANAGER_HXX
#include "OSystem.hxx"
#include "bspf.hxx"
#include "Array.hxx"
#include "Cheat.hxx"
typedef GUI::Array<Cheat*> CheatList;
/**
This class provides an interface for performing all cheat operations
in Stella. It is accessible from the OSystem interface, and contains
the list of all cheats currently in use.
@author Stephen Anthony
@version $Id: CheatManager.hxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
*/
class CheatManager
{
public:
CheatManager(OSystem* osystem);
virtual ~CheatManager();
/**
Adds the specified cheat to an internal list.
@param name Name of the cheat (not absolutely required)
@param code The actual cheatcode (in hex)
@param enable Whether to enable this cheat right away
@return The cheat (if was created), else NULL.
*/
const Cheat* add(const string& name, const string& code, bool enable = true);
/**
Adds the specified cheat to the internal per-frame list.
This method doesn't create a new cheat; it just adds/removes
an already created cheat to the per-frame list.
@param cheat The actual cheat object
@param enable Add or remove the cheat to the per-frame list
*/
void addPerFrame(Cheat* cheat, bool enable);
/**
Parses a list of cheats and adds/enables each one.
@param cheats Comma-separated list of cheats (without any names)
*/
void parse(const string& cheats);
/**
Enable/disabled the cheat specified by the given code.
@param code The actual cheatcode to search for
@param enable Enable/disable the cheat
*/
void enable(const string& code, bool enable);
/**
Clear all lists of all cheats.
*/
void clear();
/**
Returns the per-frame cheatlist (needed to evaluate cheats each frame)
*/
const CheatList& perFrame() { return myPerFrameList; }
private:
OSystem* myOSystem;
CheatList myCheatList;
CheatList myPerFrameList;
};
#endif

View File

@ -13,17 +13,15 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CheetahCheat.cxx,v 1.3 2005-09-26 19:10:37 stephena Exp $
// $Id: CheetahCheat.cxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
//============================================================================
#include "CheetahCheat.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CheetahCheat::CheetahCheat(OSystem *os, string code)
CheetahCheat::CheetahCheat(OSystem* os, const string& name, const string& code)
: Cheat(os, name, code)
{
myOSystem = os;
_enabled = false;
address = 0xf000 + unhex(code.substr(0, 3));
value = unhex(code.substr(3, 2));
count = unhex(code.substr(5, 1)) + 1;
@ -34,22 +32,11 @@ CheetahCheat::~CheetahCheat()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CheetahCheat::enabled()
{
return _enabled;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CheetahCheat::enable()
{
for(int i=0; i<count; i++)
{
savedRom[i] = myOSystem->console().cartridge().peek(address + i);
myOSystem->console().cartridge().patch(address + i, value);
}
return _enabled = true;
evaluate();
return myEnabled;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -58,5 +45,20 @@ bool CheetahCheat::disable()
for(int i=0; i<count; i++)
myOSystem->console().cartridge().patch(address + i, savedRom[i]);
return _enabled = false;
return myEnabled = false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheetahCheat::evaluate()
{
if(!myEnabled)
{
for(int i=0; i<count; i++)
{
savedRom[i] = myOSystem->console().cartridge().peek(address + i);
myOSystem->console().cartridge().patch(address + i, value);
}
myEnabled = true;
}
}

View File

@ -13,29 +13,26 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CheetahCheat.hxx,v 1.3 2005-09-26 19:10:37 stephena Exp $
// $Id: CheetahCheat.hxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
//============================================================================
#ifndef CHEETAH_CHEAT_HXX
#define CHEETAH_CHEAT_HXX
#include "OSystem.hxx"
#include "Cheat.hxx"
class CheetahCheat : public Cheat
{
public:
CheetahCheat(OSystem *os, string code);
CheetahCheat(OSystem* os, const string& name, const string& code);
~CheetahCheat();
virtual bool enabled();
virtual bool enable();
virtual bool disable();
private:
OSystem* myOSystem;
virtual void evaluate();
bool _enabled;
private:
uInt8 savedRom[16];
uInt16 address;
uInt8 value;

View File

@ -0,0 +1,60 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: RamCheat.cxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
//============================================================================
#include "System.hxx"
#include "CheatManager.hxx"
#include "RamCheat.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RamCheat::RamCheat(OSystem* os, const string& name, const string& code)
: Cheat(os, name, code)
{
address = (uInt16) unhex(myCode.substr(0, 2));
value = (uInt8) unhex(myCode.substr(2, 2));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RamCheat::~RamCheat()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RamCheat::enable()
{
if(!myEnabled)
{
myOSystem->cheat().addPerFrame(this, true);
myEnabled = true;
}
return myEnabled;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RamCheat::disable()
{
cerr << "perFrame remove " << myName << ":" << myCode << endl;
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RamCheat::evaluate()
{
myOSystem->console().system().poke(address, value);
}

View File

@ -13,30 +13,28 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Cheat.hxx,v 1.3 2005-09-26 19:10:37 stephena Exp $
// $Id: RamCheat.hxx,v 1.1 2005-11-11 21:44:18 stephena Exp $
//============================================================================
#ifndef CHEAT_HXX
#define CHEAT_HXX
#ifndef RAM_CHEAT_HXX
#define RAM_CHEAT_HXX
#include "bspf.hxx"
#include "OSystem.hxx"
#include "Cheat.hxx"
class Cheat
class RamCheat : public Cheat
{
public:
Cheat() { }
virtual ~Cheat() { }
RamCheat(OSystem* os, const string& name, const string& code);
~RamCheat();
static Cheat *parse(OSystem *osystem, string code);
static uInt16 unhex(string hex);
virtual bool enable();
virtual bool disable();
virtual bool enabled() = 0;
virtual bool enable() = 0;
virtual bool disable() = 0;
virtual void evaluate();
protected:
//Cheat(string code);
private:
uInt16 address;
uInt8 value;
};
#endif

View File

@ -0,0 +1,13 @@
MODULE := src/cheat
MODULE_OBJS := \
src/cheat/CheatManager.o \
src/cheat/CheetahCheat.o \
src/cheat/BankRomCheat.o \
src/cheat/RamCheat.o
MODULE_DIRS += \
src/cheat
# Include common rules
include $(srcdir)/common.rules

View File

@ -1,59 +0,0 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Cheat.cxx,v 1.4 2005-09-26 19:10:37 stephena Exp $
//============================================================================
#include "Cheat.hxx"
#include "CheetahCheat.hxx"
#include "BankRomCheat.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 Cheat::unhex(string hex) {
int ret = 0;
for(unsigned int i=0; i<hex.size(); i++) {
char c = hex[i];
ret *= 16;
if(c >= '0' && c <= '9')
ret += c - '0';
else if(c >= 'A' && c <= 'F')
ret += c - 'A' + 10;
else
ret += c - 'a' + 10;
}
return ret;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cheat* Cheat::parse(OSystem *osystem, string code) {
for(unsigned int i=0; i<code.size(); i++)
if(!isxdigit(code[i]))
return 0;
switch(code.size()) {
case 7:
case 8:
return new BankRomCheat(osystem, code);
case 6:
return new CheetahCheat(osystem, code);
default:
return 0;
}
}

View File

@ -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: mainSDL.cxx,v 1.52 2005-10-27 19:15:14 stephena Exp $
// $Id: mainSDL.cxx,v 1.53 2005-11-11 21:44:19 stephena Exp $
//============================================================================
#include <fstream>
@ -63,6 +63,10 @@
#include "Debugger.hxx"
#endif
#ifdef CHEATCODE_SUPPORT
#include "CheatManager.hxx"
#endif
static void SetupProperties(PropertiesSet& set);
static void Cleanup();
@ -215,6 +219,17 @@ int main(int argc, char* argv[])
if(theOSystem->settings().getBool("holdbutton0"))
theOSystem->eventHandler().handleEvent(Event::JoystickZeroFire, 1);
#ifdef CHEATCODE_SUPPORT
// 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 cheats = theOSystem->settings().getString("cheat");
if(cheats != "")
{
theOSystem->cheat().parse(cheats);
theOSystem->settings().setString("cheat", "", false);
}
#endif
#ifdef DEVELOPER_SUPPORT
Debugger& dbg = theOSystem->debugger();
@ -228,15 +243,6 @@ int main(int argc, char* argv[])
theOSystem->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 = theOSystem->settings().getString("cheetah");
if(cheetah != "")
{
dbg.run("cheetah " + cheetah);
theOSystem->settings().setString("cheetah", "", false);
}
if(theOSystem->settings().getBool("debug"))
handler.enterDebugMode();
#endif

View File

@ -1,9 +1,6 @@
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 \

View File

@ -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.87 2005-10-27 19:15:14 stephena Exp $
// $Id: DebuggerParser.cxx,v 1.88 2005-11-11 21:44:19 stephena Exp $
//============================================================================
#include "bspf.hxx"
@ -25,10 +25,12 @@
#include "YaccParser.hxx"
#include "M6502.hxx"
#include "Expression.hxx"
#include "CheetahCheat.hxx"
#include "Cheat.hxx"
#include "RomWidget.hxx"
#ifdef CHEATCODE_SUPPORT
#include "CheatManager.hxx"
#endif
#include "DebuggerParser.hxx"
Command DebuggerParser::commands[] = {
@ -86,14 +88,16 @@ Command DebuggerParser::commands[] = {
&DebuggerParser::executeC
},
#ifdef CHEATCODE_SUPPORT
{
"cheetah",
"Use Cheetah cheat code (see http://members.cox.net/rcolbert/)",
"cheat",
"Use a cheat code (see Stella manual for cheat types)",
false,
false,
{ kARG_LABEL, kARG_END_ARGS },
&DebuggerParser::executeCheetah
&DebuggerParser::executeCheat
},
#endif
{
"clearbreaks",
@ -1386,9 +1390,10 @@ void DebuggerParser::executeC() {
debugger->cpuDebug().setC(args[0]);
}
// "cheetah"
// (see http://members.cox.net/rcolbert/chtdox.htm)
void DebuggerParser::executeCheetah() {
#ifdef CHEATCODE_SUPPORT
// "cheat"
// (see Stella manual for different cheat types)
void DebuggerParser::executeCheat() {
if(argCount == 0) {
commandResult = red("Missing cheat code");
return;
@ -1396,15 +1401,15 @@ void DebuggerParser::executeCheetah() {
for(int arg = 0; arg < argCount; arg++) {
string& cheat = argStrings[arg];
Cheat *c = Cheat::parse(debugger->getOSystem(), cheat);
if(c) {
c->enable();
commandResult = "Cheetah code " + cheat + " enabled\n";
const Cheat* c = debugger->getOSystem()->cheat().add("DBG", cheat);
if(c && c->enabled()) {
commandResult = "Cheat code " + cheat + " enabled\n";
} else {
commandResult = red("Invalid cheetah code " + cheat + "\n");
commandResult = red("Invalid cheat code " + cheat + "\n");
}
}
}
#endif
// "clearbreaks"
void DebuggerParser::executeClearbreaks() {

View File

@ -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.42 2005-09-15 19:43:36 stephena Exp $
// $Id: DebuggerParser.hxx,v 1.43 2005-11-11 21:44:19 stephena Exp $
//============================================================================
#ifndef DEBUGGER_PARSER_HXX
@ -106,7 +106,9 @@ class DebuggerParser
void executeBreak();
void executeBreakif();
void executeC();
void executeCheetah();
#ifdef CHEATCODE_SUPPORT
void executeCheat();
#endif
void executeClearbreaks();
void executeCleartraps();
void executeClearwatches();

View File

@ -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: EventHandler.cxx,v 1.109 2005-11-01 16:32:27 stephena Exp $
// $Id: EventHandler.cxx,v 1.110 2005-11-11 21:44:19 stephena Exp $
//============================================================================
#include <algorithm>
@ -43,6 +43,10 @@
#include "Snapshot.hxx"
#endif
#ifdef CHEATCODE_SUPPORT
#include "CheatManager.hxx"
#endif
#ifdef MAC_OSX
extern "C" {
void handleMacOSXKeypress(int key);
@ -747,6 +751,12 @@ void EventHandler::poll(uInt32 time)
// Used to implement continuous events
if(myOverlay)
myOverlay->updateTime(time);
#ifdef CHEATCODE_SUPPORT
const CheatList& cheats = myOSystem->cheat().perFrame();
for(unsigned int i = 0; i < cheats.size(); i++)
cheats[i]->evaluate();
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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: OSystem.cxx,v 1.43 2005-10-19 00:59:51 stephena Exp $
// $Id: OSystem.cxx,v 1.44 2005-11-11 21:44:19 stephena Exp $
//============================================================================
#include <cassert>
@ -47,6 +47,10 @@
#include "Debugger.hxx"
#endif
#ifdef CHEATCODE_SUPPORT
#include "CheatManager.hxx"
#endif
#include "unzip.h"
#include "MD5.hxx"
#include "FSNode.hxx"
@ -74,6 +78,7 @@ OSystem::OSystem()
myCommandMenu(NULL),
myLauncher(NULL),
myDebugger(NULL),
myCheatManager(NULL),
myRomFile(""),
myFeatures(""),
myFont(NULL),
@ -86,6 +91,9 @@ OSystem::OSystem()
#ifdef DEVELOPER_SUPPORT
myDebugger = new Debugger(this);
#endif
#ifdef CHEATCODE_SUPPORT
myCheatManager = new CheatManager(this);
#endif
// Create fonts to draw text
myFont = new GUI::Font(GUI::stellaDesc);
@ -107,6 +115,9 @@ OSystem::OSystem()
#ifdef DEVELOPER_SUPPORT
myFeatures += "Debugger";
#endif
#ifdef CHEATCODE_SUPPORT
myFeatures += "Cheats";
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -123,6 +134,9 @@ OSystem::~OSystem()
#ifdef DEVELOPER_SUPPORT
delete myDebugger;
#endif
#ifdef CHEATCODE_SUPPORT
delete myCheatManager;
#endif
// Remove any game console that is currently attached
delete myConsole;

View File

@ -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: OSystem.hxx,v 1.30 2005-10-19 00:59:51 stephena Exp $
// $Id: OSystem.hxx,v 1.31 2005-11-11 21:44:19 stephena Exp $
//============================================================================
#ifndef OSYSTEM_HXX
@ -25,6 +25,7 @@ class Menu;
class CommandMenu;
class Launcher;
class Debugger;
class CheatManager;
#include "EventHandler.hxx"
#include "FrameBuffer.hxx"
@ -43,7 +44,7 @@ class Debugger;
other objects belong.
@author Stephen Anthony
@version $Id: OSystem.hxx,v 1.30 2005-10-19 00:59:51 stephena Exp $
@version $Id: OSystem.hxx,v 1.31 2005-11-11 21:44:19 stephena Exp $
*/
class OSystem
{
@ -152,6 +153,15 @@ class OSystem
Debugger& debugger(void) const { return *myDebugger; }
#endif
#ifdef CHEATCODE_SUPPORT
/**
Get the cheat manager of the system.
@return The cheatmanager object
*/
CheatManager& cheat(void) const { return *myCheatManager; }
#endif
/**
Get the font object of the system
@ -369,6 +379,9 @@ class OSystem
// Pointer to the Debugger object
Debugger* myDebugger;
// Pointer to the CheatManager object
CheatManager* myCheatManager;
// Number of times per second to iterate through the main loop
uInt32 myDisplayFrameRate;

View File

@ -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: CheatCodeDialog.cxx,v 1.7 2005-09-30 00:40:34 stephena Exp $
// $Id: CheatCodeDialog.cxx,v 1.8 2005-11-11 21:44:19 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -80,18 +80,15 @@ void CheatCodeDialog::handleCommand(CommandSender* sender, int cmd,
{
case kEditAcceptCmd:
// cerr << myInput->getEditString() << endl;
myCheat = Cheat::parse(instance(), myInput->getEditString());
const Cheat* cheat =
instance()->cheat().add("DLG", myInput->getEditString(), true);
if(myCheat)
if(cheat)
{
// make sure "invalid code" isn't showing any more:
myError->setLabel("");
myErrorFlag = false;
// set up the cheat
myCheat->enable();
delete myCheat; // TODO: keep and add to list
// get out of menu mode (back to emulation):
Dialog::handleCommand(sender, kCloseCmd, data, id);
instance()->eventHandler().leaveMenuMode();

View File

@ -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: CheatCodeDialog.hxx,v 1.4 2005-09-30 00:40:34 stephena Exp $
// $Id: CheatCodeDialog.hxx,v 1.5 2005-11-11 21:44:19 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -30,7 +30,7 @@ class StaticTextWidget;
#include "OSystem.hxx"
#include "Dialog.hxx"
#include "Widget.hxx"
#include "Cheat.hxx"
#include "CheatManager.hxx"
#include "EditTextWidget.hxx"
#include "Props.hxx"
#include "bspf.hxx"
@ -47,8 +47,6 @@ class CheatCodeDialog : public Dialog
void loadConfig();
private:
Cheat* myCheat;
ButtonWidget* myExitButton;
StaticTextWidget* myTitle;
StaticTextWidget* myError;