	opt	d-

send = 0
	IFNE send=0

init2		= $7f000
init		= $7f002
loadfile	= $7f004
info		= $7f006

loadpic		= $4a3e0
Game		= $580
Stack		= $580
S_Stack		= Stack-$c0
F5_Intro	= $39a54

main_len	= 32202
intro_len	= 134700
UnPack	= $7ee66

DATA_SCORE		= $200
DATA_LIFES		= $204
DATA_ALL_LIFES		= $206
DATA_DIAMONDS		= $208
DATA_ALL_DIAMONDS	= $20a
DATA_WORLD_CLEAR	= $20c
DATA_RAPID		= $20d
DATA_ACT_LIFES		= $20e
DATA_LEVEL		= $210	;Schwierigkeits-grad
DATA_CONTROL		= $211
DATA_WEAPONS		= $212
DATA_CONTINUE		= $220
DATA_BIGCPU		= $222
DATA_CHEAT		= $224
DATA_SUPER		= $225

TITEL_LEVEL		= $300+220
TITEL_RAPID		= $300+221
TITEL_CONTROL		= $300+222
TITEL_SCORE		= $300+196

	ORG	$7e900-8
	dc.l	$6e900
	dc.l	$0

start:
	clr.l	$300
	bset	#1,$bfe001
	move.l	4,a0
	sf	DATA_BIGCPU
	cmp.b	#$7f,297(a0)
	bne.s	.no_big_cpu
	st	DATA_BIGCPU
.no_big_cpu:
	move.w	#$7fff,$dff096
	clr.l	DATA_SCORE
	move.l	#trapin,($80).w
	trap	#0
	lea	Stack,sp
	jsr	init2
	moveq	#6,d0
	bsr	loadit

	move.l	#start_intro,$80
	trap	#0
loop:

	lea	Stack,sp
	moveq	#7,d0		;Titel-file
	bsr	loadit2

;	lea	$16500-$1a00+f5_len,a6
;	lea	$a00,a5
;	jsr	UnPack

	lea	Stack,sp
	move.l	#trapin,($80).w
	trap	#0

	tst.b	f5_intro_loaded
	beq.s	.no_f5_intro

	move.l	#stop_intro,$80
	trap	#0

	move.w	#$7fff,$dff09a
	move.w	#$7fff,$dff09c

.no_f5_intro:

	bsr	pic_ausblend

	moveq	#8,d0		;Titel-sound
	bsr	loadit

	move.l	DATA_SCORE.w,TITEL_SCORE.w
	jsr	$a00		;Titel-Prg

	move.b	TITEL_CONTROL.w,DATA_CONTROL.w
	move.b	TITEL_LEVEL.w,DATA_LEVEL.w
	move.b	TITEL_RAPID.w,DATA_RAPID.w
	eor.b	#1,DATA_RAPID.w

	bsr	init_game
	move.b	#4,DATA_CONTINUE


	move.w	#$7fff,$dff09a
	lea	Stack,sp
	move.l	#trapin,($80).w
	trap	#0

	bsr	get_loadpic

	moveq	#2,d0
	jsr	loadpic		;Show Load-pic (without numbers)
	move.l	a0,load_clist
	st	pic_on

	moveq	#0,d0		;Main-file
	bsr	loadit2
	bsr	create_main_file

.world1_again:

	moveq	#4,d0		;World 1
	bsr	loadit2
	moveq	#5,d0		;Sound 1
	bsr	loadit2

	bsr	pic_ausblend

	jsr	Game		;Play World 1

	bsr	check_continue
	beq	.world1_again
	bpl	loop
	bsr	skip_world
.world2_again:
	moveq	#9,d0		;World 2
	bsr	loadit2
	moveq	#10,d0		;Sound 2
	bsr	loadit2

	bsr	pic_ausblend
	jsr	Game		;Play World 2

	tst.b	DATA_LEVEL
	bne.s	.no_easy
	bsr	get_loadpic

	moveq	#3,d0
	jsr	loadpic		;Show Easy-Screen
	jsr	loadpic+4	;Load-pic ausblenden!

	moveq	#1,d0
	jsr	loadpic		;Show Game-Over-Screen
	move.l	a0,load_clist
	st	pic_on

	bra	loop
.no_easy:
	bsr	check_continue
	beq	.world2_again
	bpl	loop
	bsr	skip_world

.world3_again:
	moveq	#12,d0		;World 3
	bsr	loadit2
	moveq	#13,d0		;Sound 3
	bsr	loadit2

	bsr	pic_ausblend
	jsr	Game		;Play World 3

	bsr	check_continue
	beq	.world3_again
	bpl	loop
	bsr	skip_world

.world4_again:
	moveq	#14,d0		;World 4
	bsr	loadit2
	moveq	#15,d0		;Sound 4
	bsr	loadit2

	bsr	pic_ausblend
	jsr	Game		;Play World 4

	bsr	check_continue
	beq	.world4_again
	bpl	loop

	bsr	skip_world
.world5_again:
	moveq	#0,d0		;Main-file
	bsr	loadit2
	bsr	create_main_file

	moveq	#1,d0		;World 5
	bsr	loadit2
	moveq	#2,d0		;Sound 5
	bsr	loadit2

	bsr	pic_ausblend
	jsr	Game		;Play World 5

	bsr	check_continue
	beq	.world5_again
	bpl	loop

	moveq	#16,d0		;Outro
	bsr	loadit2

	bsr	pic_ausblend

	moveq	#8,d0		;Titel-sound
	bsr	loadit

	jsr	$a00		;Outro
	move.w	#$7fff,$dff09a

	bra	loop

get_loadpic:
	moveq	#11,d0
	bsr	loadit
	lea	$50000+intro_len-20*$1a00,a6
	lea	$40000,a5
	jsr	UnPack

	rts

pic_ausblend:
	tst.b	pic_on
	beq.s	.no
	jsr	loadpic+4	;Load-pic ausblenden!
	move.w	#$7fff,$dff09a
	sf	pic_on
.no:
	rts

check_continue:
	move.w	#$7fff,$dff09a
	tst.b	DATA_WORLD_CLEAR		;Mit ESC abgebrochen oder geschafft ?
	beq.s	.dead
	bpl.s	.out

	;Next World!

	;Loadpic laden und Anzeigen.
	bsr	get_loadpic

	moveq	#0,d0
	jsr	loadpic		;Show Load-pic (with numbers)
	move.l	a0,load_clist
	st	pic_on
	moveq	#-1,d0
	rts

.dead:
	;Loadpic laden und Anzeigen.
	bsr	get_loadpic

	subq.b	#1,DATA_CONTINUE
	ble.s	.game_over

	moveq	#-1,d0
	jsr	loadpic		;Show Continue-Screen
	beq.s	.continue

	;Game-over-Screen
.game_over:
	moveq	#1,d0
	jsr	loadpic
	move.l	a0,load_clist
	st	pic_on
	moveq	#1,d0
	rts

.continue:
	moveq	#2,d0
	jsr	loadpic		;Show Load-Screen
	st	pic_on

	moveq	#0,d0		;Main-file
	bsr	loadit2
	bsr	create_main_file

	bsr	init_game
	moveq	#0,d0		;Continue!
	rts
.out:
	rts

init_game:
	clr.l	DATA_SCORE.w
	clr.l	DATA_WEAPONS
	clr.w	DATA_WEAPONS+4
	move.b	#3,DATA_ACT_LIFES
	move.b	#1,DATA_WEAPONS+4
	clr.w	DATA_CHEAT
	rts

skip_world:
	bclr	#3,DATA_CHEAT
	beq.s	.out
	moveq	#0,d0		;Main-file
	bsr	loadit2
	bsr	create_main_file
.out:
	rts

loadit:
	lea	0.w,a0
	jmp	loadfile

loadit2:
	move.l	load_clist(pc),a0
	jmp	loadfile

start_intro:
	lea	F5_Intro+44610,a0
	moveq	#1,d0
	jsr	F5_Intro
	jsr	F5_Intro+16
	move.l	a0,load_clist
	st	f5_intro_loaded
	rte

stop_intro:
	jsr	F5_Intro+8
	move.w	#$2000,sr
	sf	f5_intro_loaded

	lea	$dff180,a0
	moveq	#31,d7
.set_cols:
	move.w	#$000,(a0)+
	dbf	d7,.set_cols

	rte

create_main_file:
	lea	$10000,a0
	lea	$580,a1
	move.l	#main_len,d0
	bsr.s	.copy_file
	lea	$10000+main_len,a0
	lea	$39a54,a1
	move.l	#26028,d0
	bsr.s	.copy_file
	lea	$10000+main_len+26028,a0
	lea	$5b500,a1
	move.l	#16488,d0
	bsr.s	.copy_file
	lea	$10000+main_len+42516,a0
	lea	$6ed20,a1
	move.l	#5104,d0
	bsr.s	.copy_file

	rts

.copy_file:
	subq.l	#1,d0
.loop:
	move.b	(a0)+,(a1)+
	dbf	d0,.loop
	rts

trapin:
	movem.l	(sp)+,d0-d2
	lea	S_Stack,sp
	movem.l	d0-d2,-(sp)
	rte

farbe:
	move.w	#$ffff,d0
.loop:
	move.w	d0,$dff180
	dbf	d0,.loop
	rts

go:
	move.w	#$0180,$dff096	;Bit-plane+Copper ausschalten.
	bra	loop

load_clist:	dc.l	0
pic_on:		dc.b	0
f5_intro_loaded:dc.b	0

	ENDC

	IFNE send=1

Execbase	= 4
AllocMem	= -198
AvailMem	= -216

	;/* Hardware-include-file      */
	;/* (p) 1990 by Peter Thierolf */

custom	= $dff000

bltddat	= $000
dmaconr	= $002
vposr	= $004
vhposr	= $006
dskdatr	= $008
joy0dat	= $00a
joy1dat	= $00c
clxdat	= $00e
adkconr	= $010
pot0dat	= $012
pot1dat	= $014
potgor	= $016
serdatr	= $018
dskbytr	= $01a
intenar	= $01c
intreqr	= $01e
dskpth	= $020
dskptl	= $022
dsklen	= $024
dskdat	= $026
refptr	= $028
vposw	= $02a
vhposw	= $02c
copcon	= $02e
serdat	= $030
serper	= $032
potgo	= $034
joytest	= $036
strequ	= $038
strvbl	= $03a
strhor	= $03c
strlong	= $03e
bltcon0	= $040
bltcon1	= $042
bltafwm	= $044
bltalwm	= $046
bltcpth	= $048
bltcptl	= $04a
bltbpth	= $04c
bltbptl	= $04e
bltapth	= $050
bltaptl	= $052
bltdpth	= $054
bltdptl	= $056
bltsize	= $058

bltcmod	= $060
bltbmod	= $062
bltamod	= $064
bltdmod	= $066
 
bltcdat	= $070
bltbdat	= $072
bltadat	= $074

dsksync	= $07e
cop1lch	= $080
cop1lcl	= $082
cop2lch	= $084
cop2lcl	= $086
copjmp1	= $088
copjmp2	= $08a
copins	= $08c
diwstrt	= $08e
diwstop	= $090
ddfstrt	= $092
ddfstop	= $094
dmacon	= $096
clxcon	= $098
intena	= $09a
intreq	= $09c
adkcon	= $09e

audlch	= $000
audlcl	= $002
audlen	= $004
audper	= $006
audvol	= $008
auddat	= $00a

aud0	= $0a0
aud1	= $0b0
aud2	= $0c0
aud3	= $0e0

bpl1pth	= $0e0
bpl1ptl	= $0e2
bpl2pth	= $0e4
bpl2ptl	= $0e6
bpl3pth	= $0e8
bpl3ptl	= $0ea
bpl4pth	= $0ec
bpl4ptl	= $0ee
bpl5pth	= $0f0
bpl5ptl	= $0f2
bpl6pth	= $0f4
bpl6ptl	= $0f6

bplcon0	= $100
bplcon1	= $102
bplcon2	= $104

bpl1mod	= $108
bpl2mod	= $10a

bpl1dat	= $110
bpl2dat	= $112
bpl3dat	= $114
bpl4dat	= $116
bpl5dat	= $118
bpl6dat	= $11a

spr0pth	= $120
spr0ptl	= $122
spr1pth	= $124
spr1ptl	= $126
spr2pth	= $128
spr2ptl	= $12a
spr3pth	= $12c
spr3ptl	= $12e
spr4pth	= $130
spr4ptl	= $132
spr5pth	= $134
spr5ptl	= $136
spr6pth	= $138
spr6ptl	= $13a
spr7pth	= $13c
spr7ptl	= $13e

sprpos	= $000
sprctl	= $002
sprdata	= $004
sprdatb	= $006

spr0	= $140
spr1	= $148
spr2	= $150
spr3	= $158
spr4	= $160
spr5	= $168
spr6	= $170
spr7	= $178

color	= $180

	;/* Cia's */

ciaa	= $bfe001
ciab	= $bfd000

pra	= $000
prb	= $100
ddra	= $200
ddrb	= $300
talo	= $400
tahi	= $500
tblo	= $600
tbhi	= $700
todlo	= $800
todmid	= $900
todhi	= $a00
sdr	= $c00
icr	= $d00
cra	= $e00
crb	= $f00

mili3	= 2128
mili50	= 35468

inbits	= ciaa+pra
outbits	= ciab+prb

font	= $7eea0
UnPack	= $7ee66

bufferstart	= $60000

	;Loading tune

mdat	= $4d8c4
smpl	= $4d8c0
tfmx	= $4de00

messclist1 = $7ee32

	;Parameter für die Disketten-erkennung

syncwert	= $4489
code1		= $2aa5		;T3 Disk-kennung!

Verify	= 0

trklen	= $1a00

	;Erweiterungen :
	;10.8.	Laden einer GENAUEN Byte-länge, nicht mehr nur vielfache der trklen.

	opt	o+,ow-,t-

	ORG	$7f000-8

	dc.l	$6f000
	dc.l	$0

	bra.s	init2
	bra.s	init
	bra.s	loadfile
	bra	getinfo
	bra	loadfile2

init2:
	bsr	get_mem_config
	bsr.s	init		;Setup Disk-IO-Registers
	bsr	setup_config	;Check Drives
	bra	search_disks	;Search for System Disks.

init:
	bra	setup

loadfile:
	clr.l	startpointer
	clr.l	destpointer
loadjmp:
	lea	custom,a5
	move.w	dmaconr(a5),d7
	or.w	#$8000,d7
	move.w	d7,olddma

	move.l	a0,d7
	bne.s	.ok
	lea	clist(pc),a0
.ok:
	move.l	a0,oldclist
	move.l	a0,cop1lch(a5)

	move.b	d0,file_number

	btst	#6,d0
	beq.s	.nosoundon

	move.l	#mdat,d0
	move.l	#smpl,d1
	jsr	tfmx+52
	moveq	#0,d0
	jsr	tfmx+44
	move.l	#vbiin,$6c
	move.w	#$c020,intena(a5)

	move.b	file_number(pc),d0
.nosoundon:
	and.w	#$1f,d0
	move.w	d0,d2
	lea	filetable(pc),a0
	asl.w	#4,d0
	move.w	d0,d1

;	cmp.w	#1,d0
;	beq.s	.no_memload

	tst.l	12(a0,d1.w)
	bne	.is_in_mem

.no_memload:
	move.l	8(a0,d1.w),d0	;Länge

	;Testen, ob im RAM platz ist.

	move.l	mem_ext_point(pc),d2
	beq.s	.no_ext_mem
	move.l	d2,d3
	neg.l	d2
	add.l	mem_ext_end(pc),d2
	cmp.l	d2,d0
	bge.s	.no_ext_mem
	move.l	d3,d2
	add.l	d0,d3

	move.l	d3,mem_ext_point

	bra	.load_to_mem

.no_ext_mem:
	move.l	mem_loc_point(pc),d2
	beq.s	.no_loc_mem
	move.l	d2,d3
	neg.l	d2
	add.l	mem_loc_end(pc),d2
	cmp.l	d2,d0
	bge.s	.no_loc_mem

	move.l	d3,d2
	add.l	d0,d3

	move.l	d3,mem_loc_point
	bra	.load_to_mem
.no_loc_mem:

	move.b	(a0,d1.w),disk_num	;Disk
	move.b	1(a0,d1.w),start_track	;Spur
	move.b	2(a0,d1.w),start_head	;Kopf

	tst.l	startpointer
	bne.s	.nomov			;Soll an andere Adresse geladen werden.
	move.l	4(a0,d1.w),startpointer	;Adresse
.nomov:
	move.l	startpointer(pc),-(sp)

	move.l	8(a0,d1.w),diskIOlen	;Länge
	bsr	set_diskname
	bsr	loadit
	move.l	(sp)+,a0

.noload:
	bclr	#0,load_flg		;Beim komplett laden nicht in den Speicher tun!
	bne.s	.nosoundoff
	cmp.l	#"TPWM",(a0)		;Ist es ein gepacktes File ?
	bne.s	.nopack
	bsr.s	.repack			;Wenn ja, repacken.
.nopack:
	btst	#5,file_number
	beq.s	.nosoundoff

	jsr	tfmx+40		;Musi stoppen.

.nosoundoff:
	bsr	unselect
	rts

.repack:					;Das File ist gepackt!
	tst.l	destpointer
	beq.s	.normal_repack
	;Das File muss an eine fremde Adresse repacked werden.
	move.l	a0,a6
	move.l	destpointer(pc),a5
	bra	UnPack
.normal_repack:
	lea	filetable(pc),a1
	moveq	#0,d0
	move.b	file_number(pc),d0
	and.w	#$1f,d0
	asl.w	#4,d0
	move.b	3(a1,d0.w),d0
	and.w	#$ff,d0
	asl.b	#2,d0
	lea	adr_table(pc),a1
	move.l	(a1,d0.w),a5
	move.l	a0,a6
	bra	UnPack

	;Speicher Verwaltung

	;­­­­­­­­Laden in den Speicher­­­­­­­­­­
.load_to_mem:
	move.l	startpointer(pc),-(sp)	;Alten startpointer sichern
	move.l	d1,-(sp)
					;(Falls an fremde Adr. geladen werden soll)
	move.l	d2,12(a0,d1.w)		;Hier liegt das File im Speicher.
	move.b	(a0,d1.w),disk_num	;Disk
	move.b	1(a0,d1.w),start_track	;Spur
	move.b	2(a0,d1.w),start_head	;Kopf

	move.l	d2,startpointer		;Adresse
	move.l	d0,diskIOlen		;Länge
	bsr	set_diskname
	bsr	loadit

	move.l	(sp)+,d1
	lea	filetable(pc),a0
	;­­­­­­­­Laden aus dem Speicher­­­­­­­­­
.load_from_mem:
	move.l	8(a0,d1.w),d7	;Länge
	move.l	12(a0,d1.w),a1	;Quelladresse
	move.l	(sp)+,d6	;Soll an fremde Adresse geladen werden ?
	beq.s	.setorig

	move.l	d6,a2		;An fremde Adresse laden.
	bra.s	.noset
.setorig:
	move.l	4(a0,d1.w),a2	;An gespeicherte Adresse laden.
.noset:
	move.l	a2,-(sp)

.loop2:
	bsr.s	.copytrack
	cmp.l	#trklen*6,d7
	bne.s	.nosnd
	btst	#5,file_number
	beq.s	.nosnd

	moveq	#3,d0
	swap	d0
	jsr	tfmx+72		;Musik ausblenden.
.nosnd:
	sub.l	#trklen,d7
	bgt	.loop2
	lea	custom,a5
	move.l	(sp)+,a0	;Wegen entpacken.
	bra	.noload

.is_in_mem:
	move.l	startpointer,-(sp)
	bra	.load_from_mem

.copytrack:
	cmp.l	#trklen,d7
	blt.s	.copy_bytes
	move.w	#207,d6
.copyloop:
	movem.l	(a1)+,d0-d5/a3/a5
	movem.l	d0-d5/a3/a5,(a2)
	lea	32(a2),a2
	dbf	d6,.copyloop
	rts

.copy_bytes:
	move.w	d7,d6
	subq.w	#1,d6
.copyloop2:
	move.b	(a1)+,(a2)+
	dbf	d6,.copyloop2
	rts

loadfile2:
	move.l	d2,destpointer
	move.l	d1,startpointer		;Adresse
	beq.s	.all_load
	bra	loadjmp
.all_load:
	clr.l	destpointer
	bset	#0,load_flg
	bra	loadjmp

getinfo:
	lea	drive_flags(pc),a0
	rts

loadit:
	bsr	setup

	move.b	disk_num(pc),d0
	lea	drive_disks(pc),a0
	moveq	#3,d1
.loop:
	cmp.b	(a0,d1.w),d0
	beq.s	.found
	dbf	d1,.loop

	lea	text2(pc),a1
	bsr	showtext
	bsr	react_user

	bra.s	.gotit

.found:
	move.w	d1,unit_num
.gotit:
	bsr	reselect

	move.b	start_track(pc),d0
	bsr	stepto
	move.b	start_head(pc),d0
	move.w	unit_num(pc),d1
	lea	side(pc),a0
	move.b	d0,(a0,d1.w)
	bsr	selside
	bsr	checkdrive
	bsr	motoron

	bsr.s	load

	bra	motoroff

	IFNE	Verify
farbe:
	move.w	#$ffff,d0
.loop:
	move.w	d0,$dff180
	dbf	d0,.loop
	rts
	ENDC

	;Erwartet einen eingeschalteten Motor, einen angefahrenen Track
	;sowie eine in 'side' eingetragene Diskettenseite.
	;Im 'startpointer' wird die Load-adresse übergeben,
	;in 'diskIOlen' wird die Load-länge übergeben.

load:
	moveq	#0,d0
	lea	tracknr(pc),a0
	move.b	(a0,d5.w),d0
	move.w	d0,act_track		;Aktuelle Spurnummer speichern.
	lea	side(pc),a0
	move.b	(a0,d5.w),act_side
	move.b	#3,trycount
.nexttrack:
	clr.b	errorcount
.tryloop:
	move.w	#$1002,intena(a5)
	move.w	#$8210,dmacon(a5)
	lea	side(pc),a0
	move.b	act_side,(a0,d5.w)

	bsr	selside
	move.w	#$7700,adkcon(a5)
	clr.w	dsklen(a5)
	move.w	#syncwert,dsksync(a5)
	move.w	#$9500,adkcon(a5)
	move.l	trkbuffer(pc),dskpth(a5)
	move.w	#$9a20,dsklen(a5)	;$1a20 Bytes laden
	move.w	#$9a20,dsklen(a5)

	;Timer steht auf 3 ms.

	move.w	#999,d0			;nach 3 sec timeout setzen.
.waiton:
	bset	#0,ciaa+cra
.waitdma:
	btst	#1,intreqr+1(a5)	;DMA finished Flag!
	bne.s	.dmaok
	btst	#0,ciaa+icr
	beq.s	.waitdma
	subq.w	#1,d0
	bpl.s	.waiton
	bra	.timeout

.dmaok:
	move.w	#$1002,intreq(a5)
	move.w	#$4000,dsklen(a5)

	move.l	startpointer(pc),a3

	move.l	trkbuffer(pc),a1
	lea	-2(a1),a1
.sync:
	addq.l	#2,a1
	cmp.w	#syncwert,(a1)
	beq	.sync

	move.w	(a1)+,d2

	move.w	(a1)+,d0
	and.w	#$5555,d0
	asl.w	#1,d0
	move.w	(a1)+,d1
	and.w	#$5555,d1
	or.w	d1,d0
	lea	tracknr(pc),a0
	cmp.b	(a0,d5.w),d0
	beq.s	.notrkerror

	;vermerkte Spur stimmt nicht mit der aktuellen überein !
	;> Drive reseten.

	bsr	resetdrive
	bsr	checkdrive
	bsr	setup
	bsr	motoron
	bsr	selside
	bra.s	.track_search

.notrkerror:
	cmp.w	act_track(pc),d0
	beq.s	.load_ok

	;Es wird vom falschen Track geladen!!!!
	;> Laufwerk zum richtigen Track fahren und Laden wiederholen.

.track_search:
	move.w	act_track(pc),d0
	bsr	stepto
	bra	.nexttrack

.load_ok:

	;Alles in Ordnung.

	cmp.w	diskcode,d2
	bne	.wrongdisk

	move.l	diskIOlen(pc),d5
	cmp.l	#trklen,d5
	ble.s	.len_ok
	move.l	#trklen,d5
	move.l	#$55555555,d6
.len_ok:
	move.w	#(trklen/4)-1,d7
	moveq	#0,d3
.loop:
	move.l	(a1)+,d0
	and.l	d6,d0
	add.l	d0,d0			;asl.l	#1,d0
	move.l	(a1)+,d1
	and.l	d6,d1
	or.l	d1,d0
	add.l	d0,d3			;Checksum
	subq.l	#4,d5
	bmi.s	.no_write		;Nicht mehr in den Speicher schreiben, File ist schon komplett!
	move.l	d0,(a3)+
.no_write:
	dbf	d7,.loop

	move.l	(a1)+,d0
	and.l	d6,d0
	add.l	d0,d0			;asl.l	#1,d0
	move.l	(a1)+,d1
	and.l	d6,d1
	or.l	d1,d0
	cmp.l	d0,d3
	bne	.checkerror

	;Checksum stimmt, also richtig geladen.

	sub.l	#trklen,diskIOlen
	beq.s	.ready
	bmi.s	.ready
	cmp.l	#trklen,diskIOlen
	bne.s	.nocheck
	btst	#5,file_number
	beq.s	.nocheck
	moveq	#3,d0
	swap	d0
	jsr	tfmx+72
.nocheck:
	add.l	#trklen,startpointer
	lea	side(pc),a0
	eor.b	#1,act_side
	eor.b	#1,(a0,d5.w)
	bne	.nexttrack
	bsr	stepin
	addq.w	#1,act_track
	bra	.nexttrack
.ready:
	rts
.end:
	bra.s	.timeout

.checkerror:
	addq.b	#1,errorcount
	cmp.b	#3,errorcount
	bne	.tryloop
	subq.b	#1,trycount
	bmi	.end
	lea	tracknr(pc),a0
	move.b	(a0,d5.w),-(sp)

	bsr	resetdrive
	bsr	checkdrive
	bsr	motoron
	bsr	selside
	move.b	(sp)+,d0
	bsr	stepto
	bra	.nexttrack

.timeout:
	move.w	#$4000,dsklen(a5)	;DMA stoppen.
	btst	#2,inbits
	beq	.notimeout		;Keine Disk drin.

	;Echter Timeout -> Diskettenfehler.

	bsr	setup			;Alles reseten.

	lea	text1(pc),a1
	bsr	showtext
	bsr	waitmouse
	bsr	resttext
	bsr	reselect

	bsr	resetdrive

	bsr	search_disks	;Search for Apidya Disks.
	bsr	reselect

	bsr	motoron
	bne	.notimeout

	bsr	selside
	move.w	act_track(pc),d0
	bsr	stepto

	move.b	#3,trycount
	clr.b	errorcount

	bra	.tryloop

.wrongdisk:			;Falsche Disk ist eingelegt.

	move.w	#$4000,dsklen(a5)
	btst	#2,inbits	;Disk drin ???
	beq.s	.notimeout	;Offensichtlich gewechselt.
	bra	.searchdisks

.notimeout:
	;Wirklich keine Disk drin ?

	btst	#5,inbits
	beq	.checkerror	;Disk ist drin.

.searchdisks:
	bsr	motoroff
	bsr	waitlong

	bsr	reselect

	lea	text2(pc),a1
	bsr	showtext

	bsr	react_user

	bsr	waitlong

	bsr	reselect
	bsr	checkdrive
	bsr	motoron
	bne	.notimeout

	bsr	waitlong

	bra	.tryloop

set_diskname:
	move.w	#code1,diskcode
	rts

stepto:
	lea	tracknr(pc),a0
	cmp.b	(a0,d5.w),d0
	beq.s	.done
	blt.s	.out
	bsr	stepin
	bra	stepto
.out:
	bsr	stepout
	bra	stepto
.done:
	rts

resetdrive:
	bsr	motoroff
	bsr	reselect
	move.b	selmask(pc),d0
	bset	#1,d0
	move.b	d0,selmask	;Step-richtung festlegen

	bsr	wait
.loop:
	btst	#4,inbits
	beq.s	.done
	bsr.s	dostep
	bsr	wait
	bra	.loop
.done:
	lea	tracknr(pc),a0
	move.b	#0,(a0,d5.w)
	rts

dostep:
	move.b	selmask(pc),d7
	bclr	#0,d7
	move.b	d7,outbits
	nop
	move.b	selmask(pc),outbits
	bra	wait

stepout:
	move.b	selmask(pc),d7
	bset	#1,d7
	move.b	d7,selmask
	lea	tracknr(pc),a0
	subq.b	#1,(a0,d5.w)
	bra.s	dostep

stepin:
	move.b	selmask(pc),d7
	bclr	#1,d7
	move.b	d7,selmask
	lea	tracknr(pc),a0
	addq.b	#1,(a0,d5.w)
	bra.s	dostep

wait:
	bset	#0,ciaa+cra
.loop:
	btst	#0,ciaa+icr
	beq.s	.loop
	rts

checkdrive:
	bsr	reselect
.checkin:
	btst	#2,inbits
	bne.s	.out

	lea	text2(pc),a1
	bsr	showtext

	bsr	react_user
.out:
	bra	reselect

motoron:
	move.b	#%01111001,outbits
	bclr	#7,selmask
	move.b	selmask(pc),outbits

	move.b	#mili50&$ff,ciaa+talo
	move.b	#mili50/$100,ciaa+tahi

	moveq	#40,d0		;Ewiger Timeout (2000 ms = 2.0 sec)
.wait2:
	bset	#0,ciaa+cra
.wait:
	btst	#0,ciaa+icr
	beq.s	.waiton
	subq.w	#1,d0
	beq.s	.fail
	bra	.wait2
.waiton:
	btst	#5,inbits
	bne	.wait

	move.b	#mili3&$ff,ciaa+talo
	move.b	#mili3/$100,ciaa+tahi
	moveq	#0,d0
	rts		;Zero-flag is set.

.fail:
	move.b	#mili3&$ff,ciaa+talo
	move.b	#mili3/$100,ciaa+tahi
	moveq	#1,d0	;Clear	Zero-flag
	rts

motoroff:
	move.b	#%11111001,outbits
	bset	#7,selmask
	move.b	selmask(pc),outbits
	or.b	#%11111000,selmask
	move.b	selmask(pc),outbits
	rts

seldrive:
	moveq	#0,d5
	move.w	d0,unit_num
	move.w	d0,d5
	addq.w	#3,d0
	move.b	selmask(pc),d7
	or.b	#%01111001,d7
	and.b	#%11111001,d7	;Motorzustand lassen, wie er ist.
	bclr	d0,d7
	move.b	d7,selmask
	move.b	d7,outbits
	rts

reselect:
	move.w	unit_num(pc),d0
	bra	seldrive

unselect:
	or.b	#%01111000,selmask
	move.b	selmask(pc),outbits
	rts

selside:
	lea	side(pc),a0
	move.b	(a0,d5.w),d0
	tst.b	d0
	beq.s	.upper
	bset	#2,selmask
	bra.s	.wait
.upper:
	bclr	#2,selmask
.wait:
	move.b	selmask(pc),outbits
	move.b	#mili50&$ff,ciaa+talo
	move.b	#mili50/$100,ciaa+tahi
	bset	#0,ciaa+cra
.loop:
	btst	#0,ciaa+icr
	beq.s	.loop
	bset	#0,ciaa+cra
.loop2:
	btst	#0,ciaa+icr
	beq.s	.loop2

	move.b	#mili3&$ff,ciaa+talo
	move.b	#mili3/$100,ciaa+tahi

	rts

setup:
	lea	custom,a5
	move.b	ciaa+ddra,d0
	and.b	#%11000011,d0
	move.b	d0,ciaa+ddra
	move.b	#%11111001,outbits
	move.b	#%11111111,ciab+ddrb
	move.b	ciaa+cra,d0
	and.b	#%11000000,d0
	or.b	#%00001000,d0
	move.b	d0,ciaa+cra
	move.b	#%01111111,ciaa+icr

	move.b	#mili3&$ff,ciaa+talo
	move.b	#mili3/$100,ciaa+tahi

	bra	wait

	;Routine checkt ständig alle vier Drives und prüft, ob
	;die geforderte Diskette eingelegt wurde.

react_user:
	move.w	unit_num(pc),d0
	lea	tracknr(pc),a0
	move.b	(a0,d0.w),-(sp)	;Tracknummer, bei der das Laden stehenblieb
	lea	side(pc),a0
	move.b	(a0,d0.w),-(sp)	;Surface, bei der das Laden stehenblieb

	bsr	search_disks	;Alle Disketten aufsuchen.

	clr.l	drive_bits

	;Alle Drives durchsuchen, bei denen Diskchange an ist.
.again:
	move.w	#3,unit_num
	lea	drive_bits(pc),a0
	lea	drive_flags(pc),a1
.loop1:
	move.w	unit_num(pc),d5
	bset	#7,selmask
	tst.b	(a0,d5.w)
	beq.s	.noton
	bclr	#7,selmask
	move.b	#%01111001,outbits
.noton:
	bsr	reselect

	tst.b	(a1,d5.w)		;Valid drive ?
	beq	.nochange

	btst	#2,inbits
	bne.s	.motoroff

	move.b	#%01111001,outbits	;Motor on
	bclr	#7,selmask
	move.b	selmask(pc),outbits	;Probably no Disk inserted.
	st	(a0,d5.w)		;Flag für Motor on setzen.
	bra.s	.nochange

.motoroff:				;A Disk is inserted!
	move.b	#%11111001,outbits	;Motor off
	bset	#7,selmask
	move.b	selmask(pc),outbits
	clr.b	(a0,d5.w)		;Flag für Motor off

.nochange:
	subq.w	#1,unit_num
	bpl	.loop1

	;Nun sind die Motoren der Laufwerke an, in denen keine Diskette ist.
	;Wo der Motor an ist, wird getestet, ob eine Diskette drin ist.

	move.w	#3,unit_num
.loop2:
	move.w	unit_num(pc),d0
	lea	drive_bits(pc),a0
	tst.b	(a0,d0.w)
	beq	.notest

	bclr	#7,selmask
	move.b	#%01111001,outbits

	bsr	reselect
	lea	drive_flags(pc),a0
	tst.b	(a0,d5.w)
	beq	.notest

	btst	#5,inbits
	bne	.notest

	;Anscheinend ist eine Diskette eingelegt. Nachprüfen!

	bsr	waitlong

	bsr	searchone

	lea	drive_disks(pc),a0
	tst.b	(a0,d5.w)
	beq	.notest

	lea	drive_bits(pc),a0
	clr.b	(a0,d5.w)		;Es ist eine Disk drin !

.notest:
	subq.w	#1,unit_num
	bpl	.loop2

	bsr	waitlong

	moveq	#3,d0
	lea	drive_disks(pc),a0
	move.b	disk_num(pc),d1
.loop3:
	cmp.b	(a0,d0.w),d1
	beq	.found
	dbf	d0,.loop3

	bra	.again
.found:
	move.w	d0,-(sp)

	;Alle Motoren wieder Ausschalten.
	move.w	#3,unit_num
.loop4:
	bsr	reselect
	bsr	motoroff
	subq.w	#1,unit_num
	bpl	.loop4

	move.w	(sp)+,d5
	move.w	d5,unit_num

	lea	side(pc),a0
	move.b	(sp)+,(a0,d5.w)	;Surface, bei der das Laden stehenblieb

	move.b	(sp)+,d0	;Tracknummer, bei der das Laden stehenblieb
	bsr	stepto
	bsr	selside
	bsr	resttext
	rts

waitlong:
	moveq	#50,d0
.waitit:
	bsr	wait
	dbf	d0,.waitit
	rts

	;Routine durchsucht alle vier Drives und merkt sich die
	;enthaltenen Disketten.

search_disks:
	clr.w	unit_num
	clr.l	drive_disks
.nextdrive:
	bsr.s	searchone
	addq.w	#1,unit_num
	cmp.w	#4,unit_num
	blt.s	.nextdrive
	clr.w	unit_num
	rts

searchone:
	move.w	unit_num(pc),d5
	lea	drive_flags(pc),a0
	tst.b	(a0,d5.w)
	beq	.nodrive
	bsr	reselect

	lea	tracknr(pc),a0
	tst.b	(a0,d5.w)
	bne.s	.notzero

	moveq	#1,d0
	bsr	stepto
	bra.s	.ok
.notzero:
	bsr	stepin

	moveq	#5,d0		;18 ms Delay
.loop:
	bsr	wait
	dbf	d0,.loop

	bsr	stepout
.ok:
	btst	#2,inbits	;Disk inserted ?
	beq	.nodrive

	move.b	#%01111001,outbits
	bclr	#7,selmask
	move.b	selmask(pc),outbits
	move.l	#$f0000,d0
.waitmotor:
	subq.l	#1,d0
	beq	.nodrive
	btst	#5,inbits
	bne	.waitmotor

	move.l	trkbuffer(pc),a0
	clr.l	(a0)+
	clr.l	(a0)+

	move.w	#$1002,intena(a5)
	move.w	#$8210,dmacon(a5)
	bsr	selside
	move.w	#$7700,adkcon(a5)
	move.w	#0,dsklen(a5)
	move.w	#syncwert,dsksync(a5)
	move.w	#$9500,adkcon(a5)
	move.l	trkbuffer(pc),dskpth(a5)
	move.w	#$8010,dsklen(a5)	;$10 Bytes laden
	move.w	#$8010,dsklen(a5)

	move.l	#$f0000,d0
.waitdma:
	subq.l	#1,d0
	beq	.nodrive
	btst	#1,intreqr+1(a5)
	beq	.waitdma

	move.w	#$1002,intreq(a5)
	move.w	#$4000,dsklen(a5)

	move.l	trkbuffer(pc),a1
	lea	-2(a1),a1
.sync:
	addq.l	#2,a1
	cmp.w	#syncwert,(a1)
	beq	.sync

	lea	drive_disks(pc),a0
	move.w	(a1),d0
	cmp.w	#code1,d0
	bne.s	.nodrive
	move.b	#1,(a0,d5.w)
.nodrive:
	bra	motoroff

get_mem_config:

	;Es sind zwei Erweiterungsspeicher möglich.

	;1. : Fastmem (Anfang über AllocMem, Ende über Ram-check)
	;2. : erweitertes Chipmem (Ende des Chip steht in der Execbase)

	move.l	(Execbase).w,a6
	move.w	$128(a6),d0
	btst	#1,d0
	beq.s	.no_68020
	st	bigcpu_flag
.no_68020
	moveq	#8,d1
	swap	d1
	clr.l	mem_loc_point
	move.l	62(a6),d0
	cmp.l	d1,d0
	ble.s	.nolocmem
	move.l	d1,mem_loc_point
	move.l	d0,mem_loc_end
.nolocmem:

	;Anfang über AllocMem holen.

	moveq	#5,d1
	moveq	#16,d0
	jsr	AllocMem(a6)
	move.l	d0,mem_ext_point
	beq	.noextmem

	moveq	#5,d1
	jsr	AvailMem(a6)
	add.l	mem_ext_point,d0
	move.l	d0,mem_ext_end

;	move.l	d0,a0		;Start
;	lea	$a00000,a1
;	cmp.l	a1,a0
;	bls	.checkmem	;Es ist Golem-Speicher ab $200000!
;	lea	$dc0000,a1
;	cmp.l	a1,a0
;	bls	.checkmem
;	lea	-1.w,a1
;	;bsr.s	.checkmem
;	;rts

;.checkmem:
;	moveq	#0,d0
;	moveq	#0,d1
;	move.w	#$5555,d2
;	move.w	#$aaaa,d3
;.loop:
;	cmp.l	a0,a1
;	bls.s	.memend2
;	move.w	d2,(a0)
;	cmp.w	(a0),d2
;	bne.s	.memend
;	move.w	d3,(a0)
;	cmp.w	(a0),d3
;	bne.s	.memend
;.nextmem:
;	lea	1024(a0),a0
;	bra	.loop
;.memend2:
;	move.l	a1,a0
;.memend:
;	move.l	a0,mem_ext_end
.noextmem:
	rts

setup_config:
	moveq	#0,d0
	bsr	seldrive
	bsr	resetdrive

	move.w	#1,unit_num
	move.l	#$ff000000,drive_flags	;Internes Laufwerk ist immer da.

.nextdrive:
	bsr	reselect

	move.b	#%01111001,outbits
	bclr	#7,selmask
	move.b	selmask,outbits		;Motor on

	move.b	#%11111001,outbits
	bset	#7,selmask
	move.b	selmask,outbits		;Motor off
	bsr	unselect

	moveq	#0,d2		;Longword to read in Drive Type!
	moveq	#31,d6
.loop:
	bsr	reselect
	bsr	wait
	move.b	inbits,d1
	and.b	#%00100000,d1
	ror.b	#5,d1
	lsl.l	#1,d2
	or.b	d1,d2
	bsr	unselect
	bsr	wait

	dbf	d6,.loop

	tst.l	d2
	bne	.nodisk

	bsr	reselect
	bsr	resetdrive

	move.w	unit_num(pc),d0
	lea	drive_flags(pc),a0
	st	(a0,d0.w)		;Dieses Laufwerk ist da!

.nodisk:
	addq.w	#1,unit_num
	cmp.w	#4,unit_num
	blt	.nextdrive
	rts

waitmouse:
	btst	#6,$bfe001
	bne.s	waitmouse
	rts

showtext:
	move.w	#$7ff0,dmacon(a5)

	move.l	trkbuffer(pc),bltdpth(a5)
	move.w	#0,bltdmod(a5)
	move.w	#$0100,bltcon0(a5)
	move.w	#$0000,bltcon1(a5)
	move.w	#$8640,dmacon(a5)

	move.w	#64*10+20,bltsize(a5)
.bwait:
	btst	#14,dmaconr(a5)
	bne	.bwait

	move.l	trkbuffer(pc),a0
	lea	32(a0),a0	;32 Byte Puffer für die REACT_USER-routine
	bsr	print

	lea	messclist1(pc),a0
	move.w	trkbuffer(pc),2(a0)
	move.w	trkbuffer+2(pc),d0
	add.w	#32,d0
	move.w	d0,6(a0)
	move.w	#$0,bpl1mod(a5)

	bsr	waitline

	move.w	#$6281,diwstrt(a5)
	move.w	#$6ac1,diwstop(a5)
	move.w	#$38,ddfstrt(a5)
	move.w	#$d0,ddfstop(a5)
	clr.w	bplcon1(a5)

	move.l	a0,cop1lch(a5)
	clr.w	copjmp1(a5)
	move.w	#$fdf,$182(a5)
	move.w	#$8380,dmacon(a5)
	rts

waitline:
	move.l	$004(a5),d0
	and.l	#$1ff00,d0
	cmp.l	#$02900,d0
	bne.s	waitline
	rts

resttext:
	bsr.s	waitline
	move.w	#$7ff0,dmacon(a5)
	move.w	olddma(pc),dmacon(a5)
	move.l	oldclist(pc),cop1lch(a5)
	clr.w	copjmp1(a5)
	move.w	#0,$180(a5)
	rts

print:
	moveq	#0,d0
	move.b	(a1)+,d0
	bmi.s	.end
	bsr.s	prchar
	lea	1(a0),a0
	bra	print
.end:
	rts

prchar:
	cmp.b	#" ",d0
	beq.s	.space
.doit:
	lea	font(pc),a2
	lea	(a2,d0.w),a2
	move.b	(a2),(a0)
	move.b	44(a2),40(a0)
	move.b	88(a2),80(a0)
	move.b	132(a2),120(a0)
	move.b	176(a2),160(a0)
	move.b	220(a2),200(a0)
	move.b	264(a2),240(a0)
	move.b	308(a2),280(a0)
	rts
.space:
	clr.b	(a0)
	clr.b	40(a0)
	clr.b	80(a0)
	clr.b	120(a0)
	clr.b	160(a0)
	clr.b	200(a0)
	clr.b	240(a0)
	clr.b	280(a0)
	rts

cacrf_cleari	= 8

clear_cash:
	tst.b	bigcpu_flag
	beq.s	.out
	dc.w	$4e7a,$0002	;MOVEC CACR,d0
	tst.w	d0
	bmi	cic_40
	or.w	#cacrf_cleari,d0
	dc.w	$4e7b,$0002	;MOVEC d0,CACR
.out:
	rts
cic_40:
	dc.w	$f4b8		;CPUSH A
	rts

vbiin:
	move.w	#$0020,$dff000+intreq
	jsr	tfmx+36
	rte

	;Filetable enthält Einträge über die möglichen zu ladenden Files.

	;Format :
	;dc.b	Disk	(1/-1)
	;dc.b	Spur
	;dc.b	Kopf
	;dc.b	Adress-nr	(Für gepackte Files)
	;dc.l	Adresse
	;dc.l	Länge
	;dc.l	MemAdr	(0 = noch auf Disk)

	;-----
	;16 Bytes pro Eintrag

filetable:
	dc.b	1	;0:Main (crunched)
	dc.b	21
	dc.b	1
	dc.b	6
	dc.l	$30000	;Wird nach $600 entpackt
	dc.l	trklen*8
	dc.l	0

	dc.b	1	;1: Level5 Prg (crunched)
	dc.b	69
	dc.b	0
	dc.b	3	;Adr nr
	dc.l	$15000	;Wird nach $9100 entpackt
	dc.l	trklen*15
	dc.l	0

	dc.b	1	;2: Level5 Snd
	dc.b	76
	dc.b	1
	dc.b	8	;Adr nr
	dc.l	$2e800
	dc.l	43856
	dc.l	0

	dc.b	1	;3:TFMX
	dc.b	29
	dc.b	1
	dc.b	0	;Adr nr
	dc.l	$6ed20
	dc.l	trklen*2
	dc.l	0

	dc.b	1	;4: Level1 Prg (crunched)
	dc.b	25
	dc.b	1
	dc.b	3	;Adr nr
	dc.l	$18000	;Wird nach $9100 entpackt
	dc.l	trklen*12
	dc.l	0

	dc.b	1	;5: Level1 Snd
	dc.b	31
	dc.b	1
	dc.b	7	;Adr nr
	dc.l	$2d300
	dc.l	50854
	dc.l	0

	dc.b	1	;6: Load Intro (crunched)
	dc.b	1
	dc.b	0
	dc.b	1	;Adr nr
	dc.l	$43000
	dc.l	trklen*2
	dc.l	0

	dc.b	1	;7: Titel (crunched)
	dc.b	2
	dc.b	0
	dc.b	0	;Adr nr
	dc.l	$16500
	dc.l	trklen*21
	dc.l	0

	dc.b	1	;8: Titel sound (crunched)
	dc.b	14
	dc.b	0
	dc.b	4	;Adr nr
	dc.l	$40280
	dc.l	trklen*14
	dc.l	0

	dc.b	1	;9: Level2 Prg (crunched)
	dc.b	35
	dc.b	1
	dc.b	3	;Adr nr
	dc.l	$14100	;Wird nach $9100 entpackt
	dc.l	trklen*13
	dc.l	0

	dc.b	1	;10: Level2 Snd
	dc.b	42
	dc.b	0
	dc.b	8	;Adr nr
	dc.l	$2cdaa
	dc.l	52394
	dc.l	0

	dc.b	1	;11: Loadpic
	dc.b	12
	dc.b	0
	dc.b	5	;Adr nr
	dc.l	$50000
	dc.l	trklen*5
	dc.l	0

	dc.b	1	;12: Level3 Prg (crunched)
	dc.b	46
	dc.b	0
	dc.b	3	;Adr nr
	dc.l	$17200	;Wird nach $9100 entpackt
	dc.l	trklen*12
	dc.l	0

	dc.b	1	;13: Level3 Snd
	dc.b	52
	dc.b	0
	dc.b	8	;Adr nr
	dc.l	$2d6b0
	dc.l	50084
	dc.l	0

	dc.b	1	;14: Level4 Prg (crunched)
	dc.b	56
	dc.b	0
	dc.b	3	;Adr nr
	dc.l	$14500	;Wird nach $9100 entpackt
	dc.l	trklen*15
	dc.l	0

	dc.b	1	;15: Level4 Snd
	dc.b	63
	dc.b	1
	dc.b	8	;Adr nr
	dc.l	$2eb20
	dc.l	44846
	dc.l	0

	dc.b	1	;16: Outro (crunched)
	dc.b	67
	dc.b	0
	dc.b	0	;Adr nr
	dc.l	$14000
	dc.l	trklen*4
	dc.l	0

	dc.b	1	;17: Level5 Snd
	dc.b	75
	dc.b	1
	dc.b	0	;Adr nr
	dc.l	$70200
	dc.l	50408
	dc.l	0

adr_table:	;Originaladressen der gecrunchten Files
	dc.l	$a00		; #0 (Titel/Outro)
	dc.l	$39a54		; #1 (Sprites)
	dc.l	$5b500		; #2 (Score-Zeile)
	dc.l	$9100		; #3 (Level-file)
	dc.l	$3688a		; #4 (Titel-sound)
	dc.l	$40000		; #5 (LoadPic)
	dc.l	$10000		; #6 (Main)
	dc.l	$70110		; #7 (Level-sound I)
	dc.l	$70200		; #8 (Level-sound II-V)

startpointer:	dc.l	0
diskIOlen:	dc.l	0
oldclist:	dc.l	0
trkbuffer:	dc.l	bufferstart

olddma:		dc.w	0

drive_flags:	dc.b	0,0,0,0	;Vier Drives
drive_disks:	dc.b	0,0,0,0
drive_bits:	dc.b	0,0,0,0
side:		dc.b	0,0,0,0
tracknr:	dc.b	0,0,0,0

diskcode:	dc.w	code1	;Erkennung der Disketten Nummer.
unit_num:	dc.w	0
errorcount:	dc.b	0
trycount:	dc.b	0
selmask:	dc.b	0
disk_num:	dc.b	1
start_head:	dc.b	0
start_track:	dc.b	0
file_number:	dc.b	0
act_side:	dc.b	0

mem_loc_end:	dc.l	0
mem_loc_point:	dc.l	0
mem_ext_end:	dc.l	0
mem_ext_point:	dc.l	0
destpointer:	dc.l	0

load_flg:	dc.w	0
act_track:	dc.w	0
bigcpu_flag

text1:	;	"SERIOUS DISKERROR. CLICK MOUSE TO RETRY.",0
	dc.b	18,4,17,8,14,20,18,32,3,8,18,10,4,17,17,14,17,36
	dc.b	2,11,8,2,10,32,12,14,20,18,4,32,19,14,32,17,4,19,17,24,36,-1

text2:	;	"PLEASE INSERT TURRICAN DISK"
	;	" IN ANY DRIVE",0
	dc.b	15,11,4,0,18,4,32,8,13,18,4,17,19,32,19,20,17,17,8,2,0,13,32,3,8,18,10
	dc.b	32,8,13,32,0,13,24,32,3,17,8,21,4,-1

scol1	= $666
scol2	= $888
scol3	= $999
scol4	= $aaa
scol5	= $bbb
scol6	= $ccc
scol7	= $bbb
scol8	= $aaa
scol9	= $999
scol10	= $888
scol11	= $fc0

score	= $4f9a0
status	= $4f400

	even

clist:
	dc.w	$0100,$0000
	dc.w	$ffff,$fffe

	ENDC

	;­­­­­­­­­­­­­­­­­­­­­

	IFNE send=2

init2		= $7f000
loadfile	= $7f004
info		= $7f006
loadfile2	= $7f00a

	dc.l	$6e800
	dc.l	$0

start:
	move.w	#$20,$dff1dc	;Auf PAL schalten.
;	btst	#6,$bfe001
;	beq	.loadall
	jmp	$7e900
.loadall:

	lea	$600,sp
	jsr	init2
	clr.w	($980).w
.loop:
	move.w	#$70a,$dff180			;Farbe zeigt das komplettladen an!
	jsr	info
	lea	-382(a0),a1
	move.w	($980).w,d0
	lea	loadlist(pc),a2
	move.b	(a2,d0.w),d0
	moveq	#0,d1
	move.b	d0,d1
	asl.w	#4,d1
	move.l	8(a1,d1.w),d2
	move.l	32(a0),d3
	sub.l	36(a0),d3
	cmp.l	d3,d2
	blo.s	.load
	move.l	40(a0),d3
	sub.l	44(a0),d3
	cmp.l	d3,d2
	blo.s	.load
	bra	.next
.load:
	moveq	#0,d1
	lea	0.w,a0				;Keine Copperlist!
	jsr	loadfile2
.next:
	addq.w	#1,($980).w
	cmp.w	#load_anz,($980).w
	ble	.loop
	jmp	$7e912

loadlist:
	dc.b	0,1,2,6,4,3,5,11,7,12,18,13,8
	dc.b	19,14,15,9,16,17,10,20
load_anz	= *-loadlist

	ENDC

	;­­­­­­­­­­­­­­­­­­­­­

	IFNE send=3
	dc.l	$6eea0
	dc.l	$0
	INCBIN	work:sources/t3/bitplanes/font.bit
	ENDC

	;­­­­­­­­­­­­­­­­­­­­­

	IFNE send=4
	dc.l	$6ee66
	dc.l	$0

	ORG	$7ee66

	;a6 = Quellbereich
	;a5 = Zielbereich

Decode2:
	move.l	(a6)+,d0	;Header
	move.l	(a6)+,d7	;Länge
	move.l	a5,a4
	add.l	d7,a4		;Endadr
.dc1:
	move.b	(a6)+,d0	;Packbyte
	moveq	#7,d7
.dc2:
	add.b	d0,d0
	bcs.s	.dc3
	move.b	(a6)+,(a5)+
.dc4:
	cmp.l	a5,a4
	bls.s	.dc5
	dbf	d7,.dc2
	bra.s	.dc1
.dc5:
	rts
.dc3:
	move.b	(a6)+,d1
	moveq	#0,d2
	move.b	d1,d2
	asl.w	#4,d2
	move.b	(a6)+,d2
	and.w	#$000f,d1
	addq.w	#2,d1
	move.l	a5,a3
	sub.w	d2,a3
.dc6:
	move.b	(a3)+,(a5)+
	dbf	d1,.dc6
	bra.s	.dc4

	ENDC

	;­­­­­­­­­­­­­­­­­­­­­

	IFNE send=5	;Messclist

	dc.l	$6ee32
	dc.l	$0

	dc.w	$00e0,0
	dc.w	$00e2,0
	dc.w	$0100,$1000
	dc.w	$6007,$fffe
	dc.w	$0180,$088
	dc.w	$6107,$fffe
	dc.w	$0180,$044
	dc.w	$6a07,$fffe
	dc.w	$0100,$0000
	dc.w	$0180,$088
	dc.w	$6b07,$fffe
	dc.w	$0180,$000

	dc.w	$ffff,$fffe
	ENDC

