go-board-code/vga_current_beam_position.v

54 lines
1.2 KiB
Verilog

// 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,
output o_IsActiveArea
);
parameter TOTAL_COLUMNS = 800;
parameter TOTAL_ROWS = 525;
parameter ACTIVE_COLUMNS = 640;
parameter ACTIVE_ROWS = 480;
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);
assign o_IsActiveArea = (o_X < ACTIVE_COLUMNS && o_Y < ACTIVE_COLUMNS);
endmodule