its like no matter what i try to get this thing to work it just refuses to work. finally got it to compile and not crash but now al of a sudden it doesnt wanna save the input from the oskeyboard to teh file. is it really tht hard to set a character limit on a message inputted...? pls if anyone can come up with a working solution to this program so it can run properly...?
#include <pspkernel.h>
#include <oslib/oslib.h>
#include <oslib/intraFont.h>
PSP_MODULE_INFO("P-Notes v 1.0", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
int runningFlag = 1; //Emergency Callback value for home button exit command
int skip = 0; //User Defined Variable
char message[100] = ""; //Limit for error messages
char userText[100] = "";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Callbacks:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
runningFlag = 0;
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, PSP_THREAD_ATTR_USER, 0);
if(thid >= 0)
sceKernelStartThread(thid, 0, 0);
return thid;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Init OSLib:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int initOSLib(){
oslInit(0);
oslInitGfx(OSL_PF_8888, 1);
// oslInitAudio();
oslSetQuitOnLoadFailure(1);
oslSetKeyAutorepeatInit(10);
oslSetKeyAutorepeatInterval(1);
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Main:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main(){
int skip = 0;
int log; //keeps track of return values
char inbuf[128*1024]; //sets up size parameters to for file that stores notes
SetupCallbacks(); //calls the callback functions for home button
initOSLib(); // inits oslib (Onscreen Library)
oslIntraFontInit(INTRAFONT_CACHE_MED); // inits intraFont
//Loads image:
OSL_IMAGE *bkg = oslLoadImageFilePNG("bkg.png", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_8888);
//Load font:
OSL_FONT *pgfFont = oslLoadFontFile("flash0:/font/ltn0.pgf");
oslIntraFontSetStyle(pgfFont, 1.0, RGBA(255,255,255,255), RGBA(0,0,0,0), INTRAFONT_ALIGN_LEFT);
oslSetFont(pgfFont);
while(!osl_quit){
if (!skip){
oslStartDrawing();
oslDrawImageXY(bkg, 0, 0);
oslDrawString(150, 10, "P-Notes version 1.0");
oslDrawString(50, 40, "Press X to Write Data");
oslDrawString(50, 60, "Press O to Read Data");
oslDrawString(50, 80, "Press [] to Delete All");
oslDrawString(50, 250, message);
oslDrawString(50, 120, inbuf);
if (oslOskIsActive()){
oslDrawOsk(); // starts the osk (Onscreen Keyboard)
if (oslGetOskStatus() == PSP_UTILITY_DIALOG_NONE){
if (oslOskGetResult() == OSL_OSK_CANCEL){
sprintf(message, "Make A Selection....");
}
else if (oslOskGetResult() != OSL_OSK_CANCEL){
char userText[100] = "";
oslOskGetText(userText); // enters a record here
}
if ( strlen(userText) >= 26 ){
sprintf(message, "Note must be 25 characters or less\n");
oslPrintf(message);
}
else if ( strlen(userText) < 26 ){
sprintf(message, "P-Note Saved ^_^ \n"); // displays record on the screen
oslPrintf(message);
strcat(userText, "\n");
log = writelog(userText); // writes the record to file
}
oslEndOsk();
}
}
//oslEndDrawing();
if (!oslOskIsActive()){
oslReadKeys();
}
if (osl_keys->pressed.triangle){
// runningFlag = 0;
oslEndGfx();
sceKernelExitGame(); // exit if triangle is pressed
}
else if (osl_keys->pressed.cross){
// enter data if cross is pressed
oslInitOsk("Please insert some text", "Input Note", 128, 1,"ENGLISH");
memset(message, 0, sizeof(message));
}
else if (osl_keys->pressed.square){
// delete the file
sceIoRemove("ms0:/P-Notes.txt");
}
else if (osl_keys->pressed.circle){
// read the file
readlog(inbuf);
oslDrawString(350, 250, "Loading...");
oslDrawString(50, 120, inbuf); // print the records
}
}
oslEndFrame();
skip = oslSyncFrame();
}
//Quit OSL:
oslEndGfx();
sceKernelExitGame();
return 0;
}
// writes the data entered from osk to a file
int writelog(char* str)
{
SceUID fd = sceIoOpen("ms0:/P-Notes.txt", PSP_O_CREAT | PSP_O_APPEND | PSP_O_WRONLY, 0777);
if (fd > 0) sceIoWrite(fd, str, strlen(str));
else return -1;
sceIoClose(fd);
return 0;
}
// reads the file
void readlog(char* buff)
{
int fd;
int flen;
if(!(fd = sceIoOpen("ms0:/P-Notes.txt", PSP_O_RDONLY, 0777)))
{
// Error if we cant open it
}
else {
flen = sceIoRead(fd, buff, 131072);
if(flen <= 0)
{
// if flen is 0 or lower, this means that the file
// is empty, it didnt read any bytes.
}
}
// Must make sure to close the file I/O before continuing
// with the rest of the program
sceIoClose(fd);
}