← 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 5 of 12

Give a chart its names

What could go wrong if the computer drew Earth at the right place but printed “Mars” underneath? A chart needs more than a bag of names and numbers. It needs a way to keep the pieces of each planet together.

Make two cards for your chart

Open CHART.bas. Begin at the bottom of the listing, where its cartographer left this row of data.

150 DATA EARTH,64,80,MARS,176,100

Read three items at a time: a name, a distance across the picture, and a distance down. Make two little cards on paper.

Card number Planet name X, across Y, down
1 EARTH 64 80
2 MARS 176 100

Which planet will appear farther to the right? Which will appear lower? In this graphics mode X grows as you move right, and Y grows as you move down. Mars has the larger number in both columns.

Deal the cards into RAM

20 DIM P$(2),X(2),Y(2)
30 FOR I=1 TO 2:READ P$(I),X(I),Y(I):NEXT I

DIM makes room for values you can look up by number. Each group is an array. P$(1) means the name for card 1, while P$(2) means the name for card 2. X(2) and Y(2) belong to that second card, too. You can think of the number in parentheses as a drawer label. BASIC calls it a subscript. A dimension of 2 makes positions 0, 1 and 2 available. This program uses positions 1 and 2 to match the numbers on the menu.

On line 30, READ asks for the next three items in DATA order. On the first pass through the loop, I is 1; on the second pass I is 2. READ remembers how far it got through the DATA list. So X(2) receives 176, even though the DATA line is more than a hundred line numbers away. BASIC only needs the list and a place to put each item.

Earth’s name is a string, so the dollar sign belongs on the name array. The X and Y arrays hold numbers. That lets the drawing code do arithmetic with the coordinates. For example, line 75 divides a pixel coordinate by eight and uses INT to find a whole text-cell position for a label.

Check the real chart against your cards

Select RGB under Video Signal for the colors used in this book. Choose the editor’s Run. Find the labels. Compare their positions with the paper cards. Press A on the CoCo keyboard. Now the text screen tells you the two marker values that the program read back from the picture.

At OK, enter PRINT P$(2);X(2);Y(2). You should get MARS 176 100. You just asked BASIC for all three entries belonging to one card, after the drawing vanished. Try PRINT LEN(P$(1));LEFT$(P$(2),1) and predict both results. Earth has five letters, and Mars begins with M, so the CoCo prints 5 M.

What if the next crew wants to read the original DATA items again? Type these three commands at the prompt, one per Return.

RESTORE
READ N$,E,V
PRINT N$;E;V

This time the result is EARTH 64 80. RESTORE moved the DATA reader back to the beginning. The new READ put the first three items into three new variables. The older arrays still have their own values. When you want to draw with those coordinates yourself, open Draw a planet you can find again.

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