process all key events at once.

This commit is contained in:
Paul Gardner-Stephen committed 2019-04-24 07:16:10 +09:30
1 parent efc83a0611
commit 4cd8451c6c
1 file changed
+50 -67
+50 -67
View File
@@ -60,11 +60,39 @@
.alias MaxKeyRollover 3 .alias MaxKeyRollover 3
scan_keyboard: scan_keyboard:
lda #$ff
sta BufferQuantity
;; Decrement key repeat timeout if non-zero
ldx key_repeat_counter
stx $0427
beq sk_start
dec key_repeat_counter
sk_start:
;; Call main keyboard scanning routine ;; Call main keyboard scanning routine
jsr Main jsr Main
bcc sk_success
lda BufferQuantity
sta $0420
beq no_keys_waiting
;; Stuff each key pressed into the keyboard buffer
ldy #$00
*
lda Buffer,y
sta $0424,y
jsr accept_key
iny
cpy BufferQuantity
bne -
no_keys_waiting:
rts rts
sk_success:
accept_key:
;; Work out what is new and needs to be added ;; Work out what is new and needs to be added
;; to the input buffer. ;; to the input buffer.
;; Also update the bucky key status flags etc ;; Also update the bucky key status flags etc
@@ -87,6 +115,8 @@ sk_success:
;; But don't insert $00 characters ;; But don't insert $00 characters
beq sk_nokey beq sk_nokey
sta $044c,y
;; Stash key into keyboard buffer ;; Stash key into keyboard buffer
ldx keys_in_key_buffer ldx keys_in_key_buffer
cpx key_buffer_size cpx key_buffer_size
@@ -146,8 +176,16 @@ OverFlow:
pla pla
pla pla
;// Don't manipulate last legal buffer as the routine will fix itself once it gets valid input again. ;// Don't manipulate last legal buffer as the routine will fix itself once it gets valid input again.
TooManyNewKeys:
ReturnNoKeys:
sec sec
lda #$ff lda #$00
sta BufferQuantity
lda #$FF
sta Buffer+0
sta Buffer+1
sta Buffer+2
rts rts
@@ -161,24 +199,7 @@ NoActivityDetected:
lda #$00 lda #$00
sta key_bucky_state sta key_bucky_state
sec jmp ReturnNoKeys
lda #$ff
;; Reset key repeat, so that pressing a key that was
;; after letting it go in the meantime doesn't result
;; in continued repeating
sta last_key_matrix_position
rts
;; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; // Exit Routine for Control Port Activity
ControlPort:
;; // Exit with A = #$02, Carry Set. Keep BufferOld to verify input after Control Port activity ceases
sec
lda #$ff
rts
;; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; // Configure Data Direction Registers ;; // Configure Data Direction Registers
@@ -203,8 +224,7 @@ skip0:
stx $dc00 ;// Disconnect all Keyboard Rows stx $dc00 ;// Disconnect all Keyboard Rows
cpx $dc01 ;// Only Control Port activity will be detected cpx $dc01 ;// Only Control Port activity will be detected
bne ControlPort bne ReturnNoKeys
;; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; // Scan Keyboard Matrix ;; // Scan Keyboard Matrix
@@ -229,7 +249,7 @@ next_row:
stx $dc00 ;// Disconnect all Keyboard Rows stx $dc00 ;// Disconnect all Keyboard Rows
cpx $dc01 ;// Only Control Port activity will be detected cpx $dc01 ;// Only Control Port activity will be detected
bne ControlPort bne ReturnNoKeys
;; Make X = $00, assumed below ;; Make X = $00, assumed below
inx inx
@@ -365,7 +385,6 @@ ProcessPressedKeys:
;; Check if the currently pressed key is continuing to be held down ;; Check if the currently pressed key is continuing to be held down
lda BufferNew,x lda BufferNew,x
sta $047A,X
cmp #$ff cmp #$ff
beq ConsiderNextKey beq ConsiderNextKey
cmp BufferOld cmp BufferOld
@@ -375,17 +394,6 @@ ProcessPressedKeys:
cmp BufferOld+2 cmp BufferOld+2
beq KeyHeld beq KeyHeld
;;
sta $0450
pha
lda BufferOld
sta $0452
lda BufferOld+1
sta $0453
lda BufferOld+2
sta $0454
pla
RecordKeypress: RecordKeypress:
@@ -404,18 +412,9 @@ ConsiderNextKey:
dex dex
bpl ProcessPressedKeys bpl ProcessPressedKeys
;; // Anything in Buffer? ;; Return success and set of pressed keys
ldy BufferQuantity clc
rts
bmi BufferEmpty
;; // Yes: Then return it and tidy up the buffer
dec BufferQuantity
lda Buffer
ldx Buffer+1
stx Buffer
ldx Buffer+2
stx Buffer+1
jmp Return
KeyHeld: KeyHeld:
;; The key in A is still held down. ;; The key in A is still held down.
@@ -446,10 +445,12 @@ BuckyHeld:
jmp ConsiderNextKey jmp ConsiderNextKey
SameKeyHeld: SameKeyHeld:
ldx key_repeat_counter
beq KeyCanRepeat
dec key_repeat_counter dec key_repeat_counter
bne KeyRepeatWait bne KeyRepeatWait
;; Count down ended, so repeat key now ;; Count down ended, so repeat key now
KeyCanRepeat:
;; (Compute's Mapping the 64 p58) ;; (Compute's Mapping the 64 p58)
pha pha
@@ -464,22 +465,4 @@ KeyRepeatWait:
BufferEmpty: ;; // No new Alphanumeric keys to handle. BufferEmpty: ;; // No new Alphanumeric keys to handle.
lda #$ff lda #$ff
Return: ;; // A is preset
clc
;; // Copy BufferNew to BufferOld
ldx BufferNew
stx BufferOld
ldx BufferNew+1
stx BufferOld+1
ldx BufferNew+2
stx BufferOld+2
rts
TooManyNewKeys:
sec
lda #$ff
sta BufferQuantity
rts