Mercurial > projects > hoofbaby
comparison deps/Platinum/ThirdParty/Neptune/Source/System/PSP/NptPSPSystem.cpp @ 0:3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
author | fraserofthenight |
---|---|
date | Mon, 06 Jul 2009 08:06:28 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3425707ddbf6 |
---|---|
1 /***************************************************************** | |
2 | | |
3 | Neptune - System :: Win32 Implementation | |
4 | | |
5 | (c) 2001-2003 Gilles Boccon-Gibod | |
6 | Author: Gilles Boccon-Gibod (bok@bok.net) | |
7 | | |
8 ****************************************************************/ | |
9 | |
10 /*---------------------------------------------------------------------- | |
11 | includes | |
12 +---------------------------------------------------------------------*/ | |
13 #include <stdlib.h> | |
14 #include <stdio.h> | |
15 #include <psptypes.h> | |
16 #include <kernel.h> | |
17 #include <rtcsvc.h> | |
18 #include <pspnet/sys/time.h> | |
19 | |
20 #include "NptConfig.h" | |
21 #include "NptTypes.h" | |
22 #include "NptSystem.h" | |
23 #include "NptResults.h" | |
24 #include "NptDebug.h" | |
25 #include "NptConstants.h" | |
26 | |
27 /*---------------------------------------------------------------------- | |
28 | NPT_PSPSystem | |
29 +---------------------------------------------------------------------*/ | |
30 class NPT_PSPSystem : public NPT_SystemInterface | |
31 { | |
32 public: | |
33 // methods | |
34 NPT_PSPSystem(); | |
35 ~NPT_PSPSystem(); | |
36 NPT_Result GetProcessId(NPT_Integer& id); | |
37 NPT_Result GetCurrentTimeStamp(NPT_TimeStamp& now); | |
38 NPT_Result Sleep(NPT_UInt32 microseconds); | |
39 NPT_Result SetRandomSeed(unsigned int seed); | |
40 NPT_Integer GetRandomInteger(); | |
41 | |
42 private: | |
43 bool m_bRandomized; | |
44 }; | |
45 | |
46 /*---------------------------------------------------------------------- | |
47 | NPT_PSPSystem::NPT_PSPSystem | |
48 +---------------------------------------------------------------------*/ | |
49 NPT_PSPSystem::NPT_PSPSystem() | |
50 : m_bRandomized(false) | |
51 { | |
52 } | |
53 | |
54 /*---------------------------------------------------------------------- | |
55 | NPT_PSPSystem::~NPT_PSPSystem | |
56 +---------------------------------------------------------------------*/ | |
57 NPT_PSPSystem::~NPT_PSPSystem() | |
58 { | |
59 } | |
60 | |
61 /*---------------------------------------------------------------------- | |
62 | NPT_PSPSystem::GetProcessId | |
63 +---------------------------------------------------------------------*/ | |
64 NPT_Result | |
65 NPT_PSPSystem::GetProcessId(NPT_Integer& id) | |
66 { | |
67 //id = getpid(); | |
68 id = 0; | |
69 return NPT_SUCCESS; | |
70 } | |
71 | |
72 /*---------------------------------------------------------------------- | |
73 | NPT_PSPSystem::GetCurrentTimeStamp | |
74 +---------------------------------------------------------------------*/ | |
75 NPT_Result | |
76 NPT_PSPSystem::GetCurrentTimeStamp(NPT_TimeStamp& now) | |
77 { | |
78 // get the current time | |
79 ScePspDateTime clock; | |
80 sceRtcGetCurrentClock(&clock, 0); | |
81 | |
82 // converts to POSIX time to get the number of seconds since 1970 | |
83 time_t time; | |
84 sceRtcGetTime_t(&clock, &time); | |
85 | |
86 // converts back to Psp date, it should be truncated | |
87 // we'll use that to get the number of nanoseconds | |
88 ScePspDateTime clock_trunk; | |
89 sceRtcSetTime_t(&clock_trunk, time); | |
90 | |
91 //_ftime(&time_stamp); | |
92 now.m_Seconds = time; | |
93 now.m_NanoSeconds = (sceRtcGetMicrosecond(&clock)-sceRtcGetMicrosecond(&clock_trunk))*1000; | |
94 | |
95 return NPT_SUCCESS; | |
96 } | |
97 | |
98 /*---------------------------------------------------------------------- | |
99 | NPT_PSPSystem::Sleep | |
100 +---------------------------------------------------------------------*/ | |
101 NPT_Result | |
102 NPT_PSPSystem::Sleep(NPT_UInt32 microseconds) | |
103 { | |
104 sceKernelDelayThread(microseconds); | |
105 return NPT_SUCCESS; | |
106 } | |
107 | |
108 /*---------------------------------------------------------------------- | |
109 | NPT_PSPSystem::SetRandomSeed | |
110 +---------------------------------------------------------------------*/ | |
111 NPT_Result | |
112 NPT_PSPSystem::SetRandomSeed(unsigned int seed) | |
113 { | |
114 srand(seed); | |
115 return NPT_SUCCESS; | |
116 } | |
117 | |
118 /*---------------------------------------------------------------------- | |
119 | NPT_System::NPT_System | |
120 +---------------------------------------------------------------------*/ | |
121 NPT_Integer | |
122 NPT_PSPSystem::GetRandomInteger() | |
123 { | |
124 if (m_bRandomized == false) { | |
125 NPT_TimeStamp now; | |
126 GetCurrentTimeStamp(now); | |
127 SetRandomSeed( now.m_Seconds ); | |
128 m_bRandomized = true; | |
129 } | |
130 NPT_Integer val = 0; | |
131 val = rand(); | |
132 return val; | |
133 } | |
134 | |
135 /*---------------------------------------------------------------------- | |
136 | NPT_System::NPT_System | |
137 +---------------------------------------------------------------------*/ | |
138 NPT_System::NPT_System() | |
139 { | |
140 m_Delegate = new NPT_PSPSystem(); | |
141 } | |
142 |