X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fdos%2Ftimer.c;h=5492f0b654242fd454dc4ed9ffd9680548bb0350;hb=HEAD;hp=f42fac695b075ad3d6da96994efccb1d08211dba;hpb=0165ec15f868a16a70b56ada2d42db0cb69ea193;p=dosdemo diff --git a/src/dos/timer.c b/src/dos/timer.c index f42fac6..5492f0b 100644 --- a/src/dos/timer.c +++ b/src/dos/timer.c @@ -1,3 +1,8 @@ +/* for sound we use MIDAS, which takes over the PIT and we can't use it + * therefore only compile this file for NO_SOUND builds. + */ +#ifdef NO_SOUND + #include #include #include @@ -9,13 +14,15 @@ #endif #ifdef __DJGPP__ -#include #include #include #include #endif #include "pit8254.h" +#include "inttypes.h" +#include "util.h" +#include "dosutil.h" #define PIT_TIMER_INTR 8 #define DOS_TIMER_INTR 0x1c @@ -39,13 +46,11 @@ static void (INTERRUPT *prev_timer_intr)(); #define INTERRUPT static _go32_dpmi_seginfo intr, prev_intr; - -#define outp(p, v) outportb(p, v) #endif static void INTERRUPT timer_irq(); -static unsigned long ticks; +static volatile unsigned long ticks; static unsigned long tick_interval, ticks_per_dos_intr; static int inum; @@ -123,6 +128,16 @@ unsigned long get_msec(void) return ticks * tick_interval; } +void sleep_msec(unsigned long msec) +{ + unsigned long wakeup_time = ticks + msec / tick_interval; + while(ticks < wakeup_time) { +#ifdef USE_HLT + halt(); +#endif + } +} + static void set_timer_reload(int reload_val) { outp(PORT_CMD, CMD_CHAN0 | CMD_ACCESS_BOTH | CMD_OP_SQWAVE); @@ -163,3 +178,5 @@ static void INTERRUPT timer_irq() /* send EOI to the PIC */ outp(PIC1_CMD, OCW2_EOI); } + +#endif /* NO_SOUND */