	LOAD	'Macros.dump'
	INCLUDE 'Pict.equ'
	INCLUDE	'Driver.equ'

	IMPORT	Q_printsquare
	IMPORT	Q_square

****************************************************************
*
*   Q_ManglePoint(srcpt:l,rectptr:l,what:w,prrec:l):dstpt:l
*		Flip/rotate a Q_Point around the Q_center of a rectangle.
*		srcpt and dstpt are values, not pointers.  Everything
*		is done according to the print record prrec.
*
****************************************************************
Q_ManglePoint	PROC		EXPORT
			;Using	Q_PictData

		input	srcpt:l,rectptr:l,who:w,prrec:l
		output   dstpt:l
		local	middle:l,prptr:l

		begin	+b

		movelong [rectptr],myrect
		movelong [rectptr]:#4,myrect+4

		cmpl	 prrec,#0
		beq	  nomap

		movelong [prrec],prptr
		movelong [prptr]:#4,Q_printsquare+4

		pushlong #myrect
		pushlong #Q_printsquare
		pushlong #Q_square
		_MapRect

		pushlong !srcpt
		pushlong #Q_printsquare
		pushlong #Q_square
		_MapPt

nomap	addword  myrect,myrect+4,middle
		addword  myrect+2,myrect+6,middle+2

		jtl	  trashPt,who

		cmpl	 prrec,#0
		beq	  nomap2

		pushlong !srcpt
		pushlong #Q_square
		pushlong #Q_printsquare
		_MapPt

nomap2	movelong srcpt,dstpt

		return

trashPt	DC.L	h_pt
	DC.L	v_pt
	DC.L	r_pt
	DC.L	l_pt
*--------------------------------------------------------------*
h_pt	lda	  middle+2		; H-flip the Q_Point around middle.x
		sec
		sbc	  srcpt+2
		sta	  srcpt+2
		rtl
*--------------------------------------------------------------*
v_pt	lda	  middle		  ; V-flip the Q_Point around middle.y
		sec
		sbc	  srcpt
		sta	  srcpt
		rtl
*--------------------------------------------------------------*
;
;  NOTE: The reason behind adding the last bit of either middle or
;		middle+2 in the calculations below is to prevent the Q_Point
;		from creeping up and/or to the left when (middle)+(middle+2)
;		is odd.  Trust me.  It works.
;											  -- jge, 1/20/88
;
r_pt	lda	  middle+2		; R-rotate the Q_Point around middle
		and	  #1			  ; <adjust for creep>
		clc
		adc	  middle+2		; pt.x <= -(pt.y - middle.y) + middle.x
		adc	  middle
		sta	  dstpt		   ; (divide middle by 2, preserving
		asl	  dstpt			;  the sign)
		ror	  a			   ;
		sec
		sbc	  srcpt
		tax					  ; D_Save it here...

		lda	  middle		  ; pt.y <= pt.x - middle.x + middle.y
		and	  #1			  ; <adjust for creep>
		clc
		adc	  middle
		sec
		sbc	  middle+2
		sta	  dstpt		   ; (divide middle by 2, preserving
		asl	  dstpt			;  the sign)
		ror	  a			   ;
		clc
		adc	  srcpt+2
		sta	  srcpt

		stx	  srcpt+2		 ; ...and store it here.

r_ptdone	rtl
*--------------------------------------------------------------*
l_pt	lda	  middle		  ; L-rotate the Q_Point around middle
		and	  #1			  ; <adjust for creep>
		clc
		adc	  middle		  ; pt.y <= -(pt.x - middle.x) + middle.y
		adc	  middle+2
		sta	  dstpt		   ; (divide middle by 2, preserving
		asl	  dstpt			;  the sign)
		ror	  a			   ;
		sec
		sbc	  srcpt+2
		tay					  ; D_Save it here...

		lda	  middle+2		; pt.x <= pt.y - middle.y + middle.x
		and	  #1			  ; <adjust for creep>
		clc
		adc	  middle+2
		sec
		sbc	  middle
		sta	  dstpt		   ;  (divide middle by 2, preserving
		asl	  dstpt			;  the sign)
		ror	  a			   ;
		clc
		adc	  srcpt
		sta	  srcpt+2

		sty	  srcpt		   ; ...and store it here.

l_ptdone	rtl
*--------------------------------------------------------------*
myrect		DS.B 8

		ENDP
		END

