En este apartado haremos especial incapie en las Librerias. Como hemos dicho antes las Librerias son archivos adicionales, requeridos por el Main.c, de esta manera ahorramos escribir codigo en el Main y asi tenerlo mas ordenado, limpio y depurado.
En letra pequeña los comentarios, no necesarios para la libreria.
#include "psppower.h"
#include <pspdisplay>
#include <pspgu>
#include <png>
#include <stdio>
#include "graphics.h"
#include <pspiofilemgr>
#include <pspdebug>
#include <pspusb>
#include <pspusbstor>
#include <pspctrl>
#include <pspumd>
#include <pspkernel>
#include <pspkerneltypes>
#include <psploadexec>
#include <pspthreadman>
#include <pspmodulemgr>
#include <string>
int scePowerSetCpuClockFrequency(int cpufreq);
int scePowerGetBatteryLifePercent(void);
extern Image* loadImage(const char* filename);
extern void initGraphics();
extern void disableGraphics();
extern void flipScreen();
extern void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy);
void writetoflashone(const char *origen, const char *destino) {
char write_buffer[128*1024];
sceIoUnassign("flash1:");
sceIoAssign("flash1:", "lflash0:0,1", "flashfat1:", IOASSIGN_RDWR, NULL, 0);
int primero;
int segundo;
primero = open(origen, PSP_O_RDONLY, 0777);
if(primero <0>= 0)
{
int bytesleidos = 1;
segundo = open(destino, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
bytesleidos = read(primero, write_buffer, sizeof(write_buffer));
while((bytesleidos > 0) && (segundo >= 0))
{
write(segundo, write_buffer, bytesleidos);
bytesleidos = read(primero, write_buffer, sizeof(write_buffer));
}
if(segundo >= 0)
{
close(segundo);
}
if(primero >= 0)
{
close(primero);
}
}
}
void writetoflash0(const char *origen, const char *destino) {
char write_buffer[128*1024];
sceIoUnassign("flash0:");
sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);
int primero;
int segundo;
primero = open(origen, PSP_O_RDONLY, 0777);
if(primero <0>= 0)
{
int bytesleidos = 1;
segundo = open(destino, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
bytesleidos = read(primero, write_buffer, sizeof(write_buffer));
while((bytesleidos > 0) && (segundo >= 0))
{
write(segundo, write_buffer, bytesleidos);
bytesleidos = read(primero, write_buffer, sizeof(write_buffer));
}
if(segundo >= 0)
{
close(segundo);
}
if(primero >= 0)
{
close(primero);
}
}
}
#define open sceIoOpen
#define close sceIoClose
#define write sceIoWrite
#define remove sceIoRemove
#define rename sceIoRename
#define read sceIoRead
#define mkdir sceIoMkdir
#define rmdir sceIoRmdir
SceUID sceIoOpen(const char *file, int flags, SceMode mode);
int sceIoClose(SceUID fd);
int sceIoWrite(SceUID fd, const void *data, SceSize size);
int sceIoRemove(const char *file);
int sceIoRead(SceUID fd, void *data, SceSize size);
int sceIoRename(const char *oldname, const char *newname);
int sceIoMkdir(const char *dir, SceMode mode);
int sceIoRmdir(const char *path);
#define screeninit pspDebugScreenInit
#define printf pspDebugScreenPrintf
#define clearscreen pspDebugScreenClear
#define backcolor pspDebugScreenSetBackColor
#define textcolor pspDebugScreenSetTextColor
#define setxy pspDebugScreenSetXY
void pspDebugScreenInit(void);
void pspDebugScreenPrintf(const char *fmt, ...) __attribute__((format(printf,1,2)));
void pspDebugScreenClear(void);
void pspDebugScreenSetBackColor(u32 color);
void pspDebugScreenSetTextColor(u32 color);
void pspDebugScreenSetXY(int x, int y);
#define USBBusDriver PSP_USBBUS_DRIVERNAME
#define USBStorDriver PSP_USBSTOR_DRIVERNAME
#define PSP_USB_ACTIVATED 0x200
#define PSP_USB_CABLE_CONNECTED 0x020
#define PSP_USB_CONNECTION_ESTABLISHED 0x002
#define startusb sceUsbStart
#define stopusb sceUsbStop
#define ausb sceUsbActivate
#define dusb sceUsbDeactivate
#define stateusb sceUsbGetState
int sceUsbStart(const char* driverName, int size, void *args);
int sceUsbStop(const char* driverName, int size, void *args);
int sceUsbActivate(u32 pid);
int sceUsbDeactivate(u32 pid);
int sceUsbGetState(void);
void loadusb()
{
pspSdkLoadStartModule("flash0:/kd/semawm.prx", PSP_MEMORY_PARTITION_KERNEL);
pspSdkLoadStartModule("flash0:/kd/usbstor.prx", PSP_MEMORY_PARTITION_KERNEL);
pspSdkLoadStartModule("flash0:/kd/usbstormgr.prx", PSP_MEMORY_PARTITION_KERNEL);
pspSdkLoadStartModule("flash0:/kd/usbstorms.prx", PSP_MEMORY_PARTITION_KERNEL);
pspSdkLoadStartModule("flash0:/kd/usbstorboot.prx", PSP_MEMORY_PARTITION_KERNEL);
}
#define CtrlData SceCtrlData
#define CtrlCycle sceCtrlSetSamplingCycle
#define CtrlMode sceCtrlSetSamplingMode
#define digital PSP_CTRL_MODE_DIGITAL
#define analog PSP_CTRL_MODE_ANALOG
#define CtrlBuffer 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 left PSP_CTRL_LEFT
#define right PSP_CTRL_RIGHT
#define down PSP_CTRL_DOWN
#define up PSP_CTRL_UP
#define aumd sceUmdActivate
int sceUmdActivate(int unit, const char *drive);
#define kprintf Kprintf
void Kprintf(const char *format, ...) __attribute__((format(printf, 1, 2)));
#define exit sceKernelExitGame
#define loadexec sceKernelLoadExec
void sceKernelExitGame(void);
int sceKernelLoadExec(const char *file, struct SceKernelLoadExecParam *param);
#define delay sceKernelDelayThread
#define exitthread sceKernelExitDeleteThread
#define screensleep sceKernelSleepThread
#define screensleepcb sceKernelSleepThreadCB
int sceKernelDelayThread(SceUInt delay);
int sceKernelSleepThread(void);
int sceKernelSleepThreadCB(void);
#define loadmodule sceKernelLoadModule
#define loadmodulems sceKernelLoadModuleMs
#define stopmodule sceKernelStopModule
#define unloadmodule sceKernelUnloadModule
SceUID sceKernelLoadModule(const char *path, int flags, SceKernelLMOption *option);
SceUID sceKernelLoadModuleMs(const char *path, int flags, SceKernelLMOption *option);
int sceKernelStopModule(SceUID modid, SceSize argsize, void *argp, int *status, SceKernelSMOption *option);
int sceKernelUnloadModule(SceUID modid);
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;
}
/**
* All of these functions can be accessed in both, SE-C (or later) and
* HEN-D (or later) in both, normal and devhook
*
* All of the functions can be used in both, user or kernel mode.
*/
/**
* Restart the vsh.
*
* @param param - Pointer to a ::SceKernelLoadExecVSHParam structure, or NULL
*
* @returns < 0 on some errors.
*
*/
int sctrlKernelExitVSH(struct SceKernelLoadExecVSHParam *param);
/**
* Executes a new executable from a disc.
* It is the function used by the firmware to execute the EBOOT.BIN from a disc.
*
* @param file - The file to execute.
* @param param - Pointer to a ::SceKernelLoadExecVSHParam structure, or NULL.
*
* @returns < 0 on some errors.
*/
int sctrlKernelLoadExecVSHDisc(const char *file, struct SceKernelLoadExecVSHParam *param);
/**
* Executes a new executable from a disc.
* It is the function used by the firmware to execute an updater from a disc.
*
* @param file - The file to execute.
* @param param - Pointer to a ::SceKernelLoadExecVSHParam structure, or NULL.
*
* @returns < 0 on some errors.
*/
int sctrlKernelLoadExecVSHDiscUpdater(const char *file, struct SceKernelLoadExecVSHParam *param);
/**
* Executes a new executable from a memory stick.
* It is the function used by the firmware to execute an updater from a memory stick.
*
* @param file - The file to execute.
* @param param - Pointer to a ::SceKernelLoadExecVSHParam structure, or NULL.
*
* @returns < 0 on some errors.
*/
int sctrlKernelLoadExecVSHMs1(const char *file, struct SceKernelLoadExecVSHParam *param);
/**
* Executes a new executable from a memory stick.
* It is the function used by the firmware to execute games (and homebrew
) from a memory stick.
*
* @param file - The file to execute.
* @param param - Pointer to a ::SceKernelLoadExecVSHParam structure, or NULL.
*
* @returns < 0 on some errors.
*/
int sctrlKernelLoadExecVSHMs2(const char *file, struct SceKernelLoadExecVSHParam *param);
/**
* Executes a new executable from a memory stick.
* It is the function used by the firmware to execute ... ?
*
* @param file - The file to execute.
* @param param - Pointer to a ::SceKernelLoadExecVSHParam structure, or NULL.
*
* @returns < 0 on some errors.
*/
int sctrlKernelLoadExecVSHMs3(const char *file, struct SceKernelLoadExecVSHParam *param);
/**
* Executes a new executable with the specified apitype
*
* @param apitype - The apitype
* @param file - The file to execute.
* @param param - Pointer to a ::SceKernelLoadExecVSHParam structure, or NULL.
*
* @returns < 0 on some errors.
*/
int sctrlKernelLoadExecVSHWithApitype(int apitype, const char *file, struct SceKernelLoadExecVSHParam *param);
/**
* Sets the api type
*
* @param apitype - The apitype to set
* @returns 0 on success
*
* @Note - this will modify also the value of sceKernelBootFrom, since the value of
* bootfrom is calculated from the apitype
*/
int sctrlKernelSetInitApitype(int apitype);
/**
* Sets the filename of the launched executable.
*
* @param filename - The filename to set
* @returns 0 on success
*/
int sctrlKernelSetInitFileName(char *filename);
/**
* Sets the user level of the current thread
*
* @param level - The user level
* @return the previous user level on success
*/
int sctrlKernelSetUserLevel(int level);
/**
* Sets the devkit version
*
* @param version - The devkit version to set
* @return 0 on success
*
*/
int sctrlKernelSetDevkitVersion(int version);
/**
* Checks if we are in SE.
*
* @returns 1 if we are in SE-C or later, 0 if we are in HEN-D or later,
* and < 0 (a kernel error code) in any other case
*/
int sctrlHENIsSE();
/**
* Checks if we are in Devhook.
*
* @returns 1 if we are in SE-C/HEN-D for devhook or later, 0 if we are in normal SE-C/HEN-D or later,
* and < 0 (a kernel error code) in any other case
*/
int sctrlHENIsDevhook();
/**
* Gets the HEN version
*
* @returns - The HEN version
*
* HEN D / SE-C : 0x00000400
*/
int sctrlHENGetVersion();
/**
* Finds a driver
*
* @param drvname - The name of the driver (without ":" or numbers)
*
* @returns the driver if found, NULL otherwise
*
*/
PspIoDrv *sctrlHENFindDriver(char *drvname);
/**
* Finds a function.
*
* @param modname - The module where to search the function
* @param libname - The library name
* @nid - The nid of the function
*
* @returns - The function address or 0 if not found
*
*/
u32 sctrlHENFindFunction(char *modname, char *libname, u32 nid);
Como podemos observar en la libreria arriba expuesta, la libreria contiene diverso codigo, como las funciones de flasheo, botones, bateria, etc, etc. Solo debemos escribir la funcion en el Main.c. y el se encargara de buscar el resto del codigo en las librerias, de este modo ahorramos tiempo tambien, puesto que no hay que estar definiendo completamente la funcion nuevamente.
Para incluir una libreria en la Main.c debemos escribir esto en las primeras lineas del Main.c
#include "Nombre de la Libreria a Incluir" Buscara la libreria al lado del Main.c
#include <Nombre> Buscara la libreria en el sdk del Pc
De momento aqui vamos a dejar el tema de las librerias, mas adelante seguiremos explicando mas, ahora es mejor ver unas definiciones y empezar a practicar.
Comentarios
Libreria Fontloader
Hola..
He seguido mucho los tutoriales y revisado algunos de los ejemplos que aqui se publican, yo he instalado el kit para programar version 3 y me parece muy bien, pues simplifica en mucho las cosas y pude hacer correr algunos programas, ahora estoy empezando a hacer los mios.
Pero me gustaria saber si hay algun tutorial y si me pueden ayudar con la cuestion de las fuentes ttf, me gustaria poder cambiar la fuente y he visto que el kit incluye una libreria fontloader, pero no he podido usarla o configurarla, no se porque, ojala alguien me pueda ayudar al respecto. De antemano muchas gracias y felicidades, muy buenos tutoriales.
Saludos
Ayuda! Por favor
Pongo esto y cuando compilo todo va bien pero en las ultimas lineas dice: number of arguments doesn't match prototype y no me lo compila
------------------------------------------------------------------------------------
// Ejemplo creado por Marce82 //
#include "Astaroth.h" // Incluimos la libreria Astaroth //
PSP_MODULE_INFO("Mi Programa", 0, 1, 0); // Definimos el nombre del modulo //
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER); // Definimos el MODO de la aplicacion en este caso es MODO USER //
void menu() // Definimos nuestro Menu (Esto es un ejemplo de como crear una funcion propia) //
{
clearscreen(); // Limpia la Pantalla //
printf(" Pulsa X\n"); // Imprime texto en Pantalla //
printf(" Pulsa para salir"); // Imprime texto en Pantalla //
CtrlData pad; // Define el control del pad //
while (1) // Comenzamos la definicion de botones //
{
CtrlBuffer(&pad, 1); // Lectura del Buffer de los botones definidos anteriormente //
if (pad.Buttons & cross) // Definimos al pulsar el Boton Equis //
{
clearscreen(); // Limpia la Pantalla //
printf("Escribiendo... Espere..."); // Imprime texto en Pantalla //
void writetoflash0("ms0:/1.txt","flash0:/1.txt") {
char write_buffer[128*1024];
sceIoUnassign("flash0:");
sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);
int primero;
int segundo;
primero = open("ms0:/1.txt", PSP_O_RDONLY, 0777);
if(primero <0>= 0)
{
int bytesleidos = 1;
segundo = open("flash0:/1.txt", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
bytesleidos = read(primero, write_buffer, sizeof(write_buffer));
while((bytesleidos > 0) && (segundo >= 0))
{
write(segundo, write_buffer, bytesleidos);
bytesleidos = read(primero, write_buffer, sizeof(write_buffer));
}
if(segundo >= 0)
{
close(segundo);
}
if(primero >= 0)
{
close(primero);
}
}
}
delay(10*1000*1000); // Retardo de Tiempo (1 Segundo) //
menu(); // Regresa al menu //
}
if (pad.Buttons & triangle) // Definimos al pulsar el Boton Triagulo //
{
clearscreen(); // Limpia la Pantalla //
printf("Saliendo... Espere..."); // Imprime texto en Pantalla //
delay(2*1000*1000); // Retardo de Tiempo (2 Segundo) //
exit(); // Sale de la Aplicacion //
}
} // Siempre que vamos a definir un comando,se abre el "{" recordad que luego ahy que cerrarlos todos "}"
}
int main() // Definimos aqui el Programa //
{
CtrlData currentPad, lastPad; // Define el control del pad //
CtrlBuffer(&lastPad, 1); // Lectura del Buffer de los botones definidos anteriormente //
screeninit(); // Inicia Pantalla para poder Escribir en ella //
menu(); // Llama a nuestra Definicion (En este caso a nuestro menu) //
}
/,*,/