Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
totologic opened this issue Jan 24, 2021 · 5 comments
Open

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

totologic opened this issue Jan 24, 2021 · 5 comments

Comments

@totologic
Copy link

totologic commented Jan 24, 2021

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 totologic changed the title Manage memory Manage memory card with bios call to CARD ($C00468) Jan 24, 2021
@dciabrin
Copy link
Owner

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
Copy link
Author

No problem, I am going to try today.

@totologic
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

totologic commented Feb 5, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants