Skip to content

Commit

Permalink
Fix some sram games(ffv)
Browse files Browse the repository at this point in the history
Also added kinda-working eeprom support
  • Loading branch information
kateeckhart committed Feb 6, 2016
1 parent 87867cf commit eb1c7d0
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions agb_inject/source/agb_inject.c
Expand Up @@ -2,15 +2,16 @@
#include <stdio.h>
#include <string.h>

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;
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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);
}

0 comments on commit eb1c7d0

Please sign in to comment.