ClusterM

Sega Mega Driver controller

Jul 23rd, 2019
289
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module SmdController
  2. (
  3.     input clk,
  4.     input smd_select,
  5.     output smd_data0, smd_data1, smd_data2, smd_data3, smd_data4, smd_data5,
  6.     input button_a, button_b, button_c, button_x, button_y, button_z, button_up, button_down, button_left, button_right, button_start, button_mode
  7. );
  8.  
  9.     reg [12:0] idle_counter;
  10.     reg [1:0] select_counter;
  11.     reg [1:0] select_counter_prev;
  12.    
  13.     wire reset = idle_counter == 0;
  14.    
  15.     assign smd_data0 = !select_counter[1] ?
  16.                 button_up :
  17.                 (!select_counter[0] ?                  
  18.                     (smd_select ? button_up : 1'b0) :
  19.                     (smd_select ? button_z : 1'b1)
  20.                 ); // Up/Z
  21.     assign smd_data1 = !select_counter[1] ?
  22.                 button_down :
  23.                 (!select_counter[0] ?                  
  24.                     (smd_select ? button_down : 1'b0) :
  25.                     (smd_select ? button_y : 1'b1)
  26.                 ); // Down/Y
  27.     assign smd_data2 = smd_select ? (select_counter[1:0] != 2'b11 ? button_left : button_x) : (select_counter[1:0] != 2'b11 ? 1'b0 : 1'b1); // Left/X
  28.     assign smd_data3 = smd_select ? (select_counter[1:0] != 2'b11 ? button_right : button_mode) : (select_counter[1:0] != 2'b11 ? 1'b0 : 1'b1); //Right/Mode
  29.     assign smd_data4 = smd_select ? button_b : button_a; // A/B
  30.     assign smd_data5 = smd_select ? button_c : button_start; // Start/C
  31.    
  32.     always @ (posedge smd_select, posedge reset)
  33.     begin
  34.       if (reset)
  35.         select_counter = 0;
  36.       else
  37.         select_counter = select_counter + 1'b1;
  38.     end
  39.    
  40.     always @ (negedge clk)
  41.     begin
  42.         if (select_counter != select_counter_prev)
  43.         begin
  44.             select_counter_prev= select_counter;
  45.             idle_counter = 1'b1;
  46.         end else begin
  47.           idle_counter = idle_counter + 1'b1;
  48.         end
  49.     end
  50.    
  51. endmodule
RAW Paste Data