// retroDE_ps2 — tb_gs_clut_load_ct16 (Ch100)
//
// Locks the contract for TEX0.CLD-driven VRAM→CLUT load with
// CPSM = PSMCT16. The Ch99 loader walked PSMCT32 entries; Ch100
// extends it to PSMCT16: 2 bytes/entry, RGB5A1 unpack with 5→8
// bit-replicate, alpha replicated across 8 bits.
//
// Setup (no gs_stub raster — VRAM written directly):
//   - VRAM[0..15]     holds a 4×4 PSMT8 sprite (indices 0x10..0x1F).
//   - VRAM[CBP*256..] holds 256 PSMCT16 entries (RGB5A1, 16-bit
//                     each, packed as {a1, b5, g5, r5}). 256 × 2
//                     = 512 bytes total. Per entry i:
//                         r5 = i[4:0]
//                         g5 = (i + 7)[4:0]
//                         b5 = (i + 13)[4:0]
//                         a1 = 1
//   - TEX0_1: CBP=4 (=1024 bytes), CPSM=2 (PSMCT16), CSM=1
//             (CSM2 linear), CSA=0, CLD=1.
//   - clut_loader_stub copies the entries (unpacking 16→32 bits
//     to PSMCT32 ABGR) into clut_stub, then PSMT8 scanout looks
//     them up.
//
// Per-pixel expectation:
//   if (x, y) in 4×4 sprite:
//     idx = 0x10 + (y * 4 + x)
//     r8 = bit-replicate(idx[4:0])
//     g8 = bit-replicate((idx + 7)[4:0])
//     b8 = bit-replicate((idx + 13)[4:0])
//   else:
//     idx = 0 → CLUT[0] is also loaded with the same formula
//     (so non-sprite pixels match clut16_decode(0))

`timescale 1ns/1ps

module tb_gs_clut_load_ct16;

    localparam int PCRTC_H_ACTIVE = 16;
    localparam int PCRTC_V_ACTIVE = 8;

    logic clk;
    logic rst_n;
    initial clk = 1'b0;
    always #5 clk = ~clk;

    logic        gif_reg_wr_en;
    logic [7:0]  gif_reg_num;
    logic [63:0] gif_reg_data;
    logic        priv_reg_wr_en;
    logic [15:0] priv_reg_wr_addr;
    logic [63:0] priv_reg_wr_data;

    logic [7:0]          bg_r, bg_g, bg_b;
    logic [63:0]         pmode_q, dispfb1_q, display1_q;
    logic [63:0]         prim_q, rgbaq_q, xyz2_q, xyzf2_q, frame_1_q, zbuf_1_q;
    logic [63:0]         tex0_1_q;
    logic [13:0]         tex0_1_cbp_q;
    logic [3:0]          tex0_1_cpsm_q;
    logic                tex0_1_csm_q;
    logic [4:0]          tex0_1_csa_q;
    logic [2:0]          tex0_1_cld_q;
    logic                tex0_1_wr_q;
    logic                prim_complete;
    logic [31:0]         prim_complete_count;
    logic [63:0]         prim_v0_q, prim_v1_q, prim_v2_q;
    logic [63:0]         prim_color_q;
    logic [63:0]         prim_color_v0_q, prim_color_v1_q, prim_color_v2_q;
    trace_pkg::vertex_t  prim_v0_decoded_q, prim_v1_decoded_q, prim_v2_decoded_q;
    trace_pkg::color_t   prim_v0_color_decoded_q, prim_v1_color_decoded_q, prim_v2_color_decoded_q;
    logic                pixel_emit;
    logic [31:0]         pixel_emit_count;
    logic [11:0]         pixel_x_q, pixel_y_q;
    logic [63:0]         pixel_color_q;
    logic [8:0]          pixel_fbp_q;
    logic [5:0]          pixel_fbw_q, pixel_psm_q;
    logic [31:0]         pixel_fb_addr_q;
    logic                raster_pixel_emit;
    logic [31:0]         raster_pixel_emit_count;
    logic [11:0]         raster_pixel_x_q, raster_pixel_y_q;
    logic [63:0]         raster_pixel_color_q;
    logic [31:0]         raster_pixel_fb_addr_q;
    logic [3:0]          raster_pixel_be_q;
    logic [5:0]          raster_pixel_psm_q;
    logic                raster_active;
    logic                raster_overflow;
    logic                raster_degenerate;
    logic                gs_ev_valid;
    trace_pkg::subsys_e  gs_ev_subsys;
    trace_pkg::event_e   gs_ev_event;
    logic [63:0]         gs_ev_arg0, gs_ev_arg1, gs_ev_arg2, gs_ev_arg3;
    logic [31:0]         gs_ev_flags;

    gs_stub u_gs (
        .clk(clk), .rst_n(rst_n),
        .reg_wr_en  (priv_reg_wr_en),
        .reg_wr_addr(priv_reg_wr_addr),
        .reg_wr_data(priv_reg_wr_data),
        .gif_reg_wr_en(gif_reg_wr_en),
        .gif_reg_num(gif_reg_num),
        .gif_reg_data(gif_reg_data),
        .bg_r(bg_r), .bg_g(bg_g), .bg_b(bg_b),
        .pmode_q(pmode_q), .dispfb1_q(dispfb1_q), .display1_q(display1_q),
        .prim_q(prim_q), .rgbaq_q(rgbaq_q),
        .xyz2_q(xyz2_q), .xyzf2_q(xyzf2_q),
        .frame_1_q(frame_1_q), .zbuf_1_q(zbuf_1_q),
        .tex0_1_q(tex0_1_q),
        .tex0_1_cbp_q(tex0_1_cbp_q),
        .tex0_1_cpsm_q(tex0_1_cpsm_q),
        .tex0_1_csm_q(tex0_1_csm_q),
        .tex0_1_csa_q(tex0_1_csa_q),
        .tex0_1_cld_q(tex0_1_cld_q),
        .tex0_1_wr_q(tex0_1_wr_q),
        .prim_complete(prim_complete),
        .prim_complete_count(prim_complete_count),
        .prim_v0_q(prim_v0_q), .prim_v1_q(prim_v1_q), .prim_v2_q(prim_v2_q),
        .prim_color_q(prim_color_q),
        .prim_color_v0_q(prim_color_v0_q),
        .prim_color_v1_q(prim_color_v1_q),
        .prim_color_v2_q(prim_color_v2_q),
        .prim_v0_decoded_q(prim_v0_decoded_q),
        .prim_v1_decoded_q(prim_v1_decoded_q),
        .prim_v2_decoded_q(prim_v2_decoded_q),
        .prim_v0_color_decoded_q(prim_v0_color_decoded_q),
        .prim_v1_color_decoded_q(prim_v1_color_decoded_q),
        .prim_v2_color_decoded_q(prim_v2_color_decoded_q),
        .pixel_emit(pixel_emit),
        .pixel_emit_count(pixel_emit_count),
        .pixel_x_q(pixel_x_q), .pixel_y_q(pixel_y_q),
        .pixel_color_q(pixel_color_q),
        .pixel_fbp_q(pixel_fbp_q),
        .pixel_fbw_q(pixel_fbw_q),
        .pixel_psm_q(pixel_psm_q),
        .pixel_fb_addr_q(pixel_fb_addr_q),
        .raster_pixel_emit(raster_pixel_emit),
        .raster_pixel_emit_count(raster_pixel_emit_count),
        .raster_pixel_x_q(raster_pixel_x_q),
        .raster_pixel_y_q(raster_pixel_y_q),
        .raster_pixel_color_q(raster_pixel_color_q),
        .raster_pixel_fb_addr_q(raster_pixel_fb_addr_q),
        .raster_pixel_be_q(raster_pixel_be_q),
        .raster_pixel_psm_q(raster_pixel_psm_q),
        .raster_active(raster_active),
        .raster_overflow(raster_overflow),
        .raster_degenerate(raster_degenerate),
        .ev_valid(gs_ev_valid),
        .ev_subsys(gs_ev_subsys),
        .ev_event(gs_ev_event),
        .ev_arg0(gs_ev_arg0), .ev_arg1(gs_ev_arg1),
        .ev_arg2(gs_ev_arg2), .ev_arg3(gs_ev_arg3),
        .ev_flags(gs_ev_flags)
    );

    logic        vram_we;
    logic [31:0] vram_waddr;
    logic [31:0] vram_wdata;
    logic [3:0]  vram_wbe;
    logic [31:0] vram_raddr;
    logic [31:0] vram_rdata;
    logic [31:0] vram_raddr2;
    logic [31:0] vram_rdata2;

    vram_stub #(.BYTES(8192)) u_vram (
        .clk(clk), .rst_n(rst_n),
        .write_en  (vram_we),
        .write_addr(vram_waddr),
        .write_data(vram_wdata),
        .write_be  (vram_wbe),
        .write_mask(32'hFFFF_FFFF),
        .read_addr (vram_raddr),
        .read_data (vram_rdata),
        .read2_addr(vram_raddr2),
        .read2_data(vram_rdata2)
    );

    logic        clut_we;
    logic [7:0]  clut_widx;
    logic [31:0] clut_wdata;
    logic [7:0]  clut_ridx;
    logic [31:0] clut_rdata;

    clut_stub u_clut (
        .clk(clk), .rst_n(rst_n),
        .write_en  (clut_we),
        .write_idx (clut_widx),
        .write_data(clut_wdata),
        .read_idx  (clut_ridx),
        .read_data (clut_rdata)
    );

    logic loader_busy;

    clut_loader_stub u_loader (
        .clk(clk), .rst_n(rst_n),
        .tex0_wr_pulse  (tex0_1_wr_q),
        .tex0_cbp       (tex0_1_cbp_q),
        .tex0_cpsm      (tex0_1_cpsm_q),
        .tex0_csm       (tex0_1_csm_q),
        .tex0_csa       (tex0_1_csa_q),
        .tex0_cld       (tex0_1_cld_q),
        .vram_read_addr (vram_raddr2),
        .vram_read_data (vram_rdata2),
        .clut_write_en  (clut_we),
        .clut_write_idx (clut_widx),
        .clut_write_data(clut_wdata),
        .load_busy      (loader_busy)
    );

    logic       hsync_o, vsync_o, de_o;
    logic [7:0] r_o, g_o, b_o;
    logic                pcrtc_ev_valid;
    trace_pkg::subsys_e  pcrtc_ev_subsys;
    trace_pkg::event_e   pcrtc_ev_event;
    logic [63:0]         pcrtc_ev_arg0, pcrtc_ev_arg1;
    logic [63:0]         pcrtc_ev_arg2, pcrtc_ev_arg3;
    logic [31:0]         pcrtc_ev_flags;

    gs_pcrtc_stub #(
        .H_ACTIVE(PCRTC_H_ACTIVE), .H_FRONT(1), .H_SYNC(1), .H_BACK(1),
        .V_ACTIVE(PCRTC_V_ACTIVE), .V_FRONT(1), .V_SYNC(1), .V_BACK(1)
    ) u_pcrtc (
        .clk(clk), .rst_n(rst_n),
        .pmode_q       (pmode_q),
        .dispfb1_q     (dispfb1_q),
        .display1_q    (display1_q),
        .vram_read_addr(vram_raddr),
        .vram_read_data(vram_rdata),
        .clut_enable   (1'b1),
        .clut_csa      (tex0_1_csa_q),
        .clut_read_idx (clut_ridx),
        .clut_read_data(clut_rdata),
        .hsync(hsync_o), .vsync(vsync_o), .de(de_o),
        .r(r_o), .g(g_o), .b(b_o),
        .ev_valid(pcrtc_ev_valid),
        .ev_subsys(pcrtc_ev_subsys),
        .ev_event(pcrtc_ev_event),
        .ev_arg0(pcrtc_ev_arg0), .ev_arg1(pcrtc_ev_arg1),
        .ev_arg2(pcrtc_ev_arg2), .ev_arg3(pcrtc_ev_arg3),
        .ev_flags(pcrtc_ev_flags)
    );

    logic [7:0] cap_r [0:PCRTC_V_ACTIVE-1][0:PCRTC_H_ACTIVE-1];
    logic [7:0] cap_g [0:PCRTC_V_ACTIVE-1][0:PCRTC_H_ACTIVE-1];
    logic [7:0] cap_b [0:PCRTC_V_ACTIVE-1][0:PCRTC_H_ACTIVE-1];
    logic       cap_de[0:PCRTC_V_ACTIVE-1][0:PCRTC_H_ACTIVE-1];

    int errors;
    bit capture_armed;

    // Ch100 audit-low — snoop every `clut_we` cycle so we can
    // assert the loader's alpha-byte unpack on specific indices
    // without going through the RGB-only scanout path.
    logic [31:0] captured_clut_wdata [0:255];

    initial begin
        for (int i = 0; i < 256; i++) captured_clut_wdata[i] = 32'd0;
    end

    always_ff @(posedge clk) begin
        if (rst_n && clut_we) begin
            captured_clut_wdata[clut_widx] <= clut_wdata;
        end
    end

    initial begin
        for (int y = 0; y < PCRTC_V_ACTIVE; y++)
            for (int x = 0; x < PCRTC_H_ACTIVE; x++) begin
                cap_r[y][x]  = 8'd0;
                cap_g[y][x]  = 8'd0;
                cap_b[y][x]  = 8'd0;
                cap_de[y][x] = 1'b0;
            end
        errors        = 0;
        capture_armed = 1'b0;
    end

    always_ff @(posedge clk) begin
        if (rst_n && capture_armed && de_o
            && (u_pcrtc.vcnt < PCRTC_V_ACTIVE)
            && (u_pcrtc.hcnt < PCRTC_H_ACTIVE)) begin
            cap_r [u_pcrtc.vcnt][u_pcrtc.hcnt] <= r_o;
            cap_g [u_pcrtc.vcnt][u_pcrtc.hcnt] <= g_o;
            cap_b [u_pcrtc.vcnt][u_pcrtc.hcnt] <= b_o;
            cap_de[u_pcrtc.vcnt][u_pcrtc.hcnt] <= 1'b1;
        end
    end

    task automatic step_drive(input logic        wr_en,
                              input logic [7:0]  num,
                              input logic [63:0] data);
        @(negedge clk);
        gif_reg_wr_en = wr_en;
        gif_reg_num   = num;
        gif_reg_data  = data;
        @(posedge clk);
    endtask

    task automatic drive_reg(input logic [7:0] num, input logic [63:0] data);
        step_drive(1'b1, num, data);
    endtask

    task automatic drive_idle();
        step_drive(1'b0, 8'd0, 64'd0);
    endtask

    task automatic drive_priv(input logic [15:0] addr,
                              input logic [63:0] data);
        @(negedge clk);
        priv_reg_wr_en   = 1'b1;
        priv_reg_wr_addr = addr;
        priv_reg_wr_data = data;
        @(posedge clk);
        @(negedge clk);
        priv_reg_wr_en   = 1'b0;
        priv_reg_wr_addr = 16'd0;
        priv_reg_wr_data = 64'd0;
    endtask

    task automatic vram_write32(input logic [31:0] addr,
                                input logic [31:0] data,
                                input logic [3:0]  be);
        @(negedge clk);
        vram_we    = 1'b1;
        vram_waddr = addr;
        vram_wdata = data;
        vram_wbe   = be;
        @(posedge clk);
        @(negedge clk);
        vram_we    = 1'b0;
        vram_waddr = 32'd0;
        vram_wdata = 32'd0;
        vram_wbe   = 4'b0000;
    endtask

    // Pack a 16-bit RGB5A1 entry per the test contract.
    function automatic logic [4:0] r5_of(input logic [7:0] i);
        return i[4:0];
    endfunction
    function automatic logic [4:0] g5_of(input logic [7:0] i);
        logic [7:0] s;
        s = i + 8'd7;
        return s[4:0];
    endfunction
    function automatic logic [4:0] b5_of(input logic [7:0] i);
        logic [7:0] s;
        s = i + 8'd13;
        return s[4:0];
    endfunction

    // Per-entry alpha bit varies with index LSB so the test
    // covers BOTH the a1=0 → a8=0x00 and a1=1 → a8=0xFF cases
    // of the loader's `{8{a1}}` expansion (Ch100 audit-low).
    function automatic logic a1_of(input logic [7:0] i);
        return i[0];
    endfunction

    function automatic logic [15:0] clut16_pack(input logic [7:0] i);
        return {a1_of(i), b5_of(i), g5_of(i), r5_of(i)};
    endfunction

    // Expected PSMCT32 ABGR after the loader's 5→8 unpack. The
    // alpha byte mirrors `{8{a1}}` exactly: 0xFF when a1=1,
    // 0x00 when a1=0. RGB doesn't depend on alpha so the
    // existing per-pixel scanout assertion (RGB-only) is
    // unaffected by the alternating-alpha pattern.
    function automatic logic [31:0] clut16_decode(input logic [7:0] i);
        logic [4:0] r5, g5, b5;
        logic [7:0] r8, g8, b8, a8;
        r5 = r5_of(i); g5 = g5_of(i); b5 = b5_of(i);
        r8 = {r5, r5[4:2]};
        g8 = {g5, g5[4:2]};
        b8 = {b5, b5[4:2]};
        a8 = {8{a1_of(i)}};
        return {a8, b8, g8, r8};
    endfunction

    function automatic logic [63:0] tex0_pack(
        input logic [13:0] cbp,
        input logic [3:0]  cpsm,
        input logic        csm,
        input logic [4:0]  csa,
        input logic [2:0]  cld);
        logic [63:0] v;
        v = 64'd0;
        v[50:37] = cbp;
        v[54:51] = cpsm;
        v[55]    = csm;
        v[60:56] = csa;
        v[63:61] = cld;
        return v;
    endfunction

    localparam logic [7:0]  GIF_TEX0_1   = 8'h06;
    localparam logic [15:0] PMODE_OFF    = 16'h0000;
    localparam logic [15:0] DISPFB1_OFF  = 16'h0070;
    localparam logic [15:0] DISPLAY1_OFF = 16'h0080;

    localparam int SPRITE_W = 4;
    localparam int SPRITE_H = 4;
    localparam logic [7:0]  BASE_IDX     = 8'h10;
    localparam int          ROW_STRIDE   = 64;
    localparam int          CLUT_CBP     = 4;
    localparam logic [31:0] CLUT_BASE    = 32'd1024;

    // PSMT8 framebuffer config: FBP=0, FBW=1, PSM=PSMT8 (0x13).
    localparam logic [63:0] DISPFB1_VAL  = 64'h0000_0000_0009_8200;
    localparam logic [63:0] DISPLAY1_VAL =
          (64'(PCRTC_H_ACTIVE - 1) << 32)
        | (64'(PCRTC_V_ACTIVE - 1) << 44);
    localparam logic [63:0] PMODE_EN1    = 64'h0000_0000_0000_0001;

    initial begin
        rst_n            = 1'b0;
        gif_reg_wr_en    = 1'b0;
        gif_reg_num      = 8'd0;
        gif_reg_data     = 64'd0;
        priv_reg_wr_en   = 1'b0;
        priv_reg_wr_addr = 16'd0;
        priv_reg_wr_data = 64'd0;
        vram_we          = 1'b0;
        vram_waddr       = 32'd0;
        vram_wdata       = 32'd0;
        vram_wbe         = 4'b0000;

        repeat (4) @(posedge clk);
        rst_n = 1'b1;
        repeat (2) @(posedge clk);

        // Stage the PSMT8 sprite at VRAM bytes 0..15.
        for (int y = 0; y < SPRITE_H; y++) begin
            logic [7:0]  i0, i1, i2, i3;
            logic [31:0] data;
            int          row_base;
            i0 = BASE_IDX + 8'(y * SPRITE_W + 0);
            i1 = BASE_IDX + 8'(y * SPRITE_W + 1);
            i2 = BASE_IDX + 8'(y * SPRITE_W + 2);
            i3 = BASE_IDX + 8'(y * SPRITE_W + 3);
            data = {i3, i2, i1, i0};
            row_base = y * ROW_STRIDE;
            vram_write32(row_base, data, 4'b1111);
        end

        // Stage 256 PSMCT16 CLUT entries at CLUT_BASE. Pack 2
        // entries per 32-bit write.
        for (int i = 0; i < 256; i = i + 2) begin
            logic [15:0] e0, e1;
            logic [31:0] data;
            logic [31:0] addr;
            e0 = clut16_pack(8'(i + 0));
            e1 = clut16_pack(8'(i + 1));
            data = {e1, e0};
            addr = CLUT_BASE + 32'(i * 2);   // 2 bytes/entry
            vram_write32(addr, data, 4'b1111);
        end

        // Trigger PSMCT16 load. CSM=1 (CSM2), CSA=0, CLD=1, CPSM=2.
        drive_reg(GIF_TEX0_1, tex0_pack(14'(CLUT_CBP), 4'd2, 1'b1, 5'd0, 3'd1));
        drive_idle();

        wait (loader_busy == 1'b1);
        wait (loader_busy == 1'b0);
        repeat (4) @(posedge clk);

        // Ch100 audit-low: lock the alpha-byte unpack. Indices
        // with a1=0 must produce A=0x00; indices with a1=1 must
        // produce A=0xFF. We picked a1 = idx[0] above so even
        // indices test the 0x00 path and odd indices test the
        // 0xFF path. Spot-check a few of each, AND scan all 256
        // captured entries to catch any inconsistency.
        if (captured_clut_wdata[8'h40][31:24] !== 8'h00) begin
            $error("alpha-low CLUT[0x40].A=0x%02x (expected 0x00 from a1=0)",
                   captured_clut_wdata[8'h40][31:24]);
            errors = errors + 1;
        end
        if (captured_clut_wdata[8'h41][31:24] !== 8'hFF) begin
            $error("alpha-high CLUT[0x41].A=0x%02x (expected 0xFF from a1=1)",
                   captured_clut_wdata[8'h41][31:24]);
            errors = errors + 1;
        end
        if (captured_clut_wdata[8'h80][31:24] !== 8'h00) begin
            $error("alpha-low CLUT[0x80].A=0x%02x (expected 0x00)",
                   captured_clut_wdata[8'h80][31:24]);
            errors = errors + 1;
        end
        if (captured_clut_wdata[8'hFF][31:24] !== 8'hFF) begin
            $error("alpha-high CLUT[0xFF].A=0x%02x (expected 0xFF)",
                   captured_clut_wdata[8'hFF][31:24]);
            errors = errors + 1;
        end
        // Sweep all 256 to catch any unexpected mid-byte alpha:
        // {8{a1}} can only be 0x00 or 0xFF.
        for (int i = 0; i < 256; i++) begin
            logic [7:0]  idx_8;
            logic [31:0] entry;
            logic [7:0]  alpha;
            idx_8 = i[7:0];
            entry = captured_clut_wdata[idx_8];
            alpha = entry[31:24];
            if (alpha !== 8'h00 && alpha !== 8'hFF) begin
                $error("CLUT[0x%02x].A=0x%02x (must be 0x00 or 0xFF)", idx_8, alpha);
                errors = errors + 1;
            end
        end

        // Configure scanout.
        drive_priv(DISPFB1_OFF,  DISPFB1_VAL);
        drive_priv(DISPLAY1_OFF, DISPLAY1_VAL);
        drive_priv(PMODE_OFF,    PMODE_EN1);

        @(posedge u_pcrtc.end_of_frame);
        @(posedge clk);
        capture_armed = 1'b1;
        @(posedge u_pcrtc.end_of_frame);
        @(posedge clk);
        capture_armed = 1'b0;

        // Per-pixel verification.
        for (int y = 0; y < PCRTC_V_ACTIVE; y++) begin
            for (int x = 0; x < PCRTC_H_ACTIVE; x++) begin
                logic [7:0]  er, eg, eb;
                bit          in_sprite;
                logic [7:0]  idx;
                logic [31:0] entry;

                in_sprite = (x < SPRITE_W) && (y < SPRITE_H);
                if (in_sprite) begin
                    idx = BASE_IDX + 8'(y * SPRITE_W + x);
                end else begin
                    // Untouched VRAM bytes read as 0 → idx=0; the
                    // loaded CLUT[0] is clut16_decode(0).
                    idx = 8'd0;
                end
                entry = clut16_decode(idx);
                er    = entry[7:0];
                eg    = entry[15:8];
                eb    = entry[23:16];

                if (!cap_de[y][x]) begin
                    $error("(%0d,%0d) DE never asserted", x, y);
                    errors = errors + 1;
                end
                if (cap_r[y][x] !== er || cap_g[y][x] !== eg || cap_b[y][x] !== eb) begin
                    $error("(%0d,%0d) got (%02x,%02x,%02x) expected (%02x,%02x,%02x) idx=0x%02x in_sprite=%0d",
                           x, y, cap_r[y][x], cap_g[y][x], cap_b[y][x],
                           er, eg, eb, idx, in_sprite);
                    errors = errors + 1;
                end
            end
        end

        $display("[tb_gs_clut_load_ct16] CBP=%0d CPSM=PSMCT16 CLD=1 256 RGB5A1 entries → PSMT8 scanout shows expanded RGB",
                 CLUT_CBP);

        if (errors == 0) $display("[tb_gs_clut_load_ct16] PASS");
        else             $display("[tb_gs_clut_load_ct16] FAIL");
        $finish;
    end

    initial begin
        #5000000;
        $error("[tb_gs_clut_load_ct16] timeout");
        $finish;
    end

endmodule : tb_gs_clut_load_ct16
