Level 27: Hello, Ports!

Open the level →Where it fits in the machine →

Task

Goal: Change the constants in the program so the pixel lights up at X=4, Y=12. Then seed the array for "Snake" (level 29): write 7 into RAM[10] and 8 into RAM[11] via the index register IX (LDX / STA [IX] / INX).

I/O ports: 252=X-coordinate, 253=Y-coordinate, 255=write pixel.

The main idea: a ready-made program is text you can read and edit surgically: the port constants sit right in the STA instructions, and changing the numbers moves the pixel across the screen. Someone else's code is material just like your own.

Related Materials

Solution for self-check

Try building the circuit yourself first. The solution below is a way to check yourself if you're stuck or have already solved it.

What you should get: the pixel lights at (4,12), and RAM[10]=7, RAM[11]=8 hold the coordinates for Snake.

LDA loads an IMMEDIATE VALUE (the operand) into the accumulator. STA writes the accumulator value TO THE ADDRESS of the operand.

The template uses LDA 8. You need to change the values 8 to 4 and 12: replace the first LDA 8 with LDA 4, and the second LDA 8 with LDA 12.

1. Open the "Assembler" tab in the right panel. 2. Replace the first LDA 8 with LDA 4 (X=4). 3. Replace the second LDA 8 with LDA 12 (Y=12). 4. Click "Run". 5. Click "Checkpoint 1" — the pixel on the display should light up at (4,12).

Assembler help →

Check yourself

Why can the value 8 from LDA 8 be stored twice by two STA instructions in a row?

STA does not clear the accumulator: both stores take the same value from Acc.