; include file

update_screenscroll




;try to scroll screen


;******************************************************************************************************
	move.w	(2,a0),d5
	sub.w	nscreenx,d5
	move.w	(4,a0),d6
	sub.w	screeny,d6

	if	w,d6<#184
	move.w	#184,d7
	sub.w	d6,d7
	move.w	d7,d6

	if	w,d6>#16
	move.w	#16,d6
	endif

	sub.w	d6,screeny
	if	ws,screeny<#0
	move.w	#0,screeny
	endif

;test
	move.w	screeny,d6
	lsr.w	#4,d6
	if	w,d6!old_screeny
	move.w	d6,old_screeny
	move.w	#1,update_scroll0
	endif

	endif





;******************************************************************************************************
	move.w	(2,a0),d5
	sub.w	nscreenx,d5
	move.w	(4,a0),d6
	sub.w	screeny,d6

	if	w,d6>#280
	sub.w	#280,d6
	if	w,d6>#16
	move.w	#16,d6
	endif

	add.w	d6,screeny
	if	ws,screeny>#288
	move.w	#288,screeny
	endif

;test
	move.w	screeny,d6
	lsr.w	#4,d6
	if	w,d6!old_screeny
	move.w	d6,old_screeny
	move.w	#1,update_scroll1
	endif

	endif


;******************************************************************************************************
	move.w	(2,a0),d5
	sub.w	nscreenx,d5
	move.w	(4,a0),d6
	sub.w	screeny,d6

; left
	if	w,d5<#216
	move.w	#216,d7
	sub.w	d5,d7
	move.w	d7,d5
	if	w,d5>#16
	move.w	#16,d5
	endif

	add.w	d5,screenx
	if	ws,screenx>#0
	move.w	#0,screenx
	endif
	move.w	#65535,d6
	sub.w	screenx,d6
	move.w	d6,nscreenx

	if	ws,nscreenx<#0
	move.w	#0,nscreenx
	endif

;test
	move.w	nscreenx,d6
	lsr.w	#4,d6
	if	w,d6!old_screenx
	move.w	d6,old_screenx
	move.w	#1,update_scroll2
	endif
	endif


;***********************************************************************************************************
	move.w	(2,a0),d5
	sub.w	nscreenx,d5

	move.w	(4,a0),d6
	sub.w	screeny,d6

; right
	if	w,d5>#348
	move.w	#348,d7
	sub.w	d7,d5
	if	w,d5>#16
	move.w	#16,d5
	endif

	sub.w	d5,screenx

	if	ws,screenx<#57840
	move.w	#57840,screenx
	endif

	move.w	#65535,d6
	sub.w	screenx,d6
	move.w	d6,nscreenx

	if	ws,nscreenx<#0
	move.w	#0,nscreenx
	endif
;test
	move.w	nscreenx,d6
	lsr.w	#4,d6
	if	w,d6!old_screenx
	move.w	d6,old_screenx
	move.w	#1,update_scroll3
	endif
	endif



	sega_scrollplanea(screenx,screeny)


	move.w	screenx,d5
	move.w	screeny,d6
	lsr.w	#3,d6
	lsr.w	#2,d5
	sega_scrollplaneb(d5,d6)



	rts

def	flipflop	word


;***************************************************************************************************************************************


update_scrollb_up


	move.l	#0,d0
	move.l	#0,d1
	move.w	nscreenx,d0
	move.w	screeny,d1
;	sub.w	#8,d1	;adjust

	add.w	#0,d0
	add.w	#0,d1	;adjustment

	lsr.w	#4,d0	;equivilant to /16
	lsr.w	#4,d1


	move.l	d0,d2
	move.l	d1,d3
	and.w	#31,d2
	lsl.b	#1,d2
	
	and.w	#15,d3
	lsl.b	#1,d3


	lea	world_map,a6
	move.l	d1,d6
	mulu.w	#512,d6
	add.w	d0,d6
	lea	(a6,d6),a6

; map is where it needs to be
; one
	move.w	#31,d5	;counter

update_scrollb_up_lp1

	move.l	#0,d6
	move.b	(a6)+,d6



	move.b	#0,d4	;priority
	if	b,d6>#58
	move.b	#1,d4
	endif


	lsl.w	#2,d6
	add.w	#200,d6



	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	add.b	#1,d3
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	sub.b	#1,d3
	add.b	#1,d2
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	add.b	#1,d3
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	sub.b	#1,d3

	add.b	#1,d2






	dbra	d5,update_scrollb_up_lp1


	rts






update_scrollb_down


	move.l	#0,d0
	move.l	#0,d1
	move.w	nscreenx,d0
	move.w	screeny,d1
;	add.w	#4,d1	;adjust

	add.w	#0,d0
	add.w	#232,d1	;adjustment

	lsr.w	#4,d0	;equivilant to /16
	lsr.w	#4,d1




	move.l	d0,d2
	move.l	d1,d3
	and.w	#31,d2
	lsl.b	#1,d2
	
	and.w	#15,d3
	lsl.b	#1,d3



	lea	world_map,a6
	move.l	d1,d6
	mulu.w	#512,d6
	add.w	d0,d6
	lea	(a6,d6),a6

; map is where it needs to be
; one
	move.w	#31,d5	;counter

update_scrollb_down_lp1

	move.l	#0,d6
	move.b	(a6)+,d6


	move.b	#0,d4	;priority
	if	b,d6>#58
	move.b	#1,d4
	endif


	lsl.w	#2,d6
	add.w	#200,d6

	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	add.b	#1,d3
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	sub.b	#1,d3
	add.b	#1,d2
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	add.b	#1,d3
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)

	sub.b	#1,d3

	add.b	#1,d2


	dbra	d5,update_scrollb_down_lp1

	rts






update_scrollb_left


	move.l	#0,d0
	move.l	#0,d1
	move.w	nscreenx,d0
	move.w	screeny,d1

	add.w	#0,d0
	add.w	#0,d1	;adjustment

	lsr.w	#4,d0	;equivilant to /16
	lsr.w	#4,d1




	move.l	d0,d2
	move.l	d1,d3
	and.w	#31,d2
	lsl.b	#1,d2
	
	and.w	#15,d3
	lsl.b	#1,d3



	lea	world_map,a6
	move.l	d1,d6
	mulu.w	#512,d6
	add.w	d0,d6
	lea	(a6,d6),a6

; map is where it needs to be
; one
	move.w	#15,d5	;counter

update_scrollb_left_lp1

	move.l	#0,d6
	move.b	(a6),d6


	move.b	#0,d4	;priority
	if	b,d6>#58
	move.b	#1,d4
	endif



	lsl.w	#2,d6
	add.w	#200,d6

	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	add.b	#1,d3
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	sub.b	#1,d3
	add.b	#1,d2
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	add.b	#1,d3
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	sub.b	#1,d2

	add.b	#1,d3

	lea	(512,a6),a6

	dbra	d5,update_scrollb_left_lp1


	rts




update_scrollb_right


	move.l	#0,d0
	move.l	#0,d1
	move.w	nscreenx,d0
	move.w	screeny,d1

	add.w	#496,d0
	add.w	#0,d1	;adjustment

	lsr.w	#4,d0	;equivilant to /16
	lsr.w	#4,d1




	move.l	d0,d2
	move.l	d1,d3
	and.w	#31,d2
	lsl.b	#1,d2
	
	and.w	#15,d3
	lsl.b	#1,d3



	lea	world_map,a6
	move.l	d1,d6
	mulu.w	#512,d6
	add.w	d0,d6
	lea	(a6,d6),a6

; map is where it needs to be
; one
	move.w	#15,d5	;counter

update_scrollb_right_lp1

	move.l	#0,d6
	move.b	(a6),d6

	move.b	#0,d4	;priority
	if	b,d6>#58
	move.b	#1,d4
	endif

	lsl.w	#2,d6
	add.w	#200,d6

	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	add.b	#1,d3
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	sub.b	#1,d3
	add.b	#1,d2
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	add.w	#1,d6
	add.b	#1,d3
	sega_setplanea(d2,d3,d6,#0,#0,#1,d4)
	sub.b	#1,d2

	add.b	#1,d3


	lea	(512,a6),a6

	dbra	d5,update_scrollb_right_lp1


	rts


def	address	long


