]> git.sur5r.net Git - cc65/blobdiff - libsrc/atari/mou/atrst.s
Disable the high frequency mouse polling IRQ while the system does
[cc65] / libsrc / atari / mou / atrst.s
index 1e7e77b3a94fa5b6bf78790fcfe2998ada986e73..773e171e1edb4b24756e7010a11ef744facf9dd3 100644 (file)
@@ -35,7 +35,7 @@ HEADER:
 
 ; Library reference
 
-        .addr   $0000
+libref: .addr   $0000
 
 ; Jump table
 
@@ -60,6 +60,8 @@ HEADER:
 
 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
 
@@ -96,9 +98,6 @@ Buttons:        .res    1               ; Button mask
 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
@@ -108,11 +107,20 @@ 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
         .word   (SCREEN_HEIGHT+1)/2     ; YPos
         .word   (SCREEN_WIDTH+1)/2      ; XPos
@@ -162,12 +170,8 @@ INSTALL:
         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
@@ -178,9 +182,24 @@ INSTALL:
         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
@@ -195,6 +214,8 @@ INSTALL:
         sta     VTIMR1+1
         plp
 
+.endif
+
         lda     #%00000001
         sta     AUDCTL
 
@@ -229,6 +250,13 @@ UNINSTALL:
         sta     IRQEN
         sta     POKMSK
 
+.ifdef __ATARIXL__
+
+        clc
+        jsr     set_VTIMR1_handler
+
+.else
+
         php
         sei
         lda     OldT1
@@ -237,6 +265,7 @@ UNINSTALL:
         sta     VTIMR1+1
         plp
 
+.endif
         ; fall thru...
 
 ;----------------------------------------------------------------------------
@@ -246,8 +275,7 @@ UNINSTALL:
 ; no special action is required besides hiding the mouse cursor.
 ; No return code required.
 
-HIDE:   dec     visible
-        php
+HIDE:   php
         sei
         jsr     CHIDE
         plp
@@ -260,8 +288,7 @@ HIDE:   dec     visible
 ; no special action is required besides enabling the mouse cursor.
 ; No return code required.
 
-SHOW:   inc     visible
-        php
+SHOW:   php
         sei
         jsr     CSHOW
         plp
@@ -322,13 +349,8 @@ MOVE:   php
         pha
         txa
         pha
-
-        lda     visible
-        beq     @L01
-
-        jsr     CHIDE
-
-@L01:   pla
+        jsr     CPREP
+        pla
         tax
         pla
 
@@ -347,15 +369,11 @@ MOVE:   php
         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
 
 ;----------------------------------------------------------------------------
@@ -428,6 +446,14 @@ IOCTL:  lda     #<MOUSE_ERR_INV_IOCTL     ; We don't support ioclts for now
 
 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
@@ -436,28 +462,11 @@ IRQ:
         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
@@ -503,22 +512,25 @@ IRQ:
         tya
         jsr     CMOVEY
 
-        ldx     visible
-        beq     @Done
-
-        jsr     CSHOW
+        jsr     CDRAW
 
-@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
@@ -690,6 +702,28 @@ mmexit: sty     oldval
         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