ORG level_start

lvl_offset EQU 8


IF output_files
	write "bin/level4.lvl"
ENDIF

;********************
;*** LEVEL 4 DATA ***	
;********************
 START	DEFB 0
 SYNCHRO	DEFW 0000
;
START1	DEFB 0
START2	DEFB 41
START3	DEFB 255
;
SYNCHRO1	DEFW SYNC1
SYNCHRO2	DEFW SYNC2
SYNCHRO3	DEFW SYNC3
;
TSPRADD		DEFW 0
TADD		DEFW 0
SEQTABLE	DEFW SQTABLE
SPEVENT1	DEFW SPEV1
SPEVENT2	DEFW SPEV2

.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 3 
.lvl_skip
	dw 0	;music to skip on music restart
.lvl_init
	dw	l4_init	;called after loading
.lvl_reinit
	dw	l4_reinit	;called each time player dies
	
.l4_init
	ld HL,egg_array
	ld (L4_array),HL
	ret
.l4_reinit
;init array
	ld HL,init_array
	ld (BG_L4Init),HL
	ld HL,run_array
	ld (BG_L4Run),HL
	ld HL,end_array
	ld (BG_L4Stop),HL
	ret
	
;****************************************
;*	LEVEL 4 - 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,3	;start egg layer

	DEFB 8-lvl_offset,1,99,4,2
	;DEFB 8-lvl_offset,23,10,31,6
 	;DEFB 8-lvl_offset,23,10,31,9
 	DEFB 8-lvl_offset,24,16,30,8
 	;DEFB 9-lvl_offset,15,10,31,4
 	;DEFB 9-lvl_offset,15,10,31,7
 	;DEFB 9-lvl_offset,15,10,31,9
 	DEFB 10-lvl_offset,0,15,30,9
 	DEFB 10-lvl_offset,24,31,30,7
	DEFB 11-lvl_offset,16,4,30,14
	DEFB 11-lvl_offset,24,4,30,6
 	DEFB 12-lvl_offset,16,15,30,1
	DEFB 13-lvl_offset,4,5,31,15
 	DEFB 13-lvl_offset,8,2,30,5
	;DEFB 13-lvl_offset,15,10,31,4
	DEFB 14-lvl_offset,3,2,30,8
	DEFB 15-lvl_offset,7,2,30,8
	DEFB 15-lvl_offset,8,5,30,15
 	DEFB 15-lvl_offset,8,12,12,254
 	DEFB 15-lvl_offset,25,2,30,6
 	DEFB 16-lvl_offset,20,2,30,10
	DEFB 17-lvl_offset,16,32,30,5
	
	DEFB 18-lvl_offset,0,14,254,1
	DEFB 18-lvl_offset,18,2,30,4
 	DEFB 18-lvl_offset,24,17,26,254
	DEFB 19-lvl_offset,1,23,30,15
	DEFB 19-lvl_offset,4,2,30,10
 	DEFB 19-lvl_offset,8,15,30,9
 	DEFB 19-lvl_offset,13,2,30,5
 	DEFB 19-lvl_offset,16,5,30,15
	

	
	DEFB 20-lvl_offset,24,33,30,2
	DEFB 22-lvl_offset,8,12,5,254
	DEFB 23-lvl_offset,1,26,12,254
 	DEFB 23-lvl_offset,1,27,15,254
 	DEFB 24-lvl_offset,0,4,30,17
	
 	DEFB 25-lvl_offset,15,45,20,254
	DEFB 25-lvl_offset,18,45,20,254
	DEFB 25-lvl_offset,21,45,20,254
	DEFB 25-lvl_offset,24,45,20,254
	DEFB 25-lvl_offset,27,45,20,254
	DEFB 25-lvl_offset,30,45,20,254
	DEFB 26-lvl_offset,1,45,20,254
 	DEFB 26-lvl_offset,4,45,20,254
 	DEFB 26-lvl_offset,7,45,20,254
 	DEFB 26-lvl_offset,10,45,20,254
	
	DEFB 27-lvl_offset,16,15,30,0
	DEFB 27-lvl_offset,16,13,16,20
 	DEFB 27-lvl_offset,24,12,17,254
	DEFB 27-lvl_offset,24,14,254,2
	
 	DEFB 28-lvl_offset,0,15,30,7
 	DEFB 28-lvl_offset,12,52,4,0
 	DEFB 28-lvl_offset,24,14,254,8
	
db 0,0,0,0,0	
	
 	DEFB 30-lvl_offset,0,15,30,6
 	DEFB 30-lvl_offset,0,4,255,8
 	DEFB 30-lvl_offset,16,4,30,16
	DEFB 31-lvl_offset,0,15,30,7
 	DEFB 32-lvl_offset,0,15,30,8
 	DEFB 32-lvl_offset,8,28,11,254
 	DEFB 32-lvl_offset,16,28,10,254
	DEFB 32-lvl_offset,24,28,9,254
 	DEFB 33-lvl_offset,0,28,8,254
	DEFB 33-lvl_offset,16,34,30,6
	DEFB 34-lvl_offset,8,15,30,2
 	DEFB 34-lvl_offset,16,52,26,0
	DEFB 34-lvl_offset,23,35,30,11
 	DEFB 35-lvl_offset,0,29,10,254
 	DEFB 35-lvl_offset,8,14,254,1
	DEFB 35-lvl_offset,8,23,30,15
	DEFB 35-lvl_offset,25,23,30,15
 	DEFB 36-lvl_offset,4,5,30,15
 	DEFB 36-lvl_offset,8,25,254,15
 	DEFB 36-lvl_offset,24,24,254,15
	DEFB 37-lvl_offset,0,18,24,254
 	DEFB 38-lvl_offset,0,29,1,254
	DEFB 39-lvl_offset,0,29,4,254
	DEFB 40-lvl_offset,0,19,254,11
.SYNC2
	DEFB 42,8,12,14,254
 	DEFB 42,16,12,9,254
 	DEFB 43,0,4,30,2
	DEFB 43,20,36,30,2
	DEFB 44,8,13,16,20
	DEFB 45,0,13,25,20
	DEFB 45,0,15,30,5
 	DEFB 45,8,15,30,3
 	DEFB 45,8,15,30,8
 	DEFB 45,16,53,20,19
 	DEFB 46,0,26,9,254
	DEFB 46,16,27,13,254
	DEFB 46,16,37,30,4
	DEFB 47,0,4,255,11
	DEFB 47,8,4,8,255
 	DEFB 47,16,4,20,255
 	DEFB 49,16,19,254,11
	DEFB 50,0,17,24,254
 ;
	DEFB 50,15,1,31,2
 	DEFB 50,23,1,31,2
 	DEFB 50,31,1,31,2
 	DEFB 51,0,15,30,9
 	DEFB 51,4,15,30,6
 	DEFB 51,7,1,31,2
	DEFB 51,8,15,30,15
	DEFB 51,12,15,30,12
 	DEFB 51,15,1,31,2
 	DEFB 51,16,15,30,3
	DEFB 51,23,1,31,2
 	DEFB 51,31,1,31,2
 	DEFB 52,7,1,31,2
	DEFB 52,15,1,31,2
 	DEFB 52,23,1,31,2
 	DEFB 52,31,1,31,2
 	DEFB 53,7,1,31,2
	DEFB 53,15,1,31,2
 	DEFB 53,23,1,31,2
 	DEFB 53,31,1,31,2
 	DEFB 54,7,1,31,2
	DEFB 54,15,1,31,2
 	DEFB 54,23,1,31,2
 ;
	DEFB 54,31,10,31,2
	DEFB 54,31,10,31,5
	DEFB 54,31,10,31,8
	DEFB 54,31,1,31,15
	DEFB 55,7,10,31,2
 	DEFB 55,7,10,31,5
 	DEFB 55,7,10,31,8
 	DEFB 55,7,1,31,15
 	DEFB 55,9,38,30,12
	DEFB 55,15,10,31,2
	DEFB 55,15,10,31,5
	DEFB 55,15,10,31,8
	DEFB 55,15,1,31,15
	DEFB 55,23,10,31,2
	DEFB 55,23,10,31,5
	DEFB 55,23,10,31,8
	DEFB 55,23,1,31,15
;
	DEFB 55,31,1,31,2
 	DEFB 56,7,1,31,4
	DEFB 56,15,1,31,4
 	DEFB 56,23,1,31,4
 	DEFB 56,24,4,30,15
	DEFB 56,24,4,30,13
	DEFB 56,24,4,30,9
 	DEFB 56,31,1,31,4
 	DEFB 57,0,52,16,0
 	DEFB 57,7,1,31,4
	DEFB 57,15,1,31,4
 	DEFB 57,16,39,30,12
 	DEFB 57,23,1,31,4
 	DEFB 57,31,1,31,4
 	DEFB 58,7,1,31,4
	DEFB 58,15,1,31,4
 	DEFB 58,16,40,30,14
 ;
	DEFB 58,23,10,31,4
	DEFB 58,23,1,31,11
	DEFB 58,31,10,31,4
	DEFB 58,31,1,31,11
	DEFB 59,0,4,29,255
	DEFB 59,7,10,31,4
 	DEFB 59,7,1,31,11
 	DEFB 59,8,4,30,7
	DEFB 59,15,10,31,4
	DEFB 59,15,1,31,11
;
	DEFB 59,23,1,31,4
 	DEFB 59,31,1,31,4
 	DEFB 60,7,1,31,4
	DEFB 60,15,1,31,4
 	DEFB 60,23,1,31,4
 	DEFB 60,31,1,31,4
 	DEFB 61,7,1,31,4
	DEFB 61,8,4,20,255
	DEFB 61,8,53,26,19
	DEFB 61,15,1,31,4
 	DEFB 61,23,1,31,4
 	DEFB 61,24,53,12,19
 	DEFB 61,31,1,31,4
 	DEFB 62,0,41,32,253
 	DEFB 62,0,51,0,4
	DEFB 62,0,51,0,7
	DEFB 62,0,51,0,11
 	DEFB 62,0,51,0,15
 	DEFB 62,7,1,31,4
	DEFB 62,15,1,31,0
 	DEFB 62,16,52,15,0
	DEFB 62,23,1,31,4
 	DEFB 62,24,51,0,9
 	DEFB 62,31,1,31,4
 	DEFB 63,0,4,8,255
 	DEFB 63,7,1,31,4
	DEFB 63,15,1,31,4
 	DEFB 63,23,1,31,0
 	DEFB 63,31,1,31,0
 	DEFB 64,0,52,23,0
 	DEFB 64,7,1,31,0
	DEFB 64,15,1,31,0
 	DEFB 64,23,1,31,0
 	DEFB 64,31,1,31,0
 	DEFB 69,24,21,30,5
	DEFB 70,24,15,30,5
	DEFB 71,24,22,254,6
 ;stop scrolling
	DEFB 74,0,99,1,0
	DEFB 74,0,99,4,4
	DEFB 75,0,99,3,1
	DEFB 75,0,44,241,5	;SHIP 3
	DEFB 75,0,99,3,2
	DEFB 75,0,43,245,2	;SHIP 2
	DEFB 75,0,99,3,3
	DEFB 75,0,42,239,2	;SHIP 1
	DEFB 75,0,99,3,4
	DEFB 75,0,48,245,8	;GLOWER 1
	DEFB 75,0,99,3,7
	DEFB 75,0,49,246,4	;GLOWER 2
	DEFB 75,0,99,3,10
 	DEFB 75,0,50,248,7	;GLOWER 3
	DEFB 103,16,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 
;****************************************
 ;FISH EGGS * 20
SQ1	DEFB 3+#20,63,12+16 ;12+16*1
 	DEFW SP1,0
;RED TWISTERS
SQ2	DEFB 0,1+64,2+16 ;*1
 	DEFW SP3,SP3,SP3,SP3,0
;
SQ3
;
;NODDING SNALIEN
 SQ4	DEFB 12+16,1+64,3+#20 ;2*16
 	DEFW SP14B,SP14,SP14C,SP14A,65535
 ;MISSILE WALKER
SQ5	DEFB 14+16,3,5+16 ;1*16
	DEFW SP26A,SP26E,SP26C,SP26D
	DEFW SP26D,SP26C,SP26E,SP26A,SP26E,SP26C,SP26D
	DEFW SP26D,SP26C,SP26A,SP26EE,SP26CC,SP26DD,SP26DD
	DEFW SP26A,SP26A,0
;MISSILE 1 L
 SQ6	DEFB 15,1,12+#30 ;3*16
	DEFW SP27A,SP27A,SP27C,SP27B,SP27B,0
;MISSILE 2 L
 SQ7	DEFB 15,1,12+#30 ;3*16
	DEFW SP27A,SP27A,SP27CC,SP27B,SP27B,0
 ;MISSILE 1 R
 SQ8	DEFB 15,1,12+#30 ;3*16
	DEFW SP27A,SP27A,SP27D,SP27B,SP27B,0
;MISSILE 2 R
SQ9	DEFB 15,1,12+#30 ;3*16
	DEFW SP27A,SP27A,SP27DD,SP27B,SP27B,0
;FISH EGGS *3
SQ10	DEFB 4+#20,63,12+16 ;*1
		DEFW SP1A,0
 ;FISH EGGS *1
SQ11	DEFB 5+#20,63,12+16 ;*1
		DEFW SP1B,0
 ;UP/DOWN EGG LAYER
 SQ12	DEFB 7,1,4+#20 ;16*2
 	DEFW SP4B8,SP4B8,SP4B8,0
;DOWN/UP EGG LAYER
 SQ13	DEFB 8,1,4+#20 ;16*2
 	DEFW SP4A8,SP4A8,SP4A8,0
;LEFT/RIGHT EGG LAYER
SQ14	DEFB 6,1,4+#20 ;16*2
 	DEFW SP4D8,SP4D8,SP4D8,SP4D8,SP4D4,0
;RIGHT/LEFT EGG LAYER
SQ15	DEFB 6,1,4+#20 ;16*2
 	DEFW SP4C8,SP4C8,SP4C8,SP4C8,SP4C4,0
;EGG LAYER 1
 SQ16	DEFB 6,1,4+#20 ;16*2
 	DEFW SP4E8,SP4C4,SP4G2,SP4B2,SP4H2,SP4B2,SP4G2
	DEFW SP4B2,SP4H2,SP4B2,SP4G2,SP4C4,SP4E8,SP4E4,0
;EGG LAYER 5
 SQ17	DEFB 6,1,4+#20 ;16*2
 	DEFW SP4B8,SP4B5,SP4G5,SP4C5,SP4E5
	DEFW SP4A4,SP4F5,SP4D5,SP4H8,SP4H8,0
;EGG LAYER 18
SQ18	DEFB 6,1,4+#20 ;16*2
 	DEFW SP4B8,SP4B1,SP4G6,SP4C8,SP4C2,SP4E8,0
;EGG LAYER 19
SQ19	DEFB 6,1,4+#20 ;16*2
 	DEFW SP4H4,SP4D4,SP4F4,SP4D4,SP4H4,SP4D6,SP4F4
	DEFW SP4A6,SP4E4,SP4C6,SP4G4,SP4B6,SP4H8,0
;EGG LAYER 27
SQ20	DEFB 6,1,4+#20 ;16*2
 	DEFW SP4A8,SP4A8,SP4F4,SP4D4,SP4H4,SP4B4
	DEFW SP4G3,SP4C3,SP4E3,SP4A4,SP4F8,SP4F8,0
;EGG LAYER 35
SQ21	DEFB 6,1,4+#20 ;16*2
 	DEFW SP4E5,SP4C6,SP4G8,SP4G8,SP4C8,0
;EGG LAYER 37
SQ22	DEFB 6,1,4+#20 ;16*2
 	DEFW SP4D8,SP4D8,SP4D2,SP4H4,SP4B4,SP4G8,0
;WALKER 1
SQ23	DEFB 1+16,1+64,2+16 ;*1
 	DEFW SP8MEG,SP8MEG,SP8MEG,SP8MEG,0
;WALKER 2
SQ24	DEFB 1+16,1+64,2+16 ;*1
 	DEFW SP80MEG,SP80MEG,SP80MEG,SP80MEG,0
;MISSILE WALKER LEFT
 SQ25	DEFB 14+16,3,5+16 ;1*16
 	DEFW SP26B,SP26EE,SP26CC,SP26DD
 	DEFW SP26DD,SP26CC,SP26EE,SP26B,SP26EE,SP26CC,SP26DD
	DEFW SP26DD,SP26CC,SP26B,SP26E,SP26C,SP26D,SP26D
	DEFW SP26B,SP26B,0
;WALKER 3
SQ26	DEFB 1+16,1+64,2+16 ;16*1
 	DEFW SP8A,SP8A,SP8A,SP8AA,SP8B,SP8MEG,SP8MEG,0
;WALKER 4
SQ27	DEFB 1+16,1+64,2+16 ;16*1
 	DEFW SP8D,SP8D,SP8DD,SP8E,SP80,SP80
 	DEFW SP8F,SP8D,SP8D,SP8D,0
;WALKER 5
SQ28	DEFB 1+16,1+64,2+16 ;16*1
 	DEFW SP8D,SP8D,SP8DD,SP8E,SP802,SP8F,SP8DD
	DEFW SP8DD,SP8E,SP80MEG,SP80MEG,0
 ;WALKER 6
SQ29	DEFB 1+16,1+64,2+16 ;16*1
 	DEFW SP8D,SP8D,SP8DD,SP8DD,SP8DD,SP8E
 	DEFW SP80MEG,SP80MEG,SP80MEG,SP80MEG,0
;BIG SHIP LASERS
 SQ30	DEFB 0,63,12+16 ;16*1
 	DEFW SP5,SP5,SP5,0
;PODDER 1
SQ31	DEFB 2+#B0,1,2+32
 	DEFW SP11A,SP11G,SP11GG,SP11HH,SP11II,0
 ;PODDER 2
SQ32	DEFB 2+#E0,1,2+32
		DEFW SP11A,SP11B,SP11C,SP11BB,SP11A,SP11B,SP11C,SP11BB,0
;PODDER 3
SQ33	DEFB 2+#D0,1,2+32
 	DEFW #2020 ;32*256+32
;PODDER 4
SQ34	DEFB 2+#70,1,2+32
	DEFW #2020 ;32*256+32
;PODDER 5
SQ35	DEFB 2+#F0,1,2+32
 	DEFW SP11AA,SP11G,SP11G,SP11E,SP11E,SP11E,SP11E,0
 ;PODDER 6
SQ36	DEFB 2+#C0,1,2+32
 	DEFW #2020 ;32*256+32
;PODDER 7
SQ37	DEFB 2+#E0,1,2+32
 	DEFW SP11A,SP11G,SP11GG,SP11HH,SP11II,0
 ;PODDER 8
SQ38	DEFB 2+#D0,1,2+32
 	DEFW SP11J,SP11J,SP11J,SP11J,SP11J,SP11J,SP11J,SP11J,0
;PODDER 9
SQ39	DEFB 2+#D0,1,2+32
 	DEFW 38*256+38
;PODDER 10
 SQ40	DEFB 2+#B0,1,2+32
 	DEFW 38*256+38
;PODDER 11
 SQ41	DEFB 2+#80,1,2+32
	DEFW SP11AA,SP11G,SP11E,SP11GG,SP11HH,0
 ;
;ALIEN SHIP 1
SQ42	DEFB 10+#30,63,12+#40 ;16*4
 	DEFW SP68,SP68,SP68,SP66,SP56,SP55,SP44,SP36,SP68,SP63
	DEFW SP58,SP53,SP48,SP45,SP116,SP68,SP61
	DEFW SP58,SP51,SP38,SP34,SP112
	DEFW SP48,SP44,SP38,SP34,SP68,SP63,SP43
 	DEFW SP42,SP58,SP53,SP85,SP66,SP95,SP85
 	DEFW SP58,SP53,SP48,SP44,SP68,SP66,SP38,SP35,SP58,SP56
	DEFW SP118,SP118,SP118,SP116
	DEFW SP106,SP56,SP86,SP105,SP35,SP58,SP53,SP43,SP104,SP74
 	DEFW SP33,SP118,SP68,SP66,SP48,SP45,SP116,SP78,SP75,SP51,SP118
	DEFW SP65,SP117,SP68,SP68,SP68,0
;
;ALIEN SHIP 2
SQ43	DEFB 10+#40,63,12+#40 ;16*4
 	DEFW SP68,SP68,SP68,SP66,SP56,SP55,SP44,SP36,SP68,SP63
	DEFW SP118,SP118,SP118,SP48,SP44,SP113
	DEFW SP58,SP51,SP38,SP34,SP112
	DEFW SP48,SP44,SP38,SP34,SP68,SP61,SP112,SP43
 	DEFW SP42,SP58,SP53,SP85,SP66,SP95,SP85
 	DEFW SP118,SP114,SP58,SP58,SP52,SP48,SP44,SP68,SP68,SP62
	DEFW SP38,SP34,SP58,SP53,SP118,SP14
 	DEFW SP106,SP56,SP86,SP105,SP35,SP58,SP53,SP43,SP104,SP74
 	DEFW SP104,SP67,SP58,SP56,SP37,SP68,SP66,SP118,SP58,SP53,SP111
	DEFW SP65,SP117,SP68,SP68,SP68,0
;
;ALIEN SHIP 3
SQ44	DEFB 10+#50,63,12+#40
 	DEFW SP68,SP68,SP68,SP66,SP56,SP55,SP44,SP36,SP68,SP63
	DEFW SP46,SP114,SP78,SP72,SP54,SP118,SP112
	DEFW SP68,SP68,SP62,SP48,SP42,SP38,SP32,SP112
 	DEFW SP48,SP42,SP54,SP118,SP32,SP112
	DEFW SP42,SP58,SP53,SP85,SP66,SP95,SP85
 	DEFW SP45,SP118,SP64,SP38,SP32,SP58,SP58,SP52,SP48,SP42
 	DEFW SP68,SP68,SP62,SP58,SP57,SP36
	DEFW SP106,SP56,SP86,SP105,SP115,SP58,SP53,SP33,SP104,SP74
	DEFW SP104,SP67,SP58,SP56,SP118,SP118,SP118,SP118,SP82,SP35,SP112
 	DEFW SP65,SP47,SP68,SP68,SP68,0
;YELLOW BUTTERFLY
SQ45	DEFB 0,1+64,3+#20
		DEFW SP7,SP7A,SP7A,SP7A,0
SQ46
SQ47
;
;ALIEN GLOWER 1
SQ48	DEFB 11+#30,32,12+#20
 	DEFW #2A2A,0
;ALIEN GLOWER 2
SQ49	DEFB 11+16*4,32,12+16*2
 	DEFW #2B2B,0
;ALIEN GLOWER 3
SQ50	DEFB 11+16*5,32,12+16*2
 	DEFW #2C2C,0
;EGG EATER LEFT/RIGHT
SQ51	DEFB 13,1,2+#20
	DEFW SP6B,65535
;EGG EATER UP/DOWN
 SQ52	DEFB 13,1,2+#20
	DEFW SP6,65535
;EGG EATER DOWN/UP
 SQ53	DEFB 13,1,2+#20
	DEFW SP6A,65535
 ;EGG EATER RIGHT/LEFT
SQ54	DEFB 13,1,2+#20
	DEFW SP6C,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,SQ47,SQ48,SQ49,SQ50
	DEFW SQ51,SQ52,SQ53,SQ54
;****************************************
 ;	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
;****************************************	
;FISH EGGS
SP1		DEFB 54,0+128	;20 12
SP1A	DEFB 53,0+128	;3 11
SP1B	DEFB 52,0+128	;1 10
;
;RED TWISTERS
SP3	DEFB 55,16,56,24,57,16,56,20,55,20,56,16,57,24,56,16+128
 ;
;EGG LAYERS
SP4A8	DEFB 52,4	;UP
SP4A7	DEFB 52,4
SP4A6	DEFB 52,4
SP4A5	DEFB 52,4
SP4A4	DEFB 52,4
SP4A3	DEFB 52,4
SP4A2	DEFB 52,4
SP4A1	DEFB 52,4+128
;
SP4B8	DEFB 52,10	;DOWN
 SP4B7	DEFB 52,10
 SP4B6	DEFB 52,10
 SP4B5	DEFB 52,10
 SP4B4	DEFB 52,10
 SP4B3	DEFB 52,10
 SP4B2	DEFB 52,10
 SP4B1	DEFB 52,10+128
 ;
SP4C8	DEFB 54,17	;LEFT
 SP4C7	DEFB 54,17
 SP4C6	DEFB 54,17
 SP4C5	DEFB 54,17
 SP4C4	DEFB 54,17
 SP4C3	DEFB 54,17
 SP4C2	DEFB 54,17
 SP4C1	DEFB 54,17+128
 ;
SP4D8	DEFB 54,32	;RIGHT
SP4D7	DEFB 54,32
 SP4D6	DEFB 54,32
 SP4D5	DEFB 54,32
 SP4D4	DEFB 54,32
 SP4D3	DEFB 54,32
 SP4D2	DEFB 54,32
 SP4D1	DEFB 54,32+128
 ;
SP4E8	DEFB 53,21	;UP/LEFT
SP4E7	DEFB 53,21
 SP4E6	DEFB 53,21
 SP4E5	DEFB 53,21
 SP4E4	DEFB 53,21
 SP4E3	DEFB 53,21
 SP4E2	DEFB 53,21
 SP4E1	DEFB 53,21+128
 ;
SP4F8	DEFB 53,36	;UP/RIGHT
 SP4F7	DEFB 53,36
 SP4F6	DEFB 53,36
 SP4F5	DEFB 53,36
 SP4F4	DEFB 53,36
 SP4F3	DEFB 53,36
 SP4F2	DEFB 53,36
 SP4F1	DEFB 53,36+128
 ;
SP4G8	DEFB 53,27	;DOWN/LEFT
SP4G7	DEFB 53,27
 SP4G6	DEFB 53,27
 SP4G5	DEFB 53,27
 SP4G4	DEFB 53,27
 SP4G3	DEFB 53,27
 SP4G2	DEFB 53,27
 SP4G1	DEFB 53,27+128
 ;
SP4H8	DEFB 53,42	;DOWN/RIGHT
 SP4H7	DEFB 53,42
 SP4H6	DEFB 53,42
 SP4H5	DEFB 53,42
 SP4H4	DEFB 53,42
 SP4H3	DEFB 53,42
 SP4H2	DEFB 53,42
 SP4H1	DEFB 53,42+128
 ;BIG SHIP LASERS
SP5	DEFB 32,32,32,32+2,32,32,32,32+2
 	DEFB 32,32,32,32+2,32,32,32,32+2+128
;EGG EATERS
SP6		DEFB 49,0,49,8,49,1,49,1+8+128			;UP/DOWN
SP6A	DEFB 49,2,49,2+4,49,3,49,3+4+128	;DOWN/UP
SP6B	DEFB 46,0,46,32,46,2,46,2+32+128	;LEFT/RIGHT
SP6C	DEFB 46,1,46,1+16,46,3,46,3+16+128	;RIGHT/LEFT
;YELLOW BUTTERFLIES
SP7		DEFB 33,8,33,8,33,8,33,8,33,8,33,8,33,8,33,8,34,24,34,24,34,24+128
SP7A	DEFB 35,16,35,16,35,16,35,16,35,16,35,16+128
;STRAIGHT WALKER R / L
 SP8MEG	DEFB 28,16,29,16
	DEFB 28,16,30,16			;WALK L 8
SP8	DEFB 28,16,29,16
 SP8M2	DEFB 28,16,30,16+128	 ;WALK L 4

 SP80MEG	DEFB 28,33,29,33,28,33,30,33
 SP80	DEFB 28,33,29,33
SP802	DEFB 28,33,30,33+128	 ;WALK R

 SP8A	DEFB 31,8,31,8,31,8
 SP8AA	DEFB 31,8,31,8+128	 ;FALL 5 L
SP8B	DEFB 30,0,30,0+128	 ;STAND STILL L
SP8C	DEFB 31,20,31,16,31,24+128	 ;ARC L
SP8D	DEFB 31,9
 SP8DD	DEFB 31,9,31,9,31,9+128 ;FALL 4 R
SP8E	DEFB 30,1,30,1+128	 ;STAND STILL R
SP8F	DEFB 31,37,31,33,31,41+128	 ;ARC R
;
;PODDERS
 SP11A	DEFB 9,24			;FLY D/L 5
 SP11AA	DEFB 9,24,9,24,9,24,9,24+128	;FLY D/L 4 
SP11B	DEFB 9,16,9,16			;FLY L 4
SP11BB	DEFB 9,16,9,16+128		;FLY L 2
SP11C	DEFB 9,20			;FLY U/L 5
 	DEFB 9,20,9,20,9,20,9,20+128	;FLY U/L 4
 SP11E	DEFB 7,16,5,16,7,16,6,16
 	DEFB 7,16,5,16,7,16,6,16+128	;WALK L
SP11G	DEFB 8,0,8,0+128			;LAND IMPACT L
SP11GG	DEFB 8,1,8,1+128			;LAND IMPACT R
 SP11HH	DEFB 9,37,9,37,9,37,9,37+128 ;FLY U/R 4
 SP11II	DEFB 9,33,9,33+128		;FLY R 2
SP11J	DEFB 8,0,8,0,8,0,8,16,8,0,8,0,8,0,8,16
 	DEFB 8,0,8,0,8,0,8,16,8,0,8,0,8,0,8,16+128

 ;
;NODDING SNALIEN
 SP14	DEFB 19,0,20,0,20,0+128
 SP14A	DEFB 21,0,20,0,20,0+128
SP14B	DEFB 19,0+128
SP14C	DEFB 21,0+128
;
;MISSILE WALKERS
 SP26A	DEFB 14,16,15,16
 	DEFB 16,16,15,16
	DEFB 14,16,15,16,16,16,15,16+128	;WALK L 8
SP26B	DEFB 14,33,15,33,16,33,15,33
 	DEFB 14,33,15,33,16,33,15,33+128	;WALK R 4
SP26C	DEFB 17,0,17,0+128						;TILT UP L
 SP26CC	DEFB 17,1,17,1+128						;TILT UP R
SP26D	DEFB 18,0,18,0,18,0,18,0,18,0,18,0+128;WAIT UP L
 SP26DD	DEFB 18,1,18,1,18,1,18,1,18,1,18,1+128;WAIT UP R
SP26E	DEFB 14,0,14,0,14,0,14,0+128					;WAIT DOWN L
SP26EE	DEFB 14,1,14,1,14,1,14,1+128					;WAIT DOWN R
 ;
;MISSILES
SP27A	DEFB 42,4,42,4,42,4,42,4+128																	;UP
 SP27B	DEFB 42,10,42,10,42,10,42,10,42,10+128	 					;DOWN
 SP27C	DEFB 43,20,44,16,44,16,43,26+128							 					;TURN L 1
 SP27CC	DEFB 43,20,43,20,44,16,44,16,43,26,43,26+128	;TURN L 2
SP27D	DEFB 43,37,44,33,44,33,43,43+128													;TURN R 1
 SP27DD	DEFB 43,37,43,37,44,33,44,33,43,43,43,43+128	;TURN R 2
;
;ALIEN SHIPS
 SP38	DEFB 25,4	;UP
 SP37	DEFB 25,4
 SP36	DEFB 25,4
 SP35	DEFB 25,4
 SP34	DEFB 25,4
 SP33	DEFB 25,4
 SP32	DEFB 25,4
 SP31	DEFB 25,4+128
 ;
SP48	DEFB 25,8	;DOWN
 SP47	DEFB 25,8
 SP46	DEFB 25,8
 SP45	DEFB 25,8
 SP44	DEFB 25,8
 SP43	DEFB 25,8
 SP42	DEFB 25,8
 SP41	DEFB 25,8+128
 ;
SP58	DEFB 25,16	;LEFT
SP57	DEFB 25,16
SP56	DEFB 25,16
SP55	DEFB 25,16
SP54	DEFB 25,16
SP53	DEFB 25,16
SP52	DEFB 25,16
SP51	DEFB 25,16+128
;
SP68	DEFB 25,32	;RIGHT
 SP67	DEFB 25,32
SP66	DEFB 25,32
SP65	DEFB 25,32
SP64	DEFB 25,32
SP63	DEFB 25,32
SP62	DEFB 25,32
SP61	DEFB 25,32+128
;
SP78	DEFB 25,20	;UP/LEFT
 SP77	DEFB 25,20
SP76	DEFB 25,20
SP75	DEFB 25,20
SP74	DEFB 25,20
SP73	DEFB 25,20
SP72	DEFB 25,20
SP71	DEFB 25,20+128
;
SP88	DEFB 25,36	;UP/RIGHT
SP87	DEFB 25,36
SP86	DEFB 25,36
SP85	DEFB 25,36
SP84	DEFB 25,36
SP83	DEFB 25,36
SP82	DEFB 25,36
SP81	DEFB 25,36+128
;
SP98	DEFB 25,24	;DOWN/LEFT
 SP97	DEFB 25,24
SP96	DEFB 25,24
SP95	DEFB 25,24
SP94	DEFB 25,24
SP93	DEFB 25,24
SP92	DEFB 25,24
SP91	DEFB 25,24+128
;
SP108	DEFB 25,40	;DOWN/RIGHT
 SP107	DEFB 25,40
 SP106	DEFB 25,40
 SP105	DEFB 25,40
 SP104	DEFB 25,40
 SP103	DEFB 25,40
 SP102	DEFB 25,40
 SP101	DEFB 25,40+128
 ;
SP118	DEFB 25,0	;STAND STILL
 SP117	DEFB 25,0
SP116	DEFB 25,0
SP115	DEFB 25,0
SP114	DEFB 25,0
SP113	DEFB 25,0
SP112	DEFB 25,0
SP111	DEFB 25,0+128
;****************************************
.SPEV1	
	DEFW FX0,FX1,FX2,FX3,FX4,FX5,FX6,FX7,FX8
	DEFW FX9,FX10,FX11,FX12,FX13,FX14,FX15
.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	JR NC,FX1A
 	JP TV5
;
;FISH EGGS
FX3	;LD HL,20*256+1
 	;LD A,20
 	;SUB B
 	;LD H,A
FX3A
	;LD A,250
	;LD (SPRITE),A
 	;DEC C
 	;LD A,68
 	;CALL COLOUR
 	;INC C
 	;LD A,32
 	;CALL TILEDIP1
 	;CALL BUFFOFF
	ld (IY+0),0
	jp TV4
;
;FISH EGGS *3
FX4	;LD HL,3*256+1
	JR FX3A
 ;FISH EGGS *1
FX5	;LD HL,1*256+1
	JR FX3A
	
;EGGS	
FX6	
	ld HL,#0101
	call array_put
	jp TV1
;UP/DOWN EGG LAYER
FX7	
	ld HL,#0001
	call array_put
 	JP TV1
;DOWN/UP EGG LAYER
FX8		
	ld HL,#0001
	call array_put
 	JP TV1


;GUN TURRETS
 FX9	
 ;BIG ALIEN SHIPS
 FX10	PUSH DE
 	LD A,(IY+5)
 	AND 240
 	CP 48
 	JR Z,FX10A
	CP 64
 	JR Z,FX10B
	LD HL,FXBYTE3
 	LD A,27
 	JR FX100
;
FX10B	LD A,(FXBYTE4)
 	AND A
 	JR Z,FX10E
	DEC A
 	LD (FXBYTE4),A
	JR FX10D
;
FX10E	LD A,(SHIPY)
 	LD L,A
	DEC L
 	LD A,B
	CP L
 	JR NC,FX10D
	ADD 5
 	CP L
	JR C,FX10D
	LD A,(SHIPX)
	LD L,A
	LD A,C
	ADD 10
	CP L
	JR NC,FX10D
 	LD HL,FX10Z+1
 	LD (HL),A
 	INC HL
	LD A,(SHIPY)
	LD (HL),A
 	DEC HL
	DEC HL
	CALL FORCESYNC
	LD A,6
	LD (FXBYTE4),A
;
FX10D	LD A,26
	LD HL,FXBYTE2
 	JR FX100
FX10A	LD A,25
	LD HL,FXBYTE1
 FX100	EX AF,AF'
	LD A,(HL)
 	AND A
 	JR Z,FX101
	DEC A
 	LD (HL),A
 	LD A,71
 	;LD (CADD+1),A
 FX101	POP DE
 	JP FX1A
 FX10Z	DEFB 30,0,0
;
;ALIEN GLOWERS
FX11	
	PUSH BC:PUSH DE
	EX AF,AF'
 	LD A,(IY+5)
 	AND 240
 	CP 48
 	JR Z,FX11A
	CP 64
 	JR Z,FX11B
	LD HL,SEQBUFF+81 ;(9*9)
 	LD DE,SEQBUFF+0  ;(9*0)
 	LD BC,FXBYTE3
 	LD A,62
 	JR FX111
FX11B	LD A,60
	LD HL,SEQBUFF+84 ;(9*6)
 	LD DE,SEQBUFF+9  ;(9*1)
 	LD BC,FXBYTE2
 	JR FX111
FX11A	LD A,58
	LD HL,SEQBUFF+27 ;(9*3)
 	LD DE,SEQBUFF+18 ;(9*2)
 	LD BC,FXBYTE1
 FX111	EX AF,AF'
	JP NC,FX11C
 	PUSH DE
 	LD DE,(CIRCHOLD2)
 	XOR A
 	LD (DE),A
 	POP DE
	PUSH HL
 	POP IX
	;LD (CADD+1),A
 	LD (IX+0),A
 	LD (IX+9),A
 	LD (IX+18),A
	PUSH DE
 	POP IX
	LD (IX+0),A
 	LD C,(IX+3)
 	LD B,(IX+4)
 	INC C
 	PUSH BC
 	INC C
 	INC C
 	INC B
 	INC B
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	POP BC
	PUSH BC
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	POP BC
	LD A,C
	ADD 4
 	LD C,A
	PUSH BC
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	POP BC
	LD A,B
	ADD 4
 	LD B,A
	PUSH BC
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	POP BC
	LD A,C
	SUB 4
 	LD C,A
	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	LD DE,5*256+4
 	CALL ATS
	POP DE:POP BC
 ;
	LD A,(SEQBUFF)
	LD L,A
	LD A,(SEQBUFF+9)
	LD H,A
	LD A,(SEQBUFF+18)
 	ADD H
 	ADD L
 	JP NZ,TV4
 	LD A,101
	LD (TILENO),A
 	JP TV4
;
FX11C	JR Z,FX11D
 	LD A,1
	LD (BC),A
FX11D	LD A,(FRAME)
 	RRCA
	RRCA
	AND 64
	ADD 4
 	;LD (CADD+1),A
 	POP DE:POP BC
 	JP FX1A
 ;
;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
	
.FX12_nocollide

	POP HL:POP DE:POP BC
	JP TV1
FX12E	
	POP BC:POP DE:POP HL
 	JP TV1
;EGG EATERS
FX13
	LD A,B
	CP 20
 	JP NC,FX13X
 	LD A,C
	CP 31
 	JP NC,FX13X
 	LD A,(SHIPX)
	INC A
 	LD L,A
	LD A,(SHIPY)
	LD H,A
;
	LD A,(DE)
 	AND 60
	CP 4
	JR Z,FX13B
	CP 8
	JR Z,FX13B
;
FX13A	LD A,C
 	CP L
	JR Z,FX13A1
 	INC A
 	CP L
	JR Z,FX13A1
 	INC A
 	CP L
	JR NZ,FX13YY
FX13A1	LD A,B
	CP H
	LD HL,SQ53
	JR NC,FX13Y
 	LD HL,SQ52
	JR FX13Y
;
FX13B	LD A,B
 	CP H
	JR NZ,FX13YY
FX13B1	LD A,C
	CP L
	LD HL,SQ54
	JR NC,FX13Y
 	LD HL,SQ51
;
FX13Y	
	LD (IY+6),L
	LD (IY+7),H
;****************************************
FX13YY	
	LD (IY+3),C
 	LD (IY+4),B
	
	push DE
	ld DE,#0404
	;call COMMON_EraseEggs
	pop DE
	
	jp TV1
	
 	;LD HL,TSPGADD
 	;LD (USPALL+1),HL
	;LD A,1
	;LD (WEAPON),A
 	;PUSH DE
 	;LD A,(DE)
 	;AND 3
 	;CP 1
	;JR Z,FXO1
 	;CP 2
	;JR Z,FXO2
 	;CP 3
	;JR Z,FXO3
 	;EX AF,AF'
 	;CALL USPN
 	;JR FXO9
;FXO1	
	;EX AF,AF'
 	;CALL USPM
 	;JR FXO9
;FXO2	
	;EX AF,AF'
 	;CALL USPF
 	;JR FXO9
;FXO3	
	;EX AF,AF'
 	;CALL USPB
;FXO9	
	;CALL KILL
 	;POP DE
	;LD HL,USPGADD
 	;LD (USPALL+1),HL
	;XOR A
 	;LD (WEAPON),A
 	;JP TV3
;****************************************
 FX13X	LD (IY+0),0
	JP TV4
;MISSILE WALKERS
 FX14	EX AF,AF'
 	CP 18
 	JR Z,FX14A
	EX AF,AF'
 	JP FX1A
 FX14A	EX AF,AF'
	LD A,(FRAME)
	AND 3
 	JP NZ,FX1A
	LD HL,FX14Z+2
 	LD (HL),B
 	DEC HL
	LD (HL),C
 ;
	LD A,(DE)
 	AND 1
 	JR Z,FX14B
	DEC (HL)
	LD A,R
	AND 1
 	ADD 8
 	JR FX14C
FX14B	INC (HL)
 	LD A,R
	AND 1
 	ADD 6
 FX14C	DEC HL
 	LD (HL),A
 	CALL FORCESYNC
; LD HL,17*256+QUART+1
; CALL BEEP
 	JP FX1A
 FX14Z	DEFB 0,0,0
 ;MISSILE IMPACT
FX15	PUSH DE
 	;CALL CONVERT
	POP DE
	JP C,TV1
	LD (IY+0),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
;
;FISH EGGS CLEAR UP
FXA2	;CALL BUFFON
 	;LD A,31
 	;CALL TILEDIP1
 	JP TV3
;
FXA3	XOR A
; 	LD (CADD+1),A
 	JR FXA1
 ;
FXA4	JR FXA3
 ;
FXA5	JR FXA3
 ;
FXA6
 ;
;PODDER TOP PILL
 FXA7	LD L,8
	JR FXA15A
 ;
;PODDER BOTTOM PILL
FXA8	LD L,9
	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,3
 	JR FXA15A
 ;
;PODDER BLOB (3)
 FXA9
 FXA12	LD L,4
 	JR FXA15A
 ;
;PODDER CIRCLE (3)
 FXA13	LD L,5
 	JR FXA15A
 ;
;PODDER BONUS
FXA14	LD L,6
 	JR FXA15A
 ;
;PODDER MISSILE
FXA15	LD L,7
 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
;****************************************
 FXA99	LD A,(IY+0)
	AND A
 	JR NZ,FXA99A
	RET
 FXA99A	POP HL
	JP FXA1
;****************************************

;*********************************
;*** put a single egg in array ***
;*********************************
; BC = yx
.array_put
	push BC
	add HL,BC
	ld C,L
	ld B,H

;in screen ?
	ld A,C
	cp 32
	jr nc,array_put_done
	
	ld A,B
	cp 20
	jr nc,array_put_done
	
	ld A,C
	
	ld L,B
	ld H,0
	
	push HL ;*1
	add HL,HL	;2
	add HL,HL	;4
	add HL,HL	;8
	add HL,HL	;16
	add HL,HL	;32
	pop BC
	add HL,BC	;33
	ld BC,egg_array
	add HL,BC
	ld C,A
	ld B,0
	add HL,BC
	ld (HL),1
.array_put_done
	pop BC
	ret
	
	
	
	


;******************
;*** init array ***
;******************

.init_array
	call init_array_empty
	call init_array_sprites
	ret
	
;init sprites
.init_array_sprites

	;save sprite found routine
	ld HL,(BULLET_InitSprites_BankSelect)
	push HL
	ld HL,TSPGADD
	ld (BULLET_InitSprites_BankSelect),HL

	;8 first sprites
	ld A,80
	ld B,8
	ld IY,array_spr
	ld IX,#F600
	ld DE,2
	
	call BULLET_InitSprites_loop
	
	ld B,4
	ld IX,#FE00
	ld DE,2
	call BULLET_InitSprites_loop
	
	pop HL
	ld (BULLET_InitSprites_BankSelect),HL
	
	ret
	
.array_spr	ds 24,0	;12 sprites

;fill array w/ zero
.init_array_empty
	ld HL,egg_array
	ld BC,660
.init_array_loop
	ld (HL),0	;remove for debug stuff
	inc HL
	dec BC
	ld A,C
	or B
	jr nz,init_array_loop
	ret
	
;********************
;*** update array ***
;********************
.run_array
	ld A,(FRAME)
	and 7
	call z,run_array_scroll

	ld A,(FRAME)
	and 1
	ret nz
	
	ld A,(FRAME)
	and 6

	ld C,A
	ld B,0
	
	ld IX,array_spr
	add IX,BC
	
	ld A,(IX+0)
	ld (run_array_case01_lo),A
	ld A,(IX+1)
	ld (run_array_case01_hi),A
	
	ld A,(IX+8)
	ld (run_array_case10_lo),A
	ld A,(IX+9)
	ld (run_array_case10_hi),A
	
	ld A,(IX+16)
	ld (run_array_case11_lo),A
	ld A,(IX+17)
	ld (run_array_case11_hi),A

	call run_array_buffer_render
	
	ret
	
;scroll array
.run_array_scroll
	ld DE,egg_array
	ld HL,egg_array+1
	xor A
	
	ld B,20
.run_array_scroll_loop
	push BC
	ld BC,32
	ldir
	ld (DE),A
	inc HL
	inc DE
	pop BC
	djnz run_array_scroll_loop
	
	ret
	
;update array into rendering buffer
.run_array_buffer_render
	ld IX,ATTR_Addr
	ld DE,egg_array
	ld BC,#2014		;32*20
	
.run_array_buffer_render_loopY
	;get work address in HL
	ld L,(IX+0)
	ld H,(IX+1)
	inc IXL
	inc IXL
	push BC
.run_array_buffer_render_loopX	

	ld A,(HL)
	and %11000011	;is this a BG solid block ?
	cp %10000011	;if yes skip it !
	jr z,run_array_buffer_render_skip
	
	ld A,(DE)
	inc DE
	or A
	jr nz,run_array_buffer_case1X
	
	ld A,(DE)
	or A
	jr nz,run_array_buffer_case01
	
;case 00	
	
	bit 6,(HL)	;is already an eggy ?
	jr z,run_array_buffer_render_done	
	
	;if yes, erase 
	ld (HL),4

.run_array_buffer_render_skip
	inc DE
.run_array_buffer_render_done
	inc L
	djnz run_array_buffer_render_loopX	
	
	inc DE ;is 33 width
	
	pop BC
	dec C
	jr nz,run_array_buffer_render_loopY
	
	ret

.run_array_buffer_case1X
	ld A,(DE)
	or A
	jr nz,run_array_buffer_case11
;case 10
	ld A,H
	ld (HL),55+128+64	;solid block destructible
	inc H
	;ld (HL),#C6			;bank
	inc H
run_array_case10_lo		EQU $+1
	ld (HL),0
	inc H
run_array_case10_hi		EQU $+1
	ld (HL),0
	inc H
	ld (HL),32
	ld H,A
	jr run_array_buffer_render_done
;case 11
.run_array_buffer_case11
	ld A,H
	ld (HL),55+128+64	;solid block destructible
	inc H
	;ld (HL),#C6			;bank
	inc H
run_array_case11_lo		EQU $+1
	ld (HL),0
	inc H
run_array_case11_hi		EQU $+1
	ld (HL),0
	inc H
	ld (HL),32
	ld H,A
	jr run_array_buffer_render_done
;case 01
.run_array_buffer_case01
	ld A,H
	ld (HL),55+128+64	;solid block destructible
	inc H
	;ld (HL),#C6			;bank
	inc H
run_array_case01_lo		EQU $+1
	ld (HL),0
	inc H
run_array_case01_hi		EQU $+1
	ld (HL),0
	inc H
	ld (HL),32
	ld H,A
	jr run_array_buffer_render_done
	

	
.end_array
	ret


;*****************
;*** EGG ARRAY ***
;*****************
;egg array size = 33*20
.egg_array
	ds 33*20,1
	