diff --git a/src/debugger/gui/CartRamWidget.hxx b/src/debugger/gui/CartRamWidget.hxx index bc0f4f810..d24a5d134 100644 --- a/src/debugger/gui/CartRamWidget.hxx +++ b/src/debugger/gui/CartRamWidget.hxx @@ -67,11 +67,11 @@ class CartRamWidget : public Widget, public CommandSender int x, int y, int w, int h, CartDebugWidget& cartDebug); ~InternalRamWidget() override = default; + string getLabel(int addr) const override; private: uInt8 getValue(int addr) const override; void setValue(int addr, uInt8 value) override; - string getLabel(int addr) const override; void fillList(uInt32 start, uInt32 size, IntArray& alist, IntArray& vlist, BoolArray& changed) const override; diff --git a/src/debugger/gui/DataGridWidget.cxx b/src/debugger/gui/DataGridWidget.cxx index 4304ecb0e..5d0dc0623 100644 --- a/src/debugger/gui/DataGridWidget.cxx +++ b/src/debugger/gui/DataGridWidget.cxx @@ -579,13 +579,20 @@ int DataGridWidget::getToolTipIndex(const Common::Point& pos) const const int col = (pos.x - getAbsX()) / _colWidth; const int row = (pos.y - getAbsY()) / _rowHeight; - return row * _cols + col; + if(row >= 0 && row < _rows && col >= 0 && col < _cols) + return row * _cols + col; + else + return -1; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string DataGridWidget::getToolTip(const Common::Point& pos) const { const int idx = getToolTipIndex(pos); + + if(idx < 0) + return EmptyString; + const Int32 val = _valueList[idx]; ostringstream buf; @@ -593,7 +600,11 @@ string DataGridWidget::getToolTip(const Common::Point& pos) const << "$" << Common::Base::toString(val, Common::Base::Fmt::_16) << " = #" << val; if(val < 0x100) + { + if(val >= 0x80) + buf << '/' << -(0x100 - val); buf << " = %" << Common::Base::toString(val, Common::Base::Fmt::_2); + } return buf.str(); } diff --git a/src/debugger/gui/DataGridWidget.hxx b/src/debugger/gui/DataGridWidget.hxx index 37434db3c..848993311 100644 --- a/src/debugger/gui/DataGridWidget.hxx +++ b/src/debugger/gui/DataGridWidget.hxx @@ -102,6 +102,7 @@ class DataGridWidget : public EditableWidget void lostFocusWidget() override; bool hasToolTip() const override { return true; } + int getToolTipIndex(const Common::Point& pos) const; void handleMouseDown(int x, int y, MouseButton b, int clickCount) override; void handleMouseUp(int x, int y, MouseButton b, int clickCount) override; @@ -150,7 +151,6 @@ class DataGridWidget : public EditableWidget void enableEditMode(bool state) { _editMode = state; } - int getToolTipIndex(const Common::Point& pos) const; private: // Following constructors and assignment operators not supported diff --git a/src/debugger/gui/RamWidget.cxx b/src/debugger/gui/RamWidget.cxx index 77456f810..7f651910a 100644 --- a/src/debugger/gui/RamWidget.cxx +++ b/src/debugger/gui/RamWidget.cxx @@ -15,7 +15,7 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ -#include "DataGridWidget.hxx" +#include "DataGridRamWidget.hxx" #include "EditTextWidget.hxx" #include "GuiObject.hxx" #include "InputTextDialog.hxx" @@ -54,8 +54,8 @@ RamWidget::RamWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n // Add RAM grid (with scrollbar) int xpos = x + _font.getStringWidth("xxxx"); bool useScrollbar = ramsize / numrows > 16; - myRamGrid = new DataGridWidget(_boss, _nfont, xpos, ypos, - 16, myNumRows, 2, 8, Common::Base::Fmt::_16, useScrollbar); + myRamGrid = new DataGridRamWidget(_boss, *this, _nfont, xpos, ypos, + 16, myNumRows, 2, 8, Common::Base::Fmt::_16, useScrollbar); myRamGrid->setTarget(this); myRamGrid->setID(kRamGridID); addFocusWidget(myRamGrid); diff --git a/src/debugger/gui/RamWidget.hxx b/src/debugger/gui/RamWidget.hxx index fbc7747e6..069086fef 100644 --- a/src/debugger/gui/RamWidget.hxx +++ b/src/debugger/gui/RamWidget.hxx @@ -22,6 +22,7 @@ class GuiObject; class ButtonWidget; class DataGridWidget; class DataGridOpsWidget; +class DataGridRamWidget; class EditTextWidget; class StaticTextWidget; class InputTextDialog; @@ -41,11 +42,12 @@ class RamWidget : public Widget, public CommandSender void setOpsWidget(DataGridOpsWidget* w); void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + virtual string getLabel(int addr) const = 0; + private: // To be implemented by derived classes virtual uInt8 getValue(int addr) const = 0; virtual void setValue(int addr, uInt8 value) = 0; - virtual string getLabel(int addr) const = 0; virtual void fillList(uInt32 start, uInt32 size, IntArray& alist, IntArray& vlist, @@ -97,7 +99,7 @@ class RamWidget : public Widget, public CommandSender StaticTextWidget* myRamStart{nullptr}; std::array myRamLabels{nullptr}; - DataGridWidget* myRamGrid{nullptr}; + DataGridRamWidget* myRamGrid{nullptr}; DataGridWidget* myHexValue{nullptr}; DataGridWidget* myDecValue{nullptr}; DataGridWidget* myBinValue{nullptr}; diff --git a/src/debugger/gui/RiotRamWidget.hxx b/src/debugger/gui/RiotRamWidget.hxx index 53d006bb0..3e30fc3e0 100644 --- a/src/debugger/gui/RiotRamWidget.hxx +++ b/src/debugger/gui/RiotRamWidget.hxx @@ -36,10 +36,11 @@ class RiotRamWidget : public RamWidget int x, int y, int w); ~RiotRamWidget() override = default; + string getLabel(int addr) const override; + private: uInt8 getValue(int addr) const override; void setValue(int addr, uInt8 value) override; - string getLabel(int addr) const override; void fillList(uInt32 start, uInt32 size, IntArray& alist, IntArray& vlist, BoolArray& changed) const override; diff --git a/src/debugger/gui/RiotWidget.cxx b/src/debugger/gui/RiotWidget.cxx index 73a70391f..053ff1325 100644 --- a/src/debugger/gui/RiotWidget.cxx +++ b/src/debugger/gui/RiotWidget.cxx @@ -66,11 +66,13 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, on.push_back("1"); } + StringList labels; + #define CREATE_IO_REGS(desc, bits, bitsID, editable) \ t = new StaticTextWidget(boss, lfont, xpos, ypos+2, lwidth, fontHeight,\ - desc, TextAlign::Left); \ + desc); \ xpos += t->getWidth() + 5; \ - bits = new ToggleBitWidget(boss, nfont, xpos, ypos, 8, 1); \ + bits = new ToggleBitWidget(boss, nfont, xpos, ypos, 8, 1, 1, labels); \ bits->setTarget(this); \ bits->setID(bitsID); \ if(editable) addFocusWidget(bits); else bits->setEditable(false); \ @@ -78,6 +80,7 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, bits->setList(off, on); // SWCHA bits in 'poke' mode + labels.clear(); CREATE_IO_REGS("SWCHA(W)", mySWCHAWriteBits, kSWCHABitsID, true) col = xpos + 20; // remember this for adding widgets to the second column @@ -87,10 +90,20 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, // SWCHA bits in 'peek' mode xpos = 10; ypos += lineHeight + 5; + labels.clear(); + labels.push_back("P0 right"); + labels.push_back("P0 left"); + labels.push_back("P0 down"); + labels.push_back("P0 up"); + labels.push_back("P1 right"); + labels.push_back("P1 left"); + labels.push_back("P1 down"); + labels.push_back("P1 up"); CREATE_IO_REGS("SWCHA(R)", mySWCHAReadBits, kSWCHARBitsID, true) // SWCHB bits in 'poke' mode xpos = 10; ypos += 2 * lineHeight; + labels.clear(); CREATE_IO_REGS("SWCHB(W)", mySWCHBWriteBits, kSWCHBBitsID, true) // SWBCNT bits @@ -99,6 +112,15 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, // SWCHB bits in 'peek' mode xpos = 10; ypos += lineHeight + 5; + labels.clear(); + labels.push_back("P1 difficulty"); + labels.push_back("P0 difficulty"); + labels.push_back(""); + labels.push_back(""); + labels.push_back("Color/B+W"); + labels.push_back(""); + labels.push_back("Select"); + labels.push_back("Reset"); CREATE_IO_REGS("SWCHB(R)", mySWCHBReadBits, kSWCHBRBitsID, true) // Timer registers (R/W) diff --git a/src/debugger/gui/RomListWidget.cxx b/src/debugger/gui/RomListWidget.cxx index 868b72cdf..aab298fad 100644 --- a/src/debugger/gui/RomListWidget.cxx +++ b/src/debugger/gui/RomListWidget.cxx @@ -452,7 +452,8 @@ Common::Point RomListWidget::getToolTipIndex(const Common::Point& pos) const const int col = (pos.x - r.x() - getAbsX()) / _font.getMaxCharWidth(); const int row = (pos.y - getAbsY()) / _lineHeight; - if(col < 0) + if(col < 0 || col >= 8 + || row < 0 || row + _currentPos >= int(myDisasm->list.size())) return Common::Point(-1, -1); else return Common::Point(col, row + _currentPos); @@ -463,7 +464,7 @@ string RomListWidget::getToolTip(const Common::Point& pos) const { const Common::Point& idx = getToolTipIndex(pos); - if(idx.y == -1) + if(idx.y < 0) return EmptyString; const string bytes = myDisasm->list[idx.y].bytes; @@ -480,12 +481,18 @@ string RomListWidget::getToolTip(const Common::Point& pos) const else { // 1..3 hex values - if(idx.x % 3 == 2) - // Skip gaps between hex values + if(idx.x == 2) + // Skip gap after first byte return EmptyString; - // Get one hex byte - const string valStr = bytes.substr((idx.x / 3) * 3, 2); + string valStr; + + if(idx.x < 2 || bytes.length() < 8) + // 1 or 2 hex bytes, get one hex byte + valStr = bytes.substr((idx.x / 3) * 3, 2); + else + // 3 hex bytes, get two rightmost hex bytes + valStr = bytes.substr(6, 2) + bytes.substr(3, 2); val = static_cast(stol(valStr, nullptr, 16)); } @@ -495,7 +502,11 @@ string RomListWidget::getToolTip(const Common::Point& pos) const << "$" << Common::Base::toString(val, Common::Base::Fmt::_16) << " = #" << val; if(val < 0x100) + { + if(val >= 0x80) + buf << '/' << -(0x100 - val); buf << " = %" << Common::Base::toString(val, Common::Base::Fmt::_2); + } return buf.str(); } diff --git a/src/debugger/gui/ToggleBitWidget.cxx b/src/debugger/gui/ToggleBitWidget.cxx index 39ca7dcce..212ae60ed 100644 --- a/src/debugger/gui/ToggleBitWidget.cxx +++ b/src/debugger/gui/ToggleBitWidget.cxx @@ -25,8 +25,10 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ToggleBitWidget::ToggleBitWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int cols, int rows, int colchars) - : ToggleWidget(boss, font, x, y, cols, rows) + int x, int y, int cols, int rows, int colchars, + const StringList& labels) + : ToggleWidget(boss, font, x, y, cols, rows), + _labelList(labels) { _rowHeight = font.getLineHeight(); _colWidth = colchars * font.getMaxCharWidth() + 8; @@ -47,6 +49,13 @@ ToggleBitWidget::ToggleBitWidget(GuiObject* boss, const GUI::Font& font, _h = _rowHeight * rows + 1; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +ToggleBitWidget::ToggleBitWidget(GuiObject* boss, const GUI::Font& font, + int x, int y, int cols, int rows, int colchars) + : ToggleBitWidget(boss, font, x, y, cols, rows, colchars, StringList()) +{ +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ToggleBitWidget::setList(const StringList& off, const StringList& on) { @@ -69,6 +78,27 @@ void ToggleBitWidget::setState(const BoolArray& state, const BoolArray& changed) setDirty(); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string ToggleBitWidget::getToolTip(const Common::Point& pos) const +{ + Common::Point idx = getToolTipIndex(pos); + + if(idx.y < 0) + return EmptyString; + + const string tip = ToggleWidget::getToolTip(pos); + + if(idx.x < _labelList.size()) + { + const string label = _labelList[idx.x]; + + if(!label.empty()) + return tip + "\n" + label; + } + return tip; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ToggleBitWidget::drawWidget(bool hilite) { diff --git a/src/debugger/gui/ToggleBitWidget.hxx b/src/debugger/gui/ToggleBitWidget.hxx index 6d5505030..707aea1cc 100644 --- a/src/debugger/gui/ToggleBitWidget.hxx +++ b/src/debugger/gui/ToggleBitWidget.hxx @@ -26,17 +26,23 @@ class ToggleBitWidget : public ToggleWidget public: ToggleBitWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int cols, int rows, int colchars = 1); + ToggleBitWidget(GuiObject* boss, const GUI::Font& font, + int x, int y, int cols, int rows, int colchars, + const StringList& labels); ~ToggleBitWidget() override = default; void setList(const StringList& off, const StringList& on); void setState(const BoolArray& state, const BoolArray& changed); + string getToolTip(const Common::Point& pos) const override; + protected: void drawWidget(bool hilite) override; protected: StringList _offList; StringList _onList; + StringList _labelList; private: // Following constructors and assignment operators not supported diff --git a/src/debugger/gui/ToggleWidget.cxx b/src/debugger/gui/ToggleWidget.cxx index ac321f4bf..adb33e118 100644 --- a/src/debugger/gui/ToggleWidget.cxx +++ b/src/debugger/gui/ToggleWidget.cxx @@ -209,17 +209,25 @@ void ToggleWidget::handleCommand(CommandSender* sender, int cmd, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int ToggleWidget::getToolTipIndex(const Common::Point& pos) const +Common::Point ToggleWidget::getToolTipIndex(const Common::Point& pos) const { + const int col = (pos.x - getAbsX()) / _colWidth; const int row = (pos.y - getAbsY()) / _rowHeight; - return row * _cols; + if(row >= 0 && row < _rows && col >= 0 && col < _cols) + return Common::Point(col, row); + else + return Common::Point(-1, -1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string ToggleWidget::getToolTip(const Common::Point& pos) const { - const int idx = getToolTipIndex(pos); + const int idx = getToolTipIndex(pos).y * _cols; + + if(idx < 0) + return EmptyString; + Int32 val = 0; ostringstream buf; diff --git a/src/debugger/gui/ToggleWidget.hxx b/src/debugger/gui/ToggleWidget.hxx index 347359677..ee70f6233 100644 --- a/src/debugger/gui/ToggleWidget.hxx +++ b/src/debugger/gui/ToggleWidget.hxx @@ -51,6 +51,7 @@ class ToggleWidget : public Widget, public CommandSender protected: bool hasToolTip() const override { return true; } + Common::Point getToolTipIndex(const Common::Point& pos) const; protected: int _rows{0}; @@ -76,8 +77,6 @@ class ToggleWidget : public Widget, public CommandSender bool handleKeyDown(StellaKey key, StellaMod mod) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override; - int getToolTipIndex(const Common::Point& pos) const; - // Following constructors and assignment operators not supported ToggleWidget() = delete; ToggleWidget(const ToggleWidget&) = delete; diff --git a/src/debugger/gui/module.mk b/src/debugger/gui/module.mk index cda7666e9..0a985e71b 100644 --- a/src/debugger/gui/module.mk +++ b/src/debugger/gui/module.mk @@ -55,6 +55,7 @@ MODULE_OBJS := \ src/debugger/gui/CartDebugWidget.o \ src/debugger/gui/CpuWidget.o \ src/debugger/gui/DataGridOpsWidget.o \ + src/debugger/gui/DataGridRamWidget.o \ src/debugger/gui/DataGridWidget.o \ src/debugger/gui/DebuggerDialog.o \ src/debugger/gui/DelayQueueWidget.o \ diff --git a/src/windows/Stella.vcxproj b/src/windows/Stella.vcxproj index f9b5d3499..76e311ce3 100644 --- a/src/windows/Stella.vcxproj +++ b/src/windows/Stella.vcxproj @@ -525,6 +525,9 @@ true + + true + true @@ -1550,6 +1553,9 @@ true + + true + true diff --git a/src/windows/Stella.vcxproj.filters b/src/windows/Stella.vcxproj.filters index 550419e9a..6db5675f0 100644 --- a/src/windows/Stella.vcxproj.filters +++ b/src/windows/Stella.vcxproj.filters @@ -1035,6 +1035,9 @@ Source Files\gui + + Source Files\debugger + @@ -2129,6 +2132,9 @@ Header Files\gui + + Header Files\debugger +