ORG level_start

lvl_offset EQU 9 ;14
lvl_offsetB	EQU lvl_offset+1
bosspos	   EQU 62

IF output_files
	write "bin/level2.lvl"
ENDIF

;*** LEVEL 2 ***
START	DEFB 0	;6
SYNCHRO	DEFW 0000
;
START1	DEFB 0 ;23-lvl_offset ;bosspos-lvl_offset ;0
START2	DEFB 43
START3	DEFB 255
;
SYNCHRO1	DEFW SYNC1 ; SYNC25 ;SYNC_BOSS ;SYNC1
SYNCHRO2	DEFW SYNC2
SYNCHRO3	DEFW SYNC3
;
TSPRADD		DEFW 0
TADD		DEFW 0
SEQTABLE	DEFW SQTABLE
SPEVENT1	DEFW SPEV1
SPEVENT2	DEFW SPEV2

;*** new stuff ***

;palette stuff 16 colors+border
.lvl_pal
	db 0,26,11,6,3,20,10,2,1,25,16,18,9,15,12,4
	db 0
	db 0,20,2,3,0,10,1,1,0,12,3,9,0,3,1,0
	db 0
	db 0,11,1,3,0,1,0,1,0,3,0,9,0,3,0,0
	db 0
	db 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db 0
.lvl_floating_color
	db 14
.lvl_music
	db 1 
.lvl_skip
	dw 0	;music to skip on music restart
.lvl_init
	dw	0	;called after loading
.lvl_reinit
	dw	FX_Init	;called each time player dies

.FX_Init
	ld HL,0
	ld (FX98_last),HL
	ret
	
; ****************************************
;*	LEVEL 2 - ATTACK WAVES
;****************************************
;	1ST BYTE = TILENO
;	2ND BYTE
;		BITS 0-2 = TILESCROLL
;		BITS 3-4 = TILEPOS
;		BITS 5-7 = 
;	3RD BYTE = SEQUENCE NUMBER
;	4TH BYTE = INITIAL X POSITION
;	5TH BYTE = INITIAL Y POSITION
;	(TILESCROLL = FRAME OR BITPOS)
;****************************************
.SYNC1	
	;START_EFFECT 0,1,0
	;LVL_FLcolor	0,1,12
	DEFB 17-lvl_offsetB,1,99,4,0
	DEFB 17-lvl_offsetB,1,99,3,1
	DEFB 17-lvl_offsetB,1,46,50,10
	DEFB 17-lvl_offsetB,1,1,8,18
	DEFB 17-lvl_offsetB,14,17,32,10 ;8
	DEFB 18-lvl_offsetB,0,4,30,253
	DEFB 19-lvl_offsetB,24,2,28,18
	DEFB 21-lvl_offsetB,8,4,28,253
	DEFB 21-lvl_offsetB,12,3,1,253
	DEFB 22-lvl_offsetB,24,1,8,18

.SYNC25	

	;DEFB 25-lvl_offset,0,37,32,15 ;31,37,18,16;LAUNCH 1
	FORCE_Slot 2,25-lvl_offsetB,6,37,35,15
	
	DEFB 25-lvl_offsetB,8,4,28,253
	DEFB 25-lvl_offsetB,8,2,28,18
	
	
	FORCE_Slot 1,25-lvl_offsetB,24,46,35,0	;dummy to avoid objets from passing behind
	

	
 	DEFB 27-lvl_offsetB,0,1,8,18
	DEFB 27-lvl_offsetB,10,1,8,18
 	DEFB 27-lvl_offsetB,16,4,31,253
	
 	DEFB 28-lvl_offsetB,0,5,31,5
	DEFB 28-lvl_offsetB,11,5,31,11
	DEFB 28-lvl_offsetB,24,9,31,7
 	DEFB 28-lvl_offsetB,24,3,1,253
	
	DEFB 29-lvl_offsetB,3,5,31,9
	DEFB 29-lvl_offsetB,16,5,31,11
	DEFB 29-lvl_offsetB,27,7,31,9
 
	DEFB 30-lvl_offsetB,0,2,28,18
 	DEFB 30-lvl_offsetB,8,5,31,7
	DEFB 30-lvl_offsetB,19,5,31,9
	
 	DEFB 31-lvl_offsetB,0,8,31,5
	DEFB 31-lvl_offsetB,11,5,31,7
 	;DEFB 31-lvl_offset,20,99,6,16
	;DEFB 31-lvl_offset,20,38,12,17;A
 	DEFB 31-lvl_offsetB,24,5,31,11
	

	
	DEFB 32-lvl_offsetB,0,18,31,5
 	DEFB 32-lvl_offsetB,3,5,31,7
	;DEFB 32-lvl_offset,16,5,31,5
 	;DEFB 32-lvl_offset,20,39,24,9;A
	
	
	
	
	DEFB 32-lvl_offsetB,24,1,8,18
 	DEFB 32-lvl_offsetB,27,5,31,11
	
 	DEFB 33-lvl_offsetB,8,6,31,9
	DEFB 33-lvl_offsetB,19,5,31,5
	
	;DEFB 33-lvl_offset,0,40,32,0 ;31,40,32,1;LAUNCH 2	
	FORCE_Slot 1,33-lvl_offset,0,40,32,0
	
	;DEFB 33-lvl_offset,8,99,6,16
 	;DEFB 33-lvl_offset,8,38,5,19;B

 	DEFB 34-lvl_offsetB,0,5,31,11
 	;DEFB 34-lvl_offset,8,39,16,11;B
	DEFB 34-lvl_offsetB,11,10,31,9
	DEFB 34-lvl_offsetB,24,5,31,7
 	DEFB 34-lvl_offsetB,24,2,24,18 
 	DEFB 35-lvl_offsetB,3,5,31,9
	DEFB 35-lvl_offsetB,16,7,31,7
 	DEFB 35-lvl_offsetB,27,5,31,11
	DEFB 36-lvl_offsetB,8,5,31,5
	DEFB 36-lvl_offsetB,8,2,26,18
 	DEFB 36-lvl_offsetB,19,5,31,11
	DEFB 37-lvl_offsetB,0,5,31,5
	DEFB 37-lvl_offsetB,11,8,31,9
 	DEFB 37-lvl_offsetB,24,5,31,7
	
 	
	
 	DEFB 38-lvl_offsetB,3,5,31,9
	DEFB 38-lvl_offsetB,16,5,31,5
 	DEFB 38-lvl_offsetB,24,3,4,253
	DEFB 38-lvl_offsetB,27,9,31,7
 	DEFB 39-lvl_offsetB,8,5,31,11
 	DEFB 39-lvl_offsetB,16,3,1,253
	;DEFB 39-lvl_offsetB,16,99,6,16
	;DEFB 39-lvl_offset,16,41,12,1;C
	DEFB 39-lvl_offsetB,19,5,31,5
 	DEFB 40-lvl_offsetB,0,9,31,9
	DEFB 40-lvl_offsetB,8,4,31,253
	DEFB 40-lvl_offsetB,11,5,31,11
	;DEFB 40-lvl_offset,16,39,24,10;C
 	DEFB 40-lvl_offsetB,24,3,20,253
 	DEFB 40-lvl_offsetB,24,5,31,7
 	;DEFB 41-lvl_offsetB,0,99,6,16
 	;DEFB 41-lvl_offset,0,41,7,2;D
	DEFB 41-lvl_offsetB,3,11,31,9
 	DEFB 41-lvl_offsetB,16,5,31,11
	DEFB 41-lvl_offsetB,27,5,31,7
 	;DEFB 42-lvl_offset,0,39,19,10;D
	DEFB 42-lvl_offsetB,8,8,31,5
	DEFB 42-lvl_offsetB,8,4,28,253
	DEFB 42-lvl_offsetB,19,5,31,11
	DEFB 43-lvl_offsetB,0,5,31,7
	DEFB 43-lvl_offsetB,0,1,4,18
	DEFB 43-lvl_offsetB,3,2,24,18
 	DEFB 43-lvl_offsetB,11,8,31,5

	CHECK_POINT 44-lvl_offsetB,0
.SYNC2	
	DEFB 44-lvl_offsetB,16,3,0,253
 	DEFB 50-lvl_offsetB,0,19,31,13;;3
 	DEFB 50-lvl_offsetB,0,1,8,18
	DEFB 51-lvl_offsetB,8,2,28,18
 	DEFB 52-lvl_offsetB,0,1,4,18
	DEFB 54-lvl_offsetB,0,4,28,253
;snake 1
	LVL_SetSpec1	56-lvl_offset,0,0
 	DEFB 56-lvl_offset,0,12,33,5
 	DEFB 56-lvl_offset,2,13,33,5
 	DEFB 56-lvl_offset,4,14,33,5
 	DEFB 56-lvl_offset,6,14,33,5
 	DEFB 56-lvl_offset,8,14,33,5
 	DEFB 56-lvl_offset,8,20,30,1;;4
	DEFB 56-lvl_offset,10,14,33,5
	DEFB 56-lvl_offset,12,14,33,5
	DEFB 56-lvl_offset,14,14,33,5
	DEFB 56-lvl_offset,16,14,33,5
	DEFB 56-lvl_offset,16,3,0,253
	DEFB 56-lvl_offset,18,14,33,5
	DEFB 56-lvl_offset,20,14,33,5
	DEFB 56-lvl_offset,22,14,33,5
	DEFB 56-lvl_offset,24,14,33,5
	DEFB 56-lvl_offset,26,14,33,5
	DEFB 56-lvl_offset,28,14,33,5
	DEFB 56-lvl_offset,29,15,33,5

.SYNC_BOSS
	
	
	LVL_Music	63-lvl_offset,16,8
	;DEFB 63-lvl_offset,26,99,6,19
	

;switch off scroll
 	;DEFB 63-lvl_offset,31,99,1,0

	
	LVL_SetSpec2 64-lvl_offset,0,1	;boss will survive 5 cycles of 52 (62-10))
	

	DEFB 64-lvl_offset,0,99,6,sfx_boss2
	DEFB 64-lvl_offset,0,42,4,15		
	
	DEFB 64-lvl_offset,1,99,1,0
	
 	;DEFB 64-lvl_offset,26,99,6,18

	DEFB 65-lvl_offset,0,99,3,1
	DEFB 65-lvl_offset,0,16,14,9	;eye 13,8
	
	LVL_Do	65-lvl_offset,0,2	;repeat 4

 ;snake 2
	LVL_SetSpec1	66-lvl_offset,0,0
 	DEFB 66-lvl_offset,0,99,6,sfx_boss2
	DEFB 66-lvl_offset,0,42,4,15
 	DEFB 66-lvl_offset,0,21,4,15
 	DEFB 66-lvl_offset,2,22,4,15
 	DEFB 66-lvl_offset,4,23,4,15
 	DEFB 66-lvl_offset,6,23,4,15
 	DEFB 66-lvl_offset,8,23,4,15
 	DEFB 66-lvl_offset,10,23,4,15
	DEFB 66-lvl_offset,12,23,4,15
	DEFB 66-lvl_offset,14,23,4,15
	DEFB 66-lvl_offset,16,23,4,15
	DEFB 66-lvl_offset,18,23,4,15
	DEFB 66-lvl_offset,20,23,4,15
	DEFB 66-lvl_offset,22,23,4,15
	DEFB 66-lvl_offset,24,23,4,15
	DEFB 66-lvl_offset,26,23,4,15
	DEFB 66-lvl_offset,28,23,4,15
	DEFB 66-lvl_offset,29,24,4,15
	;DEFB 67-lvl_offset,0,99,6,sfx_boss2
 	DEFB 69-lvl_offset,8,99,6,sfx_boss2
	DEFB 69-lvl_offset,8,43,8,8
	;DEFB 70-lvl_offset,8,99,6,
 
 ;snake 3
	LVL_SetSpec1	71-lvl_offset,0,0
 	DEFB 71-lvl_offset,0,99,6,sfx_boss2
	DEFB 71-lvl_offset,0,44,22,15	;23
	DEFB 71-lvl_offset,0,25,25,15
	DEFB 71-lvl_offset,2,26,25,15
	DEFB 71-lvl_offset,4,27,25,15
	DEFB 71-lvl_offset,6,27,25,15
	DEFB 71-lvl_offset,8,27,25,15
	DEFB 71-lvl_offset,10,27,25,15
 	DEFB 71-lvl_offset,12,27,25,15
 	DEFB 71-lvl_offset,14,27,25,15
 	DEFB 71-lvl_offset,16,27,25,15
 	DEFB 71-lvl_offset,18,27,25,15
 	DEFB 71-lvl_offset,20,27,25,15
 	DEFB 71-lvl_offset,22,27,25,15
 	DEFB 71-lvl_offset,24,27,25,15
 	DEFB 71-lvl_offset,26,27,25,15
 	DEFB 71-lvl_offset,28,27,25,15
 	DEFB 71-lvl_offset,29,28,25,15
 	;DEFB 72-lvl_offset,0,99,6,sfx_boss2
 	DEFB 72-lvl_offset,20,99,6,sfx_boss2
	DEFB 72-lvl_offset,20,42,4,15
	;DEFB 73-lvl_offset,20,99,6,18
;snake 4
	LVL_SetSpec1	74-lvl_offset,0,0
 	DEFB 74-lvl_offset,0,99,6,sfx_boss2
	DEFB 74-lvl_offset,0,45,19,8 
 	DEFB 74-lvl_offset,0,29,22,8
 	DEFB 74-lvl_offset,2,30,22,8
 	DEFB 74-lvl_offset,4,31,22,8
 	DEFB 74-lvl_offset,6,31,22,8
 	DEFB 74-lvl_offset,8,31,22,8
 	DEFB 74-lvl_offset,10,31,22,8
	DEFB 74-lvl_offset,12,31,22,8
	DEFB 74-lvl_offset,14,31,22,8
	DEFB 74-lvl_offset,16,31,22,8
	DEFB 74-lvl_offset,18,31,22,8
	DEFB 74-lvl_offset,20,31,22,8
	DEFB 74-lvl_offset,22,31,22,8
	DEFB 74-lvl_offset,24,31,22,8
	DEFB 74-lvl_offset,26,31,22,8
	DEFB 74-lvl_offset,28,31,22,8
	DEFB 74-lvl_offset,29,32,22,8
	;DEFB 75-lvl_offset,0,99,6,sfx_boss2
 	DEFB 75-lvl_offset,26,99,6,sfx_boss2
	DEFB 75-lvl_offset,26,42,4,15
	;DEFB 76-lvl_offset,26,99,6,18
;snake 5
	LVL_SetSpec1	78-lvl_offset,0,0
 	DEFB 78-lvl_offset,0,99,6,sfx_boss2
	DEFB 78-lvl_offset,0,43,8,8
	DEFB 78-lvl_offset,0,33,8,8
	DEFB 78-lvl_offset,2,34,8,8
	DEFB 78-lvl_offset,4,35,8,8
	DEFB 78-lvl_offset,6,35,8,8
	DEFB 78-lvl_offset,8,35,8,8
	DEFB 78-lvl_offset,10,35,8,8
 	DEFB 78-lvl_offset,12,35,8,8
 	DEFB 78-lvl_offset,14,35,8,8
 	DEFB 78-lvl_offset,16,35,8,8
 	DEFB 78-lvl_offset,18,35,8,8
 	DEFB 78-lvl_offset,20,35,8,8
 	DEFB 78-lvl_offset,22,35,8,8
 	DEFB 78-lvl_offset,24,35,8,8
 	DEFB 78-lvl_offset,26,35,8,8
 	DEFB 78-lvl_offset,28,35,8,8
 	DEFB 78-lvl_offset,29,36,8,8
 	;DEFB 79-lvl_offset,0,99,6,sfx_boss2
 	DEFB 79-lvl_offset,24,99,6,sfx_boss2
	DEFB 79-lvl_offset,24,44,22,15	;23
 	;DEFB 80-lvl_offset,24,99,6,18
;snake3/6
	LVL_SetSpec1	82-lvl_offset,0,0
	DEFB 82-lvl_offset,0,99,6,sfx_boss2
	DEFB 82-lvl_offset,0,44,22,15 ;23
	DEFB 82-lvl_offset,0,25,25,15
	DEFB 82-lvl_offset,2,26,25,15
	DEFB 82-lvl_offset,4,27,25,15
	DEFB 82-lvl_offset,6,27,25,15
	DEFB 82-lvl_offset,8,27,25,15
	DEFB 82-lvl_offset,10,27,25,15
 	DEFB 82-lvl_offset,12,27,25,15
 	DEFB 82-lvl_offset,14,27,25,15
 	DEFB 82-lvl_offset,16,27,25,15
 	DEFB 82-lvl_offset,18,27,25,15
 	DEFB 82-lvl_offset,20,27,25,15
 	DEFB 82-lvl_offset,22,27,25,15
 	DEFB 82-lvl_offset,24,27,25,15
 	DEFB 82-lvl_offset,26,27,25,15
 	DEFB 82-lvl_offset,28,27,25,15
 	DEFB 82-lvl_offset,29,28,25,15
 	;DEFB 83-lvl_offset,0,99,6,sfx_boss2
 	DEFB 83-lvl_offset,20,99,6,sfx_boss2
	DEFB 83-lvl_offset,20,42,4,15
	;DEFB 84-lvl_offset,20,99,6,18
;snake2/7
	LVL_SetSpec1	85-lvl_offset,0,0
	DEFB 85-lvl_offset,0,99,6,sfx_boss2
	DEFB 85-lvl_offset,0,42,4,15
 	DEFB 85-lvl_offset,0,21,4,15
 	DEFB 85-lvl_offset,2,22,4,15
 	DEFB 85-lvl_offset,4,23,4,15
 	DEFB 85-lvl_offset,6,23,4,15
 	DEFB 85-lvl_offset,8,23,4,15
 	DEFB 85-lvl_offset,10,23,4,15
	DEFB 85-lvl_offset,12,23,4,15
	DEFB 85-lvl_offset,14,23,4,15
	DEFB 85-lvl_offset,16,23,4,15
	DEFB 85-lvl_offset,18,23,4,15
	DEFB 85-lvl_offset,20,23,4,15
	DEFB 85-lvl_offset,22,23,4,15
	DEFB 85-lvl_offset,24,23,4,15
	DEFB 85-lvl_offset,26,23,4,15
	DEFB 85-lvl_offset,28,23,4,15
	DEFB 85-lvl_offset,29,24,4,15
	;DEFB 86-lvl_offset,0,99,6,sfx_boss2
 	DEFB 88-lvl_offset,8,99,6,sfx_boss2
	DEFB 88-lvl_offset,8,43,8,8
	;DEFB 89-lvl_offset,8,99,6,18
 ;snake 5/8
	LVL_SetSpec1	90-lvl_offset,0,0
 	DEFB 90-lvl_offset,0,99,6,sfx_boss2
	DEFB 90-lvl_offset,0,43,8,8
	DEFB 90-lvl_offset,0,33,8,8
	DEFB 90-lvl_offset,2,34,8,8
	DEFB 90-lvl_offset,4,35,8,8
	DEFB 90-lvl_offset,6,35,8,8
	DEFB 90-lvl_offset,8,35,8,8
	DEFB 90-lvl_offset,10,35,8,8
 	DEFB 90-lvl_offset,12,35,8,8
 	DEFB 90-lvl_offset,14,35,8,8
 	DEFB 90-lvl_offset,16,35,8,8
 	DEFB 90-lvl_offset,18,35,8,8
 	DEFB 90-lvl_offset,20,35,8,8
 	DEFB 90-lvl_offset,22,35,8,8
 	DEFB 90-lvl_offset,24,35,8,8
 	DEFB 90-lvl_offset,26,35,8,8
 	DEFB 90-lvl_offset,28,35,8,8
 	DEFB 90-lvl_offset,29,36,8,8
 	;DEFB 91-lvl_offset,0,99,6,sfx_boss2
 	DEFB 91-lvl_offset,24,99,6,sfx_boss2
	DEFB 91-lvl_offset,24,44,22,15 ;23
 	;DEFB 92-lvl_offset,24,99,6,18
;snake 4/93
	LVL_SetSpec1	94-lvl_offset,0,0
 	DEFB 94-lvl_offset,0,99,6,sfx_boss2
	DEFB 94-lvl_offset,0,45,19,8	
 	DEFB 94-lvl_offset,0,29,22,8
 	DEFB 94-lvl_offset,2,30,22,8
 	DEFB 94-lvl_offset,4,31,22,8
 	DEFB 94-lvl_offset,6,31,22,8
 	DEFB 94-lvl_offset,8,31,22,8
 	DEFB 94-lvl_offset,10,31,22,8
	DEFB 94-lvl_offset,12,31,22,8
	DEFB 94-lvl_offset,14,31,22,8
	DEFB 94-lvl_offset,16,31,22,8
	DEFB 94-lvl_offset,18,31,22,8
	DEFB 94-lvl_offset,20,31,22,8
	DEFB 94-lvl_offset,22,31,22,8
	DEFB 94-lvl_offset,24,31,22,8
	DEFB 94-lvl_offset,26,31,22,8
	DEFB 94-lvl_offset,28,31,22,8
	DEFB 94-lvl_offset,29,32,22,8
	;DEFB 95-lvl_offset,0,99,6,sfx_boss2
 	DEFB 95-lvl_offset,26,99,6,sfx_boss2
	DEFB 95-lvl_offset,26,42,4,15
	;DEFB 96-lvl_offset,26,99,6,18
;
	LVL_Loop	97-lvl_offset,0

	DEFB 98-lvl_offset,0,99,5,0
SYNC3	
	DEFB 255,255,255,255,255	
;****************************************
 ;	1ST BYTE
 ;		BITS 0-3 = SPECIAL EVENT 1
;		BITS 0-4 = SPECIAL EVENT 2
;	2ND BYTE = HIT POINTS
;	3RD BYTE
 ;		BITS 0-3 = POINT VALUE
;		BITS 4-7 = EXPLOSION TYPE
 ;	BYTES ARE NOW PAIRED TO MAKE UP
;	ADDRESS OF SPRITE PATTERNS
 ;	WORD 0 = END OF SEQUENCE 
;****************************************
 ;SCORPION UP / RIGHT
L2_MASTER1			EQU $+1
L2_MASTER1234_val	EQU 48
SQ1	DEFB 51,16,69 ;3+16*3,16,5+4*16
	DEFW SP1,SP1,SP1A,SP1A,SP1A,SP1,SP1,0
 ;SCORPION UP / LEFT
L2_MASTER2		EQU $+1
SQ2	DEFB 51,16,69 ;3+16*3,16,5+4*16
	DEFW SP2,SP2,SP2A,SP2A,SP2A,SP2,SP2,0
 ;SCORPION DOWN / RIGHT
L2_MASTER3		EQU $+1
SQ3	DEFB 51,16,69 ;3+16*3,16,5+4*16
	DEFW SP3,SP3,SP3A,SP3A,SP3A,SP3,SP3,0
 ;SCORPION DOWN / LEFT
L2_MASTER4		EQU $+1
SQ4	DEFB 51,16,69 ;3+16*3,16,5+4*16
	DEFW SP4,SP4,SP4A,SP4A,SP4A,SP4,SP4,0
 ;STRAIGHT SPERMIES
SQ5	DEFB 0,1,49 ;0,1,1+3*16
	DEFW SP5,SP5,0
;SPERMIES DOWN / RIGHT 4
SQ6	DEFB 0,1,49 ;0,1,1+3*16
	DEFW SP5,SP7,SP7,SP7,0
;SPERMIES DOWN / RIGHT 6
SQ7	DEFB 0,1,49 ;0,1,1+3*16
	DEFW SP5,SP5A,SP7,SP7,SP7,0
 ;SPERMIES DOWN / RIGHT 8
SQ8	DEFB 0,1,49 ;0,1,1+3*16
	DEFW SP5,SP5,SP7,SP7,SP7,0
;SPERMIES DOWN / LEFT 0
SQ9	DEFB 0,1,49 ;0,1,1+3*16
	DEFW SP8,SP8,SP8,SP8,0	
 ;SPERMIES DOWN / LEFT 2
SQ10	DEFB 0,1,49 ;0,1,1+3*16
 	DEFW SP5A,SP8,SP8,SP8,0
 ;SPERMIES DOWN / LEFT 4
SQ11	DEFB 0,1,49 ;0,1,1+3*16
 	DEFW SP5,SP8,SP8,SP8,0
;SNAKE 1 HEAD
SQ12	DEFB 0,63,18 ;0,63,2+16*1
	DEFW SP17,SP17,SP17,SP17,SP12A,SP12B,SP24,SP25,SP11,SP11,SP22,SP19
	DEFW SP16,SP16,SP16,SP20,SP21,SP22,SP14,SP11A,SP26
	DEFW SP9,SP23,SP15,SP15,SP15A,SP15A,SP24,SP25,SP26,SP13,SP22,SP10
 	DEFW SP10,SP14A,SP10,SP10,SP19,SP20,SP9,SP9,SP21,SP9,SP9A
 	DEFW SP23,SP12,SP24,SP25,SP26,SP13A,SP13A,SP22,SP19,SP20,SP21
 	DEFW SP22,SP19,SP20,SP23,SP12A,SP12B,SP16,0
;SNAKE 1 NECK
SQ13	DEFB 4,63,18 ;4+16*0,63,2+16*1
 	DEFW #0C0C ;12+12*256
;SNAKE 1 BODY
SQ14	DEFB 5,1,18 ;5+16*0,1,2+16*1
	DEFW #0C0C ;12+12*256
;SNAKE 1 TAIL
SQ15	DEFB 6,63,18 ;6+16*0,63,2+16*1
 	DEFW #0C0C ;12+12*256
;MOLLUSC EYE SEQUENCE 
L2_MASTER7		EQU $+1
L2_MASTER7_val	EQU 62
SQ16	DEFB 39,30,32+8 ;7+16*2,62,1+1*16 in fact 800 from snake !
 	DEFW SP27,SP27,#FFFF ;255*256+255 
 ;PODDER 1
SQ17	DEFB 226,1,34 ;2+16*14,1,2+32
 	DEFW SP6,SP6A,SP6C,SP6B,SP6D,SP6DDDD,SP6G
 	DEFW SP6F,SP6G,SP6CC,SP6B,SP6AA,SP6A,SP6A,0
 ;PODDER 2
SQ18	DEFB 194,1,34 ;2+16*12,1,2+32
 	DEFW SP6,SP6A,SP6C,SP6B,SP6,SP6A,SP6C,SP6B,0	
 ;PODDER 3
SQ19	DEFB 178,1,34 ;2+16*11,1,2+32
 	DEFW SP6C,SP6B,SP6,SP6A,SP6A,SP6A,SP6A,SP6A,0
 ;PODDER 4
SQ20	DEFB 178,1,34 ;2+16*11,1,2+32
 	DEFW SP6,SP6,SP6G,SP6E,SP6G
 	DEFW SP6C,SP6CC,SP6B,SP6,SP6A,0	
;
;
;SNAKE 2 HEAD
SQ21	DEFB 0,63,18 ;0,63,2+16*1
	DEFW SP13,SP22,SP26,SP22,SP10,SP10,SP10,SP10,SP10
 	DEFW SP19,SP20,SP15,SP24,SP25,SP26,SP13,SP9,SP9,SP9A,SP9B
 	DEFW SP13A,SP11B,SP14A,SP10B,SP16A,SP12B,SP15A
	DEFW SP9B,SP13A,SP9B,SP15A,SP24,SP16A,0
 ;SNAKE 2 NECK
SQ22	DEFB 4,63,18 ;4+16*0,63,2+16*1
 	DEFW #1515 ;21*256+21
;SNAKE 2 BODY
SQ23	DEFB 5,1,18 ;5+16*0,1,2+16*1
	DEFW #1515 ;21*256+21
;SNAKE 2 TAIL
SQ24	DEFB 6,63,18 ;6+16*0,63,2+16*1
 	DEFW #1515 ;21*256+21
;
;
;SNAKE 3 HEAD
SQ25	DEFB 0,63,18 ;0,63,2+16*1
	DEFW SP14,SP11A,SP11A,SP11A,SP13,SP9,SP9,SP9,SP9,SP9B
 	DEFW SP9A,SP15,SP12,SP12A,SP24,0
;SNAKE 3 NECK
SQ26	DEFB 4,63,18 ;4+16*0,63,2+16*1
 	DEFW #1919 ;25*256+25
;SNAKE 3 BODY
SQ27	DEFB 5,1,18 ;5+16*0,1,2+16*1
	DEFW #1919 ;25*256+25
;SNAKE 3 TAIL
SQ28	DEFB 6,63,18 ;6+16*0,63,2+16*1
 	DEFW #1919 ;25*256+25
;
;
;SNAKE 4 HEAD
SQ29	DEFB 0,63,18 ;0,63,2+16*1
	DEFW SP14A,SP14A,SP11B,SP13A,SP9B,SP15A,SP9,SP17
	DEFW SP23,SP24,SP20,SP21,SP22,SP19,SP20,SP24,SP16,0
 ;SNAKE 4 NECK
SQ30	DEFB 4,63,18 ;4+16*0,63,2+16*1
 	DEFW #1D1D ;29*256+29
;SNAKE 4 BODY
SQ31	DEFB 5,1,18 ;5+16*0,1,2+16*1
	DEFW #1D1D ;29*256+29
;SNAKE 4 TAIL
SQ32	DEFB 6,63,18 ;6+16*0,63,2+16*1
 	DEFW #1D1D ;29*256+29
;
;
;SNAKE 5 HEAD
SQ33	DEFB 0,63,18 ;0,63,2+16*1
	DEFW SP13A,SP22,SP26,SP23,SP24,SP25,SP14A,SP19,SP25,SP10A
 	DEFW SP19,SP20,SP24,SP20,0
;SNAKE 5 NECK
SQ34	DEFB 4,63,18 ;4+16*0,63,2+16*1
 	DEFW #2121 ;33*256+33
;SNAKE 5 BODY
SQ35	DEFB 5,1,18 ;5+16*0,1,2+16*1
	DEFW #2121 ;33*256+33
;SNAKE 5 TAIL
SQ36	DEFB 6,63,18 ;6+16*0,63,2+16*1
 	DEFW #2121 ;33*256+33
;
;
;LAUNCHER 1
SQ37	DEFB 72,62,64+7 ;8+4*16,63,12+16*1  4*16
	DEFW SP31,SP31,SP31,SP31,SP31
 	DEFW SP31,SP31,SP31,SP31,SP31
	DEFW SP31,SP31,SP31,SP31,SP31
	DEFW SP31,SP31,SP31,SP31,SP31
 	DEFW SP31,SP31,SP31,0
;BRAINS 1A
.SQ38	DEFB 10,63,16+5 ;0,63,12+16*1  - NEW ACTION = 10
		DEFW SP28,SP28,SP28A,SP28B,SP28B,0
;BRAINS 1B
L2_MASTER5			EQU $+1
L2_MASTER56_val		EQU 32
SQ39	DEFB 0,8,32+5 ;0,8,5+2*16
 	DEFW SP29,#FFFF ;255+255*256
 ;LAUNCHER 2
SQ40	DEFB 72,62,64+7 ;28 ;8+4*16,63,12+16*1
	DEFW SP32,SP32,SP32,SP32,SP32
 	DEFW SP32,SP32,SP32,SP32,SP32
	DEFW SP32,SP32,SP32,SP32,SP32
	DEFW SP32,SP32,SP32,SP32,SP32
 	DEFW SP32,SP32,SP32,0
 ;BRAINS 2A
L2_MASTER6			EQU $+1
SQ41	DEFB 10,255,32+5 ;0,255,12+16*1 - NEW ACTION = 10
		DEFW SP30,SP30,SP30A,SP30B,SP30B,0
;MOLLUSC TUBE BOTTOM LEFT (reversed thank totO !)
SQ42	DEFB 73,63,0 ;9+4*16,63,12+16*1
		DEFW SP18B,SP18B,SP18B,SP18B,0
		;DEFB 73,63,28 ;9+4*16,63,12+16*1
		;DEFW SP18A,SP18A,SP18A,SP18A,0
;MOLLUSC TUBE TOP LEFT
.SQ43	DEFB 73,63,0 ;9+4*16,63,12+16*1
		DEFW SP18A,SP18A,SP18A,SP18A,0
		;DEFB 73,63,28 ;9+4*16,63,12+16*1
		;DEFW SP18B,SP18B,SP18B,SP18B,0
;MOLLUSC TUBE BOTTOM RIGHT
SQ44	DEFB 73,63,0 ;9+4*16,63,12+16*1
		DEFW SP18C,SP18C,SP18C,SP18C,0
;MOLLUSC TUBE TOP RIGHT
SQ45	DEFB 73,63,0 ;9+4*16,63,12+16*1
	DEFW SP18D,SP18D,SP18D,SP18D,0
;DUMMY SPRITE 1
SQ46	DEFB 0,63,0 ;0,63,12+16*2
 	DEFW SP33,SP33,65535
;****************************************
SQTABLE	DEFW SQ1,SQ2,SQ3,SQ4,SQ5,SQ6,SQ7,SQ8,SQ9,SQ10
	DEFW SQ11,SQ12,SQ13,SQ14,SQ15,SQ16,SQ17,SQ18,SQ19,SQ20
	DEFW SQ21,SQ22,SQ23,SQ24,SQ25,SQ26,SQ27,SQ28,SQ29,SQ30
	DEFW SQ31,SQ32,SQ33,SQ34,SQ35,SQ36,SQ37,SQ38,SQ39,SQ40
	DEFW SQ41,SQ42,SQ43,SQ44,SQ45,SQ46
;****************************************
 ;	1ST BYTE = SPRITE NUMBER
 ;
;	2ND BYTE =
 ;		BITS 0-1 = ORIENTATION
;		BIT 2 = UP
;		BIT 3 = DOWN
;		BIT 4 = LEFT
;		BIT 5 = RIGHT
 ;		BIT 6 = 
;		BIT 7 = END OF PATTERN
;****************************************	
;SCORPION UP / RIGHT
 SP1	DEFB 32,1,33,1,32,1,33,1+36,32,1,33,1,32,1,33,1+36+128
 SP1A	DEFB 32,1+36,32,1+36,32,1+36,32,1+36+128
;SCORPION UP / LEFT
SP2	DEFB 32,0,33,0,32,0,33,0+20,32,0,33,0,32,0,33,0+20+128
 SP2A	DEFB 32,0+20,32,0+20,32,0+20,32,0+20+128
;SCORPION DOWN / RIGHT
 SP3	DEFB 32,3,33,3,32,3,33,3+40,32,3,33,3,32,3,33,3+40+128
 SP3A	DEFB 32,3+40,32,3+40,32,3+40,32,3+40+128
;SCORPION DOWN / LEFT
SP4	DEFB 32,2,33,2,32,2,33,2+24,32,2,33,2,32,2,33,2+24+128
 SP4A	DEFB 32,2+24,32,2+24,32,2+24,32,2+24+128
;STRAIGHT SPERMIES
 SP5	DEFB 16,16,17,16,18,16,17,16,16,16,17,16,18,16,17,16
 SP5A	DEFB 16,16,17,16,18,16,17,16,16,16,17,16,18,16,17,16+128
;PODDERS
 SP6	DEFB 38,24,38,24							;FLY D/L 6
SP6AA	DEFB 38,24,38,24,38,24,38,24+128	;FLY D/L 4 
 SP6A	DEFB 38,16,38,16							;FLY L*4
 SP6B	DEFB 38,16,38,16+128						;FLY L*2
SP6C	DEFB 38,20,38,20							;FLY U/L 6
 SP6CC	DEFB 38,20,38,20,38,20,38,20+128	;FLY U/L 4
SP6D	DEFB 38,8							;DROP 4
 SP6DD	DEFB 38,8							;DROP 3
SP6DDD	DEFB 38,8							;DROP 
SP6DDDD	DEFB 38,8+128							;DROP 1
SP6E	DEFB 34,16,35,16,34,16,36,16+128	;WALK L
SP6F	DEFB 34,33,35,33,34,33,36,33+128	;WALK R
SP6G	DEFB 37,0,37,0+128						;LAND IMPACT
SP6GG	DEFB 37,1,37,1+128
 ;SPERMIES DOWN / RIGHT
 SP7	DEFB 50,1+40,51,1+40,52,1+40,51,1+40+128
 ;SPERMIES DOWN / LEFT
SP8	DEFB 50,24,51,24,52,24,51,24+128
 ;SNAKE STRAIGHT LEFT
 SP9	DEFB 27,1+16
 SP9A	DEFB 27,1+16
SP9B	DEFB 27,1+16,27,1+16+128
;SNAKE STRAIGHT RIGHT
SP10	DEFB 27,32
SP10A	DEFB 27,32
 SP10B	DEFB 27,32,27,32+128
 ;SNAKE STRAIGHT UP
 SP11	DEFB 25,4
 SP11A	DEFB 25,4
SP11B	DEFB 25,4,25,4+128
 ;SNAKE STRAIGHT DOWN
 SP12	DEFB 25,2+8
 SP12A	DEFB 25,2+8
SP12B	DEFB 25,2+8,25,2+8+128
 ;SNAKE DIAGONAL U / L
SP13	DEFB 26,1+20
SP13A	DEFB 26,1+20,26,1+20+128
 ;SNAKE DIAGONAL U / R
SP14	DEFB 26,36
SP14A	DEFB 26,36,26,36+128
 ;SNAKE DIAGONAL D / L
SP15	DEFB 26,3+24
SP15A	DEFB 26,3+24,26,3+24+128
 ;SNAKE DIAGONAL D / R
SP16	DEFB 26,2+40
SP16A	DEFB 26,2+40,26,2+40+128
 ;SNAKE CURVE R / L
 SP17	DEFB 27,1+16,27,1+16,26,1+20,26,1+20
	DEFB 27,1+16,27,1+16,26,3+24,26,3+24+128
;MOLLUSC TUBES
SP18A	DEFB 4,0,3,0,4,0,3,0,4,0,3,0,4,0,3,0+128		;BOTTOM LEFT (reversed w/ top)
SP18B	DEFB 6,0,5,0,6,0,5,0,6,0,5,0,6,0,5,0+128		;TOP LEFT
SP18C			;BOTTOM RIGHT
		DEFB 10,0,9,0,10,0,9,0,10,0,9,0,10,0,9,0+128
		;DEFB 4,1,3,1,4,1,3,1,4,1,3,1,4,1,3,1+128		
SP18D			;TOP RIGHT
		DEFB 8,0,7,0,8,0,7,0,8,0,7,0,8,0,7,0+128
		;DEFB 6,1,5,1,6,1,5,1,6,1,5,1,6,1,5,1+128
 ;
;SNAKE TURN 1 CLOCKWISE
SP19	DEFB 27,32,27,32,27,32
	DEFB 26,2+40,26,2+40+128
;SNAKE TURN 2 CLOCKWISE
SP20	DEFB 25,2+8,25,2+8
	DEFB 26,3+24,26,3+24+128
;SNAKE TURN 3 CLOCKWISE
SP21	DEFB 27,1+16,27,1+16,27,1+16
	DEFB 26,1+20,26,1+20+128
;SNAKE TURN 4 CLOCKWISE
SP22	DEFB 25,4,25,4
	DEFB 26,36,26,36+128
;SNAKE TURN 1 ANTI-CLOCKWISE
 SP23	DEFB 27,1+16,27,1+16,27,1+16
	DEFB 26,3+24,26,3+24+128
;SNAKE TURN 2 ANTI-CLOCKWISE
 SP24	DEFB 25,2+8,25,2+8
	DEFB 26,2+40,26,2+40+128
;SNAKE TURN 3 ANTI-CLOCKWISE
 SP25	DEFB 27,32,27,32,27,32
	DEFB 26,36,26,36+128
;SNAKE TURN 4 ANTI-CLOCKWISE
 SP26	DEFB 25,4,25,4
	DEFB 26,1+20,26,1+20+128
;MOLLUSC EYE OPEN
SP27	DEFB 41,0,41,0,41,0,41,0,41,0,41,0,41,0,41,0
	DEFB 42,0,43,0,44,0,44,0,43,0,42,0,41,0
 	DEFB 41,0,41,0,41,0,41,0,41,0,41,0,41,0,41,0
	DEFB 42,0,43,0,44,0,44,0,43,0,42,0,41,0
 	DEFB 41,0,41,0,41,0,41,0,41,0,41,0,41,0,41,0
	DEFB 42,0,43,0,44,0,44,0,43,0,42,0,41,0+128
 ;BRAIN MATTER 1A
 SP28	DEFB 45,4,46,4+1,45,4+2,46,4+128
SP28A	DEFB 45,36,46,36+1,45,36+2,46,36
 	DEFB 45,32,46,32+1,45,32+2,46,32
	DEFB 45,40,46,40+1,45,40+2,46,40
SP28B	DEFB 45,00,46,00+1,45,00+2,46,00+128
 ;BRAIN MATTER 1B
 SP29	DEFB 19,24,20,24,19,24+1,20,24
	DEFB 19,16,20,16,19,16+1,20,16
	DEFB 19,20,20,20,19,20+1,20,20
	DEFB 19,4,20,4,19,4+1,20,4
	DEFB 19,36,20,36,19,36+1,20,36
	DEFB 19,32,20,32,19,32+1,20,32
	DEFB 19,40,20,40,19,40+1,20,40
	DEFB 19,8,20,8,19,8,20,8+1+128
;BRAIN MATTER 2A
SP30	DEFB 45,8,46,8+1,45,8+2,46,8+128
SP30A	DEFB 45,40,46,40+1,45,40+2,46,40
 	DEFB 45,32,46,32+1,45,32+2,46,32
	DEFB 45,36,46,36+1,45,36+2,46,36
SP30B	DEFB 45,00,46,00+1,45,00+2,46,00+128
 ;BOTTOM OPENER - all sprites are 48 , replaced w/ 1
SP31	DEFB 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0 ;16
		DEFB 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,128 ;16+128
 ;TOP OPENER
SP32	DEFB 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 ;2+16
		DEFB 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2+128 ;2+16+128
 ;DUMMY SPRITE 1
SP33	DEFB 1,0+128
;****************************************
.SPEV1	DEFW FX0,FX1,FX2,FX3,FX4,FX5,FX6,FX7,FX8,FX9,FX10,FX11	;10 & 11 are new
.SPEV2	DEFW FXA0,FXA1,FXA2,FXA3,FXA4,FXA5
		DEFW FXA6,FXA7,FXA8,FXA9,FXA10
		DEFW FXA11,FXA12,FXA13,FXA14,FXA15
;NO ACTION
FX0		JP C,TV5
FX0A	JP TV1
;
;HALF SPEED
FX1	
	JP C,TV5
FX1A	
	LD A,(FRAME)
	AND 1
 	JP NZ,TV1
 	JP TV2
;	
;PODDER EXPLOSION BYPASS
 FX2	
		;break
	;JR NC,FX1A
 	JP C,TV5
	
	;half speed
	LD A,(FRAME)
	AND 1
	jr z,FX2_NoMove
	
	LD (IY+3),C
	LD (IY+4),B
	
.FX2_NoMove

	LD A,(DE)

	PUSH DE
	PUSH AF
 	EX AF,AF'
	sub 34
	ld E,A
	ld D,0
	ld HL,FX2_table
	add HL,DE
	ld A,(HL)	
 	CALL USPGADD
	POP AF
 	AND 3
	jp NZ,THEM6
 	CALL SPNS
 	jp THEM9
	
;conversion table for armos
.FX2_table
	db 161,164,160,162,163
	

;
;SCORPION STOP AND FLASH
FX3	
	JP C,TV5
 	JR Z,FX1A
 	LD A,71
 	;LD (CADD+1),A
 	LD (FXBYTE2),A
	LD A,(FRAME)
	AND 1
	jr nz,FX3_noflash
 	;ADD 32
	
	xor A
	call SND_SfxPlay
	
	ld A,11
	
	EX AF,AF'
 	JP TV2
.FX3_noflash
 	ADD 32
	ex AF,AF'
	jp TV2
;******************
;*** SNAKE NECK ***
;*****************
FX4	EX AF,AF'
	SUB 253
 	EX AF,AF'
	
	ld A,(SCR_SPEC1)
	inc A
	cp 25
	jr c,FX4_Spec1Done
	xor A
.FX4_Spec1Done	
	ld (SCR_SPEC1),A
	
	ld HL,(FX98_last)
	ld A,L
	or H
	jp z,TV1
	
	ld A,L
	add 5
	ld L,A
	
	ld (HL),11	;force non shooting event
	
 	JP TV1
;******************
;*** SNAKE BODY ***
;******************
FX11			;special added after shoot
	JR C,FX52
	LD A,(IY+0)
 	CP 255
	JR Z,FX53
	
	;LD A,(FRAME)
	;AND 31
	;CALL Z,FXA98
	;LD A,(FRAME)
	;AND 3
	;srl A
 	;ADD 22
	ld A,22
	jr FX51
FX5	
	JR C,FX52
	LD A,(IY+0)
 	CP 255
	JR Z,FX53
FX50	
	LD A,(SCR_SPEC1)
	;AND 31 ;31
	cp 24
	CALL Z,FXA98
	;LD A,(FRAME)
	;AND 3
	;srl A
 	;ADD 22
	ld A,23
FX51	
	EX AF,AF'
	ld A,(DE)
	and %1111111100
 	;JP TV1
	LD (IY+3),C
	LD (IY+4),B
	jp TVA
;
FX52	
	LD (IY+0),255
FX53	
	SetMaster 0	;immortal !
	LD A,31
 	JR FX51
 ;
;SNAKE TAIL
FX6	EX AF,AF'
	SUB 253
 	EX AF,AF'
 	LD A,(DE)
 	AND 3
 	XOR 3
 	LD L,A
	LD A,(DE)
 	AND 252
 	OR L
	LD (IY+3),C
 	LD (IY+4),B
 	JP TVA
;********************
;*** MOLLUSC EYE ***
;********************
.FX7	
	;JR NZ,FX72
	jr c,FX7_dead
	jr nz,FX7_Hit
	
 	;LD A,(IY+8)
 	;CP 1
	;JR NZ,FX71
	;INC (IY+8)
	;LD HL,4*256+5
 	;CALL CHOP
.FX71	
	;JP FX1A
	;jr FX7_DrawEye_Inc
.FX72	
	;LD (IY+0),62
	EX AF,AF'
 	CP 44
 	JR Z,FX73
 	EX AF,AF'
 	;JP FX1A
	jr FX7_DrawEye_Inc
.FX73	
	;break
	EX AF,AF'
	jr FX7_DrawEye
 	;LD A,(FXBYTE1)
	;INC A
 	;LD (FXBYTE1),A
	;CP 16
 	;JR Z,FX74
 	;LD A,(FRAME)
	;AND 1
 	;ADD 70
	;LD (CADD+1),A
 	;JP FX1A
	;bit 7,(IY+8)
	;jr z,FX7_DrawEye	
.FX7_Hit	
	;if hit !
	ex AF,AF'
	ld A,12		;hit sprite
	ex AF,AF'

	;hit sound
	ld A,sfx_touchboss
	call SND_SfxPlay
	
	;ld A,(IY+0)
	;cp 10
	jr FX7_DrawEye_Inc

.FX7_dead	
	;ld A,(SCR_SPEC2)
	;break
	;dec A
	;ld (SCR_SPEC2),A
	;ld (IY+0),62
	;or A
	;jr nz,FX7_DrawEye_Inc
;no more , boss is dead !
	;ld A,1
	;ld (SYNCOFF),A
	;destroy all here !
	ld A,13-1	;8K !
	call SCORE_Add
	
	call BIG_EXPLO_Start
	;jr FX7_DrawEye_Inc
	jp TV5
	


.FX7_DrawEye_Inc
	SetMaster NeutralMaster+1	;solid only for player and undestructible
	
.FX7_DrawEye
	push DE
	ex AF,AF'
	CALL TSPGADD
	ld C,(IY+3)
	ld B,(IY+4)
	call SPNS_BG
	pop DE
	jp TV5
	
	
;******************************
;*** TOP AND BOTTOM OPENERS ***
;******************************
;medusa generator
;
.FX8	
	jp nc,FX8_nodie	;is dying ?
	
	push AF
	
	ld A,(FRAME)		;if dying on pair frame, draw it to avoid a hole in level
	and 1
	jr z,FX8_die_allow
	
	pop AF
	jr FX8_nodie
	
.FX8_die_allow
	pop AF
	jp TV5
	
.FX8_nodie
	jr z,FX8_notHit
	
	xor A
	call SND_SfxPlay
	
	ex AF,AF'
	push HL
	push BC
	
	ld B,53
	ld HL,FX8_table

;are we on first sprite of the animation ?	
	ld A,(FRAME)
	and 7
	srl a
	dec A
	and 3
	
	jr nz,FX8_predone	;no so ignore
	
	ld B,13
	ld HL,FX8_table_hit
	
	jr FX8_predone
	
	
;not hit , normal sprites	
.FX8_notHit

	ex AF,AF'
	push HL
	push BC
	
	ld B,53
	ld HL,FX8_table
	
.FX8_predone
	ld (FX8_table_set),HL
	
	;check if not on screen 
	ld A,C
	sub 5
	cp 27
	jr nc,FX8_SkipFire	
	
	ld A,(FRAME)
	and 63
	cp 16
	jr nc,FX8_SkipFire
	cp 8
	call z,FX8_SpawnBrain

	srl A	;per 2
	ld C,A
	ld B,0
FX8_table_set	EQU $+1
	ld HL,FX8_table
	add HL,BC
	ld B,(HL)	
	
.FX8_SkipFire	
	ld A,(FRAME)
	and 7
	srl a
	
	dec A
	and 3
	
	add B
	pop BC
	pop HL
	ex AF,AF'

		
	ld A,(FRAME)
	and 7
	cp 1
	jr nz,FX8_Draw	
	
	dec (IY+3)
	
	jr FX8_Draw
.FX8_SpawnBrain
	push HL
	push AF
	
	ld HL,FX8_Spawn
	ld A,(DE)
	and 2
	jr z,FX8_SpawnBrain_NotReverse
	
	ld HL,FX8_Spawn+3
	
.FX8_SpawnBrain_NotReverse	
	ld A,C
	inc A
	inc A
	inc HL
	ld (HL),A
	dec HL	

	call FORCESYNC
	
	ld A,sfx_medusa_level2
	call SND_SfxPlay
	
	pop AF
	pop HL
	ret
	
.FX8_Draw
	push DE
	push BC
	ld DE,#0808
	call REND_EraseZone
	pop BC
	pop DE

	jp TV2

	
	
.FX8_table
	db 57,57,61,61,61,61,57,57
.FX8_table_hit
	db 14,14,15,15,15,15,14,14
.FX8_Spawn
	db 38,0,18;A
	db 41,0,2

;***********************
;*** MOLLUSC TUBES ***
;***********************

FX9	;LD HL,5*256+5
	;CALL CHOP
 	;CALL BUFFOFF
	;LD A,255
	;LD (SPRITE),A
 	;JP TV1
	push DE
	ex AF,AF'
	CALL TSPGADD
	ld C,(IY+3)
	ld B,(IY+4)
	push BC
	push DE
	push HL
	call REND_EraseZone
	pop HL
	pop DE
	pop BC
	call SPNS_BG
	pop DE
	jp TV5
	
;**************	
;*** medusa  ***
;**************
; do the chaining
.FX10	
	;check for end SP pattern
	LD A,(DE)
	CP 128
	jp C,TV1
	;get current sequence
	push HL
	call THEM_ComputeSequence
	ld A,(HL)
	inc HL
	or (HL)
	pop HL
	jp nz,TV1
	
	;if end of the sequence, spawn second part of the medusa
	
	push HL
	
	ld HL,FX10_Spawn
	inc HL
	ld (HL),C
	inc HL
	ld (HL),B
	dec HL
	dec HL
	
	call FORCESYNC
	pop HL
	
	jp TV1
	
FX10_Spawn	db 39,0,0



;
;NO ACTION
 FXA0	JP TV3
;
;HALF SPEED
FXA1	
	LD A,(FRAME)
	AND 1
 	JP NZ,TV3
 	JP TV4
;
;MOLLUSC EYE
.FXA2	
	XOR A
 	;LD (CADD+1),A
 	JR FXA1
 ;
;SCORPION WHITE FLASH OFF
FXA3	LD A,(FXBYTE2)
	AND A
 	JR Z,FXA1
 	XOR A
 	;LD (CADD+1),A
 	LD (FXBYTE2),A
	JP TV4
;TOP AND BOTTOM OPENERS
FXA4	
	;CALL BUFFON
 	JP TV3
;
FXA5
 ;
FXA6
 ;
;PODDER TOP PILL
 FXA7	
	LD L,5
	JR FXA15A
 ;
;PODDER BOTTOM PILL
FXA8	
	LD L,5
	JR FXA15A
 ;
;PODDER BULLETS (1)
;FXA9	LD L,1
 ;	JR FXA15A
;
;PODDER MINI LASER (2)
 ;FXA10	LD L,2
;	JR FXA15A
;
;PODDER LASER (3)
FXA10
FXA11	LD L,1
 	JR FXA15A
 ;
;PODDER BLOB (3)
 FXA9
 FXA12	LD L,3
 	JR FXA15A
 ;
;PODDER CIRCLE (3)
 FXA13	LD L,2
 	JR FXA15A
 ;
;PODDER BONUS
FXA14	LD L,6
 	JR FXA15A
 ;
;PODDER MISSLIE
FXA15	LD L,4
 FXA15A	CALL FXA99
	LD A,(JEW1)
 	AND A
 	JR NZ,FXA15B
;
	LD (JEW1X),BC
 	LD A,L
	LD (JEW1),A
 	LD A,(FRAME)
	DEC A
 	AND 7
 	LD (JEW1P),A
	JP FXA1
 ;
FXA15B	LD (JEW2X),BC
 	LD A,L
	LD (JEW2),A
 	LD A,(FRAME)
	DEC A
 	AND 7
 	LD (JEW2P),A
	JP FXA1
;****************************************
;5+16*0
 FXA98	
	ld A,sfx_L1_Boss	
	call SND_SfxPlay
 
	ld (FX98_last),IY	;save last one
	;ld (IY+5),11 ;11*16
	PUSH IX
	LD IX,ALIENFIRE
 	LD (IX+0),1+32
	LD (IX+3),2+32
	LD (IX+6),4+32
	LD (IX+9),8+32
	LD (IX+12),5+32
 	LD (IX+15),6+32
 	LD (IX+18),9+32
 	LD (IX+21),10+32
	LD H,B
	LD L,C
	INC H
 	INC L
 	LD A,8
FXA98A	
	LD (IX+1),L
 	LD (IX+2),H
 	INC IX
	INC IX
	INC IX
	DEC A
 	JR NZ,FXA98A
	POP IX
	;LD HL,3*256+HALF+1
	;CALL BEEP
 	RET
.FX98_last
	dw 0
;****************************************
 FXA99	LD A,(IY+0)
	AND A
 	JR NZ,FXA99A
	RET
 FXA99A	POP HL
	JP FXA1
;****************************************

read "l2_master_data.asm"