Skip to content

Commit

Permalink
N64: Add error message if eeprom does not return data
Browse files Browse the repository at this point in the history
Should prevent problem as described in discussion #857
  • Loading branch information
sanni committed Oct 17, 2023
1 parent 2e72842 commit 029c33d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Cart_Reader/N64.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,7 @@ void writeEeprom() {
}
}

void readEepromPageList(byte* output, byte page_number, byte page_count) {
boolean readEepromPageList(byte* output, byte page_number, byte page_count) {
byte command[] = { 0x04, page_number };

// Disable interrupts for more uniform clock pulses
Expand All @@ -2267,7 +2267,12 @@ void readEepromPageList(byte* output, byte page_number, byte page_count) {
noInterrupts();
sendJoyBus(command, sizeof(command));
// XXX: is it possible to read more than 8 bytes at a time ?
recvJoyBus(output, 8);
if (recvJoyBus(output, 8) > 0) {
// If any missing bytes error out
interrupts();
return 0;
break;
}
interrupts();

if (page_count)
Expand All @@ -2276,6 +2281,7 @@ void readEepromPageList(byte* output, byte page_number, byte page_count) {
command[1]++;
output += 8;
}
return 1;
}

// Dump Eeprom to SD
Expand All @@ -2300,14 +2306,19 @@ void readEeprom() {
}

for (int i = 0; i < eepPages; i += sizeof(sdBuffer) / 8) {
readEepromPageList(sdBuffer, i, sizeof(sdBuffer) / 8);
// If any missing bytes error out
if (readEepromPageList(sdBuffer, i, sizeof(sdBuffer) / 8) == 0) {
println_Msg(F(""));
print_STR(error_STR, 0);
println_Msg(F("no data received"));
println_Msg(F(""));
break;
}
// Write 64 pages at once to the SD card
myFile.write(sdBuffer, sizeof(sdBuffer));
}
// Close the file:
myFile.close();
//clear the screen
display_Clear();
print_Msg(F("Saved to "));
print_Msg(folder);
println_Msg(F("/"));
Expand Down

0 comments on commit 029c33d

Please sign in to comment.