ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/AmigaOS/timer_amiga.cpp
Revision: 1.1.1.1 (vendor branch)
Committed: 1999-10-03T14:16:25Z (25 years, 1 month ago) by cebix
Branch: cebix
CVS Tags: release-0_7-2, start
Changes since 1.1: +0 -0 lines
Error occurred while calculating annotation data.
Log Message:
Imported sources

File Contents

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