; Library reference
- .addr $0000
+libref: .addr $0000
; Jump table
CHIDE: jmp $0000 ; Hide the cursor
CSHOW: jmp $0000 ; Show the cursor
+CPREP: jmp $0000 ; Prepare to move the cursor
+CDRAW: jmp $0000 ; Draw the cursor
CMOVEX: jmp $0000 ; Move the cursor to X coord
CMOVEY: jmp $0000 ; Move the cursor to Y coord
XPosWrk: .res 2
YPosWrk: .res 2
-OldT1: .res 2
-visible: .res 1
-
.if .defined (AMIGA_MOUSE) .or .defined (ST_MOUSE)
dumx: .res 1
dumy: .res 1
oldval: .res 1
.endif
+.ifndef __ATARIXL__
+OldT1: .res 2
+.else
-; Default values for some of the above variables
+.data
+set_VTIMR1_handler:
+ .byte $4C, 0, 0
+.endif
.rodata
+; Default values for some of the above variables
; (We use ".proc" because we want to define both a label and a scope.)
.proc DefVars
dex
bpl @L1
-; Be sure the mouse cursor is invisible and at the default location. We
-; need to do that here, because our mouse interrupt handler doesn't set the
-; mouse position if it hasn't changed.
+; Make sure the mouse cursor is at the default location.
- sei
- jsr CHIDE
lda XPos
sta XPosWrk
ldx XPos+1
ldx YPos+1
stx YPosWrk+1
jsr CMOVEY
- cli
-; install timer irq routine to poll mouse
+; Install timer irq routine to poll mouse.
+
+.ifdef __ATARIXL__
+
+ ; Setup pointer to wrapper install/deinstall function.
+ lda libref
+ sta set_VTIMR1_handler+1
+ lda libref+1
+ sta set_VTIMR1_handler+2
+
+ ; Install my handler.
+ sec
+ lda #<T1Han
+ ldx #>T1Han
+ jsr set_VTIMR1_handler
+
+.else
lda VTIMR1
sta OldT1
sta VTIMR1+1
plp
+.endif
+
lda #%00000001
sta AUDCTL
sta IRQEN
sta POKMSK
+.ifdef __ATARIXL__
+
+ clc
+ jsr set_VTIMR1_handler
+
+.else
+
php
sei
lda OldT1
sta VTIMR1+1
plp
+.endif
; fall thru...
;----------------------------------------------------------------------------
; no special action is required besides hiding the mouse cursor.
; No return code required.
-HIDE: dec visible
- php
+HIDE: php
sei
jsr CHIDE
plp
; no special action is required besides enabling the mouse cursor.
; No return code required.
-SHOW: inc visible
- php
+SHOW: php
sei
jsr CSHOW
plp
pha
txa
pha
-
- lda visible
- beq @L01
-
- jsr CHIDE
-
-@L01: pla
+ jsr CPREP
+ pla
tax
pla
lda (sp),y
sta XPos ; New X position
sta XPosWrk
-
jsr CMOVEX ; Move the cursor
- lda visible
- beq @Ret
-
- jsr CSHOW
+ jsr CDRAW
-@Ret: plp ; Restore interrupt flag
+ plp ; Restore interrupt flag
rts
;----------------------------------------------------------------------------
IRQ:
+; Turn mouse polling IRQ back on in case it disabled itself due to CRITIC
+; flag being set.
+
+ lda POKMSK
+ ora #%00000001 ; timer 1 enable
+ sta POKMSK
+ sta IRQEN
+
; Check for a pressed button and place the result into Buttons
ldx #0
ldx #MOUSE_BTN_LEFT
@L0: stx Buttons
-; Update coordinates if needed
-
- lda XPosWrk
- cmp XPos
- bne @Update
- lda XPosWrk+1
- cmp XPos+1
- bne @Update
- lda YPosWrk
- cmp YPos
- bne @Update
- lda YPosWrk+1
- cmp YPos+1
- beq @Done
-
-@Update:ldx visible
- beq @L1
- jsr CHIDE
+ jsr CPREP
; Limit the X coordinate to the bounding box
-@L1: lda XPosWrk+1
+ lda XPosWrk+1
ldy XPosWrk
tax
cpy XMin
tya
jsr CMOVEY
- ldx visible
- beq @Done
+ jsr CDRAW
- jsr CSHOW
-
-@Done: clc
+ clc
rts
+
;----------------------------------------------------------------------------
; T1Han: Local IRQ routine to poll mouse
;
-T1Han: tya
+T1Han: lda CRITIC ; if CRITIC flag is set, disable the
+ bne disable_me ; high frequency polling IRQ, in order
+ ; not to interfere with SIO I/O (e.g.
+ ; floppy access)
+
+ tya
pha
txa
- pha
+ pha
.ifdef DEBUG
lda RANDOM
tax
pla
tay
+.ifdef __ATARIXL__
+ rts
+.else
pla
rti
+.endif
+
+; Disable the interrupt source which caused us to be called.
+; The interrupt will be enabled again by the "IRQ" routine.
+; The "IRQ" routine, despite its name, is called from the
+; vertical blank NMI interrupt *only* if the CRITIC flag has
+; been cleared.
+
+disable_me:
+ lda POKMSK
+ and #%11111110 ; timer 1 disable
+ sta IRQEN
+ sta POKMSK
+.ifdef __ATARIXL__
+ rts
+.else
+ pla
+ rti
+.endif