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 ; HISTORY COMMENTS:
 11 ;  1) change(86-07-26,Westcott), approve(87-07-13,MCR7580),
 12 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 13 ;     Created.
 14 ;  2) change(86-08-27,Flegel), approve(87-07-13,MCR7580),
 15 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 16 ;     Installed support for /M option in MOWSE.
 17 ;  3) change(86-08-29,Flegel), approve(87-07-13,MCR7580),
 18 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 19 ;     Test and set installed to prevent recursive
 20 ;     calls to recevie_byte, thus preventing race condition.
 21 ;                                                      END HISTORY COMMENTS
 22 
 23 ;/* : PROCEDURE FUNCTION (rcvbyte)
 24 
 25 ;Transfer received data from the RS232 input circular buffer to the protocol
 26 ;analyzer (rcvchr.c) if MOWSE is running, and into fg_sav_buf if MOWSE is
 27 ;not running.
 28 
 29 ;This routine also detects hardware error and status flags embedded in the
 30 ;data stream in a two byte
 31 ;*/
 32 
 33 ;/* : NOTES
 34 
 35 ;format:
 36 ;      Byte 0 = 3, following byte contains line status      */
 37 ;      Byte 0 = 4, following byte contains modem status     */
 38 ;      Byte 0 = 5, following byte contains buffer status    */
 39 ;      Byte 0 = 6, following byte contains input data       */
 40 
 41 ;If an error or status message is detected, then a message will be written to
 42 ;the PC screen.
 43 
 44 ;This routine calls get_inbuff, which also detects whether the MOWSE protocol
 45 ;is running and sets the the packet_mode flag if it is.                          */
 46 ;*/
 47 
 48 ;/* : RETURNS
 49 
 50 ;number of characters transferred.
 51 ;*/
 52 
 53 include dos.mac                 ;Lattice include file
 54 include mowsdefs.mac
 55 include rs232err.mac            ; Error definitions
 56 include wsmincap.mac            ; Predefined mincaps
 57 include ws_buf.mac              ; Circular buffer definitions
 58 
 59 ;**************************************************************
 60 ;                                       DATA
 61 ;**************************************************************
 62 dseg
 63 
 64 ;--------- External Declarations
 65 
 66 extrn packet_mode:word
 67 extrn in_protocol:word
 68 extrn fg_buf:word
 69 extrn error_mode:word
 70 
 71 ;--------- Public Declarations
 72 public  receive_byte
 73 
 74 ;--------- Local Memory Declarations
 75 merr      db      "***** ERROR  Modem status :  "
 76 merrval   db      0,0
 77 rerr      db      "***** ERROR  Receive Error:  "
 78 rerrval   db      0,0
 79 berr      db      "***** ERROR Buffer overflow ",0
 80 
 81 proc_lock db      0       ; procedure lock
 82 endds
 83 
 84 ;**************************************************************
 85 ;                                       MAIN
 86 ;**************************************************************
 87 pseg
 88 
 89 ;-------- External Procedures
 90 extrn   get_inbuff:near
 91 extrn   sstmsg:near
 92 extrn   rcvchr:near
 93 extrn   setlock:near
 94 
 95 receive_byte proc near
 96         push    bp
 97 
 98 ; /* : If currently executing, return */
 99         mov     bp,sp
100         mov     bx,offset proc_lock
101         push    bx
102         call    setlock
103         mov     sp,bp
104         test    ax,1
105         je      rcv_ok                   ; if lock not set then OK
106         jmp     rcv_active               ; else do not process
107 
108 ; /* : Pass characters in inbuff to protocol */
109 
110 rcv_ok:
111         test    packet_mode,1            ; if in packet mode
112         jnz     rcv_loop                 ;    jump to packet mode handler
113         push    ax                       ; else dump chars to fg buffer
114         push    bx
115         mov     bx,offset fg_buf
116         mov     ax,bout[bx]
117         sub     ax,bin[bx]
118         ja      skip1                    ; if no wrap
119         add     ax,bsize[bx]
120 
121 skip1:
122         cmp     ax,2
123         pop     bx
124         pop     ax
125         jb      rcv_nodat               ; if fg_buf is full
126         mov     byte ptr fg_buf+bminor,FG_TERMINAL_DATA
127         jmp     rcv_loop
128 
129 rcv_nodat:
130         jmp     no_rcvdata
131 
132 rcv_loop:
133         call    get_inbuff
134         jnc     rcv_nodat               ; if input buffer empty
135         cmp     al,ESCAPE_STATUS
136         ja      call_rcv                ; if valid character
137         je      esc_rcv                 ; if escape character
138         cmp     al,LINE_STATUS
139         jb      call_rcv                ; if valid character
140         je      lsrerr                  ; receive error
141         cmp     al,INTERRUPT_STATUS
142         je      inbuff_ovf              ; if buffer overflow occurred
143         call    get_inbuff              ; get error character
144 
145 ;/* : display error message */
146 
147         mov     bx, offset merr
148         mov     merrval,al
149         jmp     display_err
150 
151 lsrerr:
152         call    get_inbuff              ; get error character
153         mov     bx, offset rerr
154         mov     rerrval,al
155 
156 display_err:
157         test    error_mode, 1           ; if in error mode, display modem error
158         je      rcv_loop
159         mov     bp,sp
160         push    bx
161         call    sstmsg
162         mov     sp,bp
163         jmp     rcv_loop
164 
165 inbuff_ovf:
166         mov     bx,offset berr
167         jmp     display_err
168 
169 esc_rcv:
170         call    get_inbuff              ; get valid character
171 
172 ;/* : call rcvchr to pass character to PAD */
173 
174 call_rcv:
175         mov     bx, packet_mode
176         cmp     bx, 1
177         jne     receive_data
178         mov     bp, sp
179         push    ax
180         call    rcvchr
181         mov     sp, bp
182         jmp     rcv_cont
183 
184 ;/* : Else move data to foreground save buffer */
185 
186 receive_data:
187         put_buf fg_buf
188         push    bx
189         mov     bx,offset fg_buf
190         mov     ax,bout[bx]
191         sub     ax,bin[bx]
192         ja      skip2                   ; if no wrap
193         add     ax,bsize[bx]
194 
195 skip2:
196         cmp     ax,2
197         pop     bx
198         jb      no_rcvdata              ; if fg_buf is full
199 
200 rcv_cont:
201         jmp     rcv_loop
202 
203 no_rcvdata:
204 lock    mov     proc_lock,0             ; clear procedure lock
205 
206 rcv_active:                             ; jump label around clearing of
207         pop     bp                      ;    procedure lock
208         ret
209 
210 ;/* : END receive_byte */
211 receive_byte endp
212 
213         endps
214         end
215 ^Z