;	Mini-Mouse driver for Jaguar
;	(table-driven)


.include	'jaguar.inc'
.include	'minnitbl.s'


	MS_MASK	equ	%00000000000000000000000000000011
	RECORD	equ	$20000


Setup:	move.l	#JOY1,a0	; address of controller port
	move.w	#$817e,(a0)	; initialize controller port (?)
	lea.l	Table,a2	; address of lookup table
	move.l	#RECORD,a4	; address of recording area

Begin:	move.l	(a0),d2		; get mouse status the first time
	rol.l	#2,d2		; make the bits useful
	and.l	#MS_MASK,d2	; mask off uninteresting bits

	
Check:	
	; Store old mouse status
	move.l	d2,d1		; store current mouse status as old

	; Get current mouse status and put it in useful form
	move.l	(a0),d2		; get current mouse status
	rol.l	#2,d2		; make the bits useful
	and.l	#MS_MASK,d2	; mask off uninteresting bits

	; Check mouse status again if it hasn't changed
	cmp.l	d2,d1		; has the mouse moved?
	beq	Check		; no, check again...

	; Mouse appears to have moved.
	; Construct the index into the mouse lookup table
Build:	move.l	d1,d3		; move old mouse status into index register
	lsl.l	#2,d3		; shift old status into position
	or.l	d2,d3		; copy in the current mouse status

	; Construct the pointer into the mouse lookup table
	move.l	a2,a3		; copy base pointer to lookup table
	add.l	d3,a3		; add index to base pointer, yields a pointer into the table

	; Get mouse result from table
Lookup:	move.b	(a3),d0		; look up how the mouse has moved from the table

	; Store mouse result in a memory transcript
Record:	move.b	d0,(a4)+	; store result and advance transcript pointer

	; Set up for next pass through the loop
	jmp	Check		; and check the mouse again
