Maze ASM - Pure ARM64
A maze game written entirely in ARM64 assembly for macOS. Navigate through randomly generated mazes using classic recursive backtracking.
The source code can be found on GitHub.
Demo Videos
About
This project demonstrates building a complete graphical application in pure assembly language without relying on high-level graphics libraries like SDL. Everything from window management to pixel rendering is implemented using native macOS frameworks called directly from assembly via the Objective-C runtime.
Why Assembly?
- Learn how graphics really work at the lowest level
- Understand CPU architecture and calling conventions
- Direct interaction with the operating system
- No abstraction layers hiding the details
Features
- Recursive Backtracking Maze Generation - Creates perfect mazes with exactly one path between any two points
- Software Rasterizer - Custom pixel-by-pixel drawing routines
- Bresenham's line algorithm
- Midpoint circle algorithm
- Filled and outlined rectangles/circles
- Native macOS Integration - No SDL or external graphics libraries
- Cocoa window management via
objc_msgSend - CoreGraphics for display and keyboard input
- Direct system calls for console output
- Cocoa window management via
- Smooth Controls - Movement cooldown for precise single-tile navigation
Controls
| Key | Action |
|---|---|
| ↑ / W | Move up |
| ↓ / S | Move down |
| ← / A | Move left |
| → / D | Move right |
| R | Generate new maze |
| ESC / Q | Quit |
Project Structure
maze_asm/
├── include/
│ └── constants.inc # Shared constants and key mappings
├── src/
│ ├── maze.s # Main game loop and rendering
│ ├── shared/
│ │ ├── maze_gen.s # Maze generation (recursive backtracking)
│ │ └── raster.s # Software rasterizer (platform-independent)
│ └── platform/
│ └── macos/
│ ├── window.s # Cocoa window management
│ ├── keyboard.s # CoreGraphics keyboard input
│ ├── timing.s # Frame timing (usleep)
│ └── print.s # Console output (syscalls)
├── build/ # Compiled output (build/maze)
├── Makefile
└── README.md
Maze Algorithm
The maze uses iterative backtracking (stack-based to avoid deep recursion):
- Start with a grid of walls
- Pick starting cell, mark as path
- Randomly shuffle directions (N, E, S, W)
- For each direction, if cell 2 steps away is unvisited:
- Carve path to that cell
- Push current position to stack
- Move to new cell
- If no valid directions, pop from stack (backtrack)
- Repeat until stack is empty
This generates a "perfect maze" - exactly one path between any two points.
Technical Details
Native Implementation Stack
| Layer | Implementation |
|---|---|
| Window | Cocoa (NSApplication, NSWindow, NSView, CALayer) |
| Display | CoreGraphics (CGImage, CGDataProvider) |
| Input | CoreGraphics (CGEventSourceKeyState) |
| Drawing | Custom assembly (framebuffer manipulation) |
| Timing | libc usleep |
| Console | macOS syscall SYS_WRITE |
ARM64 Calling Convention
Arguments: x0-x7 (w0-w7 for 32-bit)
Return value: x0
Callee-saved: x19-x28
Frame pointer: x29
Link register: x30
Stack: 16-byte aligned
Graphics Primitives
The software rasterizer provides:
_raster_init/_raster_free- Framebuffer management_raster_set_color- Set RGBA drawing color_raster_clear- Fill framebuffer with current color_raster_plot- Draw single pixel_raster_line- Bresenham's line algorithm_raster_rect/_raster_rect_outline- Rectangles_raster_circle/_raster_circle_filled- Midpoint circle algorithm
Building
Requirements
- macOS (Apple Silicon / ARM64)
- Xcode Command Line Tools
Build & Run
make run
Why This Matters
Writing graphics applications in pure assembly provides deep insights into:
- CPU Architecture: Understanding registers, calling conventions, and memory layout
- Operating System Interfaces: Direct interaction with system calls and frameworks
- Graphics Fundamentals: Pixel manipulation, rasterization algorithms, and framebuffer management
- Performance Optimization: Every instruction matters when you're writing them by hand
This project proves that even in 2024, it's possible to create engaging graphical applications using nothing but assembly language and the raw power of the CPU.
A complete maze game implemented in pure ARM64 assembly, demonstrating low-level graphics programming, maze generation algorithms, and native macOS system integration without any high-level libraries.
Arrived
Ninja Turdle