diff --git a/libsrc/c128/mou/c128-1351.s b/libsrc/c128/mou/c128-1351.s index 8aec3b7b7..e55c1d01b 100644 --- a/libsrc/c128/mou/c128-1351.s +++ b/libsrc/c128/mou/c128-1351.s @@ -12,6 +12,8 @@ .macpack generic +IRQInd = $2FD + ; ------------------------------------------------------------------------ ; Header. Includes jump table @@ -26,6 +28,7 @@ HEADER: ; Library reference +libref: .addr $0000 ; Jump table @@ -85,6 +88,15 @@ OldValue: .res 1 ; Temp for MoveCheck routine NewValue: .res 1 ; Temp for MoveCheck routine INIT_save: .res 1 +Buttons: .res 1 ; Button mask + +; Keyboard buffer fill level at start of interrupt + +old_key_count: .res 1 + +; original IRQ vector + +old_irq: .res 2 .rodata @@ -138,6 +150,48 @@ INSTALL: lda YPos ldx YPos+1 jsr CMOVEY + +; Initialize our IRQ magic + + ; remember ROM IRQ continuation address + lda IRQInd+2 + sta old_irq+1 + lda IRQInd+1 + sta old_irq + + lda libref + sta ptr3 + lda libref+1 + sta ptr3+1 + + ; set ROM IRQ continuation address to point to the provided routine + ldy #2 + lda (ptr3),y + sta IRQInd+1 + iny + lda (ptr3),y + sta IRQInd+2 + + ; set address of our IRQ callback routine + ; since it's called via "rts" we have to use "address-1" + iny + lda #<(callback-1) + sta (ptr3),y + iny + lda #>(callback-1) + sta (ptr3),y + iny + + ; set ROM entry point vector + ; since it's called via "rts" we have to decrement it by one + lda old_irq + sec + sbc #1 + sta (ptr3),y + iny + lda old_irq+1 + sbc #0 + sta (ptr3),y cli ; Done, return zero (= MOUSE_ERR_OK) @@ -151,6 +205,13 @@ INSTALL: ; No return code required (the driver is removed from memory on return). UNINSTALL: + lda old_irq + sei + sta IRQInd+1 + lda old_irq+1 + sta IRQInd+2 + cli + jsr HIDE ; Hide cursor on exit lda INIT_save sta INIT_STATUS @@ -250,14 +311,8 @@ MOVE: sei ; No interrupts ; BUTTONS: Return the button mask in a/x. BUTTONS: - lda #$7F - sei - sta CIA1_PRA - lda CIA1_PRB ; Read joystick #0 - cli - ldx #0 - and #$1F - eor #$1F + lda Buttons + ldx #$00 rts ;---------------------------------------------------------------------------- @@ -320,6 +375,15 @@ IOCTL: lda #(callback-1) + sta (ptr3),y + iny + + ; set ROM entry point vector + ; since it's called via "rts" we have to decrement it by one + lda old_irq + sec + sbc #1 + sta (ptr3),y + iny + lda old_irq+1 + sbc #0 + sta (ptr3),y cli ; Done, return zero (= MOUSE_ERR_OK) @@ -157,6 +210,13 @@ INSTALL: ; No return code required (the driver is removed from memory on return). UNINSTALL: + lda old_irq + sei + sta IRQInd+1 + lda old_irq+1 + sta IRQInd+2 + cli + jsr HIDE ; Hide cursor on exit lda INIT_save sta INIT_STATUS @@ -320,6 +380,8 @@ IOCTL: lda #@IRQCont + pha + lda #<@IRQCont + pha + php + + ; mimic the contents saved on the stack by the ROM IRQ entry handler + pha ; A + pha ; X + pha ; Y + lda #MMU_CFG_CC65 ; MMU configuration which will be active after the ROM handler returns + pha + + ; map out ROM + ldy MMU_CR + sta MMU_CR + + ; push address of ROM handler on stack and jump to it + lda jmp_rom_hdlr+1 + pha + lda jmp_rom_hdlr + pha + + sty MMU_CR ; map in ROM + rts ; jump to ROM handler + + ; our MMU configuration byte we pushed on the stack before (MMU_CFG_CC65) is now active + +@IRQCont: + + ; call mouse driver callback routine + lda #>(@IRQCont2-1) + pha + lda #<(@IRQCont2-1) + pha + lda callback+1 + pha + lda callback + pha + rts ; jump to callback routine + +@IRQCont2: + + ; return from interrupt + ; We could just jump to $FF33, but since I don't know whether this address is valid in all + ; ROM versions, duplicate that code here. + + pla + sta MMU_CR ; MMU configuration register + pla + tay + pla + tax + pla + rti