home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / NCSATELN / TEL23SRC.ZIP / NET / ENET / NETUB.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-07-02  |  17.0 KB  |  718 lines

  1. ;
  2. ;  Driver for Ungermann-Bass (IBM) NIC board
  3. ;  Tim Krauskopf
  4. ;****************************************************************************
  5. ;*                                                                          *
  6. ;*                                                                          *
  7. ;*      part of NCSA Telnet                                                 *
  8. ;*      by Tim Krauskopf, VT100 by Gaige Paulsen, Tek by Aaron Contorer     *
  9. ;*                                                                          *
  10. ;*      National Center for Supercomputing Applications                     *
  11. ;*      152 Computing Applications Building                                 *
  12. ;*      605 E. Springfield Ave.                                             *
  13. ;*      Champaign, IL  61820                                                *
  14. ;*                                                                          *
  15. ;****************************************************************************
  16.  
  17.     TITLE    NETSUPPORT -- LOW LEVEL DRIVERS FOR ETHERNET
  18. ;
  19. ;  Assembler support for interrupt-driven Ethernet I/O on the PC
  20. ;
  21. ;  Tim Krauskopf
  22. ;  National Center for Supercomputing Applications
  23. ;  9/1/87  Ungermann-Bass driver started, PC bus
  24. ;  4/88    Modified for combined - version 2.2
  25. ;
  26. ;
  27. ;Microsoft EQU 1
  28. ;Lattice EQU 1
  29. ifndef Microsoft
  30.     ifndef Lattice
  31.         if2
  32.             %out
  33.             %out ERROR: You have to specify "/DMicrosoft" OR "/DLattice" on the
  34.             %out        MASM command line to determine the type of assembly.
  35.             %out
  36.         endif
  37.         end
  38.     endif
  39. endif
  40.  
  41.     NAME    NET
  42. ifdef Microsoft
  43. X    EQU    6
  44.     DOSSEG
  45.     .MODEL    LARGE
  46. else
  47.     INCLUDE    DOS.MAC
  48.     SETX
  49. endif
  50. ;
  51. ;  Equates for controlling the UB board
  52. ;
  53. EADDR    EQU    010h        ; where EPROM address is
  54. RBUF    EQU    04000h        ; where receive buffers start
  55. TBUF    EQU    07000h        ; where transmit buffers start
  56. RPIDX    EQU    02100h        ; receive page index starts here
  57. ;
  58. ;  Registers on UB board
  59. ;
  60. TXINIT    EQU    02080h        ; initiate transmit (read)
  61. TSAMSB    EQU    02080h        ; transmit high start address
  62. TSALSB    EQU    02081h        ; transmit low start address
  63. CLRPAV    EQU    02081h        ; Clear packet available (read)
  64. INTSTAT    EQU    02082h        ; interrupt and transmit status
  65. INTCTL    EQU    02082h        ; interrupt control
  66. EPPPAV    EQU    02083h        ; packet avail, and empty page ptr
  67. FPP    EQU    02083h        ; full page ptr, high bit clear=no interrupts
  68. ;
  69. ;  EDLC registers
  70. ;
  71. TSTAT    EQU    02180h        ; transmit status, write ff to clear
  72. TMASK    EQU    02181h        ; transmit mask, which ints can occur
  73. RECSTAT    EQU    02182h        ; rec status, write ff to clear
  74. RMASK    EQU    02183h        ; rec mask, which ints can occur
  75. TMODE    EQU    02184h        ; trans mode, high nyb=# of collisions
  76.                 ;   enable loopback, write 00
  77.                 ;   disable loopback, write 02
  78. RMODE    EQU    02185h        ; rec mode, see list
  79. ERESET    EQU    02186h        ; set 080h to reset, set 0 to clear
  80. MADDR    EQU    02188h        ; write my eaddr here,+1,+2,3,4,5
  81.  
  82. ;
  83. ;  Transmit status that we are interested in
  84. ;
  85. TDONE    EQU    01        ; transmission done (when set)
  86. TOK    EQU    02          ; transmission done ok
  87. ;
  88. ;  mask for the packet available bit
  89. ;
  90. PAV    EQU    080h        ; packet is available
  91. EPP    EQU    07fh        ; inverse of PAV
  92. ;
  93. ;  Receive modes
  94. ;
  95. PROMI    EQU    03        ; promiscuous receive
  96. ROFF    EQU    00        ; don't receive
  97. LMULT    EQU    01        ; limited multicasts, bcast, mine
  98. MULT    EQU    02        ; mult, bcast, mine
  99.  
  100. ;
  101. ;  Data segment
  102. ;
  103. ifdef Microsoft
  104. ;DGROUP    group    _DATA
  105. ;_DATA    segment    public 'DATA'
  106. ;    assume    DS:DGROUP
  107.     .data
  108. else
  109.     DSEG
  110. endif
  111. ;
  112. ;  The pointers below are actually DWORDs but we access them two
  113. ;  bytes at a time.
  114. ;
  115. ; STAT change to RSTAT because of name clash with MSC library routine
  116. ifdef Microsoft
  117.     EXTRN    _RSTAT:BYTE    ; last status from read
  118.     EXTRN    _BUFPT:WORD    ; current buffer pointer
  119.     EXTRN    _BUFORG:WORD    ; pointer to beginning of buffer
  120.     EXTRN    _BUFEND:WORD    ; pointer to end of buffer
  121.     EXTRN    _BUFREAD:WORD    ; pointer to where program is reading
  122.     EXTRN    _BUFBIG:WORD    ; integer, how many bytes we have
  123.     EXTRN    _BUFLIM:WORD    ; integer, max bytes we can have
  124. else
  125.     EXTRN    RSTAT:BYTE    ; last status from read
  126.     EXTRN    BUFPT:WORD    ; current buffer pointer
  127.     EXTRN    BUFORG:WORD    ; pointer to beginning of buffer
  128.     EXTRN    BUFEND:WORD    ; pointer to end of buffer
  129.     EXTRN    BUFREAD:WORD    ; pointer to where program is reading
  130.     EXTRN    BUFBIG:WORD    ; integer, how many bytes we have
  131.     EXTRN    BUFLIM:WORD    ; integer, max bytes we can have
  132. endif
  133.  
  134. ICNT    DB    00h
  135.  
  136. SAVECS    DW    00H        ; where to save the old interrupt ptr
  137. SAVEIP    DW    00H
  138. LFPP    DB    00h        ; Full Page pointer
  139. DEAF    DB    00H        ; when we can't handle any more packets
  140. OFFS    DW    00H        ; how many times the handler was turned off
  141. UBASE    DW  0b800h    ; base segment for Ungermann-Bass board (jumper set)
  142. ;
  143. ifdef Microsoft
  144. ;_DATA    ends
  145. else
  146.     ENDDS
  147. endif
  148. ;
  149. ;
  150. ;
  151. ;   The subroutines to call from C
  152. ;
  153. ifdef Microsoft
  154. ;_TEXT    segment    public    'CODE'
  155. ;    assume CS:_TEXT
  156.     .code
  157.     PUBLIC    _U1RECV,_U1ETOPEN,_U1ETCLOSE,_U1GETADDR
  158.     PUBLIC    _U1XMIT,_U1ETUPDATE
  159. else
  160.     PSEG
  161.     PUBLIC    U1RECV,U1ETOPEN,U1ETCLOSE,U1GETADDR
  162.     PUBLIC    U1XMIT,U1ETUPDATE
  163. endif
  164.  
  165. ;******************************************************************
  166. ;  ETOPEN
  167. ;     Initialize the Ethernet board, set receive type.
  168. ;
  169. ;  usage:  etopen(s,irq,address,ioaddr)
  170. ;           char s[6];       ethernet address
  171. ;           int irq;         (unused, we don't use no interrupts)
  172. ;           int address         base mem address
  173. ;           int ioaddr       (unused for this board) io base address
  174. ;
  175. ifdef Microsoft
  176. _U1ETOPEN    PROC    FAR
  177. else
  178. U1ETOPEN    PROC    FAR
  179. endif
  180.     PUSH    BP
  181.     MOV    BP,SP
  182.     PUSH    SI
  183.     PUSH    DI
  184.     push    es
  185.     mov    ax,[bp+X+6]    ; parameter for
  186.     mov    UBASE,ax    ; base address
  187.     mov    es,ax        ; set to base address
  188. ;
  189. ;  reset the board by 
  190. ;  reset board, won't work until I set it back
  191.     mov    byte ptr es:[ERESET],080h
  192. ;
  193. ;  loopback
  194. ;
  195.     xor    ax,ax
  196.     mov    byte ptr es:[TMODE],al
  197. ;
  198. ;  turn off receive 
  199.     mov    byte ptr es:[RMODE],al
  200.     mov    al,byte ptr es:[CLRPAV]    ; clear PAV
  201. ;
  202. ;  clear interrupt control
  203.     xor    ax,ax
  204.     mov    byte ptr es:[INTCTL],al
  205. ;
  206. ;  rmask
  207.     mov    byte ptr es:[RMASK],al
  208. ;
  209. ;  tmask
  210.     mov    byte ptr es:[TMASK],al
  211. ;
  212. ;  rstat
  213.     mov    byte ptr es:[RECSTAT],0ffh    ; clear status
  214. ;
  215. ;  tstat
  216.     mov    byte ptr es:[TSTAT],0ffh    ; clear status
  217. ;
  218. ;  move my addr onto board
  219.     PUSH     DS        ; save my DS
  220.     MOV    AX,[BP+X+2]    ; get new one
  221.     MOV    DS,AX           ; set new one
  222.     MOV    SI,[BP+X]    ; get pointer, ds:si is ready
  223.     ;
  224.     MOV    CX,6
  225.     MOV    di,MADDR    ; get base i/o reg for setting address
  226.     CLD
  227.     REP    MOVSB        ; LOAD MY ADDR
  228.  
  229.     POP    DS        ; get back DS of local data
  230. ;
  231. ;  write epp to fpp and clear PAV
  232.     mov    al,byte ptr es:[EPPPAV]
  233.     and    al,07fh        ; mask PAV off
  234.     mov    byte ptr es:[FPP],al    ; no ints, set fpp=epp
  235.     mov    al,byte ptr es:[CLRPAV]
  236. ;
  237. ;
  238. ;  set board back on from reset, causes xmit to loopback
  239.     mov    es:[TSAMSB],0ff0fh    ; set to zero length xmit
  240.     mov    byte ptr es:[ERESET],00
  241. ;
  242. ;  wait for it
  243. waitforit:
  244.     mov    al,byte ptr es:[INTSTAT]    ; status of xmit
  245.     test    al,TDONE
  246.     jz    waitforit
  247. ;
  248. ;  turn off loopback
  249.     mov    byte ptr es:[TMODE],0ah        ; turn on transmit
  250. ;
  251. ;  write epp to fpp and clear PAV
  252.     mov    al,byte ptr es:[EPPPAV]
  253.     and    al,07fh        ; mask PAV off
  254.     mov    byte ptr es:[FPP],al    ; no ints, set fpp=epp
  255.     mov    LFPP,al        ; save copy of FPP
  256.     mov    al,byte ptr es:[CLRPAV]
  257. ;
  258. ;  set to receive certain types of packets
  259.     xor     ax,ax        
  260.     mov    al,MULT        ; which mode
  261.     mov    byte ptr es:[RMODE],al    ; set into reg
  262.  
  263.     xor    ax,ax
  264.     POP    ES
  265.     POP    DI
  266.     POP    SI
  267.     POP    BP
  268.     RET
  269. ifdef Microsoft
  270. _U1ETOPEN    ENDP
  271. else
  272. U1ETOPEN    ENDP
  273. endif
  274. ;
  275. ;
  276. ;*******************************************************************
  277. ;  GETADDR
  278. ;     get the Ethernet address off of the board
  279. ;
  280. ;   usage:  getaddr(s,address,ioaddr);
  281. ;    char s[6];           will get six bytes from the PROM
  282. ;       int address;         segment base address
  283. ;
  284. ifdef Microsoft
  285. _U1GETADDR    PROC    FAR
  286. else
  287. U1GETADDR    PROC    FAR
  288. endif
  289.     PUSH    BP
  290.     MOV    BP,SP
  291.     PUSH    SI
  292.     PUSH    DI
  293.  
  294.     mov    dx,[bp+X+4]    ; get board's base addr
  295.     PUSH     ES        ; save mine
  296.     MOV    AX,[BP+X+2]    ; get new one
  297.     MOV    ES,AX           ; set new one
  298.     MOV    DI,[BP+X]    ; get pointer, es:di is ready
  299.     MOV    SI,EADDR    ; get ether address ptr
  300.     ;
  301.     PUSH    DS
  302.     mov    ds,dx        ; put base addr in DS
  303.     mov    cx,6
  304.     CLD
  305.     REP    MOVSB
  306.  
  307.     POP    DS
  308.  
  309.     POP     ES
  310.     POP    DI
  311.     POP    SI
  312.     POP    BP        
  313.     RET
  314. ifdef Microsoft
  315. _U1GETADDR    ENDP
  316. else
  317. U1GETADDR    ENDP
  318. endif
  319. ;
  320. ;***********************************************************************
  321. ;  ETCLOSE
  322. ;        shut it down
  323. ;
  324. ifdef Microsoft
  325. _U1ETCLOSE    PROC    FAR
  326. else
  327. U1ETCLOSE    PROC    FAR
  328. endif
  329.     RET
  330. ifdef Microsoft
  331. _U1ETCLOSE    ENDP
  332. else
  333. U1ETCLOSE    ENDP
  334. endif
  335. ;
  336. ;
  337. ;************************************************************************
  338. ;  U1XMIT         
  339. ;     send a packet to Ethernet
  340. ;     Is not interrupt driven, just call it when you need it.
  341. ;
  342. ;  usage:   xmit(packet,count)
  343. ;        char *packet;
  344. ;        int count;
  345. ;
  346. ;   Takes a packet raw, Ethernet packets start with destination address,
  347. ;   and puts it out onto the wire.  Count is the length of packet < 2048
  348. ;
  349. ;   checks for packets under the Ethernet size limit of 60 and handles them
  350. ;
  351. ifdef Microsoft
  352. _U1XMIT    PROC    FAR
  353. else
  354. U1XMIT    PROC    FAR
  355. endif
  356.     PUSH    BP
  357.     MOV    BP,SP
  358.     PUSH    SI
  359.     PUSH    DI
  360.     push    es
  361.     mov    ax,ubase
  362.     mov    es,ax        ; base for board
  363.     PUSH    DS        ; set up proper ds for the buffer
  364.     MOV    AX,[BP+X+2]
  365.     MOV    DS,AX
  366.     MOV    SI,[BP+X]    ; offset for buffer
  367.  
  368.     MOV    AX,[BP+X+4]    ; count of bytes
  369.     MOV    CX,AX        ; save a copy, might be less than 60, ok
  370.  
  371.     CMP    AX,60        ; minimum length for Ether
  372.     JNB    OKLEN
  373.     MOV    AX,60        ; make sure size at least 60
  374. OKLEN:
  375.     mov    di,TBUF        ; start of xmit buffer
  376.     MOV    BX,2047        ; total length of buffer-1
  377.     SUB    BX,AX        ; offset from beginning of buffer
  378.     ADD    DI,BX        ; add in to get buffer pointer
  379.     MOV    BX,DI        ; make a copy
  380. ;
  381. ;  check for previous xmit
  382. xwait:
  383.     mov    al,byte ptr es:[INTSTAT]
  384.     and    al,3        ; check TXOK and TXDONE
  385.     cmp    al,3
  386.     jnz    xwait        ; not there yet, wait for it
  387. ;
  388. ;  move the data
  389.     rep    movsb        ; copy into buffer
  390. ;
  391. ;  set address regs and send it
  392.     mov    byte ptr es:[TSTAT],0fh        ; clear xmit status bits
  393.     mov    byte ptr es:[TSALSB],bl        ; address regs
  394.     mov    byte ptr es:[TSAMSB],bh
  395.     mov    al,byte ptr es:[TXINIT]    ; start xmit
  396.     xor     ax,ax
  397.     pop    ds
  398.     pop    es
  399.     POP    DI
  400.     POP    SI
  401.     POP    BP
  402.     RET
  403. ifdef Microsoft
  404. _U1XMIT    ENDP
  405. else
  406. U1XMIT    ENDP
  407. endif
  408. ;
  409. ;
  410. ;***********************************************************************
  411. ;  RECV
  412. ;  Get whatever packets are on the board
  413. ;
  414. ifdef Microsoft
  415. _U1RECV    proc    far
  416. else
  417. U1RECV    proc    far
  418. endif
  419.     push    bp
  420.     PUSH    SI
  421.     PUSH    DI
  422.     push    es
  423. ifdef Microsoft
  424.     MOV    AX,WORD PTR [_BUFPT+2]    ; buffer's ds
  425. else
  426.     MOV    AX,WORD PTR [BUFPT+2]    ; buffer's ds
  427. endif
  428. ifdef Microsoft
  429.     MOV    DI,_BUFPT    ; where buffer is
  430. else
  431.     MOV    DI,BUFPT    ; where buffer is
  432. endif
  433.     MOV    ES,AX
  434.  
  435. ;
  436. ;  check for buffer overrun or catching up with reader
  437. ;
  438. ;  implicit 64K max buffer, should stop before 64K anyway
  439. ;
  440. ifdef Microsoft
  441.     MOV    AX,_BUFBIG    ; how much stuff is in buffer
  442. else
  443.     MOV    AX,BUFBIG    ; how much stuff is in buffer
  444. endif
  445. ifdef Microsoft
  446.     MOV    BX,_BUFLIM    ; what is our size limit?
  447. else
  448.     MOV    BX,BUFLIM    ; what is our size limit?
  449. endif
  450.     CMP    AX,BX
  451.     JNA    ISROOM        ; we are ok
  452. ;
  453. ;  no room at the Inn. 
  454. ;
  455.     JMP    ENDINT        ; can't do much, we lose packets until restarted
  456.  
  457. ;
  458. ;  wrap pointer around at end, we know that we have room
  459. ;
  460. ISROOM:
  461. ifdef Microsoft
  462.     MOV    DX,_BUFEND    ; right before 2K safety area
  463. else
  464.     MOV    DX,BUFEND    ; right before 2K safety area
  465. endif
  466.     CMP    DX,DI        ; see if pointer is over limit
  467.     JA    OKAYREAD    ; we are not at wrap-around
  468.  
  469. ifdef Microsoft
  470.     MOV    AX,_BUFORG    ; wrap to here
  471. else
  472.     MOV    AX,BUFORG    ; wrap to here
  473. endif
  474. ifdef Microsoft
  475.     MOV    _BUFPT,AX    ; wrap-around
  476. else
  477.     MOV    BUFPT,AX    ; wrap-around
  478. endif
  479.     MOV    DI,AX        ; di also
  480. ;
  481. ;  here, DI contains where we want to put the packet.
  482. ;
  483. OKAYREAD:
  484.     inc    di
  485.     inc    di        ; leave space for length of packet
  486.     mov    bl,LFPP        ; local copy of FPP value
  487.     xor    bh,bh        ; clear high byte
  488.     mov    dx,ubase    ; base for board
  489.     push    ds
  490.     mov    ds,dx
  491.  
  492.     mov    al,byte ptr ds:[EPPPAV]    ; see if packet is available
  493.     test    al,PAV        ; see if bit is set
  494.     jnz    IREADONE
  495.     pop    ds
  496.     JMP SHORT STOPINT
  497.  
  498. IREADONE:
  499.     mov    dx,0        ; size of packet is zero
  500. step2:
  501.     mov    cx,0        ; size of packet segment is zero
  502.     mov    si,bx        ; save start of packet segment page # in si
  503.  
  504. step3:
  505.     push    bx        ; save LFPP value
  506.     add    bx,RPIDX    ; get into page index
  507.     mov    al,byte ptr ds:[bx]        ; get page index byte
  508.     pop    bx
  509.  
  510.     xor    ah,ah
  511.     push    ax        ; save end of packet marker
  512.     and    al,07fh        ; mask off last packet bit
  513.     inc    al        ; size is value+1
  514.     add    cx,ax        ; making total size of packet segment
  515.     inc    bl        ; increment page pointer
  516.     cmp    bl,05fh
  517.     jng    nopwrap
  518.     mov    bl,0        ; wrap around at 60h (96)
  519. nopwrap:
  520.     mov    al,byte ptr ds:[EPPPAV]    ; have we read all used pages?
  521.     and    al,EPP
  522.     cmp    al,bl        ; is EPP = LFPP?
  523.     jne    notend
  524.     mov    al,byte ptr ds:[CLRPAV]    
  525.                 ; clear packet available to make board contin.
  526. notend:
  527.     pop    ax        ; get back end-of packet marker
  528.     test    al,080h        ; is it end of packet?
  529.     jnz    dopack        ; no, get next page of packet
  530.     or    bl,bl        ; test to see if packet wraps around end
  531.     jnz    step3        ; keep adding to size
  532.  
  533. dopack:
  534. ;  move the packet into our local buffer ds:si to es:di
  535. ;     cx is size, bl is page #, al is saving EOP mark, dx is accumulated size
  536. ;     of packet
  537.     push    ax    
  538.     push    bx        ; save incremented bl
  539.     mov    bx,si        ; get back saved value from before increment
  540.     xor    al,al        ; clear low byte, load high byte
  541.     mov    ah,bl        ; multiply *256, then divide by 2 =
  542.     shr    ax,1        ; multiply * 128
  543.     add    ax,RBUF        ; add offset of rec buffer
  544.     mov    si,ax        ; this is where data resides
  545.  
  546.     add    dx,cx        ; add in to size of packet
  547.  
  548.     rep    movsb        ; copy the packet or portion of packet
  549.  
  550.     pop    bx        ; get back incremented bl
  551.     mov    byte ptr ds:[FPP],bl    ; write full page pointer where it is now
  552.     pop    ax
  553.     test    al,080h        ; was this the end of the packet?
  554.     jz    step2        ; if not, read next section of packet
  555.  
  556.     pop    ds        ; work with local data again
  557. ;
  558. ;
  559. ;  DI now contains updated value for BUFPT, BX contains size of packet
  560. ;
  561.     mov    LFPP,bl        ; store local fpp where we need it
  562. ifdef Microsoft
  563.     mov    bx,_BUFPT    ; get where size field for this packet goes
  564. else
  565.     mov    bx,BUFPT    ; get where size field for this packet goes
  566. endif
  567.     mov    ES:[bx],dx        ; put the accumulated size there
  568.  
  569. ifdef Microsoft
  570.     MOV    _BUFPT,DI    ; IT IS HERE, NOW
  571. else
  572.     MOV    BUFPT,DI    ; IT IS HERE, NOW
  573. endif
  574.  
  575. ifdef Microsoft
  576.     MOV    AX,_BUFBIG    ; TOTAL AMOUNT OF STUFF IN BUFFER
  577. else
  578.     MOV    AX,BUFBIG    ; TOTAL AMOUNT OF STUFF IN BUFFER
  579. endif
  580.     ADD    AX,DX        ; add in size of this packet
  581.     INC    AX
  582.     INC    AX        ; TO COVER THE LENGTH VALUE
  583. ifdef Microsoft
  584.     MOV    _BUFBIG,AX    ; AFTER ADDING IN CURRENT PACKET SIZE
  585. else
  586.     MOV    BUFBIG,AX    ; AFTER ADDING IN CURRENT PACKET SIZE
  587. endif
  588. ;
  589. ;  signs that something is actually happening
  590. ;
  591. ;    MOV    AX,0B000H       ; screen
  592. ;    MOV    ES,AX
  593. ;    MOV    DI,3998        ; lower right corner
  594. ;    INC    ICNT
  595. ;    MOV    al,ICNT    ; character
  596. ;    STOSB
  597.  
  598. ;
  599. ;  set up to read the next packet from the net
  600. ;
  601. STOPINT:
  602.  
  603. ENDINT:
  604.     pop    es
  605.     POP    DI
  606.     POP    SI
  607.     POP    BP
  608.     RET
  609. ifdef Microsoft
  610. _U1RECV    ENDP
  611. else
  612. U1RECV    ENDP
  613. endif
  614.  
  615. ;
  616. ;*************************************************************************
  617. ;  ETUPDATE
  618. ;      update pointers and/or restart receiver when read routine has
  619. ;      already removed the current packet
  620. ;
  621. ifdef Microsoft
  622. _U1ETUPDATE    PROC    FAR
  623. else
  624. U1ETUPDATE    PROC    FAR
  625. endif
  626.     PUSH     ES
  627. ifdef Microsoft
  628.     MOV    AX,WORD PTR [_BUFPT+2]    ; establish data segment to buffer
  629. else
  630.     MOV    AX,WORD PTR [BUFPT+2]    ; establish data segment to buffer
  631. endif
  632.     MOV    ES,AX        ; put that in es
  633. ;
  634. ifdef Microsoft
  635.     MOV    BX,_BUFREAD    ; where read pointer is now
  636. else
  637.     MOV    BX,BUFREAD    ; where read pointer is now
  638. endif
  639.     MOV    DX,ES:[BX]    ; get size of this packet
  640.     INC    DX
  641.     INC    DX        ; TWO MORE FOR LENGTH VALUE
  642.  
  643.     ADD    BX,DX        ; increment bufread by size of packet
  644.  
  645. ifdef Microsoft
  646.     MOV    CX,_BUFEND    ; right before 2K safety area
  647. else
  648.     MOV    CX,BUFEND    ; right before 2K safety area
  649. endif
  650.     CMP    BX,CX        ; see if pointer is over limit
  651.     JB    NOWRAPRD    ; we are not at wrap-around
  652.     
  653. ifdef Microsoft
  654.     MOV    BX,_BUFORG    ; wrap to here
  655. else
  656.     MOV    BX,BUFORG    ; wrap to here
  657. endif
  658. NOWRAPRD:
  659. ifdef Microsoft
  660.     MOV    _BUFREAD,BX    ; buffer pointer has been updated
  661. else
  662.     MOV    BUFREAD,BX    ; buffer pointer has been updated
  663. endif
  664.  
  665. ;
  666. ;  DECREMENT TOTAL BUFFER SIZE
  667. ;
  668.     CLI            ; keep interrupt handler from bothering dec
  669. ifdef Microsoft
  670.     MOV    CX,_BUFBIG    ; size before removing packet
  671. else
  672.     MOV    CX,BUFBIG    ; size before removing packet
  673. endif
  674.     SUB    CX,DX        ; remove size of current packet
  675. ifdef Microsoft
  676.     MOV    _BUFBIG,CX    ; put it back
  677. else
  678.     MOV    BUFBIG,CX    ; put it back
  679. endif
  680.     STI
  681. ;
  682. ;  IF RECEIVER IS ON, THEN CHECKING BUFLIM IS UNNECESSARY.
  683. ;
  684.     MOV    AL,DEAF        ; is the receiver turned off?
  685.     OR    AL,AL        ; 0 = reading, 1 = deaf
  686.     JZ    ALIVE
  687. ;
  688. ;  CHECK FOR ROOM IN THE BUFFER, IF THERE IS, TURN ON RECEIVER
  689. ;
  690. ifdef Microsoft
  691.     MOV    AX,_BUFLIM    ; what is our limit?
  692. else
  693.     MOV    AX,BUFLIM    ; what is our limit?
  694. endif
  695.     CMP    CX,AX        ; compare to limit
  696.     JA    ALIVE        ; not really alive, but can't turn on yet
  697.  
  698.     XOR    AL,AL
  699.     MOV    DEAF,AL        ; reset flag
  700.  
  701.     INC    OFFS        ; keep count how many times this happened
  702.  
  703. ALIVE:
  704.     POP    ES
  705.     RET    
  706. ifdef Microsoft
  707. _U1ETUPDATE    ENDP
  708. else
  709. U1ETUPDATE    ENDP
  710. endif
  711.  
  712. ifdef Microsoft
  713. ;_TEXT    ends
  714. else
  715.     ENDPS
  716. endif
  717.     END
  718.