		**********************************
***************************	STE	**************************
		**********************************

	opt	C8+
	xref	_intin,_intout,_ptsin,_ptsout,_contrl
	xref	_loadlength
	xref	_fileselector,_myfp,_aespb,_doalert
	xref	_savefile,_loadfile,_format
	xref	_addrin,_addrout,_global
	xdef	_loadn,_delete,_createdir,_hardcreate
	xdef	_search,_diskfree


*****************************************************************
*	diskfree()						*
*								*
*	Returns the free space left on the current disk		*
*								*
*	Returns		positive number=free space in bytes	*
*			-1.L	some error occurred		*
*								*
*****************************************************************
_diskfree:
	movem.l	d1-a6,-(sp)
	move.w	#0,-(sp)	;get info for the active drive
	move.l	#buffer,-(sp)
	move.w	#$36,-(sp)
	trap	#1
	addq.l	#8,sp
	moveq	#0,d0
	move.l	freeal,d0	;get the number allocation units free
	move.l	pspal,d1
	mulu	d1,d0		;mult by number of sectors per au
	move.l	bps,d1
	mulu	d1,d0		;mult by bytes per sector
	movem.l	(sp)+,d1-a6
	rts
buffer:
freeal:		dc.l	0
totalal:	dc.l	0
bps:		dc.l	0
pspal:		dc.l	0
*****************************************************************
*	search(control.L,Filenameadd.L,filetype.W)		*
*								*
*	Searches the relevant paths and returns full pathname	*
*	in myfp.						*
*	Filenameadd is the address of the filename.		*
*	Filetype is the file type  as follows:			*
*	control is the address of the control struct		*
*								*
*	0=Graphics						*
*	1=sound							*
*	2=card							*
*								*
*	Returns:	0.L	if the file could not be found	*
*			1.L	if found and valid fname in myfp*
*****************************************************************
_search:
	move.w	4(sp),ftype
	move.l	6(sp),savename
	move.l	10(sp),savecontrol
	movem.l	d1-a6,-(sp)
	move.l	savecontrol,a5
	tst.w	ftype
	bgt	ss1
	lea	80(a5),a6		;graphics path
	bra	dosearch
ss1:
	cmpi.w	#1,ftype
	bne	ss2
	lea	160(a5),a6		;sound path
	bra	dosearch
ss2:
	lea	160+80(a5),a6		;which other path
dosearch:
	move.l	a6,a6save
	bsr	clearpath
	move.l	savecontrol,a5
	move.l	a5,a0		;which string to copy
	bsr	copypath
	move    #0,-(SP)        ;Open file
	move.l  #_myfp,-(SP)	;Address of filename
	move    #$3D,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	cmpi.w	#-33,d0
	beq	otherpath	;wasn't found
	tst.w	d0
	bmi	oe		;some other error, give em another chance
	bra	closenreturn
otherpath:
	bsr	clearpath
	move.l	a6save,a0		;which string to copy
	bsr	copypath
	move    #0,-(SP)        ;Open file
	move.l  #_myfp,-(SP)	;Address of filename
	move    #$3D,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	cmpi.w	#-33,d0
	beq	notfound	;wasn't found
	tst.w	d0
	bmi	oe2		;some other error, give em another chance
	bra	closenreturn
notfound:
	moveq	#0,d0
	movem.l	(sp)+,d1-a6
	rts


closenreturn:
	move.w	d0,-(sp)	;put the handle there
	move    #$3E,-(SP)      ;close
	trap    #1              ;Close file
	addq.l  #4,SP
	pea	dta
	move.w	#$1a,-(sp)	;set disk transfer address
	trap	#1
	addq.l	#6,sp
	move.w	#0,-(sp)	;search for normal files
	pea	_myfp
	move.w	#$4e,-(sp)
	trap	#1
	addq.l	#8,sp
	lea	dta,a0
	move.l	26(a0),_loadlength
	moveq	#1,d0
	movem.l	(sp)+,d1-a6
	rts

oe:
	lea	someerror,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	dosearch
	bra	notfound
oe2:
	lea	someerror,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	otherpath
	bra	notfound

copypath:
	lea	_myfp,a1
cpl:
	move.b	(a0)+,(a1)+
	bne	cpl
cpe:
	subq.l	#4,a1		;back past *.*
	move.l	savename,a0
cpn:
	move.b	(a0)+,(a1)+
	bne	cpn
*	move.b	#0,(a1)+	;nul terminate
	rts
clearpath:
	lea	_myfp,a0
	moveq	#79+8+3,d0
dsl:
	move.b	#0,(a0)+		;clear pathname
	dbf	d0,dsl
	rts

a6save:		dc.l	0
ftype:		dc.w	0
savebuff:	dc.l	0
savename:	dc.l	0
savecard:	dc.l	0
savecontrol:	dc.l	0
dta:		ds.b	44
someerror:
	dc.b	'[1][Error while opening file.]'
	dc.b	'[Try again|Forget it]',0,0
	even


*****************************************************************
*	hardcreate()						*
*								*
*	Creates the directory whose full name and path is	*
*	already in myfp.					*
*	Returns:	0.L	if the directory was not created*
*			1.L	if all is well			*
*****************************************************************
_hardcreate:
	movem.l	d1-d7/a0-a6,-(sp)	;save all the regs
hc:
	move.l	#_myfp,-(sp)
	move.w	#$39,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.w	d0		;was there an error
	bpl	hc1		;nope so return to Murray
	lea	dfailalert,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	hc
	moveq	#0,d0
	bra	hcb
hc1:
	moveq	#1,d0
hcb:
	movem.l	(sp)+,d1-a6
	rts

*****************************************************************
*	Createdir, call this sucker to bring up the fileselector*
*	get the name of a directory from the file line.		*
*	make sure they wanna. and do it				*
*	Simply call   createdir()				*
*								*
*	Returns:	Buggerall				*
*****************************************************************
_createdir:
	movem.l	d1-d7/a0-a6,-(sp)	;save all the regs
	lea	createexplain,a0
	bsr	_doalert
	move.l	#createstring,-(sp)
	move.l	#nosearch,-(sp)
	jsr	_fileselector
	addq.l	#8,sp
	cmpi.w	#1,d0		;was it successful
	beq.s	docreate
	tst.w	d0		;was it cancelled
	beq	createreturn
	lea	derroralert,a0	;musta been a general error
	bsr	_doalert
createreturn:
	moveq	#0,d0		;**********************
	movem.l	(sp)+,d1-d7/a0-a6
	rts
docreate:
	lea	deletealert,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	createreturn
cretry:
	move.l	#_myfp,-(sp)
	move.w	#$39,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.w	d0		;was there an error
	bpl	cr2		;nope so return to Murray*************
	lea	dfailalert,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	cretry
	bra	createreturn

cr2:				***************
	moveq	#1,d0		***************
	movem.l	(sp)+,d1-a6	****************
	rts			***************

createstring:
	dc.b	'Create a new Sub-directory',0
createexplain:
	dc.b	'[1][Locate where you wish the new|'
	dc.b	'sub-directory to appear and|'
	dc.b	'type the name you wish on the|'
	dc.b	'selection line.]'
	dc.b	'[ OK ]',0,0
	even
*****************************************************************
*	DELETE, call this sucker to bring up the fileselector	*
*	get the name of a file and remove after asking if the	*
*	wally is certain they wanna wipe out 3 days work.	*
*	Simply call   delete()					*
*								*
*	Returns:	Buggerall				*
*****************************************************************
_delete:
	movem.l	d0-d7/a0-a6,-(sp)	;save all the regs
	move.l	#deletestring,-(sp)
	move.l	#nosearch,-(sp)
	jsr	_fileselector
	addq.l	#8,sp
	cmpi.w	#1,d0		;was it successful
	beq.s	dodelete
	tst.w	d0		;was it cancelled
	beq	deletereturn
	lea	derroralert,a0	;musta been a general error
	bsr	_doalert
deletereturn:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

dodelete:
	lea	deletealert,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	deletereturn
dretry:
	move.l	#_myfp,-(sp)
	move.w	#$41,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.w	d0		;was there an error
	bpl	deletereturn	;nope so return to Murray
	lea	dfailalert,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	dretry
	bra	deletereturn


derroralert:
	dc.b	'[3][An unknown error has occurred.]'
	dc.b	'[Return to SoundscopeII]',0,0
dfailalert:
	dc.b	'[2][An error has occurred|'
	dc.b	'Was the disk write protected ?]'
	dc.b	'[Try again|Forget it]',0,0
deletealert:
	dc.b	'[3][Are you sure]'
	dc.b	'[Not really|Sure am]',0,0

deletestring:
	dc.b	'Delete a file',0
nosearch:
	dc.b	-1
	even

*****************************************************************
*	Load a file with complete path and name in myfp		*
*	Simplicity itself. Loads length bytes from start of	*
*	file.							*
*	call LOADN(address.L,length.L)				*
*				just give me the place to put	*
*				it.				*
*				And how many bytes.		*
*	Returns:						*
*				1.L	for complete success	*
*				-1.L	for file did not exist	*
*					and user wants to try	*
*					again.			*
*				-2.L	for file did not exist	*
*					and user doesn't give	*
*					a shit.			*
*				-3.L	for some general error	*
*****************************************************************
_loadn:
	move.l	4(sp),_loadlength
	move.l	8(sp),fileaddress
	movem.l	d1-d7/a0-a6,-(sp)

	move    #0,-(SP)        ;Open file
	move.l  #_myfp,-(SP) ;Address of filename
	move    #$3D,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	tst.w	d0
	bmi	loaderror
	move.w	d0,-(sp)
	move.w	(sp),d0
	move.l  fileaddress,-(SP)	;load it straight onto screen
	move.l  _loadlength,-(SP)	;load this many bytes
	move    D0,-(SP)	;Handle
	move    #$3F,-(SP)	;bios number
	trap    #1		;Read file in
	add.l   #12,SP
	tst.l	d0
	bmi	loade2
	move.l	d0,_loadlength
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
	moveq	#1,d0
loadback:
	movem.l	(sp)+,d1-d7/a0-a6
	rts

loaderror:
	cmpi.w	#-33,d0
	beq	fnferror
	moveq	#-3,d0
	bra	loadback
fnferror:
	lea	fnealert,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	bne	fnf2
	moveq	#-1,d0		;say user wants to try again
	bra	loadback
fnf2:
	moveq	#-2,d0
	bra	loadback

loade2:
	addq.l	#2,sp
	moveq	#-3,d0
	bra	loadback
fnealert:
	dc.b	'[1][Cannot load file!]'
	dc.b	'[Try again|Cancel]'
	even
fileaddress:	dc.l	0
