home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / NCSA / TEL2307S.ZIP / NET / ENET / NETZYP.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-10-21  |  17.0 KB  |  817 lines

  1. ; Driver for Ungermann-Bass NICps/2 Zypher interface
  2. ; Tim Krauskopf
  3. ;
  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.  
  18.     TITLE    NETSUPPORT -- LOW LEVEL DRIVERS FOR ETHERNET
  19. ;
  20. ;  Tim Krauskopf
  21. ;  National Center for Supercomputing Applications
  22. ;  9/1/87  Ungermann-Bass driver started, PC bus
  23. ;  12/28/87 UB NIC driver started, Zypher interface
  24. ;
  25. ;
  26. ;Microsoft EQU 1
  27. ;Lattice EQU 1
  28. ifndef Microsoft
  29.     ifndef Lattice
  30.         if2
  31.             %out
  32.             %out ERROR: You have to specify "/DMicrosoft" OR "/DLattice" on the
  33.             %out        MASM command line to determine the type of assembly.
  34.             %out
  35.         endif
  36.         end
  37.     endif
  38. endif
  39.  
  40.     NAME    NET
  41. ifdef Microsoft
  42. X    EQU    6
  43.     DOSSEG
  44.     .MODEL    LARGE
  45. else
  46.     INCLUDE    DOS.MAC
  47.     SETX
  48. endif
  49. ifdef MSC6
  50.     INCLUDE NET\ENET\ZYPDEFS.INC
  51. else
  52.     INCLUDE ZYPDEFS.INC
  53. endif
  54. ;
  55. ;
  56. ;  Data segment
  57. ;
  58. ifdef Microsoft
  59. ;DGROUP    group    _DATA
  60. ;_DATA    segment    public 'DATA'
  61. ;    assume    DS:DGROUP
  62.     .data
  63. else
  64.     DSEG
  65. endif
  66. ;
  67. ;  The pointers below are actually DWORDs but we access them two
  68. ;  bytes at a time.
  69. ;
  70. ; STAT change to RSTAT because of name clash with MSC library routine
  71. ifdef Microsoft
  72.     EXTRN    _RSTAT:BYTE    ; last status from read
  73.     EXTRN    _BUFPT:WORD    ; current buffer pointer
  74.     EXTRN    _BUFORG:WORD    ; pointer to beginning of buffer
  75.     EXTRN    _BUFEND:WORD    ; pointer to end of buffer
  76.     EXTRN    _BUFREAD:WORD    ; pointer to where program is reading
  77.     EXTRN    _BUFBIG:WORD    ; integer, how many bytes we have
  78.     EXTRN    _BUFLIM:WORD    ; integer, max bytes we can have
  79. else
  80.     EXTRN    RSTAT:BYTE    ; last status from read
  81.     EXTRN    BUFPT:WORD    ; current buffer pointer
  82.     EXTRN    BUFORG:WORD    ; pointer to beginning of buffer
  83.     EXTRN    BUFEND:WORD    ; pointer to end of buffer
  84.     EXTRN    BUFREAD:WORD    ; pointer to where program is reading
  85.     EXTRN    BUFBIG:WORD    ; integer, how many bytes we have
  86.     EXTRN    BUFLIM:WORD    ; integer, max bytes we can have
  87. endif
  88.  
  89. SAVECS    DW    00H        ; where to save the old interrupt ptr
  90. SAVEIP    DW    00H
  91. LFPP    DB    00h        ; Full Page pointer
  92. DEAF    DB    00H        ; when we can't handle any more packets
  93. OFFS    DW    00H        ; how many times the handler was turned off
  94. ;
  95. ;
  96. ; Zypher definitions to work with
  97. ;
  98. Init_ZCB    LABEL    WORD
  99.     db    Initialize_Cmd
  100.     db    0    ; Status
  101.     db    0    ; Result
  102.     db    0    ; Report_Code
  103.     dw    0    ; Options
  104.     dd    0    ; Post_Routine
  105.     dw    2 dup (0)
  106.     dw    0    ; Modes
  107.     dw    1100    ; Max_Xmt_Length
  108.     dw    1    ; Num_Xmt_Buffers
  109.     dw    1514    ; Max_Rcv_Size
  110.     dw    12    ; Num_Rcv_Buffers
  111.     dw    0    ; Max_Multicast_Addresses
  112.     dw    7 dup (0)    ; reserved
  113.     dw    0    ; Acquired Modes
  114.     dw    0    ; Acquired Max_Xmt_Length
  115.     dw    0    ; Acquired Num_Xmt_Buffers
  116.     dw    0    ; Acquired Max_Rcv_Size
  117.     dw    0    ; Acquired Num_Rcv_Buffers
  118.     dw    0    ; Acquired Max_Multicast_Addresses
  119.     dw    3 dup (0)    ; reserved
  120.  
  121. Init2_ZCB    LABEL    WORD
  122.     db    Initialize_Cmd
  123.     db    0    ; Status
  124.     db    0    ; Result
  125.     db    0    ; Report_Code
  126.     dw    0    ; Options
  127.     dd    0    ; Post_Routine
  128.     dw    2 dup (0)
  129.     dw    0    ; Modes
  130.     dw    1100    ; Max_Xmt_Length
  131.     dw    1    ; Num_Xmt_Buffers
  132.     dw    1514    ; Max_Rcv_Size
  133.     dw    12    ; Num_Rcv_Buffers
  134.     dw    0    ; Max_Multicast_Addresses
  135.     dw    7 dup (0)    ; reserved
  136.     dw    0    ; Acquired Modes
  137.     dw    0    ; Acquired Max_Xmt_Length
  138.     dw    0    ; Acquired Num_Xmt_Buffers
  139.     dw    0    ; Acquired Max_Rcv_Size
  140.     dw    0    ; Acquired Num_Rcv_Buffers
  141.     dw    0    ; Acquired Max_Multicast_Addresses
  142.     dw    3 dup (0)    ; reserved
  143.  
  144.  
  145. Stat_ZCB    LABEL    WORD
  146.     db    Status_Cmd
  147.     db    0    ; Status
  148.     db    0    ; Result
  149.     db    0    ; Report_Code
  150.     dw    0    ; Options
  151.     dd    0    ; Post_Routine
  152.     dw    2 dup (0)
  153.     dw    0    ; state
  154.     dw    0    ; modes
  155.     dw    0    ; Max_Xmt_Length
  156.     dw    0    ; Act Num_Xmt_Buffers
  157.     dw    0    ; Act Max_Rcv_Size
  158.     dw    0    ; Act Num_Rcv_Buffers
  159.     db    6 dup (0)    ; unique ID
  160.     dw    0,0    ; total xmts
  161.     dw    0,0    ; total rcvs
  162.     dw    0,0    ; CRC errors
  163.     dw    0,0    ; ALN errors
  164.     dw    0,0    ; RSC errors
  165.     dw    0,0    ; OVR errors
  166.     dw    12 dup (0)    ; reserved
  167.  
  168. Xmt_ZCB    LABEL    WORD
  169.     db    Transmit_Cmd
  170.     db    0    ; Status
  171.     db    0    ; Result
  172.     db    0    ; Report_Code
  173.     dw    0    ; Options
  174.     dd    0
  175.     dw    2 dup (0)
  176.     dw    0    ; Xmt_Length
  177.     dw    0,0    ; Xmt_Buffer
  178.     dw    0    ; hardware status
  179.     db    0,0    ; Xmt_Bfr_ID and an unused byte
  180.     dw    0,0    ; Xmt_Bfr_Address (on-card transmit buffer address)
  181.  
  182. Cancel_ZCB    LABEL    WORD
  183.     db    Cancel_Receives_Cmd
  184.     db    0    ; Status
  185.     db    0    ; Result
  186.     db    0    ; Report_Code
  187.     dw    0    ; Options
  188.     dd    0    ; Post_Routine
  189.     dw    2 dup (0)
  190.  
  191.  
  192. Recv_ZCB    LABEL    WORD
  193.     db    Receive_Cmd
  194.     db    0    ; Status
  195.     db    0    ; Result
  196.     db    0    ; Report_Code
  197.     dw    0    ; Options
  198.     dd    0
  199.     dw    2 dup (0)
  200. ;            db    SIZE ZCB_Header dup (0)
  201. ;ZCB_Rcv_Mode        db    0
  202.     db    0
  203. ;ZCB_Rcv_Status        db    0
  204.     db    0
  205. ;ZCB_Rcv_Buffer_Size    dw    0    ; Size of user's buffer.
  206.     dw    1514            ; always this much room
  207. ;ZCB_Rcv_Buffer_Address    dd    0    ; Address of user's buffer.
  208.     dd    0
  209. ;ZCB_Rcv_Data_Length    dw    0    ; Bytes copied to user's buffer.
  210.     dw    0
  211. ;ZCB_Rcv_Frame_Count    dw    0    ; Count of as-yet-uncopied bytes left;
  212.     dw    0
  213.                     ;  in frame.
  214. ;ZCB_Rcv_Hdwr_Status    dw    0    ; Status reported by 82586.
  215.     dw    0
  216. ;ZCB_Rcv_Frame_ID    dw    0    ; Frame ID for "incremental mode".
  217.     dw    0
  218. ;ZCB_Rcv_Bfr_Ptr        dw    0,0    ; Address of next as-yet-uncopied byte
  219.     dw    0,0
  220.                     ;  of frame in on-card receive buffer.
  221. ;ZCB_Rcv_Bfr_Count    dw    0    ; Count of as-yet-uncopied bytes in
  222.     dw    0
  223.                     ;  current on-card receive buffer.
  224. ;ZCB_Rcv_Descriptor    dw    0,0    ; Address of 82586 RBD (Receive Buffer
  225.     dw    0,0
  226.                     ;  Descriptor) for current on-card
  227.                     ;  receive buffer.
  228.  
  229.  
  230. ifdef Microsoft
  231. ;_DATA    ends
  232. else
  233.     ENDDS
  234. endif
  235. ;
  236. ;
  237. ;
  238. ;   The subroutines to call from C
  239. ;
  240. ifdef Microsoft
  241. ;_TEXT    segment    public    'CODE'
  242. ;    assume CS:_TEXT
  243.     .code
  244.     PUBLIC    _U2RECV,_U2ETOPEN,_U2ETCLOSE,_U2GETADDR
  245.     PUBLIC    _U2XMIT,_U2ETUPDATE
  246. else
  247.     PSEG
  248.     PUBLIC    U2RECV,U2ETOPEN,U2ETCLOSE,U2GETADDR
  249.     PUBLIC    U2XMIT,U2ETUPDATE
  250. endif
  251.  
  252. ZYP_Entry    LABEL    DWORD
  253.     dw    0, 0D000h
  254.  
  255. ;******************************************************************
  256. ;  ETOPEN
  257. ;     Initialize the Ethernet board, set receive type.
  258. ;
  259. ;  usage:  etopen(s,irq,addr,ioaddr)
  260. ;           char s[6];       ethernet address
  261. ;           int irq,addr,ioaddr;     
  262. ;                interrupt number, base mem address and
  263. ;                i/o address to use
  264. ;
  265. ;
  266. ifdef Microsoft
  267. _U2ETOPEN    PROC    FAR
  268. else
  269. U2ETOPEN    PROC    FAR
  270. endif
  271.     PUSH    BP
  272.     MOV    BP,SP
  273.     PUSH    SI
  274.     PUSH    DI
  275.     push    es
  276.     push    ds
  277.  
  278.     mov    ax,ds
  279.     mov    es,ax        ; set to base address for NCB
  280. ;
  281. ;   Set base address for board into ZYP_Entry
  282. ;
  283.     mov    ax,[X+BP+6]    ; base address for board as installed
  284.     mov word ptr cs:[ZYP_Entry+2],ax    ; store
  285. ;
  286. ;    try shutting the board down first
  287. ;
  288. ;    MOV    BX,offset Cancel_ZCB
  289. ;    CALL    ZYP_Entry
  290. ;closeit:
  291. ;    CMP    [BX].ZCB_Status,0FFh
  292. ;    JE    closeit
  293. ;
  294. ;    now reopen it
  295. ;
  296.     MOV    BX,offset Init2_ZCB
  297.     CALL    ZYP_Entry
  298. Init_wait:
  299.     CMP    [BX].ZCB_Status,0FFh
  300.     JE    Init_wait
  301.  
  302. ;
  303. ; call ZYP receive
  304. ;
  305.     mov    bx,offset Recv_ZCB
  306. ifdef Microsoft
  307.     mov    ax,word ptr [_BUFPT+2]    ; where packet should arrive
  308. else
  309.     mov    ax,word ptr [BUFPT+2]    ; where packet should arrive
  310. endif
  311. ifdef Microsoft
  312.     mov    di,word ptr [_BUFPT]
  313. else
  314.     mov    di,word ptr [BUFPT]
  315. endif
  316.     inc    di
  317.     inc    di
  318.     ; address of packet into NCB
  319.     mov    word ptr [bx].ZCB_Rcv_Buffer_Address,di
  320.     mov    word ptr [bx].ZCB_Rcv_Buffer_Address+2,ax
  321.     CALL    ZYP_Entry
  322.  
  323.     xor    ax,ax
  324. getout:
  325.     pop    ds
  326.     POP    ES
  327.     POP    DI
  328.     POP    SI
  329.     POP    BP
  330.     RET
  331. ifdef Microsoft
  332. _U2ETOPEN    ENDP
  333. else
  334. U2ETOPEN    ENDP
  335. endif
  336. ;
  337. ;
  338. ;*******************************************************************
  339. ;  GETADDR
  340. ;     get the Ethernet address off of the board
  341. ;
  342. ;   usage:  getaddr(s,address,ioaddr);
  343. ;    char s[6];           will get six bytes from the PROM
  344. ;       int address;
  345. ;       int ioaddr;     mem address and ioaddress to use
  346. ;
  347. ;
  348. ifdef Microsoft
  349. _U2GETADDR    PROC    FAR
  350. else
  351. U2GETADDR    PROC    FAR
  352. endif
  353.     PUSH    BP
  354.     MOV    BP,SP
  355.     PUSH    SI
  356.     PUSH    DI
  357.     PUSH     ES        ; save mine
  358.     push    ds
  359.  
  360.     mov    ax,ds
  361.     mov    es,ax
  362. ;
  363. ;   Set base address for board into ZYP_Entry
  364. ;
  365.     mov    ax,[X+BP+4]    ; base address for board as installed
  366.     mov word ptr cs:[ZYP_Entry+2],ax    ; store
  367. ;
  368. ;
  369.     MOV    BX,offset Init_ZCB
  370.     CALL    ZYP_Entry
  371. ifdef OLD_WAY
  372. Init_wt:
  373.     CMP    [BX].ZCB_Status,0FFh
  374.     JE    Init_wt
  375. else
  376.     MOV AX,0
  377. Init_wt:
  378.     INC AX
  379.     CMP AX,0ffh
  380.     JE  getaddr_timeout
  381.     CMP [BX].ZCB_Status,0FFh
  382.     JE    Init_wt
  383. getaddr_timeout:
  384. endif
  385.  
  386. ;    CMP    [BX].ZCB_Result,Initialization_Complete
  387. ;    JNE    oh_well
  388.  
  389.     MOV    BX,offset Stat_ZCB
  390.     CALL    ZYP_Entry
  391. addr_wait:
  392.     CMP    [BX].ZCB_Status,0FFh
  393.     JE    addr_wait
  394.     CMP    [BX].ZCB_Result,Status_Complete
  395.     JE    get_addr
  396. oh_well:
  397.     mov    ax,-1
  398.     jmp SHORT nomore
  399.  
  400. get_addr:
  401.     MOV    AX,[BP+X+2]    ; get new one
  402.     MOV    ES,AX           ; set new one
  403.     MOV    DI,[BP+X]    ; get pointer, es:di is ready
  404.     MOV    SI,BX
  405.     add    si,ZCB_Stat_Unique_ID
  406.     ;
  407.     mov    cx,3
  408.     CLD
  409.     rep movsw        ; copy address
  410.     xor    ax,ax
  411. nomore:
  412.     pop    ds
  413.     POP     ES
  414.     POP    DI
  415.     POP    SI
  416.     POP    BP        
  417.     RET
  418. ifdef Microsoft
  419. _U2GETADDR    ENDP
  420. else
  421. U2GETADDR    ENDP
  422. endif
  423. ;
  424. ;***********************************************************************
  425. ;  ETCLOSE
  426. ;        shut it down
  427. ;
  428. ifdef Microsoft
  429. _U2ETCLOSE    PROC    FAR
  430. else
  431. U2ETCLOSE    PROC    FAR
  432. endif
  433.     push    bp
  434.     push    si
  435.     push    di
  436.     push    es
  437.     push    ds
  438.     mov    ax,ds
  439.     mov    es,ax
  440.  
  441.     MOV    BX,offset Cancel_ZCB
  442.     CALL    ZYP_Entry
  443. canwait:
  444.     CMP    [BX].ZCB_Status,0FFh
  445.     JE    canwait
  446.  
  447.     pop    ds
  448.     pop    es
  449.     pop    di
  450.     pop    si
  451.     pop    bp
  452.     RET
  453. ifdef Microsoft
  454. _U2ETCLOSE    ENDP
  455. else
  456. U2ETCLOSE    ENDP
  457. endif
  458. ;
  459. ;
  460. ;************************************************************************
  461. ;  XMIT         
  462. ;     send a packet to Ethernet
  463. ;     Is not interrupt driven, just call it when you need it.
  464. ;
  465. ;  usage:   xmit(packet,count)
  466. ;        char *packet;
  467. ;        int count;
  468. ;
  469. ;   Takes a packet raw, Ethernet packets start with destination address,
  470. ;   and puts it out onto the wire.  Count is the length of packet < 2048
  471. ;
  472. ;   checks for packets under the Ethernet size limit of 60 and handles them
  473. ;
  474. ifdef Microsoft
  475. _U2XMIT    PROC    FAR
  476. else
  477. U2XMIT    PROC    FAR
  478. endif
  479.     PUSH    BP
  480.     MOV    BP,SP
  481.     PUSH    SI
  482.     PUSH    DI
  483.     push    es
  484.     push    ds
  485.  
  486.     MOV    CX,[BP+X+2]    ; ds for buffer
  487.     MOV    SI,[BP+X]    ; offset for buffer
  488.  
  489.     MOV    AX,[BP+X+4]    ; count of bytes
  490.     cmp    ax,1100
  491.     jle    oklen
  492.     mov    ax,1100        ; maximum for me
  493. oklen:
  494. ;
  495. ;  place into Xmit parms
  496. ;
  497.     MOV    BX,offset Xmt_ZCB    ; Start the 1st transmit, using
  498.     mov    word ptr [bx].ZCB_Xmt_Data_Address,si
  499.     mov    word ptr [bx].ZCB_Xmt_Data_Address+2,CX
  500.     mov    [bx].ZCB_Xmt_Data_Length,ax
  501.  
  502.     mov    ax,ds
  503.     mov    es,ax        ; base for ZCB block
  504.  
  505.     CALL    ZYP_Entry
  506.  
  507. ifdef OLD_WAY
  508. waitstat:
  509.     CMP    [BX].ZCB_Status,0FFh
  510.     JE    waitstat
  511. else
  512.     MOV AX,0
  513. waitstat:
  514.     INC AX
  515.     CMP AX,0ffh
  516.     JE  timeout
  517.     CMP [BX].ZCB_Status,0FFh
  518.     JE  waitstat
  519. timeout:
  520. endif
  521.  
  522.     xor    ax,ax
  523. ;    CMP    [BX].ZCB_Result,Initialization_Complete
  524. ;    JE    xmitok
  525.     
  526. ;    mov    al,[BX].ZCB_Result
  527. xmitok:
  528.  
  529.     pop    ds
  530.     pop    es
  531.     POP    DI
  532.     POP    SI
  533.     POP    BP
  534.     RET
  535. ifdef Microsoft
  536. _U2XMIT    ENDP
  537. else
  538. U2XMIT    ENDP
  539. endif
  540. ;
  541. ;
  542. ;***********************************************************************
  543. ;   Receive
  544. ;   This is a CPU hook for boards that must be polled before we can
  545. ;   deliver packets into the receive buffer.  (i.e. no interrupts used)
  546. ;
  547. ;    usage:  recv();
  548. ;
  549. ;
  550. ifdef Microsoft
  551. _U2RECV    proc    far
  552. else
  553. U2RECV    proc    far
  554. endif
  555.     push    bp
  556.     PUSH    SI
  557.     PUSH    DI
  558.     push    es
  559.     push    ds
  560. ;
  561.     mov    bx,offset Recv_ZCB
  562.     CMP    [BX].ZCB_Status,0FFh ; status byte for outstanding read request
  563.  
  564.     JNE    newpkt
  565. ;
  566. ; no packet yet, skip
  567. ;
  568.     pop    ds
  569.     pop    es
  570.     POP    DI
  571.     POP    SI
  572.     pop    bp
  573.     ret            ; no packet arrival yet
  574.  
  575. newpkt:
  576.     mov    dx,[bx].ZCB_Rcv_Data_Length    ; length of recieved packet
  577.  
  578. ifdef Microsoft
  579.     MOV    aX,word ptr [_BUFPT+2]    ; buffer's ds
  580. else
  581.     MOV    aX,word ptr [BUFPT+2]    ; buffer's ds
  582. endif
  583. ifdef Microsoft
  584.     mov    bx,word ptr [_BUFPT]    ; get where size field for this packet goes
  585. else
  586.     mov    bx,word ptr [BUFPT]    ; get where size field for this packet goes
  587. endif
  588.  
  589.     mov    es,ax
  590.     mov    es:[bx],dx        ; put the accumulated size there
  591.  
  592.     add    bx,dx        ; add length to bufpt
  593.     inc    bx
  594.     inc    bx
  595.  
  596. ifdef Microsoft
  597.     MOV    word ptr [_BUFPT],bx    ; it is here, now
  598. else
  599.     MOV    word ptr [BUFPT],bx    ; it is here, now
  600. endif
  601.  
  602. ifdef Microsoft
  603.     MOV    AX,word ptr [_BUFBIG]    ; total amount of stuff in buffer
  604. else
  605.     MOV    AX,word ptr [BUFBIG]    ; total amount of stuff in buffer
  606. endif
  607.  
  608.     ADD    AX,DX        ; add in size of this packet
  609.     INC    AX
  610.     INC    AX        ; to cover the length value
  611.  
  612. ifdef Microsoft
  613.     MOV    word ptr [_BUFBIG],AX    ; after adding in current packet size
  614. else
  615.     MOV    word ptr [BUFBIG],AX    ; after adding in current packet size
  616. endif
  617.  
  618. ;
  619. ;  set up to read the next packet from the net
  620. ;
  621.  
  622. ifdef Microsoft
  623.     MOV    aX,word ptr [_BUFPT+2]    ; buffer's ds
  624. else
  625.     MOV    aX,word ptr [BUFPT+2]    ; buffer's ds
  626. endif
  627. ifdef Microsoft
  628.     MOV    DI,word ptr [_BUFPT]     ; where buffer is
  629. else
  630.     MOV    DI,word ptr [BUFPT]     ; where buffer is
  631. endif
  632.     mov    es,ax
  633.  
  634. ;
  635. ;  check for buffer overrun or catching up with reader
  636. ;
  637. ;  implicit 64K max buffer, should stop before 64K anyway
  638. ;
  639. ifdef Microsoft
  640.     MOV    AX,_BUFBIG    ; how much stuff is in buffer
  641. else
  642.     MOV    AX,BUFBIG    ; how much stuff is in buffer
  643. endif
  644. ifdef Microsoft
  645.     MOV    BX,_BUFLIM    ; what is our size limit?
  646. else
  647.     MOV    BX,BUFLIM    ; what is our size limit?
  648. endif
  649.     CMP    AX,BX
  650.     JNA    ISROOM        ; we are ok
  651. ;
  652. ;  no room at the Inn. 
  653. ;
  654.     JMP SHORT ENDINT      ; can't do much, we lose packets until restarted
  655.  
  656. ;
  657. ;  wrap pointer around at end, we know that we have room
  658. ;
  659. ISROOM:
  660. ifdef Microsoft
  661.     MOV    DX,word ptr [_BUFEND]    ; right before 2K safety area
  662. else
  663.     MOV    DX,word ptr [BUFEND]    ; right before 2K safety area
  664. endif
  665.     CMP    DX,DI        ; see if pointer is over limit
  666.     JA    OKAYREAD    ; we are not at wrap-around
  667.  
  668. ifdef Microsoft
  669.     MOV    AX,word ptr [_BUFORG]    ; wrap to here
  670. else
  671.     MOV    AX,word ptr [BUFORG]    ; wrap to here
  672. endif
  673. ifdef Microsoft
  674.     MOV    word ptr [_BUFPT],AX    ; wrap-around
  675. else
  676.     MOV    word ptr [BUFPT],AX    ; wrap-around
  677. endif
  678.     MOV    DI,AX        ; di also
  679. ;
  680. ;  here, DI contains where we want to put the packet.
  681. ;
  682. OKAYREAD:
  683.     inc    di
  684.     inc    di        ; leave space for length of packet
  685. ;
  686. ;
  687. ; call receive again
  688. ;
  689.     mov    bx,offset Recv_ZCB
  690.     ; address of packet into NCB
  691.     mov    word ptr [bx].ZCB_Rcv_Buffer_Address,di
  692.     mov    word ptr [bx].ZCB_Rcv_Buffer_Address+2,es
  693.     mov    ax,ds
  694.     mov    es,ax
  695.     CALL    ZYP_Entry
  696.  
  697. STOPINT:
  698.  
  699. ENDINT:
  700.     pop    ds
  701.     pop    es
  702.     POP    DI
  703.     POP    SI
  704.     POP    BP
  705.     RET
  706. ifdef Microsoft
  707. _U2RECV    ENDP
  708. else
  709. U2RECV    ENDP
  710. endif
  711.  
  712. ;
  713. ;*************************************************************************
  714. ;  ETUPDATE
  715. ;      update pointers and/or restart receiver when read routine has
  716. ;      already removed the current packet
  717. ;
  718. ifdef Microsoft
  719. _U2ETUPDATE    PROC    FAR
  720. else
  721. U2ETUPDATE    PROC    FAR
  722. endif
  723.     PUSH     ES
  724.  
  725. ifdef Microsoft
  726.     MOV    AX,word ptr [_BUFPT+2] ; establish data segment to buffer
  727. else
  728.     MOV    AX,word ptr [BUFPT+2] ; establish data segment to buffer
  729. endif
  730.     MOV    ES,AX        ; put that in es
  731. ;
  732. ifdef Microsoft
  733.     MOV    BX,word ptr [_BUFREAD]    ; where read pointer is now
  734. else
  735.     MOV    BX,word ptr [BUFREAD]    ; where read pointer is now
  736. endif
  737.     MOV    DX,ES:[BX]    ; get size of this packet
  738.     INC    DX
  739.     INC    DX        ; TWO MORE FOR LENGTH VALUE
  740.  
  741.     ADD    BX,DX        ; increment bufread by size of packet
  742.  
  743. ifdef Microsoft
  744.     MOV    CX,word ptr [_BUFEND]    ; right before 2K safety area
  745. else
  746.     MOV    CX,word ptr [BUFEND]    ; right before 2K safety area
  747. endif
  748.     CMP    BX,CX        ; see if pointer is over limit
  749.     JB    NOWRAPRD    ; we are not at wrap-around
  750.     
  751. ifdef Microsoft
  752.     MOV    BX,_BUFORG    ; wrap to here
  753. else
  754.     MOV    BX,BUFORG    ; wrap to here
  755. endif
  756. NOWRAPRD:
  757. ifdef Microsoft
  758.     MOV    _BUFREAD,BX    ; buffer pointer has been updated
  759. else
  760.     MOV    BUFREAD,BX    ; buffer pointer has been updated
  761. endif
  762.  
  763. ;
  764. ;  DECREMENT TOTAL BUFFER SIZE
  765. ;
  766.     CLI            ; keep interrupt handler from bothering dec
  767. ifdef Microsoft
  768.     MOV    CX,_BUFBIG    ; size before removing packet
  769. else
  770.     MOV    CX,BUFBIG    ; size before removing packet
  771. endif
  772.     SUB    CX,DX        ; remove size of current packet
  773. ifdef Microsoft
  774.     MOV    _BUFBIG,CX    ; put it back
  775. else
  776.     MOV    BUFBIG,CX    ; put it back
  777. endif
  778.     STI
  779. ;
  780. ;  IF RECEIVER IS ON, THEN CHECKING BUFLIM IS UNNECESSARY.
  781. ;
  782.     MOV    AL,DEAF        ; is the receiver turned off?
  783.     OR    AL,AL        ; 0 = reading, 1 = deaf
  784.     JZ    ALIVE
  785. ;
  786. ;  CHECK FOR ROOM IN THE BUFFER, IF THERE IS, TURN ON RECEIVER
  787. ;
  788. ifdef Microsoft
  789.     MOV    AX,_BUFLIM    ; what is our limit?
  790. else
  791.     MOV    AX,BUFLIM    ; what is our limit?
  792. endif
  793.     CMP    CX,AX        ; compare to limit
  794.     JA    ALIVE        ; not really alive, but can't turn on yet
  795.  
  796.     XOR    AL,AL
  797.     MOV    DEAF,AL        ; reset flag
  798.  
  799.     INC    OFFS        ; keep count how many times this happened
  800.  
  801. ALIVE:
  802.     POP    ES
  803.     RET    
  804. ifdef Microsoft
  805. _U2ETUPDATE    ENDP
  806. else
  807. U2ETUPDATE    ENDP
  808. endif
  809.  
  810. ;
  811. ifdef Microsoft
  812. ;_TEXT    ends
  813. else
  814.     ENDPS
  815. endif
  816.     END
  817.