diff --git a/stella/src/gui/DataGridWidget.cxx b/stella/src/gui/DataGridWidget.cxx index df75bca66..367f28e6e 100644 --- a/stella/src/gui/DataGridWidget.cxx +++ b/stella/src/gui/DataGridWidget.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: DataGridWidget.cxx,v 1.7 2005-07-03 00:53:59 stephena Exp $ +// $Id: DataGridWidget.cxx,v 1.8 2005-07-03 21:14:42 urchlay Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -28,6 +28,7 @@ #include "Debugger.hxx" #include "FrameBuffer.hxx" #include "DataGridWidget.hxx" +#include "RamWidget.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DataGridWidget::DataGridWidget(GuiObject* boss, int x, int y, int cols, int rows, @@ -76,9 +77,9 @@ void DataGridWidget::setList(const AddrList& alist, const ValueList& vlist, _valueStringList.clear(); _changedList.clear(); - _addrList = alist; - _valueList = vlist; - _changedList = changed; + _addrList = alist; + _valueList = vlist; + _changedList = changed; // An efficiency thing string temp; @@ -268,6 +269,61 @@ bool DataGridWidget::handleKeyDown(int ascii, int keycode, int modifiers) default: handled = false; } + + // handle ASCII codes if no keycodes matched. + // These really should only send commands if _selectedItem + // is a RamWidget, but other widgets may implement these + // commands someday (the CPU tab in particular should). + if(!handled) switch(ascii) { + case 'n': // negate + sendCommand(kRNegateCmd, _selectedItem); + dirty = true; + handled = true; + break; + + case 'i': // invert + case '!': + sendCommand(kRInvertCmd, _selectedItem); + dirty = true; + handled = true; + break; + + case '-': // decrement + sendCommand(kRDecCmd, _selectedItem); + dirty = true; + handled = true; + break; + + case '+': // increment + case '=': + sendCommand(kRIncCmd, _selectedItem); + dirty = true; + handled = true; + break; + + case '<': // shift left + case ',': + sendCommand(kRShiftLCmd, _selectedItem); + dirty = true; + handled = true; + break; + + case '>': // shift right + case '.': + sendCommand(kRShiftRCmd, _selectedItem); + dirty = true; + handled = true; + break; + + case 'z': // zero + sendCommand(kRZeroCmd, _selectedItem); + dirty = true; + handled = true; + break; + + default: + handled = false; + } } if (dirty) @@ -440,3 +496,4 @@ bool DataGridWidget::tryInsertChar(char c, int pos) else return false; } + diff --git a/stella/src/gui/RamWidget.cxx b/stella/src/gui/RamWidget.cxx index f528e5095..b9001caf9 100644 --- a/stella/src/gui/RamWidget.cxx +++ b/stella/src/gui/RamWidget.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: RamWidget.cxx,v 1.12 2005-07-03 00:53:59 stephena Exp $ +// $Id: RamWidget.cxx,v 1.13 2005-07-03 21:14:42 urchlay Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -32,16 +32,6 @@ #include "RamWidget.hxx" -enum { - kRZeroCmd = 'RWze', - kRInvertCmd = 'RWiv', - kRNegateCmd = 'RWng', - kRIncCmd = 'RWic', - kRDecCmd = 'RWdc', - kRShiftLCmd = 'RWls', - kRShiftRCmd = 'RWrs' -}; - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h) : Widget(boss, x, y, w, h), @@ -52,6 +42,7 @@ RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h) int lwidth = 30; const int vWidth = _w - kButtonWidth - 20, space = 6, buttonw = 24; const GUI::Font& font = instance()->consoleFont(); + _oldValueList = new ValueList; // Create a 16x8 grid holding byte values (16 x 8 = 128 RAM bytes) with labels myRamGrid = new DataGridWidget(boss, xpos+lwidth + 5, ypos, 16, 8, 2, 0xff, kBASE_16); @@ -120,6 +111,16 @@ RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h) b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "<<", kRShiftLCmd, 0); b->setTarget(this); + ypos += 16 + space; + // keep a pointer to this one, it gets disabled/enabled + myUndoButton = b = new ButtonWidget(boss, xpos, ypos, buttonw*2+10, 16, "Undo", kUndoCmd, 0); + b->setTarget(this); + + ypos += 16 + space; + // keep a pointer to this one, it gets disabled/enabled + myRevertButton = b = new ButtonWidget(boss, xpos, ypos, buttonw*2+10, 16, "Revert", kRevertCmd, 0); + b->setTarget(this); + xpos = vWidth + 30 + 10; ypos = 20; // b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "", kRCmd, 0); // b->setTarget(this); @@ -140,6 +141,7 @@ RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RamWidget::~RamWidget() { + delete _oldValueList; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -152,15 +154,22 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data) unsigned char byte; const char* buf; + Debugger& dbg = instance()->debugger(); + switch(cmd) { case kDGItemDataChangedCmd: addr = myRamGrid->getSelectedAddr(); value = myRamGrid->getSelectedValue(); + myUndoAddress = addr; + myUndoValue = dbg.readRAM(addr - kRamStart); + instance()->debugger().writeRAM(addr - kRamStart, value); myDecValue->setEditString(instance()->debugger().valueToString(value, kBASE_10)); myBinValue->setEditString(instance()->debugger().valueToString(value, kBASE_2)); + myRevertButton->setFlags(WIDGET_ENABLED); + myUndoButton->setFlags(WIDGET_ENABLED); break; case kDGSelectionChangedCmd: @@ -214,6 +223,19 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data) byte >>= 1; myRamGrid->setSelectedValue((int)byte); break; + + case kRevertCmd: + for(unsigned int i = 0; i < kRamSize; i++) + dbg.writeRAM(i, (*_oldValueList)[i]); + fillGrid(true); + break; + + case kUndoCmd: + dbg.writeRAM(myUndoAddress - kRamStart, myUndoValue); + myUndoButton->clearFlags(WIDGET_ENABLED); + fillGrid(false); + break; + } // TODO - dirty rect, or is it necessary here? @@ -223,23 +245,31 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void RamWidget::loadConfig() { - fillGrid(); + fillGrid(true); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void RamWidget::fillGrid() +void RamWidget::fillGrid(bool updateOld) { AddrList alist; ValueList vlist; BoolArray changed; + if(updateOld) _oldValueList->clear(); + Debugger& dbg = instance()->debugger(); for(unsigned int i = 0; i < kRamSize; i++) { alist.push_back(kRamStart + i); vlist.push_back(dbg.readRAM(i)); + if(updateOld) _oldValueList->push_back(dbg.readRAM(i)); changed.push_back(dbg.ramChanged(i)); } myRamGrid->setList(alist, vlist, changed); + if(updateOld) + { + myRevertButton->clearFlags(WIDGET_ENABLED); + myUndoButton->clearFlags(WIDGET_ENABLED); + } } diff --git a/stella/src/gui/RamWidget.hxx b/stella/src/gui/RamWidget.hxx index e62851f5d..c5c34ab89 100644 --- a/stella/src/gui/RamWidget.hxx +++ b/stella/src/gui/RamWidget.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: RamWidget.hxx,v 1.4 2005-06-22 18:30:44 stephena Exp $ +// $Id: RamWidget.hxx,v 1.5 2005-07-03 21:14:42 urchlay Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -26,11 +26,23 @@ class GuiObject; class ButtonWidget; class StaticTextWidget; class EditTextWidget; -class DataGridWidget; #include "Array.hxx" #include "Widget.hxx" #include "Command.hxx" +#include "DataGridWidget.hxx" + +enum { + kRZeroCmd = 'RWze', + kRInvertCmd = 'RWiv', + kRNegateCmd = 'RWng', + kRIncCmd = 'RWic', + kRDecCmd = 'RWdc', + kRShiftLCmd = 'RWls', + kRShiftRCmd = 'RWrs', + kUndoCmd = 'RWud', + kRevertCmd = 'RWrv' +}; class RamWidget : public Widget, public CommandSender @@ -45,15 +57,22 @@ class RamWidget : public Widget, public CommandSender void loadConfig(); private: - void fillGrid(); + void fillGrid(bool updateOld); private: + int myUndoAddress; + int myUndoValue; + Widget* myActiveWidget; DataGridWidget* myRamGrid; EditTextWidget* myBinValue; EditTextWidget* myDecValue; EditTextWidget* myLabel; + ButtonWidget *myRevertButton; + ButtonWidget *myUndoButton; + + ValueList *_oldValueList; }; #endif