Skip to content

Commit

Permalink
fixed chromadeck duo updi pull modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Dec 21, 2024
1 parent 37921f3 commit d5c294b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions VortexEngine/src/UPDI/updi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,18 @@

// the old duo header was embedded in the entire mode save
// so we have to load the whole modes
#define LEGACY_DUO_HEADER_SIZE 255
#define LEGACY_DUO_HEADER_SIZE_1 5
#define LEGACY_DUO_HEADER_SIZE_2 255


UPDI::StorageType UPDI::m_storageType = MODERN_STORAGE;
#endif

bool UPDI::init()
{
#ifdef VORTEX_EMBEDDED
m_storageType = MODERN_STORAGE;
#endif
return true;
}

Expand Down Expand Up @@ -109,15 +113,14 @@ bool UPDI::readHeader(ByteStream &header)
}
const uint32_t size = *(uint32_t *)ptr;
if (!size) {
Leds::holdAll(RGB_RED);
return false;
}
// more than 30 is old old duo where header is combined with save
if (size > 30) {
return readHeaderLegacy2(header);
}
// less than 20 is old duo where header is separate but smaller
if (size < 20) {
// less than 6 is old duo where header is separate but smaller (no build number)
if (size < 6) {
return readHeaderLegacy1(header);
}
// modern duo header is 27 total and separate from modes
Expand All @@ -127,7 +130,6 @@ bool UPDI::readHeader(ByteStream &header)
}
header.sanity();
if (!header.checkCRC()) {
Leds::holdAll(RGB_YELLOW);
header.clear();
ERROR_LOG("ERROR Header CRC Invalid!");
reset();
Expand All @@ -153,7 +155,7 @@ bool UPDI::readHeaderLegacy1(ByteStream &header)
// takes up about 17 bytes (12 + 5) of the start of the eeprom because
// it is contained in it's own ByteStream. Later on the size was increased
// by 10 bytes and 1 more of those bytes were used to store the build number
if (!header.init(5)) {
if (!header.init(LEGACY_DUO_HEADER_SIZE_1)) {
return false;
}
enterProgrammingMode();
Expand All @@ -165,7 +167,6 @@ bool UPDI::readHeaderLegacy1(ByteStream &header)
}
header.sanity();
if (!header.checkCRC()) {
Leds::holdAll(RGB_BLUE);
header.clear();
ERROR_LOG("ERROR Header CRC Invalid!");
reset();
Expand All @@ -187,7 +188,7 @@ bool UPDI::readHeaderLegacy2(ByteStream &header)
// didn't actually work and only 255 bytes were available causing a bad
// storage bug that erased modes. So this reads the entire storage even
// though we only need the header at the start
if (!header.init(255)) {
if (!header.init(LEGACY_DUO_HEADER_SIZE_2)) {
return false;
}
//enterProgrammingMode();
Expand All @@ -199,7 +200,6 @@ bool UPDI::readHeaderLegacy2(ByteStream &header)
}
header.sanity();
if (!header.checkCRC()) {
Leds::holdAll(RGB_PURPLE);
header.clear();
ERROR_LOG("ERROR Header CRC Invalid!");
reset();
Expand Down Expand Up @@ -255,6 +255,13 @@ bool UPDI::readMode(uint8_t idx, ByteStream &modeBuffer)
for (uint16_t i = 0; i < modeBuffer.rawSize(); ++i) {
ptr[i] = ldinc_b();
}
modeBuffer.sanity();
if (!modeBuffer.checkCRC()) {
modeBuffer.clear();
ERROR_LOG("ERROR Header CRC Invalid!");
reset();
return false;
}
#endif
return true;
}
Expand Down

0 comments on commit d5c294b

Please sign in to comment.