
; label.asm - Change the disk label.
; Copyright 2004-2005 Christopher Evans
; email:   tekno1911@yahoo.com
; Website: http://nxdos.sourceforge.net/
;                                                                           ;
;       This program is copyrighted, but may be freely distributed          ;
;       under the terms of the Free Software Foundation's GNU General       ;
;       Public License v2 (or later.)  See the file COPYING for the         ;
;       legalities.  If you did not receive a copy of COPYING, you          ;
;       may request one from the Free Software Foundation, Inc.,            ;
;       59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           ;
;       ABSOLUTELY NO WARRANTY -- use it at your own risk!                  ;
;                                                                           ;

code            segment byte public
                assume  cs:code, ds:code
		org	100h
label_prog           proc    far

start:          jmp     initialize
include         \nxdos\src\toolbox.asm
initialize:
                mov     ah, 19h
                int     21h      ; al = current drive
                mov     drive, al
                ;
                mov  bh, '/'
                mov  bl, '?'
                call scancmdline
                mov  argc, cx
                or   cx, cx
                jz   promptforlabel
                _print syntaxmsg, 1
                jmp  exitptr
promptforlabel:
                call cs:find_volumelabel

                mov  si, 081h         ; find new label in command tail.
                mov  cl, ds:[080h]
                or   cl, cl
                jnz  find_loop        ; parameter length 

                call cs:prompt_for_label

                cmp  cx, 0
                jne  nodelete
                _print deletevolumelabelmsg, 1
                call readkey
                cmp  al, 'Y'
                je   deletevolumelabel
                cmp  al, 'y'
                je   deletevolumelabel
                jmp  nodelete
deletevolumelabel:
                call cs:delete_volumelabel
nodelete:
                mov  si, offset labeldata
                jmp  mov_cmdline
find_loop:
                mov  si, 081h
                lodsb                   ; first find a non-space character
                cmp     al, 20h
                loopz   find_loop
                jcxz    exitptr
mov_cmdline:
                mov     cx, 11
                mov     di, offset xfcbFileName
move_loop:                  ; copy characters until end of command tail
                stosb
                lodsb
                cmp     al, 13
                loopnz  move_loop
                jcxz    creat_new_label
no_labelcmd: ;   mov     si, offset labeldata
             ;   mov     al, 20h          ; fill in rest of name with spaces
             ;   rep     stosb
creat_new_label:
                mov     ah,016h         ; and create the new disk lable
                int     21h

exitptr:        call dosexit
                int 20h      

label_prog           endp

prompt_for_label proc far
         _print volumeindrive, 1
         _echo drive+65
         _echo 'i'
         _echo 's'
         _echo ' '
         _print ff_name, 1
;        _print hasnolabel, 1
         _newline
                _print volumeserialno, 1
                ; call put_hex
                _newline
                _print volumelabel_p, 1
                lea  si, labeldata
                mov  cx, 11
                call getdata
                _newline
          ret
prompt_for_label endp

find_volumelabel proc far
          mov  ah, 1ah
          lea  dx, FileInfoRec
          int  21h

          mov  ah, 4eh    ; findfirst
          xor  al, al
          mov  cx, 8 
          lea  dx, ff_filespec
          int  21h

          ret
find_volumelabel endp

delete_volumelabel proc far
                mov     di, offset xfcbSignature
                mov     dx, di
                mov     al, drive
                inc     al
                mov     xfcbDriveID, al
                mov     ah,13h          ; delete current volume label.
                int     21h
                ret
delete_volumelabel endp

argc      dw ?
drive     db ?
labeldata db 11 dup(0),0
syntaxmsg db 'Creates, changes, or deletes the volume label of disk.',0ffh
          db 'LABEL [volume label]',0ffh,0
volumeindrive  db 'Volume in drive ',0
hasnolabel     db 'has no label',0
volumeserialno db 'Volume Serial Number is ',0 ; xxxx-xxxx
volumelabel_p  db 'Volume label (11 characters, ENTER for none)? ',0
deletevolumelabelmsg db 'Delete the current volume label? (y/N)',0

   ; <,,08h,,,,0,0,,0,0,,0,>
   xfcbSignature    db  0ffh
   xfcbReserved1    db  5 dup(0)
   xfcbAttribute    db  08h
   xfcbDriveID      db  ?
   xfcbFileName     db  8 dup('?')
   xfcbExtent       db  3 dup('?')
   xfcbCurBlockNo   dw  ?
   xfcbRecSize      dw  ?
   xfcbFileSize     db  4 dup(0)
   xfcbFileDate     dw  ?
   xfcbFileTime     dw  ?
   xfcbReserved2    db  8 dup(0)
   xfcbCurRecNo     db  ?
   xfcbRandomRecNo  db  4 dup(0)

FileInfoRec:
ff_fill   db 21 dup(0)
ff_attr   db 8
ff_time   dd ?
ff_size   dd ?
ff_name   db 13 dup(0),0
ff_filespec db '*.*',0


code            ends

ProgramEnd      EQU $-01h

		end	start
