1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-25 18:33:11 +00:00
8bitworkshop/presets/verilog/ball_absolute.v

76 lines
1.7 KiB
Coq
Raw Normal View History

2018-02-07 00:07:40 +00:00
`include "hvsync_generator.v"
module ball_absolute_top(clk, reset, hsync, vsync, rgb);
2018-02-07 00:07:40 +00:00
input clk;
input reset;
output hsync, vsync;
output [2:0] rgb;
wire display_on;
wire [8:0] hpos;
wire [8:0] vpos;
reg [8:0] ball_hpos;
reg [8:0] ball_vpos;
reg [8:0] ball_horiz_initial = 128;
reg [8:0] ball_horiz_move = -2;
reg [8:0] ball_vert_initial = 128;
reg [8:0] ball_vert_move = 2;
2018-06-01 17:33:37 +00:00
localparam BALL_SIZE = 4;
2018-02-07 00:07:40 +00:00
hvsync_generator hvsync_gen(
.clk(clk),
.reset(reset),
.hsync(hsync),
.vsync(vsync),
.display_on(display_on),
.hpos(hpos),
.vpos(vpos)
);
// update horizontal timer
always @(posedge vsync or posedge reset)
begin
if (reset) begin
ball_hpos <= ball_horiz_initial;
ball_vpos <= ball_vert_initial;
end else begin
ball_hpos <= ball_hpos + ball_horiz_move;
ball_vpos <= ball_vpos + ball_vert_move;
end
end
// vertical bounce
always @(posedge ball_vert_collide)
begin
ball_vert_move <= -ball_vert_move;
end
// horizontal bounce
always @(posedge ball_horiz_collide)
begin
ball_horiz_move <= -ball_horiz_move;
end
2018-06-01 17:33:37 +00:00
wire [8:0] ball_hdiff = hpos - ball_hpos;
wire [8:0] ball_vdiff = vpos - ball_vpos;
2018-02-07 00:07:40 +00:00
wire ball_hgfx = ball_hdiff < BALL_SIZE;
wire ball_vgfx = ball_vdiff < BALL_SIZE;
wire ball_gfx = ball_hgfx && ball_vgfx;
// collide with vertical and horizontal boundaries
2018-06-01 17:33:37 +00:00
wire ball_vert_collide = ball_vpos >= 240 - BALL_SIZE;
wire ball_horiz_collide = ball_hpos >= 256 - BALL_SIZE;
2018-02-07 00:07:40 +00:00
wire grid_gfx = (((hpos&7)==0) && ((vpos&7)==0));
wire r = display_on && (ball_hgfx | ball_gfx);
wire g = display_on && (grid_gfx | ball_gfx);
wire b = display_on && (ball_vgfx | ball_gfx);
assign rgb = {b,g,r};
endmodule