
>EXTERN "TUT",TUT,-1

TUT   =$50000	;14400 = $3840
DOTS  =$54000	;-$5D600
A_SCR1=$5E000	;$6000
A_SCR2=$64000	;-$6A000

JMP S

ORG $48000
LOAD$48000

S:

S1:	CMP.B	#$FF,$DFF006
	BNE	S1
S2:	CMP.B	#$37,$DFF006
	BNE	S2

	MOVE.W	#$0020,$DFF096

	BSR	M_RUT	;MAKEDOTS
	BSR	A_INIT	;MULU
	BSR	B_INIT

	MOVE.L	$04.W,A6
	MOVE.W	#$4000,$DFF09A
	ADDQ.B	#$1,$0126(A6)
	MOVE.W	#$83DF,$DFF096
	MOVE.L	#COP,$DFF080
	CLR.W	$DFF180

	MOVE.W	$DFF01C,OLDENA
	OR.W	#$8000,OLDENA
	MOVE.L	$6C.W,OLDIRQ
	MOVE.W	#$7FFF,$DFF09A
	MOVE.L	#MYIRQ,$6C.W
	MOVE.W	#$C020,$DFF09A

	MOVE.W	$DFF00A,OLDA

EVER:	CMP.B	#$FF,$DFF006
	BNE	EVER
EVER2:	CMP.B	#$30,$DFF006
	BNE	EVER2

BSR	MOVE1

MOVE.W	#-1,FRAMES

MOVE.W	#$0,$DFF180
BSR	EX_RUT
BSR	B_RUT
MOVE.W	#$4,$DFF180

MOVE.W	FRAMES,TID
MOVE.W	$DFF006,TID+2
MOVE.W	$DFF006,D0
AND.W	#$FF00,D0
OR.W	#$7,D0
MOVE.W	D0,COPINS

	BTST	#$6,$BFE001
	BNE	EVER

END:	MOVE.W	#$7FFF,$DFF09A
	MOVE.L	OLDIRQ,$6C.W
	MOVE.W	OLDENA,$DFF09A

	MOVE.L	$04.W,A6
	SUBQ.B	#1,$0126(A6)
	BGE	END1
	MOVE.W	#$C000,$DFF09A
END1:	MOVE.W	#$83F0,$DFF096
	MOVE.W	#$000F,$DFF096
	LEA	ENDGRAPH,A1
	CLR.L	D0
	JSR	-408(A6)
	MOVE.L	D0,A0
	MOVE.L	38(A0),$DFF080
	CLR.L	D0
RTS:	RTS

ENDGRAPH:	DC.B	'graphics.library',$00,$00

FRAMES:	DC.W	$0
TID:	DC.L	$0

;팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎

OLDA:	DC.W	$0
NUA:	DC.W	$0

MOVE1:	MOVE.W	$DFF00A,D0
	CMP.W	OLDA,D0
	BEQ.S	RTS
	MOVE.W	D0,NUA

	MOVE.B	OLDA+1,D1
	SUB.B	D0,D1
	EXT.W	D1
	EXT.L	D1
	SUB.L	D1,X1-2

	MOVE.B	NUA,D0
	MOVE.B	OLDA,D1
	SUB.B	D0,D1
	EXT.W	D1
	EXT.L	D1
	SUB.L	D1,Y1-2

	MOVE.W	NUA,OLDA
	RTS

;팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎

MYIRQ:	ADDQ.W	#$1,FRAMES
	MOVE.W	#$0020,$DFF09C
	RTE

OLDENA:	DC.W	$0
OLDIRQ:	DC.L	$0

;팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎팎

B_RUT:	MOVE.L	A_DRAW1,A1
	MOVE.L	A_DRAW2,A2
	MOVE.L	A_DRAW3,A3
	LEA	A_MULU,A4
	MOVE.L	#A_HOJD,A5
	MOVE.L	#A_BREDD,A6

	MOVE.W	Y4,D0
	SUB.W	Y1,D0
	BPL.S	B_DE
	NEG.W	D0
B_DE:	BEQ.S	B_CE
	SUBQ.W	#$1,D0
B_CE:	MOVE.W	D0,HOJDCOU-A_MULU(A4)

	MOVE.W	X4,D0
	SUB.W	X1,D0
	BPL.S	B_DF
	NEG.W	D0
B_DF:	BEQ.S	B_CF
	SUBQ.W	#$1,D0
B_CF:	MOVE.W	D0,B_BREDD-A_MULU(A4)

	MOVE.L	X1-2,D0
	MOVE.L	Y1-2,D2
	MOVE.W	D0,B_XPOS-A_MULU(A4)
	MOVE.W	D2,B_YPOS-A_MULU(A4)
	MOVE.L	X4-2,D4
	MOVE.L	Y4-2,D5
	SUB.L	D0,D4
	S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$3200,$0102,$0000,$0104,$0000,$0108,$0000,$010A,$0000
DC.W $008E,$4481,$0090,$0CC1,$0092,$0038,$0094,$00D0

INS1: DC.W $00E0,$0000,$00E2,$0000
INS2: DC.W $00E4,$0000,$00E6,$0000
INS3: DC.W $00E8,$0000,$00EA,$0000

DC.W $0180,$000,$0182,$001,$0184,$004,$0186,$310
DC.W $0188,$640,$018A,$740,$018C,$A71,$018E,$540


COPINS:	DC.W	$0007,$FFFE,$0180,$003

DC.W	$FFFF,$FFFE

