dciabrin / ngdevkit

Open source development for Neo-Geo
GNU Lesser General Public License v3.0
262 stars 26 forks source link

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

Open totologic opened 3 years ago

totologic commented 3 years ago

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) ?

dciabrin commented 3 years ago

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.

totologic commented 3 years ago

No problem, I am going to try today.

totologic commented 3 years ago

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 `

dciabrin commented 3 years ago

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.

totologic commented 3 years ago

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)