From 77ba5b7e1c218b1294da14b8d9b1bb70337bfddb Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 14 Jan 2014 11:43:34 +0100 Subject: [PATCH] Fix timer IRQ hooking for atarixl target. --- libsrc/atari/libref.s | 4 +- libsrc/atari/mou/atrst.s | 49 ++++++++++++++--- libsrc/atari/shadow_ram_timerirq1.s | 81 +++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 libsrc/atari/shadow_ram_timerirq1.s diff --git a/libsrc/atari/libref.s b/libsrc/atari/libref.s index e6b9df6a5..4f7cbbef6 100644 --- a/libsrc/atari/libref.s +++ b/libsrc/atari/libref.s @@ -8,11 +8,13 @@ em_libref := _exit joy_libref := _exit -mouse_libref := _exit ser_libref := atari_ser_libref .ifdef __ATARIXL__ .import CIO_handler tgi_libref := CIO_handler + .import set_VTIMR1_handler +mouse_libref := set_VTIMR1_handler .else +mouse_libref := _exit tgi_libref := _exit .endif diff --git a/libsrc/atari/mou/atrst.s b/libsrc/atari/mou/atrst.s index 72808ad16..04580f31a 100644 --- a/libsrc/atari/mou/atrst.s +++ b/libsrc/atari/mou/atrst.s @@ -35,7 +35,7 @@ HEADER: ; Library reference - .addr $0000 +libref: .addr $0000 ; Jump table @@ -96,7 +96,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) @@ -108,11 +107,18 @@ 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 @@ -182,7 +188,23 @@ INSTALL: 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 + jsr set_VTIMR1_handler + +.else lda VTIMR1 sta OldT1 @@ -197,6 +219,8 @@ INSTALL: sta VTIMR1+1 plp +.endif + lda #%00000001 sta AUDCTL @@ -231,6 +255,13 @@ UNINSTALL: sta IRQEN sta POKMSK +.ifdef __ATARIXL__ + + clc + jsr set_VTIMR1_handler + +.else + php sei lda OldT1 @@ -239,6 +270,7 @@ UNINSTALL: sta VTIMR1+1 plp +.endif ; fall thru... ;---------------------------------------------------------------------------- @@ -354,7 +386,7 @@ MOVE: php lda visible beq @Ret - + jsr CSHOW @Ret: plp ; Restore interrupt flag @@ -520,7 +552,7 @@ IRQ: T1Han: tya pha txa - pha + pha .ifdef DEBUG lda RANDOM @@ -692,6 +724,9 @@ mmexit: sty oldval tax pla tay +.ifdef __ATARIXL__ + rts +.else pla rti - +.endif diff --git a/libsrc/atari/shadow_ram_timerirq1.s b/libsrc/atari/shadow_ram_timerirq1.s new file mode 100644 index 000000000..f8a3e9b4d --- /dev/null +++ b/libsrc/atari/shadow_ram_timerirq1.s @@ -0,0 +1,81 @@ +; +; Atari XL shadow RAM timer IRQ #1 handler +; +; Christian Groessler, chris@groessler.org, 2014 +; + +;DEBUG = 1 + +.ifdef __ATARIXL__ + +SHRAM_HANDLERS = 1 + .include "atari.inc" + .include "romswitch.inc" + .export set_VTIMR1_handler + + +.segment "LOWBSS" + +VTIMR1_handler: .res 3 + + +.segment "BSS" + +old_VTIMR1_handler: + .res 2 + + +.segment "LOWCODE" + +; timer interrupt handler: +; disable ROM, call user handler, enable ROM again + +my_VTIMR1_handler: + disable_rom_quick + jsr VTIMR1_handler + enable_rom_quick + pla + rti + +.segment "CODE" + +; install or remove VTIMR1 handler +; input: CF - 0/1 for remove/install handler +; AX - pointer to handler (if CF=1) +; registers destroyed + +set_VTIMR1_handler: + + bcc @remove + +; install vector + + stx VTIMR1_handler+2 + sta VTIMR1_handler+1 ; save passed vector in low memory + lda #$4C ; "JMP" opcode + sta VTIMR1_handler + + lda VTIMR1 + sta old_VTIMR1_handler + lda VTIMR1+1 + sta old_VTIMR1_handler+1 + + lda #my_VTIMR1_handler + sta VTIMR1+1 + plp + rts + +@remove: php + sei + lda old_VTIMR1_handler + sta VTIMR1 + lda old_VTIMR1_handler+1 + sta VTIMR1+1 + plp + rts + +.endif ; .ifdef __ATARIXL__