
The x64 version received significant visual and UX improvements, leveraging modern Windows 11 APIs while maintaining the lightweight assembly approach:
| Feature | Description |
|---|---|
| Mica Backdrop Effect | Dark mode title bar with Windows 11 Mica material (DWMWA_USE_IMMERSIVE_DARK_MODE + DWMWA_SYSTEMBACKDROP_TYPE) for a sleek, modern appearance |
| Segoe UI Typography | All UI elements now use the Segoe UI font family with proper weight variations for improved readability |
| Green Player Field | Player name input field changes to light green (#E0FFE0) when text is entered, providing visual feedback that the name is set |
| Gold Line Clear Animation | Clearing lines triggers a smooth 300ms fade-out animation from gold (RGB 255,215,0) to black, replacing instant row removal |
| Modern Button Styling | Buttons use smaller, cleaner font styling consistent with Windows 11 design language |
| Resource Files | Added tetris.rc (resource script) and tetris.manifest (application manifest for DPI awareness and visual styles) |
Binary size impact: x64 binary increased from ~15 KB to ~18 KB (+20%) due to DWM API integration and animation code.
Note: These enhancements are exclusive to the x64 version. The x86 version remains unchanged at ~13 KB with classic Windows styling. The x64 implementation demonstrates more advanced Win32/DWM techniques due to the additional complexity already inherent in 64-bit assembly programming.
A high-performance, lightweight Tetris implementation written in pure Assembly (MASM) utilizing the Windows API. The project focuses on minimal binary footprint, efficient memory management, and direct OS integration without C Runtime (CRT) dependency.
Available in two architectures:
Subsystem: Windows (GUI)
| Metric | x86 (32-bit) | x64 (64-bit) | Notes |
|---|---|---|---|
| Final Binary Size | ~13 KB | ~18 KB | +38% size increase due to 64-bit pointers, alignment, and DWM/Mica integration |
| Source Code Lines | ~2,400 LOC | ~2,600 LOC | +8% lines for manual calling convention management |
| Calling Convention | stdcall |
Microsoft x64 (fastcall) |
Fundamental architectural difference |
The x86 version benefits from the comfortable stdcall convention with MASM's invoke macro, which abstracts argument passing:
; x86: Simple and readable
invoke MessageBox, hWnd, addr szMessage, addr szTitle, MB_OK
The x64 version requires manual implementation of Microsoft's x64 calling convention (fastcall variant):
; x64: Manual register loading and stack management
mov rcx, hWnd ; 1st argument in RCX
lea rdx, szMessage ; 2nd argument in RDX
lea r8, szTitle ; 3rd argument in R8
mov r9d, MB_OK ; 4th argument in R9
sub rsp, 32 ; Shadow space (mandatory 32 bytes)
call MessageBox
add rsp, 32 ; Clean up shadow space
x64 mandates 32 bytes (4ร8-byte slots) of "shadow space" on the stack for every function call, even if the function takes fewer than 4 parameters. This is a strict ABI requirement for Windows x64 and must be maintained even when not passing arguments via stack.
x64 requires 16-byte stack alignment (RSP & 0xF == 0) before call instructions. Misalignment causes crashes in many API functions (particularly graphics-related). This requires explicit alignment:
and rsp, -16 ; Align to 16-byte boundary
EAXRCX, RDX, R8, R9; additional arguments on stack; return value in RAXAll pointers and handles are 64-bit (8 bytes) in x64, affecting:
The transition from x86 to x64 was a significant undertaking, primarily due to:
Loss of High-Level Abstractions: The comfortable invoke macro in x86 (which auto-generates push sequences) is unavailable in x64. Every API call requires 5-7 lines of manual register/stack management.
Shadow Space Management: Unlike x86's simple stack cleanup (add esp, N), x64's shadow space requirement adds cognitive overhead to every function call. Forgetting to allocate or deallocate shadow space leads to stack corruption.
Stack Alignment Debugging: Crashes due to misaligned stacks are notoriously difficult to debug. A single misalignment early in the call chain can cause failures deep in GDI/Win32 APIs, far from the actual error.
Increased Code Verbosity: Simple operations in x86 (1 line with invoke) expand to 6+ lines in x64, reducing code readability and increasing maintenance burden.
No invoke Safety Net: The x86 invoke macro performs type checking and automatic stack cleanup. x64 requires manual verification of argument types, counts, and calling conventions for every API.
Despite these challenges, the x64 version maintains identical functionality and visual behavior, demonstrating that low-level assembly can achieve platform parity with careful attention to ABI details.
user32, gdi32, kernel32, advapi32, shell32).GAME_STATE structure.CreateCompatibleDC and CreateCompatibleBitmap to eliminate flickering during high-frequency screen invalidation.CreateHatchBrush with HS_DIAGCROSS pattern.SHAPE_TEMPLATES, allowing for efficient rotation and collision calculations via iterative offset addition.Unlike traditional implementations using .ini or .cfg files, this project utilizes the Windows Registry for state persistence:
HKEY_CURRENT_USER\Software\TetrisPlayerName (REG_SZ / Unicode): Last active player identity.HighScore (REG_DWORD): Maximum score achieved.HighScoreName (REG_SZ / Unicode): Name of the record holder.RegQueryValueExW and RegSetValueExW.shell32.dll via ExtractIcon API (configurable index).EN_CHANGE notification.The repository contains separate implementations for both architectures in dedicated directories:
Tetris_asm/
โโโ x86/ # 32-bit implementation
โ โโโ main.asm # Entry point, WndProc, message loop
โ โโโ game.asm # Core game logic
โ โโโ render.asm # GDI rendering engine
โ โโโ registry.asm # Registry persistence layer
โ โโโ data.inc # Structures and constants
โ โโโ proto.inc # Procedure prototypes
โโโ x64/ # 64-bit implementation
โ โโโ main.asm # Entry point (manual x64 calling convention)
โ โโโ game.asm # Core logic (64-bit registers)
โ โโโ render.asm # GDI rendering (shadow space management)
โ โโโ registry.asm # Registry operations (64-bit pointers)
โ โโโ data.inc # Structures (8-byte alignment)
โ โโโ proto.inc # Procedure prototypes (fastcall)
โ โโโ tetris.rc # Resource script (icon, manifest)
โ โโโ tetris.manifest # Application manifest (DPI, visual styles)
โโโ bin/ # Output directory (created by build script)
โ โโโ tetris.exe # x86 binary (~13 KB)
โ โโโ tetris64.exe # x64 binary (~18 KB)
โโโ build.ps1 # Unified PowerShell build script for both versions
| File | Description |
|---|---|
main.asm |
Entry point, Window Procedure (WndProc), Message Loop, UI Control handling, and keyboard accelerators. |
game.asm |
Core logic: Tetromino movement, rotation with wall kicks, 7-bag generation using LCG RNG, collision detection, and line clearing. |
render.asm |
GDI rendering engine: Backbuffer management, block drawing, ghost piece rendering, pulsing text animation, and info panel output. |
registry.asm |
Low-level wrapper for advapi32 functions to handle persistent data storage (High Score, Player Name). |
data.inc |
Structure definitions (GAME_STATE, PIECE, RENDERER_STATE) and constant declarations. |
proto.inc |
Procedure prototypes for inter-modular communication. |
tetris.rc |
(x64 only) Resource script linking icon and application manifest. |
tetris.manifest |
(x64 only) Application manifest enabling DPI awareness, visual styles, and Windows 11 features. |
build.ps1 |
PowerShell script that builds both x86 and x64 versions using Visual Studio 2026 toolchain. |
ml.exe for x86, ml64.exe for x64)Note for older Visual Studio versions (2022 and below): If you're using VS 2022 or earlier, you'll need to adjust the build.ps1 PowerShell script to point to the correct Visual Studio installation path and toolchain version (lines 7-14).
A single PowerShell script builds both x86 and x64 versions simultaneously:
.\build.ps1
The script will:
x86/ directory โ bin/tetris.exe (~13 KB)x64/ directory โ bin/tetris64.exe (~18 KB)Output:
bin/
โโโ tetris.exe (x86, ~13 KB)
โโโ tetris64.exe (x64, ~18 KB)
Open "x86 Native Tools Command Prompt for VS 2026", navigate to the x86/ directory, and run:
cd x86
:: Assemble all modules
ml /c /Cp /Cx /Zd /Zf /Zi main.asm
ml /c /Cp /Cx /Zd /Zf /Zi game.asm
ml /c /Cp /Cx /Zd /Zf /Zi render.asm
ml /c /Cp /Cx /Zd /Zf /Zi registry.asm
:: Link objects into a standalone GUI executable
link main.obj game.obj render.obj registry.obj /subsystem:windows /entry:start /out:tetris.exe
Output: tetris.exe (~13 KB)
Open "x64 Native Tools Command Prompt for VS 2026", navigate to the x64/ directory, and run:
cd x64
:: Assemble all modules (64-bit)
ml64 /c /Cp /Cx /Zd /Zf /Zi main.asm
ml64 /c /Cp /Cx /Zd /Zf /Zi game.asm
ml64 /c /Cp /Cx /Zd /Zf /Zi render.asm
ml64 /c /Cp /Cx /Zd /Zf /Zi registry.asm
:: Link objects into a standalone 64-bit GUI executable
link main.obj game.obj render.obj registry.obj /subsystem:windows /entry:start /out:tetris64.exe
Output: tetris64.exe (~18 KB)
Technical Note: The x64 version requires significantly more manual code for API calls due to the lack of invoke macro support and mandatory shadow space allocation (32 bytes per call).
| Key | Action |
|---|---|
| Left / Right | Move Tetromino horizontally |
| Up | Rotate clockwise (with wall kicks) |
| Down | Soft Drop (faster fall) |
| Space | Hard Drop (instant placement) |
| P | Pause / Resume / Restart (on Game Over) |
| F2 | Start New Game |
| ESC | Exit Application |
| Alt+P | Pause Game |
| Alt+R | Resume Game |
| Alt+C | Clear High Score Record |
For x86 version - Edit main.asm around line 83-84:
invoke ExtractIcon, g_hInstance, offset szShell32, 19 ; Change icon index here
For x64 version - Edit main64.asm (manual calling convention):
mov rcx, g_hInstance
lea rdx, szShell32
mov r8d, 19 ; Change icon index here
sub rsp, 32
call ExtractIcon
add rsp, 32
Recommended DLL files for icons (Windows 11):
shell32.dll - Classic system iconsimageres.dll - Modern icon collection (300+ icons)ddores.dll - Hardware/device iconsUse Resource Hacker to browse available icons and their indices in these files.
seed = seed ร 1103515245 + 12345yFloat)base_speed(300) + level ร 50Both versions provide the same core gameplay experience. The x64 version offers enhanced visuals on Windows 11.
Author: Marek Wesoลowski
Email: marek@wesolowski.eu.org
Website: https://kvc.pl
License: MIT