go-board-code/vga_current_beam_position.v

48 lines
1.0 KiB
Coq
Raw Normal View History

2024-07-06 18:51:29 +00:00
// Keys off of HSync and VSync signals to get the actual electron
// beam position
module VGA_Current_Beam_Position(
input i_Clk,
input i_HSync,
input i_VSync,
output reg o_HSync = 0,
output reg o_VSync = 0,
output reg [$clog2(TOTAL_COLUMNS)-1:0] o_X,
output reg [$clog2(TOTAL_ROWS)-1:0] o_Y
);
parameter TOTAL_COLUMNS = 800;
parameter TOTAL_ROWS = 525;
wire w_frameStart;
// forward these flip-flop style. use these instead of what
// comes out of sync pulse generator!
always @(posedge i_Clk) begin
o_VSync <= i_VSync;
o_HSync <= i_HSync;
end
always @(posedge i_Clk) begin
if (w_frameStart == 1) begin
o_X <= 0;
o_Y <= 0;
end else begin
if (o_X == TOTAL_COLUMNS - 1) begin
o_X <= 0;
if (o_Y == TOTAL_ROWS - 1) begin
o_Y <= 0;
end else begin
o_Y <= o_Y + 1;
end
end else begin
o_X <= o_X + 1;
end
end
end
// rising vsync == new frame
assign w_frameStart = (~o_VSync & i_VSync);
endmodule