how to load binary files from USB?

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

how to load binary files from USB?

Post by kouky »

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
ffgriever
Posts: 11
Joined: Sat Oct 27, 2007 7:06 am

Post by ffgriever »

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.
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

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?
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

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??
cosmito
Posts: 307
Joined: Sun Mar 04, 2007 4:26 am
Location: Portugal
Contact:

Post by cosmito »

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.
Mega Man
Posts: 260
Joined: Sat Jun 18, 2005 3:14 am
Contact:

Post by Mega Man »

usb_mass needs some time to detect the USB stick. So just try to add a sleep or reconnect the USB device.
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

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: Select all

 #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&#40;int argc, char **argv&#41; &#123;

  
	Uint32 videoflags;


  	/* Initialize SDL */
	if &#40; SDL_Init&#40;SDL_INIT_VIDEO&#41; < 0 &#41; &#123;
		fprintf&#40;stderr, "Couldn't initialize SDL&#58; %s\n",SDL_GetError&#40;&#41;&#41;;
		exit&#40;1&#41;;
	&#125;
	atexit&#40;SDL_Quit&#41;;
	
	videoflags = SDL_SWSURFACE;
	while&#40; argc > 1 &#41; &#123;
		--argc;
		if &#40; argv&#91;argc&#93; && !strcmp&#40;argv&#91;argc&#93;, "-fullscreen"&#41; &#41; &#123;
			videoflags |= SDL_FULLSCREEN;
		&#125; else &#123;
			fprintf&#40;stderr, "Usage&#58; %s &#91;-fullscreen&#93;\n", argv&#91;0&#93;&#41;;
			exit&#40;1&#41;;
		&#125;
	&#125;
	
    screen = SDL_SetVideoMode&#40;640, 480, 0, videoflags&#41;;//0
    
    SDL_Rect temp;
    temp.x = 0;
    temp.y = 0;
    temp.h = 480;
    temp.w = 640;
    SDL_FillRect&#40;screen,&temp,31&#41;;

    SDL_Flip&#40; screen &#41;;

    FILE *infile; 
    int b=0;

    infile = fopen&#40;"mass&#58;polly.jpg", "rb"&#41;;
    fread&#40;&b,sizeof&#40;unsigned char&#41;,1,infile&#41;;
    fclose&#40;infile&#41;;

    //draw a small square
    temp.x = 20;
    temp.y = 20;
    temp.h = 40;
    temp.w = 40;
    SDL_FillRect&#40;screen,&temp,31*32&#41;;
    SDL_Flip&#40; screen &#41;;
  
  

  // The main loop...
  for &#40;;;&#41; &#123;

  &#125;

  // End program.
  return 0;

 &#125;

any suggestions ?
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

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
cosmito
Posts: 307
Joined: Sun Mar 04, 2007 4:26 am
Location: Portugal
Contact:

Post by cosmito »

I didn't compile your example (weekend time ran out too much quicly) but
from your code :

Code: Select all

    FILE *infile; 
    int b=0; 

    infile = fopen&#40;"mass&#58;polly.jpg", "rb"&#41;; 
    fread&#40;&b,sizeof&#40;unsigned char&#41;,1,infile&#41;; 
    fclose&#40;infile&#41;; 
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.
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

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
Mega Man
Posts: 260
Joined: Sat Jun 18, 2005 3:14 am
Contact:

Post by Mega Man »

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.
Post Reply