GP32 Gp32 Dev Util


Pirotic

Certified Guru
Joined
Feb 16, 2004
Messages
593
Hiya, pretty much coded everything i know how to code in Gigas now so im moving into all the scary stuff i dont really have a clue about, currently trying to get the SMC system working, which is vital in allowing users to create there own content and play on it without fuss. i've read up on all the SMC functions, and i've done a few tests - i can write a file into a folder of my choice with the content of my choice for instance, whic his a start.

but now i need to learn how to load data off the SMC and 'use' that data.

first up is this dillema, i have an array which is something like:

short data[200];

and i have a file on the SMC called "test.dat" which is basically a huge line of 1's and 0's, now what i'd like to do is load them one by one into the array.

so if the test.dat for instance started off as "100100"

i'd like data[0] to be 1, [1] to be 0, [2] to be 0.

you get the idea,

i tried variations of..

for (i = 0; i < collision_count; i++)
{

//Set the collisions
char *buffer;
int bytes=1;
int offset = (i * bytes);
buffer = (char*) malloc(bytes);
GpFileRead(h_file, buffer, offset, (ulong*)bytes );
collision = buffer;

}

but im confident im making a total balls job of that :p so if anybody would like to tell me how it should be done i'd be well chuffed as thats the biggest thing 'to do' atm.

Secondly was, do manuals exist for that GP32 Dev Util? because i can easily convert the sound files into .sef and whack them on the SMC but have no frigging clue how to use them.

before i was just including the audio into a .h file then using..

GpPcmPlay((unsigned short*)plug_sfx,plug_sfx_length, 0);

any help would be great! wish they had proper manuals out for all this stuff :p
 
I haven't done any fileIO on GP32 yet (always thought it would be to tricky :)) but shouldn't your line:

collision = buffer;

be

collision = *buffer;

to get the value not the address?

shout at me if that's wrong

sam
 
Hi Pirotic

this is not the way to do it fast, any kind of file parsing like this will be slow esp for large amounts of data. The usual way to this is to read/write the structures directly:

bytes=sizeof(mystruct);
GpFileRead(h_file, mystruct, offset, (ulong*)bytes );
or
bytes=sizeof(mystruct);
GpFileWrite(h_file, mystruct, offset, (ulong*)bytes );


there is one problem tho - across platforms compiler could/might align structures differently - but you can usually get around this with pragmas e.t.c..
 
ZardozJones posted on Apr 2 2004 at 04:11 PM said:
Hi Pirotic

this is not the way to do it fast, any kind of file parsing like this will be slow esp for large amounts of data. The usual way to this is to read/write the structures directly:

bytes=sizeof(mystruct);
GpFileRead(h_file, mystruct, offset, (ulong*)bytes );
or
bytes=sizeof(mystruct);
GpFileWrite(h_file, mystruct, offset, (ulong*)bytes );


there is one problem tho - across platforms compiler could/might align structures differently - but you can usually get around this with pragmas e.t.c..
hiya, this method looks perfect - but i cannot get it working...


#define collision_count 1920
char collision[collision_count];

F_HANDLE h_file;
GpFileOpen( "col.dat", OPEN_W, &h_file );
int bytes=sizeof(collision);
int offset = 0;
GpFileRead(h_file, collision, offset, (ulong*)bytes );
GpFileClose( h_file );

.. not sure if im passing the 'collision' data correctly or not, but when i compile and run it every collision[] value is zero, and some should be 1's

any more suggestions mate?
 
Last edited by a moderator:
Hi
yes - sanity check the .dat file with any good hex viewer - just to make sure your data is indeed binary and correct and not text e.t.c..
 
Also Just Noticed:

GpFileRead(h_file, buffer, offset, (ulong*)bytes );

should be

GpFileRead(h_file, buffer, offset, (ulong*)&bytes );

if the function is expecting a pointer :)
 
hmm, something which baffles me is - the zero and ones are not binary, they are simply the values for each char of the array.

surely as im loading it into a char array, it'd work when the col.dat is written in text?

i dont see how binary reading 010 would end up as
collision[0] = 0
collision[1] = 1
collision[0] = 0

:p eitherway, fixed the code as you noted and it still had all the values as zero when loading it from a text file, i figured a lazy way of getting it into binary was to have the values as an include then use a GpFileWrite(h_file, collision, bytes ); instead of a read, but the output file just had a line of the square ASCII symbols
 
OK so your .dat file is a bit stream?
there are multiple solutions here

1) you can block load the .dat file into a temp array and bit stream parse into your destionation array

2) Fix the program that generates the .dat so it's optimal to load directly via a struct

3) Generate a H file and forget about smc loading

have much fun :)
 
thanks for all your help,

like you said, i think its going to be tricky as its an char array, ideally i just wanted to be able to type what i wanted into the .dat file, such as ABCDEF then for a to be in [0] and B to end up in [1] etc, you probably already know that tho.

at the moment its all zeros and ones (off and on) but i'm planning to add more options which is why it has to be a char array and not a bit array :p

the include is so much easier, but as the whole purpose of gigas was to allow users to create there own games which are then just put in a folder and run by the application, i gotta find a way :D

*scratchs head*

oh well, im learning slowly :D

thanks again
 
No problem dude

I'd write longer fuller answers but it's of course a fredagsol - so no chance of that today :) *burp*
 
its annoying, i can get it half working - i can load the array via the include then using..

GpFileWrite(h_file, (char*)collision, bytes );

it writes the data down, but instead of writing it back into the file as text (ascii) it does it as binary :p so now i've got both a binary and text version of the .dat but no way to load either into the array :D

oh well, SMC isnt vital - just frustrating i can write it but not read it back in :p logic dictates if i can do one, i can do the other.

whats a fredagsol btw? never heard that expression/word before.
 
Fredagsol... You mean Fredagsöl??? A cold beer on a friday... Sooo good tasting after a hard weeks work...
 
You could always look for examples and rip code from them ...

Try (my :) ) pokersquares source... http://www.geocities.com/gp32rich

It reads a highscore file from SMC, creates one if it doesn't exist.
The 'highscore' function writes the struct of ints and chars in memory to SMC.

Also has a 'TranslateErrCode' wrapper for debugging B)


Hope these help
 
Back
Top