VT220 emulation with ANSI colour, underline and smooth scrolling
- Terminal engine rewritten for VT220: scroll regions, IL/DL/ICH/DCH/ECH, SU/SD, origin mode, insert mode, tab stops, DEC special graphics with G0/G1 and SO/SI, DECSC/DECRC, DECSTR, RIS, DECALN, DECLL LEDs - Replies to DA, secondary DA, DSR and CPR over the UART - 16-colour SGR (256-colour and RGB approximated), bold, underline, blink, reverse and conceal; cells are now 18 bits - Smooth scrolling (SW8 or DECSCLM): the region slides per frame and rows are moved during vertical blanking; XON/XOFF holds the host back - Keyboard: DECCKM, keypad application mode, F5-F12, VT220 Home/End, Alt as ESC prefix - basys3 terminfo entry (vt220 + 16 colours, 30 lines) - Flash script reboots the FPGA from flash after programming - Testbench covers replies, modes, attributes, editing and smooth scroll Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a95062f42d
commit
6e54d75c56
10 files changed
+1173
-350
No files matched your search
+111
-51
@@ -1,19 +1,24 @@
|
||||
`timescale 1ns / 1ps
|
||||
|
||||
// Basys 3 ASCII terminal.
|
||||
// Basys 3 VT220 terminal with ANSI colour.
|
||||
// Keyboard (USB HID port) -> UART TX (USB-UART port)
|
||||
// UART RX -> 80x30 text on VGA
|
||||
// UART RX -> 80x30 colour text on VGA
|
||||
//
|
||||
// SW1:0 baud rate: 00 115200, 01 9600, 10 19200, 11 57600 (8N1)
|
||||
// SW2 local echo
|
||||
// SW3 received LF also does CR
|
||||
// SW5:4 colour: 00 green, 01 amber, 10 white, 11 cyan
|
||||
// SW5:4 default text colour: 00 green, 01 yellow, 10 white, 11 cyan
|
||||
// SW6 Backspace sends DEL (7F) instead of BS (08)
|
||||
// SW7 Enter sends CR LF instead of CR
|
||||
// SW8 smooth scrolling (also turned on by ESC [ ? 4 h)
|
||||
// SW9 fast smooth scrolling
|
||||
// BTNC reset BTNU clear screen
|
||||
// LED7:0 last byte received LED12 bell LED13 Caps Lock
|
||||
// LED14 UART RX activity LED15 keyboard activity
|
||||
// LED7:0 last byte received LED11:8 VT220 LEDs L4..L1 (DECLL)
|
||||
// LED12 bell LED13 Caps Lock LED14 UART RX activity LED15 keyboard activity
|
||||
// 7-seg last scan code (left), last byte sent (right)
|
||||
//
|
||||
// The terminal sends XOFF when its input buffer passes 256 bytes and XON when
|
||||
// it drains below 32, so smooth scrolling can hold the host back.
|
||||
|
||||
module basys3_terminal #(
|
||||
parameter FONT_FILE = "font.mem",
|
||||
@@ -37,6 +42,8 @@ module basys3_terminal #(
|
||||
input PS2Clk,
|
||||
input PS2Data
|
||||
);
|
||||
localparam [7:0] XON = 8'h11, XOFF = 8'h13;
|
||||
|
||||
// ---------------------------------------------------------------- reset
|
||||
reg [1:0] btn_sync;
|
||||
reg [15:0] por = 16'd0;
|
||||
@@ -48,10 +55,10 @@ module basys3_terminal #(
|
||||
rst <= !por[15];
|
||||
end
|
||||
|
||||
reg [7:0] sw_r;
|
||||
reg [9:0] sw_r;
|
||||
reg [1:0] clr_sync;
|
||||
always @(posedge clk) begin
|
||||
sw_r <= sw[7:0];
|
||||
sw_r <= sw[9:0];
|
||||
clr_sync <= {clr_sync[0], btnU};
|
||||
end
|
||||
|
||||
@@ -64,12 +71,22 @@ module basys3_terminal #(
|
||||
2'b11: baud_div <= CLK_HZ / 57600;
|
||||
endcase
|
||||
|
||||
reg [3:0] def_fg;
|
||||
always @(posedge clk)
|
||||
case (sw_r[5:4])
|
||||
2'b00: def_fg <= 4'd10; // bright green
|
||||
2'b01: def_fg <= 4'd11; // yellow
|
||||
2'b10: def_fg <= 4'd7; // white
|
||||
2'b11: def_fg <= 4'd14; // bright cyan
|
||||
endcase
|
||||
|
||||
// ------------------------------------------------------------- keyboard
|
||||
wire [7:0] scan;
|
||||
wire scan_valid;
|
||||
wire [7:0] key;
|
||||
wire key_valid;
|
||||
wire caps;
|
||||
wire cursor_app, keypad_app, lnm;
|
||||
|
||||
ps2_rx kbd_rx (
|
||||
.clk(clk), .rst(rst), .ps2_clk(PS2Clk), .ps2_data(PS2Data),
|
||||
@@ -78,27 +95,69 @@ module basys3_terminal #(
|
||||
|
||||
ps2_keymap kbd_map (
|
||||
.clk(clk), .rst(rst), .code(scan), .code_valid(scan_valid),
|
||||
.bs_del(sw_r[6]), .enter_crlf(sw_r[7]),
|
||||
.bs_del(sw_r[6]), .enter_crlf(sw_r[7] | lnm),
|
||||
.cursor_app(cursor_app), .keypad_app(keypad_app),
|
||||
.ascii(key), .ascii_valid(key_valid), .caps(caps)
|
||||
);
|
||||
|
||||
// ------------------------------------------------------------- transmit
|
||||
wire [7:0] kq;
|
||||
wire kq_empty;
|
||||
// Sources: flow control (first), then keyboard and terminal replies. The
|
||||
// keyboard/reply choice sticks until that queue is empty, so multi-byte
|
||||
// sequences are never interleaved.
|
||||
wire [7:0] kq, rq;
|
||||
wire kq_empty, rq_empty, rq_full;
|
||||
wire [7:0] resp_byte;
|
||||
wire resp_wr;
|
||||
wire tx_busy;
|
||||
reg tx_start;
|
||||
reg tx_start, kq_rd, rq_rd, from_resp;
|
||||
reg [7:0] tx_byte;
|
||||
reg flow_pend;
|
||||
reg [7:0] flow_byte;
|
||||
|
||||
fifo #(.W(8), .A(4)) key_fifo (
|
||||
.clk(clk), .rst(rst), .din(key), .wr(key_valid),
|
||||
.rd(tx_start), .dout(kq), .empty(kq_empty), .full()
|
||||
.rd(kq_rd), .dout(kq), .empty(kq_empty), .full(), .count()
|
||||
);
|
||||
|
||||
fifo #(.W(8), .A(4)) resp_fifo (
|
||||
.clk(clk), .rst(rst), .din(resp_byte), .wr(resp_wr),
|
||||
.rd(rq_rd), .dout(rq), .empty(rq_empty), .full(rq_full), .count()
|
||||
);
|
||||
|
||||
wire [10:0] tq_count;
|
||||
reg xoff_sent;
|
||||
|
||||
always @(posedge clk) begin
|
||||
tx_start <= 1'b0;
|
||||
if (!kq_empty && !tx_busy && !tx_start && !rst) begin
|
||||
tx_start <= 1'b1;
|
||||
tx_byte <= kq;
|
||||
kq_rd <= 1'b0;
|
||||
rq_rd <= 1'b0;
|
||||
if (rst) begin
|
||||
from_resp <= 1'b0;
|
||||
flow_pend <= 1'b0;
|
||||
xoff_sent <= 1'b0;
|
||||
end else begin
|
||||
if (!flow_pend && !xoff_sent && tq_count >= 256) begin
|
||||
flow_pend <= 1'b1; flow_byte <= XOFF; xoff_sent <= 1'b1;
|
||||
end else if (!flow_pend && xoff_sent && tq_count < 32) begin
|
||||
flow_pend <= 1'b1; flow_byte <= XON; xoff_sent <= 1'b0;
|
||||
end
|
||||
|
||||
if (!tx_busy && !tx_start) begin
|
||||
if (flow_pend) begin
|
||||
tx_byte <= flow_byte;
|
||||
tx_start <= 1'b1;
|
||||
flow_pend <= 1'b0;
|
||||
end else if (!from_resp && !kq_empty) begin
|
||||
tx_byte <= kq;
|
||||
tx_start <= 1'b1;
|
||||
kq_rd <= 1'b1;
|
||||
end else if (from_resp && !rq_empty) begin
|
||||
tx_byte <= rq;
|
||||
tx_start <= 1'b1;
|
||||
rq_rd <= 1'b1;
|
||||
end else
|
||||
from_resp <= !from_resp;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -118,10 +177,11 @@ module basys3_terminal #(
|
||||
|
||||
// Start-up banner, fed in like received text. Bytes are read from the
|
||||
// high end of the string; the unused high bytes are zero and skipped.
|
||||
localparam [8*160-1:0] BANNER = {
|
||||
"Basys 3 ASCII Terminal 80x30\015\012",
|
||||
"UART RX -> screen, keyboard -> UART TX\015\012",
|
||||
"SW1:0 baud 00=115200 01=9600 10=19200 11=57600 SW2 echo\015\012\012"};
|
||||
localparam [8*200-1:0] BANNER = {
|
||||
"\033[1mBasys 3 VT220 Terminal\033[0m 80x30 ",
|
||||
"\033[31mc\033[33mo\033[32ml\033[36mo\033[34mu\033[35mr\033[0m ",
|
||||
"\033[4munderline\033[0m\015\012",
|
||||
"UART RX -> screen, keyboard -> UART TX TERM=basys3 or vt220\015\012\012"};
|
||||
reg [7:0] ban_i;
|
||||
wire [7:0] ban_c = BANNER[ban_i*8 +: 8];
|
||||
|
||||
@@ -134,20 +194,20 @@ module basys3_terminal #(
|
||||
|
||||
always @(posedge clk) begin
|
||||
tin_wr <= 1'b0;
|
||||
if (tx_start && sw_r[2]) begin
|
||||
if (kq_rd && sw_r[2]) begin
|
||||
echo_pend <= 1'b1;
|
||||
echo_byte <= kq;
|
||||
end
|
||||
if (rst) begin
|
||||
echo_pend <= 1'b0;
|
||||
ban_i <= 8'd159;
|
||||
ban_i <= 8'd199;
|
||||
end else if (rx_valid) begin
|
||||
tin <= rx_byte;
|
||||
tin_wr <= 1'b1;
|
||||
end else if (echo_pend && !tin_full) begin
|
||||
tin <= echo_byte;
|
||||
tin_wr <= 1'b1;
|
||||
echo_pend <= tx_start && sw_r[2];
|
||||
echo_pend <= kq_rd && sw_r[2];
|
||||
end else if (ban_i != 8'hFF && !tin_full && !tin_wr) begin
|
||||
ban_i <= ban_i - 1'b1;
|
||||
if (ban_c != 0) begin
|
||||
@@ -161,49 +221,49 @@ module basys3_terminal #(
|
||||
wire tq_empty;
|
||||
wire tq_rd;
|
||||
|
||||
fifo #(.W(8), .A(6)) term_fifo (
|
||||
fifo #(.W(8), .A(10)) term_fifo (
|
||||
.clk(clk), .rst(rst), .din(tin), .wr(tin_wr),
|
||||
.rd(tq_rd), .dout(tq), .empty(tq_empty), .full(tin_full)
|
||||
.rd(tq_rd), .dout(tq), .empty(tq_empty), .full(tin_full), .count(tq_count)
|
||||
);
|
||||
|
||||
// ------------------------------------------------------------- terminal
|
||||
wire we;
|
||||
wire [11:0] waddr;
|
||||
wire [8:0] wdata;
|
||||
wire [4:0] top, cur_row;
|
||||
wire [11:0] t_addr;
|
||||
wire t_we;
|
||||
wire [17:0] t_wdata, t_rdata;
|
||||
wire [4:0] cur_row, stop, sbot, sm_off;
|
||||
wire [6:0] cur_col;
|
||||
wire cur_vis;
|
||||
wire cur_vis, sm_on, sm_dir;
|
||||
wire [3:0] dec_leds;
|
||||
wire bell;
|
||||
wire frame_tick;
|
||||
|
||||
term_ctrl term (
|
||||
.clk(clk), .rst(rst), .in_byte(tq), .in_empty(tq_empty), .in_rd(tq_rd),
|
||||
.lf_cr(sw_r[3]), .clear_req(clr_sync[1]),
|
||||
.we(we), .waddr(waddr), .wdata(wdata),
|
||||
.top(top), .row(cur_row), .col(cur_col), .cur_vis(cur_vis), .bell(bell)
|
||||
.lf_cr(sw_r[3]), .clear_req(clr_sync[1]), .def_fg(def_fg),
|
||||
.smooth_sw(sw_r[8]), .smooth_fast(sw_r[9]), .frame_tick(frame_tick),
|
||||
.addr(t_addr), .we(t_we), .wdata(t_wdata), .rdata(t_rdata),
|
||||
.row(cur_row), .col(cur_col), .cur_vis(cur_vis),
|
||||
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
|
||||
.resp_byte(resp_byte), .resp_wr(resp_wr), .resp_full(rq_full),
|
||||
.cursor_app(cursor_app), .keypad_app(keypad_app), .lnm(lnm),
|
||||
.dec_leds(dec_leds), .bell(bell)
|
||||
);
|
||||
|
||||
wire [11:0] raddr;
|
||||
wire [8:0] rdata;
|
||||
wire [11:0] v_addr;
|
||||
wire [17:0] v_data;
|
||||
|
||||
char_ram screen (
|
||||
.clk(clk), .we(we), .waddr(waddr), .wdata(wdata),
|
||||
.raddr(raddr), .rdata(rdata)
|
||||
.clk(clk),
|
||||
.a_addr(t_addr), .a_we(t_we), .a_wdata(t_wdata), .a_rdata(t_rdata),
|
||||
.b_addr(v_addr), .b_rdata(v_data)
|
||||
);
|
||||
|
||||
reg [11:0] fg;
|
||||
always @(posedge clk)
|
||||
case (sw_r[5:4])
|
||||
2'b00: fg <= 12'h3F3; // green
|
||||
2'b01: fg <= 12'hFA0; // amber
|
||||
2'b10: fg <= 12'hDDD; // white
|
||||
2'b11: fg <= 12'h0EF; // cyan
|
||||
endcase
|
||||
|
||||
text_display #(.FONT_FILE(FONT_FILE)) video (
|
||||
.clk(clk), .rst(rst), .top(top), .cur_row(cur_row), .cur_col(cur_col),
|
||||
.cur_vis(cur_vis), .fg(fg), .bg(12'h000),
|
||||
.ram_addr(raddr), .ram_data(rdata),
|
||||
.red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .hsync(Hsync), .vsync(Vsync)
|
||||
.clk(clk), .rst(rst), .cur_row(cur_row), .cur_col(cur_col), .cur_vis(cur_vis),
|
||||
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
|
||||
.ram_addr(v_addr), .ram_data(v_data),
|
||||
.red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .hsync(Hsync), .vsync(Vsync),
|
||||
.frame_tick(frame_tick)
|
||||
);
|
||||
|
||||
// ----------------------------------------------------- status displays
|
||||
@@ -215,13 +275,13 @@ module basys3_terminal #(
|
||||
always @(posedge clk) begin
|
||||
if (rx_valid) last_rx <= rx_byte;
|
||||
if (scan_valid) last_scan <= scan;
|
||||
if (tx_start) last_tx <= kq;
|
||||
if (tx_start) last_tx <= tx_byte;
|
||||
rx_led <= rx_valid ? 23'h7FFFFF : rx_led - (rx_led != 0);
|
||||
kb_led <= scan_valid ? 23'h7FFFFF : kb_led - (kb_led != 0);
|
||||
bell_led <= bell ? 23'h7FFFFF : bell_led - (bell_led != 0);
|
||||
end
|
||||
|
||||
assign led = {kb_led != 0, rx_led != 0, caps, bell_led != 0, 4'b0000, last_rx};
|
||||
assign led = {kb_led != 0, rx_led != 0, caps, bell_led != 0, dec_leds[3:0], last_rx};
|
||||
assign dp = 1'b1;
|
||||
|
||||
sevenseg digits (.clk(clk), .value({last_scan, last_tx}), .seg(seg), .an(an));
|
||||
|
||||
Reference in new issue
Block a user