ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/timer_beos.cpp
Revision: 1.13
Committed: 2006-04-30T21:26:21Z (18 years, 2 months ago) by gbeauche
Branch: MAIN
CVS Tags: nigel-build-19
Changes since 1.12: +16 -1 lines
Log Message:
Tentative fixes to BeOS idle suspend/resume routines. Well, I have no-op'ed
them. So, if someone has BeOS and wants to give it a try, please change and
test this new code. Corner case could be a resume_thread() when emul_thread
is not suspended.

Fixlet to powerrom_cpu: call idle_resume() from TriggerInterrupt().

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 // From main_beos.cpp
32 extern thread_id emul_thread;
33
34
35 /*
36 * Return microseconds since boot (64 bit)
37 */
38
39 void Microseconds(uint32 &hi, uint32 &lo)
40 {
41 D(bug("Microseconds\n"));
42 bigtime_t time = system_time();
43 hi = time >> 32;
44 lo = time;
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 return TimeToMacTime(time(NULL));
55 }
56
57
58 /*
59 * Get current time
60 */
61
62 void timer_current_time(tm_time_t &t)
63 {
64 t = system_time();
65 }
66
67
68 /*
69 * Add times
70 */
71
72 void timer_add_time(tm_time_t &res, tm_time_t a, tm_time_t b)
73 {
74 res = a + b;
75 }
76
77
78 /*
79 * Subtract times
80 */
81
82 void timer_sub_time(tm_time_t &res, tm_time_t a, tm_time_t b)
83 {
84 res = a - b;
85 }
86
87
88 /*
89 * Compare times (<0: a < b, =0: a = b, >0: a > b)
90 */
91
92 int timer_cmp_time(tm_time_t a, tm_time_t b)
93 {
94 tm_time_t r = a - b;
95 return r < 0 ? -1 : (r > 0 ? 1 : 0);
96 }
97
98
99 /*
100 * Convert Mac time value (>0: microseconds, <0: microseconds) to tm_time_t
101 */
102
103 void timer_mac2host_time(tm_time_t &res, int32 mactime)
104 {
105 if (mactime > 0)
106 res = mactime * 1000; // Time in milliseconds
107 else
108 res = -mactime; // Time in negative microseconds
109 }
110
111
112 /*
113 * Convert positive tm_time_t to Mac time value (>0: microseconds, <0: microseconds)
114 * A negative input value for hosttime results in a zero return value
115 * As long as the microseconds value fits in 32 bit, it must not be converted to milliseconds!
116 */
117
118 int32 timer_host2mac_time(tm_time_t hosttime)
119 {
120 if (hosttime < 0)
121 return 0;
122 else if (hosttime > 0x7fffffff)
123 return hosttime / 1000; // Time in milliseconds
124 else
125 return -hosttime; // Time in negative microseconds
126 }
127
128
129 /*
130 * Delay by specified number of microseconds (<1 second)
131 */
132
133 void Delay_usec(uint32 usec)
134 {
135 snooze(usec);
136 }
137
138
139 /*
140 * Suspend emulator thread, virtual CPU in idle mode
141 */
142
143 void idle_wait(void)
144 {
145 #if 0
146 /*
147 FIXME: add a semaphore (counter) to avoid a B_BAD_THREAD_STATE
148 return if we call idle_resume() when thread is not suspended?
149
150 Sorry, I can't test -- gb.
151 */
152 suspend_thread(emul_thread);
153 #endif
154 }
155
156
157 /*
158 * Resume execution of emulator thread, events just arrived
159 */
160
161 void idle_resume(void)
162 {
163 #if 0
164 resume_thread(emul_thread);
165 #endif
166 }