]> icculus.org git repositories - btb/d2x.git/blob - include/timer.h
implemented cfile wrappers for writing and other modes besides "rb" (mostly taken...
[btb/d2x.git] / include / timer.h
1 /* $Id: timer.h,v 1.5 2003-02-21 04:08:48 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Header for timer functions
18  *
19  * Old Log:
20  * Revision 1.8  1994/12/10  12:27:23  john
21  * Added timer_get_approx_seconds.
22  *
23  * Revision 1.7  1994/12/10  12:10:25  john
24  * Added types.h.
25  *
26  * Revision 1.6  1994/12/10  12:07:06  john
27  * Added tick counter variable.
28  *
29  * Revision 1.5  1994/11/15  12:04:15  john
30  * Cleaned up timer code a bit... took out unused functions
31  * like timer_get_milliseconds, etc.
32  *
33  * Revision 1.4  1994/04/28  23:50:08  john
34  * Changed calling for init_timer.  Made the function that the
35  * timer calls be a far function. All of this was done to make
36  * our timer system compatible with the HMI sound stuff.
37  *
38  * Revision 1.3  1994/02/17  15:57:12  john
39  * Changed key libary to C.
40  *
41  * Revision 1.2  1994/01/18  10:58:34  john
42  * Added timer_get_fixed_seconds
43  *
44  * Revision 1.1  1993/07/10  13:10:41  matt
45  * Initial revision
46  *
47  */
48
49
50 #ifndef _TIMER_H
51 #define _TIMER_H
52
53 #include "pstypes.h"
54 #include "fix.h"
55
56 //==========================================================================
57 // This installs the timer services and interrupts at the rate specified by
58 // count_val.  If 'function' isn't 0, the function pointed to by function will
59 // be called 'freq' times per second.  Should be > 19 and anything around
60 // 2-3000 is gonna start slowing down the system.  Count_val should be
61 // 1,193,180 divided by your target frequency. Use 0 for the normal 18.2 Hz
62 // interrupt rate.
63
64 #define TIMER_FREQUENCY 1193180
65 #define _far
66 #define __far
67 #define __interrupt
68
69 extern void timer_init();
70 extern void timer_close();
71 extern void timer_set_rate(int count_val);
72 extern void timer_set_function( void _far * function );
73
74 //==========================================================================
75 // These functions return the time since the timer was initialized in
76 // some various units. The total length of reading time varies for each
77 // one.  They will roll around after they read 2^32.
78 // There are milliseconds, milliseconds times 10, milliseconds times 100,
79 // and microseconds.  They time out after 1000 hrs, 100 hrs, 10 hrs, and
80 // 1 hr, respectively.
81
82 extern fix timer_get_fixed_seconds();   // Rolls about every 9 hours...
83 #ifdef __DJGPP__
84 extern fix timer_get_fixed_secondsX(); // Assume interrupts already disabled
85 extern fix timer_get_approx_seconds();          // Returns time since program started... accurate to 1/120th of a second
86 extern void timer_set_joyhandler( void (*joy_handler)() );
87 #else
88 #define timer_get_fixed_secondsX timer_get_fixed_seconds
89 //#define timer_get_approx_seconds timer_get_fixed_seconds
90 extern fix timer_get_approx_seconds();
91 #endif
92
93 //NOT_USED extern unsigned int timer_get_microseconds();
94 //NOT_USED extern unsigned int timer_get_milliseconds100();
95 //NOT_USED extern unsigned int timer_get_milliseconds10();
96 //NOT_USED extern unsigned int timer_get_milliseconds();
97 //NOT_USED extern unsigned int timer_get_millisecondsX();       // Assume interrupts disabled
98
99 void timer_delay(fix seconds);
100
101 //==========================================================================
102 // Use to access the BIOS ticker... ie...   i = TICKER
103 #ifndef __DJGPP__
104 #define TICKER (timer_get_fixed_seconds())
105 #endif
106
107 #ifdef __DJGPP__
108
109 #ifndef __GNUC__
110 #define TICKER (*(volatile int *)0x46C)
111 #else
112 #include <go32.h>
113 #include <sys/farptr.h>
114 #define TICKER _farpeekl(_dos_ds, 0x46c)
115 #endif
116 #define USECS_PER_READING( start, stop, frames ) (((stop-start)*54945)/frames)
117 #endif
118
119
120 #define approx_usec_to_fsec(usec) ((usec) >> 4)
121 #define approx_fsec_to_usec(fsec) ((fsec) << 4)
122 #define approx_msec_to_fsec(msec) ((msec) << 6)
123 #define approx_fsec_to_msec(fsec) ((fsec) >> 6)
124
125 #endif