PSP Clock Problem

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Twenty 2
Posts: 15
Joined: Mon Jul 25, 2005 3:23 am

PSP Clock Problem

Post by Twenty 2 »

I cant get this script to put the exact time and date it. The date keeps updating every sec and the times way off.Can anyone help?

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&#40;"Hello World", 0, 1, 1&#41;;

#define printf pspDebugScreenPrintf
#define clrscr pspDebugScreenClear
#define SIZE 256
   
/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
        sceKernelExitGame&#40;&#41;;
        return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
    int cbid;

    cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
    sceKernelRegisterExitCallback&#40;cbid&#41;;

    sceKernelSleepThreadCB&#40;&#41;;

    return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
    int thid = 0;

    thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
    if&#40;thid >= 0&#41; &#123;
            sceKernelStartThread&#40;thid, 0, 0&#41;;
    &#125;

    return thid;
&#125;

int main&#40;void&#41; &#123; 
    pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;

	char buffer&#91;SIZE&#93;;
	time_t curtime, oldtime;
	struct tm *loctime;
    
    while&#40;1&#41; &#123;
        do &#123;
            /* Get the current time. */
             curtime = time &#40;NULL&#41;;
        &#125; while&#40;curtime == oldtime&#41;;
        
        oldtime = curtime;

	clrscr&#40;&#41;;

        /* Convert it to local time representation. */
        loctime = localtime &#40;&curtime&#41;;

        /* Print out the date and time in the standard format. */
        printf &#40;asctime &#40;loctime&#41;, stdout&#41;;

        /* Print it out in a nice format. */
        strftime &#40;buffer, SIZE, "Today is %A, %B %d.\n", loctime&#41;;
        printf &#40;buffer, stdout&#41;;
        strftime &#40;buffer, SIZE, "The time is %I&#58;%M %p.\n", loctime&#41;;
        printf &#40;buffer, stdout&#41;;
    &#125;
       
    sceKernelSleepThread&#40;&#41;;
       
    return 0;        
&#125;  
Warren
Posts: 175
Joined: Sat Jan 24, 2004 8:26 am
Location: San Diego, CA

Post by Warren »

Dunno, but try using the time functions in psprtc.h. I know they work correctly (I had a nice sample written for it but it got nuked in a SVN snafu)
Post Reply