diff --git a/src/debugger/gui/CartELFStateWidget.cxx b/src/debugger/gui/CartELFStateWidget.cxx new file mode 100644 index 000000000..037812116 --- /dev/null +++ b/src/debugger/gui/CartELFStateWidget.cxx @@ -0,0 +1,106 @@ +//============================================================================ +// +// 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-2024 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#include "CartELFStateWidget.hxx" + +#include + +#include "CartELF.hxx" +#include "DataGridWidget.hxx" +#include "ToggleBitWidget.hxx" + +namespace { + string registerName(uInt8 reg) { + switch (reg) { + case 11: + return "FP (R11) = "; + + case 12: + return "IP (R12) = "; + + case 13: + return "SP (R13) = "; + + case 14: + return "LR (R14) = "; + + case 15: + return "PC (R15) = "; + + default: { + ostringstream s; + s << "R" << static_cast(reg) << " = "; + + return s.str(); + } + } + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +CartridgeELFStateWidget::CartridgeELFStateWidget(GuiObject* boss, const GUI::Font& lfont, + const GUI::Font& nfont, + int x, int y, int w, int h, + CartridgeELF& cart) + : CartDebugWidget(boss, lfont, nfont, x, y, w, h), myCart(cart), myFlagValues(4) +{ + initialize(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void CartridgeELFStateWidget::initialize() +{ + constexpr int x0 = 2; + const int lineHeight = _font.getLineHeight(); + int y = lineHeight / 2; + + new StaticTextWidget(_boss, _font, x0, y, "ARM registers:"); + const int indent = _font.getMaxCharWidth() * 15; + + myArmRegisters = new DataGridWidget(_boss, _font, x0 + indent, y, 4, 4, 8, 8, Common::Base::Fmt::_16_8); + y += myArmRegisters->getHeight() + lineHeight / 2; + + myArmRegisters->setEditable(false); + for (uInt8 i = 0; i < 16; i++) myArmRegisters->setToolTip(i % 4, i / 4, registerName(i)); + + new StaticTextWidget(_boss, _font, x0, y, "ARM flags:"); + myFlags = new ToggleBitWidget(_boss, _font, x0 + indent, y + lineHeight, 4, 1, 1); + myFlags->setEditable(false); + + new StaticTextWidget(_boss, _font, x0 + indent + 3, y, "N"); + new StaticTextWidget(_boss, _font, x0 + indent + 3 + myFlags->colWidth(), y, "Z"); + new StaticTextWidget(_boss, _font, x0 + indent + 3 + 2 * myFlags->colWidth(), y, "C"); + new StaticTextWidget(_boss, _font, x0 + indent + 3 + 3 * myFlags->colWidth(), y, "V"); +} + +void CartridgeELFStateWidget::loadConfig() +{ + for (uInt8 i = 0; i < 16; i++) + myArmRegisters->setValue(i, myCart.myCortexEmu.getRegister(i)); + + BoolArray flags(4); + flags[0] = myCart.myCortexEmu.getN(); + flags[1] = myCart.myCortexEmu.getZ(); + flags[2] = myCart.myCortexEmu.getC(); + flags[3] = myCart.myCortexEmu.getV(); + + BoolArray flagsChanged(4); + for (uInt8 i = 0; i < 4; i++) flagsChanged[i] = flags[i] != myFlagValues[i]; + myFlagValues = flags; + + myFlags->setState(flags, flagsChanged); +} diff --git a/src/debugger/gui/CartELFStateWidget.hxx b/src/debugger/gui/CartELFStateWidget.hxx new file mode 100644 index 000000000..581a06e15 --- /dev/null +++ b/src/debugger/gui/CartELFStateWidget.hxx @@ -0,0 +1,49 @@ +//============================================================================ +// +// 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-2024 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef CART_ELF_INFO_WIDGET_HXX +#define CART_ELF_INFO_WIDGET_HXX + +#include "CartDebugWidget.hxx" + +class CartridgeELF; +class DataGridWidget; +class ToggleBitWidget; + +class CartridgeELFStateWidget : public CartDebugWidget { + public: + CartridgeELFStateWidget(GuiObject* boss, const GUI::Font& lfont, + const GUI::Font& nfont, + int x, int y, int w, int h, + CartridgeELF& cart); + + ~CartridgeELFStateWidget() override = default; + + private: + void initialize(); + + void loadConfig() override; + + private: + CartridgeELF& myCart; + BoolArray myFlagValues; + + DataGridWidget* myArmRegisters{nullptr}; + ToggleBitWidget* myFlags{nullptr}; +}; + +#endif // CART_ELF_INFO_WIDGET_HXX diff --git a/src/debugger/gui/module.mk b/src/debugger/gui/module.mk index 39fa861d5..367322000 100644 --- a/src/debugger/gui/module.mk +++ b/src/debugger/gui/module.mk @@ -49,6 +49,7 @@ MODULE_OBJS := \ src/debugger/gui/CartFEWidget.o \ src/debugger/gui/CartGLWidget.o \ src/debugger/gui/CartELFWidget.o \ + src/debugger/gui/CartELFStateWidget.o \ src/debugger/gui/CartJANEWidget.o \ src/debugger/gui/CartMDMWidget.o \ src/debugger/gui/CartRamWidget.o \ diff --git a/src/emucore/CartELF.cxx b/src/emucore/CartELF.cxx index 29dc642ac..223be687e 100644 --- a/src/emucore/CartELF.cxx +++ b/src/emucore/CartELF.cxx @@ -28,6 +28,7 @@ #ifdef DEBUGGER_SUPPORT #include "CartELFWidget.hxx" + #include "CartELFStateWidget.hxx" #endif #include "CartELF.hxx" @@ -90,7 +91,7 @@ namespace { stream << sections[i].name - << " @ 0x"<< std::setw(8) + << " @ 0x" << std::setw(8) << (relocatedSections[i]->offset + linker.getSegmentBase(relocatedSections[i]->segment)) << " size 0x" << std::setw(8) << sections[i].size << '\n'; } @@ -379,10 +380,18 @@ uInt8 CartridgeELF::overdrivePoke(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartDebugWidget* CartridgeELF::debugWidget( GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h +) { + return new CartridgeELFStateWidget(boss, lfont, nfont, x, y, w, h, *this); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +CartDebugWidget* CartridgeELF::infoWidget( + GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h ) { return new CartridgeELFWidget(boss, lfont, nfont, x, y, w, h, *this); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string CartridgeELF::getDebugLog() const { ostringstream s; @@ -390,7 +399,10 @@ string CartridgeELF::getDebugLog() const s << "ARM entrypoint: 0x" << std::hex << std::setw(8) << std::setfill('0') << myArmEntrypoint - << std::dec << '\n'; + << '\n' + << "vsclib stubs @ 0x" << std::setw(8) << ADDR_STUB_BASE + << " size 0x" << std::setw(8) << STUB_SIZE << "\n" + << std::dec; dumpLinkage(myElfParser, *myLinker, s); diff --git a/src/emucore/CartELF.hxx b/src/emucore/CartELF.hxx index 56c8b33d6..94dfb1d1e 100644 --- a/src/emucore/CartELF.hxx +++ b/src/emucore/CartELF.hxx @@ -30,11 +30,13 @@ class ElfLinker; #ifdef DEBUGGER_SUPPORT class CartridgeELFWidget; + class CartridgeELFStateWidget; #endif class CartridgeELF: public Cartridge { #ifdef DEBUGGER_SUPPORT friend CartridgeELFWidget; + friend CartridgeELFStateWidget; #endif public: @@ -84,6 +86,10 @@ class CartridgeELF: public Cartridge { CartDebugWidget* debugWidget( GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h ) override; + + CartDebugWidget* infoWidget( + GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h + ) override; #endif public: diff --git a/src/emucore/CortexM0.cxx b/src/emucore/CortexM0.cxx index 6a761120f..5116bcc1c 100644 --- a/src/emucore/CortexM0.cxx +++ b/src/emucore/CortexM0.cxx @@ -773,11 +773,36 @@ CortexM0& CortexM0::setRegister(uInt8 regno, uInt32 value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 CortexM0::getRegister(uInt32 regno) +uInt32 CortexM0::getRegister(uInt32 regno) const { return read_register(regno); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CortexM0::getN() const +{ + return znFlags & 0x80000000; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CortexM0::getZ() const +{ + return znFlags == 0; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CortexM0::getC() const +{ + return cFlag; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CortexM0::getV() const +{ + return vFlag; +} + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 CortexM0::decodeInstructionWord(uInt16 instructionWord) { diff --git a/src/emucore/CortexM0.hxx b/src/emucore/CortexM0.hxx index 5450f6547..b3c86c802 100644 --- a/src/emucore/CortexM0.hxx +++ b/src/emucore/CortexM0.hxx @@ -127,7 +127,12 @@ class CortexM0: public Serializable CortexM0& reset(); CortexM0& setPc(uInt32 pc); CortexM0& setRegister(uInt8 regno, uInt32 value); - uInt32 getRegister(uInt32 regno); + uInt32 getRegister(uInt32 regno) const; + + bool getN() const; + bool getZ() const; + bool getC() const; + bool getV() const; static uInt8 decodeInstructionWord(uInt16 instructionWord); diff --git a/src/os/windows/Stella.vcxproj b/src/os/windows/Stella.vcxproj index 4dab35566..7382c6e00 100755 --- a/src/os/windows/Stella.vcxproj +++ b/src/os/windows/Stella.vcxproj @@ -548,6 +548,7 @@ true + true @@ -1521,6 +1522,7 @@ true + true @@ -1986,4 +1988,4 @@ - \ No newline at end of file + diff --git a/src/os/windows/Stella.vcxproj.filters b/src/os/windows/Stella.vcxproj.filters index e3cbf8760..89b949e32 100644 --- a/src/os/windows/Stella.vcxproj.filters +++ b/src/os/windows/Stella.vcxproj.filters @@ -1266,6 +1266,9 @@ Source Files\debugger\gui + + Source Files\debugger\gui + Source Files\emucore @@ -2564,6 +2567,9 @@ Header Files\debugger\gui + + Header Files\debugger\gui + Header Files\emucore\elf @@ -2581,4 +2587,4 @@ Resource Files - \ No newline at end of file +