Retro Tetris

Tetris for the terminal, hand-written in x86-64 assembly. A Windows console Tetris on a green-phosphor palette: ANSI escape codes for the screen, the Win32 console API for input, and not a line of C. Just NASM.
Status
Active
Features
| Feature | Description |
|---|
| Pure assembly | x86-64 NASM, zero C/C++/Rust |
| CRT aesthetic | Green-phosphor palette via ANSI escape codes |
| Raw input | Win32 Console API (arrow keys + numpad) |
| Classic mechanics | 7-bag randomizer, wall kicks, lock delay |
| Controls | Hard/soft drop, hold piece, next piece preview |
| High scores | Top 10 persisted to scores.txt |
| Pause/quit | P to pause, Q/Esc to quit |
Tech Stack
| Component | Tool | Purpose |
|---|
| Assembler | NASM | x86-64 assembly |
| Linker | LLVM lld-link | No MSVC link.exe required |
| System libs | Windows SDK | kernel32.lib, user32.lib |
| Build | PowerShell | build.ps1 script |
Architecture
Rendering (ANSI + Win32 Console)
- Virtual 20×10 board + side panels rendered to off-screen buffer
- ANSI escape sequences: cursor positioning, color (green phosphor palette), clear
WriteConsoleOutput blits full frame each tick - no flicker, no partial redraws
Input (Win32 Console API)
ReadConsoleInput reads KEY_EVENT records
- Maps arrow keys, numpad, space,
P, Q, Esc to game actions
- No buffering - immediate response, supports key repeat via OS
Game Loop
- Fixed timestep (~60 FPS via
Sleep)
- Input poll → piece update → collision check → line clear → score update → render
- 7-bag randomizer ensures fair piece distribution
- Wall kicks (SRS-lite) for rotation near walls/floor
Install
| Platform | Command |
|---|
| Windows (Winget) | winget install rugbedbugg.RetroTetris |
| Windows (Chocolatey) | choco install retro-tetris |
Controls
| Key | Action |
|---|
← → / 7 9 | Move left / right |
↑ / 8 | Rotate clockwise |
↓ / 4 | Soft drop |
Space | Hard drop |
P | Pause / resume |
Q / Esc | Quit |
Build & Run
Prerequisites
| Requirement | Details |
|---|
| NASM | nasm on PATH |
| LLVM lld-link | lld-link.exe on PATH |
| Windows SDK | For kernel32.lib, user32.lib, etc. |
Build
.\build.ps1 # nasm + lld-link -> tetris.exe
Run
.\tetris.exe
Scores are saved to scores.txt - the top ten sit beside the board and on the game-over screen.
Project Structure
Retro-Tetris/
├── src/
│ ├── main.asm # Entry point, game loop, Win32 console setup
│ ├── render.asm # ANSI rendering, frame buffer, color palette
│ ├── input.asm # Win32 Console input handling
│ ├── tetris.asm # Core game logic: pieces, board, collision, scoring
│ ├── random.asm # 7-bag randomizer
│ └── scores.asm # High-score load/save (scores.txt)
├── build.ps1 # NASM + lld-link build script
├── tetris.exe # Built binary (gitignored)
├── scores.txt # High scores (gitignored)
└── README.md
Testing
No automated test suite (assembly game). Manual verification:
.\build.ps1
.\tetris.exe
# Verify: renders, input responds, pieces move/rotate/drop, lines clear, scores persist
Notes
| Note | Details |
|---|
| Platform | Windows only (Win32 Console API + ANSI) |
| Terminal | Requires ANSI support (Windows Terminal, ConEmu, cmd.exe on Win10+) |
| Palette | Green phosphor hardcoded - no config yet |
| Exit | Task Manager → End Task loses score; Q/Esc saves gracefully |
License
MIT, see LICENSE.
Links