;; Protect.i	Copyright 1987 by James M Synge
;;
;; An assembly macro for protecting registers.
;; Not for the weak of heart.

	macro	protect

	if	NARG <> 2
	fail		; Must specify the number of args!
	mexit
	endc

	iflt	\2
	fail		; Negative number of args!
	mexit
	endc

; Until a bug fix arrives for the assembler so that the \0
; macro works, we must assume the argument size is 4 bytes.

\@elementsize	set 4
\@bytes		set \@elementsize * \2
\@offset	set \@bytes + (AztecBugSize * 4)

	movem.l	AztecBugList,-(sp)	; Save some regs

	; Push the argument(s).  We'll use D0 as our scratch
	; register.  It is free for that use according to
	; the register convention.  It is used as the result
	; register.
	
	ifne	\2	; If there are any arguments

	moveq	#\2,d0	; Number of arguments to move
\@loop	move.l	\@offset(sp),-(sp)	; Push an arg
	subq.l	#1,d0		; Last argument?
	bne	\@loop		; If so, loop again?

	endc

	jsr	\1	; Call the C routine

	ifne	\2		; Pop any arguments
	ifge	8 - \@bytes	; Can we use addq.l?
	addq.l	#\@bytes,sp	; Yup!
	else
	lea	\@bytes(sp),sp	; Otherwise use lea
	endc
	endc

	movem.l	(sp)+,AztecBugList	; Restore regs
	rts		; And return

	endm	; End of the protect macro
