You are on page 1of 13

Block diagrams of the design, design explanation, design

criteria and functionality for the different design blocks.







entity SpaceInv is
Port( Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
Test : in std_logic;
Start : in std_logic;
Left : in std_logic;
Right : in std_logic;
Fire : in std_logic;
HSync : out std_logic;
VSync : out std_logic;
R,G,B : out std_logic );
end SpaceInv;



This is the top entity of our Space Invaders game. As inputs, it has the clock (Clk)
and reset for synchronous operations. It has another the five inputs (Fire, Left,
Right, Start and Test) that are linked to some buttons on the Spartan board to
control the game. The outputs of the entity (R, G, B, HSync and VSync) are those
that control the display through a VGA cable.

This entity has no logic inside it, it is only a container to link all the components
that the game has and control each one an specific aspect of the game (invaders,
screen, etc.).




entity ScreenFormat is
Port ( RGB : out STD_LOGIC_VECTOR(2 downto 0);
X : in unsigned (4 downto 0);
Y : in unsigned (4 downto 0);
subX : in unsigned (3 downto 0);
subY : in unsigned (3 downto 0);
Test : in std_logic;
iArray : in unsigned (0 to 19);
iRow : in unsigned (3 downto 0);
starshipArray : in unsigned (0 to 19);
shotX : in unsigned (4 downto 0);
shotY : in unsigned (4 downto 0);
fin : in std_logic );
end ScreenFormat;



This entity controls the RGB (red, green and blue) signal. It receives all the
information needed to deduce what color it has to output. X and Y are the current
coordinates of the screen. SubX and SubY are the subcoordinates used to print
the sprites of the invaders and the starship (extra explained later on).

ScreenFormat receives the current state of the invaders, starship and shot to know
where the have to be printed on the screen. When fin is 1, there are no invaders
left so the game is over.

If Test input in 1 the program prints out a chessboard and pauses the game.




entity VGA is
Port ( Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
RGB : in STD_LOGIC_VECTOR(2 downto 0);
HSync : out STD_LOGIC;
VSync : out STD_LOGIC;
R,G,B : out STD_LOGIC;
X : out unsigned (4 downto 0);
Y : out unsigned (4 downto 0);
subX : out unsigned (3 downto 0);
subY : out unsigned (3 downto 0) );
end VGA;



This entity is designed to count the pixels of the screen. With two counters, it
counts some specific times, (detailed in a table in the practice workbook).

CounterX counts the coordinates of the X axis, and CounterY counts only when
CounterX is full, so, when the line ends Y coordinate is increased by one.

This entity also controls HSync and VSync outputs, sent to the screen to control
the synchronization of the screen (horizontal and vertical).

X and Y are the output coordinates supposing that we divide the screen in 20
columns and 15 rows. SubX and subY are used to divide each of the squares
obtained with X and Y in 32x32 pixels.




entity Invaders is
Port( Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
Test : in std_logic;
Start : in std_logic;
shotX : in unsigned (4 downto 0);
shotY : in unsigned (4 downto 0);
iArray : out unsigned (0 to 19);
iRow : out unsigned (3 downto 0);
fin : out std_logic );
end Invaders;



This entity controls the logic of the invaders in our game. The invaders are stored
in an unsigned array of 20 elements (iArray). In this array, a 1 represent a living
invader, while a 0 represents an empty space.

Invaders entity has a timer component, so each 0.6 seconds (approximately) the
invaders move one space to the right. When the invader on the right side arrives to
the end of the screen, invaders go down one row (information stored in iRow) and
start to move on the left direction.

Inputs shotX and shotY determine where the bullet is at each moment. If the bullet
an a invader are at the same place in the screen at the same moment, that invader
is deleted from the invaders array (1 0).

When the invaders reach the last row, where the starship is, or all invaders are
eliminated, output fin is set to 1 so others component may know that the game is
over.








entity Starship is
Port( Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
Test : in std_logic;
Start : in std_logic;
Left : in std_logic;
Right : in std_logic;
starshipArray : out unsigned (0 to 19);
pos : out unsigned (4 downto 0) );
end Starship;



This entity controls the starship logic. The starship position is stored in an array
like the invaders, but there is only a one at each time in the entire array, as there
can only be one starship in the game.

The array is shifted to the right or to the left as Right or Left input buttons are
pressed. If the starship reaches one of the edges of the screen it will not move more
to that side.

Starship entity also outputs the position of the starship in the Array (number of
column) with pos, to make more easy to handle that position in Bullet entity, in
order to know in which square the bullet has to appear.

As a summary, this entity has almost the same logic that the invaders one, but the
invaders are moved in an specific time using a timer and here the starship is
moved using the input buttons on the Spartan board.








entity Shot is
Port( Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
Test : in std_logic;
Start : in std_logic;
Fire : in std_logic;
posStarhip : in unsigned (4 downto 0);
fin : in std_logic;
shotX : out unsigned (4 downto 0);
shotY : out unsigned (4 downto 0) );
end Shot;



This is the entity that deals with the bullet in our game. When the user presses Fire
button, a new bullet must appear.

This bullet appears at the position the starship is when the button is pressed. Then
it moves to the top but always in the same column. A timer controls this movement
as in the invaders entity, but of a lower size, so the bullet moves faster than the
invaders.

There can only be one bullet at the same time in the screen, and when the bullet
reaches the position of an invader, that invader and the bullet disappear from the
screen.

The input fin is received from Invaders entity and tells us that the game is over,
because there are no invaders left or they have reached the last row, where the
starship is. When fin is 1 the game is over, so no more bullets will appear on the
screen.







entity EdgeDetector is
Port ( Clk : in STD_LOGIC;
Reset : in std_logic;
E : in STD_LOGIC;
S : out STD_LOGIC );
end EdgeDetector;



On the practice workbook we were asked to implement an edge detector for some
of the input buttons as Left or Right, and it is implemented in this entity. This is a
falling edge detector, so when the player presses the button Left for example, the
starship does not move until the user releases the button, and moves only one
position. This is the schematic of an edge detector:





It works as follows: while the button is pressed E is equal to 1, so first flip-flop
output will be 1, but the second will be zero, so the output is equal to 0. When
the button is released, the first flip-flop output is equal to 0, but the second is
equal to 1, so the output will be 1 for just one clock cycle, as in the next cycle the
second Q will be zero.



entity Debouncer is
Generic( counter_size : integer );

Port( Clk : in STD_LOGIC;
button : in STD_LOGIC;
result : out STD_LOGIC );
end Debouncer;



This entity is made as an optional assignment of the project. It is used to
debounce some of the input buttons of the game.

The bouncing is an effect that the hardware buttons always have. When it is
pressed and then released, it produces a train of pulses before setting in 0. So we
had to make an entity that discards this train of pulses, as they are not real
pressings of the buttons.

This is done by a timer. When the entity receives a 1 from the button, it starts the
timer and waits until the timer is full. If in that moment the input is also 1 it is
taken as a real pressing and the output result is 1. If not, the output is 0.



















entity timer is
Generic( width : integer );

Port ( Clk : in std_logic;
Reset : in std_logic;
Enable : in std_logic;
Count : out std_logic_vector (width-1 downto 0);
Full : out std_logic );
end timer;























FSMs Diagrams.
Functionality of the testbenches performed.


Todo

Hsync


Vsync




invaders horizontal



invaders vertical


Nave



timer



edge detector

Explanation of the improvements made.
Synthesis Results (area, delay, maximum clock frequency, etc.)
with detailed explanations.
If warnings occur during synthesis, a detailed explanation of
them.
Comments related to some difficult points encountered during
the design implementation.
Other appropriate or relevant comments.

You might also like