| View previous topic :: View next topic |
| Author |
Message |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Thu Mar 30, 2006 6:51 am Post subject: Files in eboot for single file programs |
|
|
Hi Guys,
I've searched for a way to do this, but hit a dead end.
I would like to know how to store complete files in a c program so
that they can be accessed by the program and written to memory
stick or flash at run time.
I have seen MPH downgrader stores a font in the c program this way,
and there's a program called mach-1 that stores pictures this way,
but doesn't tell you how to access them.
Any help in this matter would be appreciated. (inc. links to source) :)
Cheers, Art. |
|
| Back to top |
|
 |
ipsp
Joined: 01 Feb 2006 Posts: 26 Location: Sydney
|
Posted: Thu Mar 30, 2006 9:35 am Post subject: |
|
|
Are you really sure you want to do this ????
There are various side-effects you should consider, biggest of those being that each resource you include will add to the amount of memory required to start up the application. For example say the executable is 250kb, and you include 2mb of images, the executable will become 2.25Mb, and hence when the progam starts up it will need that much memory to execute.
If you need these resources, why not just dump them into a subfolder and access them that way.
I get the impression people have read examples that come with the PSPSDK, and assume that this is the best way to include resources, infact most of the gu examples are like that. If you give an example of what you are trying to do then perhap I can give you an example of a better way to do it. |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Thu Mar 30, 2006 10:13 am Post subject: |
|
|
I don't care if it uses more memory and takes more time to load.
In fact, that's great, I won't see the ms LED flashing after the program
is loaded into RAM.
| Quote: | | Are you really sure you want to do this ???? |
Um, Yes :)
| Quote: | | If you need these resources, why not just dump them into a subfolder and access them that way. |
I am, but I don't want to.
| Quote: | | I get the impression people have read examples that come with the PSPSDK, and assume that this is the best way to include resources, |
I've looked at quite a few samples, and still can't see how to do it.
| Quote: | | If you give an example of what you are trying to do then perhap I can give you an example of a better way to do it. |
Store certain files destined for flash0 and flash1 away from anyone who
would pry or alter the files. opening_plugin.rco is one example,
The pair of registry files in flash1 complete with WEP keys is a better example.
I have my program working, but there files are in subfolders that are best off
not there. |
|
| Back to top |
|
 |
starman2049
Joined: 19 Sep 2005 Posts: 75
|
Posted: Thu Mar 30, 2006 11:48 am Post subject: |
|
|
I use bin2o to convert a file into object format that can then be linked into my app.
In my makefile I include, for example, golfball.vo as an object file, and the the rule to make golfball.vo is:
golfball.vo: golfball.bin
bin2o -i golfball.bin golfball.vo golfball
This creates an extern int reference to 'golfball_start' which I can get the address of at runtime. If you look at bin2o I think it generates other ints too.
Don't know if this helps or not but I use it sucessfully... |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Thu Mar 30, 2006 2:06 pm Post subject: |
|
|
ok, Google yields results for bin2o, so there's no problem finding it,
but could you provide syntax of how you'd retrieve the file and use
it in a copy routine? |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Fri Mar 31, 2006 7:33 am Post subject: |
|
|
I didn't realise it was a tool in the sdk http://ps2dev.org/kbversions.x?T=1161
Are you supposed to compile bin2o and bin2c on the PSP and convert the
files with the PSP? |
|
| Back to top |
|
 |
weltall
Joined: 20 Feb 2004 Posts: 310
|
Posted: Fri Mar 31, 2006 3:12 pm Post subject: |
|
|
| no they should be compiled for your pc/mac if you made the toolchain |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Fri Mar 31, 2006 5:02 pm Post subject: |
|
|
I only got the c files in the sdk.
I downloaded bin2c executeable from the net though,
but is there any samples to show how it is inserted into a program
and accessed with fileio? |
|
| Back to top |
|
 |
danzel
Joined: 04 Nov 2005 Posts: 182
|
Posted: Fri Mar 31, 2006 5:26 pm Post subject: |
|
|
A quick look at the code of bin2c explains what it does:
It reads in your input file and create a c file containing the following code:
| Code: | extern const unsigned char %s[];
extern const unsigned int %sSize;
static const unsigned char %s[] = {%x,%x....};
static const unsigned int %sSize = %d; |
(where %s = the name you want the output file to have without extension, I'll assume bob for the rest of the explanation)
So now your input file is stored in a character array named bob, which has size bobSize.
In your code you access your file as a character array (c-string).
To use it in your program you should copy the first two lines into a header file and include it, and add the .c file it generated to your makefile.
| Code: | //bob.h
extern const unsigned char bob[];
extern const unsigned int bobSize;
|
and then use it in your program as a c-string, example:
| Code: | printf("size of file: %i\n", bobSize);
printf("first 3 bytes in hex: %x %x %x \n", bob[0], bob[1], bob[2]);
|
|
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Fri Mar 31, 2006 6:07 pm Post subject: |
|
|
Idealy, I would like to save the file back to memory stick, but that's a very
good start, thanx :)
I will try to get what you have posted so far working. |
|
| Back to top |
|
 |
danzel
Joined: 04 Nov 2005 Posts: 182
|
Posted: Fri Mar 31, 2006 10:12 pm Post subject: |
|
|
(iirc) Writing the data out to a file would go like this:
| Code: | FILE* outfile = fopen("somefile", "w");
size_t written = fwrite(bob, 1, bobSize, outfile);
fclose(outfile);
printf("wrote %i bytes\n", written); |
Standard c file output stuff :) |
|
| Back to top |
|
 |
floorball92
Joined: 05 Apr 2008 Posts: 30 Location: Germany -> Hessen -> Hanau
|
Posted: Tue Apr 22, 2008 1:00 am Post subject: |
|
|
OK, but how to use the picture than in the file, I mean, bin2c makes my .png to a c file, and in this c file, there is my image in hey, but there is only the hex code, so I don' t know, how to blit it. Could you please explain this?? _________________
 |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
|
| Back to top |
|
 |
floorball92
Joined: 05 Apr 2008 Posts: 30 Location: Germany -> Hessen -> Hanau
|
Posted: Tue Apr 22, 2008 9:58 pm Post subject: |
|
|
Oh, that' s nothing for me cause I' m using the OSL to make my Programms. Then I will have to load them from Memory, if it' s only for normal graphics.c. _________________
 |
|
| Back to top |
|
 |
AlphaDingDong
Joined: 21 Mar 2008 Posts: 29 Location: The interwebs
|
Posted: Wed Apr 23, 2008 1:29 pm Post subject: |
|
|
What's the difference in loading the filedata via bin2c vs bin2o? I mean, yeah, an .o is a binary data file iirc, but I've never worked with them directly. Are they accessed from the program in the same way? Also, is it really true that a larger eboot will take up more memory? It can't be possible that an eboot loads completely into memory because the PSP only has 32mb of ram and many eboots are much, much larger than 32mb. I suppose that if you used bin2c it would work that way, since I'm assuming bin2c simply string-dumps the file and then puts it into a char array, so the array would be loaded into memory, but ... Hmm... (So if I did it that way I could just cut and paste the file created by bin2c and put the data into the variable manually when I wanted it to load, then kill it when done...) Anyway, does using a .o file work differently? There must be some way to store massive amounts of data in an eboot and then load them when they're needed. :p
I'm rambling. Sorry. I'm a PSP-C noob. |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Wed Apr 23, 2008 2:30 pm Post subject: |
|
|
The whole eboot is loaded into memory with all the images that were stored in arrays with it.
Then graphics c loads the images into another array at runtime using more memory,
so one image used double the memory,
BUT once the image is loaded, you are free to use the original array for something else, so you can claim the first part of memory back for yourself. _________________ If not actually, then potentially. |
|
| Back to top |
|
 |
AlphaDingDong
Joined: 21 Mar 2008 Posts: 29 Location: The interwebs
|
Posted: Fri Apr 25, 2008 11:49 am Post subject: |
|
|
I'm confused then. How can eboots be larger than the RAM size and still run?
Why would the eboot itself be loaded into RAM when it can just be read from the ms? At any rate, the idea I had about bin2c was that you could use it to create the char array and then just copy and paste the char array into the statement that creates the image. For instance, if a png image converted to:
"dfjvnadfjkvnajklfdnvladf"
then instead of loading that into a char[?] you could just feed it to the image creation command directly... Unless that command takes a pointer....
Argh... I need to look it up now, but my docs are at home. |
|
| Back to top |
|
 |
Tinnus
Joined: 29 Jul 2006 Posts: 67
|
Posted: Fri Apr 25, 2008 12:44 pm Post subject: |
|
|
"dfjvnadfjkvnajklfdnvladf" is a pointer.
What bin2c or bin2o do is that they convert your stuff to a char*, not much different than "sgjvoryh9ejg9ejrf0e", IIRC it writes the data in hex because not all 256 char values can be encoded in the C file. _________________ Let's see what the PSP reserves... well, I'd say anything is better than Palm OS. |
|
| Back to top |
|
 |
AlphaDingDong
Joined: 21 Mar 2008 Posts: 29 Location: The interwebs
|
Posted: Fri Apr 25, 2008 3:14 pm Post subject: |
|
|
"dfjvnadfjkvnajklfdnvladf" is a char array. A pointer is just a number referring to a memory address. The pointer for "dfjvnadfjkvnajklfdnvladf" would just refer to the location of the RAM address of the first byte.
char mystr[20];
mystr is an array containing 20 char's
int mystrp = *char;
mystrp is a pointer that refers to the first byte of mystr
If it's hex then that would work even better because the size would be smaller. It could be handled similarly with a simple function.
I'm still confused about how a 500mb eboot can run if eboots are loaded into RAM on runtime.
If the image from memory function takes a pointer then the data could be handled jit:
| Code: | char imagedata[200] = "????????????";
Image myimg = functionWhosNameIdontKnow(*imagedata);
imagedata = NULL; |
But if the whole eboot is loaded into RAM then it's pointless. |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Fri Apr 25, 2008 3:40 pm Post subject: |
|
|
| Quote: | int mystrp = *char;
mystrp is a pointer that refers to the first byte of mystr |
char *mystrp = mystr;
| Quote: | | If it's hex then that would work even better because the size would be smaller |
No, there's no difference between
char mystr="ABC";
and
char mystr[]={0x41, 0x42, 0x43, 0x00};
| Quote: |
char imagedata[200] = "????????????";
Image myimg = functionWhosNameIdontKnow(*imagedata);
imagedata = NULL;
|
You can do
| Code: | char imagedata[200] = "????????????";
Image myimg = functionWhosNameIdontKnow(imagedata); |
But you can't free it by doing
imagedata=NULL;
You really need to brush up on your C coding before tackling the PSP.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
sallyxi
Joined: 25 Apr 2008 Posts: 3
|
Posted: Fri Apr 25, 2008 9:22 pm Post subject: |
|
|
| Oh,if I' m using the OSL to make my Programms. Then I will have to load them from Memory, how shall i do.. |
|
| Back to top |
|
 |
AlphaDingDong
Joined: 21 Mar 2008 Posts: 29 Location: The interwebs
|
Posted: Sun Apr 27, 2008 12:15 pm Post subject: |
|
|
| Jim wrote: | | Quote: | int mystrp = *char;
mystrp is a pointer that refers to the first byte of mystr | char *mystrp = mystr; | Yeah. That one. | Jim wrote: | | Quote: | | If it's hex then that would work even better because the size would be smaller | No, there's no difference between
char mystr="ABC";
and
char mystr[]={0x41, 0x42, 0x43, 0x00}; | I thought what he was saying was that rather than dumping it to a string of escaped base 10 values it was dumping to a string of hex values "41424300" and converting them later with an included function. I guess it makes more sense the way you describe. At any rate I found the source of bin2c and bin2o and I'm gonna read them in a little while here and figure out what the hell is going on. | Jim wrote: | | Quote: | char imagedata[200] = "????????????";
Image myimg = functionWhosNameIdontKnow(*imagedata);
imagedata = NULL; | You can do | Code: | char imagedata[200] = "????????????";
Image myimg = functionWhosNameIdontKnow(imagedata); | But you can't free it by doing
imagedata=NULL; | Ah, there's no garbage collector in C, is there. I think I was thinking in Lua.
Is it 'free(imagedata);'?
I'll look it up. | Jim wrote: | | You really need to brush up on your C coding before tackling the PSP. |
If I never developed anything because I didn't know the language first I wouldn't know any languages at all. One of the advantages of 'tackling the PSP' is that I've already learned more C just by PSP tinkering than I did in the two semesters I took in college, but I'm also in the middle of learning Lua, trying to figure out all the in's and out's of cygwin, learning to manage downloaded libraries and trying to figure out where the hell the documentation for them is and still trying to deal with paying the bills and feeding the cat. I can't afford to go to school for this stuff and I don't have an internet connection at home because I'm poor, so I have to drive to a friend's house and mooch bandwidth.
I'm sorry I got pointer declaration wrong and forgot that there's no GC in C. I'm trying to figure this stuff out all at once because after the Brad Dwyer tuts and my crappy old "C for Yourself" reference book I'm having a hard time finding documentation on a lot of things and understanding what the hell it's talking about when I do. Lately I've been spending more time on Lua than C because I can't go much further with C until I've put together what libraries to use for sound and how to use the GU for more than just drawing wavy triangles and squares.
Please bear with me while I try to wrap my brain around this stuff. I'm not trying to step on anyone's toes or anything. Give me a couple months and I should have caught up.
At any rate, does the whole eboot seriously load into RAM at runtime?
Meh, nevermind. I'll just write something to check it out myself.
My whole point was just that unless the eboot is indeed loaded into RAM then this can be done without detriment. But if the whole eboot is loaded into RAM then it has a big downside. However, I know from experience that eboots larger than the RAM can be loaded and run, therefore I know that there must some way of loading and running an eboot with at least part of it outside memory. Possibly the same method could be used to accomplish what's being discussed.
---------------------------------------------------------------
edit:
Convergence. One of the other questions I came up with last night was wth is a .psar?
Googling resulted in finding this:
| Quote: | EBOOT.PBP contents:
PARAM.SFO 944b
ICON0.PNG 24830b, 0.02mb
PIC0.PNG 2847b
PIC1.PNG 269424b, 0.26mb
DATA.PSP 29595b
DATA.PSAR 143.44mb |
I think they were discussing an eboot of a POPS game from the playstation store. The reason I had the question is because I saw last night that mksfo can take a .psar along with icons and all that. Now researching .psar's. I'll post back here what I find.
-----------------------------------------------------------------
After googling the site all I've found about psars is that they're archives in eboots that Sony uses to store FW upgrade files and PSX ISO data. This means that if someone has figured out how to create and access a psar then we have our answer. (lol. I'm half expecting a similar response to this: (http://www.dcemu.co.uk/vbulletin/showthread.php?t=45247) |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sun Apr 27, 2008 9:05 pm Post subject: |
|
|
| Quote: | | Is it 'free(imagedata);'? |
You can only free() something that you got with malloc(), calloc() or realloc(). There's no way at all to free a static array.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
adrahil
Joined: 16 Mar 2006 Posts: 277
|
Posted: Mon Apr 28, 2008 5:02 am Post subject: |
|
|
| You could also use the PBP format to embed your file inside, such as updaters who embed the PSAR ones. (Then, they just sceIoOpen the file and seek to the position of the PSAR which is indicated in the PBP header) Like this, you can embed a lot of data in a file and read parts of it without loading it all to memory. |
|
| Back to top |
|
 |
AlphaDingDong
Joined: 21 Mar 2008 Posts: 29 Location: The interwebs
|
Posted: Mon Apr 28, 2008 9:29 am Post subject: |
|
|
Sweet. It can be done then.
I'll look into malloc() and try to figure that out. Thank you for your patience.
I'll look around for psar embedding stuff and if I can't find anything I'll try fiddling with it myself. |
|
| Back to top |
|
 |
jsharrad
Joined: 20 Oct 2005 Posts: 102
|
Posted: Mon Apr 28, 2008 1:17 pm Post subject: |
|
|
There's a program out there called PBPCat that does it, it's by flatmush and should still be available for download on the psp-programming.com forums.
I believe it allows you to use a command line tool to add any file you like to the EBOOT.PBP itself and just stores the data offsets in its own header at the beginning of the file. |
|
| Back to top |
|
 |
|