	fopt	prec=d
* 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

numframes:	equ	15
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	#40,delay
	bsr	setupscreen

	bsr	getfile
	moveq	#0,d6
	moveq	#0,d7
	move.w	delay,d7
mainloop:
	subq.w	#1,d7
	bpl	ook
	move.w	#37,-(sp)
	trap	#14
	addq.l	#2,sp

	move.w	delay,d7
	addq.l	#1,d6
	cmpi.w	#numframes,d6
	blt.s	okframes
	moveq	#0,d6
okframes:
	move.l	#(sw*2)*sh,d0
	mulu.l	d6,d0
	add.l	viewscreen,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
ook:
	movem.l	d6/d7,-(sp)
	bsr	keyboard
	movem.l	(sp)+,d6/d7
	bra	mainloop

getfile:
	move.w	#2,-(sp)
	move.l	#fname,-(sp)
	move.w	#$3D,-(sp)
	trap	#1
	addq.l	#8,sp
	move.w	d0,handle

	move.l	viewscreen,-(sp)
	move.l	#((sw*2)*sh)*numframes,-(sp)
	move.w	handle,-(sp)
	move.w	#$3f,-(sp)
	trap	#1
	add.l	#12,sp
	rts


fname:	dc.b	'TRACEY.ANM',0
	even
handle:	dc.w	0


*****************************************************************
*	Putpic, pass x and y in px,py and set expansion to 1	*
*	to blit the pic expanded or -1 to blit it normal or	*
*	0 to blit half size.					*
*****************************************************************
putpic:
	move.l	viewscreen,a1
	moveq	#9,d2
	move.l	py,d0
	move.l	d0,d1
	asl.l	d2,d0
	add.l	d0,a1
	asl.l	#8,d1
	add.l	d1,a1
	move.l	px,d0
	add.l	d0,d0
	add.l	d0,a1
	move.l	picsource,a0
	tst.w	expansion
	bgt	expandblit
	bmi	singleblit

*****************************************************************
*	This will take the 180*144 image in a0 and blit it	*
*	half size to the address in a1				*
*****************************************************************
halfblit:
	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	#4,src_xinc(a6)
	move.w	#2,dst_xinc(a6)
	move.w	#180/2,x_count(a6)
	move.w	#144/2,y_count(a6)
	move.w	#180*2,src_yinc(a6)
	move.w	#(sw*2)-180+2,dst_yinc(a6)
	move.w	#-1,endmask1(a6)
	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#$3,op(a6)
	move.b	#2,hop(a6)
	move.b	#%10000000,skew(a6)
*	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
.nhogwait:
	bset.b	#7,line_num(a6)
	bne	.nhogwait
	rts

*****************************************************************
*	This will take the 180*144 image in a0 and blit it	*
*	straight to the address in a1				*
*****************************************************************
singleblit:
	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	#180,x_count(a6)
	move.w	#144,y_count(a6)
	move.w	#0,src_yinc(a6)
	move.w	#(sw*2)-360+2,dst_yinc(a6)
	move.w	#-1,endmask1(a6)
	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#$3,op(a6)
	move.b	#2,hop(a6)
	move.b	#%10000000,skew(a6)
*	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
.nhogwait:
	bset.b	#7,line_num(a6)
	bne	.nhogwait
	rts

*****************************************************************
*	This will take the 180*144 image in a0 and blit it	*
*	expanded by 4 to the address in a1			*
*****************************************************************
expandblit:
	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	#4,dst_xinc(a6)
	move.w	#180,x_count(a6)
	move.w	#144,y_count(a6)
	move.w	#0,src_yinc(a6)
	move.w	#(sw*2)+48+4,dst_yinc(a6)
	move.w	#-1,endmask1(a6)
	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#$3,op(a6)
	move.b	#2,hop(a6)
	move.b	#%10000000,skew(a6)
*	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
.nhogwait:
	bset.b	#7,line_num(a6)
	bne	.nhogwait
expand1:
	lea	(sw*2)(a1),a2
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit
	move.l	a0,src_addr(a6)
	move.l	a2,dst_addr(a6)
	move.w	#180,x_count(a6)
	move.w	#144,y_count(a6)
	move.w	#0,src_yinc(a6)
	move.w	#(sw*2)+48+4,dst_yinc(a6)
	move.w	#2,src_xinc(a6)
	move.w	#4,dst_xinc(a6)
	move.b	#%10000000,skew(a6)
*	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
.nhogwait:
	bset.b	#7,line_num(a6)
	bne	.nhogwait
expand2:
	lea	2(a1),a2
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit
	move.l	a1,src_addr(a6)
	move.l	a2,dst_addr(a6)
	move.w	#180,x_count(a6)
	move.w	#144*2,y_count(a6)
	move.w	#4,src_xinc(a6)
	move.w	#4,dst_xinc(a6)
	move.w	#52,src_yinc(a6)
	move.w	#52,dst_yinc(a6)
	move.b	#%00000000,skew(a6)
*	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
.nhogwait:
	bset.b	#7,line_num(a6)
	bne	.nhogwait
	rts



printtime:
	move.l	time,d0
	moveq	#10,d1
	moveq	#0,d2
	moveq	#0,d3
	bsr	prtnum
	rts
printframes:
	move.l	frames,d0
	moveq	#10,d1
	moveq	#0,d2
	moveq	#1,d3
	bsr	prtnum

	move.l	time,d1
	divu	#200,d1
	move.l	frames,d0
	divu	d1,d0
	and.l	#$0000ffff,d0
	moveq	#10,d1
	moveq	#0,d2
	moveq	#2,d3
	bsr	prtnum

	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


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

	cmp.b	#16,d0		*space
	beq	exit		*yes/no
	cmpi.b	#$39,d0
	beq	pause
plus:
	cmpi.b	#$4e,d0
	bne	minus
	addq.w	#5,delay
	rts
minus:
	cmpi.b	#$4a,d0
	bne	keyback
	subq.w	#5,delay
keyback:
	rts

pause:
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	rts


exit:
	tst.l	viewscreen
	bmi	skipdm1
	move.l	viewscreen,d0
	bsr	deallocate
skipdm1:
	bsr	restoreregs

	bsr	printtime
	bsr	printframes

	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp


*	move.l	savedta,-(sp)
*	move.w	#$1a,-(sp)	;set disk transfer address
*	trap	#1
*	addq.l	#6,sp


	move.w	handle,-(sp)	;close file
	move.w	#$3e,-(sp)
	trap	#1
	addq.l	#4,sp


	move.l	savesp,-(sp)
	move.w	#$20,-(sp)
	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)*numframes,-(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

	bsr	saveregs
	bsr	setregs
	rts





viewscreen:	dc.l	-1
screen1:	dc.l	-1
screen2:	dc.l	-1

restoreregs:
	move.w	shht,hht
	move.w	shss,hss
	move.w	shbb,hbb
	move.w	shbe,hbe
	move.w	shdb,hdb
	move.w	shde,hde
	move.w	shfs,hfs
	move.w	shee,hee

	move.w	svid_bh,vid_bh
	move.w	svid_bm,vid_bm
	move.w	svid_bl,vid_bl

	move.w	svwrap,vwrap

	move.w	svft,vft
	move.w	svss,vss
	move.w	svbb,vbb
	move.w	svbe,vbe
	move.w	svdb,vdb
	move.w	svde,vde

	move.w	ssp_shift,sp_shift
	move.w	sst_shift,st_shift

	move.w	svco,vco

	lea	savepal,a0
	lea	st_palette,a1
	rept	16
	move.w	(a0)+,(a1)+
	endr

	rts

setregs:
	move.l	#0,sp_palette
	move.l	viewscreen,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	#524,vft
	move.w	#518,vss
	move.w	#513,vbb
	move.w	#22,vbe
	move.w	#27,vdb
	move.w	#507,vde

	move.w	#254,hht
	move.w	#214,hss
	move.w	#203,hbb
	move.w	#39,hbe
	move.w	#2,hdb
	move.w	#179,hde
	move.w	#$0100,sp_shift
	move.w	#2,vco
	move.w	#384,vwrap
	move.w	sp_palette,dummy
	rts


saveregs:
	move.w	vid_bh,svid_bh
	move.w	vid_bm,svid_bm
	move.w	vid_bl,svid_bl

	lea	savepal,a1
	lea	st_palette,a0
	rept	16
	move.w	(a0)+,(a1)+
	endr

	move.w	vft,svft
	move.w	vss,svss
	move.w	vbb,svbb
	move.w	vbe,svbe
	move.w	vdb,svdb
	move.w	vde,svde
	move.w	hht,shht
	move.w	hss,shss
	move.w	hbb,shbb
	move.w	hbe,shbe
	move.w	hdb,shdb
	move.w	hde,shde
	move.w	hfs,shfs
	move.w	hee,shee
	move.w	st_shift,sst_shift
	move.w	sp_shift,ssp_shift
	move.w	vco,svco
	move.w	vwrap,svwrap
	rts

	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
svid_bh:	ds.w	1
svid_bm:	ds.w	1
svid_bl:	ds.w	1
savepal:	ds.w	16
dummy:		ds.w	1
savesp:		ds.l	1
time:		ds.l	1
frames:		ds.l	1
px:		ds.l	1
py:		ds.l	1
picsource:	ds.l	1
expansion:	ds.w	1
pixelx:		ds.w	1
pixely:		ds.w	1
color:		ds.w	1
sxscreen:	ds.l	1
syscreen:	ds.l	1
delay:		ds.w	0

bufferword:
	ds.w	1

