]> git.sur5r.net Git - cc65/commitdiff
Workaround for "phantom" key presses in the C128 "1351" mouse driver.
authorChristian Groessler <chris@groessler.org>
Thu, 24 Apr 2014 22:21:41 +0000 (00:21 +0200)
committerChristian Groessler <chris@groessler.org>
Thu, 24 Apr 2014 22:22:23 +0000 (00:22 +0200)
libsrc/c128/mou/c128-1351.s
libsrc/c128/mou/c128-joy.s
libsrc/c128/mou/callback.inc [new file with mode: 0644]

index 8aec3b7b7863c2d18bc15a8b826a59ba4244c713..c81ad04d0d0f169926ef7e30e2adb1fdb408f32f 100644 (file)
@@ -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     #<MOUSE_ERR_INV_IOCTL     ; We don't support ioclts for now
 ;
 
 IRQ:    jsr     CPREP
+        lda     KEY_COUNT
+        sta     old_key_count
+        lda     #$7F
+        sta     CIA1_PRA
+        lda     CIA1_PRB                ; Read joystick #0
+        and     #$1F
+        eor     #$1F                    ; Make all bits active high
+        sta     Buttons
+
         lda     SID_ADConv1             ; Get mouse X movement
         ldy     OldPotX
         jsr     MoveCheck               ; Calculate movement vector
@@ -450,3 +506,5 @@ MoveCheck:
         clc
         rts
 
+.define  OLD_BUTTONS Buttons            ; tells callback.inc where the old port status is stored
+.include "callback.inc"
index 339fdc836f7ac0b06817ba35a55830ba713c4723..83255b64ef8014a074d9fb1b711b6066c2bbfd63 100644 (file)
@@ -491,28 +491,5 @@ IRQ:    jsr     CPREP
         clc                             ; Interrupt not "handled"
         rts
 
-;----------------------------------------------------------------------------
-; Called after ROM IRQ handler has been run.
-; Check if there was joystick activity before and/or after the ROM handler.
-; If there was activity, discard the key presses since they are most
-; probably "phantom" key presses.
-
-callback:
-        ldx     old_key_count
-        cpx     KEY_COUNT
-        beq     @nokey
-
-        lda     Temp                    ; keypress before?
-        bne     @discard_key            ; yes, discard key
-
-        lda     #$7F
-        sta     CIA1_PRA
-        lda     CIA1_PRB                ; Read joystick #0
-        and     #$1F
-        eor     #$1F                    ; keypress after
-        beq     @nokey                  ; no, probably a real key press
-
-@discard_key:
-        stx     KEY_COUNT               ; set old keyboard buffer fill level
-
-@nokey: rts
+.define  OLD_BUTTONS Temp               ; tells callback.inc where the old port status is stored
+.include "callback.inc"
diff --git a/libsrc/c128/mou/callback.inc b/libsrc/c128/mou/callback.inc
new file mode 100644 (file)
index 0000000..ea64b89
--- /dev/null
@@ -0,0 +1,29 @@
+;
+; Callback routine called from the IRQ handler after the ROM IRQ handler
+; had been run.
+;
+; Christian Groessler, 24.04.2014
+;
+; Check if there was joystick activity before and/or after the ROM handler.
+; If there was activity, discard the key presses since they are most
+; probably "phantom" key presses.
+
+callback:
+        ldx     old_key_count
+        cpx     KEY_COUNT
+        beq     @nokey
+
+        lda     OLD_BUTTONS             ; keypress before?
+        bne     @discard_key            ; yes, discard key
+
+        lda     #$7F
+        sta     CIA1_PRA
+        lda     CIA1_PRB                ; Read joystick #0
+        and     #$1F
+        eor     #$1F                    ; keypress after
+        beq     @nokey                  ; no, probably a real key press
+
+@discard_key:
+        stx     KEY_COUNT               ; set old keyboard buffer fill level
+
+@nokey: rts