
extern_lib	macro
	xref	_lvo\1
	endm
structure	macro
\1	equ	0
soffset	set	\2
	endm
bool	macro
\1	equ	soffset
soffset	set	soffset+2
	endm
byte	macro
\1	equ	soffset
soffset	set	soffset+1
	endm
ubyte	macro
\1	equ	soffset
soffset	set	soffset+1
	endm
word	macro
\1	equ	soffset
soffset	set	soffset+2
	endm
uword	macro
\1	equ	soffset
soffset	set	soffset+2
	endm
short	macro
\1	equ	soffset
soffset	set	soffset+2
	endm
ushort	macro
\1	equ	soffset
soffset	set	soffset+2
	endm
long	macro
\1	equ	soffset
soffset	set	soffset+4
	endm
ulong	macro
\1	equ	soffset
soffset	set	soffset+4
	endm
float	macro
\1	equ	soffset
soffset	set	soffset+4
	endm
aptr	macro
\1	equ	soffset
soffset	set	soffset+4
	endm
cptr	macro
\1	equ	soffset
soffset	set	soffset+4
	endm
rptr	macro
\1	equ	soffset
soffset	set	soffset+2
	endm
struct	macro
\1	equ	soffset
soffset	set	soffset+\2
	endm
label	macro
\1	equ	soffset
	endm
bitdef	macro
	bitdef0	\1,\2,b_,\3
\@bitdef	set	1<<\3
	bitdef0	\1,\2,f_,\@bitdef
	endm
bitdef0	macro
\1\3\2	equ	\4
	endm
library_version	equ	33

      structure	bitmapheader,0
      uword	_w
      uword	_h
      word	_x
      word	_y
      ubyte	_nplanes
      ubyte	_masking
      ubyte	_compression
      ubyte	_pad1
      uword	_transparentcolor
      ubyte	_xaspect
      ubyte	_yaspect
      word	_pagewidth
      word	_pageheight
      label	_sizeof

iea:	equ	$fffa07
ieb:	equ	$fffa09
isra:	equ	$fffa0f
ima:	equ	$fffa13
tbcr:	equ	$fffa1b
tbdr:	equ	$fffa21
vbl_vec:	equ	$70
key_vec:	equ	$118
hbl_vec:	equ	$120
magic:		equ	1650
numstars:	equ	12
speed:		equ	350
zclip:		equ	100
start:
	dc.w	$a00a
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
        move.l  D0,savesup
	move.l	$426,rvsave
	move.l	$42a,resave
	move.w	#4,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	d0,ressave
	lea	palsave,a0
	move.l	#$ff8240,a1
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+

	pea	credtext
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp

	move.l	#4000000,d7
	jsr	generaldelay


	jsr	getscrn
	move.w	#0,-(sp)	;set to low res
	move.l	seen,-(sp)
	move.l	seen,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp

	move.l	#500000,d7
	bsr	generaldelay
	move.l	#12345,d0
	jsr	randomseed
	lea	framevbl,a1
	jsr	putvbl
	move.l	a0,oldvbl1
	jsr	savemfp

	jsr	setupdisk
	bsr	mouseoff
	move.l	#100000,howlong
mainloop:
	jsr	keyboard
	move.w	#-1,vblcol
	jsr	restoremfp
	jsr	getlast
	jsr	loadscr2
	move.l	#5000,d7
	bsr	generaldelay
	jsr	mydocolors
	jsr	getnextfile
	lea	effectlist,a0
	addq.w	#1,whicheffect
	cmpi.w	#13,whicheffect
	ble	iok
	move.w	#0,whicheffect
iok:	move.w	whicheffect,d0
	asl.w	#2,d0
	move.l	(a0,d0.w),a0
	jmp	(a0)

whicheffect:	dc.w	0
effectlist:
	dc.l	fadeffect
	dc.l	fadeupeffect,staticeffect
	dc.l	boxescheffect
	dc.l	rolleffect,boxeseffect
	dc.l	fadedowneffect
	dc.l	slideffect2,boxesudeffect,slideffect
	dc.l	rolleffect,boxesspeffect
	dc.l	fadeffect
	dc.l	stretcheffect
******************************
mouseoff:
	move.l	#moff,-(sp)
	clr.w	-(sp)
	move.w	#25,-(sp)
	trap	#14
	addq.l	#8,sp
	rts
mouseon:
	move.l	#mon,-(sp)
	clr.w	-(sp)
	move.w	#25,-(sp)
	trap	#14
	addq.l	#8,sp
	rts

mon:	dc.b	$08
moff:	dc.b	$12
	even

*****************************************
clearseen:
	move.l	seen,a0
	move.w	#8000,d0
clsl:
	move.l	#0,(a0)+
	dbf	d0,clsl
	rts
rowy:		dc.w	0
whichscreen:	dc.l	0
*****************************************
fadedowneffect:
	move.w	#1,vblcol
	jsr	setuphbl3
	move.w	#0,scrolly
	move.l	hiden,a5
	move.l	seen,a6
fdedl:
	bsr	fcopyline
	lea	160(a5),a5
	lea	160(a6),a6
	move.l	#4000,d7
	bsr	generaldelay
*	move.w	#37,-(sp)
*	trap	#14
*	addq.l	#2,sp
	addq.w	#1,scrolly
	cmpi.w	#199,scrolly
	ble	fdedl
	bra	mainloop

fadeupeffect:
	move.w	#2,vblcol
	jsr	setuphbl4
	move.w	#199,scrolly
	move.l	hiden,a5
	move.l	seen,a6
	add.l	#32000-160,a6
	add.l	#32000-160,a5
fdedu:
	bsr	fcopyline
*	subi.l	#160,a5
	lea	-160(a5),a5
	lea	-160(a6),a6
*	subi.l	#160,a6
	move.l	#4000,d7
	bsr	generaldelay
*	move.w	#37,-(sp)
*	trap	#14
*	addq.l	#2,sp
	subq.w	#1,scrolly
	bpl	fdedu
	bra	mainloop


fcopyline:
	move.l	a5,a0
	move.l	a6,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	rts
d1save:	dc.w	0
*****************************************
staticeffect:
	move.l	#12000,d7
	move.l	seen,a0
	move.l	a0,a1
	lea	8000(a1),a1
	move.l	a1,a2
	lea	8000(a2),a2
	move.l	a2,a3
	lea	8000(a3),a3
stl:
*	move.l	d7,-(sp)
	move.w	#16,d0
	bsr	randomplus
	move.w	#%1111111111111100,d1
	rol.w	d0,d1
	move.w	#1000,d0
	bsr	randomplus
	asl.w	#3,d0
	move.w	d0,d2
	add.w	#160,d2
	and.w	d1,0(a0,d0.w)
	and.w	d1,2(a0,d0.w)
	and.w	d1,4(a0,d0.w)
	and.w	d1,6(a0,d0.w)
	and.w	d1,0(a1,d0.w)
	and.w	d1,2(a1,d0.w)
	and.w	d1,4(a1,d0.w)
	and.w	d1,6(a1,d0.w)
	and.w	d1,0(a2,d0.w)
	and.w	d1,2(a2,d0.w)
	and.w	d1,4(a2,d0.w)
	and.w	d1,6(a2,d0.w)
	and.w	d1,0(a3,d0.w)
	and.w	d1,2(a3,d0.w)
	and.w	d1,4(a3,d0.w)
	and.w	d1,6(a3,d0.w)
	and.w	d1,0(a0,d2.w)
	and.w	d1,2(a0,d2.w)
	and.w	d1,4(a0,d2.w)
	and.w	d1,6(a0,d2.w)
	and.w	d1,0(a1,d2.w)
	and.w	d1,2(a1,d2.w)
	and.w	d1,4(a1,d2.w)
	and.w	d1,6(a1,d2.w)
	and.w	d1,0(a2,d2.w)
	and.w	d1,2(a2,d2.w)
	and.w	d1,4(a2,d2.w)
	and.w	d1,6(a2,d2.w)
	and.w	d1,0(a3,d2.w)
	and.w	d1,2(a3,d2.w)
	and.w	d1,4(a3,d2.w)
	and.w	d1,6(a3,d2.w)
	subq.l	#1,d7
	bpl	stl
	bsr	fadeto
	bsr	clearseen
	bsr	fadein
	move.l	#15000,d7
	move.l	hiden,a1
	move.l	a1,a5
	move.l	seen,a0
	move.l	a0,a2
	lea	8000(a2),a2
	move.l	a2,a3
	lea	8000(a3),a3
	move.l	a3,a4
	lea	8000(a4),a4
stl2:
	move.w	#%0000000000000011,d1
	move.w	#16,d0
	bsr	randomplus
	rol.w	d0,d1
	move.w	#1000,d0
	bsr	randomplus
	asl.w	#3,d0
	move.w	d0,d3
	add.w	#160,d3

	move.w	0(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,0(a0,d0.w)
	move.w	2(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,2(a0,d0.w)
	move.w	4(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,4(a0,d0.w)
	move.w	6(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,6(a0,d0.w)

	move.w	0(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,0(a0,d3.w)
	move.w	2(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,2(a0,d3.w)
	move.w	4(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,4(a0,d3.w)
	move.w	6(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,6(a0,d3.w)

	lea	8000(a1),a1

	move.w	0(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,0(a2,d0.w)
	move.w	2(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,2(a2,d0.w)
	move.w	4(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,4(a2,d0.w)
	move.w	6(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,6(a2,d0.w)

	move.w	0(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,0(a2,d3.w)
	move.w	2(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,2(a2,d3.w)
	move.w	4(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,4(a2,d3.w)
	move.w	6(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,6(a2,d3.w)

	lea	8000(a1),a1
	move.w	0(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,0(a3,d0.w)
	move.w	2(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,2(a3,d0.w)
	move.w	4(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,4(a3,d0.w)
	move.w	6(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,6(a3,d0.w)

	move.w	0(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,0(a3,d3.w)
	move.w	2(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,2(a3,d3.w)
	move.w	4(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,4(a3,d3.w)
	move.w	6(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,6(a3,d3.w)

	lea	8000(a1),a1
	move.w	0(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,0(a4,d0.w)
	move.w	2(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,2(a4,d0.w)
	move.w	4(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,4(a4,d0.w)
	move.w	6(a1,d0.w),d2
	and.w	d1,d2
	or.w	d2,6(a4,d0.w)

	move.w	0(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,0(a4,d3.w)
	move.w	2(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,2(a4,d3.w)
	move.w	4(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,4(a4,d3.w)
	move.w	6(a1,d3.w),d2
	and.w	d1,d2
	or.w	d2,6(a4,d3.w)
	move.l	a5,a1
	subq.l	#1,d7
	bpl	stl2
	bsr	copyhtos
	move.l	howlong,d7
	bsr	generaldelay
	bra	mainloop

*****************************************
boxesudeffect:
	lea	udlist,a5
	bra	dbs
boxesspeffect:
	lea	splist,a5
	bra	dbs
boxescheffect:
	lea	chlist,a5
	bra	dbs

dbs:	move.l	a5,a6
	move.l	(a6)+,d5
	move.w	#259,d6		;numbers in list
budloop1:
	moveq	#0,d0
	moveq	#0,d1
	move.b	(a6)+,d0	;x
	move.b	(a6)+,d1	;y
	bsr	removeblock
	move.l	d5,d7
	bsr	generaldelay
	dbf	d6,budloop1
	bsr	fadeto
	bsr	fadein
*	move.l	a5,a6
	move.w	#259,d6		;numbers in list
budloop2:
	moveq	#0,d0
	moveq	#0,d1
	move.b	-(a6),d1	;x
	move.b	-(a6),d0	;y
	bsr	putblock
	move.l	d5,d7
	bsr	generaldelay
	dbf	d6,budloop2
	move.l	howlong,d7
	bsr	generaldelay
	bra	mainloop

chlist:
	dc.l	3000
	dc.b	0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0,18,0
	dc.b	1,1,3,1,5,1,7,1,9,1,11,1,13,1,15,1,17,1,19,1
	dc.b	0,2,2,2,4,2,6,2,8,2,10,2,12,2,14,2,16,2,18,2
	dc.b	1,3,3,3,5,3,7,3,9,3,11,3,13,3,15,3,17,3,19,3
	dc.b	0,4,2,4,4,4,6,4,8,4,10,4,12,4,14,4,16,4,18,4
	dc.b	1,5,3,5,5,5,7,5,9,5,11,5,13,5,15,5,17,5,19,5
	dc.b	0,6,2,6,4,6,6,6,8,6,10,6,12,6,14,6,16,6,18,6
	dc.b	1,7,3,7,5,7,7,7,9,7,11,7,13,7,15,7,17,7,19,7
	dc.b	0,8,2,8,4,8,6,8,8,8,10,8,12,8,14,8,16,8,18,8
	dc.b	1,9,3,9,5,9,7,9,9,9,11,9,13,9,15,9,17,9,19,9
	dc.b	0,10,2,10,4,10,6,10,8,10,10,10,12,10,14,10,16,10,18,10
	dc.b	1,11,3,11,5,11,7,11,9,11,11,11,13,11,15,11,17,11,19,11
	dc.b	0,12,2,12,4,12,6,12,8,12,10,12,12,12,14,12,16,12,18,12

	dc.b	1,12,3,12,5,12,7,12,9,12,11,12,13,12,15,12,17,12,19,12
	dc.b	0,11,2,11,4,11,6,11,8,11,10,11,12,11,14,11,16,11,18,11
	dc.b	1,10,3,10,5,10,7,10,9,10,11,10,13,10,15,10,17,10,19,10
	dc.b	0,9,2,9,4,9,6,9,8,9,10,9,12,9,14,9,16,9,18,9
	dc.b	1,8,3,8,5,8,7,8,9,8,11,8,13,8,15,8,17,8,19,8
	dc.b	0,7,2,7,4,7,6,7,8,7,10,7,12,7,14,7,16,7,18,7
	dc.b	1,6,3,6,5,6,7,6,9,6,11,6,13,6,15,6,17,6,19,6
	dc.b	0,5,2,5,4,5,6,5,8,5,10,5,12,5,14,5,16,5,18,5
	dc.b	1,4,3,4,5,4,7,4,9,4,11,4,13,4,15,4,17,4,19,4
	dc.b	0,3,2,3,4,3,6,3,8,3,10,3,12,3,14,3,16,3,18,3
	dc.b	1,2,3,2,5,2,7,2,9,2,11,2,13,2,15,2,17,2,19,2
	dc.b	0,1,2,1,4,1,6,1,8,1,10,1,12,1,14,1,16,1,18,1
	dc.b	1,0,3,0,5,0,7,0,9,0,11,0,13,0,15,0,17,0,19,0


splist:
	dc.l	2500
	dc.b	0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0
	dc.b	10,0,11,0,12,0,13,0,14,0,15,0,16,0,17,0,18,0,19,0
	dc.b	19,1,19,2,19,3,19,4,19,5,19,6,19,7,19,8,19,9
	dc.b	19,10,19,11,19,12
	dc.b	18,12,17,12,16,12,15,12,14,12,13,12,12,12
	dc.b	11,12,10,12,9,12,8,12,7,12,6,12,5,12,4,12
	dc.b	3,12,2,12,1,12,0,12
	dc.b	0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,0,2,0,1
	dc.b	1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,1
	dc.b	10,1,11,1,12,1,13,1,14,1,15,1,16,1,17,1,18,1
	dc.b	18,2,18,3,18,4,18,5,18,6,18,7,18,8,18,9
	dc.b	18,10,18,11
	dc.b	17,11,16,11,15,11,14,11,13,11,12,11
	dc.b	11,11,10,11,9,11,8,11,7,11,6,11,5,11,4,11
	dc.b	3,11,2,11,1,11
	dc.b	1,10,1,9,1,8,1,7,1,6,1,5,1,4,1,3,1,2
	dc.b	2,2,3,2,4,2,5,2,6,2,7,2,8,2,9,2,10,2,11,2
	dc.b	12,2,13,2,14,2,15,2,16,2,17,2
	dc.b	17,3,17,4,17,5,17,6,17,7,17,8,17,9,17,10
	dc.b	16,10,15,10,14,10,13,10,12,10,11,10,10,10
	dc.b	9,10,8,10,7,10,6,10,5,10,4,10,3,10,2,10
	dc.b	2,9,2,8,2,7,2,6,2,5,2,4,2,3
	dc.b	3,3,4,3,5,3,6,3,7,3,8,3,9,3,10,3,11,3,12,3
	dc.b	13,3,14,3,15,3,16,3
	dc.b	16,4,16,5,16,6,16,7,16,8,16,9
	dc.b	15,9,14,9,13,9,12,9,11,9,10,9,9,9,8,9
	dc.b	7,9,6,9,5,9,4,9,3,9
	dc.b	3,8,3,7,3,6,3,5,3,4
	dc.b	4,4,5,4,6,4,7,4,8,4,9,4,10,4,11,4,12,4
	dc.b	13,4,14,4,15,4
	dc.b	15,5,15,6,15,7,15,8
	dc.b	14,8,13,8,12,8,11,8,10,8,9,8,8,8
	dc.b	7,8,6,8,5,8,4,8
	dc.b	4,7,4,6,4,5
	dc.b	5,5,6,5,7,5,8,5,9,5,10,5,11,5,12,5,13,5,14,5
	dc.b	14,6,14,7
	dc.b	13,7,12,7,11,7,10,7,9,7,8,7,7,7,6,7,5,7
	dc.b	5,6
	dc.b	6,6,7,6,8,6,9,6,10,6,11,6,12,6,13,6,14,6
udlist:
	dc.l	5000
	dc.b	0,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7
	dc.b	0,8,0,9,0,10,0,11,0,12
	dc.b	1,12,1,11,1,10,1,9,1,8,1,7,1,6
	dc.b	1,5,1,4,1,3,1,2,1,1,1,0
	dc.b	2,0,2,1,2,2,2,3,2,4,2,5,2,6,2,7
	dc.b	2,8,2,9,2,10,2,11,2,12
	dc.b	3,12,3,11,3,10,3,9,3,8,3,7,3,6
	dc.b	3,5,3,4,3,3,3,2,3,1,3,0
	dc.b	4,0,4,1,4,2,4,3,4,4,4,5,4,6,4,7
	dc.b	4,8,4,9,4,10,4,11,4,12
	dc.b	5,12,5,11,5,10,5,9,5,8,5,7,5,6
	dc.b	5,5,5,4,5,3,5,2,5,1,5,0
	dc.b	6,0,6,1,6,2,6,3,6,4,6,5,6,6,6,7
	dc.b	6,8,6,9,6,10,6,11,6,12
	dc.b	7,12,7,11,7,10,7,9,7,8,7,7,7,6
	dc.b	7,5,7,4,7,3,7,2,7,1,7,0
	dc.b	8,0,8,1,8,2,8,3,8,4,8,5,8,6,8,7
	dc.b	8,8,8,9,8,10,8,11,8,12
	dc.b	9,12,9,11,9,10,9,9,9,8,9,7,9,6
	dc.b	9,5,9,4,9,3,9,2,9,1,9,0
	dc.b	10,0,10,1,10,2,10,3,10,4,10,5,10,6,10,7
	dc.b	10,8,10,9,10,10,10,11,10,12
	dc.b	11,12,11,11,11,10,11,9,11,8,11,7,11,6
	dc.b	11,5,11,4,11,3,11,2,11,1,11,0
	dc.b	12,0,12,1,12,2,12,3,12,4,12,5,12,6,12,7
	dc.b	12,8,12,9,12,10,12,11,12,12
	dc.b	13,12,13,11,13,10,13,9,13,8,13,7,13,6
	dc.b	13,5,13,4,13,3,13,2,13,1,13,0
	dc.b	14,0,14,1,14,2,14,3,14,4,14,5,14,6,14,7
	dc.b	14,8,14,9,14,10,14,11,14,12
	dc.b	15,12,15,11,15,10,15,9,15,8,15,7,15,6
	dc.b	15,5,15,4,15,3,15,2,15,1,15,0
	dc.b	16,0,16,1,16,2,16,3,16,4,16,5,16,6,16,7
	dc.b	16,8,16,9,16,10,16,11,16,12
	dc.b	17,12,17,11,17,10,17,9,17,8,17,7,17,6
	dc.b	17,5,17,4,17,3,17,2,17,1,17,0
	dc.b	18,0,18,1,18,2,18,3,18,4,18,5,18,6,18,7
	dc.b	18,8,18,9,18,10,18,11,18,12
	dc.b	19,12,19,11,19,10,19,9,19,8,19,7,19,6
	dc.b	19,5,19,4,19,3,19,2,19,1,19,0
	even
*****************************************

*****************************************
stretcheffect:
	move.w	#0,scrolly
	move.l	seen,a0
steloop2:
	bsr	scopyline2
*	add.l	#160,a0
	lea	160(a0),a0
	addq.w	#1,scrolly
	cmpi.w	#199,scrolly
	ble	steloop2
	bsr	fadeto
	bsr	clearseen
	bsr	fadein
	move.w	#199,scrolly
	move.l	hiden,a0
	add.l	#32000-160,a0
steloop:
	bsr	scopyline
	sub.l	#160,a0
	subq.w	#1,scrolly
	bge	steloop
	move.l	howlong,d7
	bsr	generaldelay
	bra	mainloop


scopyline2:
	move.w	scrolly,d7
	move.l	a0,a6
scloop2:
	move.l	a0,a1
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
*	subi.l	#160*2,a6
	lea	-160*2(a6),a6
	dbf	d7,scloop2
	rts
scopyline:
	move.w	scrolly,d7
	move.l	seen,a6
scloop:
	move.l	a0,a1
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	move.l	(a1)+,(a6)+
	dbf	d7,scloop
	rts



*****************************************
slideffect:
	move.w	#19,d7
	moveq	#0,d6
sel:
	move.w	d7,-(sp)
	move.w	d6,d0
	bsr	slideit
	addq.w	#1,d6
	move.w	(sp)+,d7
	dbf	d7,sel

	bsr	fadeto
	bsr	fadein
	move.w	#19,d7
	moveq	#0,d6
sela:
	move.w	d7,-(sp)
	move.w	d6,d0
	bsr	slideita
	addq.w	#1,d6
	move.w	(sp)+,d7
	dbf	d7,sela

	move.l	howlong,d7
	bsr	generaldelay
	bra	mainloop

slideit:
	asl.w	#3,d0
	move.l	seen,a0
	add.w	d0,a0
	move.l	a0,a1
	moveq	#15,d2
	moveq	#0,d0
	move.w	#-1,d0
slido:
	lsr.w	#1,d0
	move.w	#199,d1
	move.l	a1,a0
slidl:
	and.w	d0,(a0)
	and.w	d0,2(a0)
	and.w	d0,4(a0)
	and.w	d0,6(a0)
*	addi.l	#160,a0
	lea	160(a0),a0
	dbf	d1,slidl
	move.l	#1000,d7
	bsr	generaldelay
	dbf	d2,slido
	rts

slideita:
	asl.w	#3,d0
	move.l	seen,a0
	move.l	hiden,a2
	add.w	d0,a0
	add.w	d0,a2
	move.l	a0,a1
	move.l	a2,a3
	moveq	#15,d2
	moveq	#0,d0
	move.w	#-1,d0
	swap	d0
slidoa:
	lsr.l	#1,d0
	move.w	#199,d1
	move.l	a1,a0
	move.l	a3,a2
slidla:
	move.w	(a2),d3
	and.w	d0,d3
	move.w	d3,(a0)
	move.w	2(a2),d3
	and.w	d0,d3
	move.w	d3,2(a0)
	move.w	4(a2),d3
	and.w	d0,d3
	move.w	d3,4(a0)
	move.w	6(a2),d3
	and.w	d0,d3
	move.w	d3,6(a0)
*	addi.l	#160,a0
	lea	160(a0),a0
*	addi.l	#160,a2
	lea	160(a2),a2
	dbf	d1,slidla
	dbf	d2,slidoa
	rts
*****************************************
slideffect2:
	moveq	#15,d5
sel2a:
	move.w	#19,d7
	moveq	#0,d6
sel2:
	movem.w	d5/d7,-(sp)
	move.w	d6,d0
	bsr	slideit2
	addq.w	#1,d6
	movem.w	(sp)+,d5/d7
	dbf	d7,sel2
	dbf	d5,sel2a
	bsr	fadeto
	bsr	fadein

	moveq	#15,d5
	moveq	#16,d1
ssel2a:
	moveq	#0,d6
	subq.w	#1,d1
	move.w	#19,d7
ssel2:
	move.w	d6,d0
	bsr	slideit2a
	addq.w	#1,d6
	dbf	d7,ssel2
	dbf	d5,ssel2a
	move.l	howlong,d7
	bsr	generaldelay
	bra	mainloop

slideit2a:
	asl.w	#3,d0
	move.l	seen,a0
	move.l	hiden,a2
	add.w	d0,a0
	add.w	d0,a2
	move.w	#199,d4
slidl2a:
	move.w	(a2),d3
	lsl.w	d1,d3
	move.w	d3,(a0)
	move.w	2(a2),d3
	lsl.w	d1,d3
	move.w	d3,2(a0)
	move.w	4(a2),d3
	lsl.w	d1,d3
	move.w	d3,4(a0)
	move.w	6(a2),d3
	lsl.w	d1,d3
	move.w	d3,6(a0)
*	addi.l	#160,a0
	lea	160(a0),a0
*	addi.l	#160,a2
	lea	160(a2),a2
	dbf	d4,slidl2a
	rts

slideit2:
	asl.w	#3,d0
	move.l	seen,a0
	add.w	d0,a0
	move.l	a0,a1
*	moveq	#15,d2
slido2:
	move.w	#199,d1
	move.l	a1,a0
slidl2:
	lsr.w	(a0)
	lsr.w	2(a0)
	lsr.w	4(a0)
	lsr.w	6(a0)
	lea	160(a0),a0
	dbf	d1,slidl2
	rts

*****************************************
boxeseffect:
	move.w	#1,vblcol
	bsr	setuphbl2
	move.w	#0,scrolly
	move.w	#0,scrolly3
bbe:
	bsr	doboxes
	move.l	#25000,d7
	bsr	generaldelay
	addq.w	#1,scrolly
	cmpi.w	#3,scrolly
	ble	bbe
	move.w	#0,scrolly2
bbe2:
	bsr	doboxes
	bsr	doboxes2
	move.l	#25000,d7
	bsr	generaldelay
	addq.w	#1,scrolly
	cmpi.w	#17,scrolly
	bge	bout
	addq.w	#1,scrolly2
	cmpi.w	#17,scrolly2
	ble	bbe2
bout:
	bsr	doboxes2
	move.l	#25000,d7
	bsr	generaldelay
	addq.w	#1,scrolly2
	cmpi.w	#17,scrolly2
	ble	bout
	move.l	howlong,d7
	bsr	generaldelay
	bra	mainloop	

doboxes:
	move.w	scrolly,rowy
	move.w	#3,d7
	bsr	doline
	move.w	scrolly,rowy
	subq.w	#1,rowy
	bmi	doboxesover
	move.w	#8,d7
	bsr	doline
	move.w	scrolly,rowy
	subq.w	#2,rowy
	bmi	doboxesover
	move.w	#15,d7
	bsr	doline
	move.w	scrolly,rowy
	subq.w	#3,rowy
	move.w	rowy,scrolly3
	bmi	doboxesover
	bsr	doallline
doboxesover:
	rts

doline:
	move.w	#20,d0
	bsr	randomplus
	move.w	last,d1
	cmp.w	d1,d0
	beq	doline
	move.w	d0,last
	move.w	rowy,d1
	bsr	removeblock
	dbf	d7,doline
	rts
doallline:
	moveq	#19,d7
dal:
	move.w	d7,d0
	move.w	rowy,d1
	bsr	removeblock
	dbf	d7,dal
	rts
doallline2:
	moveq	#19,d7
dal2:
	move.w	d7,d0
	move.w	rowy,d1
	bsr	putblock
	dbf	d7,dal2
	rts

doboxes2:
	move.w	scrolly2,rowy
	move.w	#3,d7
	bsr	doline2
	move.w	scrolly2,rowy
	subq.w	#1,rowy
	bmi	doboxesover2
	move.w	#8,d7
	bsr	doline2
	move.w	scrolly2,rowy
	subq.w	#2,rowy
	bmi	doboxesover2
	move.w	#15,d7
	bsr	doline2
	move.w	scrolly2,rowy
	subq.w	#3,rowy
	bmi	doboxesover2
	bsr	doallline2
doboxesover2:
	rts

doline2:
	move.w	#20,d0
	bsr	randomplus
	move.w	last,d1
	cmp.w	d1,d0
	beq	doline2
	move.w	d0,last
	move.w	rowy,d1
	bsr	putblock
	dbf	d7,doline2
	rts

last:		dc.w	0
*****************************************
*	provide position across screen	*
*	in d0 (0-19). And y in d1	*
*****************************************
removeblock:
	and.l	#$0000ffff,d0
	and.l	#$0000ffff,d1

	asl.w	#4,d1			;*16 for screeny
	cmpi.w	#200,d1
	bge	rmbo
	asl.w	#3,d0			;*8 for pos across
	mulu	#160,d1
	move.l	seen,a0
	move.l	a0,a1
	add.l	#32000,a1
	add.w	d1,d0
	add.w	d0,a0
	moveq	#15,d0
	moveq	#0,d1
	cmp.l	a1,a0
	bge	rmbo
rmbloop:
	move.l	d1,(a0)
	move.l	d1,4(a0)
*	addi.l	#160,a0
	lea	160(a0),a0
	cmp.l	a1,a0
	bge	rmbo
	dbf	d0,rmbloop
rmbo:	rts
*****************************************
*	provide position across screen	*
*	in d0 (0-19). And y in d1	*
*****************************************
putblock:
	and.l	#$0000ffff,d0
	and.l	#$0000ffff,d1
	asl.w	#4,d1			;*16 for screeny
	asl.w	#3,d0			;*8 for pos across
	cmpi.w	#200,d1
	bge	rpbo
	mulu	#160,d1
	move.l	seen,a0
	move.l	hiden,a2
	move.l	a0,a1
	add.l	#32000,a1
	add.w	d1,d0
	add.w	d0,a0
	add.w	d0,a2
	moveq	#15,d0
	cmp.l	a1,a0
	bge	rpbo
rpbloop:
	move.l	(a2),(a0)
	move.l	4(a2),4(a0)
*	addi.l	#160,a0
	lea	160(a0),a0
*	addi.l	#160,a2
	lea	160(a2),a2
	cmp.l	a1,a0
	bge	rpbo
	dbf	d0,rpbloop
rpbo:	rts

*****************************************
vblcol:		dc.w	0
howlong:	dc.l	0
copyhtos:
	move.l	hiden,a0
	move.l	seen,a1
	move.w	#16000,d0
fadlc:
	move.w	(a0)+,(a1)+
	dbf	d0,fadlc
	rts

*****************************************
fadeffect:
	move.w	#-1,vblcol
	bsr	fadeto
	move.l	hiden,a0
	move.l	seen,a1
	move.w	#16000,d0
fadl:
	move.w	(a0)+,(a1)+
	dbf	d0,fadl
	bsr	fadein
	move.l	howlong,d7
	bsr	generaldelay
	bra	mainloop

generaldelay:
	subq.l	#1,d7
	bpl	generaldelay
	rts	

*****************************************
rolleffect2:
	move.l	hiden,a0
	move.w	#159,d0
	add.l	#32000,a0
rlq2:
	move.w	#0,(a0)+
	dbf	d0,rlq2

	move.w	#1,vblcol
	jsr	setuphbl
	move.w	#-1,scrolly
roller2:
	jsr	doroll
	bra	roller2
	move.l	howlong,d7
	bsr	generaldelay
	rts

*****************************************
rolleffect:
	move.l	hiden,a0
	move.w	#159,d0
	add.l	#32000,a0
rlq:
	move.w	#0,(a0)+
	dbf	d0,rlq

	move.w	#1,vblcol
	jsr	setuphbl
	move.w	#-1,scrolly
roller:
	jsr	doroll	
	bra	roller
rollerback:
	move.l	howlong,d7
	bsr	generaldelay
	bra	mainloop
doroll:
	move.w	#$25,-(sp)
	trap	#14
	addq.l	#2,sp
	addq.w	#1,scrolly
	cmpi.w	#200,scrolly
	blt	rt
	addq.l	#4,sp
	bra	rollerback
rt:	move.l	hiden,a0
	move.l	a0,a4
	add.l	#32000,a4
	moveq	#0,d0
	moveq	#0,d2
	moveq	#0,d1
	move.w	scrolly,d0
	addq.w	#1,d0
	move.w	d0,d2
	add.w	#90,d0
	move.w	#33,d7
	mulu	#160,d0
	move.l	seen,a6
	mulu	#160,d2
	move.l	a6,a5
	add.l	d2,a6
	sub.l	#160,d2
	move.l	a0,a3
	add.l	d2,a5		;screen ad to put line that stays
	add.l	d2,a3
	add.l	d0,a0		;get screen ad to copy from
	lea	rollist,a1
	movem.l	a0-a6,-(sp)
	move.l	a3,a0
	move.l	a5,a6
	bsr	copyline
	movem.l	(sp)+,a0-a6
	moveq	#0,d6
rloop:
	bsr	copyline
	move.w	(a1)+,d2
	mulu	#160,d2
	sub.w	d2,a0
	dbf	d7,rloop
	move.l	a3,a0
	move.l	a5,a6
	bra	copyline2
norol:	rts

scrolly:	dc.w	0
scrolly2:	dc.w	0
scrolly3:	dc.w	0

copyline:
	move.l	a0,a2
	cmp.l	a4,a0
	bgt	nocline
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	a2,a0
	rts
nocline:
*	addi.l	#160,a6
	lea	160(a6),a6
	addq.w	#1,d6		;counter for extra during clipping
	rts
copyline2:
	move.w	d6,scrolly2	
cll:
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	move.l	(a0)+,(a6)+
	dbf	d6,cll
	rts
rollist:
	dc.w	5,4,3,3,2,2,2,1,1,1,1,1,1,1,1,1,1
	dc.w	1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,5
**********************************************
temppal:	dc.l	0
temppal2:	dc.l	0
*****************************************
*	general fadeto routine		*
* load color for fade into fadetocol	*
*****************************************
fadeto:
	lea	fadebuff,a0
	move.l	temppal2,a1
	moveq	#15,d7
ftl:
	move.w	(a1)+,(a0)+
	dbf	d7,ftl
	moveq	#6,d7
ftoloop:
	movem.l	d0-d7/a0-a6,-(sp)
	bsr	fademath
	move.l	#20000,d7
	bsr	generaldelay
	move.l	#fadebuff,-(sp)
	move.w	#6,-(sp)
	trap	#14
	addq.l	#6,sp
	move.w	#37,-(sp)
	trap	#14
	addq.l	#2,sp
	movem.l	(sp)+,d0-d7/a0-a6
	dbf	d7,ftoloop
	rts
fademath:
	moveq	#15,d7
	lea	fadebuff,a1
fml:
	move.w	(a1),d0
	move.w	d0,d1
	move.w	d0,d2
	and.w	#$0700,d0
	and.w	#$0070,d1
	and.w	#$0007,d2
	sub.w	#$0100,d0
	tst.w	d0
	bpl	fml2
	moveq	#0,d0
fml2:
	sub.w	#$0010,d1
	tst.w	d1
	bpl	fml3
	moveq	#0,d1
fml3:
	sub.w	#$0001,d2
	tst.w	d2
	bpl	fml4
	move.w	#0,d2
fml4:
	or.w	d2,d0
	or.w	d1,d0
	move.w	d0,(a1)+
	dbf	d7,fml
	rts

*****************************************
*	general fadeto routine		*
* load color for fade into fadetocol	*
*****************************************
fadein:
	lea	fadebuff,a0
	moveq	#15,d7
ftli:
	move.w	#0,(a0)+
	dbf	d7,ftli
	moveq	#6,d7
ftoloopi:
	move.w	d7,-(sp)
	bsr	fademathi
	move.l	#20000,d7
	bsr	generaldelay
	move.l	#fadebuff,-(sp)
	move.w	#6,-(sp)
	trap	#14
	addq.l	#6,sp
	move.w	#37,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	(sp)+,d7
	dbf	d7,ftoloopi
	rts
fademathi:
	moveq	#15,d7
	lea	fadebuff,a1
	move.l	temppal,a2
fmli:
	move.w	(a1),d0
	move.w	d0,d1
	move.w	d0,d2
	and.w	#$0700,d0
	and.w	#$0070,d1
	and.w	#$0007,d2
	add.w	#$0100,d0
	move.w	(a2),d3
	and.w	#$0700,d3
	cmp.w	d0,d3
	bge	fml2i
	move.w	d3,d0
fml2i:
	move.w	(a2),d3
	and.w	#$0070,d3
	add.w	#$0010,d1
	cmp.w	d1,d3
	bge	fml3i
	move.w	d3,d1
fml3i:
	move.w	(a2)+,d3
	and.w	#$0007,d3
	add.w	#$0001,d2
	cmp.w	d2,d3
	bge	fml4i
	move.w	d3,d2
fml4i:
	or.w	d2,d0
	or.w	d1,d0
	move.w	d0,(a1)+
	dbf	d7,fmli
	rts


fadebuff:	ds.w	16


**********************************************
setupdisk:
	move.l	#diskbuffer,-(sp)
	move.w	#$1a,-(sp)
	trap	#1
	addq.l	#6,sp
	move.w	#$01,-(sp)	;attribute norm read only
	move.l	#pattern,-(sp)
	move.w	#$4e,-(sp)
	trap	#1
	addq.l	#8,sp
	tst.w	d0
	bne	nofiles
	bra	gettype
nofiles:
	bra	gem

getnextfile:
	move.w	#$4f,-(sp)
	trap	#1
	addq.l	#2,sp
	tst.w	d0
	bne	setupdisk
*********************************
*	Check file types	*
*********************************
gettype:
	lea	diskbuffer+30,a0
ftl1:
	tst.b	(a0)		;first find the null at end
	beq	fend
	addq.l	#1,a0
	bra.s	ftl1
fend:
	sub.l	#4,a0		;step back at least 3 chars
ftl2:
	cmpi.b	#'.',(a0)
	beq	fend2
	addq.l	#1,a0
	bra.s	ftl2
fend2:
	lea	extrabit,a1
	move.b	(a0)+,(a1)+
	move.b	(a0)+,(a1)+
	move.b	(a0)+,(a1)+
	move.b	(a0)+,(a1)+
	lea	extrabit,a1
	move.b	#1,pictype
	cmp.l	#'.NEO',(a1)
	beq	fexit
	move.b	#5,pictype
	cmp.l	#'.PI1',(a1)
	beq	fexit
	move.b	#8,pictype
	cmp.l	#'.PC1',(a1)
	beq	fexit
	move.b	#3,pictype
	cmp.l	#'.IFF',(a1)
	beq	fexit
	bra	getnextfile
fexit:
	rts

pictype:	dc.b	0
pattern:	dc.b	'*.*',0
	even
extrabit:	dc.l	0
diskbuffer:	ds.b	44
spritex:	dc.w	160
spritey:	dc.w	50
******************************************
savemfp:
	move.b	ieb,oldieb
	move.b	iea,oldiea
	move.b	ima,oldima
	move.l	key_vec,oldkeyvec
	move.l	hbl_vec,oldhblvec
	move.l	vbl_vec,oldvblvec
	rts

setuphbl:
	move.w	#$2700,sr
	move.l	#hbllist,hblsave
	move.b	ieb,oldieb
	move.b	iea,oldiea
	move.b	ima,oldima
	move.l	key_vec,oldkeyvec
	move.l	key_vec,keyt+2
	move.l	#key_handler,key_vec		;put new key stuff in
	move.l	hbl_vec,oldhblvec

	and.b	#$df,ieb	;stop 200hz timer
	and.b	#$fe,iea	;stop hblank
	move.l	hbl_vec,oldhblvec
	move.l	#hblhandler1,hbl_vec
	or.b	#1,iea			;enable hblank
	or.b	#1,ima
	move.l	vbl_vec,vblt+2		;set up vbl handler
	move.l	vbl_vec,oldvblvec
	move.l	#vbl_handler,vbl_vec
	move.b	#0,tbcr
	move.b	#5,tbdr
	move.b	#8,tbcr
	move.w	#$2300,sr
	rts

setuphbl3:
	move.w	#$2700,sr
	move.l	#hbllist,hblsave
	move.b	ieb,oldieb
	move.b	iea,oldiea
	move.b	ima,oldima
	move.l	key_vec,oldkeyvec
	move.l	key_vec,keyt+2
	move.l	#key_handler,key_vec		;put new key stuff in
	move.l	hbl_vec,oldhblvec
	and.b	#$df,ieb	;stop 200hz timer
	and.b	#$fe,iea	;stop hblank
	move.l	hbl_vec,oldhblvec
	move.l	#hblhandler1,hbl_vec
	or.b	#1,iea			;enable hblank
	or.b	#1,ima
	move.l	vbl_vec,vblt3+2		;set up vbl handler
	move.l	vbl_vec,oldvblvec
	move.l	#vbl_handler3,vbl_vec
	move.b	#0,tbcr
	move.b	#1,tbdr
	move.b	#8,tbcr
	move.w	#$2300,sr
	rts
setuphbl4:
	move.w	#$2700,sr
	move.l	#hbllist,hblsave
	move.b	ieb,oldieb
	move.b	iea,oldiea
	move.b	ima,oldima
	move.l	key_vec,oldkeyvec
	move.l	key_vec,keyt+2
	move.l	#key_handler,key_vec		;put new key stuff in
	move.l	hbl_vec,oldhblvec
	and.b	#$df,ieb	;stop 200hz timer
	and.b	#$fe,iea	;stop hblank
	move.l	hbl_vec,oldhblvec
	move.l	#hblhandler1,hbl_vec
	or.b	#1,iea			;enable hblank
	or.b	#1,ima
	move.l	vbl_vec,vblt4+2		;set up vbl handler
	move.l	vbl_vec,oldvblvec
	move.l	#vbl_handler4,vbl_vec
	move.b	#0,tbcr
	move.b	#1,tbdr
	move.b	#8,tbcr
	move.w	#$2300,sr
	rts

hblhandler1:
	movem.l	d0/a0-a2,-(sp)
	move.l	hblsave,a0
endlist:
	move.l	(a0)+,a1
	move.l	#$ff8240,a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	move.b	#0,tbcr
	moveq	#0,d0
	move.w	(a0)+,d0
	move.l	a0,hblsave
	move.b	d0,tbdr
	move.b	#8,tbcr
	bclr	#0,isra
	movem.l	(sp)+,d0/a0-a2
	rte
hbllist:
	dc.l	palette1
	dc.w	1		;whole palete,0 palnum,numlines to next
	dc.l	palette2
	dc.w	1
	dc.l	palette2
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette0
	dc.w	1
	dc.l	palette0
	dc.w	1
	dc.l	palette0
	dc.w	1
	dc.l	palette0
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette2
	dc.w	1
	dc.l	palette2
	dc.w	1
	dc.l	palette1
	dc.w	1		;whole palete,0 palnum,numlines to next
	dc.l	palette1
	dc.w	1		;whole palete,0 palnum,numlines to next
	dc.l	palette1
	dc.w	1		;whole palete,0 palnum,numlines to next
	dc.l	palettel
	dc.w	200		;whole palete,0 palnum,numlines to next

hbllist2:
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette2
	dc.w	1
	dc.l	palette2
	dc.w	1
	dc.l	palette1
	dc.w	1
	dc.l	palette1
	dc.w	1
	dc.l	paletteblack
	dc.w	1
	dc.l	paletteblack
	dc.w	1
	dc.l	paletteblack
	dc.w	1
	dc.l	palette1l
	dc.w	1
	dc.l	palette1l
	dc.w	1
	dc.l	palette2l
	dc.w	1
	dc.l	palette2l
	dc.w	1
	dc.l	palette3l
	dc.w	1
	dc.l	palette3l
	dc.w	1
	dc.l	palette4l
	dc.w	1
	dc.l	palette4l
	dc.w	1
	dc.l	palette5l
	dc.w	1
	dc.l	palette5l
	dc.w	1
	dc.l	palettel
	dc.w	200
hbllist3:
	dc.l	palette5l
	dc.w	1
	dc.l	palette5l
	dc.w	1
	dc.l	palette4l
	dc.w	1
	dc.l	palette4l
	dc.w	1
	dc.l	palette3l
	dc.w	1
	dc.l	palette3l
	dc.w	1
	dc.l	palette2l
	dc.w	1
	dc.l	palette2l
	dc.w	1
	dc.l	palette1l
	dc.w	1
	dc.l	palette1l
	dc.w	1
	dc.l	paletteblack
	dc.w	1
	dc.l	paletteblack
	dc.w	1
	dc.l	paletteblack
	dc.w	1
	dc.l	palette1
	dc.w	1
	dc.l	palette1
	dc.w	1
	dc.l	palette2
	dc.w	1
	dc.l	palette2
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette3
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette4
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette5
	dc.w	1
	dc.l	palette0
	dc.w	200

paletteblack:
	ds.w	16

setuphbl2:
	move.w	#$2700,sr
	move.l	#hbllist,hblsave
	move.b	ieb,oldieb
	move.b	iea,oldiea
	move.b	ima,oldima
	move.l	key_vec,oldkeyvec
	move.l	key_vec,keyt+2
	move.l	#key_handler,key_vec		;put new key stuff in
	move.l	hbl_vec,oldhblvec

	and.b	#$df,ieb	;stop 200hz timer
	and.b	#$fe,iea	;stop hblank
	move.l	hbl_vec,oldhblvec
	move.l	#hblhandler2,hbl_vec
	or.b	#1,iea			;enable hblank
	or.b	#1,ima
	move.l	vbl_vec,vblt2+2		;set up vbl handler
	move.l	vbl_vec,oldvblvec
	move.l	#vbl_handler2,vbl_vec
	move.b	#0,tbcr
	move.b	#5,tbdr
	move.b	#8,tbcr
	move.w	#$2300,sr
	rts
hblhandler2:
	movem.l	a0-a1,-(sp)
	lea	palettel,a0
	addq.l	#2,a0
	move.l	#$fff8242,a1
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	movem.l	(sp)+,a0-a1
	bclr	#0,isra
	rte

hblsave:	dc.l	0
vbl_handler:
	move.l	#hbllist,hblsave
	movem.l	d0/d1/a0,-(sp)
	moveq	#0,d0
	moveq	#0,d1
	move.w	scrolly,d0
	addq.w	#1,d0
	cmpi.w	#109,d0
	ble	vbww
	move.w	scrolly2,d1
	add.w	d1,d0
	mulu	#6,d1
	lea	hbllist,a0
	add.w	d1,a0
	move.l	a0,hblsave
vbww:	move.b	#0,tbcr
	move.b	d0,tbdr
	move.b	#8,tbcr
	movem.l	(sp)+,d0/d1/a0
vblt:	jmp	$0
vbl_handler2:
	move.l	d0,-(sp)
	move.w	scrolly3,d0
	bgt	vbh2
	move.w	#1,d0
	bra	vbh3
vbh2:	asl.w	#4,d0
vbh3:	move.b	#0,tbcr
	move.b	d0,tbdr
	move.b	#8,tbcr
	move.l	(sp)+,d0
vblt2:	jmp	$0


vbl_handler3:
	move.l	#hbllist2,hblsave
	movem.l	d0/d1/a0,-(sp)
	moveq	#0,d0
	moveq	#0,d1
	move.w	scrolly,d0
	sub.w	#10,d0
	bgt	vbt1
	neg.w	d0
	mulu	#6,d0
	lea	hbllist2,a0
	add.w	d0,a0
	move.l	a0,hblsave
	moveq	#1,d0
vbt1:
	move.b	#0,tbcr
	move.b	d0,tbdr
	move.b	#8,tbcr
	movem.l	(sp)+,d0/d1/a0
vblt3:	jmp	$0
vbl_handler4:
	move.l	#hbllist3,hblsave
	movem.l	d0/d1/a0,-(sp)
	moveq	#0,d0
	moveq	#0,d1
	move.w	scrolly,d0
	sub.w	#12,d0
	bgt	vbt2
	neg.w	d0
	mulu	#6,d0
	lea	hbllist3,a0
	add.w	d0,a0
	move.l	a0,hblsave
	moveq	#1,d0
vbt2:
	move.b	#0,tbcr
	move.b	d0,tbdr
	move.b	#8,tbcr
	movem.l	(sp)+,d0/d1/a0
vblt4:	jmp	$0

key_handler:
	move.w	#$2500,sr
keyt:	jmp	$0


oldvblvec:	ds.l	1
oldkeyvec:	ds.l	1
oldhblvec:	ds.l	1
oldieb:		ds.b	1
oldiea:		ds.b	1
oldima:		ds.b	1
	even
restoremfp:
	move.b	oldieb,ieb
	move.b	oldiea,iea
	move.b	oldima,ima
	move.l	oldkeyvec,key_vec
	move.l	oldhblvec,hbl_vec
	move.l	oldvblvec,vbl_vec
	rts
my400save:	dc.l	0

*************************************
leftbutton:	equ	1
rightbutton:	equ	2
bothbuttons:	equ	3

**********************************
clearboth:
	move.l	seen,a0
	move.l	hiden,a1
	move.w	#15999,d0
cbl:
	move.w	#0,(a0)+
	move.w	#0,(a1)+
	dbf	d0,cbl
	rts
*****************************************
xvel:		dc.w	0
yvel:		dc.w	0
tilt:		dc.w	0
yoffs:		dc.w	560

****************************************
keyboard:
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     keyback
        swap    d0
quitk:   cmpi.w  #$10,d0
        bne     space
        bra     gem
space:
	cmpi.w	#$39,d0
	bne	f1
	bra	pause

f1:
	cmpi.w	#$3b,d0
	bne	f2
	move.l	#100000,howlong
	rts
f2:
	cmpi.w	#$3c,d0
	bne	f3
	move.l	#200000,howlong
	rts
f3:
	cmpi.w	#$3d,d0
	bne	f4
	move.l	#400000,howlong
	rts
f4:
	cmpi.w	#$3e,d0
	bne	f5
	move.l	#800000,howlong
	rts
f5:
	cmpi.w	#$3f,d0
	bne	f6
	move.l	#1600000,howlong
	rts
f6:
	cmpi.w	#$40,d0
	bne	f7
	move.l	#2000000,howlong
	rts
f7:
	cmpi.w	#$41,d0
	bne	f8
	move.l	#2400000,howlong
	rts
f8:
	cmpi.w	#$42,d0
	bne	f9
	move.l	#2800000,howlong
	rts
f9:
	cmpi.w	#$43,d0
	bne	f10
	move.l	#3200000,howlong
	rts
f10:
	cmpi.w	#$44,d0
	bne	keyback
	move.l	#36000000,howlong
	rts
keyback:rts

cldelay:	dc.w	-1
rcldelay:	dc.w	-0
wx:		dc.w	0
wy:		dc.w	0
wz:		dc.w	0
proz:		dc.w	0
spadd:		dc.w	0
*****************************
pause:  
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     pause
	rts

gkey:
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     gkey
        swap    d0
        rts

***********************************
mydocolors2:
	move.l	#$ff8240,a1
	moveq	#15,d0
	lea	picpalette,a0
mdcloop2:
	move.w	(a0)+,(a1)+
	dbf	d0,mdcloop2
	rts
mydocolors3:
	move.l	#$ff8240,a1
	moveq	#15,d0
	lea	palettel,a0
mdcloop3:
	move.w	(a0)+,(a1)+
	dbf	d0,mdcloop3
	rts

getlast:
	moveq	#15,d0
	lea	picpalette,a0
	lea	palettel,a1
	move.l	a1,temppal2
	move.l	#$fff8240,a2
glast:
	move.w	(a0),(a1)+
	move.w	(a0)+,(a2)+
	dbf	d0,glast

	lea	palette5,a0
	lea	palette5l,a1
	bsr	docop
	lea	palette4,a0
	lea	palette4l,a1
	bsr	docop
	lea	palette3,a0
	lea	palette3l,a1
	bsr	docop
	lea	palette2,a0
	lea	palette2l,a1
	bsr	docop
	lea	palette1,a0
	lea	palette1l,a1
	bsr	docop
	rts

docop:
	rept	16
	move.w	(a0)+,(a1)+
	endr
	rts

mydocolors:
	lea	picpalette,a0
	move	#$0500,d0		;sub value
	move	#$0050,d1		;sub value
	move	#$0005,d2		;sub value
	lea	palette1,a1	;where to put modified palette
	bsr	domod

	lea	picpalette,a0
	move	#$0400,d0		;sub value
	move	#$0040,d1		;sub value
	move	#$0004,d2		;sub value
	lea	palette2,a1	;where to put modified palette
	bsr	domod

	lea	picpalette,a0
	move	#$0300,d0		;sub value
	move	#$0030,d1		;sub value
	move	#$0003,d2		;sub value
	lea	palette3,a1	;where to put modified palette
	bsr	domod

	lea	picpalette,a0
	move	#$0200,d0		;sub value
	move	#$0020,d1		;sub value
	move	#$0002,d2		;sub value
	lea	palette4,a1	;where to put modified palette
	bsr	domod

	lea	picpalette,a0
	move	#$0100,d0		;sub value
	move	#$0010,d1		;sub value
	move	#$0001,d2		;sub value
	lea	palette5,a1	;where to put modified palette
	bsr	domod

	lea	picpalette,a0
	move	#$0000,d0		;sub value
	move	#$0000,d1		;sub value
	move	#$0000,d2		;sub value
	lea	palette0,a1	;where to put modified palette
	move.l	a1,temppal
	bsr	domod
	rts

domod:
	moveq	#15,d7
dmloop:
	move.w	(a0)+,d6
	move.w	d6,d3
	move.w	d6,d4
	move.w	d6,d5
	and.w	#$0700,d3
	and.w	#$0070,d4
	and.w	#$0007,d5
	sub.w	d0,d3
	bge	dml1
	moveq	#0,d3
dml1:
	sub.w	d1,d4
	bge	dml2
	moveq	#0,d4
dml2:
	sub.w	d2,d5
	bge	dml3
	moveq	#0,d5
dml3:
	or.w	d3,d4
	or.w	d4,d5
	move.w	d5,(a1)+
	dbf	d7,dmloop
	rts



palette1:	ds.w	16
palette2:	ds.w	16
palette3:	ds.w	16
palette4:	ds.w	16
palette5:	ds.w	16
palette1l:	ds.w	16
palette2l:	ds.w	16
palette3l:	ds.w	16
palette4l:	ds.w	16
palette5l:	ds.w	16
palette0:	ds.w	16
palettel:	ds.w	16
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
************get screen address***************
getscrn:
	move.w  #2,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,screen
	move.l	#seenm,d0
	add.l	#512,d0
	and.w	#%1111111100000000,d0		;make sure of boundry
	move.l	d0,seen
	move.l	#hidenm,d0
	add.l	#512,d0
	and.w	#%1111111100000000,d0		;make sure of boundry
	move.l	d0,hiden
	rts
screen1:	dc.l	0
screen2:	dc.l	0
screen3:	dc.l	0
seen:	dc.l	0
hiden:	dc.l	0
screen:	dc.l	0
*************************************
clearquick:
	move.l	hiden,a0
	adda.l	#4048-8-320,a0
	move.l	a0,a1
	move	#152,d0
	moveq	#0,d7
cl2loop:
	move.l	d7,(a0)+
	move.w	d7,(a0)+
	addq.l	#2,a0
	move.l	d7,(a0)+
	move.w	d7,(a0)+
	addq.l	#2,a0
	move.l	d7,(a0)+
	move.w	d7,(a0)+
	addq.l	#2,a0
	move.l	d7,(a0)+
	move.w	d7,(a0)+
	addq.l	#2,a0
	move.l	d7,(a0)+
	move.w	d7,(a0)+
	addq.l	#2,a0
	move.l	d7,(a0)+
	move.w	d7,(a0)+
	addq.l	#2,a0
	move.l	d7,(a0)+
	move.w	d7,(a0)+
	addq.l	#2,a0
	move.l	d7,(a0)+
	move.w	d7,(a0)+
*	add.l	#160,a1
	lea	160(a1),a1
	move.l	a1,a0
	dbf	d0,cl2loop
cqb:	rts


beamer:
	move.l	#$ff8205,a0
	moveq	#0,d0
	move.b	(a0),d0
	asl.l	#8,d0
	adda.w	#2,a0
	move.b	(a0),d0
	asl.l	#8,d0
	adda.w	#2,a0
	move.b	(a0),d0
	move.l	d0,a0
	move.w	#0,(a0)
	rts
flip_scr:
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
	move.b	seen+1,$ff8201
	move.b	seen+2,$ff8203
	move.w	#37,-(sp)
	trap	#14
	addq.l	#2,sp
	bsr	clearquick
	rts


flip_scr3:
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
	move.b	seen+1,$ff8201
	move.b	seen+2,$ff8203
	move.w	#36,-(sp)
	trap	#14
	addq.l	#2,sp
	rts

framevbl:
	tst.w	vblcol
	bmi	skvbl
	cmpi.w	#2,vblcol
	beq	fvbl2
	bra	mydocolors2
fvbl2:
	bra	mydocolors3

skvbl:	rts
*****************************************
*	load a1 with routine address	*
*****************************************
vbl_list=$4ce
prt_cnt=$4ee
putvbl:
	move.l	#vbl_list,a0	; put start of vbl queue in a0
scanq:
	tst.l	(a0)		; current queue entry empty?
	beq.s	newvbl		; yes, install new vbl routine
	addq.l	#4,a0		; no, check next entry
	bra.s	scanq		; loop back

newvbl:
	move.l	a1,(a0)		; install routine in queue
	rts

oldvbl1:	dc.l	0
******************************************
*               RETURN TO GEM
gem:
	bsr	restoremfp
*	move.b	#%11111110,$ff820a
	move.l	#$ff8240,a0
	lea	palsave,a1
	moveq	#15,d7
rspl:
	move.w	(a1)+,d0
	and.w	#$0777,d0
	move.w	d0,(a0)+
	dbf	d7,rspl

	move.w	#0,$452
	move.l	oldvbl1,a0
	move.l	#0,(a0)
	move.w	#1,$452

        move.b  #7,$484

        move.w  ressave,-(sp)
        move.l  screen,-(sp)
        move.l  screen,-(sp)
        move.w  #5,-(sp)
        trap    #14
        add.l  #12,sp

	move.l	rvsave,$426
	move.l	resave,$42a
	bsr	mouseon
        
        move.l  savesup,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,(SP)
illegal
	clr.w	-(sp)
	trap	#1


rvsave:	dc.l	0
resave:	dc.l	0
palsave:	ds.w	16
*********************************************************
*       my routines for loading in the screens          *
*********************************************************
loadscr2:
	move    #0,-(SP)        ;Open file
	lea	diskbuffer,a0
	add.l	#30,a0
        move.l  a0,-(SP) ;Address of filename
        move    #$3D,-(SP)
        trap    #1              ;Get handle number in D0
        addq.l  #8,SP

	move.w	d0,-(sp)
	move.w	(sp),d0
	pea	picbuffer	;load it straight onto screen
        move.l  #100000,-(SP)    	;length to read in
        move    D0,-(SP)        ;Handle
        move    #$3F,-(SP)      ;bios number
        trap    #1              ;Read file in
        add.l   #12,SP
	move.l	d0,_loadlength

        move    #$3E,-(SP)      ;Handle already on stack
        trap    #1              ;Close file
        addq.l  #4,SP

	pea	picbuffer
	jsr	_hndlpix
	add.l	#4,sp
	tst.l	d0
	bmi.s	nogood
	rts

nogood:
	jsr	getnextfile
	bra	loadscr2

_loadlength:
	dc.l	0


*****************************************************************
*								*
*	hndlpix(card.l,rawdat.l)				*
*								*
*	places palette data in correct position of card and	*
*	deals with the various formats.				*
*	also puts the actual screen data at the address pointed	*
*	to by *picmap.						*
*								*
*	filetypes handled so far:	neo	st low res	*
*					pi1			*
*					pc1			*
*					iff			*
*	to be done:			none!! (yet)		*
*								*
*	returns:	0	something not right, possibly	*
*				wrong resolution iff, or unknown*
*				filetype.			*
*			1	all aok and palette and screen	*
*				data are in place.		*
*					*			*
*****************************************************************
_hndlpix:
	move.l	4(sp),savebuff
	movem.l	d1-a6,-(sp)
hneo:
	cmpi.b	#1,pictype	;check pictype
	bne	hdeg
	move.l	savebuff,a5
	lea	4(a5),a4
	lea	picpalette,a3
	rept	8
	move.l	(a4)+,(a3)+	;put palette in card
	endr
	lea	128(a5),a0	;screen data
	move.l	hiden,a1	;screen address in card
	bsr	putscrdat
	bra	exitok
hdeg:
	cmpi.b	#5,pictype
	bne	hdegcomp
	move.l	savebuff,a5
	lea	2(a5),a4
	lea	picpalette,a3
	rept	8
	move.l	(a4)+,(a3)+	;put palette in card
	endr
	lea	34(a5),a0	;screen data
	move.l	hiden,a1	;screen address in card
	bsr	putscrdat
	bra	exitok

hdegcomp:
	cmpi.b	#8,pictype
	bne	hiff
	move.l	savebuff,a5
	lea	2(a5),a4
	lea	picpalette,a3
	rept	8
	move.l	(a4)+,(a3)+	;put palette in card
	endr
*	lea	34(a5),a1	;screen data
*	move.l	hiden,a0	;screen address in card
*	move.l	_loadlength,d0
*	sub.l	#34+32,d0	;length of packed data
*	bsr	degas
	lea	34(a5),a0	;screen data
	move.l	hiden,a1	;screen address in card
	move.w	#40,bpline
	move.w	#200,iheight
	move.w	#4,planes
	bsr	iffdecomp
	bra	exitok

hiff:
	cmpi.b	#3,pictype	;is it iff ?
	bne	hnext
	bsr	cleariff
	bsr	doiff
	tst.w	d0
	beq	exiterror
*	move.l	savecard,a6
	lea	picpalette,a3	;pal address
	lea	palconvert,a2
	rept	8
	move.l	(a2)+,(a3)+
	endr
	bra	exitok
hnext:
	bra	exiterror	;other ftypes not yet implemented
exiterror:
	moveq	#0,d0
	movem.l	(sp)+,d1-a6
	rts

exitok:
	moveq	#1,d0
	movem.l	(sp)+,d1-a6
	rts

putscrdat:
	move	#199,d0
psdl:
	rept	40
	move.l	(a0)+,(a1)+
	endr
	dbf	d0,psdl
	rts

doiff:
	move.l	savebuff,iffpointer
getiff:
	move.l	iffpointer,a0
	cmpi.l	#'FORM',(a0)	; chunktype proper iff ?
	beq.s	iff_ok		; yes! now check 1st chunk
	cmpi.l	#'ILBM',8(a0)	; or chunksubtype?
	bne	freeiffbuff	; not iff - do your own error routines
iff_ok:
	lea	12(a0),a2
readilbm:
	lea.l	chunkbuff(pc),a0	;copy chunkinfo to buffer
	moveq	#8,d3
	bsr	transfer		;transfer 1st chunkname+length
ckbmhd:
	move.l	chunktype(pc),d0      ;what sort of chunk ?
	cmp.l	#'BMHD',d0             ;is it a bitmap header
	bne.s	ckcmap                ;no check if cmap
	lea.l	bmhdcopy,a0            ;if bmhd then copy it
	moveq	#_sizeof,d3        ;# of bytes to read
	bsr	transfer
	bra.s	readilbm               ;get next piece of data
ckcmap:
	cmpi.l	#'CMAP',d0		;is it a color map?
	bne.s	ckbody			;no
	move.l	chunklen(pc),d4		;# of colors to read * 3
	move.l	d4,d3			;# of data to read
	lea.l	coltable(pc),a0		;color table
	bsr	transfer		;copy chunk to coltable
	divu	#3,d4			;divide by 3 to get color count
	move.w	d4,numcols		;save count of colors in map
	subq.w	#1,d4
	lea.l	cmapcopy,a3		;a3 = ptr to cmap buffer
	lea.l	coltable(pc),a0		;a0 = color table
nextcol:
	move.b	(a0)+,d1
	lsl.w	#4,d1
	or.b	(a0)+,d1
	lsl.w	#4,d1
	or.b	(a0)+,d1
	lsr.w	#4,d1
	move.w	d1,(a3)+
	dbra	d4,nextcol
	bsr	convertpal
	bra	readilbm		;get next piece of data
ckbody:
	cmp.l	#'BODY',d0		;is it the ilbm body?
	beq.s	continue		;
	move.l	chunklen(pc),d2		;weird chunk !!
	add.l	d2,a2			;ptr to next chunk
	bra	readilbm
continue:
	move.l	a2,picbodyptr
*************************************************
*	check for res here			*
*	ste version				*
*************************************************
	lea.l	bmhdcopy,a3		;use values from bmhd to initialize
	cmpi.w	#320,_w(a3)
	bne	quit
	cmpi.w	#200,_h(a3)
	bne	quit
	cmpi.b	#4,_nplanes(a3)
	bne	quit
	moveq	#0,d0
	move.w	_w(a3),d0
	divu	#8,d0		;gives number bytes per plane per line
	move.w	d0,bpline
	move.w	_h(a3),iheight
	moveq	#0,d0
	move.b	_nplanes(a3),d0
	move.w	d0,planes
	move.b	_compression(a3),d3
	cmp.b	#2,d3			;do i know this kind of compression?
	bge	quit			;no, give up...
decomp:
	move.l	picbodyptr,a0
*	move.l	savecard,a1
	move.l	hiden,a1
*****************************************************
* iff decompressor				    *
* a1 - destination address                          *
* a0 - source address                               *
*****************************************************
iffdecomp:
	move.w	iheight,d7	;number of lines
	subq	#1,d7
doaline:
	lea	buffer,a6
	move.w	planes,d6
	subq	#1,d6
daloop:
	move.w	bpline,d5
daloop2:
	moveq	#0,d0
	move.b	(a0)+,d0
	cmpi.b	#128,d0
	beq	daloop2
	tst.b	d0
	bmi	decomp2		;-127 <= n <= -1
decomp1:			;for use the next n +1 bytes literally
	move.b	(a0)+,(a6)+
	subq.w	#1,d5		;dec bpl counter
	dbf	d0,decomp1
	tst.w	d5		;finished 1 line of 1 plane
	bne	daloop2		;nope keep going
	dbf	d6,daloop	;planes counter
	bra	finline
decomp2:			;for use the next byte -n + 1 times
	neg.b	d0	;-n
	move.b	(a0)+,d1
dc2l:
	move.b	d1,(a6)+
	subq.w	#1,d5
	dbf	d0,dc2l
	tst.w	d5		;finished 1 line of 1 plane
	bne	daloop2		;nope keep going
	dbf	d6,daloop	;planes counter
finline:
	lea	buffer,a6
	move.w	bpline,d0
	lea	(a6,d0.w),a5
	lea	(a5,d0.w),a4
	lea	(a4,d0.w),a3
	move.w	bpline,d0
	asr.w	#1,d0
	subq.w	#1,d0
fnl:
	move.w	(a6)+,(a1)+
	move.w	(a5)+,(a1)+
	move.w	(a4)+,(a1)+
	move.w	(a3)+,(a1)+
	dbf	d0,fnl
	dbf	d7,doaline
	moveq	#1,d0
	bra	exitiff
quit:
freeiffbuff:
	moveq	#0,d0
exitiff:
	rts 
*****************************************
*	color converter			*
*	takes sensible color format	*
*	ie:	1,2,3,4-a,b,c,d,e,f	*
*	and turns it into the ste's 	*
*	stupid format			*
*	ie:	0,8,1,9,2,a,3,b,....	*
*****************************************
convertpal:
	movem.l	d0-a6,-(sp)
	lea	cmapcopy,a0
	lea	64(a0),a6	;32 colors max
	lea	redcolors,a2
	lea	greencolors,a3
	lea	bluecolors,a4
	lea	palconvert,a1		;where the new pal goes
conloop:
	moveq	#0,d0		;for construction
	moveq	#0,d1
	moveq	#0,d2
	moveq	#0,d3
	moveq	#0,d4
	move.w	(a0)+,d1	;get the color
	move.w	d1,d2		;copy it
	move.w	d2,d3
	and.w	#$0f00,d1	;isolate the red
	lsr.w	#8,d1		;now use it to index
	add.w	d1,d1
	or.w	(a2,d1.w),d0
	and.w	#$00f0,d2	;isolate the red
	lsr.w	#4,d2
	add.w	d2,d2
	or.w	(a3,d2.w),d0
	and.w	#$000f,d3	;isolate the red
	add.w	d3,d3
	or.w	(a4,d3.w),d0
	move.w	d0,(a1)+
	cmp.l	a6,a0
	blt	conloop
	movem.l	(sp)+,d0-a6
	rts
* ==========================================================================

transfer:	move.l  a0,-(sp)
		subq     #1,d3
copyinfo:	move.b   (a2)+,(a0)+
		dbra     d3,copyinfo
		move.l  (sp)+,a0
		rts

* ==========================================================================

redcolors:
	dc.w	$0000,$0800,$0100,$0900,$0200,$0a00,$0300,$0b00
	dc.w	$0400,$0c00,$0500,$0d00,$0600,$0e00,$0700,$0f00
greencolors:
	dc.w	$0000,$0080,$0010,$0090,$0020,$00a0,$0030,$00b0
	dc.w	$0040,$00c0,$0050,$00d0,$0060,$00e0,$0070,$00f0
bluecolors:
	dc.w	$0000,$0008,$0001,$0009,$0002,$000a,$0003,$000b
	dc.w	$0004,$000c,$0005,$000d,$0006,$000e,$0007,$000f

cleariff:
	lea	bpline,a0
	move.l	a0,d0
	move.l	#iffcend,d1
	sub.l	d0,d1
cil:
	move.b	#0,(a0)+
	dbf	d1,cil
	rts

bpline:		dc.w	0
iheight:		dc.w	0
planes:		dc.w	0
buffer:		ds.b	320		;maximum necessary for 1 line buff
iffsize:	dc.l	0

wdwptr:		dc.l	0
scrptr:		dc.l	0
picbodyptr:	dc.l	0

chunkbuff:
chunktype       dc.l	0	;iff chunk info -- ilbm string
chunklen        dc.l	0	
chunksubtype    dc.l	0

numcols		dc.w	0
height:		dc.w	0
width:		dc.w	0

bmhdcopy	ds.b	_sizeof
	even
cmapcopy	ds.b	32*2
coltable	ds.b	128
palconvert:	ds.b	64
iffcend:
		ds.w	10
		
savebuff:	dc.l	0
iffpointer:	dc.l	0

savesup:	dc.l	0
ressave:	dc.w	0
filename:	dc.l	0
bluepalette:
	dc.w	$0000,$0010,$0111,$0121,$0222,$0232,$0333,$0433
	dc.w	$0344,$0444,$0545,$0555,$0656,$0666,$0767,$0777
credtext:
	dc.b	27,'E'
	dc.b	'SHOWTRIX',$0D,$0a,$0D,$0a
	dc.b	'Programmed by Tony Barker of',$0D,$0a
	dc.b	'MOVING PIXELS',$0D,$0a
	dc.b	'(c) 1991',$0D,$0a
	dc.b	$0D,$0a
	dc.b	'Will handle NEO, PI1, PC1 and IFF.',$0D,$0a
	dc.b	'Does not handle some IFF files produced',$0D,$0a
	dc.b	'with Deluxe Paint ST, due to a',$0D,$0a
	dc.b	'different compression method.',$0D,$0a,$0D,$0a
	dc.b	'Moving Pixels can be contacted at:',$0D,$0a
	dc.b	'2/39 Frazer St',$0D,$0a
	dc.b	'Leichhardt, 2040',$0D,$0a
	dc.b	'AUSTRALIA',$0D,$0a
	dc.b	'Ph:(02)555 7312',$0D,$0a
	even
	section	bss
picbuffer:
	ds.b	40000
picpalette:
	ds.w	16
seenm:
	ds.b	32512
hidenm:
	ds.b	32512

