A course for the Dragon 32 · Chapters 0 to 15
In Chapters 7 and 8 we opened up the fixed ending: LDX $A000 points the finger at the keyboard checker, a small job that lives in the Dragon’s fixed memory. JSR ,X goes to it and comes back. We saw that when nothing is pressed, lamp Z is on.
Now the missing part: the checker comes back with the key’s code in drawer A. G pressed? A will hold $47, exactly like LDA #'G. Nothing pressed? A will hold 0, and that is why Z is on.
Now you can read the fixed ending like a sentence: “Ask the keyboard. If nothing was pressed, ask again. If something was pressed, go back to DREAM.” Until now we didn’t care which key. From today we do.
From here on the fixed ending is written out in the windows, and the processor really runs it. At the end of every run you will have to press a key, just like on the Dragon.
The fixed ending’s waiting loop, in the middle of the program. Here it is called WAIT, because the name KEY is taken. Under the screen there is a small keyboard. You can also press keys on your own keyboard, after clicking on the window.
Press the keys and see what arrives in drawer A. The letters have a code you already know. The arrows and SPACE have codes of their own.
Every key you press is written on the screen, one after another. Q stops. Notice the two questions: BEQ LOOP = “nothing pressed? ask again”. CMPA #'Q and BEQ KEY = “Q pressed? go to the end”.
LDX $A000 overwrites X on every question. The keyboard checker doesn’t touch Y or B, so they are safe.Now we decide by the key: R paints the square red, B blue, Q leaves. This is exactly the crossroads from Chapter 8, only the question is “which key?”.
Notice: the colour goes through B (LDB, STB). Why not A? Because A holds the key’s code, and we still need it for the next question.
Each puzzle is checked in several cases. In each case different keys are “pressed”, one after another, and at the end the screen must look like the picture. You don’t need to type the fixed ending: it is already there, and the Q key must get to it.
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).