The picture that is also a program
Here's a party trick we believe has never been published before: a single,
ordinary 6912-byte ZX Spectrum SCREEN$ file that leads a double
life. Load it the normal way and it's a picture. Load the same bytes
somewhere else in memory, call them, and they're a working machine-code
program — one that cycles the border through the rainbow and prints a
message, using the ROM's own routines, before returning politely to BASIC.
Anatomy of a SCREEN$
A Spectrum screen dump is two things glued together: 6144 bytes of bitmap (one bit per pixel, in the machine's famously interleaved layout) followed by 768 bytes of attributes — one byte per 8×8 character cell, controlling that cell's colours:
bit 7 FLASH
bit 6 BRIGHT
bits 5-3 PAPER colour (0-7)
bits 2-0 INK colour (0-7)
And here is the whole trick: every possible byte value is a legal attribute. There is no such thing as an invalid colour. Which means the attribute area of a screen can hold absolutely anything… including executable Z80 machine code. The display hardware will happily interpret your opcodes as ink and paper; the CPU will happily execute your colour scheme.
One file, two load addresses
The tape header declares a load address of 16384 — the screen — so
a plain LOAD "" CODE paints the picture. But BASIC lets you
override a CODE block's address, and that gives the file its second life:
CLEAR 39999
LOAD "" CODE 40000
RANDOMIZE USR 46144
Why 46144? The code sits in the attribute area, which starts 6144 bytes into the file: 40000 + 6144 = 46144. The bitmap — all 6144 bytes of picture data — is never executed at all.
The payload
Seventy-four bytes, hand-assembled. It leans on the ROM for all the hard work:
ORG 46144
LD B,64 ; 64 border changes
outer: LD A,B
AND 7 ; colour 0-7
OUT (254),A ; set the border
LD DE,3072 ; delay counter
delay: DEC DE ; DEC rr sets no flags...
LD A,D ; ...hence this OR test
OR E
JR NZ,delay
DJNZ outer
LD A,7
OUT (254),A ; border back to white
LD A,2
CALL 0x1601 ; ROM CHAN-OPEN: stream 2 (the screen)
LD HL,msg
print: LD A,(HL)
OR A
RET Z ; zero terminator -> back to BASIC
RST 0x10 ; ROM print routine
INC HL
JR print
msg: DEFB 13
DEFM "HELLO! I WAS HIDING IN THE COLOURS."
DEFB 13, 0
Two details worth savouring:
- The program flashes at you. Any opcode with bit 7 set
becomes a FLASH attribute on screen.
OUT (254),Ais0xD3 0xFE— both high — so the instruction that paints the rainbow border literally blinks in the mosaic. The code advertises itself. - The message is readable in the colours. ASCII capitals are 0x41-0x5A — bit 6 set, bit 7 clear — so the hidden text appears as a run of BRIGHT, non-flashing cells. Once you know, you can almost read it off the screen.
Try it yourself
- polyglot.tap — the tape image. Open it in Fuse or any emulator that accepts .tap files.
- polyglot.scr — the raw 6912 bytes, for hex-editor spelunking.
- polyglot_screen.py — the generator: dependency-free Python 3 that builds the whole thing, hand-assembled opcodes and all. Change the message, redraw the picture, make your own.
Picture personality: LOAD "" CODE. Program personality: the
three lines above. Same file, same bytes, both true.
Where you could take it
- A loading screen for your own game that, loaded elsewhere, becomes the game's cheat menu — the easter egg hides on the box art.
- A demoscene entry where every effect's code is shown on screen as colour while it runs.
- The bitmap area is 6144 unexecuted bytes — room for a much bigger second payload, with the attribute code as a stage-one loader that copies it somewhere safe.
The 8×8 character font used in the picture is public domain (by Marcel Sondaar and Daniel Hepper). Everything else — file, code and generator — is original to The Speccy: consider it public domain too. If you build something with it, we'd love to hear.