diff --git a/stella/src/build/makefile b/stella/src/build/makefile index 311358530..23da1d25e 100644 --- a/stella/src/build/makefile +++ b/stella/src/build/makefile @@ -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: makefile,v 1.100 2005-06-16 12:28:53 stephena Exp $ +## $Id: makefile,v 1.101 2005-06-16 18:40:16 stephena Exp $ ##============================================================================ ##============================================================================ @@ -158,11 +158,12 @@ M6502_OBJS = D6502.o Device.o M6502.o M6502Low.o M6502Hi.o NullDev.o System.o GUI_OBJS = Font.o Menu.o Launcher.o \ Widget.o PopUpWidget.o ScrollBarWidget.o ListWidget.o TabWidget.o \ EditableWidget.o EditTextWidget.o EditNumWidget.o AddrValueWidget.o \ + ByteGridWidget.o \ Dialog.o DialogContainer.o OptionsDialog.o VideoDialog.o AudioDialog.o \ EventMappingDialog.o GameInfoDialog.o HelpDialog.o AboutDialog.o \ LauncherDialog.o LauncherOptionsDialog.o BrowserDialog.o GameList.o \ ProgressDialog.o \ - DebuggerDialog.o PromptWidget.o CheatWidget.o + DebuggerDialog.o PromptWidget.o CheatWidget.o RamWidget.o DBG_OBJS = Debugger.o DebuggerParser.o EquateList.o PackedBitArray.o @@ -420,6 +421,9 @@ EditNumWidget.o: $(GUI)/EditNumWidget.cxx $(GUI)/EditNumWidget.hxx AddrValueWidget.o: $(GUI)/AddrValueWidget.cxx $(GUI)/AddrValueWidget.hxx $(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/AddrValueWidget.cxx +ByteGridWidget.o: $(GUI)/ByteGridWidget.cxx $(GUI)/ByteGridWidget.hxx + $(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/ByteGridWidget.cxx + Dialog.o: $(GUI)/Dialog.cxx $(GUI)/Dialog.hxx $(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/Dialog.cxx @@ -471,6 +475,9 @@ PromptWidget.o: $(GUI)/PromptWidget.cxx $(GUI)/PromptWidget.hxx CheatWidget.o: $(GUI)/CheatWidget.cxx $(GUI)/CheatWidget.hxx $(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/CheatWidget.cxx +RamWidget.o: $(GUI)/RamWidget.cxx $(GUI)/RamWidget.hxx + $(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/RamWidget.cxx + Debugger.o: $(DBG)/Debugger.cxx $(DBG)/Debugger.hxx $(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(DBG)/Debugger.cxx diff --git a/stella/src/gui/ByteGridWidget.cxx b/stella/src/gui/ByteGridWidget.cxx new file mode 100644 index 000000000..505187cf1 --- /dev/null +++ b/stella/src/gui/ByteGridWidget.cxx @@ -0,0 +1,463 @@ +//============================================================================ +// +// 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: ByteGridWidget.cxx,v 1.1 2005-06-16 18:40:17 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#include +#include + +#include "OSystem.hxx" +#include "Widget.hxx" +#include "Dialog.hxx" +#include "FrameBuffer.hxx" +#include "ByteGridWidget.hxx" + +enum { + kColWidth = 2 * 6 + 4 // FIXME - get this info from _font +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +ByteGridWidget::ByteGridWidget(GuiObject* boss, int x, int y, int w, int h, + int cols, int rows) + : EditableWidget(boss, x, y, w, h), + CommandSender(boss), + _rows(rows), + _cols(cols), + _currentRow(0), + _currentCol(0), + _selectedItem(0) +{ + _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | + WIDGET_TAB_NAVIGATE; + _type = kByteGridWidget; + _editMode = false; + + _entriesPerPage = _rows;//(_h - 2) / kLineHeight; + _currentPos = 0; + _currentKeyDown = 0; + + _quickSelectTime = 0; + + // The item is selected, thus _bgcolor is used to draw the caret and + // _textcolorhi to erase it + _caretInverse = true; + + // FIXME: This flag should come from widget definition + _editable = true; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +ByteGridWidget::~ByteGridWidget() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ByteGridWidget::setList(const ByteAddrList& alist, const ByteValueList& vlist) +{ + _addrList.clear(); + _valueList.clear(); + _addrStringList.clear(); + _valueStringList.clear(); + + _addrList = alist; + _valueList = vlist; + + int size = _addrList.size(); // assume vlist is the same size +//FIXME assert(size != _rows * _cols); + + // An efficiency thing + char temp[10]; + for(unsigned int i = 0; i < (unsigned int)size; ++i) + { + sprintf(temp, "%.2x", _valueList[i]); + _valueStringList.push_back(temp); + } + + if (_currentPos >= size) + _currentPos = size - 1; + if (_currentPos < 0) + _currentPos = 0; + _selectedItem = 0; + _currentRow = 0; + _currentCol = 0; + _editMode = false; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ByteGridWidget::handleMouseDown(int x, int y, int button, int clickCount) +{ + if (!isEnabled()) + return; + + // A click indicates this widget has been selected + // It should receive focus (because it has the WIDGET_TAB_NAVIGATE property) + receivedFocus(); + + // First check whether the selection changed + int newSelectedItem; + newSelectedItem = findItem(x, y); + if (newSelectedItem > (int)_valueList.size() - 1) + newSelectedItem = -1; + + if (_selectedItem != newSelectedItem) + { + if (_editMode) + abortEditMode(); + + _selectedItem = newSelectedItem; + _currentRow = _selectedItem / _cols; + _currentCol = _selectedItem - (_currentRow * _cols); + + sendCommand(kBGSelectionChangedCmd, _selectedItem); + instance()->frameBuffer().refresh(); + } + + // TODO: Determine where inside the string the user clicked and place the + // caret accordingly. See _editScrollOffset and EditTextWidget::handleMouseDown. + draw(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ByteGridWidget::handleMouseUp(int x, int y, int button, int clickCount) +{ + // If this was a double click and the mouse is still over the selected item, + // send the double click command + if (clickCount == 2 && (_selectedItem == findItem(x, y))) + { + sendCommand(kBGItemDoubleClickedCmd, _selectedItem); + + // Start edit mode + if(_editable && !_editMode) + startEditMode(); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +int ByteGridWidget::findItem(int x, int y) +{ + int row = (y - 1) / kLineHeight; + if(row >= _rows) row = _rows - 1; + + int col = x / kColWidth; + if(col >= _cols) col = _cols - 1; + + return row * _cols + col; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool ByteGridWidget::handleKeyDown(int ascii, int keycode, int modifiers) +{ + // Ignore all mod keys + if(instance()->eventHandler().kbdControl(modifiers) || + instance()->eventHandler().kbdAlt(modifiers)) + return true; + + bool handled = true; + bool dirty = false; + + if (_editMode) + { + // Class EditableWidget handles all text editing related key presses for us + handled = EditableWidget::handleKeyDown(ascii, keycode, modifiers); + } + else + { + // not editmode + switch (keycode) + { + case '\n': // enter/return + case '\r': + if (_currentRow >= 0 && _currentCol >= 0) + { + dirty = true; + _selectedItem = _currentRow*_cols + _currentCol; + startEditMode(); + } + break; + + case 256+17: // up arrow + if (_currentRow > 0) + { + _currentRow--; + dirty = true; + } + break; + + case 256+18: // down arrow + if (_currentRow < (int) _rows - 1) + { + _currentRow++; + dirty = true; + } + break; + + case 256+20: // left arrow + if (_currentCol > 0) + { + _currentCol--; + dirty = true; + } + break; + + case 256+19: // right arrow + if (_currentCol < (int) _cols - 1) + { + _currentCol++; + dirty = true; + } + break; + + case 256+24: // pageup + if (_currentRow > 0) + { + _currentRow = 0; + dirty = true; + } + break; + + case 256+25: // pagedown + if (_currentRow < (int) _rows - 1) + { + _currentRow = _rows - 1; + dirty = true; + } + break; + + case 256+22: // home + if (_currentCol > 0) + { + _currentCol = 0; + dirty = true; + } + break; + + case 256+23: // end + if (_currentCol < (int) _cols - 1) + { + _currentCol = _cols - 1; + dirty = true; + } + break; + + default: + handled = false; + } + } + + if (dirty) + { + _selectedItem = _currentRow*_cols + _currentCol; + draw(); + sendCommand(kBGSelectionChangedCmd, _selectedItem); + instance()->frameBuffer().refresh(); + } + + _currentKeyDown = keycode; + return handled; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool ByteGridWidget::handleKeyUp(int ascii, int keycode, int modifiers) +{ + if (keycode == _currentKeyDown) + _currentKeyDown = 0; + return true; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ByteGridWidget::lostFocusWidget() +{ + _editMode = false; + draw(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ByteGridWidget::handleCommand(CommandSender* sender, int cmd, int data) +{ + switch (cmd) + { + case kSetPositionCmd: + if (_currentPos != (int)data) + { + _currentPos = data; + draw(); + } + break; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ByteGridWidget::drawWidget(bool hilite) +{ + FrameBuffer& fb = _boss->instance()->frameBuffer(); + int row, col, deltax; + string buffer; + + // Draw the internal grid +// int linewidth = + for (row = 0; row <= _rows; row++) + fb.hLine(_x, _y + (row * kLineHeight), _x + _w - 1, kColor); + for (col = 0; col <= _cols; col++) + fb.vLine(_x + (col * kColWidth), _y, _y + _h - 1, kColor); + + // Draw the list items + for (row = 0; row < _rows; row++) + { + for (col = 0; col < _cols; col++) + { + int x = _x + 2 + (col * kColWidth); + int y = _y + 2 + (row * kLineHeight); + int pos = row*_cols + col; + + // Draw the selected item inverted, on a highlighted background. + if (_currentRow == row && _currentCol == col) + { + if (_hasFocus && !_editMode) + fb.fillRect(x - 2, y - 2, kColWidth+1, kLineHeight+1, kTextColorHi); + else + fb.frameRect(x - 2, y - 2, kColWidth+1, kLineHeight+1, kTextColorHi); + } + +// GUI::Rect r(getEditRect()); + if (_selectedItem == pos && _editMode) + { + buffer = _editString; + adjustOffset(); + deltax = -_editScrollOffset; + +// fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor, + fb.drawString(_font, buffer, x, y, kColWidth, kTextColor, + kTextAlignLeft, deltax, false); + } + else + { + buffer = _valueStringList[pos]; + deltax = 0; + fb.drawString(_font, buffer, x, y, kColWidth, kTextColor); + } + } + } + +/* + for (i = 0, pos = _currentPos; i < _entriesPerPage && pos < len; i++, pos++) + { + const int y = _y + 2 + kLineHeight * i; + + GUI::Rect r(getEditRect()); + // Draw the selected item inverted, on a highlighted background. + if (_selectedItem == pos) + { + if (_hasFocus && !_editMode) + fb.fillRect(_x + 1, _y + 1 + kLineHeight * i, _w - 1, kLineHeight, kTextColorHi); + else + fb.frameRect(_x + 1, _y + 1 + kLineHeight * i, _w - 2, kLineHeight, kTextColorHi); + } + + if (_selectedItem == pos && _editMode) + { + buffer = _editString; + adjustOffset(); + deltax = -_editScrollOffset; + + fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor, + kTextAlignLeft, deltax, false); + } + else + { + buffer = _valueStringList[pos]; + deltax = 0; + fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor); + } + } +*/ + // Only draw the caret while editing, and if it's in the current viewport + if(_editMode) + drawCaret(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +GUI::Rect ByteGridWidget::getEditRect() const +{ + GUI::Rect r(1, 0, kColWidth, kLineHeight); + const int rowoffset = _currentRow * kLineHeight; + const int coloffset = _currentCol * kColWidth; + r.top += rowoffset; + r.bottom += rowoffset; + r.left += coloffset; + r.right += coloffset - 1; + + return r; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ByteGridWidget::startEditMode() +{ + if (_editable && !_editMode && _selectedItem >= 0) + { + _editMode = true; + setEditString(""); // Erase current entry when starting editing + draw(); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ByteGridWidget::endEditMode() +{ + if (!_editMode) + return; + + // send a message that editing finished with a return/enter key press + _editMode = false; + + // Update the both the string representation and the real data + int value = atoi(_editString.c_str()); + if(_editString.length() == 0 || value < 0 || value > 255) + { + abortEditMode(); + return; + } + + // Append a leading 0 when necessary + if(value < 10) + _editString = "0" + _editString; + + _valueStringList[_selectedItem] = _editString; // FIXME - make sure only length of 2 + _valueList[_selectedItem] = value; + + sendCommand(kBGItemDataChangedCmd, _selectedItem); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ByteGridWidget::abortEditMode() +{ + // undo any changes made + assert(_selectedItem >= 0); + _editMode = false; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool ByteGridWidget::tryInsertChar(char c, int pos) +{ + if (c >= '0' && c <= '9') + { + _editString.insert(pos, 1, c); + return true; + } + return false; +} diff --git a/stella/src/gui/ByteGridWidget.hxx b/stella/src/gui/ByteGridWidget.hxx new file mode 100644 index 000000000..b0fd7340a --- /dev/null +++ b/stella/src/gui/ByteGridWidget.hxx @@ -0,0 +1,107 @@ +//============================================================================ +// +// 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: ByteGridWidget.hxx,v 1.1 2005-06-16 18:40:17 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#ifndef BYTE_GRID_WIDGET_HXX +#define BYTE_GRID_WIDGET_HXX + +#include "GuiObject.hxx" +#include "Widget.hxx" +#include "Command.hxx" +#include "StringList.hxx" +#include "EditableWidget.hxx" +#include "Array.hxx" +#include "Rect.hxx" + +typedef GUI::Array ByteAddrList; +typedef GUI::Array ByteValueList; + +// Some special commands +enum { + kBGItemDoubleClickedCmd = 'BGdb', + kBGItemActivatedCmd = 'BGac', + kBGItemDataChangedCmd = 'BGch', + kBGSelectionChangedCmd = 'BGsc' +}; + +/* ByteGridWidget */ +class ByteGridWidget : public EditableWidget, public CommandSender +{ + public: + ByteGridWidget(GuiObject* boss, int x, int y, int w, int h, + int cols, int rows); + virtual ~ByteGridWidget(); + + void setList(const ByteAddrList& alist, const ByteValueList& vlist); + +// int getSelectedAddr() const { return _addrList[_selectedItem]; } +// int getSelectedValue() const { return _valueList[_selectedItem]; } + + bool isEditable() const { return _editable; } + void setEditable(bool editable) { _editable = editable; } + + virtual void handleMouseDown(int x, int y, int button, int clickCount); + virtual void handleMouseUp(int x, int y, int button, int clickCount); + virtual bool handleKeyDown(int ascii, int keycode, int modifiers); + virtual bool handleKeyUp(int ascii, int keycode, int modifiers); + virtual void handleCommand(CommandSender* sender, int cmd, int data); + + virtual bool wantsFocus() { return true; } + + void startEditMode(); + void endEditMode(); + + protected: + void drawWidget(bool hilite); + + int findItem(int x, int y); + + void abortEditMode(); + + GUI::Rect getEditRect() const; + + void lostFocusWidget(); + + bool tryInsertChar(char c, int pos); + + protected: + int _rows; + int _cols; + int _currentRow; + int _currentCol; + + ByteAddrList _addrList; + ByteValueList _valueList; + StringList _addrStringList; + StringList _valueStringList; + + bool _editable; + bool _editMode; + int _currentPos; + int _entriesPerPage; + int _selectedItem; + int _currentKeyDown; + string _backupString; + + string _quickSelectStr; + int _quickSelectTime; +}; + +#endif diff --git a/stella/src/gui/CheatWidget.cxx b/stella/src/gui/CheatWidget.cxx index 78dc47a4e..de9b36a68 100644 --- a/stella/src/gui/CheatWidget.cxx +++ b/stella/src/gui/CheatWidget.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: CheatWidget.cxx,v 1.7 2005-06-16 00:55:59 stephena Exp $ +// $Id: CheatWidget.cxx,v 1.8 2005-06-16 18:40:17 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -210,7 +210,8 @@ void CheatWidget::doCompare() } // Do some pre-processing on the string - if(str.find_first_of("+-", 0) > 0) + string::size_type pos = str.find_first_of("+-", 0); + if(pos > 0 && pos != string::npos) { // Only accept '+' or '-' at the start of the string myResult->setLabel("Input must be [+|-]NUM"); diff --git a/stella/src/gui/DebuggerDialog.cxx b/stella/src/gui/DebuggerDialog.cxx index 81221f3ed..a1df2e7a4 100644 --- a/stella/src/gui/DebuggerDialog.cxx +++ b/stella/src/gui/DebuggerDialog.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: DebuggerDialog.cxx,v 1.9 2005-06-16 00:55:59 stephena Exp $ +// $Id: DebuggerDialog.cxx,v 1.10 2005-06-16 18:40:17 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -23,6 +23,7 @@ #include "ListWidget.hxx" #include "PromptWidget.hxx" #include "CheatWidget.hxx" +#include "RamWidget.hxx" #include "DebuggerDialog.hxx" @@ -39,8 +40,7 @@ DebuggerDialog::DebuggerDialog(OSystem* osystem, DialogContainer* parent, // 1) The Prompt/console tab myTab->addTab("Prompt"); - PromptWidget* prompt = new PromptWidget(myTab, 2, 2, - _w - vBorder, _h - 25); + PromptWidget* prompt = new PromptWidget(myTab, 2, 2, _w - vBorder, _h - 25); myTab->setActiveWidget(0, prompt); // 2) The CPU tab @@ -49,6 +49,8 @@ DebuggerDialog::DebuggerDialog(OSystem* osystem, DialogContainer* parent, // 3) The RAM tab myTab->addTab("RAM"); + RamWidget* ram = new RamWidget(myTab, 2, 2, _w - vBorder, _h - 25); + myTab->setActiveWidget(2, ram->activeWidget()); // 4) The ROM tab diff --git a/stella/src/gui/EditableWidget.cxx b/stella/src/gui/EditableWidget.cxx index 5834d1615..7ba29f65c 100644 --- a/stella/src/gui/EditableWidget.cxx +++ b/stella/src/gui/EditableWidget.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: EditableWidget.cxx,v 1.3 2005-06-16 00:55:59 stephena Exp $ +// $Id: EditableWidget.cxx,v 1.4 2005-06-16 18:40:17 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -173,16 +173,8 @@ void EditableWidget::drawCaret() x += getAbsX(); y += _y; -/* -cerr << "draw caret: " << endl - << "x = " << x << endl - << "y = " << y << endl - << "h = " << editRect.height() - 2 << endl - << "c = " << color << endl - << endl; -*/ FrameBuffer& fb = _boss->instance()->frameBuffer(); - fb.vLine(x, y, y + editRect.height() - 2, color); + fb.vLine(x, y+2, y + editRect.height() - 2, color); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/gui/RamWidget.cxx b/stella/src/gui/RamWidget.cxx new file mode 100644 index 000000000..c1969cd98 --- /dev/null +++ b/stella/src/gui/RamWidget.cxx @@ -0,0 +1,161 @@ +//============================================================================ +// +// 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: RamWidget.cxx,v 1.1 2005-06-16 18:40:17 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#include + +#include "OSystem.hxx" +#include "FrameBuffer.hxx" +#include "GuiUtils.hxx" +#include "GuiObject.hxx" +#include "Debugger.hxx" +#include "Widget.hxx" +#include "ByteGridWidget.hxx" + +#include "RamWidget.hxx" + +/* +enum { + kSearchCmd = 'CSEA', + kCmpCmd = 'CCMP', + kRestartCmd = 'CRST' +}; +*/ + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h) + : Widget(boss, x, y, w, h), + CommandSender(boss) +{ + int gwidth = 16 * 2 * instance()->consoleFont().getMaxCharWidth() + 20; + int gheight = 8 * instance()->consoleFont().getFontHeight() + 20; + + // Create a 16x8 grid (16 x 8 = 128 RAM bytes) + myRamGrid = new ByteGridWidget(boss, 10, 10, gwidth, gheight, 16, 8); + myRamGrid->setFont(instance()->consoleFont()); + myRamGrid->setTarget(this); + myActiveWidget = myRamGrid; + + fillGrid(); + +#if 0 + const int border = 20; + const int bwidth = 50; + const int charWidth = instance()->consoleFont().getMaxCharWidth(); + const int charHeight = instance()->consoleFont().getFontHeight() + 2; + int xpos = x + border; + int ypos = y + border; + + // Add the numedit label and box + new StaticTextWidget(boss, xpos, ypos, 70, kLineHeight, + "Enter a value:", kTextAlignLeft); + + myEditBox = new EditNumWidget(boss, 90, ypos - 2, charWidth*10, charHeight, ""); + myEditBox->setFont(instance()->consoleFont()); +// myEditBox->setTarget(this); + myActiveWidget = myEditBox; + ypos += border; + + // Add the result text string area + myResult = new StaticTextWidget(boss, border + 5, ypos, 175, kLineHeight, + "", kTextAlignLeft); + myResult->setColor(kTextColorEm); + + // Add the three search-related buttons + xpos = x + border; + ypos += border * 2; + mySearchButton = new ButtonWidget(boss, xpos, ypos, bwidth, 16, + "Search", kSearchCmd, 0); + mySearchButton->setTarget(this); + xpos += 8 + bwidth; + + myCompareButton = new ButtonWidget(boss, xpos, ypos, bwidth, 16, + "Compare", kCmpCmd, 0); + myCompareButton->setTarget(this); + xpos += 8 + bwidth; + + myRestartButton = new ButtonWidget(boss, xpos, ypos, bwidth, 16, + "Restart", kRestartCmd, 0); + myRestartButton->setTarget(this); + + // Add the list showing the results of a search/compare + xpos = 200; ypos = border/2; + new StaticTextWidget(boss, xpos + 10, ypos, 70, kLineHeight, + "Address Value", kTextAlignLeft); + ypos += kLineHeight; + + myResultsList = new AddrValueWidget(boss, xpos, ypos, 100, 75); + myResultsList->setNumberingMode(kHexNumbering); + myResultsList->setFont(instance()->consoleFont()); + myResultsList->setTarget(this); + + // Start in a known state + doRestart(); +#endif +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +RamWidget::~RamWidget() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void RamWidget::handleCommand(CommandSender* sender, int cmd, int data) +{ + switch(cmd) + { +/* + case kBGItemDoubleClickedCmd: + cerr << "double-clicked on " << data << endl; + break; + + case kBGItemActivatedCmd: + cerr << "item activated on " << data << endl; + break; + + case kBGSelectionChangedCmd: + cerr << "selection changed on " << data << endl; + break; +*/ + case kBGItemDataChangedCmd: + cerr << "data changed on " << data << endl; +/* + int addr = myResultsList->getSelectedAddr() - kRamStart; + int value = myResultsList->getSelectedValue(); + instance()->debugger().writeRAM(addr, value); +*/ + break; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void RamWidget::fillGrid() +{ + ByteAddrList alist; + ByteValueList vlist; + + for(unsigned int i = 0; i < kRamSize; i++) + { + alist.push_back(i); + vlist.push_back(instance()->debugger().readRAM(i)); + } + + myRamGrid->setList(alist, vlist); +} diff --git a/stella/src/gui/RamWidget.hxx b/stella/src/gui/RamWidget.hxx new file mode 100644 index 000000000..74da45d49 --- /dev/null +++ b/stella/src/gui/RamWidget.hxx @@ -0,0 +1,54 @@ +//============================================================================ +// +// 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: RamWidget.hxx,v 1.1 2005-06-16 18:40:17 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#ifndef RAM_WIDGET_HXX +#define RAM_WIDGET_HXX + +class GuiObject; +class ButtonWidget; +class StaticTextWidget; +class ByteGridWidget; + +#include "Array.hxx" +#include "Widget.hxx" +#include "Command.hxx" + + +class RamWidget : public Widget, public CommandSender +{ + public: + RamWidget(GuiObject* boss, int x, int y, int w, int h); + virtual ~RamWidget(); + + Widget* activeWidget() { return myActiveWidget; } + + void handleCommand(CommandSender* sender, int cmd, int data); + + public: + void fillGrid(); + + private: + Widget* myActiveWidget; + + ByteGridWidget* myRamGrid; +}; + +#endif diff --git a/stella/src/gui/Widget.cxx b/stella/src/gui/Widget.cxx index 37e6b731d..6028a2bc6 100644 --- a/stella/src/gui/Widget.cxx +++ b/stella/src/gui/Widget.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: Widget.cxx,v 1.16 2005-06-16 00:56:00 stephena Exp $ +// $Id: Widget.cxx,v 1.17 2005-06-16 18:40:17 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -87,12 +87,12 @@ void Widget::draw() // Now perform the actual widget draw drawWidget((_flags & WIDGET_HILITED) ? true : false); - +/* FIXME // Indicate if this is the currently active widget // by drawing a box around it. if((_activeWidget == this) && (_flags & WIDGET_TAB_NAVIGATE)) fb.frameRect(_x, _y, _w, _h, kTextColorEm); // FIXME - maybe chose a better color - +*/ // Restore x/y if (_flags & WIDGET_BORDER) { _x -= 4; diff --git a/stella/src/gui/Widget.hxx b/stella/src/gui/Widget.hxx index a61901f61..bd7a1068f 100644 --- a/stella/src/gui/Widget.hxx +++ b/stella/src/gui/Widget.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: Widget.hxx,v 1.17 2005-06-16 00:56:00 stephena Exp $ +// $Id: Widget.hxx,v 1.18 2005-06-16 18:40:17 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -54,7 +54,8 @@ enum { kScrollBarWidget = 'SCRB', kPopUpWidget = 'POPU', kTabWidget = 'TABW', - kPromptWidget = 'PROM' + kPromptWidget = 'PROM', + kByteGridWidget = 'BGRI' }; enum { @@ -66,7 +67,7 @@ enum { This is the base class for all widgets. @author Stephen Anthony - @version $Id: Widget.hxx,v 1.17 2005-06-16 00:56:00 stephena Exp $ + @version $Id: Widget.hxx,v 1.18 2005-06-16 18:40:17 stephena Exp $ */ class Widget : public GuiObject {