From d677fc5de0568924b39eecae11a24f40566860b9 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 9 May 2021 13:53:41 -0700 Subject: Keyboard input. --- hdl/core.sv | 27 +++++++++++++++++++++++++-- mem/hello.pal | 13 ++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/hdl/core.sv b/hdl/core.sv index 02ff231..7edf523 100644 --- a/hdl/core.sv +++ b/hdl/core.sv @@ -67,6 +67,9 @@ bit [8:0] operand; bit [DATA_BITS-1:0] acc; bit link; +bit kbd_valid; +bit [DATA_BITS-1:0] kbd_data; + bit i; bit z; bit [6:0] wip; @@ -93,9 +96,14 @@ always_ff @(posedge clk) begin pc = 'o200; acc = 0; link = 0; + kbd_valid = 0; state = state.first; end else begin if (`lag(tx_ready)) tx_valid = 0; + if (rx_ready && `lag(rx_valid)) begin + kbd_valid = 1; + kbd_data = {4'b0, 1'b1, `lag(rx_data[6:0])}; + end case (state) FETCH: begin @@ -115,7 +123,7 @@ always_ff @(posedge clk) begin if (`lag(mem_read_valid)) begin state = FETCH; {opcode, operand} = `lag(mem_read_data); - $display("%d decode %x: %b %b", $time, pc-1, opcode, operand); + //$display("%d decode %x: %b %b", $time, pc-1, opcode, operand); {i, z, wip} = operand; if (z) address = {page, wip}; @@ -191,6 +199,19 @@ always_ff @(posedge clk) begin end 'b110: begin case (operand[8:3]) + 'b000011: begin + case (operand[2:0]) + 'b001: if (kbd_valid) pc++; + 'b110: begin + acc = kbd_data; + kbd_valid = 0; + end + default: begin + $display("unsupported keyboard op %b", operand[2:0]); + $finish; + end + endcase + end 'b000100: begin case (operand[2:0]) 'b001: if (!tx_valid) pc++; @@ -199,7 +220,7 @@ always_ff @(posedge clk) begin tx_data = {1'b0, acc[6:0]}; end default: begin - $display("unsupported device op %b", operand[2:0]); + $display("unsupported tty op %b", operand[2:0]); $finish; end endcase @@ -320,6 +341,8 @@ always_ff @(posedge clk) begin $finish; end endcase + + rx_ready = !kbd_valid; end end diff --git a/mem/hello.pal b/mem/hello.pal index 437ccf9..989eff8 100644 --- a/mem/hello.pal +++ b/mem/hello.pal @@ -4,14 +4,19 @@ START, CLA CLL DCA 10 LOOP, TAD I 10 SNA - JMP EXIT + JMP ECHO TLS TSF JMP .-1 CLA JMP LOOP -EXIT, HLT - JMP START +ECHO, KSF + JMP .-1 + KRB + TLS + TSF + JMP .-1 + JMP ECHO HELLO, . "H "e @@ -26,5 +31,7 @@ HELLO, . "l "d "! + 15 + 12 0 $ -- cgit v1.2.3