
; Listing18j.s = clip.POLY6ok.s

****************************************************************************
	SECTION	exe000000,CODE_C
ProgStart:
	MOVEM.L	D1-D7/A0-A6,-(SP)
	MOVEA.L	4,A6
	JSR	-$84(A6)
	LEA	GFX(PC),A1
	MOVEQ	#0,D0
	JSR	-$228(A6)
	TST.L	D0
	beq.w	GFXERR
	MOVEA.L	D0,A1
	LEA	SYSINFO(PC),A5
	MOVE.L	$26(A1),8(A5)
	MOVE.L	$32(A1),12(A5)
	JSR	-$19E(A6)
	LEA	$DFF000,A6
	BTST	#6,2(A6)
BW__001:
	BTST	#6,2(A6)
	BNE.S	BW__001
VB1__002:
	BTST	#0,5(A6)
;	BEQ.S	VB1__002
VB2__002:
	BTST	#0,5(A6)
;	BNE.S	VB2__002
	MOVE.W	$1C(A6),(A5)
	MOVE.W	2(A6),2(A5)
	MOVE.W	#$7FFF,$9A(A6)
	MOVE.W	#$7FFF,$96(A6)
	MOVE.L	$6C,4(A5)
	bsr.w	_BOOT
	LEA	$DFF000,A6
	LEA	SYSINFO(PC),A5
	MOVE.L	4(A5),$6C
	MOVE.L	8(A5),$80(A6)
	MOVE.L	12(A5),$84(A6)
	MOVE.W	(A5),D0
	ORI.W	#$C000,D0
	MOVE.W	D0,$9A(A6)
	MOVE.W	2(A5),D0
	ORI.W	#$8100,D0
	MOVE.W	D0,$96(A6)
GFXERR:
	MOVEA.L	4,A6
	JSR	-$8A(A6)
	MOVEM.L	(SP)+,D1-D7/A0-A6
	MOVEQ	#0,D0
	RTS

GFX:
	dc.b	'graphics.library',0,0
SYSINFO:
	dcb.l	$4,0

LOADPOINTERS:
	MOVEM.L	D0/D1/A0/A1,-(SP)
	SUBQ.L	#1,D1
	MOVE.L	A0,D0
NXTPLANE:
	MOVE.W	D0,4(A1)
	SWAP	D0
	MOVE.W	D0,(A1)
	SWAP	D0
	ADD.L	D2,D0
	ADDQ.L	#8,A1
	DBRA	D1,NXTPLANE
	MOVEM.L	(SP)+,D0/D1/A0/A1
	RTS

_BOOT:
	LEA	$DFF000,A6
VB1__003:
	BTST	#0,5(A6)
;	BEQ.S	VB1__003
VB2__003:
	BTST	#0,5(A6)
;	BNE.S	VB2__003
	MOVE.W	#$87C0,$96(A6)
	BSR.S	SETCOPPER
	MOVE.L	#MY_COPPER,$80(A6)
	MOVE.W	D0,$88(A6)
	move.w	#0,$1fc(a6)
	MOVE.L	#MY_VBI,$6C
	MOVE.L	#$C0207FFF,$9A(A6)
MLP:
	bsr.w	DBUFFER
	bsr.w	DOANIM
	bsr.w	PLOTPOLYS
	bsr.w	FILLVPLANE
	CMPI.W	#2,ANIMPOS
	BEQ.S	QUIT
	BTST	#6,$BFE001
	BNE.S	MLP
QUIT:
	RTS

MY_VBI:
	MOVEM.L	D0-D7/A0-A6,-(SP)
	LEA	$DFF000,A6
	MOVE.W	#$4020,$9C(A6)
	MOVEM.L	(SP)+,D0-D7/A0-A6
	RTE

SETCOPPER:
	LEA	SCREEN,A0
	LEA	PLPTR1(PC),A1
	MOVEQ	#2,D1
	MOVE.W	#$2C,D2
	bsr.w	LOADPOINTERS
	RTS

MY_COPPER:
	dc.l	$8E2A71,$9036D1,$920030,$9400D8,$1002200,$1020000
	dc.l	$1040000,$108002C,$10A002C
	dc.w	$180
COLPTR1:
	dc.w	0,$182,$855,$184,$585,$186,$558,$E0
PLPTR1:
	dc.w	0,$E2,0,$E4,0,$E6,0,$FFFF,$FFFE

DBUFFER:
	BTST	#6,2(A6)
BW__004:
	BTST	#6,2(A6)
	BNE.S	BW__004
	MOVE.L	D0,-(SP)
CP__005:
	MOVE.L	4(A6),D0
	ROR.L	#8,D0
	CMP.W	#$138,D0
	BNE.S	CP__005
	MOVE.L	(SP)+,D0
	CMPI.L	#SCREEN,VECTPLPTR
	BEQ.S	DBUFFSCRN2
	MOVEA.L	#SCREEN2,A0
	MOVE.L	#SCREEN,VECTPLPTR
	BRA.S	DBUFFPUTIT

DBUFFSCRN2:
	MOVE.L	#SCREEN2,VECTPLPTR
	MOVEA.L	#SCREEN,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w	$19
ANIMPOS:
	dc.w	0
VECTSIZE:
	dc.w	$100
XCENTRE:
	dc.w	$B0
YCENTRE:
	dc.w	$86
POLYPTRLIST:
	dc.l	POLY1,$8000
POLY1:
	dc.w	2,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11
	dc.w	11,12,12,13,13,14,14,15,15,0,$8001
SRCCOORDS:
	dc.w	$FFEC,0,$FFD8,$14,$FFD8,$28,$FFEC,$28,0,$14,$14
	dcb.w	$4,$28
	dcb.w	$2,$14
	dc.w	0,$28,$FFEC,$28,$FFD8,$14,$FFD8,0,$FFEC,$FFEC
	dcb.w	$4,$FFD8
	dc.w	$FFEC,$8000
POINTLIST:
	dcb.l	$3F,0
	dcb.l	$25,0
EDGEDLIST:
	dcb.l	$3F,0
	dcb.l	$3F,0
	dcb.l	$3F,0
	dcb.l	$3F,0
	dcb.l	$30,0
VECTPLPTR:
	dc.l	SCREEN

	SECTION	exe000C5C,BSS_c
	ds.l	$16
SCREEN:
	ds.l	$1708
SCREEN2:
	ds.l	$171E
	end
