;*************************** AMUS Program Label ******************************
; Filename: FNDUFD.M68                                      Date: 11/05/89
; Category: UTIL         Hash Code: 646-333-232-232      Version: none    
; Initials: WYCH/AM      Name: W HARTGERS      
; Company: OMEGON HOLLAND                          Telephone #: 85-40404  
; Related Files: None
; Min. Op. Sys.: AMOSL 2.0                     Expertise Level: INT
; Special: This program runs ONLY on AMOS 2.0 with extended file structure
; Description: Program to look for ufd block on disk
; 
;
;*****************************************************************************
; Important: This program runs ONLY on amos 2.0 with extended file structure
;            It's not to be used for disks created and used by older
;            file systems!
;
; In case of corrupt ufd-links, you should be able to run this program, 
; and re-build the corrupt ufd-list by using DSKDDT or BLKEDT (on this system
; also) will do.
;
;***************************************************************************;

	SEARCH SYS	
	SEARCH SYSSYM
	SEARCH TRM	

	.OFINI
	.OFDEF	DDB1,D.DDB
	.OFDEF	ASC,80.
	.OFDEF	CH,DC.SIZ		; Work field for DEVCHR
	.OFDEF	SZBLK,4.   		; # of blocks on devive 
	.OFSIZ	SIZE


START:	GETIMP	SIZE,A5

	LIN				; Enf of line ?
	JEQ		FOUT		; Yes, error
	BYP				; Bypass blanks

	FSPEC		DDB1(A5)	; Uphere A2 points to the device name
	INIT		DDB1(A5)	; Init buffer
	DEVCHR		DDB1(A5),CH(A5)		; Return chararistics of device
	CLR		D1
	MOVW		DDB1+D.FMT(A5),D1 	; D1=Structure of the disk
	CMP		D1,#2			; Extended?
	BEQ		5$			; Yep
	TYPECR		<?Device is traditional format>
	EXIT
5$:
	MOV		CH+DC.BLK(A5),SZBLK(A5)	; Save number of blocks on device
	TYPE		<Device has >		; Say howmany blocks to check
	MOV		SZBLK(A5),D1
	DCVT		0,OT$TRM
	TYPECR		< blocks.>
	MOV		SZBLK(A5),D4		; Save # of blocks
	MOV		#0,D3			; Clear counter
10$:
	CMP		D3,D4			; End of physical?
	JLE		12$			; Nope
	JMP		FINE			; Yes, stop it

12$:
	MOV		D3,DDB1+D.REC(A5)	; Set up block number
	READ		DDB1(A5)		; Read block
	MOV		DDB1+D.BUF(A5),A4	; A4=start of buffer
	CTRLC 		FINE
25$:

	ADD		#4.,A4			; Update pointer
	CMPB		(A4)+,#4.		; Could it be an UFD block?
	JNE		50$			; Nope
	ADD		#1,A4			; 
	CMPB		(A4)+,#6.		; Still UFD?
 	JNE		50$			; Nope
	CMPB		(A4)+,#0.		; Last check also OK?
	JNE		50$			; Nope
	;	
	; assume UFD block (2.0) 
	;
	ADD		#28.,A4			; Index RAD50 file-name
	LEA		A2,ASC(A5)		; and the ascii field
	MOV		A4,A1			; Save pointer
	UNPACK					; Unpack file name
	UNPACK				
	MOVB		#'.,(A2)+		; 
	UNPACK					; and extention
	CLRB		(A2)+			
	LEA		A2,ASC(A5)

	TYPE		<Found block : >	; Output req. information
	MOV		D3,D1
	DCVT		0,OT$TRM
	TYPE		< (>
	OCVT		0,OT$TRM
	TYPE		<)>
	TYPE		<, first file in it  : >
	TAB
	TTYL		@A2			; and file name
	CRLF


50$:
	ADD		#1,D3			; Update block # 
	JMP		10$			; and try again

	
FINE:
	EXIT

FOUT:  
	TYPECR	<FNDUFD device-name: >
	EXIT

	END