ORG level_start

lvl_offset EQU 8

IF output_files
write "bin/level6.lvl"
ENDIF

;******************
;**	LEVEL 6 DATA **
;******************
 START	DEFB 0
 SYNCHRO	DEFW SYNC1
 ;
START1	DEFB 0 ;pos_test ;0
START2	DEFB 39-lvl_offset
START3	DEFB 255
;
SYNCHRO1	DEFW SYNC1 ;sync_test ;SYNC1 ;SYNC1
SYNCHRO2	DEFW SYNC2
SYNCHRO3	DEFW SYNC3
;
TSPRADD		DEFW 0
TADD		DEFW 0
SEQTABLE	DEFW SQTABLE
SPEVENT1	DEFW SPEV1
SPEVENT2	DEFW SPEV2

;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 5 
.lvl_skip
	dw 0	;music to skip on music restart
.lvl_init
	dw	0	;called after loading
.lvl_reinit
	dw	l6_reinit	;called each time player dies

.l6_reinit	
	ld HL,L6BG_Init
	ld (BG_LevelEffect0_Init),HL
	ld HL,L6BG_Run
	ld (BG_LevelEffect0_Run),HL
	ld HL,BG_EffectNull
	ld (BG_LevelEffect0_Stop),HL	;never stop
	ret


;******************************
;*** LEVEL 6 - 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,1	;BG run
	DEFB 8-lvl_offset,1,99,3,26
 	DEFB 8-lvl_offset,1,1,100,100
	DEFB 8-lvl_offset,1,99,4,8
 	DEFB 10-lvl_offset,0,42,31,2
 	DEFB 10-lvl_offset,0,47,31,17
	DEFB 10-lvl_offset,29,29,31,6
	DEFB 11-lvl_offset,0,2,32,8
	DEFB 11-lvl_offset,0,3,53,2
	DEFB 12-lvl_offset,0,3,49,2
	DEFB 12-lvl_offset,16,53,31,5
	DEFB 13-lvl_offset,0,3,45,2
	DEFB 14-lvl_offset,0,3,41,2
	DEFB 14-lvl_offset,8,57,31,11
	DEFB 15-lvl_offset,0,3,37,2
	DEFB 16-lvl_offset,0,2,32,2
	DEFB 16-lvl_offset,8,48,31,17
	DEFB 17-lvl_offset,0,2,32,2
	DEFB 18-lvl_offset,0,4,25,248
	DEFB 18-lvl_offset,8,43,31,2
 	DEFB 19-lvl_offset,0,5,14,22
 	DEFB 19-lvl_offset,6,6,253,14
	DEFB 19-lvl_offset,16,33,29,10
 	DEFB 19-lvl_offset,24,33,29,6
	DEFB 20-lvl_offset,0,4,17,248
	DEFB 20-lvl_offset,24,34,27,1
	DEFB 21-lvl_offset,0,34,26,1
 	DEFB 21-lvl_offset,4,2,32,2
	DEFB 21-lvl_offset,14,6,244,14
 	DEFB 21-lvl_offset,16,49,31,17
 	DEFB 21-lvl_offset,24,7,9,248
	DEFB 22-lvl_offset,0,54,31,5
 	DEFB 22-lvl_offset,0,2,32,2
	DEFB 22-lvl_offset,6,6,241,14
	DEFB 22-lvl_offset,30,6,238,14
 	DEFB 24-lvl_offset,0,8,31,14
 	DEFB 24-lvl_offset,0,11,254,14
 	DEFB 25-lvl_offset,6,9,37,14
 	DEFB 25-lvl_offset,30,9,34,14
	DEFB 26-lvl_offset,24,10,248,2
 	DEFB 28-lvl_offset,20,12,38,2
	DEFB 31-lvl_offset,0,13,0,14
 	DEFB 32-lvl_offset,20,14,20,20
 	DEFB 33-lvl_offset,20,15,24,20
 	DEFB 34-lvl_offset,16,16,28,253
	DEFB 36-lvl_offset,8,35,27,253
 	DEFB 36-lvl_offset,16,17,24,20
 	DEFB 38-lvl_offset,0,37,22,253
 	DEFB 38-lvl_offset,4,37,22,253
 	DEFB 38-lvl_offset,8,37,21,253
 	DEFB 38-lvl_offset,12,37,21,253
	DEFB 38-lvl_offset,16,37,20,253
	DEFB 38-lvl_offset,20,37,20,253
	DEFB 38-lvl_offset,24,36,10,251
	DEFB 38-lvl_offset,24,37,19,253
	DEFB 38-lvl_offset,28,37,19,253
	DEFB 39-lvl_offset,0,35,16,253
 	DEFB 39-lvl_offset,0,38,18,253
	
	CHECK_POINT 39-lvl_offset,0
	
.SYNC2	
	DEFB 39-lvl_offset,4,38,18,253
	DEFB 39-lvl_offset,8,38,17,253
 	DEFB 39-lvl_offset,12,38,17,253
	DEFB 39-lvl_offset,16,38,16,253
	DEFB 39-lvl_offset,20,38,16,253
	DEFB 39-lvl_offset,24,38,15,253
	DEFB 39-lvl_offset,28,38,15,253
	DEFB 40-lvl_offset,0,39,14,253
 	DEFB 40-lvl_offset,4,39,14,253
 	DEFB 40-lvl_offset,8,39,13,253
 	DEFB 40-lvl_offset,12,39,13,253
	DEFB 40-lvl_offset,16,39,12,253
	DEFB 40-lvl_offset,20,39,12,253
	DEFB 40-lvl_offset,28,40,11,253
	DEFB 41-lvl_offset,12,18,35,2
	DEFB 42-lvl_offset,0,30,30,9
 	DEFB 44-lvl_offset,8,50,31,17
	DEFB 44-lvl_offset,16,19,42,14
 	DEFB 45-lvl_offset,24,19,37,14
 	DEFB 45-lvl_offset,28,55,31,5
	DEFB 45-lvl_offset,28,55,31,11
 	DEFB 47-lvl_offset,0,19,32,14
	DEFB 47-lvl_offset,8,44,31,2
 	DEFB 47-lvl_offset,16,20,44,14
 	DEFB 48-lvl_offset,0,20,42,14
	DEFB 48-lvl_offset,1,31,31,9
 	DEFB 48-lvl_offset,8,51,31,17
	DEFB 48-lvl_offset,16,20,40,14
 	DEFB 50-lvl_offset,18,10,244,2
 	DEFB 51-lvl_offset,4,56,31,5
 	DEFB 51-lvl_offset,4,56,31,11
	DEFB 51-lvl_offset,18,10,240,2
 	DEFB 53-lvl_offset,8,2,32,8
	DEFB 54-lvl_offset,8,21,32,14
	DEFB 54-lvl_offset,8,22,32,2
 	DEFB 54-lvl_offset,12,45,31,2
	DEFB 55-lvl_offset,10,2,32,8
 	DEFB 55-lvl_offset,24,52,31,17
 	DEFB 55-lvl_offset,26,23,19,252
	DEFB 59-lvl_offset,0,99,3,25
 	DEFB 59-lvl_offset,0,32,31,15

sync_test	EQU $
pos_test 	EQU 58-lvl_offset	
	
	LVL_Music	60-lvl_offset,0,8
	
	DEFB 61-lvl_offset,7,41,23,15
;STOP SCROLLING
	;DEFB 61-lvl_offset,16,99,1,0	
	DEFB 62-lvl_offset,1,99,1,0
	
new_offset 	EQU lvl_offset-1
new_pos 	EQU 16
	
 	DEFB 62-new_offset,0,26,16,253
 	DEFB 62-new_offset,24,25,new_pos,253
	DEFB 63-new_offset,16,25,new_pos,253
	DEFB 64-new_offset,8,26,16,253
 	DEFB 65-new_offset,0,25,new_pos,253
 	DEFB 65-new_offset,24,26,16,253
	DEFB 66-new_offset,16,26,16,253
	DEFB 67-new_offset,8,25,new_pos,253
 	DEFB 68-new_offset,0,28,14,253
 	DEFB 68-new_offset,24,25,new_pos,253
	DEFB 69-new_offset,16,25,new_pos,253
	DEFB 70-new_offset,8,27,15,253
 	DEFB 71-new_offset,0,26,16,253
 	DEFB 71-new_offset,24,25,new_pos,253
	DEFB 72-new_offset,16,28,14,253
	DEFB 73-new_offset,8,26,16,253
	
	START_EFFECT 76-new_offset,0,0	;Stop BG effect
 	DEFB 76-new_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 
;****************************************
 ;NULL ENTRY
SQ1	DEFB 0,63,12+32
	DEFW SP0,SP0,65535

PISTON_POW	EQU 24	
	
;PISTON 1/7/11/15/19/40/43
L6_MASTER0		EQU $+1
L6_MASTER0_val	EQU PISTON_POW*2

SQ2	DEFB 3,PISTON_POW,10+64
	DEFW SP18,SP18,SP18,SP18,0
	
;PISTON 2/3/4/5/6
L6_MASTER1		EQU $+1
L6_MASTER1_val	EQU PISTON_POW*2

SQ3	DEFB 3,PISTON_POW,10+64
	DEFW SP18,SP18,SP18,SP18,SP48
 	DEFW SP44,SP28,SP28,SP28,SP28,0
	
;PISTON 8/10
L6_MASTER2		EQU $+1
L6_MASTER2_val	EQU PISTON_POW*2

SQ4	DEFB 3,PISTON_POW,10+64
	DEFW SP48,SP48,SP18,SP18,SP18,0
;PISTON 9
L6_MASTER3		EQU $+1
L6_MASTER3_val	EQU PISTON_POW*2

SQ5	DEFB 3,PISTON_POW,10+64
	DEFW SP38,SP18,SP18,0
;PISTON 12/14/16/17
L6_MASTER4		EQU $+1
L6_MASTER4_val	EQU PISTON_POW*2

SQ6	DEFB 3,PISTON_POW,10+64
	DEFW SP28,SP28,SP28,SP28,SP38
 	DEFW SP34,SP18,SP18,SP18,SP18,0
 ;PISTON 13
L6_MASTER5		EQU $+1
L6_MASTER5_val	EQU PISTON_POW*2

SQ7	DEFB 3,PISTON_POW,10+64
	DEFW SP48,SP48,SP38,SP38,0
;PISTON 18
L6_MASTER6		EQU $+1
L6_MASTER6_val	EQU PISTON_POW*2

SQ8	DEFB 3,PISTON_POW,10+64
	DEFW SP18,SP14,SP36,SP28,SP28,0
;PISTON 20/22
L6_MASTER7		EQU $+1
L6_MASTER7_val	EQU PISTON_POW*2
 
SQ9	DEFB 3,PISTON_POW,10+64
	DEFW SP18,SP18,SP18,SP36,SP28,SP28
	DEFW SP46,SP18,SP18,SP18,SP18,0
 ;PISTON 23/24/38/39
L6_MASTER8		EQU $+1
L6_MASTER8_val	EQU PISTON_POW*2
 
SQ10	DEFB 3,PISTON_POW,10+64
 	DEFW SP28,SP28,SP28,SP28,SP48
 	DEFW SP44,SP18,SP18,SP18,0
;REVERSE PISTON 21
L6_MASTER9		EQU $+1
L6_MASTER9_val	EQU PISTON_POW*2

 SQ11	DEFB 4,PISTON_POW,10+64
 	DEFW SP24,SP28,SP38,SP34,SP18,SP18,0
;PISTON 25
L6_MASTERA		EQU $+1
L6_MASTERA_val	EQU PISTON_POW*2

 SQ12	DEFB 3,PISTON_POW,10+64
 	DEFW SP14,SP18,SP48,SP48,SP48,0
 ;PISTON 26
L6_MASTERB		EQU $+1
L6_MASTERB_val	EQU PISTON_POW*2

 SQ13	DEFB 3,PISTON_POW,10+64
 	DEFW SP28,SP28,SP21,SP38,SP34
 	DEFW SP13,SP48,SP48,SP48,0
;PISTON 27
L6_MASTERC		EQU $+1
L6_MASTERC_val	EQU PISTON_POW*2

 SQ14	DEFB 3,PISTON_POW,10+64
 	DEFW SP32,SP38,SP38,SP18
	DEFW SP14,SP48,SP48,SP48,0
;PISTON 28
L6_MASTERD		EQU $+1
L6_MASTERD_val	EQU PISTON_POW*2

 SQ15	DEFB 3,PISTON_POW,10+64
 	DEFW SP32,SP38,SP38,SP24
	DEFW SP48,SP48,SP48,0
 ;PISTON 29
L6_MASTERE		EQU $+1
L6_MASTERE_val	EQU PISTON_POW*2
 
 SQ16	DEFB 3,PISTON_POW,10+64
 	DEFW SP48,SP46,SP12,SP48,0
;PISTON 30
L6_MASTERF		EQU $+1
L6_MASTERF_val	EQU PISTON_POW*2

 SQ17	DEFB 3,PISTON_POW,10+64
 	DEFW SP34,SP28,SP24,0
 ;PISTON 31
L6_MASTERG		EQU $+1
L6_MASTERG_val	EQU PISTON_POW*2
 
 SQ18	DEFB 3,PISTON_POW,10+64
 	DEFW SP14,SP18,SP48,SP11,SP48,SP48,0
;PISTON 32/33/34
L6_MASTERH		EQU $+1
L6_MASTERH_val	EQU PISTON_POW*2

 SQ19	DEFB 3,PISTON_POW,10+64
 	DEFW SP18,SP18,SP38
 	DEFW SP34,SP28,SP28,SP28,0
;PISTON 35/36/37
L6_MASTERI		EQU $+1
L6_MASTERI_val	EQU PISTON_POW*2

 SQ20	DEFB 3,PISTON_POW,10+64
 	DEFW SP18,SP18,SP18,SP18,SP38,SP34,SP28,SP28
	DEFW SP21,SP48,SP44,SP18,SP18,SP18,SP18,0
 ;PISTON 41
L6_MASTERJ		EQU $+1
L6_MASTERJ_val	EQU PISTON_POW*2
 
 SQ21	DEFB 3,PISTON_POW,10+64
 	DEFW SP18,SP18,SP11,SP28,SP23,SP48,0
;PISTON 42
L6_MASTERK		EQU $+1
L6_MASTERK_val	EQU PISTON_POW*2

 SQ22	DEFB 3,PISTON_POW,10+64
 	DEFW SP18,SP18,SP11,SP28,SP22
 	DEFW SP48,SP48,SP48,0
 ;PISTON 44
L6_MASTERL		EQU $+1
L6_MASTERL_val	EQU PISTON_POW*2
 
 SQ23	DEFB 3,PISTON_POW,10+64
 	DEFW SP48,SP48,SP42,SP18,SP14
 	DEFW SP28,SP23,SP18,SP18,SP14,0
 ;PISTON 45
L6_MASTERM		EQU $+1
L6_MASTERM_val	EQU PISTON_POW*2
 
 SQ24	DEFB 3,PISTON_POW,10+64
 	DEFW SP28,SP28,SP21,SP36,SP13,SP46
	DEFW SP11,SP46,SP28,SP28,SP36,SP11
	DEFW SP36,SP13,SP46,SP28,SP28,0
 ;END PISTON LEFT
L6_MASTERN		EQU $+1
L6_MASTERN_val	EQU PISTON_POW*2 
 
 SQ25	DEFB 3,PISTON_POW,10+64
 	DEFW SP48,SP48,SP41,SP18,SP12,SP38,SP34
 	DEFW SP23,SP46,SP18,SP18,0
;END PISTON RIGHT
L6_MASTERO		EQU $+1
L6_MASTERO_val	EQU PISTON_POW*2

SQ26	DEFB 3,PISTON_POW,10+64
 	DEFW SP48,SP48,SP41,SP28,SP22,SP38,SP34
 	DEFW SP13,SP46,SP28,SP28,0
;END PISTON LEFT REVERSE
L6_MASTERP		EQU $+1
L6_MASTERP_val	EQU PISTON_POW*2

 SQ27	DEFB 4,PISTON_POW,10+64
 	DEFW SP48,SP48,SP41,SP18,SP12,SP38,SP34
 	DEFW SP23,SP46,SP18,SP18,0
;END PISTON RIGHT REVERSE
L6_MASTERQ		EQU $+1
L6_MASTERQ_val	EQU PISTON_POW*2

SQ28	DEFB 4,PISTON_POW,10+64
 	DEFW SP48,SP48,SP41,SP28,SP22,SP38,SP34
 	DEFW SP13,SP46,SP28,SP28,0
;PODDER 1
SQ29	DEFB 2+176,1,2+32
 	DEFW SP9B,SP9A,SP9DD,SP9G
 	DEFW SP9F,SP9GG,SP9H,0
;PODDER 2
SQ30	DEFB 2+192,1,2+32
 	DEFW SP9E,SP9E,SP9G,SP9CCX,SP9B,SP9B,SP9D
 	DEFW SP9DDDD,SP9G,SP9E,SP9E,SP9E,SP9E,0
 ;PODDER 3
SQ31	DEFB 2+176,1,2+32
 	DEFW SP9E,SP9E,SP9E,SP9E,SP9GG,SP9HHX,SP9K,SP9GG
	DEFW SP9F,SP9FF,SP9GG,SP9HHX,SP9HHX,SP9KK,SP9KK
 	DEFW SP9GG,SP9E,SP9G,SP9CCXX,SP9DDDD,SP9G,SP9E
	DEFW SP9E,SP9E,SP9GG,SP9G,SP9GG,SP9D,SP9D,0
 ;PODDER 4 PART 1
 SQ32	DEFB 2+240,1,2+32
 	DEFW SP9E,SP9E,SP9E,SP9E,SP9E,SP9GG,SP9HHX,SP9K
 	DEFW SP9GG,SP9F,SP9F,SP9FF,0
;WALKER 1/2
SQ33	DEFB 0,64+1,2+32
	DEFW SP8A,SP8A,SP8A,0
 ;WALKER 3/4
SQ34	DEFB 0,64+1,2+32
	DEFW SP8AA,SP8C,SP8A,SP8A,SP8A,0
;WALKER 5/7
SQ35	DEFB 0,64+1,2+32
	DEFW SP8AA,SP8AA,SP8B,SP8,SP8
 	DEFW SP8C,SP8A,SP8A,SP8A,0
;WALKER 6
SQ36	DEFB 0,64+1,2+32
	DEFW SP8D,SP8D,SP8E,SP7,SP7,SP7
 	DEFW SP7A,SP8F,SP8D,0
 ;WALKER 8/15
 SQ37	DEFB 0,64+1,2+32
	DEFW SP8DD
	DEFW SP8G,SP8G,SP8G,SP8G,SP8G
 	DEFW SP8F,SP8D,SP8D,SP8DD,0
 ;WALKER 16/23
SQ38	DEFB 0,64+1,2+32
	DEFW SP8DD
	DEFW SP8G,SP8G,SP8G,SP8G,SP8G
 	DEFW SP8F,SP8D,SP8D,SP8DD,0
 ;WLAKER 24/31
SQ39	DEFB 0,64+1,2+32
	DEFW SP8DD
	DEFW SP8G,SP8G,SP8G,SP8G,SP8G
 	DEFW SP8F,SP8D,SP8D,SP8DD,0
 ;WALKER 32
 SQ40	DEFB 0,64+1,2+32
	DEFW SP8DD
	DEFW SP8G,SP8G,SP8G,SP8G,SP8G,SP8GG
 	DEFW SP8F,SP8D,SP8E,SP7,SP7,SP8F,SP8DX
	DEFW SP8E,SP7,SP7,0
 ;PODDER 4 PART 2
 SQ41	DEFB 5+240,1,2+32
 	DEFW SP9G,SP9CCXX,SP9DDDD,SP9G
	DEFW SP9E,SP9E,SP9E,SP9E,SP9GG,SP9HHX,SP9K
	DEFW SP9GG,SP9F,SP9F,SP9F,SP9F
	DEFW 65535
;CRAWLER 1
 SQ42	DEFB 6,2+64,3+64
	DEFW SP168,SP154,SP168,SP164,SP158,SP154
	DEFW SP162,SP168,SP168,SP168,SP154,SP158
	DEFW SP168,SP164,SP154,SP168,0
;CRAWLER 2
 SQ43	DEFB 6,2+64,3+64
	DEFW SP168,SP154,SP168,SP164,SP158,SP154
	DEFW SP168,SP168,SP168,SP162,SP158,SP158,SP158,SP152
	DEFW SP168,SP168,SP168,SP162,SP158,SP158,SP152
	DEFW SP151,SP168,SP168,SP164,SP156,SP151,SP168,SP164,0
;CRAWLER 3
 SQ44	DEFB 6,2+64,3+64
	DEFW SP168,SP154,SP168,SP164,SP158,SP154
	DEFW SP168,SP168,SP168,SP162,SP158,SP152,SP168
	DEFW SP166,0
;CRAWLER 4
 SQ45	DEFB 6,2+64,3+64
	DEFW SP168,SP154,SP168,SP164,SP156,SP51
 	DEFW SP168,SP168,SP164,SP156,SP164
	DEFW SP154,SP164,SP154,SP164,SP154,SP164,SP154,SP164
	DEFW SP154,SP164,SP154,SP164,SP154,SP164,SP154,SP164
	DEFW SP154,SP164,SP154,SP164,SP154,SP164,SP154,SP164
	DEFW SP154,SP164,SP154,SP164,SP154,SP164,SP154,SP164,0
;CRAWLER 5
 SQ46	DEFB 6,2+64,3+64
	DEFW SP168,0
;CRAWLER 6
 SQ47	DEFB 0,2+64,3+64
	DEFW SP68,SP54,SP68,SP64,SP58,SP52,SP51
 	DEFW SP68,SP68,SP68,SP61,SP58,SP68,SP52,SP51,SP68,0
 ;CRAWLER 7
 SQ48	DEFB 0,2+64,3+64
	DEFW SP68,SP54,SP68,SP64,SP58
 	DEFW SP68,SP68,SP66,SP56,SP51,SP68,SP52,SP51,SP68,0
 ;CRAWLER 8
 SQ49	DEFB 0,2+64,3+64
	DEFW SP68,SP54,SP68,SP64,SP58,SP54,SP51
 	DEFW SP68,SP68,SP68,SP64,SP58,SP54,SP68,SP68
	DEFW 0
;CRAWLER 9
 SQ50	DEFB 0,2+64,3+64
	DEFW SP68,SP61,SP54,SP51,SP68,SP66,SP61,SP56
	DEFW SP68,SP68,SP61,SP54,SP51,SP68,SP62,0
 ;CRAWLER 10
SQ51	DEFB 0,2+64,3+64
	DEFW SP68,SP54,SP68,SP64,SP58,SP54,SP51
 	DEFW SP68,SP68,SP68,SP64,SP58,SP52,SP68,SP68,0
;CRAWLER 11/A
SQ52	DEFB 0,2+64,3+64
	DEFW SP68,SP54,SP68,SP64,SP58,SP54,SP51
 	DEFW SP68,SP68,SP68
 	DEFW SP58,SP58,SP54,SP68,SP68,SP64
	DEFW SP58,SP58,SP54,SP68,SP68,SP64
	DEFW SP58,SP58,SP54,SP68,SP68,SP64
	DEFW SP58,SP58,SP54,SP68,SP68,SP64,0
;CRAWLER 12
SQ53	DEFB 0,2+64,3+64
	DEFW SP68,SP54,SP68,SP64,SP56,SP51
	DEFW SP68,SP68,SP64,SP61,SP56,SP51,SP68,SP52,SP51,SP68,0
;CRAWLER 13
SQ54	DEFB 0,2+64,3+64
	DEFW SP68,SP54,SP68,SP64,SP56,SP68,SP68,SP62
	DEFW SP56,SP68,SP68,0
 ;CRAWLER 14/17
 SQ55	DEFB 0,2+64,3+64
	DEFW SP68,SP54,SP68,SP64,SP56,SP68
	DEFW SP68,SP62,SP56,SP68,SP52,SP51,SP68,0
 ;CRAWLER 15/18
 SQ56	DEFB 0,2+64,3+64
	DEFW SP68,SP52,SP51,SP68,SP61,SP52,SP51
 	DEFW SP68,SP61,SP52,SP51,SP68,SP61,SP52,SP51
	DEFW SP68,SP52,SP51,SP68,0
;CRAWLER 16
SQ57	DEFB 0,2+64,3+64
	DEFW SP68,SP54,SP68,SP64,SP58,SP51,SP68,SP68
	DEFW SP68,SP58,SP68,SP52,SP51,SP68,0
;****************************************
 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,SQ55,SQ56,SQ57
;****************************************
 ;	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
;****************************************	
SP0	DEFB 1,0+128
 ;
;STRAIGHT WALKER L / R
 SP7	DEFB 5,33,5,1,6,33,6,1
 SP7A	DEFB 5,33,5,1,7,33,7,1+128
;
;STRAIGHT WALKER R / L
 SP8	DEFB 5,16,5,0,6,16,6,0,5,16,5,0,7,16,7,0+128
 SP8A	DEFB 8,8,8,8,8,8,8,8
SP8AA	DEFB 8,8,8,8+128
 SP8B	DEFB 7,0,7,0+128
SP8C	DEFB 8,20,8,16,8,24+128
 SP8D	DEFB 8,9,8,9
SP8DX	DEFB 8,9,8,9
 SP8DD	DEFB 8,9,8,9,8,9,8,9+128
 SP8E	DEFB 7,1,7,1+128
SP8F	DEFB 8,37,8,33,8,41+128
 SP8G	DEFB 7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1
SP8GG	DEFB 7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1+128
 ;
;PODDERS
 SP9A	DEFB 13,24,13,24							;FLY D/L 6
 SP9AA	DEFB 13,24,13,24,13,24,13,24+128	;FLY D/L 4 
 SP9B	DEFB 13,16,13,16							;FLY L 4
 SP9BB	DEFB 13,16,13,16+128						;FLY L 2
 SP9C	DEFB 13,20,13,20							;FLY U/L 6
 SP9CC	DEFB 13,20
 SP9CCX	DEFB 13,20,13,20
SP9CCXX	DEFB 13,20+128						;FLY U/L 4
 SP9D	DEFB 13,8							;DROP 4
 SP9DD	DEFB 13,8							;DROP 3
SP9DDD	DEFB 13,8							;DROP 2
 SP9DDDD	DEFB 13,8+128							;DROP 1
SP9E	DEFB 11,16,9,16,11,16,10,16+128		;WALK L
SP9F	DEFB 11,33,9,33,11,33,10,33+128		;WALK R
SP9FF	DEFB 11,33,9,33+128
SP9G	DEFB 12,0,12,0+128						;LAND IMPACT L
SP9GG	DEFB 12,1,12,1+128						;LAND IMPACT R
 SP9H	DEFB 13,37,13,37							;FLY U/R 6
 SP9HH	DEFB 13,37,13,37,13,37
 SP9HHX	DEFB 13,37+128	;FLY U/R 4
 SP9I	DEFB 13,33,13,33							;FLY R 4
 SP9II	DEFB 13,33,13,33+128						;FLY R 2
 SP9J	DEFB 13,41,13,41							;FLY D/R 6
 SP9JJ	DEFB 13,41,13,41,13,41,13,41+128	;FLY D/R 4
SP9KK	DEFB 13,9,13,9,13,9
SP9K	DEFB 13,9+128
 ;
;LEFT PISTON
 SP18	DEFB 15,16
SP17	DEFB 15,16
SP16	DEFB 16,16
SP15	DEFB 16,16
SP14	DEFB 17,16
SP13	DEFB 17,16
SP12	DEFB 16,16
SP11	DEFB 16,16+128
;RIGHT PISTON
SP28	DEFB 15,32
SP27	DEFB 15,32
SP26	DEFB 16,32
SP25	DEFB 16,32
SP24	DEFB 17,32
SP23	DEFB 17,32
SP22	DEFB 16,32
SP21	DEFB 16,32+128
;UP PISTON
 SP38	DEFB 15,4
 SP37	DEFB 15,4
 SP36	DEFB 16,4
 SP35	DEFB 16,4
 SP34	DEFB 17,4
 SP33	DEFB 17,4
 SP32	DEFB 16,4
 SP31	DEFB 16,4+128
 ;DOWN PISTON
 SP48	DEFB 15,8
 SP47	DEFB 15,8
 SP46	DEFB 16,8
 SP45	DEFB 16,8
 SP44	DEFB 17,8
 SP43	DEFB 17,8
 SP42	DEFB 16,8
 SP41	DEFB 16,8+128
 ;
;RIGHT CRAWLERS
SP58	DEFB 19,0,20,0,21,0,22,32
 	DEFB 23,0,24,0,25,0,18,32
 SP56	DEFB 19,0,20,0,21,0,22,32
 	DEFB 23,0,24,0,25,0,18,32
 SP54	DEFB 19,0,20,0,21,0,22,32
 	DEFB 23,0,24,0,25,0,18,32
 SP52	DEFB 19,0,20,0,21,0,22,32
 	DEFB 23,0,24,0,25,0,18,32+128
 SP51	DEFB 19,0,20,0,21,0,22,32+128
 ;LEFT CRAWLERS
 SP68	DEFB 19,1,20,1,21,1,22,17
 	DEFB 23,1,24,1,25,1,18,17
 SP66	DEFB 19,1,20,1,21,1,22,17
 	DEFB 23,1,24,1,25,1,18,17
 SP64	DEFB 19,1,20,1,21,1,22,17
 	DEFB 23,1,24,1,25,1,18,17
 SP62	DEFB 19,1,20,1,21,1,22,17
 	DEFB 23,1,24,1,25,1,18,17+128
 SP61	DEFB 19,1,20,1,21,1,22,17+128
 
 ;RIGHT HALF CRAWLERS
 SP158	DEFB 27,2,28,2,29,2,30,34
		DEFB 27,2,28,2,29,2,30,34
 SP156	DEFB 27,2,28,2,29,2,30,34
		DEFB 27,2,28,2,29,2,30,34
 SP154	DEFB 27,2,28,2,29,2,30,34
		DEFB 27,2,28,2,29,2,30,34
 SP152	DEFB 27,2,28,2,29,2,30,34
		DEFB 27,2,28,2,29,2,30,34+128
 SP151	DEFB 27,2,28,2,29,2,30,34+128

 ;LEFT HALF CRAWLERS
SP168	DEFB 27,3,28,3,29,3,30,19
		DEFB 27,3,28,3,29,3,30,19
 SP166	DEFB 27,3,28,3,29,3,30,19
		DEFB 27,3,28,3,29,3,30,19
 SP164	DEFB 27,3,28,3,29,3,30,19
		DEFB 27,3,28,3,29,3,30,19
 SP162	DEFB 27,3,28,3,29,3,30,19
		DEFB 27,3,28,3,29,3,30,19+128
 SP161	DEFB 27,3,28,3,29,3,30,19+128
;****************************************
.SPEV1	DEFW FX0,FX1,FX2,FX3,FX4,FX5,FX6
.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
  	JP C,TV5
.FX2A
	
	;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 9
	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
;
;PISTONS
FX3	
	JR C,FX3A
	
	

	ex AF,AF'
	ld L,A
	ex AF,AF'
	ld H,14
	
	jr z,FX3_NotTouched
	
	ld A,(FRAME)
	and 1
	jr nz,FX3_NotTouched
	
	ld A,20
	add L
	ld L,A
	ld A,20
	add H
	ld H,A	

;touch sound	
	xor A
	call SND_SfxPlay
	
.FX3_NotTouched
	ld A,H
	ld (FX3_Sprite),A
	ex AF,AF'
	ld A,L
	ex AF,AF'
	

	LD A,(DE)
 	AND 254
 	LD (DE),A
 	LD A,(SPRITE)
 	PUSH AF
 	EX AF,AF'
 	PUSH AF:PUSH BC:PUSH DE
 	DEC C
 	DEC C
 	LD A,154
	LD (SPRITE),A
	
FX3_Sprite	EQU $+1	
	
 	LD A,14
 	CALL TSPGADD
	
	SaveMaster		;this part is immortal
	SetMaster 0
	
	CALL SPNS
	RestoreMaster
	
 	POP DE:POP BC:POP AF
	EX AF,AF'
 	POP AF
	LD (SPRITE),A
 	Jp FX0A
FX3A	
	LD HL,(CIRCHOLD2)
	INC HL
	DEC (HL)
	DEC (HL)
	JP TV5
;
;REVERSE PISTONS
FX4	
	JP C,TV5
	
	ex AF,AF'
	ld L,A
	ex AF,AF'
	ld H,14
	
	jr z,FX4_NotTouched
	
	ld A,(FRAME)
	and 1
	jr nz,FX4_NotTouched
	
	ld A,20
	add L
	ld L,A
	ld A,20
	add H
	ld H,A	
	
.FX4_NotTouched
	ld A,H
	ld (FX4_Sprite),A
	ex AF,AF'
	ld A,L
	ex AF,AF'
	
 	LD A,(DE)
 	OR 1
	LD (DE),A
 	LD (DE),A
 	LD A,(SPRITE)
 	PUSH AF
 	EX AF,AF'
 	PUSH AF:PUSH BC:PUSH DE
 	INC C
 	INC C
 	LD A,154
	LD (SPRITE),A
FX4_Sprite	EQU $+1	
 	LD A,14
 	CALL TSPGADD
	
	SaveMaster
	SetMaster 0
	CALL SPMS
	RestoreMaster
	
 	POP DE:POP BC:POP AF
	EX AF,AF'
 	POP AF
	LD (SPRITE),A
 	Jp FX0A
	
 ;SWITCH PODDER 54
FX5	
	JR NC,FX5A
	LD HL,(CIRCHOLD2)
 	LD (HL),0
 	JP TV5
FX5A	
	LD A,(SEQBUFF+224)
	CP 12
 	JP Z,FX2 ;FX1A
 	XOR A
 	LD (IY+0),A
 	JP TV4
;
;TOP CRAWLER EXPLOSION
 FX6	JP NC,TV1
	LD HL,(CIRCHOLD2)
 	INC HL
	INC HL
	DEC (HL)
	DEC (HL)
	DEC (HL)
	JP TV5
;****************************************
 ;NO ACTION
 FXA0	JP TV3
;
;HALF SPEED
FXA1	LD A,(FRAME)
	AND 1
 	JP NZ,TV3
 	JP TV4
;
FXA2
 ;PISTONS
 FXA3	
	JR FXA0
 ;
FXA4
 ;
FXA5
 ;
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,1
 	JR FXA15A
 ;
;PODDER BLOB (3)
FXA9
FXA12	LD L,1
 	JR FXA15A
 ;
;PODDER CIRCLE (3)
 FXA13	LD L,2
 	JR FXA15A
 ;
;PODDER BONUS
FXA14	LD L,6
 	JR FXA15A
 ;
;PODDER MISSLIE
FXA15	LD L,5
 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
	
read "l6_bg.asm"

read "l6_master_data.asm"