News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Patching GBA game to save high scores  (Read 750 times)

CecilMcW00t

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Patching GBA game to save high scores
« on: March 03, 2019, 11:05:54 pm »
Okay, so I have an addiction to arcade compilation games that save high scores. There is a game on the GBA called Konami Collector's Series: Arcade Advanced that has two of my favorite arcade games on it, Frogger and Scramble. The cart has great ports of these games but no option to save high score data.

So, I just need a bit of guidance to get started. From the research I have done so far, I think what I need to do is enable SRAM in this game and then find the RAM addresses that store the high scores in the rom, correct? Then, I need to make it so that those addresses are set to "save" to the SRAM? There is an app called GBATA which can patch in SRAM. But I believe it converts other save types to SRAM. Can it add SRAM to a rom that didn't originally save? This information is in the rom header, right?

Once I can figure out the workflow, I will get started on this.

FAST6191

  • Hero Member
  • *****
  • Posts: 2501
    • View Profile
Re: Patching GBA game to save high scores
« Reply #1 on: March 04, 2019, 12:41:45 pm »
Yeah GBATA changes saves to SRAM so old school flash carts (which are only SRAM) can save. The differences between such things are very small.

It will however have no clue what to do about creating a save.

There is no save info in the ROM header. To detect what it is tools and whatever else will run an ASCII search for SRAM, EEPROM or Flash and following that will be a version number which can also affect things (there is a reason older builds of VBA might need you to set the save mode for pokemon).

Yes you would need to liven up the memory of choice (might as well be SRAM), write the relevant data to it, read it back out on next boot (hopefully after the game does any clearing of the area, or disable said clearing for the area). Some of the newer flash carts and flash cart kernels with GBA side auto patching might have a problem if they do some kind of header detection to read against their onboard database of saves. If so just change the serial or something and fix the header with GBATA (or flash advance toolkit). Old school flash carts tended to do detection so just make sure you have the read commands and ASCII text in a suitable location.
Anyway for the hardware stuff then GBATEK is where it is at
http://problemkaputt.de/gbatek.htm#gbacartbackupsramfram

For a simple high score table it should be so bad but I can't see a way where you would not have to learn some assembly to do this, and probably have to understand some things as well rather than do a bit more of a brute force approach like you can with some cheat porting efforts.

Speaking of cheats then that should be a good way to find where the high score table was stashed in RAM.

CecilMcW00t

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: Patching GBA game to save high scores
« Reply #2 on: March 05, 2019, 12:08:25 am »
Thank you so much for that info. I'm definitely not afraid to get my hands dirty with assembly, especially since that may end up being required. And yes, I was thinking about using a cheat trainer to locate where high score tables are stored more quickly.

Okay, going to get back to researching...

SuperStarFox

  • Jr. Member
  • **
  • Posts: 45
    • View Profile
Re: Patching GBA game to save high scores
« Reply #3 on: April 12, 2019, 04:37:14 am »
Don't Forget Pac Man Collection and Namco Museum On The GBA Also!

phonymike

  • Jr. Member
  • **
  • Posts: 19
    • View Profile
Re: Patching GBA game to save high scores
« Reply #4 on: April 27, 2019, 04:22:01 pm »
I'm rusty but hope this helps.

No$GBA would really help debug, especially if you know a little assembly, it has a great interface. Devkitpro has a C compiler and Assembler. GBAdev.org also has a forum for more development conversation.

On the GBA in C, reading and writing a byte from SRAM is as easy as

Code: [Select]
byte_to_read = *(u8 *)0x0E000000;
*(u8 *)0x0E000000 = byte_to_write;

In ASM it's probably like

Code: [Select]
ldrb r0,#0xE000000    ;read
strb r0,#0xE000000    ;write

It's an 8 bit bus so you read a byte at a time. For flash or eeprom you have to send the binary commands as writes and then write the data. SRAM is just a memory read or write. That's what GBATA does, find the pattern of code that does flash or eeprom, then patches it to use simple SRAM read/writes. Not all flash cartridges have flash/eeprom support, only SRAM, and flash/eeprom is used as a hardware copy protection.

Here's a little ASM. You can only MOV a value that's based on 8 bits and shifted. So you can MOV #0x4000000, but not #0x40000D4. The code below sets r0 to #0x4000000, then computes the addresses later. The processor takes [r0,#0xD4] and makes 0x40000D4. If you want to put a 32 bit value directly into a register, you need LDR r0,#0x4000D4, that will work.

Code: [Select]
ldr r1,#0x8040000    ;some location in ROM
ldr r2,#0x2000000    ;some location in EWRAM
ldr r3,#0x1000       ;length
bl DMA3
b more_code

DMA3
    mov  r0,#0x04000000      ;i/o base, later used to set DMA settings
    str  r1,[r0,#0xD4]       ;store (32 bit) source address at 0x040000D4
    str  r2,[r0,#0xD8]       ;store (32 bit) destination address at 0x040000D8
    strh r3,[r0,#0xDC]       ;store (16 bit) DMA length at 0x040000DC
    mov  r3,#0x8400          ;value to start a 32 bit dma transfer
    strh r3,[r0,#0xDE]       ;store (16 bit) DMA setting at 0x040000DE, which now begins the DMA transfer from ROM to EWRAM
    bx   lr                  ;return to link register

Here's a pdf that can help with ARM asm
https://people.freebsd.org/~cognet/t/PDF/ADS_ASSEMBLERGUIDE_B.PDF

just found this one maybe it's simpler
https://www.csie.ntu.edu.tw/~cyy/courses/assembly/07fall/lectures/handouts/lec08_ARMasm_4up.pdf