ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/AmigaOS/timer_amiga.cpp
Revision: 1.2
Committed: 1999-10-19T17:41:24Z (24 years, 8 months ago) by cebix
Branch: MAIN
CVS Tags: snapshot-21101999
Changes since 1.1: +0 -2 lines
Log Message:
- added external file system
- moved most init/deinit code to InitAll()/ExitAll() in main.cpp

File Contents

# User Rev Content
1 cebix 1.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     uint32 TimerDateTime(void)
56     {
57     ULONG secs;
58     ULONG mics;
59     CurrentTime(&secs, &mics);
60     return secs + TIME_OFFSET;
61     }
62    
63    
64     /*
65     * Get current time
66     */
67    
68     void timer_current_time(tm_time_t &t)
69     {
70     GetSysTime(&t);
71     }
72    
73    
74     /*
75     * Add times
76     */
77    
78     void timer_add_time(tm_time_t &res, tm_time_t a, tm_time_t b)
79     {
80     res = a;
81     AddTime(&res, &b);
82     }
83    
84    
85     /*
86     * Subtract times
87     */
88    
89     void timer_sub_time(tm_time_t &res, tm_time_t a, tm_time_t b)
90     {
91     res = a;
92     SubTime(&res, &b);
93     }
94    
95    
96     /*
97     * Compare times (<0: a < b, =0: a = b, >0: a > b)
98     */
99    
100     int timer_cmp_time(tm_time_t a, tm_time_t b)
101     {
102     return CmpTime(&b, &a);
103     }
104    
105    
106     /*
107     * Convert Mac time value (>0: microseconds, <0: microseconds) to tm_time_t
108     */
109    
110     void timer_mac2host_time(tm_time_t &res, int32 mactime)
111     {
112     if (mactime > 0) {
113     res.tv_secs = mactime / 1000; // Time in milliseconds
114     res.tv_micro = (mactime % 1000) * 1000;
115     } else {
116     res.tv_secs = -mactime / 1000000; // Time in negative microseconds
117     res.tv_micro = -mactime % 1000000;
118     }
119     }
120    
121    
122     /*
123     * Convert positive tm_time_t to Mac time value (>0: microseconds, <0: microseconds)
124     * A negative input value for hosttime results in a zero return value
125     * As long as the microseconds value fits in 32 bit, it must not be converted to milliseconds!
126     */
127    
128     int32 timer_host2mac_time(tm_time_t hosttime)
129     {
130     if (hosttime.tv_secs < 0)
131     return 0;
132     else
133     return TimevalToMacTime(&hosttime);
134     }