1 |
/* |
2 |
* timer_amiga.cpp - Time Manager emulation, AmigaOS specific stuff |
3 |
* |
4 |
* Basilisk II (C) 1997-2008 Christian Bauer |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#include <exec/types.h> |
22 |
#include <devices/timer.h> |
23 |
#define __USE_SYSBASE |
24 |
#include <proto/timer.h> |
25 |
#include <proto/intuition.h> |
26 |
#include <inline/timer.h> |
27 |
#include <inline/intuition.h> |
28 |
|
29 |
#include "sysdeps.h" |
30 |
#include "timer.h" |
31 |
|
32 |
#define DEBUG 0 |
33 |
#include "debug.h" |
34 |
|
35 |
|
36 |
/* |
37 |
* Return microseconds since boot (64 bit) |
38 |
*/ |
39 |
|
40 |
void Microseconds(uint32 &hi, uint32 &lo) |
41 |
{ |
42 |
D(bug("Microseconds\n")); |
43 |
struct timeval tv; |
44 |
GetSysTime(&tv); |
45 |
uint64 tl = (uint64)tv.tv_secs * 1000000 + tv.tv_micro; |
46 |
hi = tl >> 32; |
47 |
lo = tl; |
48 |
} |
49 |
|
50 |
|
51 |
/* |
52 |
* Return local date/time in Mac format (seconds since 1.1.1904) |
53 |
*/ |
54 |
|
55 |
uint32 TimerDateTime(void) |
56 |
{ |
57 |
ULONG secs, mics; |
58 |
CurrentTime(&secs, &mics); |
59 |
return secs + 0x8b31ef80; |
60 |
} |
61 |
|
62 |
|
63 |
/* |
64 |
* Get current time |
65 |
*/ |
66 |
|
67 |
void timer_current_time(tm_time_t &t) |
68 |
{ |
69 |
GetSysTime(&t); |
70 |
} |
71 |
|
72 |
|
73 |
/* |
74 |
* Add times |
75 |
*/ |
76 |
|
77 |
void timer_add_time(tm_time_t &res, tm_time_t a, tm_time_t b) |
78 |
{ |
79 |
res = a; |
80 |
AddTime(&res, &b); |
81 |
} |
82 |
|
83 |
|
84 |
/* |
85 |
* Subtract times |
86 |
*/ |
87 |
|
88 |
void timer_sub_time(tm_time_t &res, tm_time_t a, tm_time_t b) |
89 |
{ |
90 |
res = a; |
91 |
SubTime(&res, &b); |
92 |
} |
93 |
|
94 |
|
95 |
/* |
96 |
* Compare times (<0: a < b, =0: a = b, >0: a > b) |
97 |
*/ |
98 |
|
99 |
int timer_cmp_time(tm_time_t a, tm_time_t b) |
100 |
{ |
101 |
return CmpTime(&b, &a); |
102 |
} |
103 |
|
104 |
|
105 |
/* |
106 |
* Convert Mac time value (>0: microseconds, <0: microseconds) to tm_time_t |
107 |
*/ |
108 |
|
109 |
void timer_mac2host_time(tm_time_t &res, int32 mactime) |
110 |
{ |
111 |
if (mactime > 0) { |
112 |
res.tv_secs = mactime / 1000; // Time in milliseconds |
113 |
res.tv_micro = (mactime % 1000) * 1000; |
114 |
} else { |
115 |
res.tv_secs = -mactime / 1000000; // Time in negative microseconds |
116 |
res.tv_micro = -mactime % 1000000; |
117 |
} |
118 |
} |
119 |
|
120 |
|
121 |
/* |
122 |
* Convert positive tm_time_t to Mac time value (>0: microseconds, <0: microseconds) |
123 |
* A negative input value for hosttime results in a zero return value |
124 |
* As long as the microseconds value fits in 32 bit, it must not be converted to milliseconds! |
125 |
*/ |
126 |
|
127 |
int32 timer_host2mac_time(tm_time_t hosttime) |
128 |
{ |
129 |
if (hosttime.tv_secs < 0) |
130 |
return 0; |
131 |
else { |
132 |
uint64 t = (uint64)hosttime.tv_secs * 1000000 + hosttime.tv_micro; |
133 |
if (t > 0x7fffffff) |
134 |
return t / 1000; // Time in milliseconds |
135 |
else |
136 |
return -t; // Time in negative microseconds |
137 |
} |
138 |
} |
139 |
|
140 |
|
141 |
/* |
142 |
* Suspend emulator thread, virtual CPU in idle mode |
143 |
*/ |
144 |
|
145 |
void idle_wait(void) |
146 |
{ |
147 |
// XXX if you implement this make sure to call idle_resume() from TriggerInterrupt() |
148 |
} |
149 |
|
150 |
|
151 |
/* |
152 |
* Resume execution of emulator thread, events just arrived |
153 |
*/ |
154 |
|
155 |
void idle_resume(void) |
156 |
{ |
157 |
} |