Skip to content

Commit

Permalink
Update FLASH.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
sanni committed Aug 9, 2024
1 parent dae03f8 commit e196335
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 64 deletions.
130 changes: 70 additions & 60 deletions Cart_Reader/FLASH.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2066,35 +2066,8 @@ void verifyFlash(byte currChip, byte totalChips, boolean reversed) {
if (openVerifyFlashFile()) {
blank = 0;

if ((currChip == 1) && (totalChips == 4)) {
if (reversed)
myFile.seekSet(4194304);
fileSize = 2097152;
} else if ((currChip == 2) && (totalChips == 4) && (fileSize > 6291456)) {
if (reversed)
myFile.seekSet(6291456);
fileSize = 2097152;
} else if ((currChip == 3) && (totalChips == 4)) {
if (reversed)
myFile.seekSet(0);
fileSize = 2097152;
} else if ((currChip == 4) && (totalChips == 4)) {
if (reversed)
myFile.seekSet(2097152);
fileSize = 2097152;
} else if ((currChip == 1) && (totalChips == 2)) {
if (reversed)
myFile.seekSet(4194304);
fileSize = 4194304;
} else if ((currChip == 2) && (totalChips == 2)) {
if (reversed)
myFile.seekSet(0);
fileSize = 4194304;
} else if ((currChip == 1) && (totalChips == 1)) {
if (reversed)
myFile.seekSet(4194304);
} else
fileSize = 0; // skip write
// Adjust filesize to fit flashchip
adjustFileSize(currChip, totalChips, reversed);

//Initialize progress bar
uint32_t processedProgressBar = 0;
Expand Down Expand Up @@ -2884,6 +2857,72 @@ void identifyCFI_Flash() {
display_Update();
}

// Adjust file size to fit flash chip
void adjustFileSize(byte currChip, byte totalChips, boolean reversed) {
// 1 flash chip
if ((currChip == 1) && (totalChips == 1) && reversed) {
myFile.seekSet(4194304);
}
// 2 flash chips
else if ((currChip == 1) && (totalChips == 2)) {
if (fileSize > flashSize / 2)
fileSize = flashSize / 2;
} else if ((currChip == 2) && (totalChips == 2) && (fileSize > flashSize / 2)) {
fileSize = fileSize - flashSize / 2;
myFile.seekSet(flashSize / 2);
}

// 4*2MB
else if ((currChip == 1) && (totalChips == 4)) {
if (reversed)
myFile.seekSet(4194304);
if (fileSize > 2097152)
fileSize = 2097152;

} else if ((currChip == 2) && (totalChips == 4)) {
if (reversed) {
if (fileSize > 6291456) {
myFile.seekSet(6291456);
fileSize = 2097152;
} else
fileSize = 0;
} else {
if (fileSize > 2097152) {
myFile.seekSet(2097152);
fileSize = 2097152;
} else
fileSize = 0;
}

} else if ((currChip == 3) && (totalChips == 4)) {
if (reversed) {
myFile.seekSet(0);
fileSize = 2097152;
} else {
if (fileSize > 4194304) {
myFile.seekSet(4194304);
fileSize = 2097152;
} else
fileSize = 0;
}

} else if ((currChip == 4) && (totalChips == 4)) {
if (reversed) {
myFile.seekSet(2097152);
fileSize = 2097152;
} else {
if (fileSize > 6291456) {
myFile.seekSet(6291456);
fileSize = 2097152;
} else
fileSize = 0;
}
}
// skip write
else
fileSize = 0;
}

// Write flashrom
void writeCFI_Flash(byte currChip, byte totalChips, boolean reversed) {
if (openFileOnSD()) {
Expand Down Expand Up @@ -2931,37 +2970,8 @@ void writeCFI_Flash(byte currChip, byte totalChips, boolean reversed) {
print_Msg(currChip);
print_Msg(F("/"));
println_Msg(totalChips);

if ((currChip == 1) && (totalChips == 4)) {
if (reversed)
myFile.seekSet(4194304);
fileSize = 2097152;
} else if ((currChip == 2) && (totalChips == 4) && (fileSize > 6291456)) {
if (reversed)
myFile.seekSet(6291456);
fileSize = 2097152;
} else if ((currChip == 3) && (totalChips == 4)) {
if (reversed)
myFile.seekSet(0);
fileSize = 2097152;
} else if ((currChip == 4) && (totalChips == 4)) {
if (reversed)
myFile.seekSet(2097152);
fileSize = 2097152;
} else if ((currChip == 1) && (totalChips == 2)) {
if (reversed)
myFile.seekSet(4194304);
fileSize = 4194304;
} else if ((currChip == 2) && (totalChips == 2)) {
if (reversed)
myFile.seekSet(0);
fileSize = 4194304;
} else if ((currChip == 1) && (totalChips == 1)) {
if (reversed)
myFile.seekSet(4194304);
} else
fileSize = 0; // skip write

// Adjust filesize to fit flashchip
adjustFileSize(currChip, totalChips, reversed);
display_Update();

//Initialize progress bar
Expand Down
8 changes: 4 additions & 4 deletions Cart_Reader/SNES.ino
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ static const char reproCFIItem5[] PROGMEM = "4x 2MB";
static const char reproCFIItem6[] PROGMEM = "1x 8MB";
static const char* const menuOptionsReproCFI[] PROGMEM = { reproCFIItem1, reproCFIItem2, reproCFIItem3, reproCFIItem4, reproCFIItem5, reproCFIItem6, FSTRING_RESET };

// EX ROM config
static const char reproEXItem1[] PROGMEM = "standard (CDAB)";
static const char reproEXItem2[] PROGMEM = "in-order (ABCD)";
// ROM file order
static const char reproEXItem1[] PROGMEM = "ExROM (CDAB)";
static const char reproEXItem2[] PROGMEM = "standard (ABCD)";
static const char* const menuOptionsReproEX[] PROGMEM = { reproEXItem1, reproEXItem2, FSTRING_RESET };

void setupCFI() {
Expand All @@ -98,7 +98,7 @@ boolean reproEXMenu() {
unsigned char snsReproEX;
// Copy menuOptions out of progmem
convertPgm(menuOptionsReproEX, 3);
snsReproEX = question_box(F("ExROM file order"), menuOptions, 3, 0);
snsReproEX = question_box(F("ROM file order"), menuOptions, 3, 0);

// wait for user choice to come back from the question box menu
switch (snsReproEX) {
Expand Down

0 comments on commit e196335

Please sign in to comment.