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 

using the SceIO functions

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



Joined: 28 Mar 2009
Posts: 61

PostPosted: Thu Apr 02, 2009 6:36 am    Post subject: using the SceIO functions Reply with quote

can someone show me how to write a file from ms to flash0, minus the assigning and reassgning flash in write

i only need to learn how to write stuff from a desired source to another.

thanks :D
Back to top
View user's profile Send private message Visit poster's website
Coldbird



Joined: 08 Feb 2007
Posts: 155

PostPosted: Thu Apr 02, 2009 9:45 am    Post subject: Reply with quote

Don't quite know what you're after but I hope this little example out of my PRX Library can help you out.
Code:
#include <pspiofilemgr.h>

int appendBufferToFile(const char * path, void * buffer, int buflen)
{
  // Written Bytes
  int written = 0;
 
  // Open File for Appending
  SceUID file = sceIoOpen(path, PSP_O_APPEND | PSP_O_CREAT | PSP_O_WRONLY, 0777);
 
  // Opened File
  if(file >= 0)
  {
    // Write Buffer
    written = sceIoWrite(file, buffer, buflen);
   
    // Close File
    sceIoClose(file);
  }
 
  // Return Written Bytes
  return written;
}

_________________
Been gone for some time. Now I'm back. Someone mind getting me up-2-date?
Back to top
View user's profile Send private message MSN Messenger
PsPfReAK



Joined: 28 Mar 2009
Posts: 61

PostPosted: Fri Apr 03, 2009 1:11 am    Post subject: Reply with quote

okay, say that i want to write a rco from ms0:/whatever.rco to flash0:/whatever.rco

how would i go about doing that?

like

Sce....<i dont know how to use it, so im asking how?

noob example? with HEAVY comments?

not a sample please, i would like to learn how to do it, noy copy and paste some elses code.

okay say this, continue the code, you are flashing a file from ms0 to flash0, minus the assinging of flash

Code:
 break;
assignign flash0 blah blah...

///you guys help me here by input the commands, ie writing a file from mso to flash0
Back to top
View user's profile Send private message Visit poster's website
Coldbird



Joined: 08 Feb 2007
Posts: 155

PostPosted: Fri Apr 03, 2009 9:16 am    Post subject: Reply with quote

Alright... Minus the assigning of flash you say...
Code:
#include <pspiofilemgr.h> // Include for Sony IO Functions
#include <stdio.h> // Include for Seek Constants
#include <string.h> // Include for NULL Macro

SceOff fileSize(SceUID file)
{
  // File Length
  SceOff length = 0;
 
  // Sanity Check for Valid File Handler
  if(file >= 0)
  {
    // Save Position in File
    SceOff pos = sceIoLseek(file, 0, SEEK_CUR);
   
    // Move to EOF & Grab Location (Size)
    length = sceIoLseek(file, 0, SEEK_END);
   
    // Restore Position in File
    sceIoLseek(file, pos, SEEK_SET);
  }
 
  // Return File Length
  return length;
}

int copyFile(const char * from, const char * to)
{
  // Result (0 = Worked, 1 = Failed)
  int result = 0;
 
  // Sanity Check to avoid NULL Pointers
  if(from && to)
  {
    // Open Input File
    SceUID infile = sceIoOpen(from, PSP_O_RDONLY, 0777);
   
    // Opened Input File
    if(infile >= 0)
    {
      // Get Filesize
      SceOff insize = fileSize(infile);
     
      // Open Output File
      SceUID outfile = sceIoOpen(to, PSP_O_WRONLY | PSP_O_CREAT, 0777);
     
      // Opened Output File
      if(outfile >= 0)
      {
        // Transfer Buffer
        unsigned char buffer[1024];
       
        // Copy Buffer Blocks
        int copied = 0;
        while(copied < insize)
        {
          // Read Block from Input File
          int read = sceIoRead(infile, buffer, 1024);
         
          // Written Bytes
          int written = sceIoWrite(outfile, buffer, read);
         
          // Write Block to Output File
          if(written) copied += written;
         
          // Writing Error
          else
          {
            // Change Result
            result = 1;
           
            // Break out of Loop
            break;
          }
        }
      }
    }
  }
 
  // Return Result
  return result;
}

Be warned. I quickly wrote this up. It's untested.
Anyway, it should give you a pretty good idea how to work with the sceIo API.
_________________
Been gone for some time. Now I'm back. Someone mind getting me up-2-date?
Back to top
View user's profile Send private message MSN Messenger
PsPfReAK



Joined: 28 Mar 2009
Posts: 61

PostPosted: Fri Apr 03, 2009 10:55 pm    Post subject: Reply with quote

so would this be adequate?

Code:

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <pspiofilemgr.h> // Include for Sony IO Functions


////////////////////////////////////////////////////////////////////////////////
#define MODULE "test"
////////////////////////////////////////////////////////////////////////////////
PSP_MODULE_INFO(MODULE, 0x0800, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_VSH);
////////////////////////////////////////////////////////////////////////////////
#define p2c pspDebugScreenPrintf
#define RED 0x111FFF
#define WHITE 0xFFFFF1
#define GREEN 0x0000FF00
#define TextColor pspDebugScreenSetTextColor
#define ClearScreen pspDebugScreenClear
#define test_size 20
char test_buffer[test_size];
int readSize;

////////////////////////////////////////////////////////////////////////////////
char msg[256];
int cbid;
int thid;
int written;
int file_size;
/////
SceUID fd;
/////
////////////////////////////////////////
int exit_callback(int arg1, int arg2, void *common) {
    sceKernelExitGame();
   return 0; }
////////////////////////////////////////
int CallbackThread(SceSize args, void *argp) {
    cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
    sceKernelRegisterExitCallback(cbid);
    sceKernelSleepThreadCB();
   return 0; }
////////////////////////////////////////
int SetupCallbacks(void) {
    thid = 0;
    thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, THREAD_ATTR_USER, 0);
    if (thid >= 0)
   sceKernelStartThread(thid, 0, 0);
    return thid; }
////////////////////////////////////////
void ErrorExit(int milisecs, char *fmt, ...) {
   va_list list;
   va_start(list, fmt);
   vsprintf(msg, fmt, list);
   va_end(list);
   p2c(msg);
   sceKernelDelayThread(milisecs*1000);
   sceKernelExitGame(); }
////////////////////////////////////////
SceOff fileSize(SceUID file)
{
  // File Length
  SceOff length = 0;
 
  // Sanity Check for Valid File Handler
  if(file >= 0)
  {
    // Save Position in File
    SceOff pos = sceIoLseek(file, 0, SEEK_CUR);
   
    // Move to EOF & Grab Location (Size)
    length = sceIoLseek(file, 0, SEEK_END);
   
    // Restore Position in File
    sceIoLseek(file, pos, SEEK_SET);
  }
 
  // Return File Length
  return length;
}

int copyFile(const char * from, const char * to)
{
  // Result (0 = Worked, 1 = Failed)
  int result = 0;
 
  // Sanity Check to avoid NULL Pointers
  if(from && to)
  {
    // Open Input File
    SceUID infile = sceIoOpen(from, PSP_O_RDONLY, 0777);
   
    // Opened Input File
    if(infile >= 0)
    {
      // Get Filesize
      SceOff insize = fileSize(infile);
     
      // Open Output File
      SceUID outfile = sceIoOpen(to, PSP_O_WRONLY | PSP_O_CREAT, 0777);
     
      // Opened Output File
      if(outfile >= 0)
      {
        // Transfer Buffer
        unsigned char buffer[1024];
       
        // Copy Buffer Blocks
        int copied = 0;
        while(copied < insize)
        {
          // Read Block from Input File
          int read = sceIoRead(infile, buffer, 1024);
         
          // Written Bytes
          int written = sceIoWrite(outfile, buffer, read);
         
          // Write Block to Output File
          if(written) copied += written;
         
          // Writing Error
          else
          {
            // Change Result
            result = 1;
           
            // Break out of Loop
            break;
          }
        }
      }
    }
  }
 
  // Return Result
  return result;
}
////////////////////////////////////////
void remove_files(char *files) {
     p2c("Removing File %s....", files);
     sceIoRemove(files);
     p2c("OK\n"); }
////////////////////////////////////////
// copies the binary file contents from the input file to the output file
int copyFileContents(SceUID* InputFilePointer, SceUID* OutputFilePointer)
{
   int readsize=512; // just an arbitrary value, generally larger chunks are faster in file copies due to the way sectors are handled on disk writes
   u8 buffer[readsize];
   int bytesRead, bytesWritten;
   bytesRead = sceIoRead(*InputFilePointer, buffer, readSize);
   bytesWritten = sceIoWrite(*OutputFilePointer, buffer, bytesRead);
   if(bytesWritten != bytesRead)
   {
      // write error
      
      return -1;
   }
   return 1; // bytecopy successful
}
///////////////////////////////////////
int main() {
   pspDebugScreenInit();
   TextColor(WHITE);
   SetupCallbacks();
       
   p2c("test to\n");
    p2c("flash test.txt with contents to flash0:/\n");
    p2c("To do so Press X to start at your own risk, R to exit.\n\n");
   
   while (1) {
        SceCtrlData pad;
        sceCtrlReadBufferPositive(&pad, 1);

      if (pad.Buttons & PSP_CTRL_CROSS) {
                        p2c("Assigning flash0.... ");                       
                        if (sceIoUnassign("flash0:") < 0)
                        p2c("Cannot Un-Assign flash0:");
                        if (sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0) < 0) {
                                             p2c("Error Assigning flash0 in write mode"); }
                        p2c("OK\n\n");
                  
                        copyFile("flash0:/test.txt");
                        break; }

      else if (pad.Buttons & PSP_CTRL_RTRIGGER) {
             p2c("\n\nExited by the user");
             sceKernelExitGame(); }

      sceKernelDelayThread(10000); }
      
      p2c("\n\nPress X to Exit");
      
      while (1) {
        SceCtrlData pad;
        sceCtrlReadBufferPositive(&pad, 1);

      if (pad.Buttons & PSP_CTRL_CROSS) {
                        break; }

      sceKernelDelayThread(10000); }
   
   sceKernelExitGame();

   return 0; }
////////////////////////////////////////////////////////////////////////////////
Back to top
View user's profile Send private message Visit poster's website
Coldbird



Joined: 08 Feb 2007
Posts: 155

PostPosted: Sat Apr 04, 2009 10:39 am    Post subject: Reply with quote

Nope. Wouldn't.
copyFile("flash0:/test.txt"); -> wrong
copyFile("ms0:/test.txt", "flash0:/test.txt"); -> right

This command would then copy the file ms0:/test.txt to flash0:/test.txt.
_________________
Been gone for some time. Now I'm back. Someone mind getting me up-2-date?
Back to top
View user's profile Send private message MSN Messenger
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