	load	'macros.dump'
	include	'driver.equ'
	include	'scrap.equ'

	import	X_ScPLtoAsciiScrap
	import	X_ScWPtoAsciiScrap
	import	X_ScSStoAsciiScrap
	import	X_ScPLtoWPScrap
	import	X_ScImportAsciitoWPScrap
	import	X_ScAsciitoWPScrap
	import	X_ScAWDBtoDBScrap
	import	X_ScInitFieldScanner
	import	X_ScMSGStoWPScrap
	import	X_ScDBtoPICT
	import	X_ScDBtoPLScrap
	import	X_ScWPtoPLScrap
	import	X_ScSStoPLScrap
	import	X_ScImportAsciitoPLText
	import	X_ScAWSStoSSScrap
	import	X_ScDoAsciitoSSScrap
	import	X_ScImportAsciitoSSScrap
	import	X_ScLoad_Picture
	import	X_ScReadWPScrap
	import	X_ScWriteWPScrap
	import	X_ScWriteThread
	import	X_ScImportWP
	import	X_ScAWWPtoWPScrap
	import	X_ScDoAsciitoDBScrap
	import	X_ScImportAsciitoDBScrap
	import	D_LoadSegment
	import	D_UnloadSegment
	import	X_ScDoAsciitoPLText

;DOASCII segment
X_PLtoAsciiScrap	PROC	EXPORT
	
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segToAscii:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScPLtoAsciiScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segToAscii:w,#0:w)

@exit	return
	ENDP
	
X_WPtoAsciiScrap	PROC	EXPORT
	
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segToAscii:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScWPtoAsciiScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segToAscii:w,#0:w)

@exit	return
	ENDP

X_SStoAsciiScrap	PROC	EXPORT
	
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segToAscii:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScSStoAsciiScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segToAscii:w,#0:w)

@exit	return
	ENDP

;TOWPTEXT segment
X_PLtoWPScrap	PROC	EXPORT
	
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segToWPScrap:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScPLtoWPScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segToWPScrap:w,#0:w)

@exit	return
	ENDP

X_AsciitoWPScrap	PROC	EXPORT
	
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segToWPScrap:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScAsciitoWPScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segToWPScrap:w,#0:w)

@exit	return
	ENDP



;IMPORTAWDB segment
X_AWDBtoDBScrap	PROC	EXPORT
	
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	stz	err
	
	call	D_LoadSegment,in=(#SegImportAWDB:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScAWDBtoDBScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#SegImportAWDB:w,#0:w)
	
@exit	return
	
	ENDP

;TODBSCRAP segment
X_DoAsciitoDBScrap	PROC	EXPORT

	input	Src:l,SepFlag:w,ScanFields:w
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	stz	err
	
	call	D_LoadSegment,in=(#segToDBScrap:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScDoAsciitoDBScrap,in=(Src:l,SepFlag:w,ScanFields:w),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segToDBScrap:w,#0:w)
	
@exit	return
	ENDP

X_ImportAsciitoDBScrap	PROC	EXPORT
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	stz	err
	
	call	D_LoadSegment,in=(#segToDBScrap:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScImportAsciitoDBScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segToDBScrap:w,#0:w)
	
@exit	return
	ENDP



;IMPORTMSGS segment
X_MSGStoWPScrap	PROC	EXPORT

	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segImportMSGS:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScMSGStoWPScrap,in=(Src:l),Out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segImportMSGS:w,#0:w)
	
@exit	return

	ENDP


;TOPICT segment
X_DBtoPICT	PROC	EXPORT

	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segTOPICT:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScDBToPICT,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segTOPICT:w,#0:w)

@exit	return

	ENDP


;TOSTATTEXT segment
X_DBtoPLScrap	PROC	EXPORT

	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segTOSTATTEXT:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScDBToPLScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segTOSTATTEXT:w,#0:w)

@exit	return

	ENDP

X_WPtoPLScrap	PROC	EXPORT

	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segTOSTATTEXT:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScWPtoPLScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segTOSTATTEXT:w,#0:w)

@exit	return

	ENDP

X_SStoPLScrap	PROC	EXPORT

	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segTOSTATTEXT:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScSStoPLScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segTOSTATTEXT:w,#0:w)

@exit	return

	ENDP

X_DoAsciitoPLText	PROC	EXPORT

	input	Src:l,FontID:l,Color:w
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segTOSTATTEXT:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScDoAsciitoPLText,in=(Src:l,FontID:l,Color:w),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segTOSTATTEXT:w,#0:w)

@exit	return

	ENDP



;IMPORTAWSS segment
X_AWSStoSSScrap	PROC	EXPORT
	
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segImportAWSS:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScAWSStoSSScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segImportAWSS:w,#0:w)

@exit	return

	ENDP

;TOSSScrap segment
X_DoAsciitoSSScrap	PROC	EXPORT

	input	Src:l,SepFlag:w,ScanFields:w
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	stz	err
	
	call	D_LoadSegment,in=(#segToSSScrap:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScDoAsciitoSSScrap,in=(Src:l,SepFlag:w,ScanFields:w),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segToSSScrap:w,#0:w)
	
@exit	return
	ENDP

X_ImportAsciitoSSScrap	PROC	EXPORT
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	stz	err
	
	call	D_LoadSegment,in=(#segToSSScrap:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScImportAsciitoSSScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segToSSScrap:w,#0:w)
	
@exit	return
	ENDP


;IMPORTPICT segment
X_Load_Picture	PROC	EXPORT
	sta	>TheA
	txa
	sta	>TheX
	tya
	sta	>TheY
	
	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	stz	err
	
	call	D_LoadSegment,in=(#segImportPICT:w,#0:w),out=(ax:l),err=err
	jcs	@exit

	SpaceLong
	PushLong	Src
	lda	TheA
	ldx	TheX
	ldy	TheY
	jsl	X_ScLoad_Picture
	sta	err
	PullLong	Dest		;I have to unload even if error
	
	call	D_UnloadSegment,in=(#segImportPICT:w,#0:w)
	
@exit	return
	
TheA	DS.W	1
TheX	DS.W	1
TheY	DS.W	1
	ENDP


;WPIO segment - X_ReadWPScrap, X_WriteWPScrap, and X_WriteThread depend on the segment
;already being loaded.
X_ReadWPScrap	PROC	EXPORT
	input	FileRef:w,Type:w
	output	Scrap:l
	error	err
	begin	+b
	call	X_ScReadWPScrap,in=(FileRef:w,Type:w),out=(Scrap:l),err=err
	return
	
	ENDP
	
X_WriteWPScrap	PROC	EXPORT
	input	FileRef:w,Scrap:l,Type:w
	error	err
	begin	+b
	call	X_ScWriteWPScrap,in=(FileRef:w,Scrap:l,Type:w),err=err
	return
	
	ENDP

X_WriteThread	PROC	EXPORT
	input	FileRef:w,Pars:w,Scrap:l,Type:w
	error	err
	begin	+b
	call	X_ScWriteThread,in=(FileRef:w,Pars:w,Scrap:l,Type:w),err=err
	return
	
	ENDP

X_ImportWP	PROC	EXPORT
	
	input	FileRef:w
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	stz	err
	call	D_LoadSegment,in=(#segWPIO:w,#0:w),out=(ax:l),err=err
	bcs	@exit
	
	call	X_ScImportWP,in=(FileRef:w),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segWPIO:w,#0:w)
	
@exit	return
	ENDP
	

;IMPORTAWWP segment
X_AWWPtoWPScrap	PROC	EXPORT

	input	Src:l
	
	output	Dest:l
	
	error	err
	
	begin	+b
	
	call	D_LoadSegment,in=(#segImportAWWP:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	
	call	X_ScAWWPtoWPScrap,in=(Src:l),out=(Dest:l),err=err
	
	call	D_UnloadSegment,in=(#segImportAWWP:w,#0:w)

@exit	return

	ENDP

X_InitScrap	PROC	EXPORT

	error	err
	
	begin

	call	D_LoadSegment,in=(#segToAscii:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	call	D_UnloadSegment,in=(#segToAscii:w,#0:w)

	call	D_LoadSegment,in=(#segToWPScrap:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	call	D_UnloadSegment,in=(#segToWPScrap:w,#0:w)

	call	D_LoadSegment,in=(#segToDBScrap:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	call	D_UnloadSegment,in=(#segToDBScrap:w,#0:w)

	call	D_LoadSegment,in=(#segToPICT:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	call	D_UnloadSegment,in=(#segToPICT:w,#0:w)

	call	D_LoadSegment,in=(#segToStatText:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	call	D_UnloadSegment,in=(#segToStatText:w,#0:w)

	call	D_LoadSegment,in=(#segToSSScrap:w,#0:w),out=(ax:l),err=err
	jcs	@exit
	call	D_UnloadSegment,in=(#segToSSScrap:w,#0:w)


@exit	return
	ENDP

	END

