From 5bf82ca8444b65fe15f48d8466582bae4ccbef76 Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Fri, 22 Dec 2023 12:10:54 +0100 Subject: [PATCH] wip: kb --- main.s65 | 4 ++-- spicode.s65 | 36 +++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/main.s65 b/main.s65 index fe31982..872ca6d 100644 --- a/main.s65 +++ b/main.s65 @@ -91,11 +91,11 @@ irq: jsr spi_p::read bra @irq_return @irq_kb1: - PrintNC "<30>" + ; PrintNC "<30>" jsr $3000 bra @irq_return @irq_kb2: - PrintNC "<31>" + ; PrintNC "<31>" jsr $3100 bra @irq_return ; @irq_dht: diff --git a/spicode.s65 b/spicode.s65 index b43754c..665f6fe 100644 --- a/spicode.s65 +++ b/spicode.s65 @@ -82,6 +82,10 @@ CODE_START: beq @l3 cmp #'A' beq @lA + cmp #'B' + beq @lB + cmp #'C' + beq @lC jsr lcd::print_char bra @loop @l1: @@ -105,6 +109,13 @@ CODE_START: lda kb::KB_IO + IO::SR jsr lcd::print_char bra @loop +@lB: + Strf fmt_str, out_str, keycode + Print out_str + bra @loop +@lC: + jsr lcd::clear + bra @loop kbinit: @@ -132,6 +143,9 @@ kbinit: rts +;; @details +;; IO::SR has to be read before the next bit is shifted in, which happens ~75us after the irq +;; at 1MHz, handlings this interrupt takes about 50us (without any additional debug code), so it should work irq_on_shift_reg: ; lda #'{' ; jsr lcd::print_char @@ -154,8 +168,8 @@ irq_on_shift_reg: irq_on_timer: - lda #'<' - jsr lcd::print_char + ; lda #'<' + ; jsr lcd::print_char lda kb::KB_IO + IO::SR sta key_read + 1 @@ -167,14 +181,10 @@ irq_on_timer: ; enable shift register interrupts lda #(IO::IRQ::IRQ | IO::IRQ::SR) sta kb::KB_IO + IO::IER - ; load SR to reset + ; reset SR stz kb::KB_IO + IO::SR ; lda #'|' - lda key_read - jsr lcd::print_char - lda key_read + 1 - jsr lcd::print_char ; rotate bit 2 (last bit of keycode) into the carry ror ror @@ -183,11 +193,13 @@ irq_on_timer: rol ; rotate carry into byte, rotate startbit into carry ; TODO byte is inverted, maybe consider wasting 256 bytes for a bit reverse lookup table? sta keycode + + Strf fmt_str2, out_str, keycode, key_read, key_read+1 + PrintNC out_str + stz key_read stz key_read+1 - Strf "kc:%x", out_str, keycode - PrintNC out_str rts key_read: .res 2 @@ -204,10 +216,12 @@ kb_irq2: ; lda #'?' ; jsr lcd::print_char jsr irq_on_timer - lda #';' - jsr lcd::print_char + ; lda #';' + ; jsr lcd::print_char rts .byte '@' out_str: .res 40 +fmt_str: .asciiz "kc%x;" +fmt_str2: .asciiz "kc%x-%x-%x; "