Skip to content
18 changes: 11 additions & 7 deletions VortexEngine/src/Modes/Modes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void Modes::play()
// full save/load to/from buffer
bool Modes::saveToBuffer(ByteStream &modesBuffer)
{
// first write out the header
if (!serializeSaveHeader(modesBuffer)) {
return false;
}
Expand Down Expand Up @@ -142,10 +141,20 @@ bool Modes::saveHeader()
if (!serializeSaveHeader(headerBuffer)) {
return false;
}
// serialize the number of modes
// the number of modes
if (!headerBuffer.serialize8(m_numModes)) {
return false;
}
// only on the duo just save some extra stuff to the header slot
#ifdef VORTEX_EMBEDDED
// Duo also saves the build number to the save header so the chromalink can
// read it out, other devices just have the version hardcoded into their
// editor connection hello message. Don't do this in VortexLib because
// it will alter the savefile format and break compatibility
if (!headerBuffer.serialize8((uint8_t)VORTEX_BUILD_NUMBER)) {
return false;
}
#endif
if (!Storage::write(0, headerBuffer)) {
return false;
}
Expand Down Expand Up @@ -267,8 +276,6 @@ bool Modes::serializeSaveHeader(ByteStream &saveBuffer)
if (!VortexEngine::serializeVersion(saveBuffer)) {
return false;
}
// NOTE: instead of global brightness the duo uses this to store the
// startup mode ID. The duo doesn't offer a global brightness option
if (!saveBuffer.serialize8(m_globalFlags)) {
return false;
}
Expand Down Expand Up @@ -303,9 +310,6 @@ bool Modes::unserializeSaveHeader(ByteStream &saveHeader)
ERROR_LOGF("Incompatible savefile version: %u.%u", major, minor);
return false;
}
// NOTE: instead of global brightness the duo uses this to store the
// startup mode ID. The duo doesn't offer a global brightness option
// unserialize the global brightness
if (!saveHeader.unserialize8(&m_globalFlags)) {
return false;
}
Expand Down
11 changes: 8 additions & 3 deletions VortexEngine/src/Storage/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ std::string Storage::m_storageFilename;
// The position of the flash storage is right before the end of the flash, as long
// as the program leaves 256 bytes of space at the end of flash then this will fit
#define FLASH_STORAGE_SPACE ((volatile uint8_t *)(0x10000 - FLASH_STORAGE_SIZE))

// 12 for the serialbuffer header + 5 for the actual header data
#define STORAGE_HEADER_SIZE 17
// The header is max 15 bytes big, this is decided by the MAX_MODE_SIZE being
// 76, since there's only 256 bytes in the eeprom that leaves exactly 27 bytes
// leftover after packing 3x modes. Out of the 27 bytes 12 is the ByteStream
// header leaving 15 for the max header size. Of the 15 only 7 bytes are really
// being used and the rest are extra bytes reserved for future use
#define HEADER_SIZE 15
// The full header size includes the 12 bytes for the serialbuffer header
#define STORAGE_HEADER_SIZE (HEADER_SIZE + 12)

uint32_t Storage::m_lastSaveSize = 0;

Expand Down