pico-ice-video/ice/coords.sv

43 lines
892 B
Systemverilog
Raw Normal View History

2024-10-06 04:18:41 +00:00
module coords
#(
2024-10-09 19:18:36 +00:00
parameter WIDTH = 256,
parameter HEIGHT = 256,
2024-10-06 04:18:41 +00:00
parameter POS_COUNT = 4,
localparam WIDTH_BITS = $clog2(WIDTH),
localparam HEIGHT_BITS = $clog2(HEIGHT)
)(
input wire clk,
input wire rst,
2024-10-09 19:18:36 +00:00
input wire inc,
2024-10-06 04:18:41 +00:00
output reg [WIDTH_BITS-1:0] x[POS_COUNT],
2024-10-09 19:18:36 +00:00
output reg [HEIGHT_BITS-1:0] y[POS_COUNT],
2024-10-06 04:18:41 +00:00
output wire finished
);
reg [POS_COUNT-1:0] finished_r;
always_ff @(posedge clk) begin
if (rst) begin
2024-10-09 19:18:36 +00:00
integer i;
2024-10-06 04:18:41 +00:00
for (i = 0; i < POS_COUNT; i = i + 1) begin
x[i] <= WIDTH_BITS'(i);
y[i] <= 0;
end
finished_r <= '1;
2024-10-09 19:18:36 +00:00
end else if (inc) begin
integer i;
2024-10-06 04:18:41 +00:00
for (i = 0; i < POS_COUNT; i = i + 1) begin
2024-10-09 19:18:36 +00:00
x[i] <= x[i] + POS_COUNT;
if (32'(x[i]) > (32'(x[i]) + POS_COUNT) % WIDTH) begin
2024-10-06 04:18:41 +00:00
y[i] <= y[i] + 1;
2024-10-09 19:18:36 +00:00
if (32'(y[i]) > (32'(y[i]) + 1) % HEIGHT) begin
2024-10-06 04:18:41 +00:00
finished_r[i] <= 0;
end
end
end
end
end
assign finished = finished_r == 0;
endmodule