
soundflag:	equ	1
graphflag:	equ	2
prodflag:	equ	3
introflag:	equ	4

calldelay:	equ	7
* BLiTTER BASE ADDRESS

blitter         equ     $FF8A00

* BLiTTER REGISTER OFFSETS
halftone        equ     0
src_xinc        equ     32
src_yinc        equ     34
src_addr        equ     36
endmask1        equ     40
endmask2        equ     42
endmask3        equ     44
dst_xinc        equ     46
dst_yinc        equ     48
dst_addr        equ     50
x_count         equ     54
y_count         equ     56
hop             equ     58
op              equ     59
line_num        equ     60
skew            equ     61
vbl_vec:	equ	$70

vertflag:	equ	$0100
stmodes:	equ	$0080
overscan:	equ	$0040
pal:		equ	$0020
vga:		equ	$0010
tv:		equ	$0000

col80:		equ	$0008
col40:		equ	$0000
numcols:	equ	$0007

bps16:		equ	4
bps8:		equ	3
bps4:		equ	2
bps2:		equ	1
bps1:		equ	0
mybit:		equ	%0000001000000000

fu:		equ	1
fd:		equ	2
fb:		equ	3
fn:		equ	0

fw:	equ	160
fh:	equ	120
sw:	equ	640
sh:	equ	480
*****************************************************************
*	Falcon Slide Demo.					*
*	Version 1.0						*
*****************************************************************
	include	gemmacro.i
	include	'fequates.s'
start:
	move.l	4(a7),a3		base page
	move.l	#mystack,a7
	move.l	$c(a3),d0		text len
	add.l	$14(a3),d0		data len
	add.l	$1c(a3),d0		BSS len
	add.l	#$100,d0		basepage
	move.l	d0,-(sp)
	move.l	a3,-(sp)
	clr.w	-(sp)
	move.w	#$4a,-(sp)
	trap	#1			shrink memory
	lea	12(sp),sp


	appl_init
	move.w	d0,ap_id		store the application id

	graf_handle
	move.w	d0,current_handle	Desktop's VDI handle

* start by opening a virtual workstation
	lea	intin,a0
	moveq	#10-1,d0		-1 for DBF
.fill	move.w	#1,(a0)+		most params are 1
	dbf	d0,.fill
	move.w	#2,(a0)+		use RC system

	v_opnvwk			open it

* set the mouse to an arrow
	graf_mouse	#0		arrow please
	

	clr.l	-(sp)		;as usual the first thing to
	move.w	#$20,-(sp)	;do is go into supervisor mode
	trap	#1
	addq.l	#6,sp
	move.l	d0,savesp

	move.l	$4ba,d0
	bsr	randomseed


	dc.w	$a000
	move.l	d0,linea
bp1:

	move.w	#0,-598(a0)


	move.l	linea,a0
*	move.w	-339(a0),d0
*	move.w	#0,-339(a0)
*	move.l	8(a0),a1
*	move.l	#arrow,(a1)
*	dc.w	$a00b
*	move.w	d0,-339(a0)



*	bsr	putrout
	bsr	putvbl
	bsr	puttime


	bsr	setupscreen
	bsr	clearscreens


	move.w	#$80,-(sp)		;lock the sound system
	trap	#14
	addq.l	#2,sp

	move.w	#-1,-(sp)
	move.w	#0,-(sp)	;ltatten
	move.w	#$82,-(sp)
	trap	#14
	addq.l	#6,sp
	move.w	d0,leftvol

	move.w	#-1,-(sp)
	move.w	#1,-(sp)	;rtatten
	move.w	#$82,-(sp)
	trap	#14
	addq.l	#6,sp
	move.w	d0,rightvol

	lea	palclear,a0
	move.w	#256,numcol
	bsr	dopal		;and d0 already set

	move.w	#1,fade
	lea	mainscreen,a0
	bsr	doscreen


	bsr	mouseon
	move.w	#50*calldelay,timer
	move.w	#3,lapsecount		;after 4 lapse go auto
mainloop:
	bsr	handlewhat
	bsr	domouse
	bsr	keyboard
	tst.w	timer
	bpl	mainloop
	bsr	timelapse
	bra	mainloop


timelapse:
	tst.l	ssmem		;is sound mem alloc
	bmi	.nias
	move.l	ssmem,d0
	bsr	deallocate
.nias:
	subq.w	#1,lapsecount
	bmi	lapsed
	neg.w	whichcall
	bpl	call2
call1:
	lea	callsound1,a0
	bra	lhs
call2:
	lea	callsound2,a0
lhs:
	bsr	loadsound
	bsr	startsound
	move.w	#50*calldelay,timer
	rts

lapsed:
	move.w	#50*calldelay,timer
	move.w	#3,lapsecount
	move.w	#3,d0
	bsr	randomplus
	move.w	d0,what
	rts




arrow:
	dc.w	1,1	;x,y hotspot offset
	dc.w	1	;format flag
	dc.w	0	;background color
	dc.w	128	;foreground color
	dc.w	49152,0,40960,16384,36864,24576,34816,28672
	dc.w	33792,30720,33280,31744,33024,32256,32896
	dc.w	32512,32832,32640,33728,31744,37376,27648,47360
	dc.w	17920,51456,1536,1152,768,1152,768,896,0


lapsecount:	dc.w	0
whichcall:	dc.w	-1
callsound1:	dc.b	'call1.8bt',0
callsound2:	dc.b	'call2.8bt',0
	even
ap_id:	dc.w	0
buttonlist:
	dc.w	30,23,310,231,graphflag
	dc.w	30,247,310,455,prodflag
	dc.w	327,23,606,231,introflag
	dc.w	326,247,606,455,soundflag
	dc.w	-1

domouse:
	move.l	linea,a0
	tst.w	-596(a0)
	beq	nomouse
bp:	move.w	-602(a0),d0	;mx
	move.w	-600(a0),d1	;my
	lea	buttonlist,a1
dmloop:
	tst.w	(a1)
	bmi	nomouse
	cmp.w	(a1),d0
	blt	dmc
	cmp.w	2(a1),d1
	blt	dmc

	cmp.w	4(a1),d0
	bgt	dmc
	cmp.w	6(a1),d1
	bgt	dmc
	move.w	8(a1),what
	rts
dmc:
	add.l	#10,a1
	bra	dmloop
	
nomouse:
	rts


*********************************************************
*	Check to see if something has been chosen	*
*	and take the appropriate action			*
*********************************************************
handlewhat:
	tst.w	what
	bmi	hback

	tst.l	ssmem		;is sound mem alloc
	bmi	.nias
	move.l	ssmem,d0
	bsr	deallocate
.nias:

h1:
	cmpi.w	#soundflag,what
	bne	h2
	bra	dosoundscript
h2:
	cmpi.w	#graphflag,what
	bne	h3
	bra	dographscript
h3:
	cmpi.w	#prodflag,what
	bne	h4
	bra	doprodscript
h4:
	cmpi.w	#introflag,what
	bne	hback
	bra	dointroscript
hback:
	rts


dointroscript:
	move.w	#2,fade
	lea	mainscreen,a0
	bsr	fadedown
	dc.w	$a00a
	lea	iscript,a6
	move.l	#-1,ssmem	;flag no mem allocated
	move.l	#0,count
diloop:
	move.l	(a6)+,d0
	bmi	iscriptover
	move.l	d0,a5
	tst.l	cardsound(a5)
	bmi	noisound
	tst.l	ssmem		;is sound mem alloc
	bmi	nias
	move.l	ssmem,d0
	bsr	deallocate
nias:
	move.l	cardsound(a5),a0
	bsr	loadsound
noisound:
	move.l	cardgraph(a5),a0
	bsr	loadgraph
	move.w	cardfade(a5),fade
	move.l	graphmem,a0
	bsr	doscreen
	tst.l	cardsound(a5)
	bmi	noisound2
	bsr	startsound
noisound2:
	move.w	cardtime(a5),d0
	bsr	waittime
	move.l	graphmem,a0
	bsr	fadedown
	addq.l	#1,count
	bra	diloop
iscriptover:
	tst.l	ssmem		;is sound mem alloc
	bmi	.nsa
	move.l	ssmem,d0
	bsr	deallocate
.nsa:
	move.w	#1,fade
	lea	mainscreen,a0
	bsr	doscreen
	bsr	mouseon
	move.w	#-1,what
	move.w	#50*calldelay,timer
	rts


dosoundscript:
	move.w	#2,fade
	lea	mainscreen,a0
	bsr	fadedown
	dc.w	$a00a
	lea	sscript,a6
	move.l	#-1,ssmem	;flag no mem allocated
	move.l	#0,count
dsloop:
	move.l	(a6)+,d0
	bmi	sscriptover
	move.l	d0,a5
	tst.l	cardsound(a5)
	bmi	nossound
	tst.l	ssmem		;is sound mem alloc
	bmi	nsas
	move.l	ssmem,d0
	bsr	deallocate
nsas:
	move.l	cardsound(a5),a0
	bsr	loadsound
nossound:
	move.l	cardgraph(a5),a0
	bsr	loadgraph
	move.w	cardfade(a5),fade
	move.l	graphmem,a0
	bsr	doscreen
	tst.l	cardsound(a5)
	bmi	nossound2
	bsr	startsound
nossound2:

*	movem.l	d0-a6,-(sp)
*	move.l	count,d0		;count
*	moveq	#10,d1
*	moveq	#0,d2
*	moveq	#0,d3
*	bsr	 prtnum
*	movem.l	(sp)+,d0-a6

	move.w	cardtime(a5),d0
	bsr	waittime
	move.l	graphmem,a0
	bsr	fadedown
	addq.l	#1,count
	bra	dsloop
sscriptover:
	tst.l	ssmem		;is sound mem alloc
	bmi	.nsa
	move.l	ssmem,d0
	bsr	deallocate
.nsa:
	move.w	#1,fade
	lea	mainscreen,a0
	bsr	doscreen
	bsr	mouseon
	move.w	#-1,what
	move.w	#50*calldelay,timer
	rts


doprodscript:
	move.w	#2,fade
	lea	mainscreen,a0
	bsr	fadedown
	dc.w	$a00a

	lea	pscript,a6
	move.l	#-1,ssmem	;flag no mem allocated
	move.l	#0,count
dploop:
	move.l	(a6)+,d0
	bmi	pscriptover
	move.l	d0,a5
	tst.l	cardsound(a5)
	bmi	nopsound
	tst.l	ssmem		;is sound mem alloc
	bmi	nsap
	move.l	ssmem,d0
	bsr	deallocate
nsap:
	move.l	cardsound(a5),a0
	bsr	loadsound
nopsound:
	move.l	cardgraph(a5),a0
	bsr	loadgraph
	move.w	cardfade(a5),fade
	move.l	graphmem,a0
	bsr	doscreen
	tst.l	cardsound(a5)
	bmi	nopsound2
	bsr	startsound
nopsound2:


*	movem.l	d0-a6,-(sp)
*	move.l	count,d0		;count
*	moveq	#10,d1
*	moveq	#0,d2
*	moveq	#0,d3
*	bsr	 prtnum
*	movem.l	(sp)+,d0-a6


	move.w	cardtime(a5),d0
	bsr	waittime
	move.l	graphmem,a0
	bsr	fadedown
	addq.l	#1,count
	bra	dploop
pscriptover:
	tst.l	ssmem		;is sound mem alloc
	bmi	.nsa
	move.l	ssmem,d0
	bsr	deallocate
.nsa:
	move.w	#1,fade
	lea	mainscreen,a0
	bsr	doscreen
	bsr	mouseon
	move.w	#-1,what
	move.w	#50*calldelay,timer
	rts

dographscript:
	move.w	#2,fade
	lea	mainscreen,a0
	bsr	fadedown
	dc.w	$a00a
	lea	gscript,a6
	move.l	#-1,ssmem	;flag no mem allocated
dgloop:
	move.l	(a6)+,d0
	bmi	gscriptover
	move.l	d0,a5
	tst.l	cardsound(a5)
	bmi	nogsound
	bsr	stopsound
	tst.l	ssmem		;is sound mem alloc
	bmi	nsa
	move.l	ssmem,d0
	bsr	deallocate
nsa:
	move.l	cardsound(a5),a0
	bsr	loadsound
nogsound:
	move.l	cardgraph(a5),a0
	bsr	loadgraph

	move.w	cardfade(a5),fade
	move.l	graphmem,a0
	bsr	doscreen

	tst.l	cardsound(a5)
	bmi	nogsound2
	bsr	startsound
nogsound2:
	move.w	cardtime(a5),d0
	bsr	waittime
	move.l	graphmem,a0
	bsr	fadedown
	bra	dgloop
gscriptover:
	tst.l	ssmem		;is sound mem alloc
	bmi	.nsa
	move.l	ssmem,d0
	bsr	deallocate
.nsa:
	move.w	#1,fade
	lea	mainscreen,a0
	bsr	doscreen
	bsr	mouseon
	move.w	#-1,what
	move.w	#50*calldelay,timer
	rts
waittime:
	move.w	d0,timer	;start counting down
wttloop:
	move.l	linea,a0
	tst.w	-596(a0)
	bne	wtback
	move.w	#$ff,-(sp)	;same for keyboard
	move.w	#$6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0
	beq	wtt
*	swap	d0
*	cmp.b	#$10,d0
*	beq	exit
*	cmpi.b	#$39,d0
*	bne	wtback
*	move.w	#7,-(sp)
*	trap	#1
*	addq.l	#2,sp
	bra	wtback
wtt:
	tst.w	timer
	bpl	wttloop
wtback:
	rts

iscript:
	dc.l	icard1,icard2,-1
icard1:
	dc.w	900		;duration
	dc.w	fb
	dc.l	issound1
	dc.l	isgraph1
icard2:
	dc.w	300		;duration
	dc.w	fb
	dc.l	issound2
	dc.l	isgraph2

issound1:	dc.b	'over1.8bt',0
issound2:	dc.b	'over2.8bt',0
isgraph1:	dc.b	'over1.raw',0
isgraph2:	dc.b	'over2.raw',0


sscript:
	dc.l	scard1,scard2,scard3,scard4,scard5,scard6
	dc.l	scard7,scard8,scardef,scard9,scard10,scard11,scard12
	dc.l	scard13,-1
scard1:
	dc.w	820		;duration
	dc.w	fb
	dc.l	sssound1
	dc.l	ssgraph1
scard2:
	dc.w	50		;duration
	dc.w	fu
	dc.l	-1		;no sound
	dc.l	ssgraph2
scard3:
	dc.w	300		;duration
	dc.w	fn
	dc.l	sssound2
	dc.l	ssgraph3
scard4:
	dc.w	320		;duration
	dc.w	fn
	dc.l	sssound3
	dc.l	ssgraph4
scard5:
	dc.w	200		;duration
	dc.w	fn
	dc.l	sssound4
	dc.l	ssgraph5
scard6:
	dc.w	130		;duration
	dc.w	fn
	dc.l	sssounde
	dc.l	ssgraph6
scard7:
	dc.w	150		;duration
	dc.w	fn
	dc.l	sssoundf
	dc.l	ssgraph7
scard8:
	dc.w	150		;duration
	dc.w	fd
	dc.l	sssound5
	dc.l	ssgraph8

scardef:
	dc.w	650		;duration
	dc.w	fb
	dc.l	sssoundef
	dc.l	ssgraphef

scard9:
	dc.w	150		;duration
	dc.w	fu
	dc.l	sssound6
	dc.l	ssgraph9
scard10:
	dc.w	150		;duration
	dc.w	fn
	dc.l	sssound7
	dc.l	ssgraph10
scard11:
	dc.w	350		;duration
	dc.w	fn
	dc.l	sssound8
	dc.l	ssgraph11
scard12:
	dc.w	300		;duration
	dc.w	fd
	dc.l	sssound9
	dc.l	ssgraph12
scard13:
	dc.w	650		;duration
	dc.w	fb
	dc.l	sssound10
	dc.l	ssgraph13


ssgraph1:	dc.b	'sound1.raw',0
ssgraph2:	dc.b	'fd2d1.raw',0
ssgraph3:	dc.b	'fd2d2.raw',0
ssgraph4:	dc.b	'fd2d3.raw',0
ssgraph5:	dc.b	'fd2d4.raw',0
ssgraph6:	dc.b	'fd2d5.raw',0
ssgraph7:	dc.b	'fd2d6.raw',0
ssgraph8:	dc.b	'fd2d7.raw',0
ssgraphef:	dc.b	'seffect.raw',0
ssgraph9:	dc.b	'sam1.raw',0
ssgraph10:	dc.b	'sam2.raw',0
ssgraph11:	dc.b	'sam3.raw',0
ssgraph12:	dc.b	'sam4.raw',0
ssgraph13:	dc.b	'sound2.raw',0

sssound1:	dc.b	'snd1.8bt',0
sssound2:	dc.b	'fd2d1.8bt',0
sssound3:	dc.b	'fd2d2.8bt',0
sssound4:	dc.b	'fd2d3.8bt',0
sssound5:	dc.b	'fd2d4.8bt',0
sssoundef:	dc.b	'comedy.8bt',0	
sssound6:	dc.b	'sam1.8bt',0
sssound7:	dc.b	'sam2.8bt',0
sssound8:	dc.b	'sam3.8bt',0
sssound9:	dc.b	'sam4.8bt',0
sssound10:	dc.b	'snd2.8bt',0
sssounde:	dc.b	'echo.8bt',0
sssoundf:	dc.b	'flange.8bt',0
	even

pscript:
	dc.l	pcard0,pcard1,pcard2,pcard3,pcard4,pcard5,pcard6
	dc.l	pcard7,pcard8,pcard9,pcard10,pcard11,pcard12
	dc.l	pcard13,pcard14,pcard15,pcard16,pcard17
	dc.l	pcard18,pcard19,pcard20,pcard21,pcard22
	dc.l	pcard23,pcard24,pcard25,pcard26,pcard27
	dc.l	pcard28,pcard29,pcard30,pcard31,pcard32
	dc.l	pcard33,pcard34,pcard35,pcard36,pcard37
	dc.l	pcard38,pcard39,pcard40,pcard41,pcard42
	dc.l	pcard43,pcard44,pcard45,-1

pcard0:
	dc.w	720		;duration
	dc.w	fb
	dc.l	pssound1
	dc.l	psgraph0
pcard1:
	dc.w	50		;duration
	dc.w	fu
	dc.l	-1		;no sound
	dc.l	psgraph1
pcard2:
	dc.w	420		;duration
	dc.w	fn
	dc.l	pssound2
	dc.l	psgraph2
pcard3:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph3
pcard4:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph4
pcard5:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph5
pcard6:
	dc.w	310		;duration
	dc.w	fn
	dc.l	pssound3
	dc.l	psgraph6
pcard7:
	dc.w	330		;duration
	dc.w	fn
	dc.l	pssound4
	dc.l	psgraph7

pcard8:
	dc.w	850		;duration
	dc.w	fd
	dc.l	pssound5
	dc.l	psgraph8
pcard9:
	dc.w	50		;duration
	dc.w	fu
	dc.l	-1		;no sound
	dc.l	psgraph9
pcard10:
	dc.w	680		;duration
	dc.w	fn
	dc.l	pssound6
	dc.l	psgraph10
pcard11:
	dc.w	50		;duration
	dc.w	fn
	dc.l	pssound7
	dc.l	psgraph11
pcard12:
	dc.w	50		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph12
pcard13:
	dc.w	50		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph13
pcard14:
	dc.w	90		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph14
pcard15:
	dc.w	300		;duration
	dc.w	fn
	dc.l	pssound8
	dc.l	psgraph15
pcard16:
	dc.w	50		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph16
pcard17:
	dc.w	370		;duration
	dc.w	fd
	dc.l	pssound9
	dc.l	psgraph17
pcard18:
	dc.w	50		;duration
	dc.w	fu
	dc.l	-1		;no sound
	dc.l	psgraph18
pcard19:
	dc.w	190		;duration
	dc.w	fd
	dc.l	pssound10
	dc.l	psgraph19
pcard20:
	dc.w	180		;duration
	dc.w	fu
	dc.l	pssound11
	dc.l	psgraph20
pcard21:
	dc.w	10		;duration
	dc.w	fn
	dc.l	pssound12
	dc.l	psgraph21
pcard22:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1
	dc.l	psgraph22
pcard23:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph23
pcard24:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph24
pcard25:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph25
pcard26:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph26
pcard27:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph27
pcard28:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph28
pcard29:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph29
pcard30:
	dc.w	10		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph30
pcard31:
	dc.w	50		;duration
	dc.w	fd
	dc.l	-1
	dc.l	psgraph31
pcard32:
	dc.w	50		;duration
	dc.w	fu
	dc.l	-1
	dc.l	psgraph32
pcard33:
	dc.w	280		;duration
	dc.w	fn
	dc.l	pssound13
	dc.l	psgraph33
pcard34:
	dc.w	250		;duration
	dc.w	fn
	dc.l	pssound14
	dc.l	psgraph34
pcard35:
	dc.w	200		;duration
	dc.w	fd
	dc.l	pssound15
	dc.l	psgraph35

*	start of other

pcard36:
	dc.w	50		;duration
	dc.w	fu
	dc.l	-1		;no sound
	dc.l	psgraph36
pcard37:
	dc.w	250		;duration
	dc.w	fn
	dc.l	pssound16
	dc.l	psgraph37
pcard38:
	dc.w	150		;duration
	dc.w	fn
	dc.l	pssoundtc		;talking clock
	dc.l	psgraph38
pcard39:
	dc.w	150		;duration
	dc.w	fn
	dc.l	pssound17
	dc.l	psgraph39
pcard40:
	dc.w	30		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	psgraph40
pcard41:
	dc.w	150		;duration
	dc.w	fn
	dc.l	pssound18
	dc.l	psgraph41
pcard42:
	dc.w	150		;duration
	dc.w	fn
	dc.l	pssound19
	dc.l	psgraph42
pcard43:
	dc.w	100		;duration
	dc.w	fn
	dc.l	pssound20
	dc.l	psgraph43
pcard44:
	dc.w	150		;duration
	dc.w	fn
	dc.l	pssound21
	dc.l	psgraph44
pcard45:
	dc.w	450		;duration
	dc.w	fd
	dc.l	pssound22
	dc.l	psgraph45

pssound1:	dc.b	'wp1.8bt',0
pssound2:	dc.b	'wp2.8bt',0
pssound3:	dc.b	'wp3.8bt',0
pssound4:	dc.b	'wp4.8bt',0
pssound5:	dc.b	'wp5.8bt',0
pssound6:	dc.b	'wp6.8bt',0
pssound7:	dc.b	'wp7.8bt',0
pssound8:	dc.b	'wp8.8bt',0
pssound9:	dc.b	'wp9.8bt',0
pssound10:	dc.b	'wp10.8bt',0
pssound11:	dc.b	'wp11.8bt',0
pssound12:	dc.b	'wp12.8bt',0
pssound13:	dc.b	'wp13.8bt',0
pssound14:	dc.b	'wp14.8bt',0
pssound15:	dc.b	'wp15.8bt',0
pssound16:	dc.b	'oth1.8bt',0
pssound17:	dc.b	'oth2.8bt',0
pssound18:	dc.b	'oth3.8bt',0
pssound19:	dc.b	'oth4.8bt',0
pssound20:	dc.b	'oth5.8bt',0
pssound21:	dc.b	'oth6.8bt',0
pssound22:	dc.b	'oth7.8bt',0
pssoundtc:	dc.b	'time.8bt',0

psgraph0:	dc.b	'wp0.raw',0
psgraph1:	dc.b	'wp1.raw',0
psgraph2:	dc.b	'wp2.raw',0
psgraph3:	dc.b	'wp3.raw',0
psgraph4:	dc.b	'wp4.raw',0
psgraph5:	dc.b	'wp5.raw',0
psgraph6:	dc.b	'wp6.raw',0
psgraph7:	dc.b	'wp7.raw',0
psgraph8:	dc.b	'wp8.raw',0
psgraph9:	dc.b	'wp9.raw',0
psgraph10:	dc.b	'wp10.raw',0
psgraph11:	dc.b	'wp11.raw',0
psgraph12:	dc.b	'wp12.raw',0
psgraph13:	dc.b	'wp13.raw',0
psgraph14:	dc.b	'wp14.raw',0
psgraph15:	dc.b	'wp15.raw',0
psgraph16:	dc.b	'wp16.raw',0
psgraph17:	dc.b	'wp17.raw',0
psgraph18:	dc.b	'wp18.raw',0
psgraph19:	dc.b	'wp19.raw',0
psgraph20:	dc.b	'wp20.raw',0
psgraph21:	dc.b	'wp21.raw',0
psgraph22:	dc.b	'wp22.raw',0
psgraph23:	dc.b	'wp23.raw',0
psgraph24:	dc.b	'wp24.raw',0
psgraph25:	dc.b	'wp25.raw',0
psgraph26:	dc.b	'wp26.raw',0
psgraph27:	dc.b	'wp27.raw',0
psgraph28:	dc.b	'wp28.raw',0
psgraph29:	dc.b	'wp29.raw',0
psgraph30:	dc.b	'wp30.raw',0
psgraph31:	dc.b	'wp31.raw',0
psgraph32:	dc.b	'wp32.raw',0
psgraph33:	dc.b	'wp33.raw',0
psgraph34:	dc.b	'wp34.raw',0
psgraph35:	dc.b	'wp35.raw',0
psgraph36:	dc.b	'oth1.raw',0
psgraph37:	dc.b	'oth2.raw',0
psgraph38:	dc.b	'oth3.raw',0
psgraph39:	dc.b	'oth4.raw',0
psgraph40:	dc.b	'oth5.raw',0
psgraph41:	dc.b	'oth6.raw',0
psgraph42:	dc.b	'oth7.raw',0
psgraph43:	dc.b	'oth8.raw',0
psgraph44:	dc.b	'oth9.raw',0
psgraph45:	dc.b	'oth10.raw',0
	even

gscript:
	dc.l	gcard1,gcard2,gcard3,gcard4,gcard5,gcard6
	dc.l	gcard7,gcard8,gcard9,gcard10,gcard11,gcard12
	dc.l	gcard13,gcard15,-1
gcard1:
	dc.w	400		;duration
	dc.w	fb
	dc.l	gssound1
	dc.l	gsgraph1
gcard2:
	dc.w	100		;duration
	dc.w	fb
	dc.l	-1		;no sound
	dc.l	gsgraph2
gcard3:
	dc.w	100		;duration
	dc.w	fb
	dc.l	-1		;no sound
	dc.l	gsgraph3
gcard4:
	dc.w	100		;duration
	dc.w	fb
	dc.l	-1		;no sound
	dc.l	gsgraph4
gcard5:
	dc.w	100		;duration
	dc.w	fb
	dc.l	-1		;no sound
	dc.l	gsgraph5
gcard6:
	dc.w	100		;duration
	dc.w	fb
	dc.l	-1		;no sound
	dc.l	gsgraph6

gcard7:
	dc.w	750		;duration
	dc.w	fb
	dc.l	gssound2	;no sound
	dc.l	gsgraph7

gcard8:
	dc.w	100		;duration
	dc.w	fb
	dc.l	-1		;no sound
	dc.l	gsgraph8
gcard9:
	dc.w	100		;duration
	dc.w	fb
	dc.l	-1		;no sound
	dc.l	gsgraph9
gcard10:
	dc.w	100		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	gsgraph10
gcard11:
	dc.w	100		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	gsgraph11
gcard12:
	dc.w	100		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	gsgraph12
gcard13:
	dc.w	100		;duration
	dc.w	fn
	dc.l	-1		;no sound
	dc.l	gsgraph13
gcard15:
	dc.w	900		;duration
	dc.w	fb
	dc.l	gssound3
	dc.l	gsgraph15


gsgraph1:	dc.b	'gs1.raw',0
gsgraph2:	dc.b	'art.raw',0
gsgraph3:	dc.b	'palette.raw',0
gsgraph4:	dc.b	'yoda.raw',0
gsgraph5:	dc.b	'fruit.raw',0
gsgraph6:	dc.b	'girl.raw',0
gsgraph7:	dc.b	'graph2.raw',0	;more words
gsgraph8:	dc.b	'angelo.raw',0
gsgraph9:	dc.b	'baby.raw',0
gsgraph10:	dc.b	'leaves.raw',0
gsgraph11:	dc.b	'fruit2.raw',0
gsgraph12:	dc.b	'fish.raw',0
gsgraph13:	dc.b	'pool.raw',0

gsgraph15:	dc.b	'graph3.raw',0	;more words

gssound1:	dc.b	'gr1.8bt',0
gssound2:	dc.b	'gr2.8bt',0
gssound3:	dc.b	'gr3.8bt',0
	even


loadgraph:
	move.w	#0,-(sp)
	move.l	a0,-(sp)	;open the file
	move.w	#$3d,-(sp)
	trap	#1
	addq.l	#8,sp
	move.w	d0,handles

	move.l	graphmem,-(sp)
	move.l	#350000,-(sp)
	move.w	handles,-(sp)
	move.w	#$3f,-(sp)
	trap	#1
	add.l	#12,sp

	move.w	handles,-(sp)	;close the file
	move.w	#$3e,-(sp)
	trap	#1
	addq.l	#4,sp
	rts

startsound:
	movem.l	d0-a6,-(sp)

	move.w	#%0000000000000000,-(sp)	;stop the sound
	move.w	#$88,-(sp)
	trap	#14
	addq.l	#4,sp

	move.l	ssmem,d0
	add.l	samplesize,d0
	move.l	d0,-(sp)	;endaddress
	move.l	ssmem,-(sp)	;start address
	move.w	#0,-(sp)	;playback
	move.w	#$83,-(sp)	;setbuffer
	trap	#14
	add.l	#12,sp

	move.w	#%0000000000000001,-(sp)	;play once
	move.w	#$88,-(sp)
	trap	#14
	addq.l	#4,sp
	movem.l	(sp)+,d0-a6
	rts

stopsound:
	movem.l	d0-a6,-(sp)
	move.w	#%0000000000000000,-(sp)	;stop the sound
	move.w	#$88,-(sp)
	trap	#14
	addq.l	#4,sp
	movem.l	(sp)+,d0-a6
	rts

setlvol:
	move.w	mastervol,-(sp)
	move.w	#0,-(sp)	;ltatten
	move.w	#$82,-(sp)
	trap	#14
	addq.l	#6,sp
	rts
setrvol:
	move.w	mastervol,-(sp)
	move.w	#1,-(sp)	;rtatten
	move.w	#$82,-(sp)
	trap	#14
	addq.l	#6,sp
	rts

*****************************************************************
*	This has to find the sound file get it's size		*
*	allocate mem for it and load it in			*
*****************************************************************
loadsound:
	movem.l	d0-a6,-(sp)
	move.l	a0,a6

	move.w	#0,-(sp)
	move.l	a0,-(sp)	;open the file
	move.w	#$3d,-(sp)
	trap	#1
	addq.l	#8,sp
	move.w	d0,handles

	pea	avrheader
	move.l	#128,-(sp)
	move.w	handles,-(sp)
	move.w	#$3f,-(sp)
	trap	#1
	add.l	#12,sp

	lea	avrheader,a1
	move.l	avrslength(a1),d0
	move.l	d0,samplesize
	move.l	d0,-(sp)	;file length from DTA
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	lsback		;not enough mem
	move.l	d0,ssmem

*	now that we've allocated the right amount of mem load it in

	move.l	ssmem,-(sp)
	move.l	samplesize,-(sp)
	move.w	handles,-(sp)
	move.w	#$3f,-(sp)
	trap	#1
	add.l	#12,sp

	move.w	handles,-(sp)	;close the file
	move.w	#$3e,-(sp)
	trap	#1
	addq.l	#4,sp
	bsr	setsoundup
lsback:
	movem.l	(sp)+,d0-a6
	rts


flist:
	dc.l	49170,1,33880,2,24585,3,20770,4,16490,5
	dc.l	12292,7,9834,9,8195,11,0

setsoundup:
	move.w	#$00f0,mastervol
	bsr	setlvol	
	move.w	#$00f0,mastervol
	bsr	setrvol	


	lea	avrheader,a6
	cmpi.w	#16,avrres(a6)
	beq	a16bitstereo
	tst.w	avrmono(a6)
	bmi	a8bitstereo
a8bitmono:
	move.w	#2,-(sp)		;setmode 8bit mono
	move.w	#$84,-(sp)
	trap	#14
	addq.l	#4,sp
	bra	setspeed
a8bitstereo:
	move.w	#0,-(sp)		;setmode 8bit mono
	move.w	#$84,-(sp)
	trap	#14
	addq.l	#4,sp
	bra	setspeed
a16bitstereo:
	move.w	#1,-(sp)		;setmode 8bit mono
	move.w	#$84,-(sp)
	trap	#14
	addq.l	#4,sp
setspeed:
	moveq	#0,d0
	move.l	avrspeed(a6),d0
*	and.l	#$00000fff,d0
	and.l	#%00000000111111111111111111111111,d0
	lea	flist,a5
.loop:
	move.l	(a5)+,d1
	beq	nosound		;error
	cmp.l	d0,d1
	beq	foundfreq
	addq.l	#4,a5		;skip prescale number
	bra	.loop
foundfreq:
	move.l	(a5)+,d0

	move.w	#1,-(sp)	;disable handshaking
	move.w	d0,-(sp)	;prescale
	move.w	#0,-(sp)	;srclk internal 25.175Mhz
	move.w	#8,-(sp)	;dst dac
	move.w	#0,-(sp)	;src dma playback
	move.w	#$8b,-(sp)	;devconnect
	trap	#14
	add.l	#12,sp

	move.w	#0,-(sp)	;rectracks
	move.w	#0,-(sp)	;playtracks
	move.w	#$85,-(sp)	;set tracks
	trap	#14
	addq.l	#6,sp
nosound:
	move.w	leftvol,mastervol
	bsr	setlvol	
	move.w	rightvol,mastervol
	bsr	setrvol	
	rts

avrslength:	equ	26
avrmono:	equ	12
avrres:		equ	14
avrspeed:	equ	22

avrheader:
	ds.b	128

*****************************************************************
*	Scriptlists control what happens in a section		*
*	they are constructed from a series of cards.		*
*	each card has the following make up.			*
*								*
*	dc.w	0	time to remain on screen in 1/50sec	*
*	dc.w	x	fade or not (1=fadeup 2=fadedown 0=nofade)
*			3=fadeboth
*	dc.l	x	pointer to sound filename -1 if none	*
*	dc.l	x	pointer to graphic fname (must be present)
*								*
*****************************************************************
	rsreset
cardtime:	rs.w	1
cardfade:	rs.w	1
cardsound:	rs.l	1
cardgraph:	rs.l	1

swapnshow:
	movem.l	d0-a6,-(sp)
	move.l	viewscreen1,d0
	move.l	viewscreen2,viewscreen1
	move.l	d0,viewscreen2
waitvbl:
	move.w	#1,vblflag
wvbloop:
	tst.w	vblflag
	bpl	wvbloop
	move.l	viewscreen1,d0
	move.l	d0,d1
	move.l	d1,d2
	lsr.l	#8,d0
	lsr.l	#8,d0
	move.w	d0,vid_bh
	lsr.l	#8,d1
	and.l	#$000000ff,d1
	move.w	d1,vid_bm
	and.l	#$000000ff,d2
	move.w	d2,vid_bl



	move.w	#-1,-(sp)
	move.l	viewscreen1,-(sp)
	move.l	viewscreen1,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp

	movem.l	(sp)+,d0-a6
	rts



*****************************************
*	number in d0.l			*
*	d1.l is base			*
*	d2,x cursor			*
*	d3,y cursor			*
*****************************************
prtnum:
	movem.l	d0/d1,-(sp)
	lea	posstring,a0
	add.w	#32,d3
	move.b	d3,2(a0)	
	add.w	#32,d2
	move.b	d2,3(a0)
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	movem.l	(sp)+,d0/d1

	lea	linebuffer,a0
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
loop1:
	divu	d1,d0
	swap	d0
	addi	#'0',d0
	cmpi.w	#'9',d0
	ble.s	ok
	addq.w	#7,d0
ok:
	move.b	d0,-(a0)
	clr	d0
	swap	d0
	bne	loop1
loop2:
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	rts

clearnums:
	lea	clearstring,a0
	add.w	#32,d3
	move.b	d3,2(a0)	
*	move.b	d3,10(a0)	
	add.w	#32,d2
	move.b	d2,3(a0)
*	move.b	d2,11(a0)	
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	rts
linebuffer:
	ds.l	5
digits:
	dc.b	0
posstring:	dc.b	27,'Y',0,0,0,0
clearstring:	dc.b	27,'Y',0,0,'   ',0,0
	even
klock:		dc.w	1

keyboard:
	move.w	#$ff,-(sp)
	move.w	#$6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0
	beq	keyback
	swap	d0

	tst.w	klock		;is the keyboard locked?
	bpl	klocked		;if so respond only to special sequence
qkey2:
	cmp.b	#16,d0
	beq	exit
klocked:		;no quit key if locked
f1:
	cmp.b	#$3b,d0	
	bne	f2
	move.w	#graphflag,what
	rts
f2:
	cmp.b	#$3c,d0
	bne	f3
	move.w	#introflag,what
	rts
f3:
	cmp.b	#$3d,d0
	bne	f4
	move.w	#prodflag,what
	rts

f4:
	cmp.b	#$3e,d0
	bne	lkey
	move.w	#soundflag,what
	rts

lkey:
	cmp.b	#$26,d0		*space
	bne	keyback
	bra	glock
keyback:
*	move.w	#-1,what
	rts

glock:
	lea	lockword,a6
.loop:
	move.b	(a6)+,d7
	beq	gotlock
	move.w	#7,-(sp)
	trap	#1
	addq.l	#2,sp
	cmp.b	d0,d7		;is it one of the key words chars
	beq	.loop		;yep so keep going
*	neg.w	klock		;nope so return without lock
	rts
gotlock:
	neg.w	klock		;nope so return without lock
*	move.w	#1,klock	;return with lock
	rts

lockword:	dc.b	'amanda',0
	even

clearscreens:
	lea	blitter,a6
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit
	move.l	viewscreen1,a0
	move.l	viewscreen2,a1
	move.l	a0,dst_addr(a6)
	move.w	#2,dst_xinc(a6)
	move.w	#2,dst_yinc(a6)
	move.w	#sw/2,x_count(a6)
	move.w	#sh,y_count(a6)
	move.w	#-1,endmask1(a6)
 	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#0,skew(a6)
	move.b	#$0,op(a6)
	move.b	#2,hop(a6)
	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
*.waitblit:
*	btst	#7,line_num(a6)
*	bne	.waitblit
*	move.l	a1,dst_addr(a6)
*	move.w	#2,dst_xinc(a6)
*	move.w	#2,dst_yinc(a6)
*	move.w	#sw,x_count(a6)
*	move.w	#sh,y_count(a6)
*	bset	#6,line_num(a6)
*	bset	#7,line_num(a6)
	rts


doclear:
	movem.l	a0/a6,-(sp)

	lea	blitter,a6
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit
	move.l	viewscreen1,a0
	move.l	a0,dst_addr(a6)
	move.w	#2,dst_xinc(a6)
	move.w	#2,dst_yinc(a6)
	move.w	#sw/2,x_count(a6)
	move.w	#sh,y_count(a6)
	move.w	#-1,endmask1(a6)
 	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#0,skew(a6)
	move.b	#$0,op(a6)
	move.b	#2,hop(a6)
	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
	movem.l	(sp)+,a0/a6
	rts

putpoint:
	movem.l	d0/d1/a0,-(sp)
	moveq	#0,d0
	move.l	d0,d1
	move.w	pixelx,d0
	add.l	d0,d0
	move.w	pixely,d1
	mulu	#sw*2,d1
	add.l	d1,d0
	move.l	viewscreen1,a0
	add.l	d0,a0
	move.w	color,(a0)
	movem.l	(sp)+,d0/d1/a0
	rts



buttondat:	dc.w	0
mx:		dc.w	0
my:	dc.w	0
*************puts my mouse interupt in***************** 
putrout:move.w  #34,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,a0
	move.l	16(a0),oldmouse
        move.l  #myrout,16(a0)
        rts
lastb:		dc.w	-1
mousehasgoneup:	dc.w	0

**************my ubeut mouse interupt*******************
myrout:
	movem.l	d0-d2/a0-a1,-(sp)
	moveq	#0,d0	
	move.b	(a0),d0
	cmpi.b	#$fa,d0
	bne	myr1
	move.w	#1,buttondat
	bra	myrxy
myr1:
	cmpi.b	#$f9,d0
	bne	myr2
	move.w	#2,buttondat
	bra	myrxy
myr2:
	cmpi.b	#$fb,d0
	bne	myr3
	move.w	#3,buttondat
	bra	myrxy
myr3:
	move.w	#1,mousehasgoneup
	move.w	#0,buttondat
myrxy:
	moveq	#0,d0
	move.b	1(a0),d0
	ext.w	d0
	moveq	#0,d1
	move.b	2(a0),d1
	ext.w	d1
	add.w	d0,mx
	add.w	d1,my
*	sub.w	d1,my2
myr4:	move.w	mx,d0
	move.w	my,d1
	bsr	extra
	move.w	d0,mx
	move.w	d1,my
	movem.l	(sp)+,d0-d2/a0-a1
	rts

extra:  cmpi.w	#mminx,d0
        bge	extra1
        move.w	#mminx,d0
        bra	extra2
extra1: cmpi.w   #mmaxx,d0
        ble	extra2
        move.w  #mmaxx,d0
extra2:	cmpi.w  #mminy,d1
        bge	extra3
        move.w  #mminy,d1
        bra	extra4
extra3: cmpi.w   #mmaxy,d1
        ble	extra4
        move.w  #mmaxy,d1
extra4:
        rts

mminx:	equ	0
mmaxx:	equ	sw
mminy:	equ	0
mmaxy:	equ	sh


putvbl:
	move.l	vbl_vec,vblt+2		;set up vbl handler
	move.l	vbl_vec,oldvblvec
	move.l	#vbl_handler,vbl_vec
	rts

halfframe:	dc.w	0
ddl:		dc.w	-1
vbl_handler:
*	move.b	currentscreen+1,$ff8205
*	move.b	currentscreen+2,$ff8207
*	move.b	currentscreen+3,$ff8209
*	subq.w	#1,halfframe
*	bpl.s	skipfa
*	tst.w	syncmode
*	bmi	skipfa
*	move.w	#1,halfframe
*	addq.l	#1,frame		;update current frame each
*	cmpi.l	#maxframes,frame
*	blt	skipfa
*	move.l	#0,frame
*	move.w	#1,ddl
skipfa:
	move.w	#-1,vblflag
vblt:
	jmp	$0.L


puttime:
	move.l	$114,save114
	move.l	$114,my114drop+2
	move.l	#my114,$114
	rts

my114:
	move.l	d0,-(sp)
	move.b	c25,d0
	ror.b	#1,d0
	bpl	not25hz
	subq.w	#1,timer
not25hz:
	move.b	d0,c25
	move.l	(sp)+,d0
my114drop:
	jmp	$0.L

c25:		dc.b	%00010001
	even


exit:
	move.l	save114,$114
	bsr	stopsound

	move.w	#$81,-(sp)		;unlock the sound system
	trap	#14
	addq.l	#2,sp

*	move.w  #34,-(sp)
*        trap    #14
*        addq.l  #2,sp
*        move.l  d0,a0
*	move.l	oldmouse,16(a0)

	lea	memlist,a6
demem:
	move.l	(a6)+,d0
	bmi	nomoremem
	beq	demem
	bsr	deallocate
	bra	demem
nomoremem:
	move.l	oldvblvec,vbl_vec

	move.w	savemode,-(sp)
	move.w	#3,-(sp)
	move.l	savescreen,-(sp)
	move.l	savescreen,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#14,sp


	move.l	savesp,-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq.l	#6,sp

	v_clsvwk			close it

	appl_exit			tell GEM I've finished


	clr.w	-(sp)
	trap	#1

deallocate:
	move.l	d0,-(sp)
	move.w	#$49,-(sp)
	trap	#1
	addq.l	#6,sp
	rts

clearmem:
	move.l	#(sw*sh),d0
	asr.l	#1,d0
	subq.l	#1,d0
	moveq	#0,d1
cml:
	move.w	d1,(a0)+
	subq.l	#1,d0
	bpl	cml
	rts

*********************************************************
*	One call does it all				*
*	Allocates memory for 3 screens 			*
*	targa load/hold area is internal.		*
*	Then sets all the hardware stuff to create	*
*	a 384*480 16bit screen				*
*********************************************************
setupscreen:
	move.l	#(sw*sh)+8,-(sp)	;thats 1 screen size
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	exit
	move.l	d0,savemem1
	and.l	#$fffffffc,d0
	move.l	d0,viewscreen1
	move.l	d0,a0

*	bsr	clearmem

	move.l	#(sw*sh)+8,-(sp)	;thats 1 screen size
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	exit
	move.l	d0,savemem2
	and.l	#$fffffffc,d0
	move.l	d0,viewscreen2

	move.l	#(sw*sh)+1000+8,-(sp)	;thats 1 screen size
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	exit
	move.l	d0,savescreen2

	move.l	#(sw*sh)+8,-(sp)	;thats 1 screen size
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	exit
	move.l	d0,graphmem

	move.w	#2,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,savescreen

	move.w	#-1,-(sp)
	move.w	#88,-(sp)
	trap	#14
	addq.l	#4,sp
	move.w	d0,savemode

	move.w	#pal|vga|col80|bps8,-(sp)
	move.w	#3,-(sp)
	move.l	viewscreen1,-(sp)
	move.l	viewscreen1,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#14,sp

*	move.w	#2,-(sp)
*	trap	#14
*	addq.l	#2,sp
*	move.l	d0,savescreen2

*	move.l	#0,$ffff9800
	rts

*********************************************************
*	copy whole screen with blitter			*
*	set screen to copy to in a1			*
*********************************************************
copywhole:
	movem.l	d0-a6,-(sp)
	move.l	savescreen2,a0
	tst.w	rawplanes(a6)
	bne	cw1
	move.w	rawx(a6),d0
	bra	cw2
cw1:
	move.w	rawx(a6),d0
	asr.w	#4,d0
	mulu	rawplanes(a6),d0

cw2:
	move.l	a6,a5
	lea	blitter,a6
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit

	move.l	a0,src_addr(a6)
	move.l	a1,dst_addr(a6)
	move.w	#2,src_xinc(a6)
	move.w	#2,dst_xinc(a6)
	move.w	#2,src_yinc(a6)
	move.w	#2,dst_yinc(a6)
	move.w	d0,x_count(a6)
	move.w	rawy(a5),y_count(a6)
	move.w	#-1,endmask1(a6)
	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#0,skew(a6)
	move.b	#$3,op(a6)
	move.b	#2,hop(a6)
	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
	movem.l	(sp)+,d0-a6
	rts

*********************************************************
*	copy whole screen with blitter			*
*	set screen to copy to in a1			*
*	where from in a0				*
*	raw pointer in a6				*
*********************************************************
copyraw:
	movem.l	d0-a6,-(sp)
*	move.l	savescreen2,a0
	tst.w	rawplanes(a6)
	bne	cnn
	move.w	rawx(a6),d0
	bra	cnn2
cnn:
	move.w	rawx(a6),d0
	asr.w	#4,d0
	mulu	rawplanes(a6),d0
cnn2:
	move.l	a6,a5
	lea	blitter,a6
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit

	move.l	a0,src_addr(a6)
	move.l	a1,dst_addr(a6)
	move.w	#2,src_xinc(a6)
	move.w	#2,dst_xinc(a6)
	move.w	#2,src_yinc(a6)
	move.w	#2,dst_yinc(a6)
	move.w	d0,x_count(a6)
	move.w	rawy(a5),y_count(a6)
	move.w	#-1,endmask1(a6)
	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#0,skew(a6)
	move.b	#$3,op(a6)
	move.b	#2,hop(a6)
	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
	movem.l	(sp)+,d0-a6
	rts

	rsreset
rawx:		rs.w	1
rawy:		rs.w	1
rawplanes	rs.w	1
rawpal:		rs.l	256

*********************************************************
*	pass the address of the raw format data		*
*	and this will set the machine to the correct	*
*	video mode, decompress the screen data and copy	*
*	it to savescreen2.				*
*	address in A0					*
*********************************************************
doscreen:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	a0,a6
	moveq	#0,d7		;build modecode
	or.w	#vga,d7
	or.w	#pal,d7
	cmpi.w	#640,rawx(a0)
	bne	mm1
	or.w	#col80,d7
mm1:
	cmpi.w	#240,rawy(a0)
	bne	mm2
	or.w	#vertflag,d7
mm2:
	cmpi.w	#8,rawplanes(a0)
	bne	mm3
	or.w	#bps8,d7
	bra	mmfin
mm3:
	cmpi.w	#4,rawplanes(a0)
	bne	mm4
	or.w	#bps4,d7
	bra	mmfin
mm4:
	cmpi.w	#0,rawplanes(a0)
	bne	mmfin
	or.w	#bps16,d7
mmfin:
	move.w	#-1,-(sp)	;first check if we need to
	move.w	#88,-(sp)	;switch video modes
	trap	#14
	addq.l	#4,sp
	cmp.w	d0,d7
	beq	noneed


*	move.w	#1,vblflag
*.wvbloop:
*	tst.w	vblflag
*	bpl	.wvbloop

	bsr	doclear
	move.w	d7,-(sp)	;set the proper vid mode
	move.w	#88,-(sp)
	trap	#14
	addq.l	#4,sp


	moveq	#1,d0
	move.w	rawplanes(a6),d1
	beq	noneed		;for tru col
	asl.w	d1,d0
	move.w	d0,numcol
	lea	palclear,a0
	bsr	dopal		;and d0 already set
noneed:
	move.l	a6,a0
	add.l	#6,a0
	moveq	#1,d0
	move.w	rawplanes(a6),d1
	beq	non2
	asl.w	d1,d0
	asl.l	#2,d0
	add.l	d0,a0			;a0 points to start of compressed
non2:
	move.l	savescreen2,a1		;image data
	jsr	ice_unpack
	tst.w	wasnotwas
	bpl	wascomp
	bsr	copyraw
wascomp:
	move.l	viewscreen2,a1
	bsr	copywhole
	bsr	swapnshow
	move.l	a6,a0
	bsr	fadeup
	movem.l	(sp)+,d0-d7/a0-a6
	rts
wasnotwas:	dc.w	0
*************************************************
*	Requires address of pal dat 		*
*	in a0 and num cols in d0		*
*************************************************
dopal:
	movem.l	d0-a6,-(sp)
	move.w	#1,vblflag
.wvbloop:
	tst.w	vblflag
	bpl	.wvbloop
	move.l	a0,-(sp)		;color array
	move.w	numcol,-(sp)		;number to set
	move.w	#0,-(sp)		;index to start at
	move.w	#93,-(sp)
	trap	#14
	add.l	#10,sp
	movem.l	(sp)+,d0-a6
	rts

*************************************************
*	fade colors from black to pallete in	*
*	raw file				*
*************************************************
fadeup:
	movem.l	d0-a6,-(sp)
	moveq	#1,d0
	move.w	rawplanes(a0),d1
	asl.w	d1,d0			;gives number of colors
	move.w	d0,numcol
	subq.w	#1,d0

	lea	6(a0),a6
	move.w	fade,d5
	btst	#0,d5			;if no fade just do pal
	beq	fuback

	move.w	d0,d7
	lea	paltemp,a2
.loop:
	move.l	#0,(a2)+		;set the palette to black
	dbf	d7,.loop


	move.w	d0,d7
	lea	6(a0),a1
	lea	palsubs,a2
fuloop1:
	addq.l	#1,a1		;skip blank
	addq.l	#1,a2		;skip blank
	moveq	#0,d1
	move.b	(a1)+,d1	;get red
	asr.w	#4,d1
	tst.b	d1
	bne	rou
	moveq	#1,d1
rou:
	move.b	d1,(a2)+
	moveq	#0,d1
	move.b	(a1)+,d1	;get red
	asr.w	#4,d1
	tst.b	d1
	bne	gou
	moveq	#1,d1
gou:
	move.b	d1,(a2)+

	moveq	#0,d1
	move.b	(a1)+,d1	;get red
	asr.w	#4,d1
	tst.b	d1
	bne	bou
	moveq	#1,d1
bou:
	move.b	d1,(a2)+
	dbf	d7,fuloop1

	lea	6(a0),a6
	move.l	a6,a5
	moveq	#15,d6
	lea	paltemp,a1
	lea	palsubs,a2
fuloop2a:
	move.l	a6,a5
	lea	paltemp,a1
	lea	palsubs,a2
	move.w	d0,d7
fuloop2b:
	addq.l	#1,a1
	addq.l	#1,a5
	addq.l	#1,a2
	moveq	#0,d1
	moveq	#0,d2
	move.b	(a1),d1
	move.b	(a2)+,d2
	ext.w	d2
	add.w	d2,d1
*	cmp.b	(a5),d1
*	ble	roku
*	move.b	(a5),d1
roku:
	addq.l	#1,a5
	move.b	d1,(a1)+

	moveq	#0,d1
	moveq	#0,d2
	move.b	(a1),d1
	move.b	(a2)+,d2
	ext.w	d2
	add.w	d2,d1
*	cmp.b	(a5),d1
*	ble	goku
*	move.b	(a5),d1
goku:
	addq.l	#1,a5
	move.b	d1,(a1)+

	moveq	#0,d1
	moveq	#0,d2
	move.b	(a1),d1
	move.b	(a2)+,d2
	ext.w	d2
	add.w	d2,d1
*	cmp.b	(a5),d1
*	ble	boku
*	move.b	(a5),d1
boku:
	addq.l	#1,a5
	move.b	d1,(a1)+

	dbf	d7,fuloop2b
	lea	paltemp,a0
	bsr	dopal		;and d0 already set
	dbf	d6,fuloop2a
fuback:
	move.l	a6,a0
	bsr	dopal		;and d0 already set
	movem.l	(sp)+,d0-a6
	rts

*************************************************
*	fade colors to black			*
*	address of raw in a0			*
*************************************************
fadedown:
	movem.l	d0-a6,-(sp)
	move.w	fade,d0
	btst	#1,d0			;if no fade just do pal
	beq	fdback

	moveq	#1,d0
	move.w	rawplanes(a0),d1
	asl.w	d1,d0			;gives number of colors
	move.w	d0,numcol
	subq.w	#1,d0
	move.w	d0,d7
	lea	paltemp,a2
	lea	6(a0),a1		;ad of pal
.loop:
	move.l	(a1)+,(a2)+
	dbf	d7,.loop

	move.l	d0,d7
	lea	paltemp,a1
	lea	palsubs,a2
fdloop1:
	addq.l	#1,a1		;skip blank
	addq.l	#1,a2		;skip blank
	moveq	#0,d1
	move.b	(a1)+,d1	;get red
	asr.w	#4,d1
	tst.b	d1
	bne	ro
	moveq	#1,d1
ro:
	move.b	d1,(a2)+

	moveq	#0,d1
	move.b	(a1)+,d1	;get red
	asr.w	#4,d1
	tst.b	d1
	bne	go
	moveq	#1,d1
go:
	move.b	d1,(a2)+

	moveq	#0,d1
	move.b	(a1)+,d1	;get red
	asr.w	#4,d1
	tst.b	d1
	bne	bo
	moveq	#1,d1
bo:
	move.b	d1,(a2)+
	dbf	d7,fdloop1

	moveq	#15,d6
	lea	paltemp,a1
	lea	palsubs,a2
fdloop2a:
	lea	paltemp,a1
	lea	palsubs,a2
	move.w	d0,d7
fdloop2b:
	addq.l	#1,a1
	addq.l	#1,a2
	moveq	#0,d1
	moveq	#0,d2
	move.b	(a1),d1
	move.b	(a2)+,d2
	ext.w	d2
	sub.w	d2,d1
	bge	rok
	move.b	#0,d1
rok:
	move.b	d1,(a1)+

	moveq	#0,d1
	moveq	#0,d2
	move.b	(a1),d1
	move.b	(a2)+,d2
	ext.w	d2
	sub.w	d2,d1
	bge	gok
	move.b	#0,d1
gok:
	move.b	d1,(a1)+

	moveq	#0,d1
	moveq	#0,d2
	move.b	(a1),d1
	move.b	(a2)+,d2
	ext.w	d2
	sub.w	d2,d1
	bge	bok
	move.b	#0,d1
bok:
	move.b	d1,(a1)+

	dbf	d7,fdloop2b
	lea	paltemp,a0
	bsr	dopal		;and d0 already set
	dbf	d6,fdloop2a
	lea	palclear,a0
	bsr	dopal		;and d0 already set
fdback:
	movem.l	(sp)+,d0-a6
	rts

palsubs:	ds.l	256
paltemp:	ds.l	256
palclear:	ds.l	256
delayticks:
	move.l	$4ba,d1
dltl:
	move.l	$4ba,d2
	sub.l	d1,d2
	cmp.l	d0,d2
	blt	dltl
	rts
mouseon:
	movem.l	d0/a0,-(sp)

*	move.l	linea,a0
*	move.w	-339(a0),d0
*	move.w	#0,-339(a0)
*	move.l	8(a0),a1
*	move.l	#arrow,(a1)
*	dc.w	$a00b
*	move.w	d0,-339(a0)

	move.l	linea,a0
	move.b	#-1,-340(a0)
	dc.w	$a009
	movem.l	(sp)+,d0/a0
	rts

RND:		ds.l	5
*******************************************************************
randomseed:     ADD.L   D0,D1           ;user seed in d0 (d1 too)
                MOVEM.L D0/D1,RND
; drops through to the main random function (not user callable)
LongRnd:        MOVEM.L D1-D3,-(SP)     
                MOVEM.L RND,D0/D1       ;D0=LSB's, D1=MSB's of random number
                ANDI.B  #$0E,D0         ;ensure upper 59 bits are an...
                ORI.B   #$20,D0         ;...odd binary number
                MOVE.L  D0,D2
                MOVE.L  D1,D3
                ADD.L   D2,D2           ;accounts for 1 of 17 left shifts
                ADDX.L  D3,D3           ;[D2/D3] = RND*2
                ADD.L   D2,D0
                ADDX.L  D3,D1           ;[D0/D1] = RND*3
                SWAP    D3              ;shift [D2/D3] additional 16 times
                SWAP    D2
                MOVE.W  D2,D3
                CLR.W   D2
                ADD.L   D2,D0           ;add to [D0/D1]
                ADDX.L  D3,D1
                MOVEM.L D0/D1,RND       ;save for next time through
                MOVE.L  D1,D0           ;most random part to D0
                MOVEM.L (SP)+,D1-D3
                RTS
random:         MOVE.w  D2,-(SP)
                MOVE.W  D0,D2           ;save upper limit
                BEQ.S   r1              ;range of 0 returns 0 always
                BSR.S   LongRnd         ;get a longword random number
                CLR.W   D0              ;use upper word (it's most random)
                SWAP    D0
                ext.l   d0
                DIVs    D2,D0           ;divide by range...
                CLR.W   D0              ;...and use remainder for the value
                SWAP    D0              ;result in D0.W
r1:             MOVE.w  (SP)+,D2
                RTS

randomplus:     MOVE.w  D2,-(SP)
                MOVE.W  D0,D2           ;save upper limit
                BEQ.S   r2              ;range of 0 returns 0 always
                BSR.S   LongRnd         ;get a longword random number
                CLR.W   D0              ;use upper word (it's most random)
                SWAP    D0
                DIVu    D2,D0           ;divide by range...
                CLR.W   D0              ;...and use remainder for the value
                SWAP    D0              ;result in D0.W
r2:             MOVE.w  (SP)+,D2
                RTS



;********************************************* Unpackroutine von ICE-PACK
; assemble with Devpac or any other Assembler
; length of this unpacking routine: 294 bytes
;  a0 = address of packed data
;  a1 = address of unpacked data
ice_unpack:
	movem.l d0-a6,-(sp)
	bsr	ice04
	cmpi.l	#'Ice!',d0		; Is file packed?
	bne	ice03b			; no, leave this routine
	bsr	ice04
	lea	-8(a0,d0.l),a5
	bsr	ice04
*	move.l	d0,(sp)
	movea.l a1,a4
	movea.l a1,a6
	adda.l	d0,a6
	movea.l a6,a3
	move.b	-(a5),d7
	bsr	ice06
ice03:
	move.w	#1,wasnotwas
	movem.l (sp)+,d0-a6
	rts
ice03b:
	move.w	#-1,wasnotwas
	movem.l (sp)+,d0-a6
	rts
ice04:	moveq	#3,d1
ice05:	lsl.l	#8,d0
	move.b	(a0)+,d0
	dbra	d1,ice05
	rts
ice06:	bsr	ice0a
	bcc	ice09
	moveq	#0,d1
	bsr	ice0a
	bcc	ice08
	lea	ice17(pc),a1
	moveq	#4,d3
ice07:	move.l	-(a1),d0
	bsr	ice0c
	swap	d0
	cmp.w	d0,d1
	dbne	d3,ice07
	add.l	20(a1),d1
ice08:	move.b	-(a5),-(a6)
	dbra	d1,ice08
ice09:	cmpa.l	a4,a6
	bgt	ice0f
	rts
ice0a:	add.b	d7,d7
	bne	ice0b
	move.b	-(a5),d7
	addx.b	d7,d7
ice0b:	rts
ice0c:	moveq	#0,d1
ice0d:	add.b	d7,d7
	bne	ice0e
	move.b	-(a5),d7
	addx.b	d7,d7
ice0e:	addx.w	d1,d1
	dbra	d0,ice0d
	rts
ice0f:	lea	ice18(pc),a1
	moveq	#3,d2
ice10:	bsr	ice0a
	dbcc	d2,ice10
	moveq	#0,d4
	moveq	#0,d1
	move.b	1(a1,d2.w),d0
	ext.w	d0
	bmi	ice11
	bsr	ice0c
ice11:	move.b	6(a1,d2.w),d4
	add.w	d1,d4
	beq	ice13
	lea	ice19(pc),a1
	moveq	#1,d2
ice12:	bsr	ice0a
	dbcc	d2,ice12
	moveq	#0,d1
	move.b	1(a1,d2.w),d0
	ext.w	d0
	bsr	ice0c
	add.w	d2,d2
	add.w	6(a1,d2.w),d1
	bpl	ice15
	sub.w	d4,d1
	bra	ice15
ice13:	moveq	#0,d1
	moveq	#5,d0
	moveq	#-1,d2
	bsr	ice0a
	bcc	ice14
	moveq	#8,d0
	moveq	#$3f,d2
ice14:	bsr	ice0c
	add.w	d2,d1 
ice15:	lea	2(a6,d4.w),a1
	adda.w	d1,a1
	move.b	-(a1),-(a6)
ice16:	move.b	-(a1),-(a6)
	dbra	d4,ice16
	bra	ice06

	DC.B $7f,$ff,$00,$0e,$00,$ff,$00,$07
	DC.B $00,$07,$00,$02,$00,$03,$00,$01
	DC.B $00,$03,$00,$01
ice17:	DC.B $00,$00,$01,$0d,$00,$00,$00,$0e
	DC.B $00,$00,$00,$07,$00,$00,$00,$04
	DC.B $00,$00,$00,$01
ice18:	DC.B $09,$01,$00,$ff,$ff,$08,$04,$02
	DC.B $01,$00
ice19:	DC.B $0b,$04,$07,$00,$01,$1f,$ff,$ff
	DC.B $00,$1f
	even



		section data

viewscreen2:	dc.l	-1
viewscreen1:	dc.l	-1
memlist:
savemem1:	dc.l	0
savemem2:	dc.l	0
savemem3:	dc.l	0
graphmem:	dc.l	0
		dc.l	-1	;end of mem list flag

soundmem:	dc.l	0
howlong:	dc.l	0
handles:	dc.w	0
	even
mainscreen:	incbin	'main.raw'
	SECTION BSS
		ds.l	5000
mystack:	ds.l	1	;stacks go backwards
savepal:	ds.w	16
dummy:		ds.w	1
color:		ds.w	1
pixelx:		ds.w	1
pixely:		ds.w	1
savesp:		ds.l	1
time:		ds.l	1
frames:		ds.l	1
blitx:		ds.l	1
blity:		ds.l	1
picsource:	ds.l	1
expansion:	ds.w	1
oldmouse:	ds.l	1
whichpic:	ds.l	1
frame:		ds.l	1
whicheffect:	ds.l	1
oldvblvec:	ds.l	1
vblflag:	ds.w	1
savescreen:	ds.l	1
savescreen2:	ds.l	1
savemode:	ds.w	1
save114:	ds.l	1
mastervol:	ds.w	1
bufferword:	ds.w	1
what:		ds.w	1
samplesize:	ds.l	1
sgmem:		ds.l	1
ssmem:		ds.l	1
timer:		ds.l	1
fade:		ds.w	1
numcol:		ds.w	1
count:		ds.l	1
leftvol:	ds.w	1
rightvol:	ds.w	1
linea:		ds.l	1
	include	aeslib.s
	include	vdilib.s
	even
