make cast in read function explicit and reduce duplicate read functions

This commit is contained in:
smesgr9000 2024-05-03 19:12:48 +02:00
parent e8e6d15a72
commit 990b61ca3a
14 changed files with 88 additions and 139 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 {

View File

@ -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);
}

View File

@ -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"));
}

View File

@ -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

View File

@ -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 {

View File

@ -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() {

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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 {

View File

@ -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"));
}