diff options
author | Ancyker <[email protected]> | 2024-03-02 11:26:35 -0500 |
---|---|---|
committer | Ancyker <[email protected]> | 2024-03-02 11:26:35 -0500 |
commit | e61ac414d89556c941f0b8ca76e5d7d6684037f0 (patch) | |
tree | e8afd45cf20a11d54ecc85e40b25f842a78509eb /Cart_Reader/FAIRCHILD.ino | |
parent | 3468703a51846cbb668f1efc020728d85fd9b76b (diff) | |
download | cartreader-e61ac414d89556c941f0b8ca76e5d7d6684037f0.tar.gz cartreader-e61ac414d89556c941f0b8ca76e5d7d6684037f0.zip |
Code optimization, cleanup, and stylization
* Reduced PROGMEM / DRAM usage slightly (Using defaults w/HW5: Before -> 214,668 bytes / 5,757 bytes; After -> 213,414 bytes / 5,751 bytes)
* Optimized some menu options and calls
* Added more string constants and implemented them where found.
* Fixed some stylization
* Constants should always be uppercase.
* Features should use the `ENABLE_<feature name>` format.
* Options for features should use the `OPTION_<feature name>_<option name>` format.
* Added ENUMs for more clarity and better type checking.
* Moved some defines over to `constexpr` and `const` types. These are preferred over preprocessor constants when not intended for use with `#if` and other preprocessor language.
Diffstat (limited to 'Cart_Reader/FAIRCHILD.ino')
-rw-r--r-- | Cart_Reader/FAIRCHILD.ino | 98 |
1 files changed, 47 insertions, 51 deletions
diff --git a/Cart_Reader/FAIRCHILD.ino b/Cart_Reader/FAIRCHILD.ino index 8fc7137..0500712 100644 --- a/Cart_Reader/FAIRCHILD.ino +++ b/Cart_Reader/FAIRCHILD.ino @@ -1,7 +1,7 @@ //****************************************** // FAIRCHILD CHANNEL F MODULE //****************************************** -#if defined(enable_FAIRCHILD) +#if defined(ENABLE_FAIRCHILD) // Fairchild Channel F // Cartridge Pinout // 22P (27P Width) 2.54mm pitch connector @@ -79,12 +79,8 @@ byte newfairchildsize; // Menu //****************************************** // Base Menu -static const char fairchildMenuItem1[] PROGMEM = "Select Cart"; -static const char fairchildMenuItem2[] PROGMEM = "Read ROM"; -static const char fairchildMenuItem3[] PROGMEM = "Set Size"; static const char fairchildMenuItem4[] PROGMEM = "Read 16K"; -static const char fairchildMenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsFAIRCHILD[] PROGMEM = { fairchildMenuItem1, fairchildMenuItem2, fairchildMenuItem3, fairchildMenuItem4, fairchildMenuItem5 }; +static const char* const menuOptionsFAIRCHILD[] PROGMEM = { FSTRING_SELECT_CART, FSTRING_READ_ROM, FSTRING_SET_SIZE, fairchildMenuItem4, FSTRING_RESET }; void setup_FAIRCHILD() { // Request 5V @@ -125,7 +121,7 @@ void setup_FAIRCHILD() { checkStatus_FAIRCHILD(); strcpy(romName, "FAIRCHILD"); - mode = mode_FAIRCHILD; + mode = CORE_FAIRCHILD; } void fairchildMenu() { @@ -478,7 +474,7 @@ void readROM_FAIRCHILD() { calcCRC(fileName, cartsize, NULL, 0); - println_Msg(F("")); + println_Msg(FS(FSTRING_EMPTY)); print_STR(press_button_STR, 1); display_Update(); wait(); @@ -533,7 +529,7 @@ void read16K_FAIRCHILD() // Read 16K Bytes calcCRC(fileName, 0x4000, NULL, 0); - println_Msg(F("")); + println_Msg(FS(FSTRING_EMPTY)); print_STR(press_button_STR, 1); display_Update(); wait(); @@ -544,21 +540,21 @@ void read16K_FAIRCHILD() // Read 16K Bytes //****************************************** void setROMSize_FAIRCHILD() { -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display_Clear(); if (fairchildlo == fairchildhi) newfairchildsize = fairchildlo; else { - int b = 0; + uint8_t b = 0; int i = fairchildlo; display_Clear(); print_Msg(F("ROM Size: ")); println_Msg(FAIRCHILD[i]); - println_Msg(F("")); -#if defined(enable_OLED) + println_Msg(FS(FSTRING_EMPTY)); +#if defined(ENABLE_OLED) print_STR(press_to_change_STR, 1); print_STR(right_to_select_STR, 1); -#elif defined(enable_LCD) +#elif defined(ENABLE_LCD) print_STR(rotate_to_change_STR, 1); print_STR(press_to_select_STR, 1); #endif @@ -575,11 +571,11 @@ void setROMSize_FAIRCHILD() { display_Clear(); print_Msg(F("ROM Size: ")); println_Msg(FAIRCHILD[i]); - println_Msg(F("")); -#if defined(enable_OLED) + println_Msg(FS(FSTRING_EMPTY)); +#if defined(ENABLE_OLED) print_STR(press_to_change_STR, 1); print_STR(right_to_select_STR, 1); -#elif defined(enable_LCD) +#elif defined(ENABLE_LCD) print_STR(rotate_to_change_STR, 1); print_STR(press_to_select_STR, 1); #endif @@ -594,11 +590,11 @@ void setROMSize_FAIRCHILD() { display_Clear(); print_Msg(F("ROM Size: ")); println_Msg(FAIRCHILD[i]); - println_Msg(F("")); -#if defined(enable_OLED) + println_Msg(FS(FSTRING_EMPTY)); +#if defined(ENABLE_OLED) print_STR(press_to_change_STR, 1); print_STR(right_to_select_STR, 1); -#elif defined(enable_LCD) +#elif defined(ENABLE_LCD) print_STR(rotate_to_change_STR, 1); print_STR(press_to_select_STR, 1); #endif @@ -636,7 +632,7 @@ setrom: newfairchildsize = sizeROM.toInt() + fairchildlo; if (newfairchildsize > fairchildhi) { Serial.println(F("SIZE NOT SUPPORTED")); - Serial.println(F("")); + Serial.println(FSTRING_EMPTY); goto setrom; } } @@ -655,11 +651,11 @@ void checkStatus_FAIRCHILD() { EEPROM_writeAnything(8, fairchildsize); } -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display_Clear(); println_Msg(F("CHANNEL F READER")); println_Msg(F("CURRENT SETTINGS")); - println_Msg(F("")); + println_Msg(FS(FSTRING_EMPTY)); print_Msg(F("ROM SIZE: ")); print_Msg(FAIRCHILD[fairchildsize]); println_Msg(F("K")); @@ -669,7 +665,7 @@ void checkStatus_FAIRCHILD() { Serial.print(F("CURRENT ROM SIZE: ")); Serial.print(FAIRCHILD[fairchildsize]); Serial.println(F("K")); - Serial.println(F("")); + Serial.println(FSTRING_EMPTY); #endif } @@ -722,7 +718,7 @@ bool readVals_FAIRCHILD(char* fairchildgame, char* fairchildrr, char* fairchildl bool getCartListInfo_FAIRCHILD() { bool buttonreleased = 0; bool cartselected = 0; -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display_Clear(); println_Msg(F(" HOLD TO FAST CYCLE")); display_Update(); @@ -730,9 +726,9 @@ bool getCartListInfo_FAIRCHILD() { Serial.println(F("HOLD BUTTON TO FAST CYCLE")); #endif delay(2000); -#if defined(enable_OLED) +#if defined(ENABLE_OLED) buttonVal1 = (PIND & (1 << 7)); // PD7 -#elif defined(enable_LCD) +#elif defined(ENABLE_LCD) boolean buttonVal1 = (PING & (1 << 2)); //PG2 #endif if (buttonVal1 == LOW) { // Button Held - Fast Cycle @@ -741,19 +737,19 @@ bool getCartListInfo_FAIRCHILD() { if (strcmp(fairchildcsvEND, fairchildgame) == 0) { fairchildcsvFile.seek(0); // Restart } else { -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display_Clear(); println_Msg(F("CART TITLE:")); - println_Msg(F("")); + println_Msg(FS(FSTRING_EMPTY)); println_Msg(fairchildgame); display_Update(); #else Serial.print(F("CART TITLE:")); Serial.println(fairchildgame); #endif -#if defined(enable_OLED) +#if defined(ENABLE_OLED) buttonVal1 = (PIND & (1 << 7)); // PD7 -#elif defined(enable_LCD) +#elif defined(ENABLE_LCD) buttonVal1 = (PING & (1 << 2)); //PG2 #endif if (buttonVal1 == HIGH) { // Button Released @@ -766,41 +762,41 @@ bool getCartListInfo_FAIRCHILD() { } } } -#if defined(enable_OLED) +#if defined(ENABLE_OLED) buttonVal1 = (PIND & (1 << 7)); // PD7 -#elif defined(enable_LCD) +#elif defined(ENABLE_LCD) buttonVal1 = (PING & (1 << 2)); //PG2 #endif if (buttonVal1 == HIGH) // Button Released break; } } -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display.setCursor(0, 56); println_Msg(F("FAST CYCLE OFF")); display_Update(); #else - Serial.println(F("")); + Serial.println(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(F("")); + Serial.println(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)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display_Clear(); println_Msg(F("CART TITLE:")); - println_Msg(F("")); + println_Msg(FS(FSTRING_EMPTY)); println_Msg(fairchildgame); display.setCursor(0, 48); -#if defined(enable_OLED) +#if defined(ENABLE_OLED) print_STR(press_to_change_STR, 1); print_STR(right_to_select_STR, 1); -#elif defined(enable_LCD) +#elif defined(ENABLE_LCD) print_STR(rotate_to_change_STR, 1); print_STR(press_to_select_STR, 1); #endif @@ -810,7 +806,7 @@ bool getCartListInfo_FAIRCHILD() { Serial.println(fairchildgame); #endif while (1) { // Single Step - int b = checkButton(); + uint8_t b = checkButton(); if (b == 1) { // Continue (press) break; } @@ -824,7 +820,7 @@ bool getCartListInfo_FAIRCHILD() { newfairchildsize = strtol(fairchildrr, NULL, 10); EEPROM_writeAnything(8, newfairchildsize); cartselected = 1; // SELECTION MADE -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) println_Msg(F("SELECTION MADE")); display_Update(); #else @@ -839,8 +835,8 @@ bool getCartListInfo_FAIRCHILD() { } } } -#if (defined(enable_OLED) || defined(enable_LCD)) - println_Msg(F("")); +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) + println_Msg(FS(FSTRING_EMPTY)); println_Msg(F("END OF FILE")); display_Update(); #else @@ -852,10 +848,10 @@ bool getCartListInfo_FAIRCHILD() { void checkCSV_FAIRCHILD() { if (getCartListInfo_FAIRCHILD()) { -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display_Clear(); println_Msg(F("CART SELECTED")); - println_Msg(F("")); + println_Msg(FS(FSTRING_EMPTY)); println_Msg(fairchildgame); display_Update(); // Display Settings @@ -864,16 +860,16 @@ void checkCSV_FAIRCHILD() { println_Msg(newfairchildsize); display_Update(); #else - Serial.println(F("")); + Serial.println(FSTRING_EMPTY); Serial.println(F("CART SELECTED")); Serial.println(fairchildgame); // Display Settings Serial.print(F("CODE: R")); Serial.println(newfairchildsize); - Serial.println(F("")); + Serial.println(FSTRING_EMPTY); #endif } else { -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display.setCursor(0, 56); println_Msg(F("NO SELECTION")); display_Update(); @@ -884,7 +880,7 @@ void checkCSV_FAIRCHILD() { } void setCart_FAIRCHILD() { -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display_Clear(); println_Msg(fairchildcartCSV); display_Update(); @@ -894,7 +890,7 @@ void setCart_FAIRCHILD() { sd.chdir(folder); // Switch Folder fairchildcsvFile = sd.open(fairchildcartCSV, O_READ); if (!fairchildcsvFile) { -#if (defined(enable_OLED) || defined(enable_LCD)) +#if (defined(ENABLE_OLED) || defined(ENABLE_LCD)) display_Clear(); println_Msg(F("CSV FILE NOT FOUND!")); display_Update(); |