PSP: found bug in fast getMillis() implementation. Fixed it by adding a fixed amount to the time counter.

svn-id: r49485
This commit is contained in:
Yotam Barnoy
2010-06-07 13:47:27 +00:00
parent 8ef5d55edb
commit 356728dab7
4 changed files with 55 additions and 7 deletions
+1 -2
View File
@@ -37,7 +37,6 @@
#include "backends/platform/psp/psppixelformat.h"
#include "backends/platform/psp/osys_psp.h"
#include "backends/platform/psp/powerman.h"
#include "backends/platform/psp/thread.h"
#include "backends/saves/psp/psp-saves.h"
#include "backends/timer/default/default-timer.h"
@@ -300,7 +299,7 @@ bool OSystem_PSP::pollEvent(Common::Event &event) {
}
uint32 OSystem_PSP::getMillis() {
return PspThread::getMillis();
return _pspRtc.getMillis();
}
void OSystem_PSP::delayMillis(uint msecs) {
+2
View File
@@ -40,6 +40,7 @@
#include "backends/platform/psp/input.h"
#include "backends/platform/psp/audio.h"
#include "backends/timer/psp/timer.h"
#include "backends/platform/psp/thread.h"
#include <SDL.h>
@@ -59,6 +60,7 @@ private:
InputHandler _inputHandler;
PspAudio _audio;
PspTimer _pspTimer;
PspRtc _pspRtc;
void initSDL();
+38 -3
View File
@@ -29,6 +29,7 @@
#include <pspthreadman.h>
#include "backends/platform/psp/thread.h"
#include "backends/platform/psp/trace.h"
void PspThread::delayMillis(uint32 ms) {
sceKernelDelayThread(ms * 1000);
@@ -38,15 +39,49 @@ void PspThread::delayMicros(uint32 us) {
sceKernelDelayThread(us);
}
uint32 PspThread::getMillis() {
void PspRtc::init() { // init our starting ticks
uint32 ticks[2];
sceRtcGetCurrentTick((u64 *)ticks);
return (ticks[0]/1000);
_startMillis = ticks[0]/1000;
_startMicros = ticks[0];
//_lastMillis = ticks[0]/1000; //debug - only when we don't subtract startMillis
}
uint32 PspThread::getMicros() {
#define MS_LOOP_AROUND 4294967 /* We loop every 2^32 / 1000 = 71 minutes */
#define MS_LOOP_CHECK 60000 /* Threading can cause weird mixups without this */
// Note that after we fill up 32 bits ie 50 days we'll loop back to 0, which may cause
// unpredictable results
uint32 PspRtc::getMillis() {
uint32 ticks[2];
sceRtcGetCurrentTick((u64 *)ticks); // can introduce weird thread delays
uint32 millis = ticks[0]/1000;
millis -= _startMillis; // get ms since start of program
if ((int)_lastMillis - (int)millis > MS_LOOP_CHECK) { // we must have looped around
if (_looped == false) { // check to make sure threads do this once
_looped = true;
_milliOffset += MS_LOOP_AROUND; // add the needed offset
PSP_DEBUG_PRINT("looping around. last ms[%d], curr ms[%d]\n", _lastMillis, millis);
}
} else {
_looped = false;
}
_lastMillis = millis;
return millis + _milliOffset;
}
uint32 PspRtc::getMicros() {
uint32 ticks[2];
sceRtcGetCurrentTick((u64 *)ticks);
ticks[0] -= _startMicros;
return ticks[0];
}
+14 -2
View File
@@ -32,8 +32,20 @@ class PspThread {
public:
static void delayMillis(uint32 ms);
static void delayMicros(uint32 us);
static uint32 getMillis();
static uint32 getMicros();
};
class PspRtc {
private:
uint32 _startMillis;
uint32 _startMicros;
uint32 _lastMillis;
uint32 _milliOffset; // to prevent looping around of millis
bool _looped; // make sure we only loop once
public:
PspRtc() : _startMillis(0), _startMicros(0), _lastMillis(0), _milliOffset(0), _looped(false) { init(); }
void init();
uint32 getMillis();
uint32 getMicros();
};
enum ThreadPriority {