// Test-pattern generator. One clock of latency: r, g, b belong to the // x, y, de presented on the previous clock. Outside the picture (de low) // the colour is black, which is what a DVI/HDMI transmitter expects. // mode 0: eight colour bars, H_ACTIVE/8 wide: white, yellow, cyan, green, // magenta, red, blue, black // mode 1: white grid, a line every GRID pixels, plus a one-pixel border // mode 2: gradient, red rises with x and green with y // mode 3: colour bars with the grid on top `timescale 1ns / 1ps module test_pattern #( parameter int H_ACTIVE = 640, parameter int V_ACTIVE = 480, parameter int XW = 10, parameter int YW = 10, parameter int GRID = 32 // power of two ) ( input logic clk, input logic [1:0] mode, input logic de, input logic [XW-1:0] x, input logic [YW-1:0] y, output logic [7:0] r, output logic [7:0] g, output logic [7:0] b ); localparam int BAR_W = H_ACTIVE / 8; localparam int GB = $clog2(GRID); // Bar index 0..7 from x, by comparison (no divider needed). logic [2:0] bar; always_comb begin bar = 3'd0; for (int k = 1; k < 8; k++) if (x >= XW'(k * BAR_W)) bar = 3'(k); end // Bars in order of falling brightness: the colour bits are the // inverted bar index, with bit 2 driving green, bit 1 red, bit 0 blue. logic [23:0] bars, gradient; assign bars = {{8{~bar[1]}}, {8{~bar[2]}}, {8{~bar[0]}}}; // Gradient: x and y scaled to 0..255 (multiply, then divide by a constant). logic [7:0] gx, gy; assign gx = 8'((32'(x) * 255) / (H_ACTIVE - 1)); assign gy = 8'((32'(y) * 255) / (V_ACTIVE - 1)); assign gradient = {gx, gy, 8'h00}; logic on_grid; assign on_grid = (x[GB-1:0] == '0) || (y[GB-1:0] == '0) || (x == XW'(H_ACTIVE - 1)) || (y == YW'(V_ACTIVE - 1)); logic [23:0] rgb; always_comb begin case (mode) 2'd0: rgb = bars; 2'd1: rgb = on_grid ? 24'hFFFFFF : 24'h000000; 2'd2: rgb = gradient; 2'd3: rgb = on_grid ? 24'hFFFFFF : bars; endcase if (!de) rgb = 24'h000000; end always_ff @(posedge clk) {r, g, b} <= rgb; endmodule