	.xlist
	;	Getfile - extract a file name from a directory entry
	;	SI  -  expected to hold the offset of the entry
	;	WHERE  -  location to put the file name

GetFile	macro	where
		local	nuther, extnsn
		pusha
		mov		di, si		;; Get offset into DI
		mov		bx, offset where ;; Set up access to destination
		mov		ah, 8		;; Up to 8 characters/name
nuther:
		mov		dl, ' '
		cmp		[di], dl	;; Stop moving characters 
		je		extnsn		;;  when blank detected
		mov		al, [di]
		mov		[bx], al	;; Move character to destination
		inc		bx
		inc		di
		dec		ah
		jnz		nuther
extnsn:
		mov		dl, '.'		;; Fill in the period
		mov		[bx], dl	;; Move extension (+1 byte) to
		mov		eax, [si]+8	;;  destination
		mov		[bx]+1, eax
		mov		dl, 0		;; Put in trailing null
		mov		[bx]+4, dl
		popa
	endm

	;	MakeTwo		Converts a number into two ASCII-code digits
	;			Get last two digits for large numbers, get 
	;			leading zeros if number is a single digit
	;	AX  -  holds the number to be converted
	;	SPOT  -  Memory reference for where the two-digits are to go

MakeTwo macro	spot
		pusha
		mov		bl, 10		;; Base 10 numbers
		idiv		bl
		add		ah, 30h		;; Make second digit
		mov		spot+1, ah
		cbw				;; Set up second division
		idiv		bl
		add		ah, 30h		;; Make first digit
		mov		spot, ah
		popa
	endm

	;	SetDay		Extracts year, month, and day from a directory
	;			entry and stores them as 2-digit ASCII codes
	;	DATEPACK  -  Word containing the date in directory entry form
	;	YR  -  Memory reference where 2-digit year is to go
	;	MO  -  Memory reference where 2-digit month is to go
	;	DAY  -  Memory reference where 2-digit day is to go

SetDay	macro	datepack, yr, mo, day

	endm

	;	SetTime		Extracts the hours, minutes, and seconds from
	;			a directory time entry and stores them as 
	;			2-digit ASCII codes in memory
	;	TIMEPACK  -  Word containing a directory time entry
	;	HRS  -  Memory reference where 2-digit hours is to go
	;	MINS  -  Memory reference where 2-digit minutes is to go
	;	SECS  -  Memory reference where 2-digit seconds is to go

SetTime	macro	timepack, hrs, mins, secs

	endm

	;	GetLength	Determines the length of null-terminated string
	;	STR	symbol associated with the string storage
	;	BX	Returns the length of the string

GetLength	macro	str

	endm

	;	Place	Displays a string at location specified
	;	STR	symbol associated with a null-terminated string
	;	JUST	Character indicating where to display the string
	;		C  -  Center string on current line
	;		R  -  Right justify the string on the current line
	;			(allow one space for the cursor)
	;		Blank  -  Display string where the cursor is now
	;		Anything else - generate assembly error

Place	macro	str, just

	endm

	;	ShowSize	Display a message or byte count centered
	;		Display form based on the attribute byte and DEL flag
	;	SI  -  Must contain the offset for a directory entry

ShowSize	macro
		local		skip1, skip2, skip3, skip4
		pusha
		mov		ax, [si]+11	;; Get attribute byte
		cmp		ax, 28h		;; Disk label has attribute 28h
		jne		skip1
		Place		disklab, c
		jmp		skip4
skip1:
		cmp		ax, 10h		;; Subdirectories have attribute
		jne		skip2		;;  10h
		Place		subdir, c
		jmp		skip4
skip2:
		cmp		del, 1		;; Deleted file flagged in main
		jne		skip3
		Place		deleted, c
		jmp		skip4
skip3:
		Place		space, c	;; Normal file, center a single 
		mov		eax, [si]+28	;;  blank then display number of 
		mov		bx, 10		;;  bytes in decimal
		call		Writelong
skip4:
		popa
	endm

	;	ReadDisk	Reads a disk sector on drive A into a buffer
	;	SECTOR  -  The logical number of the sector to read
	;	BUFFER  -  Memory reference to storage that can hold a sector

ReadDisk	macro	sector, buffer
		local		readok, badread
		pusha
		mov		al, 0		;; Disk drive
		mov		cx, 1		;; Number of sectors to read
		mov		dx, sector	;; Which sector
		mov		bx, offset buffer	;; Where to put it
		int		25h
		jnc		readok		;; CF set on error
		Place		badread		;; Display error message
		add		sp, 2		;; Clean up stack
		mov		ax, 4c00h	;; Terminate program early
		int		21h
readok:
		add		sp, 2		;; Clean up stack and leave
		popa

		.data
badread	db			"Some problem reading disk.",0dh,0ah,0
		.code
	endm
	.list