Thursday 16 February 2023

Load/save to/from battery-backed RAM

Curiosity got the better of me and I started looking at saving to battery-backed RAM (aka BRAM, aka NVRAM). FTR MAME saves a copy for every ROM to the nvram directory.

Turned out to be trivial to implement.

First thing I discovered is that the BIOS loads the game data as specified in the header even before the cartridge executes any code. That means by simply setting the right header data the BIOS will automatically load save data from BRAM into my buffer (long before I hook to load from memory card). Half of the solution right there!

By using the same buffer as the memory card, and the same format - including the header - I can determine whether or not valid save data has been loaded, and skip patching the high scores if not. As for saving, I just copy data to my memcard buffer, and call $C12322 instead of saving to memory card. And that's all it takes!

I still need to work out a priority for reading/writing to BRAM/memory card, but that's also trivial.

UPDATE: seems not quite as trivial as I thought... calling the BRAM save routine is corrupting the title screen that follows the GAME OVER screen. I just can't see why... it's not calling any other function, and the registers are all saved in my routine...

UPDATE: the bug has nothing to do with the BRAM save routine; comment out the entire high score load/save routines and it still happens... another known bug (4)

No comments:

Post a Comment