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();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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)
{

View File

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

View File

@ -35,22 +35,6 @@ void SaveKeyWidget::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)
{

View File

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

View File

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

View File

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

View File

@ -38,7 +38,7 @@ void FlashWidget::init(GuiObject* boss, const GUI::Font& font, int x, int y)
ypos += lineHeight + 6;
new StaticTextWidget(boss, ifont, xpos, ypos, "Pages/Ranges used:");
ypos += lineHeight + 2;
xpos += 8;
@ -48,47 +48,29 @@ void FlashWidget::init(GuiObject* boss, const GUI::Font& font, int x, int y)
page ? " " : "none ");
ypos += lineHeight;
}
/*myEEPROMEraseCurrent = new ButtonWidget(boss, font, xpos, ypos,
"Erase EEPROM range", kEEPROMEraseCurrent);
xpos -= 8; ypos += 2;
myEEPROMEraseCurrent = new ButtonWidget(boss, font, xpos, ypos,
"Erase used pages", kEEPROMEraseCurrent);
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)
{
if(cmd == kEEPROMEraseAll) {
eraseAll();
}
if(cmd == kEEPROMEraseCurrent) {
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;
for(int page = 0; page < MT24LC256::PAGE_NUM; page++)
{
if(isPageUsed(page)/* || page == 0x21 || page == 0x22*/)
if(isPageUsed(page))
{
if (startPage == -1)
startPage = page;
@ -104,7 +86,7 @@ void FlashWidget::drawWidget(bool hilite)
label.str("");
label << Common::Base::HEX3 << startPage;
if(page -1 != startPage)
if(page - 1 != startPage)
label << "-" << Common::Base::HEX3 << page - 1;
else
label << " ";
@ -118,11 +100,6 @@ void FlashWidget::drawWidget(bool hilite)
}
}
}
//updateButtonState();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FlashWidget::updateButtonState()
{
//myEEPROMEraseCurrent->setEnabled(isUseDetected());
myEEPROMEraseCurrent->setEnabled(useCount != 0);
}

View File

@ -32,28 +32,26 @@ public:
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'
};
enum { kEEPROMEraseCurrent = 'eeEC' };
static constexpr uInt32 MAX_PAGES = 7;
static constexpr uInt32 MAX_PAGES = 5;
StaticTextWidget* myPage[MAX_PAGES];
private:
void loadConfig() override {}
void loadConfig() 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 eraseAll() = 0;
virtual bool isUseDetected() = 0;
/**
Check if a page is used by the current ROM
*/
virtual bool isPageUsed(int page) = 0;
// Following constructors and assignment operators not supported