pspsystimer.h:
Code: Select all
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* pspsystimer.h - Prototypes for the sceSystimer library.
*
* Copyright (c) 2007 Iaroslav Gaponenko <[email protected]>
*
* $Id: pspctrl_kernel.h 2015 2006-10-05 20:23:07Z tyranid $
*/
#ifndef __SYSTIMER_H__
#define __SYSTIMER_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef int SceSysTimerId;
/**
* Allocate a new SysTimer timer instance.
*
* @return SysTimerId on success, < 0 on error
*/
SceSysTimerId sceSTimerAlloc(void);
/**
* Free an instance of a SysTimer timer.
*
* @param timer - The timer id.
*
*/
void sceSTimerFree(SceSysTimerId timer);
/**
* Start the SysTimer timer count.
*
* @param timer - The timer id.
*
*/
void sceSTimerStartCount(SceSysTimerId timer);
/**
* Stop the current SysTimer timer count.
*
* @param timer - The timer id.
*
*/
void sceSTimerStopCount(SceSysTimerId timer);
/**
* Reset the current SysTimer timer count.
*
* @param timer - The timer id.
*
*/
void sceSTimerResetCount(SceSysTimerId timer);
/**
* Get the current SysTimer timer count.
*
* @param timer - The timer id.
* @param count - The pointer to an integer into which the count will be written.
*
*/
void sceSTimerGetCount(SceSysTimerId timer, int* count);
/**
* Setup a SysTimer handler
*
* @param timer - The timer id.
* @param cycle - The timer cycle in microseconds (???). Maximum: 4194303 which represents ~1/10 seconds.
* @param handler - The handler function. Has to return -1.
* @param unk1 - Unknown. Pass 0.
*
*/
void sceSTimerSetHandler(SceSysTimerId timer, int cycle, int (*handler)(void), int unk1);
/* Unknown functions. */
//probably something to set the cycle of an active timer.
void SysTimerForKernel_53231A15(SceSysTimerId timer, int unk1);
//more complex. computes some ratio (unk2/unk1) and saves both parameters into the hardware registers. Might be some sort of scaling factor?
void SysTimerForKernel_B53534B4(SceSysTimerId timer, int unk1, int unk2);
#ifdef __cplusplus
}
#endif
#endif
Code: Select all
.set noreorder
#include "pspstub.s"
STUB_START "SysTimerForKernel",0x00010011,0x00090005
STUB_FUNC 0x228EDAE4,sceSTimerGetCount
STUB_FUNC 0x4A01F9D3,sceSTimerStopCount
STUB_FUNC 0x53231A15,SysTimerForKernel_53231A15
STUB_FUNC 0x54BB5DB4,sceSTimerResetCount
STUB_FUNC 0x975D8E84,sceSTimerSetHandler
STUB_FUNC 0xA95143E2,sceSTimerStartCount
STUB_FUNC 0xB53534B4,SysTimerForKernel_B53534B4
STUB_FUNC 0xC105CF38,sceSTimerFree
STUB_FUNC 0xC99073E3,sceSTimerAlloc
STUB_END
main.c:
Code: Select all
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* main.c - Simple Systimer example
*
* Copyright (c) 2007 Iaroslav Gaponenko <[email protected]>
*
* $Id: main.c 1888 2006-05-01 08:47:04Z tyranid $
* $HeadURL$
*/
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include "pspsystimer.h"
#define printf pspDebugScreenPrintf
/* Define the module info section */
PSP_MODULE_INFO("systimer", 0x1000, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_VFPU);
SceSysTimerId timer;
int tic = 0;
int my_tick_handler(void){
static int div;
div++;
//arrange to get more or less seconds...
if(div > 12){
div = 0;
if(tic){
pspDebugScreenPrintf("Tac!\n");
}else{
pspDebugScreenPrintf("Tic!\n");
}
tic = ~tic;
}
return -1;
}
int main(int argc, char *argv[]) {
pspDebugScreenInit();
pspDebugScreenPrintf("SysTimer sample by Adrahil.\n");
timer = sceSTimerAlloc();
sceSTimerStartCount(timer);
sceSTimerSetHandler(timer, 4194303, my_tick_handler, 0);
sceKernelSleepThreadCB();
return 0;
}