]> git.sur5r.net Git - cc65/commitdiff
Use Timer2 for mouse polling.
authorChristian Groessler <chris@groessler.org>
Tue, 29 Jan 2019 21:00:55 +0000 (22:00 +0100)
committerChristian Groessler <chris@groessler.org>
Tue, 29 Jan 2019 21:00:55 +0000 (22:00 +0100)
This follows a suggestion by Sijmen Schouten in issue #818.
Platoterm64 now works with mouse at 1200 baud.

Bump MOUSE_API_VERSION in asminc/mouse-kernel.inc.

Fix typo in testcode/lib/mouse-test.c.

asminc/mouse-kernel.inc
libsrc/atari/mou/atrst.s
libsrc/atari/mouseref.s
libsrc/atari/shadow_ram_timerirq2.s [new file with mode: 0644]
testcode/lib/mouse-test.c

index 3eebca244d201cbb74a1783204ea1043dd96bf2a..ab4790d1dd6444c0930c3883979d2f019a21d0d7 100644 (file)
 ;------------------------------------------------------------------------------
 ; The mouse API version, stored in MOUSE_HDR::VERSION
 
-MOUSE_API_VERSION       = $05
+MOUSE_API_VERSION       = $06
 
 ;------------------------------------------------------------------------------
 ; Bitmapped mouse driver flags, stored in MOUSE_HDR::FLAGS.
index f8ba24551200207bae0b2adf09f3f64d16a0fbb6..5d8a5cd121d01f27745a16d8b6c1abcdfc62b8b9 100644 (file)
@@ -134,6 +134,7 @@ YPosWrk:        .res    2
 irq_enabled:    .res    1               ; flag indicating that the high frequency polling interrupt is enabled
 old_porta_vbi:  .res    1               ; previous PORTA value of the VBI interrupt (IRQ)
 how_long:       .res    1               ; counter for how many VBI interrupts the mouse hasn't been moved
+in_irq:         .res    1               ; flag indicating high-frequency polling interrupt is active
 
 .if .defined (AMIGA_MOUSE) .or .defined (ST_MOUSE)
 dumx:           .res    1
@@ -145,11 +146,11 @@ oldval:         .res    1
 .endif
 
 .ifndef __ATARIXL__
-OldT1:          .res    2
+OldT2:          .res    2
 .else
 
 .data
-set_VTIMR1_handler:
+set_VTIMR2_handler:
                 .byte   $4C, 0, 0
 .endif
 
@@ -226,29 +227,29 @@ INSTALL:
 
         ; Setup pointer to wrapper install/deinstall function.
         lda     libref
-        sta     set_VTIMR1_handler+1
+        sta     set_VTIMR2_handler+1
         lda     libref+1
-        sta     set_VTIMR1_handler+2
+        sta     set_VTIMR2_handler+2
 
         ; Install my handler.
         sec
-        lda     #<T1Han
-        ldx     #>T1Han
-        jsr     set_VTIMR1_handler
+        lda     #<T2Han
+        ldx     #>T2Han
+        jsr     set_VTIMR2_handler
 
 .else
 
-        lda     VTIMR1
-        sta     OldT1
-        lda     VTIMR1+1
-        sta     OldT1+1
+        lda     VTIMR2
+        sta     OldT2
+        lda     VTIMR2+1
+        sta     OldT2+1
 
         php
         sei
-        lda     #<T1Han
-        sta     VTIMR1
-        lda     #>T1Han
-        sta     VTIMR1+1
+        lda     #<T2Han
+        sta     VTIMR2
+        lda     #>T2Han
+        sta     VTIMR2+1
         plp
 
 .endif
@@ -257,20 +258,12 @@ INSTALL:
         sta     AUDCTL
 
         lda     #0
-        sta     AUDC1
+        sta     AUDC2
 
         lda     #15
-        sta     AUDF1
+        sta     AUDF2
         sta     STIMER
 
-.if 0   ; the IRQ will now be dynamically enabled when the mouse is moved
-        lda     POKMSK
-        ora     #%00000001              ; timer 1 enable
-        sta     POKMSK
-        sta     IRQEN
-        sta     irq_enabled
-.endif
-
         lda     PORTA
         and     #$0f
         sta     old_porta_vbi
@@ -290,23 +283,23 @@ UNINSTALL:
 ; uninstall timer irq routine
 
         lda     POKMSK
-        and     #%11111110              ; timer 1 disable
+        and     #%11111101              ; timer 2 disable
         sta     IRQEN
         sta     POKMSK
 
 .ifdef __ATARIXL__
 
         clc
-        jsr     set_VTIMR1_handler
+        jsr     set_VTIMR2_handler
 
 .else
 
         php
         sei
-        lda     OldT1
-        sta     VTIMR1
-        lda     OldT1+1
-        sta     VTIMR1+1
+        lda     OldT2
+        sta     VTIMR2
+        lda     OldT2+1
+        sta     VTIMR2+1
         plp
 
 .endif
@@ -503,7 +496,7 @@ IRQ:    lda     PORTA                   ; mouse port contents
 ; Turn mouse polling IRQ back on
 
         lda     POKMSK
-        ora     #%00000001              ; timer 1 enable
+        ora     #%00000010              ; timer 2 enable
         sta     POKMSK
         sta     IRQEN
         sta     irq_enabled
@@ -533,7 +526,7 @@ IRQ:    lda     PORTA                   ; mouse port contents
 
         sta     irq_enabled
         lda     POKMSK
-        and     #%11111110              ; timer 1 disable
+        and     #%11111101              ; timer 2 disable
         sta     IRQEN
         sta     POKMSK
 
@@ -620,13 +613,18 @@ IRQ:    lda     PORTA                   ; mouse port contents
 
 
 ;----------------------------------------------------------------------------
-; T1Han: Local IRQ routine to poll mouse
+; T2Han: Local IRQ routine to poll mouse
 ;
 
-T1Han:  lda     CRITIC                  ; if CRITIC flag is set, disable the
+T2Han:  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)
+                                        ; floppy access or serial I/O)
+
+        lda     in_irq                  ; handler entered again?
+        bne     skip                    ; yes, ignore this interrupt
+        inc     in_irq
+        cli                             ; enable IRQs so that we don't block them for too long
 
         tya
         pha
@@ -803,6 +801,8 @@ mmexit: sty     oldval
         tax
         pla
         tay
+        dec     in_irq
+skip:
 .ifdef  __ATARIXL__
         rts
 .else
@@ -819,7 +819,7 @@ mmexit: sty     oldval
 
 disable_me:
         lda     POKMSK
-        and     #%11111110              ; timer 1 disable
+        and     #%11111101              ; timer 2 disable
         sta     IRQEN
         sta     POKMSK
         lda     #0
index b75df93d1177065603d46787ed99e73f9d26417d..ac99d36fad2d2a006905ccae1cbd83e8698b4e72 100644 (file)
@@ -5,8 +5,8 @@
         .export         mouse_libref
 
 .ifdef __ATARIXL__
-        .import set_VTIMR1_handler
-mouse_libref    := set_VTIMR1_handler
+        .import set_VTIMR2_handler
+mouse_libref    := set_VTIMR2_handler
 .else
         .import _exit
 mouse_libref    := _exit
diff --git a/libsrc/atari/shadow_ram_timerirq2.s b/libsrc/atari/shadow_ram_timerirq2.s
new file mode 100644 (file)
index 0000000..b2cdaec
--- /dev/null
@@ -0,0 +1,81 @@
+;
+; Atari XL shadow RAM timer IRQ #2 handler
+;
+; Christian Groessler, chris@groessler.org, 2019
+;
+
+;DEBUG           =       1
+
+.ifdef __ATARIXL__
+
+SHRAM_HANDLERS  =       1
+                .include        "atari.inc"
+                .include        "romswitch.inc"
+                .export         set_VTIMR2_handler
+
+
+.segment "LOWBSS"
+
+VTIMR2_handler: .res    3
+
+
+.segment "BSS"
+
+old_VTIMR2_handler:
+                .res    2
+
+
+.segment "LOWCODE"
+
+; timer interrupt handler:
+; disable ROM, call user handler, enable ROM again
+
+my_VTIMR2_handler:
+                disable_rom_quick
+                jsr     VTIMR2_handler
+                enable_rom_quick
+                pla
+                rti
+
+.segment "CODE"
+
+; install or remove VTIMR2 handler
+; input: CF - 0/1 for remove/install handler
+;        AX - pointer to handler (if CF=1)
+; registers destroyed
+
+set_VTIMR2_handler:
+
+                bcc     @remove
+
+; install vector
+
+                stx     VTIMR2_handler+2
+                sta     VTIMR2_handler+1        ; save passed vector in low memory
+                lda     #$4C                    ; "JMP" opcode
+                sta     VTIMR2_handler
+
+                lda     VTIMR2
+                sta     old_VTIMR2_handler
+                lda     VTIMR2+1
+                sta     old_VTIMR2_handler+1
+
+                lda     #<my_VTIMR2_handler
+                php
+                sei
+                sta     VTIMR2
+                lda     #>my_VTIMR2_handler
+                sta     VTIMR2+1
+                plp
+                rts
+
+@remove:        php
+                sei
+                lda     old_VTIMR2_handler
+                sta     VTIMR2
+                lda     old_VTIMR2_handler+1
+                sta     VTIMR2+1
+                plp
+                rts
+
+.endif  ; .ifdef __ATARIXL__
index 2e316c4c6dceb5ca58ffb24ed3ed87e926868e51..ea8311d1925b1bc0e415530730c7c7cd74786674 100644 (file)
@@ -7,7 +7,7 @@
 **
 ** Compile with "-DSTATIC_MOUSE" to statically link all available drivers.
 ** Compile with "-DMOUSE_DRIVER=<driver_sym>" to statically link the given driver.
-**     E.g., -DMOUSE_DRIVER=atrsts_mou to just link with the Atari ST mouse driver.
+**     E.g., -DMOUSE_DRIVER=atrst_mou to just link with the Atari ST mouse driver.
 */