Advertisement
kevinking0814

Untitled

Dec 7th, 2023
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module specialfunc(
  2.     input [3:0] p1_bounce, p2_bounce, p1_score, p2_score,  // Bounce signals and scores
  3.     input [10:0] x_paddle1, x_paddle2, x_ball,            // X-coordinates of paddles and ball
  4.     input [9:0] y_paddle1, y_paddle2,                      // Y-coordinates of paddles
  5.     input p1_touch, p2_touch, clk, specialfunc_call,       // Touch signals, clock, and special function call
  6.     output reg [1:0] paddlesize_switcher                    // Output for paddle size switcher
  7.     );
  8.  
  9.     reg p1_touch_init, p2_touch_init;                       // Initial touch signals for debounce
  10.     reg [3:0] p1_score_init, p2_score_init;                 // Initial scores for debounce
  11.     reg flag_1 = 1'd0;                                      // Flag for paddle 1
  12.     reg fl_2 = 1'd0;                                        // Flag for paddle 2
  13.    
  14.     localparam H_active = 11'd1279;                         // Horizontal active area
  15.     localparam BoundLR_offset = 10'd265;                    // Left and right bounds offset
  16.     localparam ballwidth = 11'd20;                          // Width of the ball
  17.    
  18.     always @(posedge clk) begin
  19.         // Check if player 2 bounces and the special function is called on the right side
  20.         if (p2_bounce == 4'd3 && specialfunc_call && x_paddle2 > 841) begin
  21.             p1_touch_init <= p1_touch;                      // Store initial touch signals
  22.             p2_touch_init <= p2_touch;
  23.             // Check for touch changes to avoid debounce
  24.             if (p1_touch_init != p1_touch || p2_touch_init != p2_touch)
  25.                 paddlesize_switcher[0] <= 0;                // Set switcher based on touch changes
  26.             else
  27.                 paddlesize_switcher[0] <= 1;                // Reset switcher if no touch changes    
  28.         end
  29.         // Check if player 1 bounces and the special function is called on the left side
  30.         else if (p1_bounce == 4'd3 && specialfunc_call && x_paddle1 < 438) begin
  31.             p1_touch_init <= p1_touch;                      // Store initial touch signals
  32.             p2_touch_init <= p2_touch;
  33.             // Check for touch changes to avoid debounce
  34.             if (p1_touch_init != p1_touch || p2_touch_init != p2_touch)
  35.                 paddlesize_switcher[1] <= 0;                // Set switcher based on touch changes
  36.             else
  37.                 paddlesize_switcher[1] <= 1;                // Reset switcher if no touch changes    
  38.         end
  39.         else begin
  40.             paddlesize_switcher <= 2'b00;                   // Reset switcher if no special function
  41.         end
  42.     end
  43.  
  44. endmodule
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement