aboutsummaryrefslogtreecommitdiff
path: root/task2/fillscreen.sv
blob: de7a9288c58f79125880387c0cd3cab4de55679b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module fillscreen(clk, rst_n, colour, start,
	done, vga_x, vga_y, vga_colour, vga_plot);

	input logic clk, rst_n, start;
	input logic [2:0] colour;
	output logic done, vga_plot;
	output logic [2:0] vga_colour;
	output logic [6:0] vga_y;
	output logic [7:0] vga_x;

	logic clear;
	logic [6:0] y_next;
	logic [7:0] x_next;

	assign vga_colour = clear ? 3'b000 : vga_x[2:0];
	assign vga_plot = clear || (start && ~done);
	assign x_next = vga_x + 1;
	assign y_next = vga_y + 1;

	always_ff @(posedge clk) begin
		if (~rst_n) begin
			done <= 1'b0;
			vga_x <= 8'b0;
			vga_y <= 7'b0;
			/* Start clearing the screen. */
			clear <= 1'b1;
		end

		if (clear || (start && ~done)) begin
			if (vga_y < 120) begin
				/* Check for one column less since it takes
				 * one clock cycle to reset and increment. */
				if (vga_x < 159)
					vga_x <= x_next;
				else begin
					vga_x <= 8'b0;
					vga_y <= y_next;
				end
			end else begin
				if (clear)
					clear <= 1'b0;
				else
					done <= 1'b1;
				vga_x <= 8'b0;
				vga_y <= 7'b0;
			end
		end else if (~start && done)
			done <= 1'b0;
	end

endmodule: fillscreen