diff --git a/src/emucore/MT24LC256.cxx b/src/emucore/MT24LC256.cxx index 15cbfae96..ba6d2348b 100644 --- a/src/emucore/MT24LC256.cxx +++ b/src/emucore/MT24LC256.cxx @@ -50,18 +50,28 @@ MT24LC256::MT24LC256(const FilesystemNode& eepromfile, const System& system, myDataFile(eepromfile) { // Load the data from an external file (if it exists) + bool fileValid = false; try { - // Get length of file; it must be 32768 + // A valid file must be 32768 bytes; otherwise we create a new one if(myDataFile.read(myData) == FLASH_SIZE) - myDataFileExists = true; + fileValid = true; } catch(...) { - myDataFileExists = false; - myData = make_unique(FLASH_SIZE); + fileValid = false; } + if(!fileValid) + { + // Work around a bug in XCode 11.2 with -O0 and -O1 + const uInt8 initialValue = INITIAL_VALUE; + + myData = make_unique(FLASH_SIZE); + std::fill_n(myData.get(), FLASH_SIZE, initialValue); + myDataChanged = true; + } + // Then initialize the I2C state jpee_init(); @@ -72,7 +82,7 @@ MT24LC256::MT24LC256(const FilesystemNode& eepromfile, const System& system, MT24LC256::~MT24LC256() { // Save EEPROM data to external file only when necessary - if(!myDataFileExists || myDataChanged) + if(myDataChanged) { try { myDataFile.write(myData, FLASH_SIZE); } catch(...) { } @@ -167,9 +177,6 @@ bool MT24LC256::isPageUsed(uInt32 page) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MT24LC256::jpee_init() { - // Work around a bug in XCode 11.2 with -O0 and -O1 - const uInt8 initialValue = INITIAL_VALUE; - jpee_sdat = 1; jpee_address = 0; jpee_state=0; @@ -177,8 +184,6 @@ void MT24LC256::jpee_init() jpee_pagemask = PAGE_SIZE - 1; jpee_smallmode = 0; jpee_logmode = -1; - if(!myDataFileExists) - std::fill_n(myData.get(), FLASH_SIZE, initialValue); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/MT24LC256.hxx b/src/emucore/MT24LC256.hxx index 6f51dea26..56c1bf804 100644 --- a/src/emucore/MT24LC256.hxx +++ b/src/emucore/MT24LC256.hxx @@ -113,9 +113,6 @@ class MT24LC256 // The file containing the EEPROM data FilesystemNode myDataFile; - // Indicates if a valid EEPROM data file exists/was successfully loaded - bool myDataFileExists{false}; - // Indicates if the EEPROM has changed since class invocation bool myDataChanged{false};