ZX SPECTRUM 48K · TECHNICAL MANUAL THE HOBBIT (1982)

Making The Hobbit (1982) Paint 23× Faster

Chapter 1

What If We Brought This Back to 1982?

Picture sitting on a living-room carpet in November 1982. You load The Hobbit onto an ordinary 48K ZX Spectrum — the exact same 3.5 MHz Z80 chip, the exact same 48 KB of memory, the exact same artwork — except Bag End finishes painting in 0.6 seconds instead of 6.7 seconds, and Wild Mountains snaps onto the screen in under a second instead of nearly 12.

To players and programmers in 1982, that speedup would have felt like a strike from another dimension. Yet the original authors at Beam Software were brilliant — they simply had no cycle-exact profilers, no automated 22-room pixel verifiers, and no AI able to audit every byte of memory in seconds.

A Mirror for Today
This experiment is really about our own era. The software we write in 2026 probably looks to future engineers — and future AI — the same way 1982 code looks to us now. Hidden inside today's "fast enough" codebases are the same 10× and 20× breakthroughs waiting for better tools to uncover them.

Watch the Full Game Race (Start to Finish)

1982 Original on the left vs. our fast version on the right — 1× real speed, finishing 107.6 seconds earlier.

Watch on YouTube ↗
▶ Try the Live Side-by-Side Race Yourself Opens a quick dialog to patch & race your own 1982 game file locally in your browser
Chapter 2

How 1982 Drew It vs. How We Rewrote It

Cycle-exact profiling of the opening Bag End scene (23.6 million Z80 ticks = 6.74 s) revealed a startling fact: 95.9% of the entire drawing time is trapped inside just 465 bytes of code ($8A4F–$8C20):

  • sub_8bbch (45.6%) — converts an (x, y) coordinate into a screen memory address and bit mask.
  • sub_8a4fh (35.3%) — the paint-bucket flood-fill loop that colours each region.
  • sub_8b93h (12.0%) — plots a single pixel and tints its 8×8 colour cell.

Why 1982 was slow: The ZX Spectrum's screen memory isn't laid out linearly — rows are bit-interleaved. Every time the 1982 flood-fill moved 1 pixel right, it called sub_8bbch four times (check above, check below, check right, then paint itself). Each call recomputed the scrambled screen address from scratch and looped a shift instruction up to 8 times just to isolate one bit — burning ~1,300 CPU ticks per pixel.

; 1982 ORIGINAL (sub_8bbch): runs 4x per pixel (~270 ticks/call)
sub_8bbch:
    ld a, $7F : sub e   ; Flip Y & reshuffle bits for
    ...                 ;   Spectrum's scrambled VRAM layout
    ld a, d : and $07   ; Pick bit index (0..7) inside byte
    inc a   : ld b, a   ; Loop counter B = 1..8
    ld a, $01           ; Start with bit 0
.shift:
    rrc a               ; Rotate bit right (8T, up to 8x!)
    djnz .shift         ; Mask ready for just 1 pixel

How our 2026 rewrite works: Two clean changes eliminate almost all of that wasted work:

  1. Pre-computed lookup tables: Instead of doing bit-shuffling maths on every pixel, look up the exact screen row address in two instructions from a 256-byte page-aligned table (H_Y_LO / H_Y_HI), and grab the bit mask from an 8-byte table.
  2. Whole-byte horizontal scanlines: Walk across each row with a single memory pointer HL. Whenever an 8-pixel byte is empty ((hl) == 0), fill all 8 pixels in one single instruction — dropping inner-loop cost from ~1,300 ticks/pixel down to 1.25 ticks/pixel.
; 2026 REWRITE: row lookup + whole-byte fill (1.25 ticks/px!)
    ld h, high(H_Y_LO)  ; Point H at row lookup table (7T)
    ld l, e             ; Index by Y — zero bit-maths (4T)
    ...
; Across open sky or walls, fill 8 pixels in 1 write:
ff_fast_byte:
    ld (hl), $FF        ; Paint 8 pixels at once! (10T)
    inc l               ; Next 8 pixels, no helper call (4T)
Chapter 3

The Hard Parts & Full Verification

Writing a fast filler on paper is easy; making it survive inside a real, unmodified 1982 game was the hard part:

  • Squeezing into 983 bytes of spare RAM: We refused to modify the 1982 48K ROM or touch any game text, parser logic, or room data. Every lookup table ($CB00–$CBFF, $CA80–$CAC7) and fast loop ($F35B–$F3FF) had to fit into audited unused gaps across the entire 48 KB address space.
  • Exact 8×8 colour-block parity: The Spectrum shares one ink/paper colour per 8×8 block ($5800–$59FF). Even a 1-pixel difference in boundary handling or fill order can tint the wrong block — our scanline filler had to reproduce 1982's exact contrast rules bit for bit.
  • Zero stack overflow across all 22 rooms: Flood-fill span queues live in tight memory; worst-case jagged outlines had to stay safely bounded without corrupting game state.

Test results: We verified every illustrated room independently (22 / 22) and ran a complete 122-command playthrough from Bag End to slaying Smaug and returning home. Across all 19 walkthrough illustrations, drawing time dropped from 117.32 s to 12.01 s (9.77× faster) — saving 107.6 seconds end-to-end, with all 632 lines of story text and all 6,912 bytes of final screen memory 100% identical (0 diffs).

Room #14 (Peak Speedup) 11.50 s → 0.49 s (23.55× faster)
Room #21 (Final Cavern) 10.41 s → 0.73 s (14.30× faster)
Room #09 (Canyon Ridge) 8.15 s → 0.59 s (13.88× faster)
Room #02 (Wild Mountains) 11.70 s → 0.99 s (11.84× faster)
Room #00 (Bag End — Opening Scene) 6.74 s → 0.61 s (11.02× faster)
Full 22-room cycle-accurate benchmark table (all 0-Diff)
Room Pointer 1982 2026 Speedup Diffs
#00 Bag End$CC436.74 s0.61 s11.02×0
#01$CE776.46 s0.62 s10.40×0
#02 Wild Mountains$CFB211.70 s0.99 s11.84×0
#03$D24E6.32 s0.59 s10.63×0
#04$D3671.82 s0.53 s3.41×0
#05$D5B50.28 s0.20 s1.38×0
#06$D7135.57 s0.71 s7.90×0
#07$D92A1.49 s0.47 s3.19×0
#08$DBA82.42 s0.56 s4.33×0
#09 Canyon Ridge$DD798.15 s0.59 s13.88×0
#10$E02C6.63 s0.55 s12.05×0
#11$E0496.41 s0.52 s12.30×0
#12$E1423.12 s0.52 s6.00×0
#13$E19F2.68 s0.48 s5.62×0
#14 Peak Speedup$E3FE11.50 s0.49 s23.55×0
#15$E47A2.04 s0.52 s3.95×0
#16$E6E41.25 s0.48 s2.61×0
#17$E9EE6.41 s1.06 s6.06×0
#18$EC3E6.29 s0.74 s8.49×0
#19 River Stronghold$EE4310.29 s0.91 s11.31×0
#20$F0018.08 s1.08 s7.45×0
#21 Final Cavern$F1E610.41 s0.73 s14.30×0
All 22 Rooms Total22 Rooms126.05 s13.94 s9.04×0
VEST8 · ZX SPECTRUM NOTES PAGE 1