From 23a46a3379314021033017a6e4f1f47af3f5fa56 Mon Sep 17 00:00:00 2001 From: Eugene Lozovoy Date: Fri, 4 Oct 2024 12:58:34 +0300 Subject: [PATCH] keyboard: fix arrow keys in basic --- rtl/periph/keyboard.v | 35 +++++++++++++++++++++++++++-------- rtl/tsconf.v | 1 + 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/rtl/periph/keyboard.v b/rtl/periph/keyboard.v index ac3058f..c3843a9 100644 --- a/rtl/periph/keyboard.v +++ b/rtl/periph/keyboard.v @@ -8,6 +8,7 @@ module keyboard output reg [7:0] scancode, input scancode_ack, input scancode_clr, + input matrix_update, input [10:0] ps2_key, input [1:0] cfg_joystick1, input [1:0] cfg_joystick2, @@ -16,18 +17,36 @@ module keyboard ); reg [4:0] keys [7:0]; +reg [4:0] keys_r [7:0]; -wire [4:0] row0 = a[0]? 5'b11111 : keys[0]; -wire [4:0] row1 = a[1]? 5'b11111 : keys[1]; -wire [4:0] row2 = a[2]? 5'b11111 : keys[2]; -wire [4:0] row3 = a[3]? 5'b11111 : keys[3]; -wire [4:0] row4 = a[4]? 5'b11111 : keys[4]; -wire [4:0] row5 = a[5]? 5'b11111 : keys[5]; -wire [4:0] row6 = a[6]? 5'b11111 : keys[6]; -wire [4:0] row7 = a[7]? 5'b11111 : keys[7]; +wire [4:0] row0 = a[0]? 5'b11111 : keys_r[0]; +wire [4:0] row1 = a[1]? 5'b11111 : keys_r[1]; +wire [4:0] row2 = a[2]? 5'b11111 : keys_r[2]; +wire [4:0] row3 = a[3]? 5'b11111 : keys_r[3]; +wire [4:0] row4 = a[4]? 5'b11111 : keys_r[4]; +wire [4:0] row5 = a[5]? 5'b11111 : keys_r[5]; +wire [4:0] row6 = a[6]? 5'b11111 : keys_r[6]; +wire [4:0] row7 = a[7]? 5'b11111 : keys_r[7]; assign keyb = row0 & row1 & row2 & row3 & row4 & row5 & row6 & row7; +reg matrix_update_r; +always @(posedge clk) + matrix_update_r <= matrix_update; + +always @(posedge clk or posedge reset) begin + integer i; + if (reset) begin + for (i = 0; i < 8; i = i + 1) + keys_r[i] <= 5'b11111; + end + else if (matrix_update && !matrix_update_r) begin + for (i = 0; i < 8; i = i + 1) + keys_r[i] <= keys[i]; + end +end + + wire [15:0] joys = {joystick2, joystick1}; reg [15:0] joys_r = 0; reg joys_ch = 0; diff --git a/rtl/tsconf.v b/rtl/tsconf.v index 7e1e0f5..5bd0786 100644 --- a/rtl/tsconf.v +++ b/rtl/tsconf.v @@ -939,6 +939,7 @@ module tsconf .scancode(key_scancode), .scancode_ack(key_scancode_ack), .scancode_clr(key_scancode_clr), + .matrix_update(VVSYNC), .ps2_key(PS2_KEY), .cfg_joystick1(CFG_JOYSTICK1), .cfg_joystick2(CFG_JOYSTICK2),