home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / assemutl.zip / TALK1.ASM < prev    next >
Assembly Source File  |  1985-05-11  |  6KB  |  196 lines

  1.     name      talk
  2.     page      66,80
  3.     .lfcond   ;conditional assem
  4.     title      TALK-dumb terminal
  5. ;
  6. ;Talk- a dumb terminal emulator
  7. ;      for the IBM-PC, illustrates
  8. ;      ROM-BIOS asynch. support.
  9. ;      copyright (c)1983 RAY DUNCAN
  10. ;      May be freely reproduced for
  11. ;      non-commercial use.
  12. CR   EQU  0DH                 ;ASCII carriage return
  13. LF   EQU  0AH                 ;ASCII line feed
  14. ESC  EQU  1BH                 ;ASCII escape code
  15. ;
  16. ECHO EQU  0                 ;flags conditional assembly 0=full duplex
  17. ;                                 1=half duplex
  18. COM_PORT EQU 0                 ;set to 0 or 1 0=comm1, 1=comm2.
  19. ;
  20. CSEG SEGMENT PARA PUBLIC 'CODE'
  21. ;
  22. ASSUME CS:CSEG,DS:DSEG,SS:STACK
  23. ;
  24. TALK  PROC FAR                 ;ENTRY POINT FROM DOS
  25.   PUSH    DS                 ;save DS:0000 on stack for return to DOS
  26.   XOR    AX,AX                 ;make data area accessible
  27.   PUSH    AX                 ;
  28.   MOV    AX,SEG DSEG             ;
  29.   MOV    DS,AX                 ;
  30.   CALL    COM_STAT             ;Check that modem is on-line by checking
  31.   TEST    AL,20H                 ;the "DATA SET READY" bit in status word.
  32.   JNZ    TALK1                 ;if the bit is on then proceed.
  33.   MOV    DX,OFFSET MSG1             ;if the bit is off, print a message and
  34.   JMP    TALK6                 ;return to DOS.
  35. ;
  36. TALK1:                     ;let the user know the modem is on.
  37.   MOV    AH,15                 ;use "get mode" of rom bios video driver
  38.   INT    10H                 ;to get the number of columns, for CLEAR
  39.   DEC    AH                 ;
  40.   MOV    COLUMNS,AH             ;
  41.   CMP    AL,7                 ;make sure screen is in text mode
  42.   JE    TALK2                 ;mode 7 ok proceed
  43.   CMP    AL,3                 ;
  44.   JBE    TALK2                 ;mode 0-3 is ok proceed
  45.   MOV    DX,OFFSET MSG2             ;all else is illegal. return and show
  46.   JMP    TALK6                 ;message.
  47. ;
  48. TALK2:                     ;clear screen,reverse video, cursor home.
  49.   MOV    BH,70H                 ;
  50.   CALL    CLEAR                 ;
  51.   CALL    HOME                 ;
  52. ;
  53. ;******************************************************************************
  54. ;         THIS IS THE MAIN BODY OF THE PROGRAM
  55. ;******************************************************************************
  56. ;
  57. TALK3:    CALL PC_STAT             ;check for keybrd buffer w/ character
  58.   JZ    TALK4                 ;Nope!
  59.   CALL    PC_IN                 ;read character from keyboard.
  60.   CMP    AL,ESC                 ;is it the ESCape key?
  61.   JE    TALK5                 ;Yes, it is, lets exit this turkey!
  62.   IF    ECHO                 ;CONDITIONAL if echo = 0 then dont
  63.   PUSH    AX                 ;assemble this.
  64.   CALL    PC_OUT                 ;save character, send it to display
  65.   POP    AX                 ;restore character.
  66. ENDIF                     ;END CONDITIONAL
  67.   CALL    COM_OUT              ;write the character to the comm port
  68. ;
  69. TALK4:    CALL COM_STAT             ;Check for character in the comm port
  70.   JZ    TALK3                 ;No? loop
  71.   CALL    COM_IN                 ;read character from comm port
  72.   CALL    PC_OUT                 ;display it
  73.   JMP    TALK3                 ;start from TALK3 and do it again
  74. ;
  75. TALK5:                     ;EXIT fom talk1,
  76.   MOV    BH,07H                 ;restore normal video
  77.   CALL    CLEAR                 ;clear screen
  78.   CALL    HOME                 ;set cursor upper left
  79.   MOV    DX,OFFSET  MSG3          ;point to sign off message
  80. ;
  81. TALK6:MOV AH,9                 ;call function 9 to display "GOOD BYE..."
  82.   INT    21H                 ;do it.
  83. RET                     ;Now return to dos
  84. ;
  85. TALK ENDP                 ;
  86. ;
  87. COM_STAT PROC NEAR             ;use ROM BIOS function 3
  88.   MOV    DX,COM_PORT            ;to get
  89.   MOV    AH,3                 ;comm port status
  90.   INT    14H                 ;
  91.   TEST    AH,098H              ;check error flags for time_out, break,
  92.   JNZ    COM_ERR              ;or frame error. error detected, then beep
  93. ;
  94. ;
  95. COM_STAT1:                 ;test data ready bit,
  96.   TEST    AH,1                 ;Z flag = 0 if data waiting
  97. RET                     ;return
  98. ;
  99. ;
  100. COM_ERR:PUSH AX              ;error detected
  101.   MOV    AL,7                 ;set 7 for beep
  102.   CALL    PC_OUT                 ;beep it
  103.   POP    AX                 ;return comm status
  104.   JMP    COM_STAT1            ;
  105. COM_STAT ENDP                 ;
  106. ;
  107. COM_IN PROC NEAR             ;use ROM BIOS function 2 to get character
  108.   MOV    DX,COM_PORT            ;
  109.   MOV    AH,2                 ;
  110.   INT    14H                 ;
  111. RET                     ;
  112. COM_IN ENDP                 ;
  113. ;
  114. COM_OUT PROC NEAR             ;write the character in AL
  115.   MOV    DX,COM_PORT            ;to the comm port. DX destroyed
  116.   MOV    AH,1                 ;use ROM BIOS function 1 to
  117.   INT    14H                 ;send character
  118. RET                     ;
  119. COM_OUT ENDP                 ;
  120. ;
  121. PC_STAT PROC NEAR             ;read status of keyboard
  122.   MOV    AL,IN_CHAR             ;Z=0 if character waiting
  123.   OR    AL,AL                 ;Z=1 if empty
  124.   JNZ    PC_STAT1             ;if character waiting just return w/status
  125.   MOV    AH,6                 ;otherwise call DOS to determine status
  126.   MOV  DL,0FFH                ;
  127.   INT    21H                 ;
  128.   JZ    PC_STAT1             ;jump if nothing ready
  129.   MOV    IN_CHAR,AL             ;got a character, save it for PC-IN
  130. ;
  131. PC_STAT1:                 ;return with status
  132. RET                     ;
  133. PC_STAT ENDP                 ;
  134. ;
  135. PC_IN PROC NEAR              ;
  136.   MOV    AL,IN_CHAR             ;
  137.   OR    AL,AL                 ;any character waiting?
  138.   JNZ    PC_IN1                 ;yes, return it to caller.
  139.   CALL    PC_STAT              ;no, try and read a character.
  140.   JMP    PC_IN                 ;
  141. ;
  142. PC_IN1: XOR AH,AH             ;clear the character waiting flag.
  143.   MOV    IN_CHAR,AH             ;
  144. RET                     ;exit with the character in AL
  145. PC_IN ENDP                 ;
  146. ;                     ;
  147. ;
  148. PC_OUT PROC NEAR             ;write the character in AL to the screen
  149.   MOV    DL,AL                 ;use DOS function 6 to send the character
  150.   MOV    AH,6                 ;because it ignores ctrl characters so
  151.   INT    21H                 ;they can be sent to remote system
  152. RET                     ;
  153. PC_OUT ENDP                 ;
  154. ;
  155. CLEAR PROC NEAR              ;clear display and set it to the attribute
  156.   MOV    DL,COLUMNS             ;in BH. AX,CX,DX may be destroyed.
  157.   MOV    DH,24                 ;DL,DH = x,y of lower right of window
  158.   MOV    CX,0                 ;CL,CH = x,y of upper left of window
  159.   MOV    AX,600H              ;AH=6 for scroll or intialize AL=0 for #
  160.   INT    10H                 ;to scroll. Call ROM BIOS video driver
  161. RET                     ;
  162. CLEAR ENDP                 ;
  163. ;
  164. HOME PROC NEAR                 ;
  165.   MOV    DX,0                 ;DL,DH = x,y for cursor both = 0
  166.   MOV    BH,0                 ;BH = video page
  167.   MOV    AH,2                 ;function 2= set cursor
  168.   INT    10H                 ;call ROM BIOS video driver
  169. RET                     ;
  170. HOME ENDP                 ;
  171. ;
  172. CSEG ENDS                 ;
  173. ;
  174. ;
  175. DSEG SEGMENT PARA'DATA'              ;
  176.   IN_CHAR DB 0                 ;stores kybrd input character
  177.   COLUMNS DB 0                 ;highest # column in current display mode
  178. ;
  179. ;
  180.   MSG1      DB CR,LF,'Check your MODEM!'
  181.       DB CR,LF,'$'
  182.   MSG2      DB cr,lf,'Display is TEXT MODE'
  183.       DB CR,LF,'$'
  184.   MSG3      DB CR,LF,'Good Bye, Thanks for Calling!'
  185.       DB CR,LF,'$'
  186. DSEG ENDS
  187. ;
  188. ;
  189. STACK SEGMENT PARA stack 'stack'
  190.   DB 64 DUP(?)
  191. STACK ENDS
  192. ;
  193. ;
  194. END TALK
  195.  
  196.