Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module ball_tb;
- reg clk;
- reg rst;
- reg [10:0] curr_x;
- reg [9:0] curr_y;
- reg [10:0] x_paddle1, x_paddle2, vcount, curr_y;
- reg [9:0] y_paddle1, y_paddle2, hcount, curr_x;
- // Outputs
- wire [1:0] x_velocity, y_velocity;
- wire [3:0] p1_score, p2_score;
- wire [10:0] x_ball;
- wire [9:0] y_ball;
- wire touch1, touch2;
- // Constants for paddle and display dimensions
- localparam L_position = 11'd350;
- localparam R_position = 11'd850;
- localparam paddlewidth = 11'd50;
- localparam paddleheight1 = 10'd590;
- localparam paddleheight2 = 10'd590;
- localparam V_active = 10'd799;
- localparam y_initial = V_active/2;
- localparam x_initial1 = L_position;
- localparam x_initial2 = R_position;
- localparam H_active = 11'd1279;
- // Instantiate the ball module
- ball uut (
- .clk(clk),
- .rst(rst),
- .curr_x(curr_x),
- .curr_y(curr_y),
- .x_paddle1(x_paddle1),
- .x_paddle2(x_paddle2),
- .y_paddle1(y_paddle1),
- .y_paddle2(y_paddle2),
- .paddlewidth(paddlewidth),
- .paddleheight1(paddleheight1),
- .paddleheight2(paddleheight2),
- .p1_score(p1_score),
- .p2_score(p2_score),
- .x_ball(x_ball),
- .y_ball(y_ball),
- .x_velocity(x_velocity),
- .y_velocity(y_velocity),
- .p1_touch(touch1),
- .p2_touch(touch2)
- );
- // Counter for horizontal and vertical display positions
- always @(posedge clk) begin
- if (hcount < 1679)
- hcount <= hcount + 1'b1;
- else begin
- if (vcount < 827) begin
- hcount <= 11'd0;
- vcount <= vcount + 1'b1;
- end else begin
- hcount <= 11'd0;
- vcount <= 10'd0;
- end
- end
- end
- // Display condition
- assign display = (335 <= hcount && hcount <= 1614) && (27 <= vcount && vcount <= 826);
- // Logic to simulate the movement of the ball
- always @(posedge clk) begin
- if (display) begin
- if (curr_x < 1279)
- curr_x <= curr_x + 1'b1;
- else begin
- if (curr_y < 799) begin
- curr_y <= curr_y + 1'b1;
- curr_x <= 11'd0;
- end else begin
- curr_x <= 11'd0;
- curr_y <= 10'd0;
- end
- end
- end
- end
- // Initial values
- initial begin
- clk = 1'b0;
- rst = 1'b1;
- curr_x = 640; // Initial x-coordinate for ball
- curr_y = 400; // Initial y-coordinate for ball
- x_paddle1 = x_initial1; // Initial x-coordinate for paddle 1
- x_paddle2 = x_initial2; // Initial x-coordinate for paddle 2
- y_paddle1 = y_initial; // Initial y-coordinate for paddle 1
- y_paddle2 = y_initial; // Initial y-coordinate for paddle 2
- #10 rst = 1'b0;
- $finish;
- end
- // Clock generation
- always #5 clk = ~clk;
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement