* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
*                            3D_01.S                          *
*                     FAST FILLING A POLYGON                    *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This is the program you should assemble. It INCLUDEs all the others.

*	SECTION TEXT
	opt	d+		put in labels for debugging
	bra	main		don't execute the INCLUDEs
	include	core_00.s	and all the subroutines

* Here's the program
main	bsr	init_LineA	fetch the parameters pointer
	dc.w	$a00a		hide the mouse
*Transfer my program data to the program data block
	move.w	#12-1,d7	6 pairs of points for polygon vertices (-1)
	lea	crds_in,a0	to be moved here
	lea	my_data,a1	from here
loop1_1	move.w	(a1)+,(a0)+	Transfer
	dbra	d7,loop1_1	them all.
	move.w	#5,no_in	5 sides to the polygon

* 6 different colour palettes altogether
loop2_1	move.w	#5,d7		6 colour palettes (-1)
	
* Do the next palette
loop3_1	lea	pal_base,a0	the palette table base address
	move	d7,d6		index to next 
	lsl.w	#5,d6		palette	
	pea	0(a0,d6.w)	at this address
	move.w	#6,-(sp)	ready for SETPALETTE 
	trap	#14		XBIOS call
	add.w	#6,sp		tidy stack
	move.w	d7,-(sp)	save palette counter

* do the next colour in this 14-colour palette
	move.w	#13,d7		colour counter
loop4_1	move	d7,d6		save it
	addq	#2,d6		top colour is #15
	move.w	d6,colour	this is the colour
	move.w	d7,-(sp)	save colour counter
	bsr	poly_fil	set up the buffer and fill it
	move.w	(sp)+,d7	restore colour counter
	dbra	d7,loop4_1	for all the colours in this palette
	move.w	(sp)+,d7	restore palette counter
	dbra	d7,loop3_1	for all palettes
	bra	loop2_1		go round again

*	SECTION DATA
* A pentagon. Here are the vertices (first one repeated at end)
* in screen coordinates.
my_data		dc.w	20,100,200,20,300,80,260,180,140,180,20,100

* Here are the colour palettes. The first three colours are black
* for the border and background.
pal_base:
* #6; red to magenta
	dc.w	$0,$0,$0,$700,$700,$701,$701,$702,$702,$703,$703
	dc.w	$704,$704,$705,$705,$706
* #5; magenta to blue
	dc.w	$0,$0,$0,$707,$707,$607,$607,$507,$507,$407,$407
	dc.w	$307,$307,$207,$207,$107
* #4; blue to cyan
	dc.w	$0,$0,$0,$007,$007,$017,$017,$027,$027,$037,$037
	dc.w	$047,$047,$057,$057,$067
* #3; cyan to green
	dc.w	$0,$0,$0,$077,$077,$076,$076,$075,$075,$075,$075
	dc.w	$074,$074,$073,$072,$071
* #2; green to yellow
	dc.w	$0,$0,$0,$070,$170,$170,$270,$270,$370,$370,$470
	dc.w	$470,$570,$570,$670,$670	
* #1; yellow to red
	dc.w	$0,$0,$0,$770,$770,$760,$760,$750,$750,$740,$740
	dc.w	$730,$730,$720,$710,$710

	include	data_00.s	list of constants
	
*	SECTION BSS
	include	bss_00.s	variables generated by program

	END
