*Arkham demo group source code license
*-------------------------------------
*
*This license is based on BSD license template.
*
*Copyright (c) 1993-1997, Antoine Guillon - guillon(at)arkham-development.com - http://www.arkham-development.com/
*All rights reserved.
*
*Redistribution and use in source and binary forms, with or without modification, 
*are permitted provided that the following conditions are met:
*
*- Redistributions of source code must retain the above copyright notice,
*  this list of conditions and the following disclaimer.
*
*- Redistributions in binary form must reproduce the above copyright notice,
*  this list of conditions and the following disclaimer in the documentation
*  and/or other materials provided with the distribution.
*
*- Neither the name of the Arkham Development, Antoine Guillon nor the names of its contributors
*  may be used to endorse or promote products derived from this software
*  without specific prior written permission.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
*CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
*INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
*MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
*CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
*SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
*HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
*CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
*OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
*EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*******************************************************************************
*******************************************************************************
**--------------------------DEMO N°1 BY PYRO ARKHAM--------------------------**
*******************************************************************************
*******************************************************************************

MP:	BRA.W	DEBUT

*******************************************************************************
* MACRO VSYNC BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:AUCUNE
* SORTIE:AUCUNE
* CHANGEMENT:D0
* FONCTION:ATTEND LA SYNCHRONISATION VERTICALE
*******************************************************************************
VSYNC:	MACRO
*	MOVE.W		#$20,$DFF09C
*VSYNC\@:
*	BTST.B		#5,$DFF01F
*	BEQ.S		VSYNC\@
*	MOVE.W		#$20,$DFF09C

	VSYNC0\@:
	BTST.B	#8,$DFF005
	BEQ.S	VSYNC0\@
	CMP.B	#$2A,$DFF006
	BHI.S	VSYNC0\@
	VSYNC1\@:
	BTST.B	#8,$DFF005
	BEQ.S	VSYNC1\@
	CMP.B	#$2A,$DFF006
	BLS.S	VSYNC1\@
ENDM 	

*******************************************************************************
* MACRO BLTWAIT BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:AUCUNE
* SORTIE:AUCUNE
* CHANGEMENT:AUCUN
* FONCTION:ATTEND LE BLITTER
*******************************************************************************
BLTWAIT:MACRO
BLTWAIT\@:
	BTST	#14,$DFF002
	BNE.S	BLTWAIT\@
ENDM

*******************************************************************************
* MACRO PSET320 BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:D6.W->X, D7.W->Y, A6.L->MEMOIRE ECRANT
* SORTIE:AUCUNE
* CHANGEMENT:D5,D6,D7,A5
* FONCTION:AFFICHE UN POINT EN 320*256 1 PLAN
*******************************************************************************
PSET320:MACRO
	LEA	TABL40(PC),A5		;A5->TABL40
	MOVE.W	(A5,D7.W*2),D7		;D7=Y*40
	MOVE.W	D6,D5			;D5=X
	LSR.W	#3,D6			;D6=D6/8
	ADD.W	D6,D7			;D7=X+Y*40
	NOT.B	D5			;D5=-D5
	BSET.B	D5,(A6,D7)		;ECRITURE POINT
ENDM
TABL40:	DC.W	0,1*40,2*40,3*40,4*40,5*40,6*40,7*40,8*40,9*40
	DC.W    10*40,11*40,12*40,13*40,14*40,15*40,16*40,17*40,18*40,19*40
	DC.W    20*40,21*40,22*40,23*40,24*40,25*40,26*40,27*40,28*40,29*40
	DC.W    30*40,31*40,32*40,33*40,34*40,35*40,36*40,37*40,38*40,39*40
	DC.W    40*40,41*40,42*40,43*40,44*40,45*40,46*40,47*40,48*40,49*40
	DC.W    50*40,51*40,52*40,53*40,54*40,55*40,56*40,57*40,58*40,59*40
	DC.W    60*40,61*40,62*40,63*40,64*40,65*40,66*40,67*40,68*40,69*40
	DC.W    70*40,71*40,72*40,73*40,74*40,75*40,76*40,77*40,78*40,79*40
	DC.W    80*40,81*40,82*40,83*40,84*40,85*40,86*40,87*40,88*40,89*40
	DC.W    90*40,91*40,92*40,93*40,94*40,95*40,96*40,97*40,98*40,99*40
	DC.W    100*40,101*40,102*40,103*40,104*40,105*40,106*40,107*40,108*40,109*40
	DC.W    110*40,111*40,112*40,113*40,114*40,115*40,116*40,117*40,118*40,119*40
	DC.W    120*40,121*40,122*40,123*40,124*40,125*40,126*40,127*40,128*40,129*40
	DC.W    130*40,131*40,132*40,133*40,134*40,135*40,136*40,137*40,138*40,139*40
	DC.W    140*40,141*40,142*40,143*40,144*40,145*40,146*40,147*40,148*40,149*40
	DC.W    150*40,151*40,152*40,153*40,154*40,155*40,156*40,157*40,158*40,159*40
	DC.W    160*40,161*40,162*40,163*40,164*40,165*40,166*40,167*40,168*40,169*40
	DC.W    170*40,171*40,172*40,173*40,174*40,175*40,176*40,177*40,178*40,179*40
	DC.W    180*40,181*40,182*40,183*40,184*40,185*40,186*40,187*40,188*40,189*40
	DC.W    190*40,191*40,192*40,193*40,194*40,195*40,196*40,197*40,198*40,199*40
	DC.W    200*40,201*40,202*40,203*40,204*40,205*40,206*40,207*40,208*40,209*40
	DC.W    210*40,211*40,212*40,213*40,214*40,215*40,216*40,217*40,218*40,219*40
	DC.W    220*40,221*40,222*40,223*40,224*40,225*40,226*40,227*40,228*40,229*40
	DC.W	230*40,231*40,232*40,233*40,234*40,235*40,236*40,237*40,238*40,239*40
	DC.W	240*40,241*40,242*40,243*40,244*40,245*40,246*40,247*40,248*40,249*40
	DC.W	250*40,251*40,252*40,253*40,254*40,255*40,256*40,257*40,258*40,259*40

*******************************************************************************
* MACRO PRESET320 BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:D6.W->X, D7.W->Y, A6.L->MEMOIRE ECRANT
* SORTIE:AUCUNE
* CHANGEMENT:D5,D6,D7,A5
* FONCTION:EFFACE UN POINT EN 320*256 1 PLAN
*******************************************************************************
PRESET320:MACRO
	LEA	TABL40(PC),A5		;A5->TABL40
	MOVE.W	(A5,D7.W*2),D7		;D7=Y*40
	MOVE.W	D6,D5			;D5=X
	LSR.W	#3,D6			;D6=D6/8
	ADD.W	D6,D7			;D7=X+Y*40
	NOT.B	D5			;D5=-D5
	BCLR.B	D5,(A6,D7)		;ECRITURE POINT
ENDM

*******************************************************************************
* MACRO POINT320 BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:D6.L->X, D7.L->Y, A6.L->MEMOIRE ECRANT
* SORTIE:FLAG_C=1 SI POINT PRESENT
* CHANGEMENT:D5,D6,D7
* FONCTION:AFFICHE UN POINT EN 320*256
*******************************************************************************
POINT320:MACRO
	LEA	TABL40(PC),A5		;A5->TABL40
	MOVE.W	(A5,D7.W*2),D7		;D7=Y*40
	MOVE.W	D6,D5			;D5=X
	LSR.W	#3,D6			;D6=D6/8
	ADD.W	D6,D7			;D7=X+Y*40
	NOT.B	D5			;D5=-D5
	BTST.B	D5,(A6,D7)		;LECTTURE POINT
ENDM

*******************************************************************************
* MACRO CALC3ROT
*******************************************************************************
* ENTREE:D0=X, D1=Y, D2=Z, D3=ZOOM (DEFAULT=256), ROTA, ROTB, ROTC, ROTD,     *
*	 ROTC, ROTD, ROTE, ROTF, ROTG, ROTH, ROTI			      *
* SORTIE:D6=X, D7=Y, D4=Z						      *
*******************************************************************************
CALC3ROT:MACRO
	MOVE.W	ROTA,D6
	MULS.W	D0,D6
	MOVE.W	ROTD,D4
	MULS.W	D1,D4
	ADD.W	D4,D6
	MOVE.W	ROTG,D4
	MULS.W	D2,D4
	ADD.W	D4,D6			;D6=X

	MOVE.W	ROTB,D7
	MULS.W	D0,D7
	MOVE.W	ROTE,D4
	MULS.W	D1,D4
	ADD.W	D4,D7
	MOVE.W	ROTH,D4
	MULS.W	D2,D4
	ADD.W	D4,D7			;D7=Y

	MOVE.W	ROTC,D5
	MULS.W	D0,D5
	MOVE.W	ROTF,D4
	MULS.W	D1,D4
	ADD.W	D4,D5
	MOVE.W	ROTI,D4
	MULS.W	D2,D4
	ADD.W	D4,D5			;D5=Z
	MOVE.W	D5,D4
	ASR.W	#8,D5
	ADD.W	D3,D5

	EXT.L	D6
	DIVS	D5,D6
	EXT.L	D7
	DIVS	D5,D7
ENDM

*******************************************************************************
* MACRO INTERPOL3D							      *
*******************************************************************************
* ENTREE:A0->BUFFER COORD COURANTE, A1->BUFFER COEFICIENT		      *
* SORTIE:D0=X, D1=Y, D2=Z						      *
*******************************************************************************
INTERPOL3D:MACRO
	MOVE.W	(A0),D0
	ADD.W	(A1)+,D0
	MOVE.W	D0,(A0)+
	ASR.W	#8,D0

	MOVE.W	(A0),D1
	ADD.W	(A1)+,D1
	MOVE.W	D1,(A0)+
	ASR.W	#8,D1
	
	MOVE.W	(A0),D2
	ADD.W	(A1)+,D2
	MOVE.W	D2,(A0)+
	ASR.W	#8,D2
ENDM

*******************************************************************************
* MACRO ROT3D
* ROTX=D4
* ROTY=D2
* ROTZ=A4
* AGX=A0
* AGY=A1
* AGZ=A2
* ROTATION X:
*	ROTX1=ROTX
*	ROTY1=ROTY*COS(AGX)+ROTZ*SIN(AGX)=D1
*	ROTZ1=ROTZ*COS(AGX)-ROTY*SIN(AGX)=A3
* ROTATION Y:
*	ROTX2=ROTX1*COS(AGY)+ROTZ1*SIN(AGY)=D3
*	ROTY2=ROTY1
*	ROTZ2=ROTZ1*COS(AGY)-ROTX1*SIN(AGY)=A4
* ROTATION Z:
*	ROTX3=ROTX2*COS(AGZ)+ROTY2*SIN(AGZ)=D4
*	ROTY3=ROTY2*COS(AGZ)-ROTX2*SIN(AGZ)=D2
*	ROTZ3=ROTZ2=A4
* PROJECTION 2D:
*	PRONF=(256+ROTZ3)->PROFONDEUR
*	ROTXF=ROTX3*256/PRONF=D6
*	ROTYF=ROTY3*256/PROMF=D7
*******************************************************************************
* ENTREE:D4=X, D2=Y, A4=Z, A0=ANGLEX, A1=ANGLEY, A2=ANGLEZ
* SORTIE:D6=X, D7=Y, A4=Z
* UTILISE:D1,D2,D3,D4,D5,D6,D7,A3,A4,A5,A6
* LIBRE:D0
* FONCTION:ROUTINE DE CALCUL EN 3 DIMENSIONS
*******************************************************************************

ROT3D:	MACRO
;	ROTX1=ROTX
;	ROTY1=ROTY*COS(AGX)+ROTZ*SIN(AGX)
;	ROTZ1=ROTZ*COS(AGX)-ROTY*SIN(AGX)

	LEA	COS,A6			;A6->COS
	MOVE.W	A0,D6			;D6=AGX
	MOVE.W	(A6,D6.W*2),D5		;D6=COS(AGX)*256
	MOVE.W	D2,D7			;D7=ROTY=D2
	MULS.W	D5,D7			;D7=D7*ROTY=ROTY*COS(AGX)*256
	ASR.L	#8,D7			;D7=D7/256=ROTY*COS(AGX)
	MOVE.W	D7,D1			;ROTY1=D7=D1

	MOVE.W	A4,D7			;D7=ROTZ=A4
	MULS.W	D5,D7			;D7=ROTZ*COS(AGX)*256
	ASR.L	#8,D7			;D7=D7/256=ROTZ*COS(AGX)
	MOVE.W	D7,A3			;ROTZ1=D7=A3

	LEA	SIN,A5			;A5->SIN
	MOVE.W	(A5,D6.W*2),D5		;D5=SIN(AGX)*256
	MOVE.W	A4,D7			;D7=ROTZ=A4
	MULS.W	D5,D7			;D7=ROTZ*SIN(AGX)*256
	ASR.L	#8,D7			;D7=D7/256=ROTZ*SIN(AGX)
	ADD.W	D7,D1			;ROTY1=ROTY*COS(AGX)+ROTZ*SIN(AGX)=D1

	MULS.W	D5,D2			;D7=ROTY*SIN(AGX)*256
	ASR.L	#8,D2			;D7=ROTY*SIN(AGX)
	SUB.W	D2,A3			;ROTZ1=ROTZ*COS(AGX)-ROTY*SIN(AGX)=A3

;	ROTX2=ROTX1*COS(AGY)+ROTZ1*SIN(AGY)
;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)*256
	ASR.L	#8,D7			;D7=D7/256=ROTY2*COS(AGZ)
	MOVE.W	D7,D2			;ROTY3=D7=D2
	
	MOVE.W	(A5,D6.W*2),D5		;D5=SIN(AGZ)*256
	MULS.W	D5,D1			;D7=ROTY2*SIN(AGZ)*256
	ASR.L	#8,D1			;D7=D7/256=ROTY2*SIN(AGZ)
	ADD.W	D1,D4			;ROTX3=ROTX2*COS(AGZ)+ROTY2*SIN(AGZ)=D4

	MULS.W	D5,D3			;D7=ROTX2*SIN(AGZ)*256
	ASR.L	#8,D3			;D7=ROTX2*SIN(AGZ)
	SUB.W	D3,D2			;ROTY3=ROTY2*COS(AGZ)-ROTX2*SIN(AGZ)=D2

;	D6=PROFONDEUR=(256+ROTZ3)

	MOVE.W	#256,D6			;D6=256
	ADD.W	A4,D6			;D6=256+ROTZ3

;	ROTXF=ROTX3*256/P
;	ROTYF=ROTY3*256/P

	MOVE.W	D4,D7			;D7=ROTX3=D4
	EXT.L	D7			;EXTENTION DU SIGNE MOT LONG
	LSL.L	#8,D7			;D7=ROTX3*256
	DIVS.W	D6,D7			;D7=ROTX3*256/(256+ROTZ3)
	MOVE.W	D7,D1			;ROTXF=ROTX3*256/(256+ROTZ3)
	MOVE.W	D2,D7			;D7=ROTY3=D2
	EXT.L	D7			;EXTENTION DU SIGNE MOT LONG
	LSL.W	#8,D7			;D7=ROTY3*256
	DIVS.W	D6,D7			;D7=ROTY3*256/(256+ROTZ3)
	MOVE.W	D1,D6			;ROTYF=ROTY3*256/(256+ROTZ3)
ENDM

*******************************************************************************
*			DEBUT DU PROGRAMME PRINCIPAL			      *
*******************************************************************************

;INITIALISATION DU PROGRAMME
;---------------------------
DEBUT:
	BSR.W	SAVE_SYSTEM		;SAUVE LE SYSTEME
	BSR.W	MAKE_CL			;CONSTRUIT LA COPPERLISTE
	MOVE.L 	#COPPERLIST,$DFF080	;PLACE LA COPPERLISTE
	MOVE.W	#0,$DFF088

;ECRAN NOIR
;----------
	LEA	SUITECOPPERLIST,A0
	MOVE.L	#$1000200,(A0)+		;MODE GRAPHIQUE 0 PLAN
	MOVE.L	#$009C8010,(A0)+
	MOVE.L	#$FFFFFFFE,(A0)+	;STRUCTURE FIN COPPERLIST

;CHARGEMENT ALIEN.MST
;--------------------
	MOVE.L	DOSBASE,A6		;A6->DOSBASE
	MOVE.L	#ALIEN_MST,D1		;D1->NOM DE FICHIER
	MOVE.L	#1005,D2		;D2=OUVERTURE NO CREATION (SINON 1004)
	JSR	-30(A6)			;OUVERTURE FICHIER
	MOVE.L	D0,D1			;D1=HANDLE
	MOVE.L	D0,-(A7)		;SAUVEGARDE HANDLE

	MOVE.L	(A7)+,D1
	MOVE.L	D1,-(A7)
	MOVE.L	SCREEN8,D2		;D2->DESTINATION
	MOVE.L	#26465,D3		;D3=LONGUEUR
	JSR	-42(A6)			;CHARGEMENT FICHIER

	MOVE.L	(A7)+,D1		;D1=HANDLE
	JSR	-36(A6)			;FERMETURE FICHIER

	MOVE.B	#%10010111,$BFD100	;COUPE MOTEURS DRIVES

;AFFECTE LA PALETTE DE ALIEN.MST
;-------------------------------
	MOVE.L	SCREEN8,A0
	ADDA	#50,A0
	MOVE.W	#$C00,D3
	MOVEQ.L	#7,D4
COUL2:
	LEA	$DFF180,A1
	MOVE.W	D3,BPLCON3
	MOVE.L	#31,D2
	MOVEQ.L	#0,D1
COUL1:
	MOVE.B	(A0)+,D1
	LSL.B	#2,D1
	OR.B	#$3,D1
	MOVE.B	D1,D7
	AND.B	#$F,D7
	MOVE.B	D7,D5
	LSL.W	#4,D5
	LSR.B	#4,D1
	MOVE.B	D1,D6
	LSL.W	#4,D6

	MOVE.B	(A0)+,D1
	LSL.B	#2,D1
	OR.B	#$3,D1
	MOVE.B	D1,D7
	AND.B	#$F,D7
	OR.B	D7,D5
	LSL.W	#4,D5
	LSR.B	#4,D1
	OR.B	D1,D6
	LSL.W	#4,D6

	MOVE.B	(A0)+,D1
	LSL.B	#2,D1
	OR.B	#$3,D1
	MOVE.B	D1,D7
	AND.B	#$F,D7
	OR.B	D7,D5		;D5=LSB
	LSR.B	#4,D1
	OR.B	D1,D6		;D6=MSB

	MOVE.W	D3,BPLCON3
	MOVE.W	D6,(A1)
	EOR.W	#$200,D3
	MOVE.W	D3,BPLCON3
	MOVE.W	D5,(A1)+
	EOR.W	#$200,D3
	DBRA	D2,COUL1
	ADD.W	#$2000,D3
	DBRA	D4,COUL2
	MOVE.W	#$C00,BPLCON3

;DECOMPACTAGE
;------------
	MOVE.L	SCREEN8,A5		;A5->IMGE COMPACTEE
	ADD.L	#818,A5			;OFFSET .MST
	MOVE.L	SCREENB,A6		;A6->DESTINATION
	MOVE.L	#64000,D7		;D7=LONGUEUR
	BSR.W	DECOMP			;DECOMPACTE L'IMAGE

;CONVERTION EN PLAN
;------------------

	MOVE.L	SCREENB,A5
	MOVE.L	SCREEN1,A6
	MOVE.L	#$2800,D6
	MOVE.B	#1,D7
	BSR.W	TRUE2PLANE

	MOVE.L	SCREENB,A5
	MOVE.L	SCREEN2,A6
	MOVE.L	#$2800,D6
	MOVE.B	#2,D7
	BSR.W	TRUE2PLANE

	MOVE.L	SCREENB,A5
	MOVE.L	SCREEN3,A6
	MOVE.L	#$2800,D6
	MOVE.B	#3,D7
	BSR.W	TRUE2PLANE

	MOVE.L	SCREENB,A5
	MOVE.L	SCREEN3,A6
	MOVE.L	#$2800,D6
	MOVE.B	#3,D7
	BSR.W	TRUE2PLANE

	MOVE.L	SCREENB,A5
	MOVE.L	SCREEN4,A6
	MOVE.L	#$2800,D6
	MOVE.B	#4,D7
	BSR.W	TRUE2PLANE

	MOVE.L	SCREENB,A5
	MOVE.L	SCREEN5,A6
	MOVE.L	#$2800,D6
	MOVE.B	#5,D7
	BSR.W	TRUE2PLANE

	MOVE.L	SCREENB,A5
	MOVE.L	SCREEN6,A6
	MOVE.L	#$2800,D6
	MOVE.B	#6,D7
	BSR.W	TRUE2PLANE

	MOVE.L	SCREENB,A5
	MOVE.L	SCREEN7,A6
	MOVE.L	#$2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$FFFE,(A0)+
	MOVE.L	#$1000210,(A0)+		;MODE GRAPHIQUE 8 PLAN
	MOVE.L	#$009C8010,(A0)+
	MOVE.L	#$FFFFFFFE,(A0)+	;STRUCTURE FIN COPPERLIST

;CHARGEMENT DAMIER.MST
;---------------------

	MOVE.W	#$03E0,$DFF096	
	BSR.W	MT_INIT
	MOVE.W	#$87C0,$DFF096
	MOVE.W	#$3FFF,$DFF09A
	MOVE.L	#IRQ,$6C.W		;PLACE L'IRQ
	MOVE.W	#$C010,$DFF09A

	LEA	J_IRQLOAD,A0
	MOVE.L	SAVE_VECT_IRQ,(A0)
	MOVE.W 	#$000F,$DFF096		;RESTAURE IRQ, INTENA ET DMACON
	MOVE.W 	#$4000,$DFF09A
	MOVE.L 	#IRQLOAD,$6C.W		;PREPARE IQRLOAD
	MOVE.W 	#$7FFF,$DFF09A
	MOVE.W 	#$E03C,$DFF09A
	MOVE.W 	#$7FFF,$DFF096
	MOVE.W	SAVE_DMACON,$DFF096

	MOVE.L	DOSBASE,A6
	MOVE.L	#DAMIER_MST,D1
	MOVE.L	#1005,D2
	JSR	-30(A6)
	MOVE.L	D0,D1
	MOVE.L	D0,-(A7)
	MOVE.L	SCREENH,D2		;DESTINATION
	MOVE.L	#29071,D3		;LONGUEUR
	JSR	-42(A6)			;CHARGEMENT FICHIER
	MOVE.L	(A7)+,D1
	JSR	-36(A6)			;FERMETURE FICHIER

	MOVE.W	#$87C0,$DFF096		;REPLACE L'IRQ, INTENA ET DMACON
	MOVE.W	#$3FFF,$DFF09A
	MOVE.L	#IRQ,$6C.W
	MOVE.W	#$C010,$DFF09A

	MOVE.B	#%10010111,$BFD100	;COUPE MOTEURS DRIVES

;DECOMPACTAGE
;------------
	MOVE.L	SCREENH,A5		;A5->IMGE COMPACTEE
	ADD.L	#818,A5			;OFFSET .MST
	MOVE.L	SCREEN9,A6		;A6->DESTINATION
	MOVE.L	#64000,D7		;D7=LONGUEUR
	BSR.W	DECOMP			;DECOMPACTE L'IMAGE

;ECRAN NOIR
;----------
	LEA	SUITECOPPERLIST,A0
	MOVE.L	#$1000200,(A0)+		;MODE GRAPHIQUE 0 PLAN
	MOVE.L	#$009C8010,(A0)+
	MOVE.L	#$FFFFFFFE,(A0)+	;STRUCTURE FIN COPPERLIST

;AFFECTE LA PALETTE DE DAMIER.MST EST LA SAUVEGARDE EN SCREENJ
;-------------------------------------------------------------
	MOVE.L	SCREENJ,A2
	MOVE.L	SCREENH,A0
	ADDA	#50,A0
	MOVE.W	#$C00,D3
	MOVEQ.L	#7,D4
COUL6:
	LEA	$DFF180,A1
	MOVE.W	D3,BPLCON3
	MOVE.L	#31,D2
	MOVEQ.L	#0,D1
COUL5:
	MOVE.B	(A0)+,D1
	LSL.B	#2,D1
	OR.B	#$3,D1
	MOVE.B	D1,D7
	AND.B	#$F,D7
	MOVE.B	D7,D5
	LSL.W	#4,D5
	LSR.B	#4,D1
	MOVE.B	D1,D6
	LSL.W	#4,D6

	MOVE.B	(A0)+,D1
	LSL.B	#2,D1
	OR.B	#$3,D1
	MOVE.B	D1,D7
	AND.B	#$F,D7
	OR.B	D7,D5
	LSL.W	#4,D5
	LSR.B	#4,D1
	OR.B	D1,D6
	LSL.W	#4,D6

	MOVE.B	(A0)+,D1
	LSL.B	#2,D1
	OR.B	#$3,D1
	MOVE.B	D1,D7
	AND.B	#$F,D7
	OR.B	D7,D5		;D5=LSB
	LSR.B	#4,D1
	OR.B	D1,D6		;D6=MSB

	MOVE.W	D3,BPLCON3
	MOVE.W	D6,(A1)
	MOVE.W	D6,(A2)+
	EOR.W	#$200,D3
	MOVE.W	D3,BPLCON3
	MOVE.W	D5,(A1)+
	MOVE.W	D5,(A2)+
	EOR.W	#$200,D3
	DBRA	D2,COUL5
	ADD.W	#$2000,D3
	DBRA	D4,COUL6
	MOVE.W	#$C00,BPLCON3

;CONVERTION EN PLAN
;------------------
	MOVE.L	SCREEN9,A5
	MOVE.L	SCREEN1,A6
	MOVE.L	#8000,D6
	MOVE.B	#1,D7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F:	MOVE.L	D1,(A0)+
	DBRA	D0,DAMEFF
	
;CHARGEMENT DOTS 3D
;------------------

	LEA	J_IRQLOAD,A0
	MOVE.L	SAVE_VECT_IRQ,(A0)
	MOVE.W 	#$000F,$DFF096		;RESTAURE IRQ, INTENA ET DMACON
	MOVE.W 	#$4000,$DFF09A
	MOVE.L 	#IRQLOAD,$6C.W		;PREPARE IQRLOAD
	MOVE.W 	#$7FFF,$DFF09A
	MOVE.W 	#$E03C,$DFF09A
	MOVE.W 	#$7FFF,$DFF096
	MOVE.W	SAVE_DMACON,$DFF096

	MOVE.L	DOSBASE,A6		;A6->DOSBASE
	MOVE.L	#CONE3D_DAT,D1		;D1->NOM DE FICHIER
	MOVE.L	#1005,D2		;D2=OUVERTURE NO CREATION (SINON 1004)
	JSR	-30(A6)			;OUVERTURE FICHIER
	MOVE.L	D0,D1			;D1=HANDLE
	MOVE.L	D0,-(A7)		;SAUVEGARDE HANDLE

	MOVE.L	(A7)+,D1
	MOVE.L	D1,-(A7)
	MOVE.L	SCREENA,D2		;D2->DESTINATION
	MOVE.L	#1200,D3		;D3=LONGUEUR
	JSR	-42(A6)			;CHARGEMENT FICHIER

	MOVE.L	(A7)+,D1		;D1=HANDLE
	JSR	-36(A6)			;FERMETURE FICHIER

	MOVE.L	DOSBASE,A6		;A6->DOSBASE
	MOVE.L	#GLOB3D_DAT,D1		;D1->NOM DE FICHIER
	MOVE.L	#1005,D2		;D2=OUVERTURE NO CREATION (SINON 1004)
	JSR	-30(A6)			;OUVERTURE FICHIER
	MOVE.L	D0,D1			;D1=HANDLE
	MOVE.L	D0,-(A7)		;SAUVEGARDE HANDLE

	MOVE.L	(A7)+,D1
	MOVE.L	D1,-(A7)
	MOVE.L	SCREENA,D2		;D2->DESTINATION
	ADD.L	#1200,D2
	MOVE.L	#1200,D3		;D3=LONGUEUR
	JSR	-42(A6)			;CHARGEMENT FICHIER

	MOVE.L	(A7)+,D1		;D1=HANDLE
	JSR	-36(A6)			;FERMETURE FICHIER

	MOVE.W	#$87C0,$DFF096		;REPLACE L'IRQ, INTENA ET DMACON
	MOVE.W	#$3FFF,$DFF09A
	MOVE.L	#IRQ,$6C.W
	MOVE.W	#$C010,$DFF09A

	MOVE.B	#%10010111,$BFD100	;COUPE MOTEURS DRIVES

;ANIMATION DOTS 3D
;-----------------

;COPPERLIST
;----------
	LEA	SUITECOPPERLIST,A0

	MOVE.L	#$1000200,(A0)+		;MODE GRAPHIQUE 0 PLAN

	MOVE.W  #$E2,(A0)+
	MOVE.L  SCREEN1,D0
	MOVE.W	D0,(A0)+
	MOVE.W	#$E0,(A0)+
	SWAP 	D0
	MOVE.W	D0,(A0)+

	MOVE.W  #$E6,(A0)+
	MOVE.L  SCREEN2,D0
	MOVE.W	D0,(A0)+
	MOVE.W	#$E4,(A0)+
	SWAP 	D0
	MOVE.W	D0,(A0)+

	MOVE.L	#$1002200,(A0)+		;MODE GRAPHIQUE 2 PLAN
	MOVE.L	#$009C8010,(A0)+
	MOVE.L	#$FFFFFFFE,(A0)+	;STRUCTURE FIN COPPERLIST

	MOVE.W	#$C00,$DFF106		;MSB PALETTE
	MOVE.W	#$006,$DFF180
	MOVE.W	#$FFF,$DFF182
	MOVE.W	#$888,$DFF184
	MOVE.W	#$FFF,$DFF186

	MOVE.L	SCREEN1,CLE5
	MOVE.L	SCREEN2,CLE6
	MOVE.L	SCREEN3,CLE7
	MOVE.L	SCREEN4,CLE8
	MOVE.L	SCREEN5,CLE9
	MOVE.L	SCREEN6,CLEA

	MOVEQ.L	#0,D0
AN0:
	MOVE.W	D0,D1
	MOVE.W	D0,D2
	MOVE.L	D0,-(A7)
	BSR.W	ROT3D2
	MOVE.L	SCREENA,A6

	MOVE.L	#199,D3
AN1:
	MOVE.W	(A6)+,D0
	MOVE.W	(A6)+,D1
	MOVE.W	(A6)+,D2
	MOVEM.L	D3/A6,-(A7)
	MOVE.W	#$FF,D3
	CALC3ROT
	
	TST.W	D4
	BGT.S	ANI1
	MOVE.L	CLE5,A6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#512,D0
	BNE.W	AN4

;CHARGE PAYSAGE.MST + POINTS.DAT
;-------------------------------
	MOVE.L	SCREEN1,PAY_0		;PAY0=ECRAN1 ACTIF
	MOVE.L	SCREEN4,PAY_1		;PAY1=ECRAN2 EFFACE
	MOVE.L	SCREEN7,PAY_2		;PAY2=ECRAN3 VISUEL
	MOVE.L	#TABL40,PAY_7		;PAY_7=TABLE MULTIPLICATION PAR 40
	MOVE.L	SCREENB,PAY_8		;PAY_8->PAYSAGE
	MOVE.L	SCREENA,PAY_9		;PAY_9->TABLE POINTS
	MOVE.L	#SUITECOPPERLIST,PAY_A	;PAY_A->COPPERLIST
	MOVE.L	#1000,D2
BOUCLE2:VSYNC
	BSR.W	PAYSAGE
	DBRA	D2,BOUCLE2
	BSR.W	MAKE_CL


;ECRAN NOIR
;----------
	LEA	SUITECOPPERLIST,A0
	MOVE.L	#$1000200,(A0)+		;MODE GRAPHIQUE 0 PLAN
	MOVE.L	#$009C8010,(A0)+
	MOVE.L	#$FFFFFFFE,(A0)+	;STRUCTURE FIN COPPERLIST

;CHARGE CERCLES.DAT
;------------------
	LEA	J_IRQLOAD,A0
	MOVE.L	SAVE_VECT_IRQ,(A0)
	MOVE.W 	#$000F,$DFF096		;RESTAURE IRQ, INTENA ET DMACON
	MOVE.W 	#$4000,$DFF09A
	MOVE.L 	#IRQLOAD,$6C.W		;PREPARE IQRLOAD
	MOVE.W 	#$7FFF,$DFF09A
	MOVE.W 	#$E03C,$DFF09A
	MOVE.W 	#$7FFF,$DFF096
	MOVE.W	SAVE_DMACON,$DFF096

	MOVE.L	DOSBASE,A6
	MOVE.L	#CERCLE_DAT,D1
	MOVE.L	#1005,D2
	JSR	-30(A6)
	MOVE.L	D0,D1
	MOVE.L	D0,-(A7)
	MOVE.L	SCREEN4,D2
	MOVE.L	#48960,D3		;LONGUEUR
	JSR	-42(A6)			;CHARGEMENT FICHIER
	MOVE.L	(A7)+,D1
	JSR	-36(A6)			;FERMETURE FICHIER

	MOVE.W	#$87C0,$DFF096		;REPLACE L'IRQ, INTENA ET DMACON
	MOVE.W	#$3FFF,$DFF09A
	MOVE.L	#IRQ,$6C.W
	MOVE.W	#$C010,$DFF09A

	MOVE.B	#%10010111,$BFD100	;COUPE MOTEURS DRIVES

	MOVE.L	SCREEN1,A0
	MOVE.W	#7680,D0
	MOVEQ.L #0,D1
EFFCER:	MOVE.L	D1,(A0)+
	DBRA	D0,EFFCER
	MOVE.L	#0,CLE5
	MOVE.L	#0,CLE6
	MOVE.L	#0,CLE7
	MOVE.L	#0,CLE8
	MOVE.L	#0,CLE9
	MOVE.L	SCREEN1,CLE1		;CLE1->1° ECRAN
	MOVE.L	SCREEN2,CLE2		;CLE2->2° ECRAN
	MOVE.L	SCREEN3,CLEA		;CLEA->3° ECRAN
	MOVE.L	SCREEN4,CLEB		;CLEB->CERCLES
	MOVE.L	#SUITECOPPERLIST,CLE9	;CLE9->COPPERLIST
	MOVE.L	#1000,D2
BOUCLE:	VSYNC
	BSR.W	TUNELCLE
	DBRA	D2,BOUCLE
	BRA.W	FIN

FIN:	MOVE.L	#50,D1
FIN2:	VSYNC
	DBRA	D1,FIN2
	BSR.W	MT_END			;FIN MUSIQUE
	BSR.W	RESTORE_SYSTEM		;RESTORE LE SYSTEME
	RTS				;RETOUR ASSEMBLEUR OU AMIGADOS

*******************************************************************************
*				FIN DU PROGRAMME			      *
*******************************************************************************

*******************************************************************************
* ROUTINE AGACYCLE							      *
*******************************************************************************
* ENTREE:D0.W=NB COULEUR(MAX 32), A0->PALETTE, A1->1°REG COULEUR	      *
*	 D3=VALEUR BANK COULEUR (BPLCON3)				      *
* UTILISE:D0,D1,D2,D3,A0,A1,A2						      *
* CHANGEMENT:AUCUN							      *
*******************************************************************************
AGACYCLE:
	MOVEM.L	D0-D4/A0-A2,-(A7)
	MOVE.W	AGCY,D1
	MOVE.L	A1,A2
	AND.L	#$FFFF,D1
	MOVE.L	D1,D2
	ADD.L	D1,D1
	ADD.L	D1,A2
	MOVE.L	D2,D1
	SUB.L	D0,D2
	NEG.L	D2			;D2=NBCOUL-POSITION

	TST.L	D2
	BEQ.S	AGACYCLE4
	SUBQ.B	#1,D2
AGACYCLE3:
	MOVE.W	D3,BPLCON3		
	MOVE.W	(A0)+,(A2)
	EOR.W	#$200,D3
	MOVE.W	D3,BPLCON3
	MOVE.W	(A0)+,(A2)+
	EOR.W	#$200,D3
	DBRA	D2,AGACYCLE3
AGACYCLE4:
	TST.W	D1
	BEQ.S	AGACYCLE6
	SUBQ.L	#1,D1
AGACYCLE5:
	MOVE.W	D3,BPLCON3
	MOVE.W	(A0)+,(A1)
	EOR.W	#$200,D3
	MOVE.W	D3,BPLCON3
	MOVE.W	(A0)+,(A1)+
	EOR.W	#$200,D3
	DBRA	D1,AGACYCLE5
AGACYCLE6:
	MOVE.W	AGCY,D1
	ADDQ.W	#1,D1
	CMP.W	D0,D1
	BNE.S	AGACYCLE2
	MOVEQ.L	#0,D1
AGACYCLE2:
	MOVE.W	D1,AGCY
	MOVEM.L	(A7)+,D0-D4/A0-A2
	RTS
AGCY:	DC.W	0			;POSITION

*******************************************************************************
* ROUTINE INITINTERPOL							      *
*******************************************************************************
* ENTREE:D0=NB POINT-1, A0->COORD DEPART, A1->COORD FIN, A2->BUFFER COEF      *
*	 A3->BUFFER COORD COURANT					      *
* CHANGEMENT:A0, A1, A2, A3,D0 , D1, D2,				      *
*******************************************************************************
INITINTERPOL:
	MOVE.W	(A1)+,D1
	MOVE.W	(A0)+,D2
	SUB.W	D2,D1
	MOVE.W	D1,(A2)+
	LSL.W	#8,D2
	MOVE.W	D2,(A3)+

	MOVE.W	(A1)+,D1
	MOVE.W	(A0)+,D2
	SUB.W	D2,D1
	MOVE.W	D1,(A2)+
	LSL.W	#8,D2
	MOVE.W	D2,(A3)+

	MOVE.W	(A1)+,D1
	MOVE.W	(A0)+,D2
	SUB.W	D2,D1
	MOVE.W	D1,(A2)+
	LSL.W	#8,D2
	MOVE.W	D2,(A3)+
	DBRA	D0,INITINTERPOL
	RTS

*******************************************************************************
* ROUTINE ROT3D								      *
*******************************************************************************
* ENTREE:D0=ANGLEX,D1=ANGLEY,D2=ANGLEZ					      *
* SORTIE->ROTA, ROTB, ROTC, ROTD, ROTE, ROTF, ROTG, ROTH, ROTI		      *
* CHANGEMENT: A5,A6,D3,D4,D5						      *
*******************************************************************************
ROT3D2:
	LEA	COS,A5			;A5->COS
	LEA	SIN,A6			;A6->SIN
	MOVE.W	D2,D5			;D5=AZ
	ADD.W	D1,D5			;D5=AZ+AY
	AND.W	#$FF,D5			;MASQUE
	MOVE.W	(A6,D5.W*2),D4		;D4=SIN(AZ+AY)
	MOVE.W	(A5,D5.W*2),D3		;D3=COS(AZ+AY)
	MOVE.W	D2,D5			;D5=AZ
	SUB.W	D1,D5			;D5=AZ-AY
	AND.W	#$FF,D5			;MASQUE
	ADD.W	(A5,D5.W*2),D3		;D3=D3+COS(AZ-AY)
	ADD.W	(A6,D5.W*2),D4		;D5=D5+SIN(AZ-AY)
	ASR.W	#1,D3			;D3=A=(COS(AZ+AX)+COS(AZ-AY))/2
	MOVE.W	D3,ROTA			;SAUVEGARDE ROTA
	ASR.W	#1,D4			;D4=B=(SIN(AZ+AY)+SIN(AZ-AY))/2
	MOVE.W	D4,ROTB			;SAUVEGARDE ROTB

	MOVE.W	D2,D5			;D5=AZ
	ADD.W	D1,D5			;D5=AZ+AY
	SUB.W	D0,D5			;D5=AZ+AY-AX
	AND.W	#$FF,D5			;MASQUE
	MOVE.W	(A6,D5.W*2),D4		;D4=SIN(AZ+AY-AX)
	MOVE.W	(A5,D5.W*2),D3		;D3=COS(AZ+AY-AX)
	MOVE.W	D2,D5			;D5=AZ
	SUB.W	D1,D5			;D5=AZ-AY
	ADD.W	D0,D5			;D5=AZ-AY+AX
	AND.W	#$FF,D5			;MASQUE
	ADD.W	(A5,D5.W*2),D3		;D3=D3+COS(AZ-AY+AX)
	ADD.W	(A6,D5.W*2),D4		;D4=D4+COS(AZ-AY+AX)
	MOVE.W	D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TC

	MOVE.W	D1,D5			;D5=AY
	ADD.W	D0,D5			;D5=AY+AX
	AND.W	#$FF,D5			;MASQUE
	MOVE.W	(A6,D5.W*2),D3		;D3=SIN(AY+AX)
	MOVE.W	(A5,D5.W*2),D4		;D4=COS(AY+AX)
	MOVE.W	D0,D5			;D5=AX
	SUB.W	D2,D5			;D5=-AY+AX
	AND.W	#$FF,D5			;MASQUE
	ADD.W	(A6,D5.W*2),D3		;D3=D3+SIN(-AY+AX)
	ASR.W	#1,D3			;D3=D3/2=F
	ADD.W	(A5,D5.W*2),D4		;D4=D4+COS(-AY+AX)
	ASR.W	#1,D4			;D4=D4/2=I
	MOVE.W	D3,ROTF			;SAUVEGARDE ROTF
	MOVE.W	D4,ROTI			;SAUVEGARSE ROTI
RTS
ROTA:	DC.W	0
ROTB:	DC.W	0
ROTC:	DC.W	0
ROTD:	DC.W	0
ROTE:	DC.W	0
ROTF:	DC.W	0
ROTG:	DC.W	0
ROTH:	DC.W	0
ROTI:	DC.W	0
BLTFILL:
	MOVE.W	#$09F0,BLTCON0
	MOVE.W	#$12,BLTCON1
	MOVE.L	#$FFFFFFFF,BLTAFWM
	MOVE.L	SCREEN1,A0
	ADD.L	#200*40,A0
	MOVE.L	A0,BLTAPTH
	MOVE.L	A0,BLTDPTH
	MOVE.W	#0,BLTAMOD
	MOVE.W	#0,BLTDMOD
	BLTWAIT
	MOVE.W	#200*40+20,BLTSIZE
	RTS

*******************************************************************************
* ROUTINE LIGNE3D PAR LA METHODE DE BRESENHAM
*******************************************************************************
* ENTREE:D0=X1,D1=Y1,D2=X2,D3=Y3,A0=BUFFER(LONGUEUR=LONG_Y.W*2)
*	 BUFFER=800080008000.....
* SORTIE:XMIN-XMAX DANS BUFFER
* CHANGEMENT:RIEN
* FONCTION:ECRIT DANS UN BUFFER LES XMIN-XMAX D'UNE SURFACE
* MECHANTE CONVERTION DU 386, TRES OPTIMISABLE!
*******************************************************************************
LIGNE3D:
	MOVE.W	D0,D4
	MOVE.W	D1,D5
	MOVE.W	D2,D6
	MOVE.W	D3,D7

	MOVE.W	D3,D4		;D3=X1
	MOVE.W	D2,D5		;D2=Y1
	MOVE.W	D4,D6		;D4=X2
	MOVE.W	D0,D7		;D0=Y2

	MOVE.W	D0,D5		;MOV 	BP,AX
	MOVE.W	D2,D6		;MOV	DS,CX
	MOVE.W	D4,D1		;MOV	BX,SI
	SUB.W	D3,D1		;SUB	BX,DX
	BLE.S	LIGNE3D0	;JNS	LIGNE3D0
	NEG.W	D1		;NEG	BX
LIGNE3D0:
	MOVE.W	D1,D2		;MOV	CX,BX
	MOVE.W	D6,D0		;MOV	AX,DS
	MOVE.W	D5,D1		;MOV	BX,BP
	SUB.W	D0,D1		;SUB	BX,AX
	BLE.S	LIGNE3D1	;JNS	LIGNE3D1
	NEG.W	D1		;NEG	BX
LIGNE3D1:
LIGNE3D2:
LIGNE3D3:
	CMP.W	D2,D1		;CMP	CX,BX
	BHI.S	LIGNE3D2	;JB	LIGNE3D2
	MOVE.W	D1,D0		;MOV	AX,BX
	LSL.W	#1,D0		;SHL	AX,1
	MOVE.W	D0,-(A7)	;PUSH	AX
	SUB.W	D2,D0		;SUB	AX,CX
	MOVE.W	(A7)+,D2	;POP	CX
	LSL.W	#1,D0		;SHL	AX,1
	MOVE.W	D0,-(A7)	;PUSH	AX
	MOVE.W	D1,-(A7)	;PUSH	BX
	CMP.W	D3,D4		;CMP	DX,SI
	BHI.S	LIGNE3D3	;JLE	LIGNE3D3
	MOVE.W	D3,D4		;MOV	DLIGNE3DV,DX
	MOVE.W	D4,D3		;MOV	DX,SI

	

*******************************************************************************
* ROUTINE PAYSAGE
*******************************************************************************
* ENTREE:PAY_0->1° ECRAN,PAY_1->2°ECRAN,PAY_2->3°ECRAN,PAY_7->TABLE *40
*	 PAY_8->PAYSAGE TRUE, PAY_9->TABLES POINTS, PAY_A->COPPERLIST
* SORTIE:AUCUNE
* CHANGEMENT:RIEN
* FONCTION:AFFICHE UN DOTS LANDSCAPE
*******************************************************************************
PAYSAGE:
PAY_X=38
PAY_Y=43
	MOVEM.L	D0-D7/A0-A6,-(A7)
	TST.B	PAY_B			;TEST D'INIT
	BNE.W	PAY0
	MOVE.B	#1,PAY_B		;INITIALISATION
	LEA	J_IRQLOAD,A0
	MOVE.L	SAVE_VECT_IRQ,(A0)
	MOVE.W 	#$000F,$DFF096		;RESTAURE IRQ, INTENA ET DMACON
	MOVE.W 	#$4000,$DFF09A
	MOVE.L 	#IRQLOAD,$6C.W		;PREPARE IQRLOAD
	MOVE.W 	#$7FFF,$DFF09A
	MOVE.W 	#$E03C,$DFF09A
	MOVE.W 	#$7FFF,$DFF096
	MOVE.W	SAVE_DMACON,$DFF096

	MOVE.L	DOSBASE,A6		;A6->DOSBASE
	MOVE.L	#PAYSAGE_MST,D1		;D1->NOM DE FICHIER
	MOVE.L	#1005,D2		;D2=OUVERTURE NO CREATION (SINON 1004)
	JSR	-30(A6)			;OUVERTURE FICHIER
	MOVE.L	D0,D1			;D1=HANDLE
	MOVE.L	D0,-(A7)		;SAUVEGARDE HANDLE

;	MOVE.L	#818,D2			;D2->DEPLACEMENT
;	MOVE.L	#-1,D3			;D3=LONGUEUR
;	JSR	-66(A6)			;CHANGEMENT POINTEUR FICHIER (SEEK)

	MOVE.L	(A7)+,D1
	MOVE.L	D1,-(A7)
	MOVE.L	PAY_8,D2		;D2->DESTINATION
	MOVE.L	#64829,D3		;D3=LONGUEUR
	JSR	-42(A6)			;CHARGEMENT FICHIER

	MOVE.L	(A7)+,D1		;D1=HANDLE
	JSR	-36(A6)			;FERMETURE FICHIER

;	MOVE.L	SCREEN7,A5
;	ADD.L	#818,A5
;	MOVE.L	SCREEN8,A6
;	MOVE.L	#$0FA00,D7
;	BSR.W	DECOMP

	MOVE.L	DOSBASE,A6		;A6->DOSBASE
	MOVE.L	#POINTS_DAT,D1		;D1->NOM DE FICHIER
	MOVE.L	#1005,D2		;D2=OUVERTURE NO CREATION (SINON 1006)
	JSR	-30(A6)			;OUVERTURE FICHIER
	MOVE.L	D0,D1			;D1=HANDLE
	MOVE.L	D0,-(A7)		;SAUVEGARDE HANDLE
	MOVE.L	PAY_9,D2		;D2->DESTINATION
	MOVE.L	#4902,D3		;LONGUEUR
	JSR	-42(A6)			;CHARGEMENT FICHIER
	MOVE.L	(A7)+,D1		;D1=HANDLE
	JSR	-36(A6)			;FERMETURE FICHIER

	MOVE.W	#$87C0,$DFF096		;REPLACE L'IRQ, INTENA ET DMACON
	MOVE.W	#$3FFF,$DFF09A
	MOVE.L	#IRQ,$6C.W
	MOVE.W	#$C010,$DFF09A

	MOVE.B	#%10000111,$BFD100	;COUPE MOTEURS DRIVES

;AFFECTE LA PALETTE DE PAYSAGE.MST
;---------------------------------
	MOVE.L	PAY_8,A0
	ADDA	#50,A0
	MOVE.W	#$C00,D3
	MOVEQ.L	#7,D4
COUL4:
	LEA	$DFF180,A1
	MOVE.W	D3,BPLCON3
	MOVE.L	#31,D2
	MOVEQ.L	#0,D1
COUL3:
	MOVE.B	(A0)+,D1
	LSL.B	#2,D1
	OR.B	#$3,D1
	MOVE.B	D1,D7
	AND.B	#$F,D7
	MOVE.B	D7,D5
	LSL.W	#4,D5
	LSR.B	#4,D1
	MOVE.B	D1,D6
	LSL.W	#4,D6

	MOVE.B	(A0)+,D1
	LSL.B	#2,D1
	OR.B	#$3,D1
	MOVE.B	D1,D7
	AND.B	#$F,D7
	OR.B	D7,D5
	LSL.W	#4,D5
	LSR.B	#4,D1
	OR.B	D1,D6
	LSL.W	#4,D6

	MOVE.B	(A0)+,D1
	LSL.B	#2,D1
	OR.B	#$3,D1
	MOVE.B	D1,D7
	AND.B	#$F,D7
	OR.B	D7,D5		;D5=LSB
	LSR.B	#4,D1
	OR.B	D1,D6		;D6=MSB

	EOR.W	#$200,D3
	MOVE.W	D3,BPLCON3
	MOVE.W	D5,(A1)
	EOR.W	#$200,D3
	MOVE.W	D3,BPLCON3
	MOVE.W	D6,(A1)+
	DBRA	D2,COUL3

	ADD.W	#$2000,D3
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TDPTH			;EFFACE
	MOVE.W	#0,BLTDMOD
	MOVE.L	#$FFFFFFFF,BLTAFWM
	MOVE.L	#$01000000,BLTCON0
	BLTWAIT
	MOVE.W	#64*256*3+20,BLTSIZE

	ADDQ.L	#2,PAY_3
	CMP.L	#256*2,PAY_3
	BNE.S	PAYB
	MOVE.L	#0,PAY_3
PAYB:	LEA	SIN,A1
	MOVE.L	PAY_8,A0		;A0->PAYSAGE
	ADD.L	#818,A0
	MOVE.L	PAY_3,D0
	MOVE.W	(A1,D0.W),D1
	ASR.W	#1,D1
	EXT.L	D1
	ADD.L	#128,D1
	ADD.L	D1,A0

	MOVEQ.L	#0,D0
	ADD.B	#200,PAY_4
	ADDX.L	D0,D0
	ADD.L	D0,D0
	ADD.L	D0,PAY_5
	CMP.L	#256*2,PAY_5
	BLS.S	PAYC
	MOVE.L	#0,PAY_5
PAYC:
	LEA	SIN,A1
	MOVE.L	PAY_5,D0
	MOVE.W	(A1,D0.W),D1
	MULS.W	#78,D1
	ASR.W	#8,D1
	MULS.W	#320,D1
	EXT.L	D1
	ADD.L	#78*320,D1
	ADD.L	D1,A0

	MOVE.L	PAY_9,A1		;A1->TABLE POINTS
	MOVE.W	#PAY_Y-1,D1		;D1=COMPTEUR Y
	MOVE.W	#3,D3			;ROTATION POUR AFFICHAGE POINTS
	MOVE.L	PAY_0,A3
	MOVE.L	A3,A4
	ADD.L	#256*40,A4
	MOVE.L	A4,A6
	ADD.L	#256*40,A6

;AFFICHAGE POINTS
;ENTREE:A1->TABLE POINTS, A0->PAYSAGE, A3->PLAN1, A4->PLAN2, A5->TABLE*40
;	A6->PLAN3, D0->COMPTEUR X, D1->COMPTEUR Y, D3->ROTATION
;UTILISE:D0->COMPTEUR X, D5->PROFONDEUR, D6->MASQUE, D7->Y, D4, D5, D6, D7
;-------------------------------------------------------------------------
PAY2:	
	MOVE.W	#PAY_X-1,D0		;D0=X
PAY1:
	MOVE.B	(A1)+,D6		;D6=MASQUEX
	MOVE.W	(A1)+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_X,A0
	DBRA	D1,PAY2
	MOVEM.L	(A7)+,D0-D7/A0-A6
	RTS
PAY_0:	DC.L	0
PAY_1:	DC.L	0
PAY_2:	DC.L	0
PAY_3:	DC.L	0
PAY_4:	DC.L	0
PAY_5:	DC.L	0
PAY_6:	DC.L	0
PAY_7:	DC.L	0
PAY_8:	DC.L	0
PAY_9:	DC.L	0
PAY_A:	DC.L	0
PAY_B:	DC.L	0


*******************************************************************************
* ROUTINE TUNELCLE BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:CLE1->1° ECRAN,CLE2->2°ECRAN,CLE9->SUITECOPPERLIST,CLEA->3°ECRAN,
*	CLEB->CERCLES
* SORTIE:AUCUNE
* CHANGEMENT:D2,D3,D4,D5,D6,D7,A5,A6
* FONCTION:TRACE UNE LIGNE AU BLITTER
*******************************************************************************
TUNELCLE:

;INITIALISATION
;--------------
	ESPCLE=4			;ESPACE ENTRE CHAQUE CERCLES
	NBCCLE=46*4/ESPCLE		;NOMBRE CERCLE
	BNPCLE=60			;NOMBRE POINT/CERCLE
	MOVEM.L	D0-D7/A0-A6,-(SP)
	TST.B	CLE0
	BNE.W	MAINCLE

	MOVE.W	#$F09,$DFF182		;COULEUR 1
	MOVE.W	#$55A,$DFF184		;COULEUR 2
	MOVE.W	#$F09,$DFF186		;COULEUR 3

	MOVE.L	CLE2,D4
	MOVE.L	CLE9,A3
	MOVE.W  #$E2,(A3)+
	MOVE.W	D4,(A3)+
	MOVE.W	#$E0,(A3)+
	SWAP	D4
	MOVE.W	D4,(A3)+
	SWAP	D4

	MOVE.L	#$1001200,(A3)+		;MODE GRAPHIQUE 1 PLAN

	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800000,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$1800000,(A3)+

	MOVE.W	#$280F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800004,(A3)+

	MOVE.W	#$300F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800008,(A3)+

	MOVE.W	#$380F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$180000C,(A3)+

	MOVE.W	#$400F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800001,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$1800000,(A3)+

	MOVE.W	#$480F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800004,(A3)+

	MOVE.W	#$500F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800008,(A3)+

	MOVE.W	#$580F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$180000C,(A3)+

	MOVE.W	#$600F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800002,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$1800000,(A3)+

	MOVE.W	#$680F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800004,(A3)+

	MOVE.W	#$700F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800008,(A3)+

	MOVE.W	#$780F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$180000C,(A3)+

	MOVE.W	#$800F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800003,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$1800000,(A3)+

	MOVE.W	#$880F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800004,(A3)+

	MOVE.W	#$900F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800008,(A3)+

	MOVE.W	#$980F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$180000C,(A3)+

	MOVE.W	#$A00F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800004,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$1800000,(A3)+

	MOVE.W	#$A80F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800004,(A3)+

	MOVE.W	#$B00F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800008,(A3)+

	MOVE.W	#$B80F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$180000C,(A3)+

	MOVE.W	#$C00F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800005,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$1800000,(A3)+

	MOVE.W	#$C80F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800004,(A3)+

	MOVE.W	#$D00F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800008,(A3)+

	MOVE.W	#$D80F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$180000C,(A3)+

	MOVE.W	#$E00F,(A3)+		;RASTER GRIS
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800225,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$180066C,(A3)+

	MOVE.L	#$1002200,(A3)+		;MODE GRAPHIQUE 2 PLAN
	MOVE.W	#$10A,(A3)+		;MODULO PLANS PAIRS
	MOVE.W	#-120,(A3)+		;REFLECTION NEGATIVE (-40-80)

	MOVE.W  #$E6,(A3)+		;ADRESSE 2° PLAN
	ADD.L	#40*175,D4
	MOVE.W	D4,(A3)+
	MOVE.W	#$E4,(A3)+
	SWAP 	D4
	MOVE.W	D4,(A3)+

	MOVE.W	#$E40F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800448,(A3)+

	MOVE.W	#$E80F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800224,(A3)+

	MOVE.W	#$EC0F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800000,(A3)+

	MOVE.W	#$F00F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800114,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$1800EEC,(A3)+

	MOVE.W	#$F40F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800CC8,(A3)+

	MOVE.W	#$F80F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800AA4,(A3)+

	MOVE.W	#$FC0F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800880,(A3)+

	MOVE.W	#$FFDF,(A3)+		;ATTENTE LIGNE 255
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800113,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$180066C,(A3)+

	MOVE.W	#$040F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800448,(A3)+

	MOVE.W	#$080F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800224,(A3)+

	MOVE.W	#$0C0F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800000,(A3)+

	MOVE.W	#$100F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800002,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$1800EEC,(A3)+

	MOVE.W	#$140F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800CC8,(A3)+

	MOVE.W	#$180F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800AA4,(A3)+

	MOVE.W	#$1C0F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800880,(A3)+

	MOVE.W	#$200F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE
	MOVE.L	#$1800001,(A3)+
	MOVE.L	#$1060E00,(A3)+		;LSB PALETTE
	MOVE.L	#$180066C,(A3)+

	MOVE.W	#$240F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800448,(A3)+

	MOVE.W	#$280F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800224,(A3)+

	MOVE.W	#$2C0F,(A3)+
	MOVE.W	#$FFFE,(A3)+
	MOVE.L	#$1800000,(A3)+

	MOVE.L	#$1060C00,(A3)+		;MSB PALETTE

	MOVE.L	#$009C8010,(A3)+
	MOVE.L	#$FFFFFFFE,(A3)+	;STRUCTURE FIN COPPERLIST

	LEA	CLE4(PC),A0
	ADD.L	#NBCCLE*12,A0
	MOVE.L	A0,CLE3			;CLE4->1° BUFFER CLE4+NBCCLE*4->2° BUFFER
	MOVE.B	#1,CLE0
	MOVE.L	CLEB,A0			;A0->CERCLES
	LEA	CLE4(PC),A2		;A2->1° BUFFER
	MOVE.L	#NBCCLE,D1
INITCLE:MOVE.L	A0,(A2)+		;(SCREEN9(0))->CERCLES
	MOVE.L  #0,(A2)+
	MOVE.L	#$FFF,(A2)+
	ADD.L	#4*BNPCLE*ESPCLE,A0		;A0=A0+ESPCLE*144
	DBRA	D1,INITCLE

	MOVEM.L	(SP)+,D0-D7/A0-A6
	RTS

;MAINCLE
;ENTREE:D2
;CHANGEMENT:D2
;-------------
MAINCLE:

;SYNCHRONISATION+CHANGE ECRAN VISUEL:SCREEN2 ET TRAVAIL:SCREEN1
;ENTREE:SCREEN1,SCREEN2,CLE4,CLE9
;CHANGE:D0,D4,A2,A3,A6
;--------------------------------------------------------------

	BLTWAIT

	MOVE.L	CLE2,D4
	MOVE.L	CLE9,A3
	MOVE.W  #$E2,(A3)+
	MOVE.W	D4,(A3)+
	MOVE.W	#$E0,(A3)+
	SWAP	D4
	MOVE.W	D4,(A3)+
	SWAP	D4
	ADD.L	#292,A3
	MOVE.W  #$E6,(A3)+		;ADRESSE 2° PLAN
	ADD.L	#40*175,D4
	MOVE.W	D4,(A3)+
	MOVE.W	#$E4,(A3)+
	SWAP 	D4
	MOVE.W	D4,(A3)+

	LEA	CLE4(PC),A2
	LEA	CLE5(PC),A3

	MOVE.L	CLE1,BLTDPTH
	MOVE.W	#0,BLTDMOD
	MOVE.L	#$FFFFFFFF,BLTAFWM
	MOVE.L	#$01000000,BLTCON0
	MOVE.W	#64*256+20,BLTSIZE

	MOVE.L	CLEA,A6

	MOVE.L	CLE1,D0			;ECHANGE ECRAN
	MOVE.L	CLE2,CLE1
	MOVE.L	D0,CLE2
	MOVE.L	CLEA,D0
	MOVE.L	CLE2,CLEA
	MOVE.L	D0,CLE2

;INCREMENTE CERCLES
;ENTREE:A2,CERCLES
;CHANGE:D1,D6,D7,A1
;---------------------

	MOVEQ.L	#0,D1
EFFACECLE:	
	MOVE.L	(A2,D1),A1		;A1=(CLE4)
	ADD.L	#4*BNPCLE,A1
	MOVE.L	A1,D0
	SUB.L	CLEB,D0
	CMP.L	#4*BNPCLE*NBCCLE*ESPCLE,D0
	BNE.W	SUITECLE
	MOVE.L	CLEB,(A2,D1)

	LEA	SIN,A0
	MOVE.L	CLE7,D7
	MOVE.W	(A0,D7),D7
	EXT.L	D7
	ASR.W	#2,D7
	SUB.W	#64,D7
	MOVE.L	D7,8(A2,D1)
	MOVE.L	D7,CLE8

	MOVE.L	CLE5,4(A2,D1)

	BRA.S	SUITECLE2
SUITECLE:
	MOVE.L	A1,(A2,D1)		;(CLE4(D1))=A1 (SAUVEGARDE)
SUITECLE2:
	ADD.W	#12,D1			;D1=D1+12
	CMP.W	#12*NBCCLE,D1		;IF D1<>4*NBCCLE THEN
	BNE.W	EFFACECLE		; GOTO EFFACECLE:END IF

	ADDQ.L	#2,CLE7			;CLE7=COMPTEUR POUR Y=SIN(CLE7)
	CMP.L	#512,CLE7
	BNE.S	SINCLE
	MOVE.L	#0,CLE7
SINCLE:
	TST.B	CLE6
	BNE.B	POSCLE
	ADDQ.L	#1,CLE5
	CMP.L	#100,CLE5
	BLE.S	POSCLE_
	MOVE.B	#2,CLE6
	BRA.B	POSCLE_
POSCLE:
	SUBQ.L	#1,CLE5
	CMP.L	#-100,CLE5
	BGE.S	POSCLE_
	MOVE.B	#0,CLE6
POSCLE_:

;AFFICHAGE CERCLES
;ENTREE:A2,A6
;CHANGE:D0,D1,D6,D7,A1
;---------------------

	MOVEQ.L	#0,D1			;D1=0 (COMPTEUR CERCLES*4)
AFFICHECLE:
	MOVE.L	(A2,D1),A1		;A1=(CLE4(D1))
	MOVE.L	4(A2,D1),D2		;D2=OFFSET X
	MOVE.L	8(A2,D1),A3		;D3=OFFSET Y
	MOVE.W	#319,D0
	MOVE.W	#255,D3
	MOVE.L	#BNPCLE-1,D4
CERCLE1:
	MOVE.W	(A1)+,D6		;D6=X(A1):A1=A1+1
	MOVE.W	(A1)+,D7		;D7=Y(A1):A1=A1+1
	ADD.W	D2,D6			;ADDITION X
	ADD.W	A3,D7			;ADDITION Y
	CMP.W	D0,D6			;TEST LIMITE ECRAN
	BHI.S	NOCERCLE1
	CMP.W	D3,D7
	BHI.W	NOCERCLE1
	PSET320				;AFFICHE POINT
NOCERCLE1:
	DBRA	D4,CERCLE1
	ADD.W	#12,D1			;D1=D1+12
	CMP.W	#12*NBCCLE,D1		;IF D1<>12*NBCCLE THEN
	BNE.W	AFFICHECLE		; GOTO AFFICHECLE:END IF
	MOVEM.L	(SP)+,D0-D7/A0-A6
	RTS

CLE0:	DC.L	0
CLE1:	DC.L	0
CLE2:	DC.L	0
CLE3:	DC.L	0
CLE4:	DS.L	NBCCLE*12
CLE5:	DC.L	0
CLE6:	DC.L	0
CLE7:	DC.L	0
CLE8:	DC.L	0
CLE9:	DC.L	0
CLEA:	DC.L	0
CLEB:	DC.L	0

*******************************************************************************
* ROUTINE 3D BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:D5.W->X, D6.W->Y, D7.W->Z, A4.W->ROTX, A5.W->ROTY, A6.W->ROTZ
* SORTIE:?
* CHANGEMENT:?
* FONCTION:?
*******************************************************************************

*******************************************************************************
* ROUTINE BLTMOVE BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:A5.L->SOURCE, A6.L->CIBLE, D7.W->FENETRE (HAUTEUR BITS 6-15 
*       LONGUEUR BITS 0-5)
* SORTIE:AUCUNE
* CHANGEMENT:AUCUN
* FONCTION:COPIE AVEC LE BLITTER (68020 + RAPIDE)
*******************************************************************************
BLTMOVE:
	MOVE.L	A5,BLTAPTH
	MOVE.L	A6,BLTDPTH
	MOVE.W	#0,BLTAMOD
	MOVE.W	#0,BLTDMOD
	MOVE.L	#$FFFFFFFF,BLTAFWM
	MOVE.L	#$09F00000,BLTCON0
BLTWT:
	BTST	#14,$DFF002
	BNE.S	BLTWT
	MOVE.W	D7,BLTSIZE
	RTS

*******************************************************************************
* ROUTINE DECOMP BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:A5->SOURCE, A6->DESTINATION, D7->LONGUEUR
* SORTIE:AUCUNE
* CHANGEMENT:D0,D2
* FONCTION:ATTEND LA SYNCHRONISATION VERTICALE
*******************************************************************************
DECOMP:
	MOVE.L	A6,D1
	ADD.L	D7,D1
DECOMP1:
	MOVE.B	(A5)+,D2
	CMP.B	#127,D2
	BHI.S	REPET1
	MOVE.B	(A5)+,D0
	AND.L	#$FF,D2
REPET2:
	MOVE.B	D0,(A6)+
	DBF	D2,REPET2	
	CMP.L	A6,D1
	BCS.S	FINDECOMP
	BRA.S	DECOMP1
REPET1:
	SUB.B	#128,D2
	AND.L	#$FF,D2
REPET3:
	MOVE.B	(A5)+,(A6)+
	DBF	D2,REPET3
	CMP.L	A6,D1
	BCS.S	FINDECOMP
	BRA.B	DECOMP1
FINDECOMP:
	RTS
	
*******************************************************************************
* ROUTINE TRUE2PLANE BY PYRO/ARKHAM
*******************************************************************************
* ENTREE:A5->SOURCE, A6->DESTINATION,D6->LONGUEUR/8,D7->PLAN
* SORTIE:AUCUNE
* CHANGEMENT:D0,D1,D2,D6,D7,A5,A6
* FONCTION:TRANSFERT UNE IMAGE TRUE COLOR EN IMAGE PAR PLAN
*******************************************************************************
TRUE2PLANE:
	SUBQ.B	#1,D6
	SUBQ.B	#1,D7
TO1:
	MOVEQ.L	#0,D1
	MOVE.B	(A5)+,D0
	BTST	D7,D0
	BEQ.S	T1
	MOVE.B	#%10000000,D1
T1:
	MOVE.B	(A5)+,D0
	BTST	D7,D0
	BEQ.S	T2
	OR.B	#%1000000,D1
T2:
	MOVE.B	(A5)+,D0
	BTST	D7,D0
	BEQ.S	T3
	OR.B	#%100000,D1
T3:
	MOVE.B	(A5)+,D0
	BTST	D7,D0
	BEQ.S	T4
	OR.B	#%10000,D1
T4:
	MOVE.B	(A5)+,D0
	BTST	D7,D0
	BEQ.S	T5
	OR.B	#%1000,D1
T5:
	MOVE.B	(A5)+,D0
	BTST	D7,D0
	BEQ.S	T6
	OR.B	#%100,D1
T6:
	MOVE.B	(A5)+,D0
	BTST	D7,D0
	BEQ.S	T7
	OR.B	#%10,D1
T7:
	MOVE.B	(A5)+,D0
	BTST	D7,D0
	BEQ.S	T8
	OR.B	#%1,D1
T8:
	MOVE.B	D1,(A6)+
	DBF	D6,TO1
	RTS
	
ATTENTE:
	MOVEM.L	D0,-(SP)
	MOVE.L	#7000,D0
ATT2:
	DBF	D0,ATT2
	MOVEM.L	(SP)+,D0
	RTS
		
SAVE_SYSTEM:
	MOVE.B	#%10010111,$BFD100
	MOVE.L	4,A6
	JSR	-132(A6)		;SUPPRESSION MULTITACHE
	MOVE.L	$6C,SAVE_VECT_IRQ
	MOVE.W	$DFF01C,SAVE_INTENA
	OR.W	#$C000,SAVE_INTENA
	MOVE.W	$DFF002,SAVE_DMACON
	OR.W	#$8100,SAVE_DMACON
	LEA	DOSNAME,A1
	MOVEQ.L	#0,D0
	MOVE.L	4,A6			;A6->EXECBASE
	JSR	-552(A6)		;OPENLIBRARY
	TST.L	D0			;SI ERREUR
	BEQ.W	FIN			;FIN
	MOVE.L	D0,DOSBASE		;SAUVEGARDE DOSBASE
	LEA	CACHE,A5		;ROUTINE ACTIVATION CACHE CPU
	MOVE.L	4,A6			;A6=EXECBASE
	JSR	-30(A6)			;SUPERVISEUR
	MOVE.L	#ZONE,D0		;ZONE VIDEO
	AND.L	#$FFFFFFF8,D0
	ADD.L	#8,D0
	MOVE.L	D0,A0
	MOVE.L	A0,SCREEN1
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREEN2
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREEN3
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREEN4
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREEN5
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREEN6
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREEN7
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREEN8
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREEN9
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREENA
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREENB
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREENC
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREEND
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREENE
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREENF
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREENG
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREENH
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREENI
	ADD.L	#256*40,A0
	MOVE.L	A0,SCREENJ
	RTS

RESTORE_SYSTEM:
	MOVE.W 	#$000F,$DFF096
	MOVE.W 	#$4000,$DFF09A
	MOVE.L 	SAVE_VECT_IRQ,$6C
	MOVE.W 	#$7FFF,$DFF09a
	MOVE.W 	SAVE_INTENA,$DFF09A
	MOVE.W 	#$7FFF,$DFF096
	MOVE.W	SAVE_DMACON,$DFF096
	MOVE.L	4,A6
	LEA	NAME_GLIB,A1
	MOVEQ 	#0,D0
	JSR 	-552(A6)
	MOVE.L	D0,A0
	MOVE.L	38(A0),$DFF080
	MOVE.W	#0,$DFF088
	JSR 	-138(A6)		;RESTORE MULTITACHE
	MOVE.L	DOSBASE,A1		;A1=DOSBASE
	JSR	-414(A6)		;FERMETURE LIBRARY
	MOVE.L	D0,A1
	JSR 	-414(A6)
	RTS

IRQ:
	MOVEM.L	D0-D7/A0-A6,-(SP)	;SAUVE TOUT LES REGISTRE SUR PILE
	MOVE.W	$DFF01C,D0
	AND.W 	$DFF01E,D0
	BTST 	#4,D0
	BEQ.S 	FIN_IRQ
	MOVE.W	#$10,$DFF09C
	BSR.W	MT_MUSIC		;ROUTINE SOUNDTRACK
FIN_IRQ:
	MOVEM.L	(SP)+,D0-D7/A0-A6	;RESTORE TOUT LES REGISTRES
	RTE

IRQLOAD:
	MOVEM.L	D0-D7/A0-A6,-(SP)	;SAUVE TOUT LES REGISTRE SUR PILE
	MOVE.W	$DFF01C,D0
	AND.W 	$DFF01E,D0
	BTST 	#4,D0
	BEQ.S 	FIN_IRQLOAD
	MOVE.W	#$10,$DFF09C
	BSR.W 	MT_MUSIC		;APPEL ROUTINE MUSIQUE
FIN_IRQLOAD:
	MOVEM.L	(SP)+,D0-D7/A0-A6	;RESTORE TOUT LES REGISTRES
	DC.W	$4EF9			;JMP SAVE_VECT_IRQ
J_IRQLOAD:
	DC.L	0

MAKE_CL:
	LEA	SUITECOPPERLIST,A0

	MOVE.W  #$E2,(A0)+
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A4),D0
	CMP.B	#$1F,D0
	BLS.S	MT_SP2
	MOVEQ	#$1F,D0
MT_SP2:	
	TST.W	D0
	BNE.S	MT_SP3
	MOVEQ	#1,D0
MT_SP3:	
	MOVE.B	D0,MT_SPEED
	RTS

MT_PERIODS:
	DC.W	$358,$328,$2FA,$2D0,$2A6,$280,$25C,$23A,$21A,$1FC,$1E0
	DC.W	$1C5,$1AC,$194,$17D,$168,$153,$140,$12E,$11D,$10D,$FE
	DC.W	$F0,$E2,$D6,$CA,$BE,$B4,$AA,$A0,$97,$8F,$87
	DC.W	$7F,$78,$71,0

MT_SPEED:	
	DC.B	6
MT_COUNTER:	
	DC.B	0
MT_PATTPOS:	
	DC.W	0
MT_SONGPOS:	
	DC.B	0
MT_BREAK:	
	DC.B	0
MT_DMACON:	
	DC.W	0
MT_SAMPLESTARTS:
	BLK.L	$1F,0
MT_VOICE1:	
	BLK.W	13,0
	DC.W	1
MT_VOICE2:	
	BLK.W	13,0
	DC.W	2
MT_VOICE3:	
	BLK.W	13,0
	DC.W	4
MT_VOICE4:	
	BLK.W	13,0
	DC.W	8
	EVEN				;FIN ROUTINE MUSIQUE

MT_DATA:
	INCBIN	"DF0:RAGE.MOD"

;DEFINITION DES VARIABLES
;------------------------
COPPERLIST:
	DC.L	$01FC0003				;A1200
	DC.L 	$01200000,$01220000,$01240000,$01260000
	DC.L 	$01280000,$012A0000,$012C0000,$012E0000
	DC.L 	$01300000,$01320000,$01340000,$01360000
	DC.L 	$01380000,$013A0000,$013C0000,$013E0000
	DC.L 	$008E3081,$009030C1,$00920038,$009400A0	;38 A0->A1200
	DC.L 	$01080000,$010A0000,$01020000,$01040000
SUITECOPPERLIST:
	DS.B 	5000
SAVE_INTENA:
	DC.W 	0
SAVE_DMACON:
	DC.W 	0
SAVE_VECT_IRQ:
	DC.L 	0
NAME_GLIB:
	DC.B	"graphics.library",0
	EVEN

SCREEN1:DC.L	0
SCREEN2:DC.L	0
SCREEN3:DC.L	0
SCREEN4:DC.L	0
SCREEN5:DC.L	0
SCREEN6:DC.L	0
SCREEN7:DC.L	0
SCREEN8:DC.L	0
SCREEN9:DC.L	0
SCREENA:DC.L	0
SCREENB:DC.L	0
SCREENC:DC.L	0
SCREEND:DC.L	0
SCREENE:DC.L	0
SCREENF:DC.L	0
SCREENG:DC.L	0
SCREENH:DC.L	0
SCREENI:DC.L	0
SCREENJ:DC.L	0
ZONE:	DS.L	11*256*18		;MEMOIRE VIDEO

B0:	DC.L	0
B1:	DC.L	0
B2:	DC.L	0
B3:	DC.L	0			
B4:	DC.L	0
B5:	DC.L	0
B6:	DC.L	0
B7:	DC.L	0			
B8:	DC.L	0
B9:	DC.L	0

COS:
	DC.W	256,255,255,255,254,254,253,252
	DC.W	251,249,248,246,244,243,241,238
	DC.W	236,234,231,228,225,222,219,216
	DC.W	212,209,205,201,197,193,189,185
	DC.W	181,176,171,167,162,157,152,147
	DC.W	142,136,131,126,120,115,109,103
	DC.W	97,92,86,80,74,68,62,56
	DC.W	49,43,37,31,25,18,12,6
	DC.W	0,-6,-12,-18,-25,-31,-37,-43
	DC.W	-49,-56,-62,-68,-74,-80,-86,-92
	DC.W	-97,-103,-109,-115,-120,-126,-131,-136
	DC.W	-142,-147,-152,-157,-162,-167,-171,-176
	DC.W	-181,-185,-189,-193,-197,-201,-205,-209
	DC.W	-212,-216,-219,-222,-225,-228,-231,-234
	DC.W	-236,-238,-241,-243,-244,-246,-248,-249
	DC.W	-251,-252,-253,-254,-254,-255,-255,-255
	DC.W	-256,-255,-255,-255,-254,-254,-253,-252
	DC.W	-251,-249,-248,-246,-244,-243,-241,-238
	DC.W	-236,-234,-231,-228,-225,-222,-219,-216
	DC.W	-212,-209,-205,-201,-197,-193,-189,-185
	DC.W	-181,-176,-171,-167,-162,-157,-152,-147
	DC.W	-142,-136,-131,-126,-120,-115,-109,-103
	DC.W	-97,-92,-86,-80,-74,-68,-62,-56
	DC.W	-49,-43,-37,-31,-25,-18,-12,-6
	DC.W	0,6,12,18,25,31,37,43
	DC.W	49,56,62,68,74,80,86,92
	DC.W	97,103,109,115,120,126,131,136
	DC.W	142,147,152,157,162,167,171,176
	DC.W	181,185,189,193,197,201,205,209
	DC.W	212,216,219,222,225,228,231,234
	DC.W	236,238,241,243,244,246,248,249
	DC.W	251,252,253,254,254,255,255,255,256

SIN:
	DC.W	0,6,12,18,25,31,37,43
	DC.W	49,56,62,68,74,80,86,92
	DC.W	97,103,109,115,120,126,131,136
	DC.W	142,147,152,157,162,167,171,176
	DC.W	181,185,189,193,197,201,205,209
	DC.W	212,216,219,222,225,228,231,234
	DC.W	236,238,241,243,244,246,248,249
	DC.W	251,252,253,254,254,255,255,255
	DC.W	256,255,255,255,254,254,253,252
	DC.W	251,249,248,246,244,243,241,238
	DC.W	236,234,231,228,225,222,219,216
	DC.W	212,209,205,201,197,193,189,185
	DC.W	181,176,171,167,162,157,152,147
	DC.W	142,136,131,126,120,115,109,103
	DC.W	97,92,86,80,74,68,62,56
	DC.W	49,43,37,31,25,18,12,6
	DC.W	0,-6,-12,-18,-25,-31,-37,-43
	DC.W	-49,-56,-62,-68,-74,-80,-86,-92
	DC.W	-97,-103,-109,-115,-120,-126,-131,-136
	DC.W	-142,-147,-152,-157,-162,-167,-171,-176
	DC.W	-181,-185,-189,-193,-197,-201,-205,-209
	DC.W	-212,-216,-219,-222,-225,-228,-231,-234
	DC.W	-236,-238,-241,-243,-244,-246,-248,-249
	DC.W	-251,-252,-253,-254,-254,-255,-255,-255
	DC.W	-256,-255,-255,-255,-254,-254,-253,-252
	DC.W	-251,-249,-248,-246,-244,-243,-241,-238
	DC.W	-236,-234,-231,-228,-225,-222,-219,-216
	DC.W	-212,-209,-205,-201,-197,-193,-189,-185
	DC.W	-181,-176,-171,-167,-162,-157,-152,-147
	DC.W	-142,-136,-131,-126,-120,-115,-109,-103
	DC.W	-97,-92,-86,-80,-74,-68,-62,-56
	DC.W	-49,-43,-37,-31,-25,-18,-12,-6,0

BPLCON3=$DFF106
BLTAPTH=$DFF050
BLTAPTL=$DFF052
BLTCPTH=$DFF048
BLTDPTH=$DFF054
BLTAMOD=$DFF064
BLTBMOD=$DFF062
BLTCMOD=$DFF060
BLTDMOD=$DFF066
BLTADAT=$DFF074
BLTBDAT=$DFF072
BLTAFWM=$DFF044
BLTCON0=$DFF040
BLTCON1=$DFF042
BLTSIZE=$DFF058
DMACONR=$DFF002

ALIEN_MST:
	DC.B	"DF0:ALIEN.MST",0
DAMIER_MST:
	DC.B	"DF0:DAMIER.MST",0
CONE3D_DAT:
	DC.B	"DF0:CONE3D.DAT",0
GLOB3D_DAT:
	DC.B	"DF0:GLOB3D.DAT",0
PAYSAGE_MST:
	DC.B	"DF0:PAYSAGE.MST",0
POINTS_DAT:
	DC.B	"DF0:POINTS.DAT",0
CERCLE_DAT:
	DC.B	"DF0:CERCLES.DAT",0
	EVEN
DOSNAME:
	DC.B	"dos.library",0
DOSBASE:DC.L	0

