Classic Computer Magazine Archive ANTIC VOL. 2, NO. 12 / MARCH 1984

LOGO/PILOT

MERGING TRAFFIC

PILOT does it on the run

by PHIL and KATHY BERGH

MERGING IN RUN MODE?
SURE!

This month's PILOT article again features Phil and Kathy Bergh and an innovative program that merges PILOT programs under program control. You can use this technique to "overlay" code and thus fit large programs into small memory spaces by LOADing only the sections of the programs needed at one time. Then, when a new section is needed, you LOAD it "over" some unneeded lines.

Our PILOT/Logo columns aim to present useful procedures using features of the languages not covered in the manuals. We invite you to send ideas for articles you'd like to see, or complete articles, to me in care of this column. Just cover something new and useful.

Next month I will use Logo to make Iarge letters (BASIC's Mode 3 and 2), and show you two safe places to put machine-language code. -Ken Harms

THE CHALLENGE: produce a usefuI PILOT program that teaches a technique or procedure not covered in depth elsewhere. To meet this challenge, we present a set of diskette-based, math-drill progams that show how to merge a new subprogram from diskette under program control without erasing the current program. We also will list the code changes necessary to use the program from cassette.

THE APPLICATION: a math-drill game with menu selection of math operation. We know that the slash mark, which Atari uses for its division computations, is not understood by younger students, so we drew upon the character set redefinition program presented in ANTIC, 1983, to create a custom division character. We will not review the technique here. The routine that prints the traditional division sign can easily be used in math programs of your own.

MATHMERG

The main program file is titled MATHMERG. It provides the title page, custom character set, menu, screen format, and correction routines. The other four files (subprograms) contain the problems and answers that will be merged with the main program.

The menu offers choices of addition, subtraction, multiplication, and division. When a choice is made, the name of the file holding the subprogram to be merged is written to the screen, the cursor is positioned above the LOAD statement, the computer is ordered to read the screen, and the program is E:nded. The computer is now in immediate mode and executes the LOAD command as if it were just entered from the keyboard. Because the program is not running, it avoids the automatic NEW that PILOT supplies to erase the current program before loading another file. ANTIC covered this automatic keyboard feature more fully in the Deleter program (ANTIC, "Lines Away" p. 24, July 1983).

MERGING FILES

Each of the subprograms we will merge are carefully numbered to position the T:ype statements from the small merge files to come after the POS:ition statements in the main program. Similarly, the answers come before the M:atch statements. Changing any line numbers could crash the programs. Notice that the main program has many lines that can be entered by renumbering previous lines and making small changes (such as the problem number). After you enter and save the first merge file, simply change the signs and numbers and save it again with the new name.

You can easily create your own merge files with problems suited to your needs. Change them as often as you wish without the difficulties caused by going into a large program and finding all of the lines that need modification.

A LOOK AT THE LISTING

Let's look through the listlng to see how it works. The code from line 275 through 320 causes the title page to be written in large letters. For a more detailed look at how this works, see "Large Text" in The Best of ANTIC, Vol. 1. Remember that when you write to the screen, you must use a CLOSE:S to let the computer know you are finished. See line 440 for an example.

The lines indented with commas are part of a custom character set routine. They create a traditional division sign to replace the slash. This allows us to format division problems with one number above the other on the drill screens.

Lines 445 through 535 write the menu in large letters on a black screen and type the instructions in the text window. The routine starting at line 540 detects if the [SELECT] or [START] button has been pressed. Always C:ompute a value of eight into byte 53279 to clear it before checking to see if a console button has been pressed. This prevents re-reading a previous press. If [OPTION] is pressed, there will be a three at byte 53279. [SELECT] is a five and [START] is a six. Line 550 J:umps to *STARTPRESSED only if there is a six in byte 53279. Line 555 checks for a five. If neither [SELECT] nor [START] were pressed, we J:ump back to "CONSOLEBUTTONS to check again.

Lines 570 to 610 move the menu arrow to the next choice. The line that the arrow is on is called #L. It is incremented by two each time [SELECT] is pressed. If it is greater than seven, it is set to one again. After the arrow moves, we J:ump back to check the console buttons.

Lines 625 through 640 identify the file to be loaded according to the position of the pointer on the menu screen.

MERGING FILES

Now the fancy stuff -- we merge the chosen file! We also learn something about Atari DOS and PILOT's load routines. Line 660 clears the graphics screen and prepares for normal text. We then skip down two lines on the screen and T:ype a "please wait" message. We then T:ype four blank lines. Line 690 T:ypes a LOAD command on the screen and we T:ype down two more lines. Line 696 T:ypes a J:ump command on the screen so the program will restart. Note that the J:ump command is followed by seven "up-arrows." To include an up-arrow in your program, press [ESC] and release, then press and hold [CTRL] while you push the up-arrow. You will do this seven times. When the program is run, the up- arrows will position the cursor three rows above the load command.

Line 700 forces the computer to read from the screen by C:omputing a 13 into byte 842. When the program is E:nded (line 705), the READY prompt appears. The cursor drops to the line with our LOAD command, and that line is acted upon as if it were just typed by hand on the screen.

"But how," you may ask, "does the program get running again!" Good question. The trick answer is simple. After PILOT LOADs the file Typed by line 690, it prints a READY prompt, skips a line and positions the cursor on the line just below. And guess what? When it hits that line, it finds the command J:*TAG2 already printed there. Since the Atari is still in auto-keyboard mode, it reads the J:ump command, PILOT takes over and does the J:ump.

Why are we J:umping to *TAG2 in the merge programs? Because *TAG2 is part of our main program after we forced the LOAD. At line 780 we finish the procedure by C:omputing a 12 into byte 842. This tells the computer to stop reading from the screen.

Lines 800 through 1010 POS:ition the math problems on the screen. Lines 1640 through 2470 present and correct the problems. Remember that you can enter much of this code by changing line numbers, problem numbers, and positions. Do not forget the space in and underline after the M:atch commands, or the program will accept incorrect answers.

Finally, *CORRECT at line 2570 uses the random number generator to play a series of notes and flash the screen colors if the user gets a problem correct. *ERROR gives a two-note response to incorrect answers, and the problem is repeated.

CASSETTE VERSION

The custom character and drill screen in Math practice can be easily used from cassette by LOADing MATHMERG from tape and then LOADing whatever problem file you wish. Many different problem sets can be accessed on different tapes. You are not limited to one file for each type of problem, as disk users are, because tape files are not called by name by the program. Two disk files of the same name are, of course, not allowed.

Cassette users should replace two lines in the listing with the following:

675 T:Please insert the $PROGRAMNAME tape and press play
690 T:LOAD C:[seven up-arrows]

If you do not want the LOAD commands that appear in the text window to be visible, then add:

676 C:@B709=5
781 C:@B709=10

Line 676 changes the luminance of the text to match the background, thus rendering it invisible. The second value restores the color values.

The youngsters who tested this program found it "more fun than flash cards." The adults found other ways to utilize some of these ideas. We hope you, too, will find it instructive and enjoyable.

MATH.PLT Download / View

ADD.PLT Download / View

SUBTRACT.PLT Download / View

MULTIPLY.PLT Download / View

DIVIDE.PLT Download / View