1 ; ***********************************************************
  2 ; *                                                         *
  3 ; * Copyright, (C) Honeywell Bull Inc., 1987                *
  4 ; *                                                         *
  5 ; * Copyright, (C) Honeywell Information Systems Inc., 1986 *
  6 ; *                                                         *
  7 ; ***********************************************************
  8 
  9 ; HISTORY COMMENTS:
 10 ;  1) change(86-01-10,Flegel), approve(87-07-13,MCR7580),
 11 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 12 ;     Created.
 13 ;  2) change(86-05-22,Westcott), approve(87-07-13,MCR7580),
 14 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 15 ;     Support for gettdata structure.
 16 ;  3) change(86-09-05,Flegel), approve(87-07-13,MCR7580),
 17 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 18 ;     Returns minor cap in AX.
 19 ;  4) change(86-12-15,Flegel), approve(87-07-13,MCR7580),
 20 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 21 ;     Concatenation of consequetive FG_TERMINAL_DATA
 22 ;     messages.
 23 ;                                                      END HISTORY COMMENTS
 24 
 25 page 55,132
 26 ;/* : PROCEDURE FUNCTION (terminal_buffer_check):
 27 ;
 28 ;Check the terminal buffer to see if anything is in it, if so, copy the
 29 ;characters into the buffer supplied in ES:DI.
 30 ;*/
 31 
 32 ;/* : ARGUMENTS:
 33 ;
 34 ;        es:di - contains a pointer (byte) to where the
 35 ;                character string is be placed.
 36 ;        cx    - max. no. of characters wanted
 37 ;*/
 38 
 39 ;/* : RETURNS:
 40 ;
 41 ;        ax - minor capability number
 42 ;        cx - numbers of characters copied to buffer
 43 ;*/
 44 
 45 include dos.mac
 46 include mowsdefs.mac
 47 include ws.mac
 48 include ws_fgb.mac
 49 include wsmincap.mac
 50 
 51 page
 52 ;**************************************************************
 53 ;                                       DATA
 54 ;**************************************************************
 55 dseg
 56 
 57 ;------------ External Declarations
 58 extrn   fgbfptr:word
 59 extrn   fgblptr:word
 60 extrn   fgaptr:word
 61 
 62 ;------------ Public Declarations
 63 public  terminal_buffer_check
 64 
 65 endds
 66 
 67 page
 68 ;**************************************************************
 69 ;                                       MAIN
 70 ;**************************************************************
 71 pseg
 72 
 73 ;------------ External Declarations
 74 extrn   wsfree:near
 75 
 76 terminal_buffer_check proc near
 77 
 78         push    bx                         ;save registers to be used
 79         push    dx
 80         push    di
 81         xor     ax,ax                      ; ax = minor capability
 82         xor     dx,dx                      ; dx = copied data length
 83 
 84         cmp     cx,0                       ; cx = length of caller's buffer
 85         jbe     normal_return              ; if caller's buffer full, return
 86 
 87 ;/* : Look at each pending piece of foreground data
 88 ;     - Check terminal_buf status */
 89 
 90 copy_buffer:
 91         mov     bx,fgbfptr                 ; bx = data buffer pointer
 92         cmp     bx,0
 93         je      normal_return              ; return if empty (no more)
 94 
 95         cmp     cx,fgb_length[bx]          ; cx = space left in caller's buffer
 96         jb      normal_return              ; if caller's buffer not big enough
 97 
 98 ;/* : Concatenate FG_TERMINAL_DATA pieces together */
 99 
100         cmp     ax,0                       ; First piece extracted ?
101         je      extract_portion            ; ... get portion
102 
103         cmp     ax,FG_TERMINAL_DATA        ; Not Concatenating ?
104         jne     normal_return              ; ... return
105 
106         cmp     fgb_minor[bx],FG_TERMINAL_DATA  ; Concatenating next piece ?
107         je      extract_portion                 ; ... get portion
108 
109         jmp     normal_return              ; Complete message so return
110 
111 ;/* : If (Something in terminal_buf) */
112 
113 extract_portion:
114         add     dx,fgb_length[bx]          ; increment copy count
115         sub     cx,fgb_length[bx]          ; decrement space left length
116         push    cx                         ; save space left length
117 
118         lea     si,fgb_char[bx]            ; load address of data
119         mov     cx,fgb_length[bx]          ; cx = length of copy data
120 
121         mov     al,fgb_minor[bx]           ; minor capability in ax
122         xor     ah,ah
123         push    ax                         ; save on stack
124 
125         or      cx,cx                      ; Empty buffer ?
126         jbe     nextbuf                    ; ... free empty buffer
127 
128 
129 ;/* : copy to caller's buffer */
130 
131 tbcloop:
132         lodsb                              ; si -> source
133         stosb                              ; di -> destination (always)
134         loop    tbcloop                    ; si++, di++, cx-- ... automagic
135 
136 nextbuf:
137         pop     ax                         ; restore minor
138         pop     cx                         ; restore space left
139 
140         mov     si,fgb_next[bx]            ; fgb_next = next foreground message
141         mov     fgbfptr,si                 ; set fgbfptr (first) to next message
142 
143 ;/* : Free the message extracted */
144 
145         cmp     si,0                       ; If more buffers
146         jne     free_msg
147         mov     fgblptr,si                 ; set fgblptr (last) to NULL
148 
149 free_msg:
150         push    ax                         ; save minor
151         push    cx                         ; save space left length
152         push    dx                         ; save length
153         push    di                         ; save destination buffer position
154 
155         push    bp
156         mov     bp,sp
157         push    bx                         ; bx = message to free
158         push    fgaptr
159         call    wsfree                     ; free the buffer just emptied
160         mov     sp,bp
161         pop     bp
162 
163         pop     di                         ; restore destination buffer position
164         pop     dx                         ; restore length
165         pop     cx                         ; restore space left length
166         pop     ax                         ; restore minor
167 
168         jmp     copy_buffer                ; Get next portion
169 
170 normal_return:
171         mov     cx,dx                      ; cx = length of copied data
172         pop     di
173         pop     dx
174         pop     bx
175         ret
176 
177 terminal_buffer_check endp                 ;End of termbuf_check procedure
178 
179         endps
180         end
181 ^Z
182 ^Z