;****************************************************************************
; FNDMOD.M68	-	"Find Module" subroutine
;
;	Written by:	Dave Heyliger - AMUS Staff
;
;	Purpose:	To search user memory for the specified module
;			that may or may not be in their memory partition
;
;	Usage:		XCALL FNDMOD,module,result
;
;		where	module is MAP1,S,30	(module name in string format)
;			result is MAP1,F	(1 = "true" ; 0 = "false")
;
;	Sample BASIC program:
;
;		module = "BOGUS.MOD"
;		XCALL FNDMOD,module,result
;		IF result = 0 THEN PRINT "module not found, fella!" &
;			      ELSE PRINT "module found!"
;
;****************************************************************************

	OBJNAM	.SBR				;final result is FNDMOD.SBR

	SEARCH	SYS				;get the regulars
	SEARCH	SYSSYM
	SEARCH	TRM

	;define version number
	VMAJOR = 1				;original by Dave Heyliger
	VMINOR = 0				; version 1.0(100)
	VEDIT = 100.

	;define some workspace - A4 default pointer
	.OFINI					;a variable buffer
	.OFDEF	BUFFER,30.			;"oversized" buffer space
	.OFSIZ	IMPSIZ				;definitions done

	PHDR	-1,0,PH$REE!PH$REU		;good programming!

	;error checking first:
	CMPW	@A3,#2				;2 arguments?
	BNE	10$				;nope, error
	CMPW	2(A3),#2			;first argument a string?
	BNE	10$				;nope, error
	CMPW	12.(A3),#4			;second argument float. pt?
	BEQ	20$				;yup, looks good

	;error in input, inform the user
10$:	TYPECR	<Usage: XCALL FNDMOD,module,result>
	TYPECR	<	where module is a string>
	TYPECR	<	and result is floating point.>
	RTN

	;input looks good - let's get on with it!
20$:	MOV	4(A3),A2			;A2 points to module string
	FILNAM	BUFFER(A4),MOD			;default extension is .MOD
	SRCH	@A4,A0,F.USR			;look only in users memory
	BEQ	40$				;found it!

	;didn't find the module - set result to "0" in floating point notation
	MOV	#0,D1				;"0" = false
30$:	MOV	16(A3),A0			;A0 points to variable
	FLTOF	D1,@A0				;set result to false
	RTN

	;found the module - set result to "1" in floating point notation
40$:	MOV	#1,D1				;"1" = found
	BR	30$				;continue w/ above code

	END