From 54be6de9bc0afa61b4f15e1f651832a614176852 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 25 Apr 2014 00:21:41 +0200 Subject: [PATCH] Workaround for "phantom" key presses in the C128 "1351" mouse driver. --- libsrc/c128/mou/c128-1351.s | 74 ++++++++++++++++++++++++++++++++---- libsrc/c128/mou/c128-joy.s | 27 +------------ libsrc/c128/mou/callback.inc | 29 ++++++++++++++ 3 files changed, 97 insertions(+), 33 deletions(-) create mode 100644 libsrc/c128/mou/callback.inc diff --git a/libsrc/c128/mou/c128-1351.s b/libsrc/c128/mou/c128-1351.s index 8aec3b7b7..c81ad04d0 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 @@ -63,6 +66,15 @@ CMOVEY: jmp $0000 ; Move the cursor to Y coord SCREEN_HEIGHT = 200 SCREEN_WIDTH = 320 +;---------------------------------------------------------------------------- +; data segment + +.data + +chainIRQ: + .byte $4c ; JMP opcode + .word 0 ; pointer to ROM IRQ handler (will be set at runtime) + ;---------------------------------------------------------------------------- ; Global variables. The bounding box values are sorted so that they can be ; written with the least effort in the SETBOX and GETBOX routines, so don't @@ -85,6 +97,11 @@ 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 .rodata @@ -138,6 +155,35 @@ INSTALL: lda YPos ldx YPos+1 jsr CMOVEY + +; Initialize our IRQ magic + + lda IRQInd+1 + sta chainIRQ+1 + lda IRQInd+2 + sta chainIRQ+2 + lda libref + sta ptr3 + lda libref+1 + sta ptr3+1 + ldy #2 + lda (ptr3),y + sta IRQInd+1 + iny + lda (ptr3),y + sta IRQInd+2 + iny + lda #<(callback-1) + sta (ptr3),y + iny + lda #>(callback-1) + sta (ptr3),y + iny + lda #<(chainIRQ-1) + sta (ptr3),y + iny + lda #>(chainIRQ-1) + sta (ptr3),y cli ; Done, return zero (= MOUSE_ERR_OK) @@ -151,6 +197,13 @@ INSTALL: ; No return code required (the driver is removed from memory on return). UNINSTALL: + lda chainIRQ+1 + sei + sta IRQInd+1 + lda chainIRQ+2 + sta IRQInd+2 + cli + jsr HIDE ; Hide cursor on exit lda INIT_save sta INIT_STATUS @@ -250,14 +303,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 +367,15 @@ IOCTL: lda #