offset:		equ	128
* 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
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

sw:	equ	384
sh:	equ	480
*****************************************************************
*	Falcon Slide Demo.					*
*	Version 1.0						*
*****************************************************************
	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

	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.w	$484,save484
	bclr	#0,$484

	bsr	setupdisk
	bsr	setupsound
	bsr	sfirst
	bsr	setupscreen
	bsr	dologo
	bsr	getfile		;put the first file up
	bsr	checkerfade
*	bsr	updownfade
	move.w	#0,whicheffect
mainloop:
	bsr	getfile
	lea	effectlist,a0
	move.w	whicheffect,d0
	asl.w	#2,d0
	move.l	(a0,d0.w),d0	;get effect for this time round
	bpl	effectok
	move.w	#0,whicheffect
	move.l	effectlist,d0
effectok:
	addq.w	#1,whicheffect
	move.l	d0,a0
	jsr	(a0)
	bsr	 keyboard
	bra	mainloop
	bra	exit

whicheffect:	dc.w	0
effectlist:
		dc.l	rollfade3
		dc.l	updownfade,rollfadevert1,interleavefade,rollfade2
		dc.l	checkerfade,rollfadevert2,hatchfade,rollfade1,-1
		dc.l	checkerfade,-1

finalname:	dc.b	'final.xxx',0
specialend:
	bsr	loadfinal
	jsr	rollfade3
	bsr	fadesound
waitend:
	move.w	#7,-(sp)
	trap	#1
	addq.l	#2,sp
	cmpi.b	#$11,d0
	bne	waitend
	swap	d0
	cmpi.b	#$10,d0
	bne	waitend
bp:
	bra	exit

fadesound:
	add.w	#$0010,mastervol
	cmpi.w	#$00f0,mastervol
	ble	.vok
	move.w	#%0000000000000000,-(sp)	;stop the sound
	move.w	#$88,-(sp)
	trap	#14
	addq.l	#4,sp
	rts
.vok
	bsr	setvol
	move.l	#300,d0
	bsr	delayticks
	bra	fadesound


loadfinal:
	move.w	#1,-(sp)
	move.l	#finalname,-(sp)
	move.w	#$3d,-(sp)
	trap	#1
	addq.l	#8,sp
	move.w	d0,handle

	pea	loadhere
	move.l	#18,-(sp)
	move.w	handle,-(sp)
	move.w	#$3f,-(sp)
	trap	#1
	add.l	#12,sp

	pea	targadata
	move.l	#368640,-(sp)
	move.w	handle,-(sp)
	move.w	#$3f,-(sp)
	trap	#1
	add.l	#12,sp

	move.w	handle,-(sp)	;close the file
	move.w	#$3e,-(sp)
	trap	#1
	addq.l	#4,sp
	bsr	converttarga
	rts

hatchfade:
	move.w	#384/4-1,d0
	move.l	screen1,source
	move.w	#0,sblocky
	move.w	#0,dblocky
	move.w	#2,width
	move.w	#480,height
	moveq	#0,d1
.ifloopb:
	move.w	d1,sblockx
	move.w	d1,dblockx
	movem.w	d0-d1,-(sp)
	bsr	putvblockd
	move.w	#2,d0
	bsr	delayticks
	movem.w	(sp)+,d0-d1
	addq.w	#4,d1
	dbf	d0,.ifloopb
*	move.w	#100,d0
*	bsr	delayticks

	move.w	#480/4-1,d0
	move.l	screen1,source
	move.w	#0,sblockx
	move.w	#0,dblockx
	move.w	#384,width
	move.w	#2,height
	moveq	#0,d1
.ifloopa:
	move.w	d1,sblocky
	move.w	d1,dblocky
	movem.w	d0-d1,-(sp)
	bsr	putvblockd
	move.w	#2,d0
	bsr	delayticks
	movem.w	(sp)+,d0-d1
	addq.w	#4,d1
	dbf	d0,.ifloopa
*	move.w	#100,d0
*	bsr	delayticks


	move.w	#384/4-1,d0
	move.l	screen1,source
	move.w	#0,sblocky
	move.w	#0,dblocky
	move.w	#1,width
	move.w	#480,height
	move	#382,d1
.ifloopd:
	move.w	d1,sblockx
	move.w	d1,dblockx
	movem.w	d0-d1,-(sp)
	bsr	putvblockd
	move.w	#2,d0
	bsr	delayticks
	movem.w	(sp)+,d0-d1
	subq.w	#4,d1
	dbf	d0,.ifloopd

	move.w	#480/4-1,d0
	move.l	screen1,source
	move.w	#0,sblockx
	move.w	#0,dblockx
	move.w	#384,width
	move.w	#2,height
	move	#478,d1
.ifloopc:
	move.w	d1,sblocky
	move.w	d1,dblocky
	movem.w	d0-d1,-(sp)
	bsr	putvblockd
	move.w	#2,d0
	bsr	delayticks
	movem.w	(sp)+,d0-d1
	subq.w	#4,d1
	dbf	d0,.ifloopc

*	move.w	#100,d0
*	bsr	delayticks

	rts


interleavefade:
	move.w	#480/4-1,d0
	move.l	screen1,source
	move.w	#0,sblockx
	move.w	#0,dblockx
	move.w	#384,width
	move.w	#2,height
	moveq	#0,d1
ifloop:
	move.w	d1,sblocky
	move.w	d1,dblocky
	movem.w	d0-d1,-(sp)
	bsr	putvblockd
	move.w	#2,d0
	bsr	delayticks
	movem.w	(sp)+,d0-d1
	addq.w	#4,d1
	dbf	d0,ifloop

	move.w	#20,d0
	bsr	delayticks

	move.w	#480/4-1,d0
	move.l	screen1,source
	move.w	#0,sblockx
	move.w	#0,dblockx
	move.w	#384,width
	move.w	#2,height
	move	#478,d1
.ifloop:
	move.w	d1,sblocky
	move.w	d1,dblocky
	movem.w	d0-d1,-(sp)
	bsr	putvblockd
	move.w	#2,d0
	bsr	delayticks
	movem.w	(sp)+,d0-d1
	subq.w	#4,d1
	dbf	d0,.ifloop

	rts
		

rollfadevert1:
	move.w	#0,stripy
	move.w	#480,stripheight
	move.l	screen1,source
	bsr	dostripv
	rts
rollfadevert2:
	move.w	#0,stripy
	move.w	#240,stripheight
	move.l	screen1,source
	bsr	dostripv
	move.w	#240,stripy
	move.w	#240,stripheight
	move.l	screen1,source
	bsr	dostripv
	rts

rollfade3:
	move.w	#0,stripx
	move.w	#384,stripwidth
	move.l	screen1,source
	bsr	dostrip
	rts

rollfade2:
	move.w	#0,stripx
	move.w	#192,stripwidth
	move.l	screen1,source
	bsr	dostrip
	move.w	#192,stripx
	move.w	#192,stripwidth
	move.l	screen1,source
	bsr	dostrip
	rts

rollfade1:
	move.w	#0,stripx
	move.w	#96,stripwidth
	move.l	screen1,source
	bsr	dostrip
	move.w	#96,stripx
	move.w	#96,stripwidth
	move.l	screen1,source
	bsr	dostrip
	move.w	#192,stripx
	move.w	#96,stripwidth
	move.l	screen1,source
	bsr	dostrip
	move.w	#288,stripx
	move.w	#96,stripwidth
	move.l	screen1,source
	bsr	dostrip
	rts


dostripv:
	move.w	stripy,sblocky
	move.w	stripy,dblocky
	move.w	stripheight,height
	move.w	#0,scrollx
	move.w	scrollx,sblockx		;put first block
	move.w	scrollx,dblockx
	move.w	#1,width
	bsr	putvblockdv
dstloopv:
	moveq	#59,d0
	move.w	scrollx,d1
	move.w	d1,d2
	add.w	#160,d1
	lea	clist,a1
.dloop:
	move.w	d2,dblockx
	move.w	d1,sblockx
	move.w	#1,width
	move.w	stripheight,height
	movem.l	d0-d2/a1,-(sp)
	bsr	putvblockdv
	movem.l	(sp)+,d0-d2/a1
	addq.w	#1,d2
	sub.w	(a1)+,d1
	dbf	d0,.dloop

	move.w	scrollx,sblockx		;put first block
	move.w	scrollx,dblockx
	move.w	stripheight,height
	move.w	#1,width
	bsr	putvblockdv

	addq.w	#1,scrollx
	cmpi.w	#383-60,scrollx
	ble	dstloopv

	move.w	#383,sblockx		;put first block
	move.w	#383,dblockx
	move.w	#1,width
	move.w	stripheight,height
	bsr	putvblockdv
	rts


dostrip:
	move.w	stripx,sblockx
	move.w	stripx,dblockx
	move.w	stripwidth,width
	move.w	#0,scrolly
	move.w	scrolly,sblocky		;put first block
	move.w	scrolly,dblocky
	move.w	#60,height
	bsr	putvblockd
dstloop:
	moveq	#59,d0
	move.w	scrolly,d1
	move.w	d1,d2
	add.w	#160,d1
	lea	clist,a1
.dloop:
	move.w	d2,dblocky
	move.w	d1,sblocky
	move.w	#1,height
	movem.l	d0-d2/a1,-(sp)
	bsr	putvblockd
	movem.l	(sp)+,d0-d2/a1
	addq.w	#1,d2
	sub.w	(a1)+,d1
	dbf	d0,.dloop

	move.w	scrolly,sblocky		;put first block
	move.w	scrolly,dblocky
	move.w	#1,height
	bsr	putvblockd

	addq.w	#1,scrolly
	cmpi.w	#479-60,scrolly
	ble	dstloop

	move.w	#479,sblocky		;put first block
	move.w	#479,dblocky
	move.w	#1,height
	bsr	putvblockd
	rts



clist:
	dc.w	6,5,4,4,3,3,3,2,2,2,2,2,2
	rept	36
	dc.w	1
	endr
	dc.w	2,2,2,2,2,2,2,2,2,4,4,5,6

scrolly:	dc.w	0
stripx:		dc.w	0
stripy:		dc.w	0
scrollx:	dc.w	0
stripwidth:	dc.w	0
stripheight:	dc.w	0


checkerfade:
	lea	checkerlist,a0
	move.l	screen1,source
cfloop:
	moveq	#0,d0
	move.w	(a0)+,d0
	bmi	cfover
	bsr	delayticks
	move.w	(a0),sblockx
	move.w	2(a0),sblocky
	move.w	(a0)+,dblockx
	move.w	(a0)+,dblocky
	move.w	(a0)+,width
	move.w	(a0)+,height
	move.l	a0,-(sp)
	bsr	putvblockd
	move.l	(sp)+,a0
	bra	cfloop
cfover:
	rts

delayticks:
	move.l	$4ba,d1
dltl:
	move.l	$4ba,d2
	sub.l	d1,d2
	cmp.l	d0,d2
	blt	dltl
	rts

checkerlist:
	dc.w	20
	dc.w	0,0,96,120
	dc.w	20
	dc.w	192,0,96,120
	dc.w	20
	dc.w	96,120,96,120
	dc.w	20
	dc.w	288,120,96,120
	dc.w	20
	dc.w	0,240,96,120
	dc.w	20
	dc.w	192,240,96,120
	dc.w	20
	dc.w	96,360,96,120
	dc.w	20
	dc.w	288,360,96,120
	dc.w	100
	dc.w	96,0,96,120
	dc.w	20
	dc.w	288,0,96,120
	dc.w	20
	dc.w	0,120,96,120
	dc.w	20
	dc.w	192,120,96,120
	dc.w	20
	dc.w	96,240,96,120
	dc.w	20
	dc.w	288,240,96,120
	dc.w	20
	dc.w	0,360,96,120
	dc.w	20
	dc.w	192,360,96,120
	dc.w	-1


updownfade:
	move.l	screen1,source
	move.w	#384,width
	move.w	#480,height
	move.w	#0,sblockx
	move.w	#0,sblocky
	move.w	#0,dblockx
	move.w	#0,dblocky
	bsr	puttblockd

	move.l	screen1,source
	move.w	#384,width
	move.w	#480,height
	move.w	#0,sblockx
	move.w	#0,sblocky
	move.w	#0,dblockx
	move.w	#0,dblocky
	bsr	puttblocku

	move.l	screen1,source
	move.w	#384,width
	move.w	#480,height
	move.w	#0,sblockx
	move.w	#0,sblocky
	move.w	#0,dblockx
	move.w	#0,dblocky
	bsr	puttblockd

	move.l	screen1,source
	move.w	#384,width
	move.w	#480,height
	move.w	#0,sblockx
	move.w	#0,sblocky
	move.w	#0,dblockx
	move.w	#0,dblocky
	bsr	puttblocku

	move.l	screen1,source
	move.w	#384,width
	move.w	#480,height
	move.w	#0,sblockx
	move.w	#0,sblocky
	move.w	#0,dblockx
	move.w	#0,dblocky
	bsr	puttblockd

	move.l	screen1,source
	move.w	#384,width
	move.w	#480,height
	move.w	#0,sblockx
	move.w	#0,sblocky
	move.w	#0,dblockx
	move.w	#0,dblocky
	bsr	putvblocku
	rts

*********************************************************
*	General transparent block routine		*
*	goes down					*
*	Set:						*
*		sBlockx					*
*		sblocky					*
*		dBlockx					*
*		dblocky					*
*		source					*
*		width					*
*		height					*
*********************************************************
puttblockd:
	move.l	source,a0
	move.l	viewscreen,a1
	moveq	#0,d0
	moveq	#0,d1
	move.w	sblockx,d0	;x
	move.w	sblocky,d1	;y
	add.l	d0,d0
	move.l	d1,d3
	mulu	#sw*2,d3
	add.l	d0,d3
	add.l	d3,a0

	moveq	#0,d0
	moveq	#0,d1
	move.w	dblockx,d0	;x
	move.w	dblocky,d1	;y
	add.l	d0,d0
	move.l	d1,d3
	mulu	#sw*2,d3
	add.l	d0,d3
	add.l	d3,a1



	move.w	height,d0
	subq.w	#1,d0
	move.l	a0,a2
	move.l	a1,a3
pbloop:
	move.w	d0,-(sp)
	move.w	width,d1
	subq.w	#1,d1
pbloop2:
	move.w	d1,-(sp)
	move.w	(a0)+,d0
	move.w	d0,d1
	move.w	d1,d2
	moveq	#0,d3
	and.w	#%0000000000011111,d0
	and.w	#%0000011111000000,d1
	lsr.w	#6,d1
	and.w	#%1111100000000000,d2
	lsr.w	#8,d2
	lsr.w	#3,d2

	move.w	(a1),d4
	move.w	d4,d5
	move.w	d5,d6
	moveq	#0,d7
	and.w	#%0000000000011111,d4
	and.w	#%0000011111000000,d5
	lsr.w	#6,d5
	and.w	#%1111100000000000,d6
	lsr.w	#8,d6
	lsr.w	#3,d6

	add.w	d2,d6
	lsr.w	#1,d6
	add.w	d1,d5
	lsr.w	#1,d5
	add.w	d0,d4
	lsr.w	#1,d4
	lsl.w	#8,d6
	lsl.w	#3,d6
	lsl.w	#6,d5

	or.w	d5,d6
	or.w	d4,d6
	move.w	d6,(a1)+
	move.w	(sp)+,d1
	dbf	d1,pbloop2
	lea	sw*2(a2),a2
	lea	sw*2(a3),a3
	move.l	a2,a0
	move.l	a3,a1

	move.w	(sp)+,d0
	dbf	d0,pbloop
	rts

*********************************************************
*	General transparent block routine		*
*	goes down	2				*
*	Set:						*
*		sBlockx					*
*		sblocky					*
*		dBlockx					*
*		dblocky					*
*		source					*
*		width					*
*		height					*
*********************************************************
puttblockd2:
	cmpi.w	#479,sblocky
	ble	.ok
	move.w	dblockx,sblockx
	move.w	dblocky,sblocky
	bra	putvblockd
.ok:
	move.l	source,a0
	move.l	viewscreen,a1
	move.l	screen1,a4
	moveq	#0,d0
	moveq	#0,d1
	move.w	sblockx,d0	;x
	move.w	sblocky,d1	;y
	add.l	d0,d0
	move.l	d1,d3
	mulu	#sw*2,d3
	add.l	d0,d3
	add.l	d3,a0

	moveq	#0,d0
	moveq	#0,d1
	move.w	dblockx,d0	;x
	move.w	dblocky,d1	;y
	add.l	d0,d0
	move.l	d1,d3
	mulu	#sw*2,d3
	add.l	d0,d3
	add.l	d3,a1
	add.l	d3,a4

	move.w	height,d0
	subq.w	#1,d0
	move.l	a0,a2
	move.l	a1,a3
	move.l	a4,a5



.pbloop:
	move.w	d0,-(sp)
	move.w	width,d1
	subq.w	#1,d1
.pbloop2:
	move.w	d1,-(sp)
	move.w	(a0)+,d0
	move.w	d0,d1
	move.w	d1,d2
	moveq	#0,d3
	and.w	#%0000000000011111,d0
	and.w	#%0000011111000000,d1
	lsr.w	#6,d1
	and.w	#%1111100000000000,d2
	lsr.w	#8,d2
	lsr.w	#3,d2

	move.w	(a4)+,d4
	move.w	d4,d5
	move.w	d5,d6
	moveq	#0,d7
	and.w	#%0000000000011111,d4
	and.w	#%0000011111000000,d5
	lsr.w	#6,d5
	and.w	#%1111100000000000,d6
	lsr.w	#8,d6
	lsr.w	#3,d6
	add.w	d2,d6
	lsr.w	#1,d6
	add.w	d1,d5
	lsr.w	#1,d5
	add.w	d0,d4
	lsr.w	#1,d4
	lsl.w	#8,d6
	lsl.w	#3,d6
	lsl.w	#6,d5
	or.w	d5,d6
	or.w	d4,d6
	move.w	d6,(a1)+
	move.w	(sp)+,d1
	dbf	d1,.pbloop2
	lea	sw*2(a2),a2
	lea	sw*2(a3),a3
	lea	sw*2(a5),a5
	move.l	a2,a0
	move.l	a3,a1
	move.l	a5,a4

	move.w	(sp)+,d0
	dbf	d0,.pbloop
	rts


*********************************************************
*	General transparent block routine		*
*	goes up						*
*	Set:						*
*		Blockx					*
*		blocky					*
*		source					*
*		width					*
*		height					*
*********************************************************
puttblocku:
	move.w	sblockx,d0	;x
	move.w	sblocky,d1	;y
	move.l	source,a0
	move.l	viewscreen,a1
	move.w	d0,d2
	add.w	d2,d2
	move.w	d1,d3
	moveq	#0,d4
	move.w	height,d4
	subq.w	#1,d4
	mulu	#sw*2,d4
	mulu	#sw*2,d3
	add.w	d2,d3
	add.l	d3,a1
	add.l	d4,a1
	add.l	d3,a0
	add.l	d4,a0
	move.w	height,d0
	subq.w	#1,d0
	move.l	a0,a2
	move.l	a1,a3
.pbloop:
	move.w	d0,-(sp)
	move.w	width,d1
	subq.w	#1,d1
.pbloop2:
	move.w	d1,-(sp)
	move.w	(a0)+,d0
	move.w	d0,d1
	move.w	d1,d2
	moveq	#0,d3
	and.w	#%0000000000011111,d0
	and.w	#%0000011111000000,d1
	lsr.w	#6,d1
	and.w	#%1111100000000000,d2
	lsr.w	#8,d2
	lsr.w	#3,d2

	move.w	(a1),d4
	move.w	d4,d5
	move.w	d5,d6
	moveq	#0,d7
	and.w	#%0000000000011111,d4
	and.w	#%0000011111000000,d5
	lsr.w	#6,d5
	and.w	#%1111100000000000,d6
	lsr.w	#8,d6
	lsr.w	#3,d6
	add.w	d2,d6
	lsr.w	#1,d6
	add.w	d1,d5
	lsr.w	#1,d5
	add.w	d0,d4
	lsr.w	#1,d4
	lsl.w	#8,d6
	lsl.w	#3,d6
	lsl.w	#6,d5
	or.w	d5,d6
	or.w	d4,d6
	move.w	d6,(a1)+
	move.w	(sp)+,d1
	dbf	d1,.pbloop2
	lea	-(sw*2)*1(a2),a2
	lea	-(sw*2)*1(a3),a3
	move.l	a2,a0
	move.l	a3,a1

	move.w	(sp)+,d0
	dbf	d0,.pbloop
	rts

*********************************************************
*	General vanilla block routine			*
*	goes down					*
*	Set:						*
*		sBlockx					*
*		sblocky					*
*		dBlockx					*
*		dblocky					*
*		source					*
*		width					*
*		height					*
*********************************************************
putvblockd:
	cmpi.w	#480,sblocky
	ble	.ok
	move.w	dblockx,sblockx
	move.w	dblocky,sblocky
.ok:
	move.l	source,a0
	move.l	source,a0
	move.l	viewscreen,a1
	moveq	#0,d0
	moveq	#0,d1
	move.w	sblockx,d0	;x
	move.w	sblocky,d1	;y
	add.l	d0,d0
	move.l	d1,d3
	mulu	#sw*2,d3
	add.l	d0,d3
	add.l	d3,a0

	moveq	#0,d0
	moveq	#0,d1
	move.w	dblockx,d0	;x
	move.w	dblocky,d1	;y
	add.l	d0,d0
	move.l	d1,d3
	mulu	#sw*2,d3
	add.l	d0,d3
	add.l	d3,a1	;at this stage a0 is source ad and a1 dest

	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	#sw*2,d0
	move.w	width,d1
	subq.w	#1,d1
	add.w	d1,d1
	sub.w	d1,d0
	move.w	d0,src_yinc(a6)
	move.w	d0,dst_yinc(a6)
	move.w	width,x_count(a6)
	move.w	height,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)
	rts

*********************************************************
*	General vanilla block routine			*
*	goes down					*
*	Set:						*
*		sBlockx					*
*		sblocky					*
*		dBlockx					*
*		dblocky					*
*		source					*
*		width					*
*		height					*
*********************************************************
putvblockdv:
	cmpi.w	#384,sblockx
	ble	.ok
	move.w	dblockx,sblockx
	move.w	dblocky,sblocky
.ok:
	move.l	source,a0
	move.l	source,a0
	move.l	viewscreen,a1
	moveq	#0,d0
	moveq	#0,d1
	move.w	sblockx,d0	;x
	move.w	sblocky,d1	;y
	add.l	d0,d0
	move.l	d1,d3
	mulu	#sw*2,d3
	add.l	d0,d3
	add.l	d3,a0

	moveq	#0,d0
	moveq	#0,d1
	move.w	dblockx,d0	;x
	move.w	dblocky,d1	;y
	add.l	d0,d0
	move.l	d1,d3
	mulu	#sw*2,d3
	add.l	d0,d3
	add.l	d3,a1	;at this stage a0 is source ad and a1 dest

	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	#sw*2,d0
	move.w	width,d1
	subq.w	#1,d1
	add.w	d1,d1
	sub.w	d1,d0
	move.w	d0,src_yinc(a6)
	move.w	d0,dst_yinc(a6)
	move.w	width,x_count(a6)
	move.w	height,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)
	rts
	






	move.w	height,d0
	subq.w	#1,d0
	move.l	a0,a2
	move.l	a1,a3
.pbloop:
	move.w	d0,-(sp)
	move.w	width,d1
	subq.w	#1,d1
.pbloop2:
	move.w	d1,-(sp)
	move.w	(a0)+,(a1)+
	move.w	(sp)+,d1
	dbf	d1,.pbloop2

	lea	sw*2(a2),a2
	lea	sw*2(a3),a3
	move.l	a2,a0
	move.l	a3,a1
	move.w	(sp)+,d0
	dbf	d0,.pbloop
	rts

*********************************************************
*	General vanilla block routine			*
*	goes up						*
*	Set:						*
*		sBlockx					*
*		sblocky					*
*		dBlockx					*
*		dblocky					*
*		source					*
*		width					*
*		height					*
*********************************************************
putvblocku:
	moveq	#0,d0
	moveq	#0,d1
	move.w	sblockx,d0	;x
	move.w	sblocky,d1	;y
	move.l	source,a0
	move.l	viewscreen,a1
	move.l	d0,d2
	add.l	d2,d2
	move.l	d1,d3
	moveq	#0,d4
	move.w	height,d4
	subq.w	#1,d4
	mulu	#sw*2,d4
	mulu	#sw*2,d3
	add.l	d2,d3
	add.l	d3,a1
	add.l	d4,a1
	add.l	d3,a0
	add.l	d4,a0






	move.w	height,d0
	subq.w	#1,d0
	move.l	a0,a2
	move.l	a1,a3
.pbloop:
	move.w	d0,-(sp)
	move.w	width,d1
	subq.w	#1,d1
.pbloop2:
	move.w	d1,-(sp)
	move.w	(a0)+,(a1)+
	move.w	(sp)+,d1
	dbf	d1,.pbloop2

	lea	-(sw*2)*1(a2),a2
	lea	-(sw*2)*1(a3),a3
	move.l	a2,a0
	move.l	a3,a1
	move.w	(sp)+,d0
	dbf	d0,.pbloop
	rts


waitkey:
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	rts

keyboard:
	move.w	#$ff,-(sp)
	move.w	#$6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0
	beq	keyback
	swap	d0
quit:
*	cmp.b	#$10,d0		;Q
*	bne	f1
*	beq	exit
f1:
	cmp.b	#$3b,d0		;Q
	bne	uparrow
	addq.l	#4,sp		;remove return address
	bra	specialend
uparrow:
	cmpi.b	#$50,d0
	bne	downarrow
	add.w	#$0010,mastervol
	cmpi.w	#$00f0,mastervol
	ble	.vok
	move.w	#$00f0,mastervol
.vok
	bsr	setvol
	rts
downarrow:
	cmpi.b	#$48,d0
	bne	keyback
	sub.w	#$0010,mastervol
	cmpi.w	#$0010,mastervol
	bge	.vok
	move.w	#$0010,mastervol
.vok
	bsr	setvol
	rts

keyback:
	rts
mastervol:	dc.w	0
savemema:	dc.l	-1
savememb:	dc.l	-1
savememc:	dc.l	-1
savemem3:	dc.l	0
savemem3a:	dc.l	-1
handles:	dc.w	0
howlong:	dc.l	0
soundpattern:	dc.b	'sample.trk',0
	even
setupsound:
	move.w	#$01,-(sp)	;read only
	pea	soundpattern	;get the info for sample.trk
	move.w	#$4e,-(sp)
	trap	#1
	addq.l	#8,sp
	tst.w	d0
	bmi	nosounds	;no sample found 


	move.l	dta+26,d0	;get file length
	addq.l	#4,d0

	move.l	d0,-(sp)	;malloc sample size mem
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	nosounds

	move.l	d0,savemem3a
	add.l	#4,d0
	and.l	#$fffffffc,d0
	move.l	d0,savemem3

	move.w	#1,-(sp)
	move.l	#dta+30,-(sp)	;read in the sound
	move.w	#$3d,-(sp)
	trap	#1
	addq.l	#8,sp
	move.w	d0,handles

	move.l	savemem3,-(sp)
	move.l	dta+26,-(sp)
	move.w	handles,-(sp)
	move.w	#$3f,-(sp)
	trap	#1
	add.l	#12,sp
	move.l	d0,howlong

	move.w	handles,-(sp)	;close the file
	move.w	#$3e,-(sp)
	trap	#1
	addq.l	#4,sp

	move.w	#$80,-(sp)		;lock the sound system
	trap	#14
	addq.l	#2,sp

	move.w	#1,-(sp)		;setmode 16bit Stereo
	move.w	#$84,-(sp)
	trap	#14
	addq.l	#4,sp

	move.w	#0,-(sp)	;rectracks
	move.w	#1,-(sp)	;playtracks
	move.w	#$85,-(sp)	;set tracks
	trap	#14
	addq.l	#6,sp

	move.w	#1,-(sp)	;disable handshaking
	move.w	#3,-(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.l	savemem3,d0
	add.l	howlong,d0
	move.l	d0,-(sp)	;endaddress
	move.l	savemem3,d0
	add.l	#offset,d0
	move.l	d0,-(sp)	;start address
	move.w	#0,-(sp)	;playback
	move.w	#$83,-(sp)	;setbuffer
	trap	#14
	add.l	#12,sp
	move.w	#$0050,mastervol
	bsr	setvol

	move.w	#%0000000000000011,-(sp)	;play once
	move.w	#$88,-(sp)
	trap	#14
	addq.l	#4,sp

nosounds:
	rts

removesound:
	tst.l	savemem3a
	bmi	skrs
	move.l	savemem3a,d0
	bsr	deallocate
	move.w	#%0000000000000000,-(sp)	;stop the sound
	move.w	#$88,-(sp)
	trap	#14
	addq.l	#4,sp
	move.w	#$81,-(sp)		;unlock the sound system
	trap	#14
	addq.l	#2,sp
skrs:
	rts
	
setvol:
	move.w	mastervol,-(sp)
	move.w	#0,-(sp)	;ltatten
	move.w	#$82,-(sp)
	trap	#14
	addq.l	#6,sp

	move.w	mastervol,-(sp)
	move.w	#1,-(sp)	;rtatten
	move.w	#$82,-(sp)
	trap	#14
	addq.l	#6,sp
	rts

*********************************************************
*	Gets the current file, loads in the first	*
*	18 bytes, checks resolution and if OK loads	*
*	it all in. Then converts it to XGA format.	*
*	and stores it in screen1			*
*********************************************************
getfile:
	lea	dta,a0
	lea	30(a0),a0	;get filename

	move.w	#1,-(sp)
	move.l	a0,-(sp)
	move.w	#$3d,-(sp)
	trap	#1
	addq.l	#8,sp
	move.w	d0,handle

	pea	loadhere
	move.l	#18,-(sp)
	move.w	handle,-(sp)
	move.w	#$3f,-(sp)
	trap	#1
	add.l	#12,sp

	lea	loadhere,a0
	move.b	13(a0),d0
	asl.w	#8,d0
	move.b	12(a0),d0	;get width
	cmpi.w	#sw,d0
	bne	getnext
	move.b	15(a0),d0
	asl.w	#8,d0
	move.b	14(a0),d0	;get width
	cmpi.w	#sh,d0
	bne	getnext

	pea	targadata
	move.l	#368640,-(sp)
	move.w	handle,-(sp)
	move.w	#$3f,-(sp)
	trap	#1
	add.l	#12,sp

	move.w	handle,-(sp)	;close the file
	move.w	#$3e,-(sp)
	trap	#1
	addq.l	#4,sp
	bsr	snext
	bsr	converttarga
	rts

getnext:
	move.w	handle,-(sp)	;close the file
	move.w	#$3e,-(sp)
	trap	#1
	addq.l	#4,sp
	bsr	snext
	bra	getfile
	

*********************************************************
*	Sets the disk transfer address and calls sfirst	*
*********************************************************
setupdisk:
	move.w	#$2f,-(sp)
	trap	#1
	addq.l	#2,sp
	move.l	d0,savedta

	pea	dta
	move.w	#$1a,-(sp)	;set disk transfer address
	trap	#1
	addq.l	#6,sp


	rts
sfirst:
	move.w	#$01,-(sp)	;read only
	pea	pattern
	move.w	#$4e,-(sp)
	trap	#1
	addq.l	#8,sp
	tst.w	d0
	bmi	exit
	rts
snext:
	move.w	#$4f,-(sp)
	trap	#1
	addq.l	#2,sp
	tst.w	d0
	bne	sfirst
	rts


exit:
	move.w	save484,$484
	bsr	removesound
	tst.l	savemema
	bmi	skipdm1
	move.l	savemema,d0
	bsr	deallocate
skipdm1:
	tst.l	savememb
	bmi	skipdm2
	move.l	savememb,d0
	bsr	deallocate
skipdm2:
	tst.l	savememc
	bmi	skipdm3
	move.l	savememc,d0
	bsr	deallocate
skipdm3:
	move.l	savesp,-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq.l	#6,sp

	move.w	savemode,-(sp)
	move.w	#88,-(sp)
	trap	#14
	addq.l	#4,sp

	move.w	#-1,-(sp)
	move.l	savescreen,-(sp)
	move.l	savescreen,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp

	move.l	savedta,-(sp)
	move.w	#$1a,-(sp)	;set disk transfer address
	trap	#1
	addq.l	#6,sp

	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
	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*2)*sh)+4+((sw*2)*100),-(sp)	;thats 1 screen size
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	exit
	and.l	#$fffffffc,d0
	move.l	d0,viewscreen
	move.l	d0,a0
	bsr	clearmem

	move.l	#((sw*2)*sh)+4+((sw*2)*100),-(sp)	;thats 1 screen size
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	exit
	and.l	#$fffffffc,d0
	move.l	d0,screen1


	move.l	#((sw*2)*sh)+4+((sw*2)*100),-(sp)	;thats 1 screen size
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	exit
	and.l	#$fffffffc,d0
	move.l	d0,screen2

	move.w	#2,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,savescreen

	move.w	#-1,-(sp)
	move.l	viewscreen,-(sp)
	move.l	viewscreen,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp

	move.w	#overscan|vertflag|col40|bps16,-(sp)
	move.w	#88,-(sp)
	trap	#14
	addq.l	#4,sp
	move.w	d0,savemode

	move.l	#0,$ffff9800
	rts





viewscreen:	dc.l	-1
screen1:	dc.l	-1
screen2:	dc.l	-1



converttarga:
	move.l	screen1,a1
	add.l	#368640,a1
	lea	targadata,a0
	move	#sh,d0
	subq.w	#1,d0
	sub.l	#sw*2,a1
.dsloop:
	rept	sw
	move.b	1(a0),d1
	lsl.w	#8,d1
	lsl.w	#1,d1
	moveq	#0,d2
	move.b	(a0),d2
	move.l	d2,d3
	and.b	#%11100000,d2
	lsl.w	#1,d2
	and.b	#%00011111,d3
	or.b	d3,d2
	or.w	d2,d1

	addq.l	#2,a0
	move.w	d1,(a1)+
	endr
	sub.l	#(sw*2)*2,a1
	dbf	d0,.dsloop
	rts

dologo:
	lea	mylogo,a0
	move.l	viewscreen,a1
	jsr	ice_unpack
	move.w	#100,d0
	bsr	delayticks
	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	ice03			; 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:
	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
pattern:	dc.b	'*.TGA',0
	even
mylogo:
	incbin	'logo.img'
	even


	SECTION BSS
		ds.l	1000
mystack:	ds.w	1	;stacks go backwards
svft:	ds.w	1
svss:	ds.w	1
svbb:	ds.w	1
svbe:	ds.w	1
svdb:	ds.w	1
svde:	ds.w	1
shht:	ds.w	1
shss:	ds.w	1
shbb:	ds.w	1
shbe:	ds.w	1
shdb:	ds.w	1
shde:	ds.w	1
shfs:	ds.w	1
shee	ds.w	1
sst_shift:	ds.w	1
ssp_shift:	ds.w	1
svco:	ds.w	1
svwrap:	ds.w	1
savescreen:	ds.l	1
svid_bh:	ds.w	1
svid_bm:	ds.w	1
svid_bl:	ds.w	1
savepal:	ds.w	16
savemode:	ds.w	1
dummy:		ds.w	1
savesp:		ds.l	1
dta:		ds.b	44
savedta:	ds.l	1
dblockx:		ds.w	1
dblocky:		ds.w	1
sblockx:	ds.w	1
sblocky:	ds.w	1
source:		ds.l	1
width:		ds.w	1
height:		ds.w	1
handle:		ds.w	1
save484:	ds.w	1
		ds.w	200
loadhere:
		ds.b	18
targadata:
		ds.b	((sw*2)*sh)

