data/full_repos/permissive/460183508/rtl/pix_gen.v
data/verilator_xmls/f1c49863-b1a7-483e-b4a8-f73438f6b780.xml
module pixel_generator
(
    input wire reset,
    input wire clk,
    input wire load,
    input wire [7:0] attribute_data,
    input wire [7:0] font_data,
    input wire [2:0] char_msbs,
    input wire blink_state,
    input wire cursor_active,
    input wire extended_bg_colours,
    
    output wire [3:0] colour_index
);


    reg [8:0] pixels;
    

    reg [7:0] attributes;
    

    reg cursor_active_latch;
    

    wire foreground = cursor_active_latch |
                      ~attributes[7] & pixels[8] |
                      ~extended_bg_colours & attributes[7] & blink_state & pixels[8] |
                      extended_bg_colours & pixels[8];
    

    wire [3:0] foreground_colour = attributes[3:0];
    wire [3:0] background_colour =
        extended_bg_colours ? attributes[7:4] : {1'b0, attributes[6:4]};
        
    assign colour_index = foreground ? foreground_colour : background_colour;
    

    always @(posedge reset, posedge clk) begin
        if (reset) begin

            pixels <= 9'b000000000;
        end
        else begin
            if (load) begin
                if (char_msbs == 3'b110) begin

                     pixels = {font_data, font_data[0]};
                end
                else begin

                     pixels = {font_data, 1'b0};
                end
            end
            else begin

                pixels <= {pixels[7:0], 1'b0};
            end
        end
    end
    

    always @(posedge clk) begin

        if (load) begin
            attributes <= attribute_data;
        end
    end
    

    always @(posedge clk) begin

        if (load) begin
            cursor_active_latch <= cursor_active;
        end
    end
endmodule
module pixel_generator
(
    input wire reset,
    input wire clk,
    input wire load,
    input wire [7:0] attribute_data,
    input wire [7:0] font_data,
    input wire [2:0] char_msbs,
    input wire blink_state,
    input wire cursor_active,
    input wire extended_bg_colours,
    
    output wire [3:0] colour_index
);



    reg [8:0] pixels;
    

    reg [7:0] attributes;
    

    reg cursor_active_latch;
    

    wire foreground = cursor_active_latch |
                      ~attributes[7] & pixels[8] |
                      ~extended_bg_colours & attributes[7] & blink_state & pixels[8] |
                      extended_bg_colours & pixels[8];
    

    wire [3:0] foreground_colour = attributes[3:0];
    wire [3:0] background_colour =
        extended_bg_colours ? attributes[7:4] : {1'b0, attributes[6:4]};
        
    assign colour_index = foreground ? foreground_colour : background_colour;
    

    always @(posedge reset, posedge clk) begin
        if (reset) begin

            pixels <= 9'b000000000;
        end
        else begin
            if (load) begin
                if (char_msbs == 3'b110) begin

                     pixels = {font_data, font_data[0]};
                end
                else begin

                     pixels = {font_data, 1'b0};
                end
            end
            else begin

                pixels <= {pixels[7:0], 1'b0};
            end
        end
    end
    

    always @(posedge clk) begin

        if (load) begin
            attributes <= attribute_data;
        end
    end
    

    always @(posedge clk) begin

        if (load) begin
            cursor_active_latch <= cursor_active;
        end
    end
endmodule