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:
brad ArantandClaude Opus 5.5 committed 2026-11-28 12:24:21 -08:00
1 parent 634e314010
commit 88b5942da5
12 files changed
+354 -220

No files matched your search

+110 -74
View File
@@ -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