1280x1024 display: 80x32 big font or 132x64 (DECCOLM)
The display runs at 1280x1024 60 Hz from a second MMCM (108 MHz pixel clock), one pixel per clock through a four-stage pipeline. 80 columns show 80x32 cells of 16x32 pixels (the 8x16 font doubled); CSI ?3 h switches to 132x64 cells of 8x16 pixels, centred, and CSI ?3 l back, both clearing the screen and margins as a VT100 does. The 320x240 graphics layer is drawn 4x4 in the top 960 lines, so 80-column row r still meets graphics line 8(r-1). The terminal engine has 6-bit rows and 8-bit columns, a 132-cell row stride in both layouts (so the copy engine is unchanged), 132 tab stops and 3-digit cursor reports. The character RAM holds two 132x64 pages (normal and alternate) and is read on the pixel clock. BASIC's LOCATE takes rows up to 64 and columns up to 132. terminfo has basys3 (80x32) and basys3-w (132x64). The testbench reads the 132-cell layout, checks 1280x1024 sync timing, captures 1280x1024 frames and tests DECCOLM both ways. Timing met (0.044 ns at 90 MHz CPU, 108 MHz pixel); 46 of 50 BRAMs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
634e314010
commit
88b5942da5
12 files changed
+354
-220
No files matched your search
+47
-15
@@ -237,7 +237,7 @@ 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*200-1:0] BANNER = {
|
||||
"\033[1mBasys 3 VT220 Terminal\033[0m 80x30 ",
|
||||
"\033[1mBasys 3 VT220 Terminal\033[0m 80x32 ",
|
||||
"\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"};
|
||||
@@ -264,6 +264,27 @@ module basys3_terminal #(
|
||||
BUFG cpu_bufg (.I(cpu_clk_mmcm), .O(cpu_clk));
|
||||
`endif
|
||||
|
||||
// ------------------------------------------------- pixel clock, 108 MHz
|
||||
// 1280x1024 at 60 Hz: 100 MHz x 10.125 / 9.375
|
||||
wire pix_clk;
|
||||
`ifdef SIMULATION
|
||||
assign pix_clk = clk;
|
||||
`else
|
||||
wire pix_fb, pix_clk_mmcm;
|
||||
MMCME2_BASE #(
|
||||
.CLKIN1_PERIOD(10.0), .DIVCLK_DIVIDE(1),
|
||||
.CLKFBOUT_MULT_F(10.125), .CLKOUT0_DIVIDE_F(9.375)
|
||||
) pix_mmcm (
|
||||
.CLKIN1(clk), .CLKFBIN(pix_fb), .CLKFBOUT(pix_fb), .CLKFBOUTB(),
|
||||
.CLKOUT0(pix_clk_mmcm), .CLKOUT0B(), .CLKOUT1(), .CLKOUT1B(), .CLKOUT2(),
|
||||
.CLKOUT2B(), .CLKOUT3(), .CLKOUT3B(), .CLKOUT4(), .CLKOUT5(), .CLKOUT6(),
|
||||
.LOCKED(), .PWRDWN(1'b0), .RST(1'b0)
|
||||
);
|
||||
BUFG pix_bufg (.I(pix_clk_mmcm), .O(pix_clk));
|
||||
`endif
|
||||
(* ASYNC_REG = "TRUE" *) reg [1:0] pix_rst_s;
|
||||
always @(posedge pix_clk) pix_rst_s <= {pix_rst_s[0], rst};
|
||||
|
||||
(* ASYNC_REG = "TRUE" *) reg [2:0] cpu_rst_s;
|
||||
always @(posedge cpu_clk) cpu_rst_s <= {cpu_rst_s[1:0], rst | zrst_sync[1] | (cad_t != 0) | !locked};
|
||||
|
||||
@@ -311,7 +332,7 @@ module basys3_terminal #(
|
||||
.rx_req(zrx_req), .rx_data(zrx_data), .rx_ack(zrx_ack),
|
||||
.tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack),
|
||||
.seg_val(z80_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]),
|
||||
.vclk(clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
||||
.vclk(pix_clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
||||
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1])
|
||||
);
|
||||
|
||||
@@ -379,16 +400,24 @@ module basys3_terminal #(
|
||||
);
|
||||
|
||||
// ------------------------------------------------------------- terminal
|
||||
wire [11:0] t_addr;
|
||||
wire alt_scr;
|
||||
wire [13:0] t_addr;
|
||||
wire alt_scr, wide;
|
||||
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 [5:0] cur_row, stop, sbot;
|
||||
wire [4:0] sm_off;
|
||||
wire [7:0] cur_col;
|
||||
wire cur_vis, sm_on, sm_dir;
|
||||
wire [3:0] dec_leds;
|
||||
wire bell;
|
||||
wire frame_tick;
|
||||
wire frame_tick, pix_frame;
|
||||
|
||||
// start of vertical blanking, from the pixel clock to this one
|
||||
reg frame_t = 1'b0;
|
||||
always @(posedge pix_clk) if (pix_frame) frame_t <= ~frame_t;
|
||||
(* ASYNC_REG = "TRUE" *) reg [2:0] frame_s = 3'd0;
|
||||
always @(posedge clk) frame_s <= {frame_s[1:0], frame_t};
|
||||
assign frame_tick = frame_s[2] ^ frame_s[1];
|
||||
|
||||
term_ctrl term (
|
||||
.clk(clk), .rst(rst), .in_byte(tq), .in_empty(tq_empty), .in_rd(tq_rd),
|
||||
@@ -399,25 +428,28 @@ module basys3_terminal #(
|
||||
.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), .alt_scr(alt_scr)
|
||||
.dec_leds(dec_leds), .bell(bell), .alt_scr(alt_scr), .wide(wide)
|
||||
);
|
||||
|
||||
wire [11:0] v_addr;
|
||||
wire [13:0] v_addr;
|
||||
wire [17:0] v_data;
|
||||
|
||||
// the alternate screen (the Z-80 monitor uses it) has no graphics layer
|
||||
// The display reads the terminal's cursor and modes across clocks: they
|
||||
// change rarely and a stale value lasts one pixel.
|
||||
// The alternate screen (the Z-80 monitor uses it) has no graphics layer.
|
||||
char_ram screen (
|
||||
.clk(clk),
|
||||
.a_addr({alt_scr, t_addr}), .a_we(t_we), .a_wdata(t_wdata), .a_rdata(t_rdata),
|
||||
.b_addr({alt_scr, v_addr}), .b_rdata(v_data)
|
||||
.clk(clk), .a_alt(alt_scr),
|
||||
.a_addr(t_addr), .a_we(t_we), .a_wdata(t_wdata), .a_rdata(t_rdata),
|
||||
.vclk(pix_clk), .b_alt(alt_scr), .b_addr(v_addr), .b_rdata(v_data)
|
||||
);
|
||||
|
||||
text_display #(.FONT_FILE(FONT_FILE)) video (
|
||||
.clk(clk), .rst(rst), .cur_row(cur_row), .cur_col(cur_col), .cur_vis(cur_vis),
|
||||
.clk(pix_clk), .rst(pix_rst_s[1]), .wide(wide),
|
||||
.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), .gfx_addr(gfx_addr), .gfx_pix(alt_scr ? 4'd0 : gfx_pix),
|
||||
.red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .hsync(Hsync), .vsync(Vsync),
|
||||
.frame_tick(frame_tick)
|
||||
.frame_tick(pix_frame)
|
||||
);
|
||||
|
||||
// ----------------------------------------------------- status displays
|
||||
|
||||
+119
-99
@@ -1,7 +1,9 @@
|
||||
`timescale 1ns / 1ps
|
||||
|
||||
// VT220 terminal engine with ANSI colour. Consumes received bytes and keeps
|
||||
// the 80x30 new_cell buffer (row-major, address = row*80 + col) up to date.
|
||||
// the character buffer up to date: 80x32, or 132x64 after DECCOLM (CSI ?3h).
|
||||
// The buffer is row-major with a 132-cell stride in both (address = row*132 +
|
||||
// col), so scrolling copies whole 132-cell rows either way.
|
||||
//
|
||||
// Cell format: {blink, underline, bg[3:0], fg[3:0], CP437 code}. Reverse,
|
||||
// bold and concealed text are resolved into the colours when a new_cell is written.
|
||||
@@ -10,7 +12,8 @@
|
||||
// ESC 7 8 D E H M Z c = > ESC ( ) <0|A|B> ESC # 8
|
||||
// CSI A B C D E F G H I J K L M P S T X Z @ ` a d e f g h l m n q r s u c
|
||||
// CSI ? J K h l n CSI > c CSI ! p
|
||||
// Modes: IRM(4) LNM(20) DECCKM(?1) DECSCLM(?4) DECOM(?6) DECAWM(?7) DECTCEM(?25)
|
||||
// Modes: IRM(4) LNM(20) DECCKM(?1) DECCOLM(?3) DECSCLM(?4) DECOM(?6) DECAWM(?7)
|
||||
// DECTCEM(?25)
|
||||
// alternate screen ?47 (parameters stop at 255, so not ?1047/?1049)
|
||||
// SGR 0 1 4 5 7 8 21-28 30-49 90-107, 38/48;5;n and 38/48;2;r;g;b (approximated)
|
||||
// DECLL (CSI n q) drives four LEDs.
|
||||
@@ -31,16 +34,16 @@ module term_ctrl (
|
||||
input smooth_fast,
|
||||
input frame_tick, // start of vertical blanking
|
||||
// character RAM port
|
||||
output reg [11:0] addr,
|
||||
output reg [13:0] addr,
|
||||
output reg we,
|
||||
output reg [17:0] wdata,
|
||||
input [17:0] rdata,
|
||||
// to the display
|
||||
output reg [4:0] row,
|
||||
output reg [6:0] col,
|
||||
output reg [5:0] row,
|
||||
output reg [7:0] col,
|
||||
output reg cur_vis,
|
||||
output reg [4:0] stop, // scroll region, inclusive
|
||||
output reg [4:0] sbot,
|
||||
output reg [5:0] stop, // scroll region, inclusive
|
||||
output reg [5:0] sbot,
|
||||
output reg sm_on,
|
||||
output reg sm_dir, // 0 = scrolling up, 1 = down
|
||||
output reg [4:0] sm_off,
|
||||
@@ -54,11 +57,16 @@ module term_ctrl (
|
||||
output reg lnm,
|
||||
output reg [3:0] dec_leds,
|
||||
output reg bell,
|
||||
output reg alt_scr // showing and writing the alternate screen
|
||||
output reg alt_scr, // showing and writing the alternate screen
|
||||
output reg wide // 132 columns (DECCOLM)
|
||||
);
|
||||
localparam [4:0] LAST_ROW = 5'd29;
|
||||
localparam [6:0] LAST_COL = 7'd79;
|
||||
localparam [11:0] CELLS = 12'd2400;
|
||||
localparam [13:0] STRIDE = 14'd132;
|
||||
localparam [13:0] ALL = 14'd8448; // 132 x 64: clears either layout
|
||||
wire [5:0] LAST_ROW = wide ? 6'd63 : 6'd31;
|
||||
wire [7:0] LAST_COL = wide ? 8'd131 : 8'd79;
|
||||
wire [7:0] NCOLS = wide ? 8'd132 : 8'd80;
|
||||
wire [6:0] NROWS = wide ? 7'd64 : 7'd32;
|
||||
wire [13:0] CELLS = wide ? 14'd8448 : 14'd4224;
|
||||
|
||||
localparam [3:0] S_IDLE = 4'd0, S_DISP = 4'd1, S_FILL = 4'd2, S_CRD = 4'd3,
|
||||
S_CWAIT = 4'd4, S_CWR = 4'd5, S_PLOOP = 4'd6, S_RESP = 4'd7,
|
||||
@@ -77,11 +85,12 @@ module term_ctrl (
|
||||
reg [3:0] fg, bg;
|
||||
reg [1:0] g0, g1; // 0 ASCII, 1 DEC special graphics, 2 UK
|
||||
reg gl; // 0 = G0 active, 1 = G1 (SO)
|
||||
reg [79:0] tabs;
|
||||
reg [131:0] tabs;
|
||||
reg colm_clr; // DECCOLM: clear the screen when idle
|
||||
|
||||
// saved cursor (DECSC)
|
||||
reg [4:0] sv_row;
|
||||
reg [6:0] sv_col;
|
||||
reg [5:0] sv_row;
|
||||
reg [7:0] sv_col;
|
||||
reg sv_pend, sv_om, sv_gl, sv_bold, sv_ul, sv_blink, sv_rev, sv_conceal;
|
||||
reg [3:0] sv_fg, sv_bg;
|
||||
reg [1:0] sv_g0, sv_g1;
|
||||
@@ -94,12 +103,12 @@ module term_ctrl (
|
||||
|
||||
// scroll request
|
||||
reg sc_dir;
|
||||
reg [4:0] sc_t, sc_b;
|
||||
reg [5:0] sc_t, sc_b;
|
||||
reg [7:0] sc_n;
|
||||
reg [5:0] sc_h, sc_k; // region height, lines to move
|
||||
reg [6:0] sc_h, sc_k; // region height, lines to move
|
||||
|
||||
// memory copy / fill engine
|
||||
reg [11:0] c_src, c_dst, c_cnt, f_addr, f_cnt;
|
||||
reg [13:0] c_src, c_dst, c_cnt, f_addr, f_cnt;
|
||||
reg c_dir;
|
||||
reg [17:0] f_cell;
|
||||
|
||||
@@ -119,12 +128,12 @@ module term_ctrl (
|
||||
integer i;
|
||||
|
||||
// ------------------------------------------------------------ helpers
|
||||
function [11:0] rc(input [4:0] r, input [6:0] cc);
|
||||
rc = {1'b0, r, 6'b0} + {3'b0, r, 4'b0} + {5'b0, cc};
|
||||
function [13:0] rc(input [5:0] r, input [7:0] cc);
|
||||
rc = {1'b0, r, 7'b0} + {6'b0, r, 2'b0} + {6'b0, cc};
|
||||
endfunction
|
||||
|
||||
function [11:0] rows80(input [5:0] n);
|
||||
rows80 = {n, 6'b0} + {2'b0, n, 4'b0};
|
||||
function [13:0] rows(input [6:0] n); // n whole rows of cells
|
||||
rows = {n, 7'b0} + {5'b0, n, 2'b0};
|
||||
endfunction
|
||||
|
||||
function [7:0] acc(input [7:0] p, input [7:0] d);
|
||||
@@ -187,20 +196,20 @@ module term_ctrl (
|
||||
end
|
||||
endfunction
|
||||
|
||||
function [6:0] next_tab(input [79:0] t, input [6:0] cc);
|
||||
function [7:0] next_tab(input [131:0] t, input [7:0] cc, input [7:0] last);
|
||||
integer k;
|
||||
begin
|
||||
next_tab = LAST_COL;
|
||||
for (k = 79; k >= 0; k = k - 1)
|
||||
if (k > cc && t[k]) next_tab = k;
|
||||
next_tab = last;
|
||||
for (k = 131; k >= 0; k = k - 1)
|
||||
if (k > cc && k < last && t[k]) next_tab = k;
|
||||
end
|
||||
endfunction
|
||||
|
||||
function [6:0] prev_tab(input [79:0] t, input [6:0] cc);
|
||||
function [7:0] prev_tab(input [131:0] t, input [7:0] cc);
|
||||
integer k;
|
||||
begin
|
||||
prev_tab = 7'd0;
|
||||
for (k = 0; k < 80; k = k + 1)
|
||||
prev_tab = 8'd0;
|
||||
for (k = 0; k < 132; k = k + 1)
|
||||
if (k < cc && t[k]) prev_tab = k;
|
||||
end
|
||||
endfunction
|
||||
@@ -210,12 +219,12 @@ module term_ctrl (
|
||||
wire [7:0] p0 = par[0];
|
||||
wire [7:0] p1 = par[1];
|
||||
reg [7:0] n8; // count parameter (default 1), registered
|
||||
reg [6:0] nc; // ... clamped to the rest of the line
|
||||
wire [6:0] room = 7'd80 - col; // cells from cursor to end of line
|
||||
reg [7:0] nc; // ... clamped to the rest of the line
|
||||
wire [7:0] room = NCOLS - col; // cells from cursor to end of line
|
||||
wire [7:0] n8_c = p0 == 0 ? 8'd1 : p0;
|
||||
always @(posedge clk) begin
|
||||
n8 <= n8_c;
|
||||
nc <= n8_c > room ? room : n8_c[6:0];
|
||||
nc <= n8_c > room ? room : n8_c;
|
||||
end
|
||||
|
||||
wire [3:0] fgb = bold ? (fg | 4'd8) : fg;
|
||||
@@ -229,29 +238,29 @@ module term_ctrl (
|
||||
wire smooth = sclm | smooth_sw;
|
||||
wire [4:0] sm_step = smooth_fast ? 5'd4 : 5'd2;
|
||||
|
||||
wire [4:0] up_lim = row >= stop ? stop : 5'd0;
|
||||
wire [4:0] dn_lim = row <= sbot ? sbot : LAST_ROW;
|
||||
wire [4:0] row_up = (row - up_lim > n8) ? row - n8 : up_lim;
|
||||
wire [4:0] row_dn = (dn_lim - row > n8) ? row + n8 : dn_lim;
|
||||
wire [6:0] col_rt = (LAST_COL - col > n8) ? col + n8 : LAST_COL;
|
||||
wire [6:0] col_lt = (col > n8) ? col - n8 : 7'd0;
|
||||
wire [5:0] up_lim = row >= stop ? stop : 6'd0;
|
||||
wire [5:0] dn_lim = row <= sbot ? sbot : LAST_ROW;
|
||||
wire [5:0] row_up = (row - up_lim > n8) ? row - n8 : up_lim;
|
||||
wire [5:0] row_dn = (dn_lim - row > n8) ? row + n8 : dn_lim;
|
||||
wire [7:0] col_rt = (LAST_COL - col > n8) ? col + n8 : LAST_COL;
|
||||
wire [7:0] col_lt = (col > n8) ? col - n8 : 8'd0;
|
||||
|
||||
wire [7:0] r_rel = p0 == 0 ? 8'd0 : p0 - 1'b1;
|
||||
wire [8:0] r_abs = (om ? stop : 5'd0) + r_rel;
|
||||
wire [4:0] r_max = om ? sbot : LAST_ROW;
|
||||
wire [4:0] row_p0 = r_abs > r_max ? r_max : r_abs[4:0];
|
||||
wire [6:0] col_p0 = p0 == 0 ? 7'd0 : p0 > 80 ? LAST_COL : p0 - 1'b1;
|
||||
wire [6:0] col_p1 = p1 == 0 ? 7'd0 : p1 > 80 ? LAST_COL : p1 - 1'b1;
|
||||
wire [8:0] r_abs = (om ? stop : 6'd0) + r_rel;
|
||||
wire [5:0] r_max = om ? sbot : LAST_ROW;
|
||||
wire [5:0] row_p0 = r_abs > r_max ? r_max : r_abs[5:0];
|
||||
wire [7:0] col_p0 = p0 == 0 ? 8'd0 : p0 > NCOLS ? LAST_COL : p0 - 1'b1;
|
||||
wire [7:0] col_p1 = p1 == 0 ? 8'd0 : p1 > NCOLS ? LAST_COL : p1 - 1'b1;
|
||||
|
||||
wire [11:0] here = rc(row, col);
|
||||
wire [4:0] rep_row = (om ? row - stop : row) + 1'b1;
|
||||
wire [6:0] rep_col = col + 1'b1;
|
||||
wire [13:0] here = rc(row, col);
|
||||
wire [6:0] rep_row = (om ? row - stop : row) + 1'b1;
|
||||
wire [7:0] rep_col = col + 1'b1;
|
||||
reg [7:0] pv; // parameter being processed, registered
|
||||
reg pv_ok;
|
||||
|
||||
// ------------------------------------------------------------ tasks
|
||||
task op(input [11:0] src, input [11:0] dst, input [11:0] ccnt, input dir,
|
||||
input [11:0] fa, input [11:0] fcnt, input [17:0] fcell, input [3:0] rs);
|
||||
task op(input [13:0] src, input [13:0] dst, input [13:0] ccnt, input dir,
|
||||
input [13:0] fa, input [13:0] fcnt, input [17:0] fcell, input [3:0] rs);
|
||||
begin
|
||||
c_src <= src; c_dst <= dst; c_cnt <= ccnt; c_dir <= dir;
|
||||
f_addr <= fa; f_cnt <= fcnt; f_cell <= fcell;
|
||||
@@ -260,14 +269,14 @@ module term_ctrl (
|
||||
end
|
||||
endtask
|
||||
|
||||
task fill(input [11:0] fa, input [11:0] fcnt);
|
||||
op(12'd0, 12'd0, 12'd0, 1'b0, fa, fcnt, BLANK, S_IDLE);
|
||||
task fill(input [13:0] fa, input [13:0] fcnt);
|
||||
op(14'd0, 14'd0, 14'd0, 1'b0, fa, fcnt, BLANK, S_IDLE);
|
||||
endtask
|
||||
|
||||
// scroll rows t..b up (dir 0) or down (dir 1) by n lines
|
||||
// scroll rows t..b up (dir 0) or down (dir 1) by n lines; the copy and fill
|
||||
// ranges are worked out over the next two clocks (S_SCR1, S_SCR2)
|
||||
task scroll(input dir, input [4:0] t, input [4:0] b, input [7:0] n, input [3:0] rs);
|
||||
task scroll(input dir, input [5:0] t, input [5:0] b, input [7:0] n, input [3:0] rs);
|
||||
begin
|
||||
sc_dir <= dir;
|
||||
sc_t <= t;
|
||||
@@ -322,7 +331,7 @@ module term_ctrl (
|
||||
awm <= 1'b1;
|
||||
cur_vis <= 1'b1;
|
||||
alt_scr <= 1'b0;
|
||||
stop <= 5'd0;
|
||||
stop <= 6'd0;
|
||||
sbot <= LAST_ROW;
|
||||
{sv_row, sv_col, sv_pend, sv_om, sv_gl, sv_bold, sv_ul, sv_blink, sv_rev, sv_conceal} <= 0;
|
||||
{sv_g0, sv_g1, sv_bg} <= 0;
|
||||
@@ -334,13 +343,14 @@ module term_ctrl (
|
||||
begin
|
||||
soft_reset;
|
||||
{row, col} <= 0;
|
||||
{sclm, lnm} <= 2'b0;
|
||||
{sclm, lnm, wide, colm_clr} <= 4'b0;
|
||||
sbot <= 6'd31;
|
||||
dec_leds <= 4'd0;
|
||||
sm_on <= 1'b0;
|
||||
sm_off <= 5'd0;
|
||||
ps <= P_NORM;
|
||||
for (i = 0; i < 80; i = i + 1) tabs[i] <= i != 0 && i % 8 == 0;
|
||||
fill(12'd0, CELLS);
|
||||
for (i = 0; i < 132; i = i + 1) tabs[i] <= i != 0 && i % 8 == 0;
|
||||
fill(14'd0, ALL);
|
||||
end
|
||||
endtask
|
||||
|
||||
@@ -352,17 +362,22 @@ module term_ctrl (
|
||||
end
|
||||
endtask
|
||||
|
||||
function [7:0] tens(input [6:0] v);
|
||||
tens = "0" + v / 7'd10;
|
||||
function [7:0] tens(input [7:0] v);
|
||||
tens = "0" + (v / 8'd10) % 8'd10;
|
||||
endfunction
|
||||
|
||||
function [7:0] ones(input [6:0] v);
|
||||
ones = "0" + v % 7'd10;
|
||||
function [7:0] ones(input [7:0] v);
|
||||
ones = "0" + v % 8'd10;
|
||||
endfunction
|
||||
|
||||
// ESC [ rr ; cc R, or ESC [ rr ; 1cc R past column 99
|
||||
task cursor_report;
|
||||
respond({8'h1B, "[", tens(rep_row), ones(rep_row), ";",
|
||||
tens(rep_col), ones(rep_col), "R", 32'd0}, 4'd8);
|
||||
if (rep_col >= 100)
|
||||
respond({8'h1B, "[", tens(rep_row), ones(rep_row), ";", "1",
|
||||
tens(rep_col), ones(rep_col), "R", 24'd0}, 4'd9);
|
||||
else
|
||||
respond({8'h1B, "[", tens(rep_row), ones(rep_row), ";",
|
||||
tens(rep_col), ones(rep_col), "R", 32'd0}, 4'd8);
|
||||
endtask
|
||||
|
||||
// one SGR parameter
|
||||
@@ -414,8 +429,13 @@ module term_ctrl (
|
||||
begin
|
||||
if (priv) begin
|
||||
if (v == 1) cursor_app <= on;
|
||||
if (v == 3) begin // DECCOLM: 80x32 / 132x64, cleared
|
||||
wide <= on; colm_clr <= 1'b1;
|
||||
{row, col, pend, om, stop} <= 0;
|
||||
sbot <= on ? 6'd63 : 6'd31;
|
||||
end
|
||||
if (v == 4) sclm <= on;
|
||||
if (v == 6) begin om <= on; row <= on ? stop : 5'd0; col <= 7'd0; pend <= 1'b0; end
|
||||
if (v == 6) begin om <= on; row <= on ? stop : 6'd0; col <= 8'd0; pend <= 1'b0; end
|
||||
if (v == 7) awm <= on;
|
||||
if (v == 25) cur_vis <= on;
|
||||
if (v == 47) alt_scr <= on;
|
||||
@@ -447,9 +467,9 @@ module term_ctrl (
|
||||
cursor_app <= 1'b0;
|
||||
end else case (st)
|
||||
S_IDLE:
|
||||
if (clear_req) begin
|
||||
{row, col, pend} <= 0;
|
||||
fill(12'd0, CELLS);
|
||||
if (clear_req || colm_clr) begin
|
||||
{row, col, pend, colm_clr} <= 0;
|
||||
fill(14'd0, ALL);
|
||||
end else if (!in_empty && !in_rd) begin
|
||||
c <= in_byte;
|
||||
in_rd <= 1'b1;
|
||||
@@ -459,16 +479,16 @@ module term_ctrl (
|
||||
// ---- scroll: size the move, then set up the copy and fill
|
||||
S_SCR1: begin
|
||||
sc_h <= sc_b - sc_t + 1'b1;
|
||||
sc_k <= sc_n > sc_b - sc_t ? sc_b - sc_t + 1'b1 : sc_n[5:0];
|
||||
sc_k <= sc_n > sc_b - sc_t ? sc_b - sc_t + 1'b1 : sc_n[6:0];
|
||||
st <= S_SCR2;
|
||||
end
|
||||
S_SCR2:
|
||||
if (!sc_dir)
|
||||
op(rc(sc_t + sc_k, 0), rc(sc_t, 0), rows80(sc_h - sc_k), 1'b0,
|
||||
rc(sc_b - sc_k + 1'b1, 0), rows80(sc_k), BLANK, ret_st);
|
||||
op(rc(sc_t + sc_k, 0), rc(sc_t, 0), rows(sc_h - sc_k), 1'b0,
|
||||
rc(sc_b - sc_k + 1'b1, 0), rows(sc_k), BLANK, ret_st);
|
||||
else
|
||||
op(rc(sc_b - sc_k + 1'b1, 0) - 1'b1, rc(sc_b + 1'b1, 0) - 1'b1, rows80(sc_h - sc_k), 1'b1,
|
||||
rc(sc_t, 0), rows80(sc_k), BLANK, ret_st);
|
||||
op(rc(sc_b - sc_k + 1'b1, 0) - 1'b1, rc(sc_b + 1'b1, 0) - 1'b1, rows(sc_h - sc_k), 1'b1,
|
||||
rc(sc_t, 0), rows(sc_k), BLANK, ret_st);
|
||||
|
||||
// ---- copy c_cnt cells, then fill f_cnt cells, then go to ret_st
|
||||
S_OP:
|
||||
@@ -521,7 +541,7 @@ module term_ctrl (
|
||||
end
|
||||
|
||||
S_TAB: begin
|
||||
col <= tdir ? prev_tab(tabs, col) : next_tab(tabs, col);
|
||||
col <= tdir ? prev_tab(tabs, col) : next_tab(tabs, col, LAST_COL);
|
||||
rep <= rep - 1'b1;
|
||||
if (rep == 1) st <= S_IDLE;
|
||||
end
|
||||
@@ -569,13 +589,13 @@ module term_ctrl (
|
||||
case (c)
|
||||
8'h07: bell <= 1'b1;
|
||||
8'h08: begin pend <= 1'b0; if (col != 0) col <= col - 1'b1; end
|
||||
8'h09: begin pend <= 1'b0; col <= next_tab(tabs, col); end
|
||||
8'h09: begin pend <= 1'b0; col <= next_tab(tabs, col, LAST_COL); end
|
||||
8'h0A, 8'h0B, 8'h0C: begin
|
||||
pend <= 1'b0;
|
||||
if (lf_cr || lnm) col <= 7'd0;
|
||||
if (lf_cr || lnm) col <= 8'd0;
|
||||
line_feed(S_IDLE);
|
||||
end
|
||||
8'h0D: begin pend <= 1'b0; col <= 7'd0; end
|
||||
8'h0D: begin pend <= 1'b0; col <= 8'd0; end
|
||||
8'h0E: gl <= 1'b1;
|
||||
8'h0F: gl <= 1'b0;
|
||||
default: ;
|
||||
@@ -586,12 +606,12 @@ module term_ctrl (
|
||||
P_NORM:
|
||||
if (pend && awm) begin
|
||||
pend <= 1'b0;
|
||||
col <= 7'd0;
|
||||
col <= 8'd0;
|
||||
line_feed(S_DISP); // wrap, then print this byte
|
||||
end else if (irm && col != LAST_COL)
|
||||
// insert mode: shift the rest of the line right first
|
||||
op(rc(row, LAST_COL - 1'b1), rc(row, LAST_COL), {5'd0, LAST_COL - col}, 1'b1,
|
||||
12'd0, 12'd0, BLANK, S_PUT);
|
||||
op(rc(row, LAST_COL - 1'b1), rc(row, LAST_COL), {6'd0, LAST_COL - col}, 1'b1,
|
||||
14'd0, 14'd0, BLANK, S_PUT);
|
||||
else
|
||||
st <= S_PUT;
|
||||
|
||||
@@ -610,7 +630,7 @@ module term_ctrl (
|
||||
cint <= 8'd0;
|
||||
end
|
||||
"D": begin pend <= 1'b0; line_feed(S_IDLE); end
|
||||
"E": begin pend <= 1'b0; col <= 7'd0; line_feed(S_IDLE); end
|
||||
"E": begin pend <= 1'b0; col <= 8'd0; line_feed(S_IDLE); end
|
||||
"M": begin pend <= 1'b0; reverse_index; end
|
||||
"H": tabs[col] <= 1'b1;
|
||||
"7": begin
|
||||
@@ -641,7 +661,7 @@ module term_ctrl (
|
||||
"#": if (c == "8") begin // DECALN: fill the screen with E
|
||||
{row, col, pend, stop} <= 0;
|
||||
sbot <= LAST_ROW;
|
||||
op(12'd0, 12'd0, 12'd0, 1'b0, 12'd0, CELLS, {2'b00, 4'd0, def_fg, "E"}, S_IDLE);
|
||||
op(14'd0, 14'd0, 14'd0, 1'b0, 14'd0, CELLS, {2'b00, 4'd0, def_fg, "E"}, S_IDLE);
|
||||
end
|
||||
default: ;
|
||||
endcase
|
||||
@@ -684,14 +704,14 @@ module term_ctrl (
|
||||
"J": begin
|
||||
pend <= 1'b0;
|
||||
if (p0 == 0) fill(here, CELLS - here);
|
||||
else if (p0 == 1) fill(12'd0, here + 1'b1);
|
||||
else if (p0 == 2) fill(12'd0, CELLS);
|
||||
else if (p0 == 1) fill(14'd0, here + 1'b1);
|
||||
else if (p0 == 2) fill(14'd0, CELLS);
|
||||
end
|
||||
"K": begin
|
||||
pend <= 1'b0;
|
||||
if (p0 == 0) fill(here, room);
|
||||
else if (p0 == 1) fill(rc(row, 0), col + 1'b1);
|
||||
else if (p0 == 2) fill(rc(row, 0), 12'd80);
|
||||
else if (p0 == 2) fill(rc(row, 0), STRIDE);
|
||||
end
|
||||
"n": if (p0 == 6) cursor_report;
|
||||
default: ;
|
||||
@@ -701,8 +721,8 @@ module term_ctrl (
|
||||
"B", "e": begin pend <= 1'b0; row <= row_dn; end
|
||||
"C", "a": begin pend <= 1'b0; col <= col_rt; end
|
||||
"D": begin pend <= 1'b0; col <= col_lt; end
|
||||
"E": begin pend <= 1'b0; row <= row_dn; col <= 7'd0; end
|
||||
"F": begin pend <= 1'b0; row <= row_up; col <= 7'd0; end
|
||||
"E": begin pend <= 1'b0; row <= row_dn; col <= 8'd0; end
|
||||
"F": begin pend <= 1'b0; row <= row_up; col <= 8'd0; end
|
||||
"G", "`": begin pend <= 1'b0; col <= col_p0; end
|
||||
"d": begin pend <= 1'b0; row <= row_p0; end
|
||||
"H", "f": begin pend <= 1'b0; row <= row_p0; col <= col_p1; end
|
||||
@@ -711,47 +731,47 @@ module term_ctrl (
|
||||
"J": begin
|
||||
pend <= 1'b0;
|
||||
if (p0 == 0) fill(here, CELLS - here);
|
||||
else if (p0 == 1) fill(12'd0, here + 1'b1);
|
||||
else if (p0 == 2 || p0 == 3) fill(12'd0, CELLS);
|
||||
else if (p0 == 1) fill(14'd0, here + 1'b1);
|
||||
else if (p0 == 2 || p0 == 3) fill(14'd0, CELLS);
|
||||
end
|
||||
"K": begin
|
||||
pend <= 1'b0;
|
||||
if (p0 == 0) fill(here, room);
|
||||
else if (p0 == 1) fill(rc(row, 0), col + 1'b1);
|
||||
else if (p0 == 2) fill(rc(row, 0), 12'd80);
|
||||
else if (p0 == 2) fill(rc(row, 0), STRIDE);
|
||||
end
|
||||
"L": if (row >= stop && row <= sbot) begin
|
||||
pend <= 1'b0; col <= 7'd0;
|
||||
pend <= 1'b0; col <= 8'd0;
|
||||
scroll(1'b1, row, sbot, n8, S_IDLE);
|
||||
end
|
||||
"M": if (row >= stop && row <= sbot) begin
|
||||
pend <= 1'b0; col <= 7'd0;
|
||||
pend <= 1'b0; col <= 8'd0;
|
||||
scroll(1'b0, row, sbot, n8, S_IDLE);
|
||||
end
|
||||
"@": begin
|
||||
pend <= 1'b0;
|
||||
op(rc(row, LAST_COL - nc), rc(row, LAST_COL), room - nc, 1'b1,
|
||||
here, nc, BLANK, S_IDLE);
|
||||
op(rc(row, LAST_COL - nc), rc(row, LAST_COL), {6'd0, room - nc}, 1'b1,
|
||||
here, {6'd0, nc}, BLANK, S_IDLE);
|
||||
end
|
||||
"P": begin
|
||||
pend <= 1'b0;
|
||||
op(rc(row, col + nc), here, room - nc, 1'b0,
|
||||
rc(row, 7'd80 - nc), nc, BLANK, S_IDLE);
|
||||
op(rc(row, col + nc), here, {6'd0, room - nc}, 1'b0,
|
||||
rc(row, NCOLS - nc), {6'd0, nc}, BLANK, S_IDLE);
|
||||
end
|
||||
"X": begin pend <= 1'b0; fill(here, nc); end
|
||||
"X": begin pend <= 1'b0; fill(here, {6'd0, nc}); end
|
||||
"S": scroll(1'b0, stop, sbot, n8, S_IDLE);
|
||||
"T": scroll(1'b1, stop, sbot, n8, S_IDLE);
|
||||
"g": if (p0 == 0) tabs[col] <= 1'b0; else if (p0 == 3) tabs <= 80'd0;
|
||||
"g": if (p0 == 0) tabs[col] <= 1'b0; else if (p0 == 3) tabs <= 132'd0;
|
||||
"h": plist(K_SET);
|
||||
"l": plist(K_RST);
|
||||
"m": plist(K_SGR);
|
||||
"q": plist(K_LL);
|
||||
"r": begin
|
||||
if ((p0 == 0 ? 8'd1 : p0) < (p1 == 0 || p1 > 30 ? 8'd30 : p1)) begin
|
||||
stop <= p0 == 0 ? 5'd0 : p0 - 1'b1;
|
||||
sbot <= p1 == 0 || p1 > 30 ? LAST_ROW : p1 - 1'b1;
|
||||
row <= om ? (p0 == 0 ? 5'd0 : p0 - 1'b1) : 5'd0;
|
||||
col <= 7'd0;
|
||||
if ((p0 == 0 ? 8'd1 : p0) < (p1 == 0 || p1 > NROWS ? {1'b0, NROWS} : p1)) begin
|
||||
stop <= p0 == 0 ? 6'd0 : p0 - 1'b1;
|
||||
sbot <= p1 == 0 || p1 > NROWS ? LAST_ROW : p1 - 1'b1;
|
||||
row <= om ? (p0 == 0 ? 6'd0 : p0 - 1'b1) : 6'd0;
|
||||
col <= 8'd0;
|
||||
pend <= 1'b0;
|
||||
end
|
||||
end
|
||||
|
||||
+110
-74
@@ -1,29 +1,33 @@
|
||||
`timescale 1ns / 1ps
|
||||
|
||||
// 640x480 @ 60 Hz VGA text display: 80x30 cells of 8x16 pixels, 16 colours,
|
||||
// underline, blink, block cursor and smooth-scroll offset for the scroll region.
|
||||
// A 320x240 graphics layer (each pixel 2x2) shows through wherever the text is
|
||||
// background; graphics colour 0 is transparent.
|
||||
// Runs on the 100 MHz clock with a 25 MHz pixel enable. After each pixel tick:
|
||||
// clock 1 scanline values registered (row base address, glyph line)
|
||||
// clock 2 character RAM read
|
||||
// clock 3 font ROM read
|
||||
// clock 4 pixel out (next tick)
|
||||
|
||||
// 1280x1024 @ 60 Hz VGA text display (108 MHz pixel clock), two layouts:
|
||||
// 80 columns: 80x32 cells of 16x32 pixels (the 8x16 font doubled)
|
||||
// 132 columns: 132x64 cells of 8x16 pixels, centred (112-pixel side borders)
|
||||
// 16 colours, underline, blink, block cursor and smooth-scroll offset for the
|
||||
// scroll region. The character buffer has a 132-cell stride in both layouts.
|
||||
// A 320x240 graphics layer (each pixel 4x4, the top 960 lines, so 80-column
|
||||
// text row r still starts at graphics line 8(r-1)) shows through wherever the
|
||||
// text is background; colour 0 is transparent.
|
||||
// One pixel per clock, pipelined:
|
||||
// clock 0 position -> row, column, glyph line (registered)
|
||||
// clock 1 character RAM and graphics reads
|
||||
// clock 2 font ROM read
|
||||
// clock 3 colour out
|
||||
module text_display #(
|
||||
parameter FONT_FILE = "font.mem"
|
||||
) (
|
||||
input clk,
|
||||
input clk, // pixel clock, 108 MHz
|
||||
input rst,
|
||||
input [4:0] cur_row,
|
||||
input [6:0] cur_col,
|
||||
input wide, // 132-column layout
|
||||
input [5:0] cur_row,
|
||||
input [7:0] cur_col,
|
||||
input cur_vis,
|
||||
input [4:0] stop, // scroll region (rows, inclusive)
|
||||
input [4:0] sbot,
|
||||
input [5:0] stop, // scroll region (rows, inclusive)
|
||||
input [5:0] sbot,
|
||||
input sm_on, // smooth scroll in progress
|
||||
input sm_dir, // 0 = up, 1 = down
|
||||
input [4:0] sm_off, // pixels the region has moved
|
||||
output [11:0] ram_addr,
|
||||
input [4:0] sm_off, // font lines the region has moved
|
||||
output [13:0] ram_addr, // row * 132 + column
|
||||
input [17:0] ram_data, // {blink, underline, bg, fg, code}
|
||||
output [16:0] gfx_addr, // graphics pixel, read a clock later
|
||||
input [3:0] gfx_pix,
|
||||
@@ -34,57 +38,87 @@ module text_display #(
|
||||
output reg vsync,
|
||||
output reg frame_tick // one clock at the start of vertical blanking
|
||||
);
|
||||
localparam H_VIS = 640, H_FP = 16, H_SYNC = 96, H_TOTAL = 800;
|
||||
localparam V_VIS = 480, V_FP = 10, V_SYNC = 2, V_TOTAL = 525;
|
||||
localparam H_VIS = 1280, H_FP = 48, H_SYNC = 112, H_TOTAL = 1688;
|
||||
localparam V_VIS = 1024, V_FP = 1, V_SYNC = 3, V_TOTAL = 1066;
|
||||
localparam WIDE_X0 = 112; // 132 x 8 = 1056 pixels, centred
|
||||
|
||||
reg [1:0] div = 2'd0;
|
||||
reg [9:0] h, v;
|
||||
reg [5:0] frame = 6'd0;
|
||||
wire tick = div == 2'd3;
|
||||
reg [10:0] h, v;
|
||||
reg [5:0] frame = 6'd0;
|
||||
|
||||
always @(posedge clk) begin
|
||||
div <= rst ? 2'd0 : div + 1'b1;
|
||||
frame_tick <= tick && h == 0 && v == V_VIS;
|
||||
frame_tick <= h == 0 && v == V_VIS;
|
||||
if (rst) begin
|
||||
h <= 0;
|
||||
v <= 0;
|
||||
end else if (tick) begin
|
||||
if (h == H_TOTAL - 1) begin
|
||||
h <= 0;
|
||||
if (v == V_TOTAL - 1) begin
|
||||
v <= 0;
|
||||
frame <= frame + 1'b1;
|
||||
end else
|
||||
v <= v + 1'b1;
|
||||
end else if (h == H_TOTAL - 1) begin
|
||||
h <= 0;
|
||||
if (v == V_TOTAL - 1) begin
|
||||
v <= 0;
|
||||
frame <= frame + 1'b1;
|
||||
end else
|
||||
h <= h + 1'b1;
|
||||
end
|
||||
v <= v + 1'b1;
|
||||
end else
|
||||
h <= h + 1'b1;
|
||||
end
|
||||
|
||||
// which buffer row and glyph line this scanline shows
|
||||
wire in_region = sm_on && v < V_VIS && v[8:4] >= stop && v[8:4] <= sbot;
|
||||
wire [9:0] ys = !in_region ? v : sm_dir ? v - sm_off : v + sm_off;
|
||||
wire gap = in_region && (sm_dir ? v < {stop, 4'b0} + sm_off : ys[9:4] > sbot);
|
||||
// ---- clock 0: where this pixel is in the text, in font units
|
||||
// yl counts font lines (a 16-line font: 32 pixels a row in 80 columns)
|
||||
wire [9:0] yl = wide ? v[9:0] : {1'b0, v[9:1]};
|
||||
wire [10:0] xw = h - WIDE_X0;
|
||||
wire [10:0] xl = wide ? xw : {1'b0, h[10:1]}; // font pixels across
|
||||
wire text_on = wide ? h >= WIDE_X0 && h < WIDE_X0 + 1056 : 1'b1;
|
||||
wire in_region = sm_on && v < V_VIS && yl[9:4] >= stop && yl[9:4] <= sbot;
|
||||
wire [9:0] ys = !in_region ? yl : sm_dir ? yl - sm_off : yl + sm_off;
|
||||
wire gap = in_region && (sm_dir ? yl < {stop, 4'b0} + sm_off : ys[9:4] > sbot);
|
||||
wire [7:0] tcol = xl[10:3];
|
||||
wire [5:0] trow = ys[9:4];
|
||||
|
||||
reg [11:0] row_base;
|
||||
reg [4:0] srow;
|
||||
reg [3:0] line;
|
||||
reg blank_line;
|
||||
reg [13:0] a_base; // row * 132
|
||||
reg [7:0] a_col;
|
||||
reg [3:0] a_line;
|
||||
reg [2:0] a_bit;
|
||||
reg a_blank, a_text, a_vis, a_cur, a_hs, a_vs, a_gon;
|
||||
reg [16:0] a_gfx;
|
||||
always @(posedge clk) begin
|
||||
srow <= ys[8:4];
|
||||
row_base <= {1'b0, ys[8:4], 6'b0} + {3'b0, ys[8:4], 4'b0};
|
||||
line <= ys[3:0];
|
||||
blank_line <= gap;
|
||||
a_base <= {trow, 7'd0} + {6'd0, trow, 2'd0};
|
||||
a_col <= tcol;
|
||||
a_line <= ys[3:0];
|
||||
a_bit <= xl[2:0];
|
||||
a_blank <= gap;
|
||||
a_text <= text_on;
|
||||
a_vis <= h < H_VIS && v < V_VIS;
|
||||
a_cur <= cur_vis && frame[5] && tcol == cur_col && ys[9:4] == cur_row && !gap;
|
||||
a_hs <= h >= H_VIS + H_FP && h < H_VIS + H_FP + H_SYNC; // positive sync
|
||||
a_vs <= v >= V_VIS + V_FP && v < V_VIS + V_FP + V_SYNC;
|
||||
a_gon <= v < 960;
|
||||
a_gfx <= {v[9:2], 8'd0} + {2'd0, v[9:2], 6'd0} + {8'd0, h[10:2]};
|
||||
end
|
||||
|
||||
wire [6:0] tcol = h[9:3];
|
||||
assign ram_addr = row_base + {5'b0, tcol};
|
||||
assign gfx_addr = {v[8:1], 8'd0} + {2'd0, v[8:1], 6'd0} + {8'd0, h[9:1]};
|
||||
// ---- clock 1: character RAM and graphics reads
|
||||
assign ram_addr = a_base + {6'd0, a_col};
|
||||
assign gfx_addr = a_gfx;
|
||||
reg [3:0] b_line;
|
||||
reg [2:0] b_bit;
|
||||
reg b_blank, b_text, b_vis, b_cur, b_hs, b_vs, b_gon;
|
||||
always @(posedge clk)
|
||||
{b_line, b_bit, b_blank, b_text, b_vis, b_cur, b_hs, b_vs, b_gon} <=
|
||||
{a_line, a_bit, a_blank, a_text, a_vis, a_cur, a_hs, a_vs, a_gon};
|
||||
|
||||
// ---- clock 2: font ROM
|
||||
reg [7:0] font [0:4095];
|
||||
reg [7:0] glyph;
|
||||
initial $readmemh(FONT_FILE, font);
|
||||
always @(posedge clk) glyph <= font[{ram_data[7:0], line}];
|
||||
reg [7:0] glyph;
|
||||
reg [17:0] c_cell;
|
||||
reg [3:0] c_gfx, c_line;
|
||||
reg [2:0] c_bit;
|
||||
reg c_blank, c_text, c_vis, c_cur, c_hs, c_vs;
|
||||
always @(posedge clk) begin
|
||||
glyph <= font[{ram_data[7:0], b_line}];
|
||||
c_cell <= ram_data;
|
||||
c_gfx <= b_gon ? gfx_pix : 4'd0;
|
||||
{c_line, c_bit, c_blank, c_text, c_vis, c_cur, c_hs, c_vs} <=
|
||||
{b_line, b_bit, b_blank, b_text, b_vis, b_cur, b_hs, b_vs};
|
||||
end
|
||||
|
||||
function [11:0] palette(input [3:0] n);
|
||||
case (n)
|
||||
@@ -99,42 +133,44 @@ module text_display #(
|
||||
endcase
|
||||
endfunction
|
||||
|
||||
wire visible = h < H_VIS && v < V_VIS;
|
||||
wire cursor = cur_vis && frame[5] && tcol == cur_col && srow == cur_row;
|
||||
wire ink = (glyph[~h[2:0]] | (ram_data[16] && line == 4'd15)) && !(ram_data[17] && frame[5]);
|
||||
wire fg = !blank_line && (ink ^ cursor);
|
||||
wire [3:0] idx = fg ? ram_data[11:8] : gfx_pix != 4'd0 ? gfx_pix :
|
||||
blank_line ? 4'd0 : ram_data[15:12];
|
||||
|
||||
// ---- clock 3: colour
|
||||
wire ink = (glyph[~c_bit] | (c_cell[16] && c_line == 4'd15)) && !(c_cell[17] && frame[5]);
|
||||
wire fg = c_text && !c_blank && (ink ^ c_cur);
|
||||
wire [3:0] idx = fg ? c_cell[11:8] : c_gfx != 4'd0 ? c_gfx :
|
||||
c_blank || !c_text ? 4'd0 : c_cell[15:12];
|
||||
always @(posedge clk) begin
|
||||
if (tick) begin
|
||||
{red, green, blue} <= visible ? palette(idx) : 12'h000;
|
||||
hsync <= !(h >= H_VIS + H_FP && h < H_VIS + H_FP + H_SYNC);
|
||||
vsync <= !(v >= V_VIS + V_FP && v < V_VIS + V_FP + V_SYNC);
|
||||
end
|
||||
{red, green, blue} <= c_vis ? palette(idx) : 12'h000;
|
||||
hsync <= c_hs;
|
||||
vsync <= c_vs;
|
||||
end
|
||||
endmodule
|
||||
|
||||
// Two 2400-cell character buffers (the normal and the alternate screen; the
|
||||
// top address bit picks one): read/write port for the terminal engine,
|
||||
// read-only port for video.
|
||||
// Two character buffers of 132x64 cells (the normal and the alternate screen,
|
||||
// picked by a_alt/b_alt): read/write port for the terminal engine, read-only
|
||||
// port for video on the pixel clock.
|
||||
module char_ram (
|
||||
input clk,
|
||||
input [12:0] a_addr,
|
||||
input a_alt,
|
||||
input [13:0] a_addr,
|
||||
input a_we,
|
||||
input [17:0] a_wdata,
|
||||
output reg [17:0] a_rdata,
|
||||
input [12:0] b_addr,
|
||||
input vclk,
|
||||
input b_alt,
|
||||
input [13:0] b_addr,
|
||||
output reg [17:0] b_rdata
|
||||
);
|
||||
(* ram_style = "block" *) reg [17:0] mem [0:8191];
|
||||
localparam PAGE = 132 * 64;
|
||||
(* ram_style = "block" *) reg [17:0] mem [0:2 * PAGE - 1];
|
||||
integer i;
|
||||
initial for (i = 0; i < 8192; i = i + 1) mem[i] = {10'h00A, 8'h20};
|
||||
initial for (i = 0; i < 2 * PAGE; i = i + 1) mem[i] = {10'h00A, 8'h20};
|
||||
|
||||
wire [14:0] aa = {1'b0, a_addr} + (a_alt ? PAGE : 0);
|
||||
wire [14:0] ba = {1'b0, b_addr} + (b_alt ? PAGE : 0);
|
||||
always @(posedge clk) begin
|
||||
if (a_we) mem[a_addr] <= a_wdata;
|
||||
a_rdata <= mem[a_addr];
|
||||
if (a_we) mem[aa] <= a_wdata;
|
||||
a_rdata <= mem[aa];
|
||||
end
|
||||
|
||||
always @(posedge clk) b_rdata <= mem[b_addr];
|
||||
always @(posedge vclk) b_rdata <= mem[ba];
|
||||
endmodule
|
||||
Reference in new issue
Block a user