; *************************************************************************************************
; * sega rom template 1.1
; *************************************************************************************************
; do not modify the start and end labels
; your code will be reconstructed when compiled in the correct place


#include	sega\s_main.mdl	;uses new library
#include	sega\s_math.mdl
#include	sega\s_saveram.mdl
#include	sega\s_sprites.mdl
#include	sega\s_input.mdl


#memstart	16711680	;$ff0000

segaromstart

	init_sega()
	init_segavdp()
; clear ports for emulator
	device_ports()
	move.b	#0,device_porta
	move.b	#0,device_portb
; ******************************
; your code starts here
; ******************************


; setup 4 palettes red,green,blue   0-63 and color 0-7

	sega_palette(#1,#0,#0,#0)		;black
	sega_palette(#2,#3,#3,#3)		;grey	text color on 2
	sega_palette(#3,#7,#0,#0)		;white
	sega_palette(#4,#0,#3,#0)		;dgreen
	sega_palette(#5,#0,#5,#0)		;green
	sega_palette(#6,#0,#7,#0)		;lgreen
	sega_palette(#7,#0,#0,#4)		;dblue
	sega_palette(#8,#0,#0,#7)		;blue
	sega_palette(#9,#4,#0,#0)		;dred
	sega_palette(#10,#7,#0,#0)	;red
	sega_palette(#11,#0,#4,#4)	;dcyan
	sega_palette(#12,#0,#7,#7)	;cyan
	sega_palette(#13,#7,#3,#7)	;purple
	sega_palette(#15,#7,#5,#2)	;dskin
	sega_palette(#14,#7,#7,#5)	;skin

	sega_palette(#17,#0,#0,#0)	;black
	sega_palette(#18,#3,#3,#3)	;grey
	sega_palette(#19,#0,#0,#7)	;white
	sega_palette(#20,#0,#3,#0)	;dgreen
	sega_palette(#21,#0,#5,#0)	;green
	sega_palette(#22,#0,#7,#0)	;lgreen
	sega_palette(#23,#0,#0,#4)	;dblue
	sega_palette(#24,#0,#0,#7)	;blue
	sega_palette(#25,#4,#0,#0)	;dred
	sega_palette(#26,#7,#0,#0)	;red
	sega_palette(#27,#0,#4,#4)	;dcyan
	sega_palette(#28,#0,#7,#7)	;cyan
	sega_palette(#29,#7,#3,#7)	;purple
	sega_palette(#31,#7,#5,#2)	;dskin
	sega_palette(#30,#7,#7,#5)	;skin

	sega_palette(#33,#0,#0,#0)	;black
	sega_palette(#34,#4,#4,#4)	;grey
	sega_palette(#35,#7,#7,#7)	;white
	sega_palette(#36,#0,#3,#0)	;dgreen
	sega_palette(#37,#0,#5,#0)	;green
	sega_palette(#38,#0,#7,#0)	;lgreen
	sega_palette(#39,#0,#0,#4)	;dblue
	sega_palette(#40,#0,#0,#7)	;blue
	sega_palette(#41,#4,#0,#0)	;dred
	sega_palette(#42,#7,#0,#0)	;red
	sega_palette(#43,#0,#4,#4)	;dcyan
	sega_palette(#44,#0,#7,#7)	;cyan
	sega_palette(#45,#7,#3,#7)	;purple
	sega_palette(#47,#7,#5,#2)	;dskin
	sega_palette(#46,#7,#7,#5)	;skin

	sega_palette(#49,#0,#0,#0)	;black
	sega_palette(#50,#7,#7,#7)	;grey moded white for test
	sega_palette(#51,#7,#7,#7)	;white
	sega_palette(#52,#0,#3,#0)	;dgreen
	sega_palette(#53,#0,#5,#0)	;green
	sega_palette(#54,#0,#7,#0)	;lgreen
	sega_palette(#55,#0,#0,#4)	;dblue
	sega_palette(#56,#0,#0,#7)	;blue
	sega_palette(#57,#4,#0,#0)	;dred
	sega_palette(#58,#7,#0,#0)	;red
	sega_palette(#59,#0,#4,#4)	;dcyan
	sega_palette(#60,#0,#7,#7)	;cyan
	sega_palette(#61,#7,#3,#7)	;purple
	sega_palette(#63,#7,#5,#2)	;dskin
	sega_palette(#62,#7,#7,#5)	;skin

	sega_font()	;setup diagnostic ascii (tiles 0-95) uses color #2 index

	sega_background(#0,#53)

doloop
	device_ports()
	inputplayer1()


	bytestring(inputplayer1_id,#word)
	sega_printa(#8,#1,#word,#0,#0,#0,#0)


;port a
	binstring(device_ports_1,#word)
	sega_printa(#2,#2,#word,#0,#0,#0,#0)
	
	binstring(device_ports_2,#word)
	sega_printa(#2,#3,#word,#0,#0,#0,#0)
	
	binstring(device_ports_3,#word)
	sega_printa(#2,#4,#word,#0,#0,#0,#0)
	
	binstring(device_ports_4,#word)
	sega_printa(#2,#5,#word,#0,#0,#0,#0)
	
	binstring(device_ports_5,#word)
	sega_printa(#2,#6,#word,#0,#0,#0,#0)
	
	binstring(device_ports_6,#word)
	sega_printa(#2,#7,#word,#0,#0,#0,#0)
	
	binstring(device_ports_7,#word)
	sega_printa(#2,#8,#word,#0,#0,#0,#0)



;***************************************************************	
	bytestring(device_ports_1,#word)
	sega_printa(#12,#2,#word,#0,#0,#0,#0)
	
	bytestring(device_ports_2,#word)
	sega_printa(#12,#3,#word,#0,#0,#0,#0)
	
	bytestring(device_ports_3,#word)
	sega_printa(#12,#4,#word,#0,#0,#0,#0)
	
	bytestring(device_ports_4,#word)
	sega_printa(#12,#5,#word,#0,#0,#0,#0)
	
	bytestring(device_ports_5,#word)
	sega_printa(#12,#6,#word,#0,#0,#0,#0)
	
	bytestring(device_ports_6,#word)
	sega_printa(#12,#7,#word,#0,#0,#0,#0)
	
	bytestring(device_ports_7,#word)
	sega_printa(#12,#8,#word,#0,#0,#0,#0)

	inputplayer2()

;******************************************************************
	binstring(inputplayer1_data1,#word)
	sega_printa(#2,#10,#word,#0,#0,#0,#0)
	binstring(inputplayer1_data2,#word)
	sega_printa(#12,#10,#word,#0,#0,#0,#0)
;mouse
	wordstring(inputplayer1_mousex,#word)
	sega_printa(#2,#12,#word,#0,#0,#0,#0)
	wordstring(inputplayer1_mousey,#word)
	sega_printa(#12,#12,#word,#0,#0,#0,#0)


	sega_setsprite(#1,#147,inputplayer1_mousex,inputplayer1_mousey,#0,#0,#0,#0,#0,#0)
	sega_setsprite(#2,#147,inputplayer2_mousex,inputplayer2_mousey,#0,#0,#0,#0,#1,#0)


	if	w,inputplayer1_mousey<inputplayer2_mousey
	sega_linksprite(#0,#1)
	sega_linksprite(#1,#2)
	sega_linksprite(#2,#0)
	else
	sega_linksprite(#0,#2)
	sega_linksprite(#2,#1)
	sega_linksprite(#1,#0)

	endif



	sync()

	syncend()
	bra	doloop


def	word	string	16


; ******************************
; * end of program
; ******************************
	even
ignore_handler
	rte	; return from exception
; included data goes here before compile automatically

	even
segaromend












