timer.cpp

00001 /*
00002 * "PS2" Application Framework
00003 *
00004 * University of Abertay Dundee
00005 * May be used for educational purposed only
00006 *
00007 * Author - Dr Henry S Fortuna
00008 *
00009 * $Revision: 1.2 $
00010 * $Date: 2007/08/19 12:45:13 $
00011 *
00012 */
00013 
00014 #include <sps2lib.h>
00015 #include <sps2tags.h>
00016 #include <sps2util.h>
00017 #include "timer.h"
00018 
00019 
00020 CTimer::CTimer(void)
00021 {
00022         m_LastTime = *EE_T3_COUNT;
00023         m_VideoMode = sps2UScreenGetVideoMode();
00024 }
00025 
00026 CTimer::~CTimer(void)
00027 {
00028 }
00029 
00030 
00031 void CTimer::PrimeTimer(void)
00032 {
00033                 m_LastTime = *EE_T3_COUNT;
00034 }
00035 
00036 
00037 unsigned int CTimer::GetTimeDelta(void)
00038 {
00039         m_Time = *EE_T3_COUNT;
00040         
00041         
00042         if(m_Time < m_LastTime)// The counter has wrapped
00043         {
00044                 m_Change = m_Time + (65536 - m_LastTime);
00045         }
00046         else
00047         {
00048                 m_Change = m_Time - m_LastTime;
00049         }
00050 
00051         m_LastTime = m_Time;
00052         
00053         return m_Change;
00054 }
00055 
00056 
00057 // The numbers in this function are the horizontal blank rates in Hz
00058 // See Page 84 of the GS Users manual
00059 
00060 float CTimer::GetFPS(void)
00061 {
00062         unsigned int TimeDelta = GetTimeDelta();
00063         
00064         if(TimeDelta == 0)return -1.0f;
00065         
00066         switch(m_VideoMode)
00067         {
00068                 case SPS2U_SCR_VESA:
00069                         return 31469.0f / (float)TimeDelta;     
00070         
00071                 case SPS2U_SCR_PAL:
00072                         return 15625.0f / (float)TimeDelta;
00073         
00074                 case SPS2U_SCR_NTSC:
00075                         return 15734.0f / (float)TimeDelta;
00076         
00077                 default:
00078                         return 0.0f;
00079         }
00080 }

Generated on Sun May 18 21:45:09 2008 for PS2X by  doxygen 1.5.4