diff options
author | smesgr9000 <smesgr9000> | 2024-05-01 09:06:23 +0200 |
---|---|---|
committer | smesgr9000 <smesgr9000> | 2024-05-01 09:06:23 +0200 |
commit | bb12c99fac68e107dd1858a67c2bad880c332422 (patch) | |
tree | 39d4e4a7de22106ce0121acbd5b909808d62ea41 /Cart_Reader/FAIRCHILD.ino | |
parent | ecc937bab300463dcc41a7f2827e8d8b611d1d17 (diff) | |
download | cartreader-bb12c99fac68e107dd1858a67c2bad880c332422.tar.gz cartreader-bb12c99fac68e107dd1858a67c2bad880c332422.zip |
replace FAIRCHILD, ODY2, MSX and VECTREX cart selection code with code used in NES, COLV & INTV. Define "Database not found" in OSCR.cpp
Diffstat (limited to 'Cart_Reader/FAIRCHILD.ino')
-rw-r--r-- | Cart_Reader/FAIRCHILD.ino | 244 |
1 files changed, 19 insertions, 225 deletions
diff --git a/Cart_Reader/FAIRCHILD.ino b/Cart_Reader/FAIRCHILD.ino index 5ef93e1..937279c 100644 --- a/Cart_Reader/FAIRCHILD.ino +++ b/Cart_Reader/FAIRCHILD.ino @@ -70,7 +70,6 @@ byte fairchildlo = 0; // Lowest Entry byte fairchildhi = 3; // Highest Entry byte fairchildsize; -byte newfairchildsize; // EEPROM MAPPING // 08 ROM SIZE @@ -540,6 +539,7 @@ void read16K_FAIRCHILD() // Read 16K Bytes //****************************************** void setROMSize_FAIRCHILD() { + byte newfairchildsize; #if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display_Clear(); if (fairchildlo == fairchildhi) @@ -672,239 +672,33 @@ void checkStatus_FAIRCHILD() { //****************************************** // CART SELECT CODE //****************************************** +void readDataLine_FAIRCHILD(FsFile& database, byte* gameSize) { + // Read rom size + (*gameSize) = database.read() - 48; -FsFile fairchildcsvFile; -char fairchildgame[33]; // title -char fairchildrr[3]; // romsize -char fairchildll[4]; // linelength (previous line) -unsigned long fairchildcsvpos; // CSV File Position -char fairchildcartCSV[] = "fairchildcart.txt"; // CSV List -char fairchildcsvEND[] = "EOF"; // CSV End Marker for scrolling - -bool readLine_FAIRCHILD(FsFile& f, char* line, size_t maxLen) { - for (size_t n = 0; n < maxLen; n++) { - int c = f.read(); - if (c < 0 && n == 0) return false; // EOF - if (c < 0 || c == '\n') { - line[n] = 0; - return true; - } - line[n] = c; - } - return false; // line too long + // Skip rest of line + database.seekCur(2); } -bool readVals_FAIRCHILD(char* fairchildgame, char* fairchildrr, char* fairchildll) { - char line[39]; - fairchildcsvpos = fairchildcsvFile.position(); - if (!readLine_FAIRCHILD(fairchildcsvFile, line, sizeof(line))) { - return false; // EOF or too long - } - char* comma = strtok(line, ","); - int x = 0; - while (comma != NULL) { - if (x == 0) - strcpy(fairchildgame, comma); - else if (x == 1) - strcpy(fairchildrr, comma); - else if (x == 2) - strcpy(fairchildll, comma); - comma = strtok(NULL, ","); - x += 1; - } - return true; -} +void setCart_FAIRCHILD() { + //go to root + sd.chdir(); -bool getCartListInfo_FAIRCHILD() { - bool buttonreleased = 0; - bool cartselected = 0; -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display_Clear(); - println_Msg(F(" HOLD TO FAST CYCLE")); - display_Update(); -#else - Serial.println(F("HOLD BUTTON TO FAST CYCLE")); -#endif - delay(2000); -#if defined(ENABLE_OLED) - buttonVal1 = (PIND & (1 << 7)); // PD7 -#elif defined(ENABLE_LCD) - boolean buttonVal1 = (PING & (1 << 2)); //PG2 -#endif - if (buttonVal1 == LOW) { // Button Held - Fast Cycle - while (1) { // Scroll Game List - while (readVals_FAIRCHILD(fairchildgame, fairchildrr, fairchildll)) { - if (strcmp(fairchildcsvEND, fairchildgame) == 0) { - fairchildcsvFile.seek(0); // Restart - } else { -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display_Clear(); - println_Msg(F("CART TITLE:")); - println_Msg(FS(FSTRING_EMPTY)); - println_Msg(fairchildgame); - display_Update(); -#else - Serial.print(F("CART TITLE:")); - Serial.println(fairchildgame); -#endif -#if defined(ENABLE_OLED) - buttonVal1 = (PIND & (1 << 7)); // PD7 -#elif defined(ENABLE_LCD) - buttonVal1 = (PING & (1 << 2)); //PG2 -#endif - if (buttonVal1 == HIGH) { // Button Released - buttonreleased = 1; - break; - } - if (buttonreleased) { - buttonreleased = 0; // Reset Flag - break; - } - } - } -#if defined(ENABLE_OLED) - buttonVal1 = (PIND & (1 << 7)); // PD7 -#elif defined(ENABLE_LCD) - buttonVal1 = (PING & (1 << 2)); //PG2 -#endif - if (buttonVal1 == HIGH) // Button Released - break; - } - } -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display.setCursor(0, 56); - println_Msg(F("FAST CYCLE OFF")); - display_Update(); -#else - Serial.println(FS(FSTRING_EMPTY)); - Serial.println(F("FAST CYCLE OFF")); - Serial.println(F("PRESS BUTTON TO STEP FORWARD")); - Serial.println(F("DOUBLE CLICK TO STEP BACK")); - Serial.println(F("HOLD TO SELECT")); - Serial.println(FS(FSTRING_EMPTY)); -#endif - while (readVals_FAIRCHILD(fairchildgame, fairchildrr, fairchildll)) { - if (strcmp(fairchildcsvEND, fairchildgame) == 0) { - fairchildcsvFile.seek(0); // Restart - } else { -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display_Clear(); - println_Msg(F("CART TITLE:")); - println_Msg(FS(FSTRING_EMPTY)); - println_Msg(fairchildgame); - display.setCursor(0, 48); -#if defined(ENABLE_OLED) - print_STR(press_to_change_STR, 1); - print_STR(right_to_select_STR, 1); -#elif defined(ENABLE_LCD) - print_STR(rotate_to_change_STR, 1); - print_STR(press_to_select_STR, 1); -#endif - display_Update(); -#else - Serial.print(F("CART TITLE:")); - Serial.println(fairchildgame); -#endif - while (1) { // Single Step - uint8_t b = checkButton(); - if (b == 1) { // Continue (press) - break; - } - if (b == 2) { // Reset to Start of List (doubleclick) - byte prevline = strtol(fairchildll, NULL, 10); - fairchildcsvpos -= prevline; - fairchildcsvFile.seek(fairchildcsvpos); - break; - } - if (b == 3) { // Long Press - Select Cart (hold) - newfairchildsize = strtol(fairchildrr, NULL, 10); - EEPROM_writeAnything(8, newfairchildsize); - cartselected = 1; // SELECTION MADE -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - println_Msg(F("SELECTION MADE")); - display_Update(); -#else - Serial.println(F("SELECTION MADE")); -#endif - break; - } - } - if (cartselected) { - cartselected = 0; // Reset Flag - return true; - } - } - } -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - println_Msg(FS(FSTRING_EMPTY)); - println_Msg(FS(FSTRING_END_OF_FILE)); - display_Update(); -#else - Serial.println(FS(FSTRING_END_OF_FILE)); -#endif + byte gameSize; - return false; -} + // Select starting letter + //byte myLetter = starting_letter(); -void checkCSV_FAIRCHILD() { - if (getCartListInfo_FAIRCHILD()) { -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display_Clear(); - println_Msg(FS(FSTRING_CART_SELECTED)); - println_Msg(FS(FSTRING_EMPTY)); - println_Msg(fairchildgame); - display_Update(); - // Display Settings - display.setCursor(0, 56); - print_Msg(F("CODE: R")); - println_Msg(newfairchildsize); - display_Update(); -#else - Serial.println(FS(FSTRING_EMPTY)); - Serial.println(FS(FSTRING_CART_SELECTED)); - Serial.println(fairchildgame); - // Display Settings - Serial.print(F("CODE: R")); - Serial.println(newfairchildsize); - Serial.println(FS(FSTRING_EMPTY)); -#endif - } else { -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display.setCursor(0, 56); - println_Msg(FS(FSTRING_NO_SELECTION)); - display_Update(); -#else - Serial.println(FS(FSTRING_NO_SELECTION)); -#endif - } -} + // Open database + if (myFile.open("fairchildcart.txt", O_READ)) { + // seek_first_letter_in_database(myFile, myLetter); -void setCart_FAIRCHILD() { -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display_Clear(); - println_Msg(fairchildcartCSV); - display_Update(); -#endif - sd.chdir(); - sprintf(folder, "FAIRCHILD/CSV"); - sd.chdir(folder); // Switch Folder - fairchildcsvFile = sd.open(fairchildcartCSV, O_READ); - if (!fairchildcsvFile) { -#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) - display_Clear(); - println_Msg(F("CSV FILE NOT FOUND!")); - display_Update(); -#else - Serial.println(F("CSV FILE NOT FOUND!")); -#endif - while (1) { - if (checkButton() != 0) - setup_FAIRCHILD(); + if(checkCartSelection(myFile, &readDataLine_ARC, &gameSize)) { + EEPROM_writeAnything(8, gameSize); } + } else { + print_FatalError(FS(FSTRING_DATABASE_FILE_NOT_FOUND)); } - checkCSV_FAIRCHILD(); - - fairchildcsvFile.close(); } #endif //****************************************** |