| View previous topic :: View next topic |
| Author |
Message |
Mak0
Joined: 27 Jan 2005 Posts: 36
|
Posted: Sat Jun 25, 2005 6:48 am Post subject: File I/O Woes |
|
|
ok let me start off by saying I still consider myself very much so a newbie when it comes to coding in C, especially with the unintuitiveness of the gcc compiler. I've had pretty good success using nem's pg library so far as I've got some simple "hello world" type programs to compile and run successfully. The problem I'm having is with the psp's file I/O functions. I have modified startup.s correctly and it even compiles 100% fine with no errors or warnings, but when I run it file2.txt is not even created. All I'm trying to accomplish is a mere copying of one file on the memory card. Here's my code (as you can probably tell it's based on nem's hello world):
| Code: | #include "pg.h"
int xmain(void)
{
unsigned long fc;
unsigned long r,g,b,rgb;
#define O_RDONLY 0x0001
#define O_WRONLY 0x0002
#define O_RDWR 0x0003
#define O_NBLOCK 0x0010
#define O_APPEND 0x0100
#define O_CREAT 0x0200
#define O_TRUNC 0x0400
#define O_NOWAIT 0x8000
pgInit();
pgScreenFrame(2,0);
pgFillvram(0);
int inF, ouF;
char line[512];
int bytes;
if((inF = sceIoOpen("ms0:/file1.txt", O_RDONLY)) == -1) {
return(1);
}
if((ouF = sceIoOpen("ms0:/file2.txt", O_WRONLY | O_CREAT)) == -1) {
return(1);
}
while((bytes = sceIoRead(inF, line, sizeof(line))) > 0)
sceIoWrite(ouF, line, bytes);
sceIoClose(inF);
sceIoClose(ouF);
fc=0;
while (1) {
fc++;
if (fc>=1536) fc=0;
if (fc<256) {
r=255; g=0; b=fc;
} else if (fc<512) {
r=511-fc; g=0; b=255;
} else if (fc<768) {
r=0; g=fc-512; b=255;
} else if (fc<1024) {
r=0; g=255; b=1023-fc;
} else if (fc<1280) {
r=fc-1024; g=255; b=0;
} else {
r=255; g=1535-fc; b=0;
}
r=r/8;
g=g/8;
b=b/8;
rgb=(b<<10)+(g<<5)+(r<<0)+0x8000;
pgPrint2(4,3,rgb,"Please Work!,");
pgScreenFlipV();
}
return 0;
} |
This is really starting to bug me. Any help is immensely appreciated! |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Sat Jun 25, 2005 6:54 am Post subject: |
|
|
| First of all, do you see your "please work" show up at all? If not, what I would do to help debug is make sure that you can get output at the end of your program, then set flags in each of your if statements to make sure that you are getting into them. Set a flag making sure you are opening "file1.txt" and opening "file2.txt". Then set a flag saying that you are going into your while loop. |
|
| Back to top |
|
 |
Mak0
Joined: 27 Jan 2005 Posts: 36
|
Posted: Sat Jun 25, 2005 6:56 am Post subject: |
|
|
| yes, "please work" displays fine and it changes colors just like its supposed to. |
|
| Back to top |
|
 |
0xdeadface
Joined: 31 May 2005 Posts: 62
|
Posted: Sat Jun 25, 2005 7:33 am Post subject: |
|
|
Why test for -1 with the open?
There are many error codes possible I think, so I would at least test for < 0 and see if it still gets to the printf.
0xdf |
|
| Back to top |
|
 |
Mak0
Joined: 27 Jan 2005 Posts: 36
|
Posted: Sat Jun 25, 2005 7:42 am Post subject: |
|
|
| tried it with < 0, it still gets to the printf and still doesnt even create the file :( |
|
| Back to top |
|
 |
0xdeadface
Joined: 31 May 2005 Posts: 62
|
Posted: Sat Jun 25, 2005 8:40 am Post subject: |
|
|
A guess, does "sceIoOpen("ms0:/file2.txt", O_WRONLY | O_CREAT, 0777)" improve anything?
0xdf |
|
| Back to top |
|
 |
Mak0
Joined: 27 Jan 2005 Posts: 36
|
Posted: Sat Jun 25, 2005 8:45 am Post subject: |
|
|
still nothing :(
would anyone happen to have a file copy code snippet they've used in a project or something that worked that I could look at? |
|
| Back to top |
|
 |
Saotome

Joined: 03 Apr 2004 Posts: 182
|
Posted: Sat Jun 25, 2005 8:55 am Post subject: |
|
|
weak does it like this in his screenshot code:
file = sceIoOpen(savePath,O_CREAT | O_TRUNC | O_RDWR, 0777); _________________ infj |
|
| Back to top |
|
 |
Mak0
Joined: 27 Jan 2005 Posts: 36
|
Posted: Sat Jun 25, 2005 9:02 am Post subject: |
|
|
| Saotome wrote: | weak does it like this in his screenshot code:
file = sceIoOpen(savePath,O_CREAT | O_TRUNC | O_RDWR, 0777); |
It worked!
thanks! :) |
|
| Back to top |
|
 |
Mak0
Joined: 27 Jan 2005 Posts: 36
|
Posted: Sat Jun 25, 2005 9:36 am Post subject: |
|
|
just one more quick question:
do I have to do anything special to access umd0?
thanks again for all you guys' help |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sat Jun 25, 2005 3:44 pm Post subject: |
|
|
| Mak0 wrote: | just one more quick question:
do I have to do anything special to access umd0?
thanks again for all you guys' help |
Yes, but answering this question is not allowed in this forum. Do some disassembling of some maybe illegal program, if you want to know more. |
|
| Back to top |
|
 |
Mak0
Joined: 27 Jan 2005 Posts: 36
|
Posted: Sun Jun 26, 2005 11:08 am Post subject: |
|
|
Are there certain things I can and cannot ask about the UMD device or is anything at all dealing with it off limits?
The reason I ask is that I simply want to be able to access individual files on my legally purchased retail games without having to dump entire images of them. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Jun 26, 2005 4:31 pm Post subject: |
|
|
| Mak0 wrote: | Are there certain things I can and cannot ask about the UMD device or is anything at all dealing with it off limits?
The reason I ask is that I simply want to be able to access individual files on my legally purchased retail games without having to dump entire images of them. |
Accessing individual files could be used for dumping games (because there are functions to list the directory) and The Rules Of The PSP Forums says "Development of methods to dump your own games is off limits", so you have to ask elsewhere. |
|
| Back to top |
|
 |
subbie
Joined: 05 May 2005 Posts: 122
|
Posted: Mon Jun 27, 2005 3:37 am Post subject: |
|
|
| Anybody figure out why its required to use the "O_TRUNC" flag when creating a file? This is something I have noticed from development. If you dont use that flag it will fail on trying to creat the file if it does not exsist. |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
Posted: Tue Jun 28, 2005 12:23 am Post subject: |
|
|
Hi, i think its the good topic to post my question.
I 'm trying to deal with the sceiowrite and sceioread functions, i have succes to use the write function, i save a selected path to a file called temp.dat, and i want to define a TARGETPATH with the path i successfully writed to the temp.dat file.
Originaly i have to put in my code :
| Quote: | | #define TARGETPATH "ms0:/PSP/GAME/TEMP/TEMP.BIN" |
I want this define path to be the one in my temp.dat file and i dont know how, i tested a lot of possibility :/
Here is the good sceiowrite code :
| Quote: |
if (key & CTRL_START) {
int fd;
fd = sceIoOpen("ms0:/PSP/temp.dat",O_CREAT|O_WRONLY|O_TRUNC, 0777);
sceIoWrite(fd,target, 90);
sceIoClose(fd);
}
|
So now if u understand my poor english, i want to define a path with the one in the temp.dat file to use it later ( eg: fd2 = sceIoOpen(TARGETPATH,O_WRONLY | O_CREAT | O_TRUNC, 0777);)
Here is the very bad code i used to define the TARGETPATH variable (it would be to easy if it worked) :
| Quote: |
//void GetTARGETPATH(int)
{
int fd;
int bytes1;
fd = sceIoOpen("ms0:/PSP/pspf.dat",O_RDONLY, 0777);
bytes1 = sceIoRead(fd, &tpath, 90);
sceIoClose(fd);
TARGETPATH = tpath
}
|
Again sorry for my poor english ... and my poor skill. |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Tue Jun 28, 2005 1:12 am Post subject: |
|
|
using #define is just a macro used by the CPP (C PreProcessor) that says "every time you see THIS which was defined, replace it with what goes after it". So in your code, you have:
| Code: | | #define TARGETPATH "ms0:/PSP/GAME/TEMP/TEMP.BIN" |
and then a
so when it compiles, what you end up with is:
| Code: | | "ms0:/PSP/GAME/TEMP/TEMP.BIN" = tpath |
So what I say is just make TARGETPATH a variable instead of a #define. |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
Posted: Tue Jun 28, 2005 1:21 am Post subject: |
|
|
| hehe yes its what i'm trying to do, and its the question, what is the code to define this as a variable including the sceioread function :/ |
|
| Back to top |
|
 |
ector
Joined: 12 May 2005 Posts: 195
|
Posted: Tue Jun 28, 2005 2:02 am Post subject: |
|
|
something like
char name[256];
blah blah open fd
sceIoRead(fd, name, 255);
blah blah close fd
then use name as the file to read
sceIoOpen(name, ....)
But you should really read up on C before trying to code on something as foreign as the PSP :) |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
Posted: Tue Jun 28, 2005 2:23 am Post subject: |
|
|
| oK many thanks, i figured out how it work. Your right i need to improve my c skill, i start learn it with some simple tutorials, but its not really easy without any help hehe. |
|
| Back to top |
|
 |
|