GBA: Add bank mapping to F0088H0 repro

This commit is contained in:
sanni 2024-07-10 23:03:40 +02:00
parent 0a3ca11dfb
commit 8cf9bc6a99

View File

@ -2207,22 +2207,36 @@ void eraseIntel4400_GBA() {
} }
void eraseF0088H0_GBA() { void eraseF0088H0_GBA() {
for (unsigned long currBlock = 0; currBlock < fileSize; currBlock += 0x40000) { //Initialize progress bar
// Unlock Block uint32_t processedProgressBar = 0;
writeWord_GBA(currBlock, 0x60); uint32_t totalProgressBar = (uint32_t)fileSize;
writeWord_GBA(currBlock, 0xD0); draw_progressbar(0, totalProgressBar);
// Erase Command // 4MB repro block size
writeWord_GBA(currBlock, 0x20); for (unsigned long currBlock = 0; currBlock < fileSize; currBlock += 0x400000) {
writeWord_GBA(currBlock, 0xD0); mapBlockF0088H0_GBA(currBlock / 1024 / 1024);
// Read the status register // 256KB flashrom sector size
word statusReg = readWord_GBA(currBlock); for (unsigned long currSector = 0; currSector < 0x400000; currSector += 0x40000) {
while ((statusReg | 0xFF7F) != 0xFFFF) { // Unlock Sector
statusReg = readWord_GBA(currBlock); writeWord_GBA(currBlock + currSector, 0x60);
writeWord_GBA(currBlock + currSector, 0xD0);
// Erase Command
writeWord_GBA(currBlock + currSector, 0x20);
writeWord_GBA(currBlock + currSector, 0xD0);
// Read the status register
word statusReg = readWord_GBA(currBlock + currSector);
while ((statusReg | 0xFF7F) != 0xFFFF) {
statusReg = readWord_GBA(currBlock + currSector);
}
// Blink led
blinkLED();
} }
// Blink led // update progress bar
blinkLED(); processedProgressBar += 0x400000;
draw_progressbar(processedProgressBar, totalProgressBar);
} }
} }
@ -2320,6 +2334,22 @@ void writeIntel4000_GBA() {
} }
} }
void mapBlockF0088H0_GBA(u32 offset) {
// Taken from gbabf
u32 chipAddr = (offset / 32 * 0x10000000) + (0x4000C0 + (offset & 31) * 0x20202);
union {
u32 addr;
u8 byte[4];
} addr;
addr.addr = chipAddr;
writeByte_GBA(0x2, addr.byte[3]);
writeByte_GBA(0x3, addr.byte[2]);
writeByte_GBA(0x4, addr.byte[1]);
delay(100);
setROM_GBA();
}
void writeF0088H0_GBA() { void writeF0088H0_GBA() {
byte writeBuffer[1024]; byte writeBuffer[1024];
@ -2337,6 +2367,8 @@ void writeF0088H0_GBA() {
// 4MB minimum repro block size // 4MB minimum repro block size
for (unsigned long currBlock = 0; currBlock < lastBlock; currBlock += 0x400000) { for (unsigned long currBlock = 0; currBlock < lastBlock; currBlock += 0x400000) {
// Set-up 369-in-1 mapper
mapBlockF0088H0_GBA((currBank + currBlock) / 1024 / 1024);
// 256KB flashrom sector size // 256KB flashrom sector size
for (unsigned long currSector = 0; currSector < 0x400000; currSector += 0x40000) { for (unsigned long currSector = 0; currSector < 0x400000; currSector += 0x40000) {
@ -2591,14 +2623,6 @@ 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 // Reset or blankcheck will fail
resetF0088H0_GBA(); resetF0088H0_GBA();
@ -2620,33 +2644,33 @@ void flashRepro_GBA() {
//} //}
} }
print_Msg(F("Blankcheck...")); //print_Msg(F("Blankcheck..."));
//display_Update();
//if (blankcheckFlashrom_GBA()) {
//println_Msg(FS(FSTRING_OK));
//Write flashrom
print_Msg(F("Writing "));
println_Msg(filePath);
display_Update(); display_Update();
if (blankcheckFlashrom_GBA()) {
println_Msg(FS(FSTRING_OK));
//Write flashrom
print_Msg(F("Writing "));
println_Msg(filePath);
display_Update();
if ((flashid == 0x8802) || (flashid == 0x8816)) { if ((flashid == 0x8802) || (flashid == 0x8816)) {
writeIntel4000_GBA(); writeIntel4000_GBA();
} else if (flashid == 0x8812) { } else if (flashid == 0x8812) {
writeF0088H0_GBA(); writeF0088H0_GBA();
} else if (flashid == 0x227E) { } else if (flashid == 0x227E) {
if ((romType == 0xC2) || (romType == 0x89) || (romType == 0x20)) { if ((romType == 0xC2) || (romType == 0x89) || (romType == 0x20)) {
//MX29GL128E (0xC2) //MX29GL128E (0xC2)
//PC28F256M29 (0x89) //PC28F256M29 (0x89)
writeMX29GL128E_GBA(); writeMX29GL128E_GBA();
} else if ((romType == 0x1) || (romType == 0x4)) { } else if ((romType == 0x1) || (romType == 0x4)) {
//MSP55LV128(N) //MSP55LV128(N)
writeMSP55LV128_GBA(); writeMSP55LV128_GBA();
}
} }
}
// Close the file: // Close the file:
myFile.close(); myFile.close();
if (flashid != 0x8812) {
// Verify // Verify
print_STR(verifying_STR, 0); print_STR(verifying_STR, 0);
display_Update(); display_Update();
@ -2674,9 +2698,10 @@ void flashRepro_GBA() {
} else { } else {
print_FatalError(F("ERROR")); print_FatalError(F("ERROR"));
} }
} else {
print_FatalError(F("failed"));
} }
//} else {
// print_FatalError(F("failed"));
//}
} else { } else {
print_FatalError(open_file_STR); print_FatalError(open_file_STR);
} }