 
ORG level_start

lvl_offset EQU 8 ;14
tur_offset EQU 1

IF output_files
write "bin/level1.lvl"
ENDIF

;*	LEVEL 1 DATA
;

BossPos	EQU 98-lvl_offset

START	DEFB 0
SYNCHRO	DEFW 0000

START1	DEFB 0 ;BossPos ;60-lvl_offset ;tst_pos ;BossPos ;DEFB 8
START2	DEFB 37-lvl_offset
START3	DEFB 75-lvl_offset

SYNCHRO1	DEFW SYNC1 ;seq_boss ;tst_sync ;seqX61 ;seq_boss ;seqX60 ;SYNC1 ;SYNC3 ;SYNC1
SYNCHRO2	DEFW SYNC2
SYNCHRO3	DEFW SYNC3

TSPRADD		DEFW 0
TADD		DEFW 0
SEQTABLE	DEFW SQTABLE
SPEVENT1	DEFW SPEV1
SPEVENT2	DEFW SPEV2
;DEFB 0,0,0

;palette stuff 16 colors+border
.lvl_pal
	db 0,26,11,6,3,20,10,2,1,25,16,18,9,15,4,0
	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 0 
.lvl_skip
	dw #300	;music to skip on music restart
.lvl_init
	dw	l1_init	;called after loading
.lvl_reinit
	dw	l1_reinit	;called each time player dies
	
.l1_init

	;registers BG effects
	ld HL,STARS_Init
	ld (BG_LevelEffect0_Init),HL
	ld HL,L1BG_Init
	ld (BG_LevelEffect1_Init),HL
	
	ld HL,STARS_Run
	ld (BG_LevelEffect0_Run),HL
	ld HL,L1BG_Run
	ld (BG_LevelEffect1_Run),HL

	ld HL,STARS_Stop
	ld (BG_LevelEffect0_Stop),HL
	ld HL,L1BG_Stop
	ld (BG_LevelEffect1_Stop),HL
	
	ret

.l1_reinit
	xor A
	ld (FX5_Wheel_ptr),A
	ld (FX5_Offset),A
	ld (FX5_Destroyed),A
	
	ld A,64
	ld (FX7_shotCounter),A
	ret

;	LEVEL	1 - 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
	;DEFB 0,1,99,11,0 ;start level music
	;LVL_Music	0,1,0
	START_EFFECT 0,1,1
	;LVL_BGcolor	0,1,1
	CHECK_POINT 16-lvl_offset,0
.SYNC1bis	
	DEFB 16-lvl_offset,1,99,4,0
L0_MASTER4		EQU $-1
L0_MASTER4_val	EQU 4
	
 	DEFB 16-lvl_offset,1,1,31,4
	DEFB 16-lvl_offset,5,1,31,1
	DEFB 16-lvl_offset,10,1,31,7
 	DEFB 16-lvl_offset,15,1,31,3
	
 	DEFB 17-lvl_offset,16,1,31,10
	DEFB 17-lvl_offset,21,1,31,7
 	DEFB 17-lvl_offset,26,1,31,13
	DEFB 17-lvl_offset,31,1,31,9
 	DEFB 18-lvl_offset,0,8,31,15
 	DEFB 18-lvl_offset,26,5,31,14
	DEFB 18-lvl_offset,29,5,31,14
	DEFB 19-lvl_offset,0,5,31,14
 	DEFB 19-lvl_offset,3,5,31,14
 	DEFB 19-lvl_offset,6,5,31,14
 	DEFB 20-lvl_offset,0,2,31,12
 	DEFB 20-lvl_offset,3,2,31,12
 	DEFB 20-lvl_offset,6,2,31,12
 	DEFB 20-lvl_offset,9,2,31,12
 	DEFB 20-lvl_offset,12,2,31,12
	DEFB 21-lvl_offset,0,1,31,10
 	DEFB 21-lvl_offset,6,1,31,7
	DEFB 21-lvl_offset,12,1,31,9
 	DEFB 23-lvl_offset,9,1,31,9
	DEFB 23-lvl_offset,18,1,31,3
 	DEFB 23-lvl_offset,27,1,31,1
 	DEFB 24-lvl_offset,4,1,31,8
	DEFB 24-lvl_offset,13,1,31,3
 	DEFB 24-lvl_offset,22,1,31,10
	DEFB 24-lvl_offset,31,1,31,1
 	DEFB 25-lvl_offset,8,1,31,3
	DEFB 25-lvl_offset,17,1,31,9
 	DEFB 25-lvl_offset,26,1,31,2
 	DEFB 26-lvl_offset,0,1,31,5
	DEFB 26-lvl_offset,9,1,31,7
	DEFB 26-lvl_offset,18,1,31,9
 	DEFB 26-lvl_offset,27,1,31,1
 	DEFB 27-lvl_offset,4,1,31,3
	DEFB 27-lvl_offset,8,24,33,5
 	DEFB 27-lvl_offset,13,1,31,9
 	DEFB 27-lvl_offset,22,1,31,4
 	DEFB 27-lvl_offset,31,1,31,10
	DEFB 28-lvl_offset,8,1,31,6
	DEFB 29-lvl_offset,0,12,24,0
 	DEFB 29-lvl_offset,0,1,31,6
	DEFB 29-lvl_offset,16,1,31,4
 	DEFB 29-lvl_offset,28,8,31,15
	
	
	STOP_EFFECT	30-lvl_offset,0	;stop starfield

	DEFB 30-lvl_offset,10,33,30,15
 	DEFB 30-lvl_offset,24,8,31,15

	
	
	DEFB 32-lvl_offset,0,99,4,4
	DEFB 32-lvl_offset,0,8,31,15
	

 	DEFB 33-lvl_offset,16,8,31,15
	DEFB 33-lvl_offset,16,7,254,15
 	DEFB 35-lvl_offset,16,15,28,7
	DEFB 36-lvl_offset,0,2,31,5
	DEFB 36-lvl_offset,3,2,31,5
	DEFB 36-lvl_offset,6,2,31,5
	DEFB 36-lvl_offset,9,2,31,5
	DEFB 36-lvl_offset,12,2,31,5

	CHECK_POINT 37-lvl_offset,0
.SYNC2
	DEFB 37-lvl_offset,14,16,25,253
 	DEFB 38-lvl_offset,14,45,252,15
	DEFB 39-lvl_offset,16,2,31,11
	DEFB 42-lvl_offset,6,14,28,255
 	DEFB 42-lvl_offset,18,14,31,4
	DEFB 42-lvl_offset,24,14,31,18
 	DEFB 42-lvl_offset,30,14,28,18
 	DEFB 44-lvl_offset,6,14,22,255
 	DEFB 44-lvl_offset,12,14,31,255
	DEFB 44-lvl_offset,24,14,31,18
 	DEFB 44-lvl_offset,30,14,22,18
	
	LVL_FLcolor 46-lvl_offset,0,0
	START_EFFECT 46-lvl_offset,0,2
	
	
 	DEFB 46-lvl_offset,6,14,16,255
 	DEFB 46-lvl_offset,12,14,31,255
	DEFB 46-lvl_offset,18,14,31,8
	DEFB 46-lvl_offset,24,14,31,18
	
	
	
 	DEFB 48-lvl_offset,6,14,10,255
 	DEFB 48-lvl_offset,12,14,31,255
	DEFB 48-lvl_offset,16,14,31,4
	DEFB 48-lvl_offset,16,14,31,12
 	DEFB 48-lvl_offset,16,14,31,16
 	DEFB 48-lvl_offset,18,14,31,10

	LVL_FLcolor 49-lvl_offset,0,1
	
	LVL_BGcolor	50-lvl_offset,0,1
	LVL_FLcolor 50-lvl_offset,0,2
	;LVL_BGcolor	50-lvl_offset,8,10

 	DEFB 50-lvl_offset,0,19,31+tur_offset,4
	DEFB 50-lvl_offset,0,22,31+tur_offset,14
	
	LVL_BGcolor	51-lvl_offset,0,10
	LVL_FLcolor	51-lvl_offset,0,20
	
 	DEFB 51-lvl_offset,0,19,31+tur_offset,4
	DEFB 51-lvl_offset,0,22,31+tur_offset,14
 	DEFB 51-lvl_offset,16,15,28,7
	DEFB 52-lvl_offset,15,19,31+tur_offset,6
	DEFB 52-lvl_offset,15,22,31+tur_offset,12
 	DEFB 53-lvl_offset,15,19,31+tur_offset,6
	DEFB 53-lvl_offset,15,22,31+tur_offset,12
	
	;LVL_BGcolor	54-lvl_offset,0,2

 	DEFB 56-lvl_offset,16,25,31,9
	DEFB 57-lvl_offset,1,33,31,15
	DEFB 57-lvl_offset,24,26,31,9
	DEFB 60-lvl_offset,8,3,24,254
	DEFB 60-lvl_offset,12,3,24,254
   	DEFB 60-lvl_offset,15,99,3,25
	DEFB 60-lvl_offset,15,19,31+tur_offset,2
	DEFB 60-lvl_offset,16,3,24,254
 	DEFB 60-lvl_offset,20,3,24,254
 	DEFB 60-lvl_offset,24,3,24,254
	
.seqX61

	FORCE_Slot 1,61-lvl_offset,0,10,48,16 ;wheel of the death

	DEFB 61-lvl_offset,7,99,3,26
	DEFB 61-lvl_offset,7,19,31+tur_offset,2	;additionnal turret
	

	DEFB 72-lvl_offset,15,19,31+tur_offset,6
	DEFB 73-lvl_offset,15,19,31+tur_offset,6
	DEFB 73-lvl_offset,16,17,28,5
	DEFB 74-lvl_offset,15,19,31+tur_offset,2
	
	;STOP_EFFECT 75-lvl_offset,0
	
	DEFB 75-lvl_offset,15,19,31+tur_offset,2
	
	CHECK_POINT 75-lvl_offset,15
.SYNC3


	
	DEFB 76-lvl_offset,0,1,31,7
 	DEFB 76-lvl_offset,6,1,31,5
	DEFB 76-lvl_offset,12,1,31,8
 	DEFB 76-lvl_offset,15,19,31+tur_offset,2
	DEFB 77-lvl_offset,1,33,31,15
	DEFB 77-lvl_offset,15,19,31+tur_offset,2
	DEFB 78-lvl_offset,12,1,31,10
	DEFB 78-lvl_offset,15,19,31+tur_offset,2
	DEFB 78-lvl_offset,16,27,31,15
 	DEFB 78-lvl_offset,18,1,31,7
 	DEFB 78-lvl_offset,24,1,31,9
 	DEFB 79-lvl_offset,15,19,31+tur_offset,2
	DEFB 82-lvl_offset,1,28,30,9
 	DEFB 82-lvl_offset,1,1,31,11
 	DEFB 82-lvl_offset,4,3,23,254
	DEFB 82-lvl_offset,8,3,23,254
	DEFB 82-lvl_offset,12,3,23,254
 	DEFB 82-lvl_offset,15,19,31+tur_offset,6
	DEFB 82-lvl_offset,15,22,31+tur_offset,12
 	DEFB 82-lvl_offset,16,3,23,254
 	DEFB 82-lvl_offset,20,3,23,254
 	DEFB 82-lvl_offset,24,3,23,254
 	DEFB 82-lvl_offset,28,3,23,254
 	DEFB 83-lvl_offset,0,3,23,254
	DEFB 83-lvl_offset,4,3,23,254
	DEFB 83-lvl_offset,8,3,23,254
	DEFB 83-lvl_offset,15,19,31+tur_offset,6
	DEFB 83-lvl_offset,15,99,3,24
	DEFB 83-lvl_offset,15,22,31+tur_offset,12
 	DEFB 83-lvl_offset,24,18,28,5
	DEFB 84-lvl_offset,16,31,14,251
	DEFB 86-lvl_offset,24,29,30,8
	
	.tst_sync
tst_pos	EQU 89-lvl_offset	
	
	DEFB 90-lvl_offset,0,19,31+tur_offset,2
	DEFB 91-lvl_offset,0,19,31+tur_offset,2
	DEFB 92-lvl_offset,0,19,31+tur_offset,2
 	DEFB 93-lvl_offset,0,19,31+tur_offset,2
	
	DEFB 93-lvl_offset,1,32,25,5
	
	DEFB 94-lvl_offset,15,19,31+tur_offset,4
	DEFB 94-lvl_offset,22,30,30,10
	
	LVL_BGcolor	95-lvl_offset,0,1
	LVL_FLcolor 95-lvl_offset,0,2
	
	
 	DEFB 95-lvl_offset,15,19,31+tur_offset,4
	
	LVL_BGcolor	96-lvl_offset,0,0
	LVL_FLcolor 96-lvl_offset,0,1
	
	LVL_FLcolor 97-lvl_offset,0,0
	
	START_EFFECT 98-lvl_offset,1,0	;stop effect
	
.seq_boss
	FORCE_Slot	24,99-lvl_offset,0,32,25,5	;red gobot 2
	
	;DEFB 99-lvl_offset,0,99,11,8 ;boss music
	LVL_Music	99-lvl_offset,0,8
 ;
	LVL_SetSpec1	100-lvl_offset,0,1	;attach connector
	LVL_SetSpec2	100-lvl_offset,0,0	;set boss phase

	FORCE_Slot	1,100-lvl_offset,0,42,38,0	;spawn boss
	FORCE_Slot	25,100-lvl_offset,0,23,44,15	;:tail
	FORCE_Slot	20,100-lvl_offset,0,46,37,2		;eye 1
	FORCE_Slot	21,100-lvl_offset,0,6,37,16		;eye 2
	FORCE_Slot	22,100-lvl_offset,0,46,41,10	;eye 3
	FORCE_Slot	23,100-lvl_offset,0,6,43,13		;eye 4

 ;stop scrolling	
 
	FORCE_Slot	2,105-lvl_offset,28,20,24,9	;head

	SCROLL_Stop 106-lvl_offset,1
	
	
	
.SPECSYNC
 	;DEFB 123-lvl_offset,0,99,5,0	;end level
	db	 0,0	;no end !
 ;
;	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
;
;RED TWISTERS
SQ1	DEFB 0,65,18 ;0,1+64,2+16*1
 	DEFW SP1,SP1,SP1,SP1,0
;BUTTERFLIES 1
SQ2	DEFB 0,65,34 ;0,1+64,2+16*2
 	DEFW SP2,SP2,0
;BUTTERFLIES 2
SQ3	DEFB 0,65,34 ;0,1+64,2+16*2
 	DEFW SP3,SP3,SP3A,SP3B,SP3B,SP3B,SP3B,0
 ;ALIEN CONNECTORS STAY ON
SQ4	;DEFB 0,63,28 ;0,63,12+16*1
	;DEFW SP30A,65535
;BUTTERFLIES 3
SQ5	DEFB 0,65,34 ;0,1+64,2+16*2
 	DEFW SP5,SP5,SP5A,SP5A,SP5B,SP5B,0
;BIG ALIEN EYES 1
SQ6	DEFB 0,32,51 ; 3,32,3+16*3
 	DEFW SP15,65535
 ;WALKER 6
SQ7	DEFB 17,65,34 ;1+16,1+64,2+16*1
	DEFW SP6,SP6,SP6,SP6,SP6,SP6,SP8D,SP6,SP6,0
 ;WALKER 1/3/4/5
SQ8	DEFB 17,65,34 ;1+16,1+64,2+16*1
	DEFW SP8,SP8,SP8,SP8,0
;WORM TWISTERS 2
SQ9	DEFB 3,62,28 ;7,63,12+16*1
	DEFW SP20,SP20,SP20,SP20C,0
	
	
	
	
;COMPLETE WHEEL OF THE DEATH !
SQ10	DEFB 5,2,32+8 ;5+16,63,12+16*2 800 points for center
		DEFW SP10,#FFFF
		
		
;BLUE CIRCLE ALIEN
SQ11	

;BLUE GOBOT
L0_MASTER0		EQU $+1
L0_MASTER0_val	EQU 28*2
SQ12	DEFB 10,28,69 ;10,28,5+4*16
 	DEFW SP12,SP12,SP12,SP12,SP12,SP12A,65535
 ;BLUE GOBOT PROJECTILE
SQ13	DEFB 11,63,28 ;11,63,12+16*1
	DEFW SP13,SP13,0
;NODDING SNALIEN
SQ14	DEFB 28,65,35 ;12+16,1+64,3+2*16
	DEFW SP14B,SP14,SP14C,SP14A,65535
 ;WALKER 7/9
SQ15	DEFB 17,65,34 ;1+16*1,1+64,2+16*1
 	DEFW SP8A,SP8B,SP8AA,SP8BB,SP8F,SP8B,SP8,SP8,0
;WALKER 8
SQ16	DEFB 17,65,34 ;1+16,1+64,2+16*1
 	DEFW SP8A,SP8A,SP8A,SP8B,SP8AA,SP8B,SP8E,SP8E
 	DEFW SP8AA,SP6,SP8B,SP8,SP8E,SP8E,SP8E,SP8E,SP8AA
 	DEFW SP6,SP8,SP6,SP8AA,SP8E,SP8AA,SP8F,0
;WALKER 10
SQ17	DEFB 17,65,34 ;1+16*1,1+64,2+16*1
 	DEFW SP8A,SP8B,SP8AA,SP8BB,SP8C,SP8CC,SP8B,SP8,SP8,0
 ;WALKER 11
SQ18	DEFB 17,65,34 ;1+16*1,1+64,2+16*1
 	DEFW SP8A,SP8B,SP8AA,SP8BB,SP8C,SP8B,SP8AA,SP8BB
	DEFW SP8C,SP8B,SP8,SP8,0
;TOP GUN TURRET
SQ19	DEFB 102,65,17 ;16+1 ;6+16*6,1+64,1+16*3
 	DEFW SP21,65535
 ;END ALIEN - SMALL HEAD
SQ20	DEFB 16+7,62,28 ;1+16,62,12+16*1
	DEFW SP19,65535
 ;WORM TWISTERS
SQ21	DEFB 3,62,28 ;7,63,12+16*1
	DEFW SP20,SP20,SP20,SP20B,0
;BOTTOM GUN TURRET
SQ22	DEFB 102,65,17 ;6+16*6,1+64,1+16*3
 	DEFW SP22,65535
 ;BIG ALIEN TAIL
SQ23	DEFB 9,63,28 ;9,63,12+16*1
 	DEFW SP24,65535
 ;PODDER 1
SQ24	DEFB 146,1,34 ;2+16*9,1,2+32
	DEFW SP11A,SP11B,SP11C,SP11BB,SP11A,SP11G
 	DEFW SP11E,SP11G,SP11C,SP11BB,0
 ;PODDER 2
SQ25	DEFB 226,1,34 ;2+16*14,1,2+32
 	DEFW SP11A,SP11B,SP11C,SP11BB,SP11B,SP11B,SP11BB,SP11C,0
 ;PODDER 3
SQ26	DEFB 162,1,34 ;2+16*10,1,2+32
 	DEFW SP11A,SP11B,SP11C,SP11B,SP11CC,SP11D
 	DEFW SP11DDD,SP11G,SP11E,SP11E,0
;PODDER 4
SQ27	DEFB 114,1,34 ;2+16*7,1,2+32
	DEFW SP11B,SP11C,SP11BB,SP11A,SP11G,SP11F,SP11F,SP11F,SP11G
 	DEFW SP11C,SP11B,SP11A,SP11G,SP11E,SP11E,SP11GG,SP11H,SP11II
	DEFW SP11H,SP11II,SP11H,0
 ;PODDER 5
SQ28	DEFB 210,1,34 ;2+16*13,1,2+32
 	DEFW SP11B,SP11B,SP11A,SP11G,SP11E,SP11E,SP11E,SP11GG,SP11H
 	DEFW SP11II,SP11JJ,SP11GG,SP11E,SP11G,SP11C,SP11BB,SP11A,0
;PODDER 6
SQ29	DEFB 242,1,34 ;2+16*15,1,2+32
 	DEFW SP11B,SP11A,SP11BB,SP11CC,SP11CC,SP11DD
	DEFW SP11DDD,SP11G,SP11E,SP11G,SP11C,SP11BB,0
 ;PODDER 7
SQ30	DEFB 178,1,34 ;2+16*11,1,2+32
 	DEFW SP11C,SP11BB,SP11A,SP11B,SP11CC,SP11BB,SP11D,SP11D
 	DEFW SP11DDDD,SP11G,SP11F,SP11G,SP11C,SP11C,SP11BB,0
;WALKER 12
SQ31	DEFB 17,1,34 ;1+16*1,1,2+16*1
	DEFW SP8A,SP8A,SP8A,SP8B,SP8AA,SP8BB,SP8C,SP8B,SP8,0
;RED GOBOT
L0_MASTER1		EQU $+1
L0_MASTER1_val	EQU 62

SQ32	DEFB 29,40,72 ;13+16*1,40,8+4*16
	DEFW SP25,SP25,SP25A,SP25B,SP25B,SP25B,SP25A,SP25FF
 	DEFW SP25F,SP25F,SP25F,SP25F,SP25D,SP25D,SP25D,0
;MISSILE WALKER
L0_MASTER2		EQU $+1
L0_MASTER2_val	EQU 48
SQ33	DEFB 30,16,37 ;14+16,5,5+1*16
 	DEFW SP26A,SP26A,SP26E,SP26BB,SP26EE,SP26CC,SP26DD
	DEFW SP26DD,SP26CC,SP26EE,SP26A,SP26E,SP26C,SP26D
 	DEFW SP26D,SP26C,SP26A,SP26EE,SP26CC,SP26DD,SP26DD,SP26CC,SP26A,0
 ;MISSILE 1 L	FIXED SCORING , 0 points !
SQ34	DEFB 0,1,48 ;0,1,12+3*16
	DEFW SP27A,SP27A,SP27C,SP27B,SP27B,0
;MISSILE 2 L
SQ35	DEFB 0,1,48 ;0,1,12+3*16
	DEFW SP27A,SP27A,SP27CC,SP27B,SP27B,0
 ;MISSILE 1 R
SQ36	DEFB 0,1,48; 0,1,12+3*16
	DEFW SP27A,SP27A,SP27D,SP27B,SP27B,0
;MISSILE 2 R
SQ37	DEFB 0,1,48 ;0,1,12+3*16
	DEFW SP27A,SP27A,SP27DD,SP27B,SP27B,0
 ;RED GOBOT MISSILE 1
 SQ38	DEFB 31,1,48 ;15+16,1,12+3*16
	DEFW SP28A,SP28B,SP28C,SP28D,65535
;RED GOBOT MISSILE 2
SQ39	DEFB 31,1,48 ;15+16,1,12+3*16
	DEFW SP28B,SP28C,SP28D,SP28A,65535
;RED GOBOT MISSILE 3
SQ40	DEFB 31,1,48 ;15+16,1,12+3*16
	DEFW SP28C,SP28D,SP28A,SP28B,65535
;RED GOBOT MISSILE 4
SQ41	DEFB 31,1,48 ;15+16,1,12+3*16
	DEFW SP28D,SP28A,SP28B,SP28C,65535
;BIG ALIEN
SQ42	DEFB 8,63,51 ;8,63,3+16*3
	DEFW SP29,65535
 ;ALIEN CONNECTORS BRING ON
SQ43	DEFB 0,63,28 ;0,63,12+16*1
 	DEFW SP30,SP30,SP30,SP30A,SP30,SP30,SP30A,0
 ;ORDINARY CIRCLE ALIENS-FIRE
SQ44	
;ADD ON WALKER
SQ45	DEFB 17,65,34 ;1+16,1+64,2+16*1
		DEFW SP6,SP6,SP6,SP8E,SP8AA,SP8E,SP8E,SP8E
		DEFW SP8AA,SP8E,SP8E,SP8E,SP8AA,0
 ;BIG ALIEN EYES 2
SQ46	DEFB 0,32,51 ;3,32,3+16*3
	DEFW SP15A,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
;
 ;RED TWISTERS
SP1	DEFB 49,16,50,24,51,16,50,20,49,20,50,16,51,24,50,16+128
 ;BUTTERFLIES 1
 SP2	DEFB 18,22,18,22,18,22,18,22,19,16,19,16,19,16,19,16
 	DEFB 18,24,18,24,18,24,18,24,19,16,19,16,19,16,19,16+128
;BUTTERFLIES 2
 SP3	DEFB 17,8,17,8,17,8,17,8+128
 SP3A	DEFB 18,24,18,24,19,16,19,16,19,16,19,16+128
SP3B	DEFB 19,16,19,16,19,16,19,16,19,16,19,16+128
;BUTTERFLIES 3
 SP5	DEFB 18,20+2,18,20+2,18,20+2,18,20+2
 	DEFB 18,20+2,18,20+2,18,20+2+128
SP5A	DEFB 19,16,19,16,19,16+128
SP5B	DEFB 18,24,18,24,18,24,18,24,18,24,18,24,18,24+128
;STRAIGHT WALKER L / R
 SP6	DEFB 53,33,54,33,53,33,55,33+128
 ;STRAIGHT WALKER R / L
 SP8	DEFB 53,16,54,16,53,16,55,16
 SP8AA	DEFB 53,16,54,16,53,16,55,16+128
 SP8A	DEFB 56,8,56,8,56,8,56,8,56,8,56,8+128
SP8B	DEFB 55,0
 SP8BB	DEFB 55,0+128
SP8C	DEFB 56,20,56,20,56,16,56,16,56,16,56,24,56,24
SP8CC	DEFB 56,24,56,24+128
 SP8D	DEFB 53,1,56,37,56,37,56,37,56,33,56,41,55,1+128
SP8E	DEFB 55,0,55,0,55,0,55,0+128
SP8F	DEFB 56,20,56,20,56,16,56,24,56,24,56,24,56,24+128
;WHEEL OF DEATH ALIENS
 ;		BITS 0-1 = ORIENTATION	;1,2
;		BIT 2 = UP				;4
;		BIT 3 = DOWN			;8
;		BIT 4 = LEFT			;16
;		BIT 5 = RIGHT			;32
 ;		BIT 6 =
;		BIT 7 = END OF PATTERN	;128
.SP10	
	
	DEFB 58,128	

;PODDERS

SP11A	DEFB 33,24,33,24							;FLY D/L 6
SP11AA	DEFB 33,24,33,24,33,24,33,24+128	;FLY D/L 4
SP11B	DEFB 33,16,33,16							;FLY L 4
SP11BB	DEFB 33,16,33,16+128						;FLY L 2
SP11C	DEFB 33,20,33,20							;FLY U/L 6
SP11CC	DEFB 33,20,33,20,33,20,33,20+128	;FLY U/L 4
SP11D	DEFB 33,8							;DROP 4
SP11DD	DEFB 33,8							;DROP 3
SP11DDD	DEFB 33,8							;DROP 2
SP11DDDD	DEFB 33,8+128							;DROP 1
SP11E	DEFB 31,16,30,16,31,16,30,16+128	;WALK L
SP11F	DEFB 31,33,30,33,31,33,30,33+128	;WALK R
SP11G	DEFB 32,0,32,0+128						;LAND IMPACT L
SP11GG	DEFB 32,1,32,1+128						;LAND IMPACT R
SP11H	DEFB 33,37,33,37							;FLY U/R 6
SP11HH	DEFB 33,37,33,37,33,37,33,37+128	;FLY U/R 4
SP11II	DEFB 33,33,33,33+128						;FLY R 2
SP11JJ	DEFB 33,41,33,41,33,41,33,41+128	;FLY D/R 4
 ;BLUE GOBOT
SP12	DEFB 41,0,41,0,41,0
 SP12A	DEFB 41,0+128
;BLUE GOBOT PROJECTILE
 SP13	DEFB 12,16,12,16+2,12,16,12,16+2
		DEFB 12,16,12,16+2,12,18+128
;NODDING SNALIEN
 SP14	DEFB 35,0,36,0,36,0+128
 SP14A	DEFB 37,0,36,0,36,0+128
SP14B	DEFB 35,0+128
SP14C	DEFB 37,0+128
;BIG ALIEN EYES
SP15	DEFB 64,0+128
 SP15A	DEFB 64,2+128
;BIG ALIEN - SMALL HEAD
;
SP19	
	DEFB 65,16,65,0,65,16
	DEFB 65,0,66,0,66,0,66,0,66,0
	
	DEFB 67,0,67,0,67,0,67,0,67,0,67,0
	
	DEFB 66,0,65,0,66,32,66,32
	DEFB 66,0,66,0,66,0+128
 ;
;WORM TWISTERS
SP20	DEFB 38,16+3,39,16+3,38,16,39,16,38,16+3,39,16+3+128
SP20B	DEFB 38,20+3,39,20+3,38,20,39,20+128
SP20C	DEFB 38,24+3,39,24+3,38,24,39,24+128
 ;
;TOP GUN TURRET
SP21	DEFB 68,2,68,2,68,2,68,2,68,2,68,2,68,2,68,2+128
 ;
;BOTTOM GUN TURRET
SP22	DEFB 68,0,68,0,68,0,68,0,68,0,68,0,68,0,68,0+128
 ;
;DUMMY BIG ALIEN TAIL
SP24	DEFB 57,0+128
 ;RED GOBOT
 
; SQ32	DEFB 29,40,72 ;13+16*1,40,8+4*16
;	DEFW SP25,SP25,SP25A,SP25B,SP25B,SP25B,SP25A,SP25FF
; 	DEFW SP25F,SP25F,SP25F,SP25F,SP25D,SP25D,SP25D,0

SP25	DEFB 43,8,43,8,43,8,43,8+128
SP25A	DEFB 43,0,43,0,43,0,43,0+128
SP25B	DEFB 43,16,44,16,43,16,44,16+128
SP25D	DEFB 43,16,43,16,43,16,43,16
		DEFB 43,16,43,16,43,16,43,16+128
		
SP25F	DEFB 43,0,43,0,43,0,43,0,43,0,43,0,43,0,43,0
SP25FF	DEFB 43,0,43,0,43,0,43,0,43,0,43,0,43,0,43,0+128
;MISSILE WALKERS
 SP26A	DEFB 21,16,22,16,23,16,22,16					;WALK L 8
 SP26AA	DEFB 21,16,22,16,23,16,22,16+128	;WALK L 4
SP26B	DEFB 21,33,22,33,23,33,22,33					;WALK R 8
 SP26BB	DEFB 21,33,22,33,23,33,22,33+128	;WALK R 4
SP26C	DEFB 24,0,24,0+128						;TILT UP L
 SP26CC	DEFB 24,1,24,1+128						;TILE UP R
SP26D	DEFB 25,0,25,0,25,0,25,0,25,0,25,0+128;WAIT UP L
 SP26DD	DEFB 25,1,25,1,25,1,25,1,25,1,25,1+128;WAIT UP R
SP26E	DEFB 21,0,21,0,21,0,21,0+128					;WAIT DOWN L
SP26EE	DEFB 21,1,21,1,21,1,21,1+128					;WAIT DOWN R
 ;MISSILES
SP27A	DEFB 2,4,2,4,2,4,2,4,2,4+128											;UP 6
 SP27B	DEFB 2,10,2,10,2,10,2,10,2,10,2,10+128 ;DOWN 7
 SP27C	DEFB 3,20,4,16,4,16,3,26+128											;TURN L 1
 SP27CC	DEFB 3,20,3,20,4,16,4,16,3,26,3,26+128	;TURN L 2
SP27D	DEFB 3,37,4,33,4,33,3,43+128											;TURN R 1
 SP27DD	DEFB 3,37,3,37,4,33,4,33,3,43,3,43+128	;TURN R 2
;RED GOBOT MISSILES
SP28A	DEFB 5,4,5,4,6,20,6,20,6,20+128
SP28B	DEFB 7,16,7,16,6,26,6,26+128
 SP28C	DEFB 5,10,5,10,6,43,6,43,6,43+128
SP28D	DEFB 7,33,7,33,6,37,6,37+128
 ;BIG ALIEN
 SP29	DEFB 8,0+128
;BIG ALIEN CONNECTOR
 SP30	;DEFB 9,0,9,0,9,0,9,0,9,0,9,0,9,0,9,16+128
 SP30A	;DEFB 9,0+128
 ;
SPEV1	DEFW FX0,FX1,FX2,FX3,FX4,FX5,FX6,FX7
		DEFW FX8,FX9,FX10,FX11,FX12,FX13,FX14,FX15
;
SPEV2	DEFW FXA0,FXA1,FXA2,FXA3,FXA4,FXA5,FXA6,FXA7
 	DEFW FXA8,FXA9,FXA10,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
pod_offset	EQU 130	;added 'cause podders are now in BASE
 ;PODDER EXPLOSION BYPASS
 FX2
	;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'
	add pod_offset	;base
 	CALL USPGADD
	POP AF
 	AND 3
	jp NZ,THEM6
 	CALL SPNS
 	jp THEM9	

;*****************************
;*** WHEEL OF THE DEATH V2 ***
;*****************************
.FX4
.FX5

	jr nc,FX5_NotDestroyed
	
	ld A,1
	ld (FX5_Destroyed),A
	xor A
	ld (FX5_DestroyCounter),A
	dec A
	ld (FX5_FrameCounter),A
	
	ld (IY+0),63
	
.FX5_NotDestroyed

	ld A,(FX5_FrameCounter)
	inc A
	ld (FX5_FrameCounter),A

	ld A,(FRAME)
	and 7
	jr nz,FX5_NoMove

 	dec (IY+3)
	ld A,(IY+3)
	cp -16
	jr nz,FX5_NoMove

	ld (IY+0),0
	jp TV5
	
.FX5_NoMove

	;ld A,(FRAME)
	;and 3
	;jr nz,FX5_NotDestroyPhase

	ld A,(FX5_Destroyed)
	or A
	jr z,FX5_NotDestroyPhase
	
	ld A,(FX5_DestroyCounter)
	inc A
	cp 32
	jr nc,FX5_NotDestroyPhase
	ld (FX5_DestroyCounter),A
	
.FX5_NotDestroyPhase

	ld A,R
	inc A
	and 15
	cp 13
	jr nc,FX5_NotUpdateShooter

	ld (FX5_CurrentShooter),A
	
.FX5_NotUpdateShooter

	push DE
	
	ld A,(MASTER)
	ld (FX5_Master),A
	
	xor A
	ld (MASTER),A	;all this stuff is understructible !

	ld A,(FRAME)
	and 1
	jr nz,FX5_NoChange

	ld A,(FX5_Wheel_ptr)
	inc A
	cp 3
	jr c,FX5_NoTableCycle
	xor A

	
	ld A,(FX5_Offset)
	inc A
	and 15
	ld (FX5_Offset),A
	
	xor A
.FX5_NoTableCycle
	ld (FX5_Wheel_ptr),A
.FX5_NoChange
	
	ld A,(FX5_Wheel_ptr)
	add A
	ld E,A
	ld D,0
	ld HL,FX5_WheelTable
	add HL,DE
	
	ld E,(HL)
	inc HL
	ld D,(HL)
	ld (FX5_current_table),DE
	
	;ld IX,FX5_WheeltableA
	ld B,12
	ld A,(FX5_Offset)
	ld E,A
	
.FX5_loop
	push BC
	push DE
	
	ld D,B	;save counter
	push DE
	
	ld A,E
	and 15
	add A	;*2
	add A	;*4
	ld E,A
	ld D,0
	
FX5_current_table	EQU $+2
	ld IX,0
	
	add IX,DE

 	LD C,(IY+3)
 	LD B,(IY+4)
	
	ld A,(IX+2)
	add C
	ld C,A
	
	ld A,(IX+3)
	add B
	ld B,A
	
	pop DE
	call FX5_GetSprite
	call FX_DrawSprite
	
	pop DE
	inc E
	
	pop BC
	djnz FX5_loop

	pop DE
	jp TV5
	
.FX5_GetSprite
	ld A,(FX5_Destroyed)
	or A
	jr nz,FX5_GetSpriteDestroyed

	ld A,D
	cp 9
	call Z,FX5_DrawWeakPoint
	
.FX5_GetSpriteElementNotDestroyed

FX5_FrameCounter EQU $+1
	ld A,0
	
	and 15
	jr nz,FX5_GetSprite_NoFire
	
	ld A,(FX5_CurrentShooter)
	cp D
	jr nz,FX5_GetSprite_NoFire
	
	ld A,D
	call ALIENPOW_Fire
	
.FX5_GetSprite_NoFire
	
	ld A,(IX+0)
	add 58
	ex AF,AF'
	ld A,(IX+1)
	ret
	
.FX5_DrawWeakPoint
	ld A,(FX5_Master)
	ld (MASTER),A		;weak point is destructible !
	
	push BC
	push IX
	ld A,(IX+0)
	add 61
	ex AF,AF'
	ld A,(IX+1)
	and 3
	call FX_DrawSprite
	pop IX
	pop BC
	
	xor A
	ld (MASTER),A	;all this stuff is understructible !
	ret
	
.FX5_GetSpriteDestroyed
	ld A,(FX5_DestroyCounter)
	sub D
	
	jr c,FX5_GetSpriteElementNotDestroyed
	

	call FX5_GetSpriteElement_Explode
	
	
	ld A,16
	ex AF,AF'
	xor A
	ret
	
.FX5_GetSpriteElement_Explode
	;cp 7
	cp 5
	ret nc
	
	call FX5_DrawExplo

	ret
	
.FX5_DrawExplo
	push BC
	push DE
	push IX
	ld HL,FX5_exploSpr
	ld E,A
	ld D,0
	add HL,DE
	;ld A,(HL)
	
	;cp 95
	or A
	jr nz,FX5_noexplo_snd
		
	;push AF
	;ld A,(FRAME)
	;and 3
	;jr nz,FX5_explo_snd_notframe
	
	ld A,sfx_explodeB
	call SND_SfxPlay
	
	push HL
	push BC
	ld A,1
	call SCORE_Add
	pop BC
	pop HL
	
.FX5_explo_snd_notframe
	;pop AF
	
.FX5_noexplo_snd

	ld A,(HL)
	
	call USPGADD
	call SPNS
	pop IX
	pop DE
	pop BC
	ret

.FX5_exploSpr
	db 95,95,94,94,97,97


.FX5_Wheel_ptr
	db 0
.FX5_Offset
	db 0
.FX5_Master
	db 0
.FX5_Destroyed
	db 0
.FX5_DestroyCounter
	db 0
.FX5_CurrentShooter
	db 1
	
;*** WOD Table ***
; db sprite offset,mirrors (0-3),xoffset,yoffset

.FX5_WheelTable
	dw FX5_WheeltableA
	dw FX5_WheeltableB
	dw FX5_WheeltableC

.FX5_WheeltableA
	db 0,0,-3,0
	db 0,0,0,0	
	
	db 1,1,3,-1	
	db 1,1,6,-3	
	
	db 2,1,7,-6	
	db 2,1,7,-9		
	
	db 1,3,6,-12	
	db 1,3,3,-14	
	
	db 0,2,0,-15
	db 0,2,-3,-15
	
	db 1,2,-6,-14
	db 1,2,-9,-12	
	
	db 2,0,-10,-9
	db 2,0,-10,-6	
	
	db 1,0,-9,-3
	db 1,0,-6,-1	
	
.FX5_WheeltableB
	db 0,0,-2,0
	db 0,0,1,0
	
	db 1,1,4,-2
	db 1,1,7,-4
	
	db 2,1,7,-7	
	db 2,1,7,-10
	
	db 1,3,5,-13	
	db 1,3,2,-15
	
	db 0,2,-1,-15
	db 0,2,-4,-15
	
	db 1,2,-7,-14
	db 1,2,-9,-11	
	
	db 2,0,-10,-8
	db 2,0,-10,-5
	
	db 1,0,-8,-2
	db 1,0,-5,0	
	
.FX5_WheeltableC
	db 0,0,-1,0
	db 0,0,2,0	
	
	db 1,1,5,-2	
	db 2,1,7,-5
	
	db 2,1,7,-8
	db 1,3,6,-11
	
	db 1,3,4,-14	
	db 0,2,1,-15	
	
	db 0,2,-2,-15
	db 1,2,-5,-15
	
	db 1,2,-8,-13
	db 2,0,-10,-10	
	
	db 2,0,-10,-7
	db 1,0,-09,-4	
	
	db 1,0,-7,-1
	db 0,0,-4,0
	
;*********************************
;*** TOP + BOTTOM GUN TURRET ***
;*********************************
FX6	
	jr c,FX6_Kill
	ld A,(FRAME)
	and 7
	jr nz,FX6_NoMove
	dec C
	ld A,-3
	cp C
	jr z,FX6_Kill
	ld (IY+3),C

.FX6_NoMove 	

	push HL
	push DE

	ld A,(FRAME)
	and 7
	srl A
	ld E,A
	ld D,0
	ld HL,FX6_Table
	add HL,DE

	LD A,(SHIPX)
	INC A
 	CP C

	jr nz,FX6_NotNeutral

	ld DE,4
	add HL,DE

	ld A,(HL)
	ex AF,AF'

	pop DE
	pop HL

	ld A,(DE)

	jr FX6_Done

.FX6_NotNeutral

	push AF

	ld A,(HL)
	ex AF,AF'

	pop AF
	jr NC,FX6_Rev

	pop DE
	pop HL

	ld A,(DE)

	jr FX6_Done
.FX6_Rev
	pop DE
	pop HL

 	LD A,(DE)
	inc A

.FX6_Done

 	JP TVA

.FX6_Kill
	ld (IY+0),0
	ld (IY+8),0
	jp TV4
.FX6_Table
	db 104,103,102,101
	;db 105,106,107,108
	db 108,107,106,105


;BOSS SMALL HEAD
.FX7	
	;jp nc,FX1
	jr nc,FX7_notdie
	
	call BIG_EXPLO_Start
	jp TV5
	
.FX7_notdie	
	jr z,FX7_NotTouched
	
	ex AF,AF'
	add 70
	ex AF,AF'
	SetNullMaster
	
.FX7_NotTouched	
	;check if head wide opened !
	;ld HL,SEQBUFF+9	
	;inc HL
	;ld E,(HL) ;get first pattern address
	;inc HL
	;ld D,(HL)
	;ld A,(DE) ;get current sprite
	ex AF,AF'
	push AF
	ex AF,AF'
	pop AF
	
	cp 67
	jr nz,FX8_Phase2NoShot
	
	;ld A,(FX8_Count)
	;or A
	;jr nz,FX8_Phase2ShotNoReverse
	
	;inc A
	;ld (FX8_Count),A
	;ld A,(FX8_Bullet)
	;xor 28
	;ld (FX8_Bullet),A
	
.FX8_Phase2ShotNoReverse
	
	ld A,(FX8_Shot)
	inc A
	ld (FX8_Shot),A
	cp 2
	jr c,FX7_done	
	xor A
	ld (FX8_Shot),A
	
	push BC
	push DE
	
	ld HL,FX8_Bullet
	ld A,C
	dec A
	inc HL
	ld (HL),A
	dec HL
	call FORCESYNC

FX7_shotCounter	EQU $+1	
	ld A,64
	dec A
	ld (FX7_shotCounter),A
	jr nz,FX7_shotCounterNotReached

	push DE
	push BC
	
	;kill eyes
	ld HL,SEQBUFF+171
	ld B,4
	
.FX7_DestroyEyeLoop
	ld (HL),0
	ld A,8
	add L
	ld L,A
	ld A,128
	or (HL)
	ld (HL),A
	inc HL
	djnz FX7_DestroyEyeLoop


	
	pop BC
	pop DE
	
.FX7_shotCounterNotReached	
	
	;shot sound
	ld A,sfx_L1_Boss	
	call SND_SfxPlay
	
	pop DE
	pop BC
	jr FX7_done	 
	
.FX8_Phase2NoShot

	;xor A
	;ld (FX8_Count),A
	;21
	ld L,21
	ld A,(SHIPY)
	cp B
	jr c,FX7_ShipUp
	
	ld L,9
	
.FX7_ShipUp
	ld A,L
	ld (FX8_Bullet),A
	
.FX7_done	
	
	jp FX1A
	
	


	;SetMaster NeutralMaster+1 
	;LD A,(IY+8)
	;CP 1
	;JP NZ,TV1
 	;INC (IY+8)
 ;LD HL,9*256+HALF+1
 ;CALL BEEP
 	;JP TV1
;**********************
;*** BIG ALIEN EYES ***
;**********************
.FX3	
	SetMaster NeutralMaster+1
	jp TV1

	;JP C,TV5
	;PUSH AF
	;CALL FXA98
	;POP AF
	;JP NC,TV1
	
	
	
	
	;jp TV1 ;added
 	;LD HL,(CIRCHOLD2)
 	;INC L
 	;DEC (HL)
	;LD HL,FXBYTE2
 	;INC (HL)
	;LD A,(HL)
 	;CP 4
	;JP NZ,TV5
 	;LD A,114-lvl_offset
	;LD (TILENO),A
 	;LD HL,SPECSYNC
	;LD (SYNCHOLD),HL
	;ld A,()
	;JP TV5	
;*****************
;*** BIG ALIEN ***
;*****************

.FX8

.FX8_Start

	;force not end lvl if scroll is stopped
	ld A,(NOSCROLL)
	or A
	jr z,FX8_Scrll
	
	;check if phase 1 or 2
	ld A,(SCR_SPEC2)
	cp 2
	jr nc,FX8_Scrll 	
	
	;ld A,115-lvl_offset	;no level end
	;ld (TILENO),A

.FX8_Scrll 

	ld A,(SCR_SPEC2)	;phase ?
	or A
	jr nz,FX8_Phase2

;*** PHASE 1 ***	
	
	
	ld A,(FRAME)
	AND 7
	jp nz,FX8_Done
	
	ld A,(IY+3)
	dec A
	ld (IY+3),A
	cp 16
	jr nc,FX8_Phase1DoMove

	ld A,1				;goto phase 2
	ld (SCR_SPEC2),A
	xor A
	ld (SCR_SPEC1),A	;detach
	ld (FX8_Shot),A
	ld (FX8_touch),A

	
.FX8_Phase1DoMove

	call FX8_Attach
	call FX8_DrawBoss
	
	jp FX8_Done


;*** PHASE 2 ***
.FX8_Phase2
	cp 1
	jp nz,FX8_Phase3
	
	;is head alive ?
	;ld A,(NOSCROLL)	;wait first if scroll stopped !
	;or A
	;jr z,FX8_Phase2_bossAlive	
	
	;ld A,(SEQBUFF+9)
	;and 63
	;jr nz,FX8_Phase2_bossAlive
	
	;destroy all here !
	;call BIG_EXPLO_Start
	;jp FX8_Phase2Done
	
.FX8_Phase2_bossAlive

	push DE
	;check if head if hit 
	;ld D,130
	;ld A,(FRAME)
	;and 64
	;cp 52
	;jr c,FX8_Phase2_NoTouch	;force release
	
	ld A,(SEQBUFF+17) ;9+8
	bit 7,A
	jr z,FX8_Phase2_NoTouch

	ld A,10
	ld (FX8_touch),A
	ld A,sfx_touchboss
	call SND_SfxPlay
	
.FX8_Phase2_NoTouch	

	ld D,130
	
	ld A,(FX8_touch)
	or A
	jr z,FX8_Phase2_NotTouched
	
	dec A
	ld (FX8_touch),A
	
	inc D
	
.FX8_Phase2_NotTouched

	;draw head
	push IX
	push HL
	push BC

	ld A,D
	CALL TSPGADD
	ld A,(IY+3)
	add 3
	ld C,A

	ld A,(IY+4)
	add 6
	ld B,A
	
	call SPNS_Static
	
	pop BC
	pop HL
	pop IX

	pop DE

	jr FX8_Phase2Done
	

.FX8_Bullet
	db 21,21,10
.FX8_Shot
	db 0
.FX8_Count
	db 0
.FX8_touch
	db 0
	
.FX8_Phase2Done
	
	call FX8_Attach	
	
	;check eyes
	ld HL,SEQBUFF+171
	ld DE,9
	
	ld A,(HL)
	add HL,DE
	or (HL)
	add HL,DE
	or (HL)
	add HL,DE
	or (HL)
	and 63
	
	jr nz,FX8_Done
	
	ld A,2
	ld (SCR_SPEC2),A ;phase 3

	;xor A
	;ld (SEQBUFF+9),A	;remove head
	;ld A,128
	;ld (SEQBUFF+9+8),A	;explode it !
	
	;force end level
	;ld HL,SPECSYNC
	;ld (SYNCHOLD),HL
	
	jr FX8_Done
	
.FX8_Phase3
	ld A,(FRAME)
	AND 7
	jp nz,FX8_Phase3Done
	ld A,(IY+3)
	dec A
	ld (IY+3),A
	
	;reach end ?
	cp -17
	call z,SOFT_END_Start
	
	ld HL,SEQBUFF+9+3
	dec (HL)
	
	call FX8_Attach	
	call FX8_DrawBoss
	
.FX8_Phase3Done

.FX8_Done

	jp TV4
 	;JP NZ,TV4
 	;JP TV1
.FX8_DrawBoss
	push IX
	push HL
	push BC
	push DE

	ld A,8
	CALL TSPGADD
	ld C,(IY+3)
	ld B,(IY+4)
	call SPNS_Static

	ld IX,FX8_Connect_table
	ld C,30

	ld A,(SCR_SPEC1)	;are connected ?
	or A
	jr z,FX8_NotConnected
	
	ld A,(IY+3)
	add 15
	ld C,A	

.FX8_NotConnected

	ld A,9
	call TSPGADD

	ld A,4

.FX8_ConnectLoop
	push AF
	push BC
	push DE
	push HL

	ld B,(IX)
	inc IX

	call SPNS_Static

	pop HL
	pop DE
	pop BC
	pop AF
	dec A
	jr nz,FX8_ConnectLoop

	pop DE
	pop BC
	pop HL	
	pop IX
	ret
.FX8_Connect_table
	db 0,17,12,5
	
.FX8_Attach	
	;setup eyes and tail
	ld B,5
	ld HL,FX8_AttachTable
	
.FX8_AttachLoop
	push BC
	ld A,(HL)
	inc HL
	ld C,(HL)
	inc HL
	ld B,(HL)
	inc HL
	push HL
	call GETSEQ	
	ld A,(HL)
	and 63
	jr z,FX8_AttachSkip	
	inc HL	;1
	inc HL	;2
	inc HL	;3
	ld A,(IY+3)
	add C
	ld (HL),A
	inc HL
	ld A,(IY+4)
	add B
	ld (HL),A
.FX8_AttachSkip		
	pop HL
	pop BC
	djnz FX8_AttachLoop
	
	ret

.FX8_AttachTable
	db 20,-1,2
	db 21,-1,16
	db 22,5,8
	db 23,5,13
	db 25,7,12

	;
;**********************
;*** BIG ALIEN TAIL ***
;**********************
FX9	
	SetMaster NeutralMaster+1
	;CALL FXA98
 	LD A,(FRAME)
	RRCA
	AND 15
	LD E,A
	ADD A
 	ADD A
 	ADD A
 	SUB E
 	LD E,A
	LD D,0
	LD HL,TAILTABLE
 	ADD HL,DE
 	LD A,128
	LD (SPRITE),A
 	LD B,15
 	LD C,(IY+3)
 	LD A,14
 FX9A	
	PUSH AF
 	AND 1
 	LD A,(HL)
 	JR Z,FX9B
 	INC HL
	RRCA
	RRCA
	RRCA
	RRCA
FX9B	
	AND 15
	CALL ALIENF99
 	PUSH HL:PUSH BC
	LD A,57
 	CALL TSPGADD
	
	inc B
	inc B

	;ld A,-2
	;add C
	;ld C,A
	dec C
	dec C

	CALL SPNS
 	POP BC:POP HL:POP AF
	DEC A
 	JR NZ,FX9A
;
	LD A,(SEQBUFF+9)
	AND A
 	JP NZ,TV4
 	;CALL BIGBANG99
	;LD DE,#0304 ;3*256+4
 	;CALL ATS
	JP TV4
;*******************
;*** BLUE GOBOT ***
;*******************

FX10	
	JP C,TV5
	
	jr z,FX10_nodamage
	
	xor A
	call SND_SfxPlay
	
.FX10_nodamage
	
	ld A,(FX10R)
	or A
	jr nz,FX10_DoRecoil

	ld A,C
	cp 22
	jr c,FX10_NoForward

	dec C

.FX10_NoForward

	LD A,(IY+8)
 	CP 6
	JR Z,FX10D
	AND 1
 	JP Z,TV1
	LD L,B
	INC L
 	INC L
 	LD A,(SHIPY)
	CP L
	JP Z,TV1
	JR C,FX10A
	INC B
 	JP TV1
FX10A	DEC B
	JP TV1
;
FX10D	LD HL,FX10E+2
	LD A,B
	INC A
 	LD (HL),A

	dec HL
	ld A,C
	ld (HL),A

 	LD HL,FX10E
 	CALL FORCESYNC
 ;LD HL,9*256+HALF+1
 ;CALL BEEP
	ld A,sfx_L1_GreenAlien
	call SND_SfxPlay 
 
	ld A,3
	ld (FX10R),A
.FX10_Recoil
	ld A,42
	ex AF,AF'
 	JP TV1
.FX10_DoRecoil
	ld A,(FX10R)
	dec A
	ld (FX10R),A

	ld A,C
	inc C
	cp 28
	jr c,FX10_Recoil

	ld C,28
	jr FX10_Recoil

FX10E	DEFB 13,24,0
FX10R	db 0

;***********************************
;*** BLUE GOBOT FLAME WEAPON ***
;***********************************
L0_MASTER3		EQU $
L0_MASTER3_val 	EQU #0D
.FX11	
	nop
	DEC C
 	JP TV1
	
;***********************
;*** NODDING SNALIEN ***
;***********************
.FX12	
	JP C,TV5
	
	LD A,(SHIPX)
	CP C
	LD L,1
	JR NC,FX12G
 	LD L,0
FX12G	LD A,(DE)
	AND 254
 	OR L
	LD (DE),A
 	LD A,(IY+8)
 	AND 1
 	JP Z,FX1A
 	PUSH BC:PUSH DE
	LD H,B
	LD L,C
	INC H
 	INC L
 	LD A,(SHIPY)
	CP H
	JR C,FX12A
	INC B
 	INC H
 	INC H
 	JR FX12B
FX12A	DEC B
	DEC H
 	DEC H
 FX12B	LD A,(SHIPX)
 	CP L
	JR C,FX12C
	INC C
 	INC L
 	INC L
 	JR FX12D
FX12C	DEC C
	DEC L
 	DEC L
 FX12D	PUSH BC
	PUSH HL
 	POP BC
	
	call COLL_CheckPosition
	jr nc,FX12E
	or A
	jr nz,FX12E
	
	;CALL CONVERT
	;AND A
 	;JR Z,FX12E
	POP HL
	POP DE
	POP BC
	JP TV1
FX12E	
	POP BC:POP DE:POP HL
 	JP TV1
;******************
;*** RED GOBOT ***
;******************
.FX13	
	JP C,TV5
	
	jr z,FX13_nodamage
	
	xor A
	call SND_SfxPlay
	
.FX13_nodamage
	
	LD A,(IY+8)
 	CP 9
	JR C,FX13A
;
	LD L,B
	INC L
 	;INC L
 	LD A,(SHIPY)
	CP L
	JR Z,FX13D
	JR C,FX13C
	INC B
 	JR FX13D
.FX13C	
	DEC B
.FX13D	
	ld A,(IY+3)
	cp 13
	jr c,FX13_NoFlySprite
	
	ex AF,AF'	
	ld A,46
	ex AF,AF'
	
.FX13_NoFlySprite
	
	LD A,(FRAME)
 	AND 15
	JR NZ,FX13A
  ;LD HL,18*256+FULL+1
  ;CALL BEEP
  
	ld A,sfx_L1_RedRobot
	call SND_SfxPlay
  
 	LD HL,ALIENFIRE+75
	LD A,(HL)
 	AND A
 	JR NZ,FX13A
.FX13DD	
	LD (HL),180 ;4+16*11
 	INC L
 	LD (HL),C
 	INC (HL)
	INC L
	dec B	;upper
 	LD (HL),B
	inc B
 	INC (HL)
	INC (HL)
;
.FX13A	
	EX AF,AF'
	;CP 43
 	;JR NZ,FX13X9
	cp 44
	jr Z,FX13X9
	
	PUSH AF
 	LD A,(IY+4)
 	CP 13
 	JR NZ,FX13AA
	POP AF
.FX13X9	
	EX AF,AF'
.FX13X	
	LD A,(FRAME)
 	AND 31
	JP NZ,FX1A
	LD A,38
 	PUSH BC
.FX13X1	
	PUSH AF
 	LD HL,FX13Z+2
 	LD (HL),B
 	DEC HL
	LD (HL),C
 	DEC HL
	LD (HL),A
 	CALL FORCESYNC
	
	
	ld A,sfx_missileNPC
	call SND_SfxPlay
	
	INC C
 	POP AF
	INC A
 	CP 42
 	JR NZ,FX13X1
	POP BC
	JP FX1A
.FX13AA	
	PUSH BC:PUSH IX:PUSH DE
 	EX DE,HL
	RES 0,(HL)
	INC B
 	LD E,C
	INC E
 	INC E
 	INC E
 	LD A,(SHIPX)
	INC A
 	CP E
	JR C,FX13F
	SET 0,(HL)
	LD A,184 ;8+16*11
	LD HL,SPMS
	JR FX13G
.FX13F	
	LD A,C
 	ADD 4
 	LD C,A
	LD A,180 ;4+16*11
	LD HL,SPNS
.FX13G	
	LD (FX13DD+1),A
	LD (FX13H+1),HL
 	LD A,(FRAME)
	AND 1
 	ADD 47
	CALL TSPGADD
.FX13H	
	CALL SPNS
	POP DE:POP IX:POP BC:POP AF
 	EX AF,AF'
 	JR FX13X
FX13Y	DEFB 42,0,0
FX13Z	DEFB 38,0,0

;***********************
;*** MISSILE WALKERS ***
;***********************
read "FX14_missile_walker.asm"	

;****************************
;*** RED GOBOT MISSILES ***
;****************************
.FX15	
	jr c,FX15A
	;PUSH DE
 	;CALL CONVERT
	;POP DE
	;JR NC,FX15A
 	;CP 156
	;JP NZ,FX1A
	call COLL_CheckPosition
	jp nc,FX1A
	or A
	jr z,FX15A
	jp FX1A

.FX15A	
	LD (IY+0),0
	ld (IY+8),0
	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	JP TV4
;
;NO ACTION
.FXA0	JP TV3
;HALF SPEED
.FXA1	
	LD A,(FRAME)
	AND 1
 	JP NZ,TV3
 	JP TV4
;
FXA2
 ;
FXA3
 ;
FXA4
 ;
;WAIT WALKERS
FXA5	;CALL BUFFON
 	JR FXA1
 ;
;TOP + BOTTOM GUN TURRET
 FXA6	;CALL BUFFON
 	;LD A,31
 	;CALL TILEDIP1
 	JR FXA0
 ;
;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
	;break
	ld L,1
	jp FXA15A
.FXA12	
	LD L,3
 	JR FXA15A
 ;
;PODDER CIRCLE (3)
.FXA13	
	LD L,2
 	JR FXA15A
 ;
;PODDER BONUS
.FXA14
	LD L,6
 	JR FXA15A
 ;
;PODDER MISSILE + MAIN SUBROUTINE
.FXA15	
	LD L,4
.FXA15A	
	
	CALL FXA99
	;LD A,(IY+0)
	;and 63
 	;jp NZ,TV3
	
	;break
	
	call JEW_Spawn
	
	;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 TV3
;
;FXA15B	
	;LD (JEW2X),BC
 	;LD A,L
	;LD (JEW2),A
 	;LD A,(FRAME)
	;DEC A
 	;AND 7
 	;LD (JEW2P),A
	;JP TV3
;
.FXA97A	
	;PUSH DE
 	;LD DE,TESTDIP2
	;LD HL,TESTDIP1
	;JR FXA97
.FXA97B	;PUSH DE
 	;LD DE,TESTDIP1
	;LD HL,TESTDIP2
.FXA97	;LD (HL),#CD
	;INC HL
	;LD (HL),EXPLODE AND 255 ;-((EXPLODE/256)*256)
 	;INC HL
	;LD (HL),(EXPLODE/256)
 	;XOR A
 	;LD (DE),A
 	;INC DE
	;LD (DE),A
 	;INC DE
	;LD (DE),A
 	;POP DE
	RET
 ;
FXA98	
	LD A,(TILENO)
	CP 115-lvl_offset ;115
	JR NC,FXA98D
	CP 106-lvl_offset
	RET NC
FXA98D	
	LD A,(FRAME)
	AND 7
 	RET NZ
	DEC C
 	LD (IY+3),C
 	RET
 ;
FXA99	
	LD A,(IY+0)
	and 63
 	jr NZ,FXA99A
	ret
 FXA99A	
	pop HL
	jp FXA1
 ;
TAILTABLE
	DEFB 0,80,85,69,100,102,70 
	DEFB 0,80,85,69,68,102,102 
 	DEFB 16,80,85,85,68,102,102
 	DEFB 16,21,17,81,69,100,102
 	DEFB 16,21,17,17,81,68,102
 	DEFB 16,68,21,145,153,81,68
 	DEFB 64,84,17,153,153,17,69
 	DEFB 64,84,21,145,153,25,81
 	DEFB 64,68,84,21,153,153,153
 	DEFB 64,68,68,84,21,145,153
 	DEFB 64,68,68,68,85,145,153
 	DEFB 64,68,100,68,84,21,153
 	DEFB 16,68,68,102,68,21,145;;entry
	DEFB 16,84,69,100,70,84,145
 	DEFB 16,80,85,68,102,70,21
 	DEFB 16,80,85,68,100,102,84
	
;bg effects
	read "starfield.asm"		;l1 starfield
	read "l1bg.asm"			;l1 background
	
;master data
	read "l1_master_data.asm"