home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / asm / 80x0393 / h2namfx.txt < prev    next >
Encoding:
Text File  |  1993-12-03  |  6.9 KB  |  185 lines

  1. (188)   Thu 2 Dec 93  1:08p     Rcvd: Sat 4 Dec 12:16a
  2. By: Ed Beroset, Durham Net NEC (1:3641/1.250)
  3. To: Terry Carmen
  4. Re: Handles to filenames
  5. St: Pvt Kill Rcvd
  6. ---------------------------------------------------------------------------
  7. @INTL 1:260/338 1:3641/1
  8. @FMPT 250
  9. @MSGID: 1:3641/1.250 3801a007
  10. @REPLY: 1:260/338@Fidonet a7814fc3
  11. In a msg on <Dec 02 13:08>, to Ed Beroset, Terry Carmen writes:
  12.  TC> Ed, is this yours?
  13.  
  14. Yep.  Sure is.
  15.  
  16.  TC> Could you send me a copy of your original? I'll replace it in the
  17.  TC> snippets file. Inbar either sent or posted this as his, since I
  18.  TC> don't change the files when they come in.
  19.  
  20. Cheeky devil, isn't he?  Here's the original:
  21.  
  22. ;  HNDLNAME.ASM
  23. ;  written on 3 February 1993 by Ed Beroset
  24. ;  released to the public domain by the author.
  25. ;
  26. ;  Given a DOS handle number, the hndl2name function will return a
  27. ;  pointer to the associated file name.  This code illustrates the
  28. ;  use of this function.
  29. ;
  30.   MODEL small
  31.   IDEAL
  32.   STACK 100h
  33.  
  34. DOS_GET_DOS_VERSION     = 030h
  35. DOS_OPEN_FILE           = 03Dh
  36. DOS_CLOSE_FILE          = 03Eh
  37. DOS_WRITE_TO_HANDLE     = 040h
  38. DOS_TERMINATE_EXE       = 04Ch
  39. DOS_GET_LIST_OF_LISTS   = 052h
  40. DOS_GET_PSP             = 062h
  41.  
  42. STDOUT                  = 1    ; stdout device handle
  43. READ_ONLY               = 0    ; file mode equate
  44.  
  45. MACRO DosInt  function
  46.   mov ah,function              ; this doesn't require much explanation
  47.   int 21h
  48.   ENDM
  49.  
  50. MACRO ShowStr string, strlen, device
  51.   IFDIF <string>,<dx>
  52.     lea dx,[string]            ; note that string is assumed to be in DS
  53.   ENDIF
  54.   mov cx,strlen                ; note no error checking
  55.   IFB <device>
  56.     mov bx,STDOUT              ; default device...
  57.   ELSE
  58.     mov bx,device              ; ...or passed device
  59.   ENDIF
  60.   DosInt DOS_WRITE_TO_HANDLE   ; show the string
  61.   ENDM
  62.  
  63. DATASEG
  64.  
  65. Msg1    DB "This program tests the hndl2name function.",13,10
  66. Msg1Len =  $-Msg1
  67.  
  68. STRUC   magic
  69.   dosmin   DB  0               ; minor DOS version
  70.   dosmaj   DB  0               ; major DOS version
  71.   SFTsize  DB  ?               ; system file table entry size (in bytes)
  72.   NameOffs DB  ?               ; offset from SFT start to first name
  73. ENDS    magic
  74.  
  75. voodoo  magic <0,4,3bh,26h>    ; DOS 4.0
  76.         magic <1,3,35h,26h>    ; DOS 3.1
  77.         magic <0,3,38h,27h>    ; DOS 3.0
  78.         magic <0,2,28h,0ah>    ; DOS 2.0
  79.         magic <>               ; end of table marker
  80.  
  81. SFTlength DB  ?
  82. SFTname   DB  ?
  83.  
  84. Dummy   DB "hndlname.asm",0    ; the name of this file
  85. Handle  DW  ?                  ; handle for this file when opened
  86.  
  87.  
  88. CODESEG
  89. Start:
  90.   mov ax,@data                 ; point DS to our own data segment
  91.   mov ds,ax
  92.   ShowStr Msg1,Msg1Len         ; print first message to user
  93.   DosInt DOS_GET_DOS_VERSION
  94.   xchg al,ah                   ; now straighten things out for our compares
  95.   mov cx,4                     ; four entries in table
  96.   lea bx,[voodoo]              ; consult our magic table
  97.  
  98. @@looky:
  99.   cmp ax,[WORD PTR bx]         ; is DOS version/rev correct?
  100.   ja  @@got_values             ; if it's greater than table value, it's OK
  101.   add bx,SIZE voodoo           ; otherwise increment to the next table entry
  102.   loop @@looky                 ; and jump back up
  103.                                ; should err_exit if < DOS 2.0 here, but...
  104. @@got_values:
  105.   mov ax,[WORD PTR bx+2]       ; get both SFTsize and NameOffs all at once
  106.   mov [WORD PTR SFTlength],ax  ; stow them the same way (cheat!)
  107.   mov dx,OFFSET Dummy          ; open dummy file
  108.   mov al,READ_ONLY             ; we don't need to modify this file!
  109.   DosInt DOS_OPEN_FILE         ;
  110.   mov [Handle],ax              ; save the handle for later use
  111.   mov bx,ax                    ; Hndl2Name requires handle number in BX
  112.   call Hndl2Name               ; test new function
  113.   push ds                      ; now ES:DX points to 11 chars
  114.   push es                      ;
  115.   pop  ds                      ; but we need DS:DX for ShowStr macro
  116.   ShowStr dx,11
  117.   pop  ds                      ; restore proper DS register
  118.   mov bx,[Handle]              ; close our dummy file
  119.   DosInt DOS_CLOSE_FILE        ;
  120.   mov al,0                     ; all successful, so error code = 0
  121.   DosInt DOS_TERMINATE_EXE
  122.  
  123. ; hndl2name
  124. ;
  125. ; PURPOSE:  given a handle, return pointer to ASCII file name
  126. ; INPUTS:   BX = handle of file to be named
  127. ;           SFTlength must be initialized and in current DS
  128. ;           SFTname   must be initialized and in current DS
  129. ; OUTPUTS:  ES:DX => ASCII file name (exactly 11 bytes long) (FCB format)
  130. ;
  131. PROC hndl2name
  132.   push ax                      ; save used registers
  133.   push bx
  134.   push si
  135.  
  136.   mov si,bx                    ; save original file handle in SI
  137.   DosInt DOS_GET_PSP           ; now get the PSP of this program
  138.   mov es,bx                    ; look in the PSP segment for the job file table
  139.   les bx,[es:34h]              ; now ES:BX => JFT
  140.   mov al,[es:bx+si]            ; now read table entry (index into SFT)
  141.   xor ah,ah                    ; clear out hi half of AX
  142.   mov si,ax                    ; now stow the SFT index
  143.   DosInt DOS_GET_LIST_OF_LISTS ; ES:BX => List Of Lists
  144.   les bx,[es:bx+4]             ; load up ES:BX => SFT
  145.  
  146. @@nextSFT:                     ; ES:BX => SFT at this point
  147.   cmp si,[es:bx+4]             ; is this handle in this SFT?
  148.   jb  @@SFT_ok                 ; if so, we're in the correct table
  149.   sub si,[es:bx+4]             ; otherwise, adjust index for next table
  150.   les bx,[es:bx]               ; and load address of next SFT
  151.   jmp @@nextSFT                ; loop back again
  152.  
  153. @@SFT_ok:
  154.   mov ax,si                    ; recall our adjusted SFT index
  155.   mov dl,[SFTlength]           ; SFTlength is the length of an SFT entry
  156.   mul dl                       ; ax = (SFT index) * (SFT length)
  157.   mov dl,[SFTname]             ; SFTname =offset from beginning of SFT to name
  158.   xor dh,dh                    ; clear out hi half of DX
  159.   add ax,dx                    ; ax = SFTindex * SFTlength + SFTname
  160.   add bx,ax                    ; bx = original offset + calc offset
  161.   mov dx,bx                    ; now ES:DX => file name string
  162.   pop si                       ; restore used registers
  163.   pop bx
  164.   pop ax
  165.   ret
  166. ENDP hndl2name
  167.  
  168.   END Start
  169. ---------------------
  170.  
  171. Hmmm... Maybe I should take a look at the snippets file and see if he's
  172. appropriated any other work of mine.  Thanks for your attention to this.
  173. Although the code has been in the public domain for almost two years now, it's
  174. still annoying to see somebody else's name on one's own work.  I think I'll
  175. just send a little netmail to Inbar Raz asking for an explanation.
  176.  
  177. -> Ed <-
  178.  
  179. @Via 1:3641/1@fidonet.org @19931203.110648 FrontDoor 2.20a.mL
  180. @Via 1:151/1003, Dec 03 12:47:10 (QM v1.23/b)
  181. @Via QM 1:270/101, Fri Dec 03 22:15 UTC (v1.26/a49)
  182. @Via MsgTrack* 1:260/1@fidonet, Sat Dec 04 1993 at 03:25 UTC
  183. @Via MsgTrack 1:260/362@Fidonet, Sat Dec 04 1993 at 05:07 UTC
  184. @Via 1:260/362@fidonet @19931204.001211 FrontDoor 2.11.SW
  185.