2018-08-13 22:17:36 +00:00
|
|
|
|
2018-06-04 02:01:40 +00:00
|
|
|
`include "hvsync_generator.v"
|
|
|
|
|
2018-10-01 16:30:47 +00:00
|
|
|
/*
|
|
|
|
Paddle demonstration.
|
|
|
|
*/
|
|
|
|
|
2018-07-22 12:31:42 +00:00
|
|
|
module paddles_top(clk, reset, hsync, vsync, hpaddle, vpaddle, rgb);
|
2018-06-04 02:01:40 +00:00
|
|
|
|
|
|
|
input clk, reset;
|
|
|
|
input hpaddle, vpaddle;
|
|
|
|
output hsync, vsync;
|
|
|
|
output [2:0] rgb;
|
|
|
|
wire display_on;
|
|
|
|
wire [8:0] hpos;
|
|
|
|
wire [8:0] vpos;
|
|
|
|
|
2018-07-31 18:41:27 +00:00
|
|
|
// player position (only set at VSYNC)
|
2018-06-04 02:01:40 +00:00
|
|
|
reg [7:0] player_x;
|
|
|
|
reg [7:0] player_y;
|
|
|
|
|
2018-07-31 18:41:27 +00:00
|
|
|
// paddle position (set continuously during frame)
|
2018-06-04 02:01:40 +00:00
|
|
|
reg [7:0] paddle_x;
|
|
|
|
reg [7:0] paddle_y;
|
|
|
|
|
|
|
|
// read horizontal paddle
|
|
|
|
always @(posedge hpaddle)
|
|
|
|
paddle_x <= vpos[7:0];
|
|
|
|
|
|
|
|
// read vertical paddle
|
|
|
|
always @(posedge vpaddle)
|
|
|
|
paddle_y <= vpos[7:0];
|
|
|
|
|
|
|
|
// update player_x and player_y
|
|
|
|
always @(posedge vsync)
|
|
|
|
begin
|
|
|
|
player_x <= paddle_x;
|
|
|
|
player_y <= paddle_y;
|
|
|
|
end
|
|
|
|
|
|
|
|
hvsync_generator hvsync_gen(
|
|
|
|
.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.hsync(hsync),
|
|
|
|
.vsync(vsync),
|
|
|
|
.display_on(display_on),
|
|
|
|
.hpos(hpos),
|
|
|
|
.vpos(vpos)
|
|
|
|
);
|
|
|
|
|
|
|
|
// display paddle positions on screen
|
|
|
|
|
|
|
|
wire h = hpos[7:0] >= paddle_x;
|
|
|
|
wire v = vpos[7:0] >= paddle_y;
|
|
|
|
|
|
|
|
assign rgb = {1'b0, display_on && h, display_on && v};
|
|
|
|
|
|
|
|
endmodule
|