* _________________________________________________________________ / / /_
*                                                                  / / /
* http://cyberpingui.free.fr/sources.htm                    ____  / / /
* Intro source                                              \   \/ / /
* ________________________________________ powered by AMIGA _\ \ \/ /_____
*                                                             \_\_\/
* fullcontact full intro
* waitrasters/cpu delay/vbl fixed (24.02.2017)
* 
* - boot audio (interrupt audio)
* - music
* - 1er part : credits (stars + 4 anims)
*  - stars forward
*  - anim credits
*  - fade out credits (original routine)
*  - start backward
* - 2eme part: team7 roll 
* - team7 down
* - 3eme part: title pic "laser"
* - Main part: pic + anim iff move up
* - 5eme part : end credits
* + first intro version (bonus)
* 
* ToDO :
* + RNC packed data (original)
* ou Depacker Custom avec Boot Audio 
* Cranker possible avec image, mais pas d'audio (v0.65)
* 
* code by VrS!

;ASMONE

* ------------------------------------- 
PT		; mod version
AUDIOINT	; audio mode manuel (interruption) sinon mode auto DMA

;RNC		; ProPack data RNC version (2 buf: anim + pic)
;RNC1		; ProPack data RNC1.0 method 1 : size- (stack $1dc)
;RNC2		; ProPack data RNC2.0 method 2 : speed+ (stack $1c)

	IFND	ASMONE
	opt	c-
	ENDC

	IFD	ASMONE
	incdir	"dh0:flc/"
	ENDC
	
* -------------------------------------


	section fullcontact,code

	rsreset
* ------- iff-ilbm-anhd player - modified version 1 bitplan
AnimWidth	rs.l	1	;0
AnimHeight	rs.l	1	;4
AnimScreenBuf1	rs.l	1	;8  Screen buffer 1
AnimScreenBuf2	rs.l	1	;12 Screen buffer 2
AnimDataPtr	rs.l	1	;16 IFF-Anim data ptr
FrameWidth	rs.w	1	;20 Anim frame width
FrameHeight	rs.w	1	;22 Anim frame height
FrameDepth	rs.w	1	;24
BufCurFlag	rs.w	1	;25
AnimFramePtr	rs.l	1	;26 Anim current frame gfx ptr
AnimFrameList	rs.l	1	;30
* ------- fader
ColList		rs.l	1	; copperlist pointer
Liste		rs.l	1	; palette colors pointer
nbrcol		rs.w	1	; nb colors
;
count		rs.w	1	; counter fade
upflag		rs.w	1	; fader start/end flag
dly		rs.w	1	; delay/speed
vdly		rs.w	1
* -------
VARSIZE2	rs.w	0
;--------------------------------------- constant
WRASTER=255	; waitraster
;----------------------- screen(s)
SCWIDTH=320/8	; 40
SCHEIGHT=256
SZPLAN=SCWIDTH*SCHEIGHT

	bra.s	Start

	dc.b	"Full Contact Intro / Team 17 - 1990-91"
	CNOP	0,4

	include	"mystartup.i"

I_SET=I_setclr!I_inten!I_Vbl
D_CON=D_setclr!D_init!D_copp!D_Btpl!D_Blit

* --------------------------------------------------------
* ---------------------------------------------- MAIN PROG
* --------------------------------------------------------
MAIN	bsr	InitAll

; boot "team7 presents full contact"
	bsr	Boot
; start zic
;---------------------------------- first version
;	btst	#10,$dff016
;	beq.s	.skipfirst
;	bsr	DoFIRST
.skipfirst
	bsr	InitMusic

	lea	$dff000,a6
	lea	Vars(pc),a5

	lea	newVBL(pc),a0
	lea	VBLpt(pc),a1
	move.l	a0,(a1)
;---------------------------------- fade in + Stars ON
;---------------------------------- Anim Credits x4
	bsr	DoCREDITS
;---------------------------------- Stars OFF + fade out
;---------------------------------- Team7 rolling down + close window
	bsr	DoTEAM7ROLL		; wait depack anim
	bsr	DoTEAM7DOWN
;---------------------------------- Main Pic Double Laser Up-Down
	bsr	DoLASER
;---------------------------------- Final Main Pic + anim iff up
	bsr	DoANIM

MainVBL:
	btst	#6,$bfe001
	bne.s	MainVBL

;---------------------------------- fade to black
; dark fader
	lea	$dff000,a6
	lea	Vars(pc),a5

	bsr	waitraster

	move.w 	#32-1,nbrcol(a5)
	move.l 	#black,Liste(a5)
	move.l	#CLpalLASER+2,ColList(a5)	; move.l 	#CLpal+2,ColList(a5)

	clr.w	count(a5)	;
	clr.w	upflag(a5)	; reinit fader
;
.wtfad	tst.b	upflag(a5)
	beq.s	.wtfad

;----------------------------------- end credits
	bsr	DoEND
;-----------------------------------
Exit	bsr	StopMusic

NoMem	rts
* --------------------------------------------
* INTERRUPTIONS
* --------------------------------------------
newVBL:		
	lea	Vars(pc),a5
	lea	$dff000,a6

	not.w	SwitchAnimFlagVbl
	beq.s	.noanim
	move.w	#-1,AnimFlagVbl
.noanim
; fader ?
	tst.b	upflag(a5)
	bne.s	.skipfader
	bsr	FaderMulti	; my own fader
.skipfader
	move.w	flagStars(pc),d0
	beq.s	.noRout
	bsr	DoStars
.noRout
	bsr	PlayMusic

	rts

flagStars dc.w	0
* ------------------------------------------------
* - Init copper, screens, sprites, datas...
* ------------------------------------------------
InitAll:
	lea	Vars(pc),a5
	lea	$dff000,a6

	move.w	#$c00,$106(a6)	; AGA fix
	move.w	#0,$1fc(a6)
	move.w	#$11,$10c(a6)

;--	fader variables
	move.w	#2,vdly(a5)
	move.w	#2,dly(a5)
	move.w	#-1,upflag(a5)
	rts
* ---------------------------------------------------------
* AUDIO DMA AUTOMATIQUE (original - not used here)
* ---------------------------------------------------------
Boot:
	lea	$dff000,a6

	bset    #1,$BFE001		; Filter PassBass - Power Led OFF

	lea	CopperListBoot,a0
	move.l	a0,$80(a6)
	move.w	#0,$88(a6)	
; pic
	move.l	#bootpic,d0	; 2 plans 40*48
	lea	CLbpl,a0
	moveq	#2-1,d1
	move.l	#40*48,d2
	bsr	Inst_plans

	move.l	#empty,d0	; sprites off
	lea	CLspr,a0
	moveq	#8-1,d1
	move.l	#0,d2
	bsr	Inst_plans
; audio
	ifnd	AUDIOINT
	 bra	AudioAuto	; original version - useless : can't wait the end of the sample
	endc

	ifd	AUDIOINT
	 bra	AudioMan	; new version : wait until the end of the sample
	endc
	rts
;------------- automatique DMA (old)
	ifnd	AUDIOINT
AudioAuto:
; sound	channel 0
	move.l	#bootsnd,$A0(a6)	; address sound
	move.w	#61000/2,$A4(a6)	; len in word $7724=30500.w=61000 .b (ee48)
	move.w	#428,$A6(a6)		; period
	move.w	#64,$A8(a6)		; volume
 ; sound channel 1
	move.l	#bootsnd,$B0(a6)	;
	move.w	#61000/2,$B4(a6)
	move.w	#428,$B6(a6)
	move.w	#64,$B8(a6)
 
	move.w	#$8003,$96(a6)		; start dma audio on

	move.l	#512,d0
waitsound
	subq.l	#1,d0
	bne.s	waitsound

	move.l	#blanksnd,$A0(a6)
	move.l	#blanksnd,$B0(a6)
	move.w	#2,$A4(a6)
	move.w	#2,$B4(a6)

	move.w	#$3,$96(a6)		; start dma audio off

	rts
	endc

* ==========================================================
* =         AUDIO MANUEL SANS DMA - INTERRUPTION AUDIO (new)
* ==========================================================
; après avoir initialisé les registres correspondant à un canal
; on autorise les transferts DMA à travers ce canal.
; Paula transfert l'adresse et la longueur du son dans ses registres
; ensuite elle genere une interruption de niveau 4 pour avertir le 68000
; qu'elle a fini.le processeur peut changer le contenu des registres
; d'adresse et de longueur.
; pendant ce temps agnus charge 1 mot de donnée toutes les 2 periodes
; dans le registre AUD DAT= $dff0A
; LEFT : 0-3
; RIGHt: 1-2
	ifd	AUDIOINT
AudioMan:
	lea	$dff000,a6

	move.w	#$c180,$9a(a6)		; start interrupt audio

; sound	channel 0
	move.l	#bootsnd,$A0(a6)	; address sound AUD0PTH (left)
	move.w	#500/2,$A4(a6)		; len in word (61000/500=122x)
	move.w	#428,$A6(a6)		; period
	move.w	#64,$A8(a6)		; volume
; sound channel 1
	move.l	#bootsnd,$B0(a6)	; AUD1PTH (right)
	move.w	#500/2,$B4(a6)
	move.w	#428,$B6(a6)
	move.w	#64,$B8(a6)

;	move.w	#$8003,$96(a6)		; start dma audio on
;
	moveq	#0,d7
.loop	tst.w	flagint
	bne.s	.loop
	
	add.l	#500,ptSound
	move.w	#2,flagint

	tst.w	flagbeg
	bne.s	.cont
	move.w	#$8203,$96(a6)		; start dma audio on
	move.w	#1,flagbeg
.cont	addq	#1,d7
	cmpi.w	#121,d7			; 122*500.b = 61000 (sample len)
	bne.s	.loop
; restore
	bsr	waitraster

	lea	VarSys(pc),a5
	move.w	#$3,$96(a6)		; start dma audio off
	move.w	#$180,$9a(a6)		; stop interrupt audio
	movea.l	sVBR(a5),a1
	move.l	intaud(a5),$70(a1)	; restore int audio vector
	rts
;--------------
interruptaud:
	movem.l	a0-a6/d0-d7,-(sp)
	lea	$dff000,a6
; aud 0
	andi.w	#$80,$1e(a6)		; interrupt channel 0 ?
	beq.s	.aud1

	move.l	ptSound(pc),$a0(a6)
	move.w	#500/2,$a4(a6)

	subq.w	#1,flagint

	move.w	#$80,$9c(a6)		; interrupt aud 0 finished
	bra	.noint
; aud 1
.aud1
	andi.w	#$100,$1e(a6)		; interrut channel 1 ?
	beq.s	.noint

	move.l	ptSound(pc),$b0(a6)
	move.w	#500/2,$b4(a6)

	subq.w	#1,flagint

	move.w	#$100,$9c(a6)		; interrupt aud 1 finished
.noint	movem.l	(sp)+,a0-a6/d0-d7
	rte

flagint	dc.w	0
flagbeg	dc.w	0

ptSound	dc.l	bootsnd
	endc

* ----------------------------------------------------------
* ---------------------------------------------- Fade In/Out
* ----------------------------------------------------------
FaderMulti:
	lea	Vars(pc),a5
	subq.w	#1,dly(a5)	; speed
	bne.s	.return
	move.w	vdly(a5),dly(a5)
	bsr.s	.DoFade
.return	rts
.DoFade:
	move.l	ColList(a5),a0	; first copper palette
	move.l	Liste(a5),a1	; final palette 1
	move.w	nbrcol(a5),d7
.DoCol	moveq	#3-1,d6		; 3 composants R,G,B
	moveq	#$f,d3		; start with R
	move.w	#$1,d4		; speed (+/- 1)
.DoRGB	move.w	(a0),d0		; get current color from copperlist 1
	and.w	d3,d0		; extract ccurrent composant

	move.w	(a1),d1		; get dest final color 1
	and.w	d3,d1

	cmp.w	d0,d1		; compare color 1 / palette 1 if incr or decr composante
	bcs.s	.decr
	beq.s	.next
.incr	add.w	d4,(a0)		; incr comp color cop1
	bra.s	.next
.decr	sub.w	d4,(a0)		; decr comp color cop1

.next	asl.w	#4,d4		; shift composant -> R->G->B
	asl.w	#4,d3		;
	dbf	d6,.DoRGB

	addq.l	#4,a0		; next color copperlist 1
	addq.l	#2,a1		; next color palette 1
	dbf	d7,.DoCol

	addq.w	#1,count(a5)
	cmpi.w	#16,count(a5)	; end ? $F
	bne.s	.retour
	clr.w	count(a5)
	seq	upflag(a5)
.retour	rts

black	ds.w	32

;=========================================================== FadeOut original (intro credits)
FadeOUT:
;	bsr	waitraster
;	lea	Vars(pc),a5
;	move.w	#2,vdly(a5)
;	move.w 	#3-1,nbrcol(a5)
;	move.l 	#backcol,Liste(a5)
;	move.l	#CLpaletteDPF+4+2,ColList(a5)
;
;	clr.w	count(a5)
;	clr.w	upflag(a5)
;
;.wfad2	tst.w	upflag(a5)
;	beq.s	.wfad2
;	rts

	lea	CLpaletteDPF,a0
	move.l	#4,d0
	move.l	#4000,d1	; ! cpu delay !
;	
	lea	BufRGBBackColor(pc),a4
	move.l	#48,d2
cleartempbuf:
	clr.l	(a4)+
	subq.l	#1,d2
	bne.w	cleartempbuf
; 
	move.l	d0,d7		; nb colors
	movea.l	a0,a2		; copperlist pointer
	adda.l	#2,a2		; pointe sur la	couleur	$23,$333,$aaa,$eee
	clr.l	d6

	lea	BufRGBColors(pc),a3
GetRGBColors:
	move.w	(a2),d6		; copperlist current color
	andi.w	#$F00,d6	; R
	divu.w	#$F,d6
	ext.l	d6
	move.w	d6,(a3)+
	move.w	(a2),d6
	lsl.w	#4,d6
	andi.w	#$F00,d6
	divu.w	#$F,d6
	ext.l	d6
	move.w	d6,(a3)+	; G
	move.w	(a2),d6
	adda.l	#4,a2
	lsl.w	#8,d6
	andi.w	#$F00,d6
	divu.w	#$F,d6
	ext.l	d6
	move.w	d6,(a3)+	; B
	subq.w	#1,d7
	bne.s	GetRGBColors
; 
	lea	BufRGBBackColor(pc),a3
	movea.l	a0,a2		; copperlist
	adda.l	#2,a2
	move.l	d0,d4		; nb colors
GetRGBBufBackColor:
	move.w	(a2),d7
	andi.w	#$F00,d7
	move.w	d7,(a3)+
	move.w	(a2),d7
	andi.w	#$F0,d7
	addi.w	#$20,d7
	lsl.w	#4,d7
	move.w	d7,(a3)+
	move.w	(a2),d7
	andi.w	#$F,d7
	addi.w	#3,d7
	lsl.w	#8,d7
	move.w	d7,(a3)+
	adda.l	#4,a2
	subi.l	#1,d4
	bne.s	GetRGBBufBackColor
; 
	lea	BufRGBColors(pc),a2
	lea	BufRGBBackColor(pc),a3
	move.l	d1,d4
	suba.l	#2,a0
	movea.l	a0,a1
	move.l	d0,d1
	clr.l	d7
	bra.s	LoopColors
;---------------------------------
FadeLoop:
	move.l	d4,d5
.cpu	subq.l	#1,d5
	bne.s	.cpu

.wraster	
	move.l	$DFF004,d5
	asr.l	#8,d5
	andi.l	#$1FF,d5
	cmpi.l	#300,d5
	bne.s	.wraster
;
	clr.l	d7
	movea.l	a1,a0		; copperlist
	move.l	d0,d1		; nb colors
	lea	BufRGBColors(pc),a2
	lea	BufRGBBackColor(pc),a3
LoopColors:
	addq.l	#4,a0
	move.w	(a0),d2		; get copperlist R
	andi.w	#$F00,d2
	tst.w	d2
	beq.s	.G

	move.w	(a2),d3		; get current R	comp
	sub.w	d3,(a3)		; back R - current R
	move.w	(a3),d3
	andi.w	#$F00,d3
	andi.w	#-$F01,(a0)
	add.w	d3,(a0)
	addq.w	#1,d7

.G	adda.l	#2,a2
	adda.l	#2,a3
	move.w	(a0),d2
	andi.w	#$F0,d2
	cmpi.w	#$20,d2
	beq.s	.B

	move.w	(a2),d3
	sub.w	d3,(a3)
	move.w	(a3),d3
	andi.w	#$F00,d3
	lsr.w	#4,d3
	andi.w	#-$F1,(a0)
	add.w	d3,(a0)
	addq.w	#1,d7
.B
	adda.l	#2,a2
	adda.l	#2,a3
	move.w	(a0),d2
	andi.w	#$F,d2
	cmpi.w	#3,d2
	beq.s	.next

	move.w	(a2),d3
	sub.w	d3,(a3)
	move.w	(a3),d3
	andi.w	#$F00,d3
	lsr.l	#8,d3
	andi.w	#-$10,(a0)

	add.w	d3,(a0)
	addq.w	#1,d7
.next
	adda.l	#2,a2
	adda.l	#2,a3

	subq.w	#1,d1
	bne	LoopColors

	tst.l	d7
	bne	FadeLoop
	rts

BufRGBColors	ds.w 96
BufRGBBackColor ds.l 48

* ==========================================================
* =                             INTRO CREDITS - ANIM + STARS
* ==========================================================
DoCREDITS:
	bsr	InitSTARS		; create stars coords
;
	move.l	#BufferAnim1,d0
	lea	CLplanDPF_anim,a0
	moveq	#2-1,d1
	move.l	#SZPLAN,d2
	bsr	Inst_plans

	move.l	#empty,d0		; plan 6 not used : blank
	lea	CLplanDPF_bp6,a0
	moveq	#4-1,d1
	move.l	#0,d2
	bsr	Inst_plans
;	
	bsr	waitraster

	lea	CopperListDPF,a0
	move.l	a0,$dff080
	move.w	#0,$dff088

; start stars in vbi	
	move.w	#1,flagStars
; fade in
	bsr	waitraster
	lea	Vars(pc),a5
	move.w	#6,vdly(a5)
	move.w 	#4-1,nbrcol(a5)
	move.l 	#paletteCRED,Liste(a5)
	move.l	#CLpaletteDPF+2,ColList(a5)

	clr.w	count(a5)
	clr.w	upflag(a5)

.wfad	tst.w	upflag(a5)
	beq.s	.wfad
	
; depack anim cred1
; duration original A500 : 426 frames
	move.l	#400,d0
.pause1	bsr	waitraster
	subq.l	#1,d0
	bne.s	.pause1

; ------------------------------ stars pop up (explode)
StartStars:
;.vbl1	tst.w	AnimFlagVbl
;	beq.s	.vbl1
;	clr.w	AnimFlagVbl

	bsr	waitvbl
;	bsr	waitraster	; VBL lasts 40*384*2 cycles/pix = 30720 cycles (2.56 ms) - 1/50 = 0.02 s

; loop : 14 cycles * 400 = 5600 cycles * 1/7 mhz = 802 ns = 0.08 ms - 1/12 mhz = 468 ns
;	move.l	#400,d0
;.delay	subq.l	#1,d0		; #xxx .l clock periods - bus read/write (r/w) : 8(2/0) - Dn : 0(0/0) - Subq #,Dn : 4(1/0)
;	bne.s	.delay		; Bcc - branch taken : 10(2/0) - branch not taken : 8(1/0) .w 12(1/0)

	addi.w	#1,counterX	; explode
	addi.w	#1,counterY

	cmpi.w	#160,counterX
	bne.s	StartStars
;
; ----------------------------- do 4 anims
	lea	cred1,a2
	bsr	DoANIMCred

; load & depack anim cred2 : dur. 192 frm
	move.l	#192,d0
.pause2	;bsr	waitraster
	bsr	waitvbl
	subq.l	#1,d0
	bne.s	.pause2
;
	bsr	FadeOUT

	lea	cred2,a2
	bsr	DoANIMCred

; load & depack anim cred3 : dur. 476
	move.l	#400,d0
.pause3	;bsr	waitraster
	bsr	waitvbl
	subq.l	#1,d0
	bne.s	.pause3

	bsr	FadeOUT
;	
	lea	cred3,a2
	bsr	DoANIMCred

; load & depack anim cred4 : dur. 436
	move.l	#400,d0
.pause4	;bsr	waitraster
	bsr	waitvbl
	subq.l	#1,d0
	bne.s	.pause4

	bsr	FadeOUT
;	
	lea	cred4,a2
	bsr	DoANIMCred

; load & depack team7 pic : dur. 188
	move.l	#200,d0
.pause5	;bsr	waitraster
	bsr	waitvbl
	subq.l	#1,d0
	bne.s	.pause5

	bsr	FadeOUT
;
	lea	BufferAnim1,a0
	move.l	#40*256*2*2,d0
	lsr.l	#2,d0
.clear	move.l	#0,(a0)+
	subq.l	#1,d0
	bne.s	.clear
;--------------------------- stars implode
	move.l	#15,d0
StarsBack:
	addi.w	#1,incZ		; -> -5+15 = 10 - low speed
	bsr	BIGCPUWAIT
	cmpi.w	#10,incZ
	beq.s	.zou
	subq.w	#1,d0
	bne.s	StarsBack
.zou
	move.l	#160,d0
StarsBack2:
	subi.w	#1,counterX	; -> 160-160=0 implode
	subi.w	#1,counterY
	bsr	BIGCPUWAIT2
	tst.w	counterX
	beq.s	.zou
	subq.w	#1,d0
	bne.s	StarsBack2
.zou
; fade out
	bsr	waitraster
	lea	Vars(pc),a5
	move.w 	#4-1,nbrcol(a5)
	move.l 	#black,Liste(a5)
	move.l	#CLpaletteDPF+2,ColList(a5)

	clr.w	count(a5)
	clr.w	upflag(a5)

.wfad	tst.w	upflag(a5)
	beq.s	.wfad

	move.w	#0,flagStars
	move.w	#2,vdly(a5)

	rts
;---------------------- env. 1.12 sec
BIGCPUWAIT:
	movem.l	d0,-(sp)
;	bsr	waitvbl
;.vbl	tst.w	AnimFlagVbl
;	beq.s	.vbl
;	clr.w	AnimFlagVbl

	move.l	#56/2,d0		; 1.12*50
.pause	;bsr	waitraster	; VBL lasts 40*384*2 cycles/pix = 30720 cycles (2.56 ms)
	bsr	waitvbl
	subq.l	#1,d0
	bne.s	.pause

;	move.l	#80000,d0
;.decr	subq.l	#1,d0
;	bne.s	.decr
	movem.l	(sp)+,d0
	rts
; 0.04s
BIGCPUWAIT2:
	movem.l	d0,-(sp)
	bsr	waitvbl
;	bsr	waitvbl
;.vbl	tst.w	AnimFlagVbl
;	beq.s	.vbl
;	clr.w	AnimFlagVbl

;	sync	255
;	sync	254
;	movem.l	d0,-(sp)
;	move.l	#3000,d0
;.decr	subq.l	#1,d0
;	bne.s	.decr
	movem.l	(sp)+,d0
	rts
;================================================= VBI routine
DoStars:
	bsr	STRFlipScreen
	bsr	STRClearBuffer
	bsr	STRStarsPlot
	rts
;------------- clear each previous stars
STRClearBuffer:
	movea.l	ptScreenStars1(pc),a0	; plan 1 working screen
	lea	48*256(a0),a1	; plan 2 48*256
	lea	48*256(a1),a2	; plan 3
	movea.l	ptBufStarsPos1(pc),a3
	move.w	NbStars(pc),d1
.loopclr
	move.l	(a3)+,d0	; stars pos (y*48+x)
	clr.b	(a0,d0.l)	; plan 1
	clr.b	(a1,d0.l)	; plan 2
	clr.b	(a2,d0.l)	; plan 3
	dbf	d1,.loopclr
	rts
;----------------------------------------------
STRStarsPlot:
	lea	BufCoordsStars(pc),a0	; (x,y,z).w
	movea.l	a0,a1
	lea	StarsStruct(pc),a2	; datas
	movem.w	(a2)+,d0-d3	; d0=incx,d1=incy,d2=incz,d3 = nb stars

	lea	PosStart(pc),a3		; CX,CY
	movea.l	ptScreenStars1(pc),a2	; screen
	movea.l	ptBufStarsPos1(pc),a4	; buf save coords
.loopstars:
	movem.w	(a0)+,d4-d6	; x,y,z
	add.w	d0,d4
	add.w	d1,d5
	add.w	d2,d6
; clip
	cmpi.w	#384,d4		; max x
	blt.s	.infx
	subi.w	#768,d4

.infx	cmpi.w	#-384,d4	; max -x
	bgt.s	.infy
	addi.w	#768,d4

.infy	cmpi.w	#256,d5		; max y
	blt.s	.supy
	subi.w	#512,d5

.supy	cmpi.w	#-256,d5	; max -y
	bgt.s	.negy
	addi.w	#512,d5

.negy	cmpi.w	#1024,d6
	ble.s	.infz
	subi.w	#960,d6

.infz	cmpi.w	#64,d6
	bgt.s	.plot
	addi.w	#960,d6

.plot:	move.w	d4,(a1)+	; save current pos
	move.w	d5,(a1)+	;
	move.w	d6,(a1)+	;

	muls.w	counterX(pc),d4	; x*160 - max X/2
	muls.w	counterY(pc),d5	; y*160 - max Y
	divs.w	d6,d4		; x*160/160
	divs.w	d6,d5		; y*160/160
	add.w	(a3),d4		; +CX
	add.w	2(a3),d5	; +CY
	bsr	DoPlot
	dbf	d3,.loopstars
	rts


exitplot
	rts	
;------------------------
DoPlot:
	tst.w	d4
	bmi.s	exitplot
	tst.w	d5
	bmi.s	exitplot
	cmpi.w	#384,d4		; max x (48*8)
	bge.s	exitplot
	cmpi.w	#256,d5		; max y
	bge.s	exitplot

	move.w	d5,d7
	asl.w	#5,d5
	asl.w	#4,d7
	add.w	d7,d5
	move.w	d4,d7
	asr.w	#3,d4
	add.w	d4,d5
	ext.l	d5		; byte screen offset
	lea	(a2,d5.l),a5
	andi.b	#7,d7
	moveq	#7,d4
	sub.b	d7,d4
	asr.w	#7,d6
	
	btst	#0,d6		; test deep z
	bne.s	.plotplan2
	bset	d4,(a5)		; plan 1

.plotplan2
	btst	#1,d6
	bne.s	.plotplan3
	bset	d4,48*256(a5)	; plan 2 48*256

.plotplan3
	btst	#2,d6
	bne.s	.endplot
	bset	d4,48*256*2(a5)	; 48*256*2 plan 3

.endplot
	move.l	d5,(a4)+	; save current plot screen offset
	rts
;----------------------
STRFlipScreen:
	lea	ptScreenStars1(pc),a1
	move.l	(a1)+,d3	; d3=bufScrStars1
	move.l	(a1),d4		; d4=bufScrStars2
	move.l	d3,(a1)		; ptScreenStars2=d3=bufScrStars1
	move.l	d4,-(a1)	; ptScreenStars1=d4=bufScrStars2
	
	move.l	d3,d0
	lea	CLplanDPF_stars,a0
	moveq	#2,d1
	move.l	#48*256,d2
	bsr	Inst_plans

	lea	ptBufStarsPos1(pc),a1
	move.l	(a1)+,d3	; d3=bufStarsPos1
	move.l	(a1),d4		; d4=bufStarsPos2
	move.l	d3,(a1)		; ptBufStarsPos2=d3=bufStarsPos1
	move.l	d4,-(a1)	; ptBufStarsPos1=d4=bufStarsPos2

	rts

;----------------------
InitSTARS:
RandomizeStars:
	move.l	#$4D373729,d0
	move.l	d0,d1
	rol.w	#3,d1
	swap	d1
	eori.l	#$5A5AA5A5,d1
	bsr	incValue

	lea	BufCoordsStars(pc),a5	; x
	move.w	#409-1,d5
.loop768:
	move.w	#768,d0		; 384*2
	bsr	GetValue
	subi.w	#384,d0
	move.w	d0,(a5)		; .w X
	lea	6(a5),a5	; next coords
	dbf	d5,.loop768

	lea	BufCoordsStars+2(pc),a5	; y
	move.w	#409-1,d5
.loop512:
	move.w	#512,d0		; 256*2
	bsr	GetValue
	subi.w	#256,d0
	move.w	d0,(a5)		; .w Y
	lea	6(a5),a5
	dbf	d5,.loop512

	lea	BufCoordsStars+4(pc),a5	; z
	move.w	#409-1,d5
.loop1024:
	move.w	#1024,d0
	bsr	GetValue
	move.w	d0,(a5)		; .w Z
	lea	6(a5),a5
	dbf	d5,.loop1024
	rts
;--
incValue:
	add.l	d0,d1
	movem.l	d0-d1,BufValRandom

computeValue:
	movem.l	d2-d3,-(sp)
	movem.l	BufValRandom(pc),d0-d1
	andi.b	#$E,d0
	ori.b	#$20,d0
	move.l	d0,d2
	move.l	d1,d3
	add.l	d2,d2	; *2
	addx.l	d3,d3	; *3
	add.l	d2,d0
	addx.l	d3,d1
	swap	d3
	swap	d2
	move.w	d2,d3
	clr.w	d2
	add.l	d2,d0
	addx.l	d3,d1
	movem.l	d0-d1,BufValRandom
	move.l	d1,d0
	movem.l	(sp)+,d2-d3
	rts

GetValue:
	addq.w	#1,d0
	move.w	d0,d2
	beq.s	.exit
	bsr.s	computeValue
	clr.w	d0
	swap	d0
	divu.w	d2,d0
	clr.w	d0
	swap	d0
.exit	rts
;-----------------
white	dcb.w	32,$fff
backcol	dcb.w	32,$023

flagFlipScreen	dc.w 0
ptScreenStars1	dc.l	BufScrStars1
ptScreenStars2	dc.l	BufScrStars2
ptBufStarsPos1	dc.l	BufStarsPos1
ptBufStarsPos2	dc.l	BufStarsPos2
;
StarsStruct	
incX	dc.w	0	; d0
incY	dc.w	0	; d1
incZ	dc.w	-5	; d2

NbStars	dc.w	65-1	; d3
; CX-CY
posStart dc.w	320/2
	 dc.w	256/2
; max X/2, Y/2 (explode,imlode)
counterX dc.w	0
counterY dc.w	0
; buffers
BufValRandom:	ds.l	2
BufStarsPos1	ds.l	200
BufStarsPos2	ds.l	200
BufCoordsStars:	ds.w	409*3	; x,y,z
* ========================================================
; a2=anim file
DoANIMCred:
	clr.w	numFrameCred
	lea	BufferAnim1,a0	; 	!!! BUG si valeur impaire !!!
	lea	BufferAnim2,a1
;	lea	animfile(pc),a2	; "FORM"
	lea	AnimStruct(pc),a3	; 0
	move.l	#SCWIDTH,d0	; width 40
	move.l	#SCHEIGHT,d1	; height 256
	bsr	AnimInit	; init 1st ILBM image and get params

	bsr	InstPlanDPF_anim1

        moveq   #0,d7
	lea     CLpaletteDPF,a0
	move.l  #$1800023,(a0)+
	move.l  #$1820333,(a0)+
	move.l  #$1840666,(a0)+
	move.l  #$1860AAA,(a0)+

AnimMainLoop:
* -------------- Unpack current animation frame..
; do buffer 2
	lea	AnimStruct(pc),a0
	bsr	AnimUnpackFrame

	tst.w	d0		; no more frame ?
	bne.s	.ExitAnim	; no
* -------------- Anim double buffer 2 (swap screens)
	bsr	InstPlanDPF_anim2

.vbl1	tst.w	AnimFlagVbl
	beq.s	.vbl1
	clr.w	AnimFlagVbl

	addi.w	#1,NumFrameCred
	cmpi.w	#25,NumFrameCred
	beq.s	.ExitAnim

* -------------- Unpack current+ animation frame..
; do buffer 1
	lea	AnimStruct(pc),a0
	bsr	AnimUnpackFrame

	tst.w	d0
	bne.s	.ExitAnim
* -------------- Anim double buffer 1 (swap screens)
	bsr	InstPlanDPF_anim1

.vbl2	tst.w	AnimFlagVbl
	beq.s	.vbl2
	clr.w	AnimFlagVbl

	bra	AnimMainLoop

* -------------- otherwise reset to 1st frame
.ExitAnim:	
.resetFrame:
	rts
;--------------
InstPlanDPF_anim1:
	lea	BufferAnim1,a1
	bra.s	InstPlansDPF

InstPlanDPF_anim2:
	lea	BufferAnim2,a1
InstPlansDPF
	move.l	a1,d0
	lea	CLplanDPF_anim,a0
	move.w	d0,6(a0)
	swap	d0
	move.w	d0,2(a0)
	swap	d0
	addi.l	#40*256,d0
	adda.l	#8,a0
	move.w	d0,6(a0)
	swap	d0
	move.w	d0,2(a0)
	rts


AnimFlagVbl dc.w	0
SwitchAnimFlagVbl dc.w	0
NumFrameCred	dc.w	0
* ==========================================================
* =                                 ROLLER EFFECT ON PICTURE
* ==========================================================
SZCPLINET7=12*4

DoTEAM7ROLL:	
; inst team7 pic
* - inst bitplans

	move.l	#fcteam7,d0
	lea	CLbplFX,a0
	moveq	#5-1,d1
	move.l	#SZPLAN,d2	; 40*256
	bsr	Inst_plans
;
	bsr	MakeCopperFX

	bsr	waitraster

	lea	CopperListFX,a0
	move.l	a0,$dff080
	move.w	#0,$dff088
;
Team7RollLoop:
	bsr	waitvbl
;	bsr	waitraster
;	cmpi.b	#255,$DFF006
;	bne.s	Team7RollLoop

	bsr	IncrLineDown	; rouleau descend

	lea	fcteam7+40*80,a0	; start 80 lines down (mirror pic)
	move.l	numLinereached(pc),d0
	mulu.w	#40,d0	; line width
	adda.l	d0,a0
	move.l	a0,d0
	clr.l	d6	; loop
	move.l	#48,d7		; nb line (roller size)
	lea	CLbufferFX+8,a1 ; skip wait+$102 2 .L = point sur bplpt

	cmpi.l	#1,numLinereached	; end of roll ? change effect ?
	bne.s	.loop

	bsr	Team7Open		; close window
; make shape
.loop	move.l	a0,d0
	lea	RollertShapeOffset(pc),a2
	move.l	d6,d5
	add.l	d5,d5
	add.l	d5,d5
	move.l	(a2,d5.l),d2
	add.l	d2,d0

	cmpi.l	#fcteam7+SZPLAN,d0	; 40*256 ($6DD64) addr end of pic reached ?
	bmi.s	.instplan	; incr 0->48
	move.l	#fcteam7+SZPLAN-40,d0	; 40*255 ($6DD3C) fix addr end of pic

.instplan	
	addi.l	#1,d6		; incr 0->48

	move.w	d0,6(a1)
	swap	d0
	move.w	d0,2(a1)
	swap	d0
	addi.l	#SZPLAN,d0
	adda.l	#8,a1		; plan 2
	move.w	d0,6(a1)
	swap	d0
	move.w	d0,2(a1)
	swap	d0
	addi.l	#SZPLAN,d0
	adda.l	#8,a1		; plan 3
	move.w	d0,6(a1)
	swap	d0
	move.w	d0,2(a1)
	swap	d0
	addi.l	#SZPLAN,d0
	adda.l	#8,a1		; plan 4
	move.w	d0,6(a1)
	swap	d0
	move.w	d0,2(a1)
	swap	d0
	addi.l	#SZPLAN,d0
	adda.l	#8,a1		; plan 5
	move.w	d0,6(a1)
	swap	d0
	move.w	d0,2(a1)

	adda.l	#12+4,a1		; next line skip 12+4 .L

	subq.l	#1,d7
	bne	.loop

	addi.l	#1,numLinereached
	cmpi.l	#211,numLinereached	; 256-211=45
	bne	Team7RollLoop
;
	; original wait depack main anim+main pic : dur. 774
	move.l	#400,d0		; 8*50 8 sec.
pause	bsr	waitraster	; VBL lasts 40*384*2 cycles/pix = 30720 cycles (2.56 ms)
	subq.l	#1,d0
	bne.s	pause

	rts
;----
; 1st effect : open window
Team7Open:
	movem.l	d0-a6,-(sp)

	move.w	#$5200,CLbplconFX
	lea	CLwstrtFX,a0
Team7OpenLoop:
	bsr	waitvbl
;	bsr	waitraster
;	cmpi.b	#-1,$DFF006
;	bne.s	Team7OpenLoop

; ! CPU delay !
; loop : 14 cycles * 400 = 5600 cycles * 1/7 mhz = 802 ns = 0.08 ms - 1/12 mhz = 468 ns
;	move.l	#400,d0
;.delay	subq.l	#1,d0		; #xxx .l clock periods - bus read/write (r/w) : 8(2/0) - Dn : 0(0/0) - Subq #,Dn : 4(1/0)
;	bne.s	.delay		; Bcc - branch taken : 10(2/0) - branch not taken : 8(1/0) .w 12(1/0)

	move.w	(a0),d0		; current wstart
	cmpi.w	#$2C81,d0	; end when reached $2C
	beq.s	ExitTeam7
	
	subi.w	#$100,d0	; decr
	move.w	d0,(a0)		; new wstart
	bra.s	Team7OpenLoop

ExitTeam7
	movem.l	(sp)+,d0-a6
	rts

; ---- roll down
IncrLineDown:
	move.l	#49,d0
	lea	CLbufferFX,a0
.loopincr 
	addi.l	#$1000000,(a0)
	adda.l	#12*4,a0	; skip 12 .L = 48
	
	subq.l	#1,d0
	bne.s	.loopincr
	rts

numLinereached:	dc.l 0

;------------------------
; size line = 12.L
MakeCopperFX:
	lea	CLbufferFX,a0
	move.l	#48,d0	; nb lines (roller)
	move.l	#$2C,d1		; wait yy0f
	lea	RollerShapeShift(pc),a5

.loop	move.l	d1,d2		; wait
	lsl.l	#8,d2		; $2C->$2C000000
	swap	d2		;
	ori.l	#$1FF00,d2	; $2C01FF00
	move.l	d2,(a0)+	; wait yy0f fffe .L
;
	move.w	#$102,(a0)+	; bplcon1 .w
	move.w	(a5)+,d7	; get shift value
	move.w	d7,d6
	lsl.w	#4,d6
	or.w	d6,d7
	move.w	d7,(a0)+	; final	bplcon value .w = .L
;
	move.l	#$E00000,(a0)+	; 5 plans = 10.L
	move.l	#$E20000,(a0)+
	move.l	#$E40000,(a0)+	;
	move.l	#$E60000,(a0)+
	move.l	#$E80000,(a0)+	;
	move.l	#$EA0000,(a0)+
	move.l	#$EC0000,(a0)+	;
	move.l	#$EE0000,(a0)+
	move.l	#$F00000,(a0)+	;
	move.l	#$F20000,(a0)+
; next line
	addq.l	#1,d1		; next line wait
	subq.l	#1,d0
	bne.s	.loop

; last raster
	move.l	d1,d2
	lsl.l	#8,d2
	swap	d2
	ori.l	#$1FF00,d2
	move.l	d2,CLendbuffFX
	rts

RollerShapeShift:
	dc.w 0,2,3,4,5,5,6,7,7,8,9,9
	dc.w $A,$A,$B,$B,$C,$C,$C,$D
	dc.w $D,$D,$D,$D,$D,$D,$D,$D
	dc.w $D,$C,$C,$C,$B,$B,$A,$A
	dc.w 9,9,8,7,7,6,5,5,4,3,2,0

; 23 -> -23 : 46 lines
RollertShapeOffset:	; L=40 width
	dc.l 920	; L*23
	dc.l 880
	dc.l 840
	dc.l 800
	dc.l 760
	dc.l 720
	dc.l 680
	dc.l 640
	dc.l 600
	dc.l 560
	dc.l 520
	dc.l 480
	dc.l 440
	dc.l 400
	dc.l 360
	dc.l 320
	dc.l 280
	dc.l 240
	dc.l 200
	dc.l 160
	dc.l 120
	dc.l SCWIDTH*2		; L*2
	dc.l SCWIDTH*1		; L*1
	dc.l SCWIDTH*0		; L*0
	dc.l 0		; -L*0
	dc.l -40	; -L*1
	dc.l -80	; -L*2
	dc.l -120
	dc.l -160
	dc.l -200
	dc.l -240
	dc.l -280
	dc.l -320
	dc.l -360
	dc.l -400
	dc.l -440
	dc.l -480
	dc.l -520
	dc.l -560
	dc.l -600
	dc.l -640
	dc.l -680
	dc.l -720
	dc.l -760
	dc.l -800
	dc.l -840
	dc.l -880
	dc.l -920	; -L*23
;-----------------------------------------------------------
DoTEAM7DOWN:
	move.l	#-2,CLbufferFX	; close copperlist before buffer

	clr.l	d7
	clr.l	d6
	move.l	#29,d5
	lea	CLwstrtFX,a0
;
Team7DownLoop:	
	bsr	waitvbl
;	bsr	waitraster
;	cmpi.b	#255,$DFF006
;	bne.s	Team7DownLoop

	move.l	#400,d0		; ! CPU delay - TO FIX ! 800ns
.delay	subq.l	#1,d0
	bne.s	.delay

	not.w	d7
	beq.s	.nomore
	addi.w	#$100,d6	; close window
.nomore
	move.w	(a0),d0
	add.w	d6,d0
	move.w	d0,(a0)

	subq.w	#1,d5
	bne.s	Team7DownLoop
;
	move.w	#$200,CLbplconFX	; screen off
	rts
* =========================================================
* =                                     COPPER LASER EFFECT
* =========================================================
; alternative intro
DoFIRST:
	lea	Module2,a0
	bsr	mt_init
;
	lea	newVBL(pc),a0
	lea	VBLpt(pc),a1
	move.l	a0,(a1)
;
	bsr	StopMusic
	rts
;-----------------------------------
SZCPLINE=(12+1)*4	; 13*4=52 (avec bpl6)
;SZCPLINE=(10+1)*4	; 11*4 (sans bpl6)

DoLASER:	
; inst main pic
	lea	palettePic(pc),a0
	lea	CLpalLASER+2,a1
	move.w	#32-1,d0
.copycol
	move.w	(a0)+,(a1)
	addq.l	#4,a1
	dbf	d0,.copycol

	bsr	MakeCopperLASER

	bsr	waitraster
	lea	CopperListLASER,a0
	move.l	a0,$dff080
	move.w	#0,$dff088
;
	lea	fctitle,a0
	move.l	a0,ptLaserPic

;
	move.l	ptLaserPic(pc),d0
	addi.l	#40*127,d0	; pic+40*127 - 1st middle
	move.l	d0,d5
	addi.l	#40,d5		; +1 line - 2nd middle
	move.l	#256/2-1,d1	; 128-1

LaserEffectLoop
;	cmpi.b	#$AD,$DFF006	; 173
;	bcs.w	LaserEffectLoop
;.wvbl	cmpi.b	#$AC,$DFF006	; 172
;	bne.w	.wvbl
	movem.l	d0,-(sp)
	sync	173
	sync	172
;.loop	move.l	$dff004,d0
;	and.l	#$1ff00,d0
;	cmp.l	#173<<8,d0
;	bne.b	.loop
;.loop2	move.l	$dff004,d0
;	and.l	#$1ff00,d0
;	cmp.l	#172<<8,d0
;	bne.b	.loop2	
	movem.l	(sp)+,d0

	addi.l	#40,d5		; +1 line
	move.l	d1,d3
	move.l	#127,d2
	sub.l	d1,d2
	mulu.w	#SZCPLINE,d2		; 13*4 .L size of a copperline

	lea	CLbufferLASER+SZCPLINE*127+6,a0 ; $19D2 = 6610 = 1652*4+2 = 13*4*127+6
	suba.l	d2,a0
	lea	CLbufferLASER+SZCPLINE*255+6,a2 ; $33D2 = 13266 = 3316*4+2 = 13*4*255+6
.loopline:
; 1st middle to up
	move.w	d0,4(a0)		; inst plan 1
	swap	d0
	move.w	d0,(a0)
	swap	d0
	addi.l	#SZPLAN,d0	; 40*256
	move.w	d0,12(a0)		; inst plan 2
	swap	d0
	move.w	d0,8(a0)
	swap	d0
	addi.l	#SZPLAN,d0		; inst plan 3
	move.w	d0,20(a0)
	swap	d0
	move.w	d0,16(a0)
	swap	d0
	addi.l	#SZPLAN,d0		; inst plan 4
	move.w	d0,28(a0)
	swap	d0
	move.w	d0,24(a0)
	swap	d0
	addi.l	#SZPLAN,d0		; inst plan 5
	move.w	d0,36(a0)
	swap	d0
	move.w	d0,32(a0)
	swap	d0
;	subi.l	#SZPLAN*4,d0
; useless plan 6
	addi.l	#SZPLAN,d0		; inst plan 6 (?)
	move.w	d0,44(a0)
	swap	d0
	move.w	d0,40(a0)
	swap	d0
	subi.l	#SZPLAN*5,d0	; -40*256*5 -> 1st plan

; 2nd middle to down
	move.w	d5,4(a2)
	swap	d5
	move.w	d5,(a2)
	swap	d5
	addi.l	#SZPLAN,d5
	move.w	d5,12(a2)
	swap	d5
	move.w	d5,8(a2)
	swap	d5
	addi.l	#SZPLAN,d5
	move.w	d5,20(a2)
	swap	d5
	move.w	d5,16(a2)
	swap	d5
	addi.l	#SZPLAN,d5
	move.w	d5,28(a2)
	swap	d5
	move.w	d5,24(a2)
	swap	d5
	addi.l	#SZPLAN,d5
	move.w	d5,36(a2)
	swap	d5
	move.w	d5,32(a2)
	swap	d5
;	subi.l	#SZPLAN*4,d5
; useless plan 6
	addi.l	#SZPLAN,d5		; inst plan 6 (?)
	move.w	d5,44(a2)
	swap	d5
	move.w	d5,40(a2)
	swap	d5
	subi.l	#SZPLAN*5,d5	; -40*256*5 (1st plan)
; 
	suba.l	#SZCPLINE,a0	; next copperline 13*4 (52)
	suba.l	#SZCPLINE,a2	;

	dbf	d3,.loopline

	move.l	ptLaserPic(pc),d0
	addi.l	#SZPLAN/2,d0	; 40*128 - 5120 - middle of pic
	move.l	#SCHEIGHT/2,d2	; 128
	sub.l	d1,d2		; -128 = nb lines left
	mulu.w	#SCWIDTH,d2	; 40 *w
	sub.l	d2,d0
	
	dbf	d1,LaserEffectLoop

	rts
;---------------------
; 13 .L par ligne - 257 lines
MakeCopperLASER:
	lea	CLbufferLASER,a0
	move.w	#$2C01,d0	; move.l	#$2C01FF00,d0
MakerCopperLaserLoop:
	move.w	d0,(a0)+	; move.l	d0,(a0)+	; wait
	move.w	#$FFFE,(a0)+
	addi.w	#$100,d0	; addi.l	#$1000000,d0
	move.l	#$E00000,(a0)+	; plan 1
	move.l	#$E20000,(a0)+
	move.l	#$E40000,(a0)+	; plan 2
	move.l	#$E60000,(a0)+
	move.l	#$E80000,(a0)+	; plan 3
	move.l	#$EA0000,(a0)+
	move.l	#$EC0000,(a0)+	; plan 4
	move.l	#$EE0000,(a0)+
	move.l	#$F00000,(a0)+	; plan 5
	move.l	#$F20000,(a0)+

	move.l	#$F40000,(a0)+	; plan 6 (?)	
	move.l	#$F60000,(a0)+
	
	cmpi.w	#$2C01,d0	; cmpi.l	#$2C01FFFE,d0
	beq.s	.exit
	cmpi.w	#$00E1,d0	; cmpi.l	#$00E1FFFE,d0

	beq.s	.nopal
	cmpi.w	#$0001,d0	; cmpi.l	#$0001FFFE,d0

	bne.s	MakerCopperLaserLoop
	
	move.w	#$FFE1,d0	; move.l	#$FFE1FFFE,d0	; pal limit
	bra.s	MakerCopperLaserLoop
.nopal
	move.w	#$0101,d0	; move.l	#$0101FFFE,d0
	bra.s	MakerCopperLaserLoop

.exit	rts

ptLaserPic dc.l	0
* =========================================================
* =                                             END CREDITS
* =========================================================
DoEND:
; load & depack pic
;
	move.l	#fcendp,d0
	lea	CLbplEND,a0
	moveq	#4-1,d1
	move.l	#SZPLAN,d2	; 40*256
	bsr	Inst_plans

	bsr	waitraster
	lea	CopperListEND,a0
	move.l	a0,$dff080
	move.w	#0,$dff088
	
	move.w	#$4200,CLbplconEND
;
	bsr	waitraster
	lea	Vars(pc),a5
	move.w 	#32-1,nbrcol(a5)
	move.l 	#palettePicEND,Liste(a5)
	move.l	#CLpalEND+2,ColList(a5)

	clr.w	count(a5)	;
	clr.w	upflag(a5)	; reinit fader
; load & depack text
;
.wtfadi	tst.b	upflag(a5)
	beq.s	.wtfadi
;
	bsr	waitraster
	move.w	#$6200,CLbplconEND

	move.l	#(256*4)-256,d7	; 1024
	clr.l	d0		; vpos in pictext
	lea	CLbp5END,a0
EndLoop:
	move.l	#fcendt,d1
	add.l	d0,d1
	move.w	d1,6(a0)	; plan 1
	swap	d1
	move.w	d1,2(a0)
	swap	d1
	addi.l	#40*(256*4),d1	; 40960 = 40*1024=40*(256*4)
	move.w	d1,14(a0)	; plan 2
	swap	d1
	move.w	d1,10(a0)

	addi.l	#40,d0		; vpos++ vertical scroll

;.vbl1	tst.w	AnimFlagVbl
;	beq.s	.vbl1
;	clr.w	AnimFlagVbl
	bsr	waitvbl
;	bsr	waitraster

;	move.l	#400,d1		; ! CPU delay - TO FIX !
;.delay	subq.l	#1,d1
;	bne.s	.delay

	dbf	d7,EndLoop
;
	bsr	waitraster
	lea	Vars(pc),a5
	move.w 	#32-1,nbrcol(a5)
	move.l 	#black,Liste(a5)
	move.l	#CLpalEND+2,ColList(a5)

	clr.w	count(a5)	;
	clr.w	upflag(a5)	; reinit fader
;
.wtfado	tst.b	upflag(a5)
	beq.s	.wtfado

	move.w	#$0200,CLbplconEND

	rts
* =========================================================
* =                                  IFF-ANIM main (plan 6) 
* =========================================================
DoANIM:	
; inst main pic
	bsr	waitraster

	move.w	#$2b81,CLwstrtLASER+2	; ! $2c->$2b decalage 1 ligne par rapport à l'effet Laser ?!
* - re-use Copperlist LASER
	lea	CLbufferLASER,a0
	move.l	#$E00000,(a0)+	; 5 bitplans
	move.l	#$E20000,(a0)+
	move.l	#$E40000,(a0)+
	move.l	#$E60000,(a0)+
	move.l	#$E80000,(a0)+
	move.l	#$EA0000,(a0)+
	move.l	#$EC0000,(a0)+
	move.l	#$EE0000,(a0)+
	move.l	#$F00000,(a0)+
	move.l	#$F20000,(a0)+
	move.l	#$D001FFFE,(a0)+ ; place 6eme plan
	move.l	#$F40000,(a0)+	; plan 6
	move.l	#$F60000,(a0)+
	move.l	#$1006200,(a0)+
	move.l	#$F301FFFE,(a0)+ ; place 2 6eme	plan
;	move.l	#$F40000,(a0)+	; plan6 - replaced by $1005200
;	move.l	#$F60000,(a0)+
	move.l	#$1005200,(a0)+
	move.l	#$ffe1fffe,(a0)+
	move.l	#$2b0ffffe,(a0)+
	move.l	#$1000000,(a0)+
	move.l	#$FFFFFFFE,(a0)+	; end copperlist

	move.l	#fctitle,d0
	lea	CLbufferLASER,a0
	moveq	#5-1,d1
	move.l	#40*256,d2
	bsr	Inst_plans

;---------------------------------
	clr.l	numframe
	bsr	PlacePlan6_buffer2_1

* -------------- Setup IFF Anim "Play structure.."
	lea	BufferAnim1+4,a0	; +40*12+4	!!! BUG si valeur impaire !!!
	lea	BufferAnim2+4,a1
	lea	animfile(pc),a2	; "FORM"
	lea	AnimStruct(pc),a3	; 0
	move.l	#SCWIDTH,d0	; width 40
	move.l	#SCHEIGHT,d1	; height 256
	bsr	AnimInit	; init 1st ILBM image and get params

* -------------- main loop
AnimLoop:	;bsr	waitraster
	btst	#6,$BFE001	; lmb
	beq	ExitAnim
;	btst	#7,$BFE001	; joy button
;	beq	ExitAnim
* -------------- Unpack current animation frame..
; do buffer 2
	lea	AnimStruct(pc),a0
	bsr	AnimUnpackFrame

	tst.w	d0		; no more frame ?
	bne.s	resetFrame	; no

* -------------- Anim double buffer 2 (swap screens)
;	bsr	WaitRaster_Dly	; delay anim
;	bsr	WaitRaster_Dly
.vbl1	tst.w	AnimFlagVbl
	beq.s	.vbl1
	clr.w	AnimFlagVbl
	
	bsr	PlacePlan6_buffer1_2

* -------------- Unpack current+ animation frame..
; do buffer 1
	lea	AnimStruct(pc),a0
	bsr	AnimUnpackFrame

	tst.w	d0
	bne.s	resetFrame

* -------------- Anim double buffer 1 (swap screens)
;	bsr	WaitRaster_Dly
;	bsr	WaitRaster_Dly
.vbl2	tst.w	AnimFlagVbl
	beq.s	.vbl2
	clr.w	AnimFlagVbl
	
	bsr	PlacePlan6_buffer2_1

	bsr	Plan6_mov

	bra	AnimLoop

* -------------- otherwise reset to 1st frame
resetFrame:	
	lea	AnimStruct(pc),a0
	bsr	initframe_ptr		; flip buffer (double buf)

	move.l	#SZPLAN*2,numframe		; size frame 40*256 = width*h
	bsr	PlacePlan6_buffer1_2

;	btst	#7,$BFE001
;	beq.s	ExitAnim
	btst	#6,$BFE001
	bne	AnimLoop

ExitAnim:	
	rts

numframe:	dc.l 0

; --------------- S U B	R O U T	I N E ---------------------------------------
CLrasterTop=10*4
CLbp6=11*4

Plan6_mov:						; move pic down to up
	cmpi.b	#$38,CLbufferLASER+CLrasterTop		; cmpi.b #$38,CLrasterTop
	beq.s	.endmov
	subi.b	#1,CLbufferLASER+CLrasterTop		; subi.b #$1,CLrasterTop
.endmov
	rts
;-------------
; buffer2
PlacePlan6_buffer2_1:
	lea	CLbufferLASER+CLbp6,a0	;	lea	CLbp6,a0
	lea	BufferAnim1,a1
	adda.l	#1,a1
	adda.l	numframe(pc),a1	; buffer 2 si numframe
	move.l	a1,d0
	move.w	d0,6(a0)
	swap	d0
	move.w	d0,2(a0)
	rts
; buffer1
PlacePlan6_buffer1_2:
	lea	CLbufferLASER+CLbp6,a0	;	lea	CLbp6,a0
	lea	BufferAnim2,a1
	adda.l	#1,a1
	suba.l	numframe(pc),a1	; buffer 1 si numframe
	move.l	a1,d0
	move.w	d0,6(a0)
	swap	d0
	move.w	d0,2(a0)
	rts

; --------------- S U B	R O U T	I N E ---------------------------------------

WaitRaster_Dly:
;	movem.l	d0,-(sp)
;	sync	255
;	sync	254
;	movem.l	(sp)+,d0

;	bsr	waitvbl
	bsr	waitraster

;	cmpi.b  #255,$DFF006
;	bne.s	WaitRaster_Dly

	move.l	#200,d0		; ! cpu counter = TO FIX ! 400ns
.counter
	subq.w	#1,d0
	bne.s	.counter

	rts
; --------------- S U B	R O U T	I N E ---------------------------------------
initframe_ptr:
	move.l	AnimFrameList(a0),AnimFramePtr(a0)
	rts
;----------------------------------- call AnimBuffer who call depack
; FORM
; ANIM
AnimInit:
	movem.l	d0-a6,-(sp)

	movea.l	a3,a6		; animstruct(pc)

	movem.l	d0-d1/a0-a2,AnimWidth(a6)	; d0=Width, d1=Height, a0=AnimBuff1, a1=AnimBuff2, a2=AnimPtr

	clr.b	BufCurFlag(a6)
	clr.l	AnimFrameList(a6)

	move.l	(a2)+,d0	; move 1st long	from iff data
	cmpi.l	#'FORM',d0      ; doest it have a form header?
	bne.s	ErrorInit	; cant convert

; foundiff	
	addq.l	#4,a2			; skip next .L
; found anim	
	move.l	(a2)+,d0
	cmpi.l	#'ANIM',d0
	bne.s	ErrorInit
;
	movea.l	a2,a0				; AnimPtr IFF
	movea.l	AnimScreenBuf1(a6),a1		; Buf1
	move.l	AnimWidth(a6),d0		; Width
	move.l	AnimHeight(a6),d1		; Height
	bsr	AnimBuffer

; copy1stframetomainscreen:
	move.l	a0,AnimFramePtr(a6)
	movea.l	AnimScreenBuf2(a6),a1
	movea.l	AnimScreenBuf1(a6),a0
	move.l	AnimWidth(a6),d0
	moveq	#0,d1
	move.b	FrameDepth(a6),d1
	mulu.w	d1,d0
	move.l	AnimHeight(a6),d1
	mulu.w	d1,d0
	subq.l	#1,d0
	lsr.l	#2,d0

.loopcopy	
	move.l	(a0)+,(a1)+
	dbf	d0,.loopcopy
	bra.s	ExitInit


ErrorInit:	
	move.w	#$F00,$DFF180
	btst	#6,$BFE001
	bne.s	ErrorInit

ExitInit	
	movem.l	(sp)+,d0-a6
	rts

; --------------- S U B	R O U T	I N E ---------------------------------------
; called by MainAnim
; ANIM
; FORM
; 1st pic : taille, resolution, palette
;  ILBM
;  BMHD (w,h,d,msk,compression)
;  CMAP
;  BODY (bitmap en ligne par ligne)
; 2em pic	differences de l'image 2 par rapport à l'image 1
; FORM ILBM
;  ANHD
;  DLTA (mask, w,h, x,y, abstime, reltime, interleave, compression 0-5
; 3em pic	differences de l'image 3 par rapport à l'image 3
; FORM ILBM
;  ANHD
;  DLTA
; ...
AnimUnpackFrame:	
	movem.l	d1-a6,-(sp)

	movea.l	a0,a6		; AnimStruct
;	movea.l	AnimFramePtr(a6),a5

	move.l	AnimFramePtr(a6),d0
	addq.l	#1,d0
	andi.w	#-2,d0
	movea.l	d0,a5

	move.l	(a5)+,d0
	cmpi.l	#'FORM',d0
	bne	LastUnpack	; no more FORM

;.foundiff2	
	addq.l	#4,a5
	move.l	(a5)+,d0
	cmpi.l	#'ILBM',d0
	bne	LastUnpack

loopAnhd	
	move.l	(a5)+,d0
	cmpi.l	#'ANHD',d0
	beq.s	getANHD
	cmpi.l	#'DLTA',d0
	beq.s	getdeltas
	move.l	(a5)+,d0

;.endhunk				; add offset now in d0 to adr in a5
	adda.l	d0,a5
	bra.s	loopAnhd

getANHD	addq.l	#4,a5
	move.b	(a5)+,d0
	cmpi.b	#5,d0
	bne	LastUnpack
	adda.w	#19,a5
	move.l	(a5)+,d7
	adda.w	#16,a5
	bra.s	loopAnhd

getdeltas:
	move.l	(a5)+,d4
	movea.l	a5,a3
	adda.l	d4,a3
	movea.l	a5,a4

	move.l	AnimWidth(a6),d4
	move.b	FrameDepth(a6),d5

	tst.b	BufCurFlag(a6)
	beq.s	.screenbuf2
	movea.l	AnimScreenBuf1(a6),a1
	bra.s	.loopd5

.screenbuf2	
	movea.l	AnimScreenBuf2(a6),a1
;
.loopd5	move.w	FrameWidth(a6),d6
	movea.l	a1,a2
	move.l	(a5)+,d0
	lea	(a4,d0.l),a0
;
.loopd6	move.b	(a0)+,d3
	beq.s	.skip2

.decloop0
	moveq	#0,d0
	move.b	(a0)+,d0
	bmi.s	.getbyte
	beq.s	.dataloop
	mulu.w	d4,d0
	adda.w	d0,a1
	bra.s	.skip

.dataloop
	moveq	#0,d0
	move.b	(a0)+,d0
	move.b	(a0)+,d1
	subq.w	#1,d0

.replicate
	move.b	d1,(a1)
	adda.w	d4,a1
	dbf	d0,.replicate
	bra.s	.skip

.getbyte
	andi.w	#$7F,d0
	subq.w	#1,d0

.copydata
	move.b	(a0)+,(a1)
	adda.w	d4,a1
	dbf	d0,.copydata

.skip	subq.b	#1,d3
	bne.s	.decloop0

.skip2	addq.w	#1,a2
	movea.l	a2,a1

	subq.w	#1,d6
	bne.s	.loopd6
;
	suba.l	AnimWidth(a6),a2	; -W
	move.l	AnimWidth(a6),d0
	move.l	AnimHeight(a6),d1
	mulu.w	d1,d0		; W*H
	adda.l	d0,a2		; a2-W+W*H
	movea.l	a2,a1

	subq.b	#1,d5
	bne.s	.loopd5
;
* -------------- check if we`ve animated all frames..
	move.l	a3,d0
	addq.l	#1,d0
	andi.l	#-2,d0
	movea.l	d0,a3

	move.l	a3,AnimFramePtr(a6)
	not.b	BufCurFlag(a6)		; flipbuf

	tst.l	AnimFrameList(a6)
	bne.s	OkUnpack

* -------------- if not, get to next frame..
	move.l	a3,AnimFrameList(a6)
		
OkUnpack			; continue frame
	moveq	#0,d0
	bra.s	ExitUnpack

LastUnpack
	moveq	#-1,d0		; no more frame ANHD

ExitUnpack
	movem.l	(sp)+,d1-a6
	rts

; --------------- S U B	R O U T	I N E ---------------------------------------
; called by AnimInit 
; Get 1st Pic and Parameters
; FORM
;  ILBM
;  BMHD (bitmap header) : getbitvars W.w H.w D.b 
;  BODY
AnimBuffer:	
	movem.l	d0-d7/a1-a6,-(sp)

	move.l	d0,d6		; W
	move.l	d1,d7		; H

	move.l	(a0)+,d0
	cmpi.l	#'FORM',d0
	bne.w	erroriff

foundiff
	addq.l	#4,a0
	move.l	(a0)+,d0
	cmpi.l	#'ILBM',d0
	bne.w	erroriff
;
searchbody:	
	move.l	(a0)+,d0
	cmpi.l	#'BMHD',d0
	beq.s	getbitvars
	cmpi.l	#'BODY',d0
	beq.s	getbody

	move.l	(a0)+,d0
	adda.l	d0,a0
	bra.s	searchbody
;-------
getbitvars	
	addq.l	#4,a0
	move.w	(a0)+,d4	; get frame width
	lsr.w	#3,d4
	move.w	d4,FrameWidth(a6)
	move.w	(a0)+,d5	; get frame height
	move.w	d5,FrameHeight(a6)
	addq.l	#4,a0
	move.b	(a0)+,d3	; get no.of bitplanes
	move.b	d3,FrameDepth(a6)
	adda.w	#11,a0
	bra	searchbody
;------
getbody	addq.l	#4,a0
	movea.l	a1,a5
	move.w	d6,d2
	mulu.w	d7,d2

decloop:
	movea.l	a5,a1
	swap	d5
	move.b	d3,d5

loopdepack	
	bsr	depack
	adda.w	d2,a1
	subq.b	#1,d5
	bne.s	loopdepack
	swap	d5
	adda.w	d6,a5

checklast
	subq.w	#1,d5
	bne.s	decloop
	bra.s	ExitAnimBuffer

erroriff
	move.w	#$F00,$DFF180
	btst	#6,$BFE001
	bne	erroriff

ExitAnimBuffer
	movem.l	(sp)+,d0-d7/a1-a6
	rts

; --------------- 
; called by AnimBuffer
depack:	movem.l	d2/a1,-(sp)

	move.w	d4,d2
	subq.w	#1,d2

.decloop:
	tst.w	d2
	bmi	.enddepack

;.byterun:	
	move.b	(a0)+,d0
	bmi.s	.next
	ext.w	d0

.copydata
	move.b	(a0)+,(a1)+
	subq.w	#1,d2
	dbf	d0,.copydata
	bra.s	.decloop

.next	ext.w	d0
	neg.w	d0
	move.b	(a0)+,d1

.byteloop
	move.b	d1,(a1)+
	subq.w	#1,d2
	dbf	d0,.byteloop
	bra.s	.decloop

.enddepack
	movem.l	(sp)+,d2/a1
	rts

* ===========================================================
	ifd	RNC

	ifd	RNC1
	 include	"RNC_1C.S"
	endc

	ifd	RNC2
	 include	"RNC_2C.S"
	endc

	endc
;----------------------------------------------------------
	ifd	PT
	 include	"ptreplay.s"
	 ;include	"playerPT3.s"
;	 include	"PT-Play_2.1a.s"
	endc
* ===========================================================
AnimStruct
Vars	ds.b	VARSIZE2
	even

paletteCRED	dc.w $23
		dc.w $333
		dc.w $666
		dc.w $AAA

; main part picture colors
palettePic
	dc.w $000,$820,$A30,$C30,$D30,$E40,$F50,$F60
	dc.w $F70,$F80,$F90,$FA0,$FD0,$FF0,$FF7,$FFE
	dc.w $FFF,$EDC,$DCB,$CBA,$BA9,$A98,$987,$876
	dc.w $765,$654,$543,$432,$321,$210,$210,$100

palettePicEND
	dc.w $000,$111,$222,$520,$333,$730,$444,$840
	dc.w $850,$555,$666,$A72,$777,$B83,$C94,$FB5
	dc.w $EEE,$EEE,$EEE,$EEE,$EEE,$EEE,$EEE,$EEE	; text
	dc.w $EEE,$EEE,$EEE,$EEE,$EEE,$EEE,$EEE,$EEE

;----- Anim Files unpacked 332k
;(no CHIPRAM needed)
	ifnd	RNC
animfile incbin	"pics/fcanim.iff"	; iff anim cust - 150k (original packed)
; 187k
cred1	incbin	"pics/cred1.iff"
cred2	incbin	"pics/cred2.iff"
cred3	incbin	"pics/cred3.iff"
cred4	incbin	"pics/cred4.iff"
	endc

;------------------------------------ packed files 223/240k
	ifd	RNC

	ifd	RNC1
	incdir	"rnc1/"
	endc

	ifd	RNC2
	incdir	"rnc2/"
	endc

animfile incbin	"fcanim.rnc"	;
;
cred1	incbin	"cred1.rnc"
cred2	incbin	"cred2.rnc"
cred3	incbin	"cred3.rnc"
cred4	incbin	"cred4.rnc"
fcteam7	incbin	"team7.rnc"		; 40*256*5 (original packed)
fctitle	incbin	"fcpic.rnc"		; 40*256*5 (original packed)
fcendp	incbin	"endpiccredits.rnc"	; 40*256*4 (original packed)
fcendt	incbin	"endcredits.rnc"	; 40*1024*2 (original packed)
	
	endc

	ifd	RNC
	section	fast,bss
BufRNCa	ds.b	150000		; buffer depack anim size max anim (fc anim)
;BufRNCp	ds.b	40*256*6	; size max pic
	endc

* =========================================================== COPPERLISTS
	section	copper,data_c
CopperListBoot
	dc.w	$96,$20

	dc.w	$8e,$9381,$90,$c3c1
	dc.w	$92,$38,$94,$d0
	dc.w	$100,$2200
	dc.w	$108,0,$10a,0
	dc.w	$102,0,$104,0

CLspr	dc.l	$1200000,$1220000
	dc.l	$1240000,$1260000
	dc.l	$1280000,$12a0000
	dc.l	$12c0000,$12e0000
	dc.l	$1300000,$1320000
	dc.l	$1340000,$1360000
	dc.l	$1380000,$13a0000
	dc.l	$13c0000,$13e0000

CLbpl	dc.l	$E00000,$E20000	; 1
	dc.l	$E40000,$E60000	; 2
	
	dc.l	$1800000,$1820CCC
	dc.l	$1840888,$1860333

	dc.l -2
;------------------------------------------ copperlist CREDITS dualplayfield
CopperListDPF:
		dc.w $100
CLBplConDPF:	dc.w $6600

		dc.l $8E2C79,$902CB9
		dc.l $920038,$9400D0

		dc.l $1800000, $1820000, $1840000, $1860000, $1880000
		dc.l $18A0000, $18C0000, $18E0000, $1900000, $1920000
		dc.l $1940000, $1960000, $1980000, $19A0000, $19C0000
		dc.l $19E0000, $1A00000, $1A20000, $1A40000, $1A60000
		dc.l $1A80000, $1AA0000, $1AC0000, $1AE0000, $1B00000
		dc.l $1B20000, $1B40000, $1B60000, $1B80000, $1BA0000
		dc.l $1BC0000, $1BE0000
; anim screen
CLplanDPF_anim	dc.l $E00000,$E20000
		dc.l $E80000,$EA0000
CLplanDPF_bp6	dc.l $F00000,$F20000
; stars screen
CLplanDPF_stars	dc.l $E40000,$E60000
		dc.l $EC0000,$EE0000
		dc.l $F40000,$F60000

		dc.l $1080000
		dc.w $10A
CLmoduloDPF2:	dc.w 8

		dc.l $960020	; dma sprites off

		dc.l $540FFFFE
CLpaletteDPF:	dc.l $1800000,$1820333,$1840666,$1860AAA	; stars
;
		dc.l $1880BA9,$18A0A98,$18C0988,$18E0887
		dc.l $1900776,$1920766,$1940655,$1960544
		dc.l $1980443,$19A0333,$19C0222,$19E0111
		dc.l $1A00620,$1A20720,$1A40730,$1A60831
		dc.l $1A80841,$1AA0941,$1AC0952,$1AE0A52
		dc.l $1B0000F,$1B2000D,$1B4000B,$1B60009
		dc.l $1B80007,$1BA0005,$1BC0003,$1BE0001

		dc.l $1920023,$1940134,$1960455,$1980577
		dc.l $19A0699,$19C0ACC,$19E0000

		dc.l $FF0FFFFE

		dc.l $1800000
		dc.l $1000200
CLbplcon1DPF	dc.l -2
	dc.l -2	
;------------------------------------------ copperlist EFFECT ROLLER
CopperListFX:
		dc.w $100
CLbplconFX	dc.w $200
	
		dc.w $8E
CLwstrtFX	dc.w $5C81

	dc.l	$902CC1
	dc.l	$920038,$9400D0
	dc.l	$1080000,$10A0000
	dc.l	$1040000,$1020000
CLpalFX
	dc.l $1800000,$1820ECA,$1840028,$186005D
	dc.l $1880001,$18A0303,$18C0404,$18E0606
	dc.l $1900818,$192091A,$1940B2D,$1960C3E
	dc.l $1980D5F,$19A0D7F,$19C0E9F,$19E0FBF
	dc.l $1A00000,$1A20110,$1A40310,$1A60420
	dc.l $1A80520,$1AA0630,$1AC0830,$1AE0940
	dc.l $1B00A41,$1B20A51,$1B40B62,$1B60C73
	dc.l $1B80D84,$1BA0D95,$1BC0EA6,$1BE0FB7

CLbplFX	dc.l	$E00000,$E20000	; 1
	dc.l	$E40000,$E60000	; 2
	dc.l	$E80000,$EA0000	; 3
	dc.l	$EC0000,$EE0000	; 4 
	dc.l	$F00000,$F20000	; 5 

CLbufferFX	ds.l 48*12	; 576
CLendbuffFX	dc.l 0
	
	dc.l	$1000200
	dc.l	$1800000
	
	dc.l	-2	
;------------------------------------------ copperlist EFFECT LASER
CopperListLASER:
	dc.l	$1005200
CLwstrtLASER
	dc.l	$8E2C81
	dc.l	$902bC1

	dc.l	$920038,$9400D0
	dc.l	$1080000,$10A0000
	dc.l	$1040000,$1020000

CLpalLASER
	dc.l $1800000,$1820000,$1840000,$1860000
	dc.l $1880000,$18A0000,$18C0000,$18E0000
	dc.l $1900000,$1920000,$1940000,$1960000
	dc.l $1980000,$19A0000,$19C0000,$19E0000
	dc.l $1A00000,$1A20000,$1A40000,$1A60000
	dc.l $1A80000,$1AA0000,$1AC0000,$1AE0000
	dc.l $1B00000,$1B20000,$1B40000,$1B60000
	dc.l $1B80000,$1BA0000,$1BC0000,$1BE0000

;	dc.l	$F40000,$F60000	; 6 

CLbufferLASER:	ds.l 13*257	; 3341 - 11*257 sans bpl6
		;ds.l 11*257

	dc.l	-2
;------------------------------------------- copperlist END
CopperListEND:
		dc.w $100
CLbplconEND	dc.w $200
	
	dc.l	$8E2C81,$902CC1
	dc.l	$920038,$9400D0
	dc.l	$1080000,$10A0000
	dc.l	$1040000,$1020000
CLpalEND
	dc.l $1800000,$1820000,$1840000,$1860000
	dc.l $1880000,$18A0000,$18C0000,$18E0000
	dc.l $1900000,$1920000,$1940000,$1960000
	dc.l $1980000,$19A0000,$19C0000,$19E0000
	dc.l $1A00000,$1A20000,$1A40000,$1A60000
	dc.l $1A80000,$1AA0000,$1AC0000,$1AE0000
	dc.l $1B00000,$1B20000,$1B40000,$1B60000
	dc.l $1B80000,$1BA0000,$1BC0000,$1BE0000

CLbplEND dc.l	$E00000,$E20000	; 1 pic
	dc.l	$E40000,$E60000	; 2
	dc.l	$E80000,$EA0000	; 3
	dc.l	$EC0000,$EE0000	; 4 
CLbp5END dc.l	$F00000,$F20000	; 5 ; text 
	dc.l	$F40000,$F60000	; 6

	dc.l	$ffe1fffe

	dc.l	-2

* -----------------------------------------------------
Module:	; 106k
mt_data:
	ifd	PT
	incbin	"fctitletune.mod"
	endc
Module2
;---- 20k
bootpic	incbin	"pics/fcload.rw"	; 40*48*2
bootsnd	incbin	"fcsound.rw"	; "team 7 presents" 44*512=22528
blanksnd ds.l	3
;---- pictures unpacked - 220k
	ifnd	RNC
fcteam7	incbin	"pics/team7.rw"	; 40*256*5 (original packed)
fctitle	incbin	"pics/fcpic.rw"	; 40*256*5 (original packed)
fcendp	incbin	"pics/endpiccredits.rw"	; 40*256*4 (original packed)
fcendt	incbin	"pics/endcredits.rw"	; 40*1024*2 (original packed)
	endc

	section	bss,bss_c
; 112k
BufferAnim1	ds.b	SZPLAN*2	; 40*256 (2 bplans pour credits anim)
BufferAnim2	ds.b	SZPLAN*2	; 40*256
empty		ds.b	SZPLAN

BufRNCp
BufScrStars1	ds.b	48*256*3	; pourra etre utilisé avec RNC depack pic
BufScrStars2	ds.b	48*256*3

	END
