Repository navigation
Releases
v0.0.1: Create a Berzerk clone for Sega Master System using Arena
Full Changelog: https://github.com/haroldo-ok/berzerk-sms/commits/v0.0.1
This is a clean-room Sega Master System port of Stern Electronics' Berzerk!
Achieving clear 1980s-style vocoded digitized speech playback on the SMS's TI SN76489 sound chip without dedicated PCM hardware is an outstanding retro-engineering feat.
System Architecture & Speech Pipeline
Sega Master System (Z80 @ 3.58 MHz)
│
┌───────────────────────────────────┼───────────────────────────────────┐
▼ ▼ ▼
Line-IRQ Speech Engine Maze Generation & AI SN76489 PSG Audio Output
- 7,866 Hz PCM streaming interrupt - Spanning-tree + flood-fill check - 3-channel volume attenuation (4+4+4)
- Banks 2--18 (240 KB for 22 clips) - 4 difficulty tiers & Evil Otto - Dynamic channel sharing with SFX/Music
- Verb + Object dynamic chatter - Electrified wall collision - Duck-stepping victory march
Technical & Engineering Highlights
-
Line-IRQ Driven PSG PCM Speech: Uses a high-frequency line interrupt running at ~7,866 Hz to write raw 4-bit volume attenuations across all three PSG square channels simultaneously, reproducing all 18 arcade callouts, random verb+object chatter combinations, and the victory fanfare without slowing down the 60 Hz game loop.
-
Procedural Maze Generation with Hardware Flood-Fill: Automatically constructs non-trivial robot mazes via spanning-tree generation and verifies full connectivity before player spawn using a RAM-side flood-fill routine.
-
Single Source of Truth (
data.def): Utilizes twin-pass X-Macros insrc/data.defto unify game constants, palettes, and data declarations, whiletools/gen_gfx.pyprogrammatically renders sprite silhouettes and pixel math directly into C source code. -
Comprehensive Automated Test Matrix: Verified with a 160-assertion headless Z80 test suite (
tests/playtest.txt) that validates game states, maze reachability, Evil Otto spawn timers, score thresholds, and PSG speech registers viatools/audit_matrix.py.
Difficulty Tiers & Threat Scaling
| Difficulty Tier | Score Threshold | Robot Color | Behaviors & Threats |
|---|---|---|---|
| Tier 0 | 0 -- 1,490 | Yellow | Unarmed/slow; 5s fire delay; 1-in-4 shot chance; slow Otto clock (~15s) |
| Tier 1 | 1,500 -- 3,990 | Purple | Armed; moderate movement; faster volleys |
| Tier 2 | 4,000 -- 8,990 | Cyan | Faster movement; shorter Otto spawn delay (~10s); aggressive strafing |
| Tier 3 | 9,000+ | Red | Fierce smart AI; high fire rate; announces "Destroy the humanoid!" |
Build & Playtest Verification
Shell
# Build the 512 KB Sega Master System cartridge (dist/berzerk.sms)
$ make
# Run the 160-assertion automated Z80 playtest suite
$ make playtest