Machine code from zero

A course for the Dragon 32 · Chapters 0 to 15

Chapter 15

To the real machine

About 20 minutes · a button, a tape, a machine

1Your game, complete

This is the game from the last stage, at “Dragon speed”. Press Run, and move the basket with the arrows (under the screen, or on your own keyboard after clicking on the window). Five apples. How many will you catch?

On the Dragon, a key that you hold down counts once (we saw this in chapter 10). To move the basket three steps, you press three times.

2Send it to the Dragon machine

Until now the game has run in a window of the course. Now it moves to the Dragon machine on the site: a whole computer, with the Dragon’s processor, memory and screen. There it runs just as it would in 1982.

Figure 30: the game’s journey. The button turns the numbers into a tape, the tape goes into “My tapes”, and on the machine you load it and run it.
  1. Press the button 🐉 Send to the Dragon machine, under the game window above. The button takes the game’s numbers, 154 houses, and puts them on a tape called CATCH, in the machine’s “My tapes”.
  2. The Dragon machine opens in a new tab. Wait until OK appears.
  3. Type CLOADM "CATCH" and ENTER. CLOADM means “load machine code from the tape”. The numbers go into memory, into the same houses as in the window, from $2EE1, and OK appears again.
  4. Type CLS:EXEC and ENTER. CLS clears the screen, and EXEC tells the processor: “jump to the first house of the program”. The tape remembers which house that is.
  5. Play! The arrows move the basket. Q quits, and one more key takes you back to BASIC’s OK.
Why does it go back to BASIC? Thanks to the fixed ending. Its last line is RTS: “go back to whoever called you”. In the course windows DREAM called us, and on the machine BASIC’s EXEC called us. It’s like the plate from Chapter 12: whoever put it down gets the processor back.

The same button is under every window in the course, from Chapter 2 to here. Any program you have seen, you can send to the machine and watch it run there.

3Your version

Want to change something in the game? Here it is, written out, and you may change anything in it: the 5 in LEFT (how many apples), the 25 in TICK (how fast), the colours. Underneath you can see every line with its numbers. When there are no errors, the button below sends your version to the machine, on a tape called MYGAME: CLOADM "MYGAME", then CLS:EXEC.

Want to write a program of your own from scratch, with every command of the processor? The Assembler is waiting: an editor, run, step and send to the machine.

4On a real Dragon

  1. On the Dragon machine, in “My tapes”, there is a 🔊 button next to the tape: it downloads it as sound (a wav file), like a tape from back then.
  2. Connect the Dragon’s cassette cable (the EAR plug) to the headphone socket of the computer or phone.
  3. On the Dragon: CLOADM, and play the sound at about 75% volume. When OK appears: CLS:EXEC.
  4. Does ?IO ERROR appear? Change the volume and try again.
Have a real Dragon with DREAM? You can also do it the old way

In 1983 people wrote a game like this in DREAM, the editor and assembler from Dragon Data, and saved it to tape themselves:

  1. Load DREAM: CLEAR 200,12000, CLOADM, EXEC, then N (new program).
  2. Type in the game, line after line, including the fixed ending and the houses after it. BREAK then A: assemble, until 0000 errors. BREAK then X: play.
  3. To save to tape: BREAK, Q and ENTER (out to BASIC; the numbers stay in memory), then the CSAVEM line from step 3, under your version. It needs three numbers: the first house, the last house, and the house where it starts running.
  4. To go back to DREAM: EXEC &H6080 (where DREAM starts), then N.

The numbers come out the same: the button assembles exactly like DREAM, house after house.

★Certificate of completion

→What now? Ideas to carry on

The game is yours, and you may change anything in it. Some ideas, from easy to hard:

  • More apples, or faster. Change the 5 in LEFT, or the 25 in TICK (in both places). Smaller = faster.
  • Winning. When the score reaches 5, write YOU WIN on the middle row, letter by letter, as in chapter 2.
  • A wide basket. A basket of three squares is easier to catch with. The check LDA ,U will still work with no change: it only asks “is there blue underneath?”.
  • A title screen. The name of the game in the middle of the screen, and “press a key” (the keyboard loop from chapter 10). Only after a key do you start.
  • Subroutines. Put the drawing of the basket and the drawing of the apple into subroutines (chapter 12). The main program will be short and easy to read.
  • Two players. Two baskets: one with the arrows, and one with letters, for example Z and X. Two scores, one in each corner.
  • Sound. A beep when you catch. That is a topic for the next course: the Dragon plays sound when you write numbers to a special house, again and again, very fast.

Write each idea in step 3, and send it to the machine with the same button.

You did it. You wrote a game in the language the games of 1982 were written in, and it runs on the machine. Every programmer of that time started exactly here: one block on the screen, and then another.

What we learned: the program is numbers, and the numbers go onto a tape. CLOADM "CATCH" loads them into memory, and EXEC runs from the first house.
From the course, through “My tapes”, to the Dragon machine, and as a sound file to a real Dragon too: exactly the same numbers.

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