home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / dirutl / volume11.arc / VOLUME11.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-07-19  |  4.2 KB  |  171 lines

  1. TITLE    VOLUME    7-19-88    [7-19-88]
  2.  
  3. ;from SIMTEL20's PD:<MSDOS.DSKUTL>VOLUME.COM
  4. ;disassembled with ASMGEN and thoroughly tweaked.
  5.  
  6. ; v1.1, Jul 88
  7. ; - Now returns ERRORLEVEL, terminating via service 4CH.
  8. ; - If no command line parms, gives usage help msg.
  9. ; - one working buffer overwrites usage text to save bytes.
  10. ;
  11. ;David Kirschbaum, Toad Hall
  12.  
  13. LF    EQU    0AH
  14. CR    EQU    0DH
  15. ;
  16. CodeSeg    SEGMENT
  17.     ASSUME DS:CodeSeg, SS:CodeSeg ,CS:CodeSeg ,ES:CodeSeg
  18.  
  19.     ORG    100H
  20.  
  21. Volume    proc    near
  22.     MOV    AH,30H            ;get DOS version
  23.     INT    21H
  24.     or    al,al            ;1.0?
  25.     JNZ    Skip1            ;nope, ok
  26.  
  27.      MOV    DX,OFFSET dosmsg    ;'DOS 2.0 or above'
  28.      inc    al            ;fake ERRORLEVEL 1
  29.      jmp    short MsgExit        ;display msg, terminate
  30.  
  31. Skip1:    CLD                ;insure fwd
  32.     CMP    BYTE PTR DS:80H,0    ;anything on cmd line?
  33.     jne    Do_CmdLine        ;yep, go process it
  34.  
  35.      mov    dx,offset usagemsg    ;show usage
  36.      xor    ax,ax            ;return ERRORLEVEL=0
  37.      jmp    short MsgExit        ;display msg, terminate
  38.  
  39. Do_CmdLine:
  40. ;Build an FCB area, properly initialized, by copying the good one
  41. ;(starting at drive) down over our usage text.
  42.     mov    si,offset drive        ;gonna initialize some working space
  43.     mov    di,offset drive_24B    ;overwrite usage text
  44.     mov    cx,BUFLEN        ;a constant
  45.     rep    movsb            ;initialize it (over old text)
  46.  
  47.     MOV    SI,81H            ;point to PSP cmd line 1st char
  48.     MOV    CX,0AH            ;up to 10 chars
  49. ScanCmd:
  50.     LODSB                ;snarf PSP cmd line char
  51.     CMP    AL,20H    ;' '
  52.     LOOPZ    ScanCmd            ;gobble leading spaces
  53.  
  54.     DEC    SI            ;back up to first REAL cmd line char
  55.                     ;(oughtta be drive name)
  56.     CMP    BYTE PTR [SI+1],3AH    ;':' drive name separator?
  57.     JNZ    NoDrive            ; nope, use current drive
  58.  
  59.      MOV    AL,[SI]            ;get actual drive char
  60.      CALL    UpperCase        ;insure uppercase
  61.      SUB    AL,40H            ;deasciify
  62.      MOV    drive,AL        ;save it
  63.      inc    si            ;TH bump past 'A:'
  64.      inc    si            ;TH (faster than add si,2)
  65. NoDrive:
  66.     PUSH    SI            ;save cmd line ptr
  67.     CALL    FindFile        ;try to find the file
  68.     POP    SI
  69.     CMP    BYTE PTR [SI],CR    ;done with cmd line? (just drive?)
  70.     JZ    Endit            ;yep, terminate, AL=ERRORLEVEL=0
  71.  
  72.     MOV    DI,OFFSET buff        ;gotta scan our working buffer
  73.     MOV    CX,0BH            ;11 chars
  74. ScanBuff_146:
  75.     LODSB                ;snarf buff char
  76.     CMP    AL,CR            ;CR means end of cmd
  77.     JZ    ScanDone        ;done
  78.      CALL    UpperCase        ;insure uppercase
  79.      STOSB                ;stuff back in buff
  80.      LOOP    ScanBuff_146        ;do them all
  81. ScanDone:
  82.     JCXZ    NoPad            ;did all 11 chars
  83.      MOV    AL,20H    ;' '        ;pad with spaces
  84.      REPZ    STOSB
  85. NoPad:    MOV    AL,drive        ;get drive val back
  86.     MOV    drive_24B,AL        ;stuff it here
  87.     MOV    AH,16H            ;create file
  88.     MOV    DX,OFFSET dta_244    ;this one
  89.     INT    21H
  90.     push    ax            ;save results
  91.  
  92.     MOV    DX,OFFSET dta_244
  93.     MOV    AH,10H            ;close file
  94.     INT    21H
  95.  
  96.     pop    ax            ;restore results
  97.     CMP    AL,0FFH            ;failed?
  98.     jne    Endit            ; nope, went ok
  99.  
  100.     MOV    DX,OFFSET failmsg    ;'can't create vol name'
  101.  
  102. MsgExit:
  103. ;expects msg offset in DX
  104.     push    ax            ;save any error value in AL
  105.     mov    ah,9            ;display string
  106.     int    21H
  107.     mov    dx,offset crlf        ;terminating CR/LF
  108.     int    21H            ;display it
  109.     pop    ax            ;restore any error in AL
  110.  
  111. Endit:
  112.     mov    ah,4CH            ;TH terminate
  113.     int    21H
  114. Volume    endp
  115.  
  116.  
  117. FindFile    proc    near
  118.     MOV    DX,OFFSET dta_244    ;our DTA
  119.     MOV    AH,1AH            ;set DTA
  120.     INT    21H
  121.     MOV    DX,OFFSET namebuff    ;file name to find
  122.     MOV    AH,11H            ;find first matching file
  123.     INT    21H
  124.     CMP    AL,0FFH            ;find it?
  125.     JZ    NotFound        ; nope, doesn't exist
  126.      MOV    DX,OFFSET dta_244    ;file DTA
  127.      MOV    AH,13H            ;delete file
  128.      INT    21H
  129. NotFound:
  130.     xor    ax,ax            ;TH clear any AL error
  131.     RET
  132. FindFile    endp
  133.  
  134.  
  135. UpperCase    proc    near
  136.     CMP    AL,'z'
  137.     JA    NoUpper        ;above
  138.     CMP    AL,'a'
  139.     JB    NoUpper        ;below
  140.      AND    AL,5FH        ;uppercase it
  141. NoUpper:
  142.     RET
  143. UpperCase    endp
  144.  
  145. dosmsg    db    'Requires MS-DOS V2.00 or higher',7,'$'
  146. failmsg    db    "Can't create volume name$",7,'$'
  147. crlf    db    CR,LF,'$'
  148.  
  149. namebuff    DB    0FFH,5 DUP(0),8
  150.  
  151. drive    DB    0
  152.     db    0BH DUP(3FH)
  153.     DB    16H DUP(0)
  154. BUFLEN    = $-drive        ;remember how long this structure is
  155.  
  156. dta_244    DB    0FFH,5 DUP(0),8
  157.  
  158. drive_24B label    byte        ;actually using text space below
  159. buff    = drive_24B+1    ;a byte later
  160.  
  161. usagemsg db    'VOLUME - rename a drive',CR,LF
  162.     db    'Usage: VOLUME [drive:][volname]',CR,LF
  163.     db    'where [drive:] is a legal system drive',CR,LF
  164.     db    '(A, B, whatever, default: current drive)',CR,LF
  165.     db    'and [volname] is a string of characters (no leading spaces)'
  166.     db    CR,LF
  167.     db    "No [volname] entry will clear target drive's volume name.$"
  168.  
  169. CodeSeg    ENDS
  170.     END    Volume
  171.