Does anyone have live links to how to make use of bram? I have an idea but the game state will probably be too big to password reasonably. I assume there's some sort of filesystem-lite going on to keep games from clobbering each-other but I haven't seen detailed resources in any of the links I've looked at which aren't bitrotted.
EDIT: These are documented in the CD BIOS manual. To get these into search engines and make sure I understand it. Notes and questions in parens.
To preempt questions about notation: when it's referring to things like _AX as registers, those are conventional zero page addresses. For example ax is $20F8. I don't think this is mentioned in any of the PDFs.
There are BM_* BIOS commands (I think just a brk with those interrupt numbers?)
Your "metadata" format is called an FCB (file cabinet I guess?) with a user id (2 bytes if I'm reading the chart right) and then 8 bytes of filename.
If ram is unformatted then you need to format it with BM_FORMAT, which wants _ax to be a pointer to the string "!BM_FORMAT!" (Q: How do I tell if it needs to be formatted or not? Will it fail if it's already formatted? A1: All the calls will return 0xFF if the backup data is unformatted, so check free space first and format it then if needed.)
You can query with BM_FREE and get the results back in _CX. I believe it also sets A to indicate any possible errors (this seems to be the case for all the bios calls?)
Now to actually save a game:
First query with BM_FREE to be sure you have enough space. If BM_FREE puts $FF in A then run BM_FORMAT. If you don't have enough space, error out or try to handle it.
If there's enough space for your data (assuming you already built your buffer) then set _AX to your FCB (which you can probably just have in ROM,) _BX to the start of your data, _CX to the file length, and _DX to the offset within the file from the top (I'm guessing this file offset is to let you do things like hold multiple high scores or do multiple transfers for a single save file? Sadly the BIOS manual doesn't say if there's an artificial limit to how long the write can be.)
In A it'll tell you whether it succeeded or if there wasn't enough space.
To load save data:
BM_READ with _AX as your FCB address, _BX the destination address, _CX the max number of bytes to read (actually read will be min(_CX, filesize),) and _DX will be the offset from the top to start at. Your data will be at *_BX, the bytes read will be in _CX, and A will be your return value (OK, no file found, corrupted data, or not formatted.)
is that about right as a summary? There's one BIOS call I'm not sure I understand, namely BM_FILES. If I had to guess it's basically letting you go "Let me see what's file 1. Okay, call again with file=2 to see what's file 2", etc. Is that correct?
And a practical note for free space handling: if you have save data that ought to be exclude from the free space (obviously) so a good recovery strategy if you have the ram for it might be to read the old save data into ram, delete that data, then try to write your new save again. If there's still not enough room then you can write the old save data back harmlessly assuming no weird hardware problems (I think?)