offset:		equ	5900400
volume:		equ	$0070
slength:	equ	5965392
maxframes:	equ	750
                                                                                                                                                                                                                                                         
* BLiTTER BASE ADDRESS

blitter         equ     $FF8A00

* BLiTTER REGISTER OFFSETS

halftone        equ     0
src_xinc        equ     32
src_yinc        equ     34
src_addr        equ     36
endmask1        equ     40
endmask2        equ     42
endmask3        equ     44
dst_xinc        equ     46
dst_yinc        equ     48
dst_addr        equ     50
x_count         equ     54
y_count         equ     56
hop             equ     58
op              equ     59
line_num        equ     60
skew            equ     61
vbl_vec:	equ	$70

vertflag:	equ	$0100
stmodes:	equ	$0080
overscan:	equ	$0040
pal:		equ	$0020
vga:		equ	$0010
tv:		equ	$0000

col80:		equ	$0008
col40:		equ	$0000
numcols:	equ	$0007

bps16:		equ	4
bps8:		equ	3
bps4:		equ	2
bps2:		equ	1
bps1:		equ	0
mybit:		equ	%0000001000000000


fw:	equ	160
fh:	equ	120
sw:	equ	320
sh:	equ	240
*****************************************************************
*	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	putrout
	bsr	putvbl

	bsr	setupscreen
	bsr	clearscreens
	bsr	display
mainloop:

	bsr	keyboard
	bra	mainloop

display:
converttarga:
	move.l	viewscreen1,a1
	add.l	#sw*sh*2,a1
	lea	tga,a0
	lea	18(a0),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
*	or.b	(a0),d1
	addq.l	#2,a0
	move.w	d1,(a1)+
	endr
	sub.l	#(sw*2)*2,a1
	dbf	d0,.dsloop
	rts

swapnshow:
	move.l	viewscreen1,d0
	move.l	viewscreen2,viewscreen1
	move.l	d0,viewscreen2
*	move.w	#37,-(sp)
*	trap	#14
*	addq.l	#2,sp

waitvbl:
	move.w	#1,vblflag
wvbloop:
	tst.w	vblflag
	bpl	wvbloop

*	move.b	viewscreen1+1,$ff8205
*	move.b	viewscreen1+2,$ff8207
*	move.b	viewscreen1+3,$ff8209
*	rts
	move.l	viewscreen1,d0
	move.l	d0,d1
	move.l	d1,d2
	lsr.l	#8,d0
	lsr.l	#8,d0
	move.w	d0,vid_bh
	lsr.l	#8,d1
	and.l	#$000000ff,d1
	move.w	d1,vid_bm
	and.l	#$000000ff,d2
	move.w	d2,vid_bl
	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
syncmode:	dc.w	1

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
keyback:
	rts

pause:
	move.w	#7,-(sp)
	trap	#1
	addq.l	#2,sp
	rts


clearscreens:
	lea	blitter,a6
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit

	move.l	viewscreen1,a0
	move.l	viewscreen2,a1
	move.l	a0,dst_addr(a6)
	move.w	#2,dst_xinc(a6)
	move.w	#2,dst_yinc(a6)
	move.w	#sw,x_count(a6)
	move.w	#sh,y_count(a6)
	move.w	#-1,endmask1(a6)
 	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#0,skew(a6)
	move.b	#$0,op(a6)
	move.b	#2,hop(a6)
	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
nextscreen:
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit
	move.l	a1,dst_addr(a6)
	move.w	#2,dst_xinc(a6)
	move.w	#2,dst_yinc(a6)
	move.w	#sw,x_count(a6)
	move.w	#sh,y_count(a6)
	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
	rts



putpoint:
	movem.l	d0/d1/a0,-(sp)
	moveq	#0,d0
	move.l	d0,d1
	move.w	pixelx,d0
	add.l	d0,d0
	move.w	pixely,d1
	mulu	#sw*2,d1
	add.l	d1,d0
	move.l	viewscreen1,a0
	add.l	d0,a0
	move.w	color,(a0)
	movem.l	(sp)+,d0/d1/a0
	rts



buttondat:	dc.w	0
mx:		dc.w	0
my:	dc.w	0
*************puts my mouse interupt in***************** 
putrout:move.w  #34,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,a0
	move.l	16(a0),oldmouse
        move.l  #myrout,16(a0)
        rts
lastb:		dc.w	-1
mousehasgoneup:	dc.w	0

**************my ubeut mouse interupt*******************
myrout:
	movem.l	d0-d2/a0-a1,-(sp)
	moveq	#0,d0	
	move.b	(a0),d0
	cmpi.b	#$fa,d0
	bne	myr1
	move.w	#1,buttondat
	bra	myrxy
myr1:
	cmpi.b	#$f9,d0
	bne	myr2
	move.w	#2,buttondat
	bra	myrxy
myr2:
	cmpi.b	#$fb,d0
	bne	myr3
	move.w	#3,buttondat
	bra	myrxy
myr3:
	move.w	#1,mousehasgoneup
	move.w	#0,buttondat
myrxy:
	moveq	#0,d0
	move.b	1(a0),d0
	ext.w	d0
	moveq	#0,d1
	move.b	2(a0),d1
	ext.w	d1
	add.w	d0,mx
	add.w	d1,my
*	sub.w	d1,my2
myr4:	move.w	mx,d0
	move.w	my,d1
	bsr	extra
	move.w	d0,mx
	move.w	d1,my
	movem.l	(sp)+,d0-d2/a0-a1
	rts

extra:  cmpi.w	#mminx,d0
        bge	extra1
        move.w	#mminx,d0
        bra	extra2
extra1: cmpi.w   #mmaxx,d0
        ble	extra2
        move.w  #mmaxx,d0
extra2:	cmpi.w  #mminy,d1
        bge	extra3
        move.w  #mminy,d1
        bra	extra4
extra3: cmpi.w   #mmaxy,d1
        ble	extra4
        move.w  #mmaxy,d1
extra4:
        rts

mminx:	equ	0
mmaxx:	equ	sw
mminy:	equ	0
mmaxy:	equ	sh


putvbl:
	move.l	vbl_vec,vblt+2		;set up vbl handler
	move.l	vbl_vec,oldvblvec
	move.l	#vbl_handler,vbl_vec
	rts

halfframe:	dc.w	0
ddl:		dc.w	-1
vbl_handler:
*	move.b	currentscreen+1,$ff8205
*	move.b	currentscreen+2,$ff8207
*	move.b	currentscreen+3,$ff8209
*	subq.w	#1,halfframe
*	bpl.s	skipfa
*	tst.w	syncmode
*	bmi	skipfa
*	move.w	#1,halfframe
*	addq.l	#1,frame		;update current frame each
*	cmpi.l	#maxframes,frame
*	blt	skipfa
*	move.l	#0,frame
*	move.w	#1,ddl
skipfa:
	move.w	#-1,vblflag
vblt:
	jmp	$0.L




exit:
	move.w  #34,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,a0
	move.l	oldmouse,16(a0)

	lea	memlist,a6
demem:
	move.l	(a6)+,d0
	bmi	nomoremem
	beq	demem
	bsr	deallocate
	bra	demem
nomoremem:
	move.l	oldvblvec,vbl_vec

	move.w	savemode,-(sp)
	move.w	#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	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
	move.l	d0,savemem1
	add.l	#4,d0
	and.l	#$fffffffc,d0
	move.l	d0,viewscreen1
	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
	move.l	d0,savemem2
	add.l	#4,d0
	and.l	#$fffffffc,d0
	move.l	d0,viewscreen2

	move.w	#2,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,savescreen

	move.w	#-1,-(sp)
	move.l	viewscreen1,-(sp)
	move.l	viewscreen1,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp

	move.w	#vertflag|vga|col40|bps16,-(sp)
	move.w	#88,-(sp)
	trap	#14
	addq.l	#4,sp
	move.w	d0,savemode

	move.l	#0,$ffff9800
	rts

c25:		dc.b	1
	even

viewscreen2:	dc.l	-1
viewscreen1:	dc.l	-1
memlist:
savemem1:	dc.l	0
savemem2:	dc.l	0
savemem3:	dc.l	0
		dc.l	-1	;end of mem list flag

soundmem:	dc.l	0
howlong:	dc.l	0
handles:	dc.w	0
fnamesound:	dc.b	'SAMPLE.TRK'
	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
svid_bh:	ds.w	1
svid_bm:	ds.w	1
svid_bl:	ds.w	1
savepal:	ds.w	16

dummy:		ds.w	1
color:		ds.w	1
pixelx:		ds.w	1
pixely:		ds.w	1
savesp:		ds.l	1
time:		ds.l	1
frames:		ds.l	1
blitx:		ds.l	1
blity:		ds.l	1
picsource:	ds.l	1
expansion:	ds.w	1
oldmouse:	ds.l	1
whichpic:	ds.l	1
frame:		ds.l	1
whicheffect:	ds.l	1
oldvblvec:	ds.l	1
vblflag:	ds.w	1
savescreen:	ds.l	1
savemode:	ds.w	1
save114:	ds.l	1
mastervol:	ds.w	1
bufferword:
	ds.w	1
	section data
tga:
	incbin	'road.tga'

