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

	IMPORT	X_AWWPtoWPScrap
	IMPORT	D_Close
	IMPORT	X_ConvertScrap
	IMPORT	X_DisposeWPScrap
	IMPORT	X_ImportWP
	IMPORT	X_MSGStoWPScrap
	IMPORT	D_Mark
	IMPORT	D_MarkId
	IMPORT	D_Message1
	IMPORT	D_MessageThere
	IMPORT	D_NeedHandle
	IMPORT	D_Open
	IMPORT	D_OpenId
	IMPORT	D_OpenNamePtr
	IMPORT	D_Read
	IMPORT	D_ReadId
	IMPORT	D_ReadPtr
	IMPORT	D_ReadRequest
	IMPORT	D_ReadWord2
	IMPORT	D_SendMessage
	IMPORT	D_Set_Mark
	IMPORT	X_WPtoAsciiScrap
	IMPORT	X_WPtoPLScrap
	import	D_SetMark2
	import	D_Read2

X_ImportWPtoAscii	PROC	EXPORT

	input FileRef:w

	local Intermed:l

	output Dest:l

	error err

	begin

	SpaceLong
	PushWord	FileRef
	jsl X_ImportWP
	sta err
	PullLong Intermed
	jcs exit

	SpaceLong
	PushLong Intermed
	jsl X_WPtoAsciiScrap
	sta err
	PullLong Dest

	PushLong Intermed
	jsl X_DisposeWPScrap

exit	return

	ENDP

X_ImportWPtoPLText	PROC	EXPORT

	input FileRef:w

	local Intermed:l

	output Dest:l

	error err

	begin

	SpaceLong
	PushWord	FileRef
	jsl X_ImportWP
	sta err
	PullLong Intermed
	jcs exit

;	SpaceLong
;	PushLong Intermed
;	jsl X_WPtoAsciiScrap
;	sta err
;	PullLong Dest

	SpaceLong
	PushWord #WPText
	PushLong Intermed
	PushWord #StaticText
	jsl X_ConvertScrap
	sta err
	PullLong Dest

	PushLong Intermed
	jsl X_DisposeWPScrap

exit	return

	ENDP

X_ImportAscii	PROC	EXPORT

	input Src:l

	output Dest:l

	error err

	begin

	MoveLong Src,Dest
	MoveWord #4,err

	return
	ENDP

X_ImportMSGStoAscii	PROC	EXPORT

	input Src:l

	local Intermed:l

	output Dest:l

	error err

	begin

	SpaceLong
	PushLong Src
	jsl X_MSGStoWPScrap
	sta err
	PullLong Intermed
	jcs exit

	SpaceLong
	PushLong Intermed
	jsl X_WPtoAsciiScrap
	sta err
	PullLong Dest

	PushLong Intermed
	jsl X_DisposeWPScrap

exit	return


	ENDP

X_ImportMSGStoPLText	PROC	EXPORT

	input Src:l

	local Intermed:l

	output Dest:l

	error err

	begin

	SpaceLong
	PushLong Src
	jsl X_MSGStoWPScrap
	sta err
	PullLong Intermed
	jcs exit

	SpaceLong
	PushLong Intermed
	jsl X_WPtoPLScrap
	sta err
	PullLong Dest

	PushLong Intermed
	jsl X_DisposeWPScrap

exit	return
	ENDP


X_ImportAWWPtoAscii	PROC	EXPORT

	input Src:l

	local Intermed:l

	output Dest:l

	error err

	begin

	SpaceLong
	PushLong Src
	jsl X_AWWPtoWPScrap
	sta err
	PullLong Intermed
	jcs exit

	SpaceLong
	PushLong Intermed
	jsl X_WPtoAsciiScrap
	sta err
	PullLong Dest

	PushLong Intermed
	jsl X_DisposeWPScrap

exit	return
	ENDP
	
X_ImportAWWPtoPLText	PROC	EXPORT

	input Src:l

	local Intermed:l

	output Dest:l

	error err

	begin

	SpaceLong
	PushLong Src
	jsl X_AWWPtoWPScrap
	sta err
	PullLong Intermed
	jcs exit

	SpaceLong
	PushLong Intermed
	jsl X_WPtoPLScrap
	sta err
	PullLong Dest

	PushLong Intermed
	jsl X_DisposeWPScrap

exit	return
	ENDP


X_ImportGRScrap	PROC	EXPORT
	;Using D_IOData
	;Using X_WPFileData
	;Using D_OpenData

	input FileRef:w

	local Total:l,Size:l,ColorHand:l

	output Dest:l

	error err

	begin +b

	stz err

	Stzl Total

; Skip past version number
	call	D_ReadWord2,in=(FileRef:w),out=(a:w),err=err
	jcs exit


; Get size of header
	call	D_ReadWord2,in=(FileRef:w),out=(Size:w),err=err
	jcs exit

	MoveLong #4,Total

; Get size of reference record
	call	D_ReadWord2,in=(FileRef:w),out=(Size:w),err=err
	jcs exit

	Addwl #2,Total
	Addwl Size,Total


; Skip past it
	call	D_SetMark2,in=(FileRef:w,#0:w,Total:l)

; Get size of color table
	call	D_ReadWord2,in=(FileRef:w),out=(Size:w),err=err
	jcs exit

	Addwl #2,Total
	Addwl Size,Total

	SpaceLong
	PushWord	#0
	PushWord Size
	PushWord #$4000
	jsl D_NeedHandle
	sta err
	PullLong ColorHand
	jcs exit
	MoveLong ColorHand,>D_Message1

	MoveWord #3,>D_MessageThere

	call	D_Read2,in=(FileRef:w,[ColorHand]:l,#0:w,Size:w),out=ax:l,err=err
	jcs	exit

; Skip past print record
	call	D_ReadWord2,in=(FileRef:w),out=(Size:w),err=err
	jcs exit

	Addwl #2,Total
	Addwl Size,Total

	call	D_SetMark2,in=(FileRef:w,#0:w,Total:l),err=err
	jcs exit

; Ask graphics for a scrap from this file
	SpaceLong
	PushWord #5
	PushWord #$0500
	PushWord #0
	PushWord	FileRef
	jsl D_SendMessage
	sta err
	PullLong Dest

exit
	return


	ENDP
	END

