*****************************************************************
*
* GRSCRAP - Graphics scrap routines.  They go through a jump
*	   table at the beginning of the static graphics segment
*	   (GRSTAT).
*
*	   Entries are:
*
*	   X_CopyGRPict
*	   X_FreeGRPict
*	   X_GRPictToPict
*
*****************************************************************
	load 'macros.dump'
	include 'driver.equ'
	include 'scrap.equ'

	IMPORT	D_LoadSegName
	entry	X_GetGRSTATAddr


*****************************************************************
*
* X_CopyGRPict - Copy a graphics picture
*
*****************************************************************
X_CopyGRPict	PROC	EXPORT
	input ingrpict:l
	output outgrpict:l

	local where:l
	error err
	begin +b

	call X_GetGRSTATAddr,out=where:l
	movew [where],slot+1
	movew [where]:#1,slot+2

	spacelong
	pushlong ingrpict
slot	jsl >0
	sta err
	pulllong outgrpict

	return

	ENDP

*****************************************************************
*
* X_FreeGRPict - Free a graphics picture
*
*****************************************************************
X_FreeGRPict	PROC	EXPORT
	input thegrpict:l
	error err

	local where:l
	begin +b

	call X_GetGRSTATAddr,out=where:l
	movew [where]:#4,slot+1
	movew [where]:#5,slot+2

	pushlong thegrpict
slot	jsl >0
	sta err

	return

	ENDP

*****************************************************************
*
* X_GRPictToPict - Convert graphics picture to PICT
*
*****************************************************************
X_GRPictToPict	PROC	EXPORT
	input ingrpict:l
	output outpict:l
	error err

	local where:l
	begin +b

	call X_GetGRSTATAddr,out=where:l
	movew [where]:#8,slot+1
	movew [where]:#9,slot+2

	spacelong
	pushlong ingrpict
slot	jsl >0
	sta err
	pulllong outpict

	return

	ENDP

*****************************************************************
*
* X_GetGRSTATAddr -- Get the address of the static graphics segment.
*	  Call the loader the first time; remember it after
*	  that.
*
*****************************************************************
X_GetGRSTATAddr	PROC	EXPORT
	output where:l
	error err
	begin
	stz err

	cmpl #0,>theaddr
	bne gotit

	call D_LoadSegName,in=#grstatname:l,out=(>theaddr:l,?:w),err=err

gotit	movel >theaddr,where
	return

theaddr	DC.L	0
grstatname	str 'GRSTAT'

	ENDP
	END

