Code: Select all
 // Time - Displays the date and time
/*
          This program was created by Josh Valdez using a GNU C libarary
          example.
   
          Editted by Twenty 2 and Yeldarb
*/
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdio.h>
#include <time.h>
 
PSP_MODULE_INFO("Hello World", 0, 1, 1);
#define printf pspDebugScreenPrintf
#define clrscr pspDebugScreenClear
#define SIZE 256
   
/* 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;
}
int main(void) { 
    pspDebugScreenInit();
	SetupCallbacks();
	char buffer[SIZE];
	time_t curtime, oldtime;
	struct tm *loctime;
    
    while(1) {
        do {
            /* Get the current time. */
             curtime = time (NULL);
        } while(curtime == oldtime);
        
        oldtime = curtime;
	clrscr();
        /* Convert it to local time representation. */
        loctime = localtime (&curtime);
        /* Print out the date and time in the standard format. */
        printf (asctime (loctime), stdout);
        /* Print it out in a nice format. */
        strftime (buffer, SIZE, "Today is %A, %B %d.\n", loctime);
        printf (buffer, stdout);
        strftime (buffer, SIZE, "The time is %I:%M %p.\n", loctime);
        printf (buffer, stdout);
    }
       
    sceKernelSleepThread();
       
    return 0;        
}