.FORCESYNC	
	EX AF,AF'
	PUSH AF
	PUSH DE
	PUSH BC
 	LD A,#C9
	LD (GETSYNC4),A
 	LD A,(HL)
 	INC HL
	LD E,(HL)
 	INC HL
	LD D,(HL)
 	CALL GETSYNCVEC
 	XOR A
 	LD (GETSYNC4),A
 	POP BC
	POP DE
	POP AF
	EX AF,AF'
 	RET

.GETSEQ	
	AND 127
 	DEC A
 	LD L,A
	ADD A
 	ADD A
 	ADD A
 	ADD L
 	LD H,SEQBUFF_high
	LD L,A
	INC L
 	LD A,(HL)
	dec L ;fix for bugged stuff ?
 	AND 63
	CP 63
 	RET
 ;
.GETSYNC	
	LD A,(SYNCOFF)
 	AND A
 	RET NZ
.GETSYNC0	
	LD HL,(SYNCHOLD)
	LD A,255
	CP (HL)
 	RET Z
 	LD A,(TILENO)
 	CP (HL)
 	RET NZ
	INC HL
	LD A,(HL)
 	RRCA
	RRCA
	RRCA
	AND 3
 	LD B,A
	LD A,(TILEPOS)
	CP B
	RET NZ
	LD A,(HL)
 	AND 7
 	LD B,A
	LD A,(TILESCROLL)
 	CP B
	RET NZ
	INC HL
	LD A,(HL)
	;break
 	CP 99
 	JP Z,GETSYNC9
 	INC HL
	LD E,(HL)
 	INC HL
	LD D,(HL)
 	INC HL
	LD (SYNCHOLD),HL
	
;A holds sequence number
 ;E holds start x point
 ;D holds start y point
.GETSYNCVEC
	LD H,0
	LD L,A
	DEC L
 	ADD HL,HL
 	LD BC,(SEQTABLE)
	ADD HL,BC
 	LD A,(HL)
 	INC HL
	LD H,(HL)
 	LD L,A
	PUSH HL
 ;
	LD HL,SEQBUFF
 	LD B,24
 	LD A,(FORCESEQ)
 	or A
 	JR Z,GETSYNC1
 	;CALL GETSEQ
	dec A
	ld L,A
	add A
	add A
	add A
	add L
	ld L,A
	ld H,SEQBUFF_high
	
 	xor A
 	LD (FORCESEQ),A
 	jr GETSYNC2
 ;
.GETSYNC1
	LD A,(HL)
 	;AND A
	and 63
 	JR Z,GETSYNC2
.GETSYNC1_Resume
 	LD A,L
	ADD 9
 	LD L,A
	DJNZ GETSYNC1
 	POP HL
	JR GETSYNC4
 ;
.GETSYNC2	
	PUSH HL
 	POP IX
	
	bit 7,(IX+8)	;check if damaged !
	jr nz,GETSYNC1_Resume	;resume if not empty !
	
	POP HL
	LD (IX+6),L
 	LD (IX+7),H
 	LD (IX+3),E
 	LD (IX+4),D
 	EX DE,HL
	LD A,(DE)
 	LD (IX+5),A
 ;
	INC DE
	LD A,(DE)
 	LD (IX+0),A
 	INC DE
	INC DE
	EX DE,HL
	LD A,(HL)
 	INC HL
	CP (HL)
 	JR NZ,GETSYNC3
	CP 128
	JR NC,GETSYNC3
	LD H,0
	LD L,A
	DEC L
 	ADD HL,HL
 	LD BC,(SEQTABLE)
	ADD HL,BC
 	LD A,(HL)
 	INC HL
	LD H,(HL)
 	LD L,A
	LD (IX+6),L
 	LD (IX+7),H
 	INC HL
	INC HL
	INC HL
	LD A,(HL)
 	INC HL
;
.GETSYNC3	
	LD (IX+1),A
 	LD A,(HL)
 	LD (IX+2),A
 	LD A,1
	LD (IX+8),A
.GETSYNC4	
	nop
 	JP GETSYNC0
 ;
.GETSYNC9	
	;break
	INC HL
	LD A,(HL)
 	INC HL
	INC HL
	LD (SYNCHOLD),HL
	DEC HL
	ld DE,GETSYNC4	;ret address
	push DE
	or A
	ret z			;ret if null
	cp 17
	ret nc			;ret >=17
	
	dec A
	
	add A
	ld E,A
	ld D,0
	ex DE,HL
	ld BC,GETSYNC_JumpTable	
	add HL,BC
	ld C,(HL)
	inc HL
	ld B,(HL)
	push BC
	ex DE,HL
	ret				;jump !

.GETSYNC_JumpTable	
	dw GETSYNC91
	dw GETSYNC92
	dw GETSYNC93
	dw GETSYNC94
	dw GETSYNC95
	dw GETSYNC96
	dw GETSYNC97
	dw GETSYNC98
	dw GETSYNC99
	dw GETSYNC9A	
	dw GETSYNC9B
	dw GETSYNC9C
	dw GETSYNC9D
	dw GETSYNC9E
	dw GETSYNC9F
	dw GETSYNC10	;16
	

 ;switch off scrolling
GETSYNC91	
	LD A,1
 	LD (NOSCROLL),A
 	;LD A,#37
	;LD (GETDET1),A
	;LD A,#C9
	;LD (GETDET1+1),A
	;LD HL,BUFFATT
 	;LD DE,22528
 	;LD BC,640
 	;LDIR
	;CALL FADEONVEC
	ret
 ;
;SWITCH ON SCROLLING
.GETSYNC92	
	CALL GETSYNC100
	ret
 ;
;FORCE SEQUENCE NUMBER n
.GETSYNC93	
	LD A,(HL)
	LD (FORCESEQ),A
 	ret
 ;
;SET ALIEN FIRE BULLETS
.GETSYNC94	
	LD A,(HL)
	LD (ALIENBULL),A
	ret
 ;
;FORCE END OF LEVEL
.GETSYNC95	
	jp SOFT_END_Start
 ;
;DO SOUND EFFECT
.GETSYNC96	
	;LD H,(HL)
	;LD L,FULL+3
 	;CALL BEEP
	ld A,(HL)
	call SND_SfxPlay
 	ret
	
;FOR setup
.GETSYNC97
	;break
	ld A,(HL)
	ld (SCR_FORCNT),A
	ld A,(TILENO)
	ld (SCR_FORTIL),A	
	
	inc HL
	ld (SCR_FORPOS),HL
	ret

;NEXT
.GETSYNC98
	;break
	ld A,(SCR_FORCNT)	;if count<=0
	dec A
	;,jp Z,GETSYNC4
	;jp C,GETSYNC4
	ret z
	ret c
	
	ld (SCR_FORCNT),A
	
	ld HL,(SCR_FORPOS)
	ld (SYNCHOLD),HL
	
	ld A,(SCR_FORTIL)
	ld (TILENO),A
	
	xor A
	ld (TILESCROLL),A
	ld (TILEPOS),A

	ret

;setup special value 1	
.GETSYNC99
	ld A,(HL)
	ld (SCR_SPEC1),A
	ret
	
;setup special value 2	
.GETSYNC9A
	ld A,(HL)
	ld (SCR_SPEC2),A
	ret
	
;Start special music , do fading before
.GETSYNC9B
	ld A,(option_menu_sound)
	cp 2
	ret z
	ld A,(HL)
	ld (LVL_NextMusik),A
	xor A
	ld (LVL_FadeVolume),A
	;ld A,(HL)
	;push HL
	;call MUSIC_Play
	;pop HL
	ret
	
;Set BG color
.GETSYNC9C
	ld A,(HL)
	call GFX_ConvertColor
	ld (BG_Color),A	
	ret
	
;save checkpoint
.GETSYNC9D

	ld A,(SHIP)	;be sure player is alive !
	or A
	ret z
	
	call GAME_SaveVars

	;save BG event
	ld HL,BG_Buffer
	ld DE,save_BG_Buffer
	ld BC,64
	ldir
	
	ret
	
;start BG event
.GETSYNC9E
	ld a,(HL)
	call BG_Effect_Start
	ret

;stop BG event	
.GETSYNC9F
	call BG_Effect_Stop
	ret
	
;set FLoat color
.GETSYNC10
	ld A,(HL)
	call GFX_ConvertColor
	ld (FL_Color),A
	ret
 ;
GETSYNC100	
	XOR A
 	LD (NOSCROLL),A
 	LD (SYNCOFF),A
	;LD A,#1C
	;LD (GETDET1),A
	;LD A,#1A
	;LD (GETDET1+1),A
	RET