Making The Hobbit (1982) Paint 23× Faster
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.
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.
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:
- 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. - 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)
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).
Full 22-room cycle-accurate benchmark table (all 0-Diff)
| Room | Pointer | 1982 | 2026 | Speedup | Diffs |
|---|---|---|---|---|---|
| #00 Bag End | $CC43 | 6.74 s | 0.61 s | 11.02× | 0 |
| #01 | $CE77 | 6.46 s | 0.62 s | 10.40× | 0 |
| #02 Wild Mountains | $CFB2 | 11.70 s | 0.99 s | 11.84× | 0 |
| #03 | $D24E | 6.32 s | 0.59 s | 10.63× | 0 |
| #04 | $D367 | 1.82 s | 0.53 s | 3.41× | 0 |
| #05 | $D5B5 | 0.28 s | 0.20 s | 1.38× | 0 |
| #06 | $D713 | 5.57 s | 0.71 s | 7.90× | 0 |
| #07 | $D92A | 1.49 s | 0.47 s | 3.19× | 0 |
| #08 | $DBA8 | 2.42 s | 0.56 s | 4.33× | 0 |
| #09 Canyon Ridge | $DD79 | 8.15 s | 0.59 s | 13.88× | 0 |
| #10 | $E02C | 6.63 s | 0.55 s | 12.05× | 0 |
| #11 | $E049 | 6.41 s | 0.52 s | 12.30× | 0 |
| #12 | $E142 | 3.12 s | 0.52 s | 6.00× | 0 |
| #13 | $E19F | 2.68 s | 0.48 s | 5.62× | 0 |
| #14 Peak Speedup | $E3FE | 11.50 s | 0.49 s | 23.55× | 0 |
| #15 | $E47A | 2.04 s | 0.52 s | 3.95× | 0 |
| #16 | $E6E4 | 1.25 s | 0.48 s | 2.61× | 0 |
| #17 | $E9EE | 6.41 s | 1.06 s | 6.06× | 0 |
| #18 | $EC3E | 6.29 s | 0.74 s | 8.49× | 0 |
| #19 River Stronghold | $EE43 | 10.29 s | 0.91 s | 11.31× | 0 |
| #20 | $F001 | 8.08 s | 1.08 s | 7.45× | 0 |
| #21 Final Cavern | $F1E6 | 10.41 s | 0.73 s | 14.30× | 0 |
| All 22 Rooms Total | 22 Rooms | 126.05 s | 13.94 s | 9.04× | 0 |