Advertisement
Guest User

Untitled

a guest
Apr 9th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer:
  5. //
  6. // Create Date: 25.03.2018 17:39:53
  7. // Design Name:
  8. // Module Name: draw_rect_ctl
  9. // Project Name:
  10. // Target Devices:
  11. // Tool Versions:
  12. // Description:
  13. //
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21.  
  22.  
  23. module draw_rect_ctl(
  24.         input wire frameClk,
  25.         input wire left,
  26.         input wire[11:0] xpos,
  27.         input wire[11:0] ypos,
  28.         output reg[11:0] rectx,
  29.         output wire[11:0] recty
  30.     );
  31.     localparam RECT_HEIGHT = 64;
  32.     localparam SPEED_INC = 24'b0_000000000001;
  33.     localparam BOUNCE_FACTOR = 24'b0_110011010000;//0.8
  34.     localparam BOTTOM = {600-RECT_HEIGHT,12'h000};//600.0 - RECT_HEIGHT
  35.    
  36.     reg[11:0] rectx_nxt;
  37.     reg signed[23:0] rectyf,velocity;
  38.     reg signed[23:0] rectyf_nxt,velocity_nxt;
  39.    
  40.    
  41.     always @* begin
  42.         if(~left) begin
  43.             velocity_nxt = 0;
  44.             rectx_nxt = xpos;
  45.             rectyf_nxt = {ypos,12'b0};
  46.         end else begin
  47.             velocity_nxt = velocity + SPEED_INC; //przyspieszenie grawitacyjne
  48.             rectx_nxt = rectx;
  49.             rectyf_nxt = rectyf + velocity_nxt;
  50.             if(rectyf_nxt > BOTTOM) begin //odbicie
  51.                 rectyf_nxt = BOTTOM - (rectyf_nxt-BOTTOM);
  52.                 //pomnoz przez wspolczynnik odbicia
  53.                 velocity_nxt = ({24'b0,velocity_nxt}*BOUNCE_FACTOR)>>12;
  54.                 velocity_nxt = -velocity_nxt;//odwroc wektor predkosci
  55.             end
  56.         end
  57.     end
  58.    
  59.     always @(posedge frameClk) begin
  60.         rectx <= rectx_nxt;
  61.         rectyf <= rectyf_nxt;
  62.         velocity <= velocity_nxt;
  63.     end
  64.     assign recty = rectyf[23:12];//czesc calkowita ulamka
  65. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement