Fish

An EE476 project by Edward Mengel
 

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, you’ll 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 it’s 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 0’s 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 it’s 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 and’ing the first four bits with the last four bits of the Timer. This value is saved as “rand.” The current rand is bitwise and’ed with the old value of rand and this new value is bitwise xor’ed 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 won’t be too random. Port D bit 7 is the Reset signal which is only high while the Start button is pressed.

Altera Board:

The Altera board uses it’s 25.175 MHz clock signal to generate H-synch and V-synch pulses for the VGA display. It also stores the coordinates and size of every fish on screen. Once every time the screen is refreshed the Altera board updates each fishes coordinates depending on the direction of each fish (the randomly controlled fish only move left or right). The coordinate of the fish are checked to see if the fish is moving off the screen, and if so it will wrap around to the other side. There is also collision detection. If your fish collides with a bigger fish, the game ends. The screen will freeze until it is Reset. If your fish collides with a fish of equal or lesser size that fish is eaten, and the fish’s position will be Reset. For every fish you eat your, score increases proportionally to the size of the fish, and your own size is dependant on your score.

Performance:

The speed and timing of the game same to operate at a level comparable to that of human reaction. The controller input can seem a bit sluggish at times. All of the fish move at the same speed (If you discard the fact that the users fish moves diagonally) which adds a reasonable amount of challenge to the game.

Possible Updates or Modifications:

The limits of the UP1 board were clearly close to being reached as was shown by the “less than 20% of logic circuits remaining” warning message, so any future upgrades could possibly require a larger gate array. The limits of the timing of the UP1 board were also being reached as shown by the “waves” made when drawing the fish. The largest obstacle was the connections to the FLEX chip on a UP1 board. These connections were meant to be soldered and nothing else. Any other type of connection will not be reliable.

Appendices:

Code and Schematics:

1.Atmel 8515 c code

2.Altera FLEX VHDL code

3.SEGA Genesis controller information

4.Top level schematic: