PS2 Linux Programming
Using a Performance Timer
Introduction
This is a short tutorial
which illustrates the use of Timer 3 within the EE core to build a performance
timer. There are four 16 bit counters within the EE core but timer 3 is ideal
since it is slow enough to be sampled in order to calculate “frames per second”
(FPS). Timer 3 uses the horizontal blank frequency of the video circuitry to
count. The frequency of the count is dependant upon the video mode being used.
Details of the count frequencies and video modes are given on page 84 of the GS
Users manual.
As a side issue, the code
accompanying this tutorial also illustrates the uploading of different textures
to GSmem during the render loop. Each frame, a font texture is uploaded to draw
text and a game texture is uploaded to draw characters.
The initialisation and
control of the timer is undertaken by the CTimer class that is contained in the
files Ctimer.cpp and Ctimer.h.
Within the class
constructor, the video mode being used is determined – this is used in order to
find the correct count frequency to be used when calculating the FPS. Note that
the class constructor must be called after the video mode has been configured
with the sps2UScreenInit(0) function– the constructor can be altered if this is
not convenient.
The method GetTimeDelta() returns
the change in the count value since the last time this function was called or
since the PrimeTimer() method was called. The count returned takes into account
any wrapping of the timer.
The method GetFPS()
calculates the current FPS of the application taking into account the video
mode frequency being used.
The use of the timer is
illustrated in the application code accompanying this tutorial.
Dr Henry S Fortuna
University of Abertay
Dundee
h.s.fortuna@abertay.ac.uk