Introduction:
The basis of this project is to create the game fish on the Atmel board. In the game fish, the big fish eat the small fish, so your job is to eat the fish smaller than you while not getting eaten by those bigger than you. You eat a fish by moving close enough to touch the fish, and if a larger fish gets close enough to touch you, you will be eaten. Furthermore, much like your mother told you in kindergarten, if you eat, youll get bigger.

For this project I wrote the display driver and game logic in VHDL on the Altera UP1 board. I wrote the controller input decoder and the game state logic in C to be put on an Atmel board. The other components needed for this project are the display and the controller.
Display:
I have decided to attempt to generate an VGA signal to use as the display for this device. This will make it possible to play fish on any household Computer Monitor. The signal generated will have 3 bit color.
Controller:
I have decided to use a SEGA Genesis control pad due to the availability of the controller and its ergonomic design. The pinout is also readily available and simple to use.

High Level Design:
The Controller communicates to the Atmel board through a 9-pin connection shown here. I connected this to Port D of the Atmel Board. The Atmel board uses this information to modify the current state of the fish you are controlling, then randomly changes the states of the other 3 fish. The controller can also send a Reset signal which will reset the Altera board. Activated by pressing the Start button.
Program Hardware Design:
Atmel Board:
The Atmel board reads the input from the controller more specifically up, down, left, and right. And If this inputs vary from the fishes current state the fishes current state will be changed. The fishes current direction is represented with the lowest order bits of Port D, and the fish can only move on the diagonal, and the fish must always be moving. So at any one time the fish is either moving left or right (bit 1) and either moving up or down (bit 0). Timer 0s prescale is set to 64 and reloaded at 256-62 so that it overflows once per ms. Then a read controller task is performed every 250 ms. Bits 2 through 5 are random to generate the direction of the three other fish (one extra bit for expansion). These bits are randomized by reading Timer 1. Timer one is set to the same prescale as Timer 0 (64), but it is reloaded to 1, so that its value has no dependence on Timer 0 (every loop should offset the timers by 1 more than the last). The four bits are determined by bitwise anding the first four bits with the last four bits of the Timer. This value is saved as rand. The current rand is bitwise anded with the old value of rand and this new value is bitwise xored with the old values of bits 2 through 5. This causes a bit to change on average every 4 seconds. So that a fishes direction wont be too random. Port D bit 7 is the Reset signal which is only high while the Start button is pressed.
Read more: Fish: Video Controller
