home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 7 / cmdtail.asm next >
Encoding:
Assembly Source File  |  1988-08-11  |  2.2 KB  |  61 lines

  1. cmdtail equ     80h             ; PSP offset of command tail
  2. fname   db      64 dup (?)
  3. fhandle dw      ?
  4.  
  5.         .
  6.         .
  7.         .
  8.                                 ; assume that DS already 
  9.                                 ; contains segment of PSP
  10.  
  11.                                 ; prepare to copy filename...
  12.         mov     si,cmdtail      ; DS:SI = command tail
  13.         mov     di,seg fname    ; ES:DI = buffer to receive
  14.         mov     es,di           ; filename from command tail
  15.         mov     di,offset fname
  16.         cld                     ; safety first!
  17.  
  18.         lodsb                   ; check length of command tail
  19.         or      al,al
  20.         jz      error           ; jump, command tail empty
  21.  
  22. label1:                         ; scan off leading spaces
  23.         lodsb                   ; get next character
  24.         cmp     al,20h          ; is it a space?
  25.         jz      label1          ; yes, skip it
  26.  
  27. label2:
  28.         cmp     al,0dh          ; look for terminator
  29.         jz      label3          ; quit if return found
  30.         cmp     al,20h
  31.         jz      label3          ; quit if space found
  32.         stosb                   ; else copy this character
  33.         lodsb                   ; get next character
  34.         jmp     label2
  35.  
  36. label3:
  37.         xor     al,al           ; store final NULL to
  38.         stosb                   ; create ASCIIZ string
  39.  
  40.                                 ; now open the file...
  41.         mov     dx,seg fname    ; DS:DX = address of
  42.         mov     ds,dx           ; pathname for file
  43.         mov     dx,offset fname
  44.         mov     ax,3d02h        ; Function 3DH = open r/w
  45.         int     21h             ; transfer to MS-DOS
  46.         jnc     label4          ; jump if file found
  47.  
  48.         cmp     ax,2            ; error 2 = file not found
  49.         jnz     error           ; jump if other error
  50.                                 ; else make the file...
  51.         xor     cx,cx           ; CX = normal attribute
  52.         mov     ah,3ch          ; Function 3CH = create
  53.         int     21h             ; transfer to MS-DOS
  54.         jc      error           ; jump if create failed
  55.  
  56. label4:
  57.         mov     fhandle,ax      ; save handle for file
  58.         .
  59.         .
  60.         .
  61.