; include file

load_map




	sega_loadtile(#200,#324,#map_tiles)


	sega_clearplanea(#200)
	sega_clearplaneb(#200)
	sega_scrollplanea(#0,#0)
	sega_scrollplaneb(#0,#0)



	sega_clearsprites()








	jsr	daytime
;	jsr	nighttime




	sega_displayoff()



	lea	level_01,a5	;full map
	lea	world_map,a6

	move.l	#16383,d0
load_map_lp
	move.b	(a5)+,d6

	if	b,d6=#255
	move.b	#0,d6
	endif

	move.b	d6,(a6)+

	dbra	d0,load_map_lp


;try to load start of screen





	lea	world_map,a6

	move.l	#0,d0	;right
	move.l	#0,d1	;dwn


load_map_drawlp
	move.l	#0,d2
	move.w	#200,d3	;empty tile
	move.b	(a6),d2	;data

	move.b	#0,d4	;priority

	if	b,d2>#0

	if	b,d2>#58
	move.b	#1,d4
	endif

	move.l	#4,d3	;every tile is 4 tiles
	mulu.w	d2,d3
	add.w	#200,d3	;d3 has true tile start
	endif

	sega_setplanea(d0,d1,d3,#0,#0,#1,d4)
	add.w	#1,d3
	add.b	#1,d1
	sega_setplanea(d0,d1,d3,#0,#0,#1,d4)
	add.w	#1,d3
	sub.b	#1,d1
	add.b	#1,d0
	sega_setplanea(d0,d1,d3,#0,#0,#1,d4)
	add.w	#1,d3
	add.b	#1,d1
	sega_setplanea(d0,d1,d3,#0,#0,#1,d4)
	sub.b	#1,d0
	sub.b	#1,d1



	lea	(1,a6),a6	;advance 1 on map
	add.b	#2,d0	;advance 2 on screen

	if	b,d0<#63
	bra	load_map_drawlp
	endif

	move.b	#0,d0	;reset x draw
	add.b	#2,d1	;advance y draw
	lea	(480,a6),a6	;advance a line

	if	b,d1<#31
	bra	load_map_drawlp
	endif

































	lea	background_01,a6

	move.l	#0,d0	;right
	move.l	#0,d1	;dwn


load_map_drawlp2
	move.l	#0,d2
	move.w	#200,d3	;empty tile
	move.b	(a6)+,d2	;data

	if	b,d2=#255
	move.b	#0,d2
	endif


	if	b,d2>#0

	move.l	#4,d3	;every tile is 4 tiles
	mulu.w	d2,d3
	add.w	#200,d3	;d3 has true tile start
	endif

	sega_setplaneb(d0,d1,d3,#0,#0,#0,#0)
	add.w	#1,d3
	add.b	#1,d1
	sega_setplaneb(d0,d1,d3,#0,#0,#0,#0)
	add.w	#1,d3
	sub.b	#1,d1
	add.b	#1,d0
	sega_setplaneb(d0,d1,d3,#0,#0,#0,#0)
	add.w	#1,d3
	add.b	#1,d1
	sega_setplaneb(d0,d1,d3,#0,#0,#0,#0)
	sub.b	#1,d0
	sub.b	#1,d1



	add.b	#2,d0	;advance 2 on screen

	if	b,d0<#63
	bra	load_map_drawlp2
	endif

	move.b	#0,d0	;reset x draw
	add.b	#2,d1	;advance y draw


	if	b,d1<#31
	bra	load_map_drawlp2
	endif



























	sega_displayon()




	rts



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

daytime

	sega_palette(#1,#3,#3,#3)	;black
	sega_palette(#2,#5,#5,#5)	;grey
	sega_palette(#3,#7,#6,#7)	;grey
	sega_palette(#4,#7,#7,#7)	;white
	sega_palette(#5,#4,#4,#0)	;brown
	sega_palette(#6,#6,#5,#3)	;
	sega_palette(#7,#7,#6,#4)	;
	sega_palette(#8,#7,#7,#6)	;skin
	sega_palette(#9,#7,#7,#0)	;yellow
	sega_palette(#10,#7,#0,#0)	;red
	sega_palette(#11,#4,#4,#7)	;blue
	sega_palette(#12,#0,#4,#0)	;green
	sega_palette(#13,#0,#6,#0)	;
	sega_palette(#14,#4,#7,#0)	;
	sega_palette(#15,#5,#7,#0)	;

	sega_background(#0,#59)	;change background color like this or59

	rts


nighttime
	sega_palette(#1,#1,#1,#1)	;black
	sega_palette(#2,#2,#2,#2)	;grey
	sega_palette(#3,#3,#3,#3)	;grey
	sega_palette(#4,#5,#5,#5)	;white
	sega_palette(#5,#1,#1,#0)	;brown
	sega_palette(#6,#2,#1,#0)	;
	sega_palette(#7,#3,#2,#0)	;
	sega_palette(#8,#4,#3,#2)	;skin
	sega_palette(#9,#5,#5,#0)	;yellow
	sega_palette(#10,#4,#0,#0)	;red
	sega_palette(#11,#0,#0,#4)	;blue
	sega_palette(#12,#0,#1,#0)	;green
	sega_palette(#13,#0,#2,#0)	;
	sega_palette(#14,#0,#3,#0)	;
	sega_palette(#15,#1,#5,#0)	;

	sega_background(#0,#1)	;change background color like this or59

	rts












; map is 512 x 32
def	world_map	string	16384
def	world_bg	string	16384


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

level_01

	incbin	'testmap_512x32'
	even
	incbin	'testmap_512x32'
	even

background_01

	incbin	'testmap_512x32bg'
	even




