Started work on better save detection. This will take quite a while to get right.

This commit is contained in:
profi200 2020-07-15 18:48:21 +02:00
parent c57e89fc49
commit 1882ba8f06
No known key found for this signature in database
GPG Key ID: 17B42AE5911139F3
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,37 @@
#pragma once
#include "types.h"
typedef struct
{
char gameCode[3]; // Without the region letter.
u8 type;
} SaveTypeLut;
static_assert(offsetof(SaveTypeLut, type) == 3, "Error: Member type of SaveTypeLut is not at offset 3!");
/*
* 0x0 = EEPROM 4k/8k (512/1024 bytes)
* 0x2 = EEPROM 64k (8 KiB)
* 0x4 = Flash 512k (64 KiB) with RTC, ID=0x3D1F, Atmel
* 0x5 = Flash 512k (64 KiB) without RTC, ID=0x3D1F, Atmel
* 0x6 = Flash 512k (64 KiB) with RTC, ID=0xD4BF, SST
* 0x7 = Flash 512k (64 KiB) without RTC, ID=0xD4BF, SST
* 0x8 = Flash 512k (64 KiB) with RTC, ID=0x1B32, Panasonic
* 0x9 = Flash 512k (64 KiB) without RTC, ID=0x1B32, Panasonic
* 0xA = Flash 1M (128 KiB) with RTC, ID=0x09C2, Macronix
* 0xB = Flash 1M (128 KiB) without RTC, ID=0x09C2, Macronix
* 0xC = Flash 1M (128 KiB) with RTC, ID=0x1362, Sanyo
* 0xD = Flash 1M (128 KiB) without RTC, ID=0x1362, Sanyo
* 0xE = SRAM/FRAM/FeRAM 256k (32 KiB)
* 0xF = No save chip
*/
// TODO: Decide how each entry should look like.
alignas(4) static const SaveTypeLut saveTypeLut[] =
{
{"AMA", 0x0}, // EEPROM_V120 Super Mario Advance
{"AA2", 0x2}, // EEPROM_V122 Super Mario Advance 2 - Super Mario World
{"A3A", 0x2}, // EEPROM_V122 Super Mario Advance 3 - Yoshi's Island
};

View File

@ -11,6 +11,7 @@
#include "arm11/hardware/mcu.h"
#include "arm11/hardware/lgyfb.h"
#include "arm11/fmt.h"
//#include "arm11/gba_save_type_table.h"
#define LGY_REGS_BASE (IO_MEM_ARM9_ARM11 + 0x41100)
@ -187,6 +188,33 @@ saveTypeFound:
return saveType;
}
/*static u16 getSaveTypeFromTable(u32 romSize)
{
const u32 gameCode = *(u32*)(ROM_LOC + 0xAC);
u16 saveType = SAVE_TYPE_NONE;
for(u32 i = 0; i < sizeof(saveTypeLut) / sizeof(*saveTypeLut); i++)
{
// Save type in last byte.
const u32 entry = *((u32*)saveTypeLut[i].gameCode);
if((entry & 0xFFFFFFu) == (gameCode & 0xFFFFFFu))
{
saveType = entry>>24;
break;
}
}
if(saveType == SAVE_TYPE_EEPROM_8k || saveType == SAVE_TYPE_EEPROM_64k)
{
// If ROM bigger than 16 MiB --> SAVE_TYPE_EEPROM_8k_2 or SAVE_TYPE_EEPROM_64k_2.
if(romSize > 0x1000000) saveType++;
}
debug_printf("Using save type %" PRIX16 ".\n", saveType);
return saveType;
}*/
static void setupFcramForGbaMode(void)
{
// FCRAM reset and clock disable.
@ -208,6 +236,7 @@ Result LGY_prepareGbaMode(bool biosIntro, char *const romPath)
// Try to detect the save type.
const u16 saveType = tryDetectSaveType(romSize);
//const u16 saveType = getSaveTypeFromTable(romSize);
// Prepare ARM9 for GBA mode + settings and save loading.
const u32 romPathLen = strlen(romPath);