home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / speech2.zip / READ.ASM < prev    next >
Assembly Source File  |  1985-09-17  |  5KB  |  147 lines

  1. TITLE Supplement to SPEECH.COM by Douglas Sisco      09-04-1985
  2. PAGE    55,132           
  3.  
  4. CODE    SEGMENT 'CODE'
  5.         ASSUME CS:CODE,DS:CODE
  6.         ORG     100H
  7.  
  8. BEGIN:  JMP     START
  9.  
  10. ; Put my name in .COM file - can be viewed with TYPE command.
  11.         DB      8,8,8,'Program by Douglas Sisco 9-6-85',13,10,26 
  12.  
  13.  
  14. STRING  DB      255 DUP(0)              ; Line input buffer to hold 255 chars
  15.  
  16. ; Here is a fake string descriptor  - BASIC Manual C-8
  17. ; SPEECH expects a pointer to this on the stack when it is called
  18.  
  19. STRLEN  DB      0
  20. STROFS  DW      STRING
  21.  
  22. INBYTE  DB      0                       ;One byte file input buffer
  23. HAND    DW      0                       ;File handle from DOS
  24.  
  25. SPEECH   DW      0972                   ;DWORD Pointer to Speech
  26.          DW      0000                   ;This is where it is put 0000:03CCH
  27.  
  28. NOSPEECH DB      'Speech Program not loaded - run SPEECH.COM and try again',13,10,'$'
  29. FNFMSG   DB      'Can not open file',13,10,'$'
  30. ERRMSG   DB      'DOS error '
  31. ERRCD    DB      '  -- failed read attempt',13,10,'$'
  32. EOF      DB      0                      ;File exist/EOF flag
  33.  
  34. START:  XOR     AX,AX
  35.         MOV     DS,AX
  36.         MOV     AL,DS:[3CCH]            ;See if SPEECH.COM is in memory
  37.         CMP     AL,0CDH
  38.         PUSH    CS
  39.         PUSH    CS
  40.         POP     ES                      ;All segment regs = CS
  41.         POP     DS
  42.         JZ      OK
  43.  
  44.         MOV     AH,9
  45.         MOV     DX,OFFSET NOSPEECH      ;Print message if not
  46.         INT     21H
  47.         INT     20H                     ;Return to DOS
  48. OK:
  49.         XOR     AX,AX
  50.         MOV     AL,DS:[80H]
  51.         MOV     DI,81H
  52.         ADD     DI,AX
  53.         MOV     BYTE PTR [DI],0         ;Put a 0 at end of command line
  54.  
  55.         CALL    OPEN                    ;Open the file for read
  56.         JNC     OK2
  57.  
  58.         MOV     AH,9
  59.         MOV     DX,OFFSET FNFMSG
  60.         INT     21H                     ;Print message
  61.         INT     20H                     ;Dont try it on non-existant files
  62.  
  63. OK2:
  64.         CALL    READLIN                 ;Read line
  65.  
  66.         CMP     STRLEN,0
  67.         JZ      OK3                     ;Str Length = 0 - Don't bother
  68.  
  69.         MOV     AX,OFFSET STRLEN
  70.  
  71.         PUSH    AX                      ;Pass data location to speech program
  72.         CALL    DWORD PTR SPEECH        ;Say it
  73. OK3:
  74.         CMP     EOF,0                   ;EOF ?
  75.         JNZ     S1
  76.         JMP     OK2
  77. S1:
  78.         CALL    CLOSE                   ;Close file
  79.         INT     20H                     ;Return to DOS
  80. ;--------------------
  81. OPEN    PROC    NEAR                    ;Attempt to OPEN file
  82.         MOV     DX,82H
  83.         MOV     AX,3D00H                ;Open for read
  84.         INT     21H                     ;Leave all flags for caller to process
  85.         MOV     HAND,AX
  86.         RET
  87. OPEN    ENDP
  88. ;--------------------
  89. READLIN PROC    NEAR                    ;Read line from file
  90.         MOV     STRLEN,0
  91.         MOV     DI,OFFSET STRING
  92. R3:
  93.         MOV     DX,OFFSET INBYTE
  94.         MOV     BX,HAND                 ;Get handle from OPEN
  95.         MOV     AX,3F00H
  96.         MOV     CX,1                    ;Read 1 byte
  97.         INT     21H
  98.         JNC     R6                      ;Check for error
  99.  
  100.         ADD     AL,'0'
  101.         MOV     ERRCD,AL
  102.         MOV     DX,OFFSET ERRMSG
  103.         MOV     AH,9
  104.         INT     21H                     ;Print error message
  105.         XOR     AX,AX                   ;Cause flag to be set
  106. R6:
  107.         OR      AX,AX                   ;See if end of file
  108.         JNZ     R4 
  109.         MOV     INBYTE,26                ;force EOF
  110. R4:
  111.         MOV     DL,INBYTE
  112.         MOV     AH,2
  113.         INT     21H                     ;Print Char on console 
  114.  
  115.         CMP     INBYTE,' '              ;See if char will work
  116.         JB      R5
  117.         CMP     INBYTE,'~'
  118.         JA      R5
  119.         CMP     STRLEN,254
  120.         JA      R5                      ;Line Too Long
  121.  
  122.         INC     STRLEN                  ;Add char to string
  123.         MOV     AL,INBYTE
  124.         STOSB                           ;Move char to string
  125.  
  126. R5:     CMP     INBYTE,26               ;^Z ? set eof flag if yes
  127.         JNZ     R1
  128.         MOV     EOF,1
  129.         MOV     INBYTE,13               ;Force true for next CMP
  130. R1:     CMP     INBYTE,13               ;use CR for EOL marker LF is ignored
  131.         JZ      R2
  132.         JMP     R3
  133. R2:     RET
  134. READLIN ENDP
  135. ;--------------------
  136. CLOSE   PROC    NEAR
  137.         MOV     BX,HAND
  138.         MOV     AH,3EH
  139.         INT     21H
  140.         RET
  141. CLOSE   ENDP
  142. ;--------------------
  143. CODE    ENDS
  144.         END     BEGIN
  145.  
  146.