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(85-12-18,Flegel), approve(87-07-13,MCR7580),
 12 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 13 ;     Created.
 14 ;  2) change(86-01-30,Flegel), approve(87-07-13,MCR7580),
 15 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 16 ;     Handle 4 types of interrupts: receive data,
 17 ;      transmit holding empty, break character/framing error, change in modem
 18 ;      status.
 19 ;  3) change(86-04-26,Westcott), approve(87-07-13,MCR7580),
 20 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 21 ;     Installed circular input buffer (inbuff) to
 22 ;      store error messages.
 23 ;  4) change(86-08-29,Flegel), approve(87-07-13,MCR7580),
 24 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 25 ;     Check line status for DR (data ready) when
 26 ;      done current interrupt.
 27 ;  5) change(86-09-12,Flegel), approve(87-07-13,MCR7580),
 28 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 29 ;     Removed calls to stack alteration routines and
 30 ;     left interrupts masked in order to provide faster service to comm line
 31 ;     thus removing numerous line overrun errors on the line.
 32 ;  6) change(88-01-27,Flegel), approve(88-02-29,MCR7853),
 33 ;     audit(88-03-10,Nakaska):
 34 ;     Added test in MODEM interrupt section to look for a delta_CTS so that
 35 ;     transmitting will begin when a modem connection completes a dial-up
 36 ;     and CTS is finally raised.
 37 ;                                                      END HISTORY COMMENTS
 38 
 39 ; PROCEDURE FUNCTION (hardware_interrupt_handler):
 40 ;
 41 ; Handle all hardware interrupts which are generated by the RS232 port (pass
 42 ; control to message handler).
 43 
 44 ; NOTES:
 45 ;
 46 ; ES register will be set to contain the DS of the routine which was
 47 ; interrupted.
 48 
 49 include dos.mac                 ; Lattice include file
 50 include mowsdefs.mac            ; Assembler Definitions
 51 include rs232err.mac            ; Error definitions
 52 include wsmincap.mac            ; Predefined mincaps
 53 include ws_buf.mac              ; Circular buffer definitions
 54 include util.mac                ; macros for saving registers
 55 
 56 page
 57 ;**************************************************************
 58 ;                                       DATA
 59 ;**************************************************************
 60 dseg
 61 
 62 ;--------- External Declarations
 63 
 64 extrn transmit_active:word
 65 extrn COM_PORT:word
 66 extrn send_buffer:word
 67 
 68 ;--------- Structures
 69 
 70 dbgs    struc                          ; Debugging structure
 71 old_bp  dw     ?
 72 dbgret  dw     ?
 73 arg1    dw     ?
 74 dbgs    ends
 75 
 76 endds
 77 
 78 page
 79 ;**************************************************************
 80 ;                                       MAIN
 81 ;**************************************************************
 82 pseg
 83 
 84 ;-------- External Procedures
 85 extrn   packet_mode:word
 86 extrn   data_seg:word                  ; MOWSE data segment
 87 extrn   put_inbuff:near
 88 extrn   RS232_OUT:near
 89 
 90 ;-------- Publics
 91 
 92 public  sdbgchr
 93 public  hardware_interrupt_handler
 94 
 95 hardware_interrupt_handler proc near
 96 
 97         push    ax
 98         push    ds                     ; save interrupted DS register
 99         SAVEALL                        ; save all registers (except ax)
100         mov     ds,CS:data_seg         ; swap in MOWSE's DS
101 
102 ; /* Get interrupt identification
103 
104         mov     dx,IIR
105         add     dx,COM_PORT
106         in      al,dx
107 
108 ; If break character interrupt (BI)
109 ;     - Read LSR to reset interrupt
110 
111 process_int:
112         and     al,MASKBREAK
113         cmp     al,LSR_LSTATUS
114         jne     test_rcv
115 
116 break_int:
117         push    ax
118         mov     dx,LSR                 ;Read the LSR to reset the interrupt
119         add     dx,COM_PORT
120         in      al,dx
121         shr     al,1
122         and     al,0fh                 ; mask non_error bits
123         mov     ah,LINE_STATUS         ; store LSR error
124         call    put_inbuff
125         pop     ax
126         jmp     done_int
127 
128 ; Else if Data ready (DR)
129 ;      - get character
130 ;      - if (char = ESCAPE_STATUS or LINE_STATUS) escape the character
131 ;        (this is necessary for recording errors received)
132 ;      - store char in buffer
133 
134 test_rcv:
135         cmp     al,LSR_RCV
136         jne     sending_int
137 
138         mov     dx,RBR                 ;Receive buffer
139         add     dx,COM_PORT
140         in      al,dx                  ;the char in al
141 
142         xor     ah,ah
143         cmp     al,ESCAPE_STATUS
144         ja      rcv_ok                 ; if received a reserved byte
145 
146         cmp     al,LINE_STATUS
147         jb      rcv_ok
148 
149         mov     ah,ESCAPE_STATUS
150 
151 rcv_ok:
152         call put_inbuff
153         jmp  done_int
154 
155 ; Else if transmit holding register clear (THRE)
156 ;      - If character in send buffer, transmit the character
157 
158 sending_int:
159         cmp     al,LSR_THRE
160         jne     modem_int
161 
162         push    ax
163 
164 delta_cts_send:                        ; From modem interrupt
165 
166         get_buf send_buffer            ; get another character from send buffer
167         jnc     done_trans             ; if send buffer empty
168 
169         call    RS232_OUT              ; send the character
170         pop     ax
171         jmp     done_int
172 
173 ; - Else clear transmit active flag
174 
175 done_trans:
176         mov     transmit_active,0
177         pop     ax
178         jmp     done_int
179 
180 ; Else if Modem error (OE | PE | FE)
181 ;      - Read MSR to reset interrupt
182 ;      - Store the status character into receive buffer
183 
184 modem_int:
185         cmp     al,MASKMCHNG
186         jne     done_int
187 
188 ; What happened on the modem
189 
190         push    ax
191         mov     dx,MSR                 ;Read the MSR to reset the interrupt
192         add     dx,COM_PORT
193         in      al,dx
194         and     al,0fh                 ; mask non_error bits
195 
196 ; If it was a delta CTS and CTS went high, then try and send data
197 
198         test    al,00000001b           ; Delta CTS (change in CTS) ?
199         je      no_delta_cts           ;  NO - an error
200 
201         test    al,MSRCTS              ; Clear to send?
202         jne     delta_cts_send         ; YES - try and send something
203 
204 no_delta_cts:
205 
206         mov     ah,MODEM_STATUS
207         call    put_inbuff             ; store modem status
208         pop     ax
209 
210 ; Check the IIR if there is a pending interrupt
211 
212 done_int:
213         mov     dx,IIR                 ;IIR register
214         add     dx,COM_PORT
215         in      al,dx
216         test    al,IIR_PENDING         ; test pending flag
217         jne     test_dr
218         jmp     process_int
219 
220 ; Check DR from the LSR
221 
222 test_dr:
223         mov     dx,LSR
224         add     dx,COM_PORT
225         in      al,dx
226         test    al,1
227         je      finished_int
228         jmp     process_int
229 
230 ; Signal 8259 that we are done
231 
232 finished_int:
233         mov     al,MASKEOI             ;Non-Specific EOI (end-of-interrupt)
234         out     OMR8259,al             ;Send it out port 20h ie 8259 INT CON
235 
236         RESTOREALL                     ; restore all registers (except ax)
237         pop     ds
238         pop     ax
239         iret
240 
241 ;END hardware_interrupt_handler
242 
243 hardware_interrupt_handler endp
244 
245 
246 ; INTERNAL PROCEDURE FUNCTION (sdbgchr):
247 ;
248 ; Write debug char to screen
249 
250 sdbgchr proc near
251         push    bp
252         mov     bp,sp
253         mov     ax,arg1[bp]
254         mov     ah,0Eh          ;Force character to screen function
255         and     al,7fh          ;ensure highlight bit is off
256         xor     bx,bx
257         int     10h             ;send char to screen
258         pop     bp
259         ret
260 
261 sdbgchr endp
262         endps
263         end