Skip to content

Commit

Permalink
[KERNAL] remove the infinite spinlock on setting the kbd LEDs and def…
Browse files Browse the repository at this point in the history
…er to next tick (X16Community#365)
  • Loading branch information
mooinglemur authored Sep 11, 2024
1 parent a8981d4 commit c921a17
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
5 changes: 4 additions & 1 deletion kernal/drivers/x16/ps2data.s
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PS2DATA_NEW_STYLE = $02
LED_NUM_LOCK = 2

.import i2c_read_byte, i2c_read_first_byte, i2c_direct_read, i2c_read_next_byte, i2c_read_stop, i2c_write_byte
.import tpmflg, tpmcache, ledstate
.import tpmflg, tpmcache, ledstate, leds_pending

.export ps2data_init, ps2data_fetch, ps2data_kbd, ps2data_kbd_count, ps2data_mouse, ps2data_mouse_count
.export ps2data_keyboard_and_mouse, ps2data_keyboard_only, ps2data_raw
Expand Down Expand Up @@ -55,6 +55,9 @@ ps2data_init:
lda #LED_NUM_LOCK
sta ledstate

; Clear flag for pending LED state change
stz leds_pending

; Compare SMC firmare version major
ldx #I2C_ADDR
ldy #CMD_GET_VER1
Expand Down
20 changes: 16 additions & 4 deletions kernal/drivers/x16/ps2kbd.s
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

.export kbd_config, kbd_scan, receive_scancode_resume, keymap, ps2kbd_typematic
.export kbd_leds
.export tpmflg, tpmcache, ledstate
.export tpmflg, tpmcache, ledstate, leds_pending

.import extapi

Expand All @@ -43,6 +43,8 @@ I2C_GET_KBD_CMD_STATUS = $18
I2C_KBD_CMD2 = $1a
I2C_CMD_PENDING = $01

PS2_CMD_SET_LEDS = $ed

MODIFIER_SHIFT = 1 ; C64: Shift
MODIFIER_ALT = 2 ; C64: Commodore
MODIFIER_CTRL = 4 ; C64: Ctrl
Expand Down Expand Up @@ -80,6 +82,8 @@ dk_scan:
.res 1
tpmcache:
.res 1
leds_pending:
.res 1


.segment "KEYMAP"
Expand Down Expand Up @@ -278,6 +282,10 @@ _kbd_scan:
jsr fetch_key_code
ora #0
bne @1
lda leds_pending
beq @0
jmp _set_kbd_leds
@0:
rts ; No key

; Set typematic rate/delay on first keycode
Expand Down Expand Up @@ -598,17 +606,21 @@ kbd_leds:
_set_kbd_leds:
ldx #I2C_ADDRESS
ldy #I2C_GET_KBD_CMD_STATUS
: jsr i2c_read_byte
jsr i2c_read_byte
cmp #I2C_CMD_PENDING
beq :-
beq @2

stz leds_pending
; Set LED state command
ldy #I2C_KBD_CMD2
lda #$ed
lda #PS2_CMD_SET_LEDS
jsr i2c_write_first_byte
lda ledstate
jsr i2c_write_next_byte
jmp i2c_write_stop
@2:
sta leds_pending
rts

;*****************************************
; SET REPEAT RATE AND DELAY
Expand Down

0 comments on commit c921a17

Please sign in to comment.