Workaround for "phantom" key presses in the C128 "1351" mouse driver.
This commit is contained in:
parent
4406307c2f
commit
54be6de9bc
3 changed files with 97 additions and 33 deletions
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
.macpack generic
|
.macpack generic
|
||||||
|
|
||||||
|
IRQInd = $2FD
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
; Header. Includes jump table
|
; Header. Includes jump table
|
||||||
|
|
||||||
|
@ -26,6 +28,7 @@ HEADER:
|
||||||
|
|
||||||
; Library reference
|
; Library reference
|
||||||
|
|
||||||
|
libref:
|
||||||
.addr $0000
|
.addr $0000
|
||||||
|
|
||||||
; Jump table
|
; Jump table
|
||||||
|
@ -63,6 +66,15 @@ CMOVEY: jmp $0000 ; Move the cursor to Y coord
|
||||||
SCREEN_HEIGHT = 200
|
SCREEN_HEIGHT = 200
|
||||||
SCREEN_WIDTH = 320
|
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
|
; 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
|
; 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
|
NewValue: .res 1 ; Temp for MoveCheck routine
|
||||||
|
|
||||||
INIT_save: .res 1
|
INIT_save: .res 1
|
||||||
|
Buttons: .res 1 ; Button mask
|
||||||
|
|
||||||
|
; Keyboard buffer fill level at start of interrupt
|
||||||
|
|
||||||
|
old_key_count: .res 1
|
||||||
|
|
||||||
.rodata
|
.rodata
|
||||||
|
|
||||||
|
@ -138,6 +155,35 @@ INSTALL:
|
||||||
lda YPos
|
lda YPos
|
||||||
ldx YPos+1
|
ldx YPos+1
|
||||||
jsr CMOVEY
|
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
|
cli
|
||||||
|
|
||||||
; Done, return zero (= MOUSE_ERR_OK)
|
; Done, return zero (= MOUSE_ERR_OK)
|
||||||
|
@ -151,6 +197,13 @@ INSTALL:
|
||||||
; No return code required (the driver is removed from memory on return).
|
; No return code required (the driver is removed from memory on return).
|
||||||
|
|
||||||
UNINSTALL:
|
UNINSTALL:
|
||||||
|
lda chainIRQ+1
|
||||||
|
sei
|
||||||
|
sta IRQInd+1
|
||||||
|
lda chainIRQ+2
|
||||||
|
sta IRQInd+2
|
||||||
|
cli
|
||||||
|
|
||||||
jsr HIDE ; Hide cursor on exit
|
jsr HIDE ; Hide cursor on exit
|
||||||
lda INIT_save
|
lda INIT_save
|
||||||
sta INIT_STATUS
|
sta INIT_STATUS
|
||||||
|
@ -250,14 +303,8 @@ MOVE: sei ; No interrupts
|
||||||
; BUTTONS: Return the button mask in a/x.
|
; BUTTONS: Return the button mask in a/x.
|
||||||
|
|
||||||
BUTTONS:
|
BUTTONS:
|
||||||
lda #$7F
|
lda Buttons
|
||||||
sei
|
ldx #$00
|
||||||
sta CIA1_PRA
|
|
||||||
lda CIA1_PRB ; Read joystick #0
|
|
||||||
cli
|
|
||||||
ldx #0
|
|
||||||
and #$1F
|
|
||||||
eor #$1F
|
|
||||||
rts
|
rts
|
||||||
|
|
||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
|
@ -320,6 +367,15 @@ IOCTL: lda #<MOUSE_ERR_INV_IOCTL ; We don't support ioclts for now
|
||||||
;
|
;
|
||||||
|
|
||||||
IRQ: jsr CPREP
|
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
|
lda SID_ADConv1 ; Get mouse X movement
|
||||||
ldy OldPotX
|
ldy OldPotX
|
||||||
jsr MoveCheck ; Calculate movement vector
|
jsr MoveCheck ; Calculate movement vector
|
||||||
|
@ -450,3 +506,5 @@ MoveCheck:
|
||||||
clc
|
clc
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
.define OLD_BUTTONS Buttons ; tells callback.inc where the old port status is stored
|
||||||
|
.include "callback.inc"
|
||||||
|
|
|
@ -491,28 +491,5 @@ IRQ: jsr CPREP
|
||||||
clc ; Interrupt not "handled"
|
clc ; Interrupt not "handled"
|
||||||
rts
|
rts
|
||||||
|
|
||||||
;----------------------------------------------------------------------------
|
.define OLD_BUTTONS Temp ; tells callback.inc where the old port status is stored
|
||||||
; Called after ROM IRQ handler has been run.
|
.include "callback.inc"
|
||||||
; 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
|
|
||||||
|
|
29
libsrc/c128/mou/callback.inc
Normal file
29
libsrc/c128/mou/callback.inc
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue