Fix NES manual mapper selection

This commit is contained in:
sanni 2022-11-02 00:32:54 +01:00
parent 78aa7a3d34
commit a3b1882e88
2 changed files with 142 additions and 134 deletions

View File

@ -971,6 +971,9 @@ void mainMenu() {
display_Clear(); display_Clear();
display_Update(); display_Update();
setup_NES(); setup_NES();
#ifdef nointro
getMapping();
#endif
checkStatus_NES(); checkStatus_NES();
nesMenu(); nesMenu();
break; break;
@ -1227,6 +1230,9 @@ void consoleMenu() {
display_Clear(); display_Clear();
display_Update(); display_Update();
setup_NES(); setup_NES();
#ifdef nointro
getMapping();
#endif
checkStatus_NES(); checkStatus_NES();
nesMenu(); nesMenu();
break; break;

View File

@ -526,6 +526,7 @@ void getMapping() {
} }
oldcrc32 = ~oldcrc32; oldcrc32 = ~oldcrc32;
oldcrc32MMC3 = ~oldcrc32MMC3; oldcrc32MMC3 = ~oldcrc32MMC3;
boolean browseDatabase;
// Filter out all 0xFF checksums at 0x8000 and 0xE000 // Filter out all 0xFF checksums at 0x8000 and 0xE000
if (oldcrc32 == 0xBD7BC39F && oldcrc32MMC3 == 0xBD7BC39F) { if (oldcrc32 == 0xBD7BC39F && oldcrc32MMC3 == 0xBD7BC39F) {
@ -534,7 +535,7 @@ void getMapping() {
display_Update(); display_Update();
delay(1000); delay(1000);
setDefaultRomName(); setDefaultRomName();
selectMapping(database); browseDatabase = selectMapping(database);
} else { } else {
println_Msg(F("Searching database")); println_Msg(F("Searching database"));
print_Msg(F("for ")); print_Msg(F("for "));
@ -573,147 +574,149 @@ void getMapping() {
// Change ROM name to CART // Change ROM name to CART
setDefaultRomName(); setDefaultRomName();
selectMapping(database); browseDatabase = selectMapping(database);
} }
} }
byte fastScrolling = 1; if (browseDatabase) {
byte fastScrolling = 1;
// Display database // Display database
while (database.available()) { while (database.available()) {
byte iNES[16]; byte iNES[16];
byte* output; byte* output;
char* input; char* input;
struct database_entry entry; struct database_entry entry;
display_Clear(); display_Clear();
readDatabaseEntry(database, &entry); readDatabaseEntry(database, &entry);
input = entry.iNES_str; input = entry.iNES_str;
output = iNES; output = iNES;
for (byte i = 0; i < sizeof(iNES); i++) { for (byte i = 0; i < sizeof(iNES); i++) {
unsigned int buf; unsigned int buf;
sscanf(input, "%2X", &buf); sscanf(input, "%2X", &buf);
*(output++) = buf; *(output++) = buf;
input += 2; input += 2;
}
mapper = (iNES[6] >> 4) | (iNES[7] & 0xF0) | (iNES[8] & 0x0F);
if ((iNES[9] & 0x0F) != 0x0F) {
// simple notation
prgsize = (iNES[4] | ((iNES[9] & 0x0F) << 8)); //*16
} else {
// exponent-multiplier notation
prgsize = (((1 << (iNES[4] >> 2)) * ((iNES[4] & 0b11) * 2 + 1)) >> 14); //*16
}
if (prgsize != 0)
prgsize = (int(log(prgsize) / log(2)));
if ((iNES[9] & 0xF0) != 0xF0) {
// simple notation
chrsize = (uppow2(iNES[5] | ((iNES[9] & 0xF0) << 4))) * 2; //*4
} else {
// exponent-multiplier notation
chrsize = (((1 << (iNES[5] >> 2)) * ((iNES[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4
}
if (chrsize != 0)
chrsize = (int(log(chrsize) / log(2)));
ramsize = ((iNES[10] & 0xF0) ? (64 << ((iNES[10] & 0xF0) >> 4)) : 0) / 4096; //*4
if (ramsize != 0)
ramsize = (int(log(ramsize) / log(2)));
prg = (int_pow(2, prgsize)) * 16;
if (chrsize == 0)
chr = 0; // 0K
else
chr = (int_pow(2, chrsize)) * 4;
if (ramsize == 0)
ram = 0; // 0K
else if (mapper == 82)
ram = 5; // 5K
else
ram = (int_pow(2, ramsize)) * 4;
// Mapper Variants
// Identify variant for use across multiple functions
if (mapper == 4) { // Check for MMC6/MMC3
checkMMC6();
if (mmc6)
ram = 1; // 1K
}
#ifdef global_log
// Disable log to prevent unnecessary logging
//println_Log(F("Get Mapping from List"));
dont_log = true;
#endif
println_Msg(entry.filename);
printNESSettings();
#if defined(enable_OLED)
print_STR(press_to_change_STR, 0);
if (fastScrolling > 1)
println_Msg(F(" (fast)"));
else
println_Msg("");
print_STR(right_to_select_STR, 1);
#elif defined(enable_LCD)
print_STR(rotate_to_change_STR, 0);
if (fastScrolling > 1)
println_Msg(F(" (fast)"));
else
println_Msg("");
print_STR(press_to_select_STR, 1);
#elif defined(SERIAL_MONITOR)
println_Msg(F("U/D to Change"));
println_Msg(F("Space to Select"));
#endif
display_Update();
#ifdef global_log
// Enable log again
dont_log = false;
#endif
int b = 0;
do {
b = checkButton();
} while (b == 0);
if (b == 1) {
// 1: Next record
if (fastScrolling > 1) {
for (byte skipped = 0; skipped < fastScrolling * 3; skipped++) {
skip_line(&database);
}
} }
continue;
} mapper = (iNES[6] >> 4) | (iNES[7] & 0xF0) | (iNES[8] & 0x0F);
if (b == 2) {
// 2: Previous record if ((iNES[9] & 0x0F) != 0x0F) {
// simple notation
prgsize = (iNES[4] | ((iNES[9] & 0x0F) << 8)); //*16
} else {
// exponent-multiplier notation
prgsize = (((1 << (iNES[4] >> 2)) * ((iNES[4] & 0b11) * 2 + 1)) >> 14); //*16
}
if (prgsize != 0)
prgsize = (int(log(prgsize) / log(2)));
if ((iNES[9] & 0xF0) != 0xF0) {
// simple notation
chrsize = (uppow2(iNES[5] | ((iNES[9] & 0xF0) << 4))) * 2; //*4
} else {
// exponent-multiplier notation
chrsize = (((1 << (iNES[5] >> 2)) * ((iNES[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4
}
if (chrsize != 0)
chrsize = (int(log(chrsize) / log(2)));
ramsize = ((iNES[10] & 0xF0) ? (64 << ((iNES[10] & 0xF0) >> 4)) : 0) / 4096; //*4
if (ramsize != 0)
ramsize = (int(log(ramsize) / log(2)));
prg = (int_pow(2, prgsize)) * 16;
if (chrsize == 0)
chr = 0; // 0K
else
chr = (int_pow(2, chrsize)) * 4;
if (ramsize == 0)
ram = 0; // 0K
else if (mapper == 82)
ram = 5; // 5K
else
ram = (int_pow(2, ramsize)) * 4;
// Mapper Variants
// Identify variant for use across multiple functions
if (mapper == 4) { // Check for MMC6/MMC3
checkMMC6();
if (mmc6)
ram = 1; // 1K
}
#ifdef global_log
// Disable log to prevent unnecessary logging
//println_Log(F("Get Mapping from List"));
dont_log = true;
#endif
println_Msg(entry.filename);
printNESSettings();
#if defined(enable_OLED)
print_STR(press_to_change_STR, 0);
if (fastScrolling > 1) if (fastScrolling > 1)
rewind_line(database, fastScrolling * 3 + 3); println_Msg(F(" (fast)"));
else else
rewind_line(database, 6); println_Msg("");
continue; print_STR(right_to_select_STR, 1);
} #elif defined(enable_LCD)
if (b == 4) { print_STR(rotate_to_change_STR, 0);
// 4: Toggle Fast Scrolling if (fastScrolling > 1)
if (fastScrolling == 1) println_Msg(F(" (fast)"));
fastScrolling = 30;
else else
fastScrolling = 1; println_Msg("");
continue; print_STR(press_to_select_STR, 1);
#elif defined(SERIAL_MONITOR)
println_Msg(F("U/D to Change"));
println_Msg(F("Space to Select"));
#endif
display_Update();
#ifdef global_log
// Enable log again
dont_log = false;
#endif
int b = 0;
do {
b = checkButton();
} while (b == 0);
if (b == 1) {
// 1: Next record
if (fastScrolling > 1) {
for (byte skipped = 0; skipped < fastScrolling * 3; skipped++) {
skip_line(&database);
}
}
continue;
}
if (b == 2) {
// 2: Previous record
if (fastScrolling > 1)
rewind_line(database, fastScrolling * 3 + 3);
else
rewind_line(database, 6);
continue;
}
if (b == 4) {
// 4: Toggle Fast Scrolling
if (fastScrolling == 1)
fastScrolling = 30;
else
fastScrolling = 1;
continue;
}
// anything else: select current record
setRomnameFromString(entry.filename);
// Save Mapper
EEPROM_writeAnything(7, mapper);
EEPROM_writeAnything(8, prgsize);
EEPROM_writeAnything(9, chrsize);
EEPROM_writeAnything(10, ramsize);
break;
} }
// anything else: select current record
setRomnameFromString(entry.filename);
// Save Mapper
EEPROM_writeAnything(7, mapper);
EEPROM_writeAnything(8, prgsize);
EEPROM_writeAnything(9, chrsize);
EEPROM_writeAnything(10, ramsize);
break;
} }
database.close(); database.close();
} }
@ -733,7 +736,7 @@ static void readDatabaseEntry(FsFile& database, struct database_entry* entry) {
entry->crc512 = strtoul(entry->crc512_str, NULL, 16); entry->crc512 = strtoul(entry->crc512_str, NULL, 16);
} }
static void selectMapping(FsFile& database) { boolean selectMapping(FsFile& database) {
// Select starting letter // Select starting letter
byte myLetter = starting_letter(); byte myLetter = starting_letter();
@ -744,6 +747,7 @@ static void selectMapping(FsFile& database) {
setPRGSize(); setPRGSize();
setCHRSize(); setCHRSize();
setRAMSize(); setRAMSize();
return 0;
} else { } else {
#ifdef global_log #ifdef global_log
// Disable log to prevent unnecessary logging // Disable log to prevent unnecessary logging
@ -766,6 +770,7 @@ static void selectMapping(FsFile& database) {
dont_log = false; dont_log = false;
#endif #endif
} }
return 1;
} }
void readRom_NES() { void readRom_NES() {
@ -2334,9 +2339,6 @@ void checkMMC6() { // Detect MMC6 Carts - read PRG 0x3E00A ("START
} }
void checkStatus_NES() { void checkStatus_NES() {
#ifdef nointro
getMapping();
#endif
EEPROM_readAnything(7, mapper); EEPROM_readAnything(7, mapper);
EEPROM_readAnything(8, prgsize); EEPROM_readAnything(8, prgsize);
EEPROM_readAnything(9, chrsize); EEPROM_readAnything(9, chrsize);