Classic Computer Magazine Archive ANTIC VOL. 7, NO. 8 / DECEMBER 1988

Type-In Software

Runner-up Prize Best Program


Atari raises the flag

by Howie Wishart

Can't find anybody to send you semaphore flag mesages for reading practice? Your Atari can be an expert signalman instructor. This BASIC program works on all 8-bit Atari computers of any memory size, with disk or cassette.

Although Morse Code training programs are fairly common, I have never seen a program for practicing semaphore flag code. As a former signalman in the Canadian Navy, I taught semaphore communications aboard ship and in classrooms. And when I bought my original Atari 800XL in 1985, a primitive version of this program was my first serious attempt at programming.


Semaphore is a means of line-of-sight communication dating from the early 1800s. It's easy to learn. No special equipment is required. But operators usually hold small flags when sending during daytime, while flashlight wands are used at night. Semaphore is still a common system of short-range communications today. It is also of interest to cadet organizations, scouts and others.

The basic technique of semaphore is to hold each arm at one of eight possible angles--straight up, straight down, left, right, or one of the diagonals. The various arm position combinations represent the 26 letters of the English alphabet.

Note that what you send is the reverse of what you see. The man in the picture sends the letter B with his right hand, and you would send a B with your right hand. Swing your arms from letter to letter to spell words. Hold both arms down and crossed in front of you to signal the space between words. Rhythm and accurate angles are important.

The code for Error is EEEEEEEE--then send the misspelled word again.

To get the other operator's attention, flap your arms up and down, like a bird. He'll wave back when he's ready to read. After reading your message, he'll hold his arms out horizontally to show the letter R (for Roger). Or he'll send you a question mark if he missed it. That's all there is to semaphore code. After you learn the letters, it's easy--and fun.

Sending speed is measured in words per minute (wpm)--15 wpm is the minimum standard in the NATO navies. But good operators can send and receive at over 30 wpm. To qualify at a given speed, you must be able to read three tests in a row with two errors or less.

Numbers are spelled out. Punctuation symbols are sent using the same combinations of letters as Morse Code. See below:

Period AAA
Comma MIM
Question mark IMI
Hyphen DU
Slant or fraction bar     XE
Colon OS
Left parenthesis KN
Right parenthesis KK
End of message AR

                     Type a letter and see it transmitted with the semaphore flags.


Type in Listing 1, SEMAFOR.BAS, check it with TYPO II and SAVE a copy before you RUN it.

Semaphore has three teaching features: (I.) You can type a letter on the keyboard and see the flag code displayed; (2.) Beginners can test on random five-letter groups; (3.) Experienced readers can test on messages taken from memory at random.

In each case, the transmitted letter is displayed onscreen in large Graphics 2 text. You can choose test speeds from 10 to 30 words per minute. After a test, you can get a printout to find out how well you did.

The program works by making the computer think that PM$ is in PlayerMissile memory instead of in the variable value table. Thus, changing the contents of PM$ causes immediate changes in the player shapes onscreen. You get a simple form of animation even though the players don't actually move.

Player 3 contains the image of a man, and players 0 (to his right), 2 (to his left) and 1 (in front of him) constantly constantly changing data to display his arms in the various positions of the semaphore alphabet. This same technique, using all five players lined up across the screen, could be used to teach the sign language alphabet for hearing-impaired.

Because timing is so important, I have avoided using FOR/NEXT loops as much as possible, PEEKing and POKEing RTCLOK (memory location 20, $14) to control the length of time that each character is displayed. This means that the program runs at the same speed in Atari BASIC as it does in BASIC XL's fast mode, without recalculating the speed logic.


Lines 50-61 load the appropriate part of PM$ with a particular flag shape. Lines 32 65-90 call lines 50-61 as needed to build alphabet letters, each of which needs two flags. Line 95 produces a raspberry noise in case of bad user input. The term X = 1^1^1^1 provides a suitable delay without a FOR/NEXT loop.

The routine at 1000-1110 sends tests. RTCLOK is POKEd with the delay value D, the character is constructed and sent, while the letter is PRINTed either visibly or invisibly at the lower left of the screen. The subroutine at title 1100 monitors RTCLOK until the necessary delay has passed, then RETURNS to erase the flags (but not the little man) and send another character. Line 1010 prevents flicker in case of two consecutive spaces. Line 1030 sends a half-length space between double letters in a word. Line 1080 walks the little man offscreen at the end of the test.

The routine at 2000-2110 reads the keyboard and displays the letter that was typed. Anything outside the range A-Z is treated as a space. As with the test routine, each character is also Printed at the lower left corner, either visibly or invisibly. Pressing [ESCAPE] returns you to the menus.

The menus at 3000 and 3500 let you select your option, set up variables for visible or invisible text by POKEing COLOR 0 (memory location 708, $02C4) with either 12 or 0, and calculate a D value to be Poked into RTCLOK to control the speed. Prerecorded tests are READ into T$ here. Five-letter random tests are generated at lines 4000-4010. The character string NRURNRURNRUR creates the arm-flapping callable routine at the beginning of a message.

After either a random-letter test or a preset message test is completed, the program proceeds to the Print Menu at lines 3800-3920. A channel is opened to either the printer or the screen, as chosen by the user. T$ is printed without wordwrap and with punctuation displayed as letter combinations. If a screen display was selected, the program waits for a keypress. Otherwise execution resumes with the main menu at line 3000.

Lines 5000-5080 perform the overlay of P/M memory onto T$, the variable holding the message to be sent. These lines set up P/M graphics (double-line resolution, all players double-width) and generates a sequence of the little man walking onscreen from the left with flags at his sides, ready to send. I used Graphics 18 to allow for the largest possible text display and to display visible instructions even if the transmitted characters are invisible.

Lines 6000-6240 initialize and fill the necessary strings. PM$ must be the first string named and used in order for the program to work properly. P$ and T$ are used variously to manipulate the text message. K$ is a series of blanks used to quickly wipe out part of PM$ and so erase players 0-2 (while leaving the little man untouched in Player 3) between letters.

'The preset tests commence at line 7000, with tests starting 10 program lines apart. The program READs C to determine how many data strings follow. Then it reads each string and adds it onto T$. Adjust the RESTORE statement in line 3550 if you want to renumber this section. There are currently 10 tests. If you add more, change the * 10 in line 3550 to reflect the actual number of tests in memory.

Semaphore requires 16K to run, with the 10 existing message texts taking up about 2K. So there is plenty of room for adding many more messages to ensure variety.

Thirty-two year-old Canadian retired naval signalman Howie Wishart has been programming for three years. This is his first publication inAntic.

Listing1:SEMAFOR.BAS Download