

;       FILLDISK.ASM                        DOS UTILITY  10/03/86 BTR
;	------------
;	Purpose:  Calculate remaining free disk space on target drive
;                 and fill with  one file of specified constant data.
;
;       Syntax:   FILLDISK <targetdrive> <filename> <fillchar> 
;
;       Example:  FILLDISK A: ZEROS.ABS 00
;         or      FILLDISK B: BLANK.TXT 20H


CSEG            Segment
		Assume	CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
		Org	002Ch
Environment	Label 	Word		; Segment of Environment
		Org	0080h
Parameter	Label	Byte		; Parameter         
		Org	0100h
Entry:		Jmp	Begin		; Entry Point


;	Data Declarations
;	-----------------

SyntaxMsg	db	"Syntax:  FILLDISK <targetdrive> <filename> <fillchar>"
 		db	13,10,10
                db	"Example: FILLDISK A: ZEROS.ABS 00",13,10
 		db	"  or     FILLDISK B: BLANK.TXT 20H$"

DosVersMsg	db	"Needs DOS 2.0 +$"
ParmsMsg	db	"Incorrect Parms$"
Delimiters	db	9,' ,;='
SpaceMsg	db	"KBytes were written to disk under filename $"
PrintMsg	db	"Want to print file allocation table? (Y/N): $"


;	Check DOS Version
;	-----------------

Begin:		Mov	AH, 30h			; Check for DOS Version
		Int	21h			;   through DOS call
		Cmp	AL, 2			; See if it's 2.0 or above
		Jae	DosVersOK		; If so, continue

		Mov	DX, Offset DosVersMsg	; Error message
ErrorExit:	mov	AH, 9			; Print String function call
		Int	21h			; Do it
		Int	20h			; And exit prematurely


;	Parse Command Line
;	------------------

ScanParms:	Lodsb				; SUBROUTINE: Get byte
		Cmp	AL, 13			; See if end of parameter
		Je	ErrorExit		; If so, exit
	 	Mov	DI, Offset Delimiters	; Check if delimiter
 	Mov	CX, 5		                ; There are 5 of them
		Repne	Scasb			; Scan the string
		Ret				; And return


;       Video Subroutines
;       -----------------

VideoMod:       Mov	AL,0			; 0 Text Med  40x25 CGA
						; 2 Text High 80x25 CGA

                Mov 	AH,0		 	; Function Set Video Mode
		Int	10h
		Ret

ClearWdw:	Mov     CH,0			; Row upper left
		Mov	CL,0			; Column upper left
		Mov 	DH,24			; Row lower left
		Mov	DL,80			; Column upper right
		Mov 	BH,7			; Blank line attribute
		Mov 	AL,0			; Number of lines to scroll

		Mov	AH,6			; Function Scroll Window Up
		Int	10h
		Ret

PosCursr:	Mov	AH,2			; Function Position Cursor
		Int	10h			; (DH Row, DL Column)
		Ret


; 	Error Handling
;	--------------

DosVersOK:	Mov	DX, Offset SyntaxMsg 	; Possible error msg
		Mov	SI, 1+Offset Parameter	; Parameter string
		Cld				; Directions forward

BegSearch:	Call	ScanParms		; Check byte in subroutine
		Je	BegSearch		; If delimeter, keep searching
		Mov	BX, SI			; Save pointer in BX
		Dec	BX			; BX points to file spec

EndSearch:	Call	ScanParms		; Check byte in subroutine
		Jne	EndSearch		; If not delimeter, keep going


;	Separate Parms  <targetdrive> <filename> <fillcharacter>
;	--------------------------------------------------------

		Dec 	SI  			; Points after Parm
		Xchg	SI, BX			; SI points to beg, BX to end
		Mov	DI, Offset FullPath	; Points to destination
		Cmp	Byte Ptr [SI + 1], ':'	; See if drive  spec included
		Jnz	GetDrive		; If not, must get the drive
		Lodsw				; Otherwise, grab drive spec
		Add	AL, 0DFh		; Capitalize letter
		Sub	AL, 40h			; get drive number (A=1) 
		Jmp	Short SaveDrive		; And skip next section
		
GetDrive:	Mov	AH, 19h			; Get current drive
		Int	21h			;   through DOS
		Add	AL, 'A'			; Convert to letter
		Mov	AH, ':'			; Colon after drive letter

SaveDrive:	Stosw				; Save drive spec and colon
		Int	21h			;   through DOS

.....

get name of disk fill file

get fill character in hex

.....
		Moö	DX¬ Offseô ParmsMsç	» Possiblå erroò message
		Jc	ErrorExit 		; Exit it error
		Sub	AL, Al			; Search for terminating zero
		Cmp	[SI], AL		; Check if Root Directory
		Jz	RootDir			; If so, don't use it
		Mov	CX, 64			; Number of byte to search
		Repnz	Scasb			; Do the search
		Dec	DI			; DI points to last zero
		Mov	AL, '\'			; Put a backslash in there
		Stosb				; So filespec can follow
RootDir:	Pop	SI			; Get back SI
AllParmsOk:	Mov	CX, BX			; End of file spec

.....

open file

write file

.....

CSEG		EndS				; End of the segment
		End	Entry			; Denotes entry point
