deepstone

diff src/timer.c @ 21:00d84ab1ef26

switched to wacom
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Sep 2013 18:17:55 +0300
parents f04884489bad
children
line diff
     1.1 --- a/src/timer.c	Sat Sep 21 16:40:31 2013 +0300
     1.2 +++ b/src/timer.c	Sat Sep 21 18:17:55 2013 +0300
     1.3 @@ -17,7 +17,9 @@
     1.4  */
     1.5  #include <stdio.h>
     1.6  #include <stdlib.h>
     1.7 +#include <conio.h>
     1.8  #include <dos.h>
     1.9 +#include <i86.h>
    1.10  #include "pit8254.h"
    1.11  
    1.12  #define PIT_TIMER_INTR	8
    1.13 @@ -29,9 +31,10 @@
    1.14  
    1.15  static void set_timer_reload(int reload_val);
    1.16  static void cleanup(void);
    1.17 -static void interrupt dos_timer_intr();
    1.18 -static void interrupt timer_irq();
    1.19 -static void interrupt (*prev_timer_intr)();
    1.20 +static void __interrupt __far timer_irq();
    1.21 +static void __interrupt __far dos_timer_intr();
    1.22 +
    1.23 +static void (__interrupt __far *prev_timer_intr)();
    1.24  
    1.25  static unsigned long ticks;
    1.26  static unsigned long tick_interval, ticks_per_dos_intr;
    1.27 @@ -39,8 +42,8 @@
    1.28  
    1.29  void init_timer(int res_hz)
    1.30  {
    1.31 +	_disable();
    1.32  
    1.33 -	disable();
    1.34  	if(res_hz > 0) {
    1.35  		int reload_val = DIV_ROUND(OSC_FREQ_HZ, res_hz);
    1.36  		set_timer_reload(reload_val);
    1.37 @@ -49,16 +52,16 @@
    1.38  		ticks_per_dos_intr = DIV_ROUND(65535L, reload_val);
    1.39  
    1.40  		inum = PIT_TIMER_INTR;
    1.41 -		prev_timer_intr = getvect(inum);
    1.42 -		setvect(inum, timer_irq);
    1.43 +		prev_timer_intr = _dos_getvect(inum);
    1.44 +		_dos_setvect(inum, timer_irq);
    1.45  	} else {
    1.46  		tick_interval = 55;
    1.47  
    1.48  		inum = DOS_TIMER_INTR;
    1.49 -		prev_timer_intr = getvect(inum);
    1.50 -		setvect(inum, dos_timer_intr);
    1.51 +		prev_timer_intr = _dos_getvect(inum);
    1.52 +		_dos_setvect(inum, dos_timer_intr);
    1.53  	}
    1.54 -	enable();
    1.55 +	_enable();
    1.56  
    1.57  	atexit(cleanup);
    1.58  }
    1.59 @@ -69,15 +72,15 @@
    1.60  		return; /* init hasn't ran, there's nothing to cleanup */
    1.61  	}
    1.62  
    1.63 -	disable();
    1.64 +	_disable();
    1.65  	if(inum == PIT_TIMER_INTR) {
    1.66  		/* restore the original timer frequency */
    1.67  		set_timer_reload(65535);
    1.68  	}
    1.69  
    1.70  	/* restore the original interrupt handler */
    1.71 -	setvect(inum, prev_timer_intr);
    1.72 -	enable();
    1.73 +	_dos_setvect(inum, prev_timer_intr);
    1.74 +	_enable();
    1.75  }
    1.76  
    1.77  void reset_timer(void)
    1.78 @@ -92,15 +95,15 @@
    1.79  
    1.80  static void set_timer_reload(int reload_val)
    1.81  {
    1.82 -	outportb(PORT_CMD, CMD_CHAN0 | CMD_ACCESS_BOTH | CMD_OP_SQWAVE);
    1.83 -	outportb(PORT_DATA0, reload_val & 0xff);
    1.84 -	outportb(PORT_DATA0, (reload_val >> 8) & 0xff);
    1.85 +	outp(PORT_CMD, CMD_CHAN0 | CMD_ACCESS_BOTH | CMD_OP_SQWAVE);
    1.86 +	outp(PORT_DATA0, reload_val & 0xff);
    1.87 +	outp(PORT_DATA0, (reload_val >> 8) & 0xff);
    1.88  }
    1.89  
    1.90 -static void interrupt dos_timer_intr()
    1.91 +static void __interrupt __far dos_timer_intr()
    1.92  {
    1.93  	ticks++;
    1.94 -	prev_timer_intr();
    1.95 +	_chain_intr(prev_timer_intr);	/* DOES NOT RETURN */
    1.96  }
    1.97  
    1.98  /* first PIC command port */
    1.99 @@ -108,7 +111,7 @@
   1.100  /* end of interrupt control word */
   1.101  #define OCW2_EOI	(1 << 5)
   1.102  
   1.103 -static void interrupt timer_irq()
   1.104 +static void __interrupt __far timer_irq()
   1.105  {
   1.106  	static unsigned long dos_ticks;
   1.107  
   1.108 @@ -118,10 +121,11 @@
   1.109  		/* I suppose the dos irq handler does the EOI so I shouldn't
   1.110  		 * do it if I am to call the previous function
   1.111  		 */
   1.112 -		prev_timer_intr();
   1.113  		dos_ticks = 0;
   1.114 -	} else {
   1.115 -		/* send EOI to the PIC */
   1.116 -		outportb(PIC1_CMD, OCW2_EOI);
   1.117 +		_chain_intr(prev_timer_intr);	/* XXX DOES NOT RETURN */
   1.118 +		return;	/* just for clarity */
   1.119  	}
   1.120 +
   1.121 +	/* send EOI to the PIC */
   1.122 +	outp(PIC1_CMD, OCW2_EOI);
   1.123  }