1 |
/* |
2 |
* timer_amiga.cpp - Time Manager emulation, AmigaOS specific stuff |
3 |
* |
4 |
* Basilisk II (C) 1997-2002 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 |
#include <proto/timer.h> |
24 |
#include <proto/intuition.h> |
25 |
|
26 |
#include "sysdeps.h" |
27 |
#include "timer.h" |
28 |
|
29 |
#define DEBUG 0 |
30 |
#include "debug.h" |
31 |
|
32 |
|
33 |
/* |
34 |
* Return microseconds since boot (64 bit) |
35 |
*/ |
36 |
|
37 |
void Microseconds(uint32 &hi, uint32 &lo) |
38 |
{ |
39 |
D(bug("Microseconds\n")); |
40 |
struct timeval tv; |
41 |
GetSysTime(&tv); |
42 |
uint64 tl = (uint64)tv.tv_secs * 1000000 + tv.tv_micro; |
43 |
hi = tl >> 32; |
44 |
lo = tl; |
45 |
} |
46 |
|
47 |
|
48 |
/* |
49 |
* Return local date/time in Mac format (seconds since 1.1.1904) |
50 |
*/ |
51 |
|
52 |
uint32 TimerDateTime(void) |
53 |
{ |
54 |
ULONG secs, mics; |
55 |
CurrentTime(&secs, &mics); |
56 |
return secs + 0x8b31ef80; |
57 |
} |
58 |
|
59 |
|
60 |
/* |
61 |
* Get current time |
62 |
*/ |
63 |
|
64 |
void timer_current_time(tm_time_t &t) |
65 |
{ |
66 |
GetSysTime(&t); |
67 |
} |
68 |
|
69 |
|
70 |
/* |
71 |
* Add times |
72 |
*/ |
73 |
|
74 |
void timer_add_time(tm_time_t &res, tm_time_t a, tm_time_t b) |
75 |
{ |
76 |
res = a; |
77 |
AddTime(&res, &b); |
78 |
} |
79 |
|
80 |
|
81 |
/* |
82 |
* Subtract times |
83 |
*/ |
84 |
|
85 |
void timer_sub_time(tm_time_t &res, tm_time_t a, tm_time_t b) |
86 |
{ |
87 |
res = a; |
88 |
SubTime(&res, &b); |
89 |
} |
90 |
|
91 |
|
92 |
/* |
93 |
* Compare times (<0: a < b, =0: a = b, >0: a > b) |
94 |
*/ |
95 |
|
96 |
int timer_cmp_time(tm_time_t a, tm_time_t b) |
97 |
{ |
98 |
return CmpTime(&b, &a); |
99 |
} |
100 |
|
101 |
|
102 |
/* |
103 |
* Convert Mac time value (>0: microseconds, <0: microseconds) to tm_time_t |
104 |
*/ |
105 |
|
106 |
void timer_mac2host_time(tm_time_t &res, int32 mactime) |
107 |
{ |
108 |
if (mactime > 0) { |
109 |
res.tv_secs = mactime / 1000; // Time in milliseconds |
110 |
res.tv_micro = (mactime % 1000) * 1000; |
111 |
} else { |
112 |
res.tv_secs = -mactime / 1000000; // Time in negative microseconds |
113 |
res.tv_micro = -mactime % 1000000; |
114 |
} |
115 |
} |
116 |
|
117 |
|
118 |
/* |
119 |
* Convert positive tm_time_t to Mac time value (>0: microseconds, <0: microseconds) |
120 |
* A negative input value for hosttime results in a zero return value |
121 |
* As long as the microseconds value fits in 32 bit, it must not be converted to milliseconds! |
122 |
*/ |
123 |
|
124 |
int32 timer_host2mac_time(tm_time_t hosttime) |
125 |
{ |
126 |
if (hosttime.tv_secs < 0) |
127 |
return 0; |
128 |
else { |
129 |
uint64 t = (uint64)hosttime.tv_secs * 1000000 + hosttime.tv_micro; |
130 |
if (t > 0x7fffffff) |
131 |
return t / 1000; // Time in milliseconds |
132 |
else |
133 |
return -t; // Time in negative microseconds |
134 |
} |
135 |
} |