// HARDWARE · WHAT'S UNDERNEATH //
The register is the bitfield
chmod 755. A pile of feature flags packed into one integer. flags |= ENABLED, flags &= ~VISIBLE. You pack booleans into bits and never quite ask why it feels so natural. On the ZX Spectrum the hardware gives you no choice — a single byte to one port runs the border, the speaker and the tape at once.
One port, several switches
The Spectrum’s ULA — the chip that does very nearly everything — listens on I/O port $FE. The byte you write there isn’t a number; it’s a row of independent switches, addressed by position:
; bit: 7 6 5 4 3 2 1 0
; speaker tape border colour
ld a, %00010010 ; speaker on, border = 010 (red)
out ($fe), aWhich is why you mask
To flip one switch without disturbing the rest, you don’t write a fresh number — you OR a bit in, or AND it out, against the byte you already have:
ld a, (shadow) ; the byte we last sent
or %00010000 ; speaker bit ON — leave the rest alone
out ($fe), a
and %11101111 ; speaker bit OFF — leave the rest alone
out ($fe), aThat is flags |= SPEAKER and flags &= ~SPEAKER, forty years early. chmod 755 is the same idea — three rwx bits per user, packed and masked — and so is every options-bitfield, permission set and packed-flags enum you’ve ever touched.
Booleans-in-bits isn’t a trick programmers invented to look clever. It’s the shape the hardware shipped in. The Spectrum’s ULA port makes the lesson literal: a bitmask is simply how you address a row of switches that happen to share one byte.