#dontinclude

;notes

; need to update for enemy spawners
; and items



;*******************************************************vertical y1-y2
update_scroll_v1

	move.w	#$8f80,$c00004	; set vdp autoincrement to 128 bytes/write
	clr.l	d7	;6 cycles
	move.w	nscreenx,d7	;16 cycles
	divu.w	#8,d7	;140 cycles

	add.w	#58,d7	;8 cycles	try 58 was 62
	mulu.w	#2,d7	;48 cycles
	and.w	#127,d7	;8 cycles



	swap	d7	;4 cycles
	add.l	#$60000003,d7	;16 cycles
	move.l	d7,$c00004	;what register? plane b

	move.l	#0,d4	;counter 4 cycles


	move.l	#0,d2
	move.l	#0,d1	;4 cycles
	add.w	screeny,d1	;offset


	divu.w	#8,d1
	subq.w	#1,d1
	move.w	d1,d3
	and.w	#31,d1
	move.w	#31,d2
	sub.w	d1,d2	;jump ahead value
	move.w	d3,d1
;lets draw

	move.l	#0,d3
	move.w	nscreenx,d3
	divu.w	#8,d3
	add.w	#58,d3	;issue here  try 58 was 62
sega_setplanebv_lp1


	lea	worldmap,a6
	move.l	#0,d7
	move.w	d1,d7	;load screen
	add.w	d2,d7	;add offset
	add.w	#1,d7
;	move.b	d7,spawnty
	mulu.w	#128,d7
	add.w	d3,d7
;	move.b	d3,spawntx
	lea	(a6,d7.w),a6


	move.w	#0,d6
	move.b	(a6),d6
;	move.b	d6,spawn

;	jsr	check_spawnin

	if	b,d6!#0
	add.w	#$6096,d6	;150
	move.w	d6,$00c00000	;written
	else
	move.w	#$6000,$00c00000	;written
	endif


	add.b	#1,d4	;counter
	add.b	#1,d2	;offset adjust
	if	w,d2>#31
	move.w	#0,d2
	endif

	if	b,d4<#32
	bra	sega_setplanebv_lp1
	endif

	move.w	#1,screenupd_1
	rts





;*******************************************************vertical y1-y2
update_scroll_v2

	move.w	#$8f80,$c00004	; set vdp autoincrement to 128 bytes/write
	clr.l	d7
	move.w	nscreenx,d7
	divu.w	#8,d7

	sub.w	#0,d7	;target
	mulu.w	#2,d7
	and.w	#127,d7


	swap	d7
	add.l	#$60000003,d7
	move.l	d7,$c00004	;what register? plane b

	move.l	#0,d4	;counter


	clr.l	d2
	move.l	#0,d1
	add.w	screeny,d1	;offset


	divu.w	#8,d1
	sub.w	#1,d1
	move.w	d1,d3
	and.w	#31,d1
	move.w	#31,d2
	sub.w	d1,d2	;jump ahead value
	move.w	d3,d1
;lets draw

	clr.l	d3
	move.w	nscreenx,d3
	divu.w	#8,d3
	sub.w	#0,d3	;target was 0

sega_setplanebv_lp2


	lea	worldmap,a6
	clr.l	d7
	move.w	d1,d7	;load screen
	add.w	d2,d7	;add offset
	add.w	#1,d7
;	move.b	d7,spawnty
	mulu.w	#128,d7
	add.w	d3,d7
;	move.b	d3,spawntx
	lea	(a6,d7.w),a6


	clr.w	d6
	move.b	(a6),d6
;	move.b	d6,spawn

;	jsr	check_spawnin

	if	b,d6!#0
	add.w	#$6096,d6	;150
	move.w	d6,$00c00000	;written
	else
	move.w	#$6000,$00c00000	;written
	endif


	add.b	#1,d4	;counter
	add.b	#1,d2	;offset adjust
	if	w,d2>#31
	clr.w	d2
	endif

	if	b,d4<#32
	bra	sega_setplanebv_lp2
	endif
	move.w	#1,screenupd_2

	rts



;needs left adjustment


;*********************************************************************horizontal updater x1-x2
update_scroll_h1
	move.w	#$8f02,$c00004	; set vdp autoincrement to 2 bytes/write
	clr.l	d2
	clr.l	d1
	clr.l	d3


	clr.l	d7
	move.w	screeny,d7
	divu.w	#8,d7


	add.w	#29,d7	;test
	and.w	#31,d7
	mulu.w	#128,d7
	swap	d7

	add.l	#$60000003,d7
	move.l	d7,$00c00004	;what register?

	clr.l	d1
	move.w	nscreenx,d1
	divu.w	#8,d1
	sub.w	#1,d1
;shift it
	move.w	d1,d3	;save
	and.w	#63,d1
	move.w	#63,d2
	sub.w	d1,d2




;d2 has starting value

	move.l	#0,d4	;counter

	move.w	d3,d1


;lets draw




	lea	worldmap,a6
	clr.l	d7
	move.w	screeny,d7
	divu.w	#8,d7

	add.w	#29,d7	;test
;	move.b	d7,spawnty
	mulu.w	#128,d7
	lea	(a6,d7),a6
	move.l	a6,address2

sega_setplanebh_lp1

	move.l	address2,a6



	clr.l	d7
	move.w	d1,d7
	add.w	d2,d7
	add.w	#1,d7
;	move.b	d7,spawntx
	lea	(a6,d7.w),a6


	clr.w	d6
	move.b	(a6),d6
;	move.b	d6,spawn

;	jsr	check_spawnin


	if	b,d6!#0
	add.w	#$6096,d6	;150
	move.w	d6,$00c00000	;written
	else
	move.w	#$6000,$00c00000	;written
	endif


	add.b	#1,d4	;counter
	add.b	#1,d2	;offset adjust
	if	b,d2>#63
	clr.b	d2
	endif

	if	b,d4<#64
	bra	sega_setplanebh_lp1
	endif

	move.w	#1,screenupd_3
	rts






;*********************************************************************horizontal updater x1-x2
update_scroll_h2
	move.w	#$8f02,$c00004	; set vdp autoincrement to 2 bytes/write

	clr.l	d2
	clr.l	d1
	clr.l	d3
	clr.l	d7
	move.w	screeny,d7
	divu.w	#8,d7

	and.w	#31,d7
	mulu.w	#128,d7
	swap	d7

	add.l	#$60000003,d7
	move.l	d7,$00c00004	;what register?

	clr.l	d1
	move.w	nscreenx,d1
	divu.w	#8,d1
	sub.w	#1,d1
;shift it
	move.w	d1,d3	;save
	and.w	#63,d1
	move.w	#63,d2
	sub.w	d1,d2




;d2 has starting value

	move.l	#0,d4	;counter

	move.w	d3,d1


;lets draw




	lea	worldmap,a6
	clr.l	d7
	move.w	screeny,d7
	divu.w	#8,d7
;	move.b	d7,spawnty
	mulu.w	#128,d7
	lea	(a6,d7.l),a6
	move.l	a6,address

sega_setplanebh_lp2

	move.l	address,a6

	clr.l	d7
	move.w	d1,d7
	add.w	d2,d7
	add.w	#1,d7
;	move.b	d7,spawntx
	lea	(a6,d7.l),a6


	clr.l	d6
	move.b	(a6),d6
;	move.b	d6,spawn

;	jsr	check_spawnin

	if	b,d6!#0
	add.w	#$6096,d6	;150
	move.w	d6,$00c00000	;written
	else
	move.w	#$6000,$00c00000	;written
	endif


	add.b	#1,d4	;counter
	add.b	#1,d2	;offset adjust
	if	b,d2>#63
	clr.b	d2
	endif

	if	b,d4<#64
	bra	sega_setplanebh_lp2
	endif
	move.w	#1,screenupd_4
	rts






;**************************************plane a at $40000003



;*******************************************************vertical y1-y2
update_scroll_av1
	move.w	#0,screenupd_1

	move.w	#$8f80,$c00004	; set vdp autoincrement to 128 bytes/write
	clr.l	d7	;6 cycles
	move.w	nscreenx,d7	;16 cycles
	divu.w	#8,d7	;140 cycles

	add.w	#58,d7	;8 cycles
	mulu.w	#2,d7	;48 cycles
	and.w	#127,d7	;8 cycles


	swap	d7	;4 cycles
	add.l	#$40000003,d7	;16 cycles
	move.l	d7,$c00004	;what register? plane b

	move.l	#0,d4	;counter 4 cycles


	move.l	#0,d2
	move.l	#0,d1	;4 cycles
	add.w	screeny,d1	;offset


	divu.w	#8,d1
	subq.w	#1,d1
	move.w	d1,d3
	and.w	#31,d1
	move.w	#31,d2
	sub.w	d1,d2	;jump ahead value
	move.w	d3,d1
;lets draw

	move.l	#0,d3
	move.w	nscreenx,d3
	divu.w	#8,d3
	add.w	#58,d3
sega_setplaneav_lp1


	lea	worldmaproof,a6
	move.l	#0,d7
	move.w	d1,d7	;load screen
	add.w	d2,d7	;add offset
	add.w	#1,d7
	move.b	d7,spawnty
	mulu.w	#128,d7
	add.w	d3,d7
	move.b	d3,spawntx
	lea	(a6,d7.w),a6


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

;new
	move.b	d6,spawn
	jsr	check_spawnin



	if	b,d6!#0	b,d6<#234
	add.w	#$e096,d6	;150
	move.w	d6,$00c00000	;written
	else
	if	b,d6=#0
	move.w	#$e000,$00c00000	;written
	else
	add.w	#$6096,d6
	move.w	d6,$00c00000	;written fire + water?
	endif
	endif


;	if	b,d6!#0
;	add.w	#$e096,d6	;150
;	move.w	d6,$00c00000	;written
;	else
;	move.w	#$e000,$00c00000	;written
;	endif



	add.b	#1,d4	;counter
	add.b	#1,d2	;offset adjust
	if	w,d2>#31
	move.w	#0,d2
	endif

	if	b,d4<#32
	bra	sega_setplaneav_lp1
	endif

	rts





;*******************************************************vertical y1-y2
update_scroll_av2
	move.w	#0,screenupd_2

	move.w	#$8f80,$c00004	; set vdp autoincrement to 128 bytes/write
	clr.l	d7
	move.w	nscreenx,d7
	divu.w	#8,d7

	sub.w	#0,d7	;was 0
	mulu.w	#2,d7
	and.w	#127,d7


	swap	d7
	add.l	#$40000003,d7
	move.l	d7,$c00004	;what register? plane b

	move.l	#0,d4	;counter


	clr.l	d2
	move.l	#0,d1
	add.w	screeny,d1	;offset


	divu.w	#8,d1
	sub.w	#1,d1
	move.w	d1,d3
	and.w	#31,d1
	move.w	#31,d2
	sub.w	d1,d2	;jump ahead value
	move.w	d3,d1
;lets draw

	clr.l	d3
	move.w	nscreenx,d3
	divu.w	#8,d3
	sub.w	#0,d3	;was 0


sega_setplaneav_lp2


	lea	worldmaproof,a6
	clr.l	d7
	move.w	d1,d7	;load screen
	add.w	d2,d7	;add offset
	add.w	#1,d7
	move.b	d7,spawnty
	mulu.w	#128,d7
	add.w	d3,d7
	move.b	d3,spawntx
	lea	(a6,d7.w),a6


	clr.w	d6
	move.b	(a6),d6
	move.b	d6,spawn

	jsr	check_spawnin

	if	b,d6!#0	b,d6<#234
	add.w	#$e096,d6	;150
	move.w	d6,$00c00000	;written
	else
	if	b,d6=#0
	move.w	#$e000,$00c00000	;written
	else
	add.w	#$6096,d6
	move.w	d6,$00c00000	;written fire + water?
	endif
	endif


;	if	b,d6!#0
;	add.w	#$e096,d6	;150
;	move.w	d6,$00c00000	;written
;	else
;	move.w	#$e000,$00c00000	;written
;	endif


	add.b	#1,d4	;counter
	add.b	#1,d2	;offset adjust
	if	w,d2>#31
	clr.w	d2
	endif

	if	b,d4<#32
	bra	sega_setplaneav_lp2
	endif

	rts



;needs left adjustment


;*********************************************************************horizontal updater x1-x2
update_scroll_ah1
	move.w	#0,screenupd_3

	move.w	#$8f02,$c00004	; set vdp autoincrement to 2 bytes/write
	clr.l	d2
	clr.l	d1
	clr.l	d3


	clr.l	d7
	move.w	screeny,d7
	divu.w	#8,d7


	add.w	#29,d7	;test
	and.w	#31,d7
	mulu.w	#128,d7
	swap	d7

	add.l	#$40000003,d7
	move.l	d7,$00c00004	;what register?

	clr.l	d1
	move.w	nscreenx,d1
	divu.w	#8,d1
	sub.w	#1,d1
;shift it
	move.w	d1,d3	;save
	and.w	#63,d1
	move.w	#63,d2
	sub.w	d1,d2




;d2 has starting value

	move.l	#0,d4	;counter

	move.w	d3,d1


;lets draw




	lea	worldmaproof,a6
	clr.l	d7
	move.w	screeny,d7
	divu.w	#8,d7

	add.w	#29,d7	;test
	move.b	d7,spawnty
	mulu.w	#128,d7
	lea	(a6,d7),a6
	move.l	a6,address2

sega_setplaneah_lp1

	move.l	address2,a6



	clr.l	d7
	move.w	d1,d7
	add.w	d2,d7
	add.w	#1,d7
	move.b	d7,spawntx
	lea	(a6,d7.w),a6


	clr.w	d6
	move.b	(a6),d6
	move.b	d6,spawn

	jsr	check_spawnin

	if	b,d6!#0	b,d6<#234
	add.w	#$e096,d6	;150
	move.w	d6,$00c00000	;written
	else
	if	b,d6=#0
	move.w	#$e000,$00c00000	;written
	else
	add.w	#$6096,d6
	move.w	d6,$00c00000	;written fire + water?
	endif
	endif


;	if	b,d6!#0
;	add.w	#$e096,d6	;150
;	move.w	d6,$00c00000	;written
;	else
;	move.w	#$e000,$00c00000	;written
;	endif


	add.b	#1,d4	;counter
	add.b	#1,d2	;offset adjust
	if	b,d2>#63
	clr.b	d2
	endif

	if	b,d4<#64
	bra	sega_setplaneah_lp1
	endif

	rts






;*********************************************************************horizontal updater x1-x2
update_scroll_ah2
	move.w	#0,screenupd_4

	move.w	#$8f02,$c00004	; set vdp autoincrement to 2 bytes/write

	clr.l	d2
	clr.l	d1
	clr.l	d3
	clr.l	d7
	move.w	screeny,d7
	divu.w	#8,d7

	and.w	#31,d7
	mulu.w	#128,d7
	swap	d7

	add.l	#$40000003,d7
	move.l	d7,$00c00004	;what register?

	clr.l	d1
	move.w	nscreenx,d1
	divu.w	#8,d1
	sub.w	#1,d1
;shift it
	move.w	d1,d3	;save
	and.w	#63,d1
	move.w	#63,d2
	sub.w	d1,d2




;d2 has starting value

	move.l	#0,d4	;counter

	move.w	d3,d1


;lets draw




	lea	worldmaproof,a6
	move.l	#0,d7
	move.w	screeny,d7
	divu.w	#8,d7
	move.b	d7,spawnty
	mulu.w	#128,d7
	lea	(a6,d7.l),a6
	move.l	a6,address

sega_setplaneah_lp2

	move.l	address,a6

	move.l	#0,d7
	move.w	d1,d7
	add.w	d2,d7
	add.w	#1,d7
	move.b	d7,spawntx
	lea	(a6,d7.l),a6


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

	jsr	check_spawnin


	if	b,d6!#0	b,d6<#234
	add.w	#$e096,d6	;150
	move.w	d6,$00c00000	;written
	else
	if	b,d6=#0
	move.w	#$e000,$00c00000	;written
	else
	add.w	#$6096,d6
	move.w	d6,$00c00000	;written fire + water?
	endif
	endif

;	if	b,d6!#0
;	add.w	#$e096,d6	;150
;	move.w	d6,$00c00000	;written
;	else
;	move.w	#$e000,$00c00000	;written
;	endif
;

	add.b	#1,d4	;counter
	add.b	#1,d2	;offset adjust
	if	b,d2>#63
	clr.b	d2
	endif

	if	b,d4<#64
	bra	sega_setplaneah_lp2
	endif

	rts






;*******************************************************************************************************************************************
def	screenupd_1	word
def	screenupd_2	word
def	screenupd_3	word
def	screenupd_4	word


def	screen_oldv	word
def	screen_oldh	word



