how to save a game
14 posts
• Page 1 of 2 • 1, 2
- Canta
- Junior Member
- Posts: 17
- Joined: Sun May 27, 2012 4:38 pm
- Location: Germany
- Calculators: Casio fx-9860GII
how to save a game
Hi.
I would like to save a game (for now it is enough to store one number).
Unfortunately I have no idea how I can do that.
Can anyone help me please?
I would like to save a game (for now it is enough to store one number).
Unfortunately I have no idea how I can do that.
Can anyone help me please?
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
Canta wrote:I would like to save a game (for now it is enough to store one number).
For small amounts of data the main memory would be best.
Look for the SDK's Bfile-functions.
Bfile_CreateMainMemory
Bfile_OpenMainMemory
Bfile_ReadFile
Bfile_WriteFile
Bfile_CloseFile
I'll be back!
- Canta
- Junior Member
- Posts: 17
- Joined: Sun May 27, 2012 4:38 pm
- Location: Germany
- Calculators: Casio fx-9860GII
Thanks for the reply.
Does this code creates a file which is named "Save" and opens it or did I something wrong? :
I don't understand " Bfile_ReadFile, Bfile_WriteFile, Bfile_CloseFile ". (With Handle and readpos etc.)
Can you please give me an example?
Does this code creates a file which is named "Save" and opens it or did I something wrong? :
- Code: Select all
#include "fxlib.h"
#include "filebios.h"
int AddIn_main(int isAppli, unsigned short OptionNum)
{
const unsigned char name[]={"Save"};
Bfile_CreateMainMemory(name);
Bfile_OpenMainMemory(name);
return 1;
}
I don't understand " Bfile_ReadFile, Bfile_WriteFile, Bfile_CloseFile ". (With Handle and readpos etc.)
Can you please give me an example?
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
- Code: Select all
unsigned int key;
int handle, success;
int itemtosave = 0x12345678;
// try to open the file
handle = Bfile_OpenMainMemory( "SAVE" );
if ( handle < 0 ){
// if the open fails, create it
success = Bfile_CreateMainMemory( "SAVE" );
// if the create succeeded, open the file again
if ( success == 0 ) handle = Bfile_OpenMainMemory( "SAVE" );
}
if ( handle >= 0 ){
// if the handle is OK, you can use the handle with Bfile_WriteFile and Bfile_ReadFile
// f. i. save
success = Bfile_WriteFile( handle, &itemtosave, sizeof( itemtosave ) );
// finally you must close the file
success = Bfile_CloseFile( handle );
// re-open the file
handle = Bfile_OpenMainMemory( "SAVE" );
if ( handle >= 0 ){
// reset itemtosave to prove, that Bfile_ReadFile did something
itemtosave = 0;
success = Bfile_ReadFile( handle, &itemtosave, sizeof( itemtosave ), 0 );
// check the readprocess
if ( itemtosave == 0x12345678 ){
locate( 1, 1 );
Print( "success" );
GetKey( &key );
}
// finally the file must be closed again
success = Bfile_CloseFile( handle );
}
I'll be back!
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
aapman55 wrote:if itemtosave is an array. is the filesize then the amount of fields in your array?
Only if the array is a one-byte-per-item array (f. i. char x[20]). Generally the filesize will be the amount of bytes (or chars) in the array.
If you have an array int x[20], the filesize will be 80, because every int occupies 4 bytes.
The function sizeof() comes in handy there. It returns the amount of bytes, which a variable occupies.
BTW: the main memory assigns at least 24 bytes to a file, so if you save one int (= 4 chars), the filsize in the main memory will be reported as 24.
I'll be back!
- Canta
- Junior Member
- Posts: 17
- Joined: Sun May 27, 2012 4:38 pm
- Location: Germany
- Calculators: Casio fx-9860GII
Thanks for the code. I tried to use it but I can't build it.
sorry for my little knowledge:rolleyes:
- Code: Select all
#include "fxlib.h"
#include "keybios.h"
int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int key;
int handle, success;
int itemtosave = 0x12345678;
// try to open the file
handle = Bfile_OpenMainMemory( "SAVE" );
if ( handle < 0 ){
// if the open fails, create it
success = Bfile_CreateMainMemory( "SAVE" );
// if the create succeeded, open the file again
if ( success == 0 ) handle = Bfile_OpenMainMemory( "SAVE" );
}
if ( handle >= 0 ){
// if the handle is OK, you can use the handle with Bfile_WriteFile and Bfile_ReadFile
// f. i. save
success = Bfile_WriteFile( handle, &itemtosave, sizeof( itemtosave ) );
// finally you must close the file
success = Bfile_CloseFile( handle );
// re-open the file
handle = Bfile_OpenMainMemory( "SAVE" );
if ( handle >= 0 ){
// reset itemtosave to prove, that Bfile_ReadFile did something
itemtosave = 0;
success = Bfile_ReadFile( handle, &itemtosave, sizeof( itemtosave ), 0 );
// check the readprocess
if ( itemtosave == 0x12345678 ){
locate( 1, 1 );
Print( "success" );
GetKey( &key );
}
// finally the file must be closed again
success = Bfile_CloseFile( handle );
}
return 1;
}
#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum)
{
return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section
- Code: Select all
save.c(10) : C1016 (W) Argument mismatch
save.c(13) : C1016 (W) Argument mismatch
save.c(15) : C1016 (W) Argument mismatch
save.c(26) : C1016 (W) Argument mismatch
save.c(34) : C1016 (W) Argument mismatch
save.c(44) : C2709 (E) Illegal section name declaration
save.c(45) : C2500 (E) Illegal token "unsigned"
save.c(45) : C2225 (E) Undeclared name "BR_Size"
save.c(46) : C2709 (E) Illegal section name declaration
save.c(47) : C2709 (E) Illegal section name declaration
save.c(49) : C2500 (E) Illegal token "int"
save.c(49) : C2500 (E) Illegal token "int"
save.c(50) : C2500 (E) Illegal token "{"
save.c(53) : C2709 (E) Illegal section name declaration
save.c(53) : C2500 (E) Illegal token ""
sorry for my little knowledge:rolleyes:
- aapman55
- Senior Member
-
- Posts: 66
- Joined: Sun Apr 15, 2012 4:00 pm
- Calculators: Casio fx-9860G
thanks! i made a little test program for it and it works great. Below is the code, in case some one needs an example with arrays and stuff.
it basically is a counter, counting by pressing EXE and quiting the program by EXIT
it basically is a counter, counting by pressing EXE and quiting the program by EXIT
- Code: Select all
#include "fxlib.h"
#define SCA 0xD201D002
#define SCB 0x422B0009
#define SCE 0x80010070
typedef int(*sc_iv)(void);
typedef void(*sc_viuc)( int, unsigned char* );
typedef void(*sc_vpuc)(unsigned char*);
// itoa
const unsigned int sc0541[] = { SCA, SCB, SCE, 0x0541 };
#define itoa (*(sc_viuc)sc0541)
int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned char viewnumber[15];
int lcont;
unsigned int key;
int handle, success;
int itemtosave[3];
lcont=1;
handle = Bfile_OpenMainMemory( "SAVE" );
if ( handle < 0 ){
itemtosave[0]=0;
itemtosave[1]=10;
itemtosave[2]=100;
Bfile_CreateMainMemory( "SAVE" );
handle = Bfile_OpenMainMemory( "SAVE" );
Bfile_WriteFile( handle, &itemtosave, sizeof( itemtosave ) );
Bfile_CloseFile( handle );
}
if ( handle >= 0 ){
Bfile_ReadFile( handle, &itemtosave, sizeof( itemtosave ), 0 );
Bfile_CloseFile( handle );
}
while(lcont){
itoa( itemtosave[0], viewnumber );
locate(1,1);
Print(viewnumber);
itoa( itemtosave[1], viewnumber );
locate(1,3);
Print(viewnumber);
itoa( itemtosave[2], viewnumber );
locate(1,5);
Print(viewnumber);
GetKey(&key);
switch(key){
case KEY_CTRL_EXE:
itemtosave[0]++;
itemtosave[1]++;
itemtosave[2]++;
break;
case KEY_CTRL_EXIT:
lcont=0;
break;
}
}
handle = Bfile_OpenMainMemory( "SAVE" );
Bfile_WriteFile( handle, &itemtosave, sizeof( itemtosave ) );
Bfile_CloseFile( handle );
return 1;
}
14 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 20 guests