home *** CD-ROM | disk | FTP | other *** search
-
- // MORSE.SCR -- Play command line text in Morse Code -- Version 1.00
- //
- // Script program for MUL - the Maximus User Language
- // MUL is (C) Copyright 1990-93 by CodeLand Australia
- //
- // Based on code written by Michael M. Dodd, N4CF, and placed in the public
- // domain. Modified for ZTC++, TC++, & BC++ by Bob Stout.
- //
- // USAGE: MUL -pMorse "String to play"
-
- char *banner = "MORSE v1.00"; // Script banner
- char *desc = "Play Text in Morse Code"; // Description
- int note = 1500; // Note to play
- int dely = 54; // Timing delay
- char line[128]; // Line to play
- int SPACE_MASK = 0x8000; // Bit mask
- int BIT_MASK = 0xFE; // Bit mask
-
- int codes[64] = { // Morse codes
- 0x8000, // Entry 0 = space (0x20)
- 0, 0, 0, 0, 0, 0, 0, 0, // ! " # $ % & " (
- 0, 0, 0, 115, 49, 106, 41, // ) * + , - . /
- 63, 62, 60, 56, 48, 32, 33, 35, // 0 1 2 3 4 5 6 7
- 39, 47, 0, 0, 0, 0, 0, 76, // 8 9 : ; < = > ?
- 0, 6, 17, 21, 9, 2, 20, 11, // @ A B C D E F G
- 16, 4, 30, 13, 18, 7, 5, 15, // H I J K L M N O
- 22, 27, 10, 8, 3, 12, 24, 14, // P Q R S T U V W
- 25, 29, 19 // X Y Z
- };
-
- // Main program
- main (int argc, char *a1, char *a2, char *a3, char *a4, char *a5, char *a6)
- {
- printf ("\n%s - %s\n\n",banner,desc); // Announce
- getcmd (argc,a1,a2,a3,a4,a5,a6); // Get the command line
-
- printf ("Playing text: ");
- morse (line); // Play the text
-
- saybibi (); // Was it good for you too?
- }
-
- // The Morse code pattern is taken from bit 0, and is shifted right each
- // time an element is sent. A special "marker bit" follows the complete
- // Morse pattern. This marker bit is tested before transmitting each bit;
- // if there are no 1's in bits 1..15, the complete character has been sent.
- // For example, an "L" would be 0000000000010010, with bit zero containing
- // the first dot, bit one the dash, etc. The marker bit is in bit 4.
-
- // Morse code function
- morse (char *cp)
- {
- int ch, c;
-
- while ((c=ch=*cp++)!=0) { // Transmit complete string
-
- ch=toupper (ch); // No lower-case characters
- ch=ch-' '; // Adjust for zero-based table
- if (ch>=0&&ch<=58) { // If out of range, ignore it
- ch=codes[ch]; // Look up Morse pattern from table
- if (And (ch,SPACE_MASK)) { // If the space bit is set
- putch (' '); // Echo the character to screen
- word_space ();
- }
- else {
- putch (c); // Echo the character to screen
- while (And (ch,BIT_MASK)) { // Transmit one character
- if (And (ch,1))
- send_dash (); // Sound a dash
- else
- send_dot (); // Sound a dot
- ch=ShiftRight (ch,1); // Bitwise shift right
- }
- ltr_space (); // Send a space following character
- }
- }
- }
- putch ('\n'); // Terminate screen line
- }
-
- // Send a dot and a space
- send_dot ()
- {
- Play (note,dely); // Play the note
- Play (0,dely); // Pause
- }
-
- // Send a dash and a space
- send_dash ()
- {
- Play (note,3*dely); // Play the note
- Play (0,dely); // Pause
- }
-
- // Produce a letter space
- ltr_space ()
- {
- Play (0,2*dely); // Pause * 2
- }
-
- // Produce a word space
- word_space ()
- {
- Play (0,4*dely); // Pause * 4
- }
-
- // Get the command line
- getcmd (int count, char *a1, char *a2, char *a3, char *a4, char *a5, char *a6)
- {
- // Load command line text to play
-
- if (count) {
- strcpy (line,a1);
- if(--count>0) { strcat (line," "); strcat (line,a2); }
- if(--count>0) { strcat (line," "); strcat (line,a3); }
- if(--count>0) { strcat (line," "); strcat (line,a4); }
- if(--count>0) { strcat (line," "); strcat (line,a5); }
- if(--count>0) { strcat (line," "); strcat (line,a6); }
- }
-
- // If nothing entered on command line use default
- if(!line[0]) strcpy (line,"Enter text on command line");
- }
-
- // Byebye
- saybibi ()
- {
- puts ("\nMorse done!\n");
- }
-
- // End of script
-
-