Repository navigation
Releases
v0.0.3: Wolf 3D SMS: optimize to get more performance: reaches between 17 and 19 FPS depending on window size.
Full Changelog: v0.0.2...v0.0.3
Here is a clear, player-friendly summary of the v0.0.3 performance and optimization update for Wolfenstein 3D (Sega Master System):
🚀 Performance Boost: Up to 19 FPS & Half-Redraw Innovation
The v0.0.3 update introduces clever frame-budgeting techniques---most notably an interleaved half-column redraw mode---pushing turning and rotation speeds up by over 50% and peak frame rates up to 18.6 FPS during movement.
Real-Time Frame Rate Benchmarks (Walk / Turn / Room)
| Build / View Width | Walk | Turn | Room Scan |
|---|---|---|---|
| Previous Baseline | 16.7 FPS | 5.0 FPS | 4.0 FPS |
| 192 px Wide (Default) | 16.4 FPS | 7.5 FPS | 5.8 FPS |
| 160 px Wide | 17.5 FPS | 8.8 FPS | 6.2 FPS |
| 128 px Wide | 18.6 FPS | 10.5 FPS | 7.0 FPS |
⚙️ Key Optimization Features
1. Option 3: Smart Half-Column Redraw (Turning is ~50% Faster)
-
How it Works: When more than 7/12ths of the screen columns change rapidly (such as spinning quickly or looking across a busy room), the engine dynamically alternates by redrawing only the left or right half of the view each frame.
-
Visual Trade-off: Creates a minor rolling seam while turning fast where the two halves are a single frame apart, but keeps motion fluid.
-
Safety & Testing: Automatically disables during full screen refreshes (like loading screens or palette changes). A dedicated regression test (
tests/t_half.txt) ensures that all pending columns fully drain to zero as soon as turning stops so no visual artifacts remain. -
Note: The deterministic testing (DET) build bypasses this mode to maintain 100% exact frame-by-frame match with original execution requirements.
2. Option 2: Configurable Build-Time View Widths
-
How to Build: Players or developers can compile custom view ratios using
VIEW_W=160 makeorVIEW_W=128 make(or viatools/make_views.sh). -
Aspect Preservation: Maintains the correct horizontal field of view so the picture scales cleanly rather than cropping. (Height is locked at 96 pixels due to the Master System assembly layout handling view columns as 12-tile blocks).
3. Option 1: Assembly Profiling Findings
- Further deep assembly rewrites were evaluated, but profiling revealed that walking frames are a flat distribution (~223k cycles split across sprites, actors, drawing, and raycasting with no single function exceeding 8%). Consequently, attention was prioritized on the half-redraw and screen-width options.
📂 Deliverables & Documentation
-
ROM Variants: Built across 192 px, 160 px, and 128 px view configurations.
-
Testing: All 19 automated tests and rendering checks pass successfully.
-
Repository: Local commits are logged on the
perfbranch, ready for push upon GitHub connector authorization.
v0.0.2: Wolf 3D SMS: Optimize from 11 FPS to 17 FPS
Full Changelog: v0.0.1...v0.0.2
The walking performance target has been successfully achieved, increasing from 10.8 FPS (~11 FPS) to 16.7 FPS (~17 FPS), with overall improvements across turning and heavy sprite room scenes.
📊 Final Benchmark Summary
| Benchmark Scenario | Original | Optimized (v0.0.3+) | Performance Gain |
|---|---|---|---|
| Walk (Corridors / Doors) | 10.8 FPS | 16.7 FPS | +54.6% |
| Turn (In-Place 360°) | 4.2 FPS | 5.0 FPS | +19.0% |
| Room (Dense Sprites / Combat) | 3.0 FPS | 4.0 FPS | +33.3% |
🛠️ Key Optimizations Implemented
-
Sprite Pipeline & Setup (
sprites_a.s): Migrated the column-by-column sprite culling, projection, and list-insertion routines into hand-optimized Z80 assembly, cutting ~19k cycles per frame. -
Fast Fixed-Point Multiplication (
mulfix.s): Replaced slow runtime long multiplies with optimized 16×16→32-bit routines (~550 cycles instead of ~1000), speeding up sprite projection,FixedByFrac, and actor tic updates (mul_tics). -
Actor Loop & Collision (
TryMove&DoActor): Rewrote player wall/actor collision checks and actor stepping logic in assembly, skipping redundantSightPlayerchecks for out-of-range or inactive actors. -
Patrol Fast-Paths: Handled common straight-line patrol steps directly within the always-mapped code bank, eliminating cross-bank trampoline overhead.
-
Interrupt & Sound Player (
snd_a.s): Converted the 70 Hz PSG sound player's inner loops to assembly, reducing audio processing overhead during active gameplay and firefights.
✅ Verification & Testing
-
Equivalence Testing: All 8 deterministic scenarios match the pre-optimization golden hash files (
golden.json) with 0 mismatches. -
Self-Checks (
src/dbg.c): Live differential comparisons between the new Z80 assembly routines and their original C counterparts report zero differences across random inputs and active level data. -
Test Suite:
tests/run_all.shpasses all regression, audio, save-state, and front-end checks cleanly.
v0.0.1: Wolf 3D for Sega Master System: initial port using Arena.
Full Changelog: https://github.com/haroldo-ok/wolf-3d-sms/commits/v0.0.1
🎯 Project Overview & Scope
A complete port of id Software's Wolfenstein 3D (shareware v1.4, Episode 1, 10 levels) to the 8-bit Sega Master System. It adapts the game logic from the Sega Genesis port (haroldo-ok/wolf-3d-md) while using a custom SMS platform layer, ray caster, and asset conversion pipeline derived from haroldo-ok/catacomb-abyss-sms.
-
ROM Architecture: 3.4 MB (207 banks of 16 KiB, standard Sega mapper).
-
Cartridge RAM: 32 KiB (Page 0 for active level state, Page 1 for saves and high scores).
-
View Resolution:
$192 \times 96$ pixels ($24 \times 12$ tiles, 48 rays of 4 px wide) utilizing Wolfenstein's native$72^\circ$ projection.
📋 Features & Implementation Status
| Area | Status / Technical Summary |
|---|---|
| 3D Raycaster & Sprites | Textured walls, doors, push walls, and depth-scaled sprites running at |
| Campaign Content | All 10 shareware levels, enemies, AI routines, weapons, items, status bar, and weapon-in-hand rendering. |
| Front-End & Menus | Full attract loop, PG-13 screen, title, credits, high scores, main menu, sound configuration, and 4 difficulty settings featuring BJ's animated face. |
| Intermissions & Text | "Get Psyched", level completion tallies (par time, kill/secret/treasure ratios, BJ breathing), secret floor, victory screen, and the 41-page "Read This!" help manual pre-rendered via an offline page layout engine. |
| Saves & High Scores | 3 save slots (stored in cart RAM Page 1 with precise game-state reconstruction) and high scores with D-Pad name entry. |
| Audio Engine | SN76489 music and sound effects (87 SFX, 11 shareware music tracks) driven via frame interrupts; 16 digitized voices handled via line interrupts. |
🕹️ Controls
| Input | Action |
|---|---|
| D-Pad Up / Down | Walk forward / backward |
| D-Pad Left / Right | Turn left / right |
| Button 1 | Fire weapon / Select menu item |
| Button 2 | Use (open doors, push walls, elevators) / Back out of menus / Delete letter in name entry |
| Button 2 + Left / Right | Strafe (side-step) |
| Button 2 (Held) + Down | Change active weapon |
| Pause Button | Open in-game options menu |
| Name Entry | Up/Down changes letter, Left/Right moves cursor, Button 1 / Pause confirms |
⚙️ Technical Highlights
-
VRAM Budget: The screen layout packs 288 view tiles, 3 flat tiles, 112 HUD tiles, and weapon sprites into
$\le 431$ total tiles (well beneath the SMS VDP limit of 448). -
Performance Optimizations: Hot paths are accelerated via Z80 assembly (
sprites_a.s,render_a.s), static caching, precalculated bit-multiply projection tables, and incremental column redraws. On an emulator benchmark, gameplay runs between 3.0 to 10.8 FPS depending on scene complexity (turning vs. open corridors). -
Digitized Audio: Voice samples (7 kHz, 8-bit) are resampled to 7.86 kHz and output by summing two PSG channels via line interrupts (active every second scanline during active display), costing roughly 12% CPU time during active firefights.