Skip to content

Peek and Poke

You'll read a machine's memory map, drive the screen and the border straight from BASIC, then assemble a routine of under forty bytes and call it from BASIC.

About

On an 8-bit machine, everything is a memory address: the screen, the colours, the keyboard, the sound chip. PEEK reads an address and POKE writes one, and once you know the map you can make the machine do things BASIC never had a command for. This badge takes you from POKEing the border colour to writing a short machine code routine with a free cross-assembler, loading it with DATA statements and calling it from BASIC. It runs fine in an emulator, and a real machine is a bonus. Demoscene's raster effects start where this ends, with code timed to the scanline. Here you just need it to work.

At a glance

Per requirement
25 XP
Completion bonus
150 XP
Requirements
6
Takes
One weekend
Skill level
Beginner (done it a few times)
Cost
Free
Supplies
Nothing special
Where
At home
Other people
On your own
Locked for now
Earn two more Common badges in Retro Computing to open this one. Log in to see how far along you are.

Requirements

  1. 1
    Find your machine's memory map and mark five addresses on it. Every popular machine has a published map: screen memory, colour memory, the border register, a keyboard register and the start of free RAM. Print it or draw it. Take a photo of the map with your five addresses circled and labelled. Photo
  2. 2
    POKE the border and the screen directly from BASIC. Change the border colour with one POKE, then write a loop that fills screen memory with a character and colour memory with a colour, without using PRINT at all. Film the fill happening, and tell us how many seconds the BASIC loop takes to cover the screen. Video
  3. 3
    Read the keyboard or joystick with PEEK and move a character with it. Read the register, mask the bit, and POKE a character to a new screen address when a key or direction is held. The trap is forgetting to erase the old position. Film 20 seconds of steering the character around. Video
  4. 4
    Assemble a screen-fill routine of under 40 bytes with a cross-assembler. ca65 and 64tass handle 6502 machines, and pasmo and sjasmplus handle the Z80. Write the loop that fills screen memory, assemble it, and look at the bytes it produced. Take a screenshot of the source and the assembled hex side by side. Photo
  5. 5
    Load the routine with DATA statements and call it from BASIC. READ the bytes into free RAM with a loop of POKEs, then call them with SYS, USR or CALL, whichever your machine uses. Time the fill against your BASIC version from earlier. Film both fills back to back, and tell us the two times, which should be seconds against a blink. Video
  6. 6
    Comment every line of the routine so a friend could follow it. Say what each instruction does and why the loop ends where it does. If you can explain the branch instruction out loud without notes, you understand it. Take a photo or a screenshot of the commented listing. Photo