GBA: Fix Blankcheck function

This commit is contained in:
sanni 2024-07-09 13:50:26 +02:00
parent e0d4da6947
commit c56ced2264

View File

@ -1985,7 +1985,7 @@ void idFlashrom_GBA() {
} }
// F0088H0 // F0088H0
else if (flashid == 0x8812) { else if (flashid == 0x8812) {
cartSize = 0x1000000; cartSize = 0x10000000;
} else { } else {
// Send swapped MX29GL128E/MSP55LV128 ID command to flashrom // Send swapped MX29GL128E/MSP55LV128 ID command to flashrom
writeWord_GAB(0xAAA, 0xAA); writeWord_GAB(0xAAA, 0xAA);
@ -2023,18 +2023,21 @@ void idFlashrom_GBA() {
} }
boolean blankcheckFlashrom_GBA() { boolean blankcheckFlashrom_GBA() {
for (unsigned long currSector = 0; currSector < fileSize; currSector += 0x20000) { boolean blank = 1;
// Blink led
blinkLED();
for (unsigned long currByte = 0; currByte < 0x20000; currByte += 2) { for (unsigned long currByte = 0; currByte < fileSize; currByte += 2) {
if (readWord_GBA(currSector + currByte) != 0xFFFF) { // Check if all bytes are 0xFFFF
if (readWord_GBA(currByte) != 0xFFFF) {
currByte = fileSize;
blank = 0;
}
}
if (blank) {
return 1;
} else {
return 0; return 0;
} }
} }
}
return 1;
}
void eraseIntel4000_GBA() { void eraseIntel4000_GBA() {
// If the game is smaller than 16Mbit only erase the needed blocks // If the game is smaller than 16Mbit only erase the needed blocks
@ -2205,12 +2208,7 @@ void eraseIntel4400_GBA() {
} }
void eraseF0088H0_GBA() { void eraseF0088H0_GBA() {
// If the game is smaller than 16Mbit only erase the needed blocks for (unsigned long currBlock = 0; currBlock < fileSize; currBlock += 0x40000) {
unsigned long lastBlock = 0xFFFFFF;
if (fileSize < 0xFFFFFF)
lastBlock = fileSize;
for (unsigned long currBlock = 0; currBlock < lastBlock; currBlock += 0x40000) {
// Unlock Block // Unlock Block
writeWord_GBA(currBlock, 0x60); writeWord_GBA(currBlock, 0x60);
writeWord_GBA(currBlock, 0xD0); writeWord_GBA(currBlock, 0xD0);
@ -2324,47 +2322,67 @@ void writeIntel4000_GBA() {
} }
void writeF0088H0_GBA() { void writeF0088H0_GBA() {
byte sdBuffer[1024]; byte writeBuffer[1024];
//Initialize progress bar //Initialize progress bar
uint32_t processedProgressBar = 0; uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = fileSize; uint32_t totalProgressBar = fileSize;
draw_progressbar(0, totalProgressBar); draw_progressbar(0, totalProgressBar);
for (unsigned long currBlock = 0; currBlock < fileSize; currBlock += 0x40000) { // 32MB max GBA bank size
for (unsigned long currBank = 0; currBank < fileSize; currBank += 0x2000000) {
// 4MB minimum repro block size
for (unsigned long currBlock = 0; currBlock < 0x2000000; currBlock += 0x400000) {
// 256KB flashrom sector size
for (unsigned long currSector = 0; currSector < 0x400000; currSector += 0x40000) {
// Unlock Sector
writeWord_GBA(currBlock + currSector, 0x60);
writeWord_GBA(currBlock + currSector, 0xD0);
// Blink led // Blink led
blinkLED(); blinkLED();
// Write to flashrom // 1024B writeBuffer
for (unsigned long currSdBuffer = 0; currSdBuffer < 0x40000; currSdBuffer += 1024) { for (unsigned long currWriteBuffer = 0; currWriteBuffer < 0x40000; currWriteBuffer += 1024) {
// Fill SD buffer // Fill writeBuffer from SD card
myFile.read(sdBuffer, 1024); myFile.read(writeBuffer, 1024);
// Buffered program command // Buffered program command
writeWord_GBA(currBlock + currSdBuffer, 0xEA); writeWord_GBA(currBlock + currSector + currWriteBuffer, 0xEA);
// Write word count (minus 1)
writeWord_GBA(currBlock + currSdBuffer, 0x1FF);
// Write buffer // Check Status register
word statusReg = readWord_GBA(currBlock + currSector + currWriteBuffer);
while ((statusReg | 0xFF7F) != 0xFFFF) {
statusReg = readWord_GBA(currBlock + currSector + currWriteBuffer);
}
// Write word count (minus 1)
writeWord_GBA(currBlock + currSector + currWriteBuffer, 0x1FF);
// Send writeBuffer to flashrom
for (word currByte = 0; currByte < 1024; currByte += 2) { for (word currByte = 0; currByte < 1024; currByte += 2) {
// Join two bytes into one word // Join two bytes into one word
word currWord = ((sdBuffer[currByte + 1] & 0xFF) << 8) | (sdBuffer[currByte] & 0xFF); word currWord = ((writeBuffer[currByte + 1] & 0xFF) << 8) | (writeBuffer[currByte] & 0xFF);
writeWord_GBA(currBlock + currSdBuffer + currByte, currWord); writeWord_GBA(currBlock + currSector + currWriteBuffer + currByte, currWord);
} }
// Write buffer to flash // Write buffer to flash
writeWord_GBA(currBlock + currSdBuffer + 1022, 0xD0); writeWord_GBA(currBlock + currSector + currWriteBuffer + 1022, 0xD0);
// Read the status register at last written address // Read the status register at last written address
word statusReg = readWord_GBA(currBlock + currSdBuffer + 1022); statusReg = readWord_GBA(currBlock + currSector + currWriteBuffer + 1022);
while ((statusReg | 0xFF7F) != 0xFFFF) { while ((statusReg | 0xFF7F) != 0xFFFF) {
statusReg = readWord_GBA(currBlock + currSdBuffer + 1022); statusReg = readWord_GBA(currBlock + currSector + currWriteBuffer + 1022);
} }
} }
processedProgressBar += 0x40000; processedProgressBar += 0x40000;
draw_progressbar(processedProgressBar, totalProgressBar); draw_progressbar(processedProgressBar, totalProgressBar);
} }
} }
}
}
void writeMSP55LV128_GBA() { void writeMSP55LV128_GBA() {
for (unsigned long currSector = 0; currSector < fileSize; currSector += 0x10000) { for (unsigned long currSector = 0; currSector < fileSize; currSector += 0x10000) {
@ -2570,7 +2588,16 @@ void flashRepro_GBA() {
} else if (flashid == 0x8812) { } else if (flashid == 0x8812) {
println_Msg(F("Erasing...")); println_Msg(F("Erasing..."));
display_Update(); display_Update();
// Set flash bank
writeByte_GBA(0x2, 0x0);
// Offset within bank
writeByte_GBA(0x3, 0x0);
// Size
writeByte_GBA(0x4, 0x20);
delay(500);
setROM_GBA();
eraseF0088H0_GBA(); eraseF0088H0_GBA();
// Reset or blankcheck will fail
resetF0088H0_GBA(); resetF0088H0_GBA();
} else if (flashid == 0x227E) { } else if (flashid == 0x227E) {
//if (sectorCheckMX29GL128E_GBA()) { //if (sectorCheckMX29GL128E_GBA()) {
@ -2589,17 +2616,16 @@ void flashRepro_GBA() {
} }
//} //}
} }
/* Skip blankcheck to save time
print_Msg(F("Blankcheck...")); print_Msg(F("Blankcheck..."));
display_Update(); display_Update();
if (blankcheckFlashrom_GBA()) { if (blankcheckFlashrom_GBA()) {
println_Msg(FS(FSTRING_OK)); println_Msg(FS(FSTRING_OK));
*/
//Write flashrom //Write flashrom
print_Msg(F("Writing ")); print_Msg(F("Writing "));
println_Msg(filePath); println_Msg(filePath);
display_Update(); display_Update();
if ((flashid == 0x8802) || (flashid == 0x8816)) { if ((flashid == 0x8802) || (flashid == 0x8816)) {
writeIntel4000_GBA(); writeIntel4000_GBA();
} else if (flashid == 0x8812) { } else if (flashid == 0x8812) {
@ -2645,12 +2671,9 @@ void flashRepro_GBA() {
} else { } else {
print_FatalError(F("ERROR")); print_FatalError(F("ERROR"));
} }
/* Skipped blankcheck } else {
}
else {
print_FatalError(F("failed")); print_FatalError(F("failed"));
} }
*/
} else { } else {
print_FatalError(open_file_STR); print_FatalError(open_file_STR);
} }