mGBA Forums

Full Version: Questions on reading RAM from external program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I tried to do a quick search on Google, on the site and here on the forums, but I didn't have any luck.

Basically what I want to achieve is reading a few bytes from a specific address of the emulated RAM of the game (the reading is done from a little program I'm working on).
My idea was to read from a save state (quick to save for the user and easy to detect changes) but I noticed that on mGBA save states hava some kind of compression applied to them, so I can't use them in the intended way. I know about the memory viewer and the selection dumping feature but that's only manual and I was looking for an automatic one-keystroke kind of solution.

So my questions are:
Is there a way to make mGBA save the whole raw emulated RAM in the save state?

If not, is there a way in mGBA to make the memory dump process automatic?

If not, what are some possible ways (if there are any) to read the emulated RAM directly from within my program?
(I don't know much abot low-level stuff and memory access but if pointed in the right direction I can learn for myself no problem, I only need a starting point. Also I don't know if mGBA itself exposes some APIs for accessing it)
It's true that savestates are compressed, though it's not that hard to decompress them if you can write some code using libpng. The decompressed states have all of RAM in them. I can give guidance if you want to go this route.

APIs are in the works but are nowhere near a usable state for most users, unfortunately. There is no easy way to do anything like this at the moment.
(08-26-2019, 03:31 AM)endrift Wrote: [ -> ]It's true that savestates are compressed, though it's not that hard to decompress them if you can write some code using libpng. The decompressed states have all of RAM in them. I can give guidance if you want to go this route.

APIs are in the works but are nowhere near a usable state for most users, unfortunately. There is no easy way to do anything like this at the moment.

Thanks for the reply. Decompression would be perfect, I'm all ears (or should I say eyes 🤔 ).
Actually, I just realized that if you uncheck "Savestate extra data -> Screenshot" in Settings -> Emulation, it saves uncompressed. RAM regions are here in the file:
  • 0x19000 - 0x20FFF: IWRAM (0x03XXXXXX address space)
  • 0x21000 - 0x60FFF: WRAM (0x02XXXXXX address space)
(08-26-2019, 06:43 AM)endrift Wrote: [ -> ]Actually, I just realized that if you uncheck "Savestate extra data -> Screenshot" in Settings -> Emulation, it saves uncompressed. RAM regions are here in the file:
  • 0x19000 - 0x20FFF: IWRAM (0x03XXXXXX address space)
  • 0x21000 - 0x60FFF: WRAM (0x02XXXXXX address space)

That's fantastic.
I almost disabled that option on the first run of the emulator for no real reason, luckily I didn't or that would have been a PITA to figure out why for other users the savestates weren't reading properly 😅️

I guess now the only issue that can arise is if the savestate structure changes slightly throughout updates, but that's easy to handle.
Thanks for the help.