Skip to content

Commit

Permalink
Change N64 timings
Browse files Browse the repository at this point in the history
Seems to more reliable read SRAM with some delays removed.
  • Loading branch information
sanni committed Aug 11, 2024
1 parent 19514f6 commit afade35
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cart_Reader/Cart_Reader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
This project represents a community-driven effort to provide
an easy to build and easy to modify cartridge dumper.
Date: 2024-08-02
Version: 14.1
Date: 2024-08-11
Version: 14.2
SD lib: https://github.com/greiman/SdFat
LCD lib: https://github.com/olikraus/u8g2
Expand Down
53 changes: 23 additions & 30 deletions Cart_Reader/N64.ino
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,7 @@ void setAddress_N64(unsigned long myAddress) {

// Switch WR(PH5) RD(PH6) ale_L(PC0) ale_H(PC1) to high (since the pins are active low)
PORTH |= (1 << 5) | (1 << 6);
PORTC |= (1 << 1);
__asm__("nop\n\t");
PORTC |= (1 << 0);
PORTC |= (1 << 0) | (1 << 1);

// Output high part to address pins
PORTF = myAdrHighOut & 0xFF;
Expand All @@ -561,18 +559,6 @@ void setAddress_N64(unsigned long myAddress) {
// Pull ale_L(PC0) low
PORTC &= ~(1 << 0);

// Wait ~600ns just to be sure address is set
__asm__("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t");

// Set data pins to input
adIn_N64();
}
Expand All @@ -595,8 +581,6 @@ word readWord_N64() {
// Pull read(PH6) high
PORTH |= (1 << 6);

// Wait 62.5ns
__asm__("nop\n\t");
return tempWord;
}

Expand Down Expand Up @@ -2184,6 +2168,8 @@ void idCart() {
sdBuffer[c] = hiByte;
sdBuffer[c + 1] = loByte;
}
// Pull ale_H(PC1) high
PORTC |= (1 << 1);

// CRC1
sprintf(checksumStr, "%02X%02X%02X%02X", sdBuffer[0x10], sdBuffer[0x11], sdBuffer[0x12], sdBuffer[0x13]);
Expand Down Expand Up @@ -2409,6 +2395,7 @@ void writeSram(unsigned long sramSize) {

// Read sram and save to the SD card
void readSram(unsigned long sramSize, byte flashramType) {
word myWord;
int offset = 512;
int bufferSize = 512;
if (flashramType == 2) {
Expand All @@ -2435,23 +2422,17 @@ void readSram(unsigned long sramSize, byte flashramType) {
setAddress_N64(currByte);

for (int c = 0; c < bufferSize; c += 2) {
// split word
word myWord = readWord_N64();
byte loByte = myWord & 0xFF;
byte hiByte = myWord >> 8;

// write to buffer
sdBuffer[c] = hiByte;
sdBuffer[c + 1] = loByte;
// read, split and write word to buffer
myWord = readWord_N64();
sdBuffer[c] = myWord >> 8;
sdBuffer[c + 1] = myWord & 0xFF;
}
// Pull ale_H(PC1) high
PORTC |= (1 << 1);
myFile.write(sdBuffer, bufferSize);
}
// Close the file:
myFile.close();
print_Msg(F("Saved to "));
print_Msg(folder);
println_Msg(F("/"));
display_Update();
}

unsigned long verifySram(unsigned long sramSize, byte flashramType) {
Expand Down Expand Up @@ -2510,6 +2491,8 @@ void sendFramCmd(unsigned long myCommand) {
// Send command
writeWord_N64(myComHighOut);
writeWord_N64(myComLowOut);
// Pull ale_H(PC1) high
PORTC |= (1 << 1);
}

// Init fram
Expand Down Expand Up @@ -2744,6 +2727,8 @@ byte waitForFram(byte flashramType) {
}
}
}
// Pull ale_H(PC1) high
PORTC |= (1 << 1);
return framStatus;
}

Expand Down Expand Up @@ -2800,10 +2785,15 @@ void getFramType() {
else {
for (byte c = 0; c < 8; c++) {
print_Msg(sdBuffer[c], HEX);
print_Msg(F(", "));
if (c < 7)
print_Msg(F(", "));
if (c == 7)
println_Msg(FS(FSTRING_EMPTY));
}
print_FatalError(F("Flashram unknown"));
}
// Pull ale_H(PC1) high
PORTC |= (1 << 1);
}

/******************************************
Expand Down Expand Up @@ -2847,6 +2837,9 @@ void readRom_N64() {

processedProgressBar += 512;
draw_progressbar(processedProgressBar, totalProgressBar);

// Pull ale_H(PC1) high
PORTC |= (1 << 1);
}
// Close the file:
myFile.close();
Expand Down
2 changes: 1 addition & 1 deletion Cart_Reader/OSCR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* String Constants
**/
// Firmware Version
constexpr char PROGMEM FSTRING_VERSION[] = "V14.1";
constexpr char PROGMEM FSTRING_VERSION[] = "V14.2";

// Universal
constexpr char PROGMEM FSTRING_RESET[] = "Reset";
Expand Down

1 comment on commit afade35

@sanni
Copy link
Owner Author

@sanni sanni commented on afade35 Aug 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly ALE_H being high instead of low between reads.

Real N64 reading flash ram save:
real_n64

OSCR before change:
oscr_before_change

OSCR after change:
oscr_after_change

Please sign in to comment.