mirror of
https://github.com/sanni/cartreader.git
synced 2024-12-02 17:24:18 +01:00
V6.6 Add slow CRC32 calculation option for N64
In option.h add // in front of #define fastcrc and remove // in front of #define slowcrc to change CRC32 calculation to slow. // Define CRC method for dumping N64 ROMs //#define fastcrc //crc will be calculated during dumping from memory #define slowcrc // crc will be calculated after dumping from SD card
This commit is contained in:
parent
07ec1f121a
commit
92b7b7bdef
@ -1,8 +1,8 @@
|
|||||||
/**********************************************************************************
|
/**********************************************************************************
|
||||||
Cartridge Reader for Arduino Mega2560
|
Cartridge Reader for Arduino Mega2560
|
||||||
|
|
||||||
Date: 22.07.2021
|
Date: 02.08.2021
|
||||||
Version: 6.5
|
Version: 6.6
|
||||||
|
|
||||||
SD lib: https://github.com/greiman/SdFat
|
SD lib: https://github.com/greiman/SdFat
|
||||||
LCD lib: https://github.com/adafruit/Adafruit_SSD1306
|
LCD lib: https://github.com/adafruit/Adafruit_SSD1306
|
||||||
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
**********************************************************************************/
|
**********************************************************************************/
|
||||||
|
|
||||||
char ver[5] = "6.5";
|
char ver[5] = "6.6";
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
Libraries
|
Libraries
|
||||||
|
@ -1705,6 +1705,35 @@ int strcicmp(char const * a, char const * b)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef slowcrc
|
||||||
|
// Calculate dumped rom's CRC32
|
||||||
|
inline uint32_t updateCRC64(uint8_t ch, uint32_t crc) {
|
||||||
|
uint32_t idx = ((crc) ^ (ch)) & 0xff;
|
||||||
|
uint32_t tab_value = pgm_read_dword(crc_32_tab + idx);
|
||||||
|
return tab_value ^ ((crc) >> 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate rom's CRC32 from SD
|
||||||
|
uint32_t crc64() {
|
||||||
|
if (myFile.open(fileName, O_READ)) {
|
||||||
|
uint32_t oldcrc32 = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
for (unsigned long currByte = 0; currByte < cartSize * 2048; currByte++) {
|
||||||
|
myFile.read(sdBuffer, 512);
|
||||||
|
for (int c = 0; c < 512; c++) {
|
||||||
|
oldcrc32 = updateCRC64(sdBuffer[c], oldcrc32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Close the file:
|
||||||
|
myFile.close();
|
||||||
|
return ~oldcrc32;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print_Error(F("File not found"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// look-up the calculated crc in the file n64.txt on sd card
|
// look-up the calculated crc in the file n64.txt on sd card
|
||||||
boolean searchCRC(char crcStr[9]) {
|
boolean searchCRC(char crcStr[9]) {
|
||||||
boolean result = 0;
|
boolean result = 0;
|
||||||
@ -2854,6 +2883,49 @@ redumpsamefolder:
|
|||||||
print_Error(F("SD Error"), true);
|
print_Error(F("SD Error"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dumping rom slow
|
||||||
|
#ifdef slowcrc
|
||||||
|
// get current time
|
||||||
|
unsigned long startTime = millis();
|
||||||
|
|
||||||
|
for (unsigned long currByte = romBase; currByte < (romBase + (cartSize * 1024 * 1024)); currByte += 512) {
|
||||||
|
// Blink led
|
||||||
|
if (currByte % 16384 == 0)
|
||||||
|
PORTB ^= (1 << 4);
|
||||||
|
|
||||||
|
// Set the address for the next 512 bytes
|
||||||
|
setAddress_N64(currByte);
|
||||||
|
|
||||||
|
for (int c = 0; c < 512; 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;
|
||||||
|
}
|
||||||
|
myFile.write(sdBuffer, 512);
|
||||||
|
}
|
||||||
|
// Close the file:
|
||||||
|
myFile.close();
|
||||||
|
|
||||||
|
// Calculate Checksum and convert to string
|
||||||
|
println_Msg(F("Calculating CRC.."));
|
||||||
|
display_Update();
|
||||||
|
char crcStr[9];
|
||||||
|
sprintf(crcStr, "%08lx", crc64());
|
||||||
|
// Print checksum
|
||||||
|
println_Msg(crcStr);
|
||||||
|
display_Update();
|
||||||
|
|
||||||
|
// end time
|
||||||
|
unsigned long timeElapsed = (millis() - startTime) / 1000; // seconds
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// dumping rom fast
|
||||||
|
#ifdef fastcrc
|
||||||
byte buffer[1024] = { 0 };
|
byte buffer[1024] = { 0 };
|
||||||
|
|
||||||
// get current time
|
// get current time
|
||||||
@ -2949,6 +3021,7 @@ redumpsamefolder:
|
|||||||
// Print checksum
|
// Print checksum
|
||||||
println_Msg(crcStr);
|
println_Msg(crcStr);
|
||||||
display_Update();
|
display_Update();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Search n64.txt for crc
|
// Search n64.txt for crc
|
||||||
if (searchCRC(crcStr)) {
|
if (searchCRC(crcStr)) {
|
||||||
|
@ -18,6 +18,10 @@
|
|||||||
// Read N64 Eeprom with Adadruit clockgen, CLK1 switch needs to be switch to ON
|
// Read N64 Eeprom with Adadruit clockgen, CLK1 switch needs to be switch to ON
|
||||||
#define clockgen_installed
|
#define clockgen_installed
|
||||||
|
|
||||||
|
// Define CRC method for dumping N64 ROMs
|
||||||
|
#define fastcrc //crc will be calculated during dumping from memory
|
||||||
|
//#define slowcrc // crc will be calculated after dumping from SD card
|
||||||
|
|
||||||
// define enable_XXX to enable
|
// define enable_XXX to enable
|
||||||
#define enable_FLASH
|
#define enable_FLASH
|
||||||
#define enable_GBX
|
#define enable_GBX
|
||||||
|
Loading…
Reference in New Issue
Block a user