Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. module lab3_top(
  2. input [3:0] KEY,
  3. input [9:0] SW,
  4. output [9:0] LEDR,
  5. input CLOCK_50,
  6. output VGA_CLK,
  7. output VGA_HS,
  8. output VGA_VS,
  9. output VGA_BLANK_N,
  10. output VGA_SYNC_N,
  11. output [7:0] VGA_R,
  12. output [7:0] VGA_G,
  13. output [7:0] VGA_B
  14. );
  15.  
  16. wire [8:0] x, o; // current board positions
  17. wire [8:0] next_o; // next position that O wants to play
  18. wire [7:0] win_line; // has someone won and if so along which line?
  19.  
  20. // The following module instance determines the next move played by O. The
  21. // logic is is described in the Lab 3 handout and in Section 9.4 of Dally.
  22. // The TicTacToe module is purely combinational logic. We connect "o" to
  23. // "xin" instead of "oin" because we want GameLogic to play for O instead
  24. // of X.
  25. TicTacToe GameLogic( .xin(o), .oin(x), .xout(next_o) );
  26.  
  27. // The following module records past moves played by you and the module above.
  28. // It uses something called "sequential logic" we will learn about later.
  29. // The implementation can be found in game_state.v, but for this lab all you
  30. // need to know is that the "x" and "o" wires are driven by this block.
  31. GameState State( // inputs
  32. .o_move(next_o),
  33. .x_move(SW[8:0]),
  34. .reset(~KEY[0]),
  35. .clk(CLOCK_50),
  36. .winner(|win_line),
  37. // outputs
  38. .o(o),
  39. .x(x) );
  40.  
  41. // The following module will be implemented by you! It detects when someone
  42. // wins and along which line
  43. DetectWinner Wins( // inputs-(9-bit) current positions of type a and b
  44. .ain(x), .bin(o),
  45. // outputs-(8-bit) if A/B wins, one hot indicates along which row, col or diag
  46. .win_line(win_line) );
  47. //always block stating winning combinations
  48. always @ ( .ain or .bin or .win_line(win_line)) begin
  49. if( .ain==000000111 or .bin == 000000111)
  50. win_line(2);
  51.  
  52. // only set LEDs for positions that X can still play (combinational logic)
  53. assign LEDR = {1'b0, ~(x|o)};
  54.  
  55. // The following module interfaces with the VGA monitor. The implementation
  56. // is in tictactoe_to_vga.v and vga.v. You do not need to understand that
  57. // code to complete this lab although you are welcome to look at it.
  58. TicTacToe_to_VGA GFX(
  59. // inputs
  60. .x_positions( {x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8]} ),
  61. .o_positions( {o[0],o[1],o[2],o[3],o[4],o[5],o[6],o[7],o[8]} ),
  62. .next_position( 9'b0 ),
  63. .win_line( win_line ),
  64. .reset(~KEY[0]),
  65. .CLOCK_50(CLOCK_50),
  66.  
  67. // outputs
  68. .VGA_CLK(VGA_CLK),
  69. .VGA_HS(VGA_HS),
  70. .VGA_VS(VGA_VS),
  71. .VGA_BLANK(VGA_BLANK_N),
  72. .VGA_SYNC(VGA_SYNC_N),
  73. .VGA_R(VGA_R),
  74. .VGA_G(VGA_G),
  75. .VGA_B(VGA_B)
  76. );
  77. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement