Newbie2:
Any additional suggestions?
First, you should make sure that the cart gets erased properly.
So you could, for example, add while(1); into the function void writeFlash_GB:
delay(100);
println_Msg(F("Erasing flash"));
display_Update();// Erase flash
writeByte_GB(0x555, 0xaa);
writeByte_GB(0x2aa, 0x55);
writeByte_GB(0x555, 0x80);
writeByte_GB(0x555, 0xaa);
writeByte_GB(0x2aa, 0x55);
writeByte_GB(0x555, 0x10);dataIn_GB();
// Read the status register
byte statusReg = readByte_GB(0);// After a completed erase D7 will output 1
while ((statusReg & 0x80) != 0x80) {
// Blink led
PORTB ^= (1 << 4);
delay(100);
// Update Status
statusReg = readByte_GB(0);
}// Blankcheck
println_Msg(F("Blankcheck"));
display_Update();
to:
delay(100);
println_Msg(F("Erasing flash"));
display_Update();// Erase flash
writeByte_GB(0x555, 0xaa);
writeByte_GB(0x2aa, 0x55);
writeByte_GB(0x555, 0x80);
writeByte_GB(0x555, 0xaa);
writeByte_GB(0x2aa, 0x55);
writeByte_GB(0x555, 0x10);dataIn_GB();
// Read the status register
byte statusReg = readByte_GB(0);// After a completed erase D7 will output 1
while ((statusReg & 0x80) != 0x80) {
// Blink led
PORTB ^= (1 << 4);
delay(100);
// Update Status
statusReg = readByte_GB(0);
}// Blankcheck
println_Msg(F("Blankcheck"));
display_Update();
while(1);
The while(1); will make sure that after the erase nothing will be written to the cartridge. Then once "Blankcheck" is displayed you can switch the Cart Reader off and then on again and try to dump the cartridge and then check with a hex editor like HxD if the whole file you dumped consists out of 0xFF, meaning it erased fully.
If it did not erase then you need to change the code according to the datasheet of the used flashrom until it is erased.
If it is fully erased you can remove the while(1); again and write a rom to the cartridge, then dump the cartridge again and compare the dump in HxD to the file you wanted to write and see where exactly the writing failed.