home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / bluebook.zip / STDIO.ASM < prev    next >
Assembly Source File  |  1986-05-08  |  7KB  |  214 lines

  1.                                       COMMENT ~
  2.  STDIO.ASM -- I/O PROCEDURES
  3.  
  4.    From `BLUEBOOK of ASSEMBLY ROUTINES for the IBM PC & XT'
  5.          by Christopher L. Morgan
  6.          Copyright (C) 1984 by The Waite Group, Inc.
  7.  
  8.    Function: These routines perform fundamental input/output functions for the
  9.      keyboard, screen, and communication lines.  The standard I/O routines
  10.      can be redirected.  The communications routines alleviate some of the
  11.      problems encountered in DOS and BIOS serial communications handling.
  12.  
  13.    See STDIO.DOC for complete information on the routines.
  14.  _____________________________________________________________________________
  15.  
  16.    Contains:
  17.    ---------
  18.    COM_INCK    --  Communications line check
  19.    COM_INIT    --  Initialize communications line
  20.    COM_OFF    --  Communications line off
  21.    COM_ON    --  Communications line on
  22.    COM_OUT    --  Communications line output
  23.    STD_CRLF    --  Standard output with carriage return & linefeed
  24.    STD_IN    --  Standard input with echo
  25.    STD_INCK    --  Standard input check
  26.    STD_INNE    --  Standard input with no echo
  27.    STD_MSGOUT    --  Standard output of a message
  28.    STD_OUT    --  Standard output
  29.    STD_OUTDR    --  Direct standard output
  30.    STD_SPACE    --  Standard output of a space    
  31.  _____________________________________________________________________________
  32.                                                                               ~
  33. CODES    SEGMENT
  34.     PUBLIC    STD_IN,STD_INNE,STD_INCK,STD_OUT,STD_OUTDR,STD_CRLF,STD_SPACE
  35.     PUBLIC    STD_MSGOUT,COM_INIT,COM_INCK,COM_OUT,COM_ON,COM_OFF
  36. ASSUME CS:CODES
  37. ;____________________________ I/O ROUTINES ___________________________________
  38. ;Routine for standard input with echo
  39. ;
  40. STD_IN    PROC    FAR
  41.     MOV    AH,1                ;Standard input
  42.     INT    21H                ; DOS call
  43.     RET                    ;Return
  44. STD_IN    ENDP
  45. ;------------------------------------------------------------------------------
  46. ;Routine for standard input with NO echo
  47. ;
  48. STD_INNE    PROC    FAR
  49.     MOV    AH,8                ;Standard input without echo
  50.     INT    21H                ; DOS call
  51.     RET                    ;Return
  52. STD_INNE ENDP
  53. ;------------------------------------------------------------------------------
  54. ;Routine for standard input check
  55. STD_INCK    PROC    FAR
  56.     PUSH    DX                ;Save register
  57.     MOV    DL,0FFH                ;Direct console input
  58.     MOV    AH,06H                ;Check std direct input status
  59.     INT    21H                ; DOS call
  60.     POP    DX                ;Restore register
  61.     RET                    ;Return
  62. STD_INCK    ENDP
  63. ;------------------------------------------------------------------------------
  64. ;Routine for standard output
  65. ;
  66. STD_OUT    PROC    FAR
  67.     PUSH    DX                ;Save register
  68.     MOV    DL,AL                ;In DL for DOS call 
  69.     MOV    AH,2                ;Standard output
  70.     INT    21H                ; DOS call
  71.     POP    DX                ;Restore register    
  72.     RET                    ;Return
  73. STD_OUT    ENDP
  74. ;------------------------------------------------------------------------------
  75. ;Routine for direct standard output
  76. ;
  77. STD_OUTDR    PROC    FAR
  78.     PUSH    DX                ;Save register
  79.     CMP    AL,0FFH                ;Check for the 1 case of input
  80.     JE    STD_OUTDRXIT            ;If so, go
  81.     MOV    DL,AL                ;Else in DL for DOS call
  82.     MOV    AH,6                ;Direct console output
  83.     INT    21H                ; DOS call
  84. STD_OUTDRXIT:
  85.     POP    DX                ;Restore register
  86.     RET                    ;Return
  87. STD_OUTDR    ENDP
  88. ;------------------------------------------------------------------------------
  89. ;Routine to send a CRLF sequence to standard output
  90. ;
  91. STD_CRLF    PROC    FAR
  92.     PUSH    AX                ;Save register
  93.     MOV    AL,13                ;ASCII carriage return
  94.     CALL    STD_OUT                ;Send it out
  95.     MOV    AL,10                ;ASCII line feed
  96.     CALL    STD_OUT                ;Send it out
  97.     POP    AX                ;Restore register
  98.     RET                    ;Return
  99. STD_CRLF    ENDP
  100. ;------------------------------------------------------------------------------
  101. ;Routine to send a space to standard output
  102. ;
  103. STD_SPACE    PROC    FAR
  104.     PUSH    AX                ;Save register
  105.     MOV    AL,32                ;ASCII space
  106.     CALL    STD_OUT                ;Send it out
  107.     POP    AX                ;Restore register
  108.     RET
  109. STD_SPACE    ENDP
  110. ;------------------------------------------------------------------------------
  111. ;Routine to send message to standard output
  112. ;
  113. STD_MSGOUT    PROC    FAR
  114.     PUSH    SI                ;Save registers
  115.     PUSH    AX
  116. STD_MSGOUT1:
  117.     MOV    AL,[SI]                ;Get byte
  118.     INC    SI                ;Point to next byte
  119.     CMP    AL,0                ;Done?
  120.     JE    STD_MSGOUTXIT            ;If so, go
  121.     CALL    STD_OUT                ;Else send it out
  122.     JMP    STD_MSGOUT1            ;Loop for more
  123. STD_MSGOUTXIT:
  124.     POP    AX                ;Restore registers
  125.     POP    SI
  126.     RET                    ;Return
  127. STD_MSGOUT    ENDP
  128. ;------------------------------------------------------------------------------
  129. ;Routine to initialize a communications line
  130. ;
  131. COM_INIT    PROC    FAR
  132.     MOV    AH,0                ;Initialize
  133.     INT    14H                ;RS232 BIOS call
  134.     RET                    ;Return
  135. COM_INIT    ENDP
  136. ;------------------------------------------------------------------------------
  137. ;Routine to check for input from a communications line
  138. ;
  139. COM_INCK    PROC    FAR
  140.     PUSH    DS                ;Save registers
  141.     PUSH    DX
  142.     PUSH    SI
  143.     MOV    SI,DX                ;Look up address of com line
  144.     ADD    SI,SI                ;Double to index into table
  145.     MOV    DX,40H                ;Segment of system I/O table
  146.     MOV    DS,DX                ;Set data seg to this table
  147.     MOV    DX,[SI]                ;Now get it
  148.     ADD    DX,5                ;Line status
  149.     IN    AL,DX                ;Get it
  150.     TEST    AL,1                ;Receive buffer full?
  151.     JZ    COM_INCKXIT            ;If so, go
  152.     MOV    DX,[SI]                ;Data register
  153.     IN    AL,DX                ;Get it
  154. COM_INCKXIT:
  155.     POP    SI                ;Restore registers
  156.     POP    DX
  157.     POP    DS
  158.     RET
  159. COM_INCK    ENDP
  160. ;------------------------------------------------------------------------------
  161. ;Routine to send output to a communications line
  162. ;
  163. COM_OUT    PROC    FAR
  164.     MOV    AH,1                ;Send it out
  165.     INT    14H                ;RS232 BIOS call
  166.     RET                    ;Return
  167. COM_OUT    ENDP
  168. ;------------------------------------------------------------------------------
  169. ;Routine to turn on input from a communications line
  170. ;
  171. COM_ON    PROC    FAR
  172.     PUSH    DS                ;Save registers
  173.     PUSH    DX
  174.     PUSH    SI
  175.     MOV    SI,DX                ;Look up address of com line
  176.     ADD    SI,SI                ;Double to index into table
  177.     MOV    DX,40H                ;Segment of system I/O table
  178.     MOV    DS,DX                ;Set data seg to this table
  179.     MOV    DX,[SI]                ;Now get it
  180.     ADD    DX,4                ;Modem control register
  181.     MOV    AL,3                ;Set DTR & RTS
  182.     OUT    DX,AL                ;Send out control byte
  183.     POP    SI                ;Restore registers
  184.     POP    DX
  185.     POP    DS
  186.     RET
  187. COM_ON    ENDP
  188. ;------------------------------------------------------------------------------
  189. ;Routine to turn off input from a communications line
  190. ;
  191. COM_OFF    PROC    FAR
  192.     PUSH    DS                ;Save registers
  193.     PUSH    DX
  194.     PUSH    SI
  195.     MOV    SI,DX                ;Look up address of com line
  196.     ADD    SI,SI                ;Double to index into table
  197.     MOV    DX,40H                ;Segment of system I/O table
  198.     MOV    DS,DX                ;Set data seg to this table
  199.     MOV    DX,[SI]                ;Now get it
  200.     ADD    DX,4                ;Modem control register
  201.     MOV    AL,2                ;Clear DTR (line 20)
  202.     OUT    DX,AL                ;Send out control byte
  203.     POP    SI                ;Restore registers
  204.     POP    DX
  205.     POP    DS
  206.     RET
  207. COM_OFF  ENDP
  208. ;-----------------------------------------------------------------------------
  209. CODES    ENDS
  210. ;
  211.     END
  212. ;_____________________________________________________________________________
  213. ;>>>>> Physical EOF STDIO.ASM <<<<
  214.