
Tetris on a 640x480 VGA screen, in a 1x2 tile.
The 10x20 board is drawn at (220,40) in 20x20-pixel cells, with a grey frame and black grid lines. Every new piece gets a random colour (red, orange, yellow, green, cyan, blue or magenta, never the same as the piece before), independent of its shape, and keeps it after it locks, until game over. Above the board, S### is the score and H### is the best score since reset (both up to 999). Points come from cleared lines: clearing 1, 2, 3 or 4 lines (a TETRIS) at once scores 1, 3, 5 or 8 points, multiplied by the level + 1. A title screen shows "PRESS ANY BUTTON TO START". When a new piece cannot be placed, the board turns grey and "GAME OVER" blinks.
Pieces are picked at random from the 7 tetrominoes. Rotation is clockwise. If a rotation is blocked, it tries one column to the left, then one to the right. Each input acts once per event and never repeats while held: left, right and rotate move or turn the piece once, and down moves it one row. With ui[4] = 0 an event is every flip of the input (DIP switches, VGA Playground keys 0-3); with ui[4] = 1 it is only a press (push buttons). The piece falls one row every 10 frames at the start, and one frame faster for every 10 cleared lines, down to every 2 frames.
How it fits in one tile:
vga_cells.v), so finding the board cell of a pixel needs no division. The sync timing is the same as the standard 640x480 shell.Connect a TinyVGA PMOD and a VGA monitor, and run the clock at 25.175 MHz (25 MHz also works). Connect the inputs (active high) to ui[0] left, ui[1] right, ui[2] rotate and ui[3] down. Set ui[4] to 0 for switches or 1 for push buttons. Flip or press any input to start a game. In the VGA Playground, keys 0-3 control the game.
TinyVGA PMOD, a VGA monitor, and four switches or push buttons.
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | Left button | R1 | |
| 1 | Right button | G1 | |
| 2 | Rotate button | B1 | |
| 3 | Down (one row) | VGA vsync | |
| 4 | Input mode: 0 = act on every flip, 1 = act on press | R0 | |
| 5 | G0 | ||
| 6 | B0 | ||
| 7 | VGA hsync |