| View previous topic :: View next topic |
| Author |
Message |
kouky

Joined: 25 Sep 2007 Posts: 48 Location: London
|
Posted: Thu Apr 17, 2008 1:45 am Post subject: how to load binary files from USB? |
|
|
I'm running my elf from a USB mass storage connected to the PS2, and I would like to load binary files from this same USB drive.
But:
FILE * f=fopen("someFile","r");
doesn't seem to work.
What would be the correct method?
Thank you |
|
| Back to top |
|
 |
ffgriever
Joined: 27 Oct 2007 Posts: 13
|
Posted: Thu Apr 17, 2008 4:18 am Post subject: |
|
|
If you didn't reset the IOP (and the program you launched yours with didn't and the drivers the launcher used are standard ioman/iomanx compatible - you probably won't get it working with SM mass drivers) then just open the "mass:somefile" or "mass0:somefile".
If you did reset IOP, then load iomanx (not really mandatory), usbd and usbhdfsd, then access your files. |
|
| Back to top |
|
 |
kouky

Joined: 25 Sep 2007 Posts: 48 Location: London
|
Posted: Fri Apr 18, 2008 5:05 am Post subject: |
|
|
None of your suggestions did worked :(
I'm using the swap magic trick,
my elf file is renamed SWAPMAGIC.ELF into a SWAPMAGIC folder.
Is there any source of a similar action available? |
|
| Back to top |
|
 |
kouky

Joined: 25 Sep 2007 Posts: 48 Location: London
|
Posted: Fri Apr 18, 2008 9:18 am Post subject: |
|
|
I've been able to load a file with
FILE * f=fopen("mass:someFile","r");
with the texture example from ps2sdk,
but when change the graphic system from the example into the SDL graphic sytem, then the fopen function doesn't seem to work anymore...
Could SDL lib or gsKit lib conflict with the fopen function?? |
|
| Back to top |
|
 |
cosmito
Joined: 04 Mar 2007 Posts: 314 Location: Portugal
|
Posted: Sat Apr 19, 2008 9:44 pm Post subject: |
|
|
| kouky wrote: | | Could SDL lib or gsKit lib conflict with the fopen function?? |
No, that's not seem to be the problem. I used in some projects with no problems gsKit, SDL along with mass: loading from. |
|
| Back to top |
|
 |
Mega Man
Joined: 18 Jun 2005 Posts: 274
|
Posted: Sat Apr 19, 2008 9:57 pm Post subject: |
|
|
| usb_mass needs some time to detect the USB stick. So just try to add a sleep or reconnect the USB device. |
|
| Back to top |
|
 |
kouky

Joined: 25 Sep 2007 Posts: 48 Location: London
|
Posted: Sun Apr 20, 2008 5:33 am Post subject: |
|
|
I can't believe this simple code doesn't work, this is so frustrating!
The PS2 crashes when the file is read well is guess so because the small SDL square drawn after the file read is not displayed.
| Code: |
#include <tamtypes.h>
#include <dma.h>
#include <draw.h>
#include <stdio.h>
#include <graph.h>
#include <malloc.h>
#include <math3d.h>
#include <packet.h>
#include <string.h>
#include <sdl.h>
SDL_Surface *screen;
int main(int argc, char **argv) {
Uint32 videoflags;
/* Initialize SDL */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
videoflags = SDL_SWSURFACE;
while( argc > 1 ) {
--argc;
if ( argv[argc] && !strcmp(argv[argc], "-fullscreen") ) {
videoflags |= SDL_FULLSCREEN;
} else {
fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]);
exit(1);
}
}
screen = SDL_SetVideoMode(640, 480, 0, videoflags);//0
SDL_Rect temp;
temp.x = 0;
temp.y = 0;
temp.h = 480;
temp.w = 640;
SDL_FillRect(screen,&temp,31);
SDL_Flip( screen );
FILE *infile;
int b=0;
infile = fopen("mass:polly.jpg", "rb");
fread(&b,sizeof(unsigned char),1,infile);
fclose(infile);
//draw a small square
temp.x = 20;
temp.y = 20;
temp.h = 40;
temp.w = 40;
SDL_FillRect(screen,&temp,31*32);
SDL_Flip( screen );
// The main loop...
for (;;) {
}
// End program.
return 0;
}
|
any suggestions ? |
|
| Back to top |
|
 |
kouky

Joined: 25 Sep 2007 Posts: 48 Location: London
|
Posted: Mon Apr 21, 2008 4:35 am Post subject: |
|
|
From all the tests I've done, I've concluded that as soon as I use gskit or SDL I can't load anymore external files :(
The texture example from the sdk which load "mass:texture.raw" works well,
but the bigtext from the gskit examples just doesn't work.
And I can't find a way to display a simple white pixel on the screen without using one of those libs.
Don't know what to try next... _________________ softwares for artists on video game systems - http://www.pikilipita.com |
|
| Back to top |
|
 |
cosmito
Joined: 04 Mar 2007 Posts: 314 Location: Portugal
|
Posted: Mon Apr 21, 2008 7:19 am Post subject: |
|
|
I didn't compile your example (weekend time ran out too much quicly) but
from your code :
| Code: | FILE *infile;
int b=0;
infile = fopen("mass:polly.jpg", "rb");
fread(&b,sizeof(unsigned char),1,infile);
fclose(infile); |
why are you trying to load 1 byte to the memory address of the b integer?
why don't you allocate a buffer and load into it the proper way?
If you comment the code above, does it still crashes?
Try to load to a allocated buffer and try again. |
|
| Back to top |
|
 |
kouky

Joined: 25 Sep 2007 Posts: 48 Location: London
|
Posted: Tue Apr 22, 2008 7:16 am Post subject: |
|
|
The 1 byte things was just here to test is the file does exist.
My research so far:
I've been able to load a file when using gsKit with
fopen() and using relative paths :
"polly.jpg" and not "mass:polly.jpg"
But loading a file with gsKit functions like:
gsKit_texture_png(gsGlobal, &Tex1, "test.png");
doesn't work for me.
fopen() also doesn't work when used with the SDL lib, or I can't make it to work... _________________ softwares for artists on video game systems - http://www.pikilipita.com |
|
| Back to top |
|
 |
Mega Man
Joined: 18 Jun 2005 Posts: 274
|
Posted: Tue Apr 22, 2008 8:31 am Post subject: |
|
|
I would suggest to use a newer loader, which loads newer modules. Some old modules have problems. A better way is to reset the IOP and load the correct modules.
Earlier I detected, that it it is sometimes not possible to load fonts into gsKit, because the size reported by fread() was too small. I removed the check in gsKit and then it was working. |
|
| Back to top |
|
 |
|