43 lines
2.2 KiB
Plaintext
43 lines
2.2 KiB
Plaintext
code ChOut=8, CrLf=9, Sound=39;
|
|
string 0; \use zero-terminated strings
|
|
|
|
proc Morse(Msg); \Output Msg string as audible International Morse code
|
|
char Msg;
|
|
char C, D;
|
|
int Code, Vol;
|
|
[Code:= [" ", \space
|
|
".-.-..",".-..-.", " ", "...-..-"," ", \!"#$%
|
|
"----.", ".----.", "-.--.-", "---..", " ", \&'()*
|
|
".-.-.", "--..--", "-....-", ".-.-.-", "-..-.", \+,-./
|
|
"-----", ".----", "..---", "...--", "....-", \01234
|
|
".....", "-....", "--...", "---..", "----.", \56789
|
|
"---...","-.-.-.", " ", "-...-", " ", \:;<=>
|
|
"..--..",".--.-.", \?@
|
|
".-", "-...", "-.-.", "-..", ".", \ABCDE
|
|
"..-.", "--.", "....", "..", ".---", \FGHIJ
|
|
"-.-", ".-..", "--", "-.", "---", \KLMNO
|
|
".--.", "--.-", ".-.", "...", "-", \PQRST
|
|
"..-", "...-", ".--", "-..-", "-.--", \UVWXY
|
|
"--.."]; \Z
|
|
Sound(0, 1, 1); \sync, for consistent durations
|
|
repeat C:= Msg(0); Msg:= Msg+1; \get character from message
|
|
ChOut(0, C); \show the character
|
|
if C>=^a & C<=^z then C:= C-$20; \convert letters to uppercase
|
|
Vol:= 1; \assume volume is on (not space)
|
|
if C>=$21 & C<=^Z then D:= Code(C-$20) \convert characters to code
|
|
else [D:= Code(0); Vol:= 0]; \space (or unsupported char)
|
|
repeat Sound(Vol, if D(0)=^- then 3 else 1, 1190000/600); \600 Hz
|
|
Sound(0, 1, 1); \gap between . and -
|
|
ChOut(0, D(0)); \show dots and dashes
|
|
D:= D+1; \next dot or dash for character
|
|
until D(0) = 0; \string terminator
|
|
Sound(0, 2, 1); \gap between letters (2+1=3)
|
|
ChOut(0, ^ ); \show gap
|
|
until Msg(0) = 0; \string terminator
|
|
];
|
|
|
|
[Morse("SOS SOS SOS "); \something easy to recognize
|
|
CrLf(0);
|
|
Morse("Hello, world!");
|
|
]
|