	IFND	EXEC_MACROS_I
EXEC_MACROS_I	 EQU	 1
**
**	$Filename: exec/macros.i $
**	$Release: 2.04 Includes, V37.4 $
**	$Revision: 36.8 $
**	$Date: 90/11/01 $
**
**	Handy macros for assembly language programmers.
**
**	(C) Copyright 1985-1991 Commodore-Amiga, Inc.
**	    All Rights Reserved
**

		IFND	DEBUG_DETAIL
DEBUG_DETAIL	SET	0	;Detail level of debugging.  Zero for none.
		ENDC



	ifnd	__m68

JSRLIB		MACRO	;FunctionName
		XREF	_LVO\1
		jsr	_LVO\1(a6)
		ENDM

JMPLIB		MACRO	;FunctionName
		XREF	_LVO\1
		jmp	_LVO\1(a6)
		ENDM

BSRSELF	MACRO
		XREF	\1
		bsr	\1
		ENDM

BRASELF	MACRO
		XREF	\1
		bra	\1
		ENDM

BLINK		MACRO
		IFNE	DEBUG_DETAIL
		  bchg.b #1,$bfe001  ;Toggle the power LED
		ENDC
		ENDM

TRIGGER		MACRO	;<level> Trigger a hardware state analyzer
		IFGE	DEBUG_DETAIL-\1
		  move.w #$5555,$2fe
		ENDC
		ENDM

CLEAR		MACRO
		moveq.l #0,\1
		ENDM

CLEARA		MACRO
		suba.l	\1,\1	;Quick way to put zero in an address register
		ENDM

	else	;is Macro68

JSRLIB	MACRO	1,1
	ifnd	_LVO\1
	xref	_LVO\1
	endc
	jsr	(_LVO\1,a6)
	ENDM

JMPLIB	MACRO	1,1
	ifnd	_LVO\1
	xref	_LVO\1
	endc
	jmp	(_LVO\1,a6)
	ENDM

BSRSELF	MACRO	1,1
	ifnd	\1
	xref	\1
	endc
	bsr	\1
	ENDM

BRASELF	MACRO	1,1
	ifnd	\1
	xref	\1
	endc
	bra	\1
	ENDM

BLINK	MACRO	0,0
	bchg	#1,($bfe001)
	ENDM

TRIGGER	MACRO	0,0
	move.w	#$5555,($2fe)
	ENDM

CLEAR	MACRO	1,1
	ifc 'A',\*UPPER(\*LEFT(\1,1))
	suba.l	\1,\1
	else
	moveq	#0,\1
	endc
	ENDM

CLEARA	MACRO	1,1
	CLEAR	\1
	ENDM

	endc	;__m68


*************************************************************************
		IFND	PRINTF

	ifnd	__m68

PRINTF		MACRO	; level,<string>,...
		IFGE	DEBUG_DETAIL-\1
		XREF	kprint_macro
PUSHCOUNT	SET	0

		IFNC	'\9',''
		move.l	\9,-(sp)
PUSHCOUNT	SET	PUSHCOUNT+4
		ENDC

		IFNC	'\8',''
		move.l	\8,-(sp)
PUSHCOUNT	SET	PUSHCOUNT+4
		ENDC

		IFNC	'\7',''
		move.l	\7,-(sp)
PUSHCOUNT	SET	PUSHCOUNT+4
		ENDC

		IFNC	'\6',''
		move.l	\6,-(sp)
PUSHCOUNT	SET	PUSHCOUNT+4
		ENDC

		IFNC	'\5',''
		move.l	\5,-(sp)
PUSHCOUNT	SET	PUSHCOUNT+4
		ENDC

		IFNC	'\4',''
		move.l	\4,-(sp)
PUSHCOUNT	SET	PUSHCOUNT+4
		ENDC

		IFNC	'\3',''
		move.l	\3,-(sp)
PUSHCOUNT	SET	PUSHCOUNT+4
		ENDC

		movem.l a0/a1,-(sp)
		lea.l	PSS\@(pc),A0
		lea.l	4*2(SP),A1
		BSR	kprint_macro
		movem.l (sp)+,a0/a1
		bra.s	PSE\@

PSS\@		dc.b	\2
		IFEQ	(\1&1)	;If even, add CR/LF par...
		   dc.b 13,10
		ENDC
		dc.b	0
		ds.w	0
PSE\@
		lea.l	PUSHCOUNT(sp),sp
		ENDC	;IFGE	DEBUG_DETAIL-\1
		ENDM	;PRINTF	MACRO

	else	;is Macro68

STACK	MACRO
	push	\(argPointer)
PUSHCOUNT  set	PUSHCOUNT+4
argPointer set	argPointer+1
	ENDM

PRINTF	MACRO
	IFGE	DEBUG_DETAIL-\1
	ifnd	kprint_macro
	XREF	kprint_macro
	endc
PUSHCOUNT  set	0
argPointer set	1
	repeat	NARG
	STACK	\1,\2,\3,\4,\5,\6,\7,\8,\9,\a,\b,\c,\d,\e,\f,\g,\h,\i,\j,\k,\l,\m,\n,\o,\p,\q,\r,\s,\t,\u,\v,\w,\x,\y,\z
	endr
	movem.l	a0/a1,-(sp)
	lea	(PSS\@,pc),A0
	lea	(4*2,sp),a1
	bsr	kprint_macro
	movem.l (sp)+,a0/a1
	bra.b	PSE\@
PSS\@	dc.b	\2
	IFEQ	(\1&1)	;If even, add CR/LF par...
	dc.b 13,10
	ENDC
	dc.b	0
	ds.w	0
PSE\@	lea	(PUSHCOUNT,sp),sp
	ENDC	;IFGE	DEBUG_DETAIL-\1
	ENDM	;PRINTF	MACRO

	endc	;__m68

		ENDC	;IFND	PRINTF


;----------------------------------------------------------------------------
;Push a set of registers onto the stack - undo with POPM.  This prevents
;the need to update or synchronize two MOVEM instructions.  These macros
;assume an optimizing assembler that will convert single register  MOVEM
;to MOVE.  Because the REG assignment can't be reset, these macros do
;not nest.
;
;	    PUSHM   d2/a2/a5
;	    ...code...
;	    POPM
;	    RTS
;
;
;
;Macro68 has built-in pushm & popm instructions.  If you want
;to use these macros then the built-in directives must first be
;disabled by editing the macro68custom.asm file and re-assembling
;it or by changing the names of these macros.  Otherwise use Macro68's
;'movem' and '_movemcount' facilities to emulate &/or improve these macros.
;
;

	ifnd	__m68

PUSHM_COUNT			SET	0
PUSHM				MACRO
				IFGT	NARG-1
				FAIL	!!!! TOO MANY ARGUMENTS TO PUSHM !!!!
				ENDC
PUSHM_COUNT			SET	PUSHM_COUNT+1
PUSHM_\*VALOF(PUSHM_COUNT)      REG     \1
				movem.l PUSHM_\*VALOF(PUSHM_COUNT),-(sp)
				ENDM

;
;Undo most recent PUSHM.  'POPM NOBUMP' allows multiple exit points.
;
POPM				MACRO
				movem.l (sp)+,PUSHM_\*VALOF(PUSHM_COUNT)
				IFNC	'\1','NOBUMP'
PUSHM_COUNT			SET	PUSHM_COUNT+1	;error if re-used
				ENDC
				ENDM

	endc	;__m68

;----------------------------------------------------------------------------


	ENDC	; EXEC_MACROS_I
