V1.9: Fix bug with Arduino IDE 1.8.7

This commit is contained in:
sanni 2018-10-05 18:33:09 +02:00 committed by GitHub
parent 0ad3a5fa7e
commit ee6d1b8f81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3466 additions and 3436 deletions

View File

@ -2,15 +2,15 @@
Cartridge Reader for Arduino Mega2560 Cartridge Reader for Arduino Mega2560
Author: sanni Author: sanni
Date: 20-09-2018 Date: 05-10-2018
Version: 1.8 Version: 1.9
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
Clockgen: https://github.com/etherkit/Si5351Arduino Clockgen: https://github.com/etherkit/Si5351Arduino
RGB Tools lib: https://github.com/joushx/Arduino-RGB-Tools RGB Tools lib: https://github.com/joushx/Arduino-RGB-Tools
Compiled with Arduino 1.8.5 Compiled with Arduino 1.8.7
Thanks to: Thanks to:
MichlK - ROM-Reader for Super Nintendo MichlK - ROM-Reader for Super Nintendo
@ -35,7 +35,7 @@
infinest - help with GB Memory cart infinest - help with GB Memory cart
**********************************************************************************/ **********************************************************************************/
char ver[5] = "1.8"; char ver[5] = "1.9";
/****************************************** /******************************************
Define Starting Point Define Starting Point
@ -683,7 +683,7 @@ unsigned char question_box(const char* question, char answers[7][20], int num_an
if (enable_OLED) { if (enable_OLED) {
return questionBox_OLED(question, answers, num_answers, default_choice); return questionBox_OLED(question, answers, num_answers, default_choice);
} }
if (enable_Serial) { else if (enable_Serial) {
return questionBox_Serial(question, answers, num_answers, default_choice); return questionBox_Serial(question, answers, num_answers, default_choice);
} }
} }
@ -729,10 +729,7 @@ void wait_serial() {
byte questionBox_Serial(const char* question, char answers[7][20], int num_answers, int default_choice) { byte questionBox_Serial(const char* question, char answers[7][20], int num_answers, int default_choice) {
// Print menu to serial monitor // Print menu to serial monitor
if (filebrowse) { //Serial.println(question);
Serial.print("Filebrowser: ");
}
Serial.println(question);
for (byte i = 0; i < num_answers; i++) { for (byte i = 0; i < num_answers; i++) {
Serial.print(i); Serial.print(i);
Serial.print(F(")")); Serial.print(F(")"));
@ -1135,7 +1132,7 @@ unsigned char questionBox_OLED(const char* question, char answers[7][20], int nu
/****************************************** /******************************************
Filebrowser Module Filebrowser Module
*****************************************/ *****************************************/
void fileBrowser(const char browserTitle[]) { void fileBrowser(const char* browserTitle) {
char fileNames[30][26]; char fileNames[30][26];
int currFile; int currFile;
filebrowse = 1; filebrowse = 1;
@ -1148,6 +1145,9 @@ void fileBrowser(const char browserTitle[]) {
browserstart: browserstart:
// Print title
println_Msg(browserTitle);
// Set currFile back to 0 // Set currFile back to 0
currFile = 0; currFile = 0;
currPage = 1; currPage = 1;
@ -1234,7 +1234,7 @@ page:
sprintf( answers[i], "%s", fileOptions[ ((currPage - 1) * 7 + i)] ); sprintf( answers[i], "%s", fileOptions[ ((currPage - 1) * 7 + i)] );
} }
// Create menu with title "Filebrowser" and 1-7 options to choose from // Create menu with title and 1-7 options to choose from
unsigned char answer = question_box(browserTitle, answers, count, 0); unsigned char answer = question_box(browserTitle, answers, count, 0);
// Check if the page has been switched // Check if the page has been switched

View File

@ -46,11 +46,12 @@ static const char* const menuOptionsFLASH16[] PROGMEM = {flash16MenuItem1, flash
// Eprom menu items // Eprom menu items
static const char epromMenuItem1[] PROGMEM = "Blankcheck"; static const char epromMenuItem1[] PROGMEM = "Blankcheck";
static const char epromMenuItem2[] PROGMEM = "Read 27C322"; static const char epromMenuItem2[] PROGMEM = "Read";
static const char epromMenuItem3[] PROGMEM = "Write 27C322"; static const char epromMenuItem3[] PROGMEM = "Write";
static const char epromMenuItem4[] PROGMEM = "Verify 27C322"; static const char epromMenuItem4[] PROGMEM = "Verify";
static const char epromMenuItem5[] PROGMEM = "Reset"; static const char epromMenuItem5[] PROGMEM = "Print";
static const char* const menuOptionsEprom[] PROGMEM = {epromMenuItem1, epromMenuItem2, epromMenuItem3, epromMenuItem4, epromMenuItem5}; static const char epromMenuItem6[] PROGMEM = "Reset";
static const char* const menuOptionsEprom[] PROGMEM = {epromMenuItem1, epromMenuItem2, epromMenuItem3, epromMenuItem4, epromMenuItem5, epromMenuItem6};
void flashMenu() { void flashMenu() {
// create menu with title and 3 options to choose from // create menu with title and 3 options to choose from
@ -328,8 +329,8 @@ void epromMenu() {
// create menu with title "Eprom Writer" and 4 options to choose from // create menu with title "Eprom Writer" and 4 options to choose from
unsigned char mainMenu; unsigned char mainMenu;
// Copy menuOptions out of progmem // Copy menuOptions out of progmem
convertPgm(menuOptionsEprom, 5); convertPgm(menuOptionsEprom, 6);
mainMenu = question_box("Eprom Writer", menuOptions, 5, 0); mainMenu = question_box("Eprom Writer", menuOptions, 6, 0);
// wait for user choice to come back from the question box menu // wait for user choice to come back from the question box menu
switch (mainMenu) switch (mainMenu)
@ -355,18 +356,27 @@ void epromMenu() {
display_Clear(); display_Clear();
time = millis(); time = millis();
write_Eprom(); write_Eprom();
delay(1000);
verify_Eprom();
break; break;
case 3: case 3:
filePath[0] = '\0'; filePath[0] = '\0';
sd.chdir("/"); sd.chdir("/");
fileBrowser("Verify against"); fileBrowser("Verify against");
sprintf(filePath, "%s/%s", filePath, fileName);
display_Clear(); display_Clear();
time = millis(); time = millis();
verify_Eprom(); verify_Eprom();
break; break;
case 4: case 4:
display_Clear();
time = millis();
print_Eprom(80);
break;
case 5:
time = 0; time = 0;
display_Clear(); display_Clear();
display_Update(); display_Update();
@ -377,8 +387,6 @@ void epromMenu() {
print_Msg(F("Operation took: ")); print_Msg(F("Operation took: "));
print_Msg((millis() - time) / 1000, DEC); print_Msg((millis() - time) / 1000, DEC);
println_Msg("s"); println_Msg("s");
println_Msg("Please do a manual");
println_Msg("powercycle now");
display_Update(); display_Update();
} }
wait(); wait();
@ -633,17 +641,6 @@ void setup_Eprom() {
// 27C322 is a 4MB eprom // 27C322 is a 4MB eprom
flashSize = 4194304; flashSize = 4194304;
display_Clear();
println_Msg("This is still a work");
println_Msg("in progress.");
println_Msg("");
println_Msg("Sometimes it works...");
println_Msg("sometimes it blows up");
println_Msg("");
println_Msg("Press Button");
display_Update();
wait();
} }
/****************************************** /******************************************
@ -1793,6 +1790,10 @@ word writeWord_Eprom(unsigned long myAddress, word myData) {
// Data out // Data out
DDRC = 0xFF; DDRC = 0xFF;
DDRA = 0xFF; DDRA = 0xFF;
// Arduino running at 16Mhz -> one nop = 62.5ns
__asm__("nop\n\t");
// Set address // Set address
PORTF = myAddress & 0xFF; PORTF = myAddress & 0xFF;
PORTK = (myAddress >> 8) & 0xFF; PORTK = (myAddress >> 8) & 0xFF;
@ -1801,7 +1802,6 @@ word writeWord_Eprom(unsigned long myAddress, word myData) {
PORTC = myData; PORTC = myData;
PORTA = (myData >> 8) & 0xFF; PORTA = (myData >> 8) & 0xFF;
// Arduino running at 16Mhz -> one nop = 62.5ns
__asm__("nop\n\t"); __asm__("nop\n\t");
// Switch VPP/OE(PH5) to HIGH // Switch VPP/OE(PH5) to HIGH
@ -1829,17 +1829,19 @@ word writeWord_Eprom(unsigned long myAddress, word myData) {
DDRA = 0x00; DDRA = 0x00;
// Arduino running at 16Mhz -> one nop = 62.5ns // Arduino running at 16Mhz -> one nop = 62.5ns
__asm__("nop\n\t"); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
// Setting CE(PH6) LOW // Setting CE(PH6) LOW
PORTH &= ~(1 << 6); PORTH &= ~(1 << 6);
// Wait 1us for Chip Enable Low to Output Valid while program verify // Wait 1us for Chip Enable Low to Output Valid while program verify
delayMicroseconds(1); delayMicroseconds(3);
// Read // Read
word tempWord = ( ( PINA & 0xFF ) << 8 ) | ( PINC & 0xFF ); word tempWord = ( ( PINA & 0xFF ) << 8 ) | ( PINC & 0xFF );
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
// Setting CE(PH6) HIGH // Setting CE(PH6) HIGH
PORTH |= (1 << 6); PORTH |= (1 << 6);
@ -1961,22 +1963,20 @@ void write_Eprom() {
PORTH |= (1 << 5); PORTH |= (1 << 5);
delay(1000); delay(1000);
int d = 0;
for (unsigned long currWord = 0; currWord < fileSize / 2; currWord += 256) { for (unsigned long currWord = 0; currWord < fileSize / 2; currWord += 256) {
// Fill SD buffer // Fill SD buffer
myFile.read(sdBuffer, 512); myFile.read(sdBuffer, 512);
int d = 0;
// Blink led // Blink led
if (currWord % 2048 == 0) if (currWord % 2048 == 0)
PORTB ^= (1 << 4); PORTB ^= (1 << 4);
// Work through SD buffer // Work through SD buffer
word checkWord = 0xFFFF;
for (int c = 0; c < 256; c++) { for (int c = 0; c < 256; c++) {
word checkWord;
word myWord = ( ( sdBuffer[d + 1] & 0xFF ) << 8 ) | ( sdBuffer[d] & 0xFF ); word myWord = ( ( sdBuffer[d + 1] & 0xFF ) << 8 ) | ( sdBuffer[d] & 0xFF );
// No need to write word if it's 0xFFFF
if (myWord != 0xFFFF) {
// Error counter // Error counter
byte n = 0; byte n = 0;
@ -1997,10 +1997,8 @@ void write_Eprom() {
n++; n++;
} }
while (checkWord != myWord); while (checkWord != myWord);
}
d += 2; d += 2;
} }
d = 0;
} }
// Close the file: // Close the file:
myFile.close(); myFile.close();
@ -2029,7 +2027,7 @@ void verify_Eprom() {
//fill sdBuffer //fill sdBuffer
myFile.read(sdBuffer, 512); myFile.read(sdBuffer, 512);
for (int c = 0; c < 256; c++) { for (int c = 0; c < 256; c++) {
word myWord = ( ( sdBuffer[d + 1] & 0xFF ) << 8 ) | ( sdBuffer[d] & 0xFF ); word myWord = (((sdBuffer[d + 1] & 0xFF) << 8) | (sdBuffer[d] & 0xFF));
if (readWord_Eprom(currWord + c) != myWord) { if (readWord_Eprom(currWord + c) != myWord) {
blank++; blank++;
@ -2057,6 +2055,38 @@ void verify_Eprom() {
} }
} }
void print_Eprom(int numBytes) {
char buf[3];
for (int currByte = 0; currByte < numBytes / 2; currByte += 5) {
// 5 words per line
for (int c = 0; c < 5; c++) {
word currWord = readWord_Eprom(currByte + c);
// Split word into two bytes
byte left_byte = currWord & 0xFF;
byte right_byte = ( currWord >> 8 ) & 0xFF;
sprintf (buf, "%x", left_byte);
for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg("0");
}
// Now print the significant bits
print_Msg(buf);
sprintf (buf, "%x", right_byte);
for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg("0");
}
// Now print the significant bits
print_Msg(buf);
}
println_Msg("");
}
display_Update();
}
//****************************************** //******************************************
// End of File // End of File
//****************************************** //******************************************