SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
timer.h File Reference

Timer support. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SUBTICKPERSECOND   76800
 Number of subtick per second.
 
#define TICKPERSECOND   300
 Number of tick per second.
 
#define TIMEPERSECOND   256
 Time sub division per second.
 
#define MAXTIMER   16
 Maximum number of timer.
 

Functions

u32 getSubTick (void)
 Returns elapsed subticks from console reset.
 
u32 getTick (void)
 Returns elapsed ticks from console reset.
 
u32 getTime (u16 fromTick)
 Returns elapsed time from console reset.
 
fix32 getTimeAsFix32 (u16 fromTick)
 Returns elapsed time in second from console reset.
 
void startTimer (u16 numTimer)
 Start internal timer (0 <= numtimer < MAXTIMER)
 
u32 getTimer (u16 numTimer, u16 restart)
 Get elapsed subticks for specified timer.
 
void waitSubTick (u32 subtick)
 Wait for a certain amount of subticks (1/76800 second based).
 
void waitTick (u32 tick)
 Wait for a certain amount of ticks (1/300 second based).
 
void waitMs (u32 ms)
 Wait for a certain amount of millisecond.
 

Variables

vu32 vtimer
 

Detailed Description

Timer support.

Author
Stephane Dallongeville
Date
08/2011

This unit provides basic timer functions (useful for profiling).
This unit uses V-Int to count frame so disabling V-Int will make timer methods to not work anymore.

Function Documentation

◆ getSubTick()

u32 getSubTick ( void )

Returns elapsed subticks from console reset.

Returns elapsed subticks from console reset (1/76800 second based).
WARNING: this function isn't accurate during VBlank (return fixed value for the whole VBlank).
This is to avoid issue with the VCounter rollback during VBlank.

◆ getTick()

u32 getTick ( void )

Returns elapsed ticks from console reset.

Returns elapsed ticks from console reset (1/300 second based).

◆ getTime()

u32 getTime ( u16 fromTick)

Returns elapsed time from console reset.

Parameters
fromTickChoose tick or sub tick (more accurate) calculation.

Returns elapsed time from console reset (1/256 second based).

◆ getTimeAsFix32()

fix32 getTimeAsFix32 ( u16 fromTick)

Returns elapsed time in second from console reset.

Parameters
fromTickChoose tick or sub tick (more accurate) calculation.

Returns elapsed time in second from console reset.
Value is returned as fix32.

◆ getTimer()

u32 getTimer ( u16 numTimer,
u16 restart )

Get elapsed subticks for specified timer.

Parameters
numTimerTimer number (0-MAXTIMER)
restartRestart timer if TRUE

Returns elapsed subticks from last call to startTimer(numTimer).

◆ startTimer()

void startTimer ( u16 numTimer)

Start internal timer (0 <= numtimer < MAXTIMER)

Parameters
numTimerTimer number (0-MAXTIMER)

◆ waitMs()

void waitMs ( u32 ms)

Wait for a certain amount of millisecond.

Parameters
msNumber of millisecond to wait for.

WARNING: ~3.33 ms based timer is used when 'ms' is >= 100.

◆ waitSubTick()

void waitSubTick ( u32 subtick)

Wait for a certain amount of subticks (1/76800 second based).

Parameters
subtickNumber of subtick to wait for.

WARNING: this function isn't accurate during VBlank (always wait until the end of VBlank) because of the VCounter rollback.

Here is the call graph for this function:

◆ waitTick()

void waitTick ( u32 tick)

Wait for a certain amount of ticks (1/300 second based).

Parameters
tickNumber of tick to wait for.

WARNING: 5/6 (PAL/NTSC) ticks based timer so use 5 or 6 ticks as minimum wait value.

Here is the call graph for this function: