*-------------------------------------------------------------------------*		
*									  *
*	- FASTMENU -				- CYBERNETICS 1992 -	  *
*									  *
*	Autogenerated Blitter tested Plasma				  *
*									  *
*-------------------------------------------------------------------------*		

		output	e:\code\effects.grx\relaps_f\fast.prg

nbligne:	equ	198
nbcouleur:	equ	200
 
		clr.l	-(sp)			* Superviseur
		move.w	#$20,-(sp)
		trap	#1
		addq.w	#6,sp
	
		move.w	#2,-(sp)		* Physbase
		trap	#14
		addq.w	#2,sp
		move.l	d0,physb
		
		move.b	#2,$ffff820a.w		* Synchro

*----------------------- NO SYSTEM AFTER THIS

		***** RESET SHIFTER *****
	
 		lea	img(pc),a0		* Decompactage
		move.l	physb(pc),a1
		lea	0.w,a2
		move.w	#199,d0
 		bsr	decomp			

		move.w	#$2700,sr		* Detourne les inters
		move.b	$fffffa07.w,oldiera	* MFP
		move.b	$fffffa09.w,oldierb
		clr.l	$fffffa06.w
		move.l	$70.w,oldvbl		* VBL
		move.l	#vbl,$70.w		
		move.w	#$2300,sr

blittertest:
	lea		$ffff8a00.w,a5		* Adresse blitter
	move.w		#2,$8a20-$8a00(a5)	* Inc X source
	clr.l		$8a2e-$8a00(a5)		* Inc X Dest & Y dest
	move.w		#$203,$8a3a-$8a00(a5)	* Mode demi teinte
	clr.b		$8a3d-$8a00(a5)		* No decalage
	move.w		#55,$8a36-$8a00(a5)	* Hori size
	move.l		#$ffff8240,$8a32-$8a00(a5) * Adr dest
 	lea		plasmacode(pc),a0	 * Table plasma (decalages)
	move.l		a0,$8a24-$8a00(a5)	 * Adr source
	moveq.l		#1,d6			 * Precharge registres
	moveq.l		#4,d2			 *
	moveq.l		#0,d3			 *
	move.b		#%11000000,d5		 *
	lea		$ffff8a22.w,a5		 * Adresse Inc Y Dest blitter
	lea		$ffff8a38.w,a6		 * Adresse Vert size blitter	
	lea		$ffff8a3c.w,a4		 * Adresse Run blitter

	move.w		#-1,vsync	* Synchro vbl 
temp4:	tst.w		vsync
	bne.s		temp4
	clr.b		$ffff8209.w	* Offset base a zero
	moveq.l		#16,d1

sync1:	move.b		$ffff8209.w,d0	* Synchro lsl
	beq.s		sync1
	sub.w		d0,d1
	lsl.w		d1,d0

	moveq.l		#7,d1		* Precharge registres
	lea		$ffff8209.w,a2
	move.b	(a2),d7			* BLITTER TEST
plasma_:	
	move.l	(a0)+,d0		* Charge le decalage
	lsl.w	d2,d0			* Decalage 0/4
	swap	d0			*
	move.w	d3,(a5)			* Inc Y source: deca >=8
	move.w	d6,(a6)			* Vert size
	move.b	d5,(a4)			* No partage & Go
	dbra.w	d1,plasma_		*
	sub.b	(a2),d7			* Delta sur compteur video
	ext.w	d7			* Resultat test
	
					* Autogeneration
	lea		plasmacode(pc),a1
	move.w		#nbligne-1,d0
	add.w		#48,d7
	asr.w		#4,d7
	subq.w		#1,d7
autogen:
	lea		tramecode(pc),a0
	rept	3
	move.l		(a0)+,(a1)+
	endr
	move.w		d7,d2
g_nop:	move.w		#$4e71,(a1)+		* Generation de nop variante
	dbra.w		d2,g_nop		* pour compenser les retards 
	dbra.w		d0,autogen		* selon les modeles de
	move.w		#$4e75,(a1)+		* Blitter

	move.l	#$4440666,$ffff8244.w		* Couleurs fixe
		
 	move.w	#-2,depha1		* Inits curves
	move.w	#-2,offd1
	move.w	#6,depha2
	move.w	#-10,offd2
	move.l	#couleur+20*2*2*2,ligne
	move.w	#$0,debut1
	move.w	#50,debut2	
	bsr	calcul

	move.w	#2,$ffff8a20.w		* Inc x
	move.w	#2,$ffff8a22.w		* Inc y
	move.l	#$ffffffff,$ffff8a28.w	* masques
	move.w	#$ffff,$ffff8a2c.w	* masque
	move.w	#2,$ffff8a2e.w		* Inc x dst
	move.w	#-2,$ffff8a30.w		
	move.w	#$203,$ffff8a3a.w
	clr.b	$ffff8a3d.w
		
	move.l	#$2001b,d2		* nb couleur
	move.w	#$c0,d3			* bit set 
	move.l	#$ff8240,d4		* add source
	lea	$ffff8a32.w,a2		* Precharge registres
	lea	$ffff8a24.w,a4
	lea	$ffff8a36.w,a5
	lea	$ffff8a3c.w,a6
	lea	$ffff8209.w,a3
		
main:		move.w	#-1,vsync		* Attend la vsync
temp:		tst.w	vsync
		bne.s	temp
		
		move.b	tch(pc),d0
		ext.w	d0
		cmp.w	#$3b,d0			* Test touches
		blt.s	nofunc
		cmp.w	#$44,d0
		bgt.s	nofunc			
		sub.w	#$3b-1,d0		* Si c'est une touche de 
		move.w	d0,$208.w		* fonction 
		move.w	d0,$210.w		* Numero de module dans
		cmp.w	#5,d0			* le machin 210 sauf pour
		bne	fin			* le flex de merde
		clr.w	$216.w
		bra	fin
nofunc:		cmp.w	#$67,d0			* Si c'est un nombre
		blt.s	nonummer
		cmp.w	#$70,d0
		bgt.s	nonummer
		neg.w	d0
		add.w	#$70,d0
		move.w	d0,$210.w
		move.w	#9,$208.w
		bra	fin
nonummer:		
		cmp.w	#$0f,d0			* Si tab: mode defilement
		bne.s	notab
		clr.w	$216.w
		clr.w	$208.w
		clr.w	$206.w
		clr.w	$210.w
		illegal
notab:

		move.w	#nbligne-1,d0
		lea	plasma(pc),a0

sync:		move.b	(a3),d1			* Synchro lsl
		beq.s	sync
		neg.w	d1
		add.w	#16,d1
		lsl.w	d1,d1

		moveq.l	#22,d1			* Nop de callage ecran
attente:	dbra.w	d1,attente

		bsr	plasmacode		* Plasma
		clr.w	$ffff8240.w		* Couleur zero
	
		bsr	calcul			* Calcul courbe plasma
		
		bra	main

*------------------------- REINITS
fin:		lea	$ffff8240.w,a0
		moveq.l	#7,d0
effpal:		clr.l	(a0)+
		dbra.w	d0,effpal
		
		MOVEQ.l	#5,D6
reset_shift		MOVE.B	#1,$ffff8260.W
		STOP	#$2300
		CLR.B	$ffff8260.W		* BASSE RESOLUTION
		STOP	#$2300
		DBF	D6,reset_shift
		STOP	#$2300
		clr.b	$ffff8260.w		* Moyenne resolution

		move.w	#$2700,sr		* Reinit des inters
		move.l	oldvbl(pc),$70.w
		move.b	oldiera(pc),$fffffa07.w
		move.b	oldierb(pc),$fffffa09.w
		move.w	#$2300,sr
		
 		clr.l	-(sp)			* Pterm
		trap	#1

*-------------------------------------------------------------------------*
*	ROUTINE VBL							  *
*-------------------------------------------------------------------------*
vbl:	clr.w	vsync
	move.b	$fffffc02.w,tch
	rte
*-------------------------------------------------------------------------*
*	CALCUL COURBE PLASMA						  *
*-------------------------------------------------------------------------*

calcul:		movem.l	d0-a6,-(sp)

		move.l	#plasma,a0		* tableau de destination
		move.l	#tableau,a1		* tableau de sinus*512
		move.l	ligne(pc),a2		* ligne de depart
		move.w	debut1(pc),d1		* angle de depart du 1er sinus 
		move.w	debut2(pc),d2		* angle de depart du 2em sinus
		move.w	depha1(pc),a3		* dephasage du premier sinus
		move.w	depha2(pc),a4
		move.w	#1023,d0
		moveq.l	#0,d5			* compensation precedente
		moveq.l	#1,d7			* compensation precedente

plasmouge:	macro
		move.w	(a1,d1.w),d3		* premier dephasage
		add.w	(a1,d2.w),d3		* 2em dephasage				
		
		move.w	d3,d4
		and.w	d7,d4			* decalage?
		sub.w	d4,d3			* offset couleur
		add.w	d3,d3			* mod 4
		add.w	d4,d4			* decalage*2
		
		sub.w	d4,d5
		addq.w	#2,d5
		move.w	d5,(a0)+		* offset decalage
		
		lea	(a2,d3.w),a5
		move.l	a5,(a0)+		* couleur depart sans dephasage
	
		add.w	a3,d1			* offset de dephasage 1
		and.w	d0,d1
		add.w	a4,d2			* offset de dephasage 2
		and.w	d0,d2


		move.w	(a1,d1.w),d3		* premier dephasage
		add.w	(a1,d2.w),d3		* 2em dephasage				
		
		move.w	d3,d5
		and.w	d7,d5			* decalage?
		sub.w	d5,d3			* offset couleur
		add.w	d3,d3
		add.w	d5,d5			* decalage*2
		
		sub.w	d5,d4
		addq.w	#2,d4
		move.w	d4,(a0)+		* offset decalage
		
*-------------------*
*tester en faisant d0+d3*
*--------------------*	
		lea	(a2,d3.w),a5
		move.l	a5,(a0)+		* couleur depart sans dephasage
	
		add.w	a3,d1			* offset de dephasage 1
		and.w	d0,d1
		add.w	a4,d2			* offset de dephasage 2
		and.w	d0,d2
		endm		
					
		move.w	#nbligne/2-1,d6
boucle:		plasmouge
		dbra.w	d6,boucle
		
		move.w	offd1(pc),d6
		add.w	d6,debut1
		and.w	d0,debut1
	
		move.w	offd2(pc),d6
		add.w	d6,debut2		
		and.w	d0,debut2
		
		movem.l	(sp)+,d0-a6 
	
		rts

*-------------------------------------------------------------------------*
*	DECOMPACTAGE IMAGE						  *
*-------------------------------------------------------------------------*
decomp:					
	movem.l	a0-a3/d0-d4,-(sp)	

	move.w	(a0)+,d4		*a0: image compactee
	lea	32(a0),a0		*a1: ecran dest
	cmp.l	#0,a2			*a2: pal 
	beq.s	endifdec2		*d0: hauteur-1
	lea	-32(a0),a0
	rept	8
	move.l	(a0)+,(a2)+
	endr
endifdec2:
	move.l	a0,a2			
	lsl.w	#2,d4			
	add.w	d4,a2	
	moveq.l	#39,d4
	moveq.l	#0,d2
	moveq.l	#0,d3
	move.l	a1,a3
dec:	move.l	a3,a1
	addq.w	#4,a3
	move.w	d0,d1			
dec2:	tst.w	d2
	bne.s	endifdec
	move.b	(a2)+,d2
	move.l	(a0)+,d3
endifdec:
	move.l	d3,(a1)
	lea	160(a1),a1
	subq.w	#1,d2
	dbra.w	d1,dec2
	dbra.w	d4,dec
	
	movem.l	(sp)+,a0-a3/d0-d4
	rts

tramecode:
	move.w	(a0)+,d1
	lsl.w	d1,d1
	move.l	(a0)+,(a4)
	move.l	d4,(a2)
	move.l	d2,(a5)
	move.b	d3,(a6)

*-------------------------------------------------------------------------*
		Section 	data

oldiera:	dc.w	0
oldierb: 	dc.w	0
oldvbl:	 	dc.l	0
*-------------------------------------------------------------------------*
ligne:		ds.l	1
debut1:		ds.w	2
debut2:		ds.w	2
depha1:		ds.w	2
depha2:		ds.w	2
offligne:	ds.l	3
offd1:		ds.w	2
offd2:		ds.w	2
tch:		dc.w	0
physb:		dc.l	0
vsync:	 	dc.w	0
couleur:	rept	15
		dc.w	$abc,$503,$345,$402,$3c5,$503,$b5d,$604
		dc.w	$b5d,$503,$3c5,$402,$345,$503,$abc,$604
		endr
tableau:	incbin		plasinus.kra
img:		incbin		select.dat

		Section		bss

plasma:		ds.w		(nbligne+1)*3+3
plasmacode:	ds.b		200*(12+4*2)
	        