//======================================================== FX_HEADER
EFF_INI		JP	EFF_INI_
EFF_RUN		JP	EFF_RUN_
//======================================================== FX_CONST
//======================================================== FX_INIT
EFF_INI_
	RET
//======================================================== FX_MAINLOOP
EFF_RUN_
	EI
	HALT
	CALL	OUTPUT
	CALL	SYNC
	CALL	SWAP
	RET
//======================================================== FX_PROCEDURES
SYNC	;--
	LD	HL,SYNC_TBL
SYNC_ADR EQU $-2
	LD	C,(HL)
	INC	HL
	LD	B,(HL)
	INC	HL
	EX	DE,HL
	LD	HL,(MUSPOS)
	AND	A
	SBC	HL,BC
	RET	C
	;---
	;LD	A,(SWAPDY)
	;NEG
	;LD	(SWAPDY),A

	
	
	LD	(SYNC_ADR),DE
	RET
SYNC_TBL
	DW	3770-1	;3772-4-1
	DW	3822-1
	DW	3874-1
	DW	#FFFF


TABLER
	DW	BABE1A
	DW	BABE1B
	DW	BABE3A
	DW	BABE3B
	DW	BABE5A
	DW	BABE5B
	DW	BABE7A
	DW	BABE7B
	DW	BABE9A
	DW	BABE9B
	DW	BABE11A
	DW	BABE11B

SWAP	LD	A,0
SWAP_A	EQU $-1
	ADD	A,1
SWAPDY	EQU $-1
	CP	#FF
	JR	NZ,SWAP2
	LD	A,11
SWAP2	CP	12
	JP	NZ,SWAP1
	XOR	A
SWAP1	LD	(SWAP_A),A
	ADD	A,A
	LD	C,A
	LD	B,0
	LD	HL,TABLER
	ADD	HL,BC
	;---
	LD	E,(HL)
	INC	HL
	LD	D,(HL)
	INC	HL
	;--
	PUSH	DE
	POP	HL
	;--
	LD	BC,768
	ADD	HL,BC
	LD	(BRGB2+1),HL
	LD	(BRGB1+1),DE
	;--
SCRX	LD	A,0
	XOR	#FF
	LD	(SCRX+1),A
	JR	NZ,SCRX1
	;--
	LD	A,#17+#08
	LD	(FPG+1),A
	LD	HL,#5800
	LD	(ATR1+1),HL
	LD	HL,#D800
	LD	(ATR2+1),HL
	RET
SCRX1
	LD	A,#17
	LD	(FPG+1),A
	LD	HL,#D800
	LD	(ATR1+1),HL
	LD	HL,#5800
	LD	(ATR2+1),HL
	RET

;896
OUTPUT
	XOR	A
	OUT	(#FE),A

	LD	BC,620+18
WR1	DEC	BC
	LD	A,B
	OR	C
	JP	NZ,WR1

	;-----
BRGB1	LD	HL,BABE1A
ATR1	LD	DE,#5800
	EXX
BRGB2	LD	HL,BABE1A+768
ATR2	LD	DE,#D800
	;----------
	LD	LX,24
	LD	BC,#7FFD
FPG	LD	A,#17+#08
	OUT	(C),A
	EX	AF,AF
LP1	;-----------------
	EXX		;4
	DUP	32
	LDI		;16*32=512
	EDUP
	;---
	
	;--w325
	LD	A,22
	DEC	A
	JP	NZ,$-1
	LD	BC,#7FFD ;10
	;--
	EX	AF,AF	;4
	XOR	#08	;7
	LD	BC,#7FFD ;10
	OUT	(C),A	;12
	EX	AF,AF	;4 /37
	;--
	LD A,R:LD A,R	;18
	;-----------------
	EXX		;4
	DUP	32
	LDI		;16*32=512
	EDUP
	;---
	
	;--w325
	LD	A,22
	DEC	A
	JP	NZ,$-1
	LD	BC,#7FFD ;10
	;--
	EX	AF,AF	;4
	XOR	#08	;7
	LD	BC,#7FFD ;10
	OUT	(C),A	;12
	EX	AF,AF	;4 /37
	;--
	DEC	LX	;8
	JP	NZ,LP1	;10 /18
	;-------------------
	RET

//======================================================== FX_INCLUDE_DATA
BBB	include "bin/babe1.asm"
	DISPLAY	"BBB ", /A, $-BBB
	include "bin/babe3.asm"
	include "bin/babe5.asm"
	include "bin/babe7.asm"
	include "bin/babe9.asm"
//======================================================== FX_TABLES


