diff --git a/kernal/drivers/x16/ps2data.s b/kernal/drivers/x16/ps2data.s index c60e2887..73c7f643 100644 --- a/kernal/drivers/x16/ps2data.s +++ b/kernal/drivers/x16/ps2data.s @@ -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 @@ -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 diff --git a/kernal/drivers/x16/ps2kbd.s b/kernal/drivers/x16/ps2kbd.s index 4542978a..0087f582 100644 --- a/kernal/drivers/x16/ps2kbd.s +++ b/kernal/drivers/x16/ps2kbd.s @@ -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 @@ -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 @@ -80,6 +82,8 @@ dk_scan: .res 1 tpmcache: .res 1 +leds_pending: + .res 1 .segment "KEYMAP" @@ -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 @@ -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