; This Intro was coded by Garfield/Thrust exept the
; soundtracker-playroutine,which was coded by Karsten Obarski
; all Graphics (Logo,Font,Vumeter) were designed by Knf/Thrust
;
;  lade "bestfontiff"   nach $60000
;  lade "inside"        nach data
;  lade "thrustlogo"    nach $70000
;  lade "vumeter"       nach $73700
; nun mit wi von $40000 $7fff0 speichern
; bytekiller laden,intro laden,offset auf $800
; beide Sprungadressen auf $40000
; warten .............(ha ha) und absaven
; fertig 
; der zu editierende text liegt ab zeile 210
; die tabelle darueber kontrolliert die sonderzeichen
; ich habe sie bestmoeglichst gelegt 
>EXTERN "bestfontiff",$60000
>extern "inside",data
>extern "thrustlogo",$70000
>extern "vumeter",$73700

	org $40000
	load $40000	
g:	
	move.l #start,$80
	trap #0
ede:	
	bsr stop_muzak

	move.l 4,a6
	lea gfxname,a1
	jsr -408(a6)
        move.l d0,a6
	move.l 38(a6),$dff080
        move.l a6,a1
	move.l 4,a6
	jsr -414(a6)

	clr.w	$dff088
	move.w #$8020,$dff096
	rts 

	even
	gfxname:dc.b "graphics.library",0

	even
	rts
start:
	lea doppendaten,a4
	move.l a4,rettme
	move.w #$e9f0,schiftme
	move.w #16,taste

	move.l #$6c000,a0
	move.w #$3000,d0
looping:
	move.b #0,(a0)+	
	move.b d0,$dff180
	dbf d0,looping

	bsr start_muzak


	lea $5f000,a0
	move.w #50,d0;anfangraster	
	move.w #51,d1;enderaster
	move.w #60,d2;x/koordinate	
	move.w #18,d3;anzahl sterne/3
	move.l #schiebtabelle,a4
again:	move.w #1,d4
	move.w #0,d5
	jsr schleif
	move.w #0,d4
	move.w #1,d5
	jsr schleif
	move.w #1,d4
	move.w #1,d5
	jsr schleif
	dbf d3,again
	move.w #$0000,(a0)+	
	move.w #$0000,(a0)+	
	jmp vorbei
schleif:
	move.b d0,(a0)+
	move.b d2,(a0)+
	move.b d1,(a0)+
	move.b #0,(a0)+
	move.w d4,(a0)+
	move.w d5,(a0)+
	move.b (a4)+,d6
	add.b d6,d2
	add.b #2,d0
	add.b #2,d1
	rts

vorbei:
	lea copwriter,a0
	move.w #88,d0
	move.l #$3109fffe,d1
	move.w #$0000,d3
	move.w #$0dc0,d4
	move.w #$01b8,d5
	move.w #$2940,d2
	move.l #$01020000,d6
loop:	move.l d1,(a0)+
	add.l #$01000000,d1	
	move.w #$00e0,(a0)+
	move.w #$0007,(a0)+
	move.w #$00e2,(a0)+
	move.w d3,(a0)+
	add.w #40,d3
	move.w #$00e4,(a0)+
	move.w #$0007,(a0)+
	move.w #$00e6,(a0)+
	move.w d4,(a0)+
	add.w #40,d4
	move.w #$00e8,(a0)+
	move.w #$0007,(a0)+
	move.w #$00ea,(a0)+
	move.w d5,(a0)+
	add.w #40,d5
	move.w #$00ec,(a0)+
	move.w #$0007,(a0)+
	move.w #$00ee,(a0)+
	move.w d2,(a0)+
	add.w #40,d2
	move.l d6,(a0)+
	sub.w #1,d0
	bne loop
	move.l #$8801fffe,(a0)+
	move.l #$01000000,(a0)+
	

	lea newclist2,a1
	move.w #600,d3
schleifen:
	move.w (a1)+,(a0)+
	dbf d3,schleifen
	

	
	move.l #$73708,fuckstartblitt
	move.l #wabbeldaten,a0	

	move.l a0,memory
	move.w #0,countmich
	lea scrolltext,a0
	move.l a0,textretter
	move.l #$60096,blitterquelle
	move.w #%0000000000000000,$dff104
	move.l #newclist,$dff080
	bsr texterrechnung

raster:
	cmp.b	#32,$dff006
	bne	raster

	bsr mover


	add.w #1,rechner
	cmp.w #14,rechner
	bne h
	move.w #1,rechner
	bsr joystick
h:		
	bsr wabbler

	move.l #$7a800,fuckendblitt
	bsr vu1
	bsr vu2
	bsr vu3
	bsr vu4

	add.w #1,countmich	
	move.w taste,d3
	cmp.w countmich,d3
	bne weiter
	move.w #0,countmich
	bsr texterrechnung
	bsr fontblitt
	bsr tastabfrage
weiter:
	bsr scroll

	cmp.w #1,aus
	beq weiter5	 
	bsr coppercabana
	jmp weiter6


weiter5:
	bsr coppercabanaein
weiter6:
	cmp.w #1,doppenein
	bne weiter7

	bsr doppen
weiter7:
	btst #6,$bfe001
	bne raster
	rte


ficktabelle:
	dc.b "abcdefghijklmnopqrstuvwxyzABC"
	dc.b " DEF':.GZIJK1234567890LMNTHRUST"
	even


scrolltext:
dc.b " LLLMMMNNN  THRUST  NNNMMMLLL "   	
dc.b "    presents      new stuff      greetings to all our con"
dc.b "tacts    / attention    DDEE   this intro was programmed by"
dc.b " G garfield G"
dc.b " a new member of thrust    ? you can change scrolling"
dc.b " speed with f1 to f5  also the wabbel speed of the"
dc.b " thrust logo  with the joystick /"
dc.b " AAAAA   greetings to all our contacts"
dc.b " sorry garfield but i am toooo lazy to make some sonder"
dc.b "zeichen so here are our special letters   ? J"
dc.b "   yeah   yeah   "  
dc.b " ABC DEF':GZIJK1234567890LMNTHRUST"
dc.b " garfiel wants to write some special words for the world"
dc.b " in his intro   THRUST  "
dc.b " now garfield is speaking for a second "
dc.b " i left  /     bfbs      ? to join  the mighty thrust "
dc.b "the special garfield greetings only go to my real friends"
dc.b " like  : F zeronine quadlite  lern "
dc.b " mal schoen fuer dein studium  ha ha ha F"
dc.b " I the invisible brains I  K lukullus  dynamo  peter"
dc.b " in cologne K  I bfbs I F solosoft and the rest of"
dc.b " mantronix F I mr.ego I  F tfs sorry that you have to leave" 
dc.b " us F  I unique front I  K unknown of doc hiho K "
dc.b " J knf J  K juergen  thanks for all films man"
dc.b " J the darkside division  i see forward to your new game "
dc.b " and naturally all of thrust especially to"
dc.b " blitter splitter "
dc.b " please contact phil for my adress if you have the newest"
dc.b " modules for the pc engine or if you are able to get infos"
dc.b " about the new sega system "
dc.b " please also get in contact with me if you are a rather "
dc.b " good coder or something like this "
dc.b " okay phil  das wars von meiner seide",0

even







coppercabanaein:
	add.w #1,zaehler32
	cmp.w #32,zaehler32	
	beq ausset2	
	add.w #1,warten
	cmp.w #2,warten
	bne ruck
	bsr einblenden
	move.w #0,warten
	bsr copyein
	rts
ausset2:
	move.w #0,aus
	move.w #0,zaehler32
	move.w #0,warten
	rts
einblenden:
	lea ftab,a1
	lea ftabbackup,a2
	move.w #31,d0
movers:
	move.w (a1),d4
	move.w (a2),d5
	cmp.w d4,d5
	beq jungle 
command:
	add.w #$0111,d4
	move.w d4,(a1)
	add.w #2,a1
	add.w #2,a2
	dbf d0,movers
	rts
jungle:	sub.w #$0111,d4
	jmp command
	rts

	rts
coppercabana:
	add.w #1,zaehler32
	cmp.w #32,zaehler32	
	beq ausset	

	add.w #1,warten
	cmp.w #2,warten
	bne ruck
	bsr ausblenden
	move.w #0,warten
	bsr copyein
ruck:
	rts
ausblenden:
	lea ftab,a1
	move.w #31,d0
int:	move.w (a1),d4
	cmp.w #$0000,(a1)
	beq ja
	sub.w #$0111,d4
	move.w d4,(a1)
	add.w #2,a1

back:	dbf d0,int
	rts
ja:	add.w #$0111,(a1)
	jmp back
	rts
ausset:
	move.w #1,aus
	move.w #0,zaehler32
	move.w #0,warten
	rts
copyein:
	move.w #30,d0
	move.l #copwriter+3534,a5
	lea ftab,a1
schlafen:
	move.w (a1)+,(a5)
	add.l #8,a5
	dbf d0,schlafen
	rts


ftab:
	dc.w $0000,$0111,$0222,$0333,$0444,$0555,$0666,$0777
	dc.w $0888,$0999,$0aaa,$0bbb,$0ccc,$0ddd,$0eee,$0fff
	dc.w $0fff,$0eee,$0ddd,$0ccc,$0bbb,$0aaa,$0999,$0888
	dc.w $0777,$0666,$0555,$0444,$0333,$0222,$0111,$0000
ftabbackup:
	dc.w $0000,$0111,$0222,$0333,$0444,$0555,$0666,$0777
	dc.w $0888,$0999,$0aaa,$0bbb,$0ccc,$0ddd,$0eee,$0fff
	dc.w $0fff,$0eee,$0ddd,$0ccc,$0bbb,$0aaa,$0999,$0888
	dc.w $0777,$0666,$0555,$0444,$0333,$0222,$0111,$0000




doppen:
	cmp.w #1,hoch
	beq runter	
	lea copwriter+3852,a0
	lea copwriter+3876,a1
	move.l rettme,a4
	add.l #2,rettme
	cmp.w #$ffc1,(a0)
	beq hhh
	move.w (a4),d1
	cmp.w #$0a00,d1
	beq phr 
	add.w d1,(a0)
	add.w d1,(a1)
	rts
phr:
	move.w #1,hoch
	lea doppendaten2,a4
	move.l a4,rettme2
	rts
doppendaten:
	dc.w $0000,$0000,$0100,$0100,$0100,$0100,$0100
	dc.w $0200,$0100,$0200,$0200,$0200,$0300,$0200,$0300,$0200
	dc.w $0200,$0300,$0300,$0300,$0300,$0300,$0300,$0400,$0300
	dc.w $0a00
doppendaten2:
	dc.w $0300,$0400,$0300,$0300,$0300,$0300,$0300,$0300,$0200
	dc.w $0200,$0300,$0200,$0300,$0200,$0200,$0200,$0100,$0200
	dc.w $0100,$0100,$0100,$0100,$0100,$0000,$0000
	dc.w $0a00

hhh:
	lea copwriter+3848,a4
	move.l #$ffdffffe,(a4)
	move.w #$01c1,(a0)
	move.w #$01d1,(a1)
	rts
runter:
	lea copwriter+3852,a0
	lea copwriter+3876,a1
	move.l rettme2,a4
	add.l #2,rettme2
	cmp.w #$01c1,(a0)
	beq hh
	move.w (a4),d1
	cmp.w #$0a00,d1
	beq phr2 
	sub.w d1,(a0)
	sub.w d1,(a1)
	rts
hh:
	lea copwriter+3848,a4
	move.l #$dc01ffffe,(a4)
	move.w #$ffc1,(a0)
	move.w #$ffd1,(a1)
	rts
phr2:
	move.w #0,hoch
	lea doppendaten,a4
	move.l a4,rettme
	rts

tastabfrage:
	move.b $bfec01,d1
	not.b d1
	ror.b #1,d1
	cmp.b #$50,d1
	beq sat0
	cmp.b #$51,d1
	beq sat1
	cmp.b #$52,d1
	beq sat2
	cmp.b #$53,d1
	beq sat3
	cmp.b #$54,d1
	beq sat4
	rts
sat0:	
	move.w #32,taste
	move.w #$f9f0,schiftme
	move.b #0,$bfec01
	rts


sat1:	
	move.w #16,taste
	move.w #$e9f0,schiftme
	move.b #0,$bfec01
	rts
sat2:
	move.w #8,taste
	move.w #$c9f0,schiftme
	move.b #0,$bfec01
	rts
sat3:
	move.w #04,taste
	move.w #$89f0,schiftme
	move.b #0,$bfec01
	rts
sat4:
	move.w #$02,taste
	move.w #$09f0,schiftme
	move.b #0,$bfec01
	rts

mover:
	move.l #$5f001,a0
	move.l #spritetabelle,a1
	move.l #60,d0	
star:	move.b (a1)+,d1
	add.b d1,(a0)
	add.l #8,a0
	dbf d0,star
	rts	
spritetabelle:
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
	dc.b 1,2,4,2,1,3,3,4,3,1,5,3,2,4,2,3,5,1,2,4
schiebtabelle:
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111
	dc.b 80,200,40,30,23,66,192,55,171,111



joystick:
	clr.w $dff036
	cmp.w #$0100,$dff00c
	bne dimiter
	cmp.l #2,joytest
	beq dimiter
	sub.l #2,joytest
dimiter:
	clr.w $dff036
	cmp.w #$0001,$dff00c
	bne dimiter2
	cmp.l #10,joytest
	beq dimiter2
	add.l #2,joytest

dimiter2:
	rts	

wabbler:
	move.l memory,a0
	add.l joytest,a0
	move.l a0,memory
	lea copwriter+38,a1
	lea copwriter+10,a2
	lea copwriter+18,a3
	lea copwriter+26,a4
	lea copwriter+34,a5
	move.w #86,d0    ;anzahl der zu verschiebenen rasterlines
	move.w #$0000,d3
	move.w #$0dc0,d4
	move.w #$1b80,d5
	move.w #$2940,d7

interne:
	move.w (a0)+,d1
	cmp.w #$00ff,d1
	beq newset
	move.w d1,d2
	and.w #$000f,d2
	move.w d2,d6
	lsl #4,d2
	add.w d6,d2
	move.w d2,(a1)
	lsr #4,d1
	mulu #2,d1
	add.w #40,d3
	add.w #40,d4
	add.w #40,d5
	add.w #40,d7
	move.w d3,d6
	sub.w d1,d6
	move.w d6,(a2)
	move.w d4,d6
	sub.w d1,d6
	move.w d6,(a3)
	move.w d5,d6
	sub.w d1,d6
	move.w d6,(a4)
	move.w d7,d6
	sub.w d1,d6
	move.w d6,(a5)
	add.l #40,a1
	add.l #40,a2
	add.l #40,a3
	add.l #40,a4
	add.l #40,a5
	dbf d0,interne
	rts	
newset:
	lea wabbeldaten,a0
	move.l a0,memory
	jmp wabbler



suber:
	sub.w #1,allmerker
	cmp.w #0,allmerker
	blt hit
go:	rts	
hit:	move.w #0,allmerker	
	jmp go
garfield:
	move.w allmerker,d4
	and.l #$00ff,d4
	move.l d4,d5
	and.l #$000f,d5
	cmp.l #$0001,d5
	beq newsetiff
	cmp.l #$0003,d5
	beq newsetiff
	cmp.l #$0005,d5
	beq newsetiff
	cmp.l #$0007,d5
	beq newsetiff
	cmp.l #$0009,d5
	beq newsetiff
	cmp.l #$000b,d5
	beq newsetiff
	cmp.l #$000d,d5
	beq newsetiff
	cmp.l #$000f,d5
	beq newsetiff




backfuck:
	lea tabelle,a5
	add.l d4,a5
	move.l (a5),d1
	add.l #$73700,d1
	move.l d1,fuckstartblitt
	rts
newsetiff:
	sub.l #1,d4
	jmp backfuck	
vu1:	move.w merker1,allmerker
	jsr vuall
	move.w allmerker,merker1
	rts
vu2:	move.w merker2,allmerker
	jsr vuall
	move.w allmerker,merker2
	rts
vu3:	move.w merker3,allmerker
	jsr vuall
	move.w allmerker,merker3
	rts
vu4:	move.w merker4,allmerker
	jsr vuall
	move.w allmerker,merker4
	rts

vuall:	jsr suber
	jsr garfield
	jsr blitten
	add.l #$00000a,fuckendblitt
	rts

blitten:
	move.l fuckstartblitt,a4
	move.l fuckendblitt,a5
	bsr allblit
	add.l #$3840,a4
	add.l #$3840,a5
	bsr allblit
	rts

allblit:
	move.w #%0000100111110000,$dff040
	move.w #$0000,$dff042
 	move.w #$ffff,$dff044
	move.w #$ffff,$dff046
	move.l a4,$dff050
	move.l a5,$dff054
	move.w #$0020,$dff064;modulo source
	move.w #$0020,$dff066;modulo ziel
	move.w #%0000110010000100,$dff058;blitterfenster+start
	jsr bbusy
	rts

bbusy:
	btst #14,$dff002
	bne bbusy
	rts
	
texterrechnung:
	move.l #$60098,blitterquelle
	move.l textretter,a0
	move.b (a0)+,d4
	move.l a0,textretter

	cmp.b #$00,d4
	beq neuset
	cmp.b #$2f,d4
	beq neuset10
	cmp.b #$3f,d4
	beq neuset20

hierhinja:
	lea ficktabelle,a1
nochmal:
	move.b (a1)+,d6
	add.w #1,textzaehler
	cmp.b d4,d6
	bne nochmal			 
	move.w textzaehler,d2
	sub.w #1,d2
	divu #10,d2	
	move.w d2,d1
	swap d2
	mulu #4,d2
	add.l d2,blitterquelle
	mulu #7400,d1
	add.l d1,blitterquelle
	move.w #0,textzaehler
backen:	
	rts	
neuset:
	lea scrolltext,a0
	move.l a0,textretter
	move.l #$60098+22200,blitterquelle
	jmp backen
neuset10:
	move.w #1,doppenein
	move.b (a0)+,d4
	move.l a0,textretter

	jmp hierhinja
neuset20:
	move.w #0,doppenein
	move.b (a0)+,d4
	move.l a0,textretter
	jmp hierhinja
fontblitt:
	bsr bbusy
	move.w #$09f0,$dff040
	move.w #$0000,$dff042
	move.l #$ffffffff,$dff044
	move.w #$0024,$dff064
	move.w #$002e,$dff066
	move.l blitterquelle,$dff050
	move.l #$6c02e,$dff054
	move.w #%0010111001000010,$dff058
;                vvvvvvvvvvhhhhhh
	rts
scroll:
	bsr bbusy
	move.w schiftme,$dff040
	move.w #$0000,$dff042
	move.l #$ffffffff,$dff044
	move.w #$0000,$dff064
	move.w #$0000,$dff066
	move.l #$6bffe,$dff050
	move.l #$6bffc,$dff054
	move.w #%0001011100110010,$dff058
;                vvvvvvvvvvhhhhhh   
	rts

tabelle:
	dc.w $0,$8,$10,$18,$20
	dc.w $07d0,$07d8,$07e0,$07e8,$07f0	
	dc.w $0fa0,$0fa8,$0fb0,$0fb8,$0fc0	
	dc.w $1770,$1778,$1780,$1788,$1790
	dc.w $1f40,$1f48,$1f50,$1f58,$1f60	
	dc.w $2710,$2718,$2720,$2728,$2730
	dc.w $2ee0,$2ee8,$2ef0,$2ef8,$2f00
	dc.w $36b0,$36b8,$36c0,$36c8,$36d0

newclist:
	dc.w $0101,$fffe
	dc.w $00f4,$0003
	dc.w $00f6,$0000
	dc.w $0120,$0005
	dc.w $0122,$f000
	dc.w $0124,$0007
	dc.w $0126,$f000
	dc.w $0128,$0007
	dc.w $012a,$f000
	dc.w $012c,$0007
	dc.w $012e,$f000
	dc.w $0130,$0007
	dc.w $0132,$f000
	dc.w $0134,$0007
	dc.w $0136,$f000
	dc.w $0138,$0007
	dc.w $013a,$f000
	dc.w $013c,$0007
	dc.w $013e,$f000
	
	dc.w $01a0,$0888
	dc.w $01a2,$0999
	dc.w $01a4,$0555
	dc.w $01a6,$0fff

	dc.w $3001,$fffe
	dc.w $0092,$0038
	dc.w $0094,$00d0
	dc.w $008e,$2970
	dc.w $0090,$29d0
	dc.w $0108,$0008
	dc.w $010a,$0008
	
	dc.w $0180,$0000
	dc.w $0182,$0c0d
	dc.w $0184,$0e3e
	dc.w $0186,$0f77
	dc.w $0188,$0335
	dc.w $018a,$0446
	dc.w $018c,$0557
	dc.w $018e,$0568
	dc.w $0190,$0669
	dc.w $0192,$0779
	dc.w $0194,$099a
	dc.w $0196,$0aab
	dc.w $0198,$0bbc
	dc.w $019a,$0ccd
	dc.w $019c,$0eee
	dc.w $019e,$0fff
	dc.w $3101,$fffe
	dc.w $0100,$4000
copwriter:	
	blk.b 15000,0

newclist2:
	dc.w $8a07,$fffe
	dc.w $0180,$0000
	dc.w $8b07,$fffe
	dc.w $0180,$0111
	dc.w $8c07,$fffe
	dc.w $0180,$0222
	dc.w $8d07,$fffe
	dc.w $0180,$0333
	dc.w $8e07,$fffe
	dc.w $0180,$0444
	dc.w $8f07,$fffe
	dc.w $0180,$0555
	dc.w $9007,$fffe
	dc.w $0180,$0666
	dc.w $9107,$fffe
	dc.w $0180,$0777
	dc.w $9207,$fffe
	dc.w $0180,$0888
	dc.w $9307,$fffe
	dc.w $0180,$0999
	dc.w $9407,$fffe
	dc.w $0180,$0aaa
	dc.w $9507,$fffe
	dc.w $0180,$0bbb
	dc.w $9607,$fffe
	dc.w $0180,$0ccc
	dc.w $9707,$fffe
	dc.w $0180,$0ddd
	dc.w $9807,$fffe
	dc.w $0180,$0eee
	dc.w $9907,$fffe
	dc.w $0180,$0fff
	dc.w $9a07,$fffe
	dc.w $0180,$0fff
	dc.w $9b07,$fffe
	dc.w $0180,$0eee
	dc.w $9c07,$fffe
	dc.w $0180,$0ddd
	dc.w $9d07,$fffe
	dc.w $0180,$0ccc
	dc.w $9e07,$fffe
	dc.w $0180,$0bbb
	dc.w $9f07,$fffe
	dc.w $0180,$0aaa
	dc.w $a007,$fffe
	dc.w $0180,$0999
	dc.w $a107,$fffe
	dc.w $0180,$0888
	dc.w $a207,$fffe
	dc.w $0180,$0777
	dc.w $a307,$fffe
	dc.w $0180,$0666
	dc.w $a407,$fffe
	dc.w $0180,$0555
	dc.w $a507,$fffe
	dc.w $0180,$0444
	dc.w $a607,$fffe
	dc.w $0180,$0333
	dc.w $a707,$fffe
	dc.w $0180,$0222
	dc.w $a807,$fffe
	dc.w $0180,$0111
	dc.w $a907,$fffe
	dc.w $0180,$0000

	dc.w $aa07,$fffe
	dc.w $008e,$2961
	dc.w $0090,$70d1
	dc.w $0100,$2000
	dc.w $0092,$0038
	dc.w $0094,$00d0
	dc.w $0108,$0000
	dc.w $010a,$0000
	dc.w $00e0,$0007
	dc.w $00e2,$a800
	dc.w $00e4,$0007
	dc.w $00e6,$e040
	dc.w $0180,$0000	
	dc.w $0182,$0aac
	dc.w $0184,$0668
	dc.w $0186,$0ddf

	dc.w $df01,$fffe
	dc.w $dfc1,$fffe
	dc.w $0092,$0028	;  28
	dc.w $0094,$00d8	;  d2 
	dc.w $0108,$00cc	;  9c 
	dc.w $010a,$00cc	;  9c
	dc.w $0100,$5000
	dc.w $dfd1,$fffe
	dc.w $00e0,$0006
	dc.w $00e2,$c000
	dc.w $00e4,$0006
	dc.w $00e6,$c032
	dc.w $00e8,$0006
	dc.w $00ea,$c064
	dc.w $00ec,$0006
	dc.w $00ee,$c096
	dc.w $00f0,$0006
	dc.w $00f2,$c0c8
	dc.w $0180,$0000
	dc.w $0182,$0530
	dc.w $0184,$0641
	dc.w $0186,$0752
	dc.w $0188,$0004
	dc.w $018a,$0015
	dc.w $018c,$0116
	dc.w $018e,$0227
	dc.w $0190,$0338
	dc.w $0192,$0449
	dc.w $0194,$056a
	dc.w $0196,$077b
	dc.w $0198,$099c
	dc.w $019a,$0bbd
	dc.w $019c,$0dde
	dc.w $019e,$0fff
	dc.w $01a0,$0860
	dc.w $01a2,$0972
	dc.w $01a4,$0a84
	dc.w $01a6,$0b97
	dc.w $01a8,$0333
	dc.w $01aa,$0444
	dc.w $01ac,$0555
	dc.w $01ae,$0666
	dc.w $01b0,$0777
	dc.w $01b2,$0888
	dc.w $01b4,$0999
	dc.w $01b6,$0aaa
	dc.w $01b8,$0ccc
	dc.w $01ba,$0ddd
	dc.w $01bc,$0eee
	dc.w $01be,$0fff
	dc.w $ffdf,$fffe
	dc.w $2001,$fffe
	dc.w $0100,$0000

	dc.w $ffff,$fffe


wabbeldaten:
dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dc.w 0,0,0,0,1,1,2,3,3,4,5,7,8,9,11,12,13,15,16,18,20,21,23,24,26,27
dc.w 29,30,31,33,34,35,36,37,37,38,39,39,39,40,40,40,39,39,39,38,37
dc.w 37,36,35,34,33,31,30,29,27,26,24,23,21,20,18,16,15,13,12,11
dc.w 9,8,7,5,4,3,3,2,1,1,0,0,0,0	
dc.w 0,0,0,0,1,1,2,3,3,4,5,7,8,9,11,12,13,15,16,18,20,21,23,24,26,27
dc.w 29,30,31,33,34,35,36,37,37,38,39,39,39,40,40,40,39,39,39,38,37
dc.w 37,36,35,34,33,31,30,29,27,26,24,23,21,20,18,16,15,13,12,11
dc.w 9,8,7,5,4,3,3,2,1,1,0,0,0,0	
dc.w 0,0,0,0,1,1,2,3,3,4,5,7,8,9,11,12,13,15,16,18,20,21,23,24,26,27
dc.w 29,30,31,33,34,35,36,37,37,38,39,39,39,40,40,40,39,39,39,38,37
dc.w 37,36,35,34,33,31,30,29,27,26,24,23,21,20,18,16,15,13,12,11
dc.w 9,8,7,5,4,3,3,2,1,1,0,0,0,0	
dc.w 0,0,0,0,1,1,2,3,3,4,5,7,8,9,11,12,13,15,16,18,20,21,23,24,26,27
dc.w 29,30,31,33,34,35,36,37,37,38,39,39,39,40,40,40,39,39,39,38,37
dc.w 37,36,35,34,33,31,30,29,27,26,24,23,21,20,18,16,15,13,12,11
dc.w 9,8,7,5,4,3,3,2,1,1,0,0,0,0	
dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dc.w $ff

textzaehler:blk.w 1,0
count:	blk.w 1,0
warten5:blk.w 1,0
zaehler32:blk.w 1,0
aus:	blk.w 1,0
doppenein:blk.w 1,0
rettme:	blk.l 1,0
rettme2:blk.l 1,0
hoch:blk.w 1,0
warten:	blk.w 1,0
textretter:blk.l 1,0
taste:	blk.w 1,0
schiftme:blk.w 1,0
retten:	blk.w 1,0
memory:	blk.l 1,0
joytest:blk.l 1,2
rechner:blk.w	1,0
blitterquelle:	blk.l 1,0
countmich:	blk.w 1,0
fuckstartblitt:	blk.l 1,0
fuckendblitt:	blk.l 1,0
stay:		blk.w 1,0
merker1:	blk.w 1,0
merker2:	blk.w 1,0
merker3:	blk.w 1,0
merker4:	blk.w 1,0
allmerker:	blk.w 1,0
ysno:		blk.w 1,0

start_muzak:
	move.l	#data,muzakoffset	;** get offset

init0:	move.l	muzakoffset,a0		;** get highest used pattern
	add.l	#472,a0
	move.l	#$80,d0
	clr.l	d1
init1:	move.l	d1,d2
	subq.w	#1,d0
init2:	move.b	(a0)+,d1
	cmp.b	d2,d1
	bgt.s	init1
	dbf	d0,init2
	addq.b	#1,d2

init3:	move.l	muzakoffset,a0		;** calc samplepointers
	lea	pointers,a1
	mulu	#1024,d2
	add.l	#600,d2
	add.l	a0,d2
	move.l	#15-1,d0
init4:	move.l	d2,(a1)+
	clr.l	d1
	move.w	42(a0),d1
	lsl.l	#1,d1
	add.l	d1,d2
	add.l	#30,a0
	dbf	d0,init4

init5:	move.w	#$0,$dff0a8		;** clear used values
	move.w	#$0,$dff0b8
	move.w	#$0,$dff0c8
	move.w	#$0,$dff0d8
	clr.w	timpos
	clr.l	trkpos
	clr.l	patpos

init6:	move.l	muzakoffset,a0		;** initialize timer irq
	move.b	470(a0),numpat+1	;number of patterns
	move.l	#240,d0
	sub.b	471(a0),d0
	mulu	#122,d0
	move.b	#$0,$bfde00
	move.b	d0,$bfd400
	lsr.w	#8,d0
	move.b	d0,$bfd500
	move.b	#$81,$bfdd00
	move.b	#$11,$bfde00
	move.l	$78,lev6save
	move.l	#lev6interrupt,$78
	rts

stop_muzak:
	move.b	#$1,$bfdd00		;** restore timer & dma
	move.l	lev6save,$78
	move.w	#$0,$dff0a8
	move.w	#$0,$dff0b8
	move.w	#$0,$dff0c8
	move.w	#$0,$dff0d8
	move.w	#$f,$dff096
	rts

lev6interrupt:
	movem.l	d0/d1,-(sp)		;** jump
	bsr	replay_muzak
	move.b	$bfdd00,d0
	move.w	#$2000,$dff09c
	movem.l	(sp)+,d0/d1
	rte

replay_muzak:
	movem.l	d0-d7/a0-a6,-(a7)
	addq.w	#1,timpos
speed:	cmp.w	#6,timpos
	beq	replaystep

chaneleffects:				;** seek effects
	lea	datach0,a6
	tst.b	3(a6)
	beq.s	ceff1
	lea	$dff0a0,a5
	bsr.s	ceff5
ceff1:	lea	datach1,a6
	tst.b	3(a6)
	beq.s	ceff2
	lea	$dff0b0,a5
	bsr.s	ceff5
ceff2:	lea	datach2,a6
	tst.b	3(a6)
	beq.s	ceff3
	lea	$dff0c0,a5
	bsr.s	ceff5
ceff3:	lea	datach3,a6
	tst.b	3(a6)
	beq.s	ceff4
	lea	$dff0d0,a5
	bsr.s	ceff5
ceff4:	movem.l	(a7)+,d0-d7/a0-a6
	rts

ceff5:	move.b	2(a6),d0		;room for some more
	and.b	#$0f,d0			;implementations below
	tst.b	d0
	beq.s	arpreggiato
	cmp.b	#1,d0
	beq	pitchup
	cmp.b	#2,d0
	beq	pitchdown
	cmp.b	#12,d0
	beq	setvol
	cmp.b	#14,d0
	beq	setfilt
	cmp.b	#15,d0
	beq	setspeed
	rts

arpreggiato:				;** spread by time
	cmp.w	#1,timpos
	beq.s	arp1
	cmp.w	#2,timpos
	beq.s	arp2
	cmp.w	#3,timpos
	beq.s	arp3
	cmp.w	#4,timpos
	beq.s	arp1
	cmp.w	#5,timpos
	beq.s	arp2
	rts

arp1:	clr.l	d0			;** get higher note-values
	move.b	3(a6),d0		;   or play original
	lsr.b	#4,d0
	bra.s	arp4
arp2:	clr.l	d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	bra.s	arp4
arp3:	move.w	16(a6),d2
	bra.s	arp6
arp4:	lsl.w	#1,d0
	clr.l	d1
	move.w	16(a6),d1
	lea	notetable,a0
arp5:	move.w	(a0,d0.w),d2
	cmp.w	(a0),d1
	beq.s	arp6
	addq.l	#2,a0
	bra.s	arp5
arp6:	move.w	d2,6(a5)
	rts

pitchdown:
	bsr	newrou
	clr.l	d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	add.w	d0,(a4)
	cmp.w	#$358,(a4)
	bmi.s	ok1
	move.w	#$358,(a4)
ok1:	move.w	(a4),6(a5)
	rts

pitchup:bsr	newrou
	clr.l	d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	sub.w	d0,(a4)
	cmp.w	#$71,(a4)
	bpl.s	ok2
	move.w	#$71,(a4)
ok2:	move.w	(a4),6(a5)
	rts

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

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

setspeed:
	clr.l	d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	move.w	d0,speed+2
	rts

newrou:	cmp.l	#datach0,a6
	bne.s	next1
	lea	voi1,a4
	rts
next1:	cmp.l	#datach1,a6
	bne.s	next2
	lea	voi2,a4
	rts
next2:	cmp.l	#datach2,a6
	bne.s	next3
	lea	voi3,a4
	rts
next3:	lea	voi4,a4
	rts

replaystep:				;** work next pattern-step
	clr.w	timpos
	move.l	muzakoffset,a0
	move.l	a0,a3
	add.l	#12,a3			;ptr to soundprefs
	move.l	a0,a2
	add.l	#472,a2			;ptr to pattern-table
	add.l	#600,a0			;ptr to first pattern
	clr.l	d1
	move.l	trkpos,d0		;get ptr to current pattern
	move.b	(a2,d0),d1
	mulu	#1024,d1
	add.l	patpos,d1		;get ptr to current step
	clr.w	enbits


	bsr stim1
	bsr stim2
	bsr stim3
	bsr stim4

	jmp stmain



stim1:	lea	$dff0a0,a5		;chanel 0
	lea	datach0,a6
	bsr	chanelhandler

	cmp.w #$0001,ysno		
	bne nonew1


	move.w stay,d0	
	cmp.w merker1,d0
	blt nonew1

	move.w stay,merker1

nonew1:
	rts

stim2:	lea	$dff0b0,a5		;chanel 1
	lea	datach1,a6
	bsr	chanelhandler

	cmp.w #$0001,ysno		
	bne nonew2

	move.w stay,d0	
	cmp.w merker3,d0
	blt nonew2

	move.w stay,merker3

nonew2:
	rts

stim3:	lea	$dff0c0,a5		;chanel 2
	lea	datach2,a6
	bsr	chanelhandler


	cmp.w #1,ysno		
	bne nonew3

	move.w stay,d0	
	cmp.w merker4,d0

	move.w stay,merker4


	
nonew3:
	rts


stim4:	lea	$dff0d0,a5		;chanel 3
	lea	datach3,a6
	bsr	chanelhandler

	cmp.w #$0001,ysno	
	bne nonew4

	move.w stay,d0	
	cmp.w merker2,d0
	blt nonew4

	move.w stay,merker2

nonew4:
rts


stmain:	move.l	#400,d0			;** wait a while and set len

rep1:	dbf	d0,rep1			;   of oneshot to 1 word
	move.l	#$8000,d0
	or.w	enbits,d0
	move.w	d0,$dff096
	cmp.w	#1,datach0+14
	bne.s	rep2
	clr.w	datach0+14
	move.w	#1,$dff0a4
rep2:	cmp.w	#1,datach1+14
	bne.s	rep3
	clr.w	datach1+14
	move.w	#1,$dff0b4
rep3:	cmp.w	#1,datach2+14
	bne.s	rep4
	clr.w	datach2+14
	move.w	#1,$dff0c4
rep4:	cmp.w	#1,datach3+14
	bne.s	rep5
	clr.w	datach3+14
	move.w	#1,$dff0d4

rep5:	add.l	#16,patpos		;next step
	cmp.l	#64*16,patpos		;pattern finished ?
	bne	rep6
	clr.l	patpos
	addq.l	#1,trkpos		;next pattern in table
	clr.l	d0
	move.w	numpat,d0
	cmp.l	trkpos,d0		;song finished ?
	bne	rep6
	clr.l	trkpos
rep6:	movem.l	(a7)+,d0-d7/a0-a6
	rts

chanelhandler:
	move.w #0,ysno
	move.l	(a0,d1.l),(a6)		;get period & action-word
	addq.l	#4,d1			;point to next chanel
	clr.l	d2
	move.b	2(a6),d2		;get nibble for soundnumber
	lsr.b	#4,d2
	beq.s	chan2			;no soundchange !
	move.l	d2,d4			;** calc ptr to sample
	lsl.l	#2,d2
	mulu	#30,d4
	lea	pointers-4,a1
	move.l	(a1,d2.l),4(a6)		;store sample-address
	move.w	(a3,d4.l),8(a6)		;store sample-len in words
	move.w	2(a3,d4.l),stay 	;store sample-volume
	sub.w #5,stay
	move.w stay,18(a6)
	move.l	d0,-(a7)
	move.b	2(a6),d0
	and.b	#$0f,d0
	cmp.b	#$0c,d0
	bne.s	ok3
	move.b	3(a6),8(a5)
	bra.s	ok4
ok3:	move.w	2(a3,d4.l),8(a5)	;change chanel-volume


ok4:	move.l	(a7)+,d0
	
	clr.l	d3
	move.w	4(a3,d4),d3		;** calc repeatstart
	add.l	4(a6),d3
	move.l	d3,10(a6)		;store repeatstart
	move.w	6(a3,d4),14(a6)		;store repeatlength
	cmp.w	#1,14(a6)
	beq.s	chan2			;no sustainsound !
	move.l	10(a6),4(a6)		;repstart  = sndstart
	move.w	6(a3,d4),8(a6)		;replength = sndlength
chan2:	cmp.w	#0,(a6)
	beq.s	chan4			;no new note set !
	move.w #1,ysno
	move.w	22(a6),$dff096		;clear dma
	cmp.w	#0,14(a6)
	bne.s	chan3			;no oneshot-sample
	move.w	#1,14(a6)		;allow resume (later)
chan3:	bsr	newrou
	move.w	(a6),(a4)
	move.w	(a6),16(a6)		;save note for effect
	move.l	4(a6),0(a5)		;set samplestart
	move.w	8(a6),4(a5)		;set samplelength
	move.w	(a6),6(a5)		;set period
	move.w	22(a6),d0
	or.w	d0,enbits		;store dma-bit
	move.w	18(a6),20(a6)		;volume trigger
chan4:	rts

datach0:	dc.w	0,0,0,0,0,0,0,0,0,0,0,1
datach1:	dc.w	0,0,0,0,0,0,0,0,0,0,0,2
datach2:	dc.w	0,0,0,0,0,0,0,0,0,0,0,4
datach3:	dc.w	0,0,0,0,0,0,0,0,0,0,0,8
voi1:		dc.w	0
voi2:		dc.w	0
voi3:		dc.w	0
voi4:		dc.w	0
pointers:	dc.l	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
notetable:	dc.w	856,808,762,720,678,640,604,570
		dc.w	538,508,480,453,428,404,381,360
		dc.w	339,320,302,285,269,254,240,226  
		dc.w	214,202,190,180,170,160,151,143
		dc.w	135,127,120,113,000
muzakoffset:	dc.l	0
lev6save:	dc.l	0
trkpos:		dc.l	0
patpos:		dc.l	0
numpat:		dc.w	0
enbits:		dc.w	0
timpos:		dc.w	0
data:		dc.l 100000

