home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / pksnd102.zip / DUMMY.ASM < prev    next >
Assembly Source File  |  1997-01-06  |  8KB  |  289 lines

  1. TITLE DUMMY.ASM: Assembly GROUP directive used to create .COM file.
  2.  
  3. Comment |
  4. ******************************************************************
  5.  
  6. File:       DUMMY.ASM
  7. Author:     Patrick Whittle
  8. Date:       2/27/95
  9. Assembler:  TASM 3.1 in MASM mode
  10.  
  11. Purpose:    Install at given interrupt vector to accept packet data
  12.  
  13. ******************************************************************|
  14.  
  15. comGrp GROUP  dSeg1, dSeg2, cSeg
  16.  
  17. cSeg   SEGMENT WORD 'CODE'
  18. cSeg   ENDS
  19. dSeg1  SEGMENT WORD PUBLIC 'DATA'
  20. dSeg1  ENDS
  21. dSeg2  SEGMENT WORD PUBLIC 'DATA'
  22. dSeg2  ENDS
  23.  
  24. CR               EQU     0Dh
  25. LF               EQU     0Ah
  26. envBlock         EQU     2Ch  ; A pointer can be found offset 2C into PSP
  27.  
  28. dSeg1  SEGMENT
  29. tsrMessage       DB 'FTP Packet Driver Emulator v1.02 Copyright (c) Patrick Whittle, 1995-1997', CR, LF
  30.                  DB 09, 'Program using interrupt '
  31. intUsing         DB 00, 00, ' hex, now resident at ', 0
  32. errorMess1       DB 'Error: Interrupts 60h to 80h are unavailable.', CR, LF, 0
  33. errorMess2       DB 'An FTP packet driver is already installed.', CR, LF, 0
  34. intNo            DB 0FFh
  35. dSeg1  ENDS
  36.  
  37. dSeg2  SEGMENT                             ; Uninitialized data here.
  38. SaveBX           DW      ?
  39.  
  40. dSeg2  ENDS
  41.  
  42. cSeg   SEGMENT
  43.  
  44.     ASSUME  cs:comGrp, ds:comGrp, es:comGrp, ss:comGrp
  45.     .186
  46.     ORG   100h
  47.  
  48. pktRoutine PROC NEAR
  49.  
  50.     call hookIn      ; never returns
  51.  
  52. pktRoutine ENDP
  53.  
  54. ;----------------------------------------------
  55.  
  56. residentCode:
  57.     jmp   over
  58.     nop              ; necessary to add to 3 bytes
  59.  
  60. signature DB 'PKT DRVR', 0           ; Any resident data can follow this, but
  61.                                      ;   cannot come before.
  62. residentData     EQU     THIS BYTE
  63. installedAddress EQU     THIS BYTE
  64. newseg           DW      2 DUP (?)
  65.                  DB      ':'
  66. newoff           DW      2 DUP (?)
  67. Cr_Lf            DB      CR, LF, 0
  68.  
  69. over:
  70.     cmp   ah, 4             ; ftp function to send packet
  71.     jne   intDone
  72.  
  73.     push  ax
  74.     push  bx
  75.     push  ds
  76.  
  77.     mov   bx, cs
  78.     mov   ds, bx            ; point to our data.
  79.     lea   bx, Cr_Lf
  80.     call  dispString        ; advance the cursor
  81.  
  82.     mov   ah, 0Fh           ; get current video mode
  83.     int   10h               ; will return active video page in bh
  84.     mov   ah, 3             ; get cursor position
  85.     int   10h
  86.     mov   ah, 2             ; set cursor position
  87.     inc   dl                ; advance cursor one column
  88.     int   10h
  89.  
  90.     pop   ds                ; point back to callers data
  91.     mov   bx, si            ; pointer passed by caller in si register
  92.     add   bx, 14            ; Point past the address portion of packet
  93.     ;call  dispString        ; display the packet string
  94.     pop   bx
  95.     pop   ax
  96.  
  97. intDone:
  98.     iret
  99.  
  100. dispString PROC NEAR
  101. ;
  102. ;  Print ASCIIZ strings.
  103. ;
  104.     push  ax
  105.     push  dx
  106.     mov   ah, 02h
  107.  
  108. sendPrompt:
  109.     cmp   BYTE PTR [bx], 00h
  110.     je    promptDone
  111.     mov   dl, BYTE PTR [bx]
  112.     int   21h
  113.     inc   bx
  114.     jmp   sendPrompt
  115.  
  116. promptDone:
  117.     pop   dx
  118.     pop   ax
  119.     ret
  120.  
  121. dispString ENDP
  122.  
  123. showAddr PROC NEAR
  124. ;
  125. ;  The caller must ensure ES:DX contains address to be converted.  Once this
  126. ;  procedure is called, "installedAddress" can be printed subsequently for
  127. ;  any purpose.  Calling a second time with new ES:DX value will replace
  128. ;  contents of "installedAddress".
  129. ;
  130.     push  dx
  131.     mov   ax, es
  132.     call  ConHexLong                 ; 357D for example in AX is returned as
  133.     mov   BYTE PTR newseg, al        ; DX:AX ---> 4437:3533
  134.     mov   BYTE PTR newseg+1, ah      ;            D 7  5 3   in ASCII.
  135.     mov   BYTE PTR newseg+2, dl      ; We then store appropriately in memory
  136.     mov   BYTE PTR newseg+3, dh      ; (i.e. al, ah, dl, then dh).
  137.  
  138.     pop   ax                         ; Now convert offset portion of ES:DX
  139.     call  ConHexLong
  140.     mov   BYTE PTR newoff, al
  141.     mov   BYTE PTR newoff+1, ah
  142.     mov   BYTE PTR newoff+2, dl
  143.     mov   BYTE PTR newoff+3, dh
  144.  
  145.     lea   bx, installedAddress
  146.     call  dispString
  147.     ret
  148.  
  149. showAddr ENDP
  150.  
  151. ConHex PROC
  152. ;
  153. ; The following routine converts the number in AL into an ASCII
  154. ; representation of the hex value, with a leading zero.  Value
  155. ; is returned in AX as well.
  156.  
  157.     mov   cl, 10h             ; What we will be dividing by
  158.     mov   ah, 0
  159.     div   cl                  ; Divide by 16
  160.     add   al, 30h
  161.     add   ah, 30h
  162.     cmp   al, '9'             ; Is it greater than 9?
  163.     jbe   CA4                 ; No, so continue
  164.     add   al, 7               ; Make into hex digit
  165.  
  166. CA4:        
  167.     cmp   ah, '9'             ; Is it greater than 9?
  168.     jbe   CA5                 ; No, so continue
  169.     add   ah, 7               ; Make into hex digit
  170.  
  171. CA5:        
  172.     ret
  173.  
  174. ConHex ENDP
  175.  
  176. ConHexLong PROC
  177. ;
  178. ; The following uses ConHex to convert a long number (AX) into it's ASCII
  179. ; equivalent in DX:AX.
  180.  
  181.     push  ax
  182.     call  ConHex
  183.     mov   dx, ax
  184.     pop   ax
  185.     mov   al, ah
  186.     call  ConHex
  187.     ret
  188.  
  189. ConHexLong ENDP
  190.  
  191. ;---------------- transient code begins here ----------------
  192.  
  193. hookIn PROC NEAR
  194. ;
  195.     push  es                 ; This first block of code checks if DUMMY.COM
  196.     push  bx                 ; is already installed.
  197.     mov   al, 80h            ; About to search backwards between 80h and 60h
  198.  
  199. scanVector:
  200.     mov   ah, 35h              ; getvect function of int 21h
  201.     int   21h                  ; ES:BX receive vector
  202.     mov   WORD PTR SaveBX, bx
  203.     mov   dx, es
  204.     add   dx, bx
  205.     cmp   dx, 0                ; Check for null pointer
  206.     je    continue             ; Okay to install
  207.  
  208.     call  chkSignature         ; Returns true or false in ZF flag.
  209.     jz    errorType2           ; Jump if an ftp driver is already present.
  210.     jmp   loopBottom
  211.  
  212. continue:                      ; Nothing is installed if we reach this point.
  213.     mov   BYTE PTR intNo, al   ; set to 0FFh at begining
  214.  
  215. loopBottom:
  216.     dec   al
  217.     cmp   al, 60h
  218.     jae   scanVector
  219.  
  220.     cmp   BYTE PTR intNo, 0FFh  ; Were absolutely no vectors available?
  221.     je    errorType1
  222.  
  223.     mov   ah, 25h               ; setvect returns installed address in DS:DX
  224.     mov   al, BYTE PTR intNo
  225.     lea   dx, residentCode      ; point intNo to the code in "residentCode"
  226.     int   21h
  227.  
  228.     lea   bx, tsrMessage
  229.     call  dispString
  230.     mov   ah, BYTE PTR intNo
  231.     shr   ax, 8               ; 6000 in ax becomes 0060
  232.     call  ConHex
  233.     mov   WORD PTR intUsing, ax
  234.     lea   bx, intUsing
  235.     call  dispString
  236.     push  ds
  237.     pop   es                  ; we need what setvect returned in ES
  238.     call  showAddr            ; Display address returned from setvect above.
  239.                               ; Ensure ES:DX contains seg:offset before hand!
  240.     mov   es, ds:[envBlock]
  241.     mov   ah, 49h             ; Free memory not needed (i.e. transient code)
  242.     int   21h
  243.     
  244.     lea   dx, hookIn      ; end of resident area
  245.     shr   dx, 4           ; num in paragraphs to keep resident (divide by 16)
  246.     inc   dx              ; add 1 for safety
  247.     mov   ax, 3100h       ; Function to go TSR
  248.  
  249. exitPgm:
  250.     pop   bx
  251.     pop   es
  252.     int   21h
  253.  
  254. errorType1:
  255.     lea   bx, errorMess1
  256.     jmp   errorCommon
  257.  
  258. errorType2:
  259.     lea   bx, errorMess2     ; This program, or valid ftp packet driver
  260.                              ;  is already resident.
  261. errorCommon:
  262.     call  dispString
  263.     mov   ax, 4CFFh          ; Return DOS errorlevel
  264.     jmp   exitPgm
  265.  
  266. hookIn ENDP
  267.  
  268. chkSignature PROC NEAR
  269. ;
  270. ; Input:   ES:BX contining interrupt vector returned from getvect
  271. ;          DS points to our data
  272. ;
  273. ; Returns: True or False condition in zero flag (i.e. ZF=1 for True).
  274. ;
  275.     mov   di, bx
  276.     add   di, 3
  277.     lea   si, signature
  278.     lea   cx, residentData
  279.     sub   cx, si             ; subtract start from end to get length
  280.     cld                      ; clear direction flag
  281.     repe  cmpsb              ; zero flag set to 0 if not equal
  282.     ret           
  283.  
  284. chkSignature ENDP
  285.  
  286. cSeg   ENDS
  287.  
  288. END pktRoutine
  289.