data/full_repos/permissive/117026779/src/VGA.v
1: b"%Error: data/full_repos/permissive/117026779/src/VGA.v:93: syntax error, unexpected '(', expecting IDENTIFIER\n    .clk(clk),\n    ^\n%Error: Exiting due to 1 error(s)\n"
module VGA_Terminal_Control_Unit(
    input wire pclk,
    input wire rst,
    input wire vblank,
    input wire hblank,
    input wire [(`TOTAL_SEGMENTS*`VALUE_BIT_WIDTH)-1:0] values,
    output reg [11:0] video_address,
    output reg [11:0] buffer_address,
    input wire [11:0] external_address,
    inout wire [7:0] video_data,
    inout wire [7:0] buffer_data,
    output reg xy_count_select,
    output reg buffer_databus_enable,
    output reg video_wr,
    output reg video_cs,
    output reg video_oe,
    output reg buffer_wr,
    output reg buffer_cs,
    output reg buffer_oe
);




parameter LOAD_RAMS 			= 0;
parameter WAIT_FOR_VBLANK 		= 1;
parameter WRITE_HEX_TO_BUFFER 	= 2;
parameter COPY_BUFFER_TO_VIDEO 	= 3;
parameter WAIT_OUT_VBLANK  		= 4;
parameter STATE_WIDTH           = $clog2(WAIT_OUT_VBLANK+1);
parameter HEX_DIGIT_WIDTH       = 4;
parameter STRING_MATRIX_WIDTH   = (`HARDWARE_CONTROLLED_ROWS*`TERMINAL_COLUMNS*`ASCII_WIDTH);



reg [STATE_WIDTH-1:0]  state;
reg [`ASCII_WIDTH-1:0] video_databus;
reg [`ASCII_WIDTH-1:0] buffer_databus;
reg [3:0] temp_value;
reg video_databus_enable;
reg [$clog2(`TERMINAL_CHARACTER_COUNT)-1:0] previous_position;
reg [$clog2(`TERMINAL_CHARACTER_COUNT)-1:0] position_counter;
reg [$clog2(`TERMINAL_CHARACTER_COUNT)-1:0] hex_counter;



wire [HEX_DIGIT_WIDTH-1:0] hex_digit;
wire [`ASCII_WIDTH-1:0] string_character;
wire [STRING_MATRIX_WIDTH-1:0] strings = {
    "       PC:0x","FFFFFFFF","   WRADDR:0x","FFFFFFFF","   DEBUG0:0x","FFFFFFFF","   DEBUG5:0x","FFFFFFFF",
    "   ALUOUT:0x","FFFFFFFF","  DataBus:0x","FFFFFFFF","   DEBUG1:0x","FFFFFFFF","   DEBUG6:0x","FFFFFFFF",
    "  REGOUT1:0x","FFFFFFFF","  AddrBus:0x","FFFFFFFF","   DEBUG2:0x","FFFFFFFF","   DEBUG7:0x","FFFFFFFF",
    "  REGOUT2:0x","FFFFFFFF","  CtrlSig:0x","FFFFFFFF","   DEBUG3:0x","FFFFFFFF","   DEBUG8:0x","FFFFFFFF",
    " REGWRITE:0x","FFFFFFFF"," Instruct:0x","FFFFFFFF","   DEBUG4:0x","FFFFFFFF","   DEBUG9:0x","FFFFFFFF",
    "------------","--------","------------","--DEBUG ","MONITOR-----","--------","------------","--------"
};



assign video_data  = (video_databus_enable)  ? video_databus  : 8'hZ;
assign buffer_data = (buffer_databus_enable) ? buffer_databus : 8'hZ;



MUX #(
    .WIDTH(HEX_DIGIT_WIDTH),
    .INPUTS((`TOTAL_SEGMENTS*`VALUE_BIT_WIDTH)/HEX_DIGIT_WIDTH)
) value_matrix_hex_multiplexer (
    .select((`TOTAL_SEGMENTS*(`VALUE_BIT_WIDTH/HEX_DIGIT_WIDTH))-hex_counter),
    .in(values),
    .out(hex_digit)
);

MUX #(
    .WIDTH(`ASCII_WIDTH),
    .INPUTS(STRING_MATRIX_WIDTH/`ASCII_WIDTH)
) string_matrix_character_multiplexer (
    .select((STRING_MATRIX_WIDTH/`ASCII_WIDTH)-position_counter),
    .in(strings),
    .out(string_character)
);



always @(posedge pclk or posedge rst)
begin
    if (rst)
    begin

        state                   <= 0;

        xy_count_select         <= 0;

        video_address           <= 0;
        video_wr                <= 0;
        video_cs                <= 0;
        video_oe                <= 0;

        buffer_address          <= 0;
        buffer_wr               <= 0;
        buffer_cs               <= 0;
        buffer_oe               <= 0;

        position_counter        <= 1;
        previous_position       <= 0;
        hex_counter             <= 0;


        video_databus_enable    <= 0;
        buffer_databus_enable   <= 0;
        video_databus           <= string_character;
        buffer_databus          <= string_character;
    end
    else
    begin
        case(state)
            LOAD_RAMS:
            begin

                state                   <= (position_counter < `TERMINAL_CHARACTER_COUNT) ? LOAD_RAMS : WAIT_FOR_VBLANK;

                xy_count_select         <= 0;

                video_address           <= position_counter - 1;
                video_wr                <= 1;
                video_cs                <= 1;
                video_oe                <= 0;

                buffer_address          <= position_counter - 1;
                buffer_wr               <= 1;
                buffer_cs               <= 1;
                buffer_oe               <= 0;

                position_counter        <= (position_counter < `TERMINAL_CHARACTER_COUNT) ? position_counter + 1 : 0;
                previous_position       <= 0;
                hex_counter             <= 0;


                video_databus_enable    <= 1;
                buffer_databus_enable   <= 1;


                video_databus           <= (position_counter < STRING_MATRIX_WIDTH/`ASCII_WIDTH) ? string_character : 8'b0;
                buffer_databus          <= (position_counter < STRING_MATRIX_WIDTH/`ASCII_WIDTH) ? string_character : 8'b0;
            end
            WAIT_FOR_VBLANK:
            begin

                state                   <= (vblank) ? WRITE_HEX_TO_BUFFER : WAIT_FOR_VBLANK;

                xy_count_select         <= 1;

                video_address           <= 0;
                video_wr                <= 0;
                video_cs                <= 1;
                video_oe                <= 1;

                buffer_address          <= 0;
                buffer_wr               <= 1;
                buffer_cs               <= 0;
                buffer_oe               <= 0;

                position_counter        <= (vblank) ? 12 : 0;
                previous_position       <= (vblank) ? 12 : 0;
                hex_counter             <= 1;


                video_databus_enable    <= 0;
                buffer_databus_enable   <= 0;
                video_databus           <= 0;
                buffer_databus          <= 0;
            end
            WRITE_HEX_TO_BUFFER:
            begin



                xy_count_select         <= 0;

                video_address           <= 0;
                video_wr                <= 0;
                video_cs                <= 0;
                video_oe                <= 0;

                buffer_address          <= position_counter;
                buffer_wr               <= 1;
                buffer_cs               <= 1;
                buffer_oe               <= 0;





                video_databus_enable    <= 0;
                buffer_databus_enable   <= 1;
                video_databus           <= 0;

                case(hex_digit)
                    4'h0: buffer_databus <= "0";
                    4'h1: buffer_databus <= "1";
                    4'h2: buffer_databus <= "2";
                    4'h3: buffer_databus <= "3";
                    4'h4: buffer_databus <= "4";
                    4'h5: buffer_databus <= "5";
                    4'h6: buffer_databus <= "6";
                    4'h7: buffer_databus <= "7";
                    4'h8: buffer_databus <= "8";
                    4'h9: buffer_databus <= "9";
                    4'hA: buffer_databus <= "A";
                    4'hB: buffer_databus <= "B";
                    4'hC: buffer_databus <= "C";
                    4'hD: buffer_databus <= "D";
                    4'hE: buffer_databus <= "E";
                    4'hF: buffer_databus <= "F";
                endcase

                if(position_counter > (`TERMINAL_COLUMNS*(`HARDWARE_CONTROLLED_ROWS-1)-2))
                begin
                    state               <= COPY_BUFFER_TO_VIDEO;
                    previous_position   <= 0;
                    position_counter    <= 0;
                    hex_counter         <= hex_counter;
                end
                else if(position_counter == previous_position+7)
                begin
                    state               <= WRITE_HEX_TO_BUFFER;
                    previous_position   <= previous_position + 20;
                    position_counter    <= previous_position + 20;
                    hex_counter         <= hex_counter + 1;
                end
                else
                begin
                    state               <= WRITE_HEX_TO_BUFFER;
                    previous_position   <= previous_position;
                    position_counter    <= position_counter + 1;
                    hex_counter         <= hex_counter + 1;
                end
            end
            COPY_BUFFER_TO_VIDEO:
            begin



                xy_count_select         <= 0;

                video_address           <= (position_counter > 1) ? position_counter-2 : 0;
                video_wr                <= 1;
                video_cs                <= 1;
                video_oe                <= 0;

                buffer_address          <= position_counter;
                buffer_wr               <= 0;
                buffer_cs               <= 1;
                buffer_oe               <= 1;


                previous_position       <= 0;


                video_databus_enable    <= 1;
                buffer_databus_enable   <= 0;


                if(buffer_address == external_address+1)
                begin
                    video_databus       <= `CURSOR;
                end
                else
                begin
                    video_databus       <= buffer_data;
                end

                if(position_counter < (`TERMINAL_CHARACTER_COUNT)-1)
                begin
                    state               <= COPY_BUFFER_TO_VIDEO;
                    position_counter    <= position_counter + 1;
                end
                else
                begin
                    state               <= WAIT_OUT_VBLANK;
                    position_counter    <= 0;
                end
            end
            WAIT_OUT_VBLANK:
            begin

                if(vblank)
                begin
                    state = WAIT_OUT_VBLANK;
                end
                else
                begin
                    state = WAIT_FOR_VBLANK;
                end

                xy_count_select         <= 0;

                video_address           <= 0;
                video_wr                <= 0;
                video_cs                <= 0;
                video_oe                <= 0;

                buffer_address          <= 0;
                buffer_wr               <= 1;
                buffer_cs               <= 0;
                buffer_oe               <= 0;

                position_counter        <= 0;
                previous_position       <= 0;


                video_databus_enable    <= 0;
                buffer_databus_enable   <= 0;
                video_databus           <= 0;
                buffer_databus          <= 0;
            end
            default:
            begin

                state                   <= 0;

                xy_count_select         <= 0;

                video_address           <= 0;
                video_wr                <= 0;
                video_cs                <= 0;
                video_oe                <= 0;

                buffer_address          <= 0;
                buffer_wr               <= 0;
                buffer_cs               <= 0;
                buffer_oe               <= 0;

                position_counter        <= 0;
                previous_position       <= 0;


                video_databus_enable    <= 0;
                buffer_databus_enable   <= 0;
                video_databus           <= 0;
                buffer_databus          <= 0;
            end
        endcase
    end
end

endmodule
module VGA_Terminal_Control_Unit(
    input wire pclk,
    input wire rst,
    input wire vblank,
    input wire hblank,
    input wire [(`TOTAL_SEGMENTS*`VALUE_BIT_WIDTH)-1:0] values,
    output reg [11:0] video_address,
    output reg [11:0] buffer_address,
    input wire [11:0] external_address,
    inout wire [7:0] video_data,
    inout wire [7:0] buffer_data,
    output reg xy_count_select,
    output reg buffer_databus_enable,
    output reg video_wr,
    output reg video_cs,
    output reg video_oe,
    output reg buffer_wr,
    output reg buffer_cs,
    output reg buffer_oe
);





parameter LOAD_RAMS 			= 0;
parameter WAIT_FOR_VBLANK 		= 1;
parameter WRITE_HEX_TO_BUFFER 	= 2;
parameter COPY_BUFFER_TO_VIDEO 	= 3;
parameter WAIT_OUT_VBLANK  		= 4;
parameter STATE_WIDTH           = $clog2(WAIT_OUT_VBLANK+1);
parameter HEX_DIGIT_WIDTH       = 4;
parameter STRING_MATRIX_WIDTH   = (`HARDWARE_CONTROLLED_ROWS*`TERMINAL_COLUMNS*`ASCII_WIDTH);



reg [STATE_WIDTH-1:0]  state;
reg [`ASCII_WIDTH-1:0] video_databus;
reg [`ASCII_WIDTH-1:0] buffer_databus;
reg [3:0] temp_value;
reg video_databus_enable;
reg [$clog2(`TERMINAL_CHARACTER_COUNT)-1:0] previous_position;
reg [$clog2(`TERMINAL_CHARACTER_COUNT)-1:0] position_counter;
reg [$clog2(`TERMINAL_CHARACTER_COUNT)-1:0] hex_counter;



wire [HEX_DIGIT_WIDTH-1:0] hex_digit;
wire [`ASCII_WIDTH-1:0] string_character;
wire [STRING_MATRIX_WIDTH-1:0] strings = {
    "       PC:0x","FFFFFFFF","   WRADDR:0x","FFFFFFFF","   DEBUG0:0x","FFFFFFFF","   DEBUG5:0x","FFFFFFFF",
    "   ALUOUT:0x","FFFFFFFF","  DataBus:0x","FFFFFFFF","   DEBUG1:0x","FFFFFFFF","   DEBUG6:0x","FFFFFFFF",
    "  REGOUT1:0x","FFFFFFFF","  AddrBus:0x","FFFFFFFF","   DEBUG2:0x","FFFFFFFF","   DEBUG7:0x","FFFFFFFF",
    "  REGOUT2:0x","FFFFFFFF","  CtrlSig:0x","FFFFFFFF","   DEBUG3:0x","FFFFFFFF","   DEBUG8:0x","FFFFFFFF",
    " REGWRITE:0x","FFFFFFFF"," Instruct:0x","FFFFFFFF","   DEBUG4:0x","FFFFFFFF","   DEBUG9:0x","FFFFFFFF",
    "------------","--------","------------","--DEBUG ","MONITOR-----","--------","------------","--------"
};



assign video_data  = (video_databus_enable)  ? video_databus  : 8'hZ;
assign buffer_data = (buffer_databus_enable) ? buffer_databus : 8'hZ;



MUX #(
    .WIDTH(HEX_DIGIT_WIDTH),
    .INPUTS((`TOTAL_SEGMENTS*`VALUE_BIT_WIDTH)/HEX_DIGIT_WIDTH)
) value_matrix_hex_multiplexer (
    .select((`TOTAL_SEGMENTS*(`VALUE_BIT_WIDTH/HEX_DIGIT_WIDTH))-hex_counter),
    .in(values),
    .out(hex_digit)
);

MUX #(
    .WIDTH(`ASCII_WIDTH),
    .INPUTS(STRING_MATRIX_WIDTH/`ASCII_WIDTH)
) string_matrix_character_multiplexer (
    .select((STRING_MATRIX_WIDTH/`ASCII_WIDTH)-position_counter),
    .in(strings),
    .out(string_character)
);



always @(posedge pclk or posedge rst)
begin
    if (rst)
    begin

        state                   <= 0;

        xy_count_select         <= 0;

        video_address           <= 0;
        video_wr                <= 0;
        video_cs                <= 0;
        video_oe                <= 0;

        buffer_address          <= 0;
        buffer_wr               <= 0;
        buffer_cs               <= 0;
        buffer_oe               <= 0;

        position_counter        <= 1;
        previous_position       <= 0;
        hex_counter             <= 0;


        video_databus_enable    <= 0;
        buffer_databus_enable   <= 0;
        video_databus           <= string_character;
        buffer_databus          <= string_character;
    end
    else
    begin
        case(state)
            LOAD_RAMS:
            begin

                state                   <= (position_counter < `TERMINAL_CHARACTER_COUNT) ? LOAD_RAMS : WAIT_FOR_VBLANK;

                xy_count_select         <= 0;

                video_address           <= position_counter - 1;
                video_wr                <= 1;
                video_cs                <= 1;
                video_oe                <= 0;

                buffer_address          <= position_counter - 1;
                buffer_wr               <= 1;
                buffer_cs               <= 1;
                buffer_oe               <= 0;

                position_counter        <= (position_counter < `TERMINAL_CHARACTER_COUNT) ? position_counter + 1 : 0;
                previous_position       <= 0;
                hex_counter             <= 0;


                video_databus_enable    <= 1;
                buffer_databus_enable   <= 1;


                video_databus           <= (position_counter < STRING_MATRIX_WIDTH/`ASCII_WIDTH) ? string_character : 8'b0;
                buffer_databus          <= (position_counter < STRING_MATRIX_WIDTH/`ASCII_WIDTH) ? string_character : 8'b0;
            end
            WAIT_FOR_VBLANK:
            begin

                state                   <= (vblank) ? WRITE_HEX_TO_BUFFER : WAIT_FOR_VBLANK;

                xy_count_select         <= 1;

                video_address           <= 0;
                video_wr                <= 0;
                video_cs                <= 1;
                video_oe                <= 1;

                buffer_address          <= 0;
                buffer_wr               <= 1;
                buffer_cs               <= 0;
                buffer_oe               <= 0;

                position_counter        <= (vblank) ? 12 : 0;
                previous_position       <= (vblank) ? 12 : 0;
                hex_counter             <= 1;


                video_databus_enable    <= 0;
                buffer_databus_enable   <= 0;
                video_databus           <= 0;
                buffer_databus          <= 0;
            end
            WRITE_HEX_TO_BUFFER:
            begin



                xy_count_select         <= 0;

                video_address           <= 0;
                video_wr                <= 0;
                video_cs                <= 0;
                video_oe                <= 0;

                buffer_address          <= position_counter;
                buffer_wr               <= 1;
                buffer_cs               <= 1;
                buffer_oe               <= 0;





                video_databus_enable    <= 0;
                buffer_databus_enable   <= 1;
                video_databus           <= 0;

                case(hex_digit)
                    4'h0: buffer_databus <= "0";
                    4'h1: buffer_databus <= "1";
                    4'h2: buffer_databus <= "2";
                    4'h3: buffer_databus <= "3";
                    4'h4: buffer_databus <= "4";
                    4'h5: buffer_databus <= "5";
                    4'h6: buffer_databus <= "6";
                    4'h7: buffer_databus <= "7";
                    4'h8: buffer_databus <= "8";
                    4'h9: buffer_databus <= "9";
                    4'hA: buffer_databus <= "A";
                    4'hB: buffer_databus <= "B";
                    4'hC: buffer_databus <= "C";
                    4'hD: buffer_databus <= "D";
                    4'hE: buffer_databus <= "E";
                    4'hF: buffer_databus <= "F";
                endcase

                if(position_counter > (`TERMINAL_COLUMNS*(`HARDWARE_CONTROLLED_ROWS-1)-2))
                begin
                    state               <= COPY_BUFFER_TO_VIDEO;
                    previous_position   <= 0;
                    position_counter    <= 0;
                    hex_counter         <= hex_counter;
                end
                else if(position_counter == previous_position+7)
                begin
                    state               <= WRITE_HEX_TO_BUFFER;
                    previous_position   <= previous_position + 20;
                    position_counter    <= previous_position + 20;
                    hex_counter         <= hex_counter + 1;
                end
                else
                begin
                    state               <= WRITE_HEX_TO_BUFFER;
                    previous_position   <= previous_position;
                    position_counter    <= position_counter + 1;
                    hex_counter         <= hex_counter + 1;
                end
            end
            COPY_BUFFER_TO_VIDEO:
            begin



                xy_count_select         <= 0;

                video_address           <= (position_counter > 1) ? position_counter-2 : 0;
                video_wr                <= 1;
                video_cs                <= 1;
                video_oe                <= 0;

                buffer_address          <= position_counter;
                buffer_wr               <= 0;
                buffer_cs               <= 1;
                buffer_oe               <= 1;


                previous_position       <= 0;


                video_databus_enable    <= 1;
                buffer_databus_enable   <= 0;


                if(buffer_address == external_address+1)
                begin
                    video_databus       <= `CURSOR;
                end
                else
                begin
                    video_databus       <= buffer_data;
                end

                if(position_counter < (`TERMINAL_CHARACTER_COUNT)-1)
                begin
                    state               <= COPY_BUFFER_TO_VIDEO;
                    position_counter    <= position_counter + 1;
                end
                else
                begin
                    state               <= WAIT_OUT_VBLANK;
                    position_counter    <= 0;
                end
            end
            WAIT_OUT_VBLANK:
            begin

                if(vblank)
                begin
                    state = WAIT_OUT_VBLANK;
                end
                else
                begin
                    state = WAIT_FOR_VBLANK;
                end

                xy_count_select         <= 0;

                video_address           <= 0;
                video_wr                <= 0;
                video_cs                <= 0;
                video_oe                <= 0;

                buffer_address          <= 0;
                buffer_wr               <= 1;
                buffer_cs               <= 0;
                buffer_oe               <= 0;

                position_counter        <= 0;
                previous_position       <= 0;


                video_databus_enable    <= 0;
                buffer_databus_enable   <= 0;
                video_databus           <= 0;
                buffer_databus          <= 0;
            end
            default:
            begin

                state                   <= 0;

                xy_count_select         <= 0;

                video_address           <= 0;
                video_wr                <= 0;
                video_cs                <= 0;
                video_oe                <= 0;

                buffer_address          <= 0;
                buffer_wr               <= 0;
                buffer_cs               <= 0;
                buffer_oe               <= 0;

                position_counter        <= 0;
                previous_position       <= 0;


                video_databus_enable    <= 0;
                buffer_databus_enable   <= 0;
                video_databus           <= 0;
                buffer_databus          <= 0;
            end
        endcase
    end
end

endmodule