GBA Hardware: e-Reader calibration initialization
Vicki Pfau vi@endrift.com
Wed, 19 Feb 2020 21:12:48 -0800
2 files changed,
19 insertions(+),
0 deletions(-)
M
src/gba/hardware.c
→
src/gba/hardware.c
@@ -95,6 +95,15 @@ { 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0 } }; +const uint8_t EREADER_CALIBRATION_TEMPLATE[] = { + 0x43, 0x61, 0x72, 0x64, 0x2d, 0x45, 0x20, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x32, 0x30, + 0x30, 0x31, 0x00, 0x00, 0xcf, 0x72, 0x2f, 0x37, 0x3a, 0x3a, 0x3a, 0x38, 0x33, 0x30, 0x30, 0x37, + 0x3a, 0x39, 0x37, 0x35, 0x33, 0x2f, 0x2f, 0x34, 0x36, 0x36, 0x37, 0x36, 0x34, 0x31, 0x2d, 0x30, + 0x32, 0x34, 0x35, 0x35, 0x34, 0x30, 0x2a, 0x2d, 0x2d, 0x2f, 0x31, 0x32, 0x31, 0x2f, 0x29, 0x2a, + 0x2c, 0x2b, 0x2c, 0x2e, 0x2e, 0x2d, 0x18, 0x2d, 0x8f, 0x03, 0x00, 0x00, 0xc0, 0xfd, 0x77, 0x00, + 0x00, 0x00, 0x01 +}; + static void _readPins(struct GBACartridgeHardware* hw); static void _outputPins(struct GBACartridgeHardware* hw, unsigned pins);@@ -686,6 +695,15 @@
void GBAHardwareInitEReader(struct GBACartridgeHardware* hw) { hw->devices |= HW_EREADER; _eReaderReset(hw); + + if (hw->p->memory.savedata.data[0xD000] == 0xFF) { + memset(&hw->p->memory.savedata.data[0xD000], 0, 0x1000); + memcpy(&hw->p->memory.savedata.data[0xD000], EREADER_CALIBRATION_TEMPLATE, sizeof(EREADER_CALIBRATION_TEMPLATE)); + } + if (hw->p->memory.savedata.data[0xE000] == 0xFF) { + memset(&hw->p->memory.savedata.data[0xE000], 0, 0x1000); + memcpy(&hw->p->memory.savedata.data[0xE000], EREADER_CALIBRATION_TEMPLATE, sizeof(EREADER_CALIBRATION_TEMPLATE)); + } } void GBAHardwareEReaderWrite(struct GBACartridgeHardware* hw, uint32_t address, uint16_t value) {