aboutsummaryrefslogtreecommitdiff
path: root/backends/platform
diff options
context:
space:
mode:
authorYotam Barnoy2010-06-21 15:13:36 +0000
committerYotam Barnoy2010-06-21 15:13:36 +0000
commit65fe8d817c627fe56929533a4a0fb4d2c5cb76c2 (patch)
tree601bf632ba46e17228497441edbf3095e93f421d /backends/platform
parent4a4fcb19dd85cd8f3ffc63ef44f033d21b50744e (diff)
downloadscummvm-rg350-65fe8d817c627fe56929533a4a0fb4d2c5cb76c2.tar.gz
scummvm-rg350-65fe8d817c627fe56929533a4a0fb4d2c5cb76c2.tar.bz2
scummvm-rg350-65fe8d817c627fe56929533a4a0fb4d2c5cb76c2.zip
PSP: moved RTC to singleton to allow usage by classes other than Osystem
svn-id: r50116
Diffstat (limited to 'backends/platform')
-rw-r--r--backends/platform/psp/Makefile1
-rw-r--r--backends/platform/psp/module.mk1
-rw-r--r--backends/platform/psp/osys_psp.cpp6
-rw-r--r--backends/platform/psp/osys_psp.h1
-rw-r--r--backends/platform/psp/rtc.cpp87
-rw-r--r--backends/platform/psp/rtc.h45
-rw-r--r--backends/platform/psp/thread.cpp57
-rw-r--r--backends/platform/psp/thread.h17
8 files changed, 140 insertions, 75 deletions
diff --git a/backends/platform/psp/Makefile b/backends/platform/psp/Makefile
index 02fd8b022a..fed558eaad 100644
--- a/backends/platform/psp/Makefile
+++ b/backends/platform/psp/Makefile
@@ -147,6 +147,7 @@ OBJS := powerman.o \
pspkeyboard.o \
audio.o \
thread.o \
+ rtc.o \
mp3.o
# Include common Scummvm makefile
diff --git a/backends/platform/psp/module.mk b/backends/platform/psp/module.mk
index 99170ce7fb..e9c896acfd 100644
--- a/backends/platform/psp/module.mk
+++ b/backends/platform/psp/module.mk
@@ -15,6 +15,7 @@ MODULE_OBJS := powerman.o \
pspkeyboard.o \
audio.o \
thread.o \
+ rtc.o \
mp3.o
MODULE_DIRS += \
diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp
index 01053b8cbb..b09d9c0c00 100644
--- a/backends/platform/psp/osys_psp.cpp
+++ b/backends/platform/psp/osys_psp.cpp
@@ -37,6 +37,7 @@
#include "backends/platform/psp/psppixelformat.h"
#include "backends/platform/psp/osys_psp.h"
#include "backends/platform/psp/powerman.h"
+#include "backends/platform/psp/rtc.h"
#include "backends/saves/psp/psp-saves.h"
#include "backends/timer/default/default-timer.h"
@@ -64,6 +65,9 @@ OSystem_PSP::~OSystem_PSP() {}
void OSystem_PSP::initBackend() {
DEBUG_ENTER_FUNC();
+ // Instantiate real time clock
+ PspRtc::instance();
+
_cursor.enableCursorPalette(false);
_cursor.setXY(PSP_SCREEN_WIDTH >> 1, PSP_SCREEN_HEIGHT >> 1); // Mouse in the middle of the screen
@@ -320,7 +324,7 @@ bool OSystem_PSP::pollEvent(Common::Event &event) {
}
uint32 OSystem_PSP::getMillis() {
- return _pspRtc.getMillis();
+ return PspRtc::instance().getMillis();
}
void OSystem_PSP::delayMillis(uint msecs) {
diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h
index 46f258f577..5721296c94 100644
--- a/backends/platform/psp/osys_psp.h
+++ b/backends/platform/psp/osys_psp.h
@@ -60,7 +60,6 @@ private:
InputHandler _inputHandler;
PspAudio _audio;
PspTimer _pspTimer;
- PspRtc _pspRtc;
public:
OSystem_PSP() : _savefile(0), _mixer(0), _timer(0), _pendingUpdate(false), _pendingUpdateCounter(0) {}
diff --git a/backends/platform/psp/rtc.cpp b/backends/platform/psp/rtc.cpp
new file mode 100644
index 0000000000..57edea7e49
--- /dev/null
+++ b/backends/platform/psp/rtc.cpp
@@ -0,0 +1,87 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $
+ * $Id: osys_psp.cpp 49903 2010-06-16 09:04:27Z Bluddy $
+ *
+ */
+
+#include <time.h>
+#include <psptypes.h>
+#include <psprtc.h>
+
+#include "common/scummsys.h"
+#include "backends/platform/psp/rtc.h"
+
+//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */
+//#define __PSP_DEBUG_PRINT__ /* For debug printouts */
+
+#include "backends/platform/psp/trace.h"
+
+
+// Class PspRtc ---------------------------------------------------------------
+DECLARE_SINGLETON(PspRtc)
+
+void PspRtc::init() { // init our starting ticks
+ uint32 ticks[2];
+ sceRtcGetCurrentTick((u64 *)ticks);
+
+ _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 PspRtc::getMicros() {
+ uint32 ticks[2];
+
+ sceRtcGetCurrentTick((u64 *)ticks);
+ ticks[0] -= _startMicros;
+
+ return ticks[0];
+}
+
diff --git a/backends/platform/psp/rtc.h b/backends/platform/psp/rtc.h
new file mode 100644
index 0000000000..3f2d52ff16
--- /dev/null
+++ b/backends/platform/psp/rtc.h
@@ -0,0 +1,45 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $
+ * $Id: osys_psp.cpp 49903 2010-06-16 09:04:27Z Bluddy $
+ *
+ */
+
+#ifndef _PSP_RTC_H_
+#define _PSP_RTC_H_
+
+#include "common/singleton.h"
+
+class PspRtc : public Common::Singleton<PspRtc>{
+private:
+ uint32 _startMillis;
+ uint32 _startMicros;
+ uint32 _lastMillis;
+ uint32 _milliOffset; // to prevent looping around of millis
+ bool _looped; // make sure we only loop once - for threading
+public:
+ PspRtc() : _startMillis(0), _startMicros(0), _lastMillis(0), _milliOffset(0), _looped(false) { init(); }
+ void init();
+ uint32 getMillis();
+ uint32 getMicros();
+};
+
+#endif \ No newline at end of file
diff --git a/backends/platform/psp/thread.cpp b/backends/platform/psp/thread.cpp
index 43e3b931c3..c19ff5f9e3 100644
--- a/backends/platform/psp/thread.cpp
+++ b/backends/platform/psp/thread.cpp
@@ -23,9 +23,6 @@
*
*/
-#include <time.h>
-#include <psptypes.h>
-#include <psprtc.h>
#include <pspthreadman.h>
#include "backends/platform/psp/thread.h"
@@ -192,57 +189,3 @@ void PspCondition::wait(PspMutex &externalMutex) {
externalMutex.lock(); // must lock external mutex here for continuation
}
-//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */
-//#define __PSP_DEBUG_PRINT__ /* For debug printouts */
-
-#include "backends/platform/psp/trace.h"
-
-
-// Class PspRtc ---------------------------------------------------------------
-
-void PspRtc::init() { // init our starting ticks
- uint32 ticks[2];
- sceRtcGetCurrentTick((u64 *)ticks);
-
- _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 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 bd7a60b6ed..27d53903d6 100644
--- a/backends/platform/psp/thread.h
+++ b/backends/platform/psp/thread.h
@@ -73,22 +73,7 @@ public:
PspCondition() : _mutex(true), _waitingThreads(0), _signaledThreads(0),
_waitSem(0), _doneSem(0) {}
void wait(PspMutex &externalMutex);
- void releaseAll();
-};
-
-
-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();
+ void releaseAll();
};
enum ThreadPriority {