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