; TABSTOP : 8
**	Assemble with Macro68

		exeobj			;generate an executable
		objfile	"cfx"		;name of output executable
		relax			;converts non specific opcodes
		addsym			;allways want symbols hunk
		mc68000			;only got this (DRAT!)
		copper			;support copper instructions
		odderror		;of course this is an error

*--------------------------------------------------------------------------
* Horizontal Copper List Effects. "cfx"
*
* by Robin Luiten
*    10 Chartwell St
*    Aspley 4034
*    Brisbane QLD Australia
*
* Yes I know its rough but it is some what of a quick hack.
* This code is public domain so up and go for it if you want to.
*
* Note that all the 'work' is actually done inside the vertical blank
* interrupt.
*
* Second file required to make this assemble is 'sintable.i' it contains
* the data for a modified sin wave.
*
* Heavy use of macros is made to cut down on the size of the source code.
* It would have been tidier to write code to generate the copper list
* but I wanted to test Macro68's copper list instructions and I didn't
* feel like writing the code.
*
*--------------------------------------------------------------------------
tv_Lev3IntVect		equ	$6c
intena			equ	$09A
dmacon			equ	$096
cop1lc			equ	$080
copjmp1			equ	$088
bplcon0			equ	$100
color			equ	$180

gb_copinit		equ	$26

MEMF_CHIP		equ	2
_LVOAllocMem		equ	-$C6
_LVOFreeMem		equ	-$D2
_LVOOldOpenLibrary	equ	-$198
_LVOCloseLibrary	equ	-$19E

custom		equ	$dff000


CL_LINES	equ	160

;-- Size Cols8 is 32 bytes
Cols8	macro
		cmove	#\1,(color)
		cmove	#\2,(color)
		cmove	#\3,(color)
		cmove	#\4,(color)
		cmove	#\5,(color)
		cmove	#\6,(color)
		cmove	#\7,(color)
		cmove	#\8,(color)
	endm
Cols8_SIZEOF	equ	32

;-- Size COLS is 128 bytes
COLS	macro
		Cols8	$0,$1,$2,$3,$4,$5,$6,$7
		Cols8	$8,$9,$a,$b,$c,$d,$e,$f
		Cols8	$f,$e,$d,$c,$b,$a,$9,$8
		Cols8	$7,$6,$5,$4,$3,$2,$1,$0
	endm
COLS_SIZEOF	equ	Cols8_SIZEOF*4

;---- First wait location for trendy bit.
FIRST_VERT	set	52
FIRST_HORI	set	11

;-- Size RedCol is 132 ( which is also size of Step)
RedCol	macro
		cwait	FIRST_VERT:FIRST_HORI
		COLS
FIRST_VERT	set	FIRST_VERT+1
*FIRST_HORI	set	FIRST_HORI+1
	endm

CLINE_SIZE	equ	COLS_SIZEOF+4

;--------------------------------------------------------------------------
Lead	macro
		cwait	FIRST_VERT:FIRST_HORI
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
		Cols8	$0,$0,$0,$0,$0,$1,$2,$3
		Cols8	$3,$2,$1,$0,$0,$0,$0,$0
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{}
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
		Cols8	$0,$0,$0,$1,$2,$3,$4,$5
		Cols8	$5,$4,$3,$2,$1,$0,$0,$0
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{}1
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
		Cols8	$0,$1,$2,$3,$4,$5,$6,$7
		Cols8	$7,$6,$5,$4,$3,$2,$1,$0
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}
		Cols8	$0,$0,$0,$0,$0,$0,$0,$1
		Cols8	$2,$3,$4,$5,$6,$7,$8,$9
		Cols8	$9,$8,$7,$6,$5,$4,$3,$2
		Cols8	$1,$0,$0,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$0,$0,$1,$2,$3
		Cols8	$4,$5,$6,$7,$8,$9,$a,$b
		Cols8	$b,$a,$9,$8,$7,$6,$5,$4
		Cols8	$3,$2,$1,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$0,$1,$2,$3,$4
		Cols8	$5,$6,$7,$8,$9,$a,$b,$c
		Cols8	$c,$b,$a,$9,$8,$7,$6,$5
		Cols8	$4,$3,$2,$1,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$1,$2,$3,$4,$5
		Cols8	$6,$7,$8,$9,$a,$b,$c,$d
		Cols8	$d,$c,$b,$a,$9,$8,$7,$6
		Cols8	$5,$4,$3,$2,$1,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$1,$2,$3,$4,$5
		Cols8	$6,$7,$8,$9,$a,$b,$c,$d
		Cols8	$d,$c,$b,$a,$9,$8,$7,$6
		Cols8	$5,$4,$3,$2,$1,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$1,$2,$3,$4,$5,$6
		Cols8	$7,$8,$9,$a,$b,$c,$d,$e
		Cols8	$e,$d,$c,$b,$a,$9,$8,$7
		Cols8	$6,$5,$4,$3,$2,$1,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$1,$2,$3,$4,$5,$6
		Cols8	$7,$8,$9,$a,$b,$c,$d,$e
		Cols8	$e,$d,$c,$b,$a,$9,$8,$7
		Cols8	$6,$5,$4,$3,$2,$1,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1
	endm

;--------------------------------------------------------------------------
Trail	macro
		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$1,$2,$3,$4,$5,$6
		Cols8	$7,$8,$9,$a,$b,$c,$d,$e
		Cols8	$e,$d,$c,$b,$a,$9,$8,$7
		Cols8	$6,$5,$4,$3,$2,$1,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$1,$2,$3,$4,$5,$6
		Cols8	$7,$8,$9,$a,$b,$c,$d,$e
		Cols8	$e,$d,$c,$b,$a,$9,$8,$7
		Cols8	$6,$5,$4,$3,$2,$1,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$1,$2,$3,$4,$5
		Cols8	$6,$7,$8,$9,$a,$b,$c,$d
		Cols8	$d,$c,$b,$a,$9,$8,$7,$6
		Cols8	$5,$4,$3,$2,$1,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$1,$2,$3,$4,$5
		Cols8	$6,$7,$8,$9,$a,$b,$c,$d
		Cols8	$d,$c,$b,$a,$9,$8,$7,$6
		Cols8	$5,$4,$3,$2,$1,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$0,$1,$2,$3,$4
		Cols8	$5,$6,$7,$8,$9,$a,$b,$c
		Cols8	$c,$b,$a,$9,$8,$7,$6,$5
		Cols8	$4,$3,$2,$1,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$0,$0,$1,$2,$3
		Cols8	$4,$5,$6,$7,$8,$9,$a,$b
		Cols8	$b,$a,$9,$8,$7,$6,$5,$4
		Cols8	$3,$2,$1,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$0,$0,$0,$0,$1
		Cols8	$2,$3,$4,$5,$6,$7,$8,$9
		Cols8	$9,$8,$7,$6,$5,$4,$3,$2
		Cols8	$1,$0,$0,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
		Cols8	$0,$1,$2,$3,$4,$5,$6,$7
		Cols8	$7,$6,$5,$4,$3,$2,$1,$0
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
		Cols8	$0,$0,$0,$1,$2,$3,$4,$5
		Cols8	$5,$4,$3,$2,$1,$0,$0,$0
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1

		cwait	FIRST_VERT:FIRST_HORI{$7f:$7f}1
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
		Cols8	$0,$0,$0,$0,$0,$1,$2,$3
		Cols8	$3,$2,$1,$0,$0,$0,$0,$0
		Cols8	$0,$0,$0,$0,$0,$0,$0,$0
FIRST_VERT	set	FIRST_VERT+1
FIRST_HORI	set	FIRST_HORI+1
	endm

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

RedCol10	macro
		RedCol
		RedCol
		RedCol
		RedCol
		RedCol
		RedCol
		RedCol
		RedCol
		RedCol
		RedCol
	endm

;--------------------------------------------------------------------------
		SECTION XX,CODE,CHIP
;--------------------------------------------------------------------------
START		move.l	(4).w,a6
		lea	(custom).l,a5		;custom base
		lea	(StartCopper).l,a3	;get addr of copper list.
		lea	(GFX_name,pc),a1
		jsr	(_LVOOldOpenLibrary,a6)
		move.l	d0,(GFX_Base).l	;gfx base
		beq.b	end

		move.w	#$0080,(dmacon,a5)
		move.l	a3,(cop1lc,a5)		;install new copper list
		move	d0,(copjmp1,a5)		;use new copper list
		move.w	#$8080,(dmacon,a5)

;-------- set up vBlank routine (for gfx FX)
		move.w	#$4000,(intena,a5)	; disable interrupts
		move.l	(tv_Lev3IntVect).l,(OLDInt3).l
		move.l	#MyInt3,(tv_Lev3IntVect).l
		move.w	#$C000,(intena,a5)	; enable interrupts

Wait_Mouse	btst	#6,($bfe001).l		;test left mouse button
		bne	Wait_Mouse

		move.w	#$4000,(intena,a5)	; disable interrupts
		move.l	(OLDInt3).l,(tv_Lev3IntVect).l
		move.w	#$C000,(intena,a5)	; enable interrupts

		move.l	(GFX_Base,pc),a6	;get initial copper list
		move.w	#$0080,(dmacon,a5)
		move.l	(gb_copinit,a6),(cop1lc,a5)	;restore
		move	d0,(copjmp1,a5)			;use
		move.w	#$8080,(dmacon,a5)

		move.l	(4).w,a6
fail_mem1	move.l	(GFX_Base,pc),a1	;get lib base to be closed
		jsr	(_LVOCloseLibrary,a6)

end
		moveq	#0,d0
		rts


;-------------------------------
; Interrupt 3 (vBlank) routine |
;--------------------------------------------------------------------------
MyInt3:		movem.l	d0-d7/a0-a6,-(sp)

		btst	#10-8,($dff016).l	;right mouse button
		beq.b	Int3END			;nice to be able to pause

		lea	(MuvStart,pc),a0
		lea	(sin,pc),a1
		move.w	(sinpos,pc),d0
		move.w	#CL_LINES-1,d1
		addq.w	#1,(sinpos)		;to next position
		cmp.w	#359,(sinpos)
		bls.b	continue		;sinpos <= 89

		move.w	#0,(sinpos)

continue:	move.b	(a1,d0.w),(1,a0)	;get sin value
		lea	(CLINE_SIZE,a0),a0
		addq.w	#1,d0
		cmp.w	#359,d0
		bls.b	dontreset		;sintable pos <= 89

		moveq	#0,d0			;modulus table length
dontreset:	dbra	d1,continue

Int3END:	movem.l	(sp)+,d0-d7/a0-a6
		dc.w	$4EF9			; JMP OPcode
OLDInt3:	dc.l	0		; do normal Level 3 interrupt

;--------------------
; START of the DATA |
;--------------------------------------------------------------------------
GFX_Base:	dc.l	0
GFX_name:	dc.b	'graphics.library',0
		cnop	0,2

sinpos:		dw	0
sin:		include	"sintable.i"

;--------------------------------------------------------------------------
; Finally here is the Copper List.
; Little visible here BUT look out for size of the macros.
;--------------------------------------------------------------------------
StartCopper:
		cmove	#0,(bplcon0)
		cmove	#0,(color)

MuvStart	Lead
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		RedCol10
		Trail
MuvEnd
		cmove	#0,(color)
		cend

		END
