Skip to content

Commit

Permalink
Fix cia generaton.
Browse files Browse the repository at this point in the history
  • Loading branch information
kateeckhart committed Jan 24, 2016
1 parent b73545b commit 9b48af0
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 200 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ agb_inject/out.sav
agb_inject/out.cia
agb_inject/gba.cxi
agb_inject/exefs/code.bin
agb_inject/header.bin
Binary file added agb_inject/3dstool_linux
Binary file not shown.
Binary file added agb_inject/ExInjector.exe
Binary file not shown.
172 changes: 0 additions & 172 deletions agb_inject/agb_inject_mb.rsf

This file was deleted.

Binary file added agb_inject/exefs.bin
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added agb_inject/exefshead.bin
Binary file not shown.
26 changes: 15 additions & 11 deletions agb_inject/gen_rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
savename = input("Type in the save's name: ")
outname = input("Type in the output cia's name: ")
savetype = int(input("Type in the save type: "))
titleid = input("Type in the title id of the game you wish to inject: ")
titleid = titleid[1:6]
titleid = int(input("Type in the title id of the game you wish to inject: "), 16)
titleid = struct.pack("<i", titleid)
with open("exheader.bin", "rb") as f:
exheader = bytearray(f.read())
exheader[0x200 : 0x200 + 4] = titleid
with open("exheader.bin", "wb") as f:
f.write(exheader)
footername = "agb_inject_mb_" + str(savetype) + ".ftr"
with open(footername, "rb") as f:
footer = f.read()
Expand All @@ -21,16 +26,15 @@
rom[0x20000 : 0x20000 + len(sav)] = sav
with open("exefs/code.bin", "wb") as f:
f.write(rom)
with open("agb_inject_mb.rsf", "rb") as f:
rsf = bytearray(f.read())
rsf[0x180 : 0x185] = bytes(titleid, "ascii")
with open("agb_inject_mb.rsf", "wb") as f:
f.write(rsf)
if platform.system() == "Linux":
makeromname = "./makerom_linux"
elif platform.system() == "Windows":
makeromname = "makerom.exe"
os.system(makeromname + " -icon exefs/icon.bin " +
"-banner exefs/banner.bin -code exefs/code.bin " +
"-exheader exheader.bin -romfs romfs.bin -rsf agb_inject_mb.rsf -o gba.cxi")
os.system(makeromname + " -content gba.cxi:0:0 -o "+ outname)
if platform.system() == "Linux":
dstoolname = "./3dstool_linux"
elif platform.system() == "Windows":
dstoolname = "3dstool_linux.exe"
os.system(dstoolname + " -c --header exefshead.bin --exefs-dir exefs --type exefs --file exefs.bin")
os.system(dstoolname + " -c --extendedheader exheader.bin " +
"--romfs romfs.bin --file gba.cxi --header header.bin --type cxi --exefs exefs.bin")
os.system(makeromname + " -content gba.cxi:0:0 -f cia -o "+ outname)
29 changes: 12 additions & 17 deletions agb_inject/source/agb_inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,27 @@ void sram() {
sram[x] = save[x];
}
}
void inline flash_command(u8 command) {
u8 volatile *command_addr1 = (void *)0xE005555;
u8 volatile *command_addr2 = (void *)0xE002AAA;
*command_addr1 = 0xAA;
*command_addr2 = 0x55;
*command_addr1 = command;
}

void flash() {
u8 const *save = (void *)0x8020000;
u8 volatile *flash = (void *)0xE000000;
u8 volatile *command1 = (void *)0xE005555;
u8 volatile *command2 = (void *)0xE002AAA;
*command1 = 0xAA; // Enter id mode
*command2 = 0x55;
*command1 = 0x90;
flash_command(0x90); // Enter id mode
flash[0]; // read manufacuer
flash[1]; // read dev
*command1 = 0xAA; // Exit id mode
*command2 = 0x55;
*command1 = 0xF0;
*command1 = 0xAA; //erase command
*command2 = 0x55;
*command1 = 0x80;
*command1 = 0xAA; //erase entire flash
*command2 = 0x55;
*command1 = 0x10;
flash_command(0xF0); // Exit id mode
flash_command(0x80); // Erase command
flash_command(0x10); // Erase entire flash
while(*flash != 0xFF); // Wait for flash to be erased
int x;
for(x = 0; x <= 65536 ; x++) {
*command1 = 0xAA; // Write byte
*command2 = 0x55;
*command1 = 0xA0;
flash_command(0xA0); // Write byte
flash[x] = save[x];
while(flash[x] != save[x]); // Wait for byte to be written
}
Expand Down

0 comments on commit 9b48af0

Please sign in to comment.