Refactored FlashWidget, SaveKeyWidget and AtariVoxWidget

This commit is contained in:
thrust26 2017-10-01 12:00:07 +02:00
parent f77cd9ab06
commit 4fe9317ad2
8 changed files with 26 additions and 92 deletions

View File

@ -35,22 +35,6 @@ void AtariVoxWidget::eraseCurrent()
avox.myEEPROM->eraseCurrent(); avox.myEEPROM->eraseCurrent();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AtariVoxWidget::eraseAll()
{
AtariVox& avox = static_cast<AtariVox&>(myController);
avox.myEEPROM->eraseAll();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AtariVoxWidget::isUseDetected()
{
AtariVox& avox = static_cast<AtariVox&>(myController);
return avox.myEEPROM->isUseDetected();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AtariVoxWidget::isPageUsed(int page) bool AtariVoxWidget::isPageUsed(int page)
{ {

View File

@ -29,8 +29,6 @@ class AtariVoxWidget : public FlashWidget
virtual ~AtariVoxWidget() = default; virtual ~AtariVoxWidget() = default;
private: private:
void loadConfig() override { }
void eraseCurrent(); void eraseCurrent();
void eraseAll(); void eraseAll();
bool isUseDetected(); bool isUseDetected();

View File

@ -35,22 +35,6 @@ void SaveKeyWidget::eraseCurrent()
skey.myEEPROM->eraseCurrent(); skey.myEEPROM->eraseCurrent();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SaveKeyWidget::eraseAll()
{
SaveKey& skey = static_cast<SaveKey&>(myController);
skey.myEEPROM->eraseAll();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SaveKeyWidget::isUseDetected()
{
SaveKey& skey = static_cast<SaveKey&>(myController);
return skey.myEEPROM->isUseDetected();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SaveKeyWidget::isPageUsed(int page) bool SaveKeyWidget::isPageUsed(int page)
{ {

View File

@ -29,8 +29,6 @@ class SaveKeyWidget : public FlashWidget
virtual ~SaveKeyWidget() = default; virtual ~SaveKeyWidget() = default;
private: private:
void loadConfig() override { }
void eraseCurrent(); void eraseCurrent();
void eraseAll(); void eraseAll();
bool isUseDetected(); bool isUseDetected();

View File

@ -55,7 +55,6 @@ MT24LC256::MT24LC256(const string& filename, const System& system)
myDataFile(filename), myDataFile(filename),
myDataFileExists(false), myDataFileExists(false),
myDataChanged(false), myDataChanged(false),
myUseDetected(false),
jpee_mdat(0), jpee_mdat(0),
jpee_sdat(0), jpee_sdat(0),
jpee_mclk(0), jpee_mclk(0),
@ -151,7 +150,6 @@ void MT24LC256::systemReset()
myCyclesWhenSDASet = myCyclesWhenSCLSet = myCyclesWhenTimerSet = myCyclesWhenSDASet = myCyclesWhenSCLSet = myCyclesWhenTimerSet =
mySystem.cycles(); mySystem.cycles();
myUseDetected = false;
memset(myPageHit, false, sizeof(myPageHit)); memset(myPageHit, false, sizeof(myPageHit));
} }
@ -252,7 +250,7 @@ void MT24LC256::jpee_data_stop()
for (int i=3; i<jpee_pptr; i++) for (int i=3; i<jpee_pptr; i++)
{ {
myDataChanged = true; myDataChanged = true;
myUseDetected = myPageHit[jpee_address / PAGE_SIZE] = true; myPageHit[jpee_address / PAGE_SIZE] = true;
myData[(jpee_address++) & jpee_sizemask] = jpee_packet[i]; myData[(jpee_address++) & jpee_sizemask] = jpee_packet[i];
if (!(jpee_address & jpee_pagemask)) if (!(jpee_address & jpee_pagemask))
break; /* Writes can't cross page boundary! */ break; /* Writes can't cross page boundary! */
@ -349,7 +347,7 @@ void MT24LC256::jpee_clock_fall()
break; break;
} }
jpee_state=3; jpee_state=3;
myUseDetected = myPageHit[jpee_address / PAGE_SIZE] = true; myPageHit[jpee_address / PAGE_SIZE] = true;
jpee_nb = (myData[jpee_address & jpee_sizemask] << 1) | 1; /* Fall through */ jpee_nb = (myData[jpee_address & jpee_sizemask] << 1) | 1; /* Fall through */
JPEE_LOG2("I2C_READ(%04X=%02X)",jpee_address,jpee_nb/2); JPEE_LOG2("I2C_READ(%04X=%02X)",jpee_address,jpee_nb/2);
[[fallthrough]]; [[fallthrough]];

View File

@ -66,9 +66,7 @@ class MT24LC256
/** Erase the pages used by the current ROM to known state ($FF) */ /** Erase the pages used by the current ROM to known state ($FF) */
void eraseCurrent(); void eraseCurrent();
/** Returns true if at least one EEPROM page has been detected for the current ROM */ /** Returns true if the page is used by the current ROM */
bool isUseDetected() const { return myUseDetected; }
bool isPageUsed(int page) const; bool isPageUsed(int page) const;
private: private:
@ -94,7 +92,6 @@ class MT24LC256
// Track which pages are used // Track which pages are used
bool myPageHit[PAGE_NUM]; bool myPageHit[PAGE_NUM];
bool myUseDetected;
// Cached state of the SDA and SCL pins on the last write // Cached state of the SDA and SCL pins on the last write
bool mySDA, mySCL; bool mySDA, mySCL;

View File

@ -49,46 +49,28 @@ void FlashWidget::init(GuiObject* boss, const GUI::Font& font, int x, int y)
ypos += lineHeight; ypos += lineHeight;
} }
/*myEEPROMEraseCurrent = new ButtonWidget(boss, font, xpos, ypos, xpos -= 8; ypos += 2;
"Erase EEPROM range", kEEPROMEraseCurrent); myEEPROMEraseCurrent = new ButtonWidget(boss, font, xpos, ypos,
"Erase used pages", kEEPROMEraseCurrent);
myEEPROMEraseCurrent->setTarget(this); myEEPROMEraseCurrent->setTarget(this);
ypos += lineHeight + 8;
new StaticTextWidget(boss, ifont, xpos, ypos, "(*) Erases only the");
ypos += iLineHeight;
new StaticTextWidget(boss, ifont, xpos, ypos, "current ROM's range");
ypos += iLineHeight + 8;
myEEPROMEraseAll = new ButtonWidget(boss, font, xpos, ypos,
myEEPROMEraseCurrent->getWidth(), myEEPROMEraseCurrent->getHeight(),
"Erase EEPROM", kEEPROMEraseAll);
myEEPROMEraseAll->setTarget(this);
ypos += lineHeight + 8;
new StaticTextWidget(boss, ifont, xpos, ypos, "(*) This will erase");
ypos += iLineHeight;
new StaticTextWidget(boss, ifont, xpos, ypos, "all EEPROM data!");
updateButtonState();*/
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FlashWidget::handleCommand(CommandSender*, int cmd, int, int) void FlashWidget::handleCommand(CommandSender*, int cmd, int, int)
{ {
if(cmd == kEEPROMEraseAll) {
eraseAll();
}
if(cmd == kEEPROMEraseCurrent) { if(cmd == kEEPROMEraseCurrent) {
eraseCurrent(); eraseCurrent();
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FlashWidget::drawWidget(bool hilite) // display the pages used by the current ROM and update erase button status
void FlashWidget::loadConfig()
{ {
int useCount = 0, startPage = -1; int useCount = 0, startPage = -1;
for(int page = 0; page < MT24LC256::PAGE_NUM; page++) for(int page = 0; page < MT24LC256::PAGE_NUM; page++)
{ {
if(isPageUsed(page)/* || page == 0x21 || page == 0x22*/) if(isPageUsed(page))
{ {
if (startPage == -1) if (startPage == -1)
startPage = page; startPage = page;
@ -104,7 +86,7 @@ void FlashWidget::drawWidget(bool hilite)
label.str(""); label.str("");
label << Common::Base::HEX3 << startPage; label << Common::Base::HEX3 << startPage;
if(page -1 != startPage) if(page - 1 != startPage)
label << "-" << Common::Base::HEX3 << page - 1; label << "-" << Common::Base::HEX3 << page - 1;
else else
label << " "; label << " ";
@ -118,11 +100,6 @@ void FlashWidget::drawWidget(bool hilite)
} }
} }
} }
//updateButtonState();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - myEEPROMEraseCurrent->setEnabled(useCount != 0);
void FlashWidget::updateButtonState()
{
//myEEPROMEraseCurrent->setEnabled(isUseDetected());
} }

View File

@ -32,28 +32,26 @@ public:
protected: protected:
void init(GuiObject* boss, const GUI::Font& font, int x, int y); void init(GuiObject* boss, const GUI::Font& font, int x, int y);
void drawWidget(bool hilite) override;
private: private:
ButtonWidget* myEEPROMEraseAll;
ButtonWidget* myEEPROMEraseCurrent; ButtonWidget* myEEPROMEraseCurrent;
enum enum { kEEPROMEraseCurrent = 'eeEC' };
{
kEEPROMEraseAll = 'eeER',
kEEPROMEraseCurrent = 'eeEC'
};
static constexpr uInt32 MAX_PAGES = 7; static constexpr uInt32 MAX_PAGES = 5;
StaticTextWidget* myPage[MAX_PAGES]; StaticTextWidget* myPage[MAX_PAGES];
private: private:
void loadConfig() override {} void loadConfig() override;
void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
void updateButtonState();
/**
Erase the EEPROM pages used by the current ROM
*/
virtual void eraseCurrent() = 0; virtual void eraseCurrent() = 0;
virtual void eraseAll() = 0;
virtual bool isUseDetected() = 0; /**
Check if a page is used by the current ROM
*/
virtual bool isPageUsed(int page) = 0; virtual bool isPageUsed(int page) = 0;
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported