ngdevkit icon indicating copy to clipboard operation
ngdevkit copied to clipboard

Manage memory card with bios call to CARD ($C00468)

Open totologic opened this issue 4 years ago • 5 comments

Hi.

Actually not really an issue. I am just interested in reading/saving datas on the memory card and I have no idea how to perform it.

I understand well the principles of the variables involved by the CARD system, as decribed in the wiki: https://wiki.neogeodev.org/index.php?title=CARD

But how to make a bios call to CARD ($C00468) ?

totologic avatar Jan 24 '21 19:01 totologic

Oh I never tried that, let me keep that open as a future feature. I never tried it, but I think ideally from C, you should run something like:

    __asm__ __volatile__ ("jsr 0xc00468" : : :
                          "d0","d1","d2","d3","d4","d5","d6","d7",
                          "a0","a1","a2","a3","a4","a5","a6");

I'm not sure of the calling convention so here the example request gcc to save all registers. I'll add a dedicated header with the appropriate macros to call all the BIOS functions.

dciabrin avatar Jan 25 '21 08:01 dciabrin

No problem, I am going to try today.

totologic avatar Jan 25 '21 13:01 totologic

Excellent ! It works. Quickly, I retrieved with success the user name of the memcard.

` #define BIOS_CARD_COMMAND ((volatile u8*)0x10FDC4) #define BIOS_CARD_ANSWER ((volatile u8*)0x10FDC6) #define BIOS_CARD_START ((volatile u32*)0x10FDC8)

char data[8]; char msg[4];

*BIOS_CARD_START = (u32)data; *BIOS_CARD_COMMAND = 7; asm volatile ("jsr 0xc00468" : : : "d0","d1","d2","d3","d4","d5","d6","d7", "a0","a1","a2","a3","a4","a5","a6");

display(1, 2, data); // display user name data string on fx layer snprintf(msg, 4, "%2d", *BIOS_CARD_ANSWER); display(1, 3, msg);// display error code `

totologic avatar Jan 25 '21 22:01 totologic

Great!

For what it's worth, latest ngdevkit master provides additional headers/helpers that allow you to access the data in the BIOS's memory as if they were regular C variables:

#include <ngdevkit/bios-ram.h>

[...]

bios_card_start = (u32)data;
bios_card_command = 7;

Maybe that can be of interest for you.

dciabrin avatar Jan 26 '21 19:01 dciabrin

Also I am able to load/save data.

After experimenting, I want to raise 2 issues:

  1. the NGH number must be considered in hex literally. For exxample, Puzzle Bobble NGH is 83, so a call for it would be:

*BIOS_CARD_FCB = 0x83;

  1. The BIOS_CARD_SUB must be read as 16 bits with data search command (1). But writing only 8 bits with load data command (2). It seems to work both with save data command (3)

totologic avatar Feb 05 '21 19:02 totologic