;*********************************************************************
;		テストプログラム	(カメラルーチン）
;			programed by H.Yajima
;*********************************************************************
	include	Xmacro.def
	include	Pmacro.def
	include	RP5A22X
	include	RP5C77X
;---------------------------------------------------------------------
	include	register.alc
	include	romdata.def
	include	alpha.def
;---------------------------------------------------------------------
	glb	MoveCamera
;---------------------------------------------------------------------
bank7f	sect	rel
	extend
	mem16
	idx16
;---------------------------------------------------------------------
;***********************************************************************
;	カメラの移動
;***********************************************************************
move_entry

	McheckkeyZ button,screen_yaw,button_right,button_left,1,0,0
	MSlimit	screen_yaw,-7,7
	McheckkeyZ button,screen_pitch,button_up,button_down,1,0,0
	MSlimit	screen_pitch,-7,7
;;	McheckkeyZ button,screen_roll,button_L,button_R,-1,0,0
;;	MSlimit	screen_roll,-7,7

	M0backZ	button,screen_pitch,button_up+button_down,1
	M0backZ	button,screen_yaw,button_left+button_right,1

	lda	screen_yaw
	sta	screen_roll
	asl	a
	clc
	adc	camera_H
	sta	camera_H

	lda	screen_pitch
	asl	a
	clc
	adc	camera_V
	sta	camera_V




	rts
;***********************************************************************
;	カメラスクロール ( 2D スクリーンのとき )
;***********************************************************************
dda_add		equ	work+6
dda_total	equ	work+8	;(4byte)
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Mdiv	macro	
	local	skip1,skip2
	php
	bpl	skip1
	eor	#0ffffh
	inc	a
skip1	sta.w	4204h
	i8
	stx.w	4206h
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	i16
	lda.w	4214h
	plp
	bpl	skip2
	eor	#0ffffh
	inc	a
skip2
	endm

MoveCamera

	lda	raster_cursor
	bne	.skip

	jsr	move_entry

.skip
;- - - - - - - - - - - - - - - - - - - - - -
	ldx	#7
	lda	screen_roll
	and	#00ffh
	xba
	cmp	#0
	Mdiv
	sta	dda_add
;- - - - - - - - - - - - - - - - - - - - - -
	sta	VoffsetDDA
;- - - - - - - - - - - - - - - - - - - - - -
	MflagOFF	Vzoom_enable,raster_status
	bne	s10
	jsr	Set_Vdata
	bra	s11
s10	jsr	Clear_Vdata
s11
;- - - - - - - - - - - - - - - - - - - - - -

	rtl

;***********************************************************************
;	Voffset
;***********************************************************************
Clear_Vdata
	ldx	Voffset_register
	ldy	#32
.loop	stz	64,x
	inx
	inx
	dey
	bne	.loop
	rts
;***********************************************************************
;	Voffset
;***********************************************************************

Set_Vdata

;- - - - - - - - - - - - - - - - - - - - - -

	lda	#15
	sta	work

	lda	#80h
	sta	dda_total+0
	stz	dda_total+2


	ldx	Voffset_register
	txy
;- - - - - - - - - - - - - - - - - - - - - -
.loop1	
	lda	camera_V
	clc
	adc	dda_total+1
	and	#03ffh
	ora	#4000h
	sta	64+30,x

	lda	camera_V
	sec
	sbc	dda_total+1
	and	#03ffh
	ora	#4000h
	sta.w	64+30,y

	clc
	lda	dda_total+0
	adc	dda_add
	sta	dda_total+0
	lda	#0
	bit	dda_add
	bpl	.skip
	dec	a
.skip	adc	dda_total+2
	sta	dda_total+2

	inx
	inx
	dey
	dey

	dec	work
	bne	.loop1

	rts

;=======================================================================
;=======================================================================
;=======================================================================
;=======================================================================
;========================================================================
	end

