My first stab at adding features to the GUI: Added shortcut keys for the

Inv, Neg, etc. buttons on the RAM tab. Also added Undo and Revert buttons
to the RAM tab. Undo undoes your last change only (and does not undo an
undo). Revert reverts RAM to the state it was in when the user entered
the RAM tab. These buttons are disabled when they're not useful.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@605 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
urchlay 2005-07-03 21:14:42 +00:00
parent a1fb0b5057
commit c4d5f9d54b
3 changed files with 126 additions and 20 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -28,6 +28,7 @@
#include "Debugger.hxx" #include "Debugger.hxx"
#include "FrameBuffer.hxx" #include "FrameBuffer.hxx"
#include "DataGridWidget.hxx" #include "DataGridWidget.hxx"
#include "RamWidget.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DataGridWidget::DataGridWidget(GuiObject* boss, int x, int y, int cols, int rows, 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(); _valueStringList.clear();
_changedList.clear(); _changedList.clear();
_addrList = alist; _addrList = alist;
_valueList = vlist; _valueList = vlist;
_changedList = changed; _changedList = changed;
// An efficiency thing // An efficiency thing
string temp; string temp;
@ -268,6 +269,61 @@ bool DataGridWidget::handleKeyDown(int ascii, int keycode, int modifiers)
default: default:
handled = false; 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) if (dirty)
@ -440,3 +496,4 @@ bool DataGridWidget::tryInsertChar(char c, int pos)
else else
return false; return false;
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -32,16 +32,6 @@
#include "RamWidget.hxx" #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) RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h)
: Widget(boss, x, y, w, 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; int lwidth = 30;
const int vWidth = _w - kButtonWidth - 20, space = 6, buttonw = 24; const int vWidth = _w - kButtonWidth - 20, space = 6, buttonw = 24;
const GUI::Font& font = instance()->consoleFont(); const GUI::Font& font = instance()->consoleFont();
_oldValueList = new ValueList;
// Create a 16x8 grid holding byte values (16 x 8 = 128 RAM bytes) with labels // 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); 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 = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "<<", kRShiftLCmd, 0);
b->setTarget(this); 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; xpos = vWidth + 30 + 10; ypos = 20;
// b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "", kRCmd, 0); // b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "", kRCmd, 0);
// b->setTarget(this); // b->setTarget(this);
@ -140,6 +141,7 @@ RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RamWidget::~RamWidget() RamWidget::~RamWidget()
{ {
delete _oldValueList;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -152,15 +154,22 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data)
unsigned char byte; unsigned char byte;
const char* buf; const char* buf;
Debugger& dbg = instance()->debugger();
switch(cmd) switch(cmd)
{ {
case kDGItemDataChangedCmd: case kDGItemDataChangedCmd:
addr = myRamGrid->getSelectedAddr(); addr = myRamGrid->getSelectedAddr();
value = myRamGrid->getSelectedValue(); value = myRamGrid->getSelectedValue();
myUndoAddress = addr;
myUndoValue = dbg.readRAM(addr - kRamStart);
instance()->debugger().writeRAM(addr - kRamStart, value); instance()->debugger().writeRAM(addr - kRamStart, value);
myDecValue->setEditString(instance()->debugger().valueToString(value, kBASE_10)); myDecValue->setEditString(instance()->debugger().valueToString(value, kBASE_10));
myBinValue->setEditString(instance()->debugger().valueToString(value, kBASE_2)); myBinValue->setEditString(instance()->debugger().valueToString(value, kBASE_2));
myRevertButton->setFlags(WIDGET_ENABLED);
myUndoButton->setFlags(WIDGET_ENABLED);
break; break;
case kDGSelectionChangedCmd: case kDGSelectionChangedCmd:
@ -214,6 +223,19 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data)
byte >>= 1; byte >>= 1;
myRamGrid->setSelectedValue((int)byte); myRamGrid->setSelectedValue((int)byte);
break; 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? // TODO - dirty rect, or is it necessary here?
@ -223,23 +245,31 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RamWidget::loadConfig() void RamWidget::loadConfig()
{ {
fillGrid(); fillGrid(true);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RamWidget::fillGrid() void RamWidget::fillGrid(bool updateOld)
{ {
AddrList alist; AddrList alist;
ValueList vlist; ValueList vlist;
BoolArray changed; BoolArray changed;
if(updateOld) _oldValueList->clear();
Debugger& dbg = instance()->debugger(); Debugger& dbg = instance()->debugger();
for(unsigned int i = 0; i < kRamSize; i++) for(unsigned int i = 0; i < kRamSize; i++)
{ {
alist.push_back(kRamStart + i); alist.push_back(kRamStart + i);
vlist.push_back(dbg.readRAM(i)); vlist.push_back(dbg.readRAM(i));
if(updateOld) _oldValueList->push_back(dbg.readRAM(i));
changed.push_back(dbg.ramChanged(i)); changed.push_back(dbg.ramChanged(i));
} }
myRamGrid->setList(alist, vlist, changed); myRamGrid->setList(alist, vlist, changed);
if(updateOld)
{
myRevertButton->clearFlags(WIDGET_ENABLED);
myUndoButton->clearFlags(WIDGET_ENABLED);
}
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -26,11 +26,23 @@ class GuiObject;
class ButtonWidget; class ButtonWidget;
class StaticTextWidget; class StaticTextWidget;
class EditTextWidget; class EditTextWidget;
class DataGridWidget;
#include "Array.hxx" #include "Array.hxx"
#include "Widget.hxx" #include "Widget.hxx"
#include "Command.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 class RamWidget : public Widget, public CommandSender
@ -45,15 +57,22 @@ class RamWidget : public Widget, public CommandSender
void loadConfig(); void loadConfig();
private: private:
void fillGrid(); void fillGrid(bool updateOld);
private: private:
int myUndoAddress;
int myUndoValue;
Widget* myActiveWidget; Widget* myActiveWidget;
DataGridWidget* myRamGrid; DataGridWidget* myRamGrid;
EditTextWidget* myBinValue; EditTextWidget* myBinValue;
EditTextWidget* myDecValue; EditTextWidget* myDecValue;
EditTextWidget* myLabel; EditTextWidget* myLabel;
ButtonWidget *myRevertButton;
ButtonWidget *myUndoButton;
ValueList *_oldValueList;
}; };
#endif #endif