;*********************************************************************
;	Wipe Program
;				programed by H.Yajima
;*********************************************************************
	include	Xmacro.def
	include Pmacro.def
	include	RP5A22X
	include	RP5C77X
;---------------------------------------------------------------------
	include	register.alc
	include	wipe.def
;---------------------------------------------------------------------
	glb	InitWipe
	glb	MainWipe
;---------------------------------------------------------------------
bank0A	sect	rel
	extend
	mem16
	idx16
;-------------------------------------------- ;( 2 byte memory )

;*********************************************************************
;	SFX system
;*********************************************************************
InitWipe
	php
	a16xW

	lda	#0
	sta.l	wipe_process
	sta.l	wipe_wait
;;	lda	#8*2
	lda	#0
	sta.l	wipe_select

	lda	#03h
	sta.w	212eh

	plp
	rtl
;------------------------------------------------------------------
MainWipe
	php
	Mbank7f
	a16xW
	lda	wipe_select
	cmp	#100
	bcc	.entry
	lda	#0
.entry	asl	a
	tax
	jsr	(.process,x)
	plb
	plp
	rtl
;------------------------------------------------------------------
.process
	dw	wipe12_open	;(16)
	dw	wipe12_close	;(17)
	dw	wipe_reset

;	dw	wipe_exit	;(0)
;	dw	wipe_exit	;(1)	

	dw	wipe1_open	;(2)
	dw	wipe1_close	;(3)
	dw	wipe2_open	;(4)
	dw	wipe2_close	;(5)
	dw	wipe3_open	;(6)
	dw	wipe3_close	;(7)
	dw	wipe4_open	;(8)
	dw	wipe4_close	;(9)
	dw	wipe5_open	;(10)
	dw	wipe5_close	;(11)
	dw	wipe6_open	;(12)
	dw	wipe6_close	;(13)

	dw	wipe7_open	;(14)
	dw	wipe7_close	;(15)
	dw	wipe8_open	;(16)
	dw	wipe8_close	;(17)
	dw	wipe9_open	;(18)
	dw	wipe9_close	;(19)
	dw	wipe10_open	;(20)
	dw	wipe10_close	;(21)
	dw	wipe11_open
	dw	wipe11_close
	dw	wipe12_open
	dw	wipe12_close
	dw	wipe_reset	;(22)
;------------------------------------------------------------------
wipe_exit
	rts
wipe_reset
	lda	#0
	sta.l	wipe_select
	lda	#0
	sta.l	wipe_process
	sta.l	wipe_wait
	rts
;===================================================================
;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*                   ***********************************************
;*  WIPE MACRO       ***********************************************
;*                   ***********************************************
;*******************************************************************
nextprocess	macro
	lda	next_wait
	sta	wipe_wait	; set next wait timer
	inc	wipe_process	; set next process
	rts
	endm
;--------------------------------------
bcs_nextprocess	macro	data
	local	exitX
	lda	wipe_counter
	cmp	#data
	bcc	exitX
	lda	next_wait
	sta	wipe_wait	; set next wait timer
	inc	wipe_process	; set next process
exitX	rts
	endm
;--------------------------------------
beq_nextprocess	macro
	local	exitX
	bne	exitX
	lda	next_wait
	sta	wipe_wait	; set next wait timer
	inc	wipe_process	; set next process
exitX	rts
	endm
;--------------------------------------
wipeSEQ	macro
	local	skipX,next
	lda	wipe_wait
	bne	skipX
	lda	wipe_process
	asl	a
	asl	a
	tax
	lda.l	next+2,x
	sta	next_wait
	jsr	(next+0,x)
	rts
skipX	dec	wipe_wait
	rts
next
	endm
;--------------------------------------
wipecode	macro	addr,counter
	dw	addr,counter
	endm
;--------------------------------------
Msetparam	macro	color,control,logic
	local	skip1,skip2

	lda	#window_wipe
	sta	window_register
	a8
	ldx	#window_wipe

	lda	#color
	cmp	#20h
	beq	skip1
;- - - - - - - - - - - - - - - - - - - - - -	
	lda	#control/16+control
	sta	_window_control+0,x
	sta	_window_control+1,x
	and	#000fh
	sta	_window_control+2,x
	lda	#00h
	sta	_window_logic+0,x
	lda	#00h
	sta	_window_logic+1,x
	bra	skip2
;- - - - - - - - - - - - - - - - - - - - - -	
skip1
	lda	#control/16+control
	eor	#01010101b
	sta	_window_control+0,x
	sta	_window_control+1,x
	and	#000fh
	sta	_window_control+2,x
	lda	#55h
	sta	_window_logic+0,x
	lda	#01h
	sta	_window_logic+1,x

;- - - - - - - - - - - - - - - - - - - - - -	
skip2

;;	MsetZAX	_color_bias,0ffh
;;	MsetZAX	_color_brend,03fh+80h

	MsetZAX _color_brend,0
	MsetZAX _color_bias,0e0h

	a16
	jsr	swap_buffer		; 転送アドレスセット
	endm
;--------------------------------------
Msetparam2	macro	control,logic		
;- - - - - - - - - - - - - - - - - - - - - -	
	lda	#window_wipe
	sta	window_register
	a8
	ldx	#window_wipe
;- - - - - - - - - - - - - - - - - - - - - -	
	lda	#control+control*16
	sta	_window_control+0,x
	sta	_window_control+1,x
	and	#01111b
	sta	_window_control+2,x
	lda	#logic+logic*4+logic*16+logic*64
	sta	_window_logic+0,x
	and	#011b
	sta	_window_logic+1,x
;- - - - - - - - - - - - - - - - - - - - - -	
	MsetZAX _color_brend,0
	MsetZAX _color_bias,0e0h
	a16
	jsr	swap_buffer		; 転送アドレスセット
	endm
;--------------------------------------
bank7fset	macro
	phb
	pea	7f7fh
	plb
	plb
	endm
;-------------------------------------------------------------------
bankprogset	macro
	phb		; >
	phk		;  >
	plb		;  
	endm
;-------------------------------------------------------------------
bankrts	macro
	plb		; 
	rts
	endm
;-------------------------------------------------------------------
dwcode	macro	data
	dw	offset	data
	endm
;-------------------------------------------------------------------
winset_dw	macro	address
	lda.w	0,x
	sta.l	address
	inx
	inx
	endm
;-------------------------------------------------------------------
winadd_dw	macro	address
	lda.l	address
	clc
	adc.w	0,x
	sta.l	address
	inx
	inx
	endm
;-------------------------------------------------------------------
winbmiadd_dw	macro	address
	local	skipX
	lda.l	address
	clc
	adc.w	0,x
	cmp.w	2,x
	bmi	skipX
	lda.w	2,x
skipX	sta.l	address
	inx
	inx
	inx
	inx
	endm
;-------------------------------------------------------------------
winbpladd_dw	macro	address
	local	skipX
	lda.l	address
	clc
	adc.w	0,x
	cmp.w	2,x
	bpl	skipX
	lda.w	2,x
skipX	sta.l	address
	inx
	inx
	inx
	inx
	endm
;-------------------------------------------------------------------
winstart	macro
	inx
	inx
	endm
;-------------------------------------------------------------------
winnext	macro
	jmp	(0,x)
	endm
;-------------------------------------------------------------------
winexit	macro
	rts
	endm
;-------------------------------------------------------------------

;*******************************************************************
;*                   ***********************************************
;*  WIPE SUB-PROG    ***********************************************
;*                   ***********************************************
;*******************************************************************
wipe_center	equ	96	
wipe_half	equ	96
wipe_full	equ	96*2
;==================================================================
offswitch

	ldx	#window_default
	lda	wipe_select
	and	#01h
	beq	.exit
	ldx	#window_black
.exit	
	stx	window_register
	nextprocess
;--------------------------------------
endofwipe
	inc	wipe_select
	stz	wipe_process
	stz	wipe_wait
	rts
;--------------------------------------
clear_wipe1
	lda	#07f80h
	jsr	wipe_clear
	nextprocess
;--------------------------------------
wipe_clear
	ldx	#OFFSET	window_bufferA
	ldy	#wipe_full	; line count
.loop	sta.w	0,x
	sta.w	2,x
	sta	wipe_full*4+0,x
	sta	wipe_full*4+2,x
	inx
	inx
	inx
	inx
	dey
	bne	.loop
	rts
;-------------------------------------------------------------------
wipe_clear2
	sta	ZZaddr+0
	sty	ZZaddr+2
	ldx	#offset	window_bufferA
	ldy	#wipe_full		; line count

.loop	
	lda	ZZaddr+0
	sta.w	0,x
	sta	wipe_full*4,x

	lda	ZZaddr+2
	sta.w	2,x
	sta	wipe_full*4+2,x

	inx
	inx
	inx
	inx
	dey
	bne	.loop
	rts
;-------------------------------------------------------------------


swap_buffer
	lda	gameframe
	lsr	a
	bcs	.bset
;----------------------------------------
; Ａ側へウィンドウデータを書き込む
;----------------------------------------
	lda	#OFFSET	window_bufferA
	bra	.commonset
;----------------------------------------
; Ｂ側へウィンドウデータを書き込む
;----------------------------------------
.bset
	lda	#OFFSET	window_bufferB
.commonset
	ldx	#window_wipe

	sta	ZZaddr
	sta	_window_addressUP,x	; window へのセットアドレス
	clc
	adc	#wipe_half*4		; 真ん中より下のウィンドウ
	sta	_window_addressDW,x

	lda	#7fh
	sta	ZZaddr+2

	rts
;-------------------------------------------------------------------








;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (1)         ***********************************************
;*		***********************************************
;*******************************************************************

;*******************************************************************
;	< close >>
;*******************************************************************
wipe1_close	wipeSEQ 
.process	wipecode clear_wipe1,0
	wipecode init_wipe1X,0
	wipecode main_wipe1,2
	wipecode offswitch,2
	wipecode endofwipe,0
;===================================================================
init_wipe1X
	Msetparam 010h,0a0h,0
	lda	#1
	sta	wipe_counter
	stz	wipe_frame
	nextprocess

;*******************************************************************
;	< open >>
;*******************************************************************
wipe1_open	wipeSEQ 
.process	wipecode clear_wipe1,0
	wipecode init_wipe1,0
	wipecode main_wipe1,2
	wipecode offswitch,2
	wipecode endofwipe,0
;-------------------------------------------------------------------
init_wipe1
	Msetparam 020h,0a0h,0
	lda	#1
	sta	wipe_counter
	stz	wipe_frame
	nextprocess
;-----------------------------------------
maxdata	equ	64
;-----------------------------------------
main_wipe1
	jsr	swap_buffer	; NMI
;-----------------------------------------
	lda	wipe_counter
	cmp	#maxdata
	bcs	.max_stop
;-----------------------------------------
	jsr	calc_r1
       	jsr	calc_r2
       	jsr	calc_r3
       	jsr	calc_r4
	bra	.skip
;-----------------------------------------
.max_stop	jsr	calc_max	; 
;-----------------------------------------
.skip	inc	wipe_counter	; end - check
	bcs_nextprocess maxdata+2
;-----------------------------------------

;*********************************************************************
calc_max

	ldy	#(wipe_full-1)*4
	lda	#0ff00h
.loop	sta	(ZZaddr),y
	dey
	dey
	dey
	dey
	bpl	.loop

	rts

;*********************************************************************
calc_r1
	lda	wipe_counter
	asl	a
	tax
	lda.l	line_data,x
	sta	ZZadd
;- - - - - - - - - - - - - - - - 
	ldy	#wipe_center*4
	ldx	#wipe_half
	stz	ZZtemp
;- - - - - - - - - - - - - - - - 
.loop	lda	ZZtemp
	clc
	adc	ZZadd
	sta	ZZtemp
	eor	#0ffffh
	sec
	adc	#08000h
	bmi	.over
;- - - - - - - - - - - - - - - - 
	xba
	a8
	sta	(ZZaddr),y
	a16
	iny
	iny
	iny
	iny
	dex
	bne	.loop
	rts
;- - - - - - - - - - - - - - - - 
.over	lda	#0
.overloop	a8
	sta	(ZZaddr),y
	a16
	iny
	iny
	iny
	iny
	dex
	bne	.overloop
	rts

;*********************************************************************
calc_r2	lda	#maxdata
	sec
	sbc	wipe_counter
	asl	a
	tax
	lda.l	line_data,x
	sta	ZZadd
;- - - - - - - - - - - - - - - - 
	ldy	#(wipe_center-1)*4+1	; window address
	ldx	#wipe_half		; counter
	stz	ZZtemp
;- - - - - - - - - - - - - - - - 
.loop	lda	ZZtemp
	clc
	adc	ZZadd
	sta	ZZtemp
	eor	#0ffffh
	sec
	adc	#08000h
	bmi	.over
;- - - - - - - - - - - - - - - - 
	xba
	a8
	sta	(ZZaddr),y
	dey
	lda	#0
	sta	(ZZaddr),y
	a16
	dey
	dey
	dey
	dex
	bne	.loop
	rts
;- - - - - - - - - - - - - - - - 
.over	rts

;*********************************************************************
calc_r3
	lda	wipe_counter
	asl	a
	tax
	lda.l	line_data,x
	sta	ZZadd
;- - - - - - - - - - - - - - - - 
	ldy	#(wipe_center-1)*4+3
	ldx	#wipe_half	; counter
	stz	ZZtemp
;- - - - - - - - - - - - - - - - 
.loop	lda	ZZtemp
	clc
	adc	ZZadd
	sta	ZZtemp
	clc
	adc	#08000h
	bpl	.over
;- - - - - - - - - - - - - - - - 
	xba
	a8
	sta	(ZZaddr),y
	a16
	dey
	dey
	dey
	dey
	dex
	bne	.loop
	rts
;- - - - - - - - - - - - - - - - 
.over	lda	#0ffh
.overloop	a8
	sta	(ZZaddr),y
	a16
	dey
	dey
	dey
	dey
	dex
	bne	.overloop
	rts
;*********************************************************************
calc_r4	lda	#maxdata
	sec
	sbc	wipe_counter
	asl	a
	tax
	lda.l	line_data,x
	sta	ZZadd
;- - - - - - - - - - - - - - - - 
	ldy	#wipe_center*4+2 ; window address
	ldx	#wipe_half	 ; counter
	stz	ZZtemp
;- - - - - - - - - - - - - - - - 
.loop	lda	ZZtemp
	clc
	adc	ZZadd
	sta	ZZtemp
	clc
	adc	#08000h
	bpl	.over
;- - - - - - - - - - - - - - - - 
	xba
	a8
	sta	(ZZaddr),y
	iny
	lda	#0ffh
	sta	(ZZaddr),y
	a16
	iny
	iny
	iny
	dex
	bne	.loop
	rts
;- - - - - -  - - - - - - - - - 
.over	rts
;=====================================================================
;***********************************************************************
;	LINE - DATA
;***********************************************************************
line_data
	dw	0,6,13,19
	dw	25,32,38,44
	dw	51,57,64,71
	dw	78,85,92,99
	dw	106,113,121,129
	dw	137,145,153,162
	dw	171,180,190,200
	dw	210,221,232,244
	dw	256,269,282,297
	dw	312,328,345,363
	dw	383,404,427,452
	dw	479,509,541,578
	dw	618,664,715,775
	dw	844,925,1022,1140
	dw	1287,1475,1726,2076
	dw	2599,3470,5211,10428
;-------------------------------------------------------------------



;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (2)         ***********************************************
;*		***********************************************
;*******************************************************************
;*******************************************************************
;	< close >>
;*******************************************************************
wipe2_open
	wipeSEQ
.process
	wipecode clear_wipe1,0
	wipecode init_wipe2,0
	wipecode main_wipe2,2
	wipecode offswitch,2
	wipecode endofwipe,0
;--------------------------------------------------
wipe2_close
	wipeSEQ
.process
	wipecode clear_wipe1,0
	wipecode init_wipe2X,0
	wipecode main_wipe2,2
	wipecode offswitch,2
	wipecode endofwipe,0
;--------------------------------------------------
init_wipe2
	Msetparam 020h,020h,0
	stz	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------
init_wipe2X
	Msetparam 010h,020h,0
	stz	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------

main_wipe2
	jsr	swap_buffer


	ldx	wipe_counter
	cpx	#15
	bcc	.entry
	ldx	#15

.entry	ldy	ZZaddr
.loop	lda	#0ff00h
	jsr	setdata
	dex
	bpl	.loop

	inc	wipe_counter
	bcs_nextprocess 18


setdata	
	sta.w	0,y
	sta.w	12*1*4,y
	sta.w	12*2*4,y
	sta.w	12*3*4,y
	sta.w	12*4*4,y
	sta.w	12*5*4,y
	sta.w	12*6*4,y
	sta.w	12*7*4,y
	sta.w	12*8*4,y
	sta.w	12*9*4,y
	sta.w	12*10*4,y
	sta.w	12*11*4,y
	sta.w	12*12*4,y
	sta.w	12*13*4,y
	sta.w	12*14*4,y
	sta.w	12*15*4,y
	iny
	iny
	iny
	iny
	rts




;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (3)         ***********************************************
;*		***********************************************
;*******************************************************************
;init_wipe4X	Msetparam 010h,0a0h,0
;	lda	#1
;	sta	wipe_counter
;	stz	wipe_frame
;	nextprocess
;-------------------------------------------------------------------
;init_wipe4	
;	Msetparam 020h,0a0h,0
;	lda	#1
;	sta	wipe_counter
;	stz	wipe_frame
;	nextprocess
;-------------------------------------------------------------------
;
;
;
;
;*******************************************************************
;	< close >>
;*******************************************************************
wipe3_close	wipeSEQ
.process
	wipecode clear_wipe1,0
	wipecode init_wipe3X,0
	wipecode main_wipe3,2
	wipecode offswitch,2
	wipecode endofwipe,0
;-----------------------------------------
init_wipe3X
	Msetparam 010h,0a0h,0
	lda	#offset	w3_data
	sta	wipe_index
	stz	wipe_anime	; animation
	stz	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------
;*******************************************************************
;	< open >>
;*******************************************************************
wipe3_open	wipeSEQ
.process
	wipecode clear_wipe1,0
	wipecode init_wipe3,0
	wipecode main_wipe3,2
	wipecode offswitch,2
	wipecode endofwipe,0
;-------------------------------------------------------------------
init_wipe3
	Msetparam 020h,0a0h,0
	lda	#offset	w3_data
	sta	wipe_index
	stz	wipe_anime	; animation
	stz	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------
;*******************************************************************
;	wipe3 main
;*******************************************************************
main_wipe3	
;-------------------------------------------------------------------
;; Set HDMA Paramter
	jsr	swap_buffer

	jsr	anime_window	; windwow anmation

	inc	wipe_counter	;(= frame counter)
	lda	wipe_index
	beq_nextprocess

;===================================================================


;-------------------------------------------------------------------
anime_window

	bankprogset

	lda.l	wipe_index
	tax
	jsr	(0,x)		; program jump
	txa
	sta.l	wipe_index

	jsr	set_window	; double buffer 
				; window parameter set

	bankrts

;-------------------------------------------------------------------
w3_data

	dwcode	win_init
	dw	-0020h,0000h,00ffh,011fh
	dwcode	win_settime
	dw	40

	dwcode	win_limitadd
	dw	4,81h,4,80h
	dw	-4,81h,-4,80h
	dwcode	win_timeloop
	dw	40

	dwcode	win_openadd
	dw	-4,4
	dwcode	win_timeloop
	dw	0

	dwcode	exit_call

;-------------------------------------------------------------------
exit_call	ldx	#0		; end index code
	rts
;-------------------------------------------------------------------
win_init	winstart
	winset_dw  wipe_1L
	winset_dw  wipe_1R
	winset_dw  wipe_2L
	winset_dw  wipe_2R
	winnext
;-------------------------------------------------------------------
win_add	winstart
	winadd_dw  wipe_1L
	winadd_dw  wipe_1R
	winadd_dw  wipe_2L
	winadd_dw  wipe_2R
	winnext
;-------------------------------------------------------------------
win_limitadd	winstart
	winbmiadd_dw  wipe_1L
	winbmiadd_dw  wipe_1R
	winbpladd_dw  wipe_2L
	winbpladd_dw  wipe_2R
	winnext
;-------------------------------------------------------------------
win_openadd	winstart
	winadd_dw  wipe_1L
	winadd_dw  wipe_2R
	winnext
;-------------------------------------------------------------------
win_timeloop	winstart
	lda.l	wipe_timer
	dec	a
	sta.l	wipe_timer
	beq	.exit
	lda.l	wipe_index	; konkai no index he modosu!
	tax
	rts
.exit	winset_dw wipe_timer
	rts
;-------------------------------------------------------------------
win_settime	winstart
	winset_dw wipe_timer
	rts
;-------------------------------------------------------------------
win_exit	winstart
	rts



;----------------------------------------
set_window
	ldx	#wipe_full
	ldy	#0
;----------------------------------------
.loop
	lda.l	wipe_1R		; window 1 right
	bpl	.skip10
	lda	#0
	bra	.skip12
.skip10	bit	#0ff00h
	beq	.skip11
	lda	#00ffh
.skip11	xba
.skip12	sta	ZZtemp

	lda.l	wipe_1L		; window 1 left
	bpl	.skip20
	lda	#0
.skip20	bit	#0ff00h
	beq	.skip21
	lda	#00ffh
.skip21	ora	ZZtemp
	sta	[ZZaddr],y

	iny
	iny

	lda.l	wipe_2R		; window 2 right
	bpl	.skip30
	lda	#0
	bra	.skip32
.skip30	bit	#0ff00h
	beq	.skip31
	lda	#00ffh
.skip31	xba
.skip32	sta	ZZtemp

	lda.l	wipe_2L		; window 2 left
	bpl	.skip40
	lda	#0
.skip40	bit	#0ff00h
	beq	.skip41
	lda	#00ffh
.skip41	ora	ZZtemp
	sta	[ZZaddr],y

	iny
	iny

	dex
	bne	.loop

	rts




;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (4)         ***********************************************
;*		***********************************************
;*******************************************************************
;
;
;
;
;*******************************************************************
;	< close >>
;*******************************************************************
;wipe1_close	wipeSEQ 
;.process	wipecode clear_wipe1,0
;	wipecode init_wipe1X,0
;	wipecode main_wipe1,2
;	wipecode offswitch,2
;	wipecode endofwipe,0
;-------------------------------------------------------------------
;
;
;
;
;
;*******************************************************************
;	< close >>
;*******************************************************************
wipe4_close	wipeSEQ
.process	
	wipecode clear_wipe1,0
	wipecode init_wipe4X,0
	wipecode main_wipe4,2
	wipecode offswitch,2
	wipecode endofwipe,0

;*******************************************************************
;	< open >>
;*******************************************************************
wipe4_open	wipeSEQ
.process	
	wipecode clear_wipe1,0
	wipecode init_wipe4,0
	wipecode main_wipe4,2
	wipecode offswitch,2
	wipecode endofwipe,0

;-------------------------------------------------------------------
init_wipe4X
	Msetparam 010h,0a0h,0
	lda	#1
	sta	wipe_counter
	stz	wipe_frame
	nextprocess

init_wipe4
	Msetparam 020h,0a0h,0
	lda	#1
	sta	wipe_counter
	stz	wipe_frame
	nextprocess

;-------------------------------------------------------------------


;*******************************************************************
;	< open >>
;*******************************************************************
ZZtemp_1L	equ	ZZwork0
ZZtemp_1R	equ	ZZwork1
ZZtemp_2L	equ	ZZwork2
ZZtemp_2R	equ	ZZwork3
ZZtemp_XX	equ	ZZwork4
;-------------------------------------------------------------------
main_wipe4
;-------------------------------------------------------------------
;; Set HDMA Paramter
	jsr	swap_buffer

	jsr	w4_calc1
	jsr	w4_calc2
       	jsr	w4_copy

	inc	wipe_counter	;(= frame counter)
	bcs_nextprocess 200

;-------------------------------------------------------------------

w4_copy

	lda	#191*4
	clc
	adc	ZZaddr
	tay

	lda	#12*4
	clc
	adc	ZZaddr
	tax

	lda	#108-16
	sta	ZZcounter
.loop
	lda.w	0,x
	sta.w	0,y
	lda.w	2,x
	sta.w	2,y
	inx
	inx
	inx
	inx
	dey
	dey
	dey
	dey
	dec	ZZcounter

	bne	.loop
	rts


;*******************************************************
;	calc
;*******************************************************

w4_calc1
	ldy	#0
	lda	#120-16
	sta	ZZcounter

	lda	#0
	sta	ZZtemp_1L
	sta	ZZtemp_2L
	lda	wipe_counter
	asl	a
	asl	a
	sec	
	sbc	#256
	sta	ZZtemp_1R
	sta	ZZtemp_2R

.loop1
	lda	ZZcounter
	and	#01000b
	beq	.skip1
	jsr	set_w4		; windwow anmation
	bra	.skip2
.skip1	iny
	iny
	iny
	iny

.skip2
	lda	ZZtemp_1R
	clc
	adc	#2
	sta	ZZtemp_1R
	sta	ZZtemp_2R

	dec	ZZcounter
	bne	.loop1

	rts

;------------------------------------------------------
w4_calc2
	ldy	#0
	lda	#120-16
	sta	ZZcounter


	lda	#0ffh
	sta	ZZtemp_1R
	sta	ZZtemp_2R
	lda	#64-1
	sec
	sbc	wipe_counter
	asl	a
	asl	a
	clc
	adc	#256
	sta	ZZtemp_1L
	sta	ZZtemp_2L

.loop2	

	lda	ZZcounter
	and	#01000b
	bne	.skip1
	jsr	set_w4		; windwow anmation
	bra	.skip2
.skip1	iny
	iny
	iny
	iny

.skip2
	lda	ZZtemp_1L
	sec
	sbc	#2
	sta	ZZtemp_1L
	sta	ZZtemp_2L

	dec	ZZcounter
	bne	.loop2

	rts
;------------------------------------------------------

;*******************************************************
;	1 line window set
;*******************************************************

set_w4
;----------------------------------------
.loop
	lda	ZZtemp_1R		; window 1 right
	bpl	.skip10
	lda	#0
	bra	.skip12
.skip10	bit	#0ff00h
	beq	.skip11
	lda	#00ffh
.skip11	xba
.skip12	sta	ZZtemp

	lda	ZZtemp_1L		; window 1 left
	bpl	.skip20
	lda	#0
.skip20	bit	#0ff00h
	beq	.skip21
	lda	#00ffh
.skip21	ora	ZZtemp
	beq	.skip22
	cmp	#0ffffh
	bne	.skip23
.skip22	lda	#0001h
.skip23	sta	[ZZaddr],y

	iny
	iny

	lda	ZZtemp_2R		; window 2 right
	bpl	.skip30
	lda	#0
	bra	.skip32
.skip30	bit	#0ff00h
	beq	.skip31
	lda	#00ffh
.skip31	xba
.skip32	sta	ZZtemp

	lda	ZZtemp_2L		; window 2 left
	bpl	.skip40
	lda	#0
.skip40	bit	#0ff00h
	beq	.skip41
	lda	#00ffh
.skip41	ora	ZZtemp
	beq	.skip42
	cmp	#0ffffh
	bne	.skip43
.skip42	lda	#0001h
.skip43	sta	[ZZaddr],y
	iny
	iny

	rts


;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (5)         ***********************************************
;*		***********************************************
;*******************************************************************
;*******************************************************************
;	< close >>
;*******************************************************************
wipe5_close	wipeSEQ
.process	
	wipecode clear_wipe1,0
	wipecode init_wipe5X,0
	wipecode main_wipe5,2
	wipecode offswitch,2
	wipecode endofwipe,0
init_wipe5X	
	Msetparam 010h,0a0h,0
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------
;*******************************************************************
;	< open >>
;*******************************************************************
wipe5_open	wipeSEQ
.process	
	wipecode clear_wipe1,0
	wipecode init_wipe5,0
	wipecode main_wipe5,2
	wipecode offswitch,2
	wipecode endofwipe,0
;-------------------------------------------------------------------
init_wipe5	
	Msetparam 020h,0a0h,0
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------
;*******************************************************************
;	< open >>
;*******************************************************************

main_wipe5	

	jsr	swap_buffer

	jsr	w5_calc1

	inc	wipe_counter	;(= frame counter)

	bcs_nextprocess 68

;===================================================================
;*******************************************************************
;	< open >>
;*******************************************************************


w5_calc1

	ldy	#0
	lda	#wipe_full
	sta	ZZcounter

	lda	wipe_counter
	asl	a
	asl	a
	asl	a
	adc	#-192
	sta	ZZtemp_1R

	lda	wipe_counter
	eor	#0ffffh
	inc	a
	asl	a
	asl	a
	asl	a
	clc
	adc	#256
	sta	ZZtemp_2L

	lda	#0
	sta	ZZtemp_1L
	
	lda	#00e0h
	sta	ZZtemp_XX

	lda	#00ffh
	sta	ZZtemp_2R

.loop1

	jsr	set_w5		; windwow anmation

	dec	ZZtemp_XX
	inc	ZZtemp_1R
	inc	ZZtemp_2L

	dec	ZZcounter
	bne	.loop1

	rts

;*******************************************************
;	1 line window set
;*******************************************************

set_w5
;----------------------------------------
.loop
	lda	ZZtemp_1R		; window 1 right
	bpl	.skip10
	lda	#0
	bra	.skip12
.skip10	
	cmp	ZZtemp_XX
	bmi	.skip11
	lda	ZZtemp_XX
	bra	.skip11

.skip19	lda	#00ffh
.skip11	xba
.skip12	sta	ZZtemp



	lda	ZZtemp_1L		; window 1 left
	bpl	.skip20
	lda	#0
.skip20	bit	#0ff00h
	beq	.skip21
	lda	#00ffh
.skip21	ora	ZZtemp
	bne	.skip2000
	lda	#00001h		; = clear window line
.skip2000	sta	[ZZaddr],y
	iny
	iny


	lda	ZZtemp_2R		; window 2 right
	bpl	.skip30
	lda	#0
	bra	.skip32
.skip30	bit	#0ff00h
	beq	.skip31
	lda	#000ffh
.skip31	xba
.skip32	sta	ZZtemp

	lda	ZZtemp_2L		; window 2 left
	bmi	.skip40
	bit	#0ff00h
	bne	.skip49
.skip40	cmp	ZZtemp_XX
	bpl	.skip41
	lda	ZZtemp_XX
	bra	.skip41

.skip49	lda	#00ffh
.skip41	ora	ZZtemp
	cmp	#0ffffh
	bne	.skip4000
	lda	#0001h		; = clear window line
.skip4000	sta	[ZZaddr],y
	iny
	iny

	rts

;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (6)         ***********************************************
;*		***********************************************
;*******************************************************************

;*******************************************************************
;	< close >>
;*******************************************************************
wipe6_close	wipeSEQ
.process	
	wipecode clear_wipe1,0
	wipecode init_wipe6X,0
	wipecode main_wipe6,2
	wipecode offswitch,2
	wipecode endofwipe,0
;-------------------------------------------------------------------
init_wipe6X
	Msetparam 010h,0a0h,0
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;*******************************************************************
;	< open >>
;*******************************************************************
wipe6_open	wipeSEQ
.process
	wipecode clear_wipe1,0
	wipecode init_wipe6,0
	wipecode main_wipe6,2
	wipecode offswitch,2
	wipecode endofwipe,0

;-------------------------------------------------------------------
init_wipe6
	Msetparam 020h,0a0h,0
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-------------------------------------------------------------------
;*******************************************************************
;	< open >>
;*******************************************************************
main_wipe6
;-------------------------------------------------------------------

	jsr	swap_buffer

	jsr	w6_calc1
	jsr	w6_copy1
	jsr	w6_copy2

	inc	wipe_counter	;(= frame counter)

	bcs_nextprocess 100

;-------------------------------------------------------------------

;*******************************************************
;	calc
;*******************************************************


w6_copy2	
	ldx	ZZaddr
	lda	#wipe_half
	sta	ZZcounter

.loop

	lda.w	0,x
	xba
	and	#000ffh
	eor	#000ffh
	ora	#0ff00h
	sta	wipe_center*4,x

	lda.w	2,x
	xba	
	and	#000ffh
	eor	#000ffh
	ora	#0ff00h
	sta	wipe_center*4+2,x


	inx
	inx
	inx
	inx
	dec	ZZcounter

	bne	.loop

	rts



;-------------------------------------------------------------------
w6_copy1

	lda	#(wipe_center-1)*4
	clc
	adc	ZZaddr
	tay
	ldx	ZZaddr

	lda	#wipe_half/2
	sta	ZZcounter
.loop
	lda.w	0,x
	sta.w	0,y
	lda.w	2,x
	sta.w	2,y
	inx
	inx
	inx
	inx
	dey
	dey
	dey
	dey
	dec	ZZcounter

	bne	.loop

	rts

;-------------------------------------------------------------------
w6_calc1

	ldy	#0
	lda	#wipe_half/2
	sta	ZZcounter

	lda	#0
	sta	ZZtemp_1L
	sta	ZZtemp_2L

	lda	wipe_counter
	asl	a
	asl	a
	asl	a
	adc	#-256
	sta	ZZtemp_1R
	sta	ZZtemp_2R

.loop1	
	jsr	set_w4

	lda	ZZtemp_1R
	clc
	adc	#4
	sta	ZZtemp_1R
	sta	ZZtemp_2R

	dec	ZZcounter
	bne	.loop1

	rts



;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (7)         ***********************************************
;*		***********************************************
;*******************************************************************
;*******************************************************************
;	< close >>
;*******************************************************************
wipe7_close	wipeSEQ
.process	wipecode clear_wipe7,0
	wipecode init2_wipe7,0
	wipecode main2_wipe7,2
	wipecode offswitch,2
	wipecode endofwipe,0
;==============================================
clear_wipe7
	lda	#0ff00h
	jsr	wipe_clear
	nextprocess
;-------------------------------------------------------------------
init2_wipe7
	Msetparam2 00fh,0
	lda	#2
	sta	wipe_counter
	stz	wipe_frame
	nextprocess
;==============================================

;*******************************************************************
main2_wipe7	

	jsr	swap_buffer
	
	jsr	w72_calc
	jsr	w72_copy

	inc	wipe_counter	;(= frame counter)
	bcs_nextprocess 160/8

;-------------------------------------------------------------------

w72_copy

	ldx	ZZaddr
	ldy	#wipe_full*4+2
.loop	lda.w	0,x
	sta	(ZZaddr),y
	inx
	inx
	inx
	inx
	dey
	dey
	dey
	dey
	bpl	.loop

	rts

;-----------------------------------------------


w72_calc


	lda	#80h		; brank set
	sta	ZZtemp_1L
	lda	#7fh
	sta	ZZtemp_1R

	lda	#-30		; start raster
	sta	ZZcounter
	ldy	#0		; buffer pointer


.loop
	lda	ZZcounter
	bmi	.skip
	jsr	set_w7
.skip
	jsr	set1

	lda	ZZcounter
	inc	a
	sta	ZZcounter
	cmp	#wipe_full
	bne	.loop

	rts





;*******************************************************************





set_w7
;----------------------------------------
.loop
	lda	ZZtemp_1R		; window 1 right
	bpl	.skip10
	lda	#0
	bra	.skip12
.skip10	bit	#0ff00h
	beq	.skip11
	lda	#00ffh
.skip11	xba
.skip12	sta	ZZtemp

	lda	ZZtemp_1L		; window 1 left
	bpl	.skip20
	lda	#0
.skip20	bit	#0ff00h
	beq	.skip21
	lda	#00ffh
.skip21	ora	ZZtemp
	sta	[ZZaddr],y

	iny
	iny
	iny
	iny

	rts

;----------------------------------------
set1
	lda	wipe_counter
	asl	a
	asl	a
	asl	a
	adc	#-30
	cmp	ZZcounter
	bpl	.skip

	lda	ZZtemp_1L
	sec
	sbc	#4
	sta	ZZtemp_1L

	lda	ZZtemp_1R
	clc
	adc	#4
	sta	ZZtemp_1R

.skip
	rts



;*******************************************************************
;	< open >>
;*******************************************************************
wipe7_open	wipeSEQ
.process	wipecode clear_wipe1,0
	wipecode init_wipe7,0
	wipecode main_wipe7,2
	wipecode offswitch,2
	wipecode endofwipe,0
;==============================================
init_wipe7
	Msetparam2 0fh,0
	lda	#2
	sta	wipe_counter
	stz	wipe_frame
	nextprocess
;==============================================


;*******************************************************************
;	< open >>
;*******************************************************************
main_wipe7
;-------------------------------------------------------------------
;; Set HDMA Paramter

	jsr	swap_buffer
	
	jsr	w7_calc1
	jsr	w7_copy

	inc	wipe_counter	;(= frame counter)
	bcs_nextprocess 220/8

;-------------------------------------------------------------------


;*******************************************************
;	calc
;*******************************************************

w7_copy

	lda	#wipe_half
	sta	ZZcounter

	ldx	ZZaddr
	lda	ZZaddr
	clc
	adc	#(wipe_full-1)*4
	tay

.loop	lda.w	0,x
	sta.w	0,y
	lda.w	2,x
	sta.w	2,y

	inx
	inx
	inx
	inx
	dey
	dey
	dey
	dey

	dec	ZZcounter
	bne	.loop


	rts


w7_calc1


	lda	#wipe_half
	sta	ZZcounter
	ldy	#0


	lda	wipe_counter
	asl	a
	asl	a
	asl	a
	eor	#0ffffh
	inc	a
	clc
	adc	#188
	sta	ZZtemp_1L

	lda	wipe_counter
	asl	a
	asl	a
	asl	a
	clc
	adc	#68
	sta	ZZtemp_2R

	lda	#00ffh
	sta	ZZtemp_1R
	lda	#0
	sta	ZZtemp_2L

;------------------------------------------
.loop

	jsr	set_w4

	lda	ZZcounter
	lsr	a
	bcc	.skip
	dec	ZZtemp_1L
	inc	ZZtemp_2R

.skip
;------------------------------------------

	dec	ZZcounter
	bne	.loop

	rts






;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (8)         ***********************************************
;*		***********************************************
;*******************************************************************
;*******************************************************************
;	< close >>
;*******************************************************************
wipe8_close
	wipeSEQ
.process
	wipecode clear_wipeX4,0
	wipecode init_wipeX4,0
	wipecode main_wipeX4,2
	wipecode offswitch,2
	wipecode endofwipe,0
;--------------------------------------------------
clear_wipeX4
	ldy	#07f80h
	lda	#0ff00h
	jsr	wipe_clear2
	nextprocess
	rts
;--------------------------------------------------
init_wipeX4
	Msetparam2 3,0
	lda	#40
	sta	wipe_work
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------

;*******************************************************************
;	< open >>
;*******************************************************************
wipe8_open	wipeSEQ
.process
	wipecode clear_wipe1,0
	wipecode init_wipeX3,0
	wipecode main_wipeX3,2
	wipecode offswitch,2
	wipecode endofwipe,0
;--------------------------------------------------
init_wipeX3
	Msetparam2 3,0
	lda	#40
	sta	wipe_work
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------


;*******************************************************************
;	< open >>
;*******************************************************************
main_wipeX3
;-------------------------------------------------------------------
	jsr	swap_buffer

	lda	wipe_counter
	asl	a
	sec
	sbc	#10
	sta	ZZtemp_1L

	lda	#wipe_full
	sta	ZZcounter

	ldx	#0800h
	ldy	#0
	jsr	setcall


	inc	wipe_counter	;(= frame counter)
	bcs_nextprocess 200/2

	

;-------------------------------------------------------------------

;*******************************************************************
;	< open >>
;*******************************************************************
main_wipeX4
;-------------------------------------------------------------------
	jsr	swap_buffer

	lda	wipe_counter
	asl	a
	eor	#0ffffh
	clc
	adc	#200-10
	sta	ZZtemp_1L


	lda	#wipe_full
	sta	ZZcounter

	ldx	#800h
	ldy	#0
	jsr	setcall


	inc	wipe_counter	;(= frame counter)
	bcs_nextprocess 200/2


;-------------------------------------------------------------------




;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (9)         ***********************************************
;*		***********************************************
;*******************************************************************
;*******************************************************************
;	< close >>
;*******************************************************************

Xwindow_data
	include	wp1.dat
	include	wp2.dat
	include	wp3.dat

;*******************************************************************
;	< close >>
;*******************************************************************
wipe9_close
wipeX_close	wipeSEQ
.process
	wipecode clear_wipeX4,0
	wipecode init_wipeX2,0
	wipecode main_wipeX2,2
	wipecode offswitch,2
	wipecode endofwipe,0
;-----------------------------------------
init_wipeX2
	Msetparam2 01011b,0
	lda	#40
	sta	wipe_work
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------

;*******************************************************************
;	< open >>
;*******************************************************************
wipeX_open
wipe9_open	wipeSEQ
.process
	wipecode clear_wipe1,0
	wipecode init_wipeX,0
	wipecode main_wipeX,2
	wipecode offswitch,2
	wipecode endofwipe,0
;--------------------------------------------------
init_wipeX
	Msetparam2 01011b,0
	lda	#40
	sta	wipe_work
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------

;*******************************************************************
;	< open >>
;*******************************************************************
main_wipeX
;-------------------------------------------------------------------
	jsr	swap_buffer

	lda	wipe_counter
	asl	a
	sec
	sbc	#60
	sta	ZZtemp_1L

	lda	#wipe_full
	sta	ZZcounter

	ldx	#0
	ldy	#0
	jsr	setcall

	lda	wipe_counter
	cmp	#60/2
	bne	.skipa
	dec	wipe_work
	bne	.skipb

.skipa	inc	wipe_counter	;(= frame counter)

.skipb
	bcs_nextprocess 200/2


;-------------------------------------------------------------------

;*******************************************************************
;	< open >>
;*******************************************************************
main_wipeX2
;-------------------------------------------------------------------
	jsr	swap_buffer
	
	lda	wipe_counter
	asl	a
	eor	#0ffffh
	clc
	adc	#200-60
	sta	ZZtemp_1L


	lda	#wipe_full
	sta	ZZcounter

	ldx	#0
	ldy	#0
	jsr	setcall

	lda	wipe_counter
	cmp	#(200-58)/2
	bne	.skipa
	dec	wipe_work
	bne	.skipb

.skipa	inc	wipe_counter	;(= frame counter)

.skipb	
	bcs_nextprocess 200/2


;-------------------------------------------------------------------







;********************************************************************
;
;********************************************************************

setcall
;============================================
.loop	
	
	lda.l	Xwindow_data+0,x	; Window1 Left
	and	#00ffh
	sec	
	sbc	ZZtemp_1L
	bpl	.skip1
	lda	#00000h
	bra	.set1
.skip1	bit	#0ff00h
	beq	.set1
	lda	#000ffh
.set1	sta	ZZtemp

	lda.l	Xwindow_data+1,x	; Window1 Right 
	and	#00ffh
	clc
	adc	ZZtemp_1L
	bpl	.skip2
	lda	#00000h
	bra	.set2
.skip2	bit	#0ff00h
	beq	.set2
	lda	#000ffh
.set2	xba
	ora	ZZtemp
	sta	(ZZaddr),y
	iny
	iny
	inx
	inx


	lda.l	Xwindow_data+0,x	; Window1 Left
	and	#00ffh
	clc	
	adc	ZZtemp_1L
	bpl	.skip3
	lda	#00000h
	bra	.set3
.skip3	bit	#0ff00h
	beq	.set3
	lda	#000ffh
.set3	sta	ZZtemp

	lda.l	Xwindow_data+1,x	; Window1 Right 
	and	#00ffh
	clc
	adc	ZZtemp_1L
	bpl	.skip4
	lda	#00000h
	bra	.set4
.skip4	bit	#0ff00h
	beq	.set4
	lda	#000ffh
.set4	xba
	ora	ZZtemp
	sta	(ZZaddr),y
	iny
	iny
	inx
	inx

	dec	ZZcounter
	bne	.loop

;============================================

	rts





;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (10)        ***********************************************
;*		***********************************************
;*******************************************************************
;*******************************************************************
;	< close >>
;*******************************************************************
wipe10_close	wipeSEQ
.process	
	wipecode clear_wipe10X,0
	wipecode init_wipe10X,0
	wipecode main_wipe10X,2
	wipecode offswitch,2
	wipecode endofwipe,0
;--------------------------------------------------
clear_wipe10X
	lda	#00100h
	ldy	#0ff00h
	jsr	wipe_clear2
	nextprocess
;--------------------------------------------------
init_wipe10X
	Msetparam 010h,0e0h,0
	lda	#40
	sta	wipe_work
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------


;*******************************************************************
;	< open >>
;*******************************************************************
wipe10_open	wipeSEQ
.process	
	wipecode clear_wipe1,0
	wipecode init_wipe10,0
	wipecode main_wipe10,2
	wipecode offswitch,2
	wipecode endofwipe,0
;--------------------------------------------------
init_wipe10

	Msetparam 010h,0e0h,0
	lda	#40
	sta	wipe_work
	lda	#1
	sta	wipe_counter
	inc	wipe_process	; next process
	stz	wipe_frame
	rts
;-----------------------------------------



;*******************************************************************
;	< open >>
;*******************************************************************
main_wipe10
;-------------------------------------------------------------------
	jsr	swap_buffer
;-------------------------------------------------------------------

	lda	#0
	sta	ZZtemp_1L
	lda	#wipe_full
	sta	ZZcounter

	lda	wipe_counter
	asl	a
	asl	a
	asl	a
	clc
	adc	#400h
	tax
	ldy	#0
	jsr	setcall2

	lda	#wipe_full
	sta	ZZcounter
	lda	#0
	sta	ZZtemp_1L

	lda	wipe_counter
	eor	#0ffffh
	inc	a
	asl	a
	asl	a
	asl	a
	clc
	adc	#400h
	tax
	ldy	#2
	jsr	setcall2

	inc	wipe_counter
	bcs_nextprocess 160/2


;-------------------------------------------------------------------

;*******************************************************************
;	< close >>
;*******************************************************************
main_wipe10X
;-------------------------------------------------------------------
	jsr	swap_buffer

	lda	#wipe_full
	sta	ZZcounter
	lda	#0
	sta	ZZtemp_1L

	lda	wipe_counter
	eor	#0ffffh
	inc	a
	asl	a
	asl	a
	asl	a
	clc
	adc	#(1024+160*4-4)
	tax
	ldy	#0
	jsr	setcall2

	lda	#wipe_full
	sta	ZZcounter
	lda	#0
	sta	ZZtemp_1L

	lda	wipe_counter
	asl	a
	asl	a
	asl	a
	clc
	adc	#(1024-160*4-4)
	tax
	ldy	#2
	jsr	setcall2

	inc	wipe_counter	;(= frame counter)
	bcs_nextprocess 164/2


;-------------------------------------------------------------------


;********************************************************************
;
;********************************************************************

setcall2
;============================================
.loop

	cpx	#400h
	bpl	.skip
	lda	#0ff00h
	bra	.skip2

.skip	lda.l	Xwindow_data,x
.skip2	sta	(ZZaddr),y

	iny
	iny
	inx
	inx
	iny
	iny
	inx
	inx

	cpx	#800h
	bmi	.next
	ldx	#7feh

.next	dec	ZZcounter
	bne	.loop

	rts


;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (11)        ***********************************************
;*		***********************************************
;*******************************************************************

;*******************************************************************
;	< close >>
;*******************************************************************
wipe11_close	wipeSEQ 
.process	
	wipecode clear_wipe11,0
	wipecode init_wipe11,0
	wipecode main_wipe11C,2
	wipecode offswitch,2
	wipecode endofwipe,0
;-------------------------------------------------------------------
clear_wipe11
	lda	#0ff00h
	jsr	wipe_clear
	nextprocess
;-------------------------------------------------------------------
main_wipe11C
	jsr	swap_buffer

	lda	#48
	sec
	sbc	wipe_counter
	beq	over_wipe11
	bmi	over_wipe11
	asl	a
	asl	a
	sta	ZZspeed

	jsr	calc11_1
	jsr	copy11_1

	inc	wipe_counter
	bcs_nextprocess	48+2
;-------------------------------------------------------------------
over_wipe11
;-------------------------------------------------------------------
	ldy	#192		; line
	ldx	ZZaddr
	lda	#7f80h
.loop	sta.w	0,x
	sta.w	2,x
	inx
	inx
	inx
	inx
	dey
	bne	.loop
	inc	wipe_counter
	bcs_nextprocess	48+2
;-------------------------------------------------------------------

;*******************************************************************
;	< open >>
;*******************************************************************
wipe11_open	wipeSEQ 
.process	
	wipecode clear_wipe1,0
	wipecode init_wipe11,0
	wipecode main_wipe11,2
	wipecode offswitch,2
	wipecode endofwipe,0
;-------------------------------------------------------------------
init_wipe11
	Msetparam 020h,0a0h,00
	lda	#0
	sta	wipe_counter
	stz	wipe_frame
	nextprocess
;-------------------------------------------------------------------
main_wipe11
	jsr	swap_buffer

	lda	wipe_counter
	asl	a
	asl	a
	sta	ZZspeed

	jsr	calc11_1
	jsr	copy11_1

	inc	wipe_counter
	bcs_nextprocess	48
;-------------------------------------------------------------------
ZZspeed	equ	ZZwork7	
;-------------------------------------------------------------------

copy11_1

	lda	#192
	sta	ZZcounter

	ldx	ZZaddr
	txy
	a8
.loop
	lda.w	191*4+1,y	; window(1) right
	sta.w	3,x
	eor	#0ffh
	inc	a
	sta.w	0,x		; window(1) left
	sta.w	191*4+2,y
	dey
	dey
	dey
	dey
	inx
	inx
	inx
	inx
	dec	ZZcounter
	bne	.loop
	a16
	rts
;-------------------------------------------------------------------
calc11_1

	lda	#224*256	; ********.00000000
	sta.l	4204h
	a8
	lda	#192		; ********.
	sec
	sbc	ZZspeed
	sta.l	4206h
	a16
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	lda.l	4214h
	sta	ZZadd		; ********.********


	lda	#0f000h
	sta	ZZtemp

	lda	ZZspeed
	asl	a
	asl	a
	adc	ZZaddr
	tax


	ldx	ZZaddr		; address
	ldy	ZZspeed	; speed ( counter )
	beq	.skip

.loop1	a8
	lda	#0f0h
	sta.w	1,x	; window(1) right
	a16
	inx
	inx
	inx
	inx
	dey
	bne	.loop1

.skip
	lda	#192
	sec
	sbc	ZZspeed
	sta	ZZcounter
	beq	.exit

.loop
	a8
	lda	ZZtemp+1
	sta.w	1,x	; window(1) left
	a16

	sec
	lda	ZZtemp
	sbc	ZZadd
	sta	ZZtemp

	inx
	inx
	inx
	inx

	dec	ZZcounter
	bne	.loop

.exit	rts




;===================================================================
;===================================================================
;===================================================================
;*******************************************************************
;*		***********************************************
;*  WIPE (12)        ***********************************************
;*		***********************************************
;*******************************************************************
work1		equ	ZZwork1
work2		equ	ZZwork2
line_counter	equ	ZZwork3
Ndata		equ	ZZwork4
;-------------------------------
product		equ	ZZwork5
multiplier	equ	ZZwork6
;-------------------------------
add_add		equ	ZZwork7
;-------------------------------
;- - - - - - - - - - - - - - - 
XProduct	equ	4216h
XMultiplicand	equ	4202h
XMultiplier	equ	4203h
;--------------------------------------------------------------------

;*******************************************************************
;	< close >>
;*******************************************************************
wipe12_open	wipeSEQ 
.process	wipecode clear_wipe1,0
		wipecode init_wipe12,0
		wipecode main_wipe12,2
		wipecode offswitch,2
		wipecode endofwipe,0
;-------------------------------------------------------------------
wipe12_close	wipeSEQ
.process	wipecode clear_wipe1,0
		wipecode init_wipe12,0
		wipecode main_wipe12X,2
		wipecode offswitch,2
		wipecode endofwipe,0
;-------------------------------------------------------------------
init_wipe12
	Msetparam 020h,0a0h,00
	lda	#2
	sta	wipe_counter
	stz	wipe_frame
	nextprocess
;-------------------------------------------------------------------
main_wipe12X
	jsr	swap_buffer
	lda	wipe_counter
	eor	#0ffffh
	inc	a
	clc
	adc	#27+2
	asl	a
	asl	a
	bra	common_call
;-------------------------------------------------------------------
main_wipe12
	jsr	swap_buffer
;- - - - - - - - - - - - - - - - - - - - - - - - -
; all clear = window
;- - - - - - - - - - - - - - - - - - - - - - - - -
;	ldy	#191*4+2
;	lda	#00001h
;.loop	sta	(addr),y
;	dey
;	dey
;	bpl	.loop
;	bra	.next
;- - - - - - - - - - - - - - - - - - - - - - - - -
; parameter
;- - - - - - - - - - - - - - - - - - - - - - - - -
	lda	wipe_counter
	asl	a
	asl	a
common_call
	sta	zoom_data
	lda	#96
	sta	Vcenter
	lda	#128
	sta	Hcenter
;- - - - - - - - - - - - - - - - - - - - - - - - -
; program
;- - - - - - - - - - - - - - - - - - - - - - - - -
	jsr	calc_entry
	inc	wipe_counter
	bcs_nextprocess	28

	rts
;-------------------------------------------------------------------
MAXCOUNT	equ	36	; kaiten kakudo 36 bunkatsu
;-------------------------------------------------------------------
calc_entry

;--------------------------------------------------------
	stz	wipe_switch
	lda	rotate_data
	sta	rotate_IDX
	asl	a
	tax
	jsr	(Xprocess,x)	; angle 0 - 360
;--------------------------------------------------------
	lda	#2
	sta	wipe_switch
	lda	rotate_data
	clc
	adc	#MAXCOUNT/2
	cmp	#MAXCOUNT
	bcc	.skip100	; sec
	sbc	#MAXCOUNT
.skip100
	sta	rotate_IDX
	asl	a
	tax
	jsr	(Xprocess,x)
;--------------------------------------------------------
.next
	lda	rotate_data
	inc	a
	inc	a
	inc	a
	cmp	#MAXCOUNT
	bcc	.exit
	sbc	#MAXCOUNT
.exit	sta	rotate_data
;--------------------------------------------------------
;;	ldy	#223*4+2	; all clear
;;.loop2
;;	lda	(addr),y
;;	bne	.s1
;;	inc	a
;;	sta	(addr),y
;;	bra	.ss
;;.s1	inc	a
;;	bne	.ss
;;	inc	a
;;	sta	(addr),y
;;.ss	dey
;;	dey
;;	bpl	.loop2
;--------------------------------------------------------
	rts

;=========================================================
Xprocess
	dw	calc1,calc1,calc1,calc1,calc1,calc1,calc1,calc1,calc1
	dw	calc1,calc1,calc1,calc1,calc1,calc1,calc1,calc1,calc1
	dw	calc2,calc3,calc3,calc3,calc3,calc3,calc3,calc3,calc3
	dw	calc3,calc3,calc3,calc3,calc3,calc3,calc3,calc3,calc3
;=========================================================
;*********************************************************************
;	angle ( 90 or 270 ) line calc
;*********************************************************************
dataopen   equ	0ff00h
dataclose  equ	00001h
;- - - - - - - - - - - - - - - - -
calc2
;- - - - - - - - - - - - - - - - -
	lda	#0	; window pointer reset
	clc
	adc	wipe_switch
	tay
	ldx	#192	; max line
;- - - - - - - - - - - - - - - - -
	lda	Vcenter
	sec
	sbc	zoom_data
	bpl	nomal_open
;- - - - - - - - - - - - - - - - -
special_open
;-----------------------------
	ldx	Vcenter
	lda	#dataopen
	jsr	set_call
;-----------------------------
	ldx	zoom_data
	lda	#dataopen
	jsr	set_call
;-----------------------------
	lda	#192
	sec
	sbc	Vcenter
	sec
	sbc	zoom_data
	bmi	.skip2
	tax
	lda	#dataclose
	jsr	set_call
.skip2	rts
;-----------------------------
;- - - - - - - - - - - - - - - - -
nomal_open
;-----------------------------
	tax
	lda	#dataclose
	jsr	set_call
;-----------------------------
	lda	zoom_data
	asl	a
	tax
	lda	#dataopen
	jsr	set_call
;-----------------------------
	ldx	#0192
	lda	#dataclose
	jsr	set_call
;-----------------------------
	rts

;---------------------------------------------------------------------
;	set call
;---------------------------------------------------------------------

;- - - - - - - - - - - - - - - - - -
set_call
	cpx	#0
	beq	.exit
.loop	sta	(ZZaddr),y
	iny
	iny
	iny
	iny
	cpy	#192*4		; < line limit >>
	bcs	.exit
	dex			; < counter >>
	bne	.loop
	rts

.exit	pla	; <
	rts
;- - - - - - - - - - - - - - - - - -


;---------------------------------------------------------------------
;	Set Window Data
;---------------------------------------------------------------------
full_close
	lda	#0001h
	bra	loop100
full_open
;- - - - - - - - - - - - - - - - - - - - - - - - - - - -
	lda	#0ff00h
loop100
	sta	(ZZaddr),y		
	iny
	iny
	iny
	iny
	dex
	bne	loop100
;- - - - - - - - - - - - - - - - - - - - - - - - - - - -
	rts






;*********************************************************************
;*********************************************************************









;*********************************************************************
Set_Parameter
;================================
	bmi	.clear
	bit	#0ff00h
	bne	.over
	a8
	sta	[ZZaddr],y
	a16
	rts
;================================
.clear
	a8
	lda	#0
	sta	[ZZaddr],y
	a16
	rts
;================================
.over
	a8
	lda	#0ffh
	sta	[ZZaddr],y
	a16
	rts
;=====================================================================

;********************************************************************
;	zoom line calc
;********************************************************************
angle_list
	dw	0
	dw	22
	dw	45
	dw	68
	dw	93
	dw	119
	dw	147
	dw	179
	dw	214
	dw	255
	dw	305
	dw	365
	dw	443
	dw	548
	dw	703
	dw	955
	dw	1451
	dw	2926
;--------------------------------------------------------------------
calc1
;- - - - - - - - - - - - - - - - - - - - - - - -
; DATABANK = PROGRAM BANK
;- - - - - - - - - - - - - - - - - - - - - - - -
	phb
	phk
	plb
;- - - - - - - - - - - - - - - - - - - - - - - -
	lda.l	rotate_IDX
	asl	a
	tax
	ldy	asin_table,x
	lda.l	zoom_data	; (000 - 127 )
	asl	a
	asl	a
	asl	a
	asl	a
	asl	a
	asl	a
	jsr	ML_s16s16
	sta	Ndata		; Y=0 / answer X
;- - - - - - - - - - - - - - - - - - - - - - - -
	clc
	adc.l	Hcenter
	sta	work1		; X line right
	lda.l	Hcenter
	sec
	sbc	Ndata
	sta	work2		; X line left
;- - - - - - - - - - - - - - - - - - - - - - - -

;- - - - - - - - - - - - - - - - - - - - - - - -
	lda.l	rotate_IDX
	asl	a
	tax
	lda	angle_list,x
	sta	add_add
	lda	#0
	sta.l	add_total+0
	sta.l	add_total+2
;- - - - - - - - - - - - - - - - - - - - - - - -

	lda.l	Vcenter	; 111*4+1
	dec	a
	asl	a
	asl	a
	inc	a

	clc
	adc.l	wipe_switch
	tay
;- - - - - - - - - - - - - - - - - - - - - - - -	
	lda.l	Vcenter
	sta	line_counter
;- - - - - - - - - - - - - - - - - - - - - - - -	
.loop
	lda.l	add_total+1
	clc
	adc	work1
	jsr	Set_Parameter	; set right 
	dey
	lda.l	add_total+1
	clc
	adc	work2
	jsr	Set_Parameter	; set left
	dey
	dey
	dey

	lda.l	add_total+0
	clc
	adc	add_add
	sta.l	add_total+0
	lda	#0
	adc.l	add_total+2
	sta.l	add_total+2

	dec	line_counter
	bne	.loop

;- - - - - - - - - - - - - - - - - - - - - - - -

	lda.l	Vcenter
	asl	a
	asl	a

	clc
	adc.l	wipe_switch
	tay

	lda	#192
	sec
	sbc.l	Vcenter
	sta	line_counter

	lda	#0
	sta.l	add_total+0
	sta.l	add_total+2
;- - - - - - - - - - - - - - - - - - - - - - - -


.loop2	
	lda	work2
	sec
	sbc.l	add_total+1
	jsr	Set_Parameter	; set left 
	iny
	lda	work1
	sec
	sbc.l	add_total+1
	jsr	Set_Parameter	; set right
	iny
	iny
	iny

	lda.l	add_total+0
	clc
	adc	add_add
	sta.l	add_total+0
	lda	#0
	adc.l	add_total+2
	sta.l	add_total+2

	dec	line_counter
	bne	.loop2


	plb
	rts

;- - - - - - - - - - - - - - - - - - - - - - - -
asin_table
	dw	400h,403h,40fh,424h
	dw	441h,469h,49eh,4e2h
	dw	538h,5a8h,639h,6f9h
	dw	800h,976h,0bb1h,0f74h
	dw	1708h,2de5h


;********************************************************************
;	zoom line calc
;********************************************************************
calc3
;- - - - - - - - - - - - - - - - - - - - - - - -
	phb
	phk
	plb
;- - - - - - - - - - - - - - - - - - - - - - - -
	lda	#MAXCOUNT	; = max counter
	sec
	sbc.l	rotate_IDX
	asl	a
	tax
	ldy	asin_table,x
	lda.l	zoom_data	; (000 - 127 )
	asl	a
	asl	a
	asl	a
	asl	a
	asl	a
	asl	a
	jsr	ML_s16s16
	sta	Ndata		; Y=0 / answer X
;- - - - - - - - - - - - - - - - - - - - - - - -
	clc
	adc.l	Hcenter
	sta	work1		; X line right
	lda.l	Hcenter
	sec
	sbc	Ndata
	sta	work2		; X line left
;- - - - - - - - - - - - - - - - - - - - - - - -
	lda	#MAXCOUNT	; = max counter
	sec
	sbc.l	rotate_IDX
	asl	a
	tax
	lda	angle_list,x
	sta	add_add
	lda	#0
	sta.l	add_total+0
	sta.l	add_total+2
;- - - - - - - - - - - - - - - - - - - - - - - -

	lda.l	Vcenter	; 111*4+1
	dec	a
	asl	a
	asl	a
	inc	a

	clc
	adc.l	wipe_switch
	tay
;- - - - - - - - - - - - - - - - - - - - - - - -
	lda.l	Vcenter
	sta	line_counter
;- - - - - - - - - - - - - - - - - - - - - - - -
.loop	
	lda	work1
	sec
	sbc.l	add_total+1
	jsr	Set_Parameter	; set right 
	dey
	lda	work2
	sec
	sbc.l	add_total+1
	jsr	Set_Parameter	; set left
	dey
	dey
	dey

	lda.l	add_total+0
	clc
	adc	add_add
	sta.l	add_total+0
	lda	#0
	adc.l	add_total+2
	sta.l	add_total+2

	dec	line_counter
	bne	.loop
;- - - - - - - - - - - - - - - - - - - - - - - -
	lda.l	Vcenter
	asl	a	
	asl	a
	clc
	adc.l	wipe_switch
	tay

	lda	#192
	sec
	sbc.l	Vcenter
	sta	line_counter

	lda	#0
	sta.l	add_total+0
	sta.l	add_total+2
;- - - - - - - - - - - - - - - - - - - - - - - -
.loop2	
	lda	work2
	clc
	adc.l	add_total+1
	jsr	Set_Parameter	; set left 
	iny
	lda	work1
	clc
	adc.l	add_total+1
	jsr	Set_Parameter	; set right
	iny
	iny
	iny

	lda.l	add_total+0
	clc
	adc	add_add
	sta.l	add_total+0
	lda	#0
	adc.l	add_total+2
	sta.l	add_total+2

	dec	line_counter
	bne	.loop2

	plb
	rts




;=====================================================================
;
;
;
;


;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;	Library Program
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;***********************************************************************
;	１６ビットと１６ビットの符号付き数の掛け算です。(整数）
;***********************************************************************
;< input >>	Areg	符号付き 16bit	; S*******.********
;		Yreg	符号付き 16bit	; S*******.********
;		jsr	ML_s08s16
;< output >>	Areg	答え上位 16bit	; S******* ******** 
;		Yreg	答え下位 16bit  ; .******** ********
;-----------------------------------------------------------------------
						;sBA*sYY=sBAYY ;mW:xW
ML_s16s16	PHX				; >>
		JSR	Xml_s16s16
		PLX				; <
		RTS
;- - - - - - - - - - - - - - - - - - - - - - - - - - -
Xml_s16s16	TYX				;W
		BPL	Multiply_s16u16
		TAY				;W
		BPL	s16s16_skip
		EOR	#0ffffh	;W
		INC	A			;W
		TAY				;W
		TXA				;W
		EOR	#0ffffh	;W
		INC	A			;W
		BRA	Multiply_s16u16
s16s16_skip	TXA				;W
		BRA	Multiply_s16u16		;mW:xW
;-----------------------------------------------------------------------
						;sBA*uYY=sBAYY
Multiply_s16u16 CMP	#8000h	;W
		BCC	Multiply_u16u16
		EOR	#0ffffh	;W
		INC	A			;W
		JSR	Multiply_u16u16
		EOR	#0ffffh	;W
		TAX				;W
		TYA				;W
		EOR	#0ffffh	;W
		TAY				;W
		INY				;W
		BNE	s16u16_skip
		INX				;W
s16u16_skip	TXA				;W
		RTS
;-----------------------------------------------------------------------
Multiply_u16u16	STY	multiplier		;W
		SEP	#00110000B
		STA	XMultiplicand		;B
		STY	XMultiplier		;B
		REP	#00100001B
		XBA
		TAX				;B
		LDY	multiplier+1		;B
		LDA	XProduct		;W
		STY	XMultiplier		;B
		STA	product		;W
		XBA
		AND	#00ffh			;W
		ADC	XProduct		;W
		LDY	multiplier+0		;B
		STX	XMultiplicand		;B
		STY	XMultiplier		;B
		NOP
		LDY	multiplier+1		;B
		ADC	XProduct		;W
		STY	XMultiplier		;B
		STA	product+1		;W
		AND	#0ff00h			;W
		ADC	#0			;W
		XBA
		REP	#00010001B
		LDY	product		;W
		ADC	XProduct		;W
                RTS				;mW:xW
;=====================================================================



;===================================================================
;===================================================================
;;; END END END END END END END END END END END END END END END ;;;;
;===================================================================
;===================================================================
	END

