	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


sw:	equ	384
sh:	equ	480

fpsw2:		fequ.s	358.5		;(sh-1)
fpsh2:		fequ.s	142.5		;(sw*2)-1.5	

fpsh:		fequ.s	479		;(sh-1)
fpsw:		fequ.s	766.5		;(sw*2)-1.5	

*****************************************************************
*	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

	bsr	setupscreen

	move.l	$4ba,time		;get time
	move.l	#0,frames
*	bsr	copyscr
	bsr	trace
mainloop:
*	cmpi.l	#200,frames
*	blt	ook
	move.l	$4ba,d7
	sub.l	time,d7
	move.l	d7,time
*	bra	exit
ook:
	addq.l	#1,frames
	bsr	keyboard
	bra	mainloop


trace:
	fmove.s	#0,fp0
	fmove.s	fp0,vx	;view coodrs
	fmove.s	#0,fp0
	fmove.s	fp0,vy
	fmove.s	#-450,fp0
	fmove.s	fp0,vz
	fmove.s	#200,fp0
	fmove.s	fp0,cx		;sphere coords
	fmove.s	#100,fp0
	fmove.s	fp0,cy
	fmove.s	#250,fp0
	fmove.s	fp0,cz
	fmove.s	#50,fp0
	fmove.s	fp0,r
	fmove.s	#0,fp0
	fmove.s	fp0,fxdisp	;pattern offsets
	fmove.s	#0,fp0
	fmove.s	fp0,fzdisp
	fmove.s	#0,fp0
	fmove.s	fp0,ydm		;dimming flag
	move.l	vy,horizon
	fmove.s	#0,fp7
	moveq	#9,d7		;for address calcs
	move.l	viewscreen,a0
yloop:
	fmove.s #0.5,fp6
xloop:
	fmove	fp6,fp0		;sxscr=(sx-0.5)/2
	fsub.s	#0.5,fp0
	fdiv.s	#2,fp0
	fmove.l	fp0,sxscreen
	fmove.l	fp7,syscreen	;syscr=sy

	fmove	fp6,fp0
	fsub.s	vx,fp0		;(sx-vx)*(sx-vx)
	fmove.s	fp0,sx_vx
	fmul	fp0,fp0
	fmove	fp7,fp1		;+
	fsub.s	vy,fp1		;(sy-vy)*(sy-vy)
	fmove.s	fp1,sy_vy
	fmul	fp1,fp1
	fadd	fp1,fp0		;+
	fmove.s	vz,fp1
	fmul	fp1,fp1		;vz*vz
	fadd	fp1,fp0
	fmove.s	fp0,ta1

	fmove.s	sx_vx,fp0
	fmove.s	vx,fp1		;*		A
	fsub.s	cx,fp1		;(vx-cx)
	fmove.s	fp1,vx_cx
	fmul	fp1,fp0
	fmove.s	sy_vy,fp1
	fmove.s	vy,fp2		;*		B
	fsub.s	cy,fp2		;(vy-cy)
	fmul	fp2,fp1
	fmove.s	vz,fp2
	fsub.s	cz,fp2				C
	fmul.s	vz,fp2		;-vz*(vz-cz)
	fadd	fp0,fp1
	fsub	fp2,fp1		;a+b-c
	fadd	fp1,fp1		;*2
	fmove.s	fp1,tb1

	fmove.s	vx_cx,fp0
	fmul	fp0,fp0		;*(vx-cx)
	fmove.s	vy,fp1
	fsub.s	cy,fp1		;(vy-cy)
	fmul	fp1,fp1		;*(vy-cy)
	fadd	fp1,fp0

	fmove.s	vz,fp1
	fsub.s	cz,fp1		;(vz-cz)
	fmul	fp1,fp1		;*(vz-cz)
	fadd	fp1,fp0

	fmove.s	r,fp1
	fmul	fp1,fp1		;-r*r
	fsub	fp1,fp0
	fmove.s	fp0,tc1

	fmove.s	tb1,fp0
	fmul	fp0,fp0
	fmove.s	ta1,fp1
	fmul.s	tc1,fp1
	fmul.s	#4,fp1		;arg=b1*b1-4*a1*c1
	fsub	fp1,fp0
	fmove.s	fp0,arg
	ftst	fp0
	fble	l1250
l1100:
	fsqrt	fp0,fp0
	fsub.s	tb1,fp0		;(-b1+sqr(arg))
	fmove.s	ta1,fp1		;/
	fadd	fp1,fp1		;(2*a1)
	fdiv	fp1,fp0
	fmove.s	fp0,scale1
	fmove.s	sx_vx,fp1
	fmul	fp0,fp1		;dx=scale1*(sx-vx)
	fmove.s	fp1,dx
	
	fmove.s	sy_vy,fp2
	fmul	fp0,fp2		;dy=scale1*(sy-vy)
	fmove.s	fp2,dy

	fmove	fp0,fp3
	fneg	fp3
	fmul.s	vz,fp3		;dz=-scale1*vz
	fmove.s	fp3,dz

	fmove	fp1,fp4
	fadd.s	vx_cx,fp4
	fmove.s	fp4,rx
	fmove	fp2,fp4
	fadd.s	vy,fp4
	fsub.s	cy,fp4		;ry=dy+vy-cy
	fmove.s	fp4,ry
	fmove	fp3,fp4
	fadd.s	vz,fp4
	fsub.s	cz,fp4		;rz=dz+vz-cz
	fmove.s	fp4,rz

	fmove	fp1,fp4
	fmul.s	rx,fp4
	fmove	fp2,fp5
	fmul.s	ry,fp5
	fadd	fp5,fp4
	fmove	fp3,fp5		;ddotn=(dx*rx+dy*ry+dz*rz)/r
	fmul.s	rz,fp5
	fadd	fp5,fp4
	fdiv.s	r,fp4
	fmove.s	fp4,ddotn

	fmove.s	#fpsh,fp4	;(191-cy-ry)
	fsub.s	cy,fp4
	fsub.s	ry,fp4
	fmove.s	ddotn,fp5
	fmul.s	ry,fp5		;/(dy+2*ddotn*ry/r)
	fadd	fp5,fp5
	fadd	fp2,fp5
	fdiv.s	r,fp5
	fdiv	fp5,fp4
	fmove.s	fp4,scale2
	ftst	fp4
	fbge	l1220


	fmove.s	#0,fp4		;(0-cy-ry)
	fsub.s	cy,fp4
	fsub.s	ry,fp4
	fmove.s	ddotn,fp5
	fmul.s	ry,fp5		;/(dy+2*ddotn*ry/r)
	fadd	fp5,fp5
	fadd	fp2,fp5
	fdiv.s	r,fp5
	fdiv	fp5,fp4
	fmove.s	fp4,scale2

	lea	roof,a6		;ray hits roof
	bsr	l1420
	bra	l1330
l1220:
	lea	floor,a6
	bsr	l1420
	bra	l1330
l1250:
	move.l	sx_vx,dx

	fmove.s	sy_vy,fp0
	fmove.s	fp0,dy

	fmove.s	vz,fp0
	fneg	fp0		;dz=-vz
	fmove.s	fp0,dz

	fcmp.s	horizon,fp7
	fble	l1300
	fmove.s	#fpsh,fp0
	fsub.s	vy,fp0		;a=(191-vy)/dy
	fdiv.s	dy,fp0
	fmove.s	fp0,a
	lea	floor,a6
	bsr	l1550
	bra	l1330
l1300:
	fmove.s	#0,fp0
	fsub.s	vy,fp0		;a=(0-vy)/dy
	fdiv.s	dy,fp0
	fmove.s	fp0,a
	lea	roof,a6
	bsr	l1550
l1330:
	fadd.s	#2,fp6
	fcmp.s	#fpsw2,fp6
	fblt	xloop
l1350:
	bsr	keyboard
	fadd.s	#1,fp7
	fcmp.s	#fpsh2,fp7
	fblt	yloop
	rts

l1420:
	fmove.s	dx,fp0
	fmove.s	ddotn,fp1
	fmul.s	rx,fp1
	fdiv.s	r,fp1
	fadd	fp1,fp1
	fsub	fp1,fp0		;drx=dx-2*ddotn*rx/r
	fmove.s	fp0,drx

	fmove.s	dy,fp0
	fmove.s	ddotn,fp1
	fmul.s	ry,fp1
	fdiv.s	r,fp1
	fadd	fp1,fp1
	fsub	fp1,fp0		;dry=dy-2*ddotn*ry/r
	fmove.s	fp0,dry

	fmove.s	dz,fp0
	fmove.s	ddotn,fp1
	fmul.s	rz,fp1
	fdiv.s	r,fp1
	fadd	fp1,fp1
	fsub	fp1,fp0		;drz=dz-2*ddotn*rz/r
	fmove.s	fp0,drz

	fmove.s	scale2,fp0
	fmul.s	drx,fp0
	fadd.s	cx,fp0		;fx=cx+rx+scale2*drx+fxdisp
	fadd.s	rx,fp0
	fadd.s	fxdisp,fp0
	fmove.s	fp0,fx

	fmove.s	scale2,fp0
	fmul.s	dry,fp0
	fadd.s	cy,fp0		;fy=cy+ry+scale2*dry
	fadd.s	ry,fp0
	fmove.s	fp0,fy

	fmove.s	scale2,fp0
	fmul.s	drz,fp0
	fadd.s	cz,fp0		;fz=cz+rz+scale2*drz+fzdisp
	fadd.s	rz,fp0
	fadd.s	fzdisp,fp0
	fmove.s	fp0,fz

	fmove.s	fx,fp0
	fmove	fp0,fp1
	fdiv.s	#fpsw,fp0
	fint	fp0,fp0		;fxscr=((fx-int(fx/318.5)*318.5)-0.5)/2
	fmul.s	#fpsw,fp0
	fsub	fp0,fp1
	fsub.s	#0.5,fp1
	fdiv.s	#2,fp1
	fmove.l	fp1,d0
	add.l	#sw/2,d0

	fmove.s	fz,fp0
	fmove	fp0,fp1
	fdiv.s	#fpsh,fp0
	fint	fp0,fp0		;fzscr=191-(fz-int(fx/191)*191)
	fmul.s	#fpsh,fp0
	fsub	fp0,fp1
	fmove.s	#fpsh,fp0
	fsub	fp1,fp0
	fmove.l	fp0,d1
	sub.l	#sh/2,d1
	bsr	getpoint

*	move.w	color,d0
*	lsr.w	#1,d0
*	bclr	#10,d0
*	bclr	#4,d0
*	move.w	d0,color
	move.l	sxscreen,d0
	move.l	syscreen,d1
	bsr	putpoint
	rts

l1550:
	fmove.s	a,fp0
	fmul.s	dx,fp0
	fadd.s	vx,fp0		;fx=vx+a*dx+fxdisp
	fadd.s	fxdisp,fp0
	fmove.s	fp0,fx

	fmove.s	a,fp0
	fmul.s	dy,fp0
	fadd.s	vy,fp0		;fy=vy+a*dy
	fmove.s	fp0,fy

	fmove.s	a,fp0
	fmul.s	dz,fp0
	fadd.s	vz,fp0		;fz=vz+a*dz+fzdisp
	fadd.s	fzdisp,fp0
	fmove.s	fp0,fz


	fmove.s	fx,fp0
	fmove	fp0,fp1
	fdiv.s	#fpsw,fp0
	fint	fp0,fp0		;fxscr=((fx-int(fx/318.5)*318.5)-0.5)/2
	fmul.s	#fpsw,fp0
	fsub	fp0,fp1
	fsub.s	#0.5,fp1
	fdiv.s	#2,fp1

	fmove.l	 fp1,d0
	add.l	#sw/2,d0

	fmove.s	fz,fp0
	fmove	fp0,fp1
	fdiv.s	#fpsh,fp0
	fint	fp0,fp0		;fzscr=191-(fz-int(fz/191)*191)
	fmul.s	#fpsh,fp0
	fsub	fp0,fp1
	fmove.s	#fpsh,fp0
	fsub	fp1,fp0
	fmove.l	fp0,d1
	sub.l	#sh/2,d1

	bsr	getpoint
	move.l	sxscreen,d0
	move.l	syscreen,d1
	bsr	putpoint
	rts



vx_cx:	dc.l	0,0
sy_vy:	dc.l	0,0
sx_vx:	dc.l	0,0
a:	dc.l	0,0
fx:	dc.l	0,0
fz:	dc.l	0,0
fy:	dc.l	0,0
dry:	dc.l	0,0
drz:	dc.l	0,0
drx:	dc.l	0,0
scale1:	dc.l	0,0
scale2:	dc.l	0,0
ddotn:	dc.l	0,0
dx:	dc.l	0,0
dy:	dc.l	0,0
dz:	dc.l	0,0
rx:	dc.l	0,0
ry:	dc.l	0,0
rz:	dc.l	0,0
arg:	dc.l	0,0
tc1:	dc.l	0,0
tb1:	dc.l	0,0
ta1:	dc.l	0,0
vz:	dc.l	0,0
vx:	dc.l	0,0
vy:	dc.l	0,0
cz:	dc.l	0,0
cx:	dc.l	0,0
cy:	dc.l	0,0
r:	dc.l	0,0
fxdisp:	dc.l	0,0
fzdisp:	dc.l	0,0
ydm:	dc.l	0,0
horizon:	dc.l	0,0


getpoint:
	tst.l	d0
	bge.s	.xok1
	moveq	#0,d0
	bra	.xok2
.xok1:
	cmpi	#sw-1,d0
	ble.s	.xok2
	move.w	#sw-1,d0
.xok2:
	add.l	d0,d0
*	move.w	pixely,d1
	tst.l	d1
	bge.s	.yok1
	moveq	#0,d1
	bra	.yok2
.yok1:
	cmpi.w	#sh-1,d1
	ble.s	.yok2
	move.w	#sh-1,d1
.yok2:
	move.l	d1,d2
	asl.l	d7,d1
	add.l	d1,d0
	asl.l	#8,d2
	add.l	d2,d0
*	mulu	#sw*2,d1
*	add.l	d1,d0
	move.w	(a6,d0.l),color
	rts

putpoint:
	add.l	#100,d0
	add.l	#150,d1
	add.l	d0,d0
	move.l	d1,d2
	asl.l	d7,d1
	add.l	d1,d0
	asl.l	#8,d2	
	add.l	d2,d0
	move.w	color,(a0,d0.l)
	rts

*****************************************************************
*	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	#2,inc
	rts
minus:
	cmpi.b	#$4a,d0
	bne	keyback
*	subq.w	#2,inc
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:
	tst.l	screen1
	bmi	skipdm2
	move.l	screen1,d0
	bsr	deallocate
skipdm2:
	tst.l	screen2
	bmi	skipdm3
	move.l	screen2,d0
	bsr	deallocate
skipdm3:
	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.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)+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

	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

copyscr:
	move.l	viewscreen,a1
	lea	floor,a0
	move	#479,d0
csl:
	rept	sw
	move.w	(a0)+,(a1)+
	endr
	dbf	d0,csl
	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


bufferword:
	ds.w	1
	section data
roof:
	incbin	'roof.img'
floor:
	incbin	'floor.img'
picend:

