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

+45 -17
View File
@@ -102,7 +102,7 @@ module tb_terminal;
function [7:0] cellraw(input integer rr, input integer cc);
reg [17:0] v;
begin
v = dut.screen.mem[(dut.alt_scr ? 4096 : 0) + rr * 80 + cc]; // the page on show
v = dut.screen.mem[(dut.alt_scr ? 8448 : 0) + rr * 132 + cc]; // the page on show
cellraw = v[7:0];
end
endfunction
@@ -193,15 +193,17 @@ module tb_terminal;
screen_pc = {cellraw(2, 4), cellraw(2, 5), cellraw(2, 6), cellraw(2, 7)};
endfunction
// capture one frame
reg [11:0] fb [0:640*480-1];
reg cap = 0, smp = 0;
reg [9:0] hh, vv;
always @(posedge clk) if (dut.video.tick) begin hh <= dut.video.h; vv <= dut.video.v; smp <= cap; end
always @(negedge clk) if (smp && hh < 640 && vv < 480) begin
fb[vv * 640 + hh] = {r, g, b};
smp = 0;
// capture one frame (1280x1024; the colour on the pins belongs to the
// position the display's counters had four clocks earlier)
reg [11:0] fb [0:1280*1024-1];
reg cap = 0;
reg [21:0] pd1, pd2, pd3, pd4;
always @(posedge dut.pix_clk) begin
pd1 <= {dut.video.h, dut.video.v};
pd2 <= pd1; pd3 <= pd2; pd4 <= pd3;
end
always @(negedge dut.pix_clk)
if (cap && pd4[21:11] < 1280 && pd4[10:0] < 1024) fb[pd4[10:0] * 1280 + pd4[21:11]] = {r, g, b};
task capture_frame(input [8*16-1:0] name);
integer fd, i;
@@ -209,24 +211,29 @@ module tb_terminal;
@(posedge vs);
cap = 1;
@(negedge vs);
@(posedge vs);
cap = 0;
fd = $fopen(name, "w");
$fwrite(fd, "P3\n640 480\n15\n");
for (i = 0; i < 640 * 480; i = i + 1)
$fwrite(fd, "P3\n1280 1024\n15\n");
for (i = 0; i < 1280 * 1024; i = i + 1)
$fwrite(fd, "%0d %0d %0d\n", fb[i][11:8], fb[i][7:4], fb[i][3:0]);
$fclose(fd);
$display("wrote %0s", name);
end
endtask
// check VGA timing on the outputs
// check VGA timing on the outputs: 1688 x 1066 pixel clocks (10 ns here)
realtime t_hs = 0, t_vs = 0, t_cmd;
always @(negedge hs) begin
if (t_hs != 0 && ($realtime - t_hs) != 32000) $display("HSYNC period %0t", $realtime - t_hs);
integer hs_bad = 0, vs_bad = 0;
always @(posedge hs) begin
if (t_hs != 0 && ($realtime - t_hs) != 16880) hs_bad = hs_bad + 1;
t_hs = $realtime;
end
always @(negedge vs) begin
if (t_vs != 0 && ($realtime - t_vs) != 16800000) $display("VSYNC period %0t", $realtime - t_vs);
always @(posedge vs) begin
if (t_vs != 0 && ($realtime - t_vs) != 16880 * 1066) begin
vs_bad = vs_bad + 1;
$display("VSYNC period %0t", $realtime - t_vs);
end
t_vs = $realtime;
end
@@ -291,13 +298,34 @@ module tb_terminal;
// ---- smooth scroll inside the region
uart_str("\033[18;1H\033[?4h\015\012r7");
capture_frame("frame_2.ppm"); // mid-scroll
#40_000_000;
#100_000_000;
expect_row(14, "r4");
expect_row(17, "r7");
expect_row(18, "below region");
uart_str("\033[?4l\033[r");
dump_screen;
// ---- 132 columns (DECCOLM): 132x64, cleared, then back to 80x32
uart_str("\033[?3h");
#1_000_000;
uart_str("132 columns\033[64;124Hcorner!\033[10;120H\033[6n");
expect_tx({8'h1B, "[10;120R"}, 9, "cursor report past column 99");
#200_000;
expect_row(0, "132 columns");
if ({cellraw(63, 123), cellraw(63, 129)} == {"c", "!"} && dut.wide)
$display("PASS 132x64: last row and column");
else begin $display("FAIL 132x64 corner: %c%c", cellraw(63, 123), cellraw(63, 129)); errors = errors + 1; end
capture_frame("frame_4.ppm");
uart_str("\033[?3l");
#1_000_000;
uart_str("\033[32;75Hend");
#200_000;
if (!dut.wide && cellraw(31, 74) == "e" && cellraw(0, 0) == " ")
$display("PASS back to 80x32, cleared");
else begin $display("FAIL back to 80x32"); errors = errors + 1; end
if (hs_bad == 0 && vs_bad == 0) $display("PASS 1280x1024 sync timing");
else begin $display("FAIL sync timing: %0d hsync, %0d vsync periods off", hs_bad, vs_bad); errors = errors + 1; end
// ---- Z-80 BASIC as the console, input pasted over the UART
uart_str("\033[2J\033[H");
#100_000;