// retroDE_ps2 — tb_ee_core_gif_primitive_observer (Ch76)
//
// Exercises gs_stub's primitive observer for the **discrete**
// primitive types: a vertex commit (XYZ2 or XYZF2) that closes a
// POINT / LINE / TRIANGLE / SPRITE pulses prim_complete, increments
// prim_complete_count, and emits EV_PRIM_DRAW (preempting that
// cycle's EV_WRITE). This TB also includes one TRI_STRIP tag with
// only 2 vertices to confirm strip/fan stay quiet when their anchor
// is unmet — but the full strip/fan cadence (anchor + saturated
// extension draws) lives in tb_ee_core_gif_primitive_strip (Ch77).
//
// No rasterization yet. This TB checks shape recognition only.
//
// Stream (5 GIFtags, 21 qwords, single DMA burst):
//
//   Tag1 — TRIANGLE (PRIM=3, threshold=3, vertices via XYZ2):
//     q0  : GIFtag NLOOP=1 NREG=5 EOP=0 PACKED, REGS=[A+D × 5]
//     q1  : A+D PRIM   data=0x0...0003
//     q2  : A+D RGBAQ  data=0x...
//     q3  : A+D XYZ2   data=0x100   (v1 — EV_WRITE)
//     q4  : A+D XYZ2   data=0x200   (v2 — EV_WRITE)
//     q5  : A+D XYZ2   data=0x300   (v3 — EV_PRIM_DRAW)
//
//   Tag2 — LINE (PRIM=1, threshold=2, vertices via XYZF2):
//     q6  : GIFtag NLOOP=1 NREG=3 EOP=0 PACKED, REGS=[A+D × 3]
//     q7  : A+D PRIM   data=0x0...0001
//     q8  : A+D XYZF2  data=0xAAA   (v1 — EV_WRITE)
//     q9  : A+D XYZF2  data=0xBBB   (v2 — EV_PRIM_DRAW)
//                                    (covers the XYZF2 vertex path)
//
//   Tag3 — SPRITE (PRIM=6, threshold=2, vertices via XYZ2):
//     q10 : GIFtag NLOOP=1 NREG=3 EOP=0 PACKED, REGS=[A+D × 3]
//     q11 : A+D PRIM   data=0x0...0006
//     q12 : A+D XYZ2   data=0x400   (v1 — EV_WRITE)
//     q13 : A+D XYZ2   data=0x500   (v2 — EV_PRIM_DRAW)
//
//   Tag4 — POINT (PRIM=0, threshold=1, vertex via XYZ2):
//     q14 : GIFtag NLOOP=1 NREG=2 EOP=0 PACKED, REGS=[A+D × 2]
//     q15 : A+D PRIM   data=0x0...0000
//     q16 : A+D XYZ2   data=0x600   (v1 — EV_PRIM_DRAW immediately)
//
//   Tag5 — TRIANGLE_STRIP (PRIM=4, anchor=3 — anchor unmet here):
//     q17 : GIFtag NLOOP=1 NREG=3 EOP=1 PACKED, REGS=[A+D × 3]
//     q18 : A+D PRIM   data=0x0...0004
//     q19 : A+D XYZ2   data=0x700   (v1 — EV_WRITE, no draw)
//     q20 : A+D XYZ2   data=0x800   (v2 — EV_WRITE, no draw)
//                                   (TRI_STRIP needs 3 vertices to
//                                    anchor; this tag only provides
//                                    2, so vert_count reaches 2 and
//                                    stops there. Full strip cadence
//                                    is exercised in
//                                    tb_ee_core_gif_primitive_strip.)
//
// Pass criteria (21-qword stream):
//   - DMAC: 1 START / 21 BEAT / 1 DONE
//   - GIF:  5 GIFTAG, 16 EV_WRITE (5+3+3+2+3 A+D entries), 0 MODE
//   - GS:   0 BGCOLOR, 12 EV_WRITE, 4 EV_PRIM_DRAW, 0 EV_MODE
//           (TRI: 4W+1PD; LINE: 2W+1PD; SPRITE: 2W+1PD; POINT: 1W+1PD;
//            STRIP: 3W+0PD)
//   - prim_complete_count == 4 (4 discrete primitives closed)
//   - prim_q final  == 0x4   (TRI_STRIP, last PRIM written)
//   - xyz2_q final  == 0x800 (last STRIP vertex)
//   - xyzf2_q final == 0xBBB (last LINE vertex; nothing after writes XYZF2)
//
// EV_PRIM_DRAW arg checks (captured into prim_draw_args[] in order):
//   [0] TRI    : arg0=3 arg1=3 arg2=1 arg3=0x300
//   [1] LINE   : arg0=1 arg1=2 arg2=2 arg3=0xBBB   (XYZF2 close path)
//   [2] SPRITE : arg0=6 arg1=2 arg2=3 arg3=0x500
//   [3] POINT  : arg0=0 arg1=1 arg2=4 arg3=0x600

`timescale 1ns/1ps

module tb_ee_core_gif_primitive_observer;

    localparam int RAM_SIZE_BYTES = 4 * 1024;
    localparam int RAM_ADDR_W     = $clog2(RAM_SIZE_BYTES);

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

    // ee_ram_stub
    logic                  ram_rd_en;
    logic [RAM_ADDR_W-1:0] ram_rd_addr;
    logic [127:0]          ram_rd_data;
    logic                  ram_rd_valid;
    logic                  ram_wr_en;
    logic [RAM_ADDR_W-1:0] ram_wr_addr;
    logic [127:0]          ram_wr_data;
    logic [15:0]           ram_wr_be;
    logic [7:0]            ram_master_id;

    ee_ram_stub #(.SIZE_BYTES(RAM_SIZE_BYTES)) u_ram (
        .clk(clk), .rst_n(rst_n),
        .rd_en(ram_rd_en), .rd_addr(ram_rd_addr),
        .rd_data(ram_rd_data), .rd_valid(ram_rd_valid),
        .wr_en(ram_wr_en), .wr_addr(ram_wr_addr),
        .wr_data(ram_wr_data), .wr_be(ram_wr_be),
        .master_id(ram_master_id),
        .ev_valid(), .ev_subsys(), .ev_event(),
        .ev_arg0(), .ev_arg1(), .ev_arg2(), .ev_arg3(), .ev_flags()
    );
    assign ram_master_id = ram_rd_en ? 8'd1 : 8'd0;

    // DMAC + map
    logic        dmac_reg_wr_en;
    logic [7:0]  dmac_reg_offset;
    logic [31:0] dmac_reg_wr_data;
    logic        dmac_mem_rd_en;
    logic [31:0] dmac_mem_rd_addr;
    logic         dmac_gif_valid;
    logic [127:0] dmac_gif_data;
    logic         dmac_gif_last;
    logic         dmac_gif_ready;

    logic                dmac_ev_valid;
    trace_pkg::subsys_e  dmac_ev_subsys;
    trace_pkg::event_e   dmac_ev_event;
    logic [63:0]         dmac_ev_arg0, dmac_ev_arg1, dmac_ev_arg2, dmac_ev_arg3;
    logic [31:0]         dmac_ev_flags;

    logic [127:0] map_to_dmac_rd_data;
    logic         map_to_dmac_rd_valid;

    dmac_reg_stub u_dmac (
        .clk(clk), .rst_n(rst_n),
        .reg_wr_en(dmac_reg_wr_en), .reg_offset(dmac_reg_offset),
        .reg_wr_data(dmac_reg_wr_data),
        .reg_rd_en(1'b0), .reg_rd_data(), .reg_rd_valid(),
        .mem_rd_en(dmac_mem_rd_en), .mem_rd_addr(dmac_mem_rd_addr),
        .mem_rd_data(map_to_dmac_rd_data), .mem_rd_valid(map_to_dmac_rd_valid),
        .ep_valid(dmac_gif_valid), .ep_data(dmac_gif_data),
        .ep_last(dmac_gif_last), .ep_ready(dmac_gif_ready),
        .irq_completion_o(),
        .ev_valid(dmac_ev_valid), .ev_subsys(dmac_ev_subsys),
        .ev_event(dmac_ev_event),
        .ev_arg0(dmac_ev_arg0), .ev_arg1(dmac_ev_arg1),
        .ev_arg2(dmac_ev_arg2), .ev_arg3(dmac_ev_arg3),
        .ev_flags(dmac_ev_flags)
    );

    logic        map_ram_rd_en;
    logic [24:0] map_ram_rd_addr;
    ee_memory_map_stub u_map (
        .clk(clk), .rst_n(rst_n),
        .ee_rd_en(1'b0), .ee_rd_addr(32'd0),
        .ee_rd_data(), .ee_rd_valid(),
        .ee_wr_en(1'b0), .ee_wr_addr(32'd0),
        .ee_wr_data(32'd0), .ee_wr_be(4'd0),
        .dmac_rd_en(dmac_mem_rd_en), .dmac_rd_addr(dmac_mem_rd_addr),
        .dmac_rd_data(map_to_dmac_rd_data),
        .dmac_rd_valid(map_to_dmac_rd_valid),
        .bios_rd_en(), .bios_rd_addr(),
        .bios_rd_data(32'd0), .bios_rd_valid(1'b0),
        .ram_rd_en(map_ram_rd_en), .ram_rd_addr(map_ram_rd_addr),
        .ram_rd_data(ram_rd_data), .ram_rd_valid(ram_rd_valid),
        .bridge_wr_en(1'b0), .bridge_wr_addr(32'd0),
        .bridge_wr_data(128'd0), .bridge_wr_be(16'd0),
        .bridge_master_id(8'd0),
        .ram_wr_en(), .ram_wr_addr(), .ram_wr_data(),
        .ram_wr_be(), .ram_master_id(),
        .ee_dmac_ch2_wr_en(), .ee_dmac_ch2_wr_addr(), .ee_dmac_ch2_wr_data(),
        .ee_dmac_ch2_rd_en(), .ee_dmac_ch2_rd_addr(),
        .ee_dmac_ch2_rd_data(32'd0), .ee_dmac_ch2_rd_valid(1'b0),
        .ee_intc_wr_en(), .ee_intc_wr_addr(), .ee_intc_wr_data(),
        .ee_intc_rd_en(), .ee_intc_rd_addr(),
        .ee_intc_rd_data(32'd0), .ee_intc_rd_valid(1'b0),
        .ee_misc_mmio_wr_en(), .ee_misc_mmio_wr_addr(), .ee_misc_mmio_wr_data(), .ee_misc_mmio_wr_be(),
        .ee_misc_mmio_rd_en(), .ee_misc_mmio_rd_addr(),
        .ee_misc_mmio_rd_data(32'd0), .ee_misc_mmio_rd_valid(1'b0),
        .ee_biu_wr_en(), .ee_biu_wr_addr(), .ee_biu_wr_data(), .ee_biu_wr_be(),
        .ee_biu_rd_en(), .ee_biu_rd_addr(),
        .ee_biu_rd_data(32'd0), .ee_biu_rd_valid(1'b0),
        .ev_valid(), .ev_subsys(), .ev_event(),
        .ev_arg0(), .ev_arg1(), .ev_arg2(), .ev_arg3(), .ev_flags()
    );

    assign ram_rd_en   = map_ram_rd_en;
    assign ram_rd_addr = map_ram_rd_addr[RAM_ADDR_W-1:0];

    // gif_packed_stub (REAL_AD_REG_MAP=1)
    logic        gif_gs_wr_en;
    logic [15:0] gif_gs_wr_addr;
    logic [63:0] gif_gs_wr_data;
    logic        gif_gif_reg_wr_en;
    logic [7:0]  gif_gif_reg_num;
    logic [63:0] gif_gif_reg_data;

    logic                gif_ev_valid;
    trace_pkg::subsys_e  gif_ev_subsys;
    trace_pkg::event_e   gif_ev_event;
    logic [63:0]         gif_ev_arg0, gif_ev_arg1, gif_ev_arg2, gif_ev_arg3;
    logic [31:0]         gif_ev_flags;

    gif_packed_stub #(.REAL_AD_REG_MAP(1'b1)) u_gif (
        .clk(clk), .rst_n(rst_n),
        .in_valid(dmac_gif_valid), .in_data(dmac_gif_data),
        .in_last(dmac_gif_last), .in_ready(dmac_gif_ready),
        .image_data_ready(1'b1),
        .raster_fifo_full(1'b0),
        .gs_wr_en(gif_gs_wr_en), .gs_wr_addr(gif_gs_wr_addr),
        .gs_wr_data(gif_gs_wr_data),
        .gif_reg_wr_en(gif_gif_reg_wr_en),
        .gif_reg_num(gif_gif_reg_num),
        .gif_reg_data(gif_gif_reg_data),
        .ev_valid(gif_ev_valid), .ev_subsys(gif_ev_subsys),
        .ev_event(gif_ev_event),
        .ev_arg0(gif_ev_arg0), .ev_arg1(gif_ev_arg1),
        .ev_arg2(gif_ev_arg2), .ev_arg3(gif_ev_arg3),
        .ev_flags(gif_ev_flags)
    );

    // gs_stub
    logic [7:0]          bg_r, bg_g, bg_b;
    logic [63:0]         prim_q, rgbaq_q, xyz2_q, xyzf2_q, frame_1_q, zbuf_1_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                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(gif_gs_wr_en), .reg_wr_addr(gif_gs_wr_addr),
        .reg_wr_data(gif_gs_wr_data),
        .gif_reg_wr_en(gif_gif_reg_wr_en),
        .gif_reg_num(gif_gif_reg_num),
        .gif_reg_data(gif_gif_reg_data),
        .bg_r(bg_r), .bg_g(bg_g), .bg_b(bg_b),
        .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),
        .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),
        .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)
    );

    trace_sink_stub #(.FILENAME("gif_primitive_observer_dmac.trace"), .SINK_LABEL("dmac"))
        u_trace_dmac (.clk(clk), .rst_n(rst_n),
            .ev_valid(dmac_ev_valid), .ev_subsys(dmac_ev_subsys),
            .ev_event(dmac_ev_event),
            .ev_arg0(dmac_ev_arg0), .ev_arg1(dmac_ev_arg1),
            .ev_arg2(dmac_ev_arg2), .ev_arg3(dmac_ev_arg3),
            .ev_flags(dmac_ev_flags));
    trace_sink_stub #(.FILENAME("gif_primitive_observer_gif.trace"), .SINK_LABEL("gif"))
        u_trace_gif (.clk(clk), .rst_n(rst_n),
            .ev_valid(gif_ev_valid), .ev_subsys(gif_ev_subsys),
            .ev_event(gif_ev_event),
            .ev_arg0(gif_ev_arg0), .ev_arg1(gif_ev_arg1),
            .ev_arg2(gif_ev_arg2), .ev_arg3(gif_ev_arg3),
            .ev_flags(gif_ev_flags));
    trace_sink_stub #(.FILENAME("gif_primitive_observer_gs.trace"), .SINK_LABEL("gs"))
        u_trace_gs (.clk(clk), .rst_n(rst_n),
            .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));

    // Counters
    int dma_start_count, dma_beat_count, dma_done_count;
    int gif_giftag_count, gif_write_count, gif_mode_count;
    int gs_bgcolor_count, gs_write_count, gs_prim_draw_count, gs_mode_count;
    int prim_complete_pulse_count;
    int errors;
    logic dma_done_seen;

    initial begin
        dma_start_count = 0; dma_beat_count = 0; dma_done_count = 0;
        gif_giftag_count = 0; gif_write_count = 0; gif_mode_count = 0;
        gs_bgcolor_count = 0; gs_write_count = 0;
        gs_prim_draw_count = 0; gs_mode_count = 0;
        prim_complete_pulse_count = 0;
        errors = 0; dma_done_seen = 1'b0;
    end

    always_ff @(posedge clk) begin
        if (rst_n && dmac_ev_valid) begin
            unique case (dmac_ev_event)
                trace_pkg::EV_DMA_START: dma_start_count <= dma_start_count + 1;
                trace_pkg::EV_DMA_BEAT:  dma_beat_count  <= dma_beat_count  + 1;
                trace_pkg::EV_DMA_DONE: begin
                    dma_done_count <= dma_done_count + 1;
                    dma_done_seen  <= 1'b1;
                end
                default: ;
            endcase
        end
        if (rst_n && gif_ev_valid) begin
            if (gif_ev_event == trace_pkg::EV_GIFTAG) gif_giftag_count <= gif_giftag_count + 1;
            if (gif_ev_event == trace_pkg::EV_WRITE)  gif_write_count  <= gif_write_count  + 1;
            if (gif_ev_event == trace_pkg::EV_MODE)   gif_mode_count   <= gif_mode_count   + 1;
        end
        if (rst_n && gs_ev_valid) begin
            if (gs_ev_event == trace_pkg::EV_BGCOLOR)   gs_bgcolor_count   <= gs_bgcolor_count   + 1;
            if (gs_ev_event == trace_pkg::EV_WRITE)     gs_write_count     <= gs_write_count     + 1;
            if (gs_ev_event == trace_pkg::EV_PRIM_DRAW) gs_prim_draw_count <= gs_prim_draw_count + 1;
            if (gs_ev_event == trace_pkg::EV_MODE)      gs_mode_count      <= gs_mode_count      + 1;
        end
        if (rst_n && prim_complete) begin
            prim_complete_pulse_count <= prim_complete_pulse_count + 1;
        end
    end

    // Stimulus
    localparam logic [7:0]  CHCR_OFF     = 8'h00;
    localparam logic [7:0]  MADR_OFF     = 8'h10;
    localparam logic [7:0]  QWC_OFF      = 8'h20;
    localparam logic [31:0] PAYLOAD_MADR = 32'h0000_0100;
    localparam int          NUM_QWORDS   = 21;

    task automatic write_dmac(input logic [7:0] offset, input logic [31:0] data);
        @(negedge clk); dmac_reg_wr_en = 1'b1; dmac_reg_offset = offset; dmac_reg_wr_data = data;
        @(negedge clk); dmac_reg_wr_en = 1'b0; dmac_reg_offset = 8'd0; dmac_reg_wr_data = 32'd0;
    endtask

    task automatic preload_qword(input logic [RAM_ADDR_W-1:0] addr,
                                 input logic [127:0] data);
        @(negedge clk); ram_wr_en = 1'b1; ram_wr_addr = addr; ram_wr_data = data; ram_wr_be = 16'hFFFF;
        @(negedge clk); ram_wr_en = 1'b0; ram_wr_addr = '0; ram_wr_data = 128'd0; ram_wr_be = 16'd0;
    endtask

    function automatic logic [127:0] giftag(
        input logic [14:0] nloop, input logic eop,
        input logic [1:0] flg, input logic [3:0] nreg, input logic [63:0] regs);
        logic [63:0] lower;
        lower = {nreg, flg, 42'd0, eop, nloop};
        return {regs, lower};
    endfunction

    function automatic logic [127:0] aplusd_real(input logic [7:0]  reg_num,
                                                 input logic [63:0] data64);
        return {56'd0, reg_num, data64};
    endfunction

    // PCSX2 GSRegs.h
    localparam logic [7:0] R_PRIM    = 8'h00;
    localparam logic [7:0] R_RGBAQ   = 8'h01;
    localparam logic [7:0] R_XYZF2   = 8'h04;
    localparam logic [7:0] R_XYZ2    = 8'h05;

    // PRIM[2:0] selectors
    localparam logic [63:0] PRIM_POINT     = 64'd0;
    localparam logic [63:0] PRIM_LINE      = 64'd1;
    localparam logic [63:0] PRIM_TRIANGLE  = 64'd3;
    localparam logic [63:0] PRIM_TRI_STRIP = 64'd4;
    localparam logic [63:0] PRIM_SPRITE    = 64'd6;

    // EV_PRIM_DRAW args + Ch78 vertex tuple, captured in firing order
    logic [63:0] prim_draw_arg0 [0:3];
    logic [63:0] prim_draw_arg1 [0:3];
    logic [63:0] prim_draw_arg2 [0:3];
    logic [63:0] prim_draw_arg3 [0:3];
    logic [63:0] prim_draw_v0     [0:3];
    logic [63:0] prim_draw_v1     [0:3];
    logic [63:0] prim_draw_v2     [0:3];
    logic [63:0] prim_draw_color  [0:3];
    logic [63:0] prim_draw_cv0    [0:3];
    logic [63:0] prim_draw_cv1    [0:3];
    logic [63:0] prim_draw_cv2    [0:3];
    trace_pkg::vertex_t prim_draw_dv0 [0:3];
    trace_pkg::vertex_t prim_draw_dv1 [0:3];
    trace_pkg::vertex_t prim_draw_dv2 [0:3];
    trace_pkg::color_t  prim_draw_dc0 [0:3];
    trace_pkg::color_t  prim_draw_dc1 [0:3];
    trace_pkg::color_t  prim_draw_dc2 [0:3];
    int          prim_draw_idx;

    initial begin
        prim_draw_idx = 0;
        for (int i = 0; i < 4; i = i + 1) begin
            prim_draw_arg0[i]  = 64'd0;
            prim_draw_arg1[i]  = 64'd0;
            prim_draw_arg2[i]  = 64'd0;
            prim_draw_arg3[i]  = 64'd0;
            prim_draw_v0[i]    = 64'd0;
            prim_draw_v1[i]    = 64'd0;
            prim_draw_v2[i]    = 64'd0;
            prim_draw_color[i] = 64'd0;
            prim_draw_cv0[i]   = 64'd0;
            prim_draw_cv1[i]   = 64'd0;
            prim_draw_cv2[i]   = 64'd0;
        end
    end

    always_ff @(posedge clk) begin
        if (rst_n && gs_ev_valid && gs_ev_event == trace_pkg::EV_PRIM_DRAW
            && prim_draw_idx < 4) begin
            prim_draw_arg0[prim_draw_idx]  <= gs_ev_arg0;
            prim_draw_arg1[prim_draw_idx]  <= gs_ev_arg1;
            prim_draw_arg2[prim_draw_idx]  <= gs_ev_arg2;
            prim_draw_arg3[prim_draw_idx]  <= gs_ev_arg3;
            prim_draw_v0[prim_draw_idx]    <= prim_v0_q;
            prim_draw_v1[prim_draw_idx]    <= prim_v1_q;
            prim_draw_v2[prim_draw_idx]    <= prim_v2_q;
            prim_draw_color[prim_draw_idx] <= prim_color_q;
            prim_draw_cv0[prim_draw_idx]   <= prim_color_v0_q;
            prim_draw_cv1[prim_draw_idx]   <= prim_color_v1_q;
            prim_draw_cv2[prim_draw_idx]   <= prim_color_v2_q;
            prim_draw_dv0[prim_draw_idx]   <= prim_v0_decoded_q;
            prim_draw_dv1[prim_draw_idx]   <= prim_v1_decoded_q;
            prim_draw_dv2[prim_draw_idx]   <= prim_v2_decoded_q;
            prim_draw_dc0[prim_draw_idx]   <= prim_v0_color_decoded_q;
            prim_draw_dc1[prim_draw_idx]   <= prim_v1_color_decoded_q;
            prim_draw_dc2[prim_draw_idx]   <= prim_v2_color_decoded_q;
            prim_draw_idx                  <= prim_draw_idx + 1;
        end
    end

    initial begin
        rst_n = 1'b0;
        dmac_reg_wr_en = 1'b0; dmac_reg_offset = 8'd0; dmac_reg_wr_data = 32'd0;
        ram_wr_en = 1'b0; ram_wr_addr = '0; ram_wr_data = 128'd0; ram_wr_be = 16'd0;

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

        begin : preload_block
            logic [RAM_ADDR_W-1:0] addr_q;

            // ---------- Tag1: TRIANGLE (5 entries) ----------
            // q0 GIFtag NLOOP=1 NREG=5 EOP=0 PACKED, REGS=[A+D × 5]
            addr_q = PAYLOAD_MADR + 32'd0;
            preload_qword(addr_q, giftag(15'd1, 1'b0, 2'd0, 4'd5,
                                         64'h0000_0000_000E_EEEE));
            // q1 PRIM=TRIANGLE
            addr_q = PAYLOAD_MADR + 32'd16;
            preload_qword(addr_q, aplusd_real(R_PRIM, PRIM_TRIANGLE));
            // q2 RGBAQ
            addr_q = PAYLOAD_MADR + 32'd32;
            preload_qword(addr_q, aplusd_real(R_RGBAQ, 64'h3F80_0000_FF00_30FF));
            // q3..q5 XYZ2 vertices
            addr_q = PAYLOAD_MADR + 32'd48;
            preload_qword(addr_q, aplusd_real(R_XYZ2, 64'h0000_0000_0000_0100));
            addr_q = PAYLOAD_MADR + 32'd64;
            preload_qword(addr_q, aplusd_real(R_XYZ2, 64'h0000_0000_0000_0200));
            addr_q = PAYLOAD_MADR + 32'd80;
            preload_qword(addr_q, aplusd_real(R_XYZ2, 64'h0000_0000_0000_0300));

            // ---------- Tag2: LINE via XYZF2 (3 entries) ----------
            // q6 GIFtag NLOOP=1 NREG=3 EOP=0
            addr_q = PAYLOAD_MADR + 32'd96;
            preload_qword(addr_q, giftag(15'd1, 1'b0, 2'd0, 4'd3,
                                         64'h0000_0000_0000_0EEE));
            // q7 PRIM=LINE
            addr_q = PAYLOAD_MADR + 32'd112;
            preload_qword(addr_q, aplusd_real(R_PRIM, PRIM_LINE));
            // q8..q9 XYZF2 vertices (covers the XYZF2 vertex path)
            addr_q = PAYLOAD_MADR + 32'd128;
            preload_qword(addr_q, aplusd_real(R_XYZF2, 64'h0000_0000_0000_0AAA));
            addr_q = PAYLOAD_MADR + 32'd144;
            preload_qword(addr_q, aplusd_real(R_XYZF2, 64'h0000_0000_0000_0BBB));

            // ---------- Tag3: SPRITE (3 entries) ----------
            // q10 GIFtag NLOOP=1 NREG=3 EOP=0
            addr_q = PAYLOAD_MADR + 32'd160;
            preload_qword(addr_q, giftag(15'd1, 1'b0, 2'd0, 4'd3,
                                         64'h0000_0000_0000_0EEE));
            // q11 PRIM=SPRITE
            addr_q = PAYLOAD_MADR + 32'd176;
            preload_qword(addr_q, aplusd_real(R_PRIM, PRIM_SPRITE));
            // q12..q13 XYZ2 vertices
            addr_q = PAYLOAD_MADR + 32'd192;
            preload_qword(addr_q, aplusd_real(R_XYZ2, 64'h0000_0000_0000_0400));
            addr_q = PAYLOAD_MADR + 32'd208;
            preload_qword(addr_q, aplusd_real(R_XYZ2, 64'h0000_0000_0000_0500));

            // ---------- Tag4: POINT (2 entries) ----------
            // q14 GIFtag NLOOP=1 NREG=2 EOP=0
            addr_q = PAYLOAD_MADR + 32'd224;
            preload_qword(addr_q, giftag(15'd1, 1'b0, 2'd0, 4'd2,
                                         64'h0000_0000_0000_00EE));
            // q15 PRIM=POINT
            addr_q = PAYLOAD_MADR + 32'd240;
            preload_qword(addr_q, aplusd_real(R_PRIM, PRIM_POINT));
            // q16 XYZ2 vertex
            addr_q = PAYLOAD_MADR + 32'd256;
            preload_qword(addr_q, aplusd_real(R_XYZ2, 64'h0000_0000_0000_0600));

            // ---------- Tag5: TRI_STRIP (3 entries) — anchor unmet (only 2 vertices) ----------
            // q17 GIFtag NLOOP=1 NREG=3 EOP=1. TRI_STRIP needs 3
            // vertices to anchor; this tag only provides 2, so
            // vert_count stops at 2 and no draw fires. Full strip
            // cadence is exercised in tb_ee_core_gif_primitive_strip.
            addr_q = PAYLOAD_MADR + 32'd272;
            preload_qword(addr_q, giftag(15'd1, 1'b1, 2'd0, 4'd3,
                                         64'h0000_0000_0000_0EEE));
            // q18 PRIM=TRI_STRIP
            addr_q = PAYLOAD_MADR + 32'd288;
            preload_qword(addr_q, aplusd_real(R_PRIM, PRIM_TRI_STRIP));
            // q19..q20 XYZ2 vertices (no draw — threshold 0)
            addr_q = PAYLOAD_MADR + 32'd304;
            preload_qword(addr_q, aplusd_real(R_XYZ2, 64'h0000_0000_0000_0700));
            addr_q = PAYLOAD_MADR + 32'd320;
            preload_qword(addr_q, aplusd_real(R_XYZ2, 64'h0000_0000_0000_0800));
        end

        write_dmac(MADR_OFF, PAYLOAD_MADR);
        write_dmac(QWC_OFF,  NUM_QWORDS);
        write_dmac(CHCR_OFF, 32'h0000_0001);

        wait (dma_done_seen == 1'b1);
        repeat (40) @(posedge clk);

        $display("[tb_ee_core_gif_primitive_observer] dma=(%0d,%0d,%0d)  gif=(tag=%0d,wr=%0d,mode=%0d)  gs=(bg=%0d,wr=%0d,prim_draw=%0d,mode=%0d)  prim_complete_count=%0d  prim_pulses=%0d",
                 dma_start_count, dma_beat_count, dma_done_count,
                 gif_giftag_count, gif_write_count, gif_mode_count,
                 gs_bgcolor_count, gs_write_count, gs_prim_draw_count, gs_mode_count,
                 prim_complete_count, prim_complete_pulse_count);
        $display("[tb_ee_core_gif_primitive_observer] final latches: prim=0x%016h xyz2=0x%016h",
                 prim_q, xyz2_q);

        if (dma_start_count != 1)         begin $error("dma_start"); errors = errors + 1; end
        if (dma_beat_count  != NUM_QWORDS) begin $error("dma_beat=%0d (expected %0d)", dma_beat_count, NUM_QWORDS); errors = errors + 1; end
        if (dma_done_count  != 1)         begin $error("dma_done"); errors = errors + 1; end
        if (gif_giftag_count != 5)        begin $error("gif_giftag=%0d (expected 5)", gif_giftag_count); errors = errors + 1; end
        if (gif_write_count != 16)        begin $error("gif_write=%0d (expected 16: 5+3+3+2+3 A+D entries)", gif_write_count); errors = errors + 1; end
        if (gif_mode_count != 0)          begin $error("gif_mode=%0d (expected 0)", gif_mode_count); errors = errors + 1; end
        if (gs_bgcolor_count != 0)        begin $error("gs_bgcolor=%0d (expected 0)", gs_bgcolor_count); errors = errors + 1; end
        if (gs_write_count != 12)         begin $error("gs_write=%0d (expected 12: TRI 4+LINE 2+SPRITE 2+POINT 1+STRIP 3)", gs_write_count); errors = errors + 1; end
        if (gs_prim_draw_count != 4)      begin $error("gs_prim_draw=%0d (expected 4: TRI+LINE+SPRITE+POINT, not STRIP)", gs_prim_draw_count); errors = errors + 1; end
        if (gs_mode_count != 0)           begin $error("gs_mode=%0d (expected 0)", gs_mode_count); errors = errors + 1; end
        if (prim_complete_count != 32'd4) begin $error("prim_complete_count=%0d (expected 4)", prim_complete_count); errors = errors + 1; end
        if (prim_complete_pulse_count != 4) begin $error("prim_complete pulses=%0d (expected 4)", prim_complete_pulse_count); errors = errors + 1; end
        if (prim_q !== PRIM_TRI_STRIP)    begin $error("prim_q=0x%016h (expected 0x4)", prim_q); errors = errors + 1; end
        if (xyz2_q !== 64'h0000_0000_0000_0800) begin $error("xyz2_q=0x%016h (expected 0x800 — last STRIP vertex)", xyz2_q); errors = errors + 1; end
        if (xyzf2_q !== 64'h0000_0000_0000_0BBB) begin $error("xyzf2_q=0x%016h (expected 0xBBB — last LINE vertex)", xyzf2_q); errors = errors + 1; end

        // EV_PRIM_DRAW arg checks — verify each event carries the right
        // per-primitive metadata. Order matches the stream above.
        // [0] TRI    : prim=3, threshold=3, count=1, vertex=0x300
        if (prim_draw_arg0[0] !== 64'd3)   begin $error("prim_draw[0].arg0(prim_type)=%0d (expected 3 TRI)",  prim_draw_arg0[0]); errors = errors + 1; end
        if (prim_draw_arg1[0] !== 64'd3)   begin $error("prim_draw[0].arg1(threshold)=%0d (expected 3)",      prim_draw_arg1[0]); errors = errors + 1; end
        if (prim_draw_arg2[0] !== 64'd1)   begin $error("prim_draw[0].arg2(count)=%0d (expected 1)",          prim_draw_arg2[0]); errors = errors + 1; end
        if (prim_draw_arg3[0] !== 64'h300) begin $error("prim_draw[0].arg3(vertex)=0x%h (expected 0x300)",    prim_draw_arg3[0]); errors = errors + 1; end
        // [1] LINE   : prim=1, threshold=2, count=2, vertex=0xBBB  (XYZF2 close)
        if (prim_draw_arg0[1] !== 64'd1)   begin $error("prim_draw[1].arg0(prim_type)=%0d (expected 1 LINE)", prim_draw_arg0[1]); errors = errors + 1; end
        if (prim_draw_arg1[1] !== 64'd2)   begin $error("prim_draw[1].arg1(threshold)=%0d (expected 2)",      prim_draw_arg1[1]); errors = errors + 1; end
        if (prim_draw_arg2[1] !== 64'd2)   begin $error("prim_draw[1].arg2(count)=%0d (expected 2)",          prim_draw_arg2[1]); errors = errors + 1; end
        if (prim_draw_arg3[1] !== 64'hBBB) begin $error("prim_draw[1].arg3(vertex)=0x%h (expected 0xBBB)",    prim_draw_arg3[1]); errors = errors + 1; end
        // [2] SPRITE : prim=6, threshold=2, count=3, vertex=0x500
        if (prim_draw_arg0[2] !== 64'd6)   begin $error("prim_draw[2].arg0(prim_type)=%0d (expected 6 SPRITE)", prim_draw_arg0[2]); errors = errors + 1; end
        if (prim_draw_arg1[2] !== 64'd2)   begin $error("prim_draw[2].arg1(threshold)=%0d (expected 2)",        prim_draw_arg1[2]); errors = errors + 1; end
        if (prim_draw_arg2[2] !== 64'd3)   begin $error("prim_draw[2].arg2(count)=%0d (expected 3)",            prim_draw_arg2[2]); errors = errors + 1; end
        if (prim_draw_arg3[2] !== 64'h500) begin $error("prim_draw[2].arg3(vertex)=0x%h (expected 0x500)",      prim_draw_arg3[2]); errors = errors + 1; end
        // [3] POINT  : prim=0, threshold=1, count=4, vertex=0x600
        if (prim_draw_arg0[3] !== 64'd0)   begin $error("prim_draw[3].arg0(prim_type)=%0d (expected 0 POINT)", prim_draw_arg0[3]); errors = errors + 1; end
        if (prim_draw_arg1[3] !== 64'd1)   begin $error("prim_draw[3].arg1(threshold)=%0d (expected 1)",       prim_draw_arg1[3]); errors = errors + 1; end
        if (prim_draw_arg2[3] !== 64'd4)   begin $error("prim_draw[3].arg2(count)=%0d (expected 4)",           prim_draw_arg2[3]); errors = errors + 1; end
        if (prim_draw_arg3[3] !== 64'h600) begin $error("prim_draw[3].arg3(vertex)=0x%h (expected 0x600)",     prim_draw_arg3[3]); errors = errors + 1; end

        // Ch78 vertex-tuple checks for discrete primitives.
        // [0] TRIANGLE : v0=0x100 v1=0x200 v2=0x300 (3 slots)
        if (prim_draw_v0[0] !== 64'h100) begin $error("prim_draw_v0[0]=0x%h (expected 0x100)", prim_draw_v0[0]); errors = errors + 1; end
        if (prim_draw_v1[0] !== 64'h200) begin $error("prim_draw_v1[0]=0x%h (expected 0x200)", prim_draw_v1[0]); errors = errors + 1; end
        if (prim_draw_v2[0] !== 64'h300) begin $error("prim_draw_v2[0]=0x%h (expected 0x300)", prim_draw_v2[0]); errors = errors + 1; end
        // [1] LINE (XYZF2) : v0=0xAAA v1=0xBBB v2=0 (2 slots)
        if (prim_draw_v0[1] !== 64'hAAA) begin $error("prim_draw_v0[1]=0x%h (expected 0xAAA — LINE first XYZF2 endpoint)", prim_draw_v0[1]); errors = errors + 1; end
        if (prim_draw_v1[1] !== 64'hBBB) begin $error("prim_draw_v1[1]=0x%h (expected 0xBBB — LINE close)", prim_draw_v1[1]); errors = errors + 1; end
        if (prim_draw_v2[1] !== 64'd0)   begin $error("prim_draw_v2[1]=0x%h (expected 0; 2-slot prim)", prim_draw_v2[1]); errors = errors + 1; end
        // [2] SPRITE : v0=0x400 v1=0x500 v2=0
        if (prim_draw_v0[2] !== 64'h400) begin $error("prim_draw_v0[2]=0x%h (expected 0x400)", prim_draw_v0[2]); errors = errors + 1; end
        if (prim_draw_v1[2] !== 64'h500) begin $error("prim_draw_v1[2]=0x%h (expected 0x500)", prim_draw_v1[2]); errors = errors + 1; end
        // [3] POINT : v0=0x600 v1=0 v2=0 (1 slot)
        if (prim_draw_v0[3] !== 64'h600) begin $error("prim_draw_v0[3]=0x%h (expected 0x600 — POINT vertex)", prim_draw_v0[3]); errors = errors + 1; end
        if (prim_draw_v1[3] !== 64'd0)   begin $error("prim_draw_v1[3]=0x%h (expected 0; 1-slot prim)", prim_draw_v1[3]); errors = errors + 1; end
        if (prim_draw_v2[3] !== 64'd0)   begin $error("prim_draw_v2[3]=0x%h (expected 0)", prim_draw_v2[3]); errors = errors + 1; end

        // Ch79 color-snapshot checks. RGBAQ=0x3F800000FF0030FF is
        // written ONCE in Tag1 (q2) and never again. All four
        // primitives close after that, so all four prim_draw_color
        // captures should equal that value — proves rgbaq_q carries
        // forward across PRIM context switches (matches real GS).
        if (prim_draw_color[0] !== 64'h3F80_0000_FF00_30FF) begin $error("prim_draw_color[0]=0x%h (expected 0x3F800000FF0030FF — RGBAQ from Tag1)", prim_draw_color[0]); errors = errors + 1; end
        if (prim_draw_color[1] !== 64'h3F80_0000_FF00_30FF) begin $error("prim_draw_color[1]=0x%h (expected RGBAQ to carry across LINE PRIM write)", prim_draw_color[1]); errors = errors + 1; end
        if (prim_draw_color[2] !== 64'h3F80_0000_FF00_30FF) begin $error("prim_draw_color[2]=0x%h (expected RGBAQ to carry across SPRITE PRIM write)", prim_draw_color[2]); errors = errors + 1; end
        if (prim_draw_color[3] !== 64'h3F80_0000_FF00_30FF) begin $error("prim_draw_color[3]=0x%h (expected RGBAQ to carry across POINT PRIM write)", prim_draw_color[3]); errors = errors + 1; end

        // Ch80 flat-shaded coherence: this stream writes RGBAQ once
        // (Tag1, before any vertex). All four primitives are
        // therefore flat-shaded — every per-vertex slot used by the
        // primitive must equal prim_color_q. Slots above the
        // primitive's vertex count read 0.
        // [0] TRI: all 3 slots used → all == prim_color_q
        if (prim_draw_cv0[0] !== prim_draw_color[0]) begin $error("prim_draw_cv0[0]=0x%h != prim_color_q (flat-shaded)", prim_draw_cv0[0]); errors = errors + 1; end
        if (prim_draw_cv1[0] !== prim_draw_color[0]) begin $error("prim_draw_cv1[0]=0x%h != prim_color_q (flat-shaded)", prim_draw_cv1[0]); errors = errors + 1; end
        if (prim_draw_cv2[0] !== prim_draw_color[0]) begin $error("prim_draw_cv2[0]=0x%h != prim_color_q (flat-shaded)", prim_draw_cv2[0]); errors = errors + 1; end
        // [1] LINE: 2 slots used; v2 == 0
        if (prim_draw_cv0[1] !== prim_draw_color[1]) begin $error("prim_draw_cv0[1]=0x%h != prim_color_q",        prim_draw_cv0[1]); errors = errors + 1; end
        if (prim_draw_cv1[1] !== prim_draw_color[1]) begin $error("prim_draw_cv1[1]=0x%h != prim_color_q",        prim_draw_cv1[1]); errors = errors + 1; end
        if (prim_draw_cv2[1] !== 64'd0)              begin $error("prim_draw_cv2[1]=0x%h (expected 0; LINE has 2 color slots)", prim_draw_cv2[1]); errors = errors + 1; end
        // [2] SPRITE: 2 slots used
        if (prim_draw_cv0[2] !== prim_draw_color[2]) begin $error("prim_draw_cv0[2]=0x%h != prim_color_q",        prim_draw_cv0[2]); errors = errors + 1; end
        if (prim_draw_cv1[2] !== prim_draw_color[2]) begin $error("prim_draw_cv1[2]=0x%h != prim_color_q",        prim_draw_cv1[2]); errors = errors + 1; end
        if (prim_draw_cv2[2] !== 64'd0)              begin $error("prim_draw_cv2[2]=0x%h (expected 0)",           prim_draw_cv2[2]); errors = errors + 1; end
        // [3] POINT: 1 slot used
        if (prim_draw_cv0[3] !== prim_draw_color[3]) begin $error("prim_draw_cv0[3]=0x%h != prim_color_q",        prim_draw_cv0[3]); errors = errors + 1; end
        if (prim_draw_cv1[3] !== 64'd0)              begin $error("prim_draw_cv1[3]=0x%h (expected 0)",           prim_draw_cv1[3]); errors = errors + 1; end
        if (prim_draw_cv2[3] !== 64'd0)              begin $error("prim_draw_cv2[3]=0x%h (expected 0)",           prim_draw_cv2[3]); errors = errors + 1; end

        // Ch81 decoded-field checks. The load-bearing distinction is
        // is_xyzf2: TRI/SPRITE/POINT are sourced from XYZ2 commits,
        // LINE uses XYZF2. The decode also reconstructs x/y from the
        // raw value (data[15:0] = x, [31:16] = y) and r/g/b/a/q
        // from the RGBAQ payload (0x3F800000_FF0030FF →
        // r=0xFF, g=0x30, b=0, a=0xFF, q=0x3F800000).
        //
        // iverilog 12 doesn't allow direct .field access on struct
        // array elements, so we copy each one into a local var.
        for (int i = 0; i < 4; i = i + 1) begin
            trace_pkg::vertex_t dv0, dv1, dv2;
            trace_pkg::color_t  dc0;
            dv0 = prim_draw_dv0[i];
            dv1 = prim_draw_dv1[i];
            dv2 = prim_draw_dv2[i];
            dc0 = prim_draw_dc0[i];
            case (i)
            0: begin // TRIANGLE — all XYZ2, all flat-colored
                if (dv0.x        !== 16'h100)        begin $error("dv0[0].x=0x%h (expected 0x100)", dv0.x); errors = errors + 1; end
                if (dv0.is_xyzf2 !== 1'b0)           begin $error("dv0[0].is_xyzf2=%b (expected 0; TRI uses XYZ2)", dv0.is_xyzf2); errors = errors + 1; end
                if (dv1.x        !== 16'h200)        begin $error("dv1[0].x=0x%h (expected 0x200)", dv1.x); errors = errors + 1; end
                if (dv1.is_xyzf2 !== 1'b0)           begin $error("dv1[0].is_xyzf2=%b (expected 0)", dv1.is_xyzf2); errors = errors + 1; end
                if (dv2.x        !== 16'h300)        begin $error("dv2[0].x=0x%h (expected 0x300)", dv2.x); errors = errors + 1; end
                if (dv2.is_xyzf2 !== 1'b0)           begin $error("dv2[0].is_xyzf2=%b (expected 0)", dv2.is_xyzf2); errors = errors + 1; end
                // RGBAQ decode for TRI's flat color
                if (dc0.r !== 8'hFF)                 begin $error("dc0[0].r=0x%h (expected 0xFF)",       dc0.r); errors = errors + 1; end
                if (dc0.g !== 8'h30)                 begin $error("dc0[0].g=0x%h (expected 0x30)",       dc0.g); errors = errors + 1; end
                if (dc0.b !== 8'h00)                 begin $error("dc0[0].b=0x%h (expected 0x00)",       dc0.b); errors = errors + 1; end
                if (dc0.a !== 8'hFF)                 begin $error("dc0[0].a=0x%h (expected 0xFF)",       dc0.a); errors = errors + 1; end
                if (dc0.q !== 32'h3F80_0000)         begin $error("dc0[0].q=0x%h (expected 0x3F800000)", dc0.q); errors = errors + 1; end
            end
            1: begin // LINE — *** is_xyzf2 == 1 *** for both endpoints
                if (dv0.x        !== 16'hAAA)        begin $error("dv0[1].x=0x%h (expected 0xAAA)", dv0.x); errors = errors + 1; end
                if (dv0.is_xyzf2 !== 1'b1)           begin $error("dv0[1].is_xyzf2=%b (expected 1; LINE uses XYZF2)", dv0.is_xyzf2); errors = errors + 1; end
                if (dv1.x        !== 16'hBBB)        begin $error("dv1[1].x=0x%h (expected 0xBBB)", dv1.x); errors = errors + 1; end
                if (dv1.is_xyzf2 !== 1'b1)           begin $error("dv1[1].is_xyzf2=%b (expected 1; LINE uses XYZF2)", dv1.is_xyzf2); errors = errors + 1; end
            end
            2: begin // SPRITE — XYZ2
                if (dv0.x        !== 16'h400)        begin $error("dv0[2].x=0x%h (expected 0x400)", dv0.x); errors = errors + 1; end
                if (dv0.is_xyzf2 !== 1'b0)           begin $error("dv0[2].is_xyzf2=%b (expected 0)", dv0.is_xyzf2); errors = errors + 1; end
                if (dv1.x        !== 16'h500)        begin $error("dv1[2].x=0x%h (expected 0x500)", dv1.x); errors = errors + 1; end
            end
            3: begin // POINT — XYZ2
                if (dv0.x        !== 16'h600)        begin $error("dv0[3].x=0x%h (expected 0x600)", dv0.x); errors = errors + 1; end
                if (dv0.is_xyzf2 !== 1'b0)           begin $error("dv0[3].is_xyzf2=%b (expected 0)", dv0.is_xyzf2); errors = errors + 1; end
            end
            endcase
        end

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

    initial begin
        #1000000;
        $error("[tb_ee_core_gif_primitive_observer] timeout");
        $finish;
    end

endmodule : tb_ee_core_gif_primitive_observer
