A course for the Dragon 32 · Chapters 0 to 15
Remember the game you saw in Chapter 0? A yellow apple falls, and a blue basket on the bottom row catches it. Now you know everything you need to write it. Not all at once: in five stages, and each stage is a program that works by itself.
In each stage one line is missing, and there are three choices. Try the wrong ones too: they show what each line does. The last stage you will write by yourself.
The basket ($AF, blue) is on the bottom row. Its finger is Y. The left arrow moves it one step left, the right arrow one step right, and Q quits. And at the walls it stops: CMPY #$05E0 asks “am I at the left edge already?”.
There is nothing new here: it is the block moved with the arrows from Chapter 11, only on the bottom row.
The apple ($9F, yellow) starts on row 1, in column 16, and falls to the bottom row. Like the apple from the puzzle in Chapter 11. Only one thing is new: its finger is U, a third finger (purple). X is busy with the keyboard checker, Y with the basket. U works exactly like Y: LDU, STA ,U, LEAU, CMPU.
The hard part: the basket has to move while the apple falls. But the keyboard loop from Chapter 10 waits for a key, and while it waits nothing moves. So on every lap the big loop does a little of everything:
LDX #800: about 7 thousandths of a second).How do you know when 25 laps have gone by? You need a counter, and all the drawers are taken. So you keep it in memory, in a house of its own, after the fixed ending: TICK FCB 25. FCB is not a command for the processor. It tells DREAM: “Put one house here, with 25 in it.” DEC TICK takes 1 off it, straight in memory. You saw in Chapter 13: the program lives on the street, so its numbers can live next to it too.
And when the apple reaches the bottom row? Look at what is on the screen at the place where it lands: LDA ,U. Is there blue there ($AF)? It landed in the basket. Write Y (yes) or N (no) in the corner, and that’s it.
Two more houses in memory: SCORE (the score) and LEFT (how many apples are left). At the start, CLR SCORE sets the score to zero. Every apple caught: INC SCORE. After every apple: DEC LEFT, and a new apple from the top. After five, the end.
The score shows in the corner as a digit: $70 is the digit 0 on the screen, so $70 plus the score is the digit of the score.
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).