
JMP	S
ORG	$30000
LOAD	$30000

>extern "Sinum",Sinum

Sinum=$40000	;$100
Z_cop1=$56040	;-$63280

bpl1=$50000
bpl2=$53020


stack:	blk.l	$c0,0
S:	move.l	a7,oldstack
	lea	s(pc),a7
	lea	$dff000,A6
	move.w	$1c(a6),oldena
	move.w	#$7fff,$9a(a6)
	move.w	#$c000,$9a(a6)
	move.w	$1e(a6),oldreq
	move.w	#$3fff,$9c(a6)
	move.w	$02(a6),olddma
	move.w	#$03df,$96(a6)
	move.l	#super,$80.w
	trap	#0

	bsr	rnd_init

	lea	$dff000,a6
	MOVE.L	#COP,$80(a6)
Sync:	move.l	$04(a6),d0
	and.l	#$1ff00,d0
	cmp.l	#$12800,d0
	bne.s	Sync
	move.w	#$83e0,$96(a6)

EVER:	lea	$dff000,a6
lever:	move.l	$04(a6),d0
	and.l	#$1ff00,d0
	cmp.l	#$13500,d0
	bne.s	lever

	bsr	random

	move.l	#$00,$dff180
	bsr	rut
wer:	btst	#14,$dff002
	bne.s	wer

	move.l	#$4040048,$dff180

	btst	#6,$bfe001
	bne.s	ever

END:	move.l	#user,$80.w
	trap	#0
	move.l	$04.w,a6
	move.l	(a6),a5
	move.l	(a5),a5
	lea	$dff000,a6
	move.l	38(a5),$80(a6)

	move.w	#$3fff,$9c(a6)
	move.w	#$7fff,$9a(a6)
	move.w	#$03ff,$96(a6)
	move.w	oldena(pc),d0
	move.w	oldreq(pc),d1
	move.w	olddma(pc),d2
	and.w	#$3fff,d1
	and.w	#$03f0,d2
	or.w	#$8000,d0
	or.w	#$8000,d1
	or.w	#$8000,d2
	move.w	d1,$9c(a6)
	move.w	d0,$9a(a6)
	move.w	d2,$96(a6)
	move.l	$04.w,a6
	move.l	oldstack(pc),a7
	moveq	#0,d0
rts:	rts

super:	move.w	#$2000,(a7)
	rte
user:	move.w	#$0000,(a7)
	rte

oldstack:dc.l	0
oldena:	dc.w	0
oldreq:	dc.w	0
olddma:	dc.w	0

;----------------------------------------------------------------

rnd_init:
	move.w	$dff004,rnd
	move.w	$dff006,rnd+2
	move.b	$dc0001,rnd+4
	move.b	$dc0003,rnd+5
	move.w	$dff00a,rnd+6
	rts

RANDOM:	MOVEM.L	RND,D0/D1	;D0=LSB's, D1=MSB's of rnd num
	ANDI.B	#$0E,D0		;ensure upper 59 bits are an...
	ORI.B	#$20,D0		;...odd binary number
	MOVE.L	D0,D2
	MOVE.L	D1,D3
	ADD.L	D2,D2		;accounts for 1 of 17 left shifts
	ADDX.L	D3,D3		;[D2/D3] = RND*2
	ADD.L	D2,D0
	ADDX.L	D3,D1		;[D0/D1] = RND*3
	SWAP	D3		;shift [D2/D3] additional 16 times
	SWAP	D2
	MOVE.W	D2,D3
	CLR.W	D2
	ADD.L	D2,D0		;add to [D0/D1]
	ADDX.L	D3,D1
	add.w	$dff006,d0
	add.w	$dff00a,d1
	MOVEM.L	D0/D1,RND	;save for next time through
;	MOVE.L D0,D1
	RTS
RND:	DC.L 0,0

;----------------------------------------------------------------

scr1:	dc.l	bpl1
scr2:	dc.l	bpl2

Rut:	lea	$dff000,a6
	move.l	scr1(pc),d0
	move.l	scr2(pc),scr1
	move.l	d0,scr2

	move.w	d0,copins+6
	move.w	d0,copins2+6
	swap	d0
	move.w	d0,copins+2
	move.w	d0,copins2+2

wai:	btst	#14,$02(a6)
	bne.s	wai
	move.l	#$01000000,$40(a6)
	move.l	scr1(pc),$54(a6)
	clr.w	$66(a6)
	move.w	#[$118*$40]+[44/2],$58(a6)
	bra.L	goon


l_zbigcou:	dc.w	$124+$80
l_fillstate:	dc.w	0

DestDat:	blk.l	$18,0
DestDatEnd:

goon:	sub.w	#3,l_zbigcou
	cmp.w	#$123,l_zbigcou
	bgt.s	goook
	add.w	#$80,l_zbigcou
	eor.w	#$4,l_fillstate
goook:

	lea	DestDat(pc),a3
	moveq	#[[DestDatEnd-DestDat]/4]-1,d7
	move.w	l_zbigcou(pc),d0
	moveq	#0,d6
	move.b	$dff00b,d6
	ext.w	d6

goolop:	move.w	d0,d1
	sub.w	#$124,d1
	muls	d6,d1
	asr.l	#$8,d1

	and.w	#$7fe,d1
	move.w	d1,(a3)+
	move.w	d0,(a3)+

	add.w	#$80,d0
	dbf	d7,goolop

;	sub.w	#$2,l_z
;	cmp.w	#$0,l_z
;	bge.s	l_zok
;	move.w	#$500,l_z
;l_zok:	move.w	l_z(pc),d4
;	add.w	#$92,d4	;$92 norm


	lea	DestDat(pc),a3
	move.w	#[[DestDatEnd-DestDat]/4]-1,d7
	tst.w	l_fillstate
	beq.s	OneMore
	subq.w	#1,d7
OneMore:move.w	d7,-(a7)
	bsr	Lines
	move.w	(a7)+,d7
	dbf	d7,oneMore




filw:	lea	$dff000,a6
	btst	#14,$02(a6)
	bne.s	filw
	move.l	scr1(pc),a0
	lea	[$117*44]+42(a0),a0
	move.l	a0,$50(a6)
	move.l	a0,$54(a6)
	clr.l	$64(a6)
	move.l	#$0ff00012,d0
	add.w	l_fillstate(pc),d0
	move.l	d0,$40(a6)
	move.w	#[$118*$40]+[44/2],$58(a6)
	rts


l_cou:	dc.w	$800-292,292,$400-292,$400+292

l_z:	dc.w	$500

lines:	lea	sinum,a0
	lea	linexy(pc),a1
	lea	l_cou(pc),a2
	moveq	#3,d6
	move.w	(a3)+,d5
	move.w	(a3)+,d4

l_lop:	moveq	#0,d0
	moveq	#0,d1
	move.w	(a2),d7
	add.w	d5,d7
	and.w	#$7fe,d7
	move.w	(a0,d7.w),d0
	add.w	#$200,d7
	and.w	#$7fe,d7
	move.w	(a0,d7.w),d1

	ext.l	d0
	ext.l	d1
	add.l	d0,d0
	add.l	d1,d1

	divs	d4,d0
	divs	d4,d1

;	muls	d2,d0
;	swap	d0
;	muls	d2,d1
;	swap	d1


	add.w	#$160/2,d0	;x
	add.w	#$118/2,d1		;y

	move.w	d0,(a1)+
	move.w	d1,(a1)+
;	add.w	#2,(a2)
	and.w	#$7fe,(a2)+
	dbf	d6,l_lop


	lea	linexy(pc),a5
	move.l	(a5),linexy2-linexy(a5)
	move.l	Linexy+$c,Lajn
	bra.s	Drawline

Lajn:	dc.l	0
linexy:	blk.w	8,0
linexy2:blk.w	2,0

;****************************************
;*	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.l	#$ffffffff	,$dff044
	move.w	#44,a1
	bsr.s	jahoo
	bsr.s	jahoo
	bsr.l	jahoo

jahoo:	moveq	#0,d0
	moveq	#0,d1
	moveq	#0,d2
	moveq	#0,d3

	move.w	(a5)+,d0
	move.w	(a5)+,d1
	move.w	(a5),d2
	move.w	2(a5),d3

	move.w	-6(a5),d4

;	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

	move.l	scr1(pc),A0
	moveq	#44,D4
	mulu	D1,D4
	lea	(a0,d4.l),a0
	move.w	d0,d4
	lsr.w	#4,d4
	add.w	d4,d4
	lea	(a0,d4.w),a0

	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

	moveq	#0,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
	Bchg	D6		,(A0)
Drawslut:
	Rts
Sud1:
	Not.w	D6
	Bchg	D6		,1(A0)
	Rts

Ld_Data1:
	Dc.B	7*4,3*4,5*4,2*4,6*4,1*4,4*4,0*4

;----------------------------------------------------------------

cop:	dc.w $100,$9200,$102,$0000,$104,$0000,$108,-44,$10a,-44
	dc.w $08e,$2071,$090,$38c7,$092,$0030,$094,$00d8,$096,$0020

copins:	dc.w $0e0,bpl1/$10000,$0e2,bpl1

	dc.w $180,$000,$182,$048

	dc.w $ac01,$fffe
copins2:dc.w $0e0,bpl1/$10000,$0e2,bpl1

	dc.l -2

