1 ;/* BEGIN INCLUDE FILE ws_buf.mac */
  2 
  3 ; HISTORY COMMENTS:
  4 ;  1) change(86-04-10,Westcott), approve(87-07-13,mcr7580),
  5 ;     audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
  6 ;     Created.
  7 ;                                                      END HISTORY COMMENTS
  8 
  9 ;/* : FUNCTION
 10 ;
 11 ;Defines macros that support circular buffers.
 12 ;*/
 13 
 14 bstruc  struc
 15 bsize   dw      ?       ;size of buffer
 16 bfirst  dw      ?       ; start of buffer
 17 blast   dw      ?       ; end of buffer
 18 bin     dw      ?       ; next empty space in buffer
 19 bout    dw      ?       ; next char to be removed
 20 bminor  db      ?       ; minor capability associated
 21 mbuffer dw      ?       ; placeholder for message
 22 bstruc  ends
 23 
 24 def_buf macro   bname,bufsize   ;define circular buffer
 25 bname   bstruc  <bufsize>
 26         db      bufsize dup(?)
 27         endm
 28 
 29 init_buf macro  bname           ; initialize circular buffer
 30         mov     bx, offset bname
 31         mov     ax, offset bname.mbuffer
 32         mov     bfirst[bx],ax
 33         mov     bin[bx],ax
 34         mov     bout[bx],ax
 35         add     ax,bname.bsize
 36         mov     blast[bx],ax
 37         endm
 38 
 39 put_buf macro   bname,nostop    ; insert character into buffer
 40         push    si
 41         push    bx
 42         mov     bx,offset bname
 43         mov     si, bin[bx]
 44         mov     byte ptr ds:[si],al
 45 
 46 ;        inbuff = inbuff + 1
 47 ;        if (inbuff is at end of buffer)
 48 ;           inbuff = start of buffer
 49 
 50         inc     si
 51         cmp     si,blast[bx]
 52 nae1    =       $
 53         jbe     short $+(nae2-nae1)   ;if not at end of buffer
 54         mov     si,bfirst[bx]
 55 nae2    =       $
 56 
 57 ;        if (not overflow) store inbuff, clear error code, and return */
 58         mov     ax,1            ;set error return code, just in case
 59         ifb     <nostop>
 60         cmp     si, bout[bx]
 61 novf1   =       $
 62         je      $ + (novf2 - novf1)
 63         endif
 64         mov     bin[bx],si
 65         xor     ax,ax           ;set return code
 66 novf2   =       $
 67         pop     bx
 68         pop     si
 69         endm
 70 
 71 get_buf macro   bname           ; get character from buffer
 72         push    si
 73         push    bx
 74         mov     bx, offset bname
 75         mov     si,bout[bx]
 76         cmp     si,bin[bx]
 77 bemp1   =       $
 78         je      $ + (bemp2 - bemp1)
 79 
 80 ;/* : if (buffer not empty) get character into AX */
 81 
 82         mov     al,byte ptr ds:[si]
 83 
 84 ;/* : outbuff = outbuff + 1
 85 ;     if (outbuff = end of buffer) outbuff = start of buffer */
 86 
 87         inc     si
 88         cmp     si,blast[bx]
 89 nae3    =       $
 90         jbe     $ + (nae4 - nae3)
 91         mov     si,bfirst[bx]
 92 nae4    =       $
 93         mov     bout[bx],si
 94         stc             ; SET carry flag to indicate data available
 95 bnemp1  =       $
 96         jmp     $ + (bnemp2 - bnemp1)
 97 
 98 ;/* : if (buffer empty) clear carry flag, and return */
 99 
100 bemp2   = $
101         clc             ; CLEAR carry flag to indicate no data
102 bnemp2  = $
103         pop     bx
104         pop     si
105         endm
106 
107 len_buf macro   bname           ; calculate empty space in buffer
108         push    bx
109         mov     bx,offset bname
110         mov     ax,bout[bx]
111         sub     ax,bin[bx]
112 lb1     =       $
113         ja      $ + (lb2-lb1)   ; if no wrap
114         add     ax,bsize[bx]
115 lb2     =       $
116         pop     bx
117         endm
118 
119 ;/* END INCLUDE FILE ws_buf.mac */
120 ^Z