#dontinclude
; include file



; *******************************************************************************************************************
; * main_anglecheck(wa.w)
; *******************************************************************************************************************
function	main_anglecheck	main_anglecheck_v
rem	main_anglecheck( anglevaluecheck.w)
rem	returns word value 0-360 from a byte angle to d7
rem	uses d7 for return
stack	a6/d6
def	main_anglecheck_v	word


main_anglecheck
	move.l	#main_anglecheck_data,a6
	move.w	#2,d6
	move.w	main_anglecheck_v,d7
	mulu.w	d6,d7
	lea	(a6,d7),a6
	clr.l	d7
	move.w	(a6),d7
	rts

main_anglecheck_data
	dc.w	0,1,2,4,5,7,8,9,11,12,14,15,16,18,19,21,22,23,25,26,28,29,31,32,33,35,36,38,39,40,42,43,45,46,47,49,50,52,53,55,56
	dc.w	57,59,60,62,63,64,66,67,69,70,71,73,74,76,77,79,80,81,83,84,86,87,88,90,91,93,94,95,97,98,100,101,103,104,105,107,108
	dc.w	110,111,112,114,115,117,118,119,121,122,124,125,127,128,129,131,132,134,135,136,138,139,141,142,143,145,146,148,149
	dc.w	151,152,153,155,156,158,159,160,162,163,165,166,167,169,170,172,173,175,176,177,179,180,182,183,184,186,187,189,190
	dc.w	191,193,194,196,197,199,200,201,203,204,206,207,208,210,211,213,214,215,217,218,220,221,223,224,225,227,228,230,231
	dc.w	232,234,235,237,238,239,241,242,244,245,247,248,249,251,252,254,255,256,258,259,261,262,263,265,266,268,269,271,272
	dc.w	273,275,276,278,279,280,282,283,285,286,287,289,290,292,293,295,296,297,299,300,302,303,304,306,307,309,310,311,313
	dc.w	314,316,317,319,320,321,323,324,326,327,328,330,331,333,334,335,337,338,340,341,343,344,345,347,348,350,351,352,354
	dc.w	355,357,358,360
endfunction




; *******************************************************************************************************************
; * main_pointangle(x1,y1,x2,y2)
; *******************************************************************************************************************
function	main_pointangle	main_pointangle_xp1,main_pointangle_yp1,main_pointangle_xp2,main_pointangle_yp2
rem	main_pointangle( x1,w, y1.w, x2.w, y2.w )
rem	
rem	returns value on d7
stack	a6/d3-d6

def	main_pointangle_xp1	word
def	main_pointangle_yp1	word
def	main_pointangle_xp2	word
def	main_pointangle_yp2	word

def	main_pointangle_xd	word
def	main_pointangle_yd	word
def	main_pointangle_wn	word
def	main_pointangle_xc	word
def	main_pointangle_yc	word



main_pointangle
	

; d4 neg x
; d3 neg y

	clr.w	d4	;x
	clr.w	d3	;y

	move.w	main_pointangle_xp1,d7
	move.w	main_pointangle_xp2,d6
	cmp.w	d6,d7
	blo	main_pointangle_xreverse1
;sub d7-d6
	sub.w	d6,d7
	move.w	#1,d4
	bra	main_pointangle_ynext1
main_pointangle_xreverse1
;sub d6-d7
	sub.w	d7,d6
	move.w	d6,d7
main_pointangle_ynext1
	move.w	d7,main_pointangle_xd

;y
	move.w	main_pointangle_yp1,d7
	move.w	main_pointangle_yp2,d6
	cmp.w	d6,d7
	blo	main_pointangle_yreverse1
;sub d7-d6
	sub.w	d6,d7
	bra	main_pointangle_znext1
main_pointangle_yreverse1
;sub d6-d7
	sub.w	d7,d6
	move.w	#1,d3
	move.w	d6,d7
main_pointangle_znext1

	move.w	d7,main_pointangle_yd

; ok which is bigger?
	move.w	main_pointangle_xd,d6
	cmp.w	d6,d7
	bhs	main_pointangle_xisbigger1
; y is bigger
	move.w	d6,main_pointangle_wn
	bra	main_pointangle_lins6

main_pointangle_xisbigger1
;x is bigger
	move.w	d7,main_pointangle_wn

;setup
main_pointangle_lins6

;hiscale
	move.l	#main_pointangle_data2,a6
	lea	(1088,a6),a6


; 4 scale
;	move.l	#main_pointangle_data,a6
;	lea	(80,a6),a6


	move.w	#0,main_pointangle_xc	;x counter
	move.w	#0,main_pointangle_yc	;y counter
;d7 has wn
	move.w	main_pointangle_wn,d7	;d7
	move.w	d7,d6	;counter
; 4 scale
;	cmp.w	#4,d6
;	bls	main_pointangle_line222
;	move.w	#4,d6	;new counter needed
; hi scale
	cmp.w	#16,d6
	bls	main_pointangle_line222
	move.w	#16,d6	;new counter needed



; ok now the main loop
main_pointangle_line222
	cmp.w	#0,d6
	bne	main_pointangle_line22
	bra	main_pointangle_good
; main loop
main_pointangle_line22

	move.w	main_pointangle_xc,d5
	add.w	main_pointangle_xd,d5	;add distance to xc counter
	cmp.w	d5,d7	;has it gone over or same as our whole fraction?
	bhs	main_pointangle_adv2	;it has on x.... lets advance it
	move.w	d5,main_pointangle_xc	;nope keep counting 
	bra	main_pointangle_chk2	;lets check y now
main_pointangle_adv2
	sub.w	main_pointangle_wn,d5	;advance the x counter....subtract the whole fraction
	move.w	d5,main_pointangle_xc	;store remainder to play with next loop

	move.w	main_pointangle_xp1,d5
	cmp.w	main_pointangle_xp2,d5
	bhi	main_pointangle_advx2

;	inc	x1	;increase y plot or dec?
	lea	(2,a6),a6
; change to lea operation

	bra	main_pointangle_chk2
main_pointangle_advx2

;	dec	x1
	lea	(-2,a6),a6
; change lea operation

main_pointangle_chk2

	move.w	main_pointangle_yc,d5	;now the y axis.... loader up
	add.w	main_pointangle_yd,d5	;add its distance

	cmp.w	main_pointangle_wn,d5	;has it gone over or the same as our whole fraction
	bhs	main_pointangle_advy2	;it has on y.... lets advance it

	move.w	d5,main_pointangle_yc	;nope... keep counting
	bra	main_pointangle_chkx2	;done
;advance it
main_pointangle_advy2
	sub.w	main_pointangle_wn,d5	;subtract the whole number from y counter
	move.w	d5,main_pointangle_yc	;store the remainder for next loop
	move.w	main_pointangle_yp1,d5
	cmp.w	main_pointangle_yp2,d5
	bhi	main_pointangle_ady2

;	inc	y1	;increase y plot or dec?

; 4 scale
;	lea	(18,a6),a6
	lea	(66,a6),a6

; lea adjust

	bra	main_pointangle_chkx2
main_pointangle_ady2	

;	dec	y1

; 4 scale
;	lea	(-18,a6),a6
	lea	(-66,a6),a6

; lea adjust
	
;done?
main_pointangle_chkx2	

	sub.w	#1,d6	;check the counter

	bne	main_pointangle_line22	;nope keep plotting the line
main_pointangle_good
	clr.l	d7
	move.w	(a6),d7
	rts	;we are done

;4 scale
main_pointangle_data
	dc.w	160,154,147,139,128,117,109,102,96	;0
	dc.w	166,160,152,141,128,115,104,96,90	;1
	dc.w	173,168,160,147,128,109,96,88,83	;2
	dc.w	182,179,173,160,128,96,83,77,74	;3
	dc.w	192,192,192,192,0,64,64,64,64	;4
	dc.w	202,205,211,224,255,32,45,51,54	;5
	dc.w	211,216,224,237,255,19,32,40,45	;6
	dc.w	218,224,232,243,255,13,24,32,38	;7
	dc.w	224,230,237,246,255,10,19,26,32	;8

	
main_pointangle_data2
	dc.w	160,159,158,156,154,153,151,149,147,145,143,141,139,136,134,131,128,125,122,120,117,115,113,111,109,107,105,103,102,100,98,97,96	;
	dc.w	161,160,159,157,156,154,152,150,149,146,144,141,139,136,134,131,128,125,122,119,117,115,112,110,107,106,104,102,100,99,97,96,95	;
	dc.w	163,161,160,158,157,156,153,151,149,147,145,142,139,137,134,132,128,124,122,119,117,114,111,109,107,105,102,100,99,98,96,95,93	;
	dc.w	164,163,162,160,158,157,155,153,151,149,146,144,141,137,134,132,128,124,122,119,115,112,110,107,105,103,101,99,98,96,94,93,92	;
	dc.w	166,165,163,162,160,158,156,154,152,150,147,144,141,139,135,132,128,124,121,117,115,112,109,106,104,102,100,98,96,94,93,91,90	;
	dc.w	168,166,165,163,162,160,158,156,154,151,149,146,142,139,136,132,128,124,120,117,114,110,107,105,102,100,98,96,94,93,91,90,88	;
	dc.w	169,168,167,166,164,162,160,158,156,153,150,147,144,140,136,132,128,124,119,116,112,109,106,103,100,98,96,94,92,90,89,88,87	;
	dc.w	171,170,169,168,166,164,163,160,158,155,152,149,145,141,137,133,128,123,119,115,111,107,104,101,98,96,93,92,90,88,87,85,85	;
	dc.w	173,172,171,170,168,166,165,163,160,158,154,151,147,143,139,134,128,122,117,113,109,105,102,98,96,93,91,90,88,86,85,84,83	;
	dc.w	175,174,173,172,170,169,168,166,163,160,157,153,149,145,139,134,128,122,117,111,107,102,99,96,93,90,88,87,85,84,83,82,81	;
	dc.w	178,177,175,175,173,172,170,168,166,163,160,156,152,147,141,135,128,121,115,109,104,100,96,93,90,88,85,84,83,81,81,79,78	;
	dc.w	180,179,178,177,176,175,173,171,169,167,164,160,156,150,144,136,128,119,112,106,100,96,92,89,87,85,83,81,80,79,78,77,76	;
	dc.w	182,182,181,180,179,178,177,175,173,171,168,165,160,154,147,139,128,117,109,102,96,91,88,85,83,81,79,78,77,76,75,74,74	;
	dc.w	185,184,183,183,182,181,180,179,178,175,173,170,166,160,154,136,128,113,103,96,90,85,83,81,78,77,76,75,74,73,73,72,71	;
	dc.w	187,187,186,186,185,185,184,183,182,181,179,177,173,166,160,143,128,117,96,90,83,79,77,75,74,73,72,71,71,70,70,69,69	;
	dc.w	190,190,189,189,189,188,188,187,187,186,185,184,182,178,171,160,128,96,85,76,74,72,71,70,69,68,68,68,67,67,67,66,66	;
	dc.w	192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,0,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64	;
	dc.w	195,195,195,195,195,196,196,197,197,198,199,200,202,204,211,224,255,32,56,54,54,56,57,58,59,59,60,60,61,61,61,61,61	;
	dc.w	197,197,198,198,199,200,200,201,202,203,205,207,211,218,224,233,255,23,32,38,45,49,51,53,54,55,56,56,57,58,58,59,59	;
	dc.w	200,200,201,201,202,203,204,205,207,209,211,214,218,224,228,239,255,15,26,32,38,42,45,47,49,51,52,53,54,55,55,56,56	;
	dc.w	202,202,203,204,205,206,207,209,211,213,216,219,224,230,237,246,255,10,19,26,32,37,40,43,45,47,49,50,51,51,53,54,54	;
	dc.w	204,205,206,207,208,209,211,213,215,217,220,224,229,234,241,248,255,8,15,22,27,32,36,39,41,43,45,47,48,49,50,51,51	;
	dc.w	207,207,209,209,211,212,214,216,218,221,224,228,232,237,243,249,255,7,13,19,24,28,32,35,38,40,42,44,45,47,47,49,49	;
	dc.w	209,210,211,212,214,215,217,219,221,224,227,231,235,239,245,250,255,6,11,17,21,25,29,32,34,37,39,41,42,44,45,46,47	;
	dc.w	211,212,213,214,216,218,219,221,224,226,230,233,237,241,246,251,255,5,10,15,19,23,26,30,32,34,37,38,40,42,43,44,45	;
	dc.w	213,214,215,217,218,220,221,224,226,229,232,235,239,243,247,251,255,5,9,13,17,21,24,27,30,32,34,36,38,39,41,42,43	;
	dc.w	215,216,217,219,220,222,224,226,229,231,234,237,241,244,248,252,255,4,8,12,15,19,22,25,27,30,32,34,36,37,39,40,41	;
	dc.w	217,218,219,221,222,224,226,228,230,233,236,238,242,245,248,252,255,4,8,11,14,17,20,23,26,28,30,32,34,35,37,38,39	;
	dc.w	218,219,221,222,224,226,228,230,232,234,237,240,243,246,249,253,255,3,7,10,13,16,19,22,24,26,28,30,32,34,35,37,38	;
	dc.w	220,221,222,224,226,227,229,231,234,236,238,241,243,247,250,253,255,3,6,9,13,15,17,20,22,25,27,29,30,32,34,35,36	;
	dc.w	221,223,224,226,227,229,231,233,235,237,239,242,245,247,250,253,255,3,6,9,11,14,17,19,21,23,25,27,29,30,32,33,34	;
	dc.w	223,224,225,227,229,230,232,234,236,238,241,243,246,248,251,253,255,3,5,8,10,13,15,18,20,22,24,26,27,29,31,32,33	;
	dc.w	224,225,226,228,230,231,233,235,237,239,241,243,246,248,251,253,255,3,5,8,10,13,15,17,19,21,23,25,26,28,30,31,32	;

endfunction







***************************************************************************************************************************************************************************************************
* main_distance(x1,y1,x2,y2)
***************************************************************************************************************************************************************************************************
function	main_distance	main_distance_x1,main_distance_y1,main_distance_x2,main_distance_y2
rem	main_distance(x1.w , y1.w , x2.w , y2.w )
rem	Returns result to d7.W register
rem	
stack	d6
def	main_distance_x1	word
def	main_distance_y1	word
def	main_distance_x2	word
def	main_distance_y2	word

def	main_distance_dx1	word
def	main_distance_dy1	word

main_distance

; lets figure out which is greater
	move.w	main_distance_x1,d7
	cmp.w	main_distance_x2,d7
	bhs	main_distance_bigx1
;x2-x1
	move.w	main_distance_x2,d7
	sub.w	main_distance_x1,d7
	move.w	d7,main_distance_dx1
	bra	main_distance_nexty
main_distance_bigx1
	sub.w	main_distance_x2,d7
	move.w	d7,main_distance_dx1
main_distance_nexty
; lets figure out which is greater
	move.w	main_distance_y1,d7
	cmp.w	main_distance_y2,d7
	bhs	main_distance_bigy1
;y2-y1
	move.w	main_distance_y2,d7
	sub.w	main_distance_y1,d7
	move.w	d7,main_distance_dy1
	bra	main_distance_nextz
main_distance_bigy1
	sub.w	main_distance_y2,d7
	move.w	d7,main_distance_dy1
main_distance_nextz
; talk longest and add 1/4 of other

	move.w	main_distance_dx1,d6
	cmp.w	d6,d7
	blo	main_distance_dister1

	lsr.w	#2,d6
;	divu.w	#5,d6
	add.w	d6,d7
	rts

main_distance_dister1

	lsr.w	#2,d7
;	divu.w	#5,d7
	add.w	d6,d7
	rts

endfunction



;
; **********************************************************************************************************************************************************************************************
; * main_stringword(word,return string address)
; **********************************************************************************************************************************************************************************************
; convert number to string
; put numbers in for string add
; 
function	main_stringword	main_stringword_num,main_stringword_ret
rem	main_stringword(word,write string address)
rem	word is a value or 0-65535 and needs a return address to populate string. 6 BYTES REQUIRED
rem	
stack	a5-a6/d5-d7
def	main_stringword_num	word
def	main_stringword_ret	long



main_stringword

	move.l	#main_stringword_data,a6	;data
	move.l	main_stringword_ret,a5	;where to write
	move.w	main_stringword_num,d7	;word

	move.w	#15,d6	;counter for loop

;clear bits

	move.w	#0,(0,a5)
	move.l	#0,(2,a5)


main_stringword_lp1

	btst	d6,d7
	beq	main_stringword_lp2


	move.b	(5,a6),d5
	add.b	(4,a5),d5
	move.b	d5,(4,a5)
	cmp.b	#9,d5
	bls	main_stringword_lp3
	sub.b	#10,d5
	move.b	d5,(4,a5)
	
	move.b	(3,a5),d5
	add.b	#1,d5
	move.b	d5,(3,a5)

main_stringword_lp3

	move.b	(4,a6),d5
	add.b	(3,a5),d5
	move.b	d5,(3,a5)
	cmp.b	#9,d5
	bls	main_stringword_lp4
	sub.b	#10,d5
	move.b	d5,(3,a5)
	
	move.b	(2,a5),d5
	add.b	#1,d5
	move.b	d5,(2,a5)

main_stringword_lp4	

	move.b	(3,a6),d5
	add.b	(2,a5),d5
	move.b	d5,(2,a5)
	cmp.b	#9,d5
	bls	main_stringword_lp5
	sub.b	#10,d5
	move.b	d5,(2,a5)
	
	move.b	(1,a5),d5
	add.b	#1,d5
	move.b	d5,(1,a5)

main_stringword_lp5


	move.b	(2,a6),d5
	add.b	(1,a5),d5
	move.b	d5,(1,a5)

	cmp.b	#9,d5
	bls	main_stringword_lp6
	sub.b	#10,d5
	move.b	d5,(1,a5)
	
	move.b	(0,a5),d5
	add.b	#1,d5
	move.b	d5,(0,a5)


main_stringword_lp6

	move.b	(1,a6),d5
	add.b	(0,a5),d5
	move.b	d5,(0,a5)
; cant add more to this one


main_stringword_lp2

	lea	(6,a6),a6	;advance counter
	dbra	d6,main_stringword_lp1


	move.b	(0,a5),d5
	add.b	#48,d5
	move.b	d5,(0,a5)

	move.b	(1,a5),d5
	add.b	#48,d5
	move.b	d5,(1,a5)

	move.b	(2,a5),d5
	add.b	#48,d5
	move.b	d5,(2,a5)

	move.b	(3,a5),d5
	add.b	#48,d5
	move.b	d5,(3,a5)

	move.b	(4,a5),d5
	add.b	#48,d5
	move.b	d5,(4,a5)

	move.b	#0,(5,a5)
	
	rts

main_stringword_data

	dc.b	0,3,2,7,6,8
	dc.b	0,1,6,3,8,4
	dc.b	0,0,8,1,9,2
	dc.b	0,0,4,0,9,6
	dc.b	0,0,2,0,4,8
	dc.b	0,0,1,0,2,4
	dc.b	0,0,0,5,1,2
	dc.b	0,0,0,2,5,6

	dc.b	0,0,0,1,2,8
	dc.b	0,0,0,0,6,4
	dc.b	0,0,0,0,3,2
	dc.b	0,0,0,0,1,6
	dc.b	0,0,0,0,0,8
	dc.b	0,0,0,0,0,4
	dc.b	0,0,0,0,0,2
	dc.b	0,0,0,0,0,1
	dc.b	0,0,0,0,0,0

endfunction







;
; **********************************************************************************************************************************************************************************************
; * main_stringbyte(byte ,return string address)
; **********************************************************************************************************************************************************************************************
; convert number to string
; put numbers in for string add
; 
function	main_stringbyte	main_stringbyte_num,main_stringbyte_ret
rem	main_stringbyte(byte,write string address)
rem	byte is a value or 0-255 and needs a return address to populate string. 4 BYTES REQUIRED
rem	
stack	a5-a6/d5-d7
def	main_stringbyte_num	byte
def	main_stringbyte_num2	byte
def	main_stringbyte_ret	long



main_stringbyte

	move.l	#main_stringbyte_data,a6	;data
	move.l	main_stringbyte_ret,a5	;where to write
	move.b	main_stringbyte_num,d7	;byte

	move.w	#7,d6	;counter for loop

;clear bits

	move.l	#0,(0,a5)


main_stringbyte_lp1

	btst	d6,d7
	beq	main_stringbyte_lp2


	move.b	(3,a6),d5
	add.b	(2,a5),d5
	move.b	d5,(2,a5)
	cmp.b	#9,d5
	bls	main_stringbyte_lp3
	sub.b	#10,d5
	move.b	d5,(2,a5)
	
	move.b	(1,a5),d5
	add.b	#1,d5
	move.b	d5,(1,a5)


main_stringbyte_lp3

	move.b	(2,a6),d5
	add.b	(1,a5),d5
	move.b	d5,(1,a5)
	cmp.b	#9,d5
	bls	main_stringbyte_lp4
	sub.b	#10,d5
	move.b	d5,(1,a5)
	
	move.b	(0,a5),d5
	add.b	#1,d5
	move.b	d5,(0,a5)

main_stringbyte_lp4	


	move.b	(0,a6),d5
	add.b	(0,a5),d5
	move.b	d5,(0,a5)
; cant add more to this one


main_stringbyte_lp2

	lea	(4,a6),a6	;advance counter
	dbra	d6,main_stringbyte_lp1


	move.b	(0,a5),d5
	add.b	#48,d5
	move.b	d5,(0,a5)

	move.b	(1,a5),d5
	add.b	#48,d5
	move.b	d5,(1,a5)

	move.b	(2,a5),d5
	add.b	#48,d5
	move.b	d5,(2,a5)

	move.b	#0,(3,a5)
	
	rts

main_stringbyte_data

	dc.b	0,1,2,8
	dc.b	0,0,6,4
	dc.b	0,0,3,2
	dc.b	0,0,1,6
	dc.b	0,0,0,8
	dc.b	0,0,0,4
	dc.b	0,0,0,2
	dc.b	0,0,0,1
	dc.b	0,0,0,0

endfunction




***************************************************************************************************************************************************************************************************
* main_rnd(x,y)
***************************************************************************************************************************************************************************************************
function	main_rnd	main_rnd_lowv,main_rnd_highv
rem	main_rnd(low range, high range)
rem	value is from range 0-254 and low cannot be higher then high range
rem	Returns result to d7.b register (requires system clock)
stack	d6
def	main_rnd_rndr	byte
def	main_rnd_lowv	byte
def	main_rnd_highv	byte
def	main_rnd_stepr	byte
def	main_rnd_res	byte
def	main_rnd_subt	byte

main_rnd

	move.b	main_rnd_highv,d7
	add.b	#1,d7
;	move.b	d7,main_rnd_highv
	sub.b	main_rnd_lowv,d7
	move.b	d7,main_rnd_rndr
;	dec	main_rnd_highv

main_rnd15

	move.w	main_systemclock_c,d7
	add.b	main_rnd_stepr,d7
	move.b	d7,main_rnd_res

;now i should have 0-15 in the bit bucket
;wrap it
;	LSLB
	move.b	d7,main_rnd_stepr

main_rnd_rndl15

	cmp.b	main_rnd_rndr,d7
	bls	main_rnd_rndr15
	sub.b	main_rnd_rndr,d7


	bra	main_rnd_rndl15

main_rnd_rndr15

	add.b	main_rnd_lowv,d7

main_rnd_rnx15

	cmp.b	main_rnd_highv,d7
	bls	main_rnd_rny15
	move.b	main_rnd_stepr,d6
	add.b	#1,d6
	move.b	d6,main_rnd_stepr
	move.b	main_rnd_lowv,d7

main_rnd_rny15

	move.b	d7,main_rnd_res
	rts

endfunction



*********************************************************************************************************************************************************************************************
* main_systemclock()
********************************************************************************************************************************************************************************************
function	main_systemclock
rem	main_systemclock()
rem	used for random number generator
rem	returns value on d7.w

def	main_systemclock_c	word

main_systemclock
	move.w	main_systemclock_c,d7
	add.w	#1,d7
	move.w	d7,main_systemclock_c
	rts
endfunction






*********************************************************************************************************************************************************************************************
* main_scorereset( string pointer.l )
********************************************************************************************************************************************************************************************
function	main_scorereset	main_scorereset_pointer
rem	main_scorereset( pointer.l )
rem	clears the ascii score 10 bytes required
rem	
stack	a6/d7
def	main_scorereset_pointer	long
main_scorereset

	move.l	main_scorereset_pointer,a6
	move.b	#$30,d7
	move.b	d7,(0,a6)
	move.b	d7,(1,a6)
	move.b	d7,(2,a6)
	move.b	d7,(3,a6)
	move.b	d7,(4,a6)
	move.b	d7,(5,a6)
	move.b	d7,(6,a6)
	move.b	d7,(7,a6)
	clr.b	(8,a6)
	clr.b	(9,a6)

	rts
endfunction




*********************************************************************************************************************************************************************************************
* main_scoreadd( target pointer.l pointer.l)
********************************************************************************************************************************************************************************************
function	main_scoreadd	main_scoreadd_p1,main_scoreadd_p2
rem	main_scoreadd( pointer.l , pointer2)
rem	adds the ascii score 10 bytes required
rem	
stack	a6/d7
def	main_scoreadd_p1	long
def	main_scoreadd_p2	long


main_scoreadd
	clr.l	d5
	clr.l	d6
	clr.l	d7
	move.l	main_scoreadd_p1,a6
	move.l	main_scoreadd_p2,a5
	move.b	#7,d7
	move.b	#0,d6
main_scoreadd_lp1
	move.b	(a6,d7),d5
	add.b	(a5,d7),d5
	add.b	d6,d5	;add carry if any
	clr.b	d6	;mt carry
	cmp.b	#57,d5
	bls	main_scoreadd_lpp
	sub.b	#10,d5
	move.b	#1,d6
main_scoreadd_lpp
	move.b	d5,(a6,d7)
	dbra	d7,main_scoreadd_lp1
main_scoreadd_lp2
	clr.b	(8,a6)
	clr.b	(9,a6)
	rts
endfunction






;***********************************************************************************************************************************************************************************************
; main_input_a()
;**********************************************************************************************************************************************************************************************
function	main_input_a
def	main_input_a1	byte
def	main_input_a2	byte
def	main_input_a3	byte
def	main_input_a4	byte
def	main_input_a5	byte
def	main_input_a6	byte
def	main_input_a7	byte
def	main_input_a8	byte
def	main_input_a_data1	byte
def	main_input_a_data2	byte
def	main_input_amouse	byte
def	main_input_amouseinvert	byte

def	main_input_a_mousex	byte
def	main_input_a_mousey	byte

def	main_input_a_mouseposx	word
def	main_input_a_mouseposy	word

def	main_input_a_mposx	word
def	main_input_a_mposy	word

rem	main_input_a()
rem	data is then accessed with these two vars[ main_input_a_data1.b , main_input_a_data2.b ] or d7.w
rem	input returned on d7.w
stack	a6/d6

main_input_a



	cmp.b	#1,main_input_amouse
	beq	main_input_amos
; clear vars
	clr.b	main_input_a1
	clr.b	main_input_a2
	clr.b	main_input_a3
	clr.b	main_input_a4
	clr.b	main_input_a5
	clr.b	main_input_a6
	clr.b	main_input_a7

	clr.b	main_input_a_data1
	clr.b	main_input_a_data2


	move.b	#%01000000,($a10009)	;ctrl one
	move.l	#$a10003,a6	;read and write port

	move.b	#$40,(a6)
	nop
	nop
	move.b	(a6),d7	;first read
	move.b	d7,main_input_a1
	move.b	#$0,(a6)
	nop
	nop
	move.b	(a6),d7	;read 2
	move.b	d7,main_input_a2
	move.b	#$40,(a6)
	nop
	nop
	move.b	(a6),d7	;read 3
	move.b	d7,main_input_a3
	move.b	#$0,(a6)
	nop
	nop
	move.b	(a6),d7	;read 4
	move.b	d7,main_input_a4
	move.b	#$40,(a6)
	nop
	nop
	move.b	(a6),d7	;read 5
	move.b	d7,main_input_a5
	move.b	#$0,(a6)
	nop
	nop
	move.b	(a6),d7	;read 6
	move.b	d7,main_input_a6
	move.b	#$40,(a6)
	nop
	nop
	move.b	(a6),d7	;read 7
	move.b	d7,main_input_a7	
; test for mouse first
	cmp.b	#75,main_input_a1
	bne	main_input_a_mc2
	cmp.b	#11,main_input_a2
	bne	main_input_a_mc2
	bra	main_input_a_ismouse



main_input_a_mc2
	cmp.b	#112,main_input_a1
	bne	main_input_a_notms
	cmp.b	#59,main_input_a2
	bne	main_input_a_notms
main_input_a_ismouse

	move.b	#1,main_input_amouse
; hack


	rts
; not a mouse
main_input_a_notms
; test for sms controller
	move.b	main_input_a1,d6
	and.b	#63,d6
	move.b	main_input_a2,d5
	cmp.b	d6,d5
	beq	main_input_a_segabutton2

; read 6 looking at value 3
	move.b	main_input_a6,d7
	and.b	#3,d7
	bne	main_input_a_segabutton3
; its a 6 button controller

main_input_a_segabutton6
	move.b	main_input_a_data1,d7
	or.b	#128,d7
	move.b	d7,main_input_a_data1
; x,y,z,m
	move.b	main_input_a_data2,d7
	move.b	main_input_a7,d6
	btst	#0,d6
	bne	main_input_a_nopush10
	or.b	#64,d7
main_input_a_nopush10
	btst	#1,d6
	bne	main_input_a_nopush11
	or.b	#32,d7
main_input_a_nopush11
	btst	#2,d6
	bne	main_input_a_nopush12
	or.b	#16,d7
main_input_a_nopush12
	btst	#3,d6
	bne	main_input_a_nopush13
	or.b	#128,d7
main_input_a_nopush13
	move.b	d7,main_input_a_data2

	bra	main_input_a_segabutton33

main_input_a_segabutton3
	move.b	main_input_a_data1,d7
	or.b	#64,d7
	move.b	d7,main_input_a_data1


main_input_a_segabutton33
; handle common buttons
	move.b	main_input_a_data2,d7
	move.b	main_input_a2,d6
	btst	#4,d6
	bne	main_input_a_nopush6
	or.b	#1,d7
main_input_a_nopush6
	btst	#5,d6
	bne	main_input_a_nopush9
	or.b	#8,d7
main_input_a_nopush9

	move.b	main_input_a1,d6
	btst	#4,d6
	bne	main_input_a_nopush7
	or.b	#2,d7
main_input_a_nopush7
	btst	#5,d6
	bne	main_input_a_nopush8
	or.b	#4,d7
main_input_a_nopush8



	move.b	d7,main_input_a_data2
	bra	main_input_a_exit

main_input_a_segabutton2
; sms controller
; needs a,b
	move.b	main_input_a1,d6
	move.b	main_input_a_data2,d7
	btst	#4,d6
	bne	main_input_a_nopush4
	or.b	#1,d7
main_input_a_nopush4
	btst	#5,d6
	bne	main_input_a_nopush5
	or.b	#2,d7
main_input_a_nopush5



	move.b	d7,main_input_a_data2

	move.b	main_input_a_data1,d7
	or.b	#32,d7
	move.b	d7,main_input_a_data1
	bra	main_input_a_exit



main_input_a_exit

; fill direction same for all controllers
	move.b	main_input_a1,d6
	move.b	main_input_a_data1,d7

	btst	#0,d6
	bne	main_input_a_nopush0
	or.b	#1,d7
main_input_a_nopush0
	btst	#1,d6
	bne	main_input_a_nopush1
	or.b	#2,d7
main_input_a_nopush1
	btst	#2,d6
	bne	main_input_a_nopush2
	or.b	#4,d7
main_input_a_nopush2
	btst	#3,d6
	bne	main_input_a_nopush3
	or.b	#8,d7
main_input_a_nopush3
	and.l	#255,d7
	move.b	d7,main_input_a_data1
	lsl.w	#8,d7
	add.b	main_input_a_data2,d7

	rts




; mouse code
main_input_amos
	move.l	#$a10009,a5
	move.l	#$a10003,a6
; ok ready
	move.b	#$60,(a5)


; counter
	move.b	#20,d7
	move.b	#$60,(a6)
	nop
	nop
main_input_a_mcc1
	sub.b	#1,d7
	beq	main_input_a_mac1
	move.b	(a6),main_input_a1	;1 read
	btst	#4,main_input_a1
	bne	main_input_a_mcc1
main_input_a_mac1


; counter
	move.b	#20,d7
	move.b	#$20,(a6)
	nop
	nop
main_input_a_mcc2
	sub.b	#1,d7
	beq	main_input_a_mac2
	move.b	(a6),main_input_a1	;2 read
	btst	#4,main_input_a1
	bne	main_input_a_mcc2
main_input_a_mac2


; counter
	move.b	#20,d7
	move.b	#$0,(a6)
	nop
	nop
main_input_a_mcc3
	sub.b	#1,d7
	beq	main_input_a_mac3
	move.b	(a6),main_input_a1	;3 read
	btst	#4,main_input_a1
	bne	main_input_a_mcc3
main_input_a_mac3



; counter
	move.b	#20,d7
	move.b	#$20,(a6)
	nop
	nop
main_input_a_mcc4
	sub.b	#1,d7
	beq	main_input_a_mac4
	move.b	(a6),main_input_a1	;4 read
	cmp.b	#63,main_input_a1
	bne	main_input_a_mcc4
main_input_a_mac4


; counter
	move.b	#20,d7
	move.b	#$0,(a6)
	nop
	nop
main_input_a_mcc5
	sub.b	#1,d7
	beq	main_input_a_mac5
	move.b	(a6),main_input_a1	;5 read
	btst	#4,main_input_a1
	bne	main_input_a_mcc5
main_input_a_mac5


; counter
	move.b	#20,d7
	move.b	#$20,(a6)
	nop
	nop
main_input_a_mcc6
	sub.b	#1,d7
	beq	main_input_a_mac6
	move.b	(a6),main_input_a2	;6 read
	btst	#4,main_input_a2
	beq	main_input_a_mcc6
main_input_a_mac6

; counter
	move.b	#20,d7
	move.b	#$0,(a6)
	nop
	nop
main_input_a_mcc7
	sub.b	#1,d7
	beq	main_input_a_mac7
	move.b	(a6),main_input_a3	;7 read
	btst	#4,main_input_a3
	bne	main_input_a_mcc7
main_input_a_mac7


; counter
	move.b	#20,d7
	move.b	#$20,(a6)
	nop
	nop
main_input_a_mcc8
	sub.b	#1,d7
	beq	main_input_a_mac8
	move.b	(a6),main_input_a4	;8 read
	btst	#4,main_input_a4
	beq	main_input_a_mcc8
main_input_a_mac8


; counter
	move.b	#20,d7
	move.b	#$0,(a6)
	nop
	nop
main_input_a_mcc9
	sub.b	#1,d7
	beq	main_input_a_mac9
	move.b	(a6),main_input_a5	;9 read
	btst	#4,main_input_a5
	bne	main_input_a_mcc9
main_input_a_mac9

; counter
	move.b	#20,d7
	move.b	#$20,(a6)
	nop
	nop
main_input_a_mcc10
	sub.b	#1,d7
	beq	main_input_a_mac10
	move.b	(a6),main_input_a6	;10 read
	btst	#4,main_input_a6
	beq	main_input_a_mcc10
main_input_a_mac10


; counter
; end
	move.b	#$60,(a6)


; unplugged mouse?
	cmp.b	#31,main_input_a1
	bne	main_input_a_mousedata
	cmp.b	#63,main_input_a2
	bne	main_input_a_mousedata
	bra	main_input_a_msunplug
; check emulation
	cmp.b	#51,main_input_a1
	bne	main_input_a_mousedata
	cmp.b	#51,main_input_a2
	bne	main_input_a_mousedata

main_input_a_msunplug
; ok mouse unplugged
	move.b	#0,main_input_amouse
	move.l	#$a10009,a5
	move.b	#$40,(a5)
	move.b	#$40,(a6)

	rts

main_input_a_mousedata
; ok lets piece this together
	and.b	#15,main_input_a3
	and.b	#15,main_input_a4
	and.b	#15,main_input_a5
	and.b	#15,main_input_a6
	move.b	main_input_a3,d7
	lsl.b	#4,d7
	add.b	main_input_a4,d7
	move.b	d7,main_input_a_mousex

	move.b	main_input_a5,d7
	lsl.b	#4,d7
	add.b	main_input_a6,d7
	move.b	d7,main_input_a_mousey

;math
	move.b	main_input_a1,d7
	btst	#0,d7
	bne	main_input_a_addmx1
	move.b	main_input_a_mousex,d7
	and.w	#255,d7

	lsr.b	#1,d7
	add.w	d7,main_input_a_mouseposx
	
	bra	main_input_a_mxd1
main_input_a_addmx1
	move.b	#255,d7
	sub.b	main_input_a_mousex,d7

	and.w	#255,d7
	lsr.b	#1,d7
	sub.w	d7,main_input_a_mouseposx
main_input_a_mxd1

; mouse y invert?
	move.b	main_input_amouseinvert,d7
	beq	main_input_a_msy2
	move.b	main_input_a1,d7
	btst	#1,d7
	bne	main_input_a_addmy1
	move.b	main_input_a_mousey,d7
	and.w	#255,d7

	lsr.b	#1,d7
	add.w	d7,main_input_a_mouseposy
	
	bra	main_input_a_myd1
main_input_a_addmy1
	move.b	#255,d7
	sub.b	main_input_a_mousey,d7

	and.w	#255,d7
	lsr.b	#1,d7
	sub.w	d7,main_input_a_mouseposy
main_input_a_myd1
	bra	main_input_a_mousbutt
; inverted mouse y
main_input_a_msy2


	move.b	main_input_a1,d7
	btst	#1,d7
	bne	main_input_a_addmy2

	move.b	main_input_a_mousey,d7
	and.w	#255,d7
	lsr.b	#1,d7
	sub.w	d7,main_input_a_mouseposy

	bra	main_input_a_myd2
main_input_a_addmy2
	move.b	#255,d7
	sub.b	main_input_a_mousey,d7

	and.b	#255,d7
	lsr.b	#1,d7
	add.w	d7,main_input_a_mouseposy
main_input_a_myd2



main_input_a_mousbutt
	move.w	main_input_a_mouseposx,d7
;	divu.w	#3,d7
;	mulu.w	#2,d7
	move.w	d7,main_input_a_mposx

	move.w	main_input_a_mouseposy,d7
;	divu.w	#3,d7
;	mulu.w	#2,d7
	move.w	d7,main_input_a_mposy




	rts
endfunction



;***********************************************************************************************************************************************************************************************
; main_input_b()
;**********************************************************************************************************************************************************************************************
function	main_input_b
def	main_input_b1	byte
def	main_input_b2	byte
def	main_input_b3	byte
def	main_input_b4	byte
def	main_input_b5	byte
def	main_input_b6	byte
def	main_input_b7	byte
def	main_input_b8	byte
def	main_input_b_data1	byte
def	main_input_b_data2	byte


rem	main_input_b()
rem	data is then accessed with these two vars[ main_input_b_data1 , main_input_b_data2 ] or d7.w
rem	returns data on d7.w
stack	a6/d6
main_input_b

; clear all vars


	clr.b	main_input_b1
	clr.b	main_input_b2
	clr.b	main_input_b3
	clr.b	main_input_b4
	clr.b	main_input_b5
	clr.b	main_input_b6
	clr.b	main_input_b7

	clr.b	main_input_b_data1
	clr.b	main_input_b_data2


	move.b	#%01000000,($a1000b)	;ctrl two
	move.l	#$a10005,a6

	move.b	#$40,(a6)
	nop
	nop
	move.b	(a6),d7	;first read
	move.b	d7,main_input_b1
	move.b	#$0,(a6)
	nop
	nop
	move.b	(a6),d7	;read 2
	move.b	d7,main_input_b2
	move.b	#$40,(a6)
	nop
	nop
	move.b	(a6),d7	;read 3
	move.b	d7,main_input_b3
	move.b	#$0,(a6)
	nop
	nop
	move.b	(a6),d7	;read 4
	move.b	d7,main_input_b4
	move.b	#$40,(a6)
	nop
	nop
	move.b	(a6),d7	;read 5
	move.b	d7,main_input_b5
	move.b	#$0,(a6)
	nop
	nop
	move.b	(a6),d7	;read 6
	move.b	d7,main_input_b6
	move.b	#$40,(a6)
	nop
	nop
	move.b	(a6),d7	;read 7
	move.b	d7,main_input_b7	
; test for sms controller
	move.b	main_input_b1,d6
	and.b	#63,d6
	move.b	main_input_b2,d5
	cmp.b	d6,d5
	beq	main_input_b_segabutton2

; read 6 looking at value 3
	move.b	main_input_b6,d7
	and.b	#3,d7
	bne	main_input_b_segabutton3
; its a 6 button controller

main_input_b_segabutton6
	move.b	main_input_b_data1,d7
	or.b	#128,d7
	move.b	d7,main_input_b_data1
; x,y,z,m
	move.b	main_input_b_data2,d7
	move.b	main_input_b7,d6
	btst	#0,d6
	bne	main_input_b_nopush10
	or.b	#64,d7
main_input_b_nopush10
	btst	#1,d6
	bne	main_input_b_nopush11
	or.b	#32,d7
main_input_b_nopush11
	btst	#2,d6
	bne	main_input_b_nopush12
	or.b	#16,d7
main_input_b_nopush12
	btst	#3,d6
	bne	main_input_b_nopush13
	or.b	#128,d7
main_input_b_nopush13
	move.b	d7,main_input_b_data2

	bra	main_input_b_segabutton33

main_input_b_segabutton3
	move.b	main_input_b_data1,d7
	or.b	#64,d7
	move.b	d7,main_input_b_data1


main_input_b_segabutton33
; handle common buttons
	move.b	main_input_b_data2,d7
	move.b	main_input_b2,d6
	btst	#4,d6
	bne	main_input_b_nopush6
	or.b	#1,d7
main_input_b_nopush6
	btst	#5,d6
	bne	main_input_b_nopush9
	or.b	#8,d7
main_input_b_nopush9

	move.b	main_input_b1,d6
	btst	#4,d6
	bne	main_input_b_nopush7
	or.b	#2,d7
main_input_b_nopush7
	btst	#5,d6
	bne	main_input_b_nopush8
	or.b	#4,d7
main_input_b_nopush8



	move.b	d7,main_input_b_data2
	bra	main_input_b_exit

main_input_b_segabutton2
; sms controller
; needs a,b
	move.b	main_input_b1,d6
	move.b	main_input_b_data2,d7
	btst	#4,d6
	bne	main_input_b_nopush4
	or.b	#1,d7
main_input_b_nopush4
	btst	#5,d6
	bne	main_input_b_nopush5
	or.b	#2,d7
main_input_b_nopush5



	move.b	d7,main_input_b_data2

	move.b	main_input_b_data1,d7
	or.b	#32,d7
	move.b	d7,main_input_b_data1
	bra	main_input_b_exit



main_input_b_exit

; fill direction same for all controllers
	move.b	main_input_b1,d6
	move.b	main_input_b_data1,d7

	btst	#0,d6
	bne	main_input_b_nopush0
	or.b	#1,d7
main_input_b_nopush0
	btst	#1,d6
	bne	main_input_b_nopush1
	or.b	#2,d7
main_input_b_nopush1
	btst	#2,d6
	bne	main_input_b_nopush2
	or.b	#4,d7
main_input_b_nopush2
	btst	#3,d6
	bne	main_input_b_nopush3
	or.b	#8,d7
main_input_b_nopush3
	and.l	#255,d7
	move.b	d7,main_input_b_data1
	lsl.w	#8,d7
	add.b	main_input_b_data2
	rts
endfunction








;
; ***********************************************************************************************************************************************************************************************
; * main_stringbin(byte address,retstring adr)
; ***********************************************************************************************************************************************************************************************
; convert number to string
; put numbers in for string add
; 
function	main_stringbin	main_stringbin_numsta,main_stringbin_x
rem	main_stringbin(byte.b , return_string.l )
rem	byte is a value of 0-255 and needs a return address to populate string. 10 BYTES REQUIRED
rem	
stack	a6/d7
def	main_stringbin_x	long	;populate x register with string at x
def	main_stringbin_numsta	byte	;save 
def	main_stringbin_dummy	byte

main_stringbin

	move.b	main_stringbin_numsta,d7
	move.l	main_stringbin_x,a6
	move.b	#$30,(0,a6)
	btst	#7,d7
	beq	main_stringbin_test7
	move.b	#$31,(0,a6)
main_stringbin_test7
	move.b	#$30,(1,a6)
	btst	#6,d7
	beq	main_stringbin_test6
	move.b	#$31,(1,a6)
main_stringbin_test6
	move.b	#$30,(2,a6)
	btst	#5,d7
	beq	main_stringbin_test5
	move.b	#$31,(2,a6)
main_stringbin_test5
	move.b	#$30,(3,a6)
	btst	#4,d7
	beq	main_stringbin_test4
	move.b	#$31,(3,a6)
main_stringbin_test4
	move.b	#$30,(4,a6)
	btst	#3,d7
	beq	main_stringbin_test3
	move.b	#$31,(4,a6)
main_stringbin_test3
	move.b	#$30,(5,a6)
	btst	#2,d7
	beq	main_stringbin_test2
	move.b	#$31,(5,a6)
main_stringbin_test2
	move.b	#$30,(6,a6)
	btst	#1,d7
	beq	main_stringbin_test1
	move.b	#$31,(6,a6)
main_stringbin_test1
	move.b	#$30,(7,a6)
	btst	#0,d7
	beq	main_stringbin_test0
	move.b	#$31,(7,a6)
main_stringbin_test0
	move.b	#0,(8,a6)
	move.b	#0,(9,a6)
	rts
endfunction





; **********************************************************************************************************************
; * sega_create_sincos( pointer.l)
; **********************************************************************************************************************
function	sega_create_sincos	sega_create_sincos_pointer

rem	sega_create_sincos( return pointer.l )
rem	this table is needed for rotational graphics such as circle
rem	
stack	a6
def	sega_create_sincos_pointer	long

sega_create_sincos_table

; word values

;	dc.w	128,131,134,137,140,143,146,149,152,155,158,162,165,167,170,173	; 16
;	dc.w	176,179,182,185,188,190,193,196,198,201,203,206,208,211,213,215	; 32
;	dc.w	218,220,222,224,226,228,230,232,233,235,237,238,240,241,243,244	; 48
;	dc.w	245,246,247,248,249,250,251,252,252,253,253,254,254,254,254,255	; 64
;	dc.w	255,254,254,254,254,253,253,252,252,251,250,250,249,248,247,246	; 80
;	dc.w	244,243,242,240,239,237,236,234,232,231,229,227,225,223,221,219	; 96
;	dc.w	216,214,212,210,207,205,202,200,197,194,192,189,186,183,181,178	; 112
;	dc.w	175,172,169,166,163,160,157,154,151,148,145,142,138,135,132,128	; 128
;	dc.w	126,124,121,118,114,111,108,105,102,99,96,93,90,87,84,81	; 144
;	dc.w	78,75,73,70,67,64,62,59,56,54,51,49,46,44,42,40	; 160
;	dc.w	37,35,33,31,29,27,25,24,22,20,19,17,16,14,13,12	; 176
;	dc.w	10,9,8,7,6,5,4,3,3,2,2,2,1,1,0,0	; 192
;	dc.w	0,1,1,2,2,2,3,3,4,5,6,7,8,9,10,11	; 208
;	dc.w	12,13,15,16,18,19,21,23,24,26,28,30,32,34,36,38	; 224
;	dc.w	41,43,45,48,50,53,55,58,60,63,66,68,71,74,77,80	; 240
;	dc.w	83,86,89,91,94,98,101,104,107,110,113,116,119,122,125,128	; 256

	dc.w	$80,$83,$86,$89,$8C,$90,$93,$96,$99,$9C,$9F,$A2,$A5,$A8,$AB,$AE
	dc.w	$B1,$B3,$B6,$B9,$BC,$BF,$C1,$C4,$C7,$C9,$CC,$CE,$D1,$D3,$D5,$D8
	dc.w	$DA,$DC,$DE,$E0,$E2,$E4,$E6,$E8,$EA, $EB, $ED, $EF, $F0, $F1, $F3, $F4
	dc.w	$F5, $F6, $F8, $F9, $FA, $FA, $FB, $FC,$FD, $FD, $FE, $FE, $FE, $FF, $FF, $FF
	dc.w	$FF, $FF, $FF, $FF, $FE, $FE, $FE, $FD,$FD, $FC, $FB, $FA, $FA, $F9, $F8, $F6
	dc.w	$F5, $F4, $F3, $F1, $F0, $EF, $ED, $EB,$EA, $E8, $E6, $E4, $E2, $E0, $DE, $DC
	dc.w	$DA, $D8, $D5, $D3, $D1, $CE, $CC, $C9,$C7, $C4, $C1, $BF, $BC, $B9, $B6, $B3
	dc.w	$B1, $AE, $AB, $A8, $A5, $A2, $9F, $9C,$99, $96, $93, $90, $8C, $89, $86, $83
	dc.w	$80, $7D, $7A, $77, $74, $70, $6D, $6A,$67, $64, $61, $5E, $5B, $58, $55, $52
	dc.w	$4F, $4D, $4A, $47, $44, $41, $3F, $3C,$39, $37, $34, $32, $2F, $2D, $2B, $28
	dc.w	$26, $24, $22, $20, $1E, $1C, $1A, $18,$16, $15, $13, $11, $10, $0F, $0D, $0C
	dc.w	$0B, $0A, $08, $07, $06, $06, $05, $04,$03, $03, $02, $02, $02, $01, $01, $01
	dc.w	$01, $01, $01, $01, $02, $02, $02, $03,$03, $04, $05, $06, $06, $07, $08, $0A
	dc.w	$0B, $0C, $0D, $0F, $10, $11, $13, $15,$16, $18, $1A, $1C, $1E, $20, $22, $24
	dc.w	$26, $28, $2B, $2D, $2F, $32, $34, $37,$39, $3C, $3F, $41, $44, $47, $4A, $4D
	dc.w	$4F, $52, $55, $58, $5B, $5E, $61, $64,$67, $6A, $6D, $70, $74, $77, $7A, $7D

sega_create_sincos

	move.l	sega_create_sincos_pointer,a6
	move.l	#sega_create_sincos_table,(a6)
	
	rts

endfunction



; **********************************************************************************************************************
; * sega_math_plot(sin_costable,x1,y1,dx,dy,angle)
; * 
; **********************************************************************************************************************
function	sega_math_plot	sega_math_plot_sine,sega_math_plot_x,sega_math_plot_y,sega_math_plot_radx,sega_math_plot_rady,sega_math_plot_angle
rem	sega_math_plot( sine_table_pointer.l , pos_x1.w , pos_y1.w ,diamx.w , diamy.w , angle.w)
rem	
rem	results returned at x=d6.w, y=d7.w
stack	a5-a6/d5
def	sega_math_plot_sine	long
def	sega_math_plot_angle	word
def	sega_math_plot_x	word
def	sega_math_plot_y	word
def	sega_math_plot_radx	word
def	sega_math_plot_rady	word

sega_math_plot

;	move.w	sega_math_plot_angle,d7
;	add.b	#1,d7
;	move.w	d7,sega_math_plot_angle

	clr.w	d7
	clr.w	d6
	move.l	sega_math_plot_sine,a6	;sinetable
	move.w	sega_math_plot_angle,d7
	and.w	#$ff,d7
	mulu.w	#2,d7
	lea	(a6,d7.w),a6

	move.l	sega_math_plot_sine,a5	;cosinetable
	move.w	sega_math_plot_angle,d7
	add.b	#64,d7
	mulu.w	#2,d7
	
	lea	(a5,d7.w),a5

; both tables should be good
	
	
	move.w	(a6),d7
	move.w	sega_math_plot_radx,d6
	mulu.w	d6,d7

	move.b	d7,d6	;b on d6
	lsr.w	#8,d7	;a on d7
	and.w	#255,d7
	asl.b	#1,d6
	roxl.b	#1,d7
	
	add.w	sega_math_plot_x,d7
;	add.w	#1,d7

	sub.w	sega_math_plot_radx,d7
	move.w	d7,d5	;x temp
	
	move.w	(a5),d7
	move.w	sega_math_plot_rady,d6
	add.w	#1,d7
	mulu.w	d6,d7

	move.b	d7,d6	;b on d6
	lsr.w	#8,d7	;a on d7
	and.w	#255,d7
	asl.b	#1,d6
	roxl.b	#1,d7
	

	add.w	sega_math_plot_y,d7
;	add.w	#1,d7
	sub.w	sega_math_plot_rady,d7

	move.w	d5,d6
	rts
endfunction


























