How to save my game in a memory card?

Anything other than PlayStation content may be posted here
Post Reply
CrisMataTuto
Curious PSXDEV User
Curious PSXDEV User
Posts: 10
Joined: May 24, 2014
I am a: Indie Programer and Designer
PlayStation Model: SCPH-101
Location: Brazil

How to save my game in a memory card?

Post by CrisMataTuto » May 31st, 2014, 12:37 am

What is the code to save my game in memory card? Tanks.
Cristiano Hoffmann dos Santos

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » May 31st, 2014, 12:40 am

In the Sony examples for the Psy-Q SDK. Tanks Yue for your question.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
Shendo
Verified
C Programming Expert
C Programming Expert
Posts: 250
Joined: Mar 21, 2012
I am a: Programmer
Motto: Never settle
PlayStation Model: SCPH-7502
Discord: ShendoXT
Location: Croatia, EU

Post by Shendo » May 31st, 2014, 12:59 am

There are several ways:
  • Using filesystem BIOS routines,
  • Using Memory Card specific BIOS routines.
  • Low level access to SIO registers (only for advanced users).
Since you are beginner I recommend slower but easier filesystem access.

In your main add this:

Code: Select all

InitCARD(1);
StartCARD();
bu_init();
And then you can access bu00 and bu10 devices for 1st and 2nd Memory Card respectively.
Do note that your array size needs to be multiple of 8 KB (eg. 16, 24, 32, etc).

To create a save you can use this code:

Code: Select all

int f;
f = open("bu00:BEmysave", O_CREAT | 1 << 16);
close(f);
And then you can write your data:

Code: Select all

f = open("bu00:BEmysave", O_WRONLY);
write(f,&SomeArry[0], 8192);
close(f);
This is just a basic code. You will also need to check if there is free space on the card
and if the file opened correctly (maybe there is no card conneceted?).
Use normal file routines for that.

Once you get better at it then use Memory Card specific routines.
With those you can check if the card is connected, formatted, you can list all file and save names, etc.
And unlike file access those routines are not blocking, meaning your game can do something else
while reading/writing data (show loading bar for example).
Dev console: SCPH-7502, FreePSXBoot, CH340 serial cable.

CrisMataTuto
Curious PSXDEV User
Curious PSXDEV User
Posts: 10
Joined: May 24, 2014
I am a: Indie Programer and Designer
PlayStation Model: SCPH-101
Location: Brazil

Post by CrisMataTuto » May 31st, 2014, 1:22 am

Ok, tanks for all. :)
Cristiano Hoffmann dos Santos

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests