mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-13 08:25:05 +01:00
commit
35b766e0a1
@ -232,6 +232,13 @@ char folder[36];
|
||||
// Array that holds the data
|
||||
byte sdBuffer[512];
|
||||
|
||||
// soft reset Arduino: jumps to 0
|
||||
// using the watchdog timer would be more elegant but some Mega2560 bootloaders are buggy with it
|
||||
void(*resetArduino) (void) = 0;
|
||||
|
||||
/* Hoping that sanni will use this progressbar function */
|
||||
void draw_progressbar(uint32_t processedsize, uint32_t totalsize);
|
||||
|
||||
//******************************************
|
||||
// Bitmaps
|
||||
//******************************************
|
||||
@ -408,9 +415,45 @@ void aboutScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
void resetArduino() {
|
||||
wdt_enable(WDTO_15MS);
|
||||
while (1);
|
||||
void draw_progressbar(uint32_t processed, uint32_t total)
|
||||
{
|
||||
uint8_t current, i;
|
||||
static uint8_t previous;
|
||||
uint8_t steps = 20;
|
||||
|
||||
//Find progressbar length and draw if processed size is not 0
|
||||
if (processed == 0)
|
||||
{
|
||||
previous = 0;
|
||||
print_Msg(F("["));
|
||||
display_Update();
|
||||
return;
|
||||
}
|
||||
|
||||
// Progress bar
|
||||
current = (processed >= total) ? steps : processed / (total / steps);
|
||||
|
||||
//Draw "*" if needed
|
||||
if (current > previous)
|
||||
{
|
||||
for (i = previous; i < current; i++)
|
||||
{
|
||||
// steps are 20, so 20 - 1 = 19.
|
||||
if (i == (19))
|
||||
{
|
||||
//If end of progress bar, finish progress bar by drawing "]"
|
||||
print_Msg(F("]"));
|
||||
}
|
||||
else
|
||||
{
|
||||
print_Msg(F("*"));
|
||||
}
|
||||
}
|
||||
//update previous "*" status
|
||||
previous = current;
|
||||
//Update display
|
||||
display_Update();
|
||||
}
|
||||
}
|
||||
|
||||
void mainMenu() {
|
||||
|
@ -2073,17 +2073,23 @@ readn64rom:
|
||||
print_Error(F("SD Error"), true);
|
||||
}
|
||||
|
||||
byte buffer[1024] = { 0 };
|
||||
|
||||
// get current time
|
||||
unsigned long startTime = millis();
|
||||
|
||||
byte buffer[1024];
|
||||
//Initialize progress bar
|
||||
uint32_t processedProgressBar = 0;
|
||||
uint32_t totalProgressBar = (uint32_t)(cartSize) * 1024 * 1024;
|
||||
draw_progressbar(0, totalProgressBar);
|
||||
|
||||
// run combined dumper + crc32 routine for better performance, as N64 ROMs are quite large for an 8bit micro
|
||||
// currently dumps + checksums a 32MB cart in 170 seconds (down from 347 seconds)
|
||||
// prepare crc32
|
||||
uint32_t oldcrc32 = 0xFFFFFFFF;
|
||||
uint32_t tab_value = 0;
|
||||
uint8_t idx = 0;
|
||||
|
||||
// run combined dumper + crc32 routine for better performance, as N64 ROMs are quite large for an 8bit micro
|
||||
// currently dumps + checksums a 32MB cart in 170 seconds (down from 347 seconds)
|
||||
for (unsigned long currByte = romBase; currByte < (romBase + (cartSize * 1024 * 1024)); currByte += 1024) {
|
||||
// Blink led
|
||||
if (currByte % 16384 == 0)
|
||||
@ -2108,10 +2114,10 @@ readn64rom:
|
||||
PORTH |= (1 << 6);
|
||||
|
||||
// crc32 update
|
||||
idx = ((oldcrc32) ^ (buffer[c])) & 0xff;
|
||||
idx = ((oldcrc32) ^ (buffer[c]));
|
||||
tab_value = pgm_read_dword(crc_32_tab + idx);
|
||||
oldcrc32 = tab_value ^ ((oldcrc32) >> 8);
|
||||
idx = ((oldcrc32) ^ (buffer[c + 1])) & 0xff;
|
||||
idx = ((oldcrc32) ^ (buffer[c + 1]));
|
||||
tab_value = pgm_read_dword(crc_32_tab + idx);
|
||||
oldcrc32 = tab_value ^ ((oldcrc32) >> 8);
|
||||
}
|
||||
@ -2143,20 +2149,19 @@ readn64rom:
|
||||
oldcrc32 = tab_value ^ ((oldcrc32) >> 8);
|
||||
}
|
||||
|
||||
processedProgressBar += 1024;
|
||||
draw_progressbar(processedProgressBar, totalProgressBar);
|
||||
// write out 1024 bytes to file
|
||||
myFile.write(buffer, 1024);
|
||||
}
|
||||
|
||||
// Close the file:
|
||||
myFile.close();
|
||||
|
||||
// print elapsed time
|
||||
print_Msg(F("Time elapsed: "));
|
||||
print_Msg((millis() - startTime) / 1000);
|
||||
println_Msg(F("s"));
|
||||
display_Update();
|
||||
unsigned long timeElapsed = (millis() - startTime) / 1000; // seconds
|
||||
|
||||
if (n64crc) {
|
||||
println_Msg(F("Checking CRC.."));
|
||||
print_Msg(F("Check CRC: "));
|
||||
display_Update();
|
||||
// convert checksum to string
|
||||
char crcStr[9];
|
||||
@ -2217,7 +2222,10 @@ readn64rom:
|
||||
}
|
||||
display_Update();
|
||||
}
|
||||
println_Msg(F("Done."));
|
||||
|
||||
print_Msg(F("Done ("));
|
||||
print_Msg(timeElapsed); // include elapsed time
|
||||
println_Msg(F("s)"));
|
||||
println_Msg(F(""));
|
||||
println_Msg(F("Press Button..."));
|
||||
display_Update();
|
||||
|
@ -25,8 +25,6 @@
|
||||
/******************************************
|
||||
Prototype Declarations
|
||||
*****************************************/
|
||||
/* Hoping that sanni will use this progressbar function */
|
||||
void draw_progressbar(uint32_t processedsize, uint32_t totalsize);
|
||||
void pcsMenu(void);
|
||||
void pceMenu(void);
|
||||
|
||||
@ -66,49 +64,6 @@ static const char pceTCMenuItem1[] PROGMEM = "Read Rom";
|
||||
static const char pceTCMenuItem2[] PROGMEM = "Reset";
|
||||
static const char* const menuOptionspceTC[] PROGMEM = {pceTCMenuItem1, pceTCMenuItem2};
|
||||
|
||||
|
||||
|
||||
void draw_progressbar(uint32_t processed, uint32_t total)
|
||||
{
|
||||
uint8_t current, i;
|
||||
static uint8_t previous;
|
||||
uint8_t steps = 20;
|
||||
|
||||
//Find progressbar length and draw if processed size is not 0
|
||||
if (processed == 0)
|
||||
{
|
||||
previous = 0;
|
||||
print_Msg(F("["));
|
||||
display_Update();
|
||||
return;
|
||||
}
|
||||
|
||||
// Progress bar
|
||||
current = (processed >= total) ? steps : processed / (total / steps) ;
|
||||
|
||||
//Draw "*" if needed
|
||||
if (current > previous)
|
||||
{
|
||||
for (i = previous; i < current; i++)
|
||||
{
|
||||
// steps are 20, so 20 - 1 = 19.
|
||||
if (i == (19))
|
||||
{
|
||||
//If end of progress bar, finish progress bar by drawing "]"
|
||||
print_Msg(F("]"));
|
||||
}
|
||||
else
|
||||
{
|
||||
print_Msg(F("*"));
|
||||
}
|
||||
}
|
||||
//update previous "*" status
|
||||
previous = current;
|
||||
//Update display
|
||||
display_Update();
|
||||
}
|
||||
}
|
||||
|
||||
// PCE start menu
|
||||
void pcsMenu(void) {
|
||||
// create menu with title and 3 options to choose from
|
||||
|
@ -413,11 +413,16 @@ byte readBank_SNES(byte myBank, word myAddress) {
|
||||
|
||||
void readLoRomBanks( unsigned int start, unsigned int total, SdFile *file)
|
||||
{
|
||||
byte buffer[1024];
|
||||
byte buffer[1024] = { 0 };
|
||||
|
||||
uint16_t c = 0;
|
||||
uint16_t currByte = 32768;
|
||||
|
||||
|
||||
//Initialize progress bar
|
||||
uint32_t processedProgressBar = 0;
|
||||
uint32_t totalProgressBar = (uint32_t)(total - start) * 1024;
|
||||
draw_progressbar(0, totalProgressBar);
|
||||
|
||||
for (int currBank = start; currBank < total; currBank++) {
|
||||
PORTL = currBank;
|
||||
currByte = 32768;
|
||||
@ -442,16 +447,25 @@ void readLoRomBanks( unsigned int start, unsigned int total, SdFile *file)
|
||||
// exit while(1) loop once the uint16_t currByte overflows from 0xffff to 0 (current bank is done)
|
||||
if (currByte == 0) break;
|
||||
}
|
||||
|
||||
// update progress bar
|
||||
processedProgressBar += 1024;
|
||||
draw_progressbar(processedProgressBar, totalProgressBar);
|
||||
}
|
||||
}
|
||||
|
||||
void readHiRomBanks( unsigned int start, unsigned int total, SdFile *file)
|
||||
{
|
||||
byte buffer[1024];
|
||||
byte buffer[1024] = { 0 };
|
||||
|
||||
uint16_t c = 0;
|
||||
uint16_t currByte = 0;
|
||||
|
||||
//Initialize progress bar
|
||||
uint32_t processedProgressBar = 0;
|
||||
uint32_t totalProgressBar = (uint32_t)(total - start) * 1024;
|
||||
draw_progressbar(0, totalProgressBar);
|
||||
|
||||
for (int currBank = start; currBank < total; currBank++) {
|
||||
PORTL = currBank;
|
||||
currByte = 0;
|
||||
@ -476,6 +490,10 @@ void readHiRomBanks( unsigned int start, unsigned int total, SdFile *file)
|
||||
// exit while(1) loop once the uint16_t currByte overflows from 0xffff to 0 (current bank is done)
|
||||
if (currByte == 0) break;
|
||||
}
|
||||
|
||||
// update progress bar
|
||||
processedProgressBar += 1024;
|
||||
draw_progressbar(processedProgressBar, totalProgressBar);
|
||||
}
|
||||
}
|
||||
|
||||
@ -956,16 +974,15 @@ boolean compare_checksum() {
|
||||
sprintf(calcsumStr, "%04X", calc_checksum(fileName, folder));
|
||||
|
||||
if (strcmp(calcsumStr, checksumStr) == 0) {
|
||||
print_Msg(F("Result: "));
|
||||
print_Msg(F("Checksum OK: "));
|
||||
println_Msg(calcsumStr);
|
||||
println_Msg(F("Checksum matches"));
|
||||
display_Update();
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
print_Msg(F("Result: "));
|
||||
print_Msg(F("Checksum Error: "));
|
||||
println_Msg(calcsumStr);
|
||||
print_Error(F("Checksum Error"), false);
|
||||
print_Error(F(""), false);
|
||||
display_Update();
|
||||
return 0;
|
||||
}
|
||||
@ -973,9 +990,6 @@ boolean compare_checksum() {
|
||||
|
||||
// Read rom to SD card
|
||||
void readROM_SNES() {
|
||||
// get current time
|
||||
unsigned long startTime = millis();
|
||||
|
||||
// Set control
|
||||
dataIn();
|
||||
controlIn_SNES();
|
||||
@ -1006,6 +1020,9 @@ void readROM_SNES() {
|
||||
print_Error(F("Can't create file on SD"), true);
|
||||
}
|
||||
|
||||
// get current time
|
||||
unsigned long startTime = millis();
|
||||
|
||||
//Dump Derby Stallion '96 (Japan) Actual Size is 24Mb
|
||||
if ((romType == LO) && (numBanks == 128) && (strcmp("CC86", checksumStr) == 0)) {
|
||||
// Read Banks 0x00-0x3F for the 1st/2nd MB
|
||||
@ -1101,7 +1118,7 @@ void readROM_SNES() {
|
||||
display_Update();
|
||||
|
||||
// 0xC00000-0xDFFFFF
|
||||
print_Msg(F("Part 1"));
|
||||
//print_Msg(F("Part 1"));
|
||||
display_Update();
|
||||
readHiRomBanks( 192, 224, &myFile );
|
||||
|
||||
@ -1115,13 +1132,13 @@ void readROM_SNES() {
|
||||
controlIn_SNES();
|
||||
|
||||
// 0xE00000-0xEFFFFF
|
||||
print_Msg(F(" 2"));
|
||||
//print_Msg(F(" 2"));
|
||||
display_Update();
|
||||
readHiRomBanks( 224, 240, &myFile );
|
||||
|
||||
if (numBanks > 48) {
|
||||
// 0xF00000-0xFFFFFF
|
||||
print_Msg(F(" 3"));
|
||||
//print_Msg(F(" 3"));
|
||||
display_Update();
|
||||
readHiRomBanks( 240, 256, &myFile );
|
||||
|
||||
@ -1135,11 +1152,12 @@ void readROM_SNES() {
|
||||
controlIn_SNES();
|
||||
|
||||
// 0xF00000-0xFFFFFF
|
||||
print_Msg(F(" 4"));
|
||||
//print_Msg(F(" 4"));
|
||||
display_Update();
|
||||
readHiRomBanks( 240, 256, &myFile );
|
||||
}
|
||||
println_Msg(F(""));
|
||||
//println_Msg(F(""));
|
||||
display_Clear(); // need more space due to the 4 progress bars
|
||||
|
||||
// Return mapping registers to initial settings...
|
||||
dataOut();
|
||||
|
Loading…
Reference in New Issue
Block a user