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

	IMPORT	D_LoadSegName

	entry	X_GetPLSCRAPAddr
	ENTRY	X_PS_SegName
	ENTRY	PS_TheAddr

;--------------------------------------------------------------------
;
;  Page layout scrap routines go through a jump table at the
;  beginning of the static page layout segment (PLSCRAP).
;
;	   Entries are:
;
;	  X_CopyPLObj (ScrapHdl:l): CopyHdl:l
;	  X_KillPLObj (ObjHdl:l)
;	  X_PL2PictScrap (ObjHdl:l): PictHdl:l
;




;------------------------------------------------------------------------------
;
; X_CopyPLObj (ScrapHdl:l) : CopyHdl:l
;

X_CopyPLObj	PROC	EXPORT
	;Using X_PS_Data

	INPUT  ScrapHdl:l
	OUTPUT CopyHdl:l
	ERROR  Err

	LOCAL Where:l

	BEGIN

	call X_GetPLSCRAPAddr,out=(Where:l)
	moveword [Where],slot+1
	moveword [Where]:#1,slot+2

	spacelong
	pushlong ScrapHdl
slot	jsl >0
	sta Err
	pulllong CopyHdl

	RETURN
	ENDP




;-----------------------------------------------------------------------------
;
; X_KillPLObj (ObjHdl:l)
;

X_KillPLObj	PROC	EXPORT
	;Using X_PS_Data

	INPUT ObjHdl:l
	LOCAL Where:l

	BEGIN

	call X_GetPLSCRAPAddr,out=(Where:l)
	moveword [Where]:#4,slot+1
	moveword [Where]:#5,slot+2

	pushlong ObjHdl
	pushword #1
slot	jsl >0

	RETURN
	ENDP



;------------------------------------------------------------------------------
;
; X_PL2PictScrap (ObjHdl:l) : PictHdl:l
;
; Converts a D_PL scrap to a picture.
;

X_PL2PictScrap	PROC	EXPORT
	;Using X_PS_Data

	INPUT  ObjHdl:l
	OUTPUT PictHdl:l
	ERROR  Err

	LOCAL Where:l

	BEGIN +b


	call X_GetPLSCRAPAddr,out=(Where:l)
	moveword [Where]:#8,slot+1
	moveword [Where]:#9,slot+2

	spacelong
	pushlong ObjHdl
slot	jsl >0
	sta Err
	pulllong PictHdl


Exit	RETURN
	ENDP




;-------------------------------------------------------------------------
;
; X_GetPLSCRAPAddr () : WHere:l
;
;   Getd the address of the PLSCRAP static segment.
;   Call the loader the first time; remember it after that.
;

X_GetPLSCRAPAddr	PROC	EXPORT
	;Using X_PS_Data

	OUTPUT Where:l

	ERROR Err

	BEGIN
	stz err

	cmpl #0,>PS_TheAddr
	beq getit
	movelong >PS_TheAddr,Where
	bra Exit

getit	call D_LoadSegName,in=(#X_PS_SegName:l),out=(Where:l,a:w),err=Err
	movelong Where,>PS_TheAddr

Exit	RETURN
	ENDP

;-----------------------------------------------------------------------------
;
; X_PS_Data

X_PS_Data	PROC	EXPORT
	EXPORT	PS_TheAddr
	EXPORT	X_PS_SegName


PS_TheAddr	DC.L	0
X_PS_SegName	str 'PLSCRAP'



	ENDP
	END

