ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/timer_beos.cpp
Revision: 1.12
Committed: 2005-06-30T10:20:18Z (19 years ago) by gbeauche
Branch: MAIN
CVS Tags: nigel-build-17
Changes since 1.11: +19 -0 lines
Log Message:
Add system-specific implementations of idle_{wait,resume} functions.

File Contents

# Content
1 /*
2 * timer_beos.cpp - Time Manager emulation, BeOS specific stuff
3 *
4 * Basilisk II (C) 1997-2005 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 <KernelKit.h>
22
23 #include "sysdeps.h"
24 #include "macos_util.h"
25 #include "timer.h"
26
27 #define DEBUG 0
28 #include "debug.h"
29
30
31 /*
32 * Return microseconds since boot (64 bit)
33 */
34
35 void Microseconds(uint32 &hi, uint32 &lo)
36 {
37 D(bug("Microseconds\n"));
38 bigtime_t time = system_time();
39 hi = time >> 32;
40 lo = time;
41 }
42
43
44 /*
45 * Return local date/time in Mac format (seconds since 1.1.1904)
46 */
47
48 uint32 TimerDateTime(void)
49 {
50 return TimeToMacTime(time(NULL));
51 }
52
53
54 /*
55 * Get current time
56 */
57
58 void timer_current_time(tm_time_t &t)
59 {
60 t = system_time();
61 }
62
63
64 /*
65 * Add times
66 */
67
68 void timer_add_time(tm_time_t &res, tm_time_t a, tm_time_t b)
69 {
70 res = a + b;
71 }
72
73
74 /*
75 * Subtract times
76 */
77
78 void timer_sub_time(tm_time_t &res, tm_time_t a, tm_time_t b)
79 {
80 res = a - b;
81 }
82
83
84 /*
85 * Compare times (<0: a < b, =0: a = b, >0: a > b)
86 */
87
88 int timer_cmp_time(tm_time_t a, tm_time_t b)
89 {
90 tm_time_t r = a - b;
91 return r < 0 ? -1 : (r > 0 ? 1 : 0);
92 }
93
94
95 /*
96 * Convert Mac time value (>0: microseconds, <0: microseconds) to tm_time_t
97 */
98
99 void timer_mac2host_time(tm_time_t &res, int32 mactime)
100 {
101 if (mactime > 0)
102 res = mactime * 1000; // Time in milliseconds
103 else
104 res = -mactime; // Time in negative microseconds
105 }
106
107
108 /*
109 * Convert positive tm_time_t to Mac time value (>0: microseconds, <0: microseconds)
110 * A negative input value for hosttime results in a zero return value
111 * As long as the microseconds value fits in 32 bit, it must not be converted to milliseconds!
112 */
113
114 int32 timer_host2mac_time(tm_time_t hosttime)
115 {
116 if (hosttime < 0)
117 return 0;
118 else if (hosttime > 0x7fffffff)
119 return hosttime / 1000; // Time in milliseconds
120 else
121 return -hosttime; // Time in negative microseconds
122 }
123
124
125 /*
126 * Delay by specified number of microseconds (<1 second)
127 */
128
129 void Delay_usec(uint32 usec)
130 {
131 snooze(usec);
132 }
133
134
135 /*
136 * Suspend emulator thread, virtual CPU in idle mode
137 */
138
139 void idle_wait(void)
140 {
141 sleep(16667);
142 }
143
144
145 /*
146 * Resume execution of emulator thread, events just arrived
147 */
148
149 void idle_resume(void)
150 {
151 }