Fix adding iNES header when manually selecting mapper

This commit is contained in:
sanni 2022-07-07 23:20:45 +02:00
parent e80866a5ff
commit 5580dffff0
2 changed files with 63 additions and 19 deletions

View File

@ -406,6 +406,23 @@ void draw_progressbar(uint32_t processedsize, uint32_t totalsize);
byte eepbit[8];
byte eeptemp;
#ifdef no-intro
// Array to hold iNES header
byte iNES_HEADER[16];
//ID 0-3
//ROM_size 4
//VROM_size 5
//ROM_type 6
//ROM_type2 7
//ROM_type3 8
//Upper_ROM_VROM_size 9
//RAM_size 10
//VRAM_size 11
//TV_system 12
//VS_hardware 13
//reserved 14, 15
#endif
//******************************************
// CRC32
//******************************************
@ -583,9 +600,43 @@ boolean compareCRC(char* database, char* crcString, int offset) {
//if checksum search successful, rename the file and end search
if (strcmp(crc_search, crcStr) == 0)
{
#ifdef enable_NES
if (mode == mode_NES) {
// Rewind to iNES Header
myFile.seekSet(myFile.curPosition() - 36);
char iNES_STR[33];
// Read iNES header
get_line(iNES_STR, &myFile, 33);
// Convert "4E4553" to (0x4E, 0x45, 0x53)
byte iNES_BUF[2];
for (byte j = 0; j < 16; j++) {
sscanf(iNES_STR + j * 2, "%2X", iNES_BUF);
iNES_HEADER[j] = iNES_BUF[0];
}
//Skip CRLF
myFile.seekSet(myFile.curPosition() + 4);
}
#endif
// Close the file:
myFile.close();
//Write iNES header
#ifdef enable_NES
if (mode == mode_NES) {
// Write iNES header
sd.chdir(folder);
if (!myFile.open(fileName, O_RDWR)) {
print_Error(F("SD Error"), true);
}
for (byte z = 0; z < 16; z++) {
myFile.write(iNES_HEADER[z]);
}
myFile.close();
}
#endif
print_Msg(F(" -> "));
println_Msg(gamename);
@ -675,6 +726,7 @@ void mainMenu() {
#ifdef enable_NES
case 1:
mode = mode_NES;
display_Clear();
display_Update();
setup_NES();
@ -684,7 +736,6 @@ void mainMenu() {
checkStatus_NES(0);
#endif
nesMenu();
mode = mode_NES;
break;
#endif
@ -834,6 +885,7 @@ void addonsMenu() {
{
#ifdef enable_NES
case 0:
mode = mode_NES;
display_Clear();
display_Update();
setup_NES();
@ -843,7 +895,6 @@ void addonsMenu() {
checkStatus_NES(0);
#endif
nesMenu();
mode = mode_NES;
break;
#endif

View File

@ -375,21 +375,6 @@ void setup_NES() {
Get Mapping from no-intro SD database
*****************************************/
#ifdef no-intro
// Array to hold iNES header
byte iNES_HEADER[16];
//ID 0-3
//ROM_size 4
//VROM_size 5
//ROM_type 6
//ROM_type2 7
//ROM_type3 8
//Upper_ROM_VROM_size 9
//RAM_size 10
//VRAM_size 11
//TV_system 12
//VS_hardware 13
//reserved 14, 15
// no clue (taken from fceux)
uint32_t uppow2(uint32_t n) {
int x;
@ -426,6 +411,10 @@ boolean getMapping() {
// Filter out 0xFF checksum
if (strcmp(crcStr, "BD7BC39F") == 0) {
romName[0] = 'C';
romName[1] = 'A';
romName[2] = 'R';
romName[3] = 'T';
return 0;
}
else {
@ -451,7 +440,7 @@ boolean getMapping() {
// Skip over semicolon
myFile.seekSet(myFile.curPosition() + 1);
// Read CRC32 of first 16 bytes
// Read CRC32 of first 512 bytes
sprintf(crc_search, "%c", myFile.read());
for (byte i = 0; i < 7; i++) {
sprintf(tempStr2, "%c", myFile.read());
@ -565,6 +554,10 @@ boolean getMapping() {
// File searched until end but nothing found
if (strcmp(crc_search, crcStr) != 0) {
println_Msg(F("Not found"));
romName[0] = 'C';
romName[1] = 'A';
romName[2] = 'R';
romName[3] = 'T';
return 0;
}
}