From 055c294ac01f7cff8dcb2223ef0b7e113918b381 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 29 Jan 2019 22:00:55 +0100 Subject: [PATCH] Use Timer2 for mouse polling. 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 | 2 +- libsrc/atari/mou/atrst.s | 74 +++++++++++++------------- libsrc/atari/mouseref.s | 4 +- libsrc/atari/shadow_ram_timerirq2.s | 81 +++++++++++++++++++++++++++++ testcode/lib/mouse-test.c | 2 +- 5 files changed, 122 insertions(+), 41 deletions(-) create mode 100644 libsrc/atari/shadow_ram_timerirq2.s diff --git a/asminc/mouse-kernel.inc b/asminc/mouse-kernel.inc index 3eebca244..ab4790d1d 100644 --- a/asminc/mouse-kernel.inc +++ b/asminc/mouse-kernel.inc @@ -103,7 +103,7 @@ ;------------------------------------------------------------------------------ ; 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. diff --git a/libsrc/atari/mou/atrst.s b/libsrc/atari/mou/atrst.s index f8ba24551..5d8a5cd12 100644 --- a/libsrc/atari/mou/atrst.s +++ b/libsrc/atari/mou/atrst.s @@ -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 - jsr set_VTIMR1_handler + lda #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+1 + 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 diff --git a/libsrc/atari/mouseref.s b/libsrc/atari/mouseref.s index b75df93d1..ac99d36fa 100644 --- a/libsrc/atari/mouseref.s +++ b/libsrc/atari/mouseref.s @@ -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 index 000000000..b2cdaecd2 --- /dev/null +++ b/libsrc/atari/shadow_ram_timerirq2.s @@ -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 + 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__ diff --git a/testcode/lib/mouse-test.c b/testcode/lib/mouse-test.c index 2e316c4c6..ea8311d19 100644 --- a/testcode/lib/mouse-test.c +++ b/testcode/lib/mouse-test.c @@ -7,7 +7,7 @@ ** ** Compile with "-DSTATIC_MOUSE" to statically link all available drivers. ** Compile with "-DMOUSE_DRIVER=" 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. */ -- 2.39.5