home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / NCSATELN / TEL23SRC.ZIP / NET / ENET / NETZYP.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-05-15  |  16.7 KB  |  795 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. Init_wt:
  372.     CMP    [BX].ZCB_Status,0FFh
  373.     JE    Init_wt
  374.  
  375. ;    CMP    [BX].ZCB_Result,Initialization_Complete
  376. ;    JNE    oh_well
  377.  
  378.     MOV    BX,offset Stat_ZCB
  379.     CALL    ZYP_Entry
  380. addr_wait:
  381.     CMP    [BX].ZCB_Status,0FFh
  382.     JE    addr_wait
  383.     CMP    [BX].ZCB_Result,Status_Complete
  384.     JE    get_addr
  385. oh_well:
  386.     mov    ax,-1
  387.     jmp SHORT nomore
  388.  
  389. get_addr:
  390.     MOV    AX,[BP+X+2]    ; get new one
  391.     MOV    ES,AX           ; set new one
  392.     MOV    DI,[BP+X]    ; get pointer, es:di is ready
  393.     MOV    SI,BX
  394.     add    si,ZCB_Stat_Unique_ID
  395.     ;
  396.     mov    cx,3
  397.     CLD
  398.     rep movsw        ; copy address
  399.     xor    ax,ax
  400. nomore:
  401.     pop    ds
  402.     POP     ES
  403.     POP    DI
  404.     POP    SI
  405.     POP    BP        
  406.     RET
  407. ifdef Microsoft
  408. _U2GETADDR    ENDP
  409. else
  410. U2GETADDR    ENDP
  411. endif
  412. ;
  413. ;***********************************************************************
  414. ;  ETCLOSE
  415. ;        shut it down
  416. ;
  417. ifdef Microsoft
  418. _U2ETCLOSE    PROC    FAR
  419. else
  420. U2ETCLOSE    PROC    FAR
  421. endif
  422.     push    bp
  423.     push    si
  424.     push    di
  425.     push    es
  426.     push    ds
  427.     mov    ax,ds
  428.     mov    es,ax
  429.  
  430.     MOV    BX,offset Cancel_ZCB
  431.     CALL    ZYP_Entry
  432. canwait:
  433.     CMP    [BX].ZCB_Status,0FFh
  434.     JE    canwait
  435.  
  436.     pop    ds
  437.     pop    es
  438.     pop    di
  439.     pop    si
  440.     pop    bp
  441.     RET
  442. ifdef Microsoft
  443. _U2ETCLOSE    ENDP
  444. else
  445. U2ETCLOSE    ENDP
  446. endif
  447. ;
  448. ;
  449. ;************************************************************************
  450. ;  XMIT         
  451. ;     send a packet to Ethernet
  452. ;     Is not interrupt driven, just call it when you need it.
  453. ;
  454. ;  usage:   xmit(packet,count)
  455. ;        char *packet;
  456. ;        int count;
  457. ;
  458. ;   Takes a packet raw, Ethernet packets start with destination address,
  459. ;   and puts it out onto the wire.  Count is the length of packet < 2048
  460. ;
  461. ;   checks for packets under the Ethernet size limit of 60 and handles them
  462. ;
  463. ifdef Microsoft
  464. _U2XMIT    PROC    FAR
  465. else
  466. U2XMIT    PROC    FAR
  467. endif
  468.     PUSH    BP
  469.     MOV    BP,SP
  470.     PUSH    SI
  471.     PUSH    DI
  472.     push    es
  473.     push    ds
  474.  
  475.     MOV    CX,[BP+X+2]    ; ds for buffer
  476.     MOV    SI,[BP+X]    ; offset for buffer
  477.  
  478.     MOV    AX,[BP+X+4]    ; count of bytes
  479.     cmp    ax,1100
  480.     jle    oklen
  481.     mov    ax,1100        ; maximum for me
  482. oklen:
  483. ;
  484. ;  place into Xmit parms
  485. ;
  486.     MOV    BX,offset Xmt_ZCB    ; Start the 1st transmit, using
  487.     mov    word ptr [bx].ZCB_Xmt_Data_Address,si
  488.     mov    word ptr [bx].ZCB_Xmt_Data_Address+2,CX
  489.     mov    [bx].ZCB_Xmt_Data_Length,ax
  490.  
  491.     mov    ax,ds
  492.     mov    es,ax        ; base for ZCB block
  493.  
  494.     CALL    ZYP_Entry
  495.  
  496. waitstat:
  497.     CMP    [BX].ZCB_Status,0FFh
  498.     JE    waitstat
  499.  
  500.     xor    ax,ax
  501. ;    CMP    [BX].ZCB_Result,Initialization_Complete
  502. ;    JE    xmitok
  503.     
  504. ;    mov    al,[BX].ZCB_Result
  505. xmitok:
  506.  
  507.     pop    ds
  508.     pop    es
  509.     POP    DI
  510.     POP    SI
  511.     POP    BP
  512.     RET
  513. ifdef Microsoft
  514. _U2XMIT    ENDP
  515. else
  516. U2XMIT    ENDP
  517. endif
  518. ;
  519. ;
  520. ;***********************************************************************
  521. ;   Receive
  522. ;   This is a CPU hook for boards that must be polled before we can
  523. ;   deliver packets into the receive buffer.  (i.e. no interrupts used)
  524. ;
  525. ;    usage:  recv();
  526. ;
  527. ;
  528. ifdef Microsoft
  529. _U2RECV    proc    far
  530. else
  531. U2RECV    proc    far
  532. endif
  533.     push    bp
  534.     PUSH    SI
  535.     PUSH    DI
  536.     push    es
  537.     push    ds
  538. ;
  539.     mov    bx,offset Recv_ZCB
  540.     CMP    [BX].ZCB_Status,0FFh ; status byte for outstanding read request
  541.  
  542.     JNE    newpkt
  543. ;
  544. ; no packet yet, skip
  545. ;
  546.     pop    ds
  547.     pop    es
  548.     POP    DI
  549.     POP    SI
  550.     pop    bp
  551.     ret            ; no packet arrival yet
  552.  
  553. newpkt:
  554.     mov    dx,[bx].ZCB_Rcv_Data_Length    ; length of recieved packet
  555.  
  556. ifdef Microsoft
  557.     MOV    aX,word ptr [_BUFPT+2]    ; buffer's ds
  558. else
  559.     MOV    aX,word ptr [BUFPT+2]    ; buffer's ds
  560. endif
  561. ifdef Microsoft
  562.     mov    bx,word ptr [_BUFPT]    ; get where size field for this packet goes
  563. else
  564.     mov    bx,word ptr [BUFPT]    ; get where size field for this packet goes
  565. endif
  566.  
  567.     mov    es,ax
  568.     mov    es:[bx],dx        ; put the accumulated size there
  569.  
  570.     add    bx,dx        ; add length to bufpt
  571.     inc    bx
  572.     inc    bx
  573.  
  574. ifdef Microsoft
  575.     MOV    word ptr [_BUFPT],bx    ; it is here, now
  576. else
  577.     MOV    word ptr [BUFPT],bx    ; it is here, now
  578. endif
  579.  
  580. ifdef Microsoft
  581.     MOV    AX,word ptr [_BUFBIG]    ; total amount of stuff in buffer
  582. else
  583.     MOV    AX,word ptr [BUFBIG]    ; total amount of stuff in buffer
  584. endif
  585.  
  586.     ADD    AX,DX        ; add in size of this packet
  587.     INC    AX
  588.     INC    AX        ; to cover the length value
  589.  
  590. ifdef Microsoft
  591.     MOV    word ptr [_BUFBIG],AX    ; after adding in current packet size
  592. else
  593.     MOV    word ptr [BUFBIG],AX    ; after adding in current packet size
  594. endif
  595.  
  596. ;
  597. ;  set up to read the next packet from the net
  598. ;
  599.  
  600. ifdef Microsoft
  601.     MOV    aX,word ptr [_BUFPT+2]    ; buffer's ds
  602. else
  603.     MOV    aX,word ptr [BUFPT+2]    ; buffer's ds
  604. endif
  605. ifdef Microsoft
  606.     MOV    DI,word ptr [_BUFPT]     ; where buffer is
  607. else
  608.     MOV    DI,word ptr [BUFPT]     ; where buffer is
  609. endif
  610.     mov    es,ax
  611.  
  612. ;
  613. ;  check for buffer overrun or catching up with reader
  614. ;
  615. ;  implicit 64K max buffer, should stop before 64K anyway
  616. ;
  617. ifdef Microsoft
  618.     MOV    AX,_BUFBIG    ; how much stuff is in buffer
  619. else
  620.     MOV    AX,BUFBIG    ; how much stuff is in buffer
  621. endif
  622. ifdef Microsoft
  623.     MOV    BX,_BUFLIM    ; what is our size limit?
  624. else
  625.     MOV    BX,BUFLIM    ; what is our size limit?
  626. endif
  627.     CMP    AX,BX
  628.     JNA    ISROOM        ; we are ok
  629. ;
  630. ;  no room at the Inn. 
  631. ;
  632.     JMP SHORT ENDINT      ; can't do much, we lose packets until restarted
  633.  
  634. ;
  635. ;  wrap pointer around at end, we know that we have room
  636. ;
  637. ISROOM:
  638. ifdef Microsoft
  639.     MOV    DX,word ptr [_BUFEND]    ; right before 2K safety area
  640. else
  641.     MOV    DX,word ptr [BUFEND]    ; right before 2K safety area
  642. endif
  643.     CMP    DX,DI        ; see if pointer is over limit
  644.     JA    OKAYREAD    ; we are not at wrap-around
  645.  
  646. ifdef Microsoft
  647.     MOV    AX,word ptr [_BUFORG]    ; wrap to here
  648. else
  649.     MOV    AX,word ptr [BUFORG]    ; wrap to here
  650. endif
  651. ifdef Microsoft
  652.     MOV    word ptr [_BUFPT],AX    ; wrap-around
  653. else
  654.     MOV    word ptr [BUFPT],AX    ; wrap-around
  655. endif
  656.     MOV    DI,AX        ; di also
  657. ;
  658. ;  here, DI contains where we want to put the packet.
  659. ;
  660. OKAYREAD:
  661.     inc    di
  662.     inc    di        ; leave space for length of packet
  663. ;
  664. ;
  665. ; call receive again
  666. ;
  667.     mov    bx,offset Recv_ZCB
  668.     ; address of packet into NCB
  669.     mov    word ptr [bx].ZCB_Rcv_Buffer_Address,di
  670.     mov    word ptr [bx].ZCB_Rcv_Buffer_Address+2,es
  671.     mov    ax,ds
  672.     mov    es,ax
  673.     CALL    ZYP_Entry
  674.  
  675. STOPINT:
  676.  
  677. ENDINT:
  678.     pop    ds
  679.     pop    es
  680.     POP    DI
  681.     POP    SI
  682.     POP    BP
  683.     RET
  684. ifdef Microsoft
  685. _U2RECV    ENDP
  686. else
  687. U2RECV    ENDP
  688. endif
  689.  
  690. ;
  691. ;*************************************************************************
  692. ;  ETUPDATE
  693. ;      update pointers and/or restart receiver when read routine has
  694. ;      already removed the current packet
  695. ;
  696. ifdef Microsoft
  697. _U2ETUPDATE    PROC    FAR
  698. else
  699. U2ETUPDATE    PROC    FAR
  700. endif
  701.     PUSH     ES
  702.  
  703. ifdef Microsoft
  704.     MOV    AX,word ptr [_BUFPT+2] ; establish data segment to buffer
  705. else
  706.     MOV    AX,word ptr [BUFPT+2] ; establish data segment to buffer
  707. endif
  708.     MOV    ES,AX        ; put that in es
  709. ;
  710. ifdef Microsoft
  711.     MOV    BX,word ptr [_BUFREAD]    ; where read pointer is now
  712. else
  713.     MOV    BX,word ptr [BUFREAD]    ; where read pointer is now
  714. endif
  715.     MOV    DX,ES:[BX]    ; get size of this packet
  716.     INC    DX
  717.     INC    DX        ; TWO MORE FOR LENGTH VALUE
  718.  
  719.     ADD    BX,DX        ; increment bufread by size of packet
  720.  
  721. ifdef Microsoft
  722.     MOV    CX,word ptr [_BUFEND]    ; right before 2K safety area
  723. else
  724.     MOV    CX,word ptr [BUFEND]    ; right before 2K safety area
  725. endif
  726.     CMP    BX,CX        ; see if pointer is over limit
  727.     JB    NOWRAPRD    ; we are not at wrap-around
  728.     
  729. ifdef Microsoft
  730.     MOV    BX,_BUFORG    ; wrap to here
  731. else
  732.     MOV    BX,BUFORG    ; wrap to here
  733. endif
  734. NOWRAPRD:
  735. ifdef Microsoft
  736.     MOV    _BUFREAD,BX    ; buffer pointer has been updated
  737. else
  738.     MOV    BUFREAD,BX    ; buffer pointer has been updated
  739. endif
  740.  
  741. ;
  742. ;  DECREMENT TOTAL BUFFER SIZE
  743. ;
  744.     CLI            ; keep interrupt handler from bothering dec
  745. ifdef Microsoft
  746.     MOV    CX,_BUFBIG    ; size before removing packet
  747. else
  748.     MOV    CX,BUFBIG    ; size before removing packet
  749. endif
  750.     SUB    CX,DX        ; remove size of current packet
  751. ifdef Microsoft
  752.     MOV    _BUFBIG,CX    ; put it back
  753. else
  754.     MOV    BUFBIG,CX    ; put it back
  755. endif
  756.     STI
  757. ;
  758. ;  IF RECEIVER IS ON, THEN CHECKING BUFLIM IS UNNECESSARY.
  759. ;
  760.     MOV    AL,DEAF        ; is the receiver turned off?
  761.     OR    AL,AL        ; 0 = reading, 1 = deaf
  762.     JZ    ALIVE
  763. ;
  764. ;  CHECK FOR ROOM IN THE BUFFER, IF THERE IS, TURN ON RECEIVER
  765. ;
  766. ifdef Microsoft
  767.     MOV    AX,_BUFLIM    ; what is our limit?
  768. else
  769.     MOV    AX,BUFLIM    ; what is our limit?
  770. endif
  771.     CMP    CX,AX        ; compare to limit
  772.     JA    ALIVE        ; not really alive, but can't turn on yet
  773.  
  774.     XOR    AL,AL
  775.     MOV    DEAF,AL        ; reset flag
  776.  
  777.     INC    OFFS        ; keep count how many times this happened
  778.  
  779. ALIVE:
  780.     POP    ES
  781.     RET    
  782. ifdef Microsoft
  783. _U2ETUPDATE    ENDP
  784. else
  785. U2ETUPDATE    ENDP
  786. endif
  787.  
  788. ;
  789. ifdef Microsoft
  790. ;_TEXT    ends
  791. else
  792.     ENDPS
  793. endif
  794.     END
  795.