* Master Soundtracker  V1.1 *
*   by THE INVISIBLE POWER  *

org	$74000
load	$74000

* Dos *

Open    = -30
Close   = -36
Read    = -42
Write   = -48
Lock    = -84
UnLock  = -90
Examine = -102
ExNext  = -108

* Intern *

SongHeader = 600

* Song Header aufbau 1:
*   0:SongName       20
*  20:SampleDats     450
* 470:Len+$78        2
* 472:Playvorschrift 128

p:		move.l	4.w,a6
		move.l	#$8000,d0
		lea	$74000,a1
		jsr	-204(a6)
		move.l	a7,OldSP
		bsr	Init
L0446A0:	bsr	L044C6E
		bsr	CheckOktaves
		bsr	CheckCursor
		bsr	CheckShift
		bsr	l044782
		bsr	PrintSpeed
		cmp.l	#'song',SongMode
		bne.s	l0446c4
		bsr	SongOn
L0446C4:	btst	#6,$BFE001
		bne.s	l0446a0
		tst.w	AW_Mode
		bne	NoRegards
		bsr	DisplayEqualizer
NoRegards:	bra	l04508a

* Initialisierungen *******************

Init:		move.l	4.w,a6			;neuer KeyInt
		move.l	$78(a6),a0
		move.l	(a0),a0
		move.l	14(a0),a0
		lea	104(a0),a0
		move.l	(a0),OldKeyInt
		move.l	#KeyInterrupt,(a0)
		move.l	a0,KeyIntPointer

		lea	DosName,A1		;Dos Lib oeffnen
		jsr	-408(A6)
		move.l	D0,DosBase

		lea	GraphicsName,a1	;Alte Copperliste
		jsr	-408(a6)
		move.l	d0,a1
		move.l	38(a1),OldCop
		jsr	-414(a6)

		move.l	#$8000,d0		;SampleBuff
		move.l	#$10000,d1
		jsr	-198(a6)
		move.l	d0,SampleBuffer

		move.l	#8400,d0		;Dir Entries
		move.l	#$10000,d1
		jsr	-198(a6)
		move.l	d0,EntryBuffer

		move.l	#$11000+SongHeader,D0	;Song reservieren
		move.l	#$10000,D1
		jsr	-198(A6)
		move.l	D0,SongPT

		move.l	#$6C70,D0		;WorkPlane
		move.l	#$10002,D1
		jsr	-198(A6)
		move.l	D0,WorkPlane
		move.w	D0,WorkPlaneLo
		swap	D0
		move.w	D0,WorkplaneHi

		move.l	#1024+$5000+[2860*4],d0	;o File res and splitt
		moveq	#2,d1
		jsr	-198(a6)
		move.l	d0,Chars
		add.l	#1024,d0
		move.l	d0,Pic
		add.l	#$5000,d0
		move.l	d0,EqualizerPic
		add.l	#2860,d0
		move.l	d0,SamplerPic
		add.l	#2860,d0
		move.l	d0,LoadPic
		add.l	#2860,d0
		move.l	d0,SavePic

		move.l	DosBase,a6		;o File reinladen
		move.l	#OName,d1
		move.l	#1005,d2
		jsr	Open(a6)
		move.l	d0,d7
		move.l	d0,d1
		move.l	Chars,d2
		move.l	#1024+$5000+[4*2860],d3
		jsr	Read(a6)
		move.l	d7,d1
		jsr	Close(a6)

		move.l	#PListName,d1		;PLST laenge ermitteln
		moveq	#-2,d2
		jsr	Lock(a6)
		move.l	d0,d7
		move.l	d7,d1
		move.l	#FileInfoBlock,d2
		jsr	Examine(a6)
		move.l	d7,d1
		jsr	UnLock(a6)
		lea	FileInfoBlock,a0
		move.l	124(a0),d0
		move.l	d0,PListLen
		divu	#30,d0
		move.w	d0,PresetEntries

		move.l	4.w,a6			;reservieren
		move.l	PListLen,d0
		moveq	#0,d1
		jsr	-198(a6)
		move.l	d0,PresetList

		move.l	DosBase,a6		;laden
		move.l	#PListName,d1
		move.l	#1005,d2
		jsr	Open(a6)
		move.l	d0,d7
		move.l	d7,d1
		move.l	PresetList,d2
		move.l	PListLen,d3
		jsr	Read(a6)
		move.l	d7,d1
		jsr	Close(a6)

		move.w	$DFF00A,D0		;mauscounter
		move.w	D0,D1
		and.w	#$FF,D0
		move.w	D0,OldX
		lsr.w	#8,D1
		move.w	D1,OldY

		bsr	ClearSong

		clr.l	0.w			;4 Sprites uebertragen
		lea	SPR0,A0
		lea	CopperList+2,A1
		moveq	#7,D2
SpriteCopyLoop:	move.w	(A0)+,(A1)
		addq.w	#4,a1
		dbf	D2,SpriteCopyLoop

		bsr	SetCursor		;Init
		bsr	DrawWorkPlane
		bsr	SongOn
		bsr	PrintPosPatt
		bsr	PrintSoundData

		lea	EquOffsetTable,a0	;Equaliiz. Offsets
		move.w	#35*40,d0
		moveq	#35,d7
I_EquLoop:	move.w	d0,(a0)+
		sub.w	#40,d0
		dbf	d7,I_EquLoop

		move.l	Pic,d0			;Picture in Cop
		lea	PicPlanes,a1
		move.w	d0,6(a1)
		swap	d0
		move.w	d0,2(a1)
		swap	d0
		add.l	#320*256/8,d0
		move.w	d0,14(a1)
		swap	d0
		move.w	d0,10(a1)

		move.l	4.w,a6			;AutoRequest
		lea	IntuitionName,a1
		jsr	-408(a6)
		move.l	d0,IntuitionBase
		move.l	d0,a0
		move.l	-346(a0),OldAutoJump+2
		move.l	#NewAutoReq,-346(a0)

		move.l	$6C.w,OldInterrupt1	;neuer Interrupt
		move.l	#Interrupt1,$6C.w

		bsr	SetWorkPlane
		bsr	SpriteGrey
		move.l	#CopperList,$DFF080
		rts

Chars:		dc.l	0
Pic:		dc.l	0
EqualizerPic:	dc.l	0
SamplerPic:	dc.l	0
LoadPic:	dc.l	0
SavePic:	dc.l	0
SampleBuffer:	dc.l	0
EntryBuffer:	dc.l	0
KeyIntPointer:	dc.l	0
DosBase:	dc.l	0
IntuitionBase:	dc.l	0
OldCop:		dc.l	0
SPR0:		dc.l	OrigMouseSprite,TextCursorSprite,0,TonCursorSprite

OName:		dc.b	'o',0
PListName:	dc.b	'PLST',0
DosName:	dc.b	'dos.library',0
IntuitionName:	dc.b	'intuition.library',0
GraphicsName:	dc.b	'graphics.library',0

* Programm beenden ********************

Quit:		move.l	OldSP,a7
		move.l	OldCop,$dff080
		move.l	4.w,a6
		move.l	IntuitionBase,a1	;Old Auto Jmp
		move.l	OldAutoJump+2,-346(a1)
		jsr	-414(a6)
		move.l	Workplane,a1		;WorkPlane
		move.l	#$6C70,D0
		jsr	-210(A6)
		move.l	DosBase,a1		;DosBase
		jsr	-414(a6)
		move.l	SongPT,a1		;Song
		move.l	#$11000+SongHeader,D0
		jsr	-210(A6)
		move.l	SampleBuffer,a1		;SampleBuffer
		move.l	#$8000,d0
		jsr	-210(a6)
		move.l	EntryBuffer,a1		;EntryBuffer
		move.l	#8400,d0
		jsr	-210(a6)
		bsr	FreeSamples		;Samples
		move.l	Chars,a1		;Chars
		move.l	#[2860*4]+$5000+1024,d0
		jsr	-210(a6)
		move.l	PresetList,a1		;Presets
		move.l	PListLen,d0
		jsr	-210(a6)
		move.l	OldInterrupt1,$6C.w	;norm Int
		move.w	#$f,$dff096		;Sound Off
		move.l	KeyIntPointer,a0
		move.l	OldKeyInt,(a0)
		moveq	#0,d0
		rts

* Maus im ActionWindow gedrueckt ******

ActionWindow:	move.w	ActualXPos,d0
		sub.w	#120,d0
		move.w	ActualYPos,d1
		sub.w	#45,d1
		move.w	AW_Mode,d2
		cmp.w	#2,d2
		beq	ExecuteSamplerGadgets
		cmp.w	#3,d2
		beq	ExecuteLoadGadgets
		cmp.w	#4,d2
		beq	ExSaveGadgets
		rts

* Equalizer anzeigen ******************

DisplayEqualizer:
		bsr	WaitAllLifted
		lea	EquOldData,a0
		lea	EquNewData,a1
		moveq	#22,d7
DECO_Loop:	clr.w	(a0)+
		clr.w	(a1)+
		dbf	d7,DECO_Loop
		bsr	ClearHiTables
		move.l	EqualizerPic,a0
		bsr	CopyPic
		bsr	ClearWorkPic
		move.w	#1,AW_Mode
		rts

* Equalizer refreshen *****************

EqualizerHandler:
		subq.w	#1,HiCounter
		bne.s	EH_NoHi0
		bsr	ClearHiTables
EH_NoHi0:	bsr	Equalizer2Handler
		cmp.w	#1,AW_Mode
		bne	EH_End
		moveq	#40,d5
		moveq	#$3c,d6
		lea	EquNewData,a0
		lea	EquOldData,a1
		lea	EquOffsetTable,a2
		lea	HiTable+2,a4
		move.l	WorkPlane,a3
		add.w	#2416,a3
		moveq	#22,d7
EH_MainLoop:	move.w	(a0)+,d0
		cmp.w	#35,d0
		blt.s	NotMoreThanO
		moveq	#35,d0
NotMoreThanO:	cmp.w	(a4),d0
		blt.s	EH_NoNewHi
		move.w	d0,(a4)
EH_NoNewHi:	move.w	(a1)+,d1
		cmp.w	d0,d1
		beq.s	EH_NextBlock
		blt.s	NewGreatherOld
		sub.w	d0,d1
		subq.w	#1,d1
		add.w	d0,d0
		move.w	(a2,d0.w),d0
OGN_Loop:	clr.b	(a3,d0.w)
		sub.w	d5,d0
		dbf	d1,OGN_Loop
		bra	EH_NextBlock
NewGreatherOld:	sub.w	d1,d0
		subq.w	#1,d0
		add.w	d1,d1
		move.w	(a2,d1.w),d1
NGO_Loop:	move.b	d6,(a3,d1.w)
		sub.w	d5,d1
		dbf	d0,NGO_Loop
EH_NextBlock:	addq.w	#1,a3
		addq.w	#4,a4
		dbf	d7,EH_MainLoop
		lea	EquNewData,a0
		lea	EquOldData,a1
		moveq	#22,d7
CopyNewToOld:	move.w	(a0),d0
		move.w	d0,(a1)+
		beq.s	NoSub
		subq.w	#1,d0
NoSub:		move.w	d0,(a0)+
		dbf	d7,CopyNewToOld

		lea	EquOffsetTable,a2
		lea	HiTable,a4
		move.l	WorkPlane,a3
		add.w	#2416,a3
		moveq	#22,d7
EH_HiMainLoop:	move.w	(a4)+,d0
		cmp.w	(a4),d0
		ble.s	EH_NoLHiClear
		add.w	d0,d0
		move.w	(a2,d0.w),d0
		clr.b	(a3,d0.w)
EH_NoLHiClear:	move.w	(a4)+,d0
		move.w	d0,-4(a4)
		add.w	d0,d0
		move.w	(a2,d0.w),d0
		move.b	d6,(a3,d0.w)
		addq.w	#1,a3
		dbf	d7,EH_HiMainLoop
EH_End:		rts

* Hi New Tables auf 0 *****************

ClearHiTables:	lea	HiTable+2,a0
		moveq	#22,d0
EH_ClearHi:	clr.w	(a0)
		addq.w	#4,a0
		dbf	d0,EH_ClearHi
		move.w	#150,HiCounter
		clr.w	Pos1+4
		clr.w	Pos2+4
		clr.w	Pos3+4
		clr.w	Pos4+4
		rts

HiCounter:	dc.w	0

* Periode in Equ umwandeln ************

AddPeriode1:	movem.l	a0/d0-d3,-(sp)
		moveq	#0,d2
		move.w	2(a6),d2
		bra	AP_1
AddPeriode:	movem.l	a0/d0-d3,-(sp)
		moveq	#0,d2
		move.w	$12(a6),d2
AP_1:		bsr	AddEquPeriode
		beq	AP_NoRightAdd
		lsl.w	#8,d2
		divu	#$2aa,d2
		move.w	d2,d3
		subq.w	#8,d3
		bpl.s	AP_Ok1
		moveq	#0,d3
AP_OK1:		move.w	d3,d4
		subq.w	#8,d4
		bpl.s	AP_Ok2
		moveq	#0,d4
AP_OK2:		lea	EquNewData,a0
		sub.w	#$71,d0
		move.w	#$358-$71,d1
		sub.w	d0,d1
		mulu	d1,d1
		divu	#$6205,d1
		move.w	d1,d0
		cmp.w	#23,d0
		blt.s	AP_Ok
		moveq	#22,d0
AP_Ok:		add.w	d0,d0
		add.w	d2,(a0,d0.w)
		cmp.w	#35,(a0,d0.w)
		blt.s	NoMiddleOverflow
		move.w	#35,(a0,d0.w)
NoMiddleOverflow:
		tst.w	d0
		beq.s	AP_NoLeftAdd
		add.w	d3,-2(a0,d0.w)
		cmp.w	#35,-2(a0,d0.w)
		blt.s	AP_Left2Add
		move.w	#35,-2(a0,d0.w)
AP_Left2Add:	cmp.w	#2,d0
		beq.s	AP_NoLeftAdd
		add.w	d4,-4(a0,d0.w)
		cmp.w	#35,-4(a0,d0.w)
		blt.s	AP_NoLeftAdd
		move.w	#35,-4(a0,d0.w)
AP_NoLeftAdd:	cmp.w	#44,d0
		beq.s	AP_NoRightAdd
		add.w	d3,2(a0,d0.w)
		cmp.w	#35,2(a0,d0.w)
		blt.s	AP_Right2Add
		move.w	#35,2(a0,d0.w)
AP_Right2Add:	cmp.w	#42,d0
		beq.s	AP_NoRightAdd
		add.w	d4,4(a0,d0.w)
		cmp.w	#35,4(a0,d0.w)
		blt.s	AP_NoRightAdd
		move.w	#35,4(a0,d0.w)
AP_NoRightAdd:	movem.l	(sp)+,a0/d0-d3
		rts

* Sampler anzeigen

DisplaySampler:	bsr	WaitAllLifted
		move.w	#2,AW_Mode
		move.l	SamplerPic,a0
		bsr	CopyPic
		bsr	ClearWorkPic
		bsr	CopyToSBuffer
		bra	ShowSample

ExecuteSamplerGadgets:
		cmp.w	#75,d0
		blt.s	ESG_1
		rts
ESG_1:		cmp.w	#11,d1
		blt.s	ESG_End
		cmp.w	#22,d1
		blt.s	StartSampling
		cmp.w	#33,d1
		blt	Cuts
		cmp.w	#44,d1
		blt	Reverse
		cmp.w	#55,d1
		blt	DisplayEqualizer
ESG_End:	rts

Cuts:		cmp.w	#24,d0
		blt.L	CutLeft
		cmp.w	#50,d0
		bgt.L	CutRight
		rts

* Samplen *

StartSampling:	bsr	StopSong
		clr.l	EditMode
		bsr	ClearWorkPic
		bsr	WaitAllLifted
		bsr	SpritePink
		move.w	$dff01c,-(sp)
		move.w	#$7fff,$dff09a

		lea	PlayBuffer,a0
		move.l	a0,$dff0a0
		move.l	a0,$dff0b0
		moveq	#124,d0
		move.w	d0,$dff0a6
		move.w	d0,$dff0b6
		moveq	#64,d0
		move.w	d0,$dff0a8
		move.w	d0,$dff0b8
		moveq	#1,d0
		move.w	d0,$dff0a4
		move.w	d0,$dff0b4
		move.w	#$8003,$dff096
		lea	SamplerOffsetTable,a0
		lea	PlayBuffer,a3
		lea	$dff0aa,a4
		lea	$dff0ba,a5
		lea	$bfe101,a6
		move.w	#$8080,d2
		move.w	#$ff,d3
		move.w	#$80,d4
		moveq	#8,d5
SS_MainLoop:	lea	PointList,a1
		move.l	WorkPlane,a2
		lea	1985(a2),a2
		moveq	#13,d7			;14Bytes
SS_1:		moveq	#7,d6			;Je7 Bits
SS_2:		moveq	#0,d0
		move.b	(a6),d0
		move.w	d0,d1
		lsl.w	d5,d0
		or.w	d1,d0
		eor.w	d2,d0
		move.w	d0,(a3)
		move.w	d0,(a4)
		move.w	d0,(a5)
		and.w	d3,d0
		eor.w	d4,d0
		lsr.w	#3,d0
		add.w	d0,d0
		move.w	(a0,d0.w),d0
		move.w	(a1),d1
		bclr	d6,(a2,d1.w)
		move.w	d0,(a1)+
		bset	d6,(a2,d0.w)

		dbf	d6,SS_2
		addq.w	#1,a2
		dbf	d7,SS_1
		btst	#6,$bfe001
		beq	SS_Cancel
		btst	#10,$dff016
		bne.s	SS_MainLoop

		bsr	SpriteBlue

		lea	SamplerOffsetTable,a0
		lea	PlayBuffer,a3
		lea	$dff0aa,a4
		lea	$dff0ba,a5
		move.l	SampleBuffer,a6
		move.w	#$8080,d2
		moveq	#0,d3
		move.w	#$80,d4
		moveq	#8,d5
SS_MainLoop2:	lea	PointList,a1
		move.l	WorkPlane,a2
		lea	1985(a2),a2
		moveq	#13,d7			;14Bytes
SS_12:		moveq	#7,d6			;Je7 Bits
SS_22:		moveq	#0,d0
		move.b	$bfe101,d0
		move.w	d0,d1
		lsl.w	d5,d0
		or.w	d1,d0
		eor.w	d2,d0
		move.b	d0,(a6)+
		move.w	d0,(a3)
		move.w	d0,(a4)
		move.w	d0,(a5)
		and.w	#$ff,d0
		eor.w	d4,d0
		lsr.w	#3,d0
		add.w	d0,d0
		move.w	(a0,d0.w),d0
		move.w	(a1),d1
		bclr	d6,(a2,d1.w)
		move.w	d0,(a1)+
		bset	d6,(a2,d0.w)
		addq.w	#1,d3
		cmp.w	#$8000,d3
		beq.s	SS_Sampled
		btst	#6,$bfe001
		beq.s	SS_Sampled

		dbf	d6,SS_22
		addq.w	#1,a2
		dbf	d7,SS_12
		bra.s	SS_MainLoop2
SS_Sampled:	move.w	#$f,$dff096
		move.l	a6,-(sp)
		bsr	ClearWorkPic
		move.l	(sp)+,d0
		sub.l	SampleBuffer,d0
		move.l	d0,SampleBufferLen
		bsr	SpriteGrey
		bsr	ShowSample
		bsr	CopySample
		bsr	InitPointer
		move.w	(sp)+,d0
		bset	#15,d0
		move.w	d0,$dff09a
		rts
SS_Cancel:	bsr	InitPointer
		move.w	(sp)+,d0
		bset	#15,d0
		move.w	d0,$dff09a
		bsr	ClearWorkPic
		bsr	ShowSample
		bra	SpriteRed

IB = 40
SamplerOffsetTable:
		dc.w	IB*44,IB*43,IB*42
		dc.w	IB*41,IB*40,IB*39,IB*38,IB*37,IB*36,IB*35,IB*34,IB*33,IB*32,IB*31,IB*30
		dc.w	IB*29,IB*28,IB*27,IB*26,IB*25,IB*24,IB*23,IB*22,IB*21,IB*20,IB*19,IB*18
		dc.w	IB*17,IB*16,IB*15,IB*14,IB*13,IB*12,IB*11,IB*10,IB*9,IB*8,IB*7,IB*6
		dc.w	IB*5,IB*4,IB*3,IB*2,IB,0

* Reversen *

Reverse:	bsr	StopSong
		clr.l	EditMode
		bsr	WaitAllLifted
		move.l	SampleBuffer,a0
		move.l	a0,a1
		add.l	SampleBufferLen,a1
		move.l	a1,d0
		sub.l	a0,d0
		lsr.l	#1,d0
		beq.s	R_Noo
R_Loop:		move.b	(a0),d1
		move.b	-(a1),d2
		move.b	d1,(a1)
		move.b	d2,(a0)+
		subq.l	#1,d0
		bne.s	R_Loop
		bsr	ClearWorkPic
		bsr	ShowSample
		bsr	CopySample
R_Noo:		rts




* CutLeft *****************************

CutLeft:	bsr	StopSong
		clr.l	EditMode
		bsr	SpriteBlue
CL_MainLoop:	bsr	WaitAllLifted
CL_Wait:	btst	#10,$dff016
		beq	SpriteRed
		btst	#6,$bfe001
		bne.s	CL_Wait
		cmp.l	#112,SampleBufferLen
		blt	SpriteRed
		bsr	GetOffset
		bne	SpriteRed
		move.l	SampleBuffer,a0
		move.l	a0,a1
		move.l	SampleBufferLen,d0
		move.l	d1,d2
CL_CopyLoop:	move.b	(a0,d1.l),(a1)+
		addq.l	#1,d1
		cmp.l	d0,d1
		blt.s	CL_CopyLoop
		sub.l	d2,SampleBufferLen
		bsr	ClearWorkPic
		bsr	ShowSample
		bsr	CopySample
		bra	SpriteGrey

* CutRight ****************************

CutRight:	bsr	StopSong
		clr.l	EditMode
		bsr	SpriteBlue
CR_MainLoop:	bsr	WaitAllLifted
CR_Wait:	btst	#10,$dff016
		beq	SpriteRed
		btst	#6,$bfe001
		bne.s	CR_Wait
		cmp.l	#112,SampleBufferLen
		blt	SpriteRed
		bsr	GetOffset
		bne	SpriteRed
		move.l	SampleBufferLen,d0
		sub.l	d1,d0
		sub.l	d0,SampleBufferLen
		bsr	ClearWorkPic
		bsr	ShowSample
		bsr	CopySample
		bra	SpriteGrey

* Offset durch pos berechnen

GetOffset:	move.w	MouseXPos,d0
		move.w	MouseYPos,d1
		cmp.w	#200,d0
		blt.s	GO_Error
		cmp.w	#62,d1
		blt.s	GO_Error
		cmp.w	#312,d0
		bge.s	GO_Error
		cmp.w	#94,d1
		bge.s	GO_Error
		sub.w	#200,d0
		move.l	SampleBufferLen,d7
		move.l	d7,d1
		lsl.l	#4,d1
		divu	#112,d1
		mulu	d0,d1
		lsr.l	#4,d1
		cmp.l	d7,d1
		bge.s	GO_Error
		bclr	#0,d1
		moveq	#0,d0
		rts
GO_Error:	moveq	#-1,d0
		rts

* Equalizer 2 *******************

CheckChannelGadgets:
		move.w	ActualYPos,d0
		cmp.w	#$2d,d0
		bge	ActionWindow
		cmp.w	#$22,d0
		bge.s	CChannel4
		cmp.w	#$17,d0
		bge.s	CChannel3
		cmp.w	#$c,d0
		bge.s	CChannel2
		tst.w	d0
		bge.s	CChannel1
		rts

CChannel1:	lea	Channel1,a0
		bra.s	ChangeChannel
CChannel2:	lea	Channel2,a0
		bra.s	ChangeChannel
CChannel3:	lea	Channel3,a0
		bra.s	ChangeChannel
CChannel4:	lea	Channel4,a0

ChangeChannel:	btst	#6,$bfe001
		beq.s	ChangeChannel
		move.l	WorkPlane,a1
		moveq	#0,d0
		move.w	2(a0),d0
		add.l	d0,a1
		eor.w	#1,(a0)
		bsr	ClearField
		tst.w	(a0)
		bne.s	CC_End
		clr.w	4(a0)
		clr.w	6(a0)
		clr.w	8(a0)
		moveq	#0,d0
		move.w	2(a0),d0
		addq.l	#1,d0
		move.l	d0,WorkPlaneOffset
		move.l	#3,TextLen
		move.l	#OffBuffer,TextPointer
		bsr	PrintText
CC_End:		move.w	Channel4,d0
		add.w	d0,d0
		or.w	Channel3,d0
		add.w	d0,d0
		or.w	Channel2,d0
		add.w	d0,d0
		or.w	Channel1,d0
		move.w	d0,ChannelMask
		eor.w	#$f,d0
		move.w	d0,$dff096
		rts

ClearField:	moveq	#4,d0
CF_Loop:	clr.b	(a1)+
		clr.l	(a1)+
		clr.b	(a1)+
		lea	34(a1),a1
		dbf	d0,CF_Loop
		rts

OffBuffer:	dc.b	'off',0

Equalizer2Handler:
		movem.l	d0-d7/A0-A6,-(sp)
		lea	Channel1,a0
		bsr.s	BuildEqu
		lea	Channel2,a0
		bsr.s	BuildEqu
		lea	Channel3,a0
		bsr.s	BuildEqu
		lea	Channel4,a0
		bsr.s	BuildEqu
		movem.l	(sp)+,d0-d7/a0-a6
		rts

BuildEqu:	tst.w	(a0)
		beq	BE_End
		move.l	WorkPlane,a2
		add.w	2(a0),a2
		move.w	4(a0),d0
		cmp.w	8(a0),d0
		blt.s	BE_NoNewHi
		move.w	d0,8(a0)
BE_NoNewHi:	lea	LeftTable,a1
		moveq	#5,d7
BE_Loop:	cmp.b	#8,d0
		blt.s	BE_Soft
		subq.b	#8,d0
		moveq	#-1,d1
		bsr.L	BE_SetByte
		dbf	d7,BE_Loop
		bra.s	BE_Ready
BE_Soft:	move.b	(a1,d0.w),d1
		bsr.s	BE_SetByte
		bra.s	BE_Clear
BE_ClearL:	moveq	#0,d1
		bsr.s	BE_SetByte
BE_Clear:	dbf	d7,BE_ClearL
BE_Ready:

		lea	HiCHRS,a1
		move.l	WorkPlane,a2
		add.w	2(a0),a2
		move.w	6(a0),d0
		cmp.w	4(a0),d0
		ble.s	BEHC_NoOld
		moveq	#5,d7
BEHC_Loop:	cmp.b	#8,d0
		blt.s	BEHC_Soft
		subq.b	#8,d0
		addq.w	#1,a2
		dbf	d7,BEHC_Loop
		bra.s	BEHC_Ready
BEHC_Soft:	move.b	(a1,d0.w),d1
		bsr.s	BE_AndByte
BEHC_Ready:
BEHC_NoOld:

		lea	HiCHRS,a1
		move.l	WorkPlane,a2
		add.w	2(a0),a2
		move.w	8(a0),d0
		move.w	d0,6(a0)
		moveq	#5,d7
BEH_Loop:	cmp.b	#8,d0
		blt.s	BEH_Soft
		subq.b	#8,d0
		addq.w	#1,a2
		dbf	d7,BEH_Loop
		bra.s	BEH_Ready
BEH_Soft:	move.b	(a1,d0.w),d1
		bsr.s	BE_OrByte
BEH_Ready:

		tst.w	4(a0)
		beq.s	BE_NoSub
		subq.w	#1,4(a0)
BE_NoSub:
BE_End:		rts


BE_SetByte:	move.b	d1,(a2)+
		move.b	d1,39(a2)
		move.b	d1,79(a2)
		move.b	d1,119(a2)
		move.b	d1,159(a2)
		rts
BE_AndByte:	not.b	d1
		and.b	d1,(a2)+
		and.b	d1,39(a2)
		and.b	d1,79(a2)
		and.b	d1,119(a2)
		and.b	d1,159(a2)
		rts
BE_OrByte:	or.b	d1,(a2)+
		or.b	d1,39(a2)
		or.b	d1,79(a2)
		or.b	d1,119(a2)
		or.b	d1,159(a2)
		rts

Channel1:	dc.w	1,4*40+33
Pos1:		dc.w	0,0,0
Channel2:	dc.w	1,15*40+33
Pos2:		dc.w	0,0,0
Channel3:	dc.w	1,26*40+33
Pos3:		dc.w	0,0,0
Channel4:	dc.w	1,37*40+33
Pos4:		dc.w	0,0,0

ChannelMask:	dc.w	$f
LeftTable:	dc.b	0,$80,$c0,$e0,$f0,$f8,$fc,$fe
HiCHRS:		dc.b	$80,$40,$20,$10,8,4,2,1

AddEquPeriode:	movem.l	a0/d0-d3,-(sp)
		cmp.w	#64,d2
		blt.s	AEP_NoOver
		moveq	#64,d2
AEP_NoOver:	lsl.w	#8,d2
		divu	#345,d2
		move.w	a5,d0
		cmp.b	#$a0,d0
		bne.s	AEP_Not1
		tst.w	Channel1
		beq	AEP_Error
		cmp.w	Pos1,d2
		blt.s	AEP_Not1
		move.w	d2,Pos1
AEP_Not1:	cmp.b	#$b0,d0
		bne.s	AEP_Not2
		tst.w	Channel2
		beq.s	AEP_Error
		cmp.w	Pos2,d2
		blt.s	AEP_Not2
		move.w	d2,Pos2
AEP_Not2:	cmp.b	#$c0,d0
		bne.s	AEP_Not3
		tst.w	Channel3
		beq.s	AEP_Error
		cmp.w	Pos3,d2
		blt.s	AEP_Not3
		move.w	d2,Pos3
AEP_Not3:	cmp.b	#$d0,d0
		bne.s	AEP_Not4
		tst.w	Channel4
		beq.s	AEP_Error
		cmp.w	Pos4,d2
		blt	AEP_Not4
		move.w	d2,Pos4
AEP_Not4:	movem.l	(sp)+,a0/d0-d3
		moveq	#1,d4
		rts
AEP_Error:	movem.l	(sp)+,a0/d0-d3
		moveq	#0,d4
		rts

* Load Part ***************************

* LoadPart anzeigen *******************

DisplayLoad:	bsr	WaitAllLifted
		move.w	#3,AW_Mode
		move.l	LoadPic,a0
		bsr	CopyPic
		bsr	ClearWorkPic
		clr.w	DirMode
		rts

ExecuteLoadGadgets:
		cmp.w	#69,d0
		blt	ELG_1
		cmp.w	#187,d0
		blt	FileSelected
		cmp.w	#11,d1
		blt	ScrollUp
		cmp.w	#43,d1
		blt	DisplayEqualizer
		bra	ScrollDown
ELG_1:		cmp.w	#11,d1
		blt	LoadModul
		cmp.w	#22,d1
		blt	LoadSong
		cmp.w	#33,d1
		blt	LoadPattern
		cmp.w	#44,d1
		blt	LoadPreset
		cmp.w	#55,d1
		blt	LoadSample
		rts

* Song-Dir laden **********************

LoadSong:	bsr	LoadInit
		lea	SongDiskName,a4
		move.l	#LoadSongDoIt,EntryJump
		bsr	CheckOldEntries
		beq.s	LS_Old
		bmi	SpriteRed
		bsr	ReadDir
		bne	SpriteRed
LS_Old:		tst.w	Entries
		beq	SpriteRed
		moveq	#0,d0
		bsr	PrintEntries
		move.w	#1,DirMode
		bra	SpriteGrey

SongDiskName:	dc.b	'st-00:songs',0

LoadPattern:	bsr	LoadInit
		lea	PatternDiskName,a4
		move.l	#LoadPatternDoIt,EntryJump
		bsr	CheckOldEntries
		beq.s	LP_Old
		bmi	SpriteRed
		bsr	ReadDir
		bne	SpriteRed
LP_Old:		tst.w	Entries
		beq	SpriteRed
		moveq	#0,d0
		bsr	PrintEntries
		move.w	#1,DirMode
		bra	SpriteGrey

PatternDiskName:dc.b	'st-00:patterns',0,0

LoadPreset:	bsr.s	LoadInit
		moveq	#0,d0
		bsr	PrintPresets
		move.w	#2,DirMode
		bra	SpriteGrey

LoadSample:	bsr	StopSong
		clr.l	EditMode
		bra	LoadSampleDoIt

LoadModul:	bsr	LoadInit
		lea	ModulDiskName,a4
		move.l	#LoadModulDoIt,EntryJump
		bsr	CheckOldEntries
		beq.s	LM_Old
		bmi	SpriteRed
		bsr	ReadDir
		bne	SpriteRed
LM_Old:		tst.w	Entries
		beq	SpriteRed
		moveq	#0,d0
		bsr	PrintEntries
		move.w	#1,DirMode
		bra	SpriteGrey

ModulDiskName:	dc.b	'st-00:modules',0
		even

* Lade initialisierung ****************

LoadInit:	bsr	SpriteGreen
		bsr	WaitAllLifted
		clr.w	DirMode
		bra	ClearWorkPic

* Checken ob alte Entries noch vorhanden

CheckOldEntries:move.l	DosBase,a6
		move.l	a4,d1
		move.l	#-2,d2
		jsr	Lock(a6)
		move.l	d0,ActualLock
		beq.s	COE_RError
		move.l	ActualLock,d1
		move.l	#FileInfoBlock,d2
		jsr	Examine(a6)
		tst.l	d0
		beq	COE_RErrorUL
		lea	FileInfoBlock,a0
		movem.l	132(a0),d0-d2

		cmp.l	EntryDirName,a4
		bne.s	COE_NewEntries
		cmp.l	EntryTime1,d0
		bne.s	COE_NewEntries
		cmp.l	EntryTime2,d1
		bne.s	COE_NewEntries
		cmp.l	EntryTime3,d2
		bne.s	COE_NewEntries

		move.l	ActualLock,d1
		jsr	UnLock(a6)
		moveq	#0,d0
		rts

COE_NewEntries:	move.l	a4,EntryDirName
		movem.l	d0-d2,EntryTime1
		clr.w	Entries
		move.l	ActualLock,d1
		jsr	UnLock(a6)
		moveq	#1,d0
		rts
COE_RErrorUL:	move.l	ActualLock,d1
		jsr	UnLock(a6)
COE_RError:	moveq	#-1,d0
		rts

* Directory neu lesen *****************

ReadDir:	move.l	DosBase,a6
		move.l	a4,d1
		moveq	#-2,d2
		jsr	Lock(a6)
		move.l	d0,ActualLock
		beq.s	RD_Error
		move.l	ActualLock,d1
		move.l	#FileInfoBlock,d2
		jsr	Examine(a6)
		tst.l	d0
		beq.s	RD_ErrorUL
RD_NextEntry:	move.l	ActualLock,d1
		move.l	#FileInfoBlock,d2
		jsr	ExNext(a6)
		tst.l	d0
		beq.s	RD_NoNextEntry
		bsr.s	AddEntry
		bra.s	RD_NextEntry
RD_NoNextEntry:	move.l	ActualLock,d1
		jsr	UnLock(a6)
		moveq	#0,d0
		rts
RD_ErrorUL:	move.l	ActualLock,d1
		jsr	UnLock(a6)
RD_Error:	moveq	#-1,d0
		rts

* hochscrollen ************************

ScrollUp:	tst.w	DirMode
		beq.s	SU_End
		move.w	TopEntry,d0
		beq.s	SU_End
		subq.w	#1,d0
		cmp.w	#2,DirMode
		beq	PrintPresets
		bra	PrintEntries
SU_End:		rts

* runter scrollen *********************

ScrollDown:	tst.w	DirMode
		beq.s	SD_End
		move.w	TopEntry,d0
		addq.w	#1,d0
		cmp.w	#2,DirMode
		beq.s	SD_Presets
		move.w	Entries,d1
		subq.w	#8,d1
		cmp.w	d1,d0
		bgt.s	SD_End
		bra	PrintEntries
SD_Presets:	move.w	PresetEntries,d1
		subq.w	#8,d1
		cmp.w	d1,d0
		bgt.s	SD_End
		bra	PrintPresets
SD_End:		rts

* Ein Entry einsortieren **************

AddEntry:	move.w	Entries,d6
		beq.L	AE_FirstEntry
		cmp.w	#8400/28,d6
		beq	AE_NoMoreMem
		subq.w	#1,d6
		lea	FileInfoBlock+8,a0
		move.l	EntryBuffer,a1
AE_NextDest:	moveq	#0,d2
		moveq	#0,d3
AE_TestLoop:	move.b	(a0,d2.w),d0
		beq.s	AE_Insert
		cmp.b	#96,d0
		blt.s	AE_Ok1
		sub.b	#32,d0
AE_Ok1:		move.b	(a1,d3.w),d1
		beq.s	AE_NextDest2
		cmp.b	#96,d1
		blt.s	AE_Ok2
		sub.b	#32,d1
AE_Ok2:		cmp.b	d0,d1
		bgt.s	AE_Insert
		beq.s	AE_NextZiff
AE_NextDest2:	add.w	#28,a1
		dbf	d6,AE_NextDest
		move.l	EntryBuffer,a1
		move.w	Entries,d0
		mulu	#28,d0
		add.w	d0,a1
		bra.s	AE_CopyEntry
AE_NextZiff:	addq.w	#1,d2
		addq.w	#1,d3
		bra.s	AE_TestLoop
AE_Insert:	move.l	EntryBuffer,a2
		move.w	Entries,d0
		mulu	#28,d0
		add.w	d0,a2
		move.l	a2,a3
		add.w	#28,a3
AE_CopyUp:	move.w	-(a2),-(a3)
		cmp.l	a2,a1
		bne.s	AE_CopyUp
		bra.s	AE_CopyEntry
AE_FirstEntry:	move.l	EntryBuffer,a1
AE_CopyEntry:	lea	FileInfoBlock+8,a0
		moveq	#27,d0
AE_Loop2:	move.b	(a0)+,d1
		beq.s	AE_Copy0
		move.b	d1,(a1)+
		dbf	d0,AE_Loop2
		bra.s	AE_All
AE_Copy0:	clr.b	(a1)+
		dbf	d0,AE_Copy0
AE_All:		addq.w	#1,Entries
AE_NoMoreMem:	rts

* Ab d0 Entries Printen ***************

PrintEntries:	move.w	d0,-(sp)
		bsr	ClearWorkPic
		move.w	(sp)+,d0
		move.w	d0,TopEntry
		lea	1984,a6
		move.l	a6,WorkPlaneOffset
		move.l	EntryBuffer,d6
		mulu	#28,d0
		add.l	d0,d6
		move.w	Entries,d0
		sub.w	TopEntry,d0
		cmp.w	#8,d0
		bge.s	PE_1
		subq.w	#1,d0
		move.w	d0,d7
		bra.s	PE_Loop
PE_1:		moveq	#7,d7
PE_Loop:	move.l	d6,TextPointer
		move.l	a6,WorkPlaneOffset
		moveq	#14,d0
		move.l	d0,TextLen
		bsr	PrintText1
		add.l	#28,d6
		lea	240(a6),a6
		dbf	d7,PE_Loop
		rts

* Presets ab d0 ausgeben **************

PrintPresets:	move.w	d0,-(sp)
		bsr	ClearWorkPic
		move.w	(sp)+,d0
		move.w	d0,TopEntry
		lea	1984,a6
		move.l	a6,WorkPlaneOffset
		move.l	PresetList,d6
		mulu	#30,d0
		add.l	d0,d6
		addq.l	#3,d6
		move.w	PresetEntries,d0
		sub.w	TopEntry,d0
		cmp.w	#8,d0
		bge.s	PP_1
		subq.w	#1,d0
		move.w	d0,d7
		bra.s	PE_Loop
PP_1:		moveq	#7,d7
PP_Loop:	move.l	d6,TextPointer
		move.l	a6,WorkPlaneOffset
		moveq	#14,d0
		move.l	d0,TextLen
		bsr	PrintText1
		add.l	#30,d6
		lea	240(a6),a6
		dbf	d7,PP_Loop
		rts

* File angeklickt *********************

FileSelected:	tst.w	DirMode
		beq.s	FS_End
		cmp.w	#4,d1
		blt.s	FS_End
		cmp.w	#51,d1
		bgt.s	FS_End
		subq.w	#4,d1
		and.l	#$ffff,d1
		divu	#6,d1
		move.w	TopEntry,d0
		add.w	d1,d0
		cmp.w	#2,DirMode
		beq.s	FS_Preset
		cmp.w	Entries,d0
		bge.s	FS_End
		mulu	#28,d0
		add.l	EntryBuffer,d0
		move.l	d0,a0
		move.l	EntryJump,a1
		jmp	(a1)
FS_Preset:	cmp.w	PresetEntries,d0
		bge.s	FS_End
		mulu	#30,d0
		add.l	PresetList,d0
		move.l	d0,a0
		bra	UsePreset
FS_End:		rts

EntryDirName:	dc.l	0
EntryTime1:	dc.l	0
EntryTime2:	dc.l	0
EntryTime3:	dc.l	0
TopEntry:	dc.w	0
Entries:	dc.w	0
EntryJump:	dc.l	0
DirMode:	dc.w	0		;0Keine Dir,1 Dir,2Presets
ActualLock:	dc.l	0

* SAVEPART ****************************

DisplaySave:	bsr	WaitAllLifted
		move.w	#4,AW_Mode
		move.l	SavePic,a0
		bsr	CopyPic
		bsr	ClearWorkPic
		bra	PrintSaveData

* Save Data ausgeben ******************

PrintSaveData:	bsr.s	PrintPackMode
		move.l	#2824,WorkPlaneOffset
		move.w	FirstPatt,PrintNumber
		bsr	PrintDez2
		move.l	#2828,WorkPlaneOffset
		move.w	LastPatt,PrintNumber
		bsr	PrintDez2
		move.l	#3268,WorkPlaneOffset
		move.w	SaveSDisk,PrintNumber
		bra	PrintDez2

PackModeChanged:bsr	WaitAllLifted
		not.w	PackModus
PrintPackMode:	tst.w	PackModus
		beq	PackModeOn
		move.l	#PackOffText,TextPointer
		bra	PMC_All
PackModeOn:	move.l	#PackOnText,TextPointer
PMC_All:	move.l	#3,TextLen
		move.l	#2388,WorkPlaneOffset
		bra	PrintText

PackOnText:	dc.b	'on ',0
PackOffText:	dc.b	'off',0

ExSaveGadgets:	cmp.w	#186,d0
		bgt	DisplayEqualizer
		cmp.w	#68,d0
		bgt.s	ESG_Special
		cmp.w	#11,d1
		blt	SaveModul
		cmp.w	#22,d1
		blt	SaveSong
		cmp.w	#33,d1
		blt	SavePatterns
		cmp.w	#44,d1
		blt	SaveSamples
		cmp.w	#55,d1
		blt	SaveSample
ESG_Ex:		rts
ESG_Special:	cmp.w	#134,d0
		bgt.s	ESG_Ex
		cmp.w	#11,d1
		blt	ESG_Ex
		cmp.w	#22,d1
		blt	PackModeChanged
		sub.w	#68,d0
		cmp.w	#33,d1
		blt	ESG_PattSpec
		cmp.w	#44,d1
		blt	ESG_SampleSpec
		rts

ESG_PattSpec:	cmp.w	#20,d0
		blt.s	ESG_Ex
		cmp.w	#27,d0
		blt.s	SubFirstPatt
		cmp.w	#34,d0
		blt.s	AddFirstPatt
		cmp.w	#52,d0
		blt.s	ESG_Ex
		cmp.w	#59,d0
		blt.s	SubLastPatt
		bra.s	AddLastPatt

SubFirstPatt:	tst.w	FirstPatt
		beq.s	SFP_Ex
		subq.w	#1,FirstPatt
		bra.s	ChangePatts
SFP_Ex:		rts

AddFirstPatt:	move.w	FirstPatt,d0
		cmp.w	LastPatt,d0
		beq.s	AFP_End
		addq.w	#1,FirstPatt
		bra.s	ChangePatts
AFP_End:	rts

SubLastPatt:	move.w	LastPatt,d0
		cmp.w	FirstPatt,d0
		beq.s	SLP_Ex
		subq.w	#1,LastPatt
		bra.s	ChangePatts
SLP_Ex:		rts

AddLastPatt:	cmp.w	#$3f,LastPatt
		beq.s	ALP_Ex
		addq.w	#1,LastPatt
		bra.s	ChangePatts
ALP_Ex:		rts

ChangePatts:	bsr	PrintSaveData
		bra	Wait

LoadPatternDoIt:move.l	a0,-(sp)
		bsr	StopSong
		clr.l	EditMode
		move.l	(sp)+,a0
		lea	PattName,a1
		moveq	#27,d0
LP_Copy:	move.b	(a0)+,(a1)+
		dbf	d0,LP_Copy
		clr.b	(a1)

		move.l	ActualTrack,d0
		lsl.l	#8,d0
		lsl.l	#2,d0
		move.l	#$10000,d1
		sub.l	d0,d1
		move.l	d1,FileLength
		move.l	SongPT,a0
		lea	SongHeader(a0),a0
		lea	(a0,d0.l),a0
		move.l	a0,FileBuffer
		move.l	#PattLoadName,FileNamePT
		bsr	ReadFile
		bra	DrawWorkPlane

SavePatterns:	lea	PattName,A0
		moveq	#$1B,D0
SP_Clear:	clr.b	(A0)+
		dbf	D0,SP_Clear
		move.l	SongPT,A0
		lea	PattName,A1
		moveq	#$13,D0
SP_Copy:	move.b	(A0)+,(A1)+
		dbf	D0,SP_Copy

		move.l	SongPT,a0
		lea	SongHeader(a0),a0
		moveq	#0,d0
		move.w	FirstPatt,d0
		lsl.l	#8,d0
		lsl.l	#2,d0
		lea	(a0,d0.l),a1
		move.l	a1,FileBuffer
		moveq	#0,d1
		move.w	LastPatt,d1
		addq.w	#1,d1
		lsl.l	#8,d1
		lsl.l	#2,d1
		sub.l	d0,d1
		move.l	d1,FileLength
		move.l	#PattLoadName,FileNamePT
		bsr	WriteFile
		bra	SpriteGrey

PattLoadName:	dc.b	'st-00:patterns/'
PattName:	blk.b	29,0

FirstPatt:	dc.w	0
LastPatt:	dc.w	0

ESG_SampleSpec:	cmp.w	#11,d0
		blt.s	Corrector
		cmp.w	#52,d0
		blt.L	ESG_Ex
		cmp.w	#59,d0
		blt.L	SubSDisk
		bra.L	AddSDisk

Corrector:	bsr	SpritePink
		bsr	SureWait
		bne	SpriteRed
		bsr	SpriteGrey
		move.w	SaveSDisk,d0
		divu	#10,d0
		add.b	#'0',d0
		move.b	d0,DiskNumTx
		swap	d0
		add.b	#'0',d0
		move.b	d0,DiskNumTx+1

		move.l	SongPT,a0
		lea	20(a0),a0
		moveq	#14,d7
C_Loop:		bsr.s	C_Correct
		lea	30(a0),a0
		dbf	d7,C_Loop
		bra	PrintSoundData
C_Correct:	tst.b	(a0)
		beq.s	CI_Ex
		move.b	DiskNumTx,d0
		move.b	DiskNumTx+1,d1
		cmp.b	#':',5(a0)
		beq.s	CI_Dir
		lea	15(a0),a1
		lea	21(a0),a2
		moveq	#14,d2
CI_Loop:	move.b	-(a1),-(a2)
		dbf	d2,CI_Loop
CI_Dir:		move.l	#'st- ',(a0)
		move.b	d0,3(a0)
		move.b	d1,4(a0)
		move.b	#':',5(a0)
CI_Ex:		rts

DiskNumTx:	dc.w	0

SubSDisk:	cmp.w	#1,SaveSDisk
		beq.s	SSD_Ex
		subq.w	#1,SaveSDisk
		bra.L	ChangePatts
SSD_Ex:		rts
AddSDisk:	cmp.w	#99,SaveSDisk
		beq.s	SSD_Ex
		addq.w	#1,SaveSDisk
		bra.L	ChangePatts

SaveSDisk:	dc.w	1

* SONG SPEICHERN *

SaveSong:	bsr	StopSong
		clr.l	EditMode
		bsr	SaveSongDoIt
		bra	SpriteGrey

SaveSample:	bsr	SaveSampleDoIt
		bra	SpriteGrey

SaveSamples:	move.w	#1,ActualSample
SS_LoadIt:	bsr	PrintSoundData
		bsr	SaveSampleDoIt
		addq.w	#1,ActualSample
		cmp.w	#16,ActualSample
		bne.s	SS_LoadIt
		move.w	#1,ActualSample
		bsr	PrintSoundData
		bra	SpriteGrey

SaveModul:	bsr	StopSong
		clr.l	EditMode
		bsr	SaveModulDoIt
		bra	SpriteGrey

* Actual Sound in SampleBuffer kopieren

CopyToSBuffer:	move.w	ActualSample,d0
		lsl.w	#2,d0
		lea	SoundMemEntries,A0
		move.l	(A0,D0.w),D1
		beq.s	CTSB_NoSound
		move.l	60(A0,D0.w),D0
		beq.s	CTSB_NoSound
		subq.l	#2,d0
		beq.s	CTSB_NoSound
		move.l	d0,SampleBufferLen
		move.l	d1,a0
		addq.w	#2,a0
		move.l	SampleBuffer,a1
		lsr.l	#1,d0
		subq.w	#1,d0
CTSB_CopySample:move.w	(a0)+,(a1)+
		dbf	d0,CTSB_CopySample
		bra	CTSB_1
CTSB_NoSound:	clr.l	SampleBufferLen
CTSB_1:		cmp.w	#2,AW_Mode
		bne.s	CTSB_2
		bsr	ClearWorkPic
		bsr	ShowSample
CTSB_2:		bra	Wait2

* SampleBuffer in Actual Sample kopieren + Laenge setzen

CopySample:	move.l	SampleBufferLen,d0	;Sample reservieren
		bsr.s	AllocSample
		beq	SpriteRed
		move.l	a0,a1
		move.l	SampleBuffer,a0
		clr.w	(a1)+		;Leer
		lsr.w	#1,d0
		subq.w	#2,d0		;-2Worte
		move.l	SampleBuffer,a0
CS_CopySample:	move.w	(a0)+,(a1)+
		dbf	d0,CS_CopySample
		bra	PrintSoundData

* Actual Sample reservieren ***********
* < Laenge d0 > Dest Ad a0 > Laenge d0 

AllocSample:	and.l	#-2,d0			;Laenge <>0 + ausmaskieren
		beq.L	AS_Error		;Laenge =0 o. 1
		move.l	d0,AS_Len

		lea	SoundMemEntries,A4
		move.w	ActualSample,d1
		lsl.w	#2,d1
		add.w	d1,a4

		move.l	(A4),D1
		beq.s	AS_NoOld		;Altes Sample?
		clr.l	(a4)
		move.l	D1,A1			;Altes Sample freigeben
		move.l	60(A4),D0
		move.l	4.w,a6
		jsr	-210(A6)

AS_NoOld:	move.l	AS_Len,d0		;reservieren
		move.l	#$10002,d1
		move.l	4.w,a6
		jsr	-198(a6)
		tst.l	d0
		beq.s	AS_Error
		move.l	d0,(a4)
		move.l	d0,AS_PT
		move.l	AS_Len,60(a4)

		move.l	SongPT,A0		;In songheader
		move.w	ActualSample,D1
		mulu	#30,D1
		lea	12(a0,d1.w),a0
		move.l	AS_Len,d0
		lsr.l	#1,d0
		move.w	d0,(a0)+
		move.w	#64,(a0)+
		clr.w	(a0)+
		move.w	#1,(a0)

		move.l	AS_PT,a0
		move.l	AS_Len,d0
		rts

AS_Error:	moveq	#0,d0
		rts
AS_PT:		dc.l	0
AS_Len:		dc.l	0

* Sample anzeigen *********************

ShowSample:	cmp.w	#2,AW_Mode
		bne.s	SS_End
		cmp.l	#112,SampleBufferLen
		ble	OrigShow
		move.l	SampleBuffer,a0
		move.l	SampleBufferLen,d1
		move.l	#112*$10000,d0
		divu	d1,d0
		and.l	#$ffff,d0
		moveq	#0,d1
		move.l	WorkPlane,a1
		lea	1985(a1),a1
		lea	SamplerOffsetTable,a2
		clr.w	d3
		moveq	#13,d7
ByteLoop:	moveq	#7,d6	
PixelLoop:	clr.w	d2
		move.b	(a0)+,d2
		eor.b	#$80,d2
		lsr.w	#3,d2
		add.w	d2,d2
		move.w	(a2,d2.w),d2
		bset	d6,(a1,d2.w)
		add.l	d0,d1
		move.l	d1,d2
		swap	d2
		cmp.w	d2,d3
		beq.s	PixelLoop
		move.w	d2,d3
		dbf	d6,PixelLoop
		addq.l	#1,a1
		dbf	d7,ByteLoop
SS_End:		rts
OrigShow:	move.l	SampleBuffer,a0
		add.l	SampleBufferLen,a0
		moveq	#112-1,d0
OS_ClearLoop:	move.b	#$ff,(a0)+
		dbf	d0,OS_ClearLoop
		move.l	SampleBuffer,a0
		move.l	WorkPlane,a1
		lea	1985(a1),a1
		lea	SamplerOffsetTable,a2
		moveq	#13,d7
ByteLoop2:	moveq	#7,d6	
PixelLoop2:	clr.w	d2
		move.b	(a0)+,d2
		eor.b	#$80,d2
		lsr.w	#3,d2
		add.w	d2,d2
		move.w	(a2,d2.w),d2
		bset	d6,(a1,d2.w)
		dbf	d6,PixelLoop2
		addq.l	#1,a1
		dbf	d7,ByteLoop2
		rts

* Picture reinkopieren ****************

CopyPic:	move.w	#145,d0
		bsr	WaitPos
		move.l	Pic,a1
		lea	1815(a1),a1
		moveq	#1,d7
CP_1:		move.l	a1,a3
		moveq	#54,d6
CP_2:		move.l	a1,a2
		moveq	#4,d5
CP_3:		move.b	(a0)+,(a1)+
		move.b	(a0)+,(a1)+
		move.b	(a0)+,(a1)+
		move.b	(a0)+,(a1)+
		move.b	(a0)+,(a1)+
		dbf	d5,CP_3
		addq.w	#1,a0
		move.l	a2,a1
		lea	40(a1),a1
		dbf	d6,CP_2
		move.l	a3,a1
		lea	$2800(a1),a1
		dbf	d7,CP_1
		rts

* Picture loeschen ********************

ClearWorkPic:	move.w	#145,d0
		bsr	WaitPos
		move.l	WorkPlane,a1
		lea	1815(a1),a1
		moveq	#54,d6
CWP_2:		move.l	a1,a2
		moveq	#4,d5
CWP_3:		clr.b	(a1)+
		clr.b	(a1)+
		clr.b	(a1)+
		clr.b	(a1)+
		clr.b	(a1)+
		dbf	d5,CWP_3
		addq.w	#1,a0
		move.l	a2,a1
		lea	40(a1),a1
		dbf	d6,CWP_2
		rts

* Pointer auf alten Wert stellen ******

InitPointer:	moveq	#0,d0
		move.b	$dff00a,d0
		move.w	d0,OldY
		move.b	$dff00b,d0
		move.w	d0,OldX
		rts

* Auf Maustasten warten ***************

WaitAllLifted:	btst	#6,$bfe001
		beq.s	WaitAllLifted
		btst	#10,$dff016
		beq.s	WaitAllLifted
		move.w	#145,d0
		bra	WaitPos

SureWait:	bsr.s	WaitAllLifted
WaitUntilSure:	btst	#10,$dff016
		beq	Sure
		btst	#6,$bfe001
		bne.s	WaitUntilSure
		moveq	#-1,d0
		rts
Sure:		moveq	#0,d0
		rts

* Auf RasterPos d0 warten *************

WaitPos:	move.l	$dff004,d1
		lsr.l	#8,d1
		and.w	#$1ff,d1
		cmp.w	d1,d0
		bne.s	WaitPos
		rts

* Spritefarbe setzen ******************

SpriteGrey:	lea	GreyColors,a0
		bra.s	SetSpriteColors
SpriteYellow:	lea	YellowCols,a0
		bra.s	SetSpriteColors
SpriteGreen:	lea	GreenColors,a0
		bra.s	SetSpriteColors
SpriteBlue:	lea	BlueColors,a0
		bra.s	SetSpriteColors
SpritePink:	lea	PinkColors,a0
SetSpriteColors:move.l	a1,-(sp)
		lea	CopperColors,a1
		move.w	(a0)+,2(a1)
		move.w	(a0)+,6(a1)
		move.w	(a0)+,10(a1)
		move.l	(sp)+,a1
		rts

GreyColors:	dc.w	$aaa,$888,$666
YellowCols:	dc.w	$ba0,$980,$760
GreenColors:	dc.w	$a0,$80,$60
BlueColors:	dc.w	$5b,$49,$b
PinkColors:	dc.w	$a5a,$828,$606

* Sprite Rot + warten *****************

SpriteRed:	lea	CopperColors,a0
		move.w	#$C00,2(A0)
		move.w	#$900,6(A0)
		move.w	#$700,$A(A0)
		moveq	#$F,D1
SR_Loop:	bsr	Wait
		dbf	D1,SR_Loop
		bra.s	SpriteGrey

L044782:	tst.l	SongMode
		beq	CheckPosKeys
		rts
CheckPosKeys:	cmp.b	#$55,Taste
		bne.s	NotF6
		clr.w	WorkPosY
		bsr	MoveWorkPlane
		clr.b	Taste
		rts
NotF6:		cmp.b	#$56,Taste
		bne.s	l0447d6
		move.w	#$10,WorkPosY
		bsr	MoveWorkPlane
		clr.b	Taste
		rts
L0447D6:	cmp.b	#$57,Taste
		bne.s	l0447f8
		move.w	#$20,WorkPosY
		bsr	MoveWorkPlane
		clr.b	Taste
		rts
L0447F8:	cmp.b	#$58,Taste
		bne.s	l04481a
		move.w	#$30,WorkPosY
		bsr	MoveWorkPlane
		clr.b	Taste
		rts
L04481A:	cmp.b	#$59,Taste
		bne.s	l04483a
		move.w	#$3F,WorkPosY
		bsr	MoveWorkPlane
		clr.b	Taste
L04483A:	rts

* Taste mit Shift gedrueckt ? *********

CheckShift:	tst.w	ShiftMode
		bne	ShiftTest
		moveq	#0,d0
		move.l	d0,a0
		tst.w	AltMode
		bne	CheckEditKeys
		rts

* Trackoffset berechnen ***************

ShiftTest:	cmp.w	#15,CursorX
		bne.s	TrackNot4
		moveq	#12,d0
		move.l	d0,a0
		bra	CheckEditKeys
TrackNot4:	cmp.w	#10,CursorX
		bne.s	TrackNot3
		moveq	#8,d0
		move.l	d0,a0
		bra	CheckEditKeys
TrackNot3:	cmp.w	#5,CursorX
		bne.s	TrackNot2
		moveq	#4,d0
		move.l	d0,a0
		bra	CheckEditKeys
TrackNot2:	tst.w	CursorX
		bne	TrackNot1
		moveq	#0,d0
		move.l	d0,a0
		bra	CheckEditKeys
TrackNot1:	rts

CheckEditKeys:	add.l	SongPT,A0
		lea	SongHeader(a0),A0
		move.l	ActualTrack,D0
		lsl.l	#8,d0
		lsl.l	#2,d0
		add.l	d0,a0
		tst.w	AltMode
		bne.s	PatternControl
		cmp.b	#$52,Taste
		beq	ClearTrack
		cmp.b	#$53,Taste
		beq	CopyTrack
		cmp.b	#$54,Taste
		beq	PasteTrack
		rts

PatternControl:	cmp.b	#$52,Taste
		beq.s	ClearPattern
		cmp.b	#$53,Taste
		beq.s	CopyPattern
		cmp.b	#$54,Taste
		beq.s	PastePattern
		rts

* Aktuelles Pattern loeschen **********

ClearPattern:	lea	PatternBuffer,a1
		move.w	#255,d0
CLP_Loop:	move.l	(a0),(a1)+
		clr.l	(A0)+
		dbf	d0,CLP_Loop
		clr.b	Taste
		bra	DrawWorkPlane

* Pattern in Buffer kopieren **********

CopyPattern:	lea	PatternBuffer,A1
		move.w	#255,d0
CP_Loop:	move.l	(A0)+,(A1)+
		dbf	d0,CP_Loop
		clr.b	Taste
		rts

* Pattern von Buffer pasten ***********

PastePattern:	lea	PatternBuffer,A1
		move.w	#255,d0
PP2_Loop:	move.l	(A1)+,(A0)+
		dbf	d0,PP2_Loop
		clr.b	Taste
		bra	DrawWorkPlane

* Aktuelle Spur loeschen **************

ClearTrack:	lea	BufferTrack,a1
		moveq	#63,d0
CLT_Loop:	move.l	(a0),(a1)+
		clr.l	(A0)
		lea	16(a0),a0
		dbf	d0,CLT_Loop
		clr.b	Taste
		bra	DrawWorkPlane

* Track(Spur) in Buffer kopieren ******

CopyTrack:	lea	BufferTrack,A1
		moveq	#63,d0
CT_Loop:	move.l	(A0),(A1)+
		lea	16(a0),a0
		dbf	d0,CT_Loop
		clr.b	Taste
		rts

* Spur von Buffer in pasten ***********

PasteTrack:	lea	BufferTrack,A1
		moveq	#63,d0
PT_Loop:	move.l	(A1)+,(A0)
		lea	16(a0),a0
		dbf	d0,PT_Loop
		clr.b	Taste
		bra	DrawWorkPlane

* f1 oder f2 gedrueckt ? **************

CheckOktaves:	cmp.b	#$50,Taste
		beq.s	SetOktave1
		cmp.b	#$51,Taste
		beq.s	SetOktave2
		rts

SetOktave1:	move.l	#PeriodTab1,ActualPeriodTab
		move.l	#NoteTab1,ActualNoteTab
		clr.b	Taste
		rts

SetOktave2:	move.l	#PeriodTab2,ActualPeriodTab
		move.l	#NoteTab2,ActualNoteTab
		clr.b	Taste
		rts

CheckCursor:	tst.w	AltMode
		beq.s	CC_Ex2
		move.b	Taste,d0
		cmp.b	#$4e,d0
		beq.s	CC_R
		cmp.b	#$4f,d0
		beq.s	CC_L
CC_Ex2:		rts
CC_L:		subq.l	#1,ActualTrack
CC_Ex:		and.l	#$3f,ActualTrack
		bra	DrawWorkPlane
CC_R:		addq.l	#1,ActualTrack
		bra.s	CC_Ex




SetMausSprite:	move.w	MouseXPos,D0
		subq.w	#4,D0
		move.w	MouseYPos,D1
		moveq	#$10,D2
		lea	OrigMouseSprite,A0
		bra	SetSpritePos
L0449C8:	cmp.l	#'edit',EditMode
		beq.s	l0449d8
		rts
L0449D8:	lea	HexRawTab,A0
		moveq	#0,d0
		moveq	#0,d1
		move.b	Taste,D0
L0449E8:	cmp.b	(A0)+,D0
		beq.s	l044a00
		addq.b	#1,D1
		cmp.b	#$10,D1
		beq.s	l0449fe
		bra.s	L0449E8
L0449FE:	rts
L044A00:	move.w	CursorX,d0
		cmp.w	#1,d0
		bne.s	l044a22
		move.l	#$FFF,D2
		move.w	#2,L04701C
		lsl.w	#4,D1
		lsl.w	#8,D1
		bra	L044BFC
L044A22:	cmp.w	#2,d0
		bne.s	l044a42
		move.l	#$F0FF,D2
		move.w	#2,L04701C
		lsl.w	#8,D1
		bra	L044BFC
L044A42:	cmp.w	#3,d0
		bne.s	l044a62
		move.l	#$FF0F,D2
		move.w	#2,L04701C
		lsl.w	#4,D1
		bra	L044BFC
L044A62:	cmp.w	#4,d0
		bne.s	l044a80
		move.l	#$FFF0,D2
		move.w	#2,L04701C
		bra	L044BFC
L044A80:	cmp.w	#6,d0
		bne.s	l044aa2
		move.l	#$FFF,D2
		move.w	#6,L04701C
		lsl.w	#4,D1
		lsl.w	#8,D1
		bra	L044BFC
L044AA2:	cmp.w	#7,d0
		bne.s	l044ac2
		move.l	#$F0FF,D2
		move.w	#6,L04701C
		lsl.w	#8,D1
		bra	L044BFC
L044AC2:	cmp.w	#8,d0
		bne.s	l044ae2
		move.l	#$FF0F,D2
		move.w	#6,L04701C
		lsl.w	#4,D1
		bra	L044BFC
L044AE2:	cmp.w	#9,d0
		bne.s	l044b00
		move.l	#$FFF0,D2
		move.w	#6,L04701C
		bra	L044BFC
L044B00:	cmp.w	#$B,d0
		bne.s	l044b22
		move.l	#$FFF,D2
		move.w	#$A,L04701C
		lsl.w	#4,D1
		lsl.w	#8,D1
		bra	L044BFC
L044B22:	cmp.w	#$C,d0
		bne.s	l044b42
		move.l	#$F0FF,D2
		move.w	#$A,L04701C
		lsl.w	#8,D1
		bra	L044BFC
L044B42:	cmp.w	#$D,d0
		bne.s	l044b62
		move.l	#$FF0F,D2
		move.w	#$A,L04701C
		lsl.w	#4,D1
		bra.s	L044BFC
L044B62:	cmp.w	#$E,d0
		bne.s	l044b80
		move.l	#$FFF0,D2
		move.w	#$A,L04701C
		bra.s	L044BFC
L044B80:	cmp.w	#$10,d0
		bne.s	l044ba2
		move.l	#$FFF,D2
		move.w	#$E,L04701C
		lsl.w	#4,D1
		lsl.w	#8,D1
		bra.s	L044BFC
L044BA2:	cmp.w	#$11,d0
		bne.s	l044bc2
		move.l	#$F0FF,D2
		move.w	#$E,L04701C
		lsl.w	#8,D1
		bra.s	L044BFC
L044BC2:	cmp.w	#$12,d0
		bne.s	l044be2
		move.l	#$FF0F,D2
		move.w	#$E,L04701C
		lsl.w	#4,D1
		bra.s	L044BFC
L044BE2:	cmp.w	#$13,d0
		bne.s	l044bfc
		move.l	#$FFF0,D2
		move.w	#$E,L04701C
L044BFC:	move.l	SongPT,A0
		lea	SongHeader(a0),A0
		move.l	ActualTrack,D0
		lsl.l	#8,d0
		lsl.l	#2,d0
		add.l	d0,a0
		moveq	#0,d0
		move.w	WorkPosY,D0
		lsl.w	#4,d0
		ext.l	d0
		add.l	d0,a0
		add.w	L04701C,A0
		AND.w	D2,(A0)
		add.w	D1,(A0)
		move.w	(A0),PrintNumber
		moveq	#0,d0
		move.w	WorkPosY,D0
		mulu	#$118,D0
		move.w	CursorX,D1
		DIVU	#5,D1
		mulu	#9,D1
		add.l	D1,D0
		add.l	#$1D68,D0
		move.l	D0,WorkPlaneOffset
		bsr	PrintHex4
		bsr	l044f82
		clr.b	Taste
		rts
L044C6E:	tst.b	Taste
		bne	L044C7C
		rts

L044C7C:	move.w	CursorX,d0
		beq	L044CBC
		cmp.w	#5,d0
		beq.s	l044cbc
		cmp.w	#10,d0
		beq.s	l044cbc
		cmp.w	#15,d0
		beq.s	l044cbc
		cmp.l	#'edit',EditMode
		beq	l0449c8
		rts
L044CBC:	moveq	#0,d1
		lea	NoteRawTab,A0
		move.b	Taste,D1
		moveq	#0,d0
L044CCC:	move.l	D0,D4
		tst.b	(a0)
		beq.s	l044_Ex
		cmp.b	(A0)+,D1
		beq.s	l044ce4
		addq.b	#1,D0
		bra.s	l044ccc
l044_Ex:	rts
L044CE4:	clr.b	Taste
		add.w	d0,d0
		add.w	d4,d4
		moveq	#0,d3
		move.l	ActualPeriodTab,A1
		move.w	(A1,D0.w),D3
		bmi.s	l044_Ex
		move.w	D3,PeriodSave
		tst.l	EditMode
		beq	L044DE0
		move.l	SongPT,A0
		lea	SongHeader(a0),a0
		move.l	ActualTrack,D0
		lsl.l	#8,d0
		lsl.l	#2,d0
		add.l	D0,A0
		moveq	#0,d0
		move.w	WorkPosY,D0
		lsl.w	#4,D0
		ext.l	d0
		add.l	D0,A0
		move.w	CursorX,D0
		DIVU	#5,D0
		lsl.w	#2,d0
		ext.l	d0
		add.l	D0,A0
		move.w	D3,(A0)
		tst.w	PeriodSave
		beq	L044D60
		moveq	#0,d0
		move.w	ActualSample,D0
		lsl.b	#4,D0
		and.b	#$F,2(A0)
		add.b	D0,2(A0)
		bra	L044D66
L044D60:	and.w	#$FFF,2(A0)
L044D66:	move.w	2(A0),L046FF0
		move.l	ActualNoteTab,A0
		add.w	d4,d4
		ext.l	d4
		add.l	D4,A0
		move.l	A0,TextPointer
		move.l	#3,TextLen
		moveq	#0,d0
		move.w	WorkPosY,D0
		mulu	#$118,D0
		move.w	CursorX,D1
		DIVU	#5,D1
		mulu	#9,D1
		add.l	D1,D0
		add.l	#$1D64,D0
		move.l	D0,WorkPlaneOffset
		bsr	PrintText
		move.w	L046FF0,PrintNumber
		addq.l	#1,WorkPlaneOffset
		bsr	PrintHex4
		bsr	l044f82
L044DE0:	tst.w	PeriodSave
		bne.s	L044DF4
		rts
L044DF4:	moveq	#0,d0
		move.l	d0,a5
		move.w	CursorX,d0
		lea	l04708e,a6
		cmp.w	#$F,d0
		bne.s	l044e12
		lea	$DFF0D0,A5
		move.w	#8,(a6)
		bra.s	L044E6E
L044E12:	cmp.w	#$A,d0
		bne.s	l044e30
		lea	$DFF0C0,A5
		move.w	#4,(a6)
		bra.s	L044E6E
L044E30:	cmp.w	#5,d0
		bne.s	l044e4e
		lea	$DFF0B0,A5
		move.w	#2,(a6)
		bra.s	L044E6E
L044E4E:	tst.w	d0
		bne.s	L044E6C
		lea	$DFF0A0,A5
		move.w	#1,(a6)
		bra.s	L044E6E
L044E6C:	rts
L044E6E:	lea	ActualLength,A6
		move.w	L04708E,d0
		and.w	ChannelMask,d0
		move.w	d0,$DFF096
		move.l	8(A6),(A5)
		move.l	8(A6),D1
		move.w	(A6),4(A5)
		move.w	4(A6),D0
		beq	L044EA4
		move.l	D1,D0
		add.w	4(A6),D0
		move.l	D0,(A5)
		move.w	6(A6),4(A5)
L044EA4:	move.w	PeriodSave,d0
		move.w	d0,6(A5)
		bsr	AddPeriode1
		move.w	2(A6),8(A5)
		move.w	#$1F4,D0
L044EB8:	dbf	D0,L044EB8
		move.w	L04708E,D0
		and.w	ChannelMask,d0
		or.w	#$8000,d0
		move.w	D0,$DFF096
		add.w	4(A6),D1
		move.l	D1,(A5)
		move.w	6(A6),4(A5)
		clr.w	L04708E
		rts

ControlCursor:	move.b	Taste,d0
		tst.w	AltMode
		bne.s	CC_NoLR
		cmp.b	#$4e,d0
		beq	CursorRight
		cmp.b	#$4f,d0
		beq	CursorLeft
CC_NoLR:	cmp.b	#$4c,d0
		beq.s	CursorUp
		cmp.b	#$4d,d0
		beq.s	CursorDown
		clr.w	L044EE8
		rts

CursorUp:	tst.w	L044EE8
		beq.s	L044F40
		addq.w	#1,L044EEA
		tst.w	ShiftMode
		bne.s	FastUp
		tst.w	AltMode
		bne.s	FasterUp
		cmp.w	#6,L044EEA
		bpl.s	L044F40
		rts

FastUp:		cmp.w	#3,l044eea
		bpl	l044f40
		rts

FasterUp:	cmp.w	#1,l044eea
		bpl	l044f40
		rts

L044F40:	clr.w	L044EEA
		move.w	#-1,L044EE8
		cmp.l	#'patt',SongMode
		beq.s	NoMove1
		subq.w	#1,WorkPosY
		and.w	#$3F,WorkPosY
		bra	MoveWorkPlane
NoMove1:	rts

CursorDown:	tst.w	L044EE8
		beq	L044F82
		addq.w	#1,L044EEA
		tst.w	ShiftMode
		bne	FastDown
		tst.w	AltMode
		bne	FasterDown
		cmp.w	#6,L044EEA
		bpl	L044F82
		rts

FastDown:	cmp.w	#3,L044EEA
		bpl	L044F82
		rts

FasterDown:	cmp.w	#1,L044EEA
		bpl	L044F82
		rts

L044F82:	clr.w	L044EEA
		move.w	#-1,L044EE8
		cmp.l	#'patt',SongMode
		beq.s	NoMove2
		addq.w	#1,WorkPosY
		and.w	#$3F,WorkPosY
		bra	MoveWorkPlane
NoMove2:	rts

CursorRight:	tst.w	L044EE8
		beq	L044FC4
		addq.w	#1,L044EEA
		tst.w	ShiftMode
		bne	FastRight
		cmp.w	#6,L044EEA
		bpl	L044FC4
		rts

FastRight:	cmp.w	#4,L044EEA
		bpl.s	L044FC4
		rts

L044FC4:	clr.w	L044EEA
		move.w	#-1,L044EE8
		addq.w	#1,CursorX
		cmp.w	#$14,CursorX
		bmi.s	L044FEC
		clr.w	CursorX
L044FEC:	bra	SetCursor

CursorLeft:	tst.w	L044EE8
		beq	L04500C
		addq.w	#1,L044EEA
		tst.w	ShiftMode
		bne	FastLeft
		cmp.w	#6,L044EEA
		bpl	L04500C
		rts

FastLeft:	cmp.w	#4,L044EEA
		bpl	L04500C
		rts
L04500C:	clr.w	L044EEA
		move.w	#-1,L044EE8
		subq.w	#1,CursorX
		tst.w	CursorX
		bpl	L045034
		move.w	#$13,CursorX
L045034:	bra	SetCursor

SetCursor:	move.w	CursorX,D0
		lea	CursorXTab,A0
		move.b	(A0,D0.w),D0
		lsl.w	#3,d0
		add.w	#9,D0
		move.w	#$BD,D1
		moveq	#$E,D2
		lea	TonCursorSprite,a0
		bra	SetSpritePos

*
* Textcursor an x/y setzen
*

SetTextCursor:	move.w	TextCursorXPos,D0
		move.w	TextCursorYPos,D1
		subq.w	#1,d0
		moveq	#2,D2
		lea	TextCursorSprite,A0
		bra	SetSpritePos

L04508A:	bsr	SetMausSprite
		bsr	ControlCursor
		bsr.s	TestGadgets
		cmp.w	#-1,L04702E
		beq.s	l0450c6
		moveq	#0,d0
L0450A4:	addq.l	#1,D0
		cmp.l	#$9C40,D0
		beq.s	l0450c6
		btst	#6,$BFE001
		beq.s	L0450A4
		clr.w	L047038
		bra	L0446A0

L0450C6:	move.w	#-1,L04702E
		btst	#6,$BFE001
		beq.s	L04508A
		clr.w	L04702E
		clr.w	L047038
		bra	L0446A0

TestGadgets:	move.w	MouseXPos,ActualXPos
		bne.s	NoQuit
		tst.w	MouseYPos
		bne.s	NoQuit
		btst	#10,$dff016
		beq	Quit
NoQuit:		move.w	ActualXPos,d0
		move.w	MouseYPos,d1
		move.w	d1,ActualYPos
		cmp.w	#$7a,d1
		bge	GetActualPattern
		cmp.w	#$6f,d1
		bge	GetSampleName
		cmp.w	#$64,d1
		bge	GetSongName

		cmp.w	#244,d0
		bge	CheckChannelGadgets
		cmp.w	#181,d0
		bge	CheckMenuGadgets
		cmp.w	#120,d0
		bge	CheckPlayGadgets
		cmp.w	#$6d,d0
		bge	CheckSubGadgets
		cmp.w	#$62,d0
		bge	CheckAddGadgets
		rts

CheckMenuGadgets:
		cmp.w	#$2d,d1
		bge	ActionWindow
		cmp.w	#$22,d1
		bge	DisplaySave
		cmp.w	#$17,d1
		bge	DisplayLoad
;		cmp.w	#$c,d1
;		bge	DisplaySpecial
		tst.w	d1
		bge	DisplaySampler
		rts

CheckPlayGadgets:
		cmp.w	#$2d,d1
		bge	ActionWindow
		cmp.w	#$22,d1
		bge	Edit
		cmp.w	#$17,d1
		bge	StopSong
		cmp.w	#$c,d1
		bge	Play
		tst.w	d1
		bge	Pattern
		rts

CheckSubGadgets:move.w	#-1,L047038
		bra.s	CheckAddSubGG

CheckAddGadgets:clr.w	L047038
CheckAddSubGG:	cmp.w	#$59,d1
		bge	ChangeRepLen
		cmp.w	#$4e,d1
		bge	ChangeRepeat
		cmp.w	#$43,d1
		bge	ChangeVolume
		cmp.w	#$38,d1
		bge	ChangeLength
		cmp.w	#$2d,d1
		bge	ChangeSound
		cmp.w	#$22,d1
		bge	ChangeSpeed
		cmp.w	#$17,d1
		bge	L045D96
		cmp.w	#$c,d1
		bge	L045E04
		tst.w	d1
		bge	L045E8E
		rts

GetActualPattern:
		clr.w	WorkPosY
		clr.w	CursorX
		clr.l	ActualTrack
		bsr	StopSong
		bsr	SpritePink
		clr.b	Taste
		move.w	#$C,TextCursorXPos
		move.w	#$88,TextCursorYPos
		bsr	SetTextCursor
		move.l	#$1479,WorkPlaneOffset
		bsr	L045368
		move.b	D1,D0
		mulu	#10,D0
		move.b	D0,ActualTrack+3
		bsr	PrintDez1
		move.w	#$14,TextCursorXPos
		move.w	#$88,TextCursorYPos
		bsr	SetTextCursor
		bsr.s	l045368
		add.b	D1,ActualTrack+3
		and.l	#$3F,ActualTrack
		clr.w	TextCursorXPos
		move.w	#$10E,TextCursorYPos
		bsr	SetTextCursor
		bsr	DrawWorkPlane
		bsr	SetCursor
		bra	SpriteGrey

L045368:	moveq	#0,d0
		move.b	Taste,d0
		beq.s	l045368
		clr.b	Taste
		cmp.b	#10,d0
		beq.s	GAP_0
		bgt.s	l045368
		cmp.b	#1,d0
		blt.s	l045368
Raus1:		move.l	d0,d1
		rts
GAP_0:		moveq	#0,d1
		rts

PrintDez1:	add.b	#$30,D1
		move.b	D1,TextBuffer
		clr.w	D1
		swap	D1
		move.l	#1,TextLen
		move.l	#TextBuffer,TextPointer
		bsr	PrintText
		clr.l	TextBuffer
		clr.w	PrintNumber
		rts
L0453D8:	move.w	MouseXPos,D0
		subq.l	#4,D0
		move.w	#$10E,D1
		moveq	#$10,D2
		lea	OrigMouseSprite,A0
		bsr	SetSpritePos
		lea	RawCodes,A5
		clr.b	Taste
		bsr	PrintSoundData
		bsr	PrintPosPatt
L04540E:	tst.b	Taste
		beq.s	L04540E
		cmp.b	#$41,Taste
		beq.s	l045494
		cmp.b	#$44,Taste
		beq	l0454cc
		clr.w	d1
		move.b	Taste,D1
		btst	#7,d1
		bne.s	l04540e
		tst.w	ShiftMode
		beq	NoShiftMode1
		bset	#7,d1
NoShiftMode1:	moveq	#0,d0
L04543A:	cmp.b	(A5,D0.w),D1
		beq.s	l045452
		addq.b	#1,D0
		cmp.b	#46,D0
		bgt.s	L04540E
		bra.s	L04543A
L045452:	move.l	L047026,D1
		cmp.l	A6,D1
		bne.s	l045462
		bra.s	L04540E
L045462:	lea	AllowedKeys,A0
		move.b	(A0,D0.w),(A6)
		addq.w	#1,A6
		addq.w	#8,TextCursorXPos
		bsr	SetTextCursor
		bsr	PrintSoundData
		bsr	PrintPosPatt
		clr.b	Taste
		bra.s	L04540E
L045494:	cmp.w	#$6C,TextCursorXPos
		bne.s	l0454a4
		bra	L04540E
L0454A4:	subq.w	#1,A6
		clr.b	(A6)
		subq.w	#8,TextCursorXPos
		bsr	SetTextCursor
		bsr	PrintSoundData
		bsr	PrintPosPatt
		clr.b	Taste
		bra	L04540E
L0454CC:	clr.w	TextCursorXPos
		move.w	#$10E,TextCursorYPos
		bra	SetTextCursor

* Sample Name eingeben ****************

GetSampleName:	bsr	SpritePink
		clr.l	EditMode
		move.l	SongPT,A6
		move.w	ActualSample,D0
		mulu	#30,D0
		lea	-10(a6,d0.l),a6
		moveq	#0,d0
L04550A:	clr.b	(A6,D0.w)
		addq.w	#1,D0
		cmp.w	#$16,D0
		bne.s	l04550a
		move.w	#$6C,TextCursorXPos
		move.w	#$77,TextCursorYPos
		bsr	SetTextCursor
		move.l	A6,L047026
		add.l	#$15,L047026
		bsr	L0453D8
		clr.l	L047026
		bra	SpriteGrey

* Song Name eingeben ******************

GetSongName:	bsr	SpritePink
		clr.l	EditMode
		move.l	SongPT,A6
		moveq	#19,d0
GSN_Clear:	clr.b	(a6,d0.w)
		dbf	d0,GSN_Clear
		moveq	#$6c,d0
		move.w	d0,TextCursorXPos
		move.w	d0,TextCursorYPos
		bsr	SetTextCursor
		move.l	a6,L047026
		add.l	#$13,L047026
		bsr	L0453D8
		clr.l	L047026
		bra	SpriteGrey

* Actual Sample laden *****************

LoadSampleDoIt:	move.w	ActualSample,D0
		bsr	FreeSample

		move.l	SongPT,A0		;Laenge holen
		move.w	ActualSample,D0
		mulu	#30,D0
		lea	12(a0,d0.w),a0
		moveq	#0,d0
		move.w	(A0),D0
		beq	ClearActSample		;Nicht laden bei 0
		add.l	d0,d0
		move.l	D0,FileLength

		lea	-22(a0),a0
		lea	SampleName,A1
		moveq	#$15,D0
L045676:	move.b	(A0)+,(A1)+
		dbf	D0,L045676
		clr.b	(a1)
		lea	SampleName,a0
		cmp.b	#':',5(a0)
		beq.s	DiskFromName
		move.l	#SampleFileName,FileNamePT
		bra.s	DFN_1
DiskFromName:	move.l	#SampleName,FileNamePT
DFN_1:		move.l	FileLength,D0
		move.l	#$10002,D1
		move.l	4.w,a6
		jsr	-198(A6)
		move.l	D0,FileBuffer
		beq.s	LS_Error
		bsr	PrintSoundData
		lea	SoundMemEntries,A0
		move.w	ActualSample,D1
		lsl.w	#2,d1
		move.l	FileBuffer,(a0,d1.w)
		move.l	FileLength,$3C(A0,D1.w)
		bsr	ReadFile
		bne.s	LS_Error
		move.l	FileBuffer,a0
		clr.w	(a0)
		bra	PrintSoundData

LS_Error:	bsr.s	ClearActSample
		bra	SpriteRed

* Act Sample loeschen *****************

ClearActSample:	move.w	ActualSample,d0
		bsr.s	FreeSample
		move.l	SongPT,a0
		move.w	ActualSample,d0
		mulu	#30,d0
		lea	-10(a0,d0.w),a0
		moveq	#27,d0
CAS_Clear:	clr.b	(a0)+
		dbf	d0,CAS_Clear
		move.w	#1,(a0)
		bra	PrintSoundData

* Sample d0 freigeben *****************

FreeSample:	lea	SoundMemEntries,A0
		lsl.w	#2,d0
		move.l	(A0,D0.w),D1
		beq.s	FS_NoOldSample
		clr.l	(a0,d0.w)
		move.l	$3C(A0,D0.w),D0
		move.l	D1,A1
		move.l	4.w,a6
		jmp	-210(A6)
FS_NoOldSample:	rts

* Song laden **************************

LoadSongDoIt:	move.l	a0,-(sp)
		bsr	StopSong
		clr.l	EditMode
		bsr	ClearSong
		move.l	(sp)+,a0
		lea	SongName,A1
		moveq	#$13,D0
LS_CopySongName:move.b	(A0)+,(A1)+
		dbf	D0,LS_CopySongName
		move.l	SongPT,FileBuffer
		move.l	#SongFileName,FileNamePT
		move.l	#$11000+SongHeader,FileLength
		bsr	ReadFile
		bne.L	LS_RError
		move.l	SongPT,a0
		cmp.l	#'PACK',(a0)
		bne.s	NoPackedFile
		move.l	4(a0),DestLength		;CompactLen
		move.l	8(a0),SourceLength		;UncompactLen
		move.l	SongPT,d0
		add.l	#$11000+SongHeader,d0
		sub.l	SourceLength,d0
		move.l	d0,SourceAd

		bsr	RePackIt

NoPackedFile:	bsr.L	InitNewSong

* SORT-LADEROUTINE *
		move.w	#$7fff,SampleBits
		bsr.s	GetVolTable

		lea	VolTable,a0
		moveq	#0,d7
LS_NextNumber:	moveq	#0,d6
LS_LoadSample:	tst.w	SampleBits
		beq.s	LSLS_Ready
		move.w	SampleBits,d0
		btst	d6,d0
		beq.s	LSLS_NoLoad
		cmp.b	(a0,d6.w),d7
		bne.s	LSLS_NoLoad
		bclr	d6,d0
		move.w	d0,SampleBits
		move.w	d6,ActualSample
		addq.w	#1,ActualSample
		movem.l	a0/d6-d7,-(sp)
		bsr	LoadSampleDoIt
		movem.l	(sp)+,a0/d6-d7
LSLS_NoLoad:	addq.w	#1,d6
		cmp.w	#15,d6
		bne.s	LS_LoadSample
		addq.b	#1,d7
		bra.s	LS_NextNumber
LSLS_Ready:	move.w	#1,ActualSample
		bra	PrintSoundData

SampleBits:	dc.w	0
VolTable:	blk.b	16,0

GetVolTable:	move.l	SongPT,a0
		lea	20(a0),a0
		lea	VolTable,a1
		moveq	#14,d7
GVT_Loop:	cmp.b	#':',5(a0)
		bne.s	GVT_0
		moveq	#0,d0
		move.b	3(a0),d0
		sub.b	#'0',d0
		mulu	#10,d0
		add.b	4(a0),d0
		sub.b	#'0',d0
		move.b	d0,(a1)+
		bra.s	GVT_All
GVT_0:		clr.b	(a1)+
GVT_All:	lea	30(a0),a0
		dbf	d7,GVT_Loop
		rts

LS_RError:	bsr	SpriteRed
		bsr	ClearSong
		bra.s	InitNewSong

InitNewSong:	clr.l	ActualTrack
		clr.l	ActualPlayPos
		bsr	SongOn
		bsr	DrawWorkPlane
		bsr	PrintSoundData
		bra	PrintPosPatt

* Modul laden *************************

LoadModulDoIt:	move.l	a0,-(sp)
		bsr	StopSong
		clr.l	EditMode
		bsr	ClearSong
		move.l	(sp)+,a0
		lea	ModulExtName,A1
		moveq	#27,D0
LM_CopySongName:move.b	(A0)+,(A1)+
		dbf	D0,LM_CopySongName
		move.l	SongPT,FileBuffer
		move.l	#ModulName,FileNamePT
		move.l	#SongHeader,FileLength
		bsr	OpenFile
		beq	LM_Error
		bsr	ReadFilePart
		bsr	GetHighestPattern
		moveq	#0,d0
		move.w	HighestPattern,d0
		lsl.l	#8,d0
		lsl.l	#2,d0
		add.l	#SongHeader,FileBuffer
		move.l	d0,FileLength
		bsr	ReadFilePart

		bsr	InitNewSong

		move.w	#1,ActualSample
LM_NextSample:	bsr	LoadSamplePart
		addq.w	#1,ActualSample
		cmp.w	#16,ActualSample
		bne.s	LM_NextSample

		bsr	CloseFile
		move.w	#1,ActualSample
		bra	PrintSoundData

LM_Error:	bsr	ClearSong
		bsr	InitNewSong
		bra	SpriteRed

* SampleTeil eines Files einlesen *****

LoadSamplePart:	move.w	ActualSample,D0
		mulu	#30,D0
		move.l	SongPT,A0
		lea	12(a0,d0.l),a0
		moveq	#0,d0
		move.w	(A0),D0
		beq.s	LSP_NoFile
		add.l	d0,d0
		move.l	D0,FileLength
		move.l	#$10002,D1
		move.l	4.w,a6
		jsr	-198(A6)
		move.l	D0,FileBuffer
		beq.s	LSP_MemError
		lea	SoundMemEntries,A0
		move.w	ActualSample,D1
		lsl.w	#2,d1
		move.l	FileBuffer,-(sp)
		move.l	(sp),(A0,D1.w)
		move.l	FileLength,$3C(A0,D1.w)
		bsr	ReadFilePart
		move.l	(sp)+,a0
		clr.w	(a0)
		bra	PrintSoundData
LSP_NoFile:	bra	ClearActSample
LSP_MemError:	bsr	ClearActSample
		bra	SpriteRed

* Song stoppen ************************

StopSong:	clr.b	Taste
		clr.l	EditMode
		clr.l	SongMode
		clr.w	L04708E
		bsr	SpriteGrey
		move.w	#$F,$DFF096
		rts

* Song loeschen + Samples freigeben ***

ClearSong:	move.l	SongPT,A0
		move.w	#[$11000+SongHeader]/4-1,d0
LM_ClearSong:	clr.l	(a0)+
		dbf	d0,LM_ClearSong

		move.l	SongPT,a0		;RepLen auf 1 setzen
		lea	20(a0),a0
		moveq	#14,d0
CS_RepLen:	move.w	#1,$1c(a0)
		lea	30(a0),a0
		dbf	d0,CS_RepLen

		move.l	SongPT,A0		;?
		lea	470(a0),A0
		move.w	#$178,(A0)

		move.w	#1,ActualSample
		bsr	PrintSoundData

* Alle Samples freigeben **************

FreeSamples:	moveq	#1,d7
FS_Loop:	move.w	d7,d0
		bsr	FreeSample
		addq.w	#1,d7
		cmp.w	#$10,d7
		bne.s	FS_Loop
		rts

* Preset a0 reinladen *****************

UsePreset:	move.l	a0,-(sp)
		bsr.s	StopSong
		clr.l	EditMode
		move.l	(sp)+,a0
		moveq	#0,d0
		move.w	ActualSample,D0
		mulu	#30,D0
		move.l	SongPT,A1
		lea	-10(a1,d0.w),a1
		moveq	#29,D0
UP_CopyName:	move.b	(A0)+,(A1)+
		dbf	D0,UP_CopyName
		bra	LoadSampleDoIt

* Edit Mode an ************************

Edit:		bsr	StopSong
		bsr	MoveWorkPlane
		clr.l	SongMode
		move.l	#'edit',EditMode
		rts

* Song abspeichern ********************

SaveSongDoIt:	bsr	GetHighestPattern
		lea	SongName,A0
		moveq	#$1B,D0
L04594A:	clr.b	(A0)+
		dbf	D0,L04594A
		move.l	SongPT,A0
		lea	SongName,A1
		moveq	#$13,D0
L045962:	move.b	(A0)+,(A1)+
		dbf	D0,L045962
		move.l	#SongFileName,FileNamePT
		move.l	SongPT,FileBuffer
		move.l	#SongHeader,FileLength
		moveq	#0,d0
		move.w	HighestPattern,D0
		lsl.l	#8,d0
		lsl.l	#2,d0
		add.l	D0,FileLength
		tst.w	PackModus
		bne	SSDI_NoPackMode1
		bsr	PackIt
SSDI_NoPackMode1:
		bsr	WriteFile
		tst.w	PackModus
		bne	SSDI_NoPackMode2
		bsr	RePackIt
SSDI_NoPackMode2:
		rts

* Hoechste Patternnummer ermitteln ****

GetHighestPattern:
		move.l	SongPT,A0
		lea	472(a0),A0
		moveq	#0,d0
		moveq	#0,d1
		moveq	#0,d2
		clr.w	HighestPattern
L04591A:	move.b	(A0,D0.w),D1
		addq.w	#1,D0
		cmp.w	#$80,D0
		bgt.s	HP_Found
		move.w	HighestPattern,D2
		cmp.w	D2,D1
		ble.s	L04591A
		move.w	D1,HighestPattern
		bra.s	L04591A
HP_Found:	addq.w	#1,HighestPattern
		rts

HighestPattern:	dc.w	0

* Packen ******************************

PackIt:		move.l	SongPT,a0		;Destination Ad
		lea	12(a0),a1
		move.l	a1,DestAd
		move.l	a0,a1			;SourceEnd
		add.l	#$11000+SongHeader,a1
		move.l	a1,SourceEnd
		move.l	a0,a1			;SourceAd
		add.l	#$11000+SongHeader,a1
		sub.l	FileLength,a1
		move.l	a1,SourceAd
		move.l	FileLength,SourceLength	;SourceLength
* Hochkopieren (rueckwaerts) *
		move.l	SongPT,a0		;Hinten Von
		add.l	FileLength,a0
		move.l	SongPT,a1		;Hinten Nach (Letzte Ad von buffer)
		add.l	#$11000+SongHeader,a1
		move.l	FileLength,d0
PI_CopyUp:	move.b	-(a0),-(a1)
		subq.l	#1,d0
		bne.s	PI_CopyUp
		bsr	PackRout
		sub.l	DestAd,a2
		move.l	a2,d0
		move.l	d0,DestLength
		move.l	d0,d1
		add.l	DestAd,d1
		move.l	d1,DestEnd
		move.l	SongPT,a0		;Kennung
		move.l	#'PACK',(a0)
		move.l	DestLength,4(a0)
		move.l	SourceLength,8(a0)
		move.l	SongPT,FileBuffer
		move.l	DestLength,d0
		add.l	#12,d0
		move.l	d0,FileLength
		rts

* Packen ******************************

PackRout:	move.l	SourceAd,a0
		move.l	SourceEnd,a1
		move.l	DestAd,a2
		moveq	#1,d2
		clr.w	d1
noteocrunch:	bsr.s	crunch
		tst.b	d0
		beq.s	crunched
		addq.w	#1,d1
		cmp.w	#264,d1
		bne.s	nojmp
		bsr.l	dojmp
nojmp:
crunched:	cmp.l	a0,a1
		bgt.s	noteocrunch
		bsr.l	dojmp
		bra.l	write1lwd
crunch:		move.l	a0,a3
		lea	$7f(a3),a3
		cmp.l	a1,a3
		ble.s	nottop
		move.l	a1,a3
nottop:		moveq	#1,d5
		move.l	a0,a5
		addq.l	#1,a5
contcrunch:	move.b	(a0),d3
		move.b	1(a0),d4
quickfind:	cmp.b	(a5)+,d3
		bne.s	contfind
		cmp.b	(a5),d4
		beq.s	lenfind
contfind:	cmp.l	a5,a3
		bgt.s	quickfind
		bra.s	endquickfind
lenfind:	subq.l	#1,a5
		move.l	a0,a4
scan:		move.b	(a4)+,d3
		cmp.b	(a5)+,d3
		bne.s	endequ
		cmp.l	a5,a3
		bgt.s	scan
endequ:		move.l	a4,d3
		sub.l	a0,d3
		subq.l	#1,d3
		cmp.l	d3,d5
		bge	nocrunch
		move.l	a5,d4
		sub.l	a0,d4
		sub.l	d3,d4
		subq.l	#1,d4
		cmp.l	#4,d3
		ble	small
		moveq	#6,d6
		cmp.l	#$101,d3
		blt	oksafe
		move.w	#$100,d3
oksafe:		bra	cont1
small:		move.w	d3,d6
		subq.w	#$2,d6
		add.w	d6,d6
cont1:		lea	table,a6
		cmp.w	(a6,d6.w),d4
		bge	nocrunch
		move.l	d3,d5
		move.l	d4,maxsoffset
		move.b	d6,tbloffset
nocrunch:	cmp.l	a5,a3
		bgt.s	contcrunch
endquickfind:	cmp.l	#1,d5
		beq.s	nothingfound
		bsr	dojmp
		move.b	tbloffset,d6
		move.l	maxsoffset,d3
		move.w	8(a6,d6.w),d0
		bsr	wd0bits
		move.w	16(a6,d6.w),d0
		beq	nolength
		move.l	d5,d3
		subq.w	#1,d3
		bsr	wd0bits
nolength:	move.w	24(a6,d6.w),d0
		move.w	32(a6,d6.w),d3
		bsr	wd0bits
		addq.w	#1,40(a6,d6.w)
		add.l	d5,a0
		clr.b	d0
		rts
nothingfound:	move.b	(a0)+,d3
		moveq	#8,d0
		bsr	wd0bits
		moveq	#1,d0
		rts

table:
offst:		dc.w	$100,$200,$400,$1000
lnoff:		dc.w	8,9,$a,8
length:		dc.w	0,0,0,8
cdlen:		dc.w	2,3,3,3
code:		dc.w	1,4,5,6
cnt:		dc.w	0,0,0,0
cntjmp:		dc.w	0,0

dojmp:		tst.w	d1
		beq	skipjmp
		move.w	d1,d3
		clr.w	d1
		cmp.w	#9,d3
		bge	bigjmp
		addq.w	#1,cntjmp
		subq.w	#1,d3
		moveq	#5,d0
		bra	wd0bits
skipjmp:	rts
bigjmp:		addq.w	#1,cntjmp+2
		subi.w	#9,d3
		or.w	#%0000011100000000,d3
		moveq	#11,d0
		bra	wd0bits
wd0bits:	subq.w	#1,d0
copybits:	lsr.l	#1,d3
		roxl.l	#1,d2
		bcs.s	writelwd
		dbf	d0,copybits
		rts
write1lwd:	clr.w	d0
writelwd:	move.l	d2,(a2)+
		moveq	#1,d2
		dbf	d0,copybits
		rts

* Recompactieren **********************

RePackIt:	move.l	SongPT,a0	;Source
		lea	12(a0),a0
		move.l	SourceAd,a1	;Destination
		move.l	DestLength,d0	;SourceLength=DestLength
		move.l	SourceLength,d1	;DestLength=SourceLength
		bsr	ReCompactor
* Runterkopieren *
		move.l	SourceAd,a0
		move.l	SongPT,a1
		move.l	SourceLength,d0
RPI_Loop:	move.b	(a0)+,(a1)+
		subq.l	#1,d0
		bne.s	RPI_Loop
* Hinten loeschen *
		move.l	SongPT,a0
		add.l	#$11000+SongHeader,a0
		move.l	SongPT,a1
		add.l	SourceLength,a1
		sub.l	a1,a0
		move.l	a0,d0
RPI_ClearLoop:	clr.b	(a1)+
		subq.l	#1,d0
		bne.s	RPI_ClearLoop
		rts

* Recompactor *************************

* a0Source
* a1Destination
* d0SourceLength
* d1DestinationLength

ReCompactor:	add.l	d0,a0		;SourceLength addieren
		move.l	d1,a2
		add.l	a1,a2
		move.l	-(a0),d0
dnotfinished:	lsr.l	#1,d0
		bne	dnotempty1
		bsr	dgetnextlwd
dnotempty1:	bcs	dbigone
		moveq	#8,d1
		moveq	#1,d3
		lsr.l	#1,d0
		bne	dnotempty2
		bsr	dgetnextlwd
dnotempty2:	bcs	ddodupl
		moveq	#3,d1
		clr.w	d4
ddojmp:		bsr	drdd1bits
		move.w	d2,d3
		add.w	d4,d3
dgetd3chr:	moveq	#7,d1
dget8bits:	lsr.l	#1,d0
		bne	dnotempty3
		bsr	dgetnextlwd
dnotempty3:	roxl.l	#1,d2
		dbf	d1,dget8bits
		move.b	d2,-(a2)
		dbf	d3,dgetd3chr
		bra	dnextcmd
dbigjmp:	moveq	#8,d1
		moveq	#8,d4
		bra.s	ddojmp
dbigone:	moveq	#2,d1
		bsr	drdd1bits
		cmp.b	#2,d2
		blt	dmidjumps
		cmp.b	#3,d2
		beq.s	dbigjmp
		moveq	#8,d1
		bsr	drdd1bits
		move.w	d2,d3
		move.w	#8,d1
		bra	ddodupl
dmidjumps:	move.w	#9,d1
		add.w	d2,d1
		addq	#2,d2
		move.w	d2,d3
ddodupl:	bsr	drdd1bits
dcopyd3bytes:	subq	#1,a2
		move.b	(a2,d2.w),(a2)
		dbf	d3,dcopyd3bytes
dnextcmd:	cmp.l	a2,a1
		blt	dnotfinished
		rts			;Zurueck
dgetnextlwd:	move.l	-(a0),d0
		move.w	#$10,ccr
		roxr.l	#1,d0
		rts
drdd1bits:	subq.w	#1,d1
		clr.w	d2
dgetbits:	lsr.l	#1,d0
		bne	dnotempty
		move.l	-(a0),d0
		move.w	#$10,ccr
		roxr.l	#1,d0
dnotempty:	roxl.l	#1,d2
		dbf	d1,dgetbits
		rts

* Modul abspeichern *******************

SaveModulDoIt:	bsr	SpriteGreen
		bsr	GetHighestPattern
		lea	ModulExtName,A0
		moveq	#27,D0
SMDI_ClearName:	clr.b	(A0)+
		dbf	D0,SMDI_Clearname
		move.l	SongPT,A0
		lea	ModulExtName,A1
		moveq	#19,D0
SMDI_CopyName:	move.b	(A0)+,(A1)+
		dbf	D0,SMDI_CopyName
		move.l	SongPT,FileBuffer
		move.l	#SongHeader,FileLength
		moveq	#0,d0
		move.w	HighestPattern,D0
		lsl.l	#8,d0
		lsl.l	#2,d0
		add.l	D0,FileLength
		bsr	OpenModul
		bne	SaveModuleError
		bsr	SaveModulPart
		bne	SavemoduleError
		moveq	#1,d6
SMDI_SampleLoop:bsr	SaveSamplePart
		addq.b	#1,d6
		cmp.b	#16,d6
		bne.s	SMDI_SampleLoop
		bsr	CloseModul
		bra	SpriteGrey
SaveModuleError:bra	SpriteRed

SaveSamplePart:	move.w	d6,d0
		lsl.w	#2,d0
		lea	SoundMemEntries,A0
		move.l	(A0,D0.w),D1
		beq	SSP_NoSave
		move.l	60(A0,D0.w),D0
		beq	SSP_NoSave
		move.l	d1,FileBuffer
		move.l	SongPT,A0
		lea	12(a0),a0
		move.w	d6,D0
		mulu	#30,D0
		add.l	D0,A0
		moveq	#0,d0
		move.w	(a0),d0
		add.l	d0,d0
		move.l	d0,FileLength
		beq	SSP_NoSave
		bsr	SaveModulPart
SSP_NoSave:	rts

OpenModul:	move.l	DosBase,a6
		move.l	#ModulName,d1
		move.l	#$3ee,d2
		jsr	Open(a6)
		move.l	d0,d7
		beq	OM_Error8
		moveq	#0,d0
		rts
OM_Error8:	moveq	#-1,d0
		rts
SaveModulPart:	move.l	DosBase,a6
		move.l	d7,d1
		move.l	FileBuffer,d2
		move.l	FileLength,d3
		jsr	Write(a6)
		cmp.l	FileLength,d0
		bne.s	SMP_Error
		moveq	#0,d0
		rts
SMP_Error:	moveq	#-1,d0
		rts
Closemodul:	move.l	DosBase,a6
		move.l	d7,d1
		jsr	Close(a6)
		rts

ModulName:	dc.b	'ST-00:modules/'
ModulExtName:	blk.b	28,0

* Sample abspeichern ******************

SaveSampleDoIt:	move.w	ActualSample,d0
		lsl.w	#2,d0
		lea	SoundMemEntries,A0
		move.l	(A0,D0.w),D1
		beq	SSDI_NoSave
		move.l	60(A0,D0.w),D0
		beq	SSDI_NoSave
		move.l	d1,FileBuffer
		move.l	d0,FileLength
		move.w	ActualSample,D0
		mulu	#30,D0
		move.l	SongPT,A0
		lea	12(a0),a0
		add.l	D0,A0
		moveq	#0,d0
		lea	-$16(a0),A0
		lea	SampleName,A1
		moveq	#$15,D0
SSDI_1:		move.b	(A0)+,(A1)+
		dbf	D0,SSDI_1
		clr.b	(a1)
		lea	SampleName,a0
		cmp.b	#':',5(a0)
		beq.s	DiskFromName5
		move.l	#SampleFileName,FileNamePT
		bra	SSDI2
DiskFromName5:	move.l	#SampleName,FileNamePT
SSDI2:		bra	WriteFile
SSDI_NoSave:	bra	Spritered

Play:		btst	#6,$BFE001
		beq.s	Play
		bsr	SpriteGrey
		move.l	#'song',SongMode
		clr.w	L04708E
		clr.l	EditMode
		clr.l	TrackOffset
		clr.w	WorkPosY
		bsr	MoveWorkPlane
		moveq	#0,d1
		move.w	L047108,D1
		move.l	ActualPlayPos,D0
		cmp.l	D1,D0
		bpl	L0459FC
		move.l	ActualPlayPos,L04707A
		rts
L0459FC:	clr.l	L04707A
		clr.l	ActualPlayPos
		rts
Pattern:	btst	#6,$BFE001
		beq.s	Pattern
		clr.l	EditMode
		bsr	StopSong
		move.l	#'patt',SongMode
		clr.w	L04708E
		lea	WorkPlaneMode,A0
		move.w	#$3200,(A0)
		move.l	ActualTrack,L04707A
		clr.l	TrackOffset
		rts

ChangeRepLen:	cmp.w	#-1,L047038
		beq.s	SubRepLen
		move.l	SongPT,A0
		lea	12(a0),a0
		moveq	#0,d0
		move.w	ActualSample,D0
		mulu	#30,D0
		add.l	D0,A0
		btst	#10,$DFF016
		bne	L045A8A
		add.w	#15,6(A0)
L045A8A:	addq.w	#1,6(A0)
		cmp.w	#$4000,6(A0)
		bmi	L045A9E
		move.w	#$4000,6(A0)
L045A9E:	bra	PrintSoundData

SubRepLen:	move.l	SongPT,A0
		lea	12(a0),a0
		moveq	#0,d0
		move.w	ActualSample,D0
		mulu	#30,D0
		add.l	D0,A0
		btst	#10,$DFF016
		bne	L045AD2
		sub.w	#15,6(A0)
L045AD2:	subq.w	#1,6(A0)
		cmp.w	#1,6(A0)
		bpl	L045AE6
		move.w	#1,6(A0)
L045AE6:	bra	PrintSoundData

ChangeRepeat:	cmp.w	#-1,L047038
		beq.s	SubRepeat
		move.l	SongPT,A0
		lea	12(a0),a0
		moveq	#0,d0
		move.w	ActualSample,D0
		mulu	#30,D0
		add.l	D0,A0
		btst	#2,$DFF016
		bne	L045B26
		add.w	#$1e,4(A0)
L045B26:	addq.w	#2,4(A0)
		cmp.w	#$8000,4(A0)
		bmi	L045B3A
		move.w	#$8000,4(A0)
L045B3A:	bra	PrintSoundData

SubRepeat:	move.l	SongPT,A0
		lea	12(a0),a0
		moveq	#0,d0
		move.w	ActualSample,D0
		mulu	#30,D0
		add.l	D0,A0
		btst	#2,$DFF016
		bne	L045B6E
		sub.w	#$1e,4(A0)
L045B6E:	subq.w	#2,4(A0)
		tst.w	4(A0)
		bpl	L045B82
		clr.w	4(A0)
L045B82:	bra	PrintSoundData

ChangeVolume:	cmp.w	#-1,L047038
		beq.s	l045bcc
		move.l	SongPT,A0
		lea	12(a0),a0
		moveq	#0,d0
		move.w	ActualSample,D0
		mulu	#30,D0
		add.l	D0,A0
		addq.w	#1,2(A0)
		cmp.w	#$40,2(A0)
		bmi	L045BC4
		move.w	#$40,2(A0)
L045BC4:	bsr	PrintSoundData
		bra	Wait

L045BCC:	move.l	SongPT,A0
		lea	12(a0),a0
		moveq	#0,d0
		move.w	ActualSample,D0
		mulu	#30,D0
		add.l	D0,A0
		subq.w	#1,2(A0)
		tst.w	2(A0)
		bpl	L045BFA
		clr.w	2(A0)
L045BFA:	bsr	PrintSoundData
		bra	Wait

ChangeLength:	cmp.w	#-1,L047038
		beq.s	SubLength
		move.l	SongPT,A0
		lea	12(a0),a0
		moveq	#0,d0
		move.w	ActualSample,D0
		mulu	#30,D0
		add.l	D0,A0
		btst	#2,$DFF016
		bne	L045C38
		add.w	#15,(A0)
L045C38:	addq.w	#1,(A0)
		cmp.w	#$4000,(A0)
		bmi.s	L045C46
		move.w	#$4000,(a0)
L045C46:	bra	PrintSoundData

SubLength:	move.l	SongPT,A0
		lea	12(a0),a0
		moveq	#0,d0
		move.w	ActualSample,D0
		mulu	#30,D0
		add.l	D0,A0
		btst	#2,$DFF016
		bne	L045C78
		sub.w	#15,(A0)
L045C78:	subq.w	#1,(A0)
		tst.w	(A0)
		bpl	L045C86
		clr.w	(a0)
L045C86:	bra	PrintSoundData

ChangeSound:	cmp.w	#-1,L047038
		beq.s	SubSound
		addq.w	#1,ActualSample
		cmp.w	#$F,ActualSample
		bmi	L045CD0
		move.w	#$F,ActualSample
L045CD0:	bsr	PrintSoundData
		bra	CopyToSBuffer
SubSound:	subq.w	#1,ActualSample
		cmp.w	#1,ActualSample
		bpl	L045CFE
		move.w	#1,ActualSample
L045CFE:	bsr	PrintSoundData
		bra	CopyToSBuffer

ChangeSpeed:	cmp	#-1,l047038
		beq.s	SubSpeed
		cmp.w	#$f,ReplaySpeed
		beq.s	CS_Exit
		addq.w	#1,ReplaySpeed
		bra.s	CS_Exit
SubSpeed:	cmp.w	#1,ReplaySpeed
		beq.s	CS_Exit
		subq.w	#1,ReplaySpeed
CS_Exit:	bsr	PrintPosPatt
		bra	Wait2

L045D96:	bsr	StopSong
		cmp.w	#-1,L047038
		beq.s	l045dd6
		move.l	SongPT,A0
		lea	470(a0),A0
		addq.b	#1,(A0)
		cmp.b	#$80,(A0)
		bmi	L045DC2
		move.b	#$80,(A0)
L045DC2:	bsr	PrintPosPatt
		bra	Wait2

L045DD6:	move.l	SongPT,A0
		lea	470(a0),A0
		subq.b	#1,(A0)
		cmp.b	#1,(A0)
		bpl	L045DF0
		move.b	#1,(A0)
L045DF0:	bsr	PrintPosPatt
		bra	Wait2

L045E04:	bsr	StopSong
		cmp.w	#-1,L047038
		beq.s	l045e52
		move.l	SongPT,A0
		lea	472(a0),a0
		add.l	ActualPlayPos,A0
		add.b	#1,(A0)
		cmp.b	#$3F,(A0)
		bmi	L045E38
		move.b	#$3F,(A0)
L045E38:	bsr	SongOn
		bra	Wait3

L045E52:	move.l	SongPT,A0
		lea	472(a0),A0
		add.l	ActualPlayPos,A0
		sub.b	#1,(A0)
		tst.b	(A0)
		bpl	L045E74
		clr.b	(A0)
L045E74:	bsr	SongOn
		bra.s	Wait3

L045E8E:	cmp.w	#-1,L047038
		beq.s	l045ed6
		addq.l	#1,ActualPlayPos
		cmp.l	#$7F,ActualPlayPos
		bmi	L045EBC
		move.l	#$7F,ActualPlayPos
L045EBC:	bsr	SongOn
		bra.s	Wait3

L045ED6:	subq.l	#1,ActualPlayPos
		tst.l	ActualPlayPos
		bpl	L045EF8
		clr.l	ActualPlayPos
L045EF8:	bsr	SongOn
		bra.s	Wait3

* A bisserl warta *********************

Wait2:		move.w	#$8000,d0
		bra.s	Wait_Loop
Wait3:		move.w	#$c000,d0
		bra.s	Wait_Loop
Wait:		move.w	#$4000,D0
Wait_Loop:	dbf	D0,Wait_Loop
		rts

* Playroutine *************************

SongHandler:	movem.l	D0-d7/a0-A6,-(A7)
		cmp.w	#$aaa,CopperColors+2
		bne.s	SH_NoEd
		tst.l	EditMode
		beq.s	SH_NoEd
		bsr	SpriteBlue
SH_NoEd:	move.l	SongPT,A0
		move.b	470(A0),L047108+1
		tst.l	SongMode
		beq	SH_Exit
		cmp.w	#$aaa,CopperColors+2
		bne.s	SH_NoYell
		bsr	SpriteYellow
SH_NoYell:	cmp.l	#'patt',SongMode
		beq.s	SH_PlayPattern
		move.l	L04707A,ActualPlayPos
SH_PlayPattern:	addq.w	#1,ActualRasCycle
		move.w	ActualRasCycle,D0
		cmp.w	ReplaySpeed,d0
		blt.s	ChannelEffects
		clr.w	ActualRasCycle
		bra	replaystep

ChannelEffects:	lea	Datach0,A6
		tst.b	3(A6)
		beq.s	ceff1
		lea	$DFF0A0,A5
		bsr	doeff
ceff1:		lea	Datach1,A6
		tst.b	3(A6)
		beq.s	ceff2
		lea	$DFF0B0,A5
		bsr	doeff
ceff2:		lea	Datach2,A6
		tst.b	3(A6)
		beq.s	ceff3
		lea	$DFF0C0,A5
		bsr	doeff
ceff3:		lea	Datach3,A6
		tst.b	3(A6)
		beq	SH_Exit
		lea	$DFF0D0,A5
		bsr	doeff
		bra	SH_Exit

doeff:		move.b	2(A6),D0
		and.b	#$F,D0
		tst.b	D0
		beq	arpreggio
		cmp.b	#1,D0
		beq	pitchup
		cmp.b	#2,D0
		beq	pitchdown
		cmp.b	#$d,d0
		beq	VolDown
		rts

arpreggio:	cmp.w	#1,ActualRasCycle
		beq.s	arp1
		cmp.w	#2,ActualRasCycle
		beq.s	arp2
		cmp.w	#3,ActualRasCycle
		beq.s	arp3
		cmp.w	#4,ActualRasCycle
		beq.s	arp1
		cmp.w	#5,ActualRasCycle
		beq.s	arp2
		rts
arp1:		moveq	#0,d0
		move.b	3(A6),D0
		lsr.b	#4,D0
		bra.s	arp4
arp2:		moveq	#0,d0
		move.b	3(A6),D0
		and.b	#$F,D0
		bra.s	arp4
arp3:		move.w	$10(A6),D2
		bra.s	arp6
arp4:		add.w	d0,d0
		moveq	#0,d1
		move.w	$10(A6),D1
		lea	FullPeriodTab,A0
arp5:		move.w	(A0,D0.w),D2
		cmp.w	(A0),D1
		beq.s	arp6
		addq.w	#2,A0
		bra.s	arp5
arp6:		move.w	D2,6(A5)
		rts

pitchup:	bsr	newrout
		moveq	#0,d0
		move.b	3(A6),D0
		sub.w	D0,(A4)
		cmp.w	#$71,(A4)
		bpl.s	pu_ok
		move.w	#$71,(A4)
pu_ok:		move.w	(A4),6(A5)
		rts

pitchdown:	bsr	newrout
		moveq	#0,d0
		move.b	3(A6),D0
		add.w	D0,(A4)
		cmp.w	#$358,(A4)
		bmi.s	pd_ok
		move.w	#$358,(A4)
pd_ok:		move.w	(A4),6(A5)
		rts

VolDown:	moveq	#0,d0
		move.b	3(a6),d0
		lsr.b	#4,d0
		beq.s	vd_volldown
		add.w	d0,18(a6)
		cmp.w	#$40,18(a6)
		bmi.s	vd_ok
		move.w	#$40,18(a6)
		bra.s	vd_ok

vd_volldown:	moveq	#0,d0
		move.b	3(a6),d0
		and.b	#$f,d0
		sub.w	d0,18(a6)
		bpl.s	vd_ok
		clr.w	18(a6)
vd_ok:		move.w	18(a6),8(a5)
		rts

newrout:	cmp.l	#Datach0,A6
		bne.s	nr_1
		lea	voi0,A4
		rts
nr_1:		cmp.l	#Datach1,A6
		bne.s	nr_2
		lea	voi1,A4
		rts
nr_2:		cmp.l	#Datach2,A6
		bne.s	nr_3
		lea	voi2,A4
		rts
nr_3:		lea	voi3,A4
		rts

replaystep:	move.l	SongPT,A0
		move.l	A0,A3
		lea	12(a3),a3
		move.l	A0,A2
		lea	472(a2),A2
		lea	SongHeader(a0),A0
		cmp.l	#'song',SongMode
		beq.s	rp_nosong
		move.l	ActualTrack,D1
		bra.s	rp_song
rp_nosong:	moveq	#0,d1
		move.l	L04707A,D0
		move.b	(A2,D0.l),D1
rp_song:	lsl.l	#8,d1
		lsl.l	#2,d1
		add.l	TrackOffset,D1
		move.l	D1,L047082
		clr.w	enbits
		lea	$DFF0A0,A5
		lea	Datach0,A6
		bsr	channelhandler
		lea	$DFF0B0,A5
		lea	Datach1,A6
		bsr	channelhandler
		lea	$DFF0C0,A5
		lea	Datach2,A6
		bsr	channelhandler
		lea	$DFF0D0,A5
		lea	Datach3,A6
		bsr	channelhandler

		move.w	#$1F4,D0
waitdma:	dbf	D0,waitdma
		move.w	enbits,d0
		and.w	ChannelMask,d0
		or.w	#$8000,d0
		move.w	d0,$dff096
		lea	Datach3,A6
		cmp.w	#1,$E(A6)
		bne.s	l04621e
		move.l	$A(A6),$DFF0D0
		move.w	$E(A6),$DFF0D4
L04621E:	lea	Datach2,A6
		cmp.w	#1,$E(A6)
		bne.s	l04623e
		move.l	$A(A6),$DFF0C0
		move.w	$E(A6),$DFF0C4
L04623E:	lea	Datach1,A6
		cmp.w	#1,$E(A6)
		bne.s	l04625e
		move.l	$A(A6),$DFF0B0
		move.w	$E(A6),$DFF0B4
L04625E:	lea	Datach0,A6
		cmp.w	#1,$E(A6)
		bne.s	l00000
		move.l	$A(A6),$DFF0A0
		move.w	$E(A6),$DFF0A4
l00000:		cmp.l	#'patt',SongMode
		bne.s	NoPatternPlay1
		bsr	SetWorkPlane
		cmp.l	#'edit',EditMode
		bne.s	NoPatternPlay1
		move.l	TrackOffset,d0
		lsr.l	#4,d0
		move.w	d0,WorkPosY
NoPatternPlay1:	add.l	#$10,TrackOffset
		cmp.l	#$400,TrackOffset
		bne.s	SH_Exit
		clr.l	TrackOffset
		addq.l	#1,L04707A
		and.l	#$7F,L04707A
		moveq	#0,d0
		move.w	L047108,D0
		move.l	L04707A,D1
		cmp.l	D0,D1
		bne.s	SH_Exit
		clr.l	L04707A
SH_Exit:	movem.l	(A7)+,D0-d7/a0-A6
		rts

channelhandler:	move.l	(A0,D1.l),(A6)
		addq.l	#4,D1

		moveq	#0,d2
		move.b	2(A6),D2
		lsr.b	#4,D2
		beq.s	chan2
		move.l	D2,D4
		lsl.l	#2,d2
		mulu	#30,D4

		lea	SoundMemEntries,a1
		move.l	(A1,D2.w),4(A6)		;PT
		move.w	(A3,D4.w),8(A6)		;Len
		move.w	2(A3,D4.w),$12(A6)	;Vol

		move.b	2(a6),d0
		and.b	#$f,d0
		cmp.b	#$c,d0
		bne.s	ok3
		move.b	3(a6),9(a5)		;Vol
		bra.s	ok4
ok3:		move.w	2(a3,d4),8(a5)		;Vol
ok4:		moveq	#0,d3
		move.w	4(A3,D4),D3
		add.l	4(a6),d3
		move.l	d3,10(a6)		;repstart
		move.w	6(A3,D4),14(A6)		;replen
		cmp.w	#1,14(a6)
		beq.s	chan2
		move.w	10(a6),4(a6)
		move.w	6(a3,d4),8(a6)		;newlen

chan2:		tst.w	(A6)
		beq	chan4
		move.w	$16(A6),d0
		and.w	ChannelMask,d0
		move.w	d0,$DFF096
		tst.w	14(a6)
		bne.s	chan3
		move.w	#1,14(a6)
chan3:		bsr	newrout
		move.w	(a6),(a4)
		move.w	(a6),16(a6)
		move.l	4(A6),(A5)		;PT
		move.w	8(A6),4(A5)		;Len
		move.w	(A6),6(a5)		;Period
		move.w	(a6),d0
		bsr	AddPeriode
		move.w	$16(A6),D0
		or.w	D0,enbits
		move.w	18(a6),20(a6)
chan4:		move.b	2(a6),d0
		and.b	#$f,d0
		cmp.b	#11,d0
		beq.s	PatternJump
		cmp.b	#12,d0
		beq.s	setvol
		cmp.b	#14,d0
		beq.s	setfilt
		cmp.b	#15,d0
		beq.s	setspeed
		rts

PatternJump:	moveq	#0,d0
		move.b	3(a6),d0
		and.b	#$3f,d0
		bne.s	pj_nonext
		move.w	#$3f,d0
pj_nonext:	lsl.w	#4,d0
		move.l	d0,TrackOffset
		rts

setvol:		move.b	3(a6),9(a5)
		rts

setfilt:	move.b	3(a6),d0
		and.b	#1,d0
		add.b	d0,d0
		and.b	#$fd,$bfe001
		or.b	d0,$bfe001
		rts

setspeed:	move.b	3(a6),d0
		and.w	#$f,d0
		beq.s	setspeedex
		move.w	d0,ReplaySpeed
setspeedex:	rts

Datach0:	blk.w	11,0
		dc.w	1
Datach1:	blk.w	11,0
		dc.w	2
Datach2:	blk.w	11,0
		dc.w	4
Datach3:	blk.w	11,0
		dc.w	8

Voi0:		dc.l	0
Voi1:		dc.l	0
Voi2:		dc.l	0
Voi3:		dc.l	0

ReplaySpeed:	dc.w	6
ActualRasCycle:	dc.w	0
enbits:		dc.w	0

* WorkplanePos erneuern ***************

SetWorkPlane:	move.l	TrackOffset,D0
		lsr.l	#4,d0
		bra.s	L046302
MoveWorkPlane:	move.w	WorkPosY,D0
L046302:	mulu	#$118,D0
		move.l	WorkPlane,A0
		lea	$15B8(a0),A0
		add.l	A0,D0
		lea	WorkPlanePT2,A1
		move.w	D0,6(A1)
		swap	D0
		move.w	D0,2(A1)
		rts

* Mausposition Aktualisieren **********

RefreshMaus:	move.w	$DFF00A,D0
		move.w	D0,D2
		and.w	#$FF,D0
		move.w	D0,D1
		sub.w	OldX,D0
		move.w	D1,OldX
		ext.w	d0
		cmp.w	#$7F,D0
		bmi.s	L046356
		moveq	#-1,d1
		sub.w	D0,D1
		move.w	D1,D0
		bra	L046362
L046356:	cmp.w	#-$7F,D0
		bpl	L046362
		add.w	#$FF,D0
L046362:	add.w	D0,MouseXOrig
		move.w	D2,D0
		lsr.w	#8,D0
		move.w	D0,D1
		sub.w	OldY,D0
		move.w	D1,OldY
		ext.w	d0
		cmp.w	#$7F,D0
		bmi	L046390
		move.w	#$FF,D1
		sub.w	D0,D1
		move.w	D1,D0
		bra	L04639C
L046390:	cmp.w	#-$7F,D0
		bpl	L04639C
		add.w	#$FF,D0
L04639C:	add.w	D0,MouseYOrig
		tst.w	MouseXOrig
		bpl	L0463B4
		clr.w	MouseXOrig
L0463B4:	cmp.w	#1,MouseYOrig
		bpl	L0463C6
		move.w	#1,MouseYOrig
L0463C6:	cmp.w	#$27F,MouseXOrig
		bmi	L0463DA
		move.w	#$27F,MouseXOrig
L0463DA:	cmp.w	#$1FF,MouseYOrig
		bmi	L0463EE
		move.w	#$1FF,MouseYOrig
L0463EE:	moveq	#0,d0
		move.w	MouseXOrig,D0
		lsr.w	#1,d0
		move.w	D0,MouseXPos
		moveq	#0,d0
		move.w	MouseYOrig,D0
		lsr.w	#1,D0
		move.w	D0,MouseYPos
		rts

Interrupt1:	movem.l	D0-D1/A0-A1/A5-A6,-(A7)
		lea	$DFF000,A0
		move.l	4.w,a6
		move.w	$1C(A0),D1
		btst	#$E,D1
		beq	L04648C
		AND.w	$1E(A0),D1
		btst	#6,D1
		beq	L046448
		movem.l	$9C(A6),A1/A5
		pea	-$24(A6)
		jmp	(A5)
L046448:	btst	#5,D1
		beq	L046478
		movem.l	D0-d7/a0-A6,-(A7)
		bsr	RefreshMaus
		bsr	SetMausSprite
		bsr	SongHandler
		bsr	ControlCursor
		bsr	EqualizerHandler
		bsr	RepeatHandler
		movem.l	(A7)+,D0-d7/a0-A6
		movem.l	$90(A6),A1/A5
		pea	-$24(A6)
		jmp	(A5)
L046478:	btst	#4,D1
		beq	L04648C
		movem.l	$84(A6),A1/A5
		pea	-$24(A6)
		jmp	(A5)
L04648C:	movem.l	(A7)+,D0-D1/A0-A1/A5-A6
		rte

KeyInterrupt:	movem.l	d0-d7/a0-a6,-(sp)
		lea	$bfe001,a0
		move.b	$c00(a0),d0		;Serieller Port
		bset	#6,$e00(a0)
		not.b	d0
		ror.b	#1,d0
		moveq	#50,d7
WK_Wait:	dbf	d7,WK_Wait
		bclr	#6,$e00(a0)
		btst	#6,d0
		beq.s	WK_Repeat
		clr.w	RepFlag
WK_Repeat:	cmp.b	#$60,d0
		beq.s	ShiftOn
		cmp.b	#$61,d0
		beq.s	ShiftOn
		cmp.b	#$62,d0
		beq.s	RepeatOn
		cmp.b	#$64,d0
		beq.s	AltOn
		cmp.b	#$65,d0
		beq.s	AltOn
		cmp.b	#$e4,d0
		beq.s	AltOff
		cmp.b	#$e5,d0
		beq.s	AltOff
		cmp.b	#$e0,d0
		beq.s	ShiftOff
		cmp.b	#$e1,d0
		beq.s	ShiftOff
		cmp.b	#$e2,d0
		beq.s	RepeatOff
		move.b	d0,Taste
		move.b	d0,OldKey
		btst	#7,d0
		bne.s	WK_End
		tst.w	RepeatOnOff
		beq.s	WK_End
		move.w	#15,RepCounter
		move.w	#1,RepFlag
WK_End:		movem.l	(sp)+,d0-d7/a0-a6
		rts

RepeatOn:	move.w	#1,RepeatOnOff
		bra.s	WK_End
RepeatOff:	clr.w	RepeatOnOff
		bra.s	WK_End

RepeatOnOff:	dc.w	0

ShiftOn:	move.w	#1,ShiftMode
		bra.s	WK_End
ShiftOff:	clr.w	ShiftMode
		bra.s	WK_End

ShiftMode:	dc.w	0

AltOn:		move.w	#1,AltMode
		bra.s	WK_End
AltOff:		clr.w	AltMode
		bra.s	WK_End

AltMode:	dc.w	0

* Repeat Interrupt ********************

RepeatHandler:	tst.w	RepFlag
		beq.s	RH_NoRep
		subq.w	#1,RepCounter
		bpl.s	RH_NoRep
		move.b	OldKey,Taste
		move.w	#3,RepCounter
RH_NoRep:	rts

OldKey:		dc.w	0
RepCounter:	dc.w	0
RepFlag:	dc.w	0

* New Auto-Request ********************

NewAutoReq:	move.l	a0,-(sp)
		move.l	OldCop,$dff080
		move.l	KeyIntPointer,a0
		move.l	OldKeyInt,(a0)
		move.l	(sp)+,a0
OldAutoJump:	jsr	0
		move.l	a0,-(sp)
		move.l	#CopperList,$dff080
		move.l	KeyIntPointer,a0
		move.l	#KeyInterrupt,(a0)
		move.l	(sp)+,a0
		rts

* Pattern aufbauen ********************

DrawWorkPlane:	move.w	#$2200,WorkPlaneMode
		move.l	#$1479,WorkPlaneOffset
		move.l	ActualTrack,D1
		lea	TextBuffer,A0
		DIVU	#10,D1
		add.w	#$30,D1
		move.b	D1,(A0)+
		clr.w	D1
		swap	D1
		add.w	#$30,D1
		move.b	D1,(A0)+
		clr.w	D1
		swap	D1
		move.l	#2,TextLen
		move.l	#TextBuffer,TextPointer
		bsr	PrintText

		move.l	#$1D61,WorkPlaneOffset
		move.l	SongPT,A6
		lea	SongHeader(a6),A6
		move.l	ActualTrack,D6
		lsl.l	#8,d6
		lsl.l	#2,d6
		add.l	D6,A6
		clr.l	WorkPlaneYCounter
		moveq	#0,d6
L0467E0:	move.l	WorkPlaneYCounter,D1
		lea	HexTab,a2
		add.w	d1,d1
		move.w	(a2,d1.w),TextBuffer
		move.l	#2,TextLen
		move.l	#TextBuffer,TextPointer
		bsr	PrintText
		clr.l	TextBuffer
		addq.l	#1,WorkPlaneOffset
		addq.l	#1,WorkPlaneYCounter

		moveq	#0,d7
L04683C:	moveq	#3,d0
		move.l	d0,TextLen
		move.w	(A6),D1

		lea	FullPeriodTab,A0
		moveq	#0,d0
DWP_SearchFreq:	cmp.w	(A0,D0.w),D1
		beq.s	DWP_FreqFound
		addq.w	#2,d0
		cmp.w	#72,d0
		bne.s	DWP_SearchFreq
		clr.w	(a6)
DWP_FreqFound:	add.l	d0,d0
		add.l	#FullNoteTab,D0
		move.l	D0,TextPointer
		bsr	PrintText

		addq.l	#1,WorkPlaneOffset
		moveq	#2,d0
		move.l	d0,TextLen

		moveq	#0,d0
		move.b	2(A6),D0
		add.w	d0,d0
		lea	HexTab,A0
		add.w	D0,A0
		move.l	A0,TextPointer
		bsr	PrintText
		moveq	#0,d0
		move.b	3(A6),D0
		add.w	d0,d0
		move.l	#HexTab,A0
		add.w	D0,A0
		move.l	A0,TextPointer
		bsr	PrintText
		addq.l	#1,WorkPlaneOffset
		addq.w	#4,A6
		addq.l	#1,D7
		cmp.l	#4,D7
		bne	L04683C
		add.l	#$F1,WorkPlaneOffset
		addq.w	#1,D6
		cmp.w	#$40,D6
		bne	l0467e0

		move.w	#$3200,WorkPlaneMode
		rts

SongOn:		move.w	ActualPosition,PrintNumber
		move.l	#$A8,WorkPlaneOffset
		bsr	PrintDez4
		move.l	SongPT,A0
		lea	472(a0),A0
		add.l	ActualPlayPos,A0
		move.b	(A0),PrintNumber+1
		move.l	#$260,WorkPlaneOffset
		bsr	PrintDez4
PrintSpeed:	move.w	ReplaySpeed,PrintNumber
		move.l	#$5d0,WorkPlaneOffset
		bra	PrintHex4

PrintPosPatt:	move.l	SongPT,A0
		lea	470(a0),A0
		move.l	A0,L046FF0
		move.b	(A0),PrintNumber+1
		move.l	#$418,WorkPlaneOffset
		bsr	PrintDez4
		move.w	ReplaySpeed,PrintNumber
		move.l	#$5D0,WorkPlaneOffset
		bsr	PrintHex4
PrintSongName:	move.l	SongPT,TextPointer
		move.l	#$1025,WorkPlaneOffset
		move.l	#$14,TextLen
		bra	PrintText
PrintSoundData:	move.w	ActualSample,PrintNumber
		move.l	#$788,WorkPlaneOffset
		bsr	PrintHex4
		lea	SoundMemEntries,a0
		move.w	ActualSample,d0
		lsl.w	#2,d0
		move.l	(a0,d0.w),ActSamplePT
		move.l	SongPT,A0
		move.w	ActualSample,D0
		mulu	#30,D0
		lea	-10(a0,d0.w),a0
		move.l	A0,L046FF0
		moveq	#0,d0
		move.w	$16(A0),D0
		move.w	D0,ActualLength
		add.l	d0,d0
		move.w	D0,PrintNumber
		move.l	#$940,WorkPlaneOffset
		bsr	PrintHex4
		move.l	L046FF0,A0
		move.w	$18(A0),PrintNumber
		move.w	$18(A0),ActualVol
		move.l	#$AF8,WorkPlaneOffset
		bsr	PrintDez4
		move.l	L046FF0,A0
		move.w	$1A(A0),PrintNumber
		move.w	$1A(A0),ActualRepeat
		move.l	#$CB0,WorkPlaneOffset
		bsr	PrintHex4
		move.l	L046FF0,A0
		moveq	#0,d0
		move.w	$1C(A0),D0
		move.w	D0,ActualRepLen
		add.l	d0,d0
		move.w	D0,PrintNumber
		move.l	#$E68,WorkPlaneOffset
		bsr	PrintHex4
		move.l	L046FF0,A0
		move.l	A0,TextPointer
		move.l	#$11DD,WorkPlaneOffset
		move.l	#$16,TextLen
		bra	PrintText

PrintDez4:	moveq	#0,d1
		move.w	PrintNumber,D1
		lea	TextBuffer,A0
		DIVU	#1000,D1
		bsr.s	MoveNumber
		DIVU	#100,D1
		bsr.s	MoveNumber
		DIVU	#10,D1
		bsr.s	MoveNumber
		bsr.s	MoveNumber
		move.l	#4,TextLen
		move.l	#TextBuffer,TextPointer
		bsr.L	PrintText
		clr.l	TextBuffer
		clr.w	PrintNumber
		rts

PrintDez2:	moveq	#0,d1
		move.w	PrintNumber,D1
		lea	TextBuffer,A0
		DIVU	#10,D1
		bsr.s	MoveNumber
		bsr.s	MoveNumber
		move.l	#2,TextLen
		move.l	#TextBuffer,TextPointer
		bsr.s	PrintText
		clr.l	TextBuffer
		clr.w	PrintNumber
		rts

MoveNumber:	add.w	#$30,D1
		move.b	D1,(A0)+
		clr.w	D1
		swap	D1
		rts

PrintHex4:	lea	PrintNumber,A0
		moveq	#0,d0
		move.b	(A0),D0
		add.w	d0,d0
		move.l	#HexTab,A0
		add.w	D0,A0
		move.l	A0,TextPointer
		move.l	#2,TextLen
		bsr	PrintText
		lea	PrintNumber,A0
		moveq	#0,d0
		move.b	1(A0),D0
		add.w	d0,d0
		move.l	#HexTab,A0
		add.w	D0,A0
		move.l	A0,TextPointer
		move.l	#2,TextLen
		bsr	PrintText
		clr.w	PrintNumber
		rts

PrintText:	clr.l	CharCounter
		move.l	TextLen,D3
PText_Loop:	move.l	TextPointer,A0
		add.l	CharCounter,A0
		moveq	#0,d1
		move.b	(A0),d1
		bne	PT_1
		move.b	ZeroChar,d1
PT_1:		cmp.b	#96,d1
		blt.s	NoBigChars
		sub.b	#32,d1
NoBigChars:	sub.b	#32,d1
		lsl.w	#4,d1
		move.l	Chars,A0
		add.w	d1,a0
		move.l	WorkPlane,A1
		add.l	WorkPlaneOffset,a1
		move.b	(A0),(A1)
		move.b	2(A0),$28(A1)
		move.b	4(A0),$28*2(A1)
		move.b	6(A0),$28*3(A1)
		move.b	8(A0),$28*4(A1)
		addq.l	#1,CharCounter
		addq.l	#1,WorkPlaneOffset
		cmp.l	CharCounter,D3
		bne.s	PText_Loop
		rts

PrintText1:	move.w	ZeroChar,-(sp)
		move.b	#' ',ZeroChar
		bsr.L	Printtext
		move.w	(sp)+,ZeroChar
		rts

ZeroChar:	dc.b	'-',0

* SpritePos setzen ********************
* <a0Sprite,<d0X,<d1Y,<d2Hoehe ********

SetSpritePos:	add.w	#$2c,D1
		add.w	D1,D2
		rol.w	#7,D2
		asl.w	#1,D2
		bcc.s	L046C74
		or.w	#2,D2
L046C74:	rol.w	#7,D1
		asl.w	#1,D1
		bcc.s	L046C80
		or.w	#4,D2
L046C80:	add.w	#$7d,D0
		asr.w	#1,D0
		bcc.s	L046C8E
		or.w	#1,D2
L046C8E:	or.w	D0,D1
		movem.w	D1-d2,(A0)
		rts

* File lesen **************************

ReadFile:	tst.l	FileLength
		beq.s	RF_Error
		bsr	SpriteGreen
		move.l	DosBase,A6
		move.l	FileNamePT,D1
		move.l	#$3ED,D2
		jsr	Open(A6)
		move.l	D0,FileHandle
		beq.s	RF_Error
		move.l	FileHandle,D1
		move.l	FileBuffer,D2
		move.l	FileLength,D3
		jsr	Read(A6)
		tst.l	d0
		beq.s	RF_Error
CloseFile:	move.l	FileHandle,D1
		move.l	DosBase,a6
		jsr	Close(A6)
		bsr	SpriteGrey
		moveq	#0,d0
		rts
RF_Error:	moveq	#-1,d0
		rts

* Fileteile lesen *********************

OpenFile:	bsr	SpriteGreen
		move.l	FileNamePT,d1
		move.l	#$3ed,d2
		move.l	DosBase,a6
		jsr	Open(a6)
		move.l	d0,FileHandle
		rts
ReadFilePart:	move.l	FileHandle,d1
		move.l	FileBuffer,d2
		move.l	FileLength,d3
		beq.s	RFP_Len0
		move.l	DosBase,a6
		jmp	Read(a6)
RFP_Len0:	rts

* File schreiben **********************

WriteFile:	bsr	SpriteGreen
		move.l	FileNamePT,D1
		move.l	#$3EE,D2
		move.l	DosBase,A6
		jsr	Open(A6)
		move.l	D0,FileHandle
		beq	SpriteRed
		move.l	FileHandle,D1
		move.l	FileBuffer,D2
		move.l	FileLength,D3
		move.l	DosBase,a6
		jsr	Write(A6)
		cmp.l	FileLength,d0
		beq.s	WI_Ok1
		bsr	SpriteRed
WI_Ok1:		move.l	FileHandle,D1
		move.l	DosBase,a6
		jsr	Close(A6)
		bra	SpriteGrey

SongFileName:	dc.b	'st-00:songs/'
SongName:	blk.b	28,0
SampleFileName:	dc.b	'st-01:'
SampleName:	blk.b	24,0

OrigMouseSprite:
	dc.l	0,$1000000,$2800180,$44003C0,$82007E0,$10100FF0,$20081FF8
	dc.l	$40043FFC,$80027FFE,$80027FFE,$83827FFE,$84427C3E,$8822781E
	dc.l	$9012700e,$a00a6006,$c0064002,$80028000,0
TonCursorSprite:
	dc.l	0,$ffe0ffe0,$ffe0ffe0,$80200000,$80200000,$80200000,$80200000
	dc.l	$80200000,$80200000,$80200000,$80200000,$80200000,$80200000
	dc.l	$ffe0,$ffe0,0
TextCursorSprite:
	dc.l	0,$fe00,$fe00,0,0
HexRawTab:
	dc.b	$A,1,2,3,4,5,6,7,8,9,$20,$35,$33,$22,$12,$23
NoteRawTab:
	dc.b	$31,$21,$32,$22,$33,$34,$24,$35,$25,$36,$26,$37
	dc.b	$38,$28,$39,$29,$3a

	dc.b	$10,2,$11,3,$12,$13,5,$14,6,$15,7,$16
	dc.b	$17,9,$18,$a,$19,$1a,$c,$1b,$d

	dc.b	$46,0

PeriodTab1:
	dc.w	$358,$328,$2FA,$2D0,$2A6,$280,$25C,$23A,$21A,$1FC,$1E0,$1C5
	dc.w	$1AC,$194,$17D,$168,$153

	dc.w	$1AC,$194,$17D,$168,$153,$140,$12E,$11D,$10D,$FE,$F0,$E2
	dc.w	$D6,$CA,$BE,$B4,$AA,$A0,$97,$8F,$87

	dc.w	0

NoteTab1:
	dc.b	'c-1 c#1 d-1 d#1 e-1 f-1 f#1 g-1 g#1 a-1 a#1 b-1 '
	dc.b	'c-2 c#2 d-2 d#2 e-2 '

	dc.b	'c-2 c#2 d-2 d#2 e-2 f-2 f#2 g-2 g#2 a-2 a#2 b-2 '
	dc.b	'c-3 c#3 d-3 d#3 e-3 f-3 f#3 g-3 g#3 '

	dc.b	'--- '

PeriodTab2:
	dc.w	$1AC,$194,$17D,$168,$153,$140,$12e,$11D,$10D,$FE,$F0,$E2
	dc.w	$D6,$CA,$BE,$b4,$aa

	dc.w	$D6,$CA,$BE,$B4,$AA,$A0,$97,$8F,$87,$7F,$78,$71
	dc.w	-1,-1,-1,-1,-1,-1,-1,-1,-1

	dc.w	0
NoteTab2:
	dc.b	'c-2 c#2 d-2 d#2 e-2 f-2 f#2 g-2 g#2 a-2 a#2 b-2 '
	dc.b	'c-3 c#3 d-3 d#3 e-3 '

	dc.b	'c-3 c#3 d-3 d#3 e-3 f-3 f#3 g-3 g#3 a-3 a#3 b-3 '
	dc.b	'                                    '
	dc.b	'--- '

FullPeriodTab:
	dc.w	$358,$328,$2FA,$2D0,$2A6,$280,$25C,$23A,$21A
	dc.w	$1FC,$1E0,$1C5,$1AC,$194,$17D,$168,$153,$140
	dc.w	$12E,$11D,$10D,$FE,$F0,$E2,$D6,$CA,$BE
	dc.w	$B4,$AA,$A0,$97,$8F,$87,$7F,$78,$71,0
FullNoteTab:
	dc.b	'c-1 c#1 d-1 d#1 e-1 f-1 f#1 g-1 g#1 a-1 a#1 b-1 '
	dc.b	'c-2 c#2 d-2 d#2 e-2 f-2 f#2 g-2 g#2 a-2 a#2 b-2 '
	dc.b	'c-3 c#3 d-3 d#3 e-3 f-3 f#3 g-3 g#3 a-3 a#3 b-3 --- '
HexTab:	dc.b	'000102030405060708090a0b0c0d0e0f'
	dc.b	'101112131415161718191a1b1c1d1e1f'
	dc.b	'202122232425262728292a2b2c2d2e2f'
	dc.b	'303132333435363738393a3b3c3d3e3f'
	dc.b	'404142434445464748494a4b4c4d4e4f'
	dc.b	'505152535455565758595a5b5c5d5e5f'
	dc.b	'606162636465666768696a6b6c6d6e6f'
	dc.b	'707172737475767778797a7b7c7d7e7f'
	dc.b	'808182838485868788898a8b8c8d8e8f'
	dc.b	'909192939495969798999a9b9c9d9e9f'
	dc.b	'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf'
	dc.b	'b0b1b2b3b4b5b6b7b8b9babbbcbdbebf'
	dc.b	'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf'
	dc.b	'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf'
	dc.b	'e0e1e2e3e4e5e6e7e8e9eaebecedeeef'
	dc.b	'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'
CursorXTab:
	dc.b	3,7,8,9,$A,$C,$10,$11,$12,$13,$15,$19,$1A,$1B,$1C,$1E
	dc.b	$22,$23,$24,$25
RawCodes:
	dc.b	$40,$20,$35,$33,$22,$12,$23,$24,$25,$17,$26
	dc.b	$27,$28,$37,$36,$18,$19,$10,$13,$21,$14,$16
	dc.b	$34,$11,$32,$15,$31,$A,1,2,3,4,5,6,7,8,9
	dc.b	$88,$89,$39,$b,$2a,$83,$3a,$a9		;(Bit7Shift)
AllowedKeys:
	dc.b	" abcdefghijklmnopqrstuvwxyz0123456789().-'#/:",0
	even
CopperList:
	dc.l	$1200000
	dc.l	$1220000
	dc.l	$1240000
	dc.l	$1260000
	dc.l	$1280000
	dc.l	$12a0000
	dc.l	$12c0000
	dc.l	$12e0000
	dc.l	$1300000
	dc.l	$1320000
	dc.l	$1340000
	dc.l	$1360000
	dc.l	$1380000
	dc.l	$13a0000
	dc.l	$13c0000
	dc.l	$13e0000
PicPlanes:
	dc.l	$e00000
	dc.l	$e20000
	dc.l	$e40000
	dc.l	$e60000
	dc.w	$E8
WorkplaneHi:
	dc.w	0,$EA
WorkPlaneLo:
	dc.w	0
CopperColors:
	dc.l	$1A20a00
	dc.l	$1a40800
	dc.l	$1a60600
	dc.l	$1a00000
	dc.l	$1800000
	dc.l	$1820344
	dc.l	$1840566
	dc.l	$1860788
	dc.l	$188008a
	dc.l	$18a0000
	dc.l	$18c0000
	dc.l	$18e0000
	dc.l	$1900000
	dc.l	$1920000
	dc.l	$1940000
	dc.l	$1960000
	dc.l	$1980000
	dc.l	$19a0000
	dc.l	$19c0000
	dc.l	$19e0000
	dc.l	$1A80000
	dc.l	$1AA0700
	dc.l	$1ac0400
	dc.l	$1ae0a00
	dc.l	$8e0581
	dc.l	$9040c1
	dc.l	$920038
	dc.l	$9400d0
	dc.l	$1020000
	dc.l	$2c07fffe
	dc.l	$1003200
	dc.l	$B807FFFE
	dc.l	$1002200
WorkPlanePT2:
	dc.l	$E80000
	dc.l	$EA0000

	dc.l	$B907FFFE
	dc.w	$100
WorkPlaneMode:
	dc.w	$3200
	dc.l	$E907FFFE
	dc.l	$10affd8
	dc.l	$108ffd8
	dc.l	$Ea07FFFE
	dc.l	$10a0000
	dc.l	$1080000
	dc.l	$Eb07FFFE
	dc.l	$10affd8
	dc.l	$108ffd8
	dc.l	$Ec07FFFE
	dc.l	$10a0000
	dc.l	$1080000
	dc.l	$Ed07FFFE
	dc.l	$10affd8
	dc.l	$108ffd8
	dc.l	$Ee07FFFE
	dc.l	$10a0000
	dc.l	$1080000
	dc.l	$ef07FFFE
	dc.l	$10affd8
	dc.l	$108ffd8
	dc.l	$f007FFFE
	dc.l	$10a0000
	dc.l	$1080000
	dc.l	$f107FFFE
	dc.l	$10affd8
	dc.l	$108ffd8
	dc.l	$f207FFFE
	dc.l	$10a0000
	dc.l	$1080000
	dc.l	$f307FFFE
	dc.l	$10affd8
	dc.l	$108ffd8
	dc.l	$f407FFFE
	dc.l	$10a0000
	dc.l	$1080000
	dc.l	$f507FFFE
	dc.l	$10affd8
	dc.l	$108ffd8
	dc.l	$f607FFFE
	dc.l	$10a0000
	dc.l	$1080000
	dc.l	$FFDFfffe
	dc.l	$2907fffe
	dc.l	$1002200
	dc.l	$2c07fffe
	dc.l	$1000000
	dc.l	-2

OldKeyInt:	dc.l	0
OldSP:		dc.l	0
OldInterrupt1:	dc.l	0
SampleBufferLen:dc.l	0
PlayBuffer:	dc.w	0
PackModus:	dc.w	0
SourceAd:	dc.l	0
SourceEnd:	dc.l	0
SourceLength:	dc.l	0
DestAd:		dc.l	0
DestEnd:	dc.l	0
DestLength:	dc.l	0
ActualOffset:	dc.l	0	
AW_Mode:	dc.w	0	;Modus0Kein,1Equalizer,2Sampler,3Load,4Save
L044EE8:	dc.w	0
L044EEA:	dc.w	0
maxsoffset:	dc.l	0
tbloffset:	dc.w	0
PListLen:	dc.l	0
PresetList:	dc.l	0
PresetEntries:	dc.w	0
WorkPlane:	dc.l	0
WorkPlaneOffset:dc.l	0
WorkPlaneYCounter:
		dc.l	0
EditMode:	dc.l	0
SongMode:	dc.l	0
L046FF0:	dc.l	0
CharCounter:	dc.l	0
TextPointer:	dc.l	0
TextLen:	dc.l	0
ActualTrack:	dc.l	0
ActualPlayPos:	dc.w	0
ActualPosition:	dc.w	0
ActualPeriodTab:dc.l	PeriodTab1
ActualNoteTab:	dc.l	NoteTab1
L04701C:	dc.w	0
Taste:		dc.w	0
Periodsave:	dc.w	0
TextCursorXPos:	dc.w	0
TextCursorYPos:	dc.w	0
L047026:	dc.l	0
WorkPosY:	dc.w	0
CursorX:	dc.w	0
L04702E:	dc.w	0
PrintNumber:	dc.w	0
ActualSample:	dc.w	1
L047038:	dc.w	0
OldX:		dc.w	0
OldY:		dc.w	0
MouseXOrig:	dc.w	0
MouseYOrig:	dc.w	0
MouseXPos:	dc.w	0
MouseYPos:	dc.w	0
ActualXPos:	dc.w	0
ActualYPos:	dc.w	0
ActualLength:	dc.w	0
ActualVol:	dc.w	0
ActualRepeat:	dc.w	0
ActualRepLen:	dc.w	0
ActSamplePT:	dc.l	0
FileNamePT:	dc.l	0
FileBuffer:	dc.l	0
FileHandle:	dc.l	0
FileLength:	dc.l	0
TrackOffset:	dc.l	0
L04707A:	dc.l	0
L047082:	dc.l	0
SongPT:		dc.w	0
SoundMemEntries:dc.w	0
L04708E:	dc.w	0
L047090:	blk.w	60,0
L047108:	dc.w	0

		align	4
FileInfoBlock:	blk.b	260,0
EquOffsetTable:	blk.w	36,0
HiTable:	blk.w	46,0
EquNewData:	blk.w	23,0	;New Data
EquOldData:	blk.w	23,0	;Old Data
TextBuffer:	blk.w	3,0
BufferTrack:	blk.l	64,0
PatternBuffer:	blk.l	256,0
PointList:	blk.w	112,0
