Notes on Timer

0. Programs here:
	tick1.asm

	See also:
		mouse/mse_int.asm: uses the realtime clock ticks
			with mouse interrupts.

1. Note on the 8253/8254 PIT (programmable interval timer),
	from helppc:

	Port 40h, 8253 Counter 0: time of day clock (normally mode 3)
	Port 41h, 8253 Counter 1: RAM refresh counter (normally mode 2)
	Port 42h, 8253 Counter 2: Cassette and Speaker functions
	Port 43h, 8253 Mod Control Regiser, data format:

	  bits 7,6:   counter select bits (+ 8254 read back command)	
			00=select counter 0
			01=select counter 1
			10=select counter 2
			11=read back command
	  bits 5,4:   read/write/latch format bits
			00=latch present counter value
			01=read/write of MSB only (MSB="Hi Byte")
			10=read/write of LSB only (LSB="Lo Byte")
			11=read/write LSB, followed by write of MSB
	  bits 3,2,1: counter mode bits
			000=mode 0, interrupt on terminal count;
				countdown, interrupt, then wait...
			001=mode 1, programmable one-shot:
				countdown with optional restart, etc.
			010=mode 2, rate generator; generate one pulse
				after 'count' CLK cycles, etc
			011=mode 3, square wave rate generator; generate
				one pulse after 'count' CLK cycles; 
				output remains high until 1/2 of the
				next countdown,...
			100=mode 4, software triggered strobe;
				countdown with output high until
				counter zero,...
			101=mode 5, hardward triggered strobe; countdown
				after triggering with output high
				until counter zero; at zero output goes
				low for one CLK period.
	  bit  0:     0=16 binary counter, 1=4 decade BCD counter


2. Sample Code (from helppc):

	Programming considerations:
		(1) load mode control reg
		(2) let bus settle (jmp $+2)
			(Note: $ is the current location value
			in current segment)
		(3) write counter value
		(4) if counter 0 is modified, an INT 8 handler must
			be written to call the original INT 8 handler
			every 18.2 seconds.  Etc.
	HERE IS A SAMPLE:

	*********************************************************

	countdown equ 8000h	; approx. 36 interrupts/sec
	
	cli
	mov al,00110110b	; bit 7,6=(00), sel timer counter 0
				; bit 5,4=(11), write LSB then MSB
				; bit 3-1=(011), generate square wave
				; bit 0=(0) binary counter
	out 43h,al		; prep PIT, counter 0, square wave
				; & init count
	jmp $+2
	mov cx,countdown	; default is 0x0000 (65536), 18.2/sec
				; interrupts when counter decrements to 0
	mov al,cl		; send LSB of timer count
	out 40h,al
	jmp $+2
	mov al,ch		; send MSB
	out 40h,al
	jmp $+2
	sti

	*********************************************************
