Tetris Fpga

download Tetris Fpga

of 4

Transcript of Tetris Fpga

  • 8/13/2019 Tetris Fpga

    1/4

    Tetris game design based on the FPGA

    Kai Liu, Yuliang Yang, Yanlin Zhu

    Dept. of Communication Engineering, School of Computer & Communication Engineering, USTB, Beijing, China

    AbstractTetris game is a classic game of logic control. This article

    gives a programming design of Tetris game based on the FPGA

    using VHDL. Game players can move and rotate blocks with the

    PS/2 interface keyboard, and the game video is showed in a VGA

    monitor. The game realized the function of the movement and

    rotation of blocks, randomly generating next blocks, eliminating

    rows, getting scores and speeding up. It also contained the normal

    mode corresponding to 7 types of blocks and the expert mode

    corresponding to 11 types of blocks. The successful transplant of

    Tetris game provides a template for the development of other

    visual control systems in the FPGA.

    Keywords- FPGA; VHDL; Tetris game;

    I. INTRODUCTION

    Tetris game is a popular television and handheld game.Because of its strict logic, simple operation, appropriate

    programming difficulty, strong entertainment and othercharacteristics. Tetris game has been transplanted to various

    platforms, such as personal computers, mobile phones, handheldgame consoles. It spawns a variety of different versions, and

    becomes one of the classic programming training and gamedevelopment theme.

    This programming of Tetris game on the FPGA can providetemplates for the similar development of visual control systemand game development.

    II. OVERVIEW OF THE GAME DESIGN

    The main body of the game is composed of three parts:controlling input, processing logic, and displaying output.

    Controlling input part includes PS/2 interface keyboard.Players use keyboards to select the game mode, control the game

    process, and complete the movement and rotation of the blocks.Logic processing part is using a FPGA chip to complete. The

    program is totally realized in the FPGA chip, and communicateswith the controlling input and displaying output part through thecorresponding interface.

    Display part transmits the VGA signals to outer. With anexternal monitor shows games screen, visual operation iscomplete.

    III. STRUCTURE OF THE GAME MODULESThe game is composed of 7 modules: keyboard control

    module, game control module, text display module, and graphic

    display module, storage unit, multiplexing unit and VGA

    modules. The graphic display module and text display module

    share VGA control through multiplexing units; game contro

    modules, graphic display module and text display module

    complete data exchange through the storage units. The specific

    module structure diagram is shown in Figure 1.

    Figure 1. Structure of the program moduleA. Keyboard control module

    The keyboard control module is identified by the keyboardrecognition and the filter of key value. Among them, thekeyboard recognition part completes one-way communicationfrom PS/2 keyboard to FPGA. When reading the scan code, tipsignal an turns from 0 to 1, or from 1 to 0;Componentswhich been connected with this module, can determine whetherthe scan codes has been read through the value of the signaan change.

    The key value filter can filter the scan codes of the keyboardAnd then other values are filtered out with the needed scancodes left. Keys that are used in table 1.

    Table 1. Game key function table

    Keys Function description

    F1 Stop game

    F2 Normal game mode

    F3 Expert game mode

    A Move blocks left

    D Move blocks right

    space Rotate blocks

    B. Game control module

    The game control module is the main body of the game

    Through the state machine describes the process of the gameA total of 15 States are in the game, which means 15 kinds of

    values of the corresponding state. Figure 2 shows the game statetransition diagram. Table 2 describes state machine.

    Whether in the normal or expert mode, the blocks are

    composed of four sub-blocks. All blocks operation is achieved

    by changing the coordinate values of sub-blocks.

    This work was supported by the National Natural Science Foundation ofChina (N.S.F.C) grant funded by the china government (No.61170225).

    2925

    978-1-4577-1415-3/12/$26.00 2012 IEEE

  • 8/13/2019 Tetris Fpga

    2/4

    Figure 2. Game state transition diagram

    Table 2. Game state machine description

    State No. State State description

    0000 stop Press F1 or game over

    0001 normal Press F2 to enter normal mode

    0010 master Press F3 to enter expert mode0011 wait Wait for cntClk signal; then turn to

    test_down state or read command form

    keyboard

    0101 test_down Try to make the current active blocks fall to

    the next line; if there have obstacles, turn to

    test_stop, or turn to step_down.

    0110 step_down The current active blocks drop a line.

    0111 test_right Try to make the current activation block

    move right a column; if there are barriers,

    jump to wait, or jump to step right.

    1000 step_right The current active block moves right a

    column.

    1001 test_left Try to make the current activation block

    move left a column; if there are barriers ,

    jump to wait, or jump to step_left

    1010 step_left The current active block moves left a

    column.

    1011 test_rotate Try to make the current activation block

    rotate as presets; if there are barriers , jump

    to wait, or jump to rotate

    1100 step_rotate The current active block rotates as presets.

    1101 test_stop Determine whether y-coordinate is 1, if so

    jump to stop, or jump to del_rows.

    1110 del_rows Determine the rows eliminating conditions,

    if it meets, then execute rows elimination

    processing.

    1) Method of randomly generating blocksAfter the current block dropped down, it needs to randomly

    generate a new blocks for players to operate in the course of the

    game.Each block is assigned a random value during initializationthat means the blocks newly generated gets a randomly valuewithin its range. The method to get a random value is that wemake the random value accumulate with the game clock signalsinstead of using the pseudo random sequence. Due to each

    blocks lifetime varying from the others, it causes the randomvalue staying in a random value within its scope.

    if (cntCLk(0)'event and cntCLk(0) = '1') thenif random="110" then

    random

  • 8/13/2019 Tetris Fpga

    3/4

    Figure 3. Graphic display method

    In the virtual coordinate system, each square is a 16 * 16 setof pixels. Each of the 16 * 16 pixel set is regarded as a graphicdisplay unit. In a graphic display unit, the outermost layer (whitesquare area) pixel is set to:

    pix (2 downto 0)

  • 8/13/2019 Tetris Fpga

    4/4

    [6] Fuqi Liu. FPGA embedded project development practice. Beijing: Publishing House of electronics industry, 2009.

    2928