From eb1c7d07434871e0611adfe94fe9ed7403538cbe Mon Sep 17 00:00:00 2001 From: Alex Eckhart Date: Sat, 6 Feb 2016 11:38:15 -0700 Subject: [PATCH] Fix some sram games(ffv) Also added kinda-working eeprom support --- agb_inject/source/agb_inject.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/agb_inject/source/agb_inject.c b/agb_inject/source/agb_inject.c index 079e0e7..5596edd 100644 --- a/agb_inject/source/agb_inject.c +++ b/agb_inject/source/agb_inject.c @@ -2,15 +2,16 @@ #include #include +u8 const *save = (void *)0x8020000; + void sram() { - u8 const *save = (void *)0x8020000; - u8 volatile *sram = (void *)SRAM; int x; - for(x = 0; x <= 32768; x++) { + for(x = 0; x <= 0x7FFE; x++) { sram[x] = save[x]; } } + void inline flash_command(u8 command) { u8 volatile *command_addr1 = (void *)0xE005555; u8 volatile *command_addr2 = (void *)0xE002AAA; @@ -20,7 +21,6 @@ void inline flash_command(u8 command) { } void flash() { - u8 const *save = (void *)0x8020000; u8 volatile *flash = (void *)0xE000000; flash_command(0x90); // Enter id mode flash[0]; // read manufacuer @@ -37,6 +37,26 @@ void flash() { } } +void eeprom() { + u16 buffer[73]; + memset(buffer, 0, sizeof(u16) * 73); + u16 x; + int z; + for(x = 0; x <= 512; x += 8) { + for(z = 0; z <= 64; z++) { + if ((save[x + (z / 8)] & 1 << z % 8) != 0) { + buffer[z + 1] = 1; + } + } + for(z = 65; z <= 71; z++) { + buffer[z] = x & 1 << z % 8; + } + buffer[72] = 1; + dmaCopy(buffer, (void *)0xDFFFF00, 73 << 1); + while((*(u8 *)0xDFFFF00 & 1) != 1); // Wait for data to be written. + } +} + int main() { u8 savetype = *(u8 *)0x801FFFF; irqInit(); @@ -46,8 +66,11 @@ int main() { if (savetype == 0) { sram(); - } else { + } else if (savetype == 1) { flash(); + } else if (savetype == 2) { + eeprom(); } iprintf("AGB_FIRM save injector\n"); + while(1); }