Help with PSP system clock

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

Moderators: cheriff, TyRaNiD

Post Reply
Davidov
Posts: 2
Joined: Sat May 13, 2006 10:39 pm
Location: Scotland, UK

Help with PSP system clock

Post by Davidov »

Hello today I started to make a small app that acts as a clock for the PSP.
I ran into trouble when compiling as I get various errors where Cywin says that the header psprtc.h supplied with the pspsdk toolchain has syntax errors on almost every line. I also recieve an error due to the command

Code: Select all

pspTime time
In the code below I have left out the initialisation of time. If anyone knows where Im going wrong whether it be coding or something else that works.

Thanks

Code: Select all

/*
          System Clock Example
          Date: 13 may 2006, 12:15pm GMT

          Thanks to www.ps2dev.org for the PSP SDK
      ***  - - - - IMPORTANT  - - - - ***
          Copyright (c) 2005  adresd
          Copyright (c) 2005  Marcus R. Brown
          Copyright (c) 2005  James Forshaw
          Copyright (c) 2005  John Kelley
          Copyright (c) 2005  Jesper Svennevid
          All rights reserved.
*/ 

#include <psprtc.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>

#define printf pspDebugScreenPrintf
PSP_MODULE_INFO&#40;"SYS Clock", 0, 0, 1&#41;;

//----------------- Callbacks -------------------------------------------------
/* 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;
// -------------------- END of Callbacks -------------------------------------
// Main Function
int main&#40;&#41;&#123;
       // Aditional setup for screen output and control input from pad
       pspDebugScreenInit&#40;&#41;;
       SetupCallbacks&#40;&#41;;
       SceCtrlData pad;
       // time initialised
       pspTime time;

       // ~~~~~~~~~~~~~~~~~~~~~ Game loop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       while &#40;1&#41;&#123;
             // Get System clock time
             sceRtcGetCurrentClockLocalTime&#40;&time&#41;;
             // Display on screen
             printf&#40;"The current time is&#58;"&#41;;
             printf&#40;"\nhours&#58; %d",time.hour&#41;;
             printf&#40;"\nminutes&#58; %d",time.minutes&#41;;
             printf&#40;"\nseconds&#58; %d",time.seconds&#41;;

             printf&#40;"\tpress x to exit to menu"&#41;;  // Option to finish program
             sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
             if&#40;pad.Buttons & PSP_CTRL_CROSS&#41; &#123;
                            break;
             &#125;
             for&#40;i=0; i<5; i++&#41; &#123;
                  	sceDisplayWaitVblankStart&#40;&#41;;
             &#125;
             pspDebugScreenClear&#40;&#41;;
       &#125;
       // ~~~~~~~~~~~~~~~~~~~~~ END ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

       sceKernelExitGame&#40;&#41;;  // quits back to psp menu
       return 0; /* just for good practice as this technically
       the program doesnt get to this point */
&#125;
Last edited by Davidov on Mon May 15, 2006 5:06 am, edited 1 time in total.
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Putting this line
#include <psprtc.h>
after this line
#include <pspkernel.h>
might help.

If you're compiling as .c then this
pspDebugScreenInit();
SetupCallbacks();
SceCtrlData pad;
pspTime time;
is all back to front. You can't have declarations inline with the code.
SceCtrlData pad;
pspTime time;
pspDebugScreenInit();
SetupCallbacks();

That will help a bit.

Jim
Davidov
Posts: 2
Joined: Sat May 13, 2006 10:39 pm
Location: Scotland, UK

Post by Davidov »

Ok thanks jim that got rid of that error. However I now get a
make: *** [Clock.elf] Error 1 message when compiling.

I remember I had this problem with another project which occured cause I missed out a required library on the makefile.
So far Ive got -lz but I dont know what other libs I need since just lz worked fine for similar coding,

yet this project includes the psprtc.h file so either Its not working or I need to state the lib for psprtc.h in the makefile.

But thanks jim.


EDIT: Ok i should have done this first but I did a google search there and found the lib i needed to add was -lpsprtc. And it works :)
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

Davidov wrote:Ok thanks jim that got rid of that error. However I now get a
make: *** [Clock.elf] Error 1 message when compiling.
For future reference, thats not the actual error message, just make informing you that it's quiting because something earlier failed.. It is completely unhelpful when trying to figure out what went wrong... You need to read up a bit higher to get the error message ;)
Shoot Pixels Not People!
Makeshift Development
Post Reply