]> icculus.org git repositories - btb/d2x.git/blob - include/timer.h
remove rcs tags
[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 /*
15  *
16  * Header for timer functions
17  *
18  */
19
20
21 #ifndef _TIMER_H
22 #define _TIMER_H
23
24 #include "pstypes.h"
25 #include "fix.h"
26
27 //==========================================================================
28 // This installs the timer services and interrupts at the rate specified by
29 // count_val.  If 'function' isn't 0, the function pointed to by function will
30 // be called 'freq' times per second.  Should be > 19 and anything around
31 // 2-3000 is gonna start slowing down the system.  Count_val should be
32 // 1,193,180 divided by your target frequency. Use 0 for the normal 18.2 Hz
33 // interrupt rate.
34
35 #define TIMER_FREQUENCY 1193180
36 #define _far
37 #define __far
38 #define __interrupt
39
40 extern void timer_init();
41 extern void timer_close();
42 extern void timer_set_rate(int count_val);
43 extern void timer_set_function( void _far * function );
44
45 //==========================================================================
46 // These functions return the time since the timer was initialized in
47 // some various units. The total length of reading time varies for each
48 // one.  They will roll around after they read 2^32.
49 // There are milliseconds, milliseconds times 10, milliseconds times 100,
50 // and microseconds.  They time out after 1000 hrs, 100 hrs, 10 hrs, and
51 // 1 hr, respectively.
52
53 extern fix timer_get_fixed_seconds();   // Rolls about every 9 hours...
54 #ifdef __DJGPP__
55 extern fix timer_get_fixed_secondsX(); // Assume interrupts already disabled
56 extern fix timer_get_approx_seconds();          // Returns time since program started... accurate to 1/120th of a second
57 extern void timer_set_joyhandler( void (*joy_handler)() );
58 #else
59 #define timer_get_fixed_secondsX timer_get_fixed_seconds
60 //#define timer_get_approx_seconds timer_get_fixed_seconds
61 extern fix timer_get_approx_seconds();
62 #endif
63
64 //NOT_USED extern unsigned int timer_get_microseconds();
65 //NOT_USED extern unsigned int timer_get_milliseconds100();
66 //NOT_USED extern unsigned int timer_get_milliseconds10();
67 //NOT_USED extern unsigned int timer_get_milliseconds();
68 //NOT_USED extern unsigned int timer_get_millisecondsX();       // Assume interrupts disabled
69
70 void timer_delay(fix seconds);
71
72 //==========================================================================
73 // Use to access the BIOS ticker... ie...   i = TICKER
74 #ifndef __DJGPP__
75 #define TICKER (timer_get_fixed_seconds())
76 #endif
77
78 #ifdef __DJGPP__
79
80 #ifndef __GNUC__
81 #define TICKER (*(volatile int *)0x46C)
82 #else
83 #include <go32.h>
84 #include <sys/farptr.h>
85 #define TICKER _farpeekl(_dos_ds, 0x46c)
86 #endif
87 #define USECS_PER_READING( start, stop, frames ) (((stop-start)*54945)/frames)
88 #endif
89
90
91 #define approx_usec_to_fsec(usec) ((usec) >> 4)
92 #define approx_fsec_to_usec(fsec) ((fsec) << 4)
93 #define approx_msec_to_fsec(msec) ((msec) << 6)
94 #define approx_fsec_to_msec(fsec) ((fsec) >> 6)
95
96 #endif