(188) Thu 2 Dec 93 1:08p Rcvd: Sat 4 Dec 12:16a By: Ed Beroset, Durham Net NEC (1:3641/1.250) To: Terry Carmen Re: Handles to filenames St: Pvt Kill Rcvd --------------------------------------------------------------------------- @INTL 1:260/338 1:3641/1 @FMPT 250 @MSGID: 1:3641/1.250 3801a007 @REPLY: 1:260/338@Fidonet a7814fc3 In a msg on , to Ed Beroset, Terry Carmen writes: TC> Ed, is this yours? Yep. Sure is. TC> Could you send me a copy of your original? I'll replace it in the TC> snippets file. Inbar either sent or posted this as his, since I TC> don't change the files when they come in. Cheeky devil, isn't he? Here's the original: ; HNDLNAME.ASM ; written on 3 February 1993 by Ed Beroset ; released to the public domain by the author. ; ; Given a DOS handle number, the hndl2name function will return a ; pointer to the associated file name. This code illustrates the ; use of this function. ; MODEL small IDEAL STACK 100h DOS_GET_DOS_VERSION = 030h DOS_OPEN_FILE = 03Dh DOS_CLOSE_FILE = 03Eh DOS_WRITE_TO_HANDLE = 040h DOS_TERMINATE_EXE = 04Ch DOS_GET_LIST_OF_LISTS = 052h DOS_GET_PSP = 062h STDOUT = 1 ; stdout device handle READ_ONLY = 0 ; file mode equate MACRO DosInt function mov ah,function ; this doesn't require much explanation int 21h ENDM MACRO ShowStr string, strlen, device IFDIF , lea dx,[string] ; note that string is assumed to be in DS ENDIF mov cx,strlen ; note no error checking IFB mov bx,STDOUT ; default device... ELSE mov bx,device ; ...or passed device ENDIF DosInt DOS_WRITE_TO_HANDLE ; show the string ENDM DATASEG Msg1 DB "This program tests the hndl2name function.",13,10 Msg1Len = $-Msg1 STRUC magic dosmin DB 0 ; minor DOS version dosmaj DB 0 ; major DOS version SFTsize DB ? ; system file table entry size (in bytes) NameOffs DB ? ; offset from SFT start to first name ENDS magic voodoo magic <0,4,3bh,26h> ; DOS 4.0 magic <1,3,35h,26h> ; DOS 3.1 magic <0,3,38h,27h> ; DOS 3.0 magic <0,2,28h,0ah> ; DOS 2.0 magic <> ; end of table marker SFTlength DB ? SFTname DB ? Dummy DB "hndlname.asm",0 ; the name of this file Handle DW ? ; handle for this file when opened CODESEG Start: mov ax,@data ; point DS to our own data segment mov ds,ax ShowStr Msg1,Msg1Len ; print first message to user DosInt DOS_GET_DOS_VERSION xchg al,ah ; now straighten things out for our compares mov cx,4 ; four entries in table lea bx,[voodoo] ; consult our magic table @@looky: cmp ax,[WORD PTR bx] ; is DOS version/rev correct? ja @@got_values ; if it's greater than table value, it's OK add bx,SIZE voodoo ; otherwise increment to the next table entry loop @@looky ; and jump back up ; should err_exit if < DOS 2.0 here, but... @@got_values: mov ax,[WORD PTR bx+2] ; get both SFTsize and NameOffs all at once mov [WORD PTR SFTlength],ax ; stow them the same way (cheat!) mov dx,OFFSET Dummy ; open dummy file mov al,READ_ONLY ; we don't need to modify this file! DosInt DOS_OPEN_FILE ; mov [Handle],ax ; save the handle for later use mov bx,ax ; Hndl2Name requires handle number in BX call Hndl2Name ; test new function push ds ; now ES:DX points to 11 chars push es ; pop ds ; but we need DS:DX for ShowStr macro ShowStr dx,11 pop ds ; restore proper DS register mov bx,[Handle] ; close our dummy file DosInt DOS_CLOSE_FILE ; mov al,0 ; all successful, so error code = 0 DosInt DOS_TERMINATE_EXE ; hndl2name ; ; PURPOSE: given a handle, return pointer to ASCII file name ; INPUTS: BX = handle of file to be named ; SFTlength must be initialized and in current DS ; SFTname must be initialized and in current DS ; OUTPUTS: ES:DX => ASCII file name (exactly 11 bytes long) (FCB format) ; PROC hndl2name push ax ; save used registers push bx push si mov si,bx ; save original file handle in SI DosInt DOS_GET_PSP ; now get the PSP of this program mov es,bx ; look in the PSP segment for the job file table les bx,[es:34h] ; now ES:BX => JFT mov al,[es:bx+si] ; now read table entry (index into SFT) xor ah,ah ; clear out hi half of AX mov si,ax ; now stow the SFT index DosInt DOS_GET_LIST_OF_LISTS ; ES:BX => List Of Lists les bx,[es:bx+4] ; load up ES:BX => SFT @@nextSFT: ; ES:BX => SFT at this point cmp si,[es:bx+4] ; is this handle in this SFT? jb @@SFT_ok ; if so, we're in the correct table sub si,[es:bx+4] ; otherwise, adjust index for next table les bx,[es:bx] ; and load address of next SFT jmp @@nextSFT ; loop back again @@SFT_ok: mov ax,si ; recall our adjusted SFT index mov dl,[SFTlength] ; SFTlength is the length of an SFT entry mul dl ; ax = (SFT index) * (SFT length) mov dl,[SFTname] ; SFTname =offset from beginning of SFT to name xor dh,dh ; clear out hi half of DX add ax,dx ; ax = SFTindex * SFTlength + SFTname add bx,ax ; bx = original offset + calc offset mov dx,bx ; now ES:DX => file name string pop si ; restore used registers pop bx pop ax ret ENDP hndl2name END Start --------------------- Hmmm... Maybe I should take a look at the snippets file and see if he's appropriated any other work of mine. Thanks for your attention to this. Although the code has been in the public domain for almost two years now, it's still annoying to see somebody else's name on one's own work. I think I'll just send a little netmail to Inbar Raz asking for an explanation. -> Ed <- @Via 1:3641/1@fidonet.org @19931203.110648 FrontDoor 2.20a.mL @Via 1:151/1003, Dec 03 12:47:10 (QM v1.23/b) @Via QM 1:270/101, Fri Dec 03 22:15 UTC (v1.26/a49) @Via MsgTrack* 1:260/1@fidonet, Sat Dec 04 1993 at 03:25 UTC @Via MsgTrack 1:260/362@Fidonet, Sat Dec 04 1993 at 05:07 UTC @Via 1:260/362@fidonet @19931204.001211 FrontDoor 2.11.SW