*=======================================================*
*	Macros: latest update 21/11/95			*
*=======================================================*
*-------------------------------------------------------*
*	Stack management macros				*
*-------------------------------------------------------*

push		macro
		move.\0		\1,-(sp)
		endm
	
pop		macro
		move.\0		(sp)+,\1
		endm

pushall		macro
		movem.l		d0-a6,-(sp)
		endm
	
popall		macro
		movem.l		(sp)+,d0-a6
		endm

*-------------------------------------------------------*
*	DSP communications macros			*
*-------------------------------------------------------*

dspexec		macro
		moveq		#1,d1
		move.l		#(\1_e-\1)/3,d0
		lea		\1,a0
		jsr		DspExecProg
		endm

dspwrite	macro
.ww\@		btst		#1,$FFFFA202.w
		beq.s		.ww\@
		ifeq		'\0'-'w'
		move.w		\1,$FFFFA206.w
		elseif
		ifeq		'\0'-'l'
		move.l		\1,$FFFFA204.w
		endc
		endc
		endm

dspread		macro
.wr\@		btst		#0,$FFFFA202.w
		beq.s		.wr\@
		ifeq		'\0'-'w'
		move.w		$FFFFA206.w,\1
		elseif
		ifeq		'\0'-'l'
		move.l		$FFFFA204.w,\1
		endc
		endc
		endm

*-------------------------------------------------------*
*	Display management macros			*
*-------------------------------------------------------*

vsync		macro
.wv\@:		tst.w		timer
		bne.s		.wv\@
		move.w		#vbilock,timer
		endm

triplebuffer	macro
		lea		screen_ptrs,a0
		move.l		(a0),d0
		move.l		4(a0),(a0)
		move.l		8(a0),4(a0)
		move.l		d0,8(a0)
		lsr.w		#8,d0
		move.l		d0,$ffff8200.w
		move.b		#0,$ffff820d.w
		endm

*-------------------------------------------------------*
*	Memory management macros			*
*-------------------------------------------------------*

Malloc		macro
		move.l		\1,-(sp)
		move.w		#$48,-(sp)
		trap		#1
		addq.l		#6,sp
		endm

Mxalloc		macro
		move.w		#\2,-(sp)
		move.l		\1,-(sp)
		move.w		#68,-(sp)
		trap		#1
		addq.l		#8,sp
		endm

*-------------------------------------------------------*
*	Big/little endian macros			*
*-------------------------------------------------------*

Fixlong		macro		register
		rol.w		#8,\1
		swap		\1
		rol.w		#8,\1
		endm

Fixword		macro		register
		rol.w		#8,\1
		endm

*-------------------------------------------------------*
*	I/O macros					*
*-------------------------------------------------------*

Cconout		macro		char
		move.w		\1,-(sp)
		move.w		#2,-(sp)
		trap		#1
		addq.l		#4,sp
		endm

Crawcin		macro
		move.w		#7,-(sp)
		trap		#1
		addq.l		#2,sp
		endm
		
Cconws		macro		string
		move.l		\1,-(sp)
		move.w		#9,-(sp)
		trap		#1
		addq.l		#6,sp
		endm

Fopen		macro		fname,mode
		move.w		\2,-(sp)
		move.l		\1,-(sp)
		move.w		#61,-(sp)
		trap		#1
		addq.l		#8,sp
		tst.w		d0
		endm

Fclose		macro		handle
		move.w		\1,-(sp)
		move.w		#62,-(sp)
		trap		#1
		addq.l		#4,sp
		endm

Fread		macro		handle,count,buffer
		move.l		\3,-(sp)
		move.l		\2,-(sp)
		move.w		\1,-(sp)
		move.w		#63,-(sp)
		trap		#1
		lea		12(sp),sp
		endm

Fseek		macro		offset,handle,seekmode
		move.w		\3,-(sp)
		move.w		\2,-(sp)
		move.l		\1,-(sp)
		move.w		#66,-(sp)
		trap		#1
		lea		10(sp),sp
		endm

Mfree		macro		address
		move.l		\1,-(sp)
		move.w		#73,-(sp)
		trap		#1
		addq.l		#6,sp
		endm

*-------------------------------------------------------*
