
; Startup MACROs - Copyright Ludde'95

	include "include:lvo3.0/exec_lib.i"
	include "include:lvo3.0/dos_lib.i"
	include "include:lvo3.0/graphics_lib.i"
	include	"include:hardware/dmabits.i"
	include	"include:hardware/intbits.i"
	include	"include:exec/memory.i"

_StartupCode		=	1


MLeft	=	$2000
MRight	=	$4000


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

BlitterWait:	MACRO		;None

.blitwait\@:
	btst	#14-8,$dff002
	bne	.blitwait\@

		ENDM

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

RasterWait:	MACRO		;RaserLine

.rast\@:
	move.l	$dff004,d0
	lsr.l	#8,d0
	and.l	#$1ff,d0
	cmp.w	#\1,d0
	bne.s	.rast\@
.rast2\@:
	move.l	$dff004,d0
	lsr.l	#8,d0
	and.l	#$1ff,d0
	cmp.w	#\1,d0
	beq.s	.rast2\@

		ENDM

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

RastPos:	MACRO		;RasterPos Destination

	move.l  $dff004,d0	
	lsr.l   #8,d0		
	and.l   #$1FF,d0	
	move.w  d0,\1		

		ENDM

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

SetBitmap:	MACRO		;Screen,bitplspointers,#.of.bitpls,size,(step)

	lea.l	\1,a0
	lea.l	\2,a1
	moveq	#\3-1,d1
.anextpl\@:
	move.l	a0,d0
	move.w	d0,6(a1)
	swap	d0
	move.w	d0,2(a1)

	IFNE	NARG-5
	addq.l	#8,a1
	ELSE
	lea.l	\5(a1),a1
	ENDIF
	
	lea.l	\4(a0),a0
	dbra	d1,.anextpl\@

		ENDM

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

CALL:		MACRO		;LibCall(a?)

	jsr	_LVO\1

		ENDM

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

OpenLib:	MACRO		;LibraryName,LibraryBase

	move.l	4.w,a6
	lea.l	\1,a1
	CALL	OldOpenLibrary(a6)
	move.l	d0,\2

		ENDM

CloseLib:	MACRO		;LibraryBase

	move.l	4.w,a6
	move.l	\1,a1
	CALL	CloseLibrary(a6)

		ENDM


;---------------------------------------------------------------
SetDMA:		MACRO		;DMA bits

        move.w	#DMAF_SETCLR!\1,$dff096

		ENDM
;---------------------------------------------------------------
SetINT:		MACRO		;INTENA bits

        move.w	#INTF_SETCLR!\1,$dff09a

		ENDM

;---------------------------------------------------------------
SetINTQ:	MACRO		;INTENA bits

        move.w	#INTF_SETCLR!\1,$dff09c

		ENDM
;---------------------------------------------------------------
ClrINT:		MACRO		;ALL or INTENA bits

	IFC	"\1","ALL"
        move.w	#$7FFF,$dff09a
	ELSE
	move.w	#\1,$dff09a
	ENDIF	

		ENDM

;---------------------------------------------------------------
ClrINTQ:	MACRO		;ALL or INTENA bits

	IFC	"\1","ALL"
        move.w	#$7FFF,$dff09c
	ELSE
	move.w	#\1,$dff09c
	ENDIF	

		ENDM
;---------------------------------------------------------------
ClrDMA:		MACRO		;ALL or DMA bits

	IFC	"\1","ALL"

        move.w	#$3FFF,$dff096

	ELSE

	move.w	#\1,$dff096

	ENDIF	

		ENDM
;---------------------------------------------------------------
SetCop:		MACRO		;CopperList

	move.l	#\1,$dff080
	clr.w	$dff088

		ENDM

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

SetCop2:	MACRO		;CopperList

	move.l	#\1,$dff084
	clr.w	$dff08a

		ENDM


;----------------------------------------------------------
	
_ReadFile:	MACRO
	move.l	DosBase,a6

	move.l	#1005,d2
	CALL	Open(a6)

	move.l	d0,d1
 	move.l	(sp)+,d2
	move.l	(sp)+,d3

	move.l	d0,-(sp)
	CALL	Read(a6)

	move.l	(sp)+,d1
	CALL	Close(A6)

		ENDM

ReadFile:	MACRO		;Filename,Buffer,Size

	movem.l	d0-a6,-(sp)

	tst.l	DosBase
	bne.b	.Old

	OpenLib		DosName,DosBase

	movem.l	(sp),d0-a6

	move.l	\3,-(sp)
	move.l	\2,-(sp)
	move.l	\1,d1
	_ReadFile

	CloseLib	DosBase
	bra.b	.New
.Old:
	move.l	\3,-(sp)
	move.l	\2,-(sp)
	move.l	\1,d1
	_ReadFile

.New:
	movem.l	(sp)+,d0-a6

		ENDM

;----------------------------------------------------------
	
WriteFile:	MACRO		;Filename,Buffer,Size

	movem.l	d0-a6,-(sp)

	move.l	DosBase,a6

	move.l	#\1,d1
	move.l	#1006,d2
	CALL	Open(a6)
	move.l	d0,-(sp)
	move.l	d0,d1
	move.l	#\2,d2
	move.l	#\3,d3
	CALL	Write(a6)
	move.l	(sp)+,d1
	CALL	Close(A6)

	movem.l	(sp)+,d0-a6

		ENDM

;---------------------------------------------------------------
AllocMem:	MACRO		;Memtype,Size
	
	movem.l	d1/a0-a1/a6,-(sp)
	move.l	\2,d0
	move.l	#MEMF_\1,d1
	move.l	4.w,a6
	CALL	AllocMem(a6)
	movem.l	(sp)+,d1/a0-a1/a6
	tst.l	d0

		ENDM
	
;---------------------------------------------------------------

SaveSystem:	MACRO

	jsr	_SaveSystem

		ENDM


RestoreSystem:	MACRO

	jsr	_RestoreSystem

		ENDM

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

WaitMouse:	MACRO

	IFEQ    (NARG-2)!((~\1)&$2000)
	btst	#6,$bfe001
	bne	\2
	ENDIF

	IFEQ    (NARG-2)!((~\1)&$4000)
	btst	#10,$dff016
	bne	\2
	ENDIF
	
	IFEQ    (NARG-1)!((~\1)&$2000)
.w\@:	btst	#6,$bfe001
	bne	.w\@
	ENDIF

	IFEQ    (NARG-1)!((~\1)&$4000)
.w\@:	btst	#10,$dff016
	bne	.w\@
	ENDIF

		ENDM

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

