home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / ADVMSDOS.ZIP / LABEL.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-06-19  |  10.9 KB  |  271 lines

  1.         name    labl
  2.         page    55,132
  3.         title   'LABEL --- display or change volume label' 
  4. ;
  5. ; LABEL --- display or change volume label. 
  6. ; Requires MS-DOS or PC-DOS version 2.X or 3.X.
  7. ; Note that DOS 3 comes with a genuine Microsoft LABEL
  8. ; utility, so you don't really need this one!
  9. ;
  10. ; Copyright (c) 1984 by Ray Duncan
  11. ;
  12. ; To assemble, link, and convert this program into 
  13. ; an EXE file, follow these steps:
  14. ;
  15. ;    C>MASM LABEL;
  16. ;     C>LINK LABEL;
  17. ;
  18.  
  19. cr      equ     0dh             ;ASCII carriage return
  20. lf      equ     0ah             ;ASCII line feed
  21. eom     equ     '$'             ;end of message flag 
  22.  
  23.                                 ;Program Segment Prefix:
  24. command equ     80h             ;command line buffer
  25. default_fcb equ 05ch            ;default file control block
  26.  
  27. rd_only equ     01h             ;file attributes
  28. hidden  equ     02h             
  29. system  equ     04h
  30. volume  equ     08h
  31. subdir  equ     10h
  32. archive equ     20h
  33.  
  34.  
  35. cseg    segment para public 'CODE'
  36.  
  37.         assume  cs:cseg,ds:data,es:data,ss:stack
  38.  
  39. labl    proc    far             ;entry point from PC-DOS
  40.  
  41.         push    ds              ;save DS:0000 for final
  42.         xor     ax,ax           ;return to PC-DOS
  43.         push    ax
  44.         mov     ah,48           ;make sure this is DOS 
  45.         int     21h             ;version 2.0 or greater
  46.         cmp     al,2
  47.         jae     labl1           ;version is ok,jump
  48.         mov     ax,data
  49.         mov     ds,ax
  50.         mov     dx,offset msg6  ;version too low, print error
  51.         mov     ah,9            ;message and exit
  52.         int     21h
  53.         ret
  54. labl1:  mov     ax,data         ;make our data segment addressable
  55.         mov     es,ax           ;via the ES register
  56.         call    vol_name        ;get name for new volume label 
  57.                                 ;if any was given by user
  58.         mov     ax,es           ;now set DS=ES for remainder
  59.         mov     ds,ax           ;of the program.
  60.         call    show_label      ;display the current volume label
  61.                                 ;on the selected diskette. subroutine
  62.                 ;returns AX=0 if no label on
  63.                 ;disk, AX=-1 if label exists.
  64.                                 ;was new label supplied by user?
  65.         cmp     byte ptr fcb+1,' '      
  66.         jne     labl2           ;yes,change or add volume label
  67.         ret                     ;no, display only, exit to PC-DOS
  68.  
  69. labl2:                          ;new name supplied by user.
  70.         or      ax,ax           ;was previous label present?
  71.                                 ;(flag in AX from SHOW_LABEL)
  72.         jz      labl3           ;no,jump
  73.         mov     cx,11           ;yes,change it
  74.         mov     di,offset buffer+24
  75.         mov     si,offset fcb+1 ;set up new name starting at
  76.         rep movsb               ; 6 bytes after old name
  77.         mov     dx,offset buffer
  78.         mov     ah,23           ;request alteration of volume name
  79.         int     21h             ;by PC-DOS function 23=RENAME
  80.         jmp     labl4           ;go check if function was successful,
  81.                                 ;if it was display new volume name. 
  82.  
  83. labl3:                          ;come here to add new label, if 
  84.                                 ;diskette previously had no label.
  85.         mov     dx,offset xfcb  ;DX=addr of extended fcb
  86.                                 ;containing "volume" attribute byte.
  87.         mov     ah,22           ;Use PC-DOS function 22 to create
  88.         int     21h             ;a new directory entry.
  89. labl4:  cmp     al,0ffh         ;was function successful?
  90.         jne     labl5           ;yes,jump to display new name.
  91.         mov     dx,offset msg2  ;no,print error message
  92.         mov     ah,9            ;and exit
  93.         int     21h
  94.         ret
  95.  
  96. labl5:                          ;label successfully created.
  97.         mov     dx,offset msg3  ;print first part of message.
  98.         mov     ah,9
  99.         int     21h
  100.         mov     bx,offset fcb+1 ;print actual volume name
  101.         call    print_vol       ;in upper case.
  102.         ret                     ;exit to PC-DOS.
  103. labl    endp
  104.  
  105.  
  106. show_label proc near            ;Display the label for the
  107.                                 ;disk in the selected drive and
  108.                                 ;return AX=-1, or display message
  109.                                 ;and return AX=0 if no label exists.
  110.         mov     dx,offset buffer
  111.         mov     ah,26           ;set disk transfer address 
  112.         int     21h             ;for use in directory search
  113.         mov     dx,offset sfcb  ;now look for the first directory
  114.                                 ;entry with "volume" attribute,
  115.         mov     ah,17           ;using PC-DOS function 17 
  116.         int     21h             ;"search for first matching filename"
  117.         cmp     al,0ffh         ;any volume label found?
  118.         je      show_label2     ;no,jump
  119.         mov     dx,offset msg4  ;yes print message and
  120.         mov     ah,9            ;volume name
  121.         int     21h
  122.         mov     bx,offset buffer+8
  123.         call    print_vol
  124.         mov     ax,-1           ;return AX=-1, label exists
  125.         ret
  126. show_label2:                    ;disk was not labeled,
  127.         mov     dx,offset msg5  ;so print message and
  128.         mov     ah,9            ;return AX=0 as signal that
  129.         int     21h             ;there is no previous label
  130.         xor     ax,ax   
  131.         ret
  132. show_label endp
  133.  
  134.  
  135. print_vol proc  near            ;print the volume name 
  136.                                 ;whose offset is in BX on
  137.                                 ;the standard output device.
  138.                                 ;Regs AX, BX, DX destroyed.
  139.         mov     cx,11           ;name is max of 11 characters
  140. pvol2:
  141.         mov     dl,[bx]         ;get next char from string
  142.         cmp     dl,' '
  143.         je      pvol4
  144.         cmp     dl,'a'          ;if it is an lower-case alpha
  145.         jb      pvol3           ;character,fold to upper case
  146.         cmp     dl,'z'  
  147.         ja      pvol3   
  148.         xor     dl,20h  
  149. pvol3:
  150.         mov     ah,2            ;function 2=output char.
  151.         int     21h             ;request output by PC-DOS
  152. pvol4:  inc     bx              ;advance to next string position
  153.         loop    pvol2           ;until 11 chars. processed.
  154. pvol9:                          ;done with string output,
  155.         mov     dx,offset msg1  ;send final carriage return 
  156.         mov     ah,9            ;and line feed,
  157.         int     21h
  158.         ret                     ;then return to caller
  159. print_vol endp
  160.  
  161. vol_name proc   near            ;Transfer the new volume name 
  162.                                 ;from the Program Segment Prefix
  163.                                 ;into the local File Control Block
  164.  
  165.                                 ;let DS:SI=command tail address
  166.         mov     si,offset command 
  167.         lodsb                   ;check string length byte,
  168.         or      al,al           ;any name present?
  169.         jz      vol_name4       ;no,go get drive
  170. vol_name1:                      ;scan for start of name
  171.         lodsb                   ;get next char
  172.         cmp     al,cr           ;if carriage return,name is missing
  173.         je      vol_name4       ;so jump to get drive
  174.         cmp     al,' '          ;if blank, keep looking
  175.         je      vol_name1
  176.                                 ;now found none-blank char
  177.                                 ;let ES:DI = addr of name field
  178.         mov     di,offset fcb+1 ;in local file control block
  179.         mov     cx,11           ;CX will be counter, 11 chars max.
  180.                                 ;did DOS's parser find legal drive?
  181.         mov     ah,ds:default_fcb
  182.         or      ah,ah
  183.         jz      vol_name2       ;no,jump.
  184.         lodsb                   ;yes,then next char ought to
  185.         cmp     al,':'          ;be a colon.
  186.         jne     vol_name4       ;not colon, some kind of error.
  187.         lodsb                   ;fetch next character after colon.
  188.         cmp     al,' '          ;make sure name is also there.
  189.         jna     vol_name4       ;no name,jump to get drive.
  190. vol_name2:                      ;now we transfer bytes from
  191.                                 ;command tail into the fcb
  192.                                 ;for the new volume name.
  193.         stosb 
  194.         lodsb                   ;check next char from input.
  195.         cmp     al,' '          ;if blank or any control char
  196.         jna     vol_name4       ;found end of name.
  197.         loop    vol_name2       ;otherwise, keep looking until
  198.                                 ;11 characters have been processed.
  199. vol_name4: 
  200.         mov     al,ds:default_fcb       
  201.         or      al,al           ;was disk drive specified?
  202.         jnz     vol_name5       ;yes,use it.
  203.         mov     ah,25           ;no, get identity of default drive.
  204.         int     21h
  205.         inc     al
  206. vol_name5:                      ;put drive into file control blocks
  207.         mov     es:fcb,al       ;for search and new volume name.
  208.         mov     es:sfcb+7,al    
  209.         add     al,'a'-1        ;also form ASCII letter for
  210.         mov     es:msg2a,al     ;drive, and put into 
  211.         mov     es:msg3a,al     ;output messages.
  212.         mov     es:msg4a,al
  213.         mov     es:msg5a,al
  214.         ret
  215. vol_name endp
  216.  
  217. cseg    ends
  218.  
  219.  
  220.                                 ;data segment for
  221.                                 ;miscellaneous messages,
  222.                                 ;constants, and variables
  223. data    segment para public 'DATA'
  224.                                 ;extended file control block
  225. xfcb    db      0ffh            ;flag for special fcb 
  226.         db      5 dup (0)       ;reserved
  227.         db      volume          ;volume label attribute byte
  228.                                 ;remainder is "normal" fcb
  229. fcb     db      0               ;drive (set by VOL_NAME)
  230.         db      11 dup (' ')    ;blank name field
  231.         db      25 dup (0)      
  232.  
  233. sfcb    db      0ffh            ;extended file control block used
  234.         db      5 dup (0)       ;to search for current label
  235.         db      volume
  236.         db      0               ;drive (set by VOL_NAME)
  237.         db      11 dup ('?')    ;wildcard name
  238.         db      25 dup (0)
  239.  
  240. buffer  db      128 dup (?)     ;buffer for disk directory search
  241.  
  242. msg1    db      cr,lf,eom
  243.  
  244. msg2    db      cr,lf
  245.         db      'Unable to write new label on disk '
  246. msg2a   db      'x: ',cr,lf,eom
  247.  
  248. msg3    db      cr,lf
  249.         db      'Label of disk in drive '
  250. msg3a   db      'x: has been changed to ',eom
  251.  
  252. msg4    db      cr,lf,'Label of disk in drive '
  253. msg4a   db      'x: is ',eom
  254.  
  255. msg5    db      cr,lf,'Disk in drive '
  256. msg5a   db      'x: has no label.',cr,lf,eom
  257.  
  258. msg6    db      cr,lf
  259.         db      'LABEL program requires DOS '
  260.         db      'version 2.0 or greater.'
  261.         db      cr,lf,eom
  262.  
  263. data    ends
  264.  
  265.  
  266. stack   segment para stack 'STACK'
  267.         db      64 dup (?) 
  268. stack   ends
  269.  
  270.         end     labl
  271.