ORG level_start

IF output_files
	write "bin/level5.lvl"
ENDIF

START	DEFB 0
SYNCHRO	DEFW 0000

START1	DEFB 0 ;test_pos ;0
START2	DEFB 35
START3	DEFB 255

SYNCHRO1	DEFW SYNC1 ;test_sync ;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 4
.lvl_skip
	dw #300	;music to skip on music restart
.lvl_init
	dw	0	;called after loading
.lvl_reinit
	dw	lvl_start	;called each time player dies
	
.lvl_start
	xor A
	ld (pat_offset),A
	ld (pat_pos),A
	ld HL,l5_lvl_run
	ld (BG_Effect_Addr),HL
	ret
	
.l5_lvl_run
	ld A,(FRAME)
	and 1
	ret nz
	
	ld A,(pat_offset)
	inc A
	and 3
	ld (pat_offset),A
	jr nz,lvl_run_offsetOK
	
	ld A,(pat_pos)
	inc A
	and 15	
	ld (pat_pos),A
	
.lvl_run_offsetOK

	ld A,(pat_offset)
	inc A
	call TSPGADDL5
	ld B,16
	ld A,(pat_pos)
	neg
	ld C,A
	
	call SPNS_Static
	
	ret
;special SPR find in bank #C5
.TSPGADDL5
	push BC
	ld C,#C5
	jp USPGADD1
	
.pat_offset
	db 0
.pat_pos
	db 0
	
;****************************************
;*	LEVEL 5 - 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)
;****************************************

lvl_offset	EQU 8

SYNC1	DEFB 0,1,99,4,4
;snake 1
 	DEFB 9-lvl_offset,0,1,31,13
	DEFB 9-lvl_offset,4,2,31,13
	DEFB 9-lvl_offset,8,2,31,13
	DEFB 9-lvl_offset,12,2,31,13
 	DEFB 9-lvl_offset,16,2,31,13
 	DEFB 9-lvl_offset,20,2,31,13
 	DEFB 9-lvl_offset,22,3,31,13
 ;snake 2
 	DEFB 10-lvl_offset,16,11,31,8
	DEFB 10-lvl_offset,20,12,31,8
	DEFB 10-lvl_offset,24,12,31,8
	DEFB 10-lvl_offset,28,12,31,8
	DEFB 11-lvl_offset,0,12,31,8
 	DEFB 11-lvl_offset,4,12,31,8
 	DEFB 11-lvl_offset,8,12,31,8
 	DEFB 11-lvl_offset,12,12,31,8
	DEFB 11-lvl_offset,16,12,31,8
	DEFB 11-lvl_offset,20,12,31,8
	DEFB 11-lvl_offset,22,13,31,8
	DEFB 12-lvl_offset,6,4,31,6
;snake 3
 	DEFB 13-lvl_offset,8,14,16,18
	DEFB 13-lvl_offset,12,15,16,18
 	DEFB 13-lvl_offset,16,15,16,18
 	DEFB 13-lvl_offset,20,15,16,18
 	DEFB 13-lvl_offset,24,15,16,18
 	DEFB 13-lvl_offset,28,15,16,18
 	DEFB 14-lvl_offset,0,15,16,18
	DEFB 14-lvl_offset,4,15,16,18
	DEFB 14-lvl_offset,6,16,16,18
;snake 4
 	DEFB 14-lvl_offset,24,44,6,18
	DEFB 14-lvl_offset,28,45,6,18
	DEFB 15-lvl_offset,0,45,6,18
 	DEFB 15-lvl_offset,4,45,6,18
 	DEFB 15-lvl_offset,8,45,6,18
 	DEFB 15-lvl_offset,12,45,6,18
	DEFB 15-lvl_offset,14,46,6,18
;snake 5
 	;DEFB 15,24,17,8,2
	;DEFB 15,28,18,8,2
	;DEFB 16,0,18,8,2
 	;DEFB 16,4,18,8,2
 	;DEFB 16,8,18,8,2
   DEFB 16-lvl_offset,10,54,30,255
 	;DEFB 16,12,18,8,2
	;DEFB 16,16,18,8,2
	;DEFB 16,20,18,8,2
	;DEFB 16,22,19,8,2
  DEFB 17-lvl_offset,24,54,16,255
  DEFB 18-lvl_offset,0,4,31,7
;snake 6
 	DEFB 18-lvl_offset,0,1,31,13
 	DEFB 18-lvl_offset,4,2,31,13
 	DEFB 18-lvl_offset,8,2,31,13
 	DEFB 18-lvl_offset,12,2,31,13
	DEFB 18-lvl_offset,16,2,31,13
	DEFB 18-lvl_offset,20,2,31,13
	DEFB 18-lvl_offset,24,2,31,13
	DEFB 18-lvl_offset,28,2,31,13
	DEFB 19-lvl_offset,0,2,31,13
 	DEFB 19-lvl_offset,4,2,31,13
 	DEFB 19-lvl_offset,6,3,31,13
 ;snake 7
 	;DEFB 19,8,20,31,14
 	;DEFB 19,12,21,31,14
	;DEFB 19,16,21,31,14
	;DEFB 19,20,21,31,14
	;DEFB 19,24,21,31,14
	;DEFB 19,28,21,31,14
	;DEFB 20,0,21,31,14
 	;DEFB 20,4,21,31,14
 	;DEFB 20,8,21,31,14
 	;DEFB 20,12,21,31,14
	;DEFB 20,14,22,31,14
	DEFB 20-lvl_offset,24,54,30,255
	DEFB 21-lvl_offset,0,56,28,20
	DEFB 21-lvl_offset,4,5,31,4
;snake 8
 	DEFB 22-lvl_offset,4,14,6,18
 	DEFB 22-lvl_offset,8,15,6,18
 	DEFB 22-lvl_offset,12,15,6,18
	DEFB 22-lvl_offset,16,15,6,18
	DEFB 22-lvl_offset,20,15,6,18
	DEFB 22-lvl_offset,24,15,6,18
	DEFB 22-lvl_offset,26,15,6,18
	DEFB 22-lvl_offset,28,16,6,18
;snake 9
 	DEFB 23-lvl_offset,12,26,26,1
	DEFB 23-lvl_offset,16,27,26,1
	DEFB 23-lvl_offset,20,27,26,1
	DEFB 23-lvl_offset,24,27,26,1
;snake 10
	DEFB 23-lvl_offset,24,11,31,8
	DEFB 23-lvl_offset,28,27,26,1
	DEFB 23-lvl_offset,28,12,31,8
	DEFB 24-lvl_offset,0,27,26,1
	DEFB 24-lvl_offset,0,12,31,8
 	DEFB 24-lvl_offset,4,27,26,1
	DEFB 24-lvl_offset,4,12,31,8
 	DEFB 24-lvl_offset,8,27,26,1
	DEFB 24-lvl_offset,8,12,31,8
 	DEFB 24-lvl_offset,10,28,26,1
	DEFB 24-lvl_offset,12,12,31,8
	DEFB 24-lvl_offset,16,12,31,8
	DEFB 24-lvl_offset,20,12,31,8
	DEFB 24-lvl_offset,20,54,16,255
	DEFB 24-lvl_offset,24,12,31,8
	DEFB 24-lvl_offset,28,12,31,8
	DEFB 24-lvl_offset,30,13,31,8
	DEFB 26-lvl_offset,0,56,20,20
	DEFB 27-lvl_offset,8,54,30,255
	DEFB 27-lvl_offset,8,56,4,20
	DEFB 27-lvl_offset,24,8,31,12
;
	DEFB 29-lvl_offset,0,9,31,14
	DEFB 29-lvl_offset,2,9,31,4
	DEFB 29-lvl_offset,4,9,31,12
	DEFB 29-lvl_offset,6,9,31,8
;SNAKE 11
	DEFB 29-lvl_offset,16,47,6,18
	DEFB 29-lvl_offset,20,48,6,18
	DEFB 29-lvl_offset,24,48,6,18
	DEFB 29-lvl_offset,28,48,6,18
	DEFB 30-lvl_offset,0,48,6,18
	DEFB 30-lvl_offset,0,9,31,14
	DEFB 30-lvl_offset,2,9,31,12
	DEFB 30-lvl_offset,4,99,3,25
	DEFB 30-lvl_offset,4,9,31,8
 	DEFB 30-lvl_offset,4,48,6,18
	DEFB 30-lvl_offset,6,99,3,26
	DEFB 30-lvl_offset,6,9,31,4
	DEFB 30-lvl_offset,6,49,6,18
 ;snake 12
	DEFB 30-lvl_offset,24,50,14,18
 	DEFB 30-lvl_offset,28,51,14,18
 	DEFB 31-lvl_offset,0,51,14,18
	DEFB 31-lvl_offset,0,99,3,27
	DEFB 31-lvl_offset,0,9,31,14
	DEFB 31-lvl_offset,2,9,31,8
	DEFB 31-lvl_offset,4,9,31,4
	DEFB 31-lvl_offset,4,51,14,18
	DEFB 31-lvl_offset,8,51,14,18
	DEFB 31-lvl_offset,12,51,14,18
 	DEFB 31-lvl_offset,14,52,14,18
 ;snake 13 and 14
 	DEFB 32-lvl_offset,0,29,31,14
	DEFB 32-lvl_offset,0,32,31,2
 	DEFB 32-lvl_offset,4,30,31,14
	DEFB 32-lvl_offset,4,33,31,2
 	DEFB 32-lvl_offset,8,30,31,14
	DEFB 32-lvl_offset,8,33,31,2
 	DEFB 32-lvl_offset,12,30,31,14
	DEFB 32-lvl_offset,12,33,31,2
	DEFB 32-lvl_offset,16,30,31,14
	DEFB 32-lvl_offset,16,33,31,2
	DEFB 32-lvl_offset,20,30,31,14
	DEFB 32-lvl_offset,20,33,31,2
	DEFB 32-lvl_offset,24,30,31,14
	DEFB 32-lvl_offset,24,33,31,2
	DEFB 32-lvl_offset,28,30,31,14
	DEFB 32-lvl_offset,28,33,31,2
	DEFB 33-lvl_offset,0,30,31,14
	DEFB 33-lvl_offset,0,33,31,2
 	DEFB 33-lvl_offset,4,30,31,14
	DEFB 33-lvl_offset,4,33,31,2
 	DEFB 33-lvl_offset,6,31,31,14
	DEFB 33-lvl_offset,6,34,31,2
	DEFB 33-lvl_offset,8,56,4,20
	DEFB 33-lvl_offset,8,54,4,255
	DEFB 34-lvl_offset,20,54,20,255
	DEFB 35-lvl_offset,0,56,30,20
 ;
SYNC2
	DEFB 35-lvl_offset,24,23,31,12
 	DEFB 36-lvl_offset,8,23,31,8
	DEFB 36-lvl_offset,14,58,2,255
	DEFB 39-lvl_offset,0,6,31,4
	DEFB 42-lvl_offset,24,23,30,4
	DEFB 43-lvl_offset,0,54,20,255
	DEFB 47-lvl_offset,0,8,12,17
	DEFB 48-lvl_offset,0,56,28,20
 	DEFB 48-lvl_offset,16,4,31,4
	DEFB 49-lvl_offset,0,56,30,20
 	DEFB 51-lvl_offset,24,7,31,7
	DEFB 53-lvl_offset,8,56,30,20
 	DEFB 53-lvl_offset,24,23,31,8
	DEFB 54-lvl_offset,8,56,30,20
 	DEFB 55-lvl_offset,24,23,31,12
 	DEFB 57-lvl_offset,24,23,31,4
	DEFB 58-lvl_offset,0,54,30,255
	DEFB 59-lvl_offset,0,56,30,20
 	DEFB 62-lvl_offset,8,8,16,17
	DEFB 63-lvl_offset,0,54,10,255
	DEFB 63-lvl_offset,0,23,31,4
	DEFB 63-lvl_offset,16,56,30,20
	DEFB 63-lvl_offset,16,23,31,8
	DEFB 64-lvl_offset,0,56,20,20
	DEFB 64-lvl_offset,0,54,30,255
	DEFB 64-lvl_offset,0,23,31,12
;snake 15/16
 	DEFB 69-lvl_offset,0,26,12,1
 	DEFB 69-lvl_offset,4,27,12,1
 	DEFB 69-lvl_offset,8,27,12,1
 	DEFB 69-lvl_offset,12,27,12,1
	DEFB 69-lvl_offset,16,27,12,1
	DEFB 69-lvl_offset,16,14,18,19
 	DEFB 69-lvl_offset,20,27,12,1
	DEFB 69-lvl_offset,20,15,18,19
 	DEFB 69-lvl_offset,24,27,12,1
	DEFB 69-lvl_offset,24,15,18,19
 	DEFB 69-lvl_offset,28,27,12,1
	DEFB 69-lvl_offset,28,15,18,19
 	DEFB 69-lvl_offset,30,28,12,1
	DEFB 70-lvl_offset,0,15,18,19
	DEFB 70-lvl_offset,4,15,18,19
	DEFB 70-lvl_offset,8,15,18,19
	DEFB 70-lvl_offset,12,15,18,19
	DEFB 70-lvl_offset,14,16,18,19
 	DEFB 71-lvl_offset,16,5,31,6
	DEFB 71-lvl_offset,16,54,8,255
;stop scrolling

test_sync	EQU $
test_pos	EQU 72-lvl_offset

	DEFB 73-lvl_offset,24,99,1,0
	DEFB 73-lvl_offset,24,99,3,27
	DEFB 73-lvl_offset,24,24,12,20
 
  DEFB 73-lvl_offset,24,35,10,20
  DEFB 73-lvl_offset,24,35,9,22
  DEFB 73-lvl_offset,24,35,15,26
  DEFB 73-lvl_offset,24,35,16,24
  DEFB 73-lvl_offset,24,35,13,27
  DEFB 73-lvl_offset,24,35,19,19
  DEFB 73-lvl_offset,24,35,14,22
  ;DEFB 73-lvl_offset,24,35,11,24
  ;DEFB 73-lvl_offset,24,35,16,20
  ;DEFB 73-lvl_offset,24,35,11,26
  ;DEFB 73-lvl_offset,24,35,19,23
  ;DEFB 73-lvl_offset,24,35,14,19
  ;DEFB 73-lvl_offset,24,35,12,22
  ;DEFB 73-lvl_offset,24,35,12,20
  ;DEFB 73-lvl_offset,24,35,14,24
  ;DEFB 73-lvl_offset,24,35,18,25
  ;DEFB 73-lvl_offset,24,35,17,22
  ;DEFB 73-lvl_offset,24,35,20,21
  ;DEFB 73-lvl_offset,24,35,17,19
  ;DEFB 73-lvl_offset,24,35,17,27
  ;DEFB 73-lvl_offset,24,35,15,24
  ;DEFB 73-lvl_offset,24,35,17,22
  ;DEFB 73-lvl_offset,24,35,16,27
  ;DEFB 73-lvl_offset,24,35,19,26
 ;
	DEFB 95-lvl_offset,0,99,5,0
SYNC3	DEFB 255,255,255,255,255	
;****************************************
 ;	1ST BYTE
 ;		BITS 0-3 = SPECIAL EVENT 1
;		BITS 0-4 = SPECIAL EVENT 2
;	2ND BYTE = HIT POINTS
;	3RD BYTE
 ;		BITS 0-3 = POINT VALUE
;		BITS 4-7 = EXPLOSION TYPE
 ;	BYTES ARE NOW PAIRED TO MAKE UP
;	ADDRESS OF SPRITE PATTERNS
 ;	WORD 0 = END OF SEQUENCE 
;****************************************
 ;SNAKE 1/6 HEAD
SQ1	DEFB 3+#10,16,8+#20
	DEFW SP13,SP13B,SP9,SP15C,SP15CA,SP9,SP13,SP11,SP11,0
 ;SNAKE 1 BODY
SQ2	DEFB 4+#10,10,3+#20
	DEFW SP13,SP13B,SP9,SP15,SP15A,SP9,SP13,SP11,SP11,0
 ;SNAKE 1 TAIL
SQ3	DEFB 5+#10,10,3+#20
 	DEFW 2*256+2
;PODDER 1/2/5
SQ4	DEFB 2+#E0,1,2+32
	DEFW SP6,SP6A,SP6C,SP6B,SP6,SP6A,SP6C,SP6B,0
;PODDER 3/7
SQ5	DEFB 2+#C0,1,2+32
	DEFW SP6,SP6A,SP6C,SP6B,SP6,SP6A,SP6C,SP6B,0
;PODDER 4
SQ6	DEFB 2+#F0,1,2+32
	DEFW SP6,SP6A,SP6C,SP6B,SP6,SP6A,SP6C,SP6B,0
;PODDER 6
SQ7	DEFB 2+#B0,1,2+32
	DEFW SP6,SP6A,SP6C,SP6B,SP6,SP6A,SP6C,SP6B,0
;NODDING SNALIEN
 SQ8	DEFB 6+16,1+64,3+2*16
	DEFW SP5B,SP5,SP5C,SP5A,65535
 ;SCISSOR FLYER
 SQ9	DEFB 7+16,1,4+#10
 	DEFW SP3,SP3,SP3,SP3,0
;SCISSOR LASERS
SQ10	DEFB 0,63,12+#10
 	DEFW SP4A,SP4,SP4,SP4,0
 ;SNAKE 2/10 HEAD
 SQ11	DEFB 3+#20,16,8+#20
 	DEFW SP13,SP9A,SP9B,SP15C,SP15C,SP15CB,SP9,SP9A,SP13,SP11
 	DEFW SP14CB,SP10B,SP16B,SP10B,SP14CB,SP10B,SP16B,SP12
 	DEFW SP16,SP10,SP14C,SP11,SP11,SP11,0
 ;SNAKE 2/10 BODY
 SQ12	DEFB 4+#20,10,3+#20
 	DEFW SP13,SP9A,SP9B,SP15,SP15,SP15B,SP9,SP9A,SP13,SP11
	DEFW SP14B,SP10B,SP16B,SP10B,SP14B,SP10B,SP16B,SP12
 	DEFW SP16,SP10,SP14,SP11,SP11,SP11,0
;SNAKE 2/10 TAIL
 SQ13	DEFB 5+#20,10,3+#20
 	DEFW 12*256+12
;SNAKE 3/8/16 HEAD
 SQ14	DEFB 3+#30,16,8+#20
 	DEFW SP11,SP11,SP14CB,SP10,SP16B,SP12,SP12,0
;SNAKE 3 BODY
SQ15	DEFB 4+#30,10,3+#20
 	DEFW SP11,SP11,SP14B,SP10,SP16B,SP12,SP12,0
 ;SNAKE 3 TAIL
SQ16	DEFB 5+#30,10,3+#20
 	DEFW 15*256+15
;SNAKE 5 HEAD
SQ17	DEFB 3+#40,16,8+#20
 	DEFW SP12,SP12,SP12B,SP16B,SP10,SP10B
 	DEFW SP14CB,SP11,SP11B,SP14CA,SP10,SP10,0
 ;SNAKE 5 BODY
SQ18	DEFB 4+#40,10,3+#20
 	DEFW SP12,SP12,SP12B,SP16B,SP10,SP10B
 	DEFW SP14B,SP11,SP11B,SP14A,SP10,SP10,0
 ;SNAKE 5 TAIL
SQ19	DEFB 5+#40,10,3+#20
 	DEFW 18*256+18
;SNAKE 7 HEAD
SQ20	DEFB 3+#50,16,8+#20
 	DEFW SP13,SP13B,SP9,SP15C,SP9,SP13,SP9,SP15C,SP15CA,0
 ;SNAKE 7 BODY
SQ21	DEFB 4+#50,10,3+#20
 	DEFW SP13,SP13B,SP9,SP15,SP9,SP13,SP9,SP15,SP15A,0
;SNAKE 7 TAIL
SQ22	DEFB 5+#50,10,3+#20
 	DEFW 21*256+21
;CHANDELIERS
 SQ23	DEFB 8+16,62,8+#40
 	DEFW SP2,SP2,SP2,SP2,SP2,SP2,SP2,SP2,SP2A,0
 ;BIG ALIEN
 SQ24	DEFB 10+#20,62,12+#40
 	DEFW SP1III,SP1AA,SP1E,SP1FF,SP1D,SP1DD,SP1II,SP1C
	DEFW SP1C,SP1II,SP1BB,SP1AA,SP1BB,SP1FF,SP1D,SP1DD
	DEFW SP1GG,SP1AA,SP1GG,SP1EE,SP1II,SP1BB,SP1D,SP1DD
 	DEFW SP1EE,SP1C,SP1DD,SP1GG,SP1FF,SP1BB,SP1FF
 	DEFW SP1CC,SP1BBB,SP1I,0
;
SQ25
 ;
;SNAKE 9 HEAD
SQ26	DEFB 3+#60,16,8+#20
 	DEFW SP12,SP12,SP15CB,SP9,SP13B,SP11,SP11,0
 ;SNAKE 9 BODY
SQ27	DEFB 4+#60,10,3+#20
 	DEFW SP12,SP12,SP15B,SP9,SP13B,SP11,SP11,0
;SNAKE 9 TAIL
SQ28	DEFB 5+#60,10,3+#20
 	DEFW 27*256+27
;SNAKE 13 HEAD
 SQ29	DEFB 3+#70,16,8+#20
 	DEFW SP9,SP9,SP9,SP9,SP9,SP9
	DEFW SP13D,SP11B,SP14CD
 	DEFW SP10,SP10,SP10,SP10,SP10,SP10B,0
 ;SNAKE 13 BODY
 SQ30	DEFB 4+#70,10,3+#20
 	DEFW SP9,SP9,SP9,SP9,SP9,SP9
	DEFW SP13D,SP11B,SP14D
	DEFW SP10,SP10,SP10,SP10,SP10,SP10B,0
 ;SNAKE 13 TAIL
 SQ31	DEFB 5+#70,10,3+#20
 	DEFW 30*256+30
;SNAKE 14 HEAD
 SQ32	DEFB 3+#80,16,8+#20
 	DEFW SP9,SP9,SP9,SP9,SP9,SP9
	DEFW SP15CD,SP12B,SP16D
 	DEFW SP10,SP10,SP10,SP10,SP10,SP10B,0
 ;SNAKE 14 BODY
 SQ33	DEFB 4+#80,10,3+#20
 	DEFW SP9,SP9,SP9,SP9,SP9,SP9
	DEFW SP15D,SP12B,SP16D
	DEFW SP10,SP10,SP10,SP10,SP10,SP10B,0
 ;SNAKE 14 TAIL
 SQ34	DEFB 5+#80,10,3+#20
 	DEFW 33*256+33
;BRAINS
SQ35	DEFB 9+#20,26,2+#20
 	DEFW SP1III,SP1AA,SP1E,SP1FF,SP1D,SP1DD,SP1II,SP1C
	DEFW SP1C,SP1II,SP1BB,SP1AA,SP1BB,SP1FF,SP1D,SP1DD
	DEFW SP1GG,SP1AA,SP1GG,SP1EE,SP1II,SP1BB,SP1D,SP1DD
 	DEFW SP1EE,SP1C,SP1DD,SP1GG,SP1FF,SP1BB,SP1FF
 	DEFW SP1CC,SP1BBB,SP1I,0
;SNAKE BODY ROTATE UP
SQ36	DEFB 0,10,3+#20
	DEFW SP17A,SP17A,SP17A,SP17A,0,0
;SNAKE BODY ROTATE UP/RIGHT
SQ37	DEFB 0,10,3+#20
	DEFW SP17F,SP17F,SP17F,SP17F,0,0
;SNAKE BODY ROTATE RIGHT
 SQ38	DEFB 0,10,3+#20
	DEFW SP17D,SP17D,SP17D,SP17D,0,0
;SNAKE BODY ROTATE DOWN/RIGHT
SQ39	DEFB 0,10,3+#20
	DEFW SP17H,SP17H,SP17H,SP17H,0,0
;SNAKE BODY ROTATE DOWN
SQ40	DEFB 0,10,3+#20
	DEFW SP17B,SP17B,SP17B,SP17B,0,0
;SNAKE BODY ROTATE DOWN/LEFT
 SQ41	DEFB 0,10,3+#20
	DEFW SP17G,SP17G,SP17G,SP17G,0,0
;SNAKE BODY ROTATE LEFT
SQ42	DEFB 0,10,3+#20
	DEFW SP17C,SP17C,SP17C,SP17C,0,0
;SNAKE BODY ROTATE UP/LEFT
 SQ43	DEFB 0,10,3+#20
	DEFW SP17E,SP17E,SP17E,SP17E,0,0
;****************************************
 ;SNAKE 4 HEAD
SQ44	DEFB 3+16*9,16,8+#20
 	DEFW SP11,SP11,SP14CB,SP10,SP16B,SP12,SP12,0
;SNAKE 4 BODY
SQ45	DEFB 4+16*9,10,3+#20
 	DEFW SP11,SP11,SP14B,SP10,SP16B,SP12,SP12,0
 ;SNAKE 4 TAIL
SQ46	DEFB 5+16*9,10,3+#20
 	DEFW 15*256+15
;SNAKE 11 HEAD
 SQ47	DEFB 3+#A0,16,8+#20
	DEFW SP11,SP11,SP14CB,SP10,SP16B,SP12,SP12,0
;SNAKE 11 BODY
 SQ48	DEFB 4+#A0,10,3+#20
	DEFW SP11,SP11,SP14B,SP10,SP16B,SP12,SP12,0
 ;SNAKE 11 TAIL
 SQ49	DEFB 5+#A0,10,3+#20
	DEFW 15*256+15
;SNAKE 12 HEAD
 SQ50	DEFB 3+#B0,16,8+#20
	DEFW SP11,SP11,SP14CB,SP10,SP16B,SP12,SP12,0
;SNAKE 12 BODY
 SQ51	DEFB 4+#B0,10,3+#20
	DEFW SP11,SP11,SP14B,SP10,SP16B,SP12,SP12,0
 ;SNAKE 12 TAIL
 SQ52	DEFB 5+#B0,10,3+#20
	DEFW 15*256+15
;
;HOMER CURVE RIGHT/DOWN
SQ53	DEFB 13+#10,1+64,3+#10
	DEFW SP7A,SP7A,0
;HOMER CURVE DOWN/LEFT
 SQ54	DEFB 13+#20,1+64,3+#10
	DEFW SP7B,SP7B,0
;HOMER CURVE LEFT/UP
 SQ55	DEFB 13+#30,1+64,3+#10
	DEFW SP7C,SP7C,0
;HOMER CURVE UP/RIGHT
SQ56	DEFB 13+#40,1+64,3+#10
	DEFW SP7D,SP7D,0
;
;HOMER CURVE LEFT/DOWN
 SQ57	DEFB 13+#50,1+64,3+#10
	DEFW SP7E,SP7E,0
;HOMER CURVE DOWN/RIGHT
SQ58	DEFB 13+#60,1+64,3+#10
	DEFW SP7F,SP7F,0
;HOMER CURVE RIGHT/UP
SQ59	DEFB 13+#70,1+64,3+#10
	DEFW SP7G,SP7G,0
;HOMER CURVE UP/LEFT
 SQ60	DEFB 13+16*8,1+64,3+#10
	DEFW SP7H,SP7H,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,SQ58,SQ59,SQ60
;****************************************
 ;	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 ALIEN
 SP1AA	DEFB 8,0,8,4,8,0,8,4
 	DEFB 8,0,8,4,8,0,8,4+128	;UP

 SP1BB	DEFB 8,0,8,8,8,0,8,8
 SP1BBB	DEFB 8,0,8,8,8,0,8,8+128	;DOWN

 SP1C	DEFB 8,0,8,16,8,0,8,16
	DEFB 8,0,8,16,8,0,8,16
SP1CC	DEFB 8,0,8,16,8,0,8,16
 	DEFB 8,0,8,16,8,0,8,16+128	;LEFT

 SP1D	DEFB 8,0,8,32,8,0,8,32
	DEFB 8,0,8,32,8,0,8,32
SP1DD	DEFB 8,0,8,32,8,0,8,32
 	DEFB 8,0,8,32,8,0,8,32+128	;RIGHT
 
 SP1E	DEFB 8,0,8,20,8,0,8,20
	DEFB 8,0,8,20,8,0,8,20 
 SP1EE	DEFB 8,0,8,20,8,0,8,20
 	DEFB 8,0,8,20,8,0,8,20+128	;UP/LEFT
 
 SP1FF	DEFB 8,0,8,36,8,0,8,36
 	DEFB 8,0,8,36,8,0,8,36+128	;UP/RIGHT

 SP1GG	DEFB 8,0,8,24,8,0,8,24
 	DEFB 8,0,8,24,8,0,8,24+128	;DOWN/LEFT
 
 SP1HH	DEFB 8,0,8,40,8,0,8,40
 	DEFB 8,0,8,40,8,0,8,40+128	;DOWN/RIGHT

 SP1I	DEFB 8,0,8,0,8,0,8,0
	DEFB 8,0,8,0,8,0,8,0
SP1II	DEFB 8,0,8,0,8,0,8,0
 	DEFB 8,0,8,0,8,0
SP1III	DEFB 8,0+128		;STAY STILL
 
 ;CHANDELIERS
 SP2	DEFB 26,0,26,0,26,0,26,16
	DEFB 26,0,26,0,26,0,26,16
 	DEFB 26,0,26,0,26,0,26,16
 SP2A	DEFB 26,0,26,0,26,0,26,16+128
 ;SCISSOR TWISTER
 SP3	DEFB 27,16,28,16,29,16,28,18
 	DEFB 27,16,28,16,29,16,28,18+128
;
;SCISSOR TWISTER LASER
 SP4	DEFB 2,18,2,16,2,18,2,16
 SP4A	DEFB 2,18,2,16,2,18,2,16+128
;
;NODDING SNALIEN
 SP5	DEFB 5,0,6,0,6,0+128
 SP5A	DEFB 7,0,6,0,6,0+128
SP5B	DEFB 5,0+128
SP5C	DEFB 7,0+128
;
;PODDERS
 SP6	DEFB 13,24,13,24							;FLY D/L 6
SP6AA	DEFB 13,24,13,24,13,24,13,24+128	;FLY D/L 4 
 SP6A	DEFB 13,16,13,16							;FLY L*4
 SP6B	DEFB 13,16,13,16+128						;FLY L*2
SP6C	DEFB 13,20,13,20							;FLY U/L 6
 SP6CC	DEFB 13,20,13,20,13,20,13,20+128	;FLY U/L 4
;
;HOMING TWIRLERS
SP7A	DEFB 14,32+1,14,32+1,15,40+1,15,40+1
	DEFB 16,8,16,8+128 			;R/D

 SP7B	DEFB 16,8,16,8,15,24,15,24
	DEFB 14,16,14,16+128	 	;D/L
 
 SP7C	DEFB 14,16,14,16,15,20+2,15,20+2
	DEFB 16,4+2,16,4+2+128			;L/U
 
 SP7D	DEFB 16,4+2,16,4+2,15,36+3,15,36+3
	DEFB 14,32+1,14,32+1+128	 	;U/R
 
 SP7E	DEFB 14,16,14,16,15,24,15,24
	DEFB 16,8,16,8+128			;L/D
 
 SP7F	DEFB 16,8,16,8,15,40+1,15,40+1
	DEFB 14,32+1,14,32+1+128			;D/R
 
 SP7G	DEFB 14,32+1,14,32+1,15,36+3,15,36+3
	DEFB 16,4+2,16,4+2+128			;R/U
 
 SP7H	DEFB 16,4+2,16,4+2,15,20+2,15,20+2
	DEFB 14,16,14,16+128			;U/L
 
 ;
;SNAKE STRAIGHT LEFT
 SP9	DEFB 19,1+16
 SP9A	DEFB 19,1+16
SP9B	DEFB 19,1+16,19,1+16+128
;SNAKE STRAIGHT RIGHT
SP10	DEFB 19,32+2
SP10A	DEFB 19,32+2
 SP10B	DEFB 19,32+2,19,32+2+128
 ;SNAKE STRAIGHT UP
 SP11	DEFB 17,1+4
 SP11A	DEFB 17,1+4
SP11B	DEFB 17,1+4
SP11D	DEFB 17,1+4+128
;SNAKE STRAIGHT DOWN
 SP12	DEFB 17,2+8
 SP12A	DEFB 17,2+8
SP12B	DEFB 17,2+8
SP12D	DEFB 17,2+8+128
;SNAKE DIAGONAL U / L
SP13	DEFB 18,1+20
SP13A	DEFB 18,1+20
 SP13B	DEFB 18,1+20
 SP13D	DEFB 18,1+20+128
 ;SNAKE DIAGONAL U / R
SP14	DEFB 18,36+3
SP14A	DEFB 18,36+3
 SP14B	DEFB 18,36+3
 SP14D	DEFB 18,36+3+128
 SP14C	DEFB 18,36
 SP14CA	DEFB 18,36
SP14CB	DEFB 18,36
SP14CD	DEFB 18,36+128
;SNAKE DIAGONAL D / L
SP15	DEFB 18,24
SP15A	DEFB 18,24
 SP15B	DEFB 18,24
 SP15D	DEFB 18,24+128
 SP15C	DEFB 35,24
 SP15CA	DEFB 35,24
SP15CB	DEFB 35,24
SP15CD	DEFB 35,24+128
;SNAKE DIAGONAL D / R
SP16	DEFB 18,2+40
SP16A	DEFB 18,2+40
 SP16B	DEFB 18,2+40
 SP16D	DEFB 18,2+40+128
 ;ROTATING SNAKE BODIES
 
 SP17A	DEFB 18,4,18,6,18,7,18,5
 	DEFB 18,4,18,6,18,7,18,5+128

 SP17F	DEFB 18,36,18,38,18,39,18,37
 	DEFB 18,36,18,38,18,39,18,37+128

 SP17D	DEFB 18,32,18,34,18,35,18,33
 	DEFB 18,32,18,34,18,35,18,33+128

 SP17H	DEFB 18,40,18,42,18,43,18,41
 	DEFB 18,40,18,42,18,43,18,41+128

 SP17B	DEFB 18,8,18,10,18,11,18,9
 	DEFB 18,8,18,10,18,11,18,9+128

 SP17G	DEFB 18,24,18,26,18,27,18,25
 	DEFB 18,24,18,26,18,27,18,25+128

 SP17C	DEFB 18,16,18,18,18,19,18,17
 	DEFB 18,16,18,18,18,19,18,17+128

 SP17E	DEFB 18,20,18,22,18,23,18,21
 	DEFB 18,20,18,22,18,23,18,21+128
;****************************************
 SPEV1	DEFW FX0,FX1,FX2,FX3,FX4,FX5,FX6,FX7,FX8
 	DEFW FX9,FX10,FX11,FX12,FX13
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
;
;SNAKE HEAD
FX3	JP NC,FXX
	PUSH DE:PUSH BC
	LD IX,SEQBUFF
 	LD DE,9
 	LD B,28
 	LD C,3
FX3A	LD A,(IY+5)
 	AND 240
 	LD L,A
	LD A,(IX+5)
 	AND 240
 	CP L
	JR NZ,FX3B
;
	LD A,C
	INC A
 	CP 8
	JR NZ,FX3A1
 	XOR A
 FX3A1	LD C,A
 	ADD A
 	ADD A
 	ADD A
 	ADD A
 	SUB C
 	LD H,0
	LD L,A
	LD DE,SQ36
	ADD HL,DE
 	LD (IX+6),L
 	LD (IX+7),H
 	LD (IX+8),0
 ;
FX3B	LD DE,9
 	ADD IX,DE
 	DJNZ FX3A
 	POP BC:POP DE
 	JP TV4
;
;SNAKE BODY
FX4	JP NC,FX4Z
 	PUSH DE:PUSH BC
	LD IX,SEQBUFF
 	LD B,28
 FX4A	LD A,(IX+0)
 	AND A
 	JR Z,FX4B
 	LD A,(IY+5)
 	AND 240
 	LD L,A
	LD A,(IX+5)
 	AND 240
 	CP L
	JR NZ,FX4B
	LD A,(IY+8)
 	CP (IX+8)
 	JR NC,FX4B
FX4D	LD C,11
 	LD A,(IX+5)
 	AND 15
	CP 5
	JR Z,FX4B
 	CP 3
	JR Z,FX4C
 	LD C,12
 FX4C	LD A,(IX+5)
 	AND 240
 	OR C
	LD (IX+5),A
 ;
FX4B	LD DE,9
 	ADD IX,DE
 	DJNZ FX4A
 	POP BC:POP DE
 	JP TV4
;****************************************
 FX4Z	EX AF,AF'
 	ADD 3
 	EX AF,AF'
 	JP FXX
;
;SNAKE TAIL
FX5	
	;break

	EX AF,AF'
	ADD 6
 	EX AF,AF'
 	JP FXX
;***********************
;*** NODDING SNALIEN ***
;***********************
.FX6	
	JP C,TV5
	
	LD A,(SHIPX)
	CP C
	LD L,1
	JR NC,FX6G
 	LD L,0
FX6G	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,FX6A
	INC B
 	INC H
 	INC H
 	JR FX6B
FX6A	DEC B
	DEC H
 	DEC H
 FX6B	LD A,(SHIPX)
 	CP L
	JR C,FX6C
	INC C
 	INC L
 	INC L
 	JR FX6D
FX6C	DEC C
	DEC L
 	DEC L
 FX6D	PUSH BC
	PUSH HL
 	POP BC
	
	call COLL_CheckPosition
	jr nc,FX6E
	or A
	jr nz,FX6E
	
	;CALL CONVERT
	;AND A
 	;JR Z,FX6E
	POP HL
	POP DE
	POP BC
	JP TV1
FX6E	
	POP BC:POP DE:POP HL
 	JP TV1
;
;SCISSOR FLYER LASERS
FX7	JP C,TV4
 	LD A,(FRAME)
	SUB 8
 	AND 31
	JP NZ,FX1A
	LD HL,FX7Z+2
	LD A,(IY+4)
 	LD (HL),A
 	DEC HL
	LD A,(IY+3)
 	DEC A
 	DEC A
 	LD (HL),A
 	DEC HL
	CALL FORCESYNC
	JP FX1A
 FX7Z	DEFB 10,0,0
 ;
;CHANDELIER FIRERS
 FX8	JP C,TV4
 	LD A,(FRAME)
	AND 31
	JP NZ,FX1A
	LD HL,FX7Z+2
	LD A,R
	AND 3
 	ADD (IY+4)
	LD (HL),A
 	DEC HL
	LD A,(IY+3)
 	DEC A
 	DEC A
 	LD (HL),A
 	DEC HL
	CALL FORCESYNC
	JP FX1A
 FX8Z	DEFB 10,0,0
;****************************************
 ;BRAIN CONTROLLER 1 
FX9	JP C,TV4
 	JP Z,FX9A
 	LD A,70
 	;LD (CADD+1),A
.FX9A	

	LD A,R
	AND 3
 	LD L,A
	ADD 30
	EX AF,AF'
 	LD A,(DE)
 	AND 252
 	OR L
	LD (DE),A
	
	;jp TV2
 ;
	LD A,(FXBYTE1)
	AND A
 	JR Z,FX9B
 	CALL FXA97
	CALL FXA98
	JP TV2
;
FX9B	
	LD A,(IY+8)
 	CP 3
	JP C,FX1A
 	CALL FXA97
	AND A
 	JR NZ,FX9C
	LD A,(FXBYTE2)
	AND A
 	JP NZ,FX1A
	LD A,(FRAME)
	AND 7
	JP NZ,FX1A
	LD A,R
	AND 7
 	JP NZ,FX1A
	INC A
 	LD (FXBYTE2),A
;****************************************
 	PUSH DE:PUSH BC:PUSH HL
 	INC B
 	INC C
 	LD L,0
	LD A,(SHIPY)
	CP B
	JR Z,FX96
 	JR C,FX95
 	SET 1,L
 	JR FX96
 FX95	SET 0,L
 FX96	LD A,(SHIPX)
	CP C
	JR Z,FX99
 	JR C,FX97
 	SET 3,L
 	JR FX99
 FX97	SET 2,L
 FX99	DEC L
 	LD H,0
	LD DE,BRAINBYTES
	ADD HL,DE
 	POP DE:POP BC
 	LD A,(HL)
 	LD (DE),A
 	INC DE
	LD A,(3+SEQBUFF+234) ;26*9)
 	SUB C
 	CPL 
	INC A
 	LD (DE),A
 	INC DE
	LD A,(4+SEQBUFF+234) ;26*9)
 	SUB B
 	CPL
 	INC A
  	LD (DE),A
	POP DE
	JP FX1A
;****************************************
 FX9C	CP 128
	JR NC,FX9D
	CALL FXA98
	LD A,C
	CP 1
	JR Z,FX9B1
	CP 28
 	JR Z,FX9B1
	LD A,B
	AND A
 	JR Z,FX9B1
	CP 17
 	JR Z,FX9B1
	JP TV2
FX9B1	SET 7,(HL)
 	JP FX1A
;****************************************
 FX9D	INC HL
	INC HL
	PUSH DE:PUSH BC
	LD A,(4+SEQBUFF+234) ;26*9)
 	ADD (HL)
	DEC HL
	CP B
	JR Z,FX9D1
	JR C,FX9D2
	INC B
 	JR FX9D1
FX9D2	DEC B
FX9D1	LD A,(3+SEQBUFF+234) ;26*9)
	ADD (HL)
	DEC HL
	CP C
	JR Z,FX9D3
	JR C,FX9D4
	INC C
 	JR FX9D3
FX9D4	DEC C
FX9D3	POP DE
 	LD A,B
	CP D
	JR NZ,FX9D5
 	LD A,C
	CP E
	JR NZ,FX9D5
 	LD (HL),0
 FX9D5	POP DE
 	JP FX1A
;****************************************
 ;BIG ALIEN
FX10	
	JR C,FX10C
	JP NZ,FX10D
 	JP FX10E
FX10C	
	LD (IY+0),62
 	LD HL,(CIRCHOLD2)
 	LD (HL),0
 	LD A,(FXBYTE3)
	INC A
 	LD (FXBYTE3),A
	CP 4
	JR NZ,FX10D
 	LD (IY+0),0
 	LD (HL),#30
	PUSH BC
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	POP BC
	INC C
 	INC C
 	INC C
 	PUSH BC
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	POP BC
	INC B
 	INC B
 	INC B
 	PUSH BC
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	POP BC
	DEC C
 	DEC C
 	DEC C
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	LD DE,#204 ;2*256+4
 	CALL ATS
	PUSH IY
 	LD IY,SEQBUFF
 	LD DE,9
 	LD B,28
 FX10F	
	LD A,(IY+0)
	AND A
 	JR Z,FX10G
	PUSH BC
 	LD (IY+0),0
 	LD C,(IY+3)
 	LD B,(IY+4)
 	LD (CIRCHOLD1),BC
 	CALL ADDEXPLO
 	POP BC
FX10G	
	LD DE,9
	ADD IY,DE
 	DJNZ FX10F
	LD A,93
 	LD (TILENO),A
 	POP IY
	JP TV4
;
FX10D	LD A,(FRAME)
 	AND 1
 	JR Z,FX10E
	LD A,71
 	;LD (CADD+1),A
 FX10E	XOR A
	LD (FXBYTE2),A
;
	LD A,(IY+8)
 	CP 1
	JR Z,FX10B
	CP 34
 	JR NZ,FX10Z
 
	PUSH BC:PUSH DE
	LD HL,BRAINTABLE
	LD B,24
 	XOR A
 FX10AA	
	LD (HL),A
 	INC (HL)
	INC A
 	AND 7
 	INC HL
	INC HL
	INC HL
	DJNZ FX10AA
 	POP DE:POP BC
 
 	LD A,1
	LD (FXBYTE1),A
	INC (IY+3)
	LD C,(IY+3)
 	JP TV2
;
FX10B	
	PUSH BC:PUSH DE
 	LD HL,BRAINTABLE
	LD BC,24*3
	CALL FILL0
	POP DE:POP BC
 	JP FX1A
.FILL0
	
.FILL0_loop
	ld (HL),0
	inc HL
	;djnz FILL0_loop
	dec BC
	ld A,C
	or B
	jr nz,FILL0_loop
	ret
	
 ;
FX10Z	LD A,(DE)
	AND 252
 	LD (DE),A
 	JP FX1A
 ;
;SNAKE HEAD
FX11	JP FYY
;
;SNAKE BODY
FX12	EX AF,AF'
 	ADD 3
 	EX AF,AF'
 	JP FYY
;
;HOMING TWIRLERS
.FX13	
	jp C,TV5
 
 
	LD A,(IY+8)
 	CP 2
	JP NZ,FXX
 	LD A,C
	CP 40
 	JR C,FX13AA
 	CP 245
	JR C,FX13AC
 FX13AA	LD A,B
	CP 30
 	JR C,FX13AB
 	CP 245
	JR NC,FX13AB
FX13AC	LD (IY+0),0
 	JP FXX
FX13AB	PUSH BC:PUSH DE
	DEC (IY+8)
	LD A,(SHIPX)
	INC A
 	LD L,A
	LD A,(SHIPY)
	LD H,A
	INC B
 	INC C
 	LD A,(IY+5)
 	RRCA
	RRCA
	RRCA
	RRCA
	AND 15
	CP 1
	JR Z,FX13L
	CP 2
	JR Z,FX13M
	CP 3
	JR Z,FX13N
	CP 4
	JR Z,FX13O
	CP 5
	JR Z,FX13L
	CP 6
	JR Z,FX13O
	CP 7
	JR Z,FX13N
	CP 8
	JR Z,FX13M
;1 R/D
 FX13L	LD A,L
 	CP C
	JR NC,FX13F
 	JR FX13B
;2 D/L
 FX13M	LD A,H
 	CP B
	JR NC,FX13E
 	JR FX13C
;3 L/U
 FX13N	LD A,L
 	CP C
	JR NC,FX13D
 	JR FX13H
;4 U/R
 FX13O	LD A,H
 	CP B
	JR NC,FX13A
 	JR FX13G
;****************************************
 ;1 R/D
 FX13A	LD HL,SQ53
 	LD DE,SP7A
	LD A,1*16
 	JR FX13Z
;2 D/L
 FX13B	LD HL,SQ54
 	LD DE,SP7B
	LD A,2*16
 	JR FX13Z
;3 L/U
 FX13C	LD HL,SQ55
 	LD DE,SP7C
	LD A,3*16
 	JR FX13Z
;4 U/R
 FX13D	LD HL,SQ56
 	LD DE,SP7D
	LD A,4*16
 	JR FX13Z
;5 L/D
 FX13E	LD HL,SQ57
 	LD DE,SP7E
	LD A,5*16
 	JR FX13Z
;6 D/R
 FX13F	LD HL,SQ58
 	LD DE,SP7F
	LD A,6*16
 	JR FX13Z
;7 R/U
 FX13G	LD HL,SQ59
 	LD DE,SP7G
	LD A,7*16
 	JR FX13Z
;8 U/L
 FX13H	LD HL,SQ60
 	LD DE,SP7H
	LD A,8*16
 ;
;
FX13Z	LD (IY+6),L
	LD (IY+7),H
 	LD (IY+1),E
 	LD (IY+2),D
 	LD L,A
	LD A,(IY+5)
 	AND 15
	OR L
	LD (IY+5),A
 	POP DE:POP BC
 	JP FYY
;****************************************
 ;NO ACTION
 FXA0	JP TV3
;
;HALF SPEED
FXA1	LD A,(FRAME)
	AND 1
 	JP NZ,TV3
 	JP TV4
;;BRAIN CONTROLLER
 FXA2	XOR A
 ;	LD (CADD+1),A
 	JR FXA1
 ;
FXA3
 ;
FXA4
 ;
FXA5
	;break
	jp TV3
 ;
FXA6
 ;
;PODDER TOP PILL
 FXA7	LD L,5
	JR FXA15A
 ;
;PODDER BOTTOM PILL
FXA8	LD L,5
	JR FXA15A
 ;
;PODDER BULLETS (1)
;FXA9	LD L,1
 ;	JR FXA15A
;
;PODDER MINI LASER (2)
 ;FXA10	LD L,2
;	JR FXA15A
;
;PODDER LASER (3)
FXA10
FXA11	LD L,1
 	JR FXA15A
 ;
;PODDER BLOB (3)
 FXA9
 FXA12	LD L,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,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
;****************************************
 BRAINTABLE	DEFS 24*3
 BRAINBYTES	DEFB 1,2,0,3,5,7,0,4,6,8
;****************************************
.FXA97	
	PUSH DE
	LD A,(SPRITE)
 	AND 127
 	DEC A
 	LD E,A
	LD D,0
	LD HL,BRAINTABLE
	ADD HL,DE
 	ADD HL,DE
 	ADD HL,DE
 	LD A,(HL)
 	POP DE
	RET
;****************************************
.FXA98	
	CP 1
 	JR NZ,FXA98B
	DEC (IY+4)
	JR FXA98Z
.FXA98B	
	CP 2
	JR NZ,FXA98C
	INC (IY+4)
	JR FXA98Z
.FXA98C	
	CP 3
	JR NZ,FXA98D
	DEC (IY+3)
	JR FXA98Z
.FXA98D	
	CP 4
	JR NZ,FXA98E
	INC (IY+3)
	JR FXA98Z
 FXA98E	
	CP 5
	JR NZ,FXA98F
	DEC (IY+4)
	DEC (IY+3)
	JR FXA98Z
 FXA98F	
	CP 6
	JR NZ,FXA98G
	DEC (IY+4)
	INC (IY+3)
	JR FXA98Z
 FXA98G	
	CP 7
	JR NZ,FXA98H
	INC (IY+4)
	DEC (IY+3)
	JR FXA98Z
 FXA98H	
	INC (IY+4)
	INC (IY+3)
FXA98Z		
	LD C,(IY+3)
 	LD B,(IY+4)
 	RET
;****************************************
 FXA99	LD A,(IY+0)
	AND A
 	JR NZ,FXA99A
	RET
 FXA99A	POP HL
	JP FXA1
;****************************************
 FXX	LD A,(FRAME)
 	AND 1
 	JP Z,FXX2
 FXX1	LD (IY+3),C
 	LD (IY+4),B
 FXX2	LD A,(DE)
 	PUSH DE
 	PUSH AF
 	EX AF,AF'
 	CALL TSPGADD
	POP AF
 	AND 3
	JR NZ,FXX6
	CALL SPNS
 	JR FXX9
 FXX6	CP 1
	JR NZ,FXX7
	CALL SPMS
 	JR FXX9
 FXX7	CP 2
	JR NZ,FXX8
	CALL SPFS
 	JR FXX9
 FXX8	CALL SPBS
 FXX9	POP DE
	LD A,(FRAME)
	AND 1
 	JP NZ,TV3
 	JP TV4
;****************************************
 FYY	LD (IY+3),C
	LD (IY+4),B
 	LD A,(DE)
 	PUSH DE
 	PUSH AF
 	EX AF,AF'
 	CALL TSPGADD
	POP AF
 	AND 3
	JR NZ,FYY6
	CALL SPNS
 	JR FYY9
 FYY6	CP 1
	JR NZ,FYY7
	CALL SPMS
 	JR FYY9
 FYY7	CP 2
	JR NZ,FYY8
	CALL SPFS
 	JR FYY9
 FYY8	CALL SPBS
 FYY9	POP DE
	JP TV3