' Morse Code Translator/Player ' Written by Vince Long ' May 2005 ' Set Up The Program CLS DIM Text$(100), Morse$(100), CodeStream$(1000) ON ERROR GOTO TrapErrors ' Initialize the File OPEN "c:\morse\morse.txt" FOR OUTPUT AS #1 PRINT #1, "0" CLOSE #1 LOCATE 5, 22 PRINT "Morse Code Sounder Player Program" ' Set the Values for the Dots and Dashes DotDelay = .1 DashDelay = DotDelay * 3 LetterSpace = DashDelay WordDelay = DotDelay * 7 GOSUB BuildArrays ' Main Program Starts Here DO ReStart: ' Check Keyboard for input I$ = INKEY$ ' The pause here just reduces the the conflicts ' between clashes between this program and the PERL ' program as the vie for use of the file t = TIMER DO LOCATE 10, 1 PRINT "Currently in Pause Mode "; INT(t + 4 - TIMER) LOOP WHILE TIMER < t + 3 LOCATE 10, 1 PRINT "Reading the file " ' Read data from the file OPEN "c:\morse\morse.txt" FOR INPUT AS #1 INPUT #1, A$ CLOSE #1 ' If the file is empty, just go back to ' the beginning of the program IF A$ = "0" THEN GOTO ReStart ' If the file had data, put a zero in ' its place OPEN "c:\morse\morse.txt" FOR OUTPUT AS #1 PRINT #1, "0" CLOSE #1 ' Search the incoming data and build the output ' by matching each letter in the data to its ' Morse Code FOR I = 1 TO LEN(A$) FOR J = 1 TO 44 IF UCASE$(MID$(A$, I, 1)) = UCASE$(Text$(J)) THEN CodeStream$(I) = Morse$(J) NEXT J NEXT I ' Output the CodeStream FOR I = 1 TO LEN(A$) LOCATE 5, 1 PRINT "Sending this to sounder-> "; CodeStream$(I) FOR J = 1 TO LEN(CodeStream$(I)) IF MID$(CodeStream$(I), J, 1) = "." THEN GOSUB PlayDot IF MID$(CodeStream$(I), J, 1) = "-" THEN GOSUB PlayDash IF MID$(CodeStream$(I), J, 1) = " " THEN GOSUB WordSpace NEXT J t = TIMER DO LOOP WHILE TIMER < t + LetterSpace NEXT I ' Check keyboard for Escape Key ' If Escape Key, End the program LOOP WHILE I$ <> CHR$(27) END PlayDot: OUT 888, 255 t = TIMER DO LOOP WHILE TIMER < t + DotDelay OUT 888, 0 t = TIMER DO LOOP WHILE TIMER < t + DotDelay RETURN PlayDash: OUT 888, 255 t = TIMER DO LOOP WHILE TIMER < t + DashDelay OUT 888, 0 t = TIMER DO LOOP WHILE TIMER < t + DotDelay RETURN WordSpace: t = TIMER DO LOOP WHILE TIMER < t + WordDelay RETURN TrapErrors: Errors = Errors + 1 LOCATE 20, 1 PRINT "Error Count: "; Errors RESUME BuildArrays: Text$(1) = "A": Morse$(1) = ".-" Text$(2) = "B": Morse$(2) = "-..." Text$(3) = "C": Morse$(3) = "-.-." Text$(4) = "D": Morse$(4) = "-.." Text$(5) = "E": Morse$(5) = "." Text$(6) = "F": Morse$(6) = "..-." Text$(7) = "G": Morse$(7) = "--." Text$(8) = "H": Morse$(8) = "...." Text$(9) = "I": Morse$(9) = ".." Text$(10) = "J": Morse$(10) = ".---" Text$(11) = "K": Morse$(11) = "-.-" Text$(12) = "L": Morse$(12) = ".-.." Text$(13) = "M": Morse$(13) = "--" Text$(14) = "N": Morse$(14) = "-." Text$(15) = "O": Morse$(15) = "---" Text$(16) = "P": Morse$(16) = ".--." Text$(17) = "Q": Morse$(17) = "--.-" Text$(18) = "R": Morse$(18) = ".-." Text$(19) = "S": Morse$(19) = "..." Text$(20) = "T": Morse$(20) = "-" Text$(21) = "U": Morse$(21) = "..-" Text$(22) = "V": Morse$(22) = "...-" Text$(23) = "W": Morse$(23) = ".--" Text$(24) = "X": Morse$(24) = "-..-" Text$(25) = "Y": Morse$(25) = "-.--" Text$(26) = "Z": Morse$(26) = "--.." Text$(27) = "1": Morse$(27) = ".----" Text$(28) = "2": Morse$(28) = "..---" Text$(29) = "3": Morse$(29) = "...--" Text$(30) = "4": Morse$(30) = "....-" Text$(31) = "5": Morse$(31) = "....." Text$(32) = "6": Morse$(32) = "-...." Text$(33) = "7": Morse$(33) = "--..." Text$(34) = "8": Morse$(34) = "---.." Text$(35) = "9": Morse$(35) = "----." Text$(36) = "0": Morse$(36) = "-----" Text$(37) = ",": Morse$(37) = "--..--" Text$(38) = ".": Morse$(38) = ".-.-.-" RETURN