forked from Ports/perfect_dark
port: use gettimeofday() as timing source; use smaller tick multiplier to avoid overflows
This commit is contained in:
1 parent
caaf82385b
commit
87529f37c8
4 files changed
+16
-20
No files matched your search
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <PR/ultratypes.h>
|
||||
|
||||
u64 sysGetTicks(void);
|
||||
u64 sysGetTicksPerSecond(void);
|
||||
void sysInitTicks(void);
|
||||
u64 sysGetMicroseconds(void);
|
||||
|
||||
void sysFatalError(const char *fmt, ...) __attribute__((noreturn));
|
||||
|
||||
|
||||
+4
-1
@@ -15,6 +15,9 @@
|
||||
#define EEPROM_FNAME "./eeprom.bin"
|
||||
#define OS_COUNTER_RATE 46875000ULL
|
||||
|
||||
#define OS_COUNTER_NUM (OS_COUNTER_RATE / 1000ULL)
|
||||
#define OS_COUNTER_DEN (1000000ULL / 1000ULL)
|
||||
|
||||
u64 osClockRate = OS_CLOCK_RATE;
|
||||
u32 osMemSize = 16 * 1024 * 1024; /* expansion pak installed plus some extra */
|
||||
s32 osTvType = OS_TV_NTSC; /* 0 = PAL, 1 = NTSC, 2 = MPAL */
|
||||
@@ -26,7 +29,7 @@ s32 osViClock = VI_NTSC_CLOCK;
|
||||
OSTime osGetTime(void)
|
||||
{
|
||||
// u64 should be enough to last a while
|
||||
return (sysGetTicks() * OS_COUNTER_RATE) / sysGetTicksPerSecond();
|
||||
return (sysGetMicroseconds() * OS_COUNTER_NUM) / OS_COUNTER_DEN;
|
||||
}
|
||||
|
||||
u32 osGetCount(void)
|
||||
|
||||
@@ -60,6 +60,7 @@ static void cleanup(void)
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
sysInitTicks();
|
||||
fsInit();
|
||||
configInit();
|
||||
videoInit();
|
||||
|
||||
+9
-17
@@ -2,33 +2,25 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <SDL.h>
|
||||
#include <PR/ultratypes.h>
|
||||
#include "system.h"
|
||||
|
||||
#define USEC_IN_SEC 1000000ULL
|
||||
|
||||
static u64 startTick = 0;
|
||||
static u64 tickFreq = 0;
|
||||
|
||||
static void sysInitTicks(void)
|
||||
void sysInitTicks(void)
|
||||
{
|
||||
tickFreq = SDL_GetPerformanceFrequency();
|
||||
startTick = SDL_GetPerformanceCounter();
|
||||
startTick = sysGetMicroseconds();
|
||||
}
|
||||
|
||||
u64 sysGetTicks(void)
|
||||
u64 sysGetMicroseconds(void)
|
||||
{
|
||||
if (tickFreq == 0) {
|
||||
sysInitTicks();
|
||||
}
|
||||
return (SDL_GetPerformanceCounter() - startTick);
|
||||
}
|
||||
|
||||
u64 sysGetTicksPerSecond(void)
|
||||
{
|
||||
if (tickFreq == 0) {
|
||||
sysInitTicks();
|
||||
}
|
||||
return tickFreq;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return ((u64)tv.tv_sec * USEC_IN_SEC + (u64)tv.tv_usec) - startTick;
|
||||
}
|
||||
|
||||
void sysFatalError(const char *fmt, ...)
|
||||
|
||||
Reference in new issue
Block a user