
DISKSHIT = $58000	;$3E80
DISKDEST = $5BE80	;$2C00
DISKDEST2= $6BE80

S:	MOVE.W	#$4000,$DFF09A
	BSR.S	DISKINIT
		MOVE.L	#DISKDEST2,A4
		MOVE.L	#40*$2C00,D7		;DISKPOS (EJ 0!!!)
		MOVE.L	#04*$2C00,D2		;D2 = ANTAL -1
		BSR.L	L_RUT
	MOVE.W	#$C000,$DFF09A

	LEA	$DFF006,A5
	LEA	$DFF180,A6
LOOP:	MOVE.W	(A5),(A6)
	BTST	#$6,$BFE001
	BNE.S	LOOP

	MOVE.W	#$83F0,$DFF096
	RTS

L_NUTRACKPOS:	DC.W	$0000

DISKINIT:
	BSR.S	L_DISKR
	BSR.S	L_LAMP1
	BSR.S	L_WAIT2
	BSR.L	L_MOV0
	BSR.S	L_WAIT2
	BSR.S	L_LAMP0
	CLR.W	L_NUTRACKPOS
	RTS

L_DISKR:LEA	$DFF000,A5
;	MOVE.B	#$7F,$BFDD00		;SET DISK-REGS
	MOVE.L	#DISKSHIT,$20(A5)
	MOVE.W	#$4000,$24(A5)
	MOVE.W	#$4489,$7E(A5)
	MOVE.W	#$7FFF,$9E(A5)		;ADCON
	MOVE.W	#$B500,$9E(A5)
	RTS
L_LAMP1:BCLR	#7,$BFD100	;MOTOR ON
	OR.B	#$78,$BFD100
	NOP
	NOP
	AND.B	#$77,$BFD100
	BRA.S	L_WAIT
L_LAMP0:OR.B	#$F8,$BFD100	;MOTOR OFF
	NOP
	NOP
	AND.B	#$F7,$BFD100
L_WAIT:	BSR.S	L_WAIT2
	NOP
L_WAIT2:MOVE.L	D7,-(A7)
	MOVE.W	#$0FA0,D7
L_LOP6:	DBF	D7,L_LOP6
	MOVE.L	(A7)+,D7
	RTS

L_RUT:	LEA	$DFF000,A3
	BSR.S	L_DISKR
	BSR.S	L_LAMP1
	BSR.S	L_WAIT2
	MOVE.L	D7,D6
	DIVS	#$2C00,D7
	MOVEM.L	D5-D7,-(A7)
	BSR.S	L_GETTRACK
	MOVEM.L	(A7)+,D5-D7
L_LOP:	BSR.L	L_READ		;READ TRACK (SPARAR ALLA REG)
	SWAP	D7		;STARTBYTE I TRACK

	MOVE.L	#DISKDEST,A0
L_NOVE:	MOVE.W	(A0,D7.W),(A4)+
	SUBQ.L	#$2,D2
	BCS.S	L_END
	ADDQ.W	#$2,D7
	CMP.W	#$2C00,D7
	BNE.S	L_NOVE
	 MOVEQ	#$0,D7
	 BRA.S	L_LOP

L_END:	BSR.S	L_WAIT2
	BSR.S	L_LAMP0
	RTS

L_GETTRACK:
	BSET	#2,$BFD100	;SIDE 0
	CMP.W	L_NUTRACKPOS,D7
	BEQ.L	L_RTS
	BLE.S	MOVEIN

	MOVE.W	D7,D6		;NUTRACK < D7 = OKA TRACKPOS
	SUB.W	L_NUTRACKPOS,D7
	SUB.W	#$1,D7
L_LOP21:AND.B	#$FC,$BFD100
	BSET	#0,$BFD100
	MOVE.W	#$0FA0,D5
L_LOP71:DBF	D5,L_LOP71
L_51:	BTST	#5,$BFE001
	BNE.S	L_51
	DBF	D7,L_LOP21
	MOVE.W	D6,L_NUTRACKPOS
	RTS

MOVEIN:	MOVE.W	D7,D6		;NUTRACK < D7 = MINSKA TRACKPOS
	MOVE.W	L_NUTRACKPOS,D5
	SUB.W	D7,D5
	SUB.W	#$1,D5
L_33:	BSET	#1,$BFD100	;DIRECTION 79 -> 00
	BCLR	#0,$BFD100	;MOVE 1 STEP
	BSET	#0,$BFD100	;  ------
	MOVE.W	#$0FA0,D7
L_JOKER:DBF	D7,L_JOKER
L_63:	BTST	#5,$BFE001
	BNE.S	L_63
	MOVE.W	#$0400,D7
L_LTPF:	DBF	D7,L_LTPF
	DBF	D5,L_33
	MOVE.W	D6,L_NUTRACKPOS
	RTS

L_READ:	MOVEM.L	A0-A2/D0-D7,-(A7)	;READ TRACK
	MOVE.L	#$55555555,D7
	LEA	DISKDEST,A0
	MOVE.W	#$0002,$9C(A3)
	LEA	DISKSHIT,A1	;DISKSHITLENGTH=$3E80
	MOVE.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BFD100	;DIRECTION 79 -> 00
		BCLR	#0,$BFD100	;MOVE 1 STEP
		BSET	#0,$BFD100	;  ------
L_WAIT3:BSR.L	L_WAIT2		;WAIT FOR DISK-READY
L_6:	BTST	#5,$BFE001
	BNE.S	L_6
		MOVE.L	D0,-(A7)
		MOVE.W	#$0400,D0
L_LOPF:		DBF	D0,L_LOPF
		MOVE.L	(A7)+,D0
	RTS

;렁렁렁렁렁렁렁렁렁렁렁렁
;렁렁렁렁렁렁렁렁렁렁렁렁
;렁렁렁렁렁렁렁렁렁렁렁렁
;렁렁렁렁렁렁렁렁렁렁렁렁

TRDISK:	JSR	TRACKINIT

	LEA	TRACKSHIT,A1
	MOVE.W	#$2,28(A1)
	MOVE.L	#DISKDEST2,40(A1)	;DEST
	MOVE.L	#41*$2C00,44(A1)	;DISKPOS
	MOVE.L	#4*$2C00,36(A1)	;LENGTH
	MOVE.L	$04.W,A6
	JSR	-456(A6)
		MOVE.W	#$9,28(A1)
		MOVE.L	#$0,36(A1)
		MOVE.L	$04.W,A6
		JSR	-456(A6)
	JSR	TRACKEND
	RTS

TRACKINIT:
	MOVE.L	$04.W,A6
	SUBA.L	A1,A1
	JSR	-294(A6)	;FINDTASK
	MOVE.L	D0,TRACKTAL2
	LEA	TRACKTAL,A1
	MOVE.L	$04.W,A6
	JSR	-354(A6)	;ADDPORT

	MOVEQ	#$0,D0		;DF1:
	CLR.L	D1
	LEA	TRACKDISK,A0
	LEA	TRACKSHIT,A1
	JSR	-444(A6)	;OPENDEVICE

	LEA	TRACKSHIT,A1
	MOVE.L	#TRACKTAL,14(A1)
	RTS

TRACKEND:
	LEA	TRACKTAL,A1
	MOVE.L	$04.W,A6
	JSR	-360(A6)
	LEA	TRACKSHIT,A1
	MOVE.L	$04.W,A6
	JSR	-450(A6)
	RTS

TRACKDISK:	DC.B  'trackdisk.device',$00,$00
TRACKSHIT:	BLK.B $50,0
TRACKTAL:	DC.L  0,0,0,0
TRACKTAL2:	DC.L  0,TRACKTAL2+$C,0,TRACKTAL2+$4




