diff --git a/stella/src/gui/CpuWidget.cxx b/stella/src/gui/CpuWidget.cxx index 9d53fbbc8..8a74bed14 100644 --- a/stella/src/gui/CpuWidget.cxx +++ b/stella/src/gui/CpuWidget.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: CpuWidget.cxx,v 1.10 2005-07-05 15:25:44 stephena Exp $ +// $Id: CpuWidget.cxx,v 1.11 2005-07-05 18:00:05 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -62,7 +62,7 @@ CpuWidget::CpuWidget(GuiObject* boss, int x, int y, int w, int h) const GUI::Font& font = instance()->consoleFont(); // Create a 1x5 grid with labels for the CPU registers - myCpuGrid = new DataGridWidget(boss, xpos+lwidth + 5, ypos, 1, 5, 8, 0xffff); + myCpuGrid = new DataGridWidget(boss, xpos+lwidth + 5, ypos, 1, 5, 8, 16); myCpuGrid->setTarget(this); myActiveWidget = myCpuGrid; diff --git a/stella/src/gui/DataGridWidget.cxx b/stella/src/gui/DataGridWidget.cxx index 178ec07ae..9e9aa3b8d 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.11 2005-07-05 15:25:44 stephena Exp $ +// $Id: DataGridWidget.cxx,v 1.12 2005-07-05 18:00:05 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -32,7 +32,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DataGridWidget::DataGridWidget(GuiObject* boss, int x, int y, int cols, int rows, - int colchars, int range, BaseFormat base) + int colchars, int bits, BaseFormat base) : EditableWidget(boss, x, y, cols*(colchars * 6 + 8) + 1, kLineHeight*rows + 1), CommandSender(boss), _rows(rows), @@ -40,7 +40,7 @@ DataGridWidget::DataGridWidget(GuiObject* boss, int x, int y, int cols, int rows _currentRow(0), _currentCol(0), _colWidth(colchars * 6 + 8), - _range(range), + _bits(bits), _base(base), _selectedItem(0) { @@ -290,59 +290,43 @@ bool DataGridWidget::handleKeyDown(int ascii, int keycode, int modifiers) } break; - 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, _id); + negateCell(); dirty = true; - handled = true; break; case 'i': // invert case '!': - sendCommand(kRInvertCmd, _selectedItem, _id); + invertCell(); dirty = true; - handled = true; break; case '-': // decrement - sendCommand(kRDecCmd, _selectedItem, _id); + decrementCell(); dirty = true; - handled = true; break; case '+': // increment case '=': - sendCommand(kRIncCmd, _selectedItem, _id); + incrementCell(); dirty = true; - handled = true; break; case '<': // shift left case ',': - sendCommand(kRShiftLCmd, _selectedItem, _id); + lshiftCell(); dirty = true; - handled = true; break; case '>': // shift right case '.': - sendCommand(kRShiftRCmd, _selectedItem, _id); + rshiftCell(); dirty = true; - handled = true; break; case 'z': // zero - sendCommand(kRZeroCmd, _selectedItem, _id); + zeroCell(); dirty = true; - handled = true; break; default: @@ -352,12 +336,14 @@ bool DataGridWidget::handleKeyDown(int ascii, int keycode, int modifiers) if (dirty) { + int oldItem = _selectedItem; _selectedItem = _currentRow*_cols + _currentCol; draw(); - sendCommand(kDGSelectionChangedCmd, _selectedItem, _id); - // TODO - dirty rectangle instance()->frameBuffer().refreshOverlay(); + + if(_selectedItem != oldItem) + sendCommand(kDGSelectionChangedCmd, _selectedItem, _id); } _currentKeyDown = keycode; @@ -392,6 +378,34 @@ void DataGridWidget::handleCommand(CommandSender* sender, int cmd, draw(); } break; + + case kDGZeroCmd: + zeroCell(); + break; + + case kDGInvertCmd: + invertCell(); + break; + + case kDGNegateCmd: + negateCell(); + break; + + case kDGIncCmd: + incrementCell(); + break; + + case kDGDecCmd: + decrementCell(); + break; + + case kDGShiftLCmd: + lshiftCell(); + break; + + case kDGShiftRCmd: + rshiftCell(); + break; } } @@ -494,7 +508,7 @@ void DataGridWidget::endEditMode() // Update the both the string representation and the real data int value = instance()->debugger().stringToValue(_editString); - if(value < 0 || value > _range) + if(value < 0 || value > (1 << _bits)) { abortEditMode(); return; @@ -526,3 +540,68 @@ bool DataGridWidget::tryInsertChar(char c, int pos) return false; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void DataGridWidget::negateCell() +{ + int mask = (1 << _bits) - 1; + int value = getSelectedValue(); + + value = ((~value) + 1) & mask; + setSelectedValue(value); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void DataGridWidget::invertCell() +{ + int mask = (1 << _bits) - 1; + int value = getSelectedValue(); + + value = ~value & mask; + setSelectedValue(value); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void DataGridWidget::decrementCell() +{ + int mask = (1 << _bits) - 1; + int value = getSelectedValue(); + + value = (value - 1) & mask; + setSelectedValue(value); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void DataGridWidget::incrementCell() +{ + int mask = (1 << _bits) - 1; + int value = getSelectedValue(); + + value = (value + 1) & mask; + setSelectedValue(value); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void DataGridWidget::lshiftCell() +{ + int mask = (1 << _bits) - 1; + int value = getSelectedValue(); + + value = (value << 1) & mask; + setSelectedValue(value); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void DataGridWidget::rshiftCell() +{ + int mask = (1 << _bits) - 1; + int value = getSelectedValue(); + + value = (value >> 1) & mask; + setSelectedValue(value); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void DataGridWidget::zeroCell() +{ + setSelectedValue(0); +} diff --git a/stella/src/gui/DataGridWidget.hxx b/stella/src/gui/DataGridWidget.hxx index 85bf01db6..0065ed35e 100644 --- a/stella/src/gui/DataGridWidget.hxx +++ b/stella/src/gui/DataGridWidget.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: DataGridWidget.hxx,v 1.6 2005-07-05 15:25:44 stephena Exp $ +// $Id: DataGridWidget.hxx,v 1.7 2005-07-05 18:00:05 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -36,10 +36,18 @@ typedef GUI::Array ValueList; // Some special commands enum { - kDGItemDoubleClickedCmd = 'BGdb', - kDGItemActivatedCmd = 'BGac', - kDGItemDataChangedCmd = 'BGch', - kDGSelectionChangedCmd = 'BGsc' + kDGItemDoubleClickedCmd = 'DGdb', + kDGItemActivatedCmd = 'DGac', + kDGItemDataChangedCmd = 'DGch', + kDGSelectionChangedCmd = 'DGsc', + + kDGZeroCmd = 'DGze', + kDGInvertCmd = 'DGiv', + kDGNegateCmd = 'DGng', + kDGIncCmd = 'DGic', + kDGDecCmd = 'DGdc', + kDGShiftLCmd = 'DGls', + kDGShiftRCmd = 'DGrs' }; /* DataGridWidget */ @@ -47,7 +55,7 @@ class DataGridWidget : public EditableWidget, public CommandSender { public: DataGridWidget(GuiObject* boss, int x, int y, int cols, int rows, - int colchars, int range, BaseFormat format = kBASE_DEFAULT); + int colchars, int bits, BaseFormat format = kBASE_DEFAULT); virtual ~DataGridWidget(); void setList(const AddrList& alist, const ValueList& vlist, @@ -70,6 +78,15 @@ class DataGridWidget : public EditableWidget, public CommandSender int colWidth() { return _colWidth; } + //* Common operations on the currently selected cell */ + void negateCell(); + void invertCell(); + void decrementCell(); + void incrementCell(); + void lshiftCell(); + void rshiftCell(); + void zeroCell(); + protected: void drawWidget(bool hilite); @@ -89,7 +106,7 @@ class DataGridWidget : public EditableWidget, public CommandSender int _currentRow; int _currentCol; int _colWidth; - int _range; + int _bits; BaseFormat _base; diff --git a/stella/src/gui/RamWidget.cxx b/stella/src/gui/RamWidget.cxx index 416d9332a..5fb07e1f6 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.14 2005-07-05 15:25:44 stephena Exp $ +// $Id: RamWidget.cxx,v 1.15 2005-07-05 18:00:05 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -45,7 +45,7 @@ RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h) _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); + myRamGrid = new DataGridWidget(boss, xpos+lwidth + 5, ypos, 16, 8, 2, 8, kBASE_16); myRamGrid->setTarget(this); myRamGrid->clearFlags(WIDGET_TAB_NAVIGATE); myActiveWidget = myRamGrid; @@ -96,20 +96,20 @@ RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h) // Add some buttons for common actions ButtonWidget* b; xpos = vWidth + 10; ypos = 20; - b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "0", kRZeroCmd, 0); - b->setTarget(this); + b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "0", kDGZeroCmd, 0); + b->setTarget(myRamGrid); ypos += 16 + space; - b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "Inv", kRInvertCmd, 0); - b->setTarget(this); + b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "Inv", kDGInvertCmd, 0); + b->setTarget(myRamGrid); ypos += 16 + space; - b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "++", kRIncCmd, 0); - b->setTarget(this); + b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "++", kDGIncCmd, 0); + b->setTarget(myRamGrid); ypos += 16 + space; - b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "<<", kRShiftLCmd, 0); - b->setTarget(this); + b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "<<", kDGShiftLCmd, 0); + b->setTarget(myRamGrid); ypos += 16 + space; // keep a pointer to this one, it gets disabled/enabled @@ -126,16 +126,16 @@ RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h) // b->setTarget(this); ypos += 16 + space; - b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "Neg", kRNegateCmd, 0); - b->setTarget(this); + b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "Neg", kDGNegateCmd, 0); + b->setTarget(myRamGrid); ypos += 16 + space; - b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "--", kRDecCmd, 0); - b->setTarget(this); + b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, "--", kDGDecCmd, 0); + b->setTarget(myRamGrid); ypos += 16 + space; - b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, ">>", kRShiftRCmd, 0); - b->setTarget(this); + b = new ButtonWidget(boss, xpos, ypos, buttonw, 16, ">>", kDGShiftRCmd, 0); + b->setTarget(myRamGrid); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -151,7 +151,6 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) // It will then send the 'kDGItemDataChangedCmd' signal to change the actual // memory location int addr, value; - unsigned char byte; const char* buf; Debugger& dbg = instance()->debugger(); @@ -184,46 +183,6 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) myBinValue->setEditString(instance()->debugger().valueToString(value, kBASE_2)); break; - case kRZeroCmd: - myRamGrid->setSelectedValue(0); - break; - - case kRInvertCmd: - byte = (unsigned char) myRamGrid->getSelectedValue(); - byte = ~byte; - myRamGrid->setSelectedValue((int)byte); - break; - - case kRNegateCmd: - byte = (unsigned char) myRamGrid->getSelectedValue(); - byte = (~byte) + 1; - myRamGrid->setSelectedValue((int)byte); - break; - - case kRIncCmd: - byte = (unsigned char) myRamGrid->getSelectedValue(); - byte += 1; - myRamGrid->setSelectedValue((int)byte); - break; - - case kRDecCmd: - byte = (unsigned char) myRamGrid->getSelectedValue(); - byte -= 1; - myRamGrid->setSelectedValue((int)byte); - break; - - case kRShiftLCmd: - byte = (unsigned char) myRamGrid->getSelectedValue(); - byte <<= 1; - myRamGrid->setSelectedValue((int)byte); - break; - - case kRShiftRCmd: - byte = (unsigned char) myRamGrid->getSelectedValue(); - byte >>= 1; - myRamGrid->setSelectedValue((int)byte); - break; - case kRevertCmd: for(unsigned int i = 0; i < kRamSize; i++) dbg.writeRAM(i, (*_oldValueList)[i]); @@ -232,7 +191,7 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) case kUndoCmd: dbg.writeRAM(myUndoAddress - kRamStart, myUndoValue); - myUndoButton->clearFlags(WIDGET_ENABLED); + myUndoButton->setEnabled(false); fillGrid(false); break; @@ -269,7 +228,7 @@ void RamWidget::fillGrid(bool updateOld) myRamGrid->setList(alist, vlist, changed); if(updateOld) { - myRevertButton->clearFlags(WIDGET_ENABLED); - myUndoButton->clearFlags(WIDGET_ENABLED); + myRevertButton->setEnabled(false); + myUndoButton->setEnabled(false); } } diff --git a/stella/src/gui/RamWidget.hxx b/stella/src/gui/RamWidget.hxx index 24c8b5cf3..c3e4d0cb9 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.6 2005-07-05 15:25:44 stephena Exp $ +// $Id: RamWidget.hxx,v 1.7 2005-07-05 18:00:05 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -33,13 +33,6 @@ class EditTextWidget; #include "DataGridWidget.hxx" enum { - kRZeroCmd = 'RWze', - kRInvertCmd = 'RWiv', - kRNegateCmd = 'RWng', - kRIncCmd = 'RWic', - kRDecCmd = 'RWdc', - kRShiftLCmd = 'RWls', - kRShiftRCmd = 'RWrs', kUndoCmd = 'RWud', kRevertCmd = 'RWrv' };