* Program 	: Display directory listing on screen
* Author	: Stephen McNabb
* Creation date : 15th February 1995
* Last update	: 15th February 1995
* Parameters	: Need to set up Disk Transfer Address(DTA) first
*		  Function Fsfirst() requires a file specification
*		  and attributes to search for
*		  Fsnext() uses the parameters that are used for Fsfirst()
* Output	: If a file is found matching the specification then
*		  d0 will contain '0' and the file attributes
*		  will be placed in the DTA

* We start by setting up the Disk Transfer Address(DTA) buffer.
* This is used by Fsfirst() and Fsnext() to return information about
* files. It must be 44 bytes long and it takes the following form:
*
*	bytes	data held
*	0-20	junk
*	21	file attributes
*	22-23	file time stamp
*	24-25	file date stamp
*	26-29	file size
*	30-43	file name and extension
*
* Note : You only need to set the DTA one time but you DO need to
* 	 set it or memory may be overwritten.

start:	jsr	cls			/clear the screen
	move.l	#dta,-(sp)		/move address of dta buffer to stack
	move.w	#$1a,-(sp)		/use Fsetdta() function
	trap	#1			/use gemdos
	addq.l	#6,sp			/tidy up stack
	
	
* Now we use Fsfirst() to find the first file that satisfies the 'spec'.
* We must first supply the attributes of the file to be searched for.
* This takes the following form:
*
*	Bits	 Type of file
*	 0	 Read only
*	 1	 Hidden
*	 2	 System
*	 3	 Volume label
*	 4	 Directory
*	 5	 Written to and closed (Archive bit set)
*
* Thefore %110111 will list all files but not the volume label

first:	move.w	#%110111,-(sp)		/we want to show all the files
	move.l	#spec,-(sp)		/move address of spec to stack
	move.w	#$4e,-(sp)		/use Fsfirst() function
	trap	#1			/use gemdos
	addq.l	#8,sp			/tidy up stack

	cmp.b	#0,d0			/check if there was a file found
	bne	end			/if there is not then end


* We then use Fsnext() to find the rest of the files matching 'spec'.
* A '0' will be returned in d0 each time Fsnext() finds a file and
* the file information will be stored in the DTA. A negative value
* will be returned in d0 if no file is found.

rest: 	move.l	#name,d0		/move address of filename to d0
	jsr	ptext			/and print to screen
	jsr	line			/print a new line
	move.w	#$4f,-(sp)		/use Fsnext() function
	trap	#1			/use gemdos
	addq.l	#2,sp			/tidy up stack
	cmp.b	#0,d0			/check if there was a file found
	beq	rest			/if there was then continue
	
end:	bra	exit			/exit from program

	include	"\SOURCE\FUNCTION.S"	/include standard functions

*** Program Data ***

spec:	dc.b	'\*.*',0	/file specification to look for
	even			/we need this line or an error will occur

dta:	ds.b	21		/junk			 -+
attrib:	ds.b	1		/file attributes	  |
time:	ds.b	2		/file time stamp	  | keep
date:	ds.b	2		/file date stamp	  | together
size:	ds.b	4		/file size		  |
name:	ds.b	14		/file name and extension -+
	
* Note: These last 6 statements must be kept together	
	
*** End of file ***	