;-----------------
LAND_PG0	INCBIN "bin/part1/landscape_pg0.bin.pl5d"
LAND_PG0_END
LAND_PG0_PG	EQU #13
;-----------------
LAND_EXE	INCBIN "bin/part1/land1_effect.bin.pl5d"
LAND_EXE_END
LAND_EXE_PG	EQU #13
;-----------------
LAND2_MAP	INCBIN "bin/part1/land2_map.bin.pl5d"
LAND2_MAP_END
LAND2_MAP_PG	EQU #13
;-----------------
LAND_YYY	INCBIN "bin/part1/landscape_yyy.bin.pl5d"
LAND_YYY_END
LAND_YYY_PG	EQU #13
;-----------------
LOAD_IMG	INCBIN "bin/part1/load_final_hidden.scr.pl5d"
LOAD_IMG_PG	EQU #13
;-----------------
DUOTUNNEL_EXE	INCBIN "bin/part1/duotunnel_effect.bin.pl5d"
DUOTUNNEL_EXE_END
DUOTUNNEL_EXE_PG EQU #13
;-----------------
D2TATR0		INCBIN "bin/part1/duo-to-twister-attr.002"
D2TATR1		INCBIN "bin/part1/duo-to-twister-attr.003"
D2TATR		INCBIN "bin/part1/duo-to-twister-attr.pl5d"
D2TATR_PG	EQU #13
;-----------------
DUO2TWIST_SCR	INCBIN "bin/part1/duo-to-twister-bits.bin"
DUO2TWIST_SCR_END
DUO2TWIST_SCR_PG EQU #13
;-----------------
MOVESQUAD_EXE	INCBIN "bin/part2/movesquad_effect.bin.pl5d"
MOVESQUAD_EXE_END
MOVESQUAD_EXE_PG EQU #13
;-----------------
DUO2TW_DO
	LD	HL,D2T_SYNC_TBL
D2T_HL	EQU	$-2
	LD	C,(HL)
	INC	HL
	LD	B,(HL)
	INC	HL
	EX	DE,HL
	LD	HL,(MUSPOS)
	AND	A
	SBC	HL,BC
	EX	DE,HL
	JP	C,D2T_NOSWP
	;--
	LD	BC,6
	ADD	HL,BC
	LD	(D2T_HL),HL
	INC	HL
	INC	HL
D2T_NOSWP ;---
	LD	E,(HL)
	INC	HL
	LD	D,(HL)
	INC	HL
	EX	DE,HL
	JP	(HL)
D2T_OUT
	XOR	A
	OUT	(#FE),A
	EX	DE,HL
	LD	E,(HL)
	INC	HL
	LD	D,(HL)
	INC	HL
	LD	A,(HL)
	INC	HL
	LD	H,(HL)
	LD	L,A

	LD	A,0
D2T_A	EQU	$-1
	XOR	#FF
	LD	(D2T_A),A
	JP	Z,D2T3
	EX	DE,HL
D2T3	LD	DE,#5800
	CALL	LDI128
	CALL	LDI128
	CALL	LDI128
	CALL	LDI128
	CALL	LDI128
	CALL	LDI128
	JP	IM2CALL_RET
D2T_INIT
	LD	A,7
	OUT	(#FE),A
	LD	HL,#5800
	LD	DE,#5801
	LD	(HL),7*8+7
	CALL	LDI128
	CALL	LDI128
	CALL	LDI128
	CALL	LDI128
	CALL	LDI128
	CALL	LDI128 + 2
	;--
	LD	(D2T_SP),SP
	LD	HL,#5400
	LD	DE,#F0F0
	LD	C,3
D2TI2	LD	SP,HL
	LD	B,4
D2TI1	DUP	128
	PUSH	DE
	EDUP
	DEC	B
	JP	NZ,D2TI1
	LD	A,H
	SUB	8
	LD	H,A
	DEC	C
	JP	NZ,D2TI2
	
	LD	SP,#3131
D2T_SP	EQU	$-2
	
	CALL	COMM_CLEAR_INT_PROC

	JP	IM2CALL_RET
D2T_SYNC_TBL
	DW	4349
	DW	D2T_OUT
	DW	D2TATR1
	DW	D2TATR0
	;--
	DW	4355 - 1
	DW	D2T_OUT
	DW	#A600 + 768*1
	DW	#A600 + 768*0
	;--
	DW	4362
	DW	D2T_OUT
	DW	#A600 + 768*3
	DW	#A600 + 768*2
	;--
	DW	4367
	DW	D2T_OUT
	DW	#A600 + 768*5
	DW	#A600 + 768*4
	;--
	DW	#FFFF
	DW	D2T_INIT
;-----------------
D2TOUT
	LD	HL,DUO2TWIST_SCR
	LD	DE,#4000
	LD	HX,6
D2T2	;-
	LD	LX,4
	PUSH	HL
D2T1	;-
	POP	HL
	PUSH	HL
	CALL	LDI128
	CALL	LDI128	;16*256=4096 ~= 16384 на 4 линии * 6 = 98304 ~= 1.3f
	;-
	DEC	LX
	JP	NZ,D2T1
	;-
	POP	BC
	DEC	HX
	JP	NZ,D2T2
	RET
LDI128	;-----
	DUP	128
	LDI		
	EDUP
	RET
