cos = 	$40000	;512
sin = 	$40200	;512
screen =$40400	;8800
screen2=$40400+8800
>extern "df0:FylldBpl.sin",cos
s:
	bsr.L	b
	move.w	#31,d0
	lea	$dff180,a0
s1:	move.w	#$000,(a0)+
	dbf	d0,s1

	move.w	#$8400,$dff096	;Blitter nasty
	move.w	#$4000,$dff09a	;inget irq
	move.l	#cop,$dff080	;cop på

main:	btst	#6,$bfe001
	beq.s	slut
tst:	btst	#2	,$dff016
	bne	tst	
wait1:	cmp.b	#220,$dff006	;Rasterrad nr.
	bne.s	wait1

	move.w	#$0f0,$dff180

	Move.l	#$ffffffff	,$dff044
	bsr	b
	bsr	a
	move.w	#$000,$dff180
	move.w	klipp,$dff180
	Clr.w	klipp
	bra.s	main

slut:	move.l	4,a6	;cop reset
	move.l	(a6),a6
	move.l	(a6),a6
	move.l	$26(a6),$dff080
	move.w	#$8020,$dff096
	move.w	#$c000,$dff09a
	rts

;---------------------------------------- VEKTORISERANDE
a:
	lea	cos,a0
	lea	sin,a1
	move.w	x_rad,d0
	move.w	x_rad+2,d1

	lea	oldx,a2
	lea	xp,a3

	moveq	#7,d7
con_lop1:
	move.w	(a2)+,d2		;x
	move.w	14(a2),d4		;y
	move.w	30(a2),d3		;z

	move.w	d2,d6
	muls	(a0,d0),d2	;x=x*cos(v)*100
	asr.l	#8,d2		;x=x/100
	move.w	d3,d5
	muls	(a1,d0),d5	;y=y*sin(v)*100
	asr.l	#8,d5		;y=y/100
	sub.w	d5,d2		;x=x*cos(v)-y*sin(v)

	muls	(a1,d0),d6	;x=x*sin(v)*100
	asr.l	#8,d6		;x=x/100

	muls	(a0,d0),d3	;y=y*cos(v)*100
	asr.l	#8,d3		;y=y/100
	add.w	d6,d3		;x=x*sin(v)+y*cos(v)



	move.w	d4,d6
	muls	(a0,d0),d4	;x=x*cos(v)*100
	asr.l	#8,d4		;x=x/100
	move.w	d3,d5
	muls	(a1,d0),d5	;y=y*sin(v)*100
	asr.l	#8,d5		;y=y/100
	sub.w	d5,d4		;x=x*cos(v)-y*sin(v)

	muls	(a1,d0),d6	;x=x*sin(v)*100
	asr.l	#8,d6		;x=x/100

	muls	(a0,d0),d3	;y=y*cos(v)*100
	asr.l	#8,d3		;y=y/100
	add.w	d6,d3		;x=x*sin(v)+y*cos(v)




;	x=x*zm/(z+zm)
;	y=y*zm/(z+zm)

	muls	#zm,d2
	muls	#zm,d4
	add.w	#zm,d3
	bne.s	test_if_zero	;STOPS GURU,CAN'T DIVIDE WITH ZERO
	addq.w	#1,d3
test_if_zero:
	move.w	d3,d5
	divs	d3,d2
	divs	d5,d4
	
	add.w	#160,d2		;Fix X-cord
	add.w	#100,d4		;Fix Y-cord

	move.w	d2,(a3)+
	move.w	d4,14(a3)
	dbf	d7,con_lop1

	moveq	#3	,d7
	lea	lines	,a3
	lea	xp	,A4
	add.w	12(a3)	,a4
	Move.w	16(a4)	,buffer	
draw_lop1:
	lea	xp,a4
	add.w	(a3)+,a4
	lea	xp,a5
	add.w	(a3)+,a5
	move.w	(a4),d0		;Xstart
	move.w	16(a4),d1	;Ystart
	move.w	(a5),d2		;Xend
	move.w	16(a5),d3	;Yend
	bsr.L	DrawLine
	dbf	d7,draw_lop1

	add.w	#$02,x_rad
	and.w	#$01ff,x_rad
	bsr	fill
rts
zm =	200

xp:	blk.w	8
yp:	blk.w	8

x_rad:	dc.w	8,0

oldx:	dc.w	-40,40,40,-40			;POINTS
	dc.w	-40,40,40,-40
oldy:	dc.w	-40,-40,40,40
	dc.w	-40,-40,40,40
oldz:	dc.w	-40,-40,-40,-40
	dc.w	40,40,40,40

lines:	dc.w	0,2	,2,4	,4,6	,6,0	;LINES
	dc.w	8,10	,10,12	,12,14	,14,8
	dc.w	0,8	,2,10	,4,12	,6,14
OldYStart:
	dc.w	0
OldYEnd:
	dc.w	0
;----------------------------------------
b:
	btst	#14,$dff002
	bne.s	b

	move.l	#$01000000,$dff040
	move.l	#screen+[25*44]+0,$dff054
	move.w	#0,$dff066
	move.w	#[170*64]+20,$df0058
	rts
;----------------------------------------------------
Fill:
	btst	#14,$dff002
	bne.s	Fill
	move.l	#screen+[44*190]+28,a0
	move.w	#24,d0
	move.l	a0,$dff050
	move.l	a0,$dff054
	move.w	d0,$dff064
	move.w	d0,$dff066
	move.l	#$0ff00012,$dff040
	move.w	#[170*64]+10,$df0058
	rts
;---------------------------------------- SCROLL

cop:	dc.w	$108,4,$10a,4,$100,$3200
	dc.w	$102,0,$104,0,$92,$30,$94,$d8,$96,$8380,$96,$20
	dc.w	$180,$000,$182,$f00,$184,$0f0,$186,$00f,$188,$b70
	dc.w	$18a,$c90,$18c,$ec0,$18e,$ff0,$8e,$2471,$90,$44d1
	dc.w	$e0,4,$e2,0
	dc.w	$e4,4,$e6,0
	dc.w	$e8,4,$ea,0

	dc.w	$100,$2200,$108,0,$10a,0
	dc.w	$00e0,4,$00e2,screen-2+[18*44]
	dc.w	$00e4,4,$00e6,screen2-2+[18*44]

	dc.w	$4607,$fffe,$180,$000
	dc.w	$ffff,$fffe
;----------------------------------------------------
;	PlotRoutine
;	d0.w=x	d1.w=y	d2.w=modulo	a0=screen
;----------------------------------------------------
PlotIt:	mulu	d2,d1
	add.l	d1,a0	
	move.b	d0,d1
	eor.b	#$07,d1
	lsr.w	#3,d0
	bclr	d1,(a0,D0.W)
rts
;****************************************
;	Line Draw by Yabba	900107	*
;****************************************
;*	D0.W =	x_Start	D1.W =	Y_Start	*
;*	D2.w =	x_End	D3.w =	Y_End	*
;*	A0.l =	Screen	A1.W =	Width	*
;*	A2.l =	LF-bits,Singel pixel m m*
;****************************************
Buffer:	Dc.w	0
DrawLine:
	Move.w	Buffer(pc)	,D4
	move.w	D1		,Buffer
	Move.w	D3		,D5
	Move.w	D0		,D6
	
	Sub.w	D1,D4	;Line x&y fixer by Rick & Yabba
	Sub.w	D1,D5
	Eor.w	D4,D5

	Lea	Screen		,A0
	Moveq	#44		,D4	;Fix pointer to the
	Mulu	D1		,D4	;raster line where
	Add.w	D4		,A0	;the line begins
	Move.W	D0		,D4	;Fix pointer
	Lsr.W	#3		,D4	;to the word
	And.w	#$fffe		,D4	;where the
	Add.w	D4		,A0	;line begins

	Moveq	#0		,D4	;Base for Bltcon 0 & 1

	Move.B	D0		,D4
	And.B	#15		,D4	;x-p
	Lsl.W	#8		,D4
	Lsl.W	#4		,D4
	Swap	D4

	Sub.W	D2		,D0	;Fix X Delta
	Bpl.s	Ld_Jump1
	Neg	D0
Ld_Jump1:
	RoXl.b	#1		,D4

	Sub.W	D3		,D1	;Fix Y Delta
	Bpl.s	Ld_Jump2
	Neg	D1
Ld_Jump2:
	RoXl.b	#1		,D4

	Tst.w	D1
	Beq.s	Ld_Jump7

	Clr.l	D2
	Move.w	D0		,D2
	Divu	D1		,D2
	Sub.w	D2		,D0
	Subq.w	#1		,D1

Ld_Jump7:
	Move.W	D0		,D2
	Sub.W	D1		,D2	;Compare Deltas
	Bpl.S	Ld_Jump3
	Exg	D0		,D1
Ld_Jump3:
	Roxl.W	#1		,D4

	Lea	Ld_Data1(pc)	,A4
	Move.B	(A4,D4.W)	,D4	;Octants in D4

	Lsl.W	#1		,D1	;2*Small Delta

	Cmp.W	D0		,D1	;Check if 2*S > L
	Bgt.S	Ld_Jump4		;If 2*S > L then
	Or.B	#$40		,D4	;Set SIGN Flag
Ld_Jump4:
	Or.L	#$0B4a0003	,D4	;BltCon 0 & 1

	Move.W	D0		,D3
	Addq.W	#1		,D3
Ld_Jump5:
	Lsl.W	#6		,D3
	Or.B	#2		,D3
Ld_Jump6:
	Btst	#14		,$DFF002
	Bne.S	Ld_Jump6

	Lea	$dff000		,A6
	Move.W	#$FFFF		,$72(A6)
	Move.W	#$8000		,$74(A6)
	Move.L	D4		,$40(A6)
	Move.l	A0		,$48(A6)
	Move.l	A0		,$54(A6)
	Move.W	#44		,$60(A6)
	Move.W	#44		,$66(A6)
	Move.W	D1		,$62(A6)
	Sub.W	D0		,D1
	Move.W	D1		,$52(A6)
	Sub.W	D0		,D1
	Move.W	D1		,$64(A6)
	Move.W	D3		,$58(A6)

	Tst.w	D5
	Bmi.s	DrawSlut

	Btst	#3		,D6
	Bne.s	Sud1
	Not.w	D6
	Bclr	D6		,(A0)
Drawslut:
	Rts
Sud1:
	Not.w	D6
	Bclr	D6		,1(A0)
	Rts
klipp:	dc.w 0
Ld_Data1:
	Dc.B	7*4,3*4,5*4,2*4,6*4,1*4,4*4,0*4

;**********	BLIT
;a0-a3 = pek. A-D, d0-d3 = mod. A-D
;d4 = BLTCON0+1, $0 900       0 000
;	 Shift A--* *-Use A-D *-Shift B
;d5 = [höjd*$40]+bredd(pix)

Blit:	btst	#14,$dff002
	bne.s	blit
	move.l	a0,$dff050
	move.l	a1,$dff04c
	move.l	a2,$dff048
	move.l	a3,$dff054
	move.w	d0,$dff064
	move.w	d1,$dff062
	move.w	d2,$dff060
	move.w	d3,$dff066
	move.l	#$ffffffff,$dff044
	move.l	d4,$dff040
	move.w	d5,$dff058
	rts

* d0 start x
* d1 start y
* d2 end x
* d3 end y
* a0 screen
*
draw:	moveq 	#$f	,d4
	and.w	d2	,d4
	sub.w 	d3	,d1	;Y delta i D1
	mulu	#44	,d3
;	asl.w 	#6	,d3
	sub.w 	d2	,d0	;x delta i D0

;	jmp noxy
	
	tst.w	d1
	beq.s	Noxy
	
	moveq	#0	,D6
	Move.w	D0	,D6
	Divu	D1	,D6
	Sub.w	D6	,D0
	Subq.w	#1	,D1

Noxy:	tst.w	d0
	blt.s 	draw6
	tst.w 	d1
	blt.s 	draw3
	cmp.w 	d0	,d1
	bge.s 	draw1
	moveq 	#$11	,d7
	bra.s 	draw11
draw1:	moveq 	#1	,d7
	exg 	d1	,d0
draw2: 	bra.s 	draw11
draw3:	neg.w 	d1
	cmp.w 	d0	,d1
	bge.s 	draw4
	moveq 	#$19	,d7
	bra.s 	draw11
draw4:	moveq 	#5	,d7
	exg 	d1	,d0
	bra.s 	draw11
draw6:	neg.w 	d0
	tst.w 	d1
	blt.s 	draw9
	cmp.w 	d0	,d1
	bge.s 	draw7
	moveq 	#$15	,d7
	bra.s 	draw11
draw7:	moveq 	#9	,d7
	exg 	d1	,d0
	bra.s 	draw11
draw9:	neg.w 	d1
	cmp.w 	d0	,d1
	bge.s 	draw10
	moveq 	#$1d	,d7
	bra.s 	draw11
draw10:	moveq 	#$d	,d7	
	exg 	d1	,d0
draw11:	add.w 	d1	,d1
	asr.w 	#3	,d2
	ext.l	d2
	add.l 	d2	,d3
	move.w 	d1	,d2
	sub.w 	d0	,d2
	bge.s 	draw12
	bset 	#6	,d7
draw12:	move.w 	d7	,d5
;	or.w	#$2	,d5	;Singel Pix
	add.l 	d3	,a0
	move.w 	d2	,d3
	sub.w 	d0	,d3
	addq.w 	#1	,d0
	asl.w 	#6	,d0
	addq.w 	#2	,d0
	swap 	d4
	asr.l 	#4	,d4
	or.w 	#$bfa	,d4
	swap 	d5
	move.w 	d4	,d5
	swap 	d5
	move.l #$dff000,a1
draw13:	btst 	#14	,$02(a1)
	bne.s 	draw13
	move.l 	d5	,$40(a1)
	move.l 	#-1	,$44(a1)
	move.l 	a0	,$48(a1)
	move.w 	d2	,$52(a1)
	move.l 	a0	,$54(a1)
	move.w 	#44	,$60(a1)
	move.w 	d1	,$62(a1)
	move.w 	d3	,$64(a1)
	move.l 	#$8000	,$72(a1)
	move.w 	d0	,$58(a1)
	rts
