;---------------T-------T-----------------------T-----------------------T


; Source by Genie / The Studio. December 1993.
; Assembled with Trash'm ONE V1.6.

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Switches

test:	equ	0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Constants

bpllen:	equ	44*283

dep_msc:	equ	4
wid_msc:	equ	40
hei_msc:	equ	256

dep_anm:	equ	5
wid_anm:	equ	40
hei_anm:	equ	256

dep_txt:	equ	5
wid_txt:	equ	44
hei_txt:	equ	283

hold_mtxt:	equ	3*50+10
hold_sibanim:	equ	80
hold_glbanim:	equ	40
hold_access:	equ	20*50

patt_sibanim:	equ	0
patt_glbanim:	equ	1
patt_area:	equ	3
patt_bonus:	equ	2
patt_howto:	equ	7
patt_whyto:	equ	48
patt_facis:	equ	29
patt_rules:	equ	12
patt_event:	equ	72
patt_craze:	equ	40
patt_movie:	equ	22
patt_conts:	equ	55
patt_access:	equ	64

col_howto:	equ	$fff
col_whyto:	equ	$ccc
col_facis:	equ	$ccc
col_rules:	equ	$fff
col_event:	equ	$f80
col_craze:	equ	$bdf
col_movie:	equ	$ff0
col_conts:	equ	$484

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Baseregisters

CB:	equr	a4
BR:	equr	a5

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Macros

wblit:	macro
.wb\@:	btst	#6,2(CB)
	bne.s	.wb\@
	endm	

wraslin:	macro
	if	\1>1
	moveq	#\1-1,d3
	endc
.wl\@:	move.b	6(CB),d4
.w\@:	cmp.b	6(CB),d4
	beq.s	.w\@
	if	\1>1
	dbf	d3,.wl\@
	endc
	endm

d_one:	macro
	lsr.l	d4
	bne.s	.get\@
	move.l	-(a0),d4
	roxr.l	d4
.get\@:	mexit
	endm

d_more:	macro
	moveq	#0,\1
.get\@:	lsr.l	d4
	bne.s	.gt\@
	move.l	-(a0),d4
	roxr.l	d4
.gt\@:	roxl.l	\1
	dbf 	d0,.get\@
	endm

copper:	macro
	section	Cop\1,data_c
hi_\1:	equ	$ac-\3/2
lo_\1:	equ	$ac+\3/2
str_\1:	equ	$88-\2*2
stp_\1:	equ	str_\1+\2*4-8
copper_\1:	dc.w	$8e,hi_\1<<8+(str_\1+8)*2
	if	lo_\1>$ff
	dc.w	$90,(lo_\1-$100)<<8+((stp_\1+16)*2)&$ff
	else
	dc.w	$90,((stp_\1+16)*2)&$ff
	endc
	dc.w	$92,str_\1,$94,stp_\1
	dc.w	$120,0,$122,0,$124,0,$126,0,$128,0,$12a,0,$12c,0,$12e,0
	dc.w	$130,0,$132,0,$134,0,$136,0,$138,0,$13a,0,$13c,0,$13e,0
colors_\1:	equ	*+2
	dc.w	$180,0,$182,0
	if	\4>1
	dc.w	$184,0,$186,0
	endc
	if	\4>2
	dc.w	$188,0,$18a,0,$18c,0,$18e,0
	endc
	if	\4>3
	dc.w	$190,0,$192,0,$194,0,$196,0,$198,0,$19a,0,$19c,0,$19e,0
	endc
	if	\4>4
	dc.w	$1a0,0,$1a2,0,$1a4,0,$1a6,0,$1a8,0,$1aa,0,$1ac,0,$1ae,0
	dc.w	$1b0,0,$1b2,0,$1b4,0,$1b6,0,$1b8,0,$1ba,0,$1bc,0,$1be,0
	endc
bpl1pth_\1:	equ	*+2
bpl1ptl_\1:	equ	*+6
	dc.w	$e0,0,$e2,0
	if	\4>1
bpl2pth_\1:	equ	*+2
bpl2ptl_\1:	equ	*+6
	dc.w	$e4,0,$e6,0
	endc
	if	\4>2
bpl3pth_\1:	equ	*+2
bpl3ptl_\1:	equ	*+6
	dc.w	$e8,0,$ea,0
	endc
	if	\4>3
bpl4pth_\1:	equ	*+2
bpl4ptl_\1:	equ	*+6
	dc.w	$ec,0,$ee,0
	endc
	if	\4>4
bpl5pth_\1:	equ	*+2
bpl5ptl_\1:	equ	*+6
	dc.w	$f0,0,$f2,0
	endc
	if	\4>5
bpl6pth_\1:	equ	*+2
bpl6ptl_\1:	equ	*+6
	dc.w	$f4,0,$f6,0
	endc
bplcon0_\1:	equ	*+2
bplcon1_\1:	equ	*+6
	dc.w	$100,\4<<12+$200,$102,0,$104,0
	dc.w	$108,\5,$10a,\5
	if	lo_\1<$100
	dc.l	lo_\1<<24+$07fffe
	dc.w	$100,$200
	endc
	dc.l	-2,-2
	mexit
	endm

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Code

	section	Global,code

s:	basereg	s,BR
	lea	s(pc),BR
	lea	$dff000,CB

	move.l	a7,adr_stack(BR)

	move.l	4.w,a6
	sub.l	a1,a1
	jsr	-294(a6)	;findtask
	move.l	d0,adr_thistask(BR)

	ifeq	test
	move.l	d0,a3
	tst.l	172(a3)	;pr_cli
	bne.s	.fromcli
	lea	92(a3),a0	;pr_msgport
	jsr	-384(a6)	;waitport
	lea	92(a3),a0	;pr_msgport
	jsr	-372(a6)	;getmsg
	move.l	d0,msg_workbench(BR)
.fromcli:	endc

	bsr.w	openlibraries
	bra.s	prepare

adr_stack:	dc.l	0
adr_thistask:	dc.l	0
msg_workbench:	dc.l	0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

prepare:	move.l	adr_copper_msc(BR),a0
	move.l	adr_bpla(BR),d0
	moveq	#wid_msc,d1
	move	d0,bpl1ptl_msc-copper_msc(a0)
	swap	d0
	move	d0,bpl1pth_msc-copper_msc(a0)
	if	dep_msc>1
	swap	d0
	add.l	d1,d0
	move	d0,bpl2ptl_msc-copper_msc(a0)
	swap	d0
	move	d0,bpl2pth_msc-copper_msc(a0)
	endc
	if	dep_msc>2
	swap	d0
	add.l	d1,d0
	move	d0,bpl3ptl_msc-copper_msc(a0)
	swap	d0
	move	d0,bpl3pth_msc-copper_msc(a0)
	endc
	if	dep_msc>3
	swap	d0
	add.l	d1,d0
	move	d0,bpl4ptl_msc-copper_msc(a0)
	swap	d0
	move	d0,bpl4pth_msc-copper_msc(a0)
	endc
	if	dep_msc>4
	swap	d0
	add.l	d1,d0
	move	d0,bpl5ptl_msc-copper_msc(a0)
	swap	d0
	move	d0,bpl5pth_msc-copper_msc(a0)
	endc

	move.l	adr_copper_txt(BR),a0
	move.l	adr_bpla(BR),d0
	move.l	#hei_txt*wid_txt,d1
	move	d0,bpl1ptl_txt-copper_txt(a0)
	swap	d0
	move	d0,bpl1pth_txt-copper_txt(a0)
	if	dep_txt>2
	swap	d0
	add.l	d1,d0
	move	d0,bpl2ptl_txt-copper_txt(a0)
	swap	d0
	move	d0,bpl2pth_txt-copper_txt(a0)
	endc
	if	dep_txt>3
	swap	d0
	add.l	d1,d0
	move	d0,bpl3ptl_txt-copper_txt(a0)
	swap	d0
	move	d0,bpl3pth_txt-copper_txt(a0)
	endc
	if	dep_txt>4
	swap	d0
	add.l	d1,d0
	move	d0,bpl4ptl_txt-copper_txt(a0)
	swap	d0
	move	d0,bpl4pth_txt-copper_txt(a0)
	endc
	if	dep_txt>5
	swap	d0
	add.l	d1,d0
	move	d0,bpl5ptl_txt-copper_txt(a0)
	swap	d0
	move	d0,bpl5pth_txt-copper_txt(a0)
	endc

	lea	window_choice,a0
	bsr.w	openwindow
.choice:	bsr.w	getkey
	cmp	#$45,d0	;escape
	beq.w	quit
	cmp	#$40,d0	;spacebar
	beq.w	full
	bsr.w	getgadget
	cmp	#1,d0
	beq.w	full
	cmp	#2,d0
	beq.b	brief
	bra.b	.choice

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

brief:	bsr.w	closewindow
	lea	window_lang,a0
	bsr.w	openwindow
.choice:	bsr.w	getkey
	cmp	#$45,d0	;escape
	beq.w	quit
	bsr.w	getgadget
	lea	name_duma(BR),a0
	cmp	#1,d0
	beq.b	.prepare
	lea	name_chat(BR),a0
	cmp	#2,d0
	beq.b	.prepare
	bra.b	.choice

.hei:	equ	30	;num of lines
.wid:	equ	150	;gadget width

.gadget:	dc.l	0	;nextgadget
	dc.w	440	;leftedge
.topedge:	dc.w	12	;topedge
	dc.w	.wid,11	;width,height
	dc.w	0,3,1	;flags,activation,gadgettype
	dc.l	render	;gadgetrender
	dc.l	0	;selectrender
.adr_itext:	dc.l	0	;gadgettext
	dc.l	0,0	;mutualexclude,specialinfo
.id:	dc.w	1	;gadgetid
	dc.l	0	;userdata

.itext:	dc.b	1,0	;frontpen,backpen
	dc.b	1,0	;drawmode,kludgefill
.leftedge:	dc.w	0,2	;leftedge,topedge
	dc.l	attr_font	;itextfont
.adr_text:	dc.l	0	;itext
	dc.l	0	;nexttext


.prepare:	bsr.w	closewindow
	bsr.w	load
	move.l	a0,adr_text(BR)
	move.l	d0,len_text(BR)
	bsr.w	freshentext

	move.l	adr_text(BR),a0
	move.l	adr_bpla(BR),a2
	move.l	adr_bplb(BR),a3
	move.l	a0,d7
	add.l	len_text(BR),d7
.searchblock:	cmp.b	#"@",(a0)+
	bne.s	.noblock

	move.l	a0,.adr_text(BR)
	bsr.w	.skipline	;skip gadget name
	move.l	a0,d0
	sub.l	.adr_text(BR),d0
	subq.l	#1,d0
	lsl	#3,d0
	sub	#.wid,d0
	neg	d0
	lsr	d0
	move	d0,.leftedge(BR)
	bsr.w	.skipline	;skip file name

	move.l	a0,(a3)+	;text start
.findeot:	cmp.b	#"@",(a0)+
	beq.s	.eot
	cmp.l	d7,a0
	blo.s	.findeot
.eot:	subq	#1,a0
	move.l	a0,(a3)+	;text end

	lea	.itext-.gadget(a2),a1
	move.l	a1,.adr_itext(BR)
	lea	.prepare-.gadget(a2),a1
	move.l	a1,.gadget(BR)
	lea	.gadget(BR),a1
	moveq	#(.prepare-.gadget)/2-1,d0
.copygadget:	move	(a1)+,(a2)+
	dbf	d0,.copygadget
	addq	#1,.id(BR)
	add	#16,.topedge(BR)
	cmp	#256-12,.topedge(BR)
	bhs.w	quit
	bra.b	.searchblock

.noblock:	cmp.l	d7,a0
	blo.s	.searchblock
.eof:	cmp.l	adr_bpla(BR),a2
	beq.w	quit
	clr.l	-(.prepare-.gadget)(a2)

	lea	window_brief,a0
	bsr.w	openwindow

.ask:	bsr.w	getkey
	cmp	#$45,d0	;escape
	beq.w	quit
	cmp	#$4c,d0
	beq.s	.keyup
	cmp	#$4d,d0
	beq.s	.keydown
	bsr.w	getgadget
	cmp	#$1000,d0
	bne.s	.noup
.keyup:	moveq	#9,d7
.up:	bsr.w	.stepup
	dbf	d7,.up
	bra.s	.ask
.noup:	cmp	#$2000,d0
	bne.s	.nodown
.keydown:	moveq	#9,d7
.down:	bsr.w	.stepdown
	dbf	d7,.down
	bra.s	.ask
.nodown:	cmp	#$3000,d0
	bne.b	.noquit
	bsr.w	.cls
	bra.w	quit
.noquit:	subq	#1,d0
	bmi.b	.ask
	lsl	#3,d0
	move.l	adr_bplb(BR),a0
	move.l	0(a0,d0.w),.beg_txt(BR)
	move.l	4(a0,d0.w),.end_txt(BR)
	move.l	4(a0,d0.w),.dsp_txt(BR)

	bsr.w	.cls
	clr	.pos(BR)
	clr	.lines(BR)
.print:	bsr.w	wras
	move.l	adr_gralib(BR),a6
	move.l	adr_rastport(BR),a1
	moveq	#0,d0
	moveq	#-8,d1
	movem	.scroll(BR),d2-d3/d4-d5
	jsr	-396(a6)	;scrollraster
	move.l	adr_rastport(BR),a1
	movem	.scroll(BR),d0/d1
	addq	#6,d1
	jsr	-240(a6)	;move
	move.l	adr_rastport(BR),a1
	moveq	#2,d0
	jsr	-342(a6)	;setapen
	move.l	.dsp_txt(BR),a0
	subq	#1,a0
.findprev:	tst.b	-(a0)
	bne.s	.findprev
	addq	#1,a0
	move.l	a0,d0
	sub.l	.dsp_txt(BR),d0
	neg.l	d0
	subq.l	#1,d0
	move.l	a0,.dsp_txt(BR)
	move.l	adr_rastport(BR),a1
	jsr	-60(a6)	;text

	addq	#1,.lines(BR)
	move.l	.beg_txt(BR),d0
	cmp.l	.dsp_txt(BR),d0
	blo.s	.print

	move	.lines(BR),d0
	sub	#.hei,d0
	bpl.s	.bigger
	moveq	#0,d0
.bigger:	move	d0,.lines(BR)

	bra.w	.ask

.skipline:	tst.b	(a0)+
	beq.s	.skipped
	cmp.l	d7,a0
	blo.s	.skipline
	subq	#1,a0
.skipped:	rts

.findline:	move.l	.beg_txt(BR),a0
	move.l	.end_txt(BR),d7
	add.l	a0,d7
.find:	subq	#1,d0
	bmi.s	.found
	bsr.s	.skipline
	bra.s	.find
.found:	move.l	a0,a1
	bsr.s	.skipline
	exg	a0,a1
	move.l	a1,d0
	sub.l	a0,d0
	subq.l	#1,d0
	rts

.cls:	moveq	#wid_txt/4-1,d7
.cl:	bsr.w	wras
	move.l	adr_gralib(BR),a6
	move.l	adr_rastport(BR),a1
	moveq	#32,d0
	moveq	#0,d1
	movem	.scroll(BR),d2-d3/d4-d5
	jsr	-396(a6)	;scrollraster
	dbf	d7,.cl
	rts

.stepup:	move	d7,-(a7)
	tst	.pos(BR)
	beq.s	.sux
	bsr.w	wras
	move.l	adr_gralib(BR),a6
	move.l	adr_rastport(BR),a1
	moveq	#0,d0
	moveq	#-8,d1
	movem	.scroll(BR),d2-d3/d4-d5
	jsr	-396(a6)	;scrollraster
	move.l	adr_rastport(BR),a1
	movem	.scroll(BR),d0/d1
	addq	#6,d1
	jsr	-240(a6)	;move
	subq	#1,.pos(BR)
	move	.pos(BR),d0
	bsr.b	.findline
	move.l	adr_rastport(BR),a1
	jsr	-60(a6)	;text
.sux:	move	(a7)+,d7
	rts

.stepdown:	move	d7,-(a7)
	move	.pos(BR),d0
	cmp	.lines(BR),d0
	bhs.s	.sdx
	bsr.w	wras
	move.l	adr_gralib(BR),a6
	move.l	adr_rastport(BR),a1
	moveq	#0,d0
	moveq	#8,d1
	movem	.scroll(BR),d2-d3/d4-d5
	jsr	-396(a6)	;scrollraster
	move.l	adr_rastport(BR),a1
	move	.scroll(BR),d0
	move	.scroll+6(BR),d1
	subq	#1,d1
	jsr	-240(a6)	;move
	addq	#1,.pos(BR)
	move	.pos(BR),d0
	add	#.hei-1,d0
	bsr.w	.findline
	move.l	adr_rastport(BR),a1
	jsr	-60(a6)	;text
.sdx:	move	(a7)+,d7
	rts

.pos:	dc.w	0
.lines:	dc.w	0
.beg_txt:	dc.l	0
.end_txt:	dc.l	0
.dsp_txt:	dc.l	0
.scroll:	dc.w	48,12,wid_txt*8+47,.hei*8+11 ;minx,miny,maxx,maxy

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

full:	bsr.w	closewindow
	lea	window_load,a0
	bsr.w	openwindow

	lea	name_chat(BR),a0	;load text
	bsr.w	load
	move.l	a0,adr_text(BR)
	move.l	d0,len_text(BR)
	bsr.w	freshentext

	lea	name_music(BR),a0	;load music
	bsr.w	loadchip
	move.l	a0,adr_music(BR)
	move.l	d0,len_music(BR)

	lea	name_mfont(BR),a0	;load mfont
	bsr.w	loadfile
	bsr.w	decode_ilbm
	cmp	#dep_msc,iff_depth(BR)
	bne.w	error_ilbm
	move	iff_imagew(BR),wid_mfont(BR)
	move	iff_imagey(BR),hei_mfont(BR)
	cmp	#40,hei_mfont(BR)
	bhi.w	error_ilbm
	lea	iff_palette(BR),a1
	lea	msc_palette(BR),a2
	moveq	#2^dep_msc-1,d0
.copymp:	move	(a1)+,(a2)+
	dbf	d0,.copymp
	move.l	a0,-(a7)
	bsr.w	getifflen
	bsr.w	alloc
	move.l	a0,adr_mfont(BR)
	move.l	d0,len_mfont(BR)
	move.l	(a7)+,a0
	move.l	adr_mfont(BR),a1
	moveq	#dep_msc,d0
	mulu	wid_mfont(BR),d0
	bsr.w	extract_ilbm
	bsr.w	unloadfile

	lea	name_sfont(BR),a0	;load sfont
	bsr.w	loadfile
	bsr.w	decode_ilbm
	cmp	#1,iff_depth(BR)
	bne.w	error_ilbm
	move	iff_imagew(BR),wid_sfont(BR)
	move	iff_imagey(BR),hei_sfont(BR)
	cmp	#20,hei_sfont(BR)
	bhi.w	error_ilbm
	move.l	a0,-(a7)
	bsr.w	getifflen
	bsr.w	alloc
	move.l	a0,adr_sfont(BR)
	move.l	d0,len_sfont(BR)
	move.l	(a7)+,a0
	move.l	adr_sfont(BR),a1
	move	wid_sfont(BR),d0
	bsr.w	extract_ilbm
	bsr.w	unloadfile

	lea	name_sibanim(BR),a0	;load sib anim
	bsr.w	load
	move.l	a0,adr_sibanim(BR)
	move.l	d0,len_sibanim(BR)

	lea	name_january(BR),a0	;load january logo
	bsr.w	load
	move.l	a0,adr_january(BR)
	move.l	d0,len_january(BR)

	bsr.w	sethighpri
	bsr.w	initreplay

main:	bsr.b	sibanim
	bsr.w	january
	bsr.w	meeting
	bsr.b	glbanim
	bsr.w	thearea
	bsr.w	howtogetthere
	bsr.w	whytocome
	bsr.w	facilities
	bsr.w	globalrules
	bsr.w	events
	bsr.w	contest
	bsr.w	fullcraze
	bsr.w	movies
	bsr.w	access
	bra.w	quit

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sibanim:	bsr.w	blankscreen
	moveq	#50,d0
	bsr.w	wait
	lea	adr_sibanim(BR),a2
	move	#hold_sibanim,d0	;hold
	moveq	#patt_sibanim,d1	;pattern
	bsr.w	playanim
	bsr.w	unload
	move	#150,d0
	bsr.w	wait
	lea	iff_palette(BR),a0
	move.l	adr_copper_anm(BR),a1
	lea	colors_anm-copper_anm(a1),a1
	bsr	darken
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

glbanim:	bsr.w	blankscreen
	bsr	clearscreena
	bsr	clearscreenb
	lea	adr_glbanim(BR),a2
	move	#hold_glbanim,d0	;hold
	moveq	#patt_glbanim,d1	;pattern
	bsr.w	playanim
	bsr.w	unload
	moveq	#50,d0
	bsr	wait
	lea	iff_palette(BR),a0
	move.l	adr_copper_anm(BR),a1
	lea	colors_anm-copper_anm(a1),a1
	bsr	darken
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

january:	movem.l	a0-a2/d0,-(a7)
	bsr.w	blankscreen
	bsr.w	clearscreena
	move.l	adr_bpla(BR),d0
	bsr.w	setscreen

	move.l	adr_january(BR),a0
	bsr.w	decode_ilbm
	cmp	#dep_anm,iff_depth(BR)
	bhi.w	error_ilbm
	cmp	#wid_anm,iff_imagew(BR)
	bne.w	error_ilbm
	cmp	#hei_anm,iff_imagey(BR)
	bne.w	error_ilbm
	move.l	adr_bpla(BR),a1
	move	#dep_anm*wid_anm,d0
	bsr.w	extract_ilbm
	lea	adr_january(BR),a2
	bsr.w	unload

	move.l	adr_copper_anm(BR),a2

	lea	colors_anm-copper_anm(a2),a0
	moveq	#2^dep_anm-1,d0
.clrc:	clr	(a0)
	addq	#4,a0
	dbf	d0,.clrc

	move.l	a2,$80(CB)
	clr	$88(CB)

	lea	iff_palette(BR),a0
	lea	colors_anm-copper_anm(a2),a1
	bsr.w	lighten

	move	#hold_mtxt,timer_vblank(BR)

	lea	name_glbanim(BR),a0	;load glob anim
	bsr.w	load
	move.l	a0,adr_glbanim(BR)
	move.l	d0,len_glbanim(BR)

	tst	sign_vblank(BR)
	beq.s	.x
.vwait:	tst	timer_vblank(BR)
	bne.s	.vwait
	lea	iff_palette(BR),a0
	lea	colors_anm-copper_anm(a2),a1
	bsr.w	darken

.x:	movem.l	(a7)+,a0-a2/d0
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

meeting:	lea	head_meeting(BR),a1
	bsr.w	mtext
	bsr.w	fademtext
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

thearea:	moveq	#patt_area,d0
	bsr	startplayer
	lea	head_area(BR),a1
	bsr.w	mtext
	bsr.w	fademtext
	lea	head_earth(BR),a1
	bsr.w	mtext
	bsr.w	fademtext
	lea	head_eur(BR),a1
	bsr.w	mtext
	bsr.w	fademtext
	lea	head_hun(BR),a1
	bsr.w	mtext
	bsr.w	fademtext
	lea	head_bp(BR),a1
	bsr.w	mtext
	bsr.w	fademtext
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

howtogetthere:	lea	name_howto(BR),a0
	lea	head_howto(BR),a1
	moveq	#patt_howto,d1
	move	#col_howto,d2
	bra.w	announce

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

whytocome:	lea	name_whyto(BR),a0
	lea	head_whyto(BR),a1
	moveq	#patt_whyto,d1
	move	#col_whyto,d2
	bra.w	announce

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

facilities:	lea	name_facis(BR),a0
	lea	head_facis(BR),a1
	moveq	#patt_facis,d1
	move	#col_facis,d2
	bra.w	announce

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

globalrules:	lea	name_rules(BR),a0
	lea	head_rules(BR),a1
	moveq	#patt_rules,d1
	move	#col_rules,d2
	bra.w	announce

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

events:	lea	name_event(BR),a0
	lea	head_event(BR),a1
	moveq	#patt_event,d1
	move	#col_event,d2
	bra.w	announce

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

fullcraze:	lea	name_craze(BR),a0
	lea	head_craze(BR),a1
	moveq	#patt_craze,d1
	move	#col_craze,d2
	bra.w	announce

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

contest:	lea	name_conts(BR),a0
	lea	head_conts(BR),a1
	moveq	#patt_conts,d1
	move	#col_conts,d2
	bra.w	announce

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

movies:	lea	name_movie(BR),a0
	lea	head_movie(BR),a1
	moveq	#patt_movie,d1
	move	#col_movie,d2
	bra.w	announce

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

access:	lea	head_finally(BR),a1
	bsr.w	mtext
	lea	name_cred1(BR),a0
	bsr.w	load
	move.l	a0,adr_cred1(BR)
	move.l	d0,len_cred1(BR)
	bsr	fademtext
	lea	head_access(BR),a1
	bsr.w	mtext
	lea	name_cred2(BR),a0
	bsr.w	load
	move.l	a0,adr_cred2(BR)
	move.l	d0,len_cred2(BR)
	lea	name_cred3(BR),a0
	bsr.w	load
	move.l	a0,adr_cred3(BR)
	move.l	d0,len_cred3(BR)
	bsr.w	fademtext

	move.l	adr_copper_txt(BR),a2
	lea	colors_txt-copper_txt(a2),a0
	moveq	#2^dep_txt-1,d0
.clrc:	clr	(a0)
	addq	#4,a0
	dbf	d0,.clrc

	bsr.w	clearscreenb

	moveq	#patt_access,d0
	bsr.w	startplayer

	move.l	a2,$80(CB)
	clr	$88(CB)

.dothat:	move.l	adr_cred1(BR),a0
	bsr.b	.show
	move.l	adr_cred2(BR),a0
	bsr.b	.show
	move.l	adr_cred3(BR),a0
	bsr.b	.show
	bra.s	.dothat

.show:	bsr.w	clearscreena
	bsr.w	decode_ilbm
	cmp	#dep_txt-1,iff_depth(BR)
	bhi.w	error_ilbm
	cmp	#wid_txt,iff_imagew(BR)
	bne.w	error_ilbm
	cmp	#hei_txt,iff_imagey(BR)
	bne.w	error_ilbm
	move.l	adr_bpla(BR),a1
	bsr.w	extract_raw

	lea	iff_palette(BR),a0
	lea	colors_txt-copper_txt(a2),a1
	bsr.w	lighten

	move	#hold_access,timer_vblank(BR)

	tst	sign_vblank(BR)
	beq.s	.x

.vwait:	btst	#2,$16(CB)
	beq.s	.out
	btst	#6,$bfe001
	beq.s	.x
	tst	timer_vblank(BR)
	bne.s	.vwait

.x:	lea	iff_palette(BR),a0
	lea	colors_txt-copper_txt(a2),a1
	bsr.w	darken
	rts

.out:	clr	s_destv(BR)
	lea	iff_palette(BR),a0
	lea	colors_txt-copper_txt(a2),a1
	bsr.w	darken
	tst	sign_vblank(BR)
	beq.w	quit
.wvol:	tst	s_volum(BR)
	bne.s	.wvol
	bra.w	quit

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

announce:	bsr.w	mtext
	bsr.w	loadfile
	bsr.w	fademtext
	bsr.w	standardbg
	bsr.w	doscroller
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

freshentext:	move.b	(a0),d1
;	and	#$7f,d1
	cmp.b	#10,d1
	bne.s	.ncr
	moveq	#0,d1
	bra.s	.nctrl
.ncr:	cmp.b	#32,d1
	bhs.s	.nctrl
	moveq	#" ",d1
.nctrl:	move.b	d1,(a0)+
	subq.l	#1,d0
	bne.s	freshentext
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

mtext:	movem.l	a0-a2/d0-d2,-(a7)
	bsr.w	blankscreen
	bsr.w	clearscreena

	move.l	a1,a0
	moveq	#1,d0
.getlines:	cmp.b	#" ",(a1)
	bne.s	.nospace
	addq	#1,d0
.nospace:	tst.b	(a1)+
	bne.s	.getlines
	mulu	hei_mfont(BR),d0
	sub	#hei_msc,d0
	neg	d0
	lsr	d0
	mulu	#dep_msc*wid_msc,d0
	add.l	adr_bpla(BR),d0
	move.l	d0,a2

.newline:	move.l	a2,-(a7)
	move.l	a0,a1
	moveq	#0,d0
.getlinelen:	move.b	(a1)+,d1
	beq.s	.render
	cmp.b	#" ",d1
	beq.s	.render
	addq	#1,d0
	cmp.b	#"I",d1
	beq.s	.getlinelen
	addq	#3,d0
	bra.s	.getlinelen

.render:	sub	#wid_msc,d0
	neg	d0
	lsr	d0
	add	d0,a2
.drawnext:	move.l	adr_mfont(BR),a1
	moveq	#0,d0
	move.b	(a0)+,d0
	beq.s	.eof
	cmp	#" ",d0
	beq.s	.eol
	sub	#"A",d0
	add	d0,d0
	add	d0,d0
	add	d0,a1
	moveq	#dep_msc,d1
	mulu	hei_mfont(BR),d1
	subq	#1,d1
	move	#dep_msc*wid_msc,d2
	mulu	hei_mfont(BR),d2
	cmp	#("I"-"A")*4,d0
	beq.s	.letteri
.letter:	move.b	(a1),(a2)
	move.b	1(a1),1(a2)
	move.b	2(a1),2(a2)
	move.b	3(a1),3(a2)
	add	wid_mfont(BR),a1
	lea	wid_msc(a2),a2
	dbf	d1,.letter
	sub.l	d2,a2
	addq	#4,a2
	bra.s	.drawnext
.letteri:	move.b	(a1),(a2)
	add	wid_mfont(BR),a1
	lea	wid_msc(a2),a2
	dbf	d1,.letteri
	sub.l	d2,a2
	addq	#1,a2
	bra.s	.drawnext

.eol:	move.l	(a7)+,a2
	move	#dep_msc*wid_msc,d0
	mulu	hei_mfont(BR),d0
	add.l	d0,a2
	bra.w	.newline

.eof:	move.l	(a7)+,a2
	move.l	adr_copper_msc(BR),a1
	move.l	a1,$80(CB)
	clr	$88(CB)

	lea	msc_palette(BR),a0
	lea	colors_msc-copper_msc(a1),a1
	bsr.w	lighten
	move	#hold_mtxt,timer_vblank(BR)
	movem.l	(a7)+,a0-a2/d0-d2
	rts

fademtext:	movem.l	a0-a1,-(a7)
	tst	sign_vblank(BR)
	beq.s	.nvbl
.wait:	tst	timer_vblank(BR)
	bne.s	.wait
.nvbl:	lea	msc_palette(BR),a0
	move.l	adr_copper_msc(BR),a1
	lea	colors_msc-copper_msc(a1),a1
	bsr.w	darken
	movem.l	(a7)+,a0-a1
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

doscroller:	movem.l	a0-a3/d0-d3,-(a7)
	move	d1,.patt(BR)
	move	d2,.color(BR)
	bsr.w	clearscreenb

	move.l	a1,a0
	move.l	adr_text(BR),a1
	move.l	a1,d3
	add.l	len_text(br),d3
.search:	cmp.b	#"@",(a1)+
	beq.s	.try
	cmp.l	d3,a1
	blo.s	.search
	movem.l	(a7)+,a0-a3/d0-d3
	rts

.try:	move.l	a0,a2
	move.l	a1,a3
.compare:	move.b	(a2)+,d1
	beq.s	.match
	cmp.b	(a3)+,d1
	beq.s	.compare
	bra.s	.search
.match:	tst.b	(a3)
	bne.s	.search
	lea	1(a3),a0

	move.l	adr_bplb(BR),a1
	lea	2*wid_txt(a1),a1
.newline:	move.l	a1,-(a7)
.print:	move.b	(a0)+,d0
	cmp.l	d3,a0
	bhs.s	.eof
	and	#$7f,d0
	bne.s	.ncr
	move.l	(a7)+,a1
	move	hei_sfont(BR),d0
	addq	#2,d0
	mulu	#wid_txt,d0
	add.l	d0,a1
	neg.l	d0
	add.l	adr_eplb(BR),d0
	cmp.l	d0,a1
	bls.s	.newline
	move.l	adr_eplb(BR),.limit(BR)
	bra.s	.eoff
.ncr:	cmp	#"@",d0
	beq.s	.eof
	sub	#" ",d0
	move.l	adr_sfont(BR),a2
	add	d0,a2
	move	wid_sfont(BR),d2
	moveq	#wid_txt,d1
	move	hei_sfont(BR),d0
	subq	#1,d0
	move.l	a1,-(a7)
.draw:	move.b	(a2),(a1)
	add	d1,a1
	add	d2,a2
	dbf	d0,.draw
	move.l	(a7)+,a1
	addq	#1,a1
	bra.s	.print

.eof:	move.l	(a7)+,a1
	move	hei_sfont(BR),d0
	mulu	#wid_txt,d0
	add.l	a1,d0
	move.l	d0,.limit(BR)

.eoff:	move.l	.limit(BR),a0
	lea	-wid_txt*hei_txt(a0),a0
	cmp.l	adr_bplb(BR),a0
	bhs.s	.canmove
	move.l	adr_bplb(BR),a0
.canmove:	move.l	a0,.limit(BR)

	move.l	adr_copper_txt(BR),a2
	lea	colors_txt-copper_txt(a2),a0
	moveq	#2^dep_txt-1,d0
.dark:	clr	(a0)
	addq	#4,a0
	dbf	d0,.dark

	lea	iff_palette+2^dep_txt(BR),a0
	moveq	#2^dep_txt/2-1,d0
.fcol:	move	.color(BR),(a0)+
	dbf	d0,.fcol
	st	(a0)

	move.l	adr_bplb(BR),d1
	bsr.b	.setbplp

	move.l	a2,$80(CB)
	clr	$88(CB)

	move	.patt(BR),d0
	bsr.w	startplayer

	lea	iff_palette(BR),a0
	lea	colors_txt-copper_txt(a2),a1
	bsr.w	lighten

	move.b	10(CB),.last(BR)
	move.l	adr_bplb(BR),d0
.scroll:	move.b	10(CB),d1
	sub.b	.last(BR),d1
	move.b	10(CB),.last(BR)
	ext	d1
	muls	#wid_txt,d1
	add.l	d0,d1
	cmp.l	adr_bplb(BR),d1
	bhs.s	.lok
	move.l	adr_bplb(BR),d1
.lok:	cmp.l	.limit(BR),d1
	bls.s	.uok
	move.l	.limit(BR),d1
.uok:	move.l	d1,d0
	bsr.s	.setbplp
	btst	#6,$bfe001
	bne.s	.scroll

	moveq	#patt_bonus,d0
	bsr.w	startplayer

;	clr	s_destv(BR)

	lea	iff_palette(BR),a0
	lea	colors_txt-copper_txt(a2),a1
	bsr.w	darken

;	tst.b	s_speed(BR)
;	beq.s	.x
;	tst.b	sign_vblank(BR)
;	beq.s	.x
;.wfade:	tst	s_volum(BR)
;	bne.s	.wfade

.x:	movem.l	(a7)+,a0-a3/d0-d3
	rts

.setbplp:	if	dep_txt=2
	move	d1,bpl2ptl_txt-copper_txt(a2)
	swap	d1
	move	d1,bpl2pth_txt-copper_txt(a2)
	endc
	if	dep_txt=3
	move	d1,bpl3ptl_txt-copper_txt(a2)
	swap	d1
	move	d1,bpl3pth_txt-copper_txt(a2)
	endc
	if	dep_txt=4
	move	d1,bpl4ptl_txt-copper_txt(a2)
	swap	d1
	move	d1,bpl4pth_txt-copper_txt(a2)
	endc
	if	dep_txt=5
	move	d1,bpl5ptl_txt-copper_txt(a2)
	swap	d1
	move	d1,bpl5pth_txt-copper_txt(a2)
	endc
	if	dep_txt=6
	move	d1,bpl6ptl_txt-copper_txt(a2)
	swap	d1
	move	d1,bpl6pth_txt-copper_txt(a2)
	endc
	rts

.limit:	dc.l	0
.last:	dc.w	0
.patt:	dc.w	0
.color:	dc.w	0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

playanim:	movem.l	a0-a3/d0-d6,-(a7)
	tst.l	(a2)
	beq.w	error_notread
	move.l	(a2),a0

	move	#1,.cnt_frame(BR)
	move	d0,.cnt_hold(BR)
	move	d1,.patt(BR)

	move.l	adr_bpla(BR),a1
	move.l	adr_bplb(BR),a2
	movem.l	a1/a2,.adr_work(BR)

	cmp.l	#"FORM",(a0)+
	bne.w	error_ilbm
	addq	#4,a0
	cmp.l	#"ANIM",(a0)+
	bne.w	error_ilbm

	bsr.w	decode_ilbm
	tst	iff_depth(BR)
	beq.w	error_ilbm
	cmp	#dep_anm,iff_depth(BR)
	bhi.w	error_ilbm
	cmp	#wid_anm*8,iff_imagex(BR)
	bne.w	error_ilbm
	cmp	#hei_anm,iff_imagey(BR)
	bne.w	error_ilbm
	move.l	adr_bpla(BR),a1
	move	#dep_anm*wid_anm,d0
	bsr.w	extract_ilbm
	move.l	adr_bplb(BR),a1
	move	#dep_anm*wid_anm,d0
	bsr.w	extract_ilbm

	add.l	(a0)+,a0
	addq	#1,a0
	move.l	a0,d0
	and	#$fffe,d0
	move.l	d0,a0

	moveq	#60,d0
	divu	iff_rate(BR),d0
	move	d0,.cnt_delay(BR)

	move.l	.adr_disp(BR),d0
	bsr.w	setscreen

	lea	iff_palette(BR),a1
	lea	colors_anm,a2
	moveq	#2^dep_anm-1,d0
.fillp:	move	(a1)+,(a2)
	addq	#4,a2
	dbf	d0,.fillp

	bsr.w	wras
	move.l	adr_copper_anm(BR),$80(CB)
	clr	$88(CB)

	move	.patt(BR),d0
	bsr.w	startplayer

	move	.cnt_hold(BR),d0
	beq.s	.play
	bsr.w	wait

.play:	bsr.b	.showframe
	move	.cnt_frame(BR),d0
	cmp	iff_frames(BR),d0
	blo.s	.play

	movem.l	(a7)+,a0-a3/d0-d6
	rts

.showframe:	cmp.l	#"FORM",(a0)+
	bne.w	error_ilbm
	addq	#4,a0
	cmp.l	#"ILBM",(a0)+
	bne.w	error_ilbm
.finddelta:	cmp.l	#"ANHD",(a0)
	bne.s	.noanhd
	addq	#4,a0
	cmp.b	#5,4(a0)	;?
	bne.w	error_ilbm
	add.l	(a0)+,a0
	bra.s	.finddelta
.noanhd:	cmp.l	#"DLTA",(a0)+
	beq.s	.framefound
	add.l	(a0)+,a0
	bra.s	.showframe

.framefound:	move.l	.adr_work(BR),a2

	moveq	#0,d0
	move	#dep_anm*wid_anm,d1
	move	iff_depth(BR),d2
	subq	#1,d2
.nextplane:	;move.l	a2,-(a7)
	move	iff_imagew(BR),d3
	subq	#1,d3
	lea	4(a0),a1
	move.l	(a1,d0),d4
	beq.s	.noplane
	add.l	d4,a1
.nextbyte:	move.l	a2,a3
	moveq	#0,d4
	move.b	(a1)+,d4
	beq.s	.nochange
	subq	#1,d4
.nextcmd:	moveq	#0,d5
	move.b	(a1)+,d5
	beq.s	.packed
	bmi.s	.unpacked
	mulu	d1,d5
	add.l	d5,a3
	bra.s	.goon

.packed:	move.b	(a1)+,d5
	subq	#1,d5
	move.b	(a1)+,d6
.fill:	move.b	d6,(a3)
	add	d1,a3
	dbf	d5,.fill
	bra.s	.goon

.unpacked:	and	#$7f,d5
	subq	#1,d5
.copy:	move.b	(a1)+,(a3)
	add	d1,a3
	dbf	d5,.copy

.goon:	dbf	d4,.nextcmd

.nochange:	addq	#1,a2
	dbf	d3,.nextbyte
.noplane:	;move.l	(a7)+,a2
	;lea	wid(a2),a2
	addq	#4,d0
	dbf	d2,.nextplane

	move	.cnt_delay(BR),d0
	bsr.w	wait

	movem.l	.adr_work(BR),a1-a2
	exg	a1,a2
	movem.l	a1-a2,.adr_work(BR)
	move.l	a2,d0
	bsr.b	setscreen

	add.l	(a0)+,a0
	addq	#1,a0
	move.l	a0,d0
	and	#$fffe,d0
	move.l	d0,a0

	addq	#1,.cnt_frame(BR)
	rts

.patt:	dc.w	0
.adr_work:	dc.l	0
.adr_disp:	dc.l	0
.cnt_frame:	dc.w	0
.cnt_hold:	dc.w	0
.cnt_delay:	dc.w	0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

setscreen:	movem.l	a1/d1,-(a7)
	move.l	adr_copper_anm(BR),a1
	moveq	#wid_anm,d1
	move	d0,bpl1ptl_anm-copper_anm(a1)
	swap	d0
	move	d0,bpl1pth_anm-copper_anm(a1)
	if	dep_anm>1
	swap	d0
	add.l	d1,d0
	move	d0,bpl2ptl_anm-copper_anm(a1)
	swap	d0
	move	d0,bpl2pth_anm-copper_anm(a1)
	endc
	if	dep_anm>2
	swap	d0
	add.l	d1,d0
	move	d0,bpl3ptl_anm-copper_anm(a1)
	swap	d0
	move	d0,bpl3pth_anm-copper_anm(a1)
	endc
	if	dep_anm>3
	swap	d0
	add.l	d1,d0
	move	d0,bpl4ptl_anm-copper_anm(a1)
	swap	d0
	move	d0,bpl4pth_anm-copper_anm(a1)
	endc
	if	dep_anm>4
	swap	d0
	add.l	d1,d0
	move	d0,bpl5ptl_anm-copper_anm(a1)
	swap	d0
	move	d0,bpl5pth_anm-copper_anm(a1)
	endc
	movem.l	(a7)+,a1/d1
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

standardbg:	movem.l	a0-a2,-(a7)
	bsr.b	decode_ilbm
	cmp	#dep_txt-1,iff_depth(BR)
	bne.w	error_ilbm
	cmp	#wid_txt,iff_imagew(BR)
	bne.w	error_ilbm
	cmp	#hei_txt,iff_imagey(BR)
	bne.w	error_ilbm
	move.l	adr_bpla(BR),a1
	bsr.w	extract_raw
	bsr.w	unloadfile
	movem.l	(a7)+,a0-a2
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

; input:	a0 as the pointer to the ILBM file
; result:	a0 pointing at the BODY chunk
;	all parameters set

decode_ilbm:	movem.l	a1-a2/d0-d2,-(a7)
	clr	iff_depth(BR)
	clr	iff_grabx(BR)
	clr	iff_graby(BR)
	clr	iff_frames(BR)
	move	#30,iff_rate(BR)

	cmp.l	#"FORM",(a0)+
	bne.w	.x
	addq	#4,a0
	cmp.l	#"ILBM",(a0)+
	bne.w	.x
	bra.s	.srch

.next:	add.l	(a0)+,a0
	move.l	a0,d0
	addq.l	#1,d0
	and	#$fffe,d0
	move.l	d0,a0

.srch:	moveq	#0,d0

	cmp.l	#"BMHD",(a0)
	bne.s	.nobmhd
	addq	#4,a0
	move	4(a0),iff_imagex(BR)	;horizontal image size
	move	6(a0),iff_imagey(BR)	;vertical image size
	move.b	12(a0),d0
	move	d0,iff_depth(BR)	;depth
	move.b	14(a0),d0
	move	d0,iff_compr(BR)	;compression mode
	move.b	16(a0),d0
	move	d0,iff_aspectx(BR)	;horizontal pixel aspect
	move.b	17(a0),d0
	move	d0,iff_aspecty(BR)	;vertical pixel aspect
	move	20(a0),iff_screenx(BR)
	move	22(a0),iff_screeny(BR)

	move	iff_imagex(BR),d0
	add	#15,d0
	lsr	#4,d0
	add	d0,d0
	move	d0,iff_imagew(BR)	;image width (in bytes)
	bra.s	.next

.nobmhd:	cmp.l	#"GRAB",(a0)
	bne.s	.nograb
	addq	#4,a0
	move	4(a0),iff_grabx(BR)	;horizontal grab position
	move	6(a0),iff_graby(BR)	;vertical grab position
	bra.s	.next

.nograb:	cmp.l	#"CMAP",(a0)
	bne.s	.nocmap
	addq	#4,a0
	lea	4(a0),a1
	lea	iff_palette(BR),a2
	move.l	(a0),d0
	divu	#3,d0
	moveq	#31,d1
.sc:	moveq	#0,d2
	move.b	(a1),d2
	lsl	#4,d2
	move.b	2(a1),d2
	lsr.b	#4,d2
	or.b	1(a1),d2
	move	d2,(a2)+
	addq	#3,a1
	subq	#1,d0
	dbeq	d1,.sc
	st	(a2)
	bra.w	.next

.nocmap:	cmp.l	#"DPAN",(a0)
	bne.s	.nodpan
	addq	#4,a0
	move	6(a0),iff_frames(BR)	;number of anim frames
	move.b	8(a0),d0
	move	d0,iff_rate(BR)	;framerate
	bra.w	.next

.nodpan:	cmp.l	#"BODY",(a0)+
	bne.w	.next

.x:	movem.l	(a7)+,a1-a2/d0-d2
	tst	iff_depth(BR)
	beq.w	error_ilbm
	rts


iff_compr:	dc.w	0
iff_depth:	dc.w	0
iff_imagey:	dc.w	0
iff_imagex:	dc.w	0
iff_screeny:	dc.w	0
iff_screenx:	dc.w	0
iff_aspectx:	dc.w	0
iff_aspecty:	dc.w	0
iff_grabx:	dc.w	0
iff_graby:	dc.w	0
iff_imagew:	dc.w	0
iff_frames:	dc.w	0
iff_rate:	dc.w	0
iff_palette:	blk.w	32,0
	dc.w	-1

getifflen:	move	iff_imagey(BR),d0
	mulu	iff_imagew(BR),d0
	mulu	iff_depth(BR),d0
	rts

extract_ilbm:	movem.l	a0-a2/d0-d5,-(a7)
	addq	#4,a0
	move.l	d0,d5

	tst	iff_compr(BR)
	bne.s	.frozen

	move	iff_imagew(BR),d0
	lsr	d0
	mulu	iff_depth(BR),d0
	subq	#1,d0
	move	iff_imagey(BR),d1
	subq	#1,d1
.nextlin:	move.l	a1,a2
	move	d0,d2
.copyline:	move	(a0)+,(a2)+
	dbf	d2,.copyline
	add	d5,a1
	dbf	d1,.nextlin
	bra.s	.x

.frozen:	cmp	#1,iff_compr(BR)
	bne.w	error_ilbm

	move	iff_imagey(BR),d1 ;height
	subq	#1,d1
.nextline:	move.l	a1,a2
	move	iff_depth(BR),d2
	subq	#1,d2
.nextplane:	move	iff_imagew(BR),d3 ;width
.nextcode:	moveq	#0,d0
	move.b	(a0)+,d0
	bmi.s	.packed
.copy:	move.b	(a0)+,(a2)+
	subq	#1,d3
	beq.s	.eol
	dbf	d0,.copy
	bra.s	.nextcode
.packed:	neg.b	d0
	move.b	(a0)+,d4
.fill:	move.b	d4,(a2)+
	subq	#1,d3
	beq.s	.eol
	dbf	d0,.fill
	bra.s	.nextcode
.eol:	dbf	d2,.nextplane
	add	d5,a1
	dbf	d1,.nextline

.x:	movem.l	(a7)+,a0-a2/d0-d5
	rts

extract_raw:	movem.l	a0-a2/d0-d5,-(a7)
	addq	#4,a0

	move	iff_imagey(BR),d5
	subq	#1,d5
	mulu	iff_imagew(BR),d5

	tst	iff_compr(BR)
	bne.s	.frozen

	move	iff_imagey(BR),d0
	subq	#1,d0
.nxtlin:	move	iff_depth(BR),d1
	subq	#1,d1
	move.l	a1,a2
.nxtpln:	move	iff_imagew(BR),d2
	lsr	d2
	subq	#1,d2
.copyline:	move	(a0)+,(a2)+
	dbf	d2,.copyline
	add.l	d5,a2
	dbf	d1,.nxtpln
	add	iff_imagew(BR),a1
	dbf	d0,.nxtlin
	bra.s	.x

.frozen:	cmp	#1,iff_compr(BR)
	bne.w	error_ilbm

	move	iff_imagey(BR),d1 ;height
	subq	#1,d1
.nextline:	move.l	a1,a2
	move	iff_depth(BR),d2
	subq	#1,d2
.nextplane:	move	iff_imagew(BR),d3 ;width

.nextcode:	moveq	#0,d0
	move.b	(a0)+,d0
	bmi.s	.packed
.copy:	move.b	(a0)+,(a2)+
	subq	#1,d3
	beq.s	.eol
	dbf	d0,.copy
	bra.s	.nextcode
.packed:	neg.b	d0
	move.b	(a0)+,d4
.fill:	move.b	d4,(a2)+
	subq	#1,d3
	beq.s	.eol
	dbf	d0,.fill
	bra.s	.nextcode

.eol:	add.l	d5,a2
	dbf	d2,.nextplane
	add	iff_imagew(BR),a1
	dbf	d1,.nextline

.x:	movem.l	(a7)+,a0-a2/d0-d5
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

wait:	bsr.b	wras
	subq	#1,d0
	bne.s	wait
	rts

wras:	move.l	d0,-(a7)
.wr:	move.l	4(CB),d0
	lsr.l	#8,d0
	and	#$1ff,d0
	cmp	#$130,d0
	bne.s	.wr
.wra:	move.l	4(CB),d0
	lsr.l	#8,d0
	and	#$1ff,d0
	cmp	#$130,d0
	beq.s	.wra
	move.l	(a7)+,d0
	rts

	rem
wras:	movem.l	a0-a1/d0-d1,-(a7)
	move.l	adr_gralib(BR),a6
	jsr	-270(a6)	;waittof
	movem.l	(a7)+,a0-a1/d0-d1
	rts
	endrem

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

blankscreen:	move.l	#copper_blk,$80(CB)
	clr	$88(CB)
	rts

clearscreena:	movem.l	a0-a1/d0-d7,-(a7)
	move.l	adr_bpla(BR),a0
	move.l	adr_epla(BR),a1
	bsr.b	clearscreen
	movem.l	(a7)+,a0-a1/d0-d7
	rts

clearscreenb:	movem.l	a0-a1/d0-d7,-(a7)
	move.l	adr_bplb(BR),a0
	move.l	adr_eplb(BR),a1
	bsr.b	clearscreen
	movem.l	(a7)+,a0-a1/d0-d7
	rts

clearscreen:	movem.l	.empty(BR),d0-d7
.clr:	movem.l	d0-d7,-(a1)
	cmp.l	a0,a1
	bhs.s	.clr
	rts

.empty:	blk.l	8,0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

lighten:	move	#$fff,d0
.lighten:	bsr.w	wras
	sub	#$101,d0
	bsr.b	setc
	bsr.w	wras
	sub	#$010,d0
	bsr.b	setc
	tst	d0
	bne.s	.lighten
	rts

darken:	moveq	#0,d0
.darken:	bsr.w	wras
	add	#$101,d0
	bsr.b	setc
	bsr.w	wras
	add	#$010,d0
	bsr.b	setc
	cmp	#$fff,d0
	bne.s	.darken
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

setc:	movem.l	a0-a1/d0-d3,-(a7)
.do:	move	(a0)+,d1
	bpl.s	.0
	movem.l	(a7)+,a0-a1/d0-d3
	rts
.0:	move	d0,d2
	;bpl.s	.s0
	;not	d1
.s0:	move	d1,d3
	and	#$0ff,d1
	and	#$f00,d2
	and	#$f00,d3
	sub	d2,d3
	blo.s	.1
	or	d3,d1
.1:	move	d0,d2
	move	d1,d3
	and	#$f0f,d1
	and	#$0f0,d2
	and	#$0f0,d3
	sub	d2,d3
	blo.s	.2
	or	d3,d1
.2:	move	d0,d2
	move	d1,d3
	and	#$ff0,d1
	and	#$00f,d2
	and	#$00f,d3
	sub	d2,d3
	blo.s	.3
	or	d3,d1
.3:	;tst	d0
	;bpl.s	.s1
	;not	d1
.s1:	move	d1,(a1)
	addq	#4,a1
	bra.s	.do

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

startplayer:	sf	s_speed(BR)
	move	#$f,$96(CB)
	clr	$a8(CB)
	clr	$b8(CB)
	clr	$c8(CB)
	clr	$d8(CB)
	tst	d0
	bmi.s	.x
	move.b	d0,s_posit(BR)
	sf	s_ptpos(BR)
	sf	s_count(BR)
	sf	s_ptdel(BR)
	sf	s_newpt(BR)
	sf	s_soffs(BR)
	move	#64,s_volum(BR)
	move	#64,s_destv(BR)
	move.b	#5,s_timer(BR)
	move.b	#6,s_speed(BR)
.x:	rts

initreplay:	move.l	adr_music(BR),a0
	move.l	a0,a1
	move	(a0)+,d0
	move.l	a0,s_slist(BR)
	lsl	#3,d0
	add	d0,a0
	move.l	a0,s_plist(BR)
	moveq	#0,d0
.0:	move.b	(a0),d1
	and	#$7f,d1
	cmp	d0,d1
	ble.s	.1
	move.b	d1,d0
.1:	tst.b	(a0)+
	bpl.s	.0
	addq	#1,a0
	move.l	a0,d1
	and	#$fffe,d1
	move.l	d1,a0
	move.l	a0,s_poffs(BR)
	addq	#1,d0
	lsl	#3,d0
	add	d0,a0
	move	(a0),d0
	add.l	d0,a0
	lea	s_smpls(BR),a2
	move	(a1)+,d0
	subq	#1,d0
.2:	move.l	a0,(a2)+
	moveq	#0,d1
	move	(a1),d1
	add.l	d1,d1
	add.l	d1,a0
	addq	#8,a1
	dbf	d0,.2

	sf	s_speed(BR)
	move.b	#%1111,s_cstat(BR)	;all channels on

	or.b	#2,$bfe001	;reset filter
	bra.w	installvblank

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sethighpri:	move.l	4.w,a6
	move.l	adr_thistask(BR),a1
	moveq	#127,d0
	jsr	-300(a6)	;settaskpri
	rts

setnormpri:	move.l	4.w,a6
	move.l	adr_thistask(BR),a1
	moveq	#0,d0
	jsr	-300(a6)	;settaskpri
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

openlibraries:	move.l	4.w,a6
	lea	name_doslib(BR),a1
	moveq	#34,d0
	jsr	-552(a6)	;openlib
	move.l	d0,adr_doslib(BR)
	beq.w	quit
	lea	name_intlib(BR),a1
	moveq	#34,d0
	jsr	-552(a6)	;openlib
	move.l	d0,adr_intlib(BR)
	beq.w	quit
	lea	name_gralib(BR),a1
	moveq	#34,d0
	jsr	-552(a6)	;openlib
	move.l	d0,adr_gralib(BR)
	beq.w	quit
	rts

closelibraries:	move.l	4.w,a6
	move.l	adr_doslib(BR),d0
	beq.s	.ndos
	move.l	d0,a1
	jsr	-414(a6)	;closelib
.ndos:	move.l	adr_intlib(BR),d0
	beq.s	.nint
	move.l	d0,a1
	jsr	-414(a6)	;closelib
.nint:	move.l	adr_gralib(BR),d0
	beq.s	.nreq
	move.l	d0,a1
	jsr	-414(a6)	;closelib
.nreq:	rts

name_doslib:	dc.b	"dos.library",0
name_intlib:	dc.b	"intuition.library",0
name_gralib:	dc.b	"graphics.library",0
	even

adr_doslib:	dc.l	0
adr_intlib:	dc.l	0
adr_gralib:	dc.l	0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	rem
opendevice:	move.l	4.w,a6
	lea	name_condev(BR),a0
	lea	io_request(BR),a1
	moveq	#-1,d0
	moveq	#0,d1
	jsr	-444(a6)	;opendevice
	tst.l	d0
	bne.w	quit
	rts

closedevice:	move.l	4.w,a6
	tst.l	adr_condev(BR)
	beq.s	.x
	lea	io_request(BR),a1
	jsr	-450(a6)	;closedevice
	clr.l	adr_condev(BR)
.x:	rts

io_request:	ds.l	5
adr_condev:	dc.l	0
	ds.l	2

name_condev:	dc.b	"console.device",0
	even
	endrem

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

openwindow:	movem.l	a0-a1/d0-a1,-(a7)
	tst.l	adr_window(BR)
	bne.s	.x
	move.l	adr_intlib(BR),a6
	move.l	56(a6),30(a0) ;wbscreen
	jsr	-204(a6)	;openwindow
	move.l	d0,adr_window(BR)
	beq.w	quit
	move.l	d0,a0
	move.l	86(a0),adr_windowport(BR) ;keyport
	move.l	50(a0),adr_rastport(BR)
.x:	movem.l	(a7)+,a0-a1/d0-a1
	rts

closewindow:	movem.l	a0-a1/d0-a1,-(a7)
	move.l	adr_intlib(BR),a6
	move.l	adr_window(BR),d0
	beq.s	.x
	move.l	d0,a0
	jsr	-72(a6)	;closewindow
	clr.l	adr_window(BR)
	clr.l	adr_windowport(BR)
	clr.l	adr_rastport(BR)
.x:	movem.l	(a7)+,a0-a1/d0-a1
	rts

adr_window:	dc.l	0
adr_windowport:	dc.l	0
adr_rastport:	dc.l	0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

getkey:	movem.l	a0-a2/d1,-(a7)

	clr	key_rawcode(BR)
	move.l	4.w,a6
	move.l	adr_windowport(BR),a0
	jsr	-384(a6)	;waitport
	move.l	adr_windowport(BR),a0
	jsr	-372(a6)	;getmsg
	tst.l	d0
	beq.s	.x
	move.l	d0,a1
	btst	#2,22(a1)	;message type
	beq.b	.norawkey
	btst	#7,25(a1)	;release
	bne.b	.norawkey
	move	24(a1),key_rawcode(BR)
	move	26(a1),key_qualifier(BR)
	move.l	28(a1),key_iaddress(BR)
.norawkey:	jsr	-378(a6)	;replymsg

.x:	movem.l	(a7)+,a0-a2/d1
	move	key_rawcode(BR),d0
	rts

key_rawcode:	dc.w	0
key_qualifier:	dc.w	0
key_iaddress:	dc.l	0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

getgadget:	movem.l	a0-a1/d1,-(a7)

	clr	gadget_id(BR)
	move.l	4.w,a6
	move.l	adr_windowport(BR),a0
	jsr	-384(a6)	;waitport
	move.l	adr_windowport(BR),a0
	jsr	-372(a6)	;getmsg
	tst.l	d0
	beq.s	.x
	move.l	d0,a1
	btst	#6,23(a1)
	beq.s	.nogadget
	move.l	28(a1),a0
	move.l	a0,gadget_address(BR)
	move	38(a0),gadget_id(BR)
.nogadget:	jsr	-378(a6)	;replymsg

.x:	movem.l	(a7)+,a0-a1/d1
	move	gadget_id(BR),d0
	rts

gadget_id:	dc.w	0
gadget_address:	dc.l	0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

installvblank:	movem.l	a0-a1/d0-d1,-(a7)
	tst	sign_vblank(BR)
	bne.s	.x
	move.l	4.w,a6
	lea	server_vblank(BR),a1
	moveq	#5,d0
	jsr	-168(a6)	;addintserver
	st	sign_vblank(BR)
.x:	movem.l	(a7)+,a0-a1/d0-d1
	rts

removevblank:	movem.l	a0-a1/d0-d1,-(a7)
	tst	sign_vblank(BR)
	beq.s	.x
	move.l	4.w,a6
	lea	server_vblank(BR),a1
	moveq	#5,d0
	jsr	-174(a6)	;remintserver
	sf	sign_vblank(BR)
	move	#$f,$96(CB)
	clr	$a8(CB)
	clr	$b8(CB)
	clr	$c8(CB)
	clr	$d8(CB)
.x:	movem.l	(a7)+,a0-a1/d0-d1
	rts

sign_vblank:	dc.w	0
timer_vblank:	dc.w	0

server_vblank:	dc.l	0,0
	dc.b	2,5
	dc.l	.name,0
	dc.l	code_vblank
.name:	dc.b	"Global.server",0
	even


; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

alloc:	movem.l	d1/a1,-(a7)
	move.l	4.w,a6
	move.l	d0,-(a7)
	move.l	#$10001,d1
	jsr	-198(a6)	;allocmem
	tst.l	d0
	beq.w	error_memory
	move.l	d0,a0
	move.l	(a7)+,d0
.x:	movem.l	(a7)+,d1/a1
	rts

unloadfile:	lea	adr_file(BR),a2
unload:	movem.l	a0-a1/d0-d1,-(a7)
	move.l	4.w,a6
	move.l	(a2),a1
	move.l	4(a2),d0
	beq.s	.x
	jsr	-210(a6)	;freemem
	clr.l	(a2)
	clr.l	4(a2)
.x:	movem.l	(a7)+,a0-a1/d0-d1
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

load:	moveq	#1,d0
	bsr.b	readfile
	beq.w	error_read
	bmi.w	error_memory
	rts

loadchip:	moveq	#2,d0
	bsr.b	readfile
	beq.w	error_read
	bmi.w	error_memory
	rts

loadfile:	tst.l	adr_file(BR)
	bne.w	error_alloc
	moveq	#1,d0
	bsr.b	readfile
	beq.w	error_read
	bmi.w	error_memory
	move.l	a0,adr_file(BR)
	move.l	d0,len_file(BR)
	rts

readfile:	movem.l	a1/d1-d7,-(a7)
	move.l	d0,.memtype(BR)

	moveq	#64,d4	;safety
	moveq	#0,d5	;fileaccess
	moveq	#0,d6	;addr
	moveq	#0,d7	;length

	move.l	adr_doslib(BR),a6
	move.l	a0,d1
	move.l	#1005,d2
	jsr	-30(a6)	;open
	move.l	d0,d5
	beq.b	.xnotread

	lea	.long(BR),a0
	moveq	#4,d0
	bsr.b	.read

	cmp.l	#"PP20",(a0)
	beq.w	.pp20

	moveq	#0,d2 ; offs
	moveq	#1,d3 ; end
	bsr.b	.seek
	moveq	#-1,d3 ; beg
	bsr.b	.seek
;	addq.l	#1,d0
;	and	#$fffe,d0 ;even
	move.l	d0,d7

	bsr.s	.alloc
	move.l	d6,a0
	move.l	d7,d0
	bsr.b	.read
	bsr.b	.close

.x:	move.l	d6,a0 ;adr
	move.l	d7,d0 ;len
	movem.l	(a7)+,a1/d1-d7
	tst.l	d0
	rts

.read:	movem.l	a0-a1/d1-d3,-(a7)
	move.l	adr_doslib(BR),a6
	move.l	d5,d1
	move.l	a0,d2
	move.l	d0,d3
	jsr	-42(a6)	;read
	cmp.l	d3,d0
	bne.s	.readerror
	movem.l	(a7)+,a0-a1/d1-d3
	rts
.readerror:	movem.l	(a7)+,a0-a1/d1-d3
	addq	#4,a7
	bsr.b	.free
	bsr.b	.close
.xnotread:	movem.l	(a7)+,a1/d1-d7
	sub.l	a0,a0
	moveq	#0,d0
	rts

.seek:	movem.l	a0-a1/d1,-(a7)
	move.l	adr_doslib(BR),a6
	move.l	d5,d1
	jsr	-66(a6)	;seek
	movem.l	(a7)+,a0-a1/d1
	rts

.alloc:	movem.l	a0-a1/d0-d1,-(a7)
	move.l	4.w,a6
	move.l	.memtype(BR),d1
	jsr	-198(a6)	;allocmem
	move.l	d0,d6
	beq.b	.nomem
	movem.l	(a7)+,a0-a1/d0-d1
	rts
.nomem:	movem.l	(a7)+,a0-a1/d0-d1
	addq	#4,a7
	bsr.b	.close
	movem.l	(a7)+,a1/d1-d7
	sub.l	a0,a0
	moveq	#-1,d0
	rts

.close:	movem.l	a0-a1/d0-d1,-(a7)
	move.l	adr_doslib(BR),a6
	move.l	d5,d1
	beq.s	.nclose
	jsr	-36(a6)	;close
	moveq	#0,d5
.nclose:	movem.l	(a7)+,a0-a1/d0-d1
	rts

.free:	tst.l	d6
	beq.s	.nfree
	move.l	4.w,a6
	move.l	d6,a1
	move.l	d7,d0
	jsr	-210(a6)	;freemem
	moveq	#0,d6
	moveq	#0,d7
.nfree:	rts

.pp20:	moveq	#-4,d2 ; offs
	moveq	#1,d3 ; end
	bsr.b	.seek

	lea	.long(BR),a0
	moveq	#4,d0
	bsr.w	.read

	move.l	(a0),d7
	lsr.l	#8,d7
	add.l	d4,d7
	and	#$fffe,d7

	move.l	d7,d0
	moveq	#2,d1
	bsr.b	.alloc

	moveq	#4,d2 ;offs
	moveq	#-1,d3 ; beg
	bsr.w	.seek
	move.l	d0,d3

	lea	.long(BR),a0
	moveq	#4,d0
	bsr.w	.read

	move.l	d6,a0
	move.l	d3,d0
	subq.l	#8,d0
	bsr.w	.read
	bsr.b	.close

	add.l	d0,a0	;source addr (end)
	move.l	d6,a1	;target addr (beg)
	add.l	d4,a1
	move.l	.long(BR),d0	;bitsequence lengths
	bsr.b	decrunch

	move.l	4.w,a6
	jsr	-132(a6)	;forbid
	move.l	d6,a1
	move.l	d7,d0
	jsr	-210(a6)	;freemem
	add.l	d4,d6
	sub.l	d4,d7
	move.l	d6,a1
	move.l	d7,d0
	jsr	-204(a6)	;allocabs
	jsr	-138(a6)	;permit

	bra.w	.x

.memtype:	dc.l	0
.long:	dc.l	0


; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

; decrunches powerpacked file
; uses	a0 as the end address of sourcefile
;	a1 as the start address of destination
;	d0 as the bitsequence lengths

decrunch:	movem.l	d0-d4/a0-a2,-(a7)
	move.l	d0,.bits(BR)
	move.l	a1,a2
	moveq	#1,d4
	move.l	-(a0),d1
	tst.b	d1
	beq.s	.zero
	d_one
	subq	#1,d1
	lsr.l	d1,d4
.zero:	lsr.l	#8,d1
	add.l	d1,a2

.nextsign:	d_one
	bcs.s	.packed

	moveq	#0,d2
.getunplen:	moveq	#0,d1
	d_one
	roxl.l	d1
	d_one
	roxl.l	d1
	add	d1,d2
	subq	#3,d1
	beq.s	.getunplen
.movebytes:	moveq	#7,d0
	d_more	d1
	move.b	d1,-(a2)
	dbf 	d2,.movebytes
	cmp.l	a2,a1
	bcs.s	.packed
	bra.w	.x

.bits:	dc.l	0

.packed:	moveq	#0,d1
	d_one
	roxl.l	d1
	d_one
	roxl.l	d1
	moveq	#0,d0
	move.b	.bits(pc,d1.w),d0
	move	d1,d2
	subq	#3,d1
	bne.s	.getdist
	d_one
	bcs.s	.usebitseq
	moveq	#7,d0
.usebitseq:	subq	#1,d0
	d_more	d3
.getpcklen:	moveq	#0,d1
	d_one
	roxl.l	d1
	d_one
	roxl.l	d1
	d_one
	roxl.l	d1
	add	d1,d2
	subq	#7,d1
	beq.s	.getpcklen
	bra.s	.dodepack
.getdist:	subq	#1,d0
	d_more	d3
.dodepack:	addq	#1,d2
.copyblock:	move.b	(a2,d3.w),-(a2)
	dbf 	d2,.copyblock
	cmp.l	a2,a1
	bcs.w	.nextsign

.x:	movem.l	(a7)+,d0-d4/a0-a2
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

writeout:	movem.l	a0-a1/d0-d3,-(a7)
	move.l	a0,a1
.searchend:	tst.b	(a1)+
	bne.s	.searchend
	move.l	a0,d2
	move.l	a1,d3
	sub.l	a0,d3
	subq.l	#1,d3
	move.l	adr_doslib(BR),a6
	ifeq	test
	jsr	-60(a6)	;output
	jsr	-48(a6)	;write
	endc
	movem.l	(a7)+,a0-a1/d0-d3
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

error_ilbm:	lea	errt_ilbm(BR),a0
	bsr.b	writeout
	bra.b	quit

error_read:	lea	errt_read(BR),a0
	bsr.b	writeout
	bra.b	quit

error_notread:	lea	errt_notread(BR),a0
	bsr.b	writeout
	bra.b	quit

error_memory:	lea	errt_memory(BR),a0
	bsr.b	writeout
	bra.b	quit

error_alloc:	lea	errt_alloc(BR),a0
	bsr.b	writeout
;	bra.b	quit

quit:	bsr.w	removevblank

	lea	allocations(BR),a2
.freeall:	bsr.w	unload
	addq	#8,a2
	tst.l	(a2)
	bpl.s	.freeall

	ifeq	test
	tst.l	msg_workbench(BR)
	beq.s	.fromcli

	jsr	-132(a6)	;forbid
	move.l	msg_workbench(BR),a1
	jsr	-378(a6)	;replymsg

.fromcli:	endc

	move.l	adr_gralib(BR),d0
	beq.s	.ngra
	bsr.w	wras
	move.l	d0,a0
	move.l	38(a0),$80(CB)
	clr	$88(CB)

.ngra:	bsr.w	setnormpri
	bsr.w	closewindow
	bsr.w	closelibraries

	move.l	adr_stack(BR),a7
	moveq	#0,d0
	rts

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

s_saveregs:	reg	a0-a2/BR/CB/d0-d7
code_vblank:	movem.l	s_saveregs,-(a7)
	lea	s(pc),BR
	lea	$dff000,CB

	tst	timer_vblank(BR)
	beq.s	.notiming
	subq	#1,timer_vblank(BR)

.notiming:	move.b	s_speed(BR),d0
	beq.w	.off
	addq.b	#1,s_timer(BR)
	cmp.b	s_timer(BR),d0
	bne.w	.notime
	sf	s_timer(BR)
	tst.b	s_ptdel(BR)
	beq.s	.ndel
	subq.b	#1,s_ptdel(BR)
	bra.w	.notime
.ndel:	subq.b	#1,s_count(BR)
	bpl.w	.nonewpattern
	move.b	s_ptpos(BR),s_count(BR)
	eor.b	#63,s_count(BR)
	moveq	#0,d0
	move.b	s_posit(BR),d0
	move.l	s_plist(BR),a0
	tst.b	s_newpt(BR)
	beq.s	.nonew
	tst.b	(a0,d0.w)
	bpl.s	.setpt
	moveq	#-1,d0
	tst.b	s_shots(BR)
	beq.s	.setpt
	subq.b	#1,s_shots(BR)
	beq.w	.off
.setpt:	addq	#1,d0
	move.b	d0,s_posit(BR)
.nonew:	st	s_newpt(BR)
	move.b	(a0,d0.w),d1
	and	#$7f,d1
	lsl	#3,d1
	move.l	s_poffs(BR),a0
	add	d1,a0
	lea	.chan(BR),a1
	moveq	#3,d2
.findchan:	move.l	a0,a2
	moveq	#0,d1
	move	(a0)+,d1
	add.l	d1,a2
	move.b	s_ptpos(BR),d0
	addq.b	#1,d0
.findnext:	subq.b	#1,d0
	beq.s	.posfound
	move	(a2)+,d1
	and	#$f800,d1
	cmp	#$4000,d1
	bne.s	.nosound
	move	(a2),d1
	and	#$7800,d1
	cmp	#$4000,d1
	beq.s	.findnext
	btst	#0,(a2)
	beq.s	.findnext
	addq	#2,a2
	bra.s	.findnext
.nosound:	cmp	#$c000,d1
	bne.s	.findnext
	move.b	-1(a2),d1
	sub.b	d1,d0
	bgt.s	.findnext
	neg.b	d0
.posfound:	move.l	a2,(a1)
	move.b	d0,._pse(a1)
	lea	.clen(a1),a1
	dbf	d2,.findchan
	sf	s_ptpos(BR)

.nonewpattern:	lea	.chan(BR),a0
	moveq	#0,d6
	moveq	#3,d7
.channels:	clr	._efx(a0)
	tst.b	._pse(a0)
	beq.s	.nodel
	subq.b	#1,._pse(a0)
	bra.s	.nextc

.nodel:	move.l	._act(a0),a1
	move	(a1)+,d0
.pcmd:	move	d0,d1
	move.l	a1,(a0)
	and	#$f800,d0
	and	#$07ff,d1
	rol	#6,d0
	lea	.table(pc,d0.w),a1
	add	(a1),a1
	jsr	(a1)
	move.l	._act(a0),a1
	move	(a1)+,d0
	move	d0,d1
	and	#$7800,d1
	cmp	#$4000,d1 ;sound
	beq.s	.nextc
	btst	#8,d0
	beq.s	.nextc
	and	#$feff,d0
	bra.s	.pcmd

.nextc:	lea	.clen(a0),a0
	lsr	#1,d6
	dbf	d7,.channels
	bra.w	.playsound

.table:	dr.w	.arp	;arpeggio	+  0
	dr.w	.pup	;portamento up	+  1
	dr.w	.pdw	;portamento down	+  2
	dr.w	.tpt	;tone-portamento	+  3
	dr.w	.vib	;vibrato	+  4
	dr.w	.tvs	;tonep+volslide	+  5
	dr.w	.vvs	;vibra+volslide	+  6
	dr.w	.trm	;tremolo	+  7
	dr.w	.snd	;sound	+ (8)
	dr.w	.sof	;sampleoffset	+  9
	dr.w	.vsl	;volumeslide	+  A
	dr.w	.jmp	;position jump	+  B
	dr.w	.vol	;set volume	+  C
	dr.w	.brk	;patternbreak	+  D
	dr.w	.ssn	;stop sound	+ (E)
	dr.w	.spd	;set speed	+  F
	dr.w	.flt	;set filter status	+  E0
	dr.w	.fsu	;fineslide up	+  E1
	dr.w	.fsd	;fineslide down	+  E2
	dr.w	.ret	;glissando control	-  E3
	dr.w	.vbc	;vibrato control	+  E4
	dr.w	.sft	;set finetune	+  E5
	dr.w	.lop	;pattern loop	+  E6
	dr.w	.trc	;tremolo control	+  E7
	dr.w	.pse	;pause	+ (E8)
	dr.w	.rtg	;retrig note	+  E9
	dr.w	.fvu	;finevol up	+  EA
	dr.w	.fvd	;finevol down	+  EB
	dr.w	.cut	;notecut	+  EC
	dr.w	.ndl	;notedelay	+  ED
	dr.w	.del	;patterndelay	+  EE
	dr.w	.ret	;invert loop	-  EF

.ret:	rts

.pse:	move.b	d1,._pse(a0)	;pause
	rts

.spd:	cmp	#31,d1
	bhi.s	.tmp
	move.b	d1,s_speed(BR)	;set speed
.tmp:	rts

.flt:	;move	d1,sign_player(BR)	;set sign
	rts

.jmp:	move.b	d1,s_posit(BR)	;position jump
	sf	s_count(BR)
	sf	s_newpt(BR)
	rts

.brk:	move	d1,d0	;break pattern
	lsr	#4,d1
	mulu	#10,d1
	and	#$f,d0
	add	d0,d1
	move.b	d1,s_ptpos(BR)
	sf	s_count(BR)
	rts

.del:	move.b	d1,s_ptdel(BR)	;pattern delay
	rts

.lop:	and	#$f,d1	;pattern loop
	bne.s	.lops
	move.b	s_count(BR),._plp(a0)
	eor.b	#63,._plp(a0)
	rts
.lops:	tst.b	._plc(a0)
	bne.s	.lopc
	move.b	d1,._plc(a0)
	bra.s	.lopj
.lopc:	subq.b	#1,._plc(a0)
	bne.s	.lopj
	sf	._plp(a0)
	rts
.lopj:	move.b	._plp(a0),s_ptpos(BR)
	sf	s_count(BR)
	sf	s_newpt(BR)
	rts

.sof:	ext.l	d1	;set sampleoffset
	beq.s	.sof1
	move.b	d1,s_soffs(BR)
.sof1:	move.b	s_soffs(BR),d1
	lsl	#7,d1
	sub	d1,._len(a0)
	bhi.s	.sof2
	move	#1,._len(a0)
	rts
.sof2:	add	d1,d1
	add.l	d1,._adr(a0)
	rts	

.vol:	move	d1,._vol(a0)	;set volume
	rts

.vvs:	move	#.evvs-.noefx,._efx(a0)
	bra.s	.asl

.tvs:	move	#.etvs-.noefx,._efx(a0)
	bra.s	.asl

.vsl:	move	#.evsl-.noefx,._efx(a0)

.asl:	move	d1,d0	;set volume slide
	and	#$f,d0
	lsr	#4,d1
	bne.s	.vsl0
	neg	d0
	move	d0,d1
.vsl0:	move	d1,._pr1(a0)
	rts

.fvd:	neg	d1	;finevol down
.fvu:	move	d1,._pr1(a0)	;finevol up
	add	._vol(a0),d1
	bpl.s	.fvl0
	moveq	#0,d1
.fvl0:	cmp	#64,d1
	ble.s	.fvl1
	moveq	#64,d1
.fvl1:	move	d1,._vol(a0)
	move	#.efvl-.noefx,._efx(a0)
	rts

.pup:	neg	d1	;set portamento up
.pdw:	move	d1,._pr1(a0)	;set portamento down
	move	#.epsl-.noefx,._efx(a0)
	rts

.fsu:	neg	d1	;fine slide up
.fsd:	move	d1,._pr1(a0)	;fine slide down
	add	._per(a0),d1
	cmp	#113,d1
	bge.s	.fsl0
	moveq	#113,d1
.fsl0:	cmp	#856,d1
	ble.s	.fsl1
	move	#856,d1
.fsl1:	move	d1,._per(a0)
	move	#.efsl-.noefx,._efx(a0)
	rts

.tpt:	cmp	#$10,d6	;toneportamento
	blo.s	.tpt0
	and	#$f,d6
	move	._opr(a0),d0
	move	._per(a0),._opr(a0)
	move	d0,._per(a0)
.tpt0:	tst	d1
	beq.s	.tptx
	move	d1,._tps(a0)
.tptx:	move	#.etpt-.noefx,._efx(a0)
	rts

.vib:	move	d1,d0	;vibrato
	beq.s	.vibx
	and	#$f,d0
	beq.s	.vib0
	move	d0,._vba(a0)
.vib0:	lsr	#2,d1
	and	#$3c,d1
	beq.s	.vib1
	move.b	d1,._vbs(a0)
.vib1:	btst	#2,._vbc(a0)
	bne.s	.vibx
	sf	._vbp(a0)
.vibx:	move	#.evib-.noefx,._efx(a0)
	rts

.vbc:	move.b	d1,._vbc(a0)	;vibrato control
	rts

.trm:	move	d1,d0	;tremolo
	beq.s	.trmx
	and	#$f,d0
	beq.s	.trm0
	move	d0,._tra(a0)
.trm0:	lsr	#2,d1
	and	#$3c,d1
	beq.s	.trm1
	move.b	d1,._trs(a0)
.trm1:	btst	#2,._trc(a0)
	bne.s	.trmx
	sf	._trp(a0)
.trmx:	move	#.etrm-.noefx,._efx(a0)
	rts

.trc:	move.b	d1,._trc(a0)	;tremolo control
	rts

.arp:	lea	.period(BR),a2	;arpeggio
	move	d1,d0
	lsr	#4,d0
	and	#$f,d1
	add	d0,d0
	add	d1,d1
	moveq	#0,d2
	move.b	._lnt(a0),d2
	add	d2,d2
	add	d2,d0
	add	d2,d1
	move	(a2,d0.w),d0
	move	(a2,d1.w),d1
	move	(a2,d2.w),d2
	sub	d2,d0
	sub	d2,d1
	move	d0,._pr0(a0)
	move	d1,._pr1(a0)
	clr	._pr2(a0)
	move	#.earp-.noefx,._efx(a0)
	rts

.ndl:	btst	#4,d6	;notedelay
	beq.s	.ndlx
	and	#$f,d6
	move	d1,._pr1(a0)
	move	#.endl-.noefx,._efx(a0)
.ndlx:	rts

.rtg:	subq	#1,d1	;retrig note
	bmi.s	.rtgx
	move	d1,._pr1(a0)
	move	d1,._pr2(a0)
	move	#.ertg-.noefx,._efx(a0)
.rtgx:	rts

.cut:	move	d1,._pr1(a0)	;notecut
	move	#.ecut-.noefx,._efx(a0)
	rts

.ssn:	move	#1,._len(a0)	;stop sound
	clr	._vol(a0)
	or	#$10,d6
	rts

.snd:	move	d1,d0	;generate sound
	and	#$1f,d1
	bne.s	.snd2
	move.b	._lsm(a0),d1
	lsl	#2,d1
	lea	s_smpls(BR),a1
	move.l	(a1,d1.w),._adr(a0)
	add	d1,d1
	move.l	s_slist(BR),a1
	add	d1,a1
	bra.s	.snd3
.snd2:	subq	#1,d1
	move.b	d1,._lsm(a0)
	lsl	#2,d1
	lea	s_smpls(BR),a1
	move.l	(a1,d1.w),._adr(a0)
	add	d1,d1
	move.l	s_slist(BR),a1
	add	d1,a1
	move	(a1),._len(a0)
	move.b	3(a1),._vol+1(a0)
	moveq	#0,d1
	move	4(a1),d1
	add.l	d1,d1
	add.l	._adr(a0),d1
	move.l	d1,._rad(a0)
	move	6(a1),._rln(a0)
.snd3:	moveq	#0,d1
	move.b	2(a1),d1
	lsr	#5,d0	;pitch
	cmp	#36,d0
	bhs.s	.snd1
	move.b	d0,._lnt(a0)
	move	d1,d2
	and	#7,d1
	and	#8,d2
	beq.s	.snd0
	or	#$fff8,d1
.snd0:	move.b	.fineoffset(pc,d0.w),d2
	muls	d2,d1
	add	d0,d0
	move	.period(pc,d0.w),d0
	sub	d1,d0
	move	d0,._per(a0)
	or	#$10,d6
.snd1:	rts

.fineoffset:	dc.b	6,6,5,5,4,3,3,3,3,3,3,3,3,3,2,2,2,2
	dc.b	2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

.period:	dc.w	$358,$328,$2fa,$2d0,$2a6,$280
	dc.w	$25c,$23a,$21a,$1fc,$1e0,$1c5
	dc.w	$1ac,$194,$17d,$168,$153,$140
	dc.w	$12e,$11d,$10d,$0fe,$0f0,$0e2
	dc.w	$0d6,$0ca,$0be,$0b4,$0aa,$0a0
	dc.w	$097,$08f,$087,$07f,$078,$071

.sft:	moveq	#0,d0
	move.b	._lnt(a0),d0
	cmp	#36,d0
	beq.s	.sft1
	move	d1,d2
	and	#7,d1
	and	#8,d2
	beq.s	.sft0
	or	#$fff8,d1
.sft0:	lea	.fineoffset(BR),a1
	move.b	(a1,d0.w),d2
	muls	d2,d1
	add	d0,d0
	move	.period(pc,d0.w),d0
	sub	d1,d0
	move	d0,._per(a0)
.sft1:	rts

.playsound:	move	s_volum(BR),d2
	and.b	s_cstat(BR),d6
	move	d6,$96(CB)
	beq.w	.exit
	lea	.chan(BR),a0
	move	d6,d0
	lsr	d0
	bcc.s	.noc1
	move.l	._adr(a0),$a0(CB)
	move	._len(a0),$a4(CB)
	move	._per(a0),._opr(a0)
.noc1:	lsr	d0
	bcc.s	.noc2
	move.l	.clen+._adr(a0),$b0(CB)
	move	.clen+._len(a0),$b4(CB)
	move	.clen+._per(a0),.clen+._opr(a0)
.noc2:	lsr	d0
	bcc.s	.noc3
	move.l	2*.clen+._adr(a0),$c0(CB)
	move	2*.clen+._len(a0),$c4(CB)
	move	2*.clen+._per(a0),2*.clen+._opr(a0)
.noc3:	lsr	d0
	bcc.s	.noc4
	move.l	3*.clen+._adr(a0),$d0(CB)
	move	3*.clen+._len(a0),$d4(CB)
	move	3*.clen+._per(a0),3*.clen+._opr(a0)
.noc4:	wraslin	8
	or	#$8000,d6
	move	d6,$96(CB)
	wraslin	3
	lsr	d6
	bcc.s	.nob1
	move.l	._rad(a0),$a0(CB)
	move.l	._rln(a0),$a4(CB)
	move	._vol(a0),d1
	mulu	d2,d1
	lsr	#6,d1
	move	d1,$a8(CB)
.nob1:	lsr	d6
	bcc.s	.nob2
	move.l	.clen+._rad(a0),$b0(CB)
	move.l	.clen+._rln(a0),$b4(CB)
	move	.clen+._vol(a0),d1
	mulu	d2,d1
	lsr	#6,d1
	move	d1,$b8(CB)
.nob2:	lsr	d6
	bcc.s	.nob3
	move.l	2*.clen+._rad(a0),$c0(CB)
	move.l	2*.clen+._rln(a0),$c4(CB)
	move	2*.clen+._vol(a0),d1
	mulu	d2,d1
	lsr	#6,d1
	move	d1,$c8(CB)
.nob3:	lsr	d6
	bcc.w	.exit
	move.l	3*.clen+._rad(a0),$d0(CB)
	move.l	3*.clen+._rln(a0),$d4(CB)
	move	3*.clen+._vol(a0),d1
	mulu	d2,d1
	lsr	#6,d1
	move	d1,$d8(CB)
	bra.w	.exit

.earp:	move	._pr0(a0),d0
	move.l	._pr1(a0),._pr0(a0)
	move	d0,._pr2(a0)
	bra.w	.nefx0

.evsl:	move	._pr1(a0),d0
	add	._vol(a0),d0
	bpl.s	.evsl0
	moveq	#0,d0
.evsl0:	cmp	#64,d0
	ble.s	.evsl1
	moveq	#64,d0
.evsl1:	move	d0,._vol(a0)
	bra.w	.noefx

.etvs:	move	._pr1(a0),d0
	add	._vol(a0),d0
	bpl.s	.etvs0
	moveq	#0,d0
.etvs0:	cmp	#64,d0
	ble.s	.etvs1
	moveq	#64,d0
.etvs1:	move	d0,._vol(a0)

.etpt:	move	._per(a0),d0
	cmp	._opr(a0),d0
	beq.w	.noefx
	bgt.s	.etpt0
	add	._tps(a0),d0
	cmp	._opr(a0),d0
	ble.s	.etpt2
	bra.s	.etpt1
.etpt0:	sub	._tps(a0),d0
	cmp	._opr(a0),d0
	bge.s	.etpt2
.etpt1:	move	._opr(a0),d0
.etpt2:	move	d0,._per(a0)
	bra.w	.noefx

.epsl:	move	._pr1(a0),d0
	add	._per(a0),d0
	cmp	#113,d0
	bge.s	.epsl0
	moveq	#113,d0
.epsl0:	cmp	#856,d0
	ble.s	.epsl1
	move	#856,d0
.epsl1:	move	d0,._per(a0)
	bra.w	.noefx

.evvs:	move	._pr1(a0),d0
	add	._vol(a0),d0
	bpl.s	.evvs0
	moveq	#0,d0
.evvs0:	cmp	#64,d0
	ble.s	.evvs1
	moveq	#64,d0
.evvs1:	move	d0,._vol(a0)

.evib:	move.b	._vbs(a0),d0
	add.b	._vbp(a0),d0
	move.b	d0,._vbp(a0)
	smi	d3
	lsr	#2,d0
	and	#$1f,d0
	move.b	._vbc(a0),d4
	and	#3,d4
	bne.s	.evib0
	move.b	.sinewave(pc,d0.w),d0	;sine
	bra.s	.evibd
.evib0:	subq	#1,d4
	bne.s	.evib1
	lsl.b	#3,d0	;rampdown
	eor.b	d3,d0
	bra.s	.evibd
.evib1:	st	d0	;square
.evibd:	mulu	._vba(a0),d0
	lsr	#7,d0
	tst.b	d3
	bpl.w	.nefx0
	neg	d0
	bra.w	.nefx0

.sinewave:	dc.b	000,024,049,074,097,120,141,161
	dc.b	180,197,212,224,235,244,250,253
	dc.b	255,253,250,244,235,224,212,197
	dc.b	180,161,141,120,097,074,049,024

.etrm:	move.b	._trs(a0),d0
	add.b	._trp(a0),d0
	move.b	d0,._trp(a0)
	smi	d3
	lsr	#2,d0
	and	#$1f,d0
	move.b	._trc(a0),d4
	and	#3,d4
	bne.s	.etrm0
	move.b	.sinewave(pc,d0.w),d0	;sine
	bra.s	.etrmd
.etrm0:	subq	#1,d4
	bne.s	.etrm1
	lsl.b	#3,d0	;rampdown
	eor.b	d3,d0
	bra.s	.etrmd
.etrm1:	st	d0	;square
.etrmd:	mulu	._tra(a0),d0
	lsr	#7,d0
	tst.b	d3
	bpl.s	.etrm3
	neg	d0
.etrm3:	move	._per(a0),(a1)
	add	._vol(a0),d0
	bpl.s	.etrm4
	moveq	#0,d0
.etrm4:	cmp	#64,d0
	bls.w	.nefx1
	moveq	#64,d0
	bra.w	.nefx1

.efsl:	tst.b	s_timer(BR)
	bne.w	.noefx
	move	._pr1(a0),d0
	add	._per(a0),d0
	cmp	#113,d0
	bge.s	.efsl0
	moveq	#113,d0
.efsl0:	cmp	#856,d0
	ble.s	.efsl1
	move	#856,d0
.efsl1:	move	d0,._per(a0)
	bra.w	.noefx

.efvl:	tst.b	s_timer(BR)
	bne.w	.noefx
	move	._pr1(a0),d0
	add	._vol(a0),d0
	bpl.s	.efvl0
	moveq	#0,d0
.efvl0:	cmp	#64,d0
	ble.s	.efvl1
	moveq	#64,d0
.efvl1:	move	d0,._vol(a0)
	bra.w	.noefx

.ecut:	move	._pr1(a0),d0
	cmp.b	s_timer(BR),d0
	bne.w	.noefx
	clr	._vol(a0)
	clr	._efx(a0)
	bra.w	.noefx

.ertg:	subq	#1,._pr2(a0)
	bpl.w	.noefx
	move	._pr1(a0),._pr2(a0)
	bra.s	.erg

.endl:	move	._pr1(a0),d0
	cmp.b	s_timer(BR),d0
	bne.w	.nefx2
	clr	._efx(a0)
.erg:	move	d6,$96(CB)
	move.l	._adr(a0),-6(a1)
	move	._len(a0),-2(a1)
	move	._per(a0),._opr(a0)
	wraslin	8
	or	#$8000,d6
	move	d6,$96(CB)
	wraslin	3
	move.l	._rad(a0),-6(a1)
	move	._rln(a0),-2(a1)
	bra.s	.noefx

.notime:	lea	.chan(BR),a0
	lea	$a6(CB),a1
	moveq	#3,d1
	move	s_volum(BR),d2
	moveq	#1,d6
.doefx:	move.b	s_cstat(BR),d0
	and	d6,d0
	beq.s	.nefx2
	move	._efx(a0),d0
	jmp	.noefx(pc,d0.w)
.noefx:	moveq	#0,d0
.nefx0:	add	._per(a0),d0
	move	d0,(a1)
	move	._vol(a0),d0
.nefx1:	mulu	d2,d0
	lsr	#6,d0
	move	d0,2(a1)
.nefx2:	lea	.clen(a0),a0
	lea	16(a1),a1
	add	d6,d6
	dbf	d1,.doefx

.exit:	cmp	s_destv(BR),d2
	beq.s	.ncv
	blo.s	.inc
	subq	#2,d2
.inc:	addq	#1,d2
.cv:	move	d2,s_volum(BR)
.ncv:	movem.l	(a7)+,s_saveregs
	rts

.off:	move	#$f,$96(CB)
	clr	$a8(CB)
	clr	$b8(CB)
	clr	$c8(CB)
	clr	$d8(CB)
	movem.l	(a7)+,s_saveregs
	rts

	rsreset
._act:	rs.l	1	;actual address
._pse:	rs.w	1	;pause
._adr:	rs.l	1	;sample address
._len:	rs.w	1	;sample length
._rad:	rs.l	1	;repeat address
._rln:	rs.w	1	;repeat length
._per:	rs.w	1	;period
._vol:	rs.w	1	;volume
._opr:	rs.w	1	;old period
._vba:	rs.w	1	;vibrato amplitude
._tra:	rs.w	1	;tremolo amplitude
._vbp:	rs.b	1	;vibrato position
._trp:	rs.b	1	;tremolo position
._vbs:	rs.b	1	;vibrato speed
._trs:	rs.b	1	;tremolo speed
._vbc:	rs.b	1	;vibrato control
._trc:	rs.b	1	;tremolo control
._lsm:	rs.b	1	;last sample
._lnt:	rs.b	1	;last note
._pr0:	rs.w	1	;arpeggio offset 0
._pr1:	rs.w	1	;arpeggio offset 1,volume slide,portamento slide,notedelay,retrigation
._pr2:	rs.w	1	;arpeggio offset 2,retrigation counter
._tps:	rs.w	1	;tone portamento speed
._plp:	rs.b	1	;pattern loop position
._plc:	rs.b	1	;pattern loop counter
._efx:	rs.w	1	;effect offset
.clen:	rs.w	0

.chan:	blk.l	.clen,0

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

s_smpls:	blk.l	31,0	;sample addresses
s_slist:	dc.l	0	;sample-list address
s_plist:	dc.l	0	;pattern-list address
s_poffs:	dc.l	0	;pattern-offset-table address
s_volum:	dc.w	0	;master volume control (0-64)
s_destv:	dc.w	0	;destination volume (0-64)
s_speed:	dc.b	0	;value of speed (0-31)
s_cstat:	dc.b	0	;chanell status (3210)
s_shots:	dc.b	0	;number of shots to play
s_timer:	dc.b	0	;time counter
s_posit:	dc.b	0	;song position
s_ptpos:	dc.b	0	;pattern position
s_count:	dc.b	0	;pattern counter
s_ptdel:	dc.b	0	;pattern delay
s_newpt:	dc.b	0	;new pattern at next restart
s_soffs:	dc.b	0	;sample offset

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

allocations:
adr_file:	dc.l	0
len_file:	dc.l	0
adr_music:	dc.l	0
len_music:	dc.l	0
adr_mfont:	dc.l	0
len_mfont:	dc.l	0
adr_sfont:	dc.l	0
len_sfont:	dc.l	0
adr_sibanim:	dc.l	0
len_sibanim:	dc.l	0
adr_glbanim:	dc.l	0
len_glbanim:	dc.l	0
adr_january:	dc.l	0
len_january:	dc.l	0
adr_text:	dc.l	0
len_text:	dc.l	0
adr_cred1:	dc.l	0
len_cred1:	dc.l	0
adr_cred2:	dc.l	0
len_cred2:	dc.l	0
adr_cred3:	dc.l	0
len_cred3:	dc.l	0
	dc.l	-1

adr_bpla:	dc.l	bpla
adr_epla:	dc.l	bplea

adr_bplb:	dc.l	bplb
adr_eplb:	dc.l	bpleb

adr_copper_anm:	dc.l	copper_anm
adr_copper_msc:	dc.l	copper_msc
adr_copper_txt:	dc.l	copper_txt

msc_palette:	blk.w	2^dep_msc,0
	dc.w	-1

wid_mfont:	dc.w	0
hei_mfont:	dc.w	0
wid_sfont:	dc.w	0
hei_sfont:	dc.w	0

errt_ilbm:	dc.b	"Incorrect ILBM file.",10,0
errt_read:	dc.b	"Error while reading file.",10,0
errt_notread:	dc.b	"File has not been loaded before.",10,0
errt_memory:	dc.b	"Insufficient free store.",10,0
errt_alloc:	dc.b	"Block has already been allocated.",10,0

name_music:	dc.b	"Things/Global Tracks",0
name_mfont:	dc.b	"Things/Font Multi",0
name_sfont:	dc.b	"Things/Font Single",0
name_sibanim:	dc.b	"Things/Anim Silence",0
name_glbanim:	dc.b	"Things/Anim Global",0
name_january:	dc.b	"Things/Logo January",0
name_chat:	dc.b	"Things/Chat",0
name_duma:	dc.b	"Things/Duma",0
name_howto:	dc.b	"Things/BG How to Get There",0
name_whyto:	dc.b	"Things/BG Why to Come",0
name_facis:	dc.b	"Things/BG Facilities",0
name_rules:	dc.b	"Things/BG Global Rules",0
name_event:	dc.b	"Things/BG Events",0
name_craze:	dc.b	"Things/BG Full Craze",0
name_conts:	dc.b	"Things/BG Contest",0
name_movie:	dc.b	"Things/BG Movies",0
name_cred1:	dc.b	"Things/End Genie",0
name_cred2:	dc.b	"Things/End Cabo",0
name_cred3:	dc.b	"Things/End Active",0

head_meeting:	dc.b	"THE MEETING",0
head_area:	dc.b	"THE AREA",0
head_earth:	dc.b	"EARTH",0
head_eur:	dc.b	"EUROPE",0
head_hun:	dc.b	"HUNGARY",0
head_bp:	dc.b	"BUDAPEST",0
head_howto:	dc.b	"HOW TO GET THERE",0
head_whyto:	dc.b	"WHY TO COME",0
head_facis:	dc.b	"FACILITIES",0
head_rules:	dc.b	"GLOBAL RULES",0
head_event:	dc.b	"EVENTS",0
head_craze:	dc.b	"FULL CRAZE",0
head_conts:	dc.b	"CONTEST",0
head_movie:	dc.b	"MOVIES",0
head_finally:	dc.b	"AND FINALLY",0
head_access:	dc.b	"ACCESS",0


; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	section	Bpl1,bss_c
	ds.l	7
bpla:	ds.b	bpllen*5
	ds.b	bpllen
bplea:
	section	Bpl6,bss_c
	ds.l	7
bplb:	ds.b	bpllen*6
	ds.b	bpllen
bpleb:

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	copper	anm,wid_anm,hei_anm,dep_anm,(dep_anm-1)*wid_anm
	copper	msc,wid_msc,hei_msc,dep_msc,(dep_msc-1)*wid_msc
	copper	txt,wid_txt,hei_txt,dep_txt,0

	section	Blk,data_c
copper_blk:	dc.w	$100,$200
	dc.w	$180,$000
	dc.l	-2,-2

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	section	Holmi,data

window_choice:	dc.w	155,100	;leftedge,topedge
	dc.w	330,26	;width,height
	dc.b	0,1	;detailpen,blockpen
	dc.l	$00000468	;IDCMP
	dc.l	$00033006	;flags
	dc.l	.gadget1	;firstgadget
	dc.l	0	;checkmark
	dc.l	.title	;title
	dc.l	0	;screen
	dc.l	0	;bitmap
	dc.w	330,26	;minwidth,minheigth
	dc.w	330,26	;maxwidth,maxheigth
	dc.w	$000f	;type (normal)
	dc.w	0	;size

.title:	dc.b	"Global Gathering invitation",0
	even

.gadget1:	dc.l	.gadget2	;nextgadget
	dc.w	10,12	;leftedge,topedge
	dc.w	150,11	;width,height
	dc.w	0,3,1	;flags,activation,gadgettype
	dc.l	render	;gadgetrender
	dc.l	0	;selectrender
	dc.l	.itext1	;gadgettext
	dc.l	0,0	;mutualexclude,specialinfo
	dc.w	1	;gadgetid
	dc.l	0	;userdata

.gadget2:	dc.l	0	;nextgadget
	dc.w	170,12	;leftedge,topedge
	dc.w	150,11	;width,height
	dc.w	0,3,1	;flags,activation,gadgettype
	dc.l	render	;gadgetrender
	dc.l	0	;selectrender
	dc.l	.itext2	;gadgettext
	dc.l	0,0	;mutualexclude,specialinfo
	dc.w	2	;gadgetid
	dc.l	0	;userdata

.itext1:	dc.b	1,0	;frontpen,backpen
	dc.b	1,0	;drawmode,kludgefill
	dc.w	(150-4*8)/2,2	;leftedge,topedge
	dc.l	attr_font	;itextfont
	dc.l	.text1	;itext
	dc.l	0	;nexttext

.itext2:	dc.b	1,0	;frontpen,backpen
	dc.b	1,0	;drawmode,kludgefill
	dc.w	(150-5*8)/2,2	;leftedge,topedge
	dc.l	attr_font	;itextfont
	dc.l	.text2	;itext
	dc.l	0	;nexttext

.text1:	dc.b	"Full",0
.text2:	dc.b	"Brief",0
	even

window_lang:	dc.w	155,100	;leftedge,topedge
	dc.w	330,26	;width,height
	dc.b	0,1	;detailpen,blockpen
	dc.l	$00000468	;IDCMP
	dc.l	$00053006	;flags
	dc.l	.gadget1	;firstgadget
	dc.l	0	;checkmark
	dc.l	.title	;title
	dc.l	0	;screen
	dc.l	0	;bitmap
	dc.w	330,26	;minwidth,minheigth
	dc.w	330,26	;maxwidth,maxheigth
	dc.w	$000f	;type (normal)
	dc.w	0	;size

.title:	dc.b	"Select your language",0
	even

.gadget1:	dc.l	.gadget2	;nextgadget
	dc.w	10,12	;leftedge,topedge
	dc.w	150,11	;width,height
	dc.w	0,3,1	;flags,activation,gadgettype
	dc.l	render	;gadgetrender
	dc.l	0	;selectrender
	dc.l	.itext1	;gadgettext
	dc.l	0,0	;mutualexclude,specialinfo
	dc.w	1	;gadgetid
	dc.l	0	;userdata

.gadget2:	dc.l	0	;nextgadget
	dc.w	170,12	;leftedge,topedge
	dc.w	150,11	;width,height
	dc.w	0,3,1	;flags,activation,gadgettype
	dc.l	render	;gadgetrender
	dc.l	0	;selectrender
	dc.l	.itext2	;gadgettext
	dc.l	0,0	;mutualexclude,specialinfo
	dc.w	2	;gadgetid
	dc.l	0	;userdata

.itext1:	dc.b	1,0	;frontpen,backpen
	dc.b	1,0	;drawmode,kludgefill
	dc.w	(150-6*8)/2,2	;leftedge,topedge
	dc.l	attr_font	;itextfont
	dc.l	.text1	;itext
	dc.l	0	;nexttext

.itext2:	dc.b	1,0	;frontpen,backpen
	dc.b	1,0	;drawmode,kludgefill
	dc.w	(150-7*8)/2,2	;leftedge,topedge
	dc.l	attr_font	;itextfont
	dc.l	.text2	;itext
	dc.l	0	;nexttext

.text1:	dc.b	"Magyar",0
.text2:	dc.b	"English",0
	even

window_load:	dc.w	155,100	;leftedge,topedge
	dc.w	330,10	;width,height
	dc.b	0,1	;detailpen,blockpen
	dc.l	$00000400	;IDCMP
	dc.l	$00053006	;flags
	dc.l	0	;firstgadget
	dc.l	0	;checkmark
	dc.l	.title	;title
	dc.l	0	;screen
	dc.l	0	;bitmap
	dc.w	330,10	;minwidth,minheigth
	dc.w	330,10	;maxwidth,maxheigth
	dc.w	$000f	;type (normal)
	dc.w	0	;size

.title:	dc.b	"Loading demo",0
	even

window_brief:	dc.w	0,0	;leftedge,topedge
	dc.w	640,256	;width,height
	dc.b	0,1	;detailpen,blockpen
	dc.l	$00000668	;IDCMP
	dc.l	$00033000	;flags
	dc.l	.gadget1	;firstgadget
	dc.l	0	;checkmark
	dc.l	.title	;title
	dc.l	0	;screen
	dc.l	0	;bitmap
	dc.w	640,256	;minwidth,minheigth
	dc.w	640,256	;maxwidth,maxheigth
	dc.w	$000f	;type (normal)
	dc.w	0	;size

.title:	dc.b	"Global Gathering information",0
	even

.gadget1:	dc.l	.gadget2	;nextgadget
	dc.w	8,12	;leftedge,topedge
	dc.w	16,16	;width,height
	dc.w	0,3,1	;flags,activation,gadgettype
	dc.l	.render	;gadgetrender
	dc.l	0	;selectrender
	dc.l	0	;gadgettext
	dc.l	0,0	;mutualexclude,specialinfo
	dc.w	$1000	;gadgetid
	dc.l	0	;userdata

.gadget2:	dc.l	.gadget3	;nextgadget
	dc.w	8,236	;leftedge,topedge
	dc.w	16,16	;width,height
	dc.w	0,3,1	;flags,activation,gadgettype
	dc.l	.render	;gadgetrender
	dc.l	0	;selectrender
	dc.l	0	;gadgettext
	dc.l	0,0	;mutualexclude,specialinfo
	dc.w	$2000	;gadgetid
	dc.l	0	;userdata

.gadget3:	dc.l	bpla	;nextgadget
	dc.w	12,78	;leftedge,topedge
	dc.w	8,108	;width,height
	dc.w	0,3,1	;flags,activation,gadgettype
	dc.l	.renderq	;gadgetrender
	dc.l	0	;selectrender
	dc.l	0	;gadgettext
	dc.l	0,0	;mutualexclude,specialinfo
	dc.w	$3000	;gadgetid
	dc.l	0	;userdata

.render:	dc.w	0,0	;leftedge,topedge
	dc.b	2,1	;frontpen,backpen
	dc.b	0,5	;drawmode,count
	dc.l	.xy	;xy
	dc.l	0	;nextborder

.renderq:	dc.w	0,0	;leftedge,topedge
	dc.b	3,2	;frontpen,backpen
	dc.b	1,5	;drawmode,count
	dc.l	.xyq	;xy
	dc.l	0	;nextborder

.xy:	dc.w	-1,-1
	dc.w	16,-1
	dc.w	16,16
	dc.w	-1,16
	dc.w	-1,-1

.xyq:	dc.w	-1,-1
	dc.w	8,-1
	dc.w	8,108
	dc.w	-1,108
	dc.w	-1,-1

render:	dc.w	0,0	;leftedge,topedge
	dc.b	1,0	;frontpen,backpen
	dc.b	0,5	;drawmode,count
	dc.l	.xy	;xy
	dc.l	0	;nextborder

.xy:	dc.w	-1,-1
	dc.w	150,-1
	dc.w	150,11
	dc.w	-1,11
	dc.w	-1,-1

attr_font:	dc.l	.name
	dc.w	8	;size
	dc.b	0,0
	dc.w	8	;size

.name:	dc.b	"topaz.font",0
	even

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	if	test
	printt	"WARNING: Workbench messages inactive!"
	endc

	end

