Machine code from zero

A course for the Dragon 32 · Chapters 0 to 15

Chapter 4

Colour squares: four lamps

About 20 minutes · and at the end: why 255

1A magnifying glass on a colour square

In Chapter 1 you saw that 191 is a red block. But every colour square is really four small blocks, two on top and two below. Each small block is a lamp: on, in colour, or off (black).

Each lamp has a fixed value: top left 8, top right 4, bottom left 2, bottom right 1. Add up the values of the lamps that are on, and you get a number from 0 to 15. That is, one digit of the computer: 0 to F.

Figure 13: the four lamps and their values, and four examples.

2The left digit: the colour

The number of a colour square has two digits. The right one, as we saw, says which lamps are on. The left one says which colour: 8 green, 9 yellow, A blue, B red, C white, D cyan, E magenta, F orange.

Figure 14: the eight colours, and the left digit of each one.
Figure 15: reading a square: $BC = red, top half.
And what about 191 from Chapter 1? 191 is $BF: red, with all the lamps on (8+4+2+1 = 15 = F). Now it is also clear why 143 ($8F) can’t be seen: full green on a green background.

3Light them yourself

Press the lamps to turn them on and off, and choose a colour. Next to it you can see how the number is built.

    4The secret of 255

    In Chapter 0 we promised to find out why a house only holds up to 255. Here is the answer: every house is really eight lamps. Four for the left digit and four more for the right one.

    Here too each lamp has a value: from the right 1, 2, 4, 8, and we keep doubling: 16, 32, 64, 128. When all eight are on: 128+64+32+16+8+4+2+1 = 255. There is no ninth lamp, so there is no room for 256.

      Every house in memory is eight lamps like these, even when it isn’t a colour square. The letter A (65) is lamp 64 and lamp 1. The computer doesn’t know it’s a letter; only the screen draws it that way.

      And what happened to 300 in Chapter 0? It needs a ninth lamp (256). DREAM threw it away, and only what was in the eight lamps was left: 300 minus 256 = 44.

      5Drawing with a program

      6A number is missing

      We wanted a square with only its left half blue. Which number goes in the empty space?

      ?Puzzles: draw it like the picture

      Your screen has to match the picture. Squares that are different will be marked in red. Hover over the picture (or tap it) to see the house number and the number in each square.

      All the programs in this chapter’s windows, and the puzzle solutions too, were typed into DREAM on our Dragon machine, translated with no errors (0000 ERRS) and run. We checked number by number: what was written in each square of the screen matches what the windows here show, and the colours match the Dragon machine’s colours too.
      What we learned: colour square = $8? to $F?. The left digit is the colour, the right one is the lamps: 8, 4, 2, 1.
      Every house is eight lamps. All on = 255 = $FF. That’s why there is no more.

      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).