diff --git a/stella/src/common/BankRomCheat.cxx b/stella/src/common/BankRomCheat.cxx index 22dd0dcf5..9d96f25c3 100644 --- a/stella/src/common/BankRomCheat.cxx +++ b/stella/src/common/BankRomCheat.cxx @@ -1,43 +1,74 @@ +//============================================================================ +// +// 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: BankRomCheat.cxx,v 1.2 2005-09-26 19:10:37 stephena Exp $ +//============================================================================ -// 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; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +BankRomCheat::BankRomCheat(OSystem *os, string code) +{ + myOSystem = os; + _enabled = false; - if(code.length() == 7) - code = "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(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() { +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +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::enabled() +{ + return _enabled; } -bool BankRomCheat::disable() { - int oldBank = myOSystem->console().cartridge().bank(); - myOSystem->console().cartridge().bank(bank); - for(int i=0; iconsole().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; + + myOSystem->console().cartridge().bank(oldBank); + + return _enabled = false; } diff --git a/stella/src/common/Cheat.cxx b/stella/src/common/Cheat.cxx index b9be6ebbf..0a39254ca 100644 --- a/stella/src/common/Cheat.cxx +++ b/stella/src/common/Cheat.cxx @@ -1,8 +1,26 @@ +//============================================================================ +// +// 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; @@ -21,6 +39,7 @@ uInt16 Cheat::unhex(string hex) { return ret; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cheat* Cheat::parse(OSystem *osystem, string code) { for(unsigned int i=0; iconsole().cartridge().peek(address + i); - myOSystem->console().cartridge().patch(address + i, value); - } - return _enabled = true; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CheetahCheat::enabled() +{ + return _enabled; } -bool CheetahCheat::disable() { - for(int i=0; iconsole().cartridge().patch(address + i, savedRom[i]); - } - return _enabled = false; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CheetahCheat::enable() +{ + for(int i=0; iconsole().cartridge().peek(address + i); + myOSystem->console().cartridge().patch(address + i, value); + } + + return _enabled = true; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CheetahCheat::disable() +{ + for(int i=0; iconsole().cartridge().patch(address + i, savedRom[i]); + + return _enabled = false; } diff --git a/stella/src/common/CheetahCheat.hxx b/stella/src/common/CheetahCheat.hxx index 13c9d47cc..de2dd4393 100644 --- a/stella/src/common/CheetahCheat.hxx +++ b/stella/src/common/CheetahCheat.hxx @@ -1,3 +1,20 @@ +//============================================================================ +// +// 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: CheetahCheat.hxx,v 1.3 2005-09-26 19:10:37 stephena Exp $ +//============================================================================ #ifndef CHEETAH_CHEAT_HXX #define CHEETAH_CHEAT_HXX @@ -5,23 +22,24 @@ #include "OSystem.hxx" #include "Cheat.hxx" -class CheetahCheat : public Cheat { - public: - CheetahCheat(OSystem *os, string code); - ~CheetahCheat(); +class CheetahCheat : public Cheat +{ + public: + CheetahCheat(OSystem *os, string code); + ~CheetahCheat(); - virtual bool enabled(); - virtual bool enable(); - virtual bool disable(); + virtual bool enabled(); + virtual bool enable(); + virtual bool disable(); + private: + OSystem* myOSystem; - private: - bool _enabled; - uInt8 savedRom[16]; - uInt16 address; - uInt8 value; - uInt8 count; - OSystem *myOSystem; + bool _enabled; + uInt8 savedRom[16]; + uInt16 address; + uInt8 value; + uInt8 count; }; #endif diff --git a/stella/src/gui/CheatCodeDialog.cxx b/stella/src/gui/CheatCodeDialog.cxx index 754233de4..1d5f0cafc 100644 --- a/stella/src/gui/CheatCodeDialog.cxx +++ b/stella/src/gui/CheatCodeDialog.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: CheatCodeDialog.cxx,v 1.5 2005-09-25 23:14:00 urchlay Exp $ +// $Id: CheatCodeDialog.cxx,v 1.6 2005-09-26 19:10:37 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -28,23 +28,36 @@ #include "bspf.hxx" +/* enum { - kEnableCheat = 'ENAC', - kLoadCmd = 'LDCH', + kEnableCheat = 'ENAC', + kLoadCmd = 'LDCH' }; +*/ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CheatCodeDialog::CheatCodeDialog(OSystem* osystem, DialogContainer* parent, int x, int y, int w, int h) - : Dialog(osystem, parent, x, y, w, h) + : Dialog(osystem, parent, x, y, w, h) { - // const GUI::Font& font = instance()->font(); + const GUI::Font& font = instance()->font(); + const int fontHeight = font.getFontHeight(), + lwidth = font.getMaxCharWidth() * 8; + int xpos, ypos; - myTitle = new StaticTextWidget(this, 10, 5, w - 20, kFontHeight, "Cheat Code", kTextAlignLeft); - myError = new StaticTextWidget(this, 10, 5 + kFontHeight + 2, w - 20, kFontHeight, "Invalid Code", kTextAlignLeft); - myError->setFlags(WIDGET_INVISIBLE); - myInput = new EditTextWidget(this, 80, 5, 48, kFontHeight, ""); + xpos = 10; ypos = 10; + myTitle = new StaticTextWidget(this, xpos, ypos, lwidth, fontHeight, + "Cheat Code", kTextAlignLeft); + + xpos += myTitle->getWidth(); + myInput = new EditTextWidget(this, xpos, ypos-1, 48, fontHeight, ""); addFocusWidget(myInput); + + xpos = 10; ypos += fontHeight + 5; + myError = new StaticTextWidget(this, xpos, ypos, lwidth, kFontHeight, + "", kTextAlignLeft); + myError->setColor(kTextColorEm); + // addButton(w - (kButtonWidth + 10), 5, "Close", kCloseCmd, 'C'); } @@ -54,54 +67,53 @@ CheatCodeDialog::~CheatCodeDialog() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatCodeDialog::handleCommand(CommandSender* sender, int cmd, - int data, int id) +void CheatCodeDialog::loadConfig() { - switch(cmd) - { - case kEditAcceptCmd: - // cerr << myInput->getEditString() << endl; - myCheat = Cheat::parse(instance(), myInput->getEditString()); - - if(myCheat) { - // make sure "invalid code" isn't showing any more: - myError->setFlags(WIDGET_INVISIBLE); - myError->setDirty(); - myError->draw(); - - // 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(); - - } else { // parse() returned 0 (null) - // cerr << "bad cheat code" << endl; - - // show error message "invalid code": - myInput->setEditString(""); - myError->clearFlags(WIDGET_INVISIBLE); - myError->setDirty(); - myError->draw(); - - // not sure this does anything useful: - Dialog::handleCommand(sender, cmd, data, 0); - } - break; - - case kEditCancelCmd: - Dialog::handleCommand(sender, kCloseCmd, data, id); - instance()->eventHandler().leaveMenuMode(); - break; - - default: - Dialog::handleCommand(sender, cmd, data, 0); - break; - } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheatCodeDialog::loadConfig() { +void CheatCodeDialog::handleCommand(CommandSender* sender, int cmd, + int data, int id) +{ + switch(cmd) + { + case kEditAcceptCmd: + // cerr << myInput->getEditString() << endl; + myCheat = Cheat::parse(instance(), myInput->getEditString()); + + if(myCheat) + { + // make sure "invalid code" isn't showing any more: + myError->setLabel(""); + + // 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(); + } + else // parse() returned 0 (null) + { + // cerr << "bad cheat code" << endl; + + // show error message "invalid code": + myInput->setEditString(""); + myError->setLabel("Invalid Code"); + + // not sure this does anything useful: + Dialog::handleCommand(sender, cmd, data, 0); + } + break; + + case kEditCancelCmd: + Dialog::handleCommand(sender, kCloseCmd, data, id); + instance()->eventHandler().leaveMenuMode(); + break; + + default: + Dialog::handleCommand(sender, cmd, data, 0); + break; + } } diff --git a/stella/src/gui/CheatCodeDialog.hxx b/stella/src/gui/CheatCodeDialog.hxx index b70dab622..8de1f5e3c 100644 --- a/stella/src/gui/CheatCodeDialog.hxx +++ b/stella/src/gui/CheatCodeDialog.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: CheatCodeDialog.hxx,v 1.2 2005-09-25 18:35:26 urchlay Exp $ +// $Id: CheatCodeDialog.hxx,v 1.3 2005-09-26 19:10:37 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -42,18 +42,18 @@ class CheatCodeDialog : public Dialog int x, int y, int w, int h); ~CheatCodeDialog(); - protected: - ButtonWidget *myExitButton; - StaticTextWidget *myTitle; - StaticTextWidget *myError; - // CheckboxWidget *myEnableCheat; + virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); + void loadConfig(); private: - virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); - void loadConfig(); - Cheat *myCheat; - EditTextWidget *myInput; + Cheat* myCheat; + + ButtonWidget* myExitButton; + StaticTextWidget* myTitle; + StaticTextWidget* myError; + EditTextWidget* myInput; + // CheckboxWidget* myEnableCheat; }; #endif diff --git a/stella/src/gui/InputTextDialog.cxx b/stella/src/gui/InputTextDialog.cxx index 8549bde44..afaff6aac 100644 --- a/stella/src/gui/InputTextDialog.cxx +++ b/stella/src/gui/InputTextDialog.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: InputTextDialog.cxx,v 1.4 2005-08-11 19:12:39 stephena Exp $ +// $Id: InputTextDialog.cxx,v 1.5 2005-09-26 19:10:37 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -46,7 +46,7 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font, // Calculate real dimensions _w = fontWidth * 30; - _h = lineHeight * 6; + _h = lineHeight * 5; xpos = 10; ypos = lineHeight; int lwidth = font.getStringWidth("Enter Data:"); @@ -62,9 +62,11 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font, _input->setFont(font); addFocusWidget(_input); - xpos = 10; ypos = 2*lineHeight; + xpos = 10; ypos = 2*lineHeight + 5; _title = new StaticTextWidget(this, xpos, ypos, _w - 2*xpos, fontHeight, "", kTextAlignCenter); + _title->setFont(font); + _title->setColor(kTextColorEm); #ifndef MAC_OSX addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "OK", kAcceptCmd, 0); diff --git a/stella/src/gui/OptionsDialog.cxx b/stella/src/gui/OptionsDialog.cxx index 243ce45ca..3d2205d4c 100644 --- a/stella/src/gui/OptionsDialog.cxx +++ b/stella/src/gui/OptionsDialog.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: OptionsDialog.cxx,v 1.28 2005-09-25 23:14:00 urchlay Exp $ +// $Id: OptionsDialog.cxx,v 1.29 2005-09-26 19:10:37 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -71,19 +71,17 @@ OptionsDialog::OptionsDialog(OSystem* osystem, DialogContainer* parent) { int yoffset = 7; const int xoffset = (_w - kBigButtonWidth) / 2; - ButtonWidget* b = NULL; addBigButton("Video Settings", kVidCmd, 0); #ifdef SOUND_SUPPORT addBigButton("Audio Settings", kAudCmd, 0); #else - b = addBigButton("Audio Settings", kAudCmd, 0); + ButtonWidget* b = addBigButton("Audio Settings", kAudCmd, 0); b->clearFlags(WIDGET_ENABLED); #endif addBigButton("Event Mapping", kEMapCmd, 0); addBigButton("Game Information", kInfoCmd, 0); - b = addBigButton("Cheat Code", kCheatCmd, 0); - // b->clearFlags(WIDGET_ENABLED); // TODO - finish after next release + addBigButton("Cheat Code", kCheatCmd, 0); addBigButton("Help", kHelpCmd, 0); addBigButton("About", kAboutCmd, 0); addBigButton("Exit Menu", kExitCmd, 0); @@ -110,7 +108,7 @@ OptionsDialog::OptionsDialog(OSystem* osystem, DialogContainer* parent) checkBounds(fbWidth, fbHeight, &x, &y, &w, &h); myGameInfoDialog = new GameInfoDialog(myOSystem, parent, x, y, w, h); - w = 140; h = 35; + w = 140; h = 40; checkBounds(fbWidth, fbHeight, &x, &y, &w, &h); myCheatCodeDialog = new CheatCodeDialog(myOSystem, parent, x, y, w, h);