4 ifdef ??version ; using TASM
\r
9 PUBLIC _pktDrop, _pktRxBuf, _pktTxBuf, _pktTemp
\r
10 PUBLIC _rxOutOfs, _rxInOfs, _PktReceiver, _pktRxEnd
\r
13 ; these sizes MUST be equal to the sizes in PKTDRVR.H
\r
16 RX_BUF_SIZE = 1500 ; max message size on Ethernet
\r
21 NUM_RX_BUF = 32 ; # of RX element buffers
\r
22 _TEXT SEGMENT PUBLIC DWORD USE16 'CODE'
\r
24 _DATA SEGMENT PUBLIC DWORD USE16 'CODE'
\r
26 D_SEG EQU <_TEXT SEGMENT>
\r
27 D_END EQU <_TEXT ENDS>
\r
28 ASSUME CS:_TEXT,DS:_TEXT
\r
32 _TEXT SEGMENT PUBLIC DWORD 'CODE'
\r
34 _DATA SEGMENT PUBLIC DWORD 'DATA'
\r
36 D_SEG EQU <_DATA SEGMENT>
\r
37 D_END EQU <_DATA ENDS>
\r
38 ASSUME CS:_TEXT,DS:_DATA
\r
41 ;-------------------------------------------
\r
46 firstCount dw 0 ; # of bytes on 1st call
\r
47 secondCount dw 0 ; # of bytes on 2nd call
\r
48 handle dw 0 ; handle for upcall
\r
49 destinAdr db 6 dup (0) ; packet destination address
\r
50 sourceAdr db 6 dup (0) ; packet source address
\r
51 protocol dw 0 ; packet protocol number
\r
52 rxBuffer db RX_BUF_SIZE dup (0) ; RX buffer
\r
55 _rxOutOfs dw offset _pktRxBuf ; ring buffer offsets
\r
56 _rxInOfs dw offset _pktRxBuf ; into _pktRxBuf
\r
57 _pktDrop dw 0,0 ; packet drop counter
\r
58 _pktTemp db 20 dup (0) ; temp work area
\r
59 _pktTxBuf db (TX_BUF_SIZE+14) dup (0) ; TX buffer
\r
60 _pktRxBuf RX_ELEMENT NUM_RX_BUF dup (<>) ; RX structures
\r
78 mov es, bx ;; r-mode segment of colour screen
\r
79 mov di, 158 ;; upper right corner - 1
\r
81 mov al, fanChars[bx] ;; get write char
\r
82 mov ah, 15 ;; and white colour
\r
83 stosw ;; write to screen at ES:EDI
\r
84 inc fanIndex ;; update next index
\r
90 ;------------------------------------------------------------------------
\r
92 ; This macro return ES:DI to tail of Rx queue
\r
96 mov ax, _rxInOfs ;; DI = current in-offset
\r
97 add ax, SIZE RX_ELEMENT ;; point to next _pktRxBuf buffer
\r
98 cmp ax, LAST_OFS ;; pointing past last ?
\r
99 jb @noWrap ;; no - jump
\r
100 lea ax, _pktRxBuf ;; yes, point to 1st buffer
\r
102 @noWrap: cmp ax, _rxOutOfs ;; in-ofs = out-ofs ?
\r
103 je @dump ;; yes, queue is full
\r
104 mov di, _rxInOfs ;; ES:DI -> buffer at queue input
\r
105 mov newInOffset, ax ;; remember new input offset
\r
107 ;; NOTE. rxInOfs is updated after the packet has been copied
\r
108 ;; to ES:DI (= DS:SI on 2nd call) by the packet driver
\r
112 ;------------------------------------------------------------------------
\r
114 ; This routine gets called by the packet driver twice:
\r
115 ; 1st time (AX=0) it requests an address where to put the packet
\r
117 ; 2nd time (AX=1) the packet has been copied to this location (DS:SI)
\r
118 ; BX has client handle (stored in RX_ELEMENT.handle).
\r
119 ; CX has # of bytes in packet on both call. They should be equal.
\r
121 ; A test for equality is done by putting CX in _pktRxBuf [n].firstCount
\r
122 ; and _pktRxBuf[n].secondCount, and CL on first call in
\r
123 ; _pktRxBuf[n].rxBuffer[CX]. These values are checked in "PktReceive"
\r
126 ;---------------------------------------------------------------------
\r
130 cli ; no distraction wanted !
\r
139 mov es, bx ; ES = DS = CS or seg _DATA
\r
140 pop bx ; restore handle
\r
142 cmp ax, 0 ; first call? (AX=0)
\r
143 jne @post ; AX=1: second call, do post process
\r
146 SHOW_RX ; show that a packet is received
\r
148 cmp cx, RX_BUF_SIZE+14 ; size OK ?
\r
149 ja @skip ; no, packet to large for us
\r
151 ENQUEUE ; ES:DI -> _pktRxBuf[n]
\r
153 mov [di].firstCount, cx ; remember the first count.
\r
154 mov [di].handle, bx ; remember the handle.
\r
155 add di, 6 ; ES:DI -> _pktRxBuf[n].destinAdr
\r
158 retf ; far return to driver with ES:DI
\r
161 @dump: inc _pktDrop[0] ; discard the packet on 1st call
\r
162 adc _pktDrop[2], 0 ; increment packets lost
\r
164 @skip: xor di, di ; return ES:DI = NIL pointer
\r
172 @post: or si, si ; DS:SI->_pktRxBuf[n][n].destinAdr
\r
173 jz @discard ; make sure we don't use NULL-pointer
\r
175 sub si, 6 ; DS:SI -> _pktRxBuf[n].destinAdr
\r
178 ; push [si].firstCount
\r
179 ; call bpf_filter_match ; run the filter here some day?
\r
184 mov [si].secondCount, cx
\r
185 mov ax, newInOffset
\r
186 mov _rxInOfs, ax ; update _pktRxBuf input offset
\r
193 _pktRxEnd db 0 ; marker for end of r-mode code/data
\r