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
.endif
.ifndef __ATARIXL__
-OldT1: .res 2
+OldT2: .res 2
.else
.data
-set_VTIMR1_handler:
+set_VTIMR2_handler:
.byte $4C, 0, 0
.endif
; 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
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
; 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
; 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
sta irq_enabled
lda POKMSK
- and #%11111110 ; timer 1 disable
+ and #%11111101 ; timer 2 disable
sta IRQEN
sta POKMSK
;----------------------------------------------------------------------------
-; 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
tax
pla
tay
+ dec in_irq
+skip:
.ifdef __ATARIXL__
rts
.else
disable_me:
lda POKMSK
- and #%11111110 ; timer 1 disable
+ and #%11111101 ; timer 2 disable
sta IRQEN
sta POKMSK
lda #0
--- /dev/null
+;
+; 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__