module vgasim #( parameter SCREEN_H = 640, parameter SCREEN_W = 480, parameter DEPTH = 8 ) ( input logic clk, input logic nreset, input logic [DEPTH-1:0] r_i, input logic [DEPTH-1:0] g_i, input logic [DEPTH-1:0] b_i, input logic hsync_i, input logic vsync_i ); import "DPI-C" function int vgasim_init(input int screen_h, input int screen_w, input int screen_bpp); import "DPI-C" function int vgasim_reset(); import "DPI-C" function int vgasim_tick(input int r, input int g, input int b, input int hsync, input int vsync); logic vgasim_initialised = 0; initial begin automatic int ret = vgasim_init(SCREEN_W, SCREEN_H, DEPTH); if (ret != 0) begin $display($sformatf("[%0t] vgasim init failed: %d", $time, ret)); end else begin vgasim_initialised = '1; end end always @(negedge nreset iff vgasim_initialised) begin automatic int ret = vgasim_reset(); assert (ret == 0) else begin $display($sformatf("[%0t] vgasim reset failed: %d", $time, ret)); $fatal(); end end always @(posedge clk iff nreset && vgasim_initialised) begin automatic int ret = vgasim_tick(r_i, g_i, b_i, hsync_i, vsync_i); assert (ret == 0) else begin $display($sformatf("[%0t] vgasim tick failed: %d", $time, ret)); $fatal(); end end endmodule : vgasim