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