Morse Trainer

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Ham Radio

A Morse code trainer. You set the pitch and speed (it suggests 9 and 20), then type a letter or word. Each letter’s dots and dashes are printed and sounded with BEEP, a dash lasting three times as long as a dot. ENTER repeats the last word, X changes pitch and speed, and * stops. T starts a test: the program plays a random letter and you have three tries to name it before it tells you the answer and plays it again.

No author is named.

Program Analysis

Structure

  • Lines 20–150: title, pitch and speed, and the command prompt.
  • Lines 160–280: play each letter of the input. The code is found by READing CODE i$(b)-64 items from DATA line 290 and then RESTORE.
  • Lines 300–340: sound one code. Each entry in the DATA is the letter followed by its code, so the subroutine plays characters 2 to 6 of m$.
  • Lines 350–510: the test mode.

Notable Techniques

  • The fixed-length string DIM m$(7) pads every code with spaces, so the sound loop can always run from character 2 to 6.
  • Dash and dot lengths are worked out once from the speed: H=S/100 and T=S/300.
  • POKE 23692,2 keeps the scroll prompt from appearing as codes print down the screen.

Potential Issues

  • Only A to Z are coded. For a digit or other symbol the READ loop does not run, so the previous letter’s code is played again. Line 190 blanks the code for “0” only.
  • A space sends the program back to the command prompt (line 200), so only the first word of a phrase is played.
  • The test accepts only capital letters, which caps lock (line 90) supplies.

This program came from an Oliger (JLO SAFE) disk, a copy of the SNUG library disk 13/14, and was converted to load from tape. The SAVE / in line 520 became a plain SAVE. It was tested in ZEsarUX, playing SOS and running the letter test.

Image Gallery

Source Code

   10 REM morse trainer
   20 PAPER 1: BORDER 1: INK 7: CLS : PRINT TAB 7;"MORSE TRAINER": PAUSE 200: CLS 
   30 POKE 23609,20
   40 DIM m$(7)
   50 DIM i$(250)
   60 PRINT "TRY 9 & 20 FOR PITCH & SPEED"
   70 INPUT "PITCH",P,"SPEED",s
   80 LET H=S/100: LET T=S/300
   90 POKE 23658,8
  100 INPUT "X=alter speed/pitch (e.g. 9&20) T=TEST","N=New phrase"'"   ENTER=repeat"; LINE A$
  110 IF A$="" THEN GO TO 160
  120 IF A$="X" THEN GO TO 70
  130 IF A$="T" THEN GO TO 350
  140 IF A$="*" THEN STOP 
  150 INPUT "ENTER Letter or Word"'"(""*"" TO STOP )", LINE i$
  160 POKE 23692,2
  170 PRINT AT 21,0,,
  180 FOR b=1 TO LEN i$
  190 IF i$(b)="0" THEN LET m$="       "
  200 IF i$(b)=" " THEN GO TO 90
  210 FOR r=1 TO (CODE i$(b)-64)
  220 READ m$: NEXT r
  230 RESTORE 
  240 PRINT m$( TO )
  250 POKE 23692,2
  260 GO SUB 300
  270 NEXT b
  280 GO TO 90
  290 DATA "A.-","B-...","C-.-.","D-..","E.","F..-.","G--.","H....","I..","J.---","K-.-","L.-..","M--","N-.","O---","P.--.","Q--.-","R.-.","S...","T-","U..-","V...-","W.--","X-..-","Y-.--","Z--.."
  300 FOR N=2 TO 6
  310 IF m$(n)="-" THEN BEEP H,P
  320 IF m$(n)="." THEN BEEP T,P
  330 NEXT N
  340 RETURN 
  350 CLS : PRINT "I WILL GIVE YOU A MORSE LETTER  AND I WANT YOU TO TELL ME WHAT  IT IS IN 3 ATTEMPTS"'" PRESS ENTER to escape ": PAUSE 100
  360 LET c=0
  370 FOR r=1 TO ((RND*26)+1)
  380 READ m$
  390 NEXT r
  400 RESTORE 
  410 GO SUB 300
  420 INPUT "WHAT WAS IT? "; LINE N$
  430 IF N$="" THEN CLS : GO TO 90
  440 IF CODE N$>90 OR CODE N$<65 THEN GO TO 420
  450 IF N$=m$(1) THEN PRINT : PRINT : PRINT "Correct; it was ";m$
  460 IF N$=m$(1) THEN PAUSE 50: GO SUB 300: PAUSE 200: GO TO 350
  470 PRINT ''"WRONG!, it was not ";N$;: PAUSE 75
  480 LET c=c+1
  490 IF c=3 THEN PRINT " It was";m$: PAUSE 50: GO SUB 300: PAUSE 120: GO TO 350
  500 PRINT " TRY AGAIN": PAUSE 50
  510 GO TO 410
  520 SAVE "MORSE" LINE 10

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.