The project is a Connect Four game and utilizes hardware to determine the game state, update it and output it via VGA. The memory of the game state is stored in Flip Flops.
Short description of the modules involved:
tt_um_RoyTr16.v
The top module of the project, connect all top components and the IOs of the board.
btn_debounce.v
Responsible for allowing the action keys to be pressed without a single press being registered as multiple rapid presses.
debug_controller.v
Responsible for allowing the running of gate level tests by giving access to internal signals and outputting them to the IOs.
connect_four_top.v
The top wrapper module for the game. Connects to the internal logic module and calculates the VGA color output of each pixel according to the game state.
vga_controller.v
Generates the VGA clock and required signals for outputting to a VGA screen.
connect_four.v
The heart of the game's logic. stores many state variables and has a state machine to determine the status of the game. Instantiates other logic modules and connects between them.
board_rw.v
Responsible for storing the game state in a 128 bit vector which represents the board. Allows reading the contents of a grid tile by specifying its row and column indices, as well as writing to a grid tile. This implementation was the most area efficient which I was able to achieve, after wiring the entire 128 bit board to every component which needed it used a lot of area.
game_sounds.v
Responsible for generating game sounds via an external buzzer. Receives a trigger to play a sound as well as its type as inputs. Has four types of sound effects: "Start", "Drop", "Error" and "Victory".
buzzer.v
Responsible for generating the square wave for the buzzer, and is controller by game_sounds
.
victory_checker.v
Responsible for checking whether the game has ended due to one of the players having a winning combination of pieces. This process happened by sequentially going over all relevant direction (determined by check_directions
) and checking whether they conatain a winning combination. If any of them do, the game ends. If not, we move to the next turn.
check_directions.v
Responsible for checking which directions need to be examined to see whether they contain a winning combination. This module is required because for example say we want to check for a winning combination that is to the left of the tile which a piece was just added to, if we are at the left edge of the board, we would wrap around to the other side of the board and read incorrect data, causing false positives. This components ensures only directions which have the ability to cause a victory are examined.
direction_checker.v
Responsible for checking whether a specific direction has a winning combination. Receives as an input a tile index and a direction, as well as start signal. After the start signal, the module outputs sequentially the indices of the tiles in the relevant direction, reads them from board_rw
, and stores them. Then, it checks whether the contents of the tiles are identical and not empty. If they are, the player whose pieces are in the winning combination is set to be the winner of the game.
pwrup_synchronizer.v
This module implements a power-up synchronizer circuit that provides synchronized reset release functionality. This module generates a clean, synchronized reset signal that is released after the clock becomes stable during power-up sequences.
<div style="display: flex; align-items: flex-start;"> <div style="flex: 1; margin-right: 20px;">
Connect the external hardware according to the specified pinout, and play the connect four game. The floating piece cursor above the board represents the column which the piece will be dropped to. There is one key for moving the cursor left, one for moving it right, and one for dropping the piece. The game ends when one player has 4 consecutive pieces vertically, horizontally, or diagonally.
</div> <div style="flex-shrink: 0;"> <img src="connect-four.jpg" width=120> </div> </div>
3 Keys (buttons) are needed for:
Additionally a VGA module is required to connect the board to an external display.
Optionally, a passive buzzer may be connected to play sound effects (NOTE: the buzzer does not work in debug mode, which is active when ui[7]
is high (VCC), and inactive when it is low (Ground)).
ui
input on the PCB:
ui[0]
ui[1]
ui[2]
uio[0]
ui[7]
is connected to Ground - the buzzer will not function in debug mode when ui[7]
is highConnect a standard VGA module to the designated VGA output pins for display functionality.
<img src="keys.jpg">
# | Input | Output | Bidirectional |
---|---|---|---|
0 | Key Drop Piece | VGA red [1] | Debug pin / Buzzer |
1 | Key Move Right | VGA green [1] | Debug pin |
2 | Key Move Left | VGA blue [1] | Debug pin |
3 | VGA vsync | Debug pin | |
4 | VGA red [0] | Debug pin | |
5 | VGA green [0] | Debug pin | |
6 | VGA blue [0] | Debug pin | |
7 | Debug Mode | VGA hsync | Debug pin |