Skip to content
Game 0 Unit 5 of 16 1 hr learning time

The Screen Is Memory

The big one. Discover that the screen is just a stretch of the same memory street — poke a byte to $4000 and pixels light up. No PLOT, no magic: the bits in the byte are the dots on the glass.

31% of Meet The Machine

This is the one the last two units were walking towards.

The boxes you met in Beat 4 don't all just hold quiet numbers. The ones starting at address $4000 are wired to the glass: write a byte into one, and eight pixels light up on screen. The screen isn't a special device you talk to — it's memory you write to, a stretch of the same numbered street. Every PLOT, every PRINT you ever ran in BASIC was poking these exact boxes for you.

And here's the part that ties the whole Primer together: we need no new instruction to do it. It's the exact store from Beat 4 — ld (addr), a — pointed at $4000 instead of $9000.

What you'll see by the end

A small mark near the top-left of the screen: a solid block running into a row of dots, with a second solid block one character-row below it.
Four bytes, drawn as pixels: a solid cell, two dotted cells beside it, and the puzzle byte at $4020 — which lands a whole character-row lower, not on the next pixel line.

Top-left: a short mark that's solid on the left and dotted on the right — and a second solid mark sitting one row below. You wrote four bytes; those are the four bytes, drawn as pixels. No border colour this time — we never touched the border; we drew straight onto the screen.

A byte is eight pixels, and its bits are the dots

Write %11111111 to $4000 and you get a solid block — all eight bits set, all eight pixels lit. Write %10101010 and you get dots — every other bit, every other pixel. This is exactly the byte-with-no-type idea from Beat 3 made visible: %10101010 is just the number 170, but written here, it's a picture. The bits are the dots.

; ============================================================================
; PRIMER — Beat 5: The Screen Is Memory
; ============================================================================
; The boxes from Beat 4 start at $4000. But these boxes are special: writing
; a byte to them doesn't just store a number — it lights up PIXELS. The screen
; is just a stretch of the same memory street, and PLOT was poking these boxes
; all along.
;
; We use NOTHING new — the very same store from Beat 4 (ld (addr), a), just
; pointed at the screen instead of $9000:
;
;   ld a, %11111111 ; all 8 bits set
;   ld ($4000), a   ; -> 8 solid pixels in the top-left corner
;
; And the byte's BITS are the pixels (remember %01000001 from Beat 3?). A
; dotted byte draws dotted pixels:
;
;   ld a, %10101010 ; every other bit
;   ld ($4001), a   ; -> a row of dots in the next cell
;
; The last store is a deliberate puzzle. $4020 is 32 boxes on from $4000 — so
; if the screen were a simple top-to-bottom list, it would be the next line
; down. Watch where it ACTUALLY lands. (We name that mystery; we don't solve
; it here. The screen's strange map is for later.)
; ============================================================================

            org     32768

start:
            ld      a, %11111111     ; 8 bits set
            ld      ($4000), a       ; solid block, top-left corner

            ld      a, %10101010     ; every other bit
            ld      ($4001), a       ; a row of dots, next cell along
            ld      ($4002), a       ; and again

            ld      a, %11111111     ; the puzzle byte
            ld      ($4020), a       ; "32 on from $4000" — but where does it land?

.loop:
            halt
            jr      .loop

            end     start

$4000 is the top-left cell. $4001 and $4002 are the next two cells to the right — so writing to consecutive boxes draws across the top of the screen, which is just what you'd expect.

The strange part — held for later

Now look at that fourth store: ld ($4020), a. $4020 is thirty-two boxes on from $4000. If the screen were a plain top-to-bottom list — 32 bytes per line, like a sane person would design it — then $4020 would be the next line down.

It isn't. On screen, $4020 lands a whole character lower — eight pixel-rows down, with seven blank rows hidden in between. And stranger still: the box for the pixel line sitting directly below $4000 isn't $4020 at all — it's $4100. The Spectrum's screen is laid out in a famously peculiar order.

We're going to leave that mystery sitting there. Naming it is enough for now; this beat teaches one thing — the screen is memory — and that's done. The screen's strange map is a topic of its own, and the first game unfolds it properly — the moment you draw a sprite into the screen and need it. For now: poke a byte, see pixels. That's the win.

In BASIC, PLOT and PRINT did all this addressing arithmetic for you, behind the curtain. You've just pulled the curtain back.

Assemble and run

pasmonext --sna screen-is-memory.asm primer.sna

Load it: a solid block, a couple of dotted cells, and the puzzle block below. You drew that with four pokes.

Try this: change the picture

Swap %10101010 for other patterns and watch the dots rearrange — %11110000 (four on, four off), %11000011, %10000001. You're not learning new instructions; you're drawing with bits. Predict the shape from the bits before you run it.

Try this: a dashed line

Poke the dotted byte into eight boxes in a row to run a dashed line across the top — the same store, repeated along $4000$4007:

The dotted byte poked across eight cells: a dashed line
+13-31
11 ; ============================================================================
2-; PRIMER — Beat 5: The Screen Is Memory
2+; PRIMER — Beat 5, "Try this: a dashed line across the top"
33 ; ============================================================================
4-; The boxes from Beat 4 start at $4000. But these boxes are special: writing
5-; a byte to them doesn't just store a number — it lights up PIXELS. The screen
6-; is just a stretch of the same memory street, and PLOT was poking these boxes
7-; all along.
8-;
9-; We use NOTHING new — the very same store from Beat 4 (ld (addr), a), just
10-; pointed at the screen instead of $9000:
11-;
12-; ld a, %11111111 ; all 8 bits set
13-; ld ($4000), a ; -> 8 solid pixels in the top-left corner
14-;
15-; And the byte's BITS are the pixels (remember %01000001 from Beat 3?). A
16-; dotted byte draws dotted pixels:
17-;
18-; ld a, %10101010 ; every other bit
19-; ld ($4001), a ; -> a row of dots in the next cell
20-;
21-; The last store is a deliberate puzzle. $4020 is 32 boxes on from $4000 — so
22-; if the screen were a simple top-to-bottom list, it would be the next line
23-; down. Watch where it ACTUALLY lands. (We name that mystery; we don't solve
24-; it here. The screen's strange map is for later.)
4+; Poke the dotted byte %10101010 into eight boxes in a row, $4000 to $4007,
5+; and the dots run right across the top of the screen. Yes, it's eight near-
6+; identical lines — Beat 9's loop will do this properly. For now, by hand.
257 ; ============================================================================
268
...
2810
2911 start:
30- ld a, %11111111 ; 8 bits set
31- ld ($4000), a ; solid block, top-left corner
32-
33- ld a, %10101010 ; every other bit
34- ld ($4001), a ; a row of dots, next cell along
35- ld ($4002), a ; and again
36-
37- ld a, %11111111 ; the puzzle byte
38- ld ($4020), a ; "32 on from $4000" — but where does it land?
12+ ld a, %10101010 ; the dotted pattern
13+ ld ($4000), a
14+ ld ($4001), a
15+ ld ($4002), a
16+ ld ($4003), a
17+ ld ($4004), a
18+ ld ($4005), a
19+ ld ($4006), a
20+ ld ($4007), a ; eight cells of dots = a dashed line, top row
3921
4022 .loop:

Eight near-identical lines, yes — that repetition is exactly the itch Beat 9's loop will scratch. For now, by hand, so you can see every box you're writing.

When it's wrong, see why

  • Nothing appears on screen. Check the addresses start with $40 — the screen begins at $4000. A typo like $5000 writes to ordinary RAM and lights nothing.
  • The pixels are there but invisible. They're drawn in the cell's INK colour. If a cell's INK and PAPER happen to match, the pixels hide — we'll take charge of those colours in the next unit.
  • pasmonext errors on the binary value. Eight bits, prefixed with %, no spaces: %10101010.

What you've learnt

The screen is memory: the boxes from $4000 are wired to the glass, so writing a byte lights eight pixels — and the byte's bits are those pixels.

What's next

You've drawn pixels, but you haven't chosen their colour — the blocks came out black on white because that's the default. Next — Colour Is a Separate Map — we find out colour lives in its own region of memory, one byte per cell, entirely apart from the pixels. It's the root of everything that makes the Spectrum look like the Spectrum.