aboutsummaryrefslogtreecommitdiff
path: root/backends/platform
diff options
context:
space:
mode:
authorYotam Barnoy2010-06-07 13:47:27 +0000
committerYotam Barnoy2010-06-07 13:47:27 +0000
commit356728dab7f2c4cedf73684d7fe3b968be7396fd (patch)
treeeebbd02cdfdfeb25579c9847ed6585fa7955ce8b /backends/platform
parent8ef5d55edb5b463abca1adf0ed1f359ce94bd391 (diff)
downloadscummvm-rg350-356728dab7f2c4cedf73684d7fe3b968be7396fd.tar.gz
scummvm-rg350-356728dab7f2c4cedf73684d7fe3b968be7396fd.tar.bz2
scummvm-rg350-356728dab7f2c4cedf73684d7fe3b968be7396fd.zip
PSP: found bug in fast getMillis() implementation. Fixed it by adding a fixed amount to the time counter.
svn-id: r49485
Diffstat (limited to 'backends/platform')
-rw-r--r--backends/platform/psp/osys_psp.cpp3
-rw-r--r--backends/platform/psp/osys_psp.h2
-rw-r--r--backends/platform/psp/thread.cpp41
-rw-r--r--backends/platform/psp/thread.h16
4 files changed, 55 insertions, 7 deletions
diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp
index a36ae1847f..2043a4bef2 100644
--- a/backends/platform/psp/osys_psp.cpp
+++ b/backends/platform/psp/osys_psp.cpp
@@ -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) {
diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h
index 3f075d0139..a6c84ba39a 100644
--- a/backends/platform/psp/osys_psp.h
+++ b/backends/platform/psp/osys_psp.h
@@ -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();
diff --git a/backends/platform/psp/thread.cpp b/backends/platform/psp/thread.cpp
index 88e7b6fe38..4e7d5eada9 100644
--- a/backends/platform/psp/thread.cpp
+++ b/backends/platform/psp/thread.cpp
@@ -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
+}
+
+#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 PspThread::getMicros() {
+uint32 PspRtc::getMicros() {
uint32 ticks[2];
+
sceRtcGetCurrentTick((u64 *)ticks);
+ ticks[0] -= _startMicros;
+
return ticks[0];
}
diff --git a/backends/platform/psp/thread.h b/backends/platform/psp/thread.h
index e83eead68e..380159fa2d 100644
--- a/backends/platform/psp/thread.h
+++ b/backends/platform/psp/thread.h
@@ -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 {