← Manual LibraryVCC Plus 3.7.1 · Reading on the web

Try the exercises in VCC Plus. Example links download files here; open them in the app to work beside the emulator.

The complete book · PDF editionBook 3: Programming in CoCo BASIC on the Color Computer 3

79 pages · VCC Plus 3.7.1 · Keep a copy to read or print.

Download PDF
Contents

Chapter 9 of 12

Listen for a signal

A joystick can report more than “left” or “right.” It can tell your program how far the stick has moved. Give the ship three messages to send, and see how one number decides which one you receive.

Point the right-port scanner

Open Input → Keyboard and Joysticks…. Make a note of your current right CoCo port assignment so you can put it back. Either select your controller for that port, or select Keyboard and the arrow-key layout. If the options are folded, expand the right port’s options. With the keyboard layout, Left and Right move the virtual stick and releasing the keys centers it.

Open RADAR.bas and click Run. Focus the CoCo display. Hold the stick toward the left, or hold Left on your keyboard, and tap A on the CoCo keyboard. You should get WEST SIGNAL. Start another run, release the direction and tap A for CENTER SIGNAL. On a third run, hold right and tap A for EAST SIGNAL. A is an ordinary typing key in the arrow layout. Choosing the W/A/S/D layout would give that key a joystick job of its own.

10 WIDTH 40:CLS
20 PRINT "RIGHT STICK SCANNER"
30 PRINT "MOVE THE STICK. PRESS A KEY TO SCAN."
40 IF INKEY$="" THEN 40
50 X=JOYSTK(0)
60 IF X<24 THEN PRINT "WEST SIGNAL":END
70 IF X>39 THEN PRINT "EAST SIGNAL":END
80 PRINT "CENTER SIGNAL"

The pause on line 40 gives you time to aim. INKEY$ returns an empty string while there is no character waiting. When it receives a character, execution reaches line 50. JOYSTK(0) then samples the right port’s horizontal axis. The 0 inside the parentheses selects the axis. The number assigned to X describes its position.

Decide where west begins

The stick reports a value from 0 through 63. The middle is around 31. The program gives the center a generous landing strip.

X reading Line that decides Message
0 through 23 60 WEST SIGNAL
24 through 39 80 CENTER SIGNAL
40 through 63 70 EAST SIGNAL

Prediction. Suppose X is exactly 39. Line 60 asks whether 39 is smaller than 24. Line 70 asks whether it is larger than 39. Both answers are false, so BASIC reaches line 80. At 40, line 70 prints its message and executes END. The center message never gets its turn.

If all three runs return CENTER, check the right-port assignment and the selected stick. If the prompt keeps asking for a key, click the CoCo display and tap A again. Restore your previous port assignment when you finish.

Give the pilot an arrival sound

The flight in VOYAGE.bas plays three notes after the landing key and before filing the log.

140 PLAY "T180O3L8CEG"
150 GOSUB 200
160 PRINT "LOG SAVED FOR ";P$(D)

Read the short score inside the quotes. T sets the tempo to 180; O picks octave 3; L8 makes the following notes eighth notes. C, E and G are the three pitches in order. PLAY follows the score just as BASIC follows a sequence of program lines. SOUND, another command in the reference, takes a pitch number and a duration for a single tone.

During the final flight, listen when you press the landing key. The words LOG SAVED FOR MARS or LOG SAVED FOR EARTH also mark the arrival. If the Mac is muted, those words remain your check that the ship landed and its log was closed.

Original VCC Plus manuals © 2026 Brian K. Holman. Third-party references retain their authors’ copyrights and licenses. Artwork notices. Edition 3.7.1; source and export identity. Printable edition: PDF source and export identity.

A closer look

Open original