![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on writting simple data to a file. within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I trying to do something very very very simple. I want my program to read a file from the flash01 ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() |
I trying to do something very very very simple. I want my program to read a file from the flash01 (system.dreg) and write it to and memory stick. The problem is that it does not write data to the file I created on the memory stick: "system.dreg". I have trying to get this work for days and I'm really get frustrated because it seems sooooo easy and the code I have seem to be right, yet its not working.
thanks in advance. oh btw, for somereason O_RDONLY....etc aren't defined for some reason Code:
#include <pspiofilemgr.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include <psppower.h>
#include "graphics.h"
#include "26calls.h"
PSP_MODULE_INFO("getreg26", 0, 1, 1);
void freemem();
void ProcessKeys(unsigned long xikeys);
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
struct SceKernelLoadExecParam* hssa;
int pktime=0;
int selComponent=0;
int theld=0;
int sqHeld=0;
int oHeld=0;
int uheld=0;
int xheld=0;
int dheld=0;
int lheld=0;
int rheld=0;
int stHeld=0;
int y=10;
int doneit=0;
SceOff fcount=0;
char data[255];
SceIoStat stat;
SceUID fd;
SceUID fd2;
#define printf pspDebugScreenPrintf
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
int main() {
int i=0;
SetupCallbacks();
initGraphics();
initCtrl();
SceCtrlData pad;
freemem();
printTextScreen(10, y, "press circle to dump reg", RGB(255, 0, 0));
flipScreen();
while(1)
{
sceCtrlReadBufferPositive(&pad, 1);
WriteDwordDummy(0,22,pad.Buttons);
ProcessKeys(pad.Buttons);
flipScreen();
for(i=0; i<1; i++) {
sceDisplayWaitVblankStart();
}
}
sceKernelSleepThread();
return 0;
}
void ProcessKeys(unsigned long xikeys) {
if (xikeys & PSP_CTRL_LEFT)
{
}
if (xikeys & PSP_CTRL_RIGHT)
{
}
if (xikeys & PSP_CTRL_DOWN)
{
if (!dheld)
{
dheld=1;
} else
{
dheld=0;
}
}
if (xikeys & PSP_CTRL_CROSS)
{
}
if (xikeys & PSP_CTRL_UP)
{
if (!uheld)
{
uheld=1;
} else
{
uheld=0;
}
}
if (xikeys & PSP_CTRL_CIRCLE)
{
if (!oHeld)
{
if (doneit ==0)
{
y+=20;
printTextScreen(10, y, "opening file...", RGB(255, 0, 0));
fd = sceIoOpen("flash1:/registry/system.dreg", 0x0001, 0777);
if (!fd)
{
y+=20;
printTextScreen(10, y, "error can not open file!", RGB(255, 0, 0));
} else {
y+=20;
printTextScreen(10, y, "sucess!", RGB(255, 0, 0));
y+=20;
}
printTextScreen(10, y, "Processing", RGB(255, 0, 0));
y+=20;
printTextScreen(10, y, "creating file..", RGB(255, 0, 0));
y+=20;
fd2 = sceIoOpen("ms0:/system.dreg", 0x0002 | 0x0200 | 0x0400 , 0777);
if (!fd2)
{
printTextScreen(10, y, "Error creating file!", RGB(255, 0, 0));
flipScreen();
return;
}
printTextScreen(10, y, "File created!", RGB(255, 0, 0));
y+=20;
sceIoGetstat("flash1:/registry/system.dreg",&stat);
printTextScreen(10, y, "writing to file...", RGB(255, 0, 0));
flipScreen();
y+=20;
data[0] = 'h';
data[1] = 'e';
data[2] = '\0';
//while (stat.st_size != fcount)
//{
// fcount++;
//sceIoRead(fd, data, sizeof(int)+100);
sceIoWrite (fd2, "something", 255);
//}
printTextScreen(10, y, "done!", RGB(255, 0, 0));
y+=20;
doneit=1;
oHeld = 1;
}
} else
{
oHeld = 0;
}
}
if (xikeys & PSP_CTRL_SQUARE)
{
if (!stHeld)
{
sqHeld=1;
} else
{
sqHeld=0;
}
}
}
void freemem()
{
int i=0;
for (i=0;i<100;i++)
{
sceKernelFreePartitionMemory(i);
}
}
Last edited by ピッカホ; 03-13-2006 at 01:46 PM.. |
|
|
|
|
|
#3 |
![]() ![]() AKA Homer
|
Copy directory (and all it's contents) and file function:
Code:
/** Structure to hold the time information for a file */
typedef struct _io_time {
unsigned short year;
unsigned short month;
unsigned short day;
unsigned short hour;
unsigned short minute;
unsigned short sec;
unsigned short unk[2]; /* Set to 0, possibly just padding */
} io_time_t;
/** Structure to hold the status information about a file */
typedef struct {
/** Access flags, zero or more of ::IOAccessModes */
unsigned int access;
/** Mode flags, zero or more of ::IOFileModes */
unsigned int mode;
/** Size of the file in bytes */
long long size;
/** Creation time */
io_time_t ctime;
/** Access time (possibly) */
io_time_t atime;
/** Modification time */
io_time_t mtime;
/** Unknown, seem to be all 0xFFFFFFFF */
unsigned int unk[6];
} io_stat_t;
/** Structure to hold a single directory entry */
typedef struct {
/** File status */
io_stat_t stat;
/** File name */
char name[264];
/** Unknown */
unsigned int dummy;
} io_dirent_t;
char line[4][256];
void num2hex(char *dst, int n) {
int i;
static char hex[]="0123456789ABCDEF";
for (i=0; i<8; i++) {
dst[i]=hex[(n>>((7-i)*4))&15];
}
}
int pgCopyDir(char *, char *);
int pgCopyFile(char *src,char *dst) {
int srcfd,dstfd,r,w,copied=0;
char buf[1024];
srcfd=sceIoOpen(src,SCE_O_RDONLY,0);
if (srcfd<0) {
return pgCopyDir(src,dst); // if can't open as file, try to copy as dir
}
dstfd=sceIoOpen(dst,SCE_O_WRONLY|SCE_O_CREAT|SCE_O_TRUNC,0777);
if (dstfd<0) { r=dstfd; goto out; }
while(1) {
r=sceIoRead(srcfd,buf,1024);
if (r<=0) goto out;
w=sceIoWrite(dstfd,buf,r);
if (w!=r) { r=0xfbadcafe; goto out; }
copied+=r;
num2hex(line[2],copied);
line[2][8]=0;
}
out:
if (srcfd>=0) sceIoClose(srcfd);
if (dstfd>=0) sceIoClose(dstfd);
return r;
}
int pgCopyDir(char *srcdir, char *dstdir) {
void *dir;
char src[256],dst[256],code[16]="--------";
int slen,dlen,ret;
io_dirent_t de;
sceIoMkdir(dstdir,0777);
strcpy(dst,dstdir);
dlen=strlen(dst);
dst[dlen]='/';
strcpy(src,srcdir);
slen=strlen(src);
dir=sceIoDopen(src);
src[slen]='/';
if (dir==(void *)0) return -1;
while((ret=sceIoDread(dir,&de))!=0) {
if (de.name[0]=='.') {
if (de.name[1]==0) continue;
if (de.name[1]=='.' && de.name[2]==0) continue;
}
strcpy(src+slen+1,de.name);
src[255]=0;
strcpy(line[0],src);
strcpy(dst+dlen+1,de.name);
dst[255]=0;
strcpy(line[1],dst);
strcpy(line[2],"-");
ret=pgCopyFile(src,dst);
}
return 0;
}
|
|
|
|
|
|
#5 |
![]() ![]() Muppet Magnet
|
BTW, looks like you aren't closing the file in your original code. If you don't close it, the PSP never flushes the data to the memstick.
__________________
Using firmware v2.00-v3.50? Open up a whole world of homebrew here
The PSP Homebrew Database needs YOU! Your ISP may be illegally wiretapping all your web activity. Stop Phorm Now! Visiting the Edinburgh Festivals? Get practical advice from experts. |
|
|
|
![]() |
| Tags |
| data , file , simple , writting |
| Thread Tools | |
|
|