L505_2:	MOVEM.L	D0-D7/A0-A6,-(A7)
	CMP.L	#'patp',L632
	BNE.S	NOTIM
	BSR	TIMER
NOTIM:	MOVE.L	L697(PC),A0
	MOVE.B	$3B6(A0),L588
	TST.L	L632
	BEQ	L505_U

	MOVE.B	#$F8,D0		;SKICKA SYNC (SPD 6)
	BSR	WRITEMIDI

	ADDQ.L	#1,L695
	MOVE.L	L695,D0
	CMP.L	L642,D0
	BLT.S	L505_4
	CLR.L	L695
	BRA	L505_F

L505_4:	LEA	L592,A6
	LEA	$DFF0A0,A5
	BSR	L577_2
L505_5:	LEA	L593,A6
	LEA	$DFF0B0,A5
	BSR	L577_2
L505_6:	LEA	L594,A6
	LEA	$DFF0C0,A5
	BSR	L577_2
L505_7:	LEA	L595,A6
	LEA	$DFF0D0,A5
	BSR	L577_2
	BRA	L505_U

L505_8:	MOVE.L	L695,D0
	DIVS	#3,D0
	SWAP	D0
	TST.W	D0
	BEQ.S	L505_B
	CMP.W	#2,D0
	BEQ.S	L505_A

L505_9:	MOVEQ	#$00,D0
	MOVE.B	$3(A6),D0
	LSR.B	#$4,D0
	BRA.S	L505_C
L505_A:	MOVEQ	#0,D0
	MOVE.B	$3(A6),D0
	AND.B	#$F,D0
	BRA.S	L505_C
L505_B:	MOVE.W	$10(A6),D2
	BRA.S	L505_E
L505_C:	ASL.W	#1,D0
	MOVEQ	#0,D1
	MOVE.W	$10(A6),D1
	AND.W	#$FFF,D1
	LEA	L602,A0
	MOVEQ	#[L603-L602]/2,D7
L505_D:	MOVE.W	(A0,D0.W),D2
	CMP.W	(A0),D1
	BGE.S	L505_E
	ADDQ.L	#$2,A0
	DBF	D7,L505_D
	RTS
L505_E:	MOVE.W	D2,$6(A5)
	RTS

L505_F:	MOVE.L	L697(PC),A0
L505_G:	MOVE.L	A0,A3
	ADD.L	#$C,A3
	MOVE.L	A0,A2
	ADD.L	#$3B8,A2
	ADD.L	#$43C,A0
	CMP.L	#'patp',L632
	BEQ.S	L505_H
	MOVE.L	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