;	Program to display the entries in the root directory on the disk 
;	in drive A:.  All entries are shown using the DOS names for the
;	files.  In addition, deleted files, subdirectories, and the disk
;	label are listed.  For each regular file, a name, date of creation
;	and size (in bytes) are shown in a screen-wide format.

		.model		small
		.stack		100h
		.386
		.data
asector		db		512 dup(?)		; Sector buffer
date		db		"  /  /      :  :  ",0	; Date template
fname		db		13 dup(0)		; File name
secnum		dw		19			; Root dir begins at 19
del		db		?			; Deleted flag
space		db		' ',0			; Used to place # bytes
lines		dw		1			; Line count
nametitle	db		"File Name",0		; Various output labels
sizetitle	db		"Size in bytes",0
datetitle	db		"Creation date/time",0
deleted		db		"Deleted",0
disklab		db		"Disk label",0
subdir		db		"Subdirectory",0

		.code
if1
		include		6macros.inc
endif
		extern	Writestring:proc, crlf:proc
		extern	Writelong:proc, Writeint:proc

main	proc
		mov		ax, @data
		mov		ds, ax
		Place		sizetitle, c		; Center Size title
		Place		datetitle, r		; Right justify date
		Place		nametitle, l		; File name title
		call		crlf			;  time title
again:
		ReadDisk	secnum, asector		; Read directory sector
		mov		si, offset asector	; Set up loop for 
		mov		cx, 16			;  16 directory entries
top:
		mov		al, [si]		; Entry beginning with
		cmp		al, 0			;  00h ends entries
		je		alldone
		mov		del, 0			; Clear deleted flag
		cmp		byte ptr [si]+11, 0Fh	; Ignore entries for
		je		next			;  extended file names
		cmp		byte ptr [si], 0E5h	; Is entry deleted?
		jne		active			; No, jump.
		mov		del, 1			; Set flag if deleted
		mov		al, '*'			; Change first character
		mov		[si], al		;  of name to asterisk
active:
		ExtractTime	[si+22], date+10, date+13, date+16
							; Extract creation time
		ExtractDate	[si+24], date, date+3, date+6
							; Extract creation date
		GetFile		fname			; Get the file name
		Place		fname			; Display file name 
							;  at the left
		Place		date, r			; Display date/time
							;  at the right
		ShowSize				; Display file size or
		call		crlf			;  other label at center
		inc		lines
		PauseCheck	lines			; Stop on screen full
next:
		add		si, 32			; Move to next entry
		dec		cx
		jz		skip
		jmp		top
skip:
		inc		secnum			; Move to next sector
		jmp		again
alldone:
		mov		ax, 4c00h		; Exit program
		int		21h
main	endp

end		main
