TXTdida.bas

This is basically the same program as DiDah.bas with the exception of the source text. The source here is a text file instead of the keyboard.
Each section is talked about in turn. Only a few lines of code in this program are necessary to run the program.
Most of the coding is for the sake of documentation and easily edited structuring. 
The sub routines can be easily copied to another application without losing their ability to perform.



    Authors remarks
10 '           prog    txtdida.bas
20 '
30 '
40 '
50 '
60 '
70 '
80 '
90 '


   Index to the modules. The LIST instructions become updated with a RENUMBER statement as do all the other vectors.
   A GOTO the line number that contains the module will list out that module only. Very handy for editing.
100 GOTO 400 '  vector to program start
110 '
120 '            index of modules
130 LIST 260-340   ' Data Statements
140 LIST 400-530   ' initalization
150 LIST 550-610   ' program banner
160 LIST 650-700   ' File name parser
170 LIST 750-790   ' sound off and display the text
180 LIST 850       ' ------- sub routines --------
190 LIST 1050-1120 ' input from disk    ( entire file)
200 LIST 1200-1260 ' output to speaker    ( 1 line)
210 LIST 1300-1470 ' sound the character in n$
220 '
230 '
240 '


  The data statements are ascii dots and dashes for the printable Morse Code characters. The element of interest can be extracted
  from an ascii array by calculating the number in the array from the ascii decinal equivelant of each character to be printed.
250 '     numbers
260 DATA "-----", ".----", "..---", "...--", "....-"
270 DATA ".....", "-....", "--...", "---..", "----."
280 '
290 '     alphas
300 DATA ".-"   , "-..." , "-.-." , "-.."  , "."    , "..-."
310 DATA "--.." , "...." , ".."   , ".---" , "-.-"  , ".-.."
320 DATA "--"   , "-."   , "---"  , ".--." , "--.-" , ".-."
330 DATA "..."  , "-"    , "..-"  , "...-" , ".--"  , "-..-"
340 DATA "-.--" , "--.."
350 '
360 '
370 '
380 '
390 '

  The program begins execution here. Initial variables and arrays are defined.
400 '    Initalization (program start)
410 '
420 KEY OFF: CLS
430 ON KEY(1) GOSUB 870: KEY (1) ON
440 ON KEY(2) GOSUB 880: KEY (2) ON
450 F= 523.25           ' frequency and duration
460 DASH=  4            ' dash duration
470 DOT=   DASH/4       ' dot  duration
480 NUL=   DASH/8       ' null twix beeps
490 ICG=   DASH * .75   ' inter character gap
500 IWG=   DASH * 1.5   ' inter word gap (space)
510 '


  DIG$ contains numers. ALF$ are the code for the alpha characters.
520 DIM DIG$(10): RESTORE 260: FOR N= 1 TO 10: READ DIG$(N): NEXT
530 DIM ALF$(26): RESTORE 300: FOR N= 1 TO 26: READ ALF$(N): NEXT
540 '

  Posted only once on program start. The program spins on the INKEY$ instruction until any key is closed.
550 '           Banner
560 PRINT "This program displays the files in the current directory"
570 PRINT "Enter the file name of the text file to hear in the prompt box"
580 PRINT "Function key 1 (Return) clears the monitor screen"
590 PRINT "Function key 2 (Return) terminates"
600 PRINT "........type any key to continue......"
610 N$= INKEY$: IF LEN(N$)=0 THEN 610
620 '
630 '
640 '

  Re-entry point to select the next file to be sounded and printed.
650 '         Select text file
660 CLS
670 LOCATE 5,1: FILES
680 LOCATE 1,1: PRINT SPACE$(60): LOCATE 1,1
690 INPUT "Enter file name ",FILE$
700 CLS
710 '

  Establish the vector for a program error. The program will jump to the value in the  ON ERRIR GOTO argument
  if the OPEN FILE$ instruction cannot open the selected file that is named in the FILE$ variable.

720 ON ERROR GOTO 950
730 OPEN FILE$ FOR INPUT AS #1
740 '

  The next two GOSUB statements sound and print the entire file and loops back to the re-entry point for another file.
750 '      Sound off and display the text
760 GOSUB 1050    ' read the file
770 GOSUB 1200   ' ouput to speaker
780 GOTO 650
790 END
800 '
810 '
820 '
830 '
840 '
850 ' __________________sub routines_______________
860 '

  During program execution, Function Key one clears the screen and and two terminates the program.
870 CLS:RETURN        ' Key (1) sub routine
880 CLS: END          ' Key (2) sub routine
890 '
900 '
910 '
920 '
930 '
940 '

  The error handler will be the result of an unsessful attempt to open the selected file for input. A message is posted and
  the program returns to the location where another invitation to select the file name is coded.

950 '          error interupt handler
960 LOCATE 2,1
970    PRINT "it seems that the file you selected isn't in this folder"
980    PRINT " file " FILE$ " not found"
990    RESUME 670
1000 '
1010 '
1020 '
1030 '
1040 '

  The input file has already been selected, tested and opened at this point. The program loops, opening each line in the file,
  sequentially and services the characters in the line in the output sub routine until the EOF (end of file) is reached. Then
  the input file is closed and the program RETURNs to the main program for the next selected file.
1050 ' input from disk
1060     LINE INPUT#1, C$
1070   IF EOF(1) THEN 1110
1080       GOSUB 1200
1090        PRINT
1100         GOTO 1060
1110    CLOSE #1
1120     RETURN
1130 '
1140 '
1150 '
1160 '
1170 '
1180 '
1190 '

  Each character within line of text in the C$ variable is MID$ed into N$ and GOSUBed to the output sub routine.
  Then the program returns to the main program with the RETURN statement.

1200 '             output C$ to speaker (one line)
1210  FOR N= 1 TO LEN(C$)
1220   N$= MID$(C$,N,1)
1230    GOSUB 1300 ' sound the character in N$
1240     SOUND 32767,ICG
1250      NEXT N
1260 RETURN
1270 '
1280 '
1290 '

  The Ascii Decimal Equivelant in N$ determines which element of the DIG$ and ALF$ corresponds to the character to be
  sounded. The ".-.-" pattern is loaded into the ALPHA$ variable to be sounded and the Ascii character is printed.
  Then the . and - characters in ALPHA$ are serviced sequentally to generate dots or dashes to the computers internal speaker.
  This nested sub-rotine then returns to sub-routine from which it was called.
1300 '         output N$ to speaker ( 1 character)
1310 ALPHA$= ""
1320 IF N$= CHR$(13) THEN PRINT: RETURN
1330 IF N$=" " THEN SOUND 32767,IWG  : PRINT N$;
1340 IF N$="." THEN ALPHA$= ".-.-.-.": PRINT N$;
1350 IF N$="," THEN ALPHA$= "--..--" : PRINT N$;
1360 IF N$="?" THEN ALPHA$= "..--.." : PRINT N$;
1370 IF N$="/" THEN ALPHA$= "-..-."  : PRINT N$;
1380 IF N$="@" THEN ALPHA$= ".--.-." : PRINT N$;
1390 IF N$=>"0" AND N$<="9" THEN ALPHA$= DIG$(ASC(N$)-47): PRINT N$;
1400 IF N$=>"A" AND N$<="Z" THEN ALPHA$= ALF$(ASC(N$)-64): PRINT N$;
1410 IF N$=>"a" AND N$<="z" THEN ALPHA$= ALF$(ASC(N$)-96): PRINT N$;
1420    FOR S= 1 TO LEN (ALPHA$)
1430       S$= MID$(ALPHA$,S,1)
1440 IF S$= "." THEN SOUND F,DOT:  SOUND 32767,NUL
1450 IF S$= "-" THEN SOUND F,DASH: SOUND 32767,NUL
1460  NEXT S
1470 RETURN
1480 '
1490 '

  This little line of code SAVES the file to the current directory periodically in case the computer locks up during editing.
  It is protected from accidental execution by the END statement in the previous line of code.
1500 END     ' save file to disk
1510 SAVE "txtdida",A