SHARE
TWEET

Untitled

a guest Aug 11th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module controller_fsm(clock, player_x, player_y, player_color, player_writeEn, player_finished,
  2.     player_laser_x, player_laser_y, player_laser_color, player_laser_writeEn, player_laser_finished,
  3.                     x, y, color, writeEn, player_enable, laser_enable, reset_n);
  4.  
  5.     input clock;
  6.     input reset_n;
  7.     input wire [7:0] player_x;
  8.     input wire [6:0] player_y;
  9.     input wire [2:0] player_color;
  10.     input wire player_writeEn;
  11.     input wire player_finished;
  12.  
  13.     input wire [7:0] player_laser_x;
  14.     input wire [6:0] player_laser_y;
  15.     input wire [2:0] player_laser_color;
  16.     input wire player_laser_writeEn;
  17.     input wire player_laser_finished;
  18.  
  19.     output reg [7:0] x;
  20.     output reg [6:0] y;
  21.     output reg [2:0] color;
  22.     output reg writeEn;
  23.  
  24.     output reg player_enable;
  25.     output reg laser_enable;
  26.  
  27.     localparam S_PLAYER = 0, S_LASER = 1;
  28.     reg [1:0] state_next, state_reg;
  29.     reg players_turn, lasers_turn;
  30.  
  31.     always @(posedge clock) begin
  32.         if (reset_n)begin
  33.             state_reg <= S_PLAYER;
  34.         end
  35.         else begin
  36.         state_reg <= state_next;
  37.         end
  38.     end
  39.  
  40.     always @(posedge clock) begin
  41.        
  42.         if (reset_n) begin
  43.         players_turn <= 1'b1;
  44.         lasers_turn <= 1'b0;
  45.         end
  46.        
  47.        
  48.         case (state_reg)
  49.             S_PLAYER: begin
  50.                 if (player_finished == 1 && players_turn == 1) begin
  51.                     state_next <= S_LASER;
  52.                     player_enable <= 0;
  53.                     //player_laser_finished <= 0;
  54.                     players_turn <= 0;
  55.                     lasers_turn <= 1;
  56.  
  57.                 end
  58.                 else if (player_finished == 0 && players_turn == 1) begin
  59.                     x <= player_x;
  60.                     y <= player_y;
  61.                     color <= player_color;
  62.                     writeEn <= player_writeEn;
  63.                     player_enable <= 1;
  64.  
  65.  
  66.                 end
  67.             end
  68.  
  69.             S_LASER: begin
  70.                 if (player_laser_finished == 1 && lasers_turn == 1) begin
  71.                     state_next <= S_PLAYER;
  72.                     laser_enable <= 0;
  73.                     players_turn <= 1;
  74.                     lasers_turn <= 0;
  75.                 end
  76.                 else if (player_laser_finished == 0 && lasers_turn == 1) begin
  77.                     x <= player_laser_x;
  78.                     y <= player_laser_y;
  79.                     color <= player_laser_color;
  80.                     writeEn <= player_laser_writeEn;
  81.                     laser_enable <= 1;
  82.  
  83.                 end
  84.             end
  85.         endcase
  86.  
  87.  
  88.     end
  89.  
  90. endmodule
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top