FPGA Tetris
FPGA Tetris
1 Introduction
Our project in Embedded Systems Design aims to recreate the iconic Tetris game by developing both
the hardware and software components necessary to run it on the DE1-SoC FPGA platform. Tetris,
a game with origins in the Soviet Union, features seven distinct shapes known as Tetrominoes, each
made up of four blocks. These Tetrominoes drop into a play area, and players have the ability to
change their orientation through some form of user interaction. Completing a full horizontal line of
Tetromino blocks removes that line, causes the blocks above to drop down, and awards points to the
player. As players successfully clear more lines, they advance to higher levels, which increases the
speed of the falling Tetrominoes. The game concludes when there’s no longer any room for a new
Tetromino to enter and descend.
To bring this classic game to life, our project will incorporate the use of a DE1-SoC FPGA board,
along with a joystick for control, a buzzer for audio feedback, and a VGA monitor for visual output.
1
3 Algorithms
3.1 Finite State Machine Control Module
The control module operates using a finite state machine, and the State Transition Diagram is displayed
in Figure 2.
2
3.2 Actions of Blocks
Blocks are categorized into inactive and active blocks. Inactive blocks are: (1) blocks that have
previously fallen; (2) the result after a block has fallen and been cleared. These are represented by the
background matrix. Active blocks are the blocks currently falling, represented by the coordinates and
type of the active block.
3
whether there are any background matrix blocks existing in the new position that the transformed
block may occupy. If both steps of judgment pass, a success signal is returned; otherwise, it fails.
The transformation process involves moving or reshaping the block. According to the KEYBOARD,
when moving, the block coordinates are changed; when reshaping, the block transforms according to
its category.
3.3 Graphics
3.3.1 Background Matrix
The background matrix, named ”Background,” is a 20-row by 10-column array of type reg, responsible
for storing the coordinates of inactive blocks, creating a 20*10 background matrix. When a position
in the background matrix is 1, the screen display is white; otherwise, it is black.
Here, we first divide the system’s inherent 100MHz clock, since the display parameters are 640*480
at 60Hz, so we approximate it to 25MHz. To ensure that each point of the image on the transmitter
side corresponds correctly to each point on the receiver side, the scanning of both the transmitter and
receiver must be synchronized. Sync pulses are stable in period with steep edges. According to the
Chinese television standard, the frequency of the horizontal sync pulse equals the line frequency of
15.625KHz, with a line period of 64us. In television technology, 64us is often used as a time unit,
represented by H, that is, 1H = 64us. The field sync pulse frequency equals the field frequency of
50Hz, with a field period of 20ms, or 312.5H. The width of the horizontal sync pulse is about 4.7us,
and the width of the field sync pulse is between 2.5 to 3Hz.
3.4 Audio
Music consists of pitches and durations. By precisely controlling the pitch and duration and accurately
driving a buzzer, melodious music can be played. This module generates different music through the
4
buzzer, controlling the buzzer’s frequency according to the pitch of the musical notes in the sheet
music.
In digital circuits, the frequency of the overflow signal of a modulo-N counter is 1/N of the count pulse
signal frequency. Therefore, a modulo-controllable counter can be designed to achieve different division
ratios, allowing the overflow signal frequency to meet different pitch requirements. The division ratios
corresponding to the pitches are shown in Table. Since the signal frequencies of the same note name
in three octaves differ by a factor of two, the pitch can be raised (or lowered) by an octave without
changing the division coefficient, by doubling (or halving) the count pulse frequency, which in turn
doubles (or halves) the frequency of the divider’s overflow signal.
The duration of a note is determined by how long the signal of that pitch frequency lasts. A counter
can be used for timing the duration, where the count pulse period is the rhythm value from the sheet
music, determining the duration of that note unit. Thus, timing for the duration can be implemented
with a counter, where the count pulse period is the value of the shortest note in the selected sheet
music. The timing for other notes’ durations can continue for different count pulse periods based on
the multiple relationships between their values and the shortest note duration (unit of measure). For
example, if the shortest note in the sheet music has an eighth-note duration, then a quarter note lasts
for two clock periods, while a whole note lasts for eight clock periods.
4 Resource Budget
The on-chip memory will be utilized for storing the game state, including the representation of the
Tetris playfield, the current and next tetrominoes, scores, and game level.
1.Playfield Storage:
The playfield for a standard Tetris game is 10 columns by 20 rows. Each cell in the playfield needs
to store information about whether it is occupied and by which type of tetromino block.Assuming a
minimalistic approach where each cell is represented by a single bit (occupied/unoccupied), the entire
playfield would require 200 bits. Considering the need to identify tetromino types, utilizing 4 bits per
cell to encode up to 16 different states (including empty) would be more practical, resulting in a total
of 800 bits (100 bytes).
2.Current and Next Tetromino Storage:
Information about the current and next tetrominoes includes the type of tetromino, its orientation,
and position.Given that there are 7 types of tetrominoes and each can have up to 4 orientations, 3 bits
for type and 2 bits for orientation are sufficient. Position can be encoded in 5 bits for X (column) and
5 bits for Y (row), totaling 15 bits per tetromino. Thus, storing current and next tetrominoes requires
30 bits.
3.Score and Level Storage:
The score and the game level are integral parts of the game’s UI.Assuming a maximum score that fits
within a 16-bit register and a level that can be represented by an 8-bit register, this sums up to 24
bits.
4.Miscellaneous:
5
Additional storage might be needed for game state (e.g., game over flag, line completion flags).32 bits
to cover various flags and small state variables.
Total On-Chip Memory Budget
1. Dynamic Block Buffer: A designated memory space dynamically renders falling and stationary
tetrominoes, allowing for real-time game display updates.
2. Memory Allocation: Dual-buffered scheme with alternating rendering to minimize display flicker.
3. Address Space: Two blocks of 256 bytes each, dynamically allocated; addresses dynamically
assigned based on rendering needs.
4. Data Format: 8-bit values representing color and state (active/inactive) for each block.
6
5.4 Audio Interface
5.4.1 Pitch and Duration Control
A division ratio (Frequency Division Ratio, FDR) is applied to the system’s clock to achieve the desired
note’s frequency.
Address Allocation
1. Pitch Control Address: 39 - Modulo-N value for pitch frequency control.
2. Data Format: 16-bit int, representing the FDR values to achieve various pitches.