sceIoOpen .. screwy?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
skeezixcodejedi
Posts: 29
Joined: Tue Aug 30, 2005 10:37 am
Contact:

sceIoOpen .. screwy?

Post by skeezixcodejedi »

Edit: Please ignore the whole posting. Looks like a library problem, fiddling with library order solves it.. so must be sucking in some incorrect lib :(

--

After getting some weird results while mucking with some basic code using the defaults in PSPSDK I put together a dumb test case..

#if 1
int fd = 0;
UInt8 buffer [ 3 ] = { 0, 0, 0 };
UInt8 error = 0;
fd = sceIoOpen ( "ms0:/ATARI_ST/TOS.IMG", PSP_O_RDONLY, 0777 );
if ( fd ) {
if ( sceIoRead ( fd, buffer, 3 ) == 3 ) {
// good
} else {
error = 1;
}
sceIoClose ( fd );
}
#endif

And later, in the display loop..

pspDebugScreenSetXY ( 0, 0 );
pspDebugScreenPrintf ( "fd %d err %d bytes %x %x %x", fd, error,
buffer [ 0 ], buffer [ 1 ], buffer [ 2 ] );

So here I get a big -ve number for the fd; it should likely be 0 (failed) or 1 (good). Naturally, the subsequant calls also fail.

The file does exist, but thats irrelevent since I'm not getting a useful return value.

(Building under Windows for now, since PSP easily plugs into Windows :)

jeff
Last edited by skeezixcodejedi on Tue Aug 30, 2005 11:36 am, edited 1 time in total.
--
Have you played Atari today?
skeezixcodejedi
Posts: 29
Joined: Tue Aug 30, 2005 10:37 am
Contact:

Post by skeezixcodejedi »

Additionally, biulding sample/kernel/fileio sample compiles flawlessly, but crashes the PSP when run.

Thanks for any ideas!

jeff

edit: Actually the Makefile is missing USE_PSPSDK_LIBC=1 .. adding that and filio.c demo seems to work, so I'll go see if it wrote anything useful out (its a rom dumper).
--
Have you played Atari today?
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

So here I get a big -ve number for the fd; it should likely be 0 (failed) or 1 (good).
Actually, fd would be a file handle, so not necessarily 0 or 1. You'd have deliberately to try to open a non-existant file to find out what the error return code is.

Jim
PSPimp
Posts: 13
Joined: Tue Apr 12, 2005 11:05 pm

Re: sceIoOpen .. screwy?

Post by PSPimp »

skeezixcodejedi wrote:So here I get a big -ve number for the fd; it should likely be 0 (failed) or 1 (good). Naturally, the subsequant calls also fail.
assumption is the mother of all fuck-ups...
go and read up on open() return codes in your favourite "teach yourself C in 24 hours" book: <0 is failed, >=0 is a valid fd
skeezixcodejedi
Posts: 29
Joined: Tue Aug 30, 2005 10:37 am
Contact:

Post by skeezixcodejedi »

It really generally depends on the platform; most unix boxes return -1 on error and set errno; some platforms return 0. >0 or >=0 is usually success.

Getting -0xFFF0000 and such seems pretty weird :)

Still, nomatter.. just had to find it out. It helped when it wasn't returnign random values.. when using some mixture of libs, I got no useful returns back, and a different result each run. After futzing with libs, the problem went away so I've not documented it well I'm afraid :(

jeff
--
Have you played Atari today?
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Most PSP OS calls that create or open objects (such as sceIoOpen()) use a UID. UIDs are never negative, but they can be large numbers. You should never have to care about the details of any UID returned from the OS.

Just stick to < 0 == error, and >= 0 == success and you'll be fine.
skeezixcodejedi
Posts: 29
Joined: Tue Aug 30, 2005 10:37 am
Contact:

Post by skeezixcodejedi »

Words to live by :) It wasn't immediately obvious until I started getting those back :)

BTW, many kudos to yourself and the others who kicked the SDK off; incredible work. Easier to develop for than Palm OS and Pocket PC and even the GP32.. surprising!

jeff
--
Have you played Atari today?
Post Reply