MacPlus_MiSTer/sys/sync_vg.v

79 lines
1.7 KiB
Coq
Raw Normal View History

2017-10-22 01:22:56 +00:00
module sync_vg
#(
2018-03-05 17:40:43 +00:00
parameter X_BITS=12, Y_BITS=12
2017-10-22 01:22:56 +00:00
)
(
input wire clk,
input wire reset,
2018-03-05 17:40:43 +00:00
input wire [Y_BITS-1:0] v_total,
input wire [Y_BITS-1:0] v_fp,
input wire [Y_BITS-1:0] v_bp,
input wire [Y_BITS-1:0] v_sync,
2017-10-22 01:22:56 +00:00
input wire [X_BITS-1:0] h_total,
input wire [X_BITS-1:0] h_fp,
input wire [X_BITS-1:0] h_bp,
input wire [X_BITS-1:0] h_sync,
2018-03-05 17:40:43 +00:00
input wire [X_BITS-1:0] hv_offset,
2017-10-22 01:22:56 +00:00
output reg vs_out,
output reg hs_out,
output reg hde_out,
output reg vde_out,
2018-03-05 17:40:43 +00:00
output reg [Y_BITS-1:0] v_count_out,
2017-10-22 01:22:56 +00:00
output reg [X_BITS-1:0] h_count_out,
output reg [X_BITS-1:0] x_out,
2018-03-05 17:40:43 +00:00
output reg [Y_BITS-1:0] y_out
2017-10-22 01:22:56 +00:00
);
reg [X_BITS-1:0] h_count;
reg [Y_BITS-1:0] v_count;
/* horizontal counter */
always @(posedge clk)
if (reset)
h_count <= 0;
else
if (h_count < h_total - 1)
h_count <= h_count + 1'd1;
else
h_count <= 0;
/* vertical counter */
always @(posedge clk)
if (reset)
v_count <= 0;
else
if (h_count == h_total - 1)
begin
if (v_count == v_total - 1)
v_count <= 0;
else
v_count <= v_count + 1'd1;
end
always @(posedge clk)
if (reset)
2018-03-05 17:40:43 +00:00
{ vs_out, hs_out, hde_out, vde_out } <= 0;
2017-10-22 01:22:56 +00:00
else begin
hs_out <= ((h_count < h_sync));
hde_out <= (h_count >= h_sync + h_bp) && (h_count <= h_total - h_fp - 1);
vde_out <= (v_count >= v_sync + v_bp) && (v_count <= v_total - v_fp - 1);
if ((v_count == 0) && (h_count == hv_offset))
vs_out <= 1'b1;
else if ((v_count == v_sync) && (h_count == hv_offset))
vs_out <= 1'b0;
/* H_COUNT_OUT and V_COUNT_OUT */
h_count_out <= h_count;
2018-03-05 17:40:43 +00:00
v_count_out <= v_count;
2017-10-22 01:22:56 +00:00
2018-03-05 17:40:43 +00:00
/* X and Y coords for a backend pattern generator */
2017-10-22 01:22:56 +00:00
x_out <= h_count - (h_sync + h_bp);
2018-03-05 17:40:43 +00:00
y_out <= v_count - (v_sync + v_bp);
2017-10-22 01:22:56 +00:00
end
endmodule