Chapter 6 of 7
Catch the computer in the act
The beacon keeper wants three blinks. If the CoCo prints all three before you can look, how can you find out when it changed from blink one to blink two?
Give the signal a counter
This program prints a numbered message for each blink. Read from line 20 to line 40 with your finger. How many times do you think your finger will pass line 30?
10 CLS
20 FOR I=1 TO 3
30 PRINT "BLINK";I
40 NEXT I
50 PRINT "SIGNAL SENT!"
I is a variable, a name BASIC uses to keep a value in RAM. Here its job is to count. FOR I=1 TO 3 starts the count at 1. PRINT "BLINK";I puts a word and the current number on the screen. NEXT I adds one to the counter and sends BASIC around again while there is another turn left. A group of instructions that repeats this way is a loop.
In Help → Manual Library…, click SIGNAL.bas. An editable copy opens in a BASIC Example window. Keep the book beside it so you can read and step through the program together. The CoCo keeps doing what it was doing until you choose Run.
Reading in a web browser? Save a copy of the linked file on your Mac, then choose Develop → BASIC Development → Open… in VCC Plus to open it. Save any previous work if the editor asks.
Stop before the first blink
- In the editor, click the circle in the left margin beside line 30. You've set a breakpoint, a request for the CoCo to pause when it reaches that line. Using the keyboard, move the insertion point to line 30 and activate the toolbar button Toggle BASIC breakpoint at insertion point. Use either method once.
- Expand Variables and Watches below the listing if it is closed. Choose Watches, type the capital letter
Iin its field and choose Add or press Return. A watch lets you read a value at each stop. - Choose the editor's Run. Choose Replace and Run if asked about replacing your previous practice program in RAM. Look for the highlight at line 30 and the value 1 beside
I. Line 10 has cleared the CoCo screen. The first BLINK is still to come.
Choose Step Into BASIC statement, the down-arrow button beside Continue, once. The highlight moves to line 40. On the CoCo display, BLINK 1 has appeared. Read the watch again. It still says 1. Which instruction will change it?
If all three blinks print in one burst, your program has finished. First check that the marker is beside line 30 and you used Run in BASIC Development. If it happens again, save any work you want to keep. In your practice session, choose Cold Restart — Clear RAM…, confirm, and wait for BASIC’s OK. Open SIGNAL in the editor, check the line 30 breakpoint and run it from there.
To see the guest screen if the editor covers it, choose Show CoCo. Use the Window menu to bring the editor with SIGNAL back to the front. Choose Help → Manual Library… to bring this lesson back. The Mac controls work while the emulated CoCo waits.
Predict the next two stops
Choose Continue once. This resumes your paused program. Before looking at the screen, predict what has changed. Line 30 is highlighted again. The watch says 2, but only BLINK 1 has printed. The highlighted line is the instruction BASIC is about to carry out.
Choose Continue once more. Stop and count the messages before you peek at the watch. Now you should have two messages and a counter of 3. What will appear if you continue one last time? Make your prediction, then choose Continue a third time.
Check the finished signal
The CoCo prints the last blink, finishes the loop and carries on to line 50. Here is the complete screen text.
BLINK 1
BLINK 2
BLINK 3
SIGNAL SENT!
OK
When you see SIGNAL SENT! followed by OK, the CoCo is ready for the quiz.
How a number gets onto the screen
At the second stop on line 30, RAM held the number 2 under the name I. The screen still showed the earlier number 1. When BASIC carried out PRINT, it turned the current number into a character you could read. You saw those two jobs happen at different times.
Memory stores patterns of bits. A bit can be 0 or 1, and eight bits make one byte. The CoCo uses patterns in memory to represent the characters on its screen. BASIC also uses space in RAM to keep a variable's name, the kind of value it holds, and the value itself. A one-letter name on your watch is enough to look up all that information.
To watch a number change one instruction at a time, follow a byte through register A. To see how RAM becomes a picture, look for a dot on a hidden page.
For the loop commands, see Tandy Corporation, Tandy Color Computer 3 BASIC Quick Reference Guide (1986), commands, pp. 2–17.