1 ; ***********************************************************
  2 ; *                                                         *
  3 ; * Copyright, (C) Honeywell Bull Inc., 1987                *
  4 ; *                                                         *
  5 ; * Copyright, (C) Honeywell Information Systems Inc., 1986 *
  6 ; *                                                         *
  7 ; ***********************************************************
  8 
  9 PAGE 55,132
 10 
 11 ; HISTORY COMMENTS:
 12 ;  1) change(85-12-15,Flegel), approve(87-07-13,MCR7580),
 13 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 14 ;     Created.
 15 ;                                                      END HISTORY COMMENTS
 16 
 17 ;/* : PROCEDURE FUNCTION (RS232_out):
 18 ;
 19 ;Send the byte in al to the RS232 port only when it is safe to do so.
 20 ;*/
 21 
 22 ;/* : ARGUMENTS
 23 ;
 24 ;     al - byte to be outputted to RS232 port
 25 ;*/
 26 
 27 include dos.mac                 ;Lattice include file
 28 include mowsdefs.mac            ;Constant values
 29 include rs232err.mac            ; Hardware interrupt errors
 30 include ws_buf.mac              ; circular buffer macros
 31 
 32 ;*******************************************************************
 33 ;                            DATA
 34 ;*******************************************************************
 35 dseg
 36 
 37 ;-------- External declarations
 38 
 39 extrn  COM_PORT:word
 40 
 41 ;-------- Public Declarations
 42 public RS232_out
 43 
 44 endds
 45 
 46 page
 47 ;*******************************************************************
 48 ;                             MAIN
 49 ;*******************************************************************
 50 pseg
 51 
 52 ;--------- External Procedures
 53 
 54 extrn put_inbuff:near
 55 
 56 RS232_out proc near
 57 
 58         push ax
 59         push bx
 60         push cx
 61         push dx
 62 
 63 ;/* : Set up RS232 */
 64 
 65         mov     bl,al                  ;Save char to bl temporarily
 66         mov     dx,MCR                 ;Modem control Register
 67         add     dx,COM_PORT
 68         mov     al,MCRREAD             ;Out2, DTR, RTS
 69         out     dx,al
 70         sub     cx,cx                  ;Initialize timeout count
 71         mov     dx,MSR                 ;Modem status Register
 72         add     dx,COM_PORT
 73 
 74 ;/* : Wait for CTS (Clear to send) */
 75 
 76 RS150:
 77         sub     cx,cx                  ;Another timeout count
 78 
 79 TIME_LOOP:
 80         in      al,dx
 81         test    al,MSRCTS              ;Clear to send?
 82         jnz     SEND_CLEAR             ;yes
 83         loop    TIME_LOOP              ;No, loop til timeout
 84 
 85 ;/* : Too long, exit */
 86 
 87         mov     ah,INTERRUPT_STATUS
 88         mov     al, ISCTSTO            ; record CTS timeout
 89         call    put_inbuff
 90         jmp     short RSXIT            ;And QUIT
 91 
 92 ;/* : Wait for THRE (Transmit Holding Register Empty) */
 93 
 94 SEND_CLEAR:
 95         mov     dx,LSR                 ;Line Status register
 96         add     dx,COM_PORT
 97         sub     cx,cx                  ;Another time out
 98 
 99 STATUS_TIMING:
100         in      al,dx                  ;LSR status
101         test    al,LSRTHRE             ;Transmit holding reg empty
102         jnz     SEND_CHAR              ;Yes
103         loop    STATUS_TIMING          ;No, loop til timeout
104 
105 ;/* : Too long, exit */
106 
107         mov     ah,INTERRUPT_STATUS
108         mov     al,ISTHRETO
109         call    put_inbuff             ;record error
110         jmp     short RSXIT            ;And QUIT
111 
112 ;/* : Get line status , send char */
113 
114 SEND_CHAR:
115         mov     ah,al                  ;Get line status for return
116         and     ah,MASK7               ;mask bit 7
117         mov     al,bl                  ;restore char to al
118         mov     dx,THR                 ;transmit holding register
119         add     dx,COM_PORT
120         out     dx,al                  ;Output it to RS232
121 
122 RSXIT:
123         pop     dx                     ;Restore Registers
124         pop     cx
125         pop     bx
126         pop     ax
127         ret
128 
129 RS232_out endp
130         endps
131         end
132 ^Z