From a92ceed195b9fdad418c47318d052906ee2ee43c Mon Sep 17 00:00:00 2001 From: thrust26 Date: Fri, 29 Sep 2017 20:12:41 +0200 Subject: [PATCH] SaveKey/AtariVox detects EEPROM areas accessed by ROM and allows erasing only these in the debugger. --- src/debugger/gui/AtariVoxWidget.cxx | 63 +++++++------------ src/debugger/gui/AtariVoxWidget.hxx | 21 ++++--- src/debugger/gui/SaveKeyWidget.cxx | 65 +++++++------------ src/debugger/gui/SaveKeyWidget.hxx | 19 +++--- src/emucore/MT24LC256.cxx | 35 ++++++++--- src/emucore/MT24LC256.hxx | 25 +++++++- src/windows/FlashWidget.cxx | 97 +++++++++++++++++++++++++++++ src/windows/FlashWidget.hxx | 64 +++++++++++++++++++ src/windows/Stella.vcxproj | 4 ++ src/windows/Stella.vcxproj.filters | 12 ++++ 10 files changed, 293 insertions(+), 112 deletions(-) create mode 100644 src/windows/FlashWidget.cxx create mode 100644 src/windows/FlashWidget.hxx diff --git a/src/debugger/gui/AtariVoxWidget.cxx b/src/debugger/gui/AtariVoxWidget.cxx index c1892b580..d3fe6e063 100644 --- a/src/debugger/gui/AtariVoxWidget.cxx +++ b/src/debugger/gui/AtariVoxWidget.cxx @@ -22,50 +22,31 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AtariVoxWidget::AtariVoxWidget(GuiObject* boss, const GUI::Font& font, int x, int y, Controller& controller) - : ControllerWidget(boss, font, x, y, controller) + : FlashWidget(boss, font, x, y, controller) { - bool leftport = myController.jack() == Controller::Left; - const string& label = leftport ? "Left (AtariVox)" : "Right (AtariVox)"; - - const int fontHeight = font.getFontHeight(), - lineHeight = font.getLineHeight(), - bwidth = font.getStringWidth("Erase EEPROM") + 20, - bheight = lineHeight + 4; - - int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (AtariVox)"); - StaticTextWidget* t; - - t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, - fontHeight, label, kTextAlignLeft); - - ypos += t->getHeight() + 20; - myEEPROMErase = - new ButtonWidget(boss, font, xpos+10, ypos, bwidth, bheight, - "Erase EEPROM", kEEPROMErase); - myEEPROMErase->setTarget(this); - ypos += lineHeight + 20; - - const GUI::Font& ifont = instance().frameBuffer().infoFont(); - lwidth = ifont.getMaxCharWidth() * 20; - new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, - fontHeight, "(*) This will erase", kTextAlignLeft); - ypos += lineHeight + 2; - new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, - fontHeight, "all EEPROM data, not", kTextAlignLeft); - ypos += lineHeight + 2; - new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, - fontHeight, "just the range used", kTextAlignLeft); - ypos += lineHeight + 2; - new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, - fontHeight, "for this ROM", kTextAlignLeft); + init(boss, font, x, y); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void AtariVoxWidget::handleCommand(CommandSender*, int cmd, int, int) +void AtariVoxWidget::eraseCurrent() { - if(cmd == kEEPROMErase) - { - AtariVox& avox = static_cast(myController); - avox.myEEPROM->erase(); - } + AtariVox& avox = static_cast(myController); + + avox.myEEPROM->eraseCurrent(); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void AtariVoxWidget::eraseAll() +{ + AtariVox& avox = static_cast(myController); + + avox.myEEPROM->eraseAll(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool AtariVoxWidget::isPageDetected() +{ + AtariVox& avox = static_cast(myController); + + return avox.myEEPROM->isPageDetected(); +} \ No newline at end of file diff --git a/src/debugger/gui/AtariVoxWidget.hxx b/src/debugger/gui/AtariVoxWidget.hxx index 4ad832ad7..bf5fbaba1 100644 --- a/src/debugger/gui/AtariVoxWidget.hxx +++ b/src/debugger/gui/AtariVoxWidget.hxx @@ -18,25 +18,26 @@ #ifndef ATARIVOX_WIDGET_HXX #define ATARIVOX_WIDGET_HXX -class ButtonWidget; - #include "Control.hxx" -#include "ControllerWidget.hxx" +#include "FlashWidget.hxx" -class AtariVoxWidget : public ControllerWidget +class AtariVoxWidget : public FlashWidget { public: AtariVoxWidget(GuiObject* boss, const GUI::Font& font, int x, int y, Controller& controller); virtual ~AtariVoxWidget() = default; - private: - ButtonWidget* myEEPROMErase; - enum { kEEPROMErase = 'eeER' }; - - private: + private: void loadConfig() override { } - void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + + string getName() + { + return "AtariVox"; + } + void eraseCurrent(); + void eraseAll(); + bool isPageDetected(); // Following constructors and assignment operators not supported AtariVoxWidget() = delete; diff --git a/src/debugger/gui/SaveKeyWidget.cxx b/src/debugger/gui/SaveKeyWidget.cxx index 02e903022..0e505e699 100644 --- a/src/debugger/gui/SaveKeyWidget.cxx +++ b/src/debugger/gui/SaveKeyWidget.cxx @@ -21,51 +21,32 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SaveKeyWidget::SaveKeyWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, Controller& controller) - : ControllerWidget(boss, font, x, y, controller) + int x, int y, Controller& controller) + : FlashWidget(boss, font, x, y, controller) { - bool leftport = myController.jack() == Controller::Left; - const string& label = leftport ? "Left (SaveKey)" : "Right (SaveKey)"; - - const int fontHeight = font.getFontHeight(), - lineHeight = font.getLineHeight(), - bwidth = font.getStringWidth("Erase EEPROM") + 20, - bheight = lineHeight + 4; - - int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (SaveKey)"); - StaticTextWidget* t; - - t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, - fontHeight, label, kTextAlignLeft); - - ypos += t->getHeight() + 20; - myEEPROMErase = - new ButtonWidget(boss, font, xpos+10, ypos, bwidth, bheight, - "Erase EEPROM", kEEPROMErase); - myEEPROMErase->setTarget(this); - ypos += lineHeight + 20; - - const GUI::Font& ifont = instance().frameBuffer().infoFont(); - lwidth = ifont.getMaxCharWidth() * 20; - new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, - fontHeight, "(*) This will erase", kTextAlignLeft); - ypos += lineHeight + 2; - new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, - fontHeight, "all EEPROM data, not", kTextAlignLeft); - ypos += lineHeight + 2; - new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, - fontHeight, "just the range used", kTextAlignLeft); - ypos += lineHeight + 2; - new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, - fontHeight, "for this ROM", kTextAlignLeft); + init(boss, font, x, y); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void SaveKeyWidget::handleCommand(CommandSender*, int cmd, int, int) +void SaveKeyWidget::eraseCurrent() { - if(cmd == kEEPROMErase) - { - SaveKey& skey = static_cast(myController); - skey.myEEPROM->erase(); - } + SaveKey& skey = static_cast(myController); + + skey.myEEPROM->eraseCurrent(); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void SaveKeyWidget::eraseAll() +{ + SaveKey& skey = static_cast(myController); + + skey.myEEPROM->eraseAll(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool SaveKeyWidget::isPageDetected() +{ + SaveKey& skey = static_cast(myController); + + return skey.myEEPROM->isPageDetected(); +} \ No newline at end of file diff --git a/src/debugger/gui/SaveKeyWidget.hxx b/src/debugger/gui/SaveKeyWidget.hxx index b4a55e5d1..ab35e17b7 100644 --- a/src/debugger/gui/SaveKeyWidget.hxx +++ b/src/debugger/gui/SaveKeyWidget.hxx @@ -18,25 +18,26 @@ #ifndef SAVEKEY_WIDGET_HXX #define SAVEKEY_WIDGET_HXX -class ButtonWidget; - #include "Control.hxx" -#include "ControllerWidget.hxx" +#include "FlashWidget.hxx" -class SaveKeyWidget : public ControllerWidget +class SaveKeyWidget : public FlashWidget { public: SaveKeyWidget(GuiObject* boss, const GUI::Font& font, int x, int y, Controller& controller); virtual ~SaveKeyWidget() = default; - private: - ButtonWidget* myEEPROMErase; - enum { kEEPROMErase = 'eeER' }; - private: void loadConfig() override { } - void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + + string getName() + { + return "SaveKey"; + } + void eraseCurrent(); + void eraseAll(); + bool isPageDetected(); // Following constructors and assignment operators not supported SaveKeyWidget() = delete; diff --git a/src/emucore/MT24LC256.cxx b/src/emucore/MT24LC256.cxx index 4f4305e2c..919195957 100644 --- a/src/emucore/MT24LC256.cxx +++ b/src/emucore/MT24LC256.cxx @@ -55,6 +55,7 @@ MT24LC256::MT24LC256(const string& filename, const System& system) myDataFile(filename), myDataFileExists(false), myDataChanged(false), + myPageDetected(false), jpee_mdat(0), jpee_sdat(0), jpee_mclk(0), @@ -74,10 +75,10 @@ MT24LC256::MT24LC256(const string& filename, const System& system) { // Get length of file; it must be 32768 in.seekg(0, std::ios::end); - if(uInt32(in.tellg()) == 32768u) + if(uInt32(in.tellg()) == FLASH_SIZE) { in.seekg(0, std::ios::beg); - in.read(reinterpret_cast(myData), 32768); + in.read(reinterpret_cast(myData), FLASH_SIZE); myDataFileExists = true; } } @@ -96,7 +97,7 @@ MT24LC256::~MT24LC256() { ofstream out(myDataFile, std::ios_base::binary); if(out.is_open()) - out.write(reinterpret_cast(myData), 32768); + out.write(reinterpret_cast(myData), FLASH_SIZE); } } @@ -149,27 +150,43 @@ void MT24LC256::systemReset() { myCyclesWhenSDASet = myCyclesWhenSCLSet = myCyclesWhenTimerSet = mySystem.cycles(); + + myPageDetected = false; + memset(myPageHit, false, sizeof(myPageHit)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void MT24LC256::erase() +void MT24LC256::eraseAll() { - memset(myData, 0xff, 32768); + memset(myData, INIT_VALUE, FLASH_SIZE); myDataChanged = true; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void MT24LC256::eraseCurrent() +{ + for(uInt32 page = 0; page < PAGE_NUM; page++) + { + if(myPageHit[page]) + { + memset(myData + page * PAGE_SIZE, INIT_VALUE, PAGE_SIZE); + myDataChanged = true; + } + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MT24LC256::jpee_init() { jpee_sdat = 1; jpee_address = 0; jpee_state=0; - jpee_sizemask = 32767; - jpee_pagemask = 63; + jpee_sizemask = FLASH_SIZE - 1; + jpee_pagemask = PAGE_SIZE - 1; jpee_smallmode = 0; jpee_logmode = -1; if(!myDataFileExists) - memset(myData, 0xff, 32768); + memset(myData, INIT_VALUE, FLASH_SIZE); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -226,6 +243,7 @@ void MT24LC256::jpee_data_stop() for (int i=3; igetHeight() + 8; + + myEEPROMEraseCurrent = + new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight, + "Erase EEPROM range", kEEPROMEraseCurrent); + myEEPROMEraseCurrent->setTarget(this); + + ypos += lineHeight + 8; + + const GUI::Font& ifont = instance().frameBuffer().infoFont(); + lwidth = ifont.getMaxCharWidth() * 20; + + new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, + fontHeight, "(*) Erases only the", kTextAlignLeft); + ypos += lineHeight + 2; + new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, + fontHeight, "current ROM's range", kTextAlignLeft); + ypos += lineHeight + 8; + + myEEPROMEraseAll = + new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight, + "Erase EEPROM", kEEPROMEraseAll); + myEEPROMEraseAll->setTarget(this); + ypos += lineHeight + 8; + + new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, + fontHeight, "(*) This will erase", kTextAlignLeft); + ypos += lineHeight + 2; + new StaticTextWidget(boss, ifont, xpos, ypos, lwidth, + fontHeight, "all EEPROM data!", kTextAlignLeft); + + updateButtonState(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FlashWidget::handleCommand(CommandSender*, int cmd, int, int) +{ + if(cmd == kEEPROMEraseAll) { + eraseAll(); + } + if(cmd == kEEPROMEraseCurrent) { + eraseCurrent(); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FlashWidget::drawWidget(bool hilite) +{ + updateButtonState(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FlashWidget::updateButtonState() +{ + myEEPROMEraseCurrent->setEnabled(isPageDetected()); +} \ No newline at end of file diff --git a/src/windows/FlashWidget.hxx b/src/windows/FlashWidget.hxx new file mode 100644 index 000000000..c9b72a037 --- /dev/null +++ b/src/windows/FlashWidget.hxx @@ -0,0 +1,64 @@ +//============================================================================ +// +// 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-2017 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 FLASH_WIDGET_HXX +#define FLASH_WIDGET_HXX + +class ButtonWidget; + +#include "Control.hxx" +#include "ControllerWidget.hxx" + +class FlashWidget : public ControllerWidget +{ +public: + FlashWidget(GuiObject* boss, const GUI::Font& font, int x, int y, + Controller& controller); + virtual ~FlashWidget() = default; + +protected: + void init(GuiObject* boss, const GUI::Font& font, int x, int y); + void drawWidget(bool hilite) override; + +private: + ButtonWidget* myEEPROMEraseAll; + ButtonWidget* myEEPROMEraseCurrent; + enum + { + kEEPROMEraseAll = 'eeER', + kEEPROMEraseCurrent = 'eeEC' + }; + +private: + void loadConfig() override {} + void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + void updateButtonState(); + + virtual string getName() = 0; + virtual void eraseCurrent() = 0; + virtual void eraseAll() = 0; + virtual bool isPageDetected() = 0; + + // Following constructors and assignment operators not supported + FlashWidget() = delete; + FlashWidget(const FlashWidget&) = delete; + FlashWidget(FlashWidget&&) = delete; + FlashWidget& operator=(const FlashWidget&) = delete; + FlashWidget& operator=(FlashWidget&&) = delete; +}; + +#endif diff --git a/src/windows/Stella.vcxproj b/src/windows/Stella.vcxproj index b07f88a65..15170444b 100644 --- a/src/windows/Stella.vcxproj +++ b/src/windows/Stella.vcxproj @@ -331,6 +331,7 @@ + @@ -489,6 +490,7 @@ + @@ -619,6 +621,7 @@ + @@ -782,6 +785,7 @@ + diff --git a/src/windows/Stella.vcxproj.filters b/src/windows/Stella.vcxproj.filters index ed00b4d3c..a0d426f29 100644 --- a/src/windows/Stella.vcxproj.filters +++ b/src/windows/Stella.vcxproj.filters @@ -840,6 +840,12 @@ Source Files + + Source Files + + + Source Files + @@ -1715,6 +1721,12 @@ Header Files + + Header Files + + + Header Files +