home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / packetdrivers.tar.gz / pd.tar / src / pktdll.asm < prev    next >
Assembly Source File  |  1993-08-05  |  32KB  |  1,292 lines

  1.     page 66, 132
  2. ; PKTDLL.ASM - Adapter provides Packet Driver interface over DLL.
  3. ;
  4. ; (c) Copyright Brian F. Angus 1992.  All rights reserved.
  5. ;
  6. ; PKTDLL was renamed from DLLPKT to fit with Digital Equipment Corporation's
  7. ; naming conventions and the left to right reading habits of the western
  8. ; world
  9. ;
  10. ; Big credits to: Harry P.E. Stox for the "c" version of DLLPKT (v0.1)
  11. ;          Daniel D. Lanciani for code chunks from ODIPKT and DIS_PKT
  12. ;          Joe R. Doupnik for code chunks from DIS_PKT
  13. ;          Chris Lord and Mitch Lichtenberg - they know who they are
  14. ;
  15. ; This unmodified source file and its executable form may be used and
  16. ; redistributed freely.  The source may be modified, and the source or
  17. ; executable versions built from the modified source may be used and
  18. ; redistributed, provided that this notice and the copyright displayed by
  19. ; the exectuable remain intact, and provided that the executable displays
  20. ; an additional message indicating that it has been modified, and by whom.
  21. ;
  22. ; Brian F. Angus releases this software "as is", with no express or
  23. ; implied warranty, including, but not limited to, the implied warranties
  24. ; of merchantability and fitness for a particular purpose.
  25. ;
  26. ; Please send bug reports to angus@trcoa.enet.dec.com or
  27. ;
  28. ; Brian Angus
  29. ; Digital Equipment of Canada
  30. ; 505 University Avenue
  31. ; Toronto, Ontario M5G 2H2
  32. ; CANADA
  33.  
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35. ;; Equates                  ;;
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37.  
  38. ; Miscellaneous Stuff
  39. carry            equ 0001h    ; carry bit in flag register
  40. cr            equ 13        ; carriage return
  41. tab            equ 9        ; tab
  42. eol            equ <13,10>    ; end of line
  43. eos            equ <13,10,'$'>    ; end of string
  44. hd1Int            equ 08h        ; 1st bank of IRQ vectors
  45. hd2Int            equ 70h        ; 2nd bank of IRQ vectors
  46.  
  47. ; DIX Ethernet Specific
  48. ethMaxFrame        equ 1514    ; maximum frame size
  49. ethMinFrame        equ 60        ; minimum frame size
  50. ethAddrLen        equ 6        ; length of ethernet address
  51. ethTypeLen        equ 2        ; length of ethernet type field
  52. ethHeadLen        equ 14        ; lenfth of ethernet header
  53. ethDataLen        equ 1500    ; length of ethernet data field
  54.  
  55. ; Packet Driver Specific
  56. pktFunction        equ 5        ; basic and high performance functions
  57. pktClass        equ 1        ; driver class (DIX ethernet)
  58. pktType            equ -1        ; driver type (match any)
  59. pktNumber        equ 0        ; driver number
  60. pktVersion        equ 10        ; driver version number
  61. pktInt            equ 61h        ; driver interrupt (default)
  62. maxHandles        equ 8        ; max active handles
  63. txBufCount        equ 8        ; back to back transmits
  64. rxBufCount        equ 8        ; back to back receives
  65.  
  66. ; Packet Driver Function Calls
  67. pktNotImplemented    equ 0        ; function not implemented
  68. pktDriverInfo        equ 1        ; get driver information
  69. pktAccessType        equ 2        ; open handle for protocol
  70. pktReleaseType        equ 3        ; close handle for protocol
  71. pktSendPkt        equ 4        ; transmit a packet
  72. pktTerminate        equ 5        ; unload driver if possible
  73. pktGetAddress        equ 6        ; get ethernet address
  74. pktResetInterface    equ 7        ; reset ethernet card and driver
  75. pktGetParameters    equ 10        ; get extended driver information
  76. pktAsSendPkt        equ 11        ; high performance transmit
  77. pktSetRcvMode        equ 20        ; set receive mode
  78. pktGetRcvMode        equ 21        ; get receive mode
  79. pktSetMulticastList    equ 22        ; set multicast list
  80. pktGetMulticastList    equ 23        ; get multicast list
  81. pktGetStatistics    equ 24        ; get statistics
  82. pktSetAddress        equ 25        ; set ethernet address
  83.  
  84. ; Packet Driver Return Codes
  85. pkterrBadHandle        equ 1        ; invalid handle number
  86. pkterrNoClass        equ 2        ; no interfaces of this class found
  87. pkterrNoType        equ 3        ; no interfaces of this type found
  88. pkterrNoNumber        equ 4        ; no interfaces of this number found
  89. pkterrBadType        equ 5        ; bad packet type specified
  90. pkterrNoMulticast    equ 6        ; multicasts not supported
  91. pkterrCantTerminate    equ 7        ; packet driver cannot terminate
  92. pkterrBadMode        equ 8        ; invalid receiver mode specified
  93. pkterrNoSpace        equ 9        ; insufficient space for operation
  94. pkterrTypeInuse        equ 10        ; type is currently in use
  95. pkterrBadCommand    equ 11        ; command is not implemented
  96. pkterrCantSend        equ 12        ; packet couldn't be sent
  97. pkterrCantSet        equ 13        ; hardware address couldn't be changed
  98. pkterrBadAddress    equ 14        ; invalid hardware address
  99. pkterrCantReset        equ 15        ; couldn't reset interface
  100.  
  101. ; DLL Specific
  102. schInt            equ 6ch        ; interrupt for scheduler
  103. dllInt            equ 69h        ; interrupt for datalink
  104. dllNoPad        equ 0        ; don't pad ethernet message
  105. dllPadMessage        equ 1        ; pad message to minimum size
  106. dllMode802        equ 0        ; 802.3 compatibility mode for Novell
  107. dllModeDIX        equ 1        ; DIX frame formats
  108. dllModePromis        equ 2        ; promiscuous mode (all frames)
  109.  
  110. ; DLL Function Calls - (the 0a00h is the DLL module id for the AH register)
  111. dllInit            equ 0a00h+0    ; initialize datalink functions
  112. dllOpen            equ 0a00h+1    ; open a portal
  113. dllClose        equ 0a00h+2    ; close a portal
  114. dllEnbMulti        equ 0a00h+3    ; enable a multicast address
  115. dllDisMulti        equ 0a00h+4    ; disable a multicast address
  116. dllTransmit        equ 0a00h+5    ; transmit a message
  117. dllRequestXmit        equ 0a00h+6    ; request a transmit buffer
  118. dllDeallocate        equ 0a00h+7    ; free a buffer
  119. dllReadChan        equ 0a00h+8    ; read channel status
  120. dllReadPlist        equ 0a00h+9    ; read portal list
  121. dllReadPortal        equ 0a00h+10    ; read portal status
  122. dllReadCount        equ 0a00h+11    ; read/zero counters
  123. dllNetworkBoot        equ 0a00h+12    ; remote boot (not implemented)
  124. dllEnableChan        equ 0a00h+13    ; emable channel
  125. dllDisabChan        equ 0a00h+14    ; disable channel
  126. dllStartMOP        equ 0a00h+15    ; enable MOP portals
  127. dllStopMOP        equ 0a00h+16    ; disable MOP portals
  128. dllReaDecparm        equ 0a00h+17    ; read DECPARM.DAT address
  129. dllSetDecparm        equ 0a00h+18    ; set DECPARM.DAT address
  130. dllExtLoopback        equ 0a00h+19    ; do external loopback
  131. dllGetPDB        equ 0a00h+20    ; get portal database pointer
  132. dllGetPrivInfo        equ 0a00h+25    ; get private information
  133. dllGetRemBoot        equ 0a00h+26    ; get remote boot information
  134. dllDisMOPmulti        equ 0a00h+29    ; disable MOP multicast
  135. dllEnaMOPmulti        equ 0a00h+30    ; enable MOP multicast
  136. dllInsCheck        equ 0a00h+31    ; installation check
  137. dllReqSized        equ 0a00h+33    ; request sized transmit buffer
  138. dllExtCount        equ 0a00h+40    ; extended counters
  139. dllReadChar        equ 0a00h+41    ; read characteristics
  140.  
  141. ; DLL Return Codes
  142. dllerrNotImpl        equ -1        ; not implemented
  143. dllerrSuccess        equ 0        ; function call succeeded
  144. dllerrInitFail        equ 1        ; initialization failed
  145. dllerrChNotOff        equ 2        ; channel not off
  146. dllerrStateOff        equ 3        ; channel is off
  147. dllerrNoAddr        equ 4        ; address has not been set
  148. dllerrNoHW        equ 5        ; hardware is broken
  149. dllerrBuf2Smal        equ 6        ; buffer is too small
  150. dllerrNoneAvl        equ 7        ; no more buffers available
  151. dllerrNoResrc        equ 8        ; no resources available
  152. dllerrPromAct        equ 9        ; promiscuous receiver is active
  153. dllerrNonExcl        equ 10        ; promiscuous receiver already active
  154. dllerrUnRec        equ 11        ; unrecognised portal
  155. dllerrPTinuse        equ 12        ; protocol type in use
  156. dllerrNotMulti        equ 13        ; address is not a multicast address
  157. dllerrOutStand        equ 14        ; portal has outstanding calls active
  158. dllerrNoRXbad        equ 15        ; hardware does not support bad frames
  159. dllerrNoneOut        equ 16        ; no receive buffers to be cancelled
  160. dllerrNoEvents        equ 17        ; no events in queue
  161. dllerrBroken        equ 18        ; port driver is broken
  162. dllerrExQuota        equ 19        ; exceeded quota
  163. dllerrAlInit        equ 20        ; already initialized
  164. dllerrLBfail        equ 21        ; loopback failure
  165. dllerrIllBuf        equ 22        ; illegal buffer freed
  166. dllerrInvCmd        equ 23        ; invalid command
  167.  
  168. ; DOS Errorlevel Codes
  169. doserrSuccess        equ 0        ; normal completion
  170. doserrFixMEM        equ 1        ; wrong memory address    - fixed
  171. doserrFixIRQ        equ 2        ; wrong IRQ level    - fixed
  172. doserrFixDMA        equ 3        ; wrong DMA channel    - fixed
  173. doserrFixIO        equ 4        ; wrong IO address    - fixed
  174. doserrExists        equ 5        ; packet driver already loaded
  175. doserrCableFail        equ 20        ; general cable failure
  176. doserrCableOpen        equ 21        ; network cable is open
  177. doserrCableShort    equ 22        ; network cable is shorted
  178. doserrUsage        equ 30        ; usage message
  179. doserrRange        equ 31        ; arguments out of range
  180. doserrError        equ 32        ; unspecified initialization error
  181. doserrBadMEM        equ 34        ; wrong memory address
  182. doserrBadIRQ        equ 35        ; wrong IRQ level
  183. doserrBadDMA        equ 36        ; wrong DMA channel
  184. doserrNoCard        equ 37        ; wrong IO address or no network card
  185.  
  186. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  187. ;; Structures Definitions          ;;
  188. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  189.  
  190. ETH    struc                ; structure of DIX ethernet packet
  191.     ethDestAddr    db ethAddrLen dup(?) ; destination address
  192.     ethSourceAddr    db ethAddrLen dup(?) ; source address
  193.     ethType        db ethTypeLen dup(?) ; protocol type
  194.     ethData        db ethDataLen dup(?) ; data
  195. ETH    ends
  196.  
  197. HND    struc                ; structure of handle block
  198.     hndInUse    db ?        ; handle in use flag
  199.     hndPerm        db ?        ; permanent handle for Windows
  200.     hndPortalID    dw ?        ; portal id
  201.     hndType        db ethTypeLen dup(?) ; protocol type
  202.     hndReceive    dd ?        ; receive packet routine
  203. HND    ends
  204.  
  205. PRM    struc                ; structure of parameter block
  206.     prmMajorRev    db 1        ; major revision = 1
  207.     prmMinorRev    db 9        ; minor revision = 9
  208.     prmParamLen    db 14        ; length of this structure = 14
  209.     prmAddrLen    db ethAddrLen    ; MAC addr length
  210.     prmMTU        dw ethMaxFrame    ; MAC packet length
  211.     prmMulticastAval dw 0        ; no multicast support
  212.     prmRcvBuffs    dw rxBufCount - 1 ; back-to-back RX -1
  213.     prmXmtBufs    dw txBufCount - 1 ; back-to-back TX -1
  214.     prmIntNum    dw 0        ; EOI interrupt
  215. PRM    ends
  216.  
  217. DCB    struc                ; structure of DLL control block
  218.     dcbPortalID    dw ?        ; portal ID
  219.     dcbSaddr    db ethAddrLen dup(?) ; ethernet source address
  220.     dcbDaddr    db ethAddrLen dup(?) ; ethernet destination address
  221.     dcbBufferPtr    dd ?        ; buffer address
  222.     dcbBufferLen    dw ?        ; buffer length
  223.     dcbOperation    dw ?        ; DCB operation
  224.     dcbPad        db ?        ; pad mode (open)
  225.     dcbMode        db ?        ; mode (open)
  226.     dcbLScallback    dd ?        ; line state callback
  227.     dcbRXcallback    dd ?        ; receive callback
  228.     dcbTXcallback    dd ?        ; transmit callback
  229.     dcbMaxOut    db ?        ; maximum outstanding
  230.     dcbPtype    db ethTypeLen dup(?) ; protocol type
  231.     dcbTXhandle    dw ?        ; transmit handle
  232. DCB    ends
  233.  
  234. UCB    struc                ; structure of user callback block
  235.     ucbPortalID    dw ?        ; portal ID
  236.     ucbDaddr    db ethAddrLen dup(?) ; destination address
  237.     ucbSaddr    db ethAddrLen dup(?) ; source address
  238.     ucbBufferPtr    dd ?        ; buffer address
  239.     ucbBufferLen    dw ?        ; buffer length
  240.     ucbBufStatus    db ?        ; buffer status
  241.     ucbBufReason    db ?        ; buffer reason
  242.     ucbTXhandle    dw ?        ; transmit handle
  243. UCB    ends
  244.  
  245. PSB    struc                ; structure of portal status block
  246.     psbBufLost    dw ?        ; number of lost buffers
  247.     psbPtype    db ethTypeLen dup(?) ; protocol type
  248. PSB    ends
  249.  
  250. DWP    struc                ; structure of double word pointer
  251.     offs        dw ?        ; define as 0
  252.     segm        dw ?        ; define as 2
  253. DWP    ends
  254.  
  255. R16    struc                ; stack offsets of 16 bit registers
  256.     _es        dw ?        ; es register
  257.     _ds        dw ?        ; ds register
  258.     _bp        dw ?        ; bp register
  259.     _di        dw ?        ; di register
  260.     _si        dw ?        ; si register
  261.     _dx        dw ?        ; dx register
  262.     _cx        dw ?        ; cx register
  263.     _bx        dw ?        ; bx register
  264.     _ax        dw ?        ; ax register
  265.     _ip        dw ?        ; ip register
  266.     _cs        dw ?        ; cs register
  267.     _flags        dw ?        ; flag register
  268. R16    ends
  269.  
  270. R08    struc                ; stack offsets of 8 bit registers
  271.             dw 5 dup(?)    ; es, ds, bp, di, si registers
  272.     _dl        db ?        ; dl register
  273.     _dh        db ?        ; dh register
  274.     _cl        db ?        ; cl register
  275.     _ch        db ?        ; ch register
  276.     _bl        db ?        ; bl register
  277.     _bh        db ?        ; bh register
  278.     _al        db ?        ; al register
  279.     _ah        db ?        ; ah register
  280. R08    ends
  281.  
  282. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  283. ;; Main Code Segment              ;;
  284. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  285.  
  286. CODE    segment word public 'CODE'
  287.     assume cs:CODE, ds:CODE, es:nothing, ss:CODE
  288.  
  289.     org    2ch
  290. envSeg    label    word
  291.     org    80h
  292. cmdBuf    label    byte
  293.     org    100h
  294. at100h:    jmp    start
  295.  
  296. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  297. ;; Driver Data                  ;;
  298. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  299.  
  300. pktName    db    'PKTDLL', 0        ; driver name used by driver_info
  301. ether    db    ethAddrLen dup(?)    ; ethernet address
  302. pktVec    dw    pktInt * 4        ; default driver vector address
  303.  
  304. param    PRM    <>            ; parameter block
  305.  
  306. hndTab    HND    maxHandles dup(<>)    ; the handle table
  307. hndEnd    label    byte
  308.  
  309. pList    dw    maxHandles dup(?)    ; active portal list
  310. pStat    PSB    <>            ; portal status block (partial)
  311.  
  312. flag802    db    0            ; novell 802.3 flag
  313.  
  314. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  315. ;; Check for Windows or Task Switcher ;;
  316. ;;  regs inp: none              ;;
  317. ;;  regs out: flags              ;;
  318. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  319.  
  320. safe:    mov    cx, 'DE'        ; check for DESQview
  321.     mov    dx, 'SQ'
  322.     mov    ax, 2b01h
  323.     int    21h
  324.     cmp    al, -1
  325.     mov    ax, 1
  326.     jne    safe1
  327.  
  328.     mov    ax, 4680h        ; check for DOS 5.0 shell
  329.     int    2fh
  330.     cmp    ax, 0
  331.     mov    ax, 2
  332.     jz    safe1
  333.  
  334.     mov    ax, 1600h        ; check for MS-Windows
  335.     int    2fh
  336.     mov    ah, 0
  337.     cmp    al, 0
  338.     jz    safe1
  339.     cmp    al, 80h
  340.     mov    al, 0
  341.     jz    safe1
  342.     mov    ax, 3
  343. safe1:    cmp    ax, 0
  344.     ret                ; "z" bit is clear if ok
  345.  
  346. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  347. ;; Send Packet Common Subroutine      ;;
  348. ;;  regs inp: ds,si,cx              ;;
  349. ;;  regs out: none              ;;
  350. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  351.  
  352. send:    cmp    cx, ethMaxFrame        ; check packet size
  353.     ja    send4
  354.     cmp    cx, ethMinFrame
  355.     jnb    send1
  356.     mov    cx, ethMinFrame
  357. send1:    sub    cx, ethHeadLen        ; adjust packet size
  358.  
  359.     mov    ax, word ptr [si].ethType ; get protocol type
  360.  
  361.     mov    di, offset hndTab    ; address handle table
  362. send2:    cmp    cs:[di].hndInUse, 1    ; find matching handle
  363.     jne    send3
  364.     cmp    word ptr cs:[di].hndType, ax
  365.     je    send5
  366. send3:    add    di, size HND
  367.     cmp    di, offset hndEnd
  368.     jb    send2
  369.  
  370. send4:    add    sp, 2            ; pop off our return address
  371.     mov    dh, pkterrCantSend    ; return can't send error
  372.     jmp    bad
  373.  
  374. send5:    push    bp            ; save register pointer
  375.     sub    sp, size DCB        ; allocate DCB on stack
  376.     mov    ax, ss
  377.     mov    es, ax
  378.     mov    bx, sp
  379.     mov    bp, sp
  380.  
  381.     mov    ax, cs:[di].hndPortalID ; store portal ID
  382.     mov    [bp].dcbPortalID, ax
  383.  
  384.     mov    ax, dllRequestXmit    ; allocate buffer
  385.     int    dllInt
  386.     cmp    ax, dllerrSuccess
  387.     jne    send6
  388.  
  389.     mov    [bp].dcbBufferLen, cx    ; store more DCB info
  390.     mov    ax, word ptr cs:[di].hndType
  391.     mov    word ptr [bp].dcbPType, ax
  392.  
  393.     push    si            ; store destination address
  394.     push    cx
  395.     lea    di, [bp].dcbDaddr
  396.     lea    si, [si].ethDestAddr
  397.     mov    cx, ethAddrLen / 2
  398.     rep    movsw
  399.     pop    cx
  400.     pop    si
  401.  
  402.     push    es            ; store packet buffer
  403.     les    di, [bp].dcbBufferPtr
  404.     lea    si, [si].ethData
  405.     clc
  406.     rcr    cx, 1
  407.     rep    movsw
  408.     rcl    cx, 1
  409.     rep    movsb
  410.     pop    es
  411.  
  412.     mov    ax, dllTransmit        ; transmit buffer
  413.     int    dllInt
  414.  
  415. send6:    add    sp, size DCB        ; deallocate DCB
  416.     pop    bp            ; restore register pointer
  417.  
  418.     cmp    ax, dllerrSuccess
  419.     jne    send4
  420.     ret
  421.  
  422. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  423. ;; DLL RX and TX Upcalls          ;;
  424. ;;  regs inp: es,bx              ;;
  425. ;;  regs out: none              ;;
  426. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  427.  
  428. rx_upc:    push    es            ; save UCB pointer
  429.     push    bx
  430.  
  431.     mov    dx, es:[bx].ucbPortalID    ; get portal ID
  432.     mov    cx, es:[bx].ucbBufferLen; get buffer length
  433.     add    cx, ethHeadLen
  434.  
  435.     mov    ax, cs            ; address data segment
  436.     mov    ds, ax
  437.  
  438.     mov    bx, offset hndTab    ; address handle table
  439. rx1:    cmp    [bx].hndInUse, 1    ; find matching handle
  440.     jne    rx2
  441.     cmp    [bx].hndPortalID, dx
  442.     je    rx3
  443. rx2:    add    bx, size HND
  444.     cmp    bx, offset hndEnd
  445.     jb    rx1
  446.     jmp    short rx5
  447.  
  448. rx3:    push    bx            ; request application buffer
  449.     push    cx
  450.     push    word ptr [bx].hndType
  451.     xor    ax, ax
  452.     call    [bx].hndReceive
  453.     pop    ax
  454.     pop    cx
  455.     pop    dx
  456.  
  457.     mov    bx, es            ; check for null pointer
  458.     cmp    bx, 0
  459.     jne    rx4
  460.     cmp    di, 0
  461.     je    rx5
  462.  
  463. rx4:    mov    bp, sp            ; address UCB
  464.     lds    bx, [bp]
  465.  
  466.     push    cx            ; save buffer length
  467.     push    es            ; save buffer pointer
  468.     push    di
  469.  
  470.     cld                ; copy buffer to application
  471.     lea    si, [bx].ucbDaddr    ;  destination
  472.     mov    cx, ethAddrLen / 2
  473.     rep    movsw
  474.     lea    si, [bx].ucbSaddr    ;  source
  475.     mov    cx, ethAddrLen / 2
  476.     rep    movsw
  477.     stosw                ;  protocol type
  478.     mov    cx, [bx].ucbBufferLen    ;  ethernet data
  479.     lds    si, [bx].ucbBufferPtr
  480.     clc
  481.     rcr    cx, 1
  482.     rep    movsw
  483.     rcl    cx, 1
  484.     rep    movsb
  485.  
  486.     pop    si            ; restore buffer pointer
  487.     pop    ds
  488.     pop    cx            ; restore buffer length
  489.     mov    bx, dx            ; restore handle
  490.  
  491.     mov    ax, 1            ; tell application copy completed
  492.     call    cs:[bx].hndReceive
  493.  
  494. rx5:    pop    bx            ; restore ucb pointer
  495.     pop    es
  496.  
  497. tx_upc:    mov    ax, dllDeallocate    ; free portal's RX buffer
  498.     int    dllInt
  499.     retf
  500.  
  501. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  502. ;; PKT Function:  not_implemented     ;;
  503. ;;  regs inp: none              ;;
  504. ;;  regs out: none              ;;
  505. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  506.  
  507. not_implemented:
  508.     mov    dh, pkterrBadCommand    ; return bad command error
  509.     jmp    bad
  510.  
  511. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  512. ;; PKT Function:  driver_info          ;;
  513. ;;  regs inp: none              ;;
  514. ;;  regs out: bx,ch,dx,cl,ds,si,al    ;;
  515. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  516.  
  517. driver_info:
  518.     mov    [bp]._al, pktFunction    ; return information in registers
  519.     mov    [bp]._ch, pktClass
  520.     mov    [bp]._dx, pktType
  521.     mov    [bp]._cl, pktNumber
  522.     mov    [bp]._bx, pktVersion
  523.     mov    [bp]._ds, cs
  524.     mov    [bp]._si, offset pktName
  525.     jmp    good
  526.  
  527. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  528. ;; PKT Function:  access_type          ;;
  529. ;;  regs inp: al,bx,dl,ds,si,cx,es,di ;;
  530. ;;  regs out: ax              ;;
  531. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  532.  
  533. access_type:
  534.     cmp    al, pktClass        ; verify class
  535.     je    acc1
  536.     mov    dh, pkterrNoClass
  537.     jmp    bad
  538.  
  539. acc1:    cmp    dl, pktNumber        ; verify number
  540.     je    acc2
  541.     mov    dh, pkterrNoNumber
  542.     jmp    bad
  543.  
  544. acc2:    cmp    cx, ethTypeLen        ; verify protocol type
  545.     je    acc3
  546.     mov    dh, pkterrBadType
  547.     jmp    bad
  548.  
  549. acc3:    mov    dx, [si]        ; save protocol type
  550.     cmp    dx, 0
  551.     je    acc8
  552.  
  553.     mov    ax, cs            ; address data segment
  554.     mov    ds, ax
  555.  
  556.     mov    si, offset hndTab    ; address handle table
  557. acc4:    cmp    word ptr [si].hndType, dx ; find matching handle
  558.     jne    acc5
  559.     cmp    [si].hndInUse, 1
  560.     je    acc7
  561.     jmp    short acc9
  562. acc5:    add    si, size HND
  563.     cmp    si, offset hndEnd
  564.     jb    acc4
  565.  
  566.     mov    si, offset hndTab    ; address handle table
  567. acc6:    cmp    word ptr [si].hndInUse, 0 ; find non-inuse non-perm handle
  568.     je    acc9
  569.     add    si, size HND
  570.     cmp    si, offset hndEnd
  571.     jb    acc6
  572.     mov    dh, pkterrNoSpace
  573.     jmp    bad
  574. acc7:    mov    dh, pkterrTypeInuse
  575.     jmp    bad
  576. acc8:    jmp    good
  577.  
  578. acc9:    mov    word ptr [si].hndType, dx ; store some handle data
  579.     mov    word ptr [si].hndReceive.segm, es
  580.     mov    word ptr [si].hndReceive.offs, di
  581.  
  582.     push    bp            ; save register pointer
  583.     sub    sp, size DCB        ; allocate DCB on stack
  584.     mov    ax, ss
  585.     mov    es, ax
  586.     mov    bx, sp
  587.     mov    bp, sp
  588.  
  589.     mov    ax, [si].hndPortalID    ; store handle and skip if open
  590.     mov    [bp].dcbPortalID, ax
  591.     cmp    [si].hndPerm, 1
  592.     jne    accy
  593.     jmp    acc11
  594.  
  595. accy:    mov    [bp].dcbBufferPtr.segm, cs ; get active portal list - C'mon Guys
  596.     mov    [bp].dcbBufferPtr.offs, offset pList
  597.     mov    [bp].dcbBufferLen, maxHandles * 2
  598.     mov    ax, dllReadPlist
  599.     int    dllInt
  600.  
  601.     mov    cx, [bp].dcbBufferLen    ; scan for match
  602.     mov    [bp].dcbBufferPtr.segm, cs
  603.     mov    [bp].dcbBufferPtr.offs, offset pStat
  604.     mov    [bp].dcbBufferLen, size PSB
  605.     mov    di, offset pList
  606. acc10:    mov    ax, [di]
  607.     mov    word ptr [bp].dcbPortalID, ax
  608.     mov    ax, dllReadPortal
  609.     int    dllInt
  610.     mov    ax, dllerrPTinuse
  611.     cmp    dx, word ptr pStat.psbPtype
  612.     je    acc13
  613.     add    di, 2
  614.     loop    acc10
  615.  
  616.     mov    [bp].dcbPad, dllNoPad    ; open portal
  617.     mov    [bp].dcbMode, dllModeDIX
  618.     cmp    dx, 3781h
  619.     jne    accx
  620.     cmp    flag802, 1
  621.     jne    accx
  622.     mov    [bp].dcbMode, dllMode802
  623. accx:    mov    word ptr [bp].dcbLScallback.segm, 0
  624.     mov    word ptr [bp].dcbLScallback.offs, 0
  625.     mov    word ptr [bp].dcbRXcallback.segm, cs
  626.     mov    word ptr [bp].dcbRXcallback.offs, offset rx_upc
  627.     mov    word ptr [bp].dcbTXcallback.segm, cs
  628.     mov    word ptr [bp].dcbTXcallback.offs, offset tx_upc
  629.     mov    word ptr [bp].dcbPType, dx
  630.     mov    ax, dllOpen
  631.     int    dllInt
  632.  
  633.     cmp    ax, dllerrSuccess    ; check for success
  634.     jne    acc13
  635.  
  636.     mov    ax, [bp].dcbPortalID    ; store portal ID
  637.     mov    [si].hndPortalID, ax
  638.  
  639. acc11:    cmp    word ptr [si].hndReceive.segm, 0 ; check for permanent flag
  640.     jne    acc12                 ; where es:bx = 0:0
  641.     cmp    word ptr [si].hndReceive.offs, 0
  642.     jne    acc12
  643.  
  644.     add    sp, size DCB        ; deallocate DCB
  645.     pop    bp            ; restore register pointer
  646.     mov    [si].hndPerm, 1        ; set permanent flag
  647.     jmp    good            ; done
  648.  
  649. acc12:    lea    di, [bp].dcbSaddr    ; enable broadcasts
  650.     mov    cx, ethAddrLen / 2
  651.     mov    ax, -1
  652.     rep    stosw
  653.     mov    ax, dllEnbMulti
  654.     int    dllInt
  655.  
  656.     add    sp, size DCB        ; deallocate DCB
  657.     pop    bp            ; restore register pointer
  658.  
  659.     mov    [si].hndInUse, 1    ; set in use flag
  660.     mov    [bp]._ax, si        ; return handle
  661.     jmp    good            ; done
  662.  
  663. acc13:    add    sp, size DCB        ; deallocate DCB
  664.     pop    bp            ; restore register pointer
  665.  
  666.     mov    dh, pkterrTypeInuse    ; protocol in use error
  667.     cmp    ax, dllerrPTinuse
  668.     je    acc14
  669.     mov    dh, pkterrNoSpace    ; all other errors
  670. acc14:    jmp    bad            ; done
  671.  
  672. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  673. ;; PKT Function:  release_type          ;;
  674. ;;  regs inp: bx              ;;
  675. ;;  regs out: none              ;;
  676. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  677.  
  678. release_type:
  679.     mov    ax, cs            ; address handle table
  680.     mov    ds, ax
  681.     mov    si, [bp]._bx        ; BX trashed by dispatcher
  682.  
  683.     cmp    si, offset hndTab    ; skip if too small
  684.     jb    rel2
  685.     cmp    si, offset hndEnd    ; skip if too large
  686.     jae    rel2
  687.     cmp    [si].hndInUse, 1    ; skip if not in use
  688.     jne    rel2
  689.  
  690.     sub    sp, size DCB        ; allocate DCB on stack
  691.     mov    ax, ss
  692.     mov    es, ax
  693.     mov    bx, sp
  694.  
  695.     mov    ax, [si].hndPortalID    ; store portal ID
  696.     mov    es:[bx].dcbPortalID, ax
  697.  
  698.     lea    di, [bx].dcbSaddr    ; disable broadcasts
  699.     mov    cx, ethAddrLen / 2
  700.     mov    ax, -1
  701.     rep    stosw
  702.     mov    ax, dllDisMulti
  703.     int    dllInt
  704.  
  705.     cmp    [si].hndPerm, 1        ; check for permanent handle
  706.     je    rel1
  707.  
  708.     mov    ax, dllClose        ; close portal
  709.     int    dllInt
  710.  
  711. rel1:    add    sp, size DCB        ; deallocate DCB
  712.  
  713.     cmp    ax, dllerrSuccess    ; check for success
  714.     jne    rel2
  715.  
  716.     mov    [si].hndInUse, 0    ; clear in use flag
  717.     jmp    good
  718.  
  719. rel2:    mov    dh, pkterrBadHandle    ; return bad handle error
  720.     jmp    bad
  721.  
  722. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  723. ;; PKT Function:  send_pkt          ;;
  724. ;;  regs inp: ds,si,cx              ;;
  725. ;;  regs out: none              ;;
  726. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  727.  
  728. send_pkt:
  729.     call    send            ; call send packet routine
  730.     jmp    good
  731.  
  732. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  733. ;; PKT Function:  terminate          ;;
  734. ;;  regs inp: bx              ;;
  735. ;;  regs out: none              ;;
  736. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  737.  
  738. terminate:
  739.     call    safe            ; check for windows or task switcher
  740.     jnz    term5
  741.  
  742.     mov    si, offset hndTab    ; address handle table
  743. term1:    cmp    cs:[si].hndInUse, 1    ; check for handles in use
  744.     je    term5
  745.     add    si, size HND
  746.     cmp    si, offset hndEnd
  747.     jb    term1
  748.  
  749.     xor    ax, ax            ; check for hooked vector
  750.     mov    ds, ax
  751.     mov    dx, cs
  752.     mov    bx, cs:pktVec
  753.     cmp    [bx].segm, dx
  754.     jne    term5
  755.     cmp    [bx].offs, offset intpkt
  756.     jne    term5
  757.  
  758.     sub    sp, size DCB        ; allocate DCB on stack
  759.     mov    ax, ss
  760.     mov    es, ax
  761.     mov    bx, sp
  762.  
  763.     mov    si, offset hndTab    ; address handle table
  764. term2:    cmp    cs:[si].hndPerm, 1    ; check for permanent handles
  765.     jne    term3
  766.     mov    ax, cs:[si].hndPortalID ; free portal
  767.     mov    es:[bx].dcbPortalID, ax
  768.     mov    ax, dllClose
  769.     int    dllInt
  770. term3:    add    si, size HND
  771.     cmp    si, offset hndEnd
  772.     jb    term2
  773.  
  774.     mov    ax, dllStartMOP        ; re-enable MOP
  775.     int    dllInt
  776.     mov    ax, dllEnaMOPmulti
  777.     int    dllInt
  778.  
  779.     add    sp, size DCB        ; deallocate DCB
  780.  
  781.     mov    bx, cs:pktVec        ; restore vector
  782.     xor    ax, ax
  783.     cli
  784.     mov    [bx].segm, ax
  785.     mov    [bx].offs, ax
  786.     sti
  787.  
  788.     mov    ax, cs            ; address TSR memory
  789.     mov    es, ax
  790.  
  791.     cmp    ax, [bp]._cs        ; avoid releasing memory twice
  792.     je    term4            ; when calling itself
  793.  
  794.     mov    ah, 49h            ; release TSR memory
  795.     int    21h
  796. term4:    jmp    good
  797.  
  798. term5:    mov    dh, pkterrCantTerminate    ; return can't terminate error
  799.     jmp    bad
  800.  
  801. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  802. ;; PKT Function:  get_address          ;;
  803. ;;  regs inp: bx,es,di,cx          ;;
  804. ;;  regs out: cx              ;;
  805. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  806.  
  807. get_address:
  808.     cmp    cx, ethAddrLen        ; check buffer length
  809.     jnb    get1
  810.     mov    dh, pkterrNoSpace
  811.     jmp    bad
  812.  
  813. get1:    mov    ax, cs            ; copy ethernet address
  814.     mov    ds, ax
  815.     mov    si, offset ether
  816.     mov    cx, ethAddrLen / 2
  817.     rep    movsw
  818.     mov    [bp]._cx, ethAddrLen
  819.     jmp    good
  820.  
  821. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  822. ;; PKT Function:  reset_interface     ;;
  823. ;;  regs inp: bx              ;;
  824. ;;  regs out: none              ;;
  825. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  826.  
  827. reset_interface:
  828.     mov    dh, pkterrCantReset    ; return can't reset error
  829.     jmp    bad
  830.  
  831. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  832. ;; PKT Function:  get_parameters      ;;
  833. ;;  regs inp: none              ;;
  834. ;;  regs out: es,di              ;;
  835. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  836.  
  837. get_parameters:
  838.     mov    [bp]._es, cs        ; return parameter block address
  839.     mov    [bp]._di, offset param
  840.     jmp    good
  841.  
  842. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  843. ;; PKT Function:  as_send_pkt          ;;
  844. ;;  regs inp: ds,si,cx,es,di          ;;
  845. ;;  regs out: none              ;;
  846. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  847.  
  848. as_send_pkt:
  849.     call    send            ; call send packet routine
  850.  
  851.     mov    ds, [bp]._es        ; call application upcall
  852.     mov    si, [bp]._di
  853.     mov    es, [bp]._ds
  854.     mov    di, [bp]._si
  855.     xor    ax, ax
  856.     call    dword ptr [si]
  857.  
  858.     jmp    good
  859.  
  860. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  861. ;; Packet Driver Function Table          ;;
  862. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  863.  
  864. funTab    dw    not_implemented        ; 0
  865.     dw    driver_info        ; 1
  866.     dw    access_type        ; 2
  867.     dw    release_type        ; 3
  868.     dw    send_pkt        ; 4
  869.     dw    terminate        ; 5
  870.     dw    get_address        ; 6
  871.     dw    reset_interface        ; 7
  872.     dw    not_implemented        ; 8
  873.     dw    not_implemented        ; 9
  874.     dw    get_parameters        ; 10
  875.     dw    as_send_pkt        ; 11
  876. maxFun    equ    ($ - offset funTab) / 2
  877.  
  878. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  879. ;; Packet Driver Interrupt Routine    ;;
  880. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  881.  
  882. intpkt: jmp    short int1        ; skip signature
  883.     nop
  884.  
  885. sig    db    'PKT DRVR', 0
  886.  
  887. int1:    sti                ; enable interrupts
  888.     cld                ; set forward direction
  889.  
  890.     push    ax            ; save all registers - hmmph!
  891.     push    bx
  892.     push    cx
  893.     push    dx
  894.     push    si
  895.     push    di
  896.     push    bp
  897.     push    ds
  898.     push    es
  899.     
  900.     mov    bp, sp            ; address registers with BP
  901.  
  902.     and    [bp]._flags, not carry    ; set success status
  903.  
  904.     cmp    ah, maxFun        ; validate function request
  905.     jb    int2
  906.     xor    ah, ah
  907.  
  908. int2:    mov    bl, ah            ; call function
  909.     xor    bh, bh            ;  note that BP must be preserved
  910.     shl    bx, 1            ;  within the functions
  911.     jmp    cs:funTab[bx]
  912.  
  913. bad:    or    [bp]._flags, carry    ; set error status
  914.     mov    [bp]._dh, dh
  915.  
  916. good:    pop    es            ; restore registers - hmmph!
  917.     pop    ds
  918.     pop    bp
  919.     pop    di
  920.     pop    si
  921.     pop    dx
  922.     pop    cx
  923.     pop    bx
  924.     pop    ax
  925.     iret
  926.  
  927. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  928. ;; Discardable PKT and DLL Init Code  ;;
  929. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  930.  
  931. start:    cld
  932.  
  933.     mov    dx, offset message    ; print copyright message
  934.     mov    ah, 9
  935.     int    21h
  936.  
  937.     call    safe            ; check for windows or task switcher
  938.     jz    parse
  939.     mov    dx, offset unsafe    ; print unsafe error and exit
  940.     mov    al, doserrError
  941.     jmp    exit
  942.  
  943. ; Parse Command Line
  944. parse:    mov    bp, offset cmdBuf + 1    ; address command line buffer
  945.  
  946.     mov    si, 60h            ; get new driver vector
  947.     mov    di, 7fh
  948.     call    space
  949.     call    number
  950.     jc    parse2
  951.  
  952.     add    ax, ax            ; store new driver vector
  953.     add    ax, ax
  954.     mov    pktVec, ax
  955.  
  956.     mov    si, 005efh
  957.     mov    di, 0fffeh
  958.     mov    bx, offset proto
  959. parse1:    push    bx            ; get protocol type
  960.     call    space
  961.     call    number
  962.     pop    bx
  963.     jc    parse2
  964.  
  965.     xchg    al, ah            ; store protocol type
  966.     mov    [bx], ax
  967.     add    bx, 2
  968.     mov    word ptr [bx], 0
  969.     cmp    ax, 0
  970.     jne    parse1
  971.  
  972. parse2:    call    space            ; check for switches
  973.     cmp    al, cr
  974.     je    check
  975.     mov    bx, ax            ; save switch
  976.  
  977.     add    bp, 2            ; check end of line
  978.     call    space
  979.     cmp    al, cr
  980.     je    parse4
  981.  
  982. parse3:    mov    dx, offset usage    ; print usage error and exit
  983.     mov    ah, doserrUsage
  984.     jmp    exit
  985.  
  986. parse4:    or    ah, 20h
  987.     cmp    bx, "n/"
  988.     je    novell
  989.     cmp    bx, "u/"
  990.     jne    parse3
  991.  
  992. ; Terminate Packet Driver
  993. term:    call    exist            ; check for existing driver
  994.     mov    dx, offset missing
  995.     mov    al, doserrError
  996.     jne    trm1
  997.  
  998.     mov    ah, pktTerminate    ; call packet driver to terminate
  999.     pushf
  1000.     call    dword ptr es:[bx]
  1001.  
  1002.     mov    dx, offset termin    ; print success and exit
  1003.     mov    al, doserrSuccess
  1004.     jnc    trm1
  1005.  
  1006.     mov    dx, offset active    ; print fail and exit
  1007.     mov    al, doserrError
  1008.  
  1009. trm1:    jmp    exit
  1010.  
  1011. ; Set Novell Netware 802.3 Flag
  1012. novell:    mov    flag802, 1
  1013.  
  1014. ; Perform Pre-Install Checks
  1015. check:    call    exist            ; check for existing driver
  1016.     mov    dx, offset already
  1017.     mov    al, doserrExists
  1018.     je    check1
  1019.  
  1020.     mov    dx, offset inuse    ; check for null vectors
  1021.     mov    al, doserrError
  1022.     cmp    es:[bx].segm, 0
  1023.     jne    check1
  1024.     cmp    es:[bx].offs, 0
  1025.     jne    check1
  1026.  
  1027.     mov    bx, schInt * 4        ; check for DLL
  1028.     les    bx, es:[bx]
  1029.     mov    dx, offset no_dll
  1030.     mov    al, doserrError
  1031.     cmp    byte ptr es:[bx]-3, 'S'
  1032.     jne    check1
  1033.     cmp    byte ptr es:[bx]-2, 'C'
  1034.     jne    check1
  1035.     cmp    byte ptr es:[bx]-1, 'H'
  1036.     jne    check1
  1037.  
  1038.     mov    ax, dllInsCheck
  1039.     int    dllInt
  1040.     cmp    ax, dllerrNotImpl
  1041.     mov    al, doserrError
  1042.     je    setup
  1043.  
  1044. check1:    jmp    exit            ; print error and exit
  1045.  
  1046. ; Setup and Start Packet Driver
  1047. setup:    push    ds            ; save data segment
  1048.     sub    sp, size DCB        ; allocate DCB on stack
  1049.     mov    ax, ss
  1050.     mov    es, ax
  1051.     mov    bx, sp
  1052.  
  1053.     mov    ds, ax            ; address ethernet address buffer
  1054.     lea    si, [bx].dcbSaddr
  1055.  
  1056.     mov    ax, dllReadChan        ; get ethernet address
  1057.     int    dllInt
  1058.  
  1059.     mov    ax, cs            ; copy ethernet address
  1060.     mov    es, ax
  1061.     mov    di, offset ether
  1062.     mov    cx, ethAddrLen / 2
  1063.     rep    movsw
  1064.  
  1065.     mov    ax, dllStopMOP        ; disable MOP
  1066.     int    dllInt
  1067.  
  1068.     add    sp, size DCB        ; deallocate DCB
  1069.     pop    ds            ; restore data segment
  1070.  
  1071.     xor    ax, ax            ; get hardware interrupt vector
  1072.     mov    es, ax
  1073.     mov    bx, schInt * 4
  1074.     mov    ax, es:[bx].segm
  1075.  
  1076.     mov    bx, hd1Int * 4 + 4    ; scan 1st bank skipping the timer
  1077.     mov    cx, 7
  1078. setup1:    cmp    ax, es:[bx].segm
  1079.     je    setup3
  1080.     add    bx, 4
  1081.     loop    setup1
  1082.  
  1083.     mov    bx, hd2Int * 4        ; scan 2nd bank
  1084.     mov    cx, 8
  1085. setup2:    cmp    ax, es:[bx].segm
  1086.     je    setup3
  1087.     add    bx, 4
  1088.     loop    setup2
  1089.  
  1090.     mov    bx, 0            ; clear if no match
  1091. setup3:    shr    bx, 1            ; store interrupt vector
  1092.     shr    bx, 1
  1093.     mov    param.prmIntNum, bx
  1094.  
  1095.     mov    bx, pktVec        ; setup up interrupt vectors
  1096.     cli
  1097.     mov    es:[bx].segm, cs
  1098.     mov    es:[bx].offs, offset intpkt
  1099.     sti
  1100.  
  1101.     push    es:[bx].segm        ; hold open protocol types for Windows
  1102.     push    es:[bx].offs        ; special permanent flag: es:di = 0:0
  1103.     mov    bp, sp
  1104.  
  1105.     xor    di, di            ; initialize registers
  1106.     mov    si, offset proto
  1107.     mov    cx, ethTypeLen
  1108.     mov    dl, pktNumber
  1109.     mov    bx, pktType
  1110.     mov    al, pktClass
  1111.     mov    ah, pktAccessType
  1112.  
  1113. setup4:    cmp    word ptr [si], 0    ; address protocol types
  1114.     je    setup6
  1115.  
  1116.     pushf                ; call packet driver to open
  1117.     call    dword ptr [bp]
  1118.     inc    si
  1119.     inc    si
  1120.     jnc    setup4
  1121.  
  1122.     mov    ah, pktTerminate    ; call packet driver to terminate
  1123.     mov    al, dh
  1124.     pushf
  1125.     call    dword ptr [bp]
  1126.     add    sp, 4            ; clean up stack
  1127.  
  1128.     mov    dx, offset ptinuse    ; print failure message and exit
  1129.     cmp    al, pkterrTypeInuse
  1130.     je    setup5
  1131.     mov    dx, offset nospace
  1132. setup5:    mov    al, doserrError
  1133.     jmp    short exit
  1134.  
  1135. setup6:    add    sp, 4            ; clean up stack
  1136.  
  1137. ; Print Message and Become Resident
  1138. ;
  1139. tsr:    mov    dx, offset install    ; print success message
  1140.     mov    ah, 9
  1141.     int    21h
  1142.  
  1143.     mov    es, envSeg        ; free environment space
  1144.     mov    ah, 49h
  1145.     int    21h
  1146.     mov    envSeg, 0
  1147.  
  1148.     mov    cx, 5            ; close all standard file handles
  1149.     xor    bx, bx
  1150. tsr1:    mov    ah, 3eh
  1151.     int    21h
  1152.     inc    bx
  1153.     loop    tsr1
  1154.  
  1155.     mov    dx, offset start    ; terminate and stay resident
  1156.     add    dx, 0fh
  1157.     mov    cl, 4
  1158.     shr    dx, cl
  1159.     mov    ax, 3100h
  1160.     int    21h
  1161.  
  1162. ; Print Message and Terminate
  1163. ;
  1164. exit:    push    ax            ; print message
  1165.     mov    ah, 9
  1166.     int    21h
  1167.     pop    ax
  1168.  
  1169.     mov    ah, 4ch            ; terminate with status
  1170.     int    21h
  1171.  
  1172. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1173. ;; Discardable Init Code Subroutines  ;;
  1174. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1175.  
  1176. space:    cmp    byte ptr [bp], ' '    ; skip spaces and tabs
  1177.     je    space1
  1178.     cmp    byte ptr [bp], tab
  1179.     je    space1
  1180.     mov    ax, word ptr [bp]
  1181.     ret
  1182. space1:    inc    bp
  1183.     jmp    short space
  1184.  
  1185. number:    xor    ax, ax            ; clear number
  1186.     mov    cx, -1
  1187.  
  1188.     cmp    word ptr [bp], 'x0'    ; remove prefix if any
  1189.     je    num1
  1190.     cmp    word ptr [bp], 'X0'
  1191.     je    num1
  1192.     jmp    short num2
  1193. num1:    xor    cx, cx
  1194.     add    si, 2
  1195.  
  1196. num2:    mov    bl, byte ptr [bp]    ; validate digit
  1197.     cmp    bl, '0'
  1198.     jb    num5
  1199.     cmp    bl, '9'
  1200.     ja    num4
  1201.  
  1202. num3:    xor    cx, cx            ; add digit
  1203.     mov    dx, 10h
  1204.     mul    dx
  1205.     cmp    dx, 0
  1206.     jnz    num6
  1207.     sub    bl, '0'
  1208.     xor    bh, bh
  1209.     add    ax, bx
  1210.     inc    bp
  1211.     jmp    num2
  1212.  
  1213. num4:    or    bl, 20h            ; check for hex
  1214.     cmp    bl, 'a'
  1215.     jb    num5
  1216.     cmp    bl, 'f'
  1217.     ja    num5
  1218.     sub    bl, 'a' - '9' - 1
  1219.     jmp    num3
  1220.  
  1221. num5:    cmp    cx, 0            ; skip if no number entered
  1222.     jnz    num8
  1223.  
  1224.     mov    bl, byte ptr [bp]    ; ok if space, tab, switch or return
  1225.     cmp    bl, ' '
  1226.     je    num7
  1227.     cmp    bl, tab
  1228.     je    num7
  1229.     cmp    bl, '/'
  1230.     je    num7
  1231.     cmp    bl, cr
  1232.     je    num7
  1233.  
  1234.     mov    dx, offset usage    ; print usage error and exit
  1235.     mov    al, doserrUsage
  1236.     jmp    exit
  1237.  
  1238. num6:    mov    dx, offset range    ; number out of range
  1239.     mov    al, doserrRange
  1240.     jmp    exit
  1241.  
  1242. num7:    cmp    ax, si            ; check interrupt number
  1243.     jb    num6
  1244.     cmp    ax, di
  1245.     ja    num6
  1246. num8:    add    cx, 1
  1247.     ret
  1248.  
  1249. exist:    xor    ax, ax            ; check for existing driver
  1250.     mov    es, ax
  1251.     mov    bx, pktVec
  1252.  
  1253.     push    es
  1254.     les    di, es:[bx]
  1255.     add    di, 3
  1256.     mov    si, offset sig
  1257.     mov    cx, 9
  1258.     rep    cmpsb
  1259.     pop    es
  1260.     ret
  1261.  
  1262. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1263. ;; Discardable Init Code Data          ;;
  1264. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1265.  
  1266. message    db    'PKTDLL 1.1'                        , eol
  1267.     db    '(c) Copyright Brian Angus 1992.  All rights reserved.'    , eol
  1268.     db    'This software is provided with NO WARRANTY.'      , eol    , eos
  1269. install    db    'PKTDLL is installed and ready.'            , eos
  1270. termin    db    'PKTDLL successfully unloaded.'                , eos
  1271. usage    db    'Usage: PKTDLL [packet_int] [proto_type...] [/n] [/u].'    , eos
  1272. range    db    'Specified values are out of range (60-7F, 05EF-FFFE).'    , eos
  1273. no_dll    db    'Please start the DLL driver first.'            , eos
  1274. already    db    'A driver is already installed at this vector.'        , eos
  1275. inuse    db    'Specified interrupt is already in use.'        , eos
  1276. nospace    db    'Not enough portals for requested protocols.'        , eol
  1277.     db    'Unload some protocols (ie. LAT, LAST, etc.)'        , eos
  1278. ptinuse    db    'Protocol type(s) are already in use.'            , eol
  1279.     db    'Check specified and/or default protocols.'        , eos
  1280. missing    db    'PKTDLL is not loaded at specified vector.'        , eos
  1281. active    db    'Cannot unload PKTDLL - protocols still active.'    , eos
  1282. unsafe    db    'Cannot load or unload PKTDLL in this environment.'    , eos
  1283. proto    dw    0008h, 0608h, 3580h, 0000h
  1284.  
  1285. CODE    ends
  1286.     end    at100h
  1287.