diff --git a/Cart_Reader/2600.ino b/Cart_Reader/2600.ino index 32e234c..13b9850 100644 --- a/Cart_Reader/2600.ino +++ b/Cart_Reader/2600.ino @@ -171,7 +171,7 @@ void readSegment_2600(uint16_t startaddr, uint16_t endaddr) { } void readDataArray_2600(uint16_t addr, uint16_t size) { - for (int w = 0; w < size; w++) { + for (uint16_t w = 0; w < size; w++) { sdBuffer[w] = readData_2600(addr + w); } myFile.write(sdBuffer, size); @@ -709,9 +709,9 @@ setmapper: //****************************************** // CART SELECT CODE //****************************************** -void readDataLine_2600(FsFile& database, byte* gameMapper) { +void readDataLine_2600(FsFile& database, void* gameMapper) { // Read mapper with three ascii character and subtract 48 to convert to decimal - (*gameMapper) = ((database.read() - 48) * 100) + ((database.read() - 48) * 10) + (database.read() - 48); + (*(byte*)gameMapper) = ((database.read() - 48) * 100) + ((database.read() - 48) * 10) + (database.read() - 48); // Skip rest of line database.seekCur(2); diff --git a/Cart_Reader/5200.ino b/Cart_Reader/5200.ino index 5d9d2aa..d1c743d 100644 --- a/Cart_Reader/5200.ino +++ b/Cart_Reader/5200.ino @@ -508,30 +508,11 @@ setmapper: //****************************************** // CART SELECT CODE //****************************************** -struct database_entry_5200 { - byte gameMapper; - byte gameSize; -}; - -void readDataLine_5200(FsFile& database, struct database_entry_5200* entry) { - // Read mapper - entry->gameMapper = database.read() - 48; - - // Skip over semicolon - database.seekCur(1); - - // Read rom size - entry->gameSize = database.read() - 48; - - // Skip rest of line - database.seekCur(2); -} - void setCart_5200() { //go to root sd.chdir(); - struct database_entry_5200 entry; + struct database_entry_mapper_size entry; // Select starting letter byte myLetter = starting_letter(); @@ -540,7 +521,7 @@ void setCart_5200() { if (myFile.open("5200.txt", O_READ)) { seek_first_letter_in_database(myFile, myLetter); - if(checkCartSelection(myFile, &readDataLine_5200, &entry)) { + if(checkCartSelection(myFile, &readDataLineMapperSize, &entry)) { EEPROM_writeAnything(7, entry.gameMapper); EEPROM_writeAnything(8, entry.gameSize); } diff --git a/Cart_Reader/7800.ino b/Cart_Reader/7800.ino index 357c987..157ee29 100644 --- a/Cart_Reader/7800.ino +++ b/Cart_Reader/7800.ino @@ -664,30 +664,12 @@ setmapper: //****************************************** // CART SELECT CODE //****************************************** -struct database_entry_7800 { - byte gameMapper; - byte gameSize; -}; - -void readDataLine_7800(FsFile& database, struct database_entry_7800* entry) { - // Read mapper - entry->gameMapper = database.read() - 48; - - // Skip over semicolon - database.seekCur(1); - - // Read rom size - entry->gameSize = database.read() - 48; - - // Skip rest of line - database.seekCur(2); -} void setCart_7800() { //go to root sd.chdir(); - struct database_entry_7800 entry; + struct database_entry_mapper_size entry; // Select starting letter byte myLetter = starting_letter(); @@ -696,7 +678,7 @@ void setCart_7800() { if (myFile.open("7800.txt", O_READ)) { seek_first_letter_in_database(myFile, myLetter); - if(checkCartSelection(myFile, &readDataLine_7800, &entry)) { + if(checkCartSelection(myFile, &readDataLineMapperSize, &entry)) { EEPROM_writeAnything(7, entry.gameMapper); EEPROM_writeAnything(8, entry.gameSize); } diff --git a/Cart_Reader/ARC.ino b/Cart_Reader/ARC.ino index 28da27d..ed5a007 100644 --- a/Cart_Reader/ARC.ino +++ b/Cart_Reader/ARC.ino @@ -281,14 +281,6 @@ void checkStatus_ARC() { //****************************************** // CART SELECT CODE //****************************************** -void readDataLine_ARC(FsFile& database, byte* gameSize) { - // Read rom size - (*gameSize) = database.read() - 48; - - // Skip rest of line - database.seekCur(2); -} - void setCart_ARC() { //go to root sd.chdir(); @@ -302,7 +294,7 @@ void setCart_ARC() { if (myFile.open("arccart.txt", O_READ)) { // seek_first_letter_in_database(myFile, myLetter); - if(checkCartSelection(myFile, &readDataLine_ARC, &gameSize)) { + if(checkCartSelection(myFile, &readDataLineSingleDigit, &gameSize)) { EEPROM_writeAnything(8, gameSize); } } else { diff --git a/Cart_Reader/C64.ino b/Cart_Reader/C64.ino index 72c8940..eabe9dd 100644 --- a/Cart_Reader/C64.ino +++ b/Cart_Reader/C64.ino @@ -913,30 +913,12 @@ void printMapper_C64(byte c64maplabel) { //****************************************** // CART SELECT CODE //****************************************** -struct database_entry_C64 { - byte gameMapper; - byte gameSize; -}; - -void readDataLine_C64(FsFile& database, struct database_entry_C64* entry) { - // Read mapper with two ascii character and subtract 48 to convert to decimal - entry->gameMapper = ((database.read() - 48) * 10) + (database.read() - 48); - - // Skip over semicolon - database.seekCur(1); - - // Read size and subtract 48 to convert to decimal - entry->gameSize = database.read() - 48; - - // Skip rest of line - database.seekCur(2); -} void setCart_C64() { //go to root sd.chdir(); - struct database_entry_C64 entry; + struct database_entry_mapper_size entry; // Select starting letter byte myLetter = starting_letter(); @@ -945,7 +927,7 @@ void setCart_C64() { if (myFile.open("c64cart.txt", O_READ)) { seek_first_letter_in_database(myFile, myLetter); - if(checkCartSelection(myFile, &readDataLine_C64, &entry)) { + if(checkCartSelection(myFile, &readDataLineMapperSize, &entry)) { EEPROM_writeAnything(7, entry.gameMapper); EEPROM_writeAnything(8, entry.gameSize); } diff --git a/Cart_Reader/COLV.ino b/Cart_Reader/COLV.ino index a088c59..201e081 100644 --- a/Cart_Reader/COLV.ino +++ b/Cart_Reader/COLV.ino @@ -317,7 +317,8 @@ struct database_entry_COL { byte gameSize; }; -void readDataLine_COL(FsFile& database, struct database_entry_COL* entry) { +void readDataLine_COL(FsFile& database, void* entry) { + struct database_entry_COL* castEntry = (database_entry_COL*)entry; // Read CRC32 checksum for (byte i = 0; i < 8; i++) { @@ -329,7 +330,7 @@ void readDataLine_COL(FsFile& database, struct database_entry_COL* entry) { // Read CRC32 of first 512 bytes for (byte i = 0; i < 8; i++) { - entry->crc_search[i] = char(database.read()); + castEntry->crc_search[i] = char(database.read()); } // Skip over semicolon @@ -337,15 +338,17 @@ void readDataLine_COL(FsFile& database, struct database_entry_COL* entry) { // Read rom size // Read the next ascii character and subtract 48 to convert to decimal - entry->gameSize = ((database.read() - 48) * 10) + (database.read() - 48); + castEntry->gameSize = ((database.read() - 48) * 10) + (database.read() - 48); // Skip rest of line database.seekCur(2); } -void printDataLine_COL(struct database_entry_COL* entry) { +void printDataLine_COL(void* entry) { + struct database_entry_COL* castEntry = (database_entry_COL*)entry; + print_Msg(F("Size: ")); - print_Msg(entry->gameSize); + print_Msg(castEntry->gameSize); println_Msg(F("KB")); } diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index a4b77f3..0d566af 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -681,6 +681,45 @@ void seek_first_letter_in_database(FsFile& database, byte myLetter) { #endif } +#if (defined(ENABLE_ARC) || defined(ENABLE_FAIRCHILD) || defined(ENABLE_VECTREX)) +// read single digit data line as byte +void readDataLineSingleDigit(FsFile& database, void* byteData) { + // Read rom size + (*(byte*)byteData) = database.read() - 48; + + // Skip rest of line + database.seekCur(2); +} +#endif + +#if (defined(ENABLE_ODY2) || defined(ENABLE_5200) || defined(ENABLE_7800) || defined(ENABLE_C64)) +struct database_entry_mapper_size { + byte gameMapper; + byte gameSize; +}; + +// read database entry with mapper and size digits +void readDataLineMapperSize(FsFile& database, void* entry) { + struct database_entry_mapper_size* castEntry = (database_entry_mapper_size*)entry; + // Read mapper + castEntry->gameMapper = database.read() - 48; + + // if next char is not a semicolon expect an additional digit + char temp = database.read(); + if(temp != ',') { + castEntry->gameMapper = (castEntry->gameMapper * 10) + (temp - 48); + // Skip over semicolon + database.seekCur(1); + } + + // Read rom size + castEntry->gameSize = database.read() - 48; + + // Skip rest of line + database.seekCur(2); +} +#endif + // navigate through the database file using OSSC input buttons. Requires function pointer readData for reading device specific data line from database // printDataLine - optional callback for printing device specific data informations about the currently browsed game // setRomName - callback function to set rom name if game is selected diff --git a/Cart_Reader/FAIRCHILD.ino b/Cart_Reader/FAIRCHILD.ino index 5d372be..757f5f7 100644 --- a/Cart_Reader/FAIRCHILD.ino +++ b/Cart_Reader/FAIRCHILD.ino @@ -622,14 +622,6 @@ void checkStatus_FAIRCHILD() { //****************************************** // CART SELECT CODE //****************************************** -void readDataLine_FAIRCHILD(FsFile& database, byte* gameSize) { - // Read rom size - (*gameSize) = database.read() - 48; - - // Skip rest of line - database.seekCur(2); -} - void setCart_FAIRCHILD() { //go to root sd.chdir(); @@ -643,7 +635,7 @@ void setCart_FAIRCHILD() { if (myFile.open("fairchildcart.txt", O_READ)) { // seek_first_letter_in_database(myFile, myLetter); - if(checkCartSelection(myFile, &readDataLine_ARC, &gameSize)) { + if(checkCartSelection(myFile, &readDataLineSingleDigit, &gameSize)) { EEPROM_writeAnything(8, gameSize); } } else { diff --git a/Cart_Reader/INTV.ino b/Cart_Reader/INTV.ino index 492b196..383f272 100644 --- a/Cart_Reader/INTV.ino +++ b/Cart_Reader/INTV.ino @@ -641,8 +641,8 @@ struct database_entry_INTV { byte gameSize; }; -void readDataLine_INTV(FsFile& database, struct database_entry_INTV* entry) { - +void readDataLine_INTV(FsFile& database, void* entry) { + struct database_entry_INTV* castEntry = (database_entry_INTV*)entry; // Read CRC32 checksum for (byte i = 0; i < 8; i++) { checksumStr[i] = char(database.read()); @@ -653,21 +653,21 @@ void readDataLine_INTV(FsFile& database, struct database_entry_INTV* entry) { // Read CRC32 of first 512 bytes for (byte i = 0; i < 8; i++) { - entry->crc_search[i] = char(database.read()); + castEntry->crc_search[i] = char(database.read()); } // Skip over semicolon database.seekCur(1); // Read mapper - entry->gameMapper = database.read() - 48; + castEntry->gameMapper = database.read() - 48; // Skip over semicolon database.seekCur(1); // Read rom size // Read the next ascii character and subtract 48 to convert to decimal - entry->gameSize = ((database.read() - 48) * 10) + (database.read() - 48); + castEntry->gameSize = ((database.read() - 48) * 10) + (database.read() - 48); // Skip over semicolon database.seekCur(1); @@ -679,12 +679,13 @@ void readDataLine_INTV(FsFile& database, struct database_entry_INTV* entry) { database.seekCur(2); } -void printDataLine_INTV(struct database_entry_INTV* entry) { +void printDataLine_INTV(void* entry) { + struct database_entry_INTV* castEntry = (database_entry_INTV*)entry; print_Msg(F("Size: ")); - print_Msg(entry->gameSize); + print_Msg(castEntry->gameSize); println_Msg(F("KB")); print_Msg(F("Mapper: ")); - println_Msg(entry->gameMapper); + println_Msg(castEntry->gameMapper); } void setCart_INTV() { diff --git a/Cart_Reader/MSX.ino b/Cart_Reader/MSX.ino index ea78d0f..e39eb54 100644 --- a/Cart_Reader/MSX.ino +++ b/Cart_Reader/MSX.ino @@ -1281,21 +1281,22 @@ struct database_entry_MSX { byte ramSize; }; -void readDataLine_MSX(FsFile& database, struct database_entry_MSX* entry) { +void readDataLine_MSX(FsFile& database, void* entry) { + database_entry_MSX* castEntry = (database_entry_MSX*)entry; // Read mapper - entry->gameMapper = ((database.read() - 48) * 10) + (database.read() - 48); + castEntry->gameMapper = ((database.read() - 48) * 10) + (database.read() - 48); // Skip over semicolon database.seekCur(1); // Read rom size - entry->gameSize = database.read() - 48; + castEntry->gameSize = database.read() - 48; // Skip over semicolon database.seekCur(1); // Read ram size - entry->ramSize = database.read() - 48; + castEntry->ramSize = database.read() - 48; // Skip rest of line database.seekCur(2); diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index 6f4f757..1865ef3 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -511,12 +511,13 @@ void setRomnameFromString(const char* input) { } } -void printDataLine_NES(struct database_entry* entry) { +void printDataLine_NES(void* entry) { + struct database_entry* castEntry = (struct database_entry*) entry; uint8_t iNES[16]; uint8_t* output; char* input; - input = entry->iNES_str; + input = castEntry->iNES_str; output = iNES; for (uint8_t i = 0; i < sizeof(iNES); i++) { unsigned int buf; @@ -670,7 +671,8 @@ static void readDatabaseEntry(FsFile& database, struct database_entry* entry) { skip_line(&database); } -void readDataLine_NES(FsFile& database, struct database_entry* entry) { +void readDataLine_NES(FsFile& database, void* e) { + struct database_entry* entry = (database_entry*)e; get_line(entry->crc_str, &database, sizeof(entry->crc_str)); entry->crc_str[8] = 0; diff --git a/Cart_Reader/ODY2.ino b/Cart_Reader/ODY2.ino index 7388861..aaf7fcf 100644 --- a/Cart_Reader/ODY2.ino +++ b/Cart_Reader/ODY2.ino @@ -369,30 +369,11 @@ void checkStatus_ODY2() { //****************************************** // CART SELECT CODE //****************************************** -struct database_entry_ODY2 { - byte gameMapper; - byte gameSize; -}; - -void readDataLine_ODY2(FsFile& database, struct database_entry_ODY2* entry) { - // Read mapper - entry->gameMapper = database.read() - 48; - - // Skip over semicolon - database.seekCur(1); - - // Read rom size - entry->gameSize = database.read() - 48; - - // Skip rest of line - database.seekCur(2); -} - void setCart_ODY2() { //go to root sd.chdir(); - struct database_entry_ODY2 entry; + struct database_entry_mapper_size entry; // Select starting letter byte myLetter = starting_letter(); @@ -401,7 +382,7 @@ void setCart_ODY2() { if (myFile.open("ody2cart.txt", O_READ)) { seek_first_letter_in_database(myFile, myLetter); - if(checkCartSelection(myFile, &readDataLine_ODY2, &entry)) { + if(checkCartSelection(myFile, &readDataLineMapperSize, &entry)) { EEPROM_writeAnything(7, entry.gameMapper); EEPROM_writeAnything(8, entry.gameSize); } diff --git a/Cart_Reader/VECTREX.ino b/Cart_Reader/VECTREX.ino index b997a18..4df8110 100644 --- a/Cart_Reader/VECTREX.ino +++ b/Cart_Reader/VECTREX.ino @@ -340,14 +340,6 @@ void checkStatus_VECTREX() { //****************************************** // CART SELECT CODE //****************************************** -void readDataLine_VECTREX(FsFile& database, byte* gameSize) { - // Read rom size - (*gameSize) = database.read() - 48; - - // Skip rest of line - database.seekCur(2); -} - void setCart_VECTREX() { //go to root sd.chdir(); @@ -361,7 +353,7 @@ void setCart_VECTREX() { if (myFile.open("vectrexcart.txt", O_READ)) { // seek_first_letter_in_database(myFile, myLetter); - if(checkCartSelection(myFile, &readDataLine_ARC, &gameSize)) { + if(checkCartSelection(myFile, &readDataLineSingleDigit, &gameSize)) { EEPROM_writeAnything(8, gameSize); } } else { diff --git a/Cart_Reader/WSV.ino b/Cart_Reader/WSV.ino index c48cb16..e4e997a 100644 --- a/Cart_Reader/WSV.ino +++ b/Cart_Reader/WSV.ino @@ -330,8 +330,8 @@ struct database_entry_WSV { byte gameSize; }; -void readDataLine_WSV(FsFile& database, struct database_entry_WSV* entry) { - +void readDataLine_WSV(FsFile& database, void* entry) { + struct database_entry_WSV* castEntry = (database_entry_WSV*)entry; // Read CRC32 checksum for (byte i = 0; i < 8; i++) { checksumStr[i] = char(database.read()); @@ -342,7 +342,7 @@ void readDataLine_WSV(FsFile& database, struct database_entry_WSV* entry) { // Read CRC32 of first 512 bytes for (byte i = 0; i < 8; i++) { - entry->crc_search[i] = char(database.read()); + castEntry->crc_search[i] = char(database.read()); } // Skip over semicolon @@ -350,18 +350,19 @@ void readDataLine_WSV(FsFile& database, struct database_entry_WSV* entry) { // Read rom size // Read the next ascii character and subtract 48 to convert to decimal - entry->gameSize = ((database.read() - 48) * 10) + (database.read() - 48); + castEntry->gameSize = ((database.read() - 48) * 10) + (database.read() - 48); // Skip rest of line database.seekCur(2); } -void printDataLine_WSV(struct database_entry_WSV* entry) { +void printDataLine_WSV(void* entry) { + struct database_entry_WSV* castEntry = (database_entry_WSV*)entry; print_Msg(F("Size: ")); - if (entry->gameSize == 51) + if (castEntry->gameSize == 51) print_Msg(F("512")); else - print_Msg(entry->gameSize); + print_Msg(castEntry->gameSize); println_Msg(F("KB")); }