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_Update();
setup_NES();
#ifdef nointro
getMapping();
#endif
checkStatus_NES();
nesMenu();
break;
@ -1227,6 +1230,9 @@ void consoleMenu() {
display_Clear();
display_Update();
setup_NES();
#ifdef nointro
getMapping();
#endif
checkStatus_NES();
nesMenu();
break;

View File

@ -526,6 +526,7 @@ void getMapping() {
}
oldcrc32 = ~oldcrc32;
oldcrc32MMC3 = ~oldcrc32MMC3;
boolean browseDatabase;
// Filter out all 0xFF checksums at 0x8000 and 0xE000
if (oldcrc32 == 0xBD7BC39F && oldcrc32MMC3 == 0xBD7BC39F) {
@ -534,7 +535,7 @@ void getMapping() {
display_Update();
delay(1000);
setDefaultRomName();
selectMapping(database);
browseDatabase = selectMapping(database);
} else {
println_Msg(F("Searching database"));
print_Msg(F("for "));
@ -573,147 +574,149 @@ void getMapping() {
// Change ROM name to CART
setDefaultRomName();
selectMapping(database);
browseDatabase = selectMapping(database);
}
}
byte fastScrolling = 1;
if (browseDatabase) {
byte fastScrolling = 1;
// Display database
while (database.available()) {
byte iNES[16];
byte* output;
char* input;
// Display database
while (database.available()) {
byte iNES[16];
byte* output;
char* input;
struct database_entry entry;
struct database_entry entry;
display_Clear();
readDatabaseEntry(database, &entry);
display_Clear();
readDatabaseEntry(database, &entry);
input = entry.iNES_str;
output = iNES;
for (byte i = 0; i < sizeof(iNES); i++) {
unsigned int buf;
input = entry.iNES_str;
output = iNES;
for (byte i = 0; i < sizeof(iNES); i++) {
unsigned int buf;
sscanf(input, "%2X", &buf);
*(output++) = buf;
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);
}
sscanf(input, "%2X", &buf);
*(output++) = buf;
input += 2;
}
continue;
}
if (b == 2) {
// 2: Previous record
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)
rewind_line(database, fastScrolling * 3 + 3);
println_Msg(F(" (fast)"));
else
rewind_line(database, 6);
continue;
}
if (b == 4) {
// 4: Toggle Fast Scrolling
if (fastScrolling == 1)
fastScrolling = 30;
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
fastScrolling = 1;
continue;
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;
}
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();
}
@ -733,7 +736,7 @@ static void readDatabaseEntry(FsFile& database, struct database_entry* entry) {
entry->crc512 = strtoul(entry->crc512_str, NULL, 16);
}
static void selectMapping(FsFile& database) {
boolean selectMapping(FsFile& database) {
// Select starting letter
byte myLetter = starting_letter();
@ -744,6 +747,7 @@ static void selectMapping(FsFile& database) {
setPRGSize();
setCHRSize();
setRAMSize();
return 0;
} else {
#ifdef global_log
// Disable log to prevent unnecessary logging
@ -766,6 +770,7 @@ static void selectMapping(FsFile& database) {
dont_log = false;
#endif
}
return 1;
}
void readRom_NES() {
@ -2334,9 +2339,6 @@ void checkMMC6() { // Detect MMC6 Carts - read PRG 0x3E00A ("START
}
void checkStatus_NES() {
#ifdef nointro
getMapping();
#endif
EEPROM_readAnything(7, mapper);
EEPROM_readAnything(8, prgsize);
EEPROM_readAnything(9, chrsize);