ORG level_start

lvl_offset EQU 10


IF output_files
	write "bin/level3.lvl"
ENDIF

;****************************************
; *	LEVEL 3 DATA	
;****************************************
 START	DEFB 0
 SYNCHRO	DEFW 0000
;
START1	DEFB 0
START2	DEFB 255
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 2 
.lvl_skip
	dw 0	;music to skip on music restart
.lvl_init
	dw	0	;called after loading
.lvl_reinit
	dw	0	;called each time player dies

;****************************************
;*	LEVEL 3 - 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 10-lvl_offset,1,99,4,28		;SET BULLETS TO 28	
	
	DEFB 10-lvl_offset,8,99,3,1		;25
	DEFB 10-lvl_offset,8,1,34,3 ;4		;BIG SHIP
	
	DEFB 10-lvl_offset,1,99,4,28		;force level lock	
	
	;*** HOLE GUNS + THRUSTER ***
 	DEFB 10-lvl_offset,8,99,3,26		;1
	DEFB 10-lvl_offset,8,12,32,12		;FRONT THRUSTER	
	DEFB 10-lvl_offset,8,99,3,8			;8	
	DEFB 10-lvl_offset,8,2,37,12		;HOLE GUN 2	
	DEFB 10-lvl_offset,8,99,3,25		;26
	DEFB 10-lvl_offset,8,2,35,12		;HOLE GUN 1
	
	;*** UP COVER ***
	DEFB 10-lvl_offset,8,99,3,2		;2
	DEFB 10-lvl_offset,8,13,44,4	;FACE COVER
	
	DEFB 10-lvl_offset,8,99,3,3		;3
	DEFB 10-lvl_offset,8,2,34,9		;TOP GUN 1
	DEFB 10-lvl_offset,8,99,3,4		;4
	DEFB 10-lvl_offset,8,2,36,8		;TOP GUN 2
	DEFB 10-lvl_offset,8,99,3,5		;5
	DEFB 10-lvl_offset,8,2,38,7		;TOP GUN 3
	
	DEFB 10-lvl_offset,8,99,3,6		;6	
	DEFB 10-lvl_offset,8,18,41,5	;MINE LAYER UNDER FACE
	
	DEFB 10-lvl_offset,8,99,3,10		;10
	DEFB 10-lvl_offset,8,16,34,15	;MINE LAYER UNDER THRUSTER
	
	;*** BOTTOM GROUP 1 ***
	DEFB 10-lvl_offset,8,99,3,13		;11
	DEFB 10-lvl_offset,8,14,40,15		;SMALL FRONT COVER
 	DEFB 10-lvl_offset,8,99,3,12		;12
	DEFB 10-lvl_offset,8,4,40,15		;BOTTOM GUN 2
	DEFB 10-lvl_offset,8,99,3,11		;13
	DEFB 10-lvl_offset,8,4,42,15		;BOTTOM GUN 3
	
	DEFB 10-lvl_offset,8,99,3,14		;14
	DEFB 10-lvl_offset,8,4,40,17		;BOTTOM GUN 4 (ON COVER)
 	DEFB 10-lvl_offset,8,99,3,15		;15
	DEFB 10-lvl_offset,8,4,43,17		;BOTTOM GUN 5 (ON COVER)

	
	DEFB 10-lvl_offset,8,99,3,9		;9	
	DEFB 10-lvl_offset,8,4,37,16		;BOTTOM GUN 1
	




 	DEFB 10-lvl_offset,8,99,3,24		;16
	DEFB 10-lvl_offset,8,33,53,17	;BIG COVER
	DEFB 10-lvl_offset,8,99,3,21		;21
	DEFB 10-lvl_offset,8,21,59,16	;THRUSTER 4
	DEFB 10-lvl_offset,8,99,3,22		;22
	DEFB 10-lvl_offset,8,20,53,16	;THRUSTER 1
	DEFB 10-lvl_offset,8,99,3,23		;23
	DEFB 10-lvl_offset,8,21,55,16	;THRUSTER 2
	DEFB 10-lvl_offset,8,99,3,16		;24
	DEFB 10-lvl_offset,8,20,57,16	;THRUSTER 3
	
	
 	DEFB 10-lvl_offset,8,99,3,27		;19
	DEFB 10-lvl_offset,8,15,44,14	;TRIANGLE COVER
	DEFB 10-lvl_offset,8,99,3,19		;27
	DEFB 10-lvl_offset,8,17,45,13	;MINE LAYER UNDER TRIANGLE COVER
	
	;*******************
	;*** UPPER STUFF ***
	;*******************
	
	DEFB 10-lvl_offset,8,99,3,20		;20
	DEFB 10-lvl_offset,8,19,56,8	;POKER MINE LAYER
	
 	DEFB 10-lvl_offset,8,99,3,17		;17
	DEFB 10-lvl_offset,8,3,50,7		;3 CHAR GUN 2
 	DEFB 10-lvl_offset,8,99,3,18		;18
	DEFB 10-lvl_offset,8,3,53,8		;3 CHAR GUN 3
	
	
 	DEFB 10-lvl_offset,8,99,3,28		;28
	DEFB 10-lvl_offset,8,32,200,200	;DUMMY SHIP PATTERN

	DEFB 11-lvl_offset,8,6,30,3
	DEFB 15-lvl_offset,0,7,30,8
	DEFB 29-lvl_offset,0,5,31,14
	DEFB 30-lvl_offset,8,5,31,14
	DEFB 31-lvl_offset,16,5,31,14
	DEFB 32-lvl_offset,24,8,31,12
	DEFB 34-lvl_offset,24,11,31,16
	DEFB 34-lvl_offset,30,11,31,16
 
 	DEFB 37-lvl_offset,8,99,3,25		;1
	DEFB 37-lvl_offset,8,29,45,7		;BACK BLASTER 4
	DEFB 37-lvl_offset,8,99,3,4		;4A
 	DEFB 37-lvl_offset,8,23,31,2		;POKER 2 CHAR GUN 2
	DEFB 37-lvl_offset,8,99,3,5		;5A
 	DEFB 37-lvl_offset,8,23,34,1		;POKER 2 CHAR GUN 3
	DEFB 37-lvl_offset,8,99,3,8		;8A
 	DEFB 37-lvl_offset,8,24,36,0		;TOP 3 CHAR BLASTER 1 A
	DEFB 37-lvl_offset,8,99,3,9		;9A
 	DEFB 37-lvl_offset,8,24,39,1		;TOP 3 CHAR BLASTER 2 A
	DEFB 37-lvl_offset,8,99,3,11		;11A
 	DEFB 37-lvl_offset,8,30,46,5		;BACK BLASTER 5
	DEFB 37-lvl_offset,8,99,3,12		;12A
 	DEFB 37-lvl_offset,8,26,39,12	;BACK BLASTER 1
	DEFB 37-lvl_offset,8,99,3,13		;13A
 	DEFB 37-lvl_offset,8,27,41,11	;BACK BLASTER 2
	DEFB 37-lvl_offset,8,99,3,14		;14A
 	DEFB 37-lvl_offset,8,23,42,2		;TOP BACK 2 CHAR BLASTER
 	DEFB 37-lvl_offset,8,99,3,15 	;15A
 	DEFB 37-lvl_offset,8,25,37,13	;BOTTOM BACK 2 CHAR BLASTER
	DEFB 37-lvl_offset,8,99,3,19		;19A
 	DEFB 37-lvl_offset,8,31,45,3		;BACK BLASTER 6
	DEFB 37-lvl_offset,8,99,3,7		;7
	DEFB 37-lvl_offset,8,28,42,9		;BACK BLASTER 3
	DEFB 37-lvl_offset,8,99,3,26		;26A
 	DEFB 37-lvl_offset,8,22,29,6		;POKER 25,6
 
  DEFB 54-lvl_offset,16,99,3,27
 DEFB 54-lvl_offset,16,9,0,3
;STOP SCROLLING
 DEFB 64-lvl_offset,0,99,1,0
 DEFB 72-lvl_offset,0,99,3,27
  DEFB 72-lvl_offset,0,10,32,12
;
 DEFB 101,0,99,5,0
 ;
SYNC2
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 
;****************************************
 ;BIG SHIP
SQ1	DEFB 3,63,2+32
 	DEFW SP3,SP3,SP3,SP3,SP3B,SP7
 	DEFW SP7,SP7,SP7,SP3,SP5,SP5,SP5,SP5,SP1
	DEFW SP1,SP1,SP1,SP5,SP5,SP3,SP3,SP3
	DEFW SP3B,SP7,SP7,SP3A,SP3A,SP3A,SP3A
 	DEFW SP3A,SP3A
	DEFW SP3A,SP3A,SP3A,SP3A,SP3A,SP7A,SP7A,SP7A,SP7A,SP7A
	DEFW SP3A,SP5,SP5,SP1,SP1,SP3,SP3B,SP7
	DEFW SP7,SP4,SP5,SP5
	DEFW SP1,SP1,SP8,SP8,SP8,SP7,SP3B,SP5,SP3B
	DEFW SP1,SP6,SP6,SP2,SP8,SP8,SP3B,SP5,SP6,SP6
 	DEFW SP4,SP7,SP7,SP7,SP7,SP3B,SP4,SP4,SP5,SP1
 	DEFW SP1,SP1,SP8,SP8,SP8,SP7,SP3,SP5,SP3B
 	DEFW SP1,SP6,SP6,SP2,SP8,SP8,SP3B,SP5,SP6,SP6
 	DEFW SP4,SP7,SP7,SP7,SP7,SP4,SP4
	DEFW SP2A,SP2A,SP2A,SP2A,SP2A,SP2A,SP2A,0
 ;2 CHAR BLASTER - FRONT
SQ2	DEFB 4,2+64,12+32
	DEFW 256+1
;3 CHAR BLASTER
SQ3	DEFB 5,8+64,12+32
	DEFW 256+1
;2 CHAR BLASTER - BOTTOM
 SQ4	DEFB 6,2+64,12+32
	DEFW 256+1
;RED TWISTERS
SQ5	DEFB 0,1+64,2+16
 	DEFW SP12,SP12,SP12,SP12,0
;PODDER 1
SQ6	DEFB 2+192,1,2+32
	DEFW SP11B,SP11A,SP11B,SP11C,SP11DDDD,SP11DDDD
	DEFW SP11DDDD,SP11D,SP11G,SP11G,SP11E,SP11E,SP11E,0
 ;PODDER 2
SQ7	DEFB 2+192,1,2+32
	DEFW SP11BB,SP11A,SP11B,SP11C,SP11BB,SP11A,SP11B,SP11C,0
;PODDER 3
SQ8	DEFB 2+208,1,2+32
	DEFW SP11AA,SP11G,SP11E,SP11E,SP11E
 	DEFW SP11E,SP11E,SP11E,SP11E,0
;PODDER 4
SQ9	DEFB 2+176,1,2+32
	DEFW SP11II,SP11JJ,SP11I,SP11HH,SP11K,SP11K,SP11K,SP11KK
	DEFW SP11GG,SP11F,SP11G,SP11C,SP11BB,SP11AA,SP11B,SP11CC,0
;PODDER 5
SQ10	DEFB 2+176,1,2+32
 	DEFW SP11AA,SP11G,SP11E,SP11GG,SP11HH,SP11II,0
;WALKERS
 SQ11	DEFB 1+16,1+64,2+16
 	DEFW SP18,SP18,SP18,SP18,0
;FRONT THRUSTER
SQ12	DEFB 7+32,62,12+32
	DEFW 256+1
;FACE COVER
SQ13	DEFB 7+#30,20,12+32
	DEFW 256+1
;SMALL COVER
 SQ14	DEFB 7+#40,62,12+32
	DEFW 256+1
;TRIANGLE COVER
SQ15	DEFB 7+#50,62,12+32
	DEFW 256+1
;MINE LAYER DOWN/LEFT
SQ16	DEFB 8+32,20,12+32
	DEFW 256+1
;MINE LAYER DOWN /RIGHT
SQ17	DEFB 8+#30,20,12+32
	DEFW 256+1
;MINE LAYER UP/LEFT
SQ18	DEFB 8+#40,20,12+32
	DEFW 256+1
;MINE LAYER UP/RIGHT
 SQ19	DEFB 8+#50,20,12+32
	DEFW 256+1
;THRUSTERS 1/3
 SQ20	DEFB 9+32,40,12+32
	DEFW 256+1
;THRUSTER 2/4
SQ21	DEFB 9+#30,40,12+32
	DEFW 256+1
;POKER
 SQ22 	DEFB 10,32,2+32
	DEFW SP3A,SP3A,SP3A
 	DEFW SP3A,SP3A,SP3A,SP3A,SP3A,SP7A,SP7A,SP7A,SP7A,SP7A
	DEFW SP3A,SP5,SP5,SP1,SP1,SP3,SP3B,SP7
	DEFW SP7,SP4,SP5,SP5
	DEFW SP1,SP1,SP8,SP8,SP8,SP7,SP3B,SP5,SP3B
	DEFW SP1,SP6,SP6,SP2,SP8,SP8,SP3B,SP5,SP6,SP6
 	DEFW SP4,SP7,SP7,SP7,SP7,SP3B,SP4,SP4,SP5,SP1
 	DEFW SP1,SP1,SP8,SP8,SP8,SP7,SP3,SP5,SP3B
 	DEFW SP1,SP6,SP6,SP2,SP8,SP8,SP3B,SP5,SP6,SP6
 	DEFW SP4,SP7,SP7,SP7,SP7,SP4,SP4
	DEFW SP2A,SP2A,SP2A,SP2A,SP2A,SP2A,SP2A,0
 ;
;2 CHAR BLASTER - POKER COVER
SQ23	DEFB 4,2+64,12+32
 	DEFW #1600+22
;3 CHAR BLASTER TOP SHIP
 SQ24	DEFB 5,8+64,12+32
 	DEFW #1600+22
;2 CHAR BLASTER - BOTTOM BACK
SQ25	DEFB 6,2+64,12+32
 	DEFW #1600+22
;BACK BLASTER 1
SQ26	DEFB 11+32,20,12+32
 	DEFW #1600+22
;BACK BLASTER 2
SQ27	DEFB 11+#30,20,12+32
 	DEFW #1600+22
;BACK BLASTER 3
SQ28	DEFB 11+#40,20,12+32
 	DEFW #1600+22
;BACK BLASTER 4
SQ29	DEFB 11+#50,202,12+32
	DEFW #1600+22
;BACK BLASTER 5
SQ30	DEFB 11+#60,20,12+32
 	DEFW #1600+22
;BACK BLASTER 6
SQ31	DEFB 11+0,20,12+32
 	DEFW #1600+22
;DUMMY SHIP PATTERN
SQ32	DEFB 15,63,12+32
	DEFW SP10,65535
 ;BIG COVER
 SQ33	DEFB 7+#60,62,12+32
	DEFW 256+1
;BACK BLASTER DOWN
 SQ34	DEFB 1+16,63,12+32
	DEFW SP13A,SP13A,SP13A,0
;BACK BLASTER DOWN/RIGHT
 SQ35	DEFB 1+16,63,12+32
	DEFW SP13B,SP13B,SP13B,0
;BACK BLASTER RIGHT
SQ36	DEFB 1+16,63,12+32
	DEFW SP13C,SP13C,SP13C,0
;BACK BLASTER UP/RIGHT
 SQ37	DEFB 1+16,63,12+32
	DEFW SP13D,SP13D,SP13D,0
;BLUE BALL 1 L
 SQ38	DEFB 14+16,1,12+48
	DEFW SP27A,SP27C,SP27B,0
;BLUE BALL 2 L
 SQ39	DEFB 14+16,1,12+48
	DEFW SP27A,SP27CC,SP27B,0
 ;BLUE BALL 1 R
 SQ40	DEFB 14+16,1,12+48
	DEFW SP27A,SP27D,SP27B,0
;BLUE BALL 2 R
 SQ41	DEFB 14+16,1,12+48
	DEFW SP27A,SP27DD,SP27B,0
 ;LONG LASERS
 SQ42	DEFB 0,63,12+32
 	DEFW SP28,SP28,SP28,SP28,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
;****************************************
 ;	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
;****************************************	
;BIG SHIPS
 SP1	DEFB 41,0,41,0,41,0,41,0	;UP
 	DEFB 41,0,41,0,41,0,41,0 
 	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,4+128
;
SP2	DEFB 41,0,41,0,41,0,41,0	;DOWN
 	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,8+128
SP2A	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,8
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,8+128
;
SP3	DEFB 41,0,41,0,41,0,41,0	;LEFT
 	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,16
 SP3B	DEFB 41,0,41,0,41,0,41,0	;LEFT
	DEFB 41,0,41,0,41,0,41,0
SP3A	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,16+128
 ;
SP4	DEFB 41,0,41,0,41,0,41,0	;RIGHT
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,32+128
 ;
SP5	DEFB 41,0,41,0,41,0,41,0	;UP/LEFT
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,20+128
 ;
SP6	DEFB 41,0,41,0,41,0,41,0	;UP/RIGHT
 	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,36+128
 ;
SP7	DEFB 41,0,41,0,41,0,41,0	;DOWN/LEFT
	DEFB 41,0,41,0,41,0,41,0
SP7A	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,24+128
 ;
SP8	DEFB 41,0,41,0,41,0,41,0	;DOWN/RIGHT
 	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,40+128
 ;
SP9	DEFB 41,0,41,0,41,0,41,0	;STOP STILL
 	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0
	DEFB 41,0,41,0,41,0,41,0+128
;
;DUMMY SHIP PATTERN
SP10	DEFB 1,0+128
;
;PODDERS
 SP11A	DEFB 39,24,39,24							;FLY D/L 6
SP11AA	DEFB 39,24,39,24,39,24,39,24+128	;FLY D/L 4 
SP11B	DEFB 39,16,39,16							;FLY L 4
SP11BB	DEFB 39,16,39,16+128						;FLY L 2
SP11C	DEFB 39,20,39,20							;FLY U/L 6
SP11CC	DEFB 39,20,39,20,39,20,39,20+128	;FLY U/L 4
 SP11DDDD	DEFB 39,8							;DROP 4
 SP11DDD	DEFB 39,8							;DROP 3
SP11DD	DEFB 39,8							;DROP 2
 SP11D	DEFB 39,8+128							;DROP 1
SP11E	DEFB 37,16,36,16,37,16,36,16+128	;WALK L
 SP11F	DEFB 37,33,36,33,37,33,36,33+128	;WALK R
 SP11G	DEFB 38,0,38,0+128						;LAND IMPACT L
 SP11GG	DEFB 38,1,38,1+128						;LAND IMPACT R
SP11HH	DEFB 39,37,39,37,39,37,39,37+128	;FLY U/R 4
 SP11I	DEFB 39,33,39,33							;FLY R 4
SP11II	DEFB 39,33,39,33+128						;FLY R 2
SP11JJ	DEFB 39,41,39,41,39,41,39,41+128	;FLY D/R 4
 SP11K	DEFB 39,8+1,39,8+1,39,8+1						;DROP R/3
 SP11KK	DEFB 39,8+1+128							;DROP R/1
 ;
;RED TWISTERS
SP12	DEFB 7,16,8,24,9,16,8,20,7,20,8,16,9,24,8,16+128
;
;BACK BLASTERS
 SP13A	DEFB 10,2,11,10,10,2,11,10,10,2,11,10,10,2,11,10+128	;DOWN
 SP13B	DEFB 12,3,13,43,12,3,13,43,12,3,13,43,12,3,13,43+128	;DOWN/RIGHT
 SP13C	DEFB 14,1,15,33,14,1,15,33,14,1,15,33,14,1,15,33+128	;RIGHT
SP13D	DEFB 12,1,13,37,12,1,13,37,12,1,13,37,12,1,13,37+128	;UP RIGHT
 ;
;STRAIGHT WALKER R / L
 SP18	DEFB 31,16,32,16,33,16,32,16
	DEFB 31,16,32,16,33,16,32,16+128
;
;BLUE BALLS
SP27A	DEFB 5,4,5,4,5,4,5,4+128							;UP
 SP27B	DEFB 5,10,5,10,5,10,5,10,5,10+128	;DOWN
SP27C	DEFB 5,20,5,16,5,26+128							;TURN L 1
SP27CC	DEFB 5,20,5,20,5,26,5,26+128						;TURN L 2
 SP27D	DEFB 5,37,5,33,5,43+128							;TURN R 1
SP27DD	DEFB 5,37,5,37,5,33,5,43,5,43+128	;TURN R 2
 ;
;LONG LASERS
 SP28	DEFB 2,16,2,18,2,16,2,18,2,16,2,18,2,16,2,18+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
;****************
;*** BIG SHIP ***
;****************
.FX3	
	LD A,156
 	LD (SPRITE),A
 	LD A,(FRAME)
	AND 7
 	JP NZ,TV3
	
	;break
	
 	EX AF,AF'
 	PUSH BC:PUSH DE:PUSH AF
 	LD A,41
.FX3A	
	EX AF,AF'
 	LD A,C
	CP 32
 	JR NC,FX3B
	;AND A		removed cause it takes all the screen
 	;JR Z,FX3B
 	EX AF,AF'
 	PUSH BC:PUSH AF
	;dec B		;new design is 1 char lower
	CALL TSPGADD
	CALL SPNS_Static
 	POP AF:POP BC
 	JR FX3C
.FX3B	
	EX AF,AF'
.FX3C	
	INC C
 	INC A
 	CP 87
 	JR NZ,FX3A
	POP AF:POP DE:POP BC
	EX AF,AF'
 	LD A,(DE)
 	AND 252
 	LD (DE),A
 	JP TV1
	
;**********************************
;*** 2 CHAR BLASTER - FRONT TOP ***
;**********************************

FX4	JP C,TV5
 	LD HL,25
	LD A,(SHIPY)
	CP B
FX4B
 	JR NC,FX4Z
	LD L,27
 	LD A,(SHIPX)
	INC A
 	CP C
	JR Z,FX4Z
 FX4A	DEC L
 	JR C,FX4Z
 	INC H
 FX4Z	LD A,L
	EX AF,AF'
 	LD A,(DE)
 	AND 252
 	OR H
	LD (DE),A
	
	;jp TV1
	
	;ex AF,AF'
	;push AF
	;push BC
	push DE
	;push HL
	
	;CALL TSPGADD
	;push BC
	;push DE
	;push HL
	;call SPNS_Special
	;call REND_EraseZone
	call SpriteSpecial
	;pop HL
	;pop DE
	;pop BC
	;call SPNS
	
	;pop HL
	pop DE
	;pop BC
	;pop AF
	;ex AF,AF'
	
	;LD (IY+3),C
	;LD (IY+4),B
	
	jp TV5
	
 	JP TV1
;
;3 CHAR BLASTER
FX5	JR C,FX5B
	LD HL,23
	LD A,(SHIPY)
	CP B
	LD A,(SHIPX)
	JR C,FX5A
 	INC A
 	CP C
	Jp C,FX4Z
 	INC H
 	Jr FX4Z
 ;
FX5A	LD L,22
 	CP C
	Jr Z,FX4Z
 	LD L,24
 	Jr C,FX4Z
 	INC H
 	Jp FX4Z
 ;
FX5B	
	LD DE,#103 ;256+3
 	CALL ATS
	JP TV4
	
;*************************************
;*** 2 CHAR BLASTER - FRONT BOTTOM ***
;*************************************

.FX6	JP C,TV5
 	LD HL,#0219 ;2*256+25
	LD A,(SHIPY)
	DEC A
 	CP B
	LD A,(SHIPX)
	JR NC,FX6A
	CP C
	JR C,FX4Z
 	INC H
 	JR FX4Z
 ;
FX6A	LD L,27
 	CP C
	JR Z,FX4Z
 	DEC L
 	JR C,FX4Z
 	INC H
 	JR FX4Z
	
;**************************
;**** DETACHABLE STUFF ****	
;**************************

.FX7	
	JP C,FX7E
	JR Z,FX7AA
	LD A,(FRAME)
	AND 1
 	JR Z,FX7AA
	LD A,71
; 	LD (CADD+1),A
.FX7AA	
	CALL FXA98
 	CP 0
	JP NZ,FX7A
;**********************
;*** FRONT THRUSTER ***
;**********************

	PUSH DE:PUSH BC
	LD HL,FXBYTE1
 	LD A,(HL)
 	AND A
 	JR Z,FX7Z
 	LD E,A
	LD A,(FRAME)
	AND 7
 	JP NZ,FX7Z9
 ;
	LD A,E
	INC A
 	LD (HL),A
 	ADD A
 	LD D,0
	LD E,A
	LD HL,FX7MOVE
 	ADD HL,DE
 	POP BC
	LD A,C
	ADD (HL)
	LD C,A
	INC HL
	LD A,B
	ADD (HL)
	LD B,A
	PUSH BC
 	JP FX7Z9
;
FX7Z	LD A,(IY+0)
 	CP 40
 	JR NC,FX7Z6
 	LD A,1
	LD (FXBYTE1),A
FX7Z6	LD A,(TILENO)
	CP 11
 	JR C,FX7Z9
	ADD A
 	ADD A
 	LD L,A
	LD A,(TILEPOS)
	ADD L
 	RRCA
	RRCA
	AND 3
 	JR NZ,FX7Z5
  LD A,(FRAME)
 AND 31
 JR NZ,FX7Z6A
; LD HL,7*256+FULL+3
; CALL BEEP
 ;
FX7Z6A	LD A,(SPRITE)
 	LD L,A
	PUSH BC:PUSH HL
	LD A,128
	LD (SPRITE),A
 	LD A,C
	SUB 6
 	LD C,A
	LD A,(FRAME)
	AND 1
 	ADD 34
	CALL TSPGADD
	CALL SPNS
 
 	POP HL:POP BC
 	LD A,L
	LD (SPRITE),A
 ;
FX7Z5	LD A,(FRAME)
 	AND 7
 	JR NZ,FX7Z9
 	LD A,(FX7BYTE)
	INC A
 	CP 3
	JR NZ,FX7Z1
 	XOR A
FX7Z1	
	LD (FX7BYTE),A
 	CP 0
	JR NZ,FX7Z2
 	LD A,5+96
 	LD HL,FX8BUFF+60 ;(20*3)
	JR FX7Z4
FX7Z2	CP 1
 	JR NZ,FX7Z3
 	LD A,4+96
 	LD HL,FX8BUFF+63 ;(21*3)
	JR FX7Z4
FX7Z3	LD A,6+96
	LD HL,FX8BUFF+66 ;(22*3)
FX7Z4	LD (HL),A
	INC HL
	INC C
 	INC C
 	LD (HL),C
 	INC HL
	LD (HL),B
.FX7Z9	
	LD HL,30
 	JP FX7D
 ;
FX7A	CP 1
	JR NZ,FX7B
;FACE COVER
	LD HL,94
	JP FX4Z
 FX7B	CP 2
	JP NZ,FX7C
;SMALL COVER
 	LD HL,FXBYTE2
 	LD A,(HL)
 	AND A
 	JR Z,FX7B2
	LD A,(FRAME)
	AND 7
 	JP NZ,FX7B1
 	INC (HL)
	INC B
 	LD HL,29
	JP FX7VEC
 FX7B2	LD A,(IY+0)
	CP 40
 	JR NC,FX7B1
 	LD A,1
	LD (FXBYTE2),A
FX7B1	LD HL,29
 	JP FX4Z
 ;
FX7C	CP 3
	JR NZ,FX7G
;TRIANGLE COVER
	LD HL,FXBYTE3
 	LD A,(HL)
 	AND A
 	JR Z,FX7C2
	LD A,(FRAME)
	AND 7
 	JR NZ,FX7C1
 	INC (HL)
	INC B
 	LD HL,28
	JR FX7VEC
 FX7C2	LD A,(IY+0)
	CP 40
 	JR NC,FX7C1
 	LD A,1
	LD (FXBYTE3),A
FX7C1	LD HL,28
 	JP FX4Z
 ;
;BIG COVER
 FX7G	LD A,(FXBYTE7)
	AND A
 	JR Z,FX7G4
	DEC A
 	LD (FXBYTE7),A
	JR FX7G3
;
FX7G4	LD A,C
 	CP 36
 	JR NC,FX7G3
 	LD A,(SHIPY)
	DEC A
 	CP B
	JR NZ,FX7G3
 	LD HL,FX11SEQ+2
 	LD (HL),B
 	DEC HL
	LD (HL),C
 	DEC HL
	LD (HL),42
	CALL FORCESYNC
	LD A,16
 	LD (FXBYTE7),A
;
FX7G3	LD HL,FXBYTE4
	LD A,(HL)
 	AND A
 	JR Z,FX7G2
	LD A,(FRAME)
	AND 7
 	JR NZ,FX7G1
 	INC (HL)
	INC B
 	LD HL,40
	JR FX7VEC
FX7G2	LD A,(IY+0)
	CP 40
 	JR NC,FX7G1
 	LD A,1
	LD (FXBYTE4),A
FX7G1	LD HL,40
 	JP FX4Z
 ;
FX7D	
	POP BC:POP DE
FX7VEC	
	LD A,B
	CP 17
 	JP C,FX4Z
FX7VEC1	LD (IY+0),0
	DEC B
 	DEC B
 	LD (CIRCHOLD1),BC
 	PUSH BC
 	CALL ADDEXPLO
 	POP BC
.FX7E	
	LD HL,(CIRCHOLD2)
 	LD (HL),8+#40
	;LD HL,10*256+FULL+2
	;CALL BEEP
 	CALL FXA98
	CP 4
	JR NZ,FX7EE
 	LD A,C
	ADD 5
 	LD C,A
	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
	;LD HL,10*256+FULL+2
	;CALL BEEP
 	LD HL,(CIRCHOLD2)
 	LD (HL),8+#40
	CALL FXA98
.FX7EE	
	LD D,0
 	LD E,A
	LD HL,FX7SCORE
	ADD HL,DE
 	LD D,(HL)
 	LD E,3
	CALL ATS
	JP TV4
	
	
;*******************
;*** MINE LAYERS ***
;*******************

.FX8	
	JR C,FX8F
	PUSH DE
 	CALL FXA98
	PUSH AF
 	LD H,0
	LD L,A
	LD DE,FX8BYTE1
	ADD HL,DE
.FX8B	
	LD A,(HL)
 	INC A
 	CP 96
 	JR NZ,FX8A
	XOR A
.FX8A
	LD (HL),A
 	RRCA
	RRCA
	RRCA
	RRCA
	AND 7
 	JR Z,FX8B
 	ADD 95
	LD L,A
	EX AF,AF'
 	POP AF
	LD H,A
	PUSH BC:PUSH HL
	LD A,(IY+8)
 	CP 1
	JR NZ,FX8C
	;LD HL,FX8BUFF
 	;LD BC,23*3
	;CALL FILL0
	JR FX8D
.FX8C	
	LD A,H
	ADD A
 	ADD A
 	ADD H
 	ADD L
 	SUB 96
	LD D,0
	LD E,A
	LD HL,FX8BYTES
	ADD HL,DE
 	;LD L,(HL)
 	;PUSH HL
 	;LD HL,FX8BUFF
 	;ADD HL,DE
 	;ADD HL,DE
 	;ADD HL,DE
 	;PUSH HL
 	;EX AF,AF'
 	;SUB 96
	;JR NZ,FX8E
	;LD DE,15
	;ADD HL,DE
;.FX8E	
	;DEC HL
	;DEC HL
	;DEC HL
	;LD (HL),0
 	;POP HL
	;POP DE
	;LD A,(HL)
 	;AND A
 	;JR NZ,FX8D
	;INC B
 	;INC C
 	;LD (HL),E
 	;SET 4,(HL)
	;INC HL
	;LD (HL),C
 	;INC HL
	;LD (HL),B
.FX8D	
	POP HL:POP BC:POP DE
	;JP FX4Z
;original FX4Z code
.FX4Z_old
	LD A,L
	EX AF,AF'
 	LD A,(DE)
 	AND 252
 	OR H
	LD (DE),A	
	jp TV1
	
 FX8F	
	LD DE,#0503 ;5*256+3
 	CALL ATS
	JP TV3
;
;4 THRUSTERS
 FX9	JR C,FX99
	LD HL,101
 	LD A,(TILENO)
 	CP 31
 	JP C,FX4Z
 	CP 51
 	JP NC,FX4Z
;
	PUSH DE
 	LD A,(TILENO)
 	SUB 31
	LD D,0
	LD E,A
	LD HL,FX9BYTES
	ADD HL,DE
 	LD A,(HL)
 	RLCA
	AND 1
 	LD E,A
	LD A,(HL)
 	AND 127
 	LD H,E
	LD L,A
	POP DE
	LD A,(TILENO)
 	AND 1
 	JP Z,FX4Z
  LD A,(FRAME)
 AND 31
 CP 4
 JR NZ,FX92A
  ;PUSH HL
  ;LD HL,7*256+FULL+3
 ;CALL BEEP
  ;POP HL
;
FX92A	LD A,(SPRITE)
	PUSH AF:PUSH BC:PUSH DE:PUSH HL
	LD A,L
	INC A
 	CP 102
	JR Z,FX92
 	DEC B
 FX92	EX AF,AF'
 	LD A,128
	LD (SPRITE),A
 	LD A,H
	LD HL,SPNS
	AND A
 	JR Z,FX91
 	LD HL,SPMS
FX91	LD (FX98+1),HL
	INC B
 	INC B
 	LD A,(FRAME)
	AND 1
 	LD L,A
	EX AF,AF'
 	ADD L
 	CALL TSPGADD
FX98	CALL 0000
 	POP HL:POP DE:POP BC:POP AF
 	LD (SPRITE),A
 	JP FX4Z
 ;
FX99	
	LD DE,#803 ;8*256+3
 	CALL ATS
	JP TV4
;
;POKER
 FX10	JP C,FX1000
 	JR Z,FX107
	LD A,(FX10HOLD+1)
 	CP 21
 	JR Z,FX107
	LD A,(FXBYTE6)
	LD (IY+0),A
 FX107	LD A,(IY+0)
	LD (FXBYTE6),A
	LD A,(SPRITE)
 	PUSH AF:PUSH DE
	LD A,(TILENO)
 	ADD A
 	ADD A
 	LD L,A
	LD A,(TILEPOS)
	ADD L
 	AND 15
	LD D,0
	LD E,A
	LD (FX10HOLD),A
 ;
	LD A,(FRAME)
	AND 7
 	JR NZ,FX100
 ;
	LD HL,FX10BYTES
 	ADD HL,DE
 	LD A,(HL)
 	CP 128
	JR C,FX101
	INC C
 	JR FX100
FX101	CP 64
	JR C,FX100
	DEC C
 ;
FX100	PUSH BC
	INC C
 	LD A,128
	LD (SPRITE),A
 	LD A,16
 	CALL TSPGADD
	CALL SPNS
 	POP BC:POP DE:POP AF
	LD (SPRITE),A
 ;
	LD A,(FX10HOLD)
 	CP 3
	JR Z,FX104
	CP 4
	JR Z,FX104
	CP 5
	JR Z,FX104
	CP 6
	JR Z,FX104
	CP 10
 	JR Z,FX102
	CP 11
 	JR Z,FX102
	CP 14
 	JP Z,FX103
	CP 15
 	JP Z,FX103
	LD HL,21
	CP 12
 	JR NC,FX106
 	LD HL,17
	JR FX106
;
FX102	LD A,(FRAME)
 	ADD 16
	RRCA
	RRCA
	AND 3
 	ADD 18
	LD H,0
	LD L,A
	JR FX106
;
FX103	LD A,(FRAME)
 	ADD 16
	RRCA
	RRCA
	AND 3
 	LD L,A
	LD A,21
 	SUB L
 	LD H,0
	LD L,A
	JR FX106
;
FX104	LD A,(FRAME)
 	AND 3
 	JR NZ,FX105
 	LD HL,FX11SEQ+2
 	LD (HL),B
 	DEC HL
	INC C
 	LD (HL),C
 	DEC HL
	LD A,R
	AND 3
 	ADD 38
	LD (HL),A
 	CALL FORCESYNC
	DEC C
 FX105	LD HL,17
 ;
FX106	LD A,L
 	LD (FX10HOLD+1),A
 	JP FX4Z
 ;
FX1000	
	LD DE,#0105
 	CALL ATS
	;CALL BIGBANG99
	JP TV4
;
;BACK BLASTERS
 FX11	JP C,FX113
	LD A,(FXBYTE5)
	AND A
 	JR Z,FX11J
	DEC A
 	LD (FXBYTE5),A
FX11J	PUSH BC:PUSH DE
 	LD A,(SHIPX)
	LD E,A
	INC E
 	LD A,(SHIPY)
	LD D,A
	CALL FXA98
	LD L,88
 	CP 0
	JR Z,FX11A
	INC L
 	CP 1
	JR Z,FX11B
	INC L
 	CP 2
	JR Z,FX11C
	INC L
 	CP 3
	JR Z,FX11B
	INC L
 	CP 4
	JR Z,FX11C
	INC L
 	JR FX11D
;DOWN
FX11A	LD A,E 
	CP C
	JR NZ,FX112
 	LD A,D
	CP B
	JR C,FX112
	INC B
 	LD A,34
 	JR FX111
;DOWN/RIGHT
FX11B	LD A,E
 	SUB C
 	LD H,A
	LD A,D
	SUB B
 	CP H
	JR NZ,FX112
 	INC B
 	INC C
 	LD A,35
 	JR FX111
;RIGHT
 FX11C	LD A,D
 	CP B
	JR NZ,FX112
 	LD A,E
	CP C
	JR C,FX112
	INC C
 	LD A,36
 	JR FX111	
 ;UP RIGHT
FX11D	LD A,E
 	SUB C
 	LD H,A
	LD A,D
	SUB B
 	CPL
 	INC A
 	CP H
	JR NZ,FX112
 	DEC B
 	LD A,37
 ;
FX111	PUSH HL
	LD HL,FX11SEQ+2
 	LD (HL),B
 	DEC HL
	LD (HL),C
 	DEC HL
	LD (HL),A
 	LD A,(FXBYTE5)
	AND A
 	JR NZ,FX11K
 	CALL FORCESYNC
	LD A,128
	LD (FXBYTE5),A
FX11K	POP HL
 FX112	POP DE:POP BC
	LD H,0
	JP FX4Z
 ;
FX113	
	LD DE,#0203 ;2*256+3
	CALL ATS
	JP TV4
;
FX12
 ;
FX13
 ;
;BLUE BALL IMPACT
FX14	
	;PUSH DE
 	;CALL CONVERT
	;POP DE
	call COLL_CheckPosition
	;JP C,FX1A
	jp nc,FX1A
	or A
	jp nz,FX1A ;must be not an enemy
	
.FX14_Collide
 	LD (IY+0),0
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
  ;LD HL,3*256+FULL+2
 ;CALL BEEP
 	JP TV4
;***************
;*** BULLETS ***
;***************
FX15	
	;JP TV4

	LD A,128
	LD (SPRITE),A
 	LD HL,FX8BUFF
 	XOR A
FX80	
	PUSH AF
 	LD A,(HL)
 	AND A
 	JR Z,FX81
 	CP 128
	JR C,FX83
FX81	
	INC HL
FX82	
	INC HL
	INC HL
	POP AF
	INC A
 	CP 23
 	JR NZ,FX80
	JP TV4
;
.FX83	
	INC HL
	LD C,(HL)
 	INC HL
	LD B,(HL)
 	CALL ALIENF99
 	EX AF,AF'
 ;
	LD A,B
	CP 20
 	JR NC,FX88
	LD A,C
	CP 31
 	JR NC,FX88
	;CALL CONVERT
	call COLL_CheckPosition
	jr nc,FX830	
	
	or A		;0 = BG
	jr z,FX88
	
	cp 32
	jr c,FX830	;1 - 31 = enemy
	
	cp #F1		;pills
	jp z,FX8
	
	cp #F0		;module
	jp z,FX8
	
	;AND A
 	;JR Z,FX830
	;CP 6
	;JR C,FX88
 	;CP 250
	;JR NC,FX88
	;CP 38
 	;JR C,FX88
	cp 32
	jp nc,FX88

 	;PUSH HL
 	;CALL GETSEQ
 	;POP HL
	;JR Z,FX88
 ;
.FX830	
	LD (HL),B
	DEC HL
	LD (HL),C
 	PUSH HL
 	EX AF,AF'
 	RRCA
	RRCA
	RRCA
	RRCA
	AND 15
	ld A,2
	CALL TSPGADD
	CALL SPNS
 	POP HL
	JR FX82
 ;
FX88	
	DEC HL
	DEC HL
	LD (HL),128
 	JR FX81
;****************************************
 ;NO ACTION
 FXA0	JP TV3
;
;HALF SPEED
FXA1	LD A,(FRAME)
	AND 1
 	JP NZ,TV3
 	JP TV4
;
FXA2	XOR A
 	;LD (CADD+1),A
 	JP TV3
;
FXA3	JR FXA2
 ;
FXA4	JR FXA2
 ;
FXA5	JR FXA2
 ;
FXA6	JR FXA2
 ;
;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
;****************************************
.FXA98	
	LD A,(IY+5)
	RRCA
	RRCA
	RRCA
	RRCA
	AND 15
	DEC A
 	DEC A
 	RET
;****************************************
 FXA99	LD A,(IY+0)
	AND A
 	JR NZ,FXA99A
	RET
 FXA99A	POP HL
	JP FXA1
;****************************************
 	DEFS 21
FX8BYTES	DEFB 5,4,6,2,10
 	DEFB 9,8,10,2,6
 	DEFB 6,4,5,1,9
	DEFB 10,8,9,1,5
FX8BUFF		ds 23*3,0 ;DEFS 23*3
FX8BYTE1	DEFB 0,0,0,0
FX7BYTE	DEFB 0
 FX7MOVE	DEFB 255,0,255,0,255,0,255,0,255,0,255,0,255,0
 	DEFB 255,1,255,1,255,1,255,1
	DEFB 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
FX7SCORE	DEFB 6,3,4,4,8
FX9BYTES	DEFB 101,101,101,104,104,104,101,101,101,101,101
	DEFB 104+128,104+128,104+128,104+128,104+128,104+128,101,101,101
FX11SEQ	DEFB 0,0,0
 FX10HOLD	DEFB 0,0
FX10BYTES	DEFB 64,64,64,0,0,0,0,128,128,128,0,0,0,0,0,0

.SpriteSpecial
	LD (IY+3),C
	LD (IY+4),B
.SS_TV2	
	LD A,(DE)
.SS_TVA	
	PUSH DE
	PUSH AF
 	EX AF,AF'
 	CALL TSPGADD
	POP AF
 	AND 3
	JR NZ,SS_THEM6
 	CALL SPNS_Special
 	JR SS_THEM9
.SS_THEM6	
	CP 1
 	JR NZ,SS_THEM7
 	CALL SPMS_Special
 	JR SS_THEM9
.SS_THEM7	
	CP 2
 	JR NZ,SS_THEM8
 	CALL SPFS_Special
 	JR SS_THEM9
.SS_THEM8	
	CALL SPBS_Special
.SS_THEM9	
	POP DE
	ret

;********************
;*** SPNS_Special ***
;********************
;put a sprite on screen buffer
;overwritte static class sprites
;HL = sprite
;DE = W,H
;BC = X,Y

.SPNS_Special
	ld A,(HL)
	or A
	ret z
	inc HL
	
	push IX
	
	;exchange x and Y
	ld A,C
	ld C,B
	ld B,A
	
	push DE
;save X,Y in BC' for clipping
	push BC
	exx
	pop BC
	exx
	
;save line larg
	ld A,D
	add A
	add D
	ld (SPNS_Special_saveWidth),A
	
;attr address base
	ld IXH,ATTR_Addr_high
;save original xpos	
	ld A,B
	ld (SPNS_Special_Xpos),A
	
	pop BC
	
	ex DE,HL
	
.SPNS_Special_yloop
	push BC
	push DE
	exx
	ld A,C
	cp 20
	jr nc,SPNS_Special_skipLine
	push BC
	exx
	;A contains Y pos
	add A	;*2
	add ATTR_Addr_low
	ld IXL,A
	ld L,(IX+0)
SPNS_Special_Xpos EQU $+1
	ld A,0
	add L
	ld L,A	
	ld H,(IX+1)	
	
.SPNS_Special_xloop
	exx
	ld A,B
	cp 32
	jr nc,SPNS_Special_Clip
	inc B
	exx
	
	ld A,(HL)
	and 15
	cp 3
	jr z,SPNS_Special_empty 
	and 3
	cp 3
	jr z,SPNS_Special_empty 
	

	
	
	;rra		;if target not empty , skip
	;and 15
	;cp 13
	;jr z,SPNS_Special_Ok	;skip only if BG
	;jr c,SPNS_Special_empty
	
	;and 3
	;cp 3
	;jr nz,SPNS_Special_empty


.SPNS_Special_Ok
	
	ld A,(DE)
	or A
	jr z,SPNS_Special_empty
	
	inc DE
	ld (HL),A
	
	ld A,H
	ld (SPNS_Special_saveH),A
	
	inc H
	
	ld A,(#4000)	;bank
	ld (HL),A
	inc H
;low byte of tile	
	ld A,(DE)
	ld (HL),A
	inc DE
	inc H
;high byte of tile
	ld A,(DE)
	ld (HL),A
	inc DE
	inc H
;master
	ld A,(MASTER)
	ld (HL),A
	
SPNS_Special_saveH EQU $+1
	ld H,0
	inc L
	
.SPNS_Special_Done
	djnz SPNS_Special_xloop
	


	exx
	pop BC
.SPNS_Special_skipLine
	inc C
	exx
	
;add sprite width to HL
	pop HL
SPNS_Special_saveWidth EQU $+1
	ld BC,0
	add HL,BC
	ex DE,HL

	;inc IX
	;inc IX
	pop BC
	dec C

	jr nz,SPNS_Special_yloop
	
	pop IX
	ret

.SPNS_Special_Clip
	inc B
	exx
.SPNS_Special_Empty
	inc DE
	inc DE
	inc DE
	inc L
	jr SPNS_Special_Done

;********************
;*** SPMS_Special ***
;********************
;put a sprite on screen buffer
;reversed on X axis
;HL = sprite
;DE = W,H
;BC = X,Y

.SPMS_Special
	ld A,(HL)
	or A
	ret z
	inc HL
	
	push IX
	
	;exchange x and Y
	ld A,C
	ld C,B
	ld B,A
	
	;add W to X
	ld A,B
	add D
	dec A
	ld B,A
	
	push DE
;save X,Y in BC' for clipping
	push BC
	exx
	pop BC
	exx
	
;save line larg
	ld A,D
	add A
	add D
	ld (SPMS_Special_saveWidth),A
	
;attr address base
	ld IXH,ATTR_Addr_high
;save original xpos	
	ld A,B
	ld (SPMS_Special_Xpos),A
	
	pop BC
	
	ex DE,HL
	
.SPMS_Special_yloop
	push BC
	push DE
	exx
	ld A,C
	cp 20
	jr nc,SPMS_Special_skipLine
	push BC
	exx
	;A contains Y pos
	add A	;*2
	add ATTR_Addr_low
	ld IXL,A
	ld L,(IX+0)
SPMS_Special_Xpos EQU $+1
	ld A,0
	add L
	ld L,A	
	ld H,(IX+1)	
	
.SPMS_Special_xloop
	exx
	ld A,B
	cp 32
	jr nc,SPMS_Special_Clip
	dec B
	exx
	
	ld A,(HL)
	and 15
	cp 3
	jr z,SPMS_Special_empty 
	and 3
	cp 3
	jr z,SPMS_Special_empty 
	
	ld A,(DE)
	or A
	jr z,SPMS_Special_empty
	
	inc DE
	or 8	;xflip
	ld (HL),A
	
	ld A,H
	ld (SPMS_Special_saveH),A
	
	inc H
	
	ld A,(#4000)	;bank
	ld (HL),A
	inc H
;low byte of tile	
	ld A,(DE)
	ld (HL),A
	inc DE
	inc H
;high byte of tile
	ld A,(DE)
	ld (HL),A
	inc DE
	inc H
;master
	ld A,(MASTER)
	ld (HL),A	
	
SPMS_Special_saveH EQU $+1
	ld H,0
	dec L
	
.SPMS_Special_Done
	djnz SPMS_Special_xloop
	


	exx
	pop BC
.SPMS_Special_skipLine
	inc C
	exx
	
;add sprite width to HL
	pop HL
SPMS_Special_saveWidth EQU $+1
	ld BC,0
	add HL,BC
	ex DE,HL

	;inc IX
	;inc IX
	pop BC
	dec C

	jr nz,SPMS_Special_yloop
	
	pop IX
	
	ret

.SPMS_Special_Clip
	dec B
	exx
.SPMS_Special_Empty
	inc DE
	inc DE
	inc DE
	dec L
	jr SPMS_Special_Done
	
;********************
;*** SPFS_Special ***
;********************
;put a sprite on screen buffer
;reversed on Y axis
;HL = sprite
;DE = W,H
;BC = X,Y

.SPFS_Special
	ld A,(HL)
	or A
	ret z
	inc HL
	
	push IX
	
	;exchange x and Y
	ld A,C
	ld C,B
	ld B,A
	
;add H to Y
	ld A,C
	add E
	dec A
	ld C,A
	
	push DE
;save X,Y in BC' for clipping
	push BC
	exx
	pop BC
	exx
	
;save line larg
	ld A,D
	add A
	add D
	ld (SPFS_Special_saveWidth),A
	
;attr address base
	ld IXH,ATTR_Addr_high
;save original xpos	
	ld A,B
	ld (SPFS_Special_Xpos),A
	
	pop BC
	
	ex DE,HL
	
.SPFS_Special_yloop
	push BC
	push DE
	exx
	ld A,C
	cp 20
	jr nc,SPFS_Special_skipLine
	push BC
	exx
	;A contains Y pos
	add A	;*2
	add ATTR_Addr_low
	ld IXL,A
	ld L,(IX+0)
SPFS_Special_Xpos EQU $+1
	ld A,0
	add L
	ld L,A	
	ld H,(IX+1)	
	
.SPFS_Special_xloop
	exx
	ld A,B
	cp 32
	jr nc,SPFS_Special_Clip
	inc B
	exx
	
	ld A,(HL)
	and 15
	cp 3
	jr z,SPFS_Special_empty 
	and 3
	cp 3
	jr z,SPFS_Special_empty 
	
	ld A,(DE)
	or A
	jr z,SPFS_Special_empty
	
	inc DE
	or 16 ;Y flip
	ld (HL),A
	
	ld A,H
	ld (SPFS_Special_saveH),A
	
	inc H
	
	ld A,(#4000)	;bank
	ld (HL),A
	inc H
;low byte of tile	
	ld A,(DE)
	ld (HL),A
	inc DE
	inc H
;high byte of tile
	ld A,(DE)
	ld (HL),A
	inc DE	
	inc H
;master
	ld A,(MASTER)
	ld (HL),A	
	
SPFS_Special_saveH EQU $+1
	ld H,0
	inc L
	
.SPFS_Special_Done
	djnz SPFS_Special_xloop

	exx
	pop BC
.SPFS_Special_skipLine
	dec C
	exx
	
;add sprite width to HL
	pop HL
SPFS_Special_saveWidth EQU $+1
	ld BC,0
	add HL,BC
	ex DE,HL

	;inc IX
	;inc IX
	pop BC
	dec C

	jr nz,SPFS_Special_yloop
	
	pop IX
	
	ret

.SPFS_Special_Clip
	inc B
	exx
.SPFS_Special_Empty
	inc DE
	inc DE
	inc DE
	inc L
	jr SPFS_Special_Done
	
;************
;*** SPBS_Special ***
;************
;X and Y axis reversed
;put a sprite on screen buffer
;HL = sprite
;DE = W,H
;BC = X,Y

.SPBS_Special
	ld A,(HL)
	or A
	ret z
	inc HL
	
	push IX
	
	;exchange x and Y
	ld A,C
	ld C,B
	ld B,A

;add W to X and H to Y
	ld A,B
	add D
	dec A
	ld B,A
	ld A,C
	add E
	dec A
	ld C,A
	
	push DE
;save X,Y in BC' for clipping
	push BC
	exx
	pop BC
	exx
	
;save line larg
	ld A,D
	add A
	add D
	ld (SPBS_Special_saveWidth),A
	
;attr address base
	ld IXH,ATTR_Addr_high
;save original xpos	
	ld A,B
	ld (SPBS_Special_Xpos),A
	
	pop BC
	
	ex DE,HL
	
.SPBS_Special_yloop
	push BC
	push DE
	exx
	ld A,C
	cp 20
	jr nc,SPBS_Special_skipLine
	push BC
	exx
	;A contains Y pos
	add A	;*2
	add ATTR_Addr_low
	ld IXL,A
	ld L,(IX+0)
SPBS_Special_Xpos EQU $+1
	ld A,0
	add L
	ld L,A	
	ld H,(IX+1)	
	
.SPBS_Special_xloop
	exx
	ld A,B
	cp 32
	jr nc,SPBS_Special_Clip
	dec B
	exx
	
	ld A,(HL)
	and 15
	cp 3
	jr z,SPFS_Special_empty 
	and 3
	cp 3
	jr z,SPFS_Special_empty 
	
	ld A,(DE)
	or A
	jr z,SPBS_Special_empty
	
	or 24;x/Y flip
	inc DE
	ld (HL),A
	
	ld A,H
	ld (SPBS_Special_saveH),A
	
	inc H
	
	ld A,(#4000)	;bank
	ld (HL),A
	inc H
;low byte of tile	
	ld A,(DE)
	ld (HL),A
	inc DE
	inc H
;high byte of tile
	ld A,(DE)
	ld (HL),A
	inc DE	
	inc H
;master
	ld A,(MASTER)
	ld (HL),A	
	
SPBS_Special_saveH EQU $+1
	ld H,0
	dec L
	
.SPBS_Special_Done
	djnz SPBS_Special_xloop
	


	exx
	pop BC
.SPBS_Special_skipLine
	dec C
	exx
	
;add sprite width to HL
	pop HL
SPBS_Special_saveWidth EQU $+1
	ld BC,0
	add HL,BC
	ex DE,HL

	;inc IX
	;inc IX
	pop BC
	dec C

	jr nz,SPBS_Special_yloop
	
	pop IX
	
	ret

.SPBS_Special_Clip
	dec B
	exx
.SPBS_Special_Empty
	inc DE
	inc DE
	inc DE
	dec L
	jr SPBS_Special_Done