home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / MSWATTCP.ZIP / SRC / ASMPKT.ASM next >
Encoding:
Assembly Source File  |  1993-03-25  |  3.5 KB  |  149 lines

  1. ;
  2. ; File: asmpkt.asm
  3. ;
  4. ; 16-Jun-92 lr
  5. ;
  6. ; C-to-assembly interface for the packet driver
  7. ;
  8. ; First, _pktasminit must be called to initialize the
  9. ; packet driver. Then, _pktentry is called back from the packet driver
  10. ; whenever it requires attention. _pktentry is currently an assembler
  11. ; routines that puts the new packet into a circular buffer, and marks
  12. ; the buffer as used. The C counterpart is in pcpkt.c
  13. ;
  14. ;  Usage :
  15. ;        _pktentry
  16. ;           _pktasminit( void far * buffers, int maxbufs, int buflen, long far *lost_packets)
  17. ;
  18. ;  (c) 1991 University of Waterloo,
  19. ;           Faculty of Engineering,
  20. ;           Engineering Microcomputer Network Development Office
  21. ;
  22. ;  version
  23. ;
  24. ;    0.1    22-May-1991   E. P. Engelke
  25. ;    0.2    22-Mar-1992   Luigi Rizzo
  26. ;
  27. ; Each data buffer is preceded by 2 bytes, the first should be
  28. ; 0 when the buffer is empty, 1 otherwise.
  29. ;
  30. ; Buffers are handled as a circular queue.
  31. ;
  32.         include masmdefs.hsm
  33.         include model.hsm
  34.  
  35. codedef ASMPKT
  36. datadef
  37.  
  38. cstart  ASMPKT
  39.  
  40. maxbufs    dw    0    ; # of data buffer
  41. maxlen    dw    0    ; size of each buffer (there are 2 more bytes each)
  42. bufs    dw    0    ; offset/
  43. bufseg    dw    0    ; segment of buffer
  44.  
  45. bufptr    dw    0    ; 19-dec-91 lr used to do round robin on buffer.
  46.             ; points to the next buffer to be used. If not free,
  47.             ; then no buffers are available.
  48. bufcnt    dw    0    ; free buffer index. easier to use as a limit.
  49.  
  50. lost_pkt_ofs    dw 0
  51. lost_pkt_seg    dw 0
  52.  
  53. cproc    _pktentry
  54.     pushf
  55.  
  56. ;
  57. ; called with AL=0 to request a buffer, AL=1 when the buffer has been filled
  58. ;
  59.     cli        ; no interrupts now
  60.  
  61.     or    AL, AL
  62.     jnz    encue    ; branch if was a 1 and must enqueue packet now
  63.  
  64.     ; otherwise it is a buffer request operation
  65.     ; to check our buffers we will need the same DS seg, set it now
  66.     ;
  67.         push    CX
  68.     push    DS
  69.         mov     DI, CS:bufseg
  70.         mov     DS, DI
  71.  
  72.     ;
  73.     ; check the packet length
  74.     ;
  75.     cmp    CX, CS:maxlen
  76.     jg    no_fnd        ; too big. Pretend none were found
  77.  
  78.     mov    DI, CS:bufptr    ; current buffer
  79.     mov    AL, 0ffh
  80.     test    AL, DS:[DI]    ; is it empty ?
  81.     jnz    no_fnd        ; no.
  82. ;
  83. ;    here it is found: simply update pointers.
  84. ;
  85.     mov    SI, DI
  86.     add    SI, CS:maxlen
  87.     add    SI, 2        ; SI points to the next avail. buffer
  88.     mov    AX, CS:bufcnt
  89.     add    AX, 1
  90.     cmp    AX, CS:maxbufs
  91.     jne    found_1        ; wrap around after last buffer
  92.     mov    AX,0
  93.     mov    SI, CS:bufs
  94. found_1:
  95.     mov    CS:bufptr,SI    ; save pointers
  96.     mov    CS:bufcnt,AX
  97.     jmp    short found
  98.     
  99. no_fnd:    ; not found. Increase the lost pkt counter.
  100.     mov    AX, CS:lost_pkt_seg
  101.     mov    DS, AX
  102.     mov    DI, CS:lost_pkt_ofs
  103.     add    word ptr [DI],1
  104.     adc    word ptr [DI+2],0
  105.     xor    DI, DI        ; for whatever error, throw away the buffer
  106.     mov    DS, DI        ; by returning 0000:0000
  107.     sub    DI, 2
  108.  
  109. found:  push    DS
  110.     pop    ES
  111.     add    DI, 2
  112.     pop    DS
  113.     pop    CX
  114.     popf
  115.     retf
  116.  
  117.     ; enqueue packet
  118.     ;
  119. encue:    or    SI, SI
  120.     jz    no_enqu        ; not a valid pointer, cannot encue
  121.     push    SI
  122.     sub    SI, 2
  123.     mov    AL, 1        ; mark as busy
  124.         mov     DS:[SI], AL;    byte ptr DS:SI, AL
  125.     pop    SI
  126. no_enqu:popf
  127.     retf
  128. cendp    _pktentry
  129.  
  130. cpublic _pktasminit        ; bufptr, maxbufs, buflen
  131.     mov    AX, +@AB + 0 [BP]    ; bufptr
  132.     mov    BX, +@AB + 2 [BP]    ; bufptr segment
  133.     mov    CX, +@AB + 4 [BP]    ; maxbufs
  134.     mov    DX, +@AB + 6 [BP]    ; buflen
  135.     mov    CS:bufs, AX
  136.     mov    CS:bufseg, BX
  137.     mov    CS:maxbufs, CX
  138.     mov    CS:maxlen, DX
  139.     mov    CS:bufptr, AX        ; 19-dec-91 lr
  140.     mov    CS:bufcnt, 0        ; 19-dec-91 lr
  141.     mov    AX, +@AB + 8 [BP]    ; bufptr
  142.     mov    BX, +@AB + 10 [BP]    ; bufptr segment
  143.     mov    CS:lost_pkt_ofs,AX
  144.     mov    CS:lost_pkt_seg,BX
  145.     
  146. creturn _pktasminit
  147. cend    ASMPKT
  148.         end
  149.