1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-16 13:31:16 +00:00

Workaround for "phantom" key presses in the C128 "1351" mouse driver.

This commit is contained in:
Christian Groessler 2014-04-25 00:21:41 +02:00
parent 4406307c2f
commit 54be6de9bc
3 changed files with 97 additions and 33 deletions

View 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"

View 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"

View 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