Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. module pipe ( input Clk, // 50 MHz clock
  2. Reset, // Active-high reset signal
  3. frame_clk, // The clock indicating a new frame (~60Hz)
  4. input [9:0] DrawX, DrawY, // Current pixel coordinates
  5. input [9:0] StartX, StartY,
  6. output logic is_pipe1 // Whether current pixel belongs to ball or backgroun
  7. );
  8. logic [9:0] Pipe_X_Pos, Pipe_X_Motion, Pipe_Y_Pos, Pipe_Y_Motion;
  9. logic [9:0] Pipe_X_Pos_in, Pipe_X_Motion_in, Pipe_Y_Pos_in, Pipe_Y_Motion_in;
  10.  
  11. parameter [9:0] Pipe_X_Center = 10'd320; // Center position on the X axis
  12. parameter [9:0] Pipe_Y_Center = 10'd240; // Center position on the Y axis
  13. parameter [9:0] Pipe_X_Min = 10'd0; // Leftmost point on the X axis
  14. parameter [9:0] Pipe_X_Max = 10'd639; // Rightmost point on the X axis
  15. parameter [9:0] Pipe_Y_Min = 10'd0; // Topmost point on the Y axis
  16. parameter [9:0] Pipe_Y_Max = 10'd479; // Bottommost point on the Y axis
  17. parameter [9:0] Pipe_X_Step = (~(10'd1) + 1'b1); // Step size on the X axis
  18. parameter [9:0] Pipe_Y_Step = 10'd0;
  19. parameter [9:0] Pipe_Size = 10'd4; // Ball size
  20.  
  21. logic frame_clk_delayed, frame_clk_rising_edge;
  22. always_ff @ (posedge Clk) begin
  23. frame_clk_delayed <= frame_clk;
  24. frame_clk_rising_edge <= (frame_clk == 1'b1) && (frame_clk_delayed == 1'b0);
  25. end
  26.  
  27. always_ff @ (posedge frame_clk_rising_edge)
  28. begin
  29. if(Reset)
  30. begin
  31. // Pipe_X_Motion <= (~(10'd1) + 1'b1);
  32. Pipe_X_Motion <= Pipe_X_Step;
  33. Pipe_Y_Motion <= Pipe_Y_Step;
  34. Pipe_X_Pos <= StartX;
  35. Pipe_Y_Pos <= StartY;
  36. end
  37. else
  38. begin
  39.  
  40. // Pipe_X_Motion <= (~(10'd1) + 1'b1);
  41. Pipe_X_Motion <= Pipe_X_Motion_in;
  42. Pipe_Y_Motion <= Pipe_Y_Motion_in;
  43. Pipe_X_Pos <= Pipe_X_Pos_in;
  44. Pipe_Y_Pos <= Pipe_Y_Pos_in;
  45. end
  46.  
  47.  
  48. end
  49.  
  50. always_comb
  51. begin
  52. Pipe_X_Pos_in = Pipe_X_Pos;
  53. Pipe_Y_Pos_in = Pipe_Y_Pos;
  54. Pipe_X_Motion_in = (~(10'd1) + 1'b1);
  55. Pipe_Y_Motion_in = Pipe_Y_Motion;
  56.  
  57. if (frame_clk_rising_edge)
  58. begin
  59. Pipe_X_Pos_in = Pipe_X_Pos + Pipe_X_Motion_in;
  60. Pipe_Y_Pos_in = Pipe_Y_Pos;
  61. end
  62. else
  63. begin
  64. Pipe_X_Pos_in = Pipe_X_Pos;
  65. Pipe_Y_Pos_in = Pipe_Y_Pos;
  66. end
  67.  
  68. end
  69.  
  70. always_comb
  71. begin
  72. if (DrawX < Pipe_X_Pos + 10'd25 && DrawX > Pipe_X_Pos + (~(10'd25) + 1'b1) && DrawY < Pipe_Y_Pos + 10'd90 && DrawY > Pipe_Y_Pos + (~(10'd90) + 1'b1))
  73. is_pipe1 = 1'b1;
  74. else
  75. is_pipe1 = 1'b0;
  76. end
  77.  
  78. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement