Machine code from zero

A course for the Dragon 32 · Chapters 0 to 15

Chapter 1

The screen is memory

About 15 minutes · still no code

1The secret: 512 houses you can see

The houses from 1024 to 1535 are special. Each one of them is a square on the screen. What is written on the house’s board is what the square shows.

How do 512 houses on one street become a screen? Cut the street every 32 houses, and lay the pieces one under the other. You get 16 rows of 32 squares.

Figure 4: We fold the street into rows of 32. The first house, 1024, is the top left corner.

2The live screen

This is the Dragon’s screen, square by square. Hover the mouse over a square (on a phone: tap it), and you’ll see its house number and what is written in it. A click chooses a square, and then you can write a number in it.

    Did you notice? You didn’t write “A”. You wrote 65, and the screen showed A. The computer doesn’t know letters, only numbers. A is what it calls 65.

    3Right is plus 1, down is plus 32

    A step to the right is simply the next house on the street: plus 1. A step down skips a whole row: plus 32, because every row has 32 houses.

    Figure 5: The map of the screen. At the side: the number of the first house in each row.

    Now try it on the live screen above: tasks 6 and 7.

    4Which number does what

    Every number from 0 to 255 draws something in the square. Here are the most useful ones. No need to remember them. The table is always here.

    There are eight colours, and every colour square can also be a half or a quarter. The maths of that is waiting for Chapter 4. For now: 191 red, 175 blue, 159 yellow, 207 white.

    5On the real Dragon

    You can do the same thing on the machine itself, in BASIC, with no extra tool. The command POKE writes a number in a house:

    CLS:POKE 1295,65:POKE 1535,191

    The A will appear in the middle of the screen, and a red block in the bottom right corner.

    A tip we found while checking: the top row is not good for trying things in BASIC. Straight after the command BASIC writes OK there, and on the way it wipes the whole row. So check in the middle of the screen. ✓ Checked on our Dragon machine

    ?Puzzles

    What we learnt: the screen is 512 houses, from 1024 to 1535, in rows of 32. Right is plus 1, down is plus 32.
    The number in the house decides what you see: 65 is A, 96 an empty square, 191 a red block.

    A hobbyist tribute project, not affiliated with or endorsed by Dragon Data. The course, drawings and text are our own. Every program in the course was checked on the site's Dragon machine (XRoar running the BASIC we wrote).