Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module md_sixbutton_encoder(
  2.     input p7, // Clock from Sega Mega Drive
  3.     input up, // Up button
  4.     input dw, // Down button
  5.     input lf, // Left button
  6.     input rg, // Right button
  7.     input a,  // A button
  8.     input b,  // B button
  9.     input c,  // C button
  10.     input st, // Start button
  11.     input x,  // X button
  12.     input y,  // Y button
  13.     input z,  // Z button
  14.     input md, // Mode button
  15.     output reg p1, // DB9 Pin 1 to Sega Mega Drive
  16.     output reg p2, // DB9 Pin 2 to Sega Mega Drive
  17.     output reg p3, // DB9 Pin 3 to Sega Mega Drive
  18.     output reg p4, // DB9 Pin 4 to Sega Mega Drive
  19.     output reg p6, // DB9 Pin 6 to Sega Mega Drive
  20.     output reg p9  // DB9 Pin 9 to Sega Mega Drive
  21. );
  22.  
  23. reg [2:0] transition = 3'b000;
  24.  
  25. always @(*) begin
  26.     if (p7) begin
  27.         case (transition)
  28.             0, 1, 2, 3, 6, 7: begin
  29.                 p1 <= up;
  30.                 p2 <= dw;
  31.                 p3 <= lf;
  32.                 p4 <= rg;
  33.                 p6 <= b;
  34.                 p9 <= c;
  35.             end
  36.             4, 5: begin
  37.                 p1 <= z;
  38.                 p2 <= y;
  39.                 p3 <= x;
  40.                 p4 <= md;
  41.                 p6 <= 1;
  42.                 p9 <= 1;
  43.             end
  44.         endcase
  45.     end else begin
  46.         case (transition)
  47.             0, 1, 2, 7: begin
  48.                 p1 <= up;
  49.                 p2 <= dw;
  50.                 p3 <= 0;
  51.                 p4 <= 0;
  52.                 p6 <= a;
  53.                 p9 <= st;
  54.             end
  55.             3, 4: begin
  56.                 p1 <= 0;
  57.                 p2 <= 0;
  58.                 p3 <= 0;
  59.                 p4 <= 0;
  60.                 p6 <= a;
  61.                 p9 <= st;
  62.             end
  63.             5, 6: begin
  64.                 p1 <= 1;
  65.                 p2 <= 1;
  66.                 p3 <= 1;
  67.                 p4 <= 1;
  68.                 p6 <= a;
  69.                 p9 <= st;
  70.             end
  71.         endcase
  72.     end
  73. end
  74.  
  75. // Is it bad practice to have more than one always block inside a module?
  76. always @(p7) begin
  77.     // Does this overflow to 3'b000 after 3'b111?
  78.     transition <= transition + 1;
  79. end
  80.  
  81. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement