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/D0-D7
		JMP	M_18

M_20:	MOVE.L	D2,A0
	CMP.L	#'FORM',(A0)
	BEQ	M_19
	MOVEM.L	A0-A6/D0-D7,-(A7)
	JSR	C_RUT
	LEA	NOAUDIO_TEXT,A0
	JSR	PRINT
	MOVEM.L	(A7)+,A0-A6/D0-D7
	JMP	M_18

M_19:		ADD.L	#$68,D2
		MOVE.L	D2,S_START
		SUB.L	#$6A,D3
		MOVE.L	D3,S_LANGD
	JSR	C_RUT
	JSR	S_RUT
	CMP.L	#$0,D0
	BNE	M_18
	MOVEM.L	A0-A6/D0-D7,-(A7)
	LEA	SAVERR_TEXT,A0
	JSR	PRINT
	MOVEM.L	(A7)+,A0-A6/D0-D7
	MOVEM.L	(A7)+,A0-A6/D0-D7
	JMP	END

M_18:	MOVEM.L	(A7)+,A0-A6/D0-D7

M_1:	MOVEM.L	A0-A6/D0-D7,-(A7)
	LEA	NEWSOUND_TEXT,A0
	JSR	PRINT
	MOVEM.L	(A7)+,A0-A6/D0-D7
M_78:	BTST	#$2,$DFF016
	BNE	M_78
	DBF	D7,M_LOOP

	MOVEM.L	A0-A6/D0-D7,-(A7)
	LEA	READY_TEXT,A0
	JSR	PRINT
	MOVEM.L	(A7)+,A0-A6/D0-D7
END:	RTS


START_TEXT:
DC.B	$C,$A,$9,$9,'Mahoney & Kaktus Audiomaster-Killer V1.0',$a
dc.b	$0a,'This program uses the ".fastdir" file, created by',$0a
dc.b	'CLImate, to convert your AudioMasterSounds to RAW data.',$a
dc.b	$0a,'Filename is printed, new length is displayed (in hex)',$a
dc.b	$0a,'Next Version, automatic presetlist-editor ...',$0a
DC.B	$0A,'Insert disk for execution ...'
dc.b	$0a,'LEFT BUTTON - continue      RIGHT BUTTON - cancel',$a,$A
DC.B	$00

FASTNOTFOUND_TEXT:
DC.B	$0a,$0a
DC.B	'Fastdir not found - Mission terminated - Over and out ...'
DC.B	$0A,$0A,$00
DIR_TEXT:	DC.B	'dir',$00
NOAUDIO_TEXT:	DC.B	' - no AudioMastersample',$00
NOTFOUND_TEXT:	DC.B	' - not found on disk',$00
SAVERR_TEXT:	DC.B	'Saving-error',$00
NEWSOUND_TEXT:	DC.B	$0A,$00
READY_TEXT:	DC.B	$0A,'   - That',$27,'s all folks!',$a,$a,$0
EVEN

DOS:	DC.B	'dos.library',$00

FASTDIR:DC.B	'.fastdir',$00
EVEN

;NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

N_TEXT:	DC.B	'1234123412341234',$00,$00,$00,$00
EVEN

NAME_PRINT:
	MOVE.L	#N_TEXT,A0
	MOVE.L	#$F,D7
N_0:	MOVE.B	#$20,(A0)+
	DBF	D7,N_0

	MOVE.L	#L_NAME,A0
	MOVE.L	#N_TEXT,A1
	MOVE.L	#$F,D7
N_1:	MOVE.B	(A0)+,D0
	CMP.B	#$0,D0
	BEQ	N_2
	MOVE.B	D0,(A1)+
	DBF	D7,N_1

N_2:	MOVE.L	#N_TEXT,A0
	JSR	PRINT
	RTS

;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

C_RUT:	MOVEM.L	A0-A6/D0-D7,-(A7)
	MOVE.W	D3,C_NR

	MOVE.W	C_NR,D0
	AND.L	#$F000,D0
	DIVU	#$1000,D0
	MOVE.B	C_DAT(PC,D0),C_PRINT
	MOVE.W	C_NR,D0
	AND.L	#$F00,D0
	DIVU	#$100,D0
	MOVE.B	C_DAT(PC,D0),C_PRINT+1
	MOVE.W	C_NR,D0
	AND.L	#$F0,D0
	DIVU	#$10,D0
	MOVE.B	C_DAT(PC,D0),C_PRINT+2
	MOVE.W	C_NR,D0
	AND.L	#$F,D0
	MOVE.B	C_DAT(PC,D0),C_PRINT+3
	LEA	C_PRINT,A0
	JSR	PRINT
	MOVEM.L	(A7)+,A0-A6/D0-D7
	RTS

C_NR:	DC.W	$0
C_PRINT:DC.B	'ffff',$00
C_DAT:	DC.B	'0123456789abcdef',$00
EVEN

;PPPPPPPPPPPPPPP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