forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File I/O Woes

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Mak0



Joined: 27 Jan 2005
Posts: 36

PostPosted: Sat Jun 25, 2005 6:48 am    Post subject: File I/O Woes Reply with quote

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
View user's profile Send private message
Agoln



Joined: 08 Jun 2005
Posts: 326
Location: Fort Wayne, IN

PostPosted: Sat Jun 25, 2005 6:54 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Mak0



Joined: 27 Jan 2005
Posts: 36

PostPosted: Sat Jun 25, 2005 6:56 am    Post subject: Reply with quote

yes, "please work" displays fine and it changes colors just like its supposed to.
Back to top
View user's profile Send private message
0xdeadface



Joined: 31 May 2005
Posts: 62

PostPosted: Sat Jun 25, 2005 7:33 am    Post subject: Reply with quote

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
View user's profile Send private message
Mak0



Joined: 27 Jan 2005
Posts: 36

PostPosted: Sat Jun 25, 2005 7:42 am    Post subject: Reply with quote

tried it with < 0, it still gets to the printf and still doesnt even create the file :(
Back to top
View user's profile Send private message
0xdeadface



Joined: 31 May 2005
Posts: 62

PostPosted: Sat Jun 25, 2005 8:40 am    Post subject: Reply with quote

A guess, does "sceIoOpen("ms0:/file2.txt", O_WRONLY | O_CREAT, 0777)" improve anything?

0xdf
Back to top
View user's profile Send private message
Mak0



Joined: 27 Jan 2005
Posts: 36

PostPosted: Sat Jun 25, 2005 8:45 am    Post subject: Reply with quote

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
View user's profile Send private message
Saotome



Joined: 03 Apr 2004
Posts: 182

PostPosted: Sat Jun 25, 2005 8:55 am    Post subject: Reply with quote

weak does it like this in his screenshot code:
file = sceIoOpen(savePath,O_CREAT | O_TRUNC | O_RDWR, 0777);
_________________
infj
Back to top
View user's profile Send private message
Mak0



Joined: 27 Jan 2005
Posts: 36

PostPosted: Sat Jun 25, 2005 9:02 am    Post subject: Reply with quote

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
View user's profile Send private message
Mak0



Joined: 27 Jan 2005
Posts: 36

PostPosted: Sat Jun 25, 2005 9:36 am    Post subject: Reply with quote

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
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sat Jun 25, 2005 3:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mak0



Joined: 27 Jan 2005
Posts: 36

PostPosted: Sun Jun 26, 2005 11:08 am    Post subject: Reply with quote

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
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sun Jun 26, 2005 4:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
subbie



Joined: 05 May 2005
Posts: 122

PostPosted: Mon Jun 27, 2005 3:37 am    Post subject: Reply with quote

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
View user's profile Send private message
Cpasjuste



Joined: 29 May 2005
Posts: 214

PostPosted: Tue Jun 28, 2005 12:23 am    Post subject: Reply with quote

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
View user's profile Send private message
Agoln



Joined: 08 Jun 2005
Posts: 326
Location: Fort Wayne, IN

PostPosted: Tue Jun 28, 2005 1:12 am    Post subject: Reply with quote

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

Code:
TARGETPATH = tpath


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
View user's profile Send private message AIM Address
Cpasjuste



Joined: 29 May 2005
Posts: 214

PostPosted: Tue Jun 28, 2005 1:21 am    Post subject: Reply with quote

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
View user's profile Send private message
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Tue Jun 28, 2005 2:02 am    Post subject: Reply with quote

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
View user's profile Send private message
Cpasjuste



Joined: 29 May 2005
Posts: 214

PostPosted: Tue Jun 28, 2005 2:23 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group