mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-13 08:25:05 +01:00
Improve Controller Pak timing
This commit is contained in:
parent
e4246d8310
commit
659eefda63
@ -4,7 +4,7 @@
|
|||||||
This project represents a community-driven effort to provide
|
This project represents a community-driven effort to provide
|
||||||
an easy to build and easy to modify cartridge dumper.
|
an easy to build and easy to modify cartridge dumper.
|
||||||
|
|
||||||
Date: 17.08.2022
|
Date: 18.08.2022
|
||||||
Version: 9.5
|
Version: 9.5
|
||||||
|
|
||||||
SD lib: https://github.com/greiman/SdFat
|
SD lib: https://github.com/greiman/SdFat
|
||||||
|
@ -210,6 +210,7 @@ void n64ControllerMenu() {
|
|||||||
display_Clear();
|
display_Clear();
|
||||||
display_Update();
|
display_Update();
|
||||||
writeMPK();
|
writeMPK();
|
||||||
|
delay(500);
|
||||||
verifyMPK();
|
verifyMPK();
|
||||||
println_Msg(F(""));
|
println_Msg(F(""));
|
||||||
println_Msg(F("Press Button..."));
|
println_Msg(F("Press Button..."));
|
||||||
@ -2013,23 +2014,36 @@ void readMPK() {
|
|||||||
uint32_t totalProgressBar = (uint32_t)(0x7FFF);
|
uint32_t totalProgressBar = (uint32_t)(0x7FFF);
|
||||||
draw_progressbar(0, totalProgressBar);
|
draw_progressbar(0, totalProgressBar);
|
||||||
|
|
||||||
|
// Dummy write because first write to file takes 1 second and messes up timing
|
||||||
|
blinkLED();
|
||||||
|
myFile.write(0xFF);
|
||||||
|
myFile.rewind();
|
||||||
|
blinkLED();
|
||||||
|
|
||||||
// Controller paks, which all have 32kB of space, are mapped between 0x0000 – 0x7FFF
|
// Controller paks, which all have 32kB of space, are mapped between 0x0000 – 0x7FFF
|
||||||
for (word i = 0x0000; i < 0x8000; i += 32) {
|
// Read 512 byte into sdBuffer
|
||||||
|
for (word currSdBuffer = 0x0000; currSdBuffer < 0x8000; currSdBuffer += 512) {
|
||||||
|
// Read 32 byte block
|
||||||
|
for (word currBlock = 0; currBlock < 512; currBlock += 32) {
|
||||||
// Read one block of the Controller Pak into array myBlock
|
// Read one block of the Controller Pak into array myBlock
|
||||||
readBlock(i);
|
readBlock(currSdBuffer + currBlock);
|
||||||
|
|
||||||
// Delay to prevent write errors
|
// Copy block to SdBuffer
|
||||||
delay(1);
|
for (byte currByte = 0; currByte < 32; currByte++) {
|
||||||
|
sdBuffer[currBlock + currByte] = myBlock[currByte];
|
||||||
// Write block to SD card
|
|
||||||
for (byte j = 0; j < 32; j++) {
|
|
||||||
myFile.write(myBlock[j]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Real N64 has about 627us pause between banks, loop takes 500us, add a bit extra delay
|
||||||
|
if (currBlock < 479)
|
||||||
|
delayMicroseconds(800);
|
||||||
|
}
|
||||||
|
// This will take 1300us
|
||||||
|
blinkLED();
|
||||||
|
myFile.write(sdBuffer, 512);
|
||||||
// Blink led
|
// Blink led
|
||||||
blinkLED();
|
blinkLED();
|
||||||
// Update progress bar
|
// Update progress bar
|
||||||
processedProgressBar += 32;
|
processedProgressBar += 512;
|
||||||
draw_progressbar(processedProgressBar, totalProgressBar);
|
draw_progressbar(processedProgressBar, totalProgressBar);
|
||||||
}
|
}
|
||||||
// Close the file:
|
// Close the file:
|
||||||
@ -2052,12 +2066,19 @@ void writeMPK() {
|
|||||||
uint32_t totalProgressBar = (uint32_t)(0x7FFF);
|
uint32_t totalProgressBar = (uint32_t)(0x7FFF);
|
||||||
draw_progressbar(0, totalProgressBar);
|
draw_progressbar(0, totalProgressBar);
|
||||||
|
|
||||||
for (word myAddress = 0x0000; myAddress < 0x8000; myAddress += 32) {
|
for (word currSdBuffer = 0x0000; currSdBuffer < 0x8000; currSdBuffer += 512) {
|
||||||
// Read 32 bytes into SD buffer
|
// Read 512 bytes into SD buffer, takes 1500us
|
||||||
myFile.read(sdBuffer, 32);
|
myFile.read(sdBuffer, 512);
|
||||||
|
|
||||||
|
// Write 32 byte block
|
||||||
|
for (word currBlock = 0; currBlock < 512; currBlock += 32) {
|
||||||
// Calculate the address CRC
|
// Calculate the address CRC
|
||||||
word myAddressCRC = addrCRC(myAddress);
|
word myAddressCRC = addrCRC(currSdBuffer + currBlock);
|
||||||
|
|
||||||
|
// Copy 32 byte block from SdBuffer
|
||||||
|
for (byte currByte = 0; currByte < 32; currByte++) {
|
||||||
|
myBlock[currByte] = sdBuffer[currBlock + currByte] ;
|
||||||
|
}
|
||||||
|
|
||||||
// Write Controller Pak command
|
// Write Controller Pak command
|
||||||
unsigned char command[] = {0x03};
|
unsigned char command[] = {0x03};
|
||||||
@ -2073,19 +2094,22 @@ void writeMPK() {
|
|||||||
N64_send(addressHigh, 1);
|
N64_send(addressHigh, 1);
|
||||||
N64_send(addressLow, 1);
|
N64_send(addressLow, 1);
|
||||||
// Send data to write
|
// Send data to write
|
||||||
N64_send(sdBuffer, 32);
|
N64_send(myBlock, 32);
|
||||||
// Send stop
|
// Send stop
|
||||||
N64_stop();
|
N64_stop();
|
||||||
// Enable interrupts
|
// Enable interrupts
|
||||||
interrupts();
|
interrupts();
|
||||||
|
|
||||||
|
// Real N64 has about 627us pause between banks, add a bit extra delay
|
||||||
|
if (currBlock < 479)
|
||||||
|
delayMicroseconds(1500);
|
||||||
|
}
|
||||||
|
|
||||||
// Blink led
|
// Blink led
|
||||||
blinkLED();
|
blinkLED();
|
||||||
// Update progress bar
|
// Update progress bar
|
||||||
processedProgressBar += 32;
|
processedProgressBar += 512;
|
||||||
draw_progressbar(processedProgressBar, totalProgressBar);
|
draw_progressbar(processedProgressBar, totalProgressBar);
|
||||||
// Delay to prevent write errors
|
|
||||||
delay(1);
|
|
||||||
}
|
}
|
||||||
// Close the file:
|
// Close the file:
|
||||||
myFile.close();
|
myFile.close();
|
||||||
@ -2113,22 +2137,30 @@ void verifyMPK() {
|
|||||||
draw_progressbar(0, totalProgressBar);
|
draw_progressbar(0, totalProgressBar);
|
||||||
|
|
||||||
// Controller paks, which all have 32kB of space, are mapped between 0x0000 – 0x7FFF
|
// Controller paks, which all have 32kB of space, are mapped between 0x0000 – 0x7FFF
|
||||||
for (word i = 0x0000; i < 0x8000; i += 32) {
|
for (word currSdBuffer = 0x0000; currSdBuffer < 0x8000; currSdBuffer += 512) {
|
||||||
|
// Read 512 bytes into SD buffer
|
||||||
|
myFile.read(sdBuffer, 512);
|
||||||
|
|
||||||
|
// Compare 32 byte block
|
||||||
|
for (word currBlock = 0; currBlock < 512; currBlock += 32) {
|
||||||
// Read one block of the Controller Pak into array myBlock
|
// Read one block of the Controller Pak into array myBlock
|
||||||
readBlock(i);
|
readBlock(currSdBuffer + currBlock);
|
||||||
// Delay to prevent read errors
|
|
||||||
delay(1);
|
|
||||||
// Check against file on SD card
|
// Check against file on SD card
|
||||||
for (byte j = 0; j < 32; j++) {
|
for (byte currByte = 0; currByte < 32; currByte++) {
|
||||||
if (myFile.read() != myBlock[j]) {
|
if (sdBuffer[currBlock + currByte] != myBlock[currByte]) {
|
||||||
writeErrors++;
|
writeErrors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Real N64 has about 627us pause between banks, add a bit extra delay
|
||||||
|
if (currBlock < 479)
|
||||||
|
delayMicroseconds(1500);
|
||||||
|
}
|
||||||
|
|
||||||
// Blink led
|
// Blink led
|
||||||
blinkLED();
|
blinkLED();
|
||||||
// Update progress bar
|
// Update progress bar
|
||||||
processedProgressBar += 32;
|
processedProgressBar += 512;
|
||||||
draw_progressbar(processedProgressBar, totalProgressBar);
|
draw_progressbar(processedProgressBar, totalProgressBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user