mete esta libreria:
--------------------------------------------------------------------------
/*----------------------------------------------------------------
| Autor: ~Arkarian~ |
| Fecha: 08/09/2007 Versión: 1.0 |
|-----------------------------------------------------------------|
| Descripción del Programa: Libreria personalizada por Arkarian |
| Esto es Top-Secret si la tienes no se lo pases a NADIEEE |
| ----------------------------------------------------------------*/
// ------------------------- Librerias ------------------------- //
#include <pspkerneltypes.h>
#include <pspmodulemgr.h>
#include <pspiofilemgr.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <psploadexec.h>
#include <pspkernel.h>
#include <pspumd.h>
#include <pspusb.h>
#include <pspthreadman.h>
#include <pspmodulemgr.h>
#include <string.h>
#include <pspthreadman.h>
#include <pspsdk.h>
#include <psputilsforkernel.h>
#include <psppower.h>
#include <psputility.h>
#include <pspsyscon.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <malloc.h>
// ------------------------- Load Exec´s ------------------------- //
#define exitgame sceKernelExitGame
#define loadexec sceKernelLoadExec
// ------------------------- IO´s ------------------------- //
#define open sceIoOpen
#define write sceIoWrite
#define read sceIoRead
#define close sceIoClose
#define remove sceIoRemove
#define mkdir sceIoMkdir
#define rename sceIoRename
// ------------------------- Debug´s ------------------------- //
#define printf pspDebugScreenPrintf
#define delay sceKernelDelayThread
#define exitthread sceKernelExitDeleteThread
#define screeninit pspDebugScreenInit
#define backcolor pspDebugScreenSetBackColor
#define textcolor pspDebugScreenSetTextColor
#define setxy pspDebugScreenSetXY
#define clearscreen pspDebugScreenClear
// ------------------------- Controls ------------------------- //
#define cactivate1 SceCtrlData
#define cactivate2 sceCtrlSetSamplingCycle
#define cactivate3 sceCtrlSetSamplingMode
#define digital PSP_CTRL_MODE_DIGITAL
#define analog PSP_CTRL_MODE_ANALOG
#define cactivate4 sceCtrlReadBufferPositive
#define cross PSP_CTRL_CROSS
#define square PSP_CTRL_SQUARE
#define circle PSP_CTRL_CIRCLE
#define triangle PSP_CTRL_TRIANGLE
#define rtrigger PSP_CTRL_RTRIGGER
#define ltrigger PSP_CTRL_LTRIGGER
#define start PSP_CTRL_START
#define select PSP_CTRL_SELECT
#define dleft PSP_CTRL_LEFT
#define dright PSP_CTRL_RIGHT
#define ddown PSP_CTRL_DOWN
#define dup PSP_CTRL_UP
// ------------------------- Exit Callbacks ------------------------- //
#define setupcall SetupCallbacks
void dump_threadstatus(void);
int done = 0;
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
done = 1;
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;
}
// ------------------------- Error Exit ------------------------- //
void errorexit(int milisecs, char *fmt, ...)
{
va_list list;
char msg[256];
va_start(list, fmt);
vsprintf(msg, fmt, list);
va_end(list);
printf(msg);
delay(milisecs*1000);
exitgame();
}
// ------------------------- Activacion de Dispositivos ------------------------- //
void activarflash0()
{
int uas0, as0;
uas0 = sceIoUnassign("flash0:");
if (uas0 < 0)
{
errorexit(6000, " No se puede asignar la flash0.\n");
}
as0 = sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);
if (as0 < 0)
{
errorexit(6000, " No se re-asignar la flash0.\n");
}
}
void activarflash1()
{
int uas1, as1;
uas1 = sceIoUnassign("flash1:");
if (uas1 < 0)
{
errorexit(6000, " No se puede asignar la flash1.\n");
}
as1 = sceIoAssign("flash1:", "lflash0:0,1", "flashfat1:", IOASSIGN_RDWR, NULL, 0);
if ( as1 < 0)
{
errorexit(6000, " No se puede re-asignar la flash1.\n");
}
}
void activarms()
{
int ums1, ms1;
ums1 = sceIoUnassign("ms0:");
if ( ums1 < 0)
{
errorexit(6000, " No se puede asignar la Memory Stick.\n");
}
ms1 = sceIoAssign("ms0:", "msstor0p1", "fatms0:", IOASSIGN_RDWR, NULL, 0);
if (ms1 < 0)
{
errorexit(6000, " No se puede re-asignar la Memory Stick.\n");
}
}
// ------------------------- Mis Funciones Personalizadas ------------------------- //
/* Esta funcion te permite comprovar si estan los archivos */
int checkfile(const char *filename) // UTILIZACION: checkfile("ms0:/archivo.txt");
{
SceUID file = sceIoOpen(filename, PSP_O_RDONLY, 0);
if (file < 0)
{
textcolor(0x0000FF);// Color Rojo
printf(" El archivo %s no se encuentra en su sitio.\n", filename);
textcolor(0xFFFFFF);// Color Blanco
sceIoClose(file);
return 0;
}
else
{
textcolor(0x00FF00);// Color Verde
printf(" Todos los archivos estan en su sitio.\n");
textcolor(0xFFFFFF);// Color Blanco
sceIoClose(file);
return 1;
}
}
/* Formatea la Flashes */
void del_file(const char * file) // convoluted method of deleting a file; copied from some other code
{
pspDebugScreenSetXY(19, 9);
printf("%s ", file);
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
sceIoGetstat(file, &stat);
stat.st_attr &= ~0x0F;
sceIoChstat(file, &stat, 3);
sceIoRemove(file);
}
void del_dir(const char * dir) // recursively delete a directory, excluding flash0:/ itself
{
pspDebugScreenSetXY(19, 9);
printf("%s ", dir);
int dl = sceIoDopen(dir);
if(dl < 0)
return;
SceIoDirent sid;
memset(&sid, 0, sizeof(SceIoDirent));
while(sceIoDread(dl, &sid))
{
if(sid.d_name[0] == '.') continue;
char compPath[260];
sprintf(compPath, "%s/%s", dir, sid.d_name);
if(FIO_S_ISDIR(sid.d_stat.st_mode))
{
del_dir(compPath);
continue;
}
del_file(compPath);
memset(&sid, 0, sizeof(SceIoDirent));
}
sceIoDclose(dl);
if(strcmp(dir, "flash0:/")) sceIoRmdir(dir);
}
void formatflash0()
{
del_dir("flash0:/");
printf(" Hecho\n");
}
void formatflash1()
{
del_dir("flash1:/");
printf(" Hecho\n");
}
/* Esto nos generara una Copia de Seguridad donde le indiquemos */
/* Build a path, append a directory slash if requested */
void build_path(char *output, const char *root, const char *path, int append)
{
while(*root != 0)
{
*output++ = *root++;
}
if(*(root-1) != '/')
{
*output++ = '/';
}
while(*path != 0)
{
*output++ = *path++;
}
if(append)
*output++ = '/';
*output++ = 0;
}
/* Define a write buffer */
char write_buffer[128*1024];
void write_file(const char *read_loc, const char *write_loc, const char *name)
{
int fdin;
int fdout;
char readpath[256];
char writepath[256];
build_path(readpath, read_loc, name, 0);
build_path(writepath, write_loc, name, 0);
printf(" Escribiendo %s\n", writepath);
fdin = sceIoOpen(readpath, PSP_O_RDONLY, 0777);
if(fdin >= 0)
{
int bytesRead = 1;
fdout = sceIoOpen(writepath, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
if(fdout < 0)
{
printf(" No se ha podido abrir %s\n", writepath);
}
bytesRead = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
while((bytesRead > 0) && (fdout >= 0))
{
sceIoWrite(fdout, write_buffer, bytesRead);
bytesRead = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
}
if(fdout >= 0)
{
sceIoClose(fdout);
}
if(fdin >= 0)
{
sceIoClose(fdin);
}
}
else
{
printf(" No se ha podido abrir %s\n", readpath);
}
}
/* Dump a filing system */
void dump_filesystem(const char *root, const char *write_loc)
{
int dfd;
char next_root[256];
char next_write[256];
sceIoMkdir(write_loc, 0777);
dfd = sceIoDopen(root);
if(dfd > 0)
{
SceIoDirent dir;
while(sceIoDread(dfd, &dir) > 0)
{
if(dir.d_stat.st_attr & FIO_SO_IFDIR)
{
if(dir.d_name[0] != '.')
{
build_path(next_write, write_loc, dir.d_name, 0);
build_path(next_root, root, dir.d_name, 1);
dump_filesystem(next_root, next_write);
}
}
else
{
write_file(root, write_loc, dir.d_name);
}
}
sceIoDclose(dfd);
}
}
void backupflash0()
{
/* Si deseas meter el backup dentro de otra carpeta que aun no este creada debes de crearla primero
mkdir("ms0:/Nueva Carpeta", 0777);
*/
dump_filesystem("flash0:/", "ms0:/Flash0");
}
void backupflash1()
{
dump_filesystem("flash1:/", "ms0:/Flash1");
}
void backupflash2()
{
dump_filesystem("flash2:/", "ms0:/Flash2");
}
void backupflash3()
{
dump_filesystem("flash3:/", "ms0:/Flash3");
}
/* Escribir en la Flash */
//NOTA: depende la flash que le asignemos con anterioridad en esas flash nos escribe.
//NOTA2: Si solamente queremos escribir en la Flash0 pondremos lo del Opcionas1.
void writetoflash(const char *origen,const char *destino) // UTILIZACION: writetoflash("ms0:/archivo.txt", "flash0:/vsh/archivo.txt");
{
char write_buffer[128*1024];
/* Opcional 1
sceIoUnassign("flash0:");
sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);
*/
int prim;
int seg;
prim = sceIoOpen(origen,PSP_O_RDONLY,0777);
if(prim>=0){
int bytesread = 1;
seg = sceIoOpen(destino,PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC,0777);
bytesread = sceIoRead(prim,write_buffer,sizeof(write_buffer));
while((bytesread>0) && (seg>=0)){
sceIoWrite(seg,write_buffer,bytesread);
bytesread = sceIoRead(prim,write_buffer,sizeof(write_buffer));
}
if(seg>=0){
sceIoClose(seg);
}
if(prim<=0){
sceIoClose(prim);
}
}
}
/* Opciones Bateria
No ejecuta el programa si no llega al % indicado, para que te compile añade -lpsppower en el makefile *//*
if (scePowerGetBatteryLifePercent() < 75)
{
screeninit();
printf(" La bateria esta por debajo del 75%%.\n");
delay(5000000);
exitgame();
}
*/
/* Esta funcion te permitira saltar lo de el % del principio*/
int saltarb()
{
SceCtrlData pad;
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_LTRIGGER)
{
if (pad.Buttons & PSP_CTRL_RTRIGGER)
{
return 1;
}
}
return 0;
}
/* Para saltarlo seria asi, inserta esto debajo del main.
if (!saltarb())
{
if (scePowerGetBatteryLifePercent() < 75)
{
screeninit();
printf(" La bateria esta por debajo del 75%%.\n");
delay(5000000);
exitgame();
}
}
*/
----------------------------------------------------------------------------------------------
y en el main pon:
del_dir("ms0:/");