MFP:	EQU	$FFFA00
IERA:	EQU	MFP+$07
IERB:	EQU	MFP+$09
IPRA:	EQU	MFP+$0B
iISRA:	EQU	MFP+$0F
IMRA:	EQU	MFP+$13
IMRB:	EQU	MFP+$15
VECTOR:	EQU	MFP+$17
TACR:	EQU	MFP+$19
TADR:	EQU	MFP+$1F
ISRVEC:	EQU	$134
SCREG:	EQU	$FF8800		;CHIP REGISTER SELECT
SCDATA:	EQU	$FF8802		;REGISTER DATA


channelvolume:		equ	0
channelwaveform:	equ	2
channellife:		equ	4
channelspeed:		equ	6
channelspeed2:		equ	8
channelfine:		equ	10
channelcoarse:		equ	12
channelreg:		equ	14
channeladd:		equ	16
channelcmp:		equ	18
channelprocess:		equ	20
channelnoise:		equ	22
channelreg2:		equ	24
channelvel:		equ	26
channelmixa:		equ	28
channelvolreg:		equ	30
channelfinereg:		equ	32
channelcoarsereg:	equ	34
channeloff:		equ	36
channelmixb:		equ	38

v:		equ	2
master:		equ	0
slave:		equ	1
single:		equ	2
yv8:		equ	3
xv8:		equ	3
nsamount2:	equ	1
*	sound stuff	*
soundstarth:	equ	2
soundstartm:	equ	4
soundstartl:	equ	6
soundendh:	equ	$e
soundendm:	equ	$10
soundendl:	equ	$12
soundmode:	equ	$20
sounddma:	equ	0

putlast:	equ	0
cxmax:		equ	319
cxmin:		equ	0
cymax:		equ	200
cymin:		equ	0
cspritex:	equ	0
cspritey:	equ	2
cspriteheight:	equ	8
cspritewidth:	equ	10
cspritead:	equ	4
cactive:	equ	12
cspritevisflag:	equ	14
cspriteclipflag:equ	16
cspritecliph:	equ	17
cquickaddress:	equ	18
cquickspaddress:equ	22
cspritexvel:	equ	26
cspriteyvel:	equ	28
cspritelife:	equ	30
cspritesub:	equ	30
cspritelocation:	equ	34
cspriteheading:		equ	38
cspritegoing:		equ	42
cspritelistad:		equ	44
cspritefollow:		equ	48
cspritefight:		equ	50
cspritehits:		equ	52
tankspine:		equ	54
tankplanee:		equ	56
tankimagee:		equ	58
tankstarte:		equ	62
tankadde:		equ	66
enshotlistp:		equ	70
whichmee:		equ	74
whichmestarte:		equ	75
whichmehighe:		equ	76
cspritevels:		equ	78
cspriteshotdel:		equ	80
cspriteexploding:	equ	82
cspriterotate:		equ	84

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
start:
*	move.l	sp,a5
*	move.l	4(a5),a5
*	move.l	$c(a5),d0
*	add.l	$14(a5),d0
*	add.l	$1c(a5),d0
*	add.l	#$100,d0	;basepage amount
*	add.l	#512000,d0
*	move.l	d0,-(sp)	;amount to keep
*	move.l	a5,-(sp)	;mem to mod
*	move	d0,-(sp)	;dummy
*	move.w	#$4a,-(sp)
*	trap	#1
*	add.l	#12,sp
*	tst.l	d0
*	bne	gem2

	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
        move.l  D0,savesup

	bsr	setupgem
righttos:
	cmpi.b	#5,$424
	bge.s	rightmem
	jmp	alertout
rightmem:
	dc.w	$a00a
	move.b	#0,$484
	move.l	$426,rvsave
	move.l	$42a,resave
	move.w	#4,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	d0,ressave

	move.w	#0,-(sp)	;set to low res
	move.l	#-1,-(sp)
	move.l	#-1,-(sp)
	move.w	#5,-(sp)	
	trap	#14
	add.l	#12,sp
	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)+

	move.l	#myprt,$502

	move.w	#2,-(sp)
	move.w	#14,-(sp)
	trap	#14
	addq.l	#4,sp
	move.l	d0,a0
	move.l	a0,midibuff
	move.l	$84,trappoke+2
	move.l	#mytrap,$84
	jsr	getscrn

	lea	blackpal2,a0
	bsr	mydocolors3
	bsr	dotitle
	move.w	#-1,novbl

*	move.b	#%11111110,$ff820a
	bsr	putrout


	move.l	#filefb,filename
	move.l	#blocks,wheretoload
	jsr	loadscr
	move.l	#fileme,filename
	move.l	#mesprites,wheretoload
	jsr	loadscr
	move.l	#filemetank,filename
	move.l	#metanksprites,wheretoload
	jsr	loadscr
	move.l	#fileshots,filename
	move.l	#shotsprites,wheretoload
	jsr	loadscr
	move.l	#fileenemy,filename
	move.l	#enemysprites,wheretoload
	jsr	loadscr
	move.l	#fileenemytank,filename
	move.l	#enemytanksprites,wheretoload
	jsr	loadscr
	move.l	#filemap1,filename
	move.l	#gamemap,wheretoload
	jsr	loadscr
	move.l	#fileintel,filename
	move.l	#list,wheretoload
	bsr	loadscr
	move.l	#filemain,filename
	move.l	hiden,wheretoload
	bsr	loadscr

	jsr	prepchannels
	lea	channel0params,a0
	move.w	#%00001001,channeloff(a0)
	move.w	#-1,channelprocess(a0)
	lea	channel1params,a0
	move.w	#%00010010,channeloff(a0)
	move.w	#-1,channelprocess(a0)
	lea	channel2params,a0
	move.w	#%00100100,channeloff(a0)
	move.w	#-1,channelprocess(a0)

	lea	blackpal2,a0
	bsr	mydocolors3
	move.w	#1,novbl
	move.l	oldvbl1,$70
	move.l	$70,oldvbl1
	move.l	$70,gooldvbl+2
	move.l	#framevbl,$70
	move.l	#filemap,filename
	move.l	screen,wheretoload
	jsr	loadscr

	move.l	$ff8206,d0
	bsr	randomseed

	bsr	joystuff
	bsr	mydocolors
*	move.w	#1,my
	move.b	screen+1,$ff8201
	move.b	screen+2,$ff8203
*	bsr	setuphbl
	bsr	setgemcolor
	bsr	setgemsize	;small font

dorestart:
	jsr	stopallsound
	move.l	hiden,a0
	move.l	seen,a1
	move.w	#7999,d0
drcl:
	move.l	(a0)+,(a1)+
	dbf	d0,	drcl

	bsr	doclearnums
	move.w	#0,enemydead
	move.w	#0,number
	move.w	#4001,numwhere
	bsr	prtnum
	move.w	#3,mines
	move.w	#2,tanks
	move.w	#0,mehits
	move.w	#-1,memapsp
	move.w	#-1,enmapsp0
	move.w	#-1,enmapsp1
	move.w	#64,shots
	bsr	clearallsprites
	bsr	testcopy
*	bsr	makemap
*	move.l	seen,a0
*	move.l	#-1,(a0)+
*	move.l	#-1,(a0)+
	move.w	#-1,mewepsp
	move.w	#-1,enwepsp
	move.w	#-1,displaymap
	bra	establishcoms


gamemulti:
mainloop:
	bsr	stch
	tst.w	tankspin
	bpl.s	skipjoy
	bsr	joydir
skipjoy:
	bsr	docollisions
	bsr	doshots
	bsr	dome
	bsr	domines
	bsr	keyboard
	bsr	sendme
	bsr	doothers
	bsr	plotplayersm
	tst.w	cheatmode
	bpl.s	skipcheat1
	cmpi.w	#12,mehits
	bge.s	exploding
skipcheat1:
	bsr	testcopy
	bsr	drawsprites
	bsr	flip_scrmidi
	bra.s	mainloop
exploding:
	move.w	#-1,tankplane
	lea	tanksp,a0
	move.w	tanks,d0
	lea	tankxylist,a1
*	asl.w	#1,d0
	add.w	d0,d0
	move.w	(a1,d0.w),(a0)
	bsr	putsprite
	subq.w	#1,tanks
	lea	bigboomsound,a6
	bsr	startsound
	move.w	#0,xvel
	move.w	#0,yvel
	lea	mesp,a0
	move.w	#-1,cactive(a0)
	lea	meshot1,a1
	lea	meshot2,a2
	lea	meshot3,a3
	lea	meshot4,a4
	move.w	cspritex(a0),d0
	move.w	cspritey(a0),d1
	addq.w	#7-1,d0
	addq.w	#7-1,d1
	move.w	d0,cspritex(a1)
	move.w	d1,cspritey(a1)
	addq.w	#3,cspritex(a1)
	subq.w	#3,cspritey(a1)
	move.w	#1,cactive(a1)
	move.w	#3,cspritexvel(a1)
	move.w	#-3,cspriteyvel(a1)
	move.w	#50,cspritelife(a1)
	move.w	d0,cspritex(a2)
	move.w	d1,cspritey(a2)
	addq.w	#3,cspritex(a2)
	addq.w	#3,cspritey(a2)
	move.w	#1,cactive(a2)
	move.w	#3,cspritexvel(a2)
	move.w	#3,cspriteyvel(a2)
	move.w	#50,cspritelife(a2)
	move.w	d0,cspritex(a3)
	move.w	d1,cspritey(a3)
	subq.w	#3,cspritex(a3)
	addq.w	#3,cspritey(a3)
	move.w	#1,cactive(a3)
	move.w	#-3,cspritexvel(a3)
	move.w	#3,cspriteyvel(a3)
	move.w	#50,cspritelife(a3)
	move.w	d0,cspritex(a4)
	move.w	d1,cspritey(a4)
	move.w	#1,cactive(a4)
	move.w	#-3,cspritexvel(a4)
	move.w	#-3,cspriteyvel(a4)
	move.w	#50,cspritelife(a4)
	subq.w	#3,cspritex(a4)
	subq.w	#3,cspritey(a4)
exploop2:
	bsr	movemyshots
	bsr	docollisions
	bsr	sendme
	bsr	doothers
	bsr	plotplayersm
	lea	meshot1,a0
	cmpi.w	#-1,cactive(a0)
	bne.s	go2
	lea	meshot2,a0
	cmpi.w	#-1,cactive(a0)
	bne.s	go2
	lea	meshot3,a0
	cmpi.w	#-1,cactive(a0)
	bne.s	go2
	lea	meshot4,a0
	cmpi.w	#-1,cactive(a0)
	bne.s	go2
	bra.s	nomore
go2:
	bsr	testcopy
	bsr	drawsprites
	bsr	flip_scrmidi
	bra	exploop2
nomore:
	lea	poslist,a0
	moveq	#4,d0
	bsr	randomplus
	lsl.w	#2,d0
	move.w	(a0,d0.w),screenx
	move.w	2(a0,d0.w),screeny
	lea	mesp,a0
	bsr	testc
	move.w	cspritex(a0),d0
	move.w	cspritey(a0),d1
	lea	enemysp0,a1
	sub.w	cspritex(a1),d0
	sub.w	cspritey(a1),d1
	muls	d0,d0
	muls	d1,d1
	add.l	d0,d1
	bsr	sqrt
	cmpi.l	#200,d1
	blt	nomore

	move.w	#0,mehits
	lea	bar2sp,a0
	bsr	putsprite
	move.w	#-1,tankplane
	lea	mesp,a0
	move.l	#metanksprites,cspritead(a0)
	move.w	#1,cactive(a0)
	move.b	#8,whichme
	move.w	#-1,tankspin
	move.w	#-yv8,shotyvel
	move.w	#0,shotxvel
	bra	mainloop

gamesingle:
	bsr	stch
	tst.w	tankspin
	bpl.s	skipjoys
	bsr	joydir
skipjoys:
	bsr	docollisions
	bsr	doshots
	bsr	doenemyshots
	bsr	doenminedrop
	bsr	dome
	bsr	enemycollision
	bsr	doenemy
	bsr	doenexplode
	bsr	domines
	jsr	keyboard
	bsr	plotplayers
	tst.w	cheatmode
	bpl.s	skipcheat2
	cmpi.w	#12,mehits
	bge	exploding2
skipcheat2:
	bsr	testcopy
	bsr	drawsprites
	bsr	flip_scr
	bra.s	gamesingle

exploding2:
	move.w	#-1,tankplane
	lea	tanksp,a0
	move.w	tanks,d0
	lea	tankxylist,a1
*	asl.w	#1,d0
	add.w	d0,d0
	move.w	(a1,d0.w),(a0)
	bsr	putsprite
	subq.w	#1,tanks
	lea	bigboomsound,a6
	bsr	startsound
	move.w	#0,xvel
	move.w	#0,yvel
	lea	mesp,a0
	move.w	#-1,cactive(a0)
	lea	meshot1,a1
	lea	meshot2,a2
	lea	meshot3,a3
	lea	meshot4,a4
	move.w	cspritex(a0),d0
	move.w	cspritey(a0),d1
	addq.w	#7-1,d0
	addq.w	#7-1,d1
	move.w	d0,cspritex(a1)
	move.w	d1,cspritey(a1)
	addq.w	#3,cspritex(a1)
	subq.w	#3,cspritey(a1)
	move.w	#1,cactive(a1)
	move.w	#3,cspritexvel(a1)
	move.w	#-3,cspriteyvel(a1)
	move.w	#50,cspritelife(a1)
	move.w	d0,cspritex(a2)
	move.w	d1,cspritey(a2)
	addq.w	#3,cspritex(a2)
	addq.w	#3,cspritey(a2)
	move.w	#1,cactive(a2)
	move.w	#3,cspritexvel(a2)
	move.w	#3,cspriteyvel(a2)
	move.w	#50,cspritelife(a2)
	move.w	d0,cspritex(a3)
	move.w	d1,cspritey(a3)
	subq.w	#3,cspritex(a3)
	addq.w	#3,cspritey(a3)
	move.w	#1,cactive(a3)
	move.w	#-3,cspritexvel(a3)
	move.w	#3,cspriteyvel(a3)
	move.w	#50,cspritelife(a3)
	move.w	d0,cspritex(a4)
	move.w	d1,cspritey(a4)
	move.w	#1,cactive(a4)
	move.w	#-3,cspritexvel(a4)
	move.w	#-3,cspriteyvel(a4)
	move.w	#50,cspritelife(a4)
	subq.w	#3,cspritex(a4)
	subq.w	#3,cspritey(a4)
exploop2s:
	bsr	docollisions
	bsr	enemycollision
	bsr	doshots
	bsr	doenemyshots
	bsr	doenemy
	jsr	keyboard
	bsr	plotplayers
	lea	meshot1,a0
	cmpi.w	#-1,cactive(a0)
	bne.s	go2s
	lea	meshot2,a0
	cmpi.w	#-1,cactive(a0)
	bne.s	go2s
	lea	meshot3,a0
	cmpi.w	#-1,cactive(a0)
	bne.s	go2s
	lea	meshot4,a0
	cmpi.w	#-1,cactive(a0)
	bne.s	go2s
	bra.s	nomores
go2s:
	bsr	testcopy
	bsr	drawsprites
	bsr	flip_scr
	bra	exploop2s
nomores:
	tst.w	tanks
	bmi.L	restartsingle
	lea	poslist,a0
	moveq	#4,d0
	bsr	randomplus
	lsl.w	#2,d0
	move.w	(a0,d0.w),screenx
	move.w	2(a0,d0.w),screeny
	move.w	#0,mehits
	lea	bar2sp,a0
	bsr	putsprite
	move.w	#-1,tankplane
	lea	mesp,a0
	move.l	#metanksprites,cspritead(a0)
	move.w	#1,cactive(a0)
	move.b	#8,whichme
	move.w	#-1,tankspin
	move.w	#-yv8,shotyvel
	move.w	#0,shotxvel
	bra	gamesingle


doenexplode:
	lea	enemysp0,a0
	tst.w	cspriteexploding(a0)
	bmi.s	de1
	bsr	tsteend
	bra.s	de2
de1:
	cmpi.w	#12,cspritehits(a0)
	blt.s	de2
	addq.w	#1,enemydead
	move.w	enemydead,number
	move.w	#4001,numwhere
	bsr	prtnum
	bsr	setupboom
de2:
	lea	enemysp1,a0
	tst.w	cspriteexploding(a0)
	bmi.s	de3
	bsr	tsteend
	bra.s	de4
de3:
	cmpi.w	#12,cspritehits(a0)
	blt.s	de4
	addq.w	#1,enemydead
	move.w	enemydead,number
	move.w	#4001,numwhere
	bsr	prtnum
	bsr	setupboom
de4:
	rts

setupboom:
	move.w	#1,cspriteexploding(a0)
*	bsr	doboom
	lea	bigboomsound,a6
	bsr	startsound
	move.w	#-1,cactive(a0)
	move.l	enshotlistp(a0),a6
	move.l	(a6)+,a1
	move.l	(a6)+,a2
	move.l	(a6)+,a3
	move.l	(a6)+,a4
	move.w	cspritex(a0),d0
	move.w	cspritey(a0),d1
	addq.w	#7-1,d0
	addq.w	#7-1,d1
	move.w	d0,cspritex(a1)
	move.w	d1,cspritey(a1)
	addq.w	#3,cspritex(a1)
	subq.w	#3,cspritey(a1)
	move.w	#1,cactive(a1)
	move.w	#3,cspritexvel(a1)
	move.w	#-3,cspriteyvel(a1)
	move.w	#50,cspritelife(a1)
	move.w	d0,cspritex(a2)
	move.w	d1,cspritey(a2)
	addq.w	#3,cspritex(a2)
	addq.w	#3,cspritey(a2)
	move.w	#1,cactive(a2)
	move.w	#3,cspritexvel(a2)
	move.w	#3,cspriteyvel(a2)
	move.w	#50,cspritelife(a2)
	move.w	d0,cspritex(a3)
	move.w	d1,cspritey(a3)
	subq.w	#3,cspritex(a3)
	addq.w	#3,cspritey(a3)
	move.w	#1,cactive(a3)
	move.w	#-3,cspritexvel(a3)
	move.w	#3,cspriteyvel(a3)
	move.w	#50,cspritelife(a3)
	move.w	d0,cspritex(a4)
	move.w	d1,cspritey(a4)
	move.w	#1,cactive(a4)
	move.w	#-3,cspritexvel(a4)
	move.w	#-3,cspriteyvel(a4)
	move.w	#50,cspritelife(a4)
	subq.w	#3,cspritex(a4)
	subq.w	#3,cspritey(a4)
	rts
tsteend:
	move.l	enshotlistp(a0),a6
	move.l	(a6)+,a1
	cmpi.w	#-1,cactive(a1)
	bne.s	go2se
	move.l	(a6)+,a1
	cmpi.w	#-1,cactive(a1)
	bne.s	go2se
	move.l	(a6)+,a1
	cmpi.w	#-1,cactive(a1)
	bne.s	go2se
	move.l	(a6)+,a1
	cmpi.w	#-1,cactive(a1)
	bne.s	go2se
	bsr	getrandlist
	move.l	a1,cspritelocation(a0)
	move.l	a1,cspriteheading(a0)
	move.l	a1,cspritelistad(a0)
	move.w	#-1,cspritegoing(a0)
	move.w	#1,cactive(a0)
	move.w	#-1,cspritefollow(a0)
	move.w	#1,cspritefight(a0)
	move.w	#0,cspritehits(a0)
	move.w	#-1,cspriteexploding(a0)
	bsr	dolist
go2se:
	rts

restartsingle:
	bsr	stopallsound
	move.w	#1,novbl
	move.b	screen+1,$ff8201
	move.b	screen+2,$ff8203
	bsr	cleartext
	lea	medeadtext1,a0
	bsr	gemprint
	lea	mewintext2,a0
	bsr	gemprint
	bsr	clearkeyboard
waitkos:
	move.w	#$ff,-(sp)
	move.w	#6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0		;wait for keypress
	beq	waitkos
	bra	dorestart



poslist:
	dc.w	16+176-128-8,16+144-64-8
	dc.w	16+1088-128-8,16+144-64-8
	dc.w	16+176-128-8,16+672-64-8
	dc.w	16+1088-128-8,16+672-64-8
***************************************
prepchannels:
	move.b	#%00111111,d1
	moveq	#7,d0
	bsr	writedata
	moveq	#0,d1
	moveq	#8,d0
	bsr	writedata
	moveq	#0,d1
	moveq	#9,d0
	bsr	writedata
	moveq	#0,d1
	moveq	#10,d0
	bsr	writedata
	rts
stopallsound:
	lea	channel0params,a1
	move.w	#-1,channelprocess(a1)
	bsr	stopsound0
	lea	channel1params,a1
	move.w	#-1,channelprocess(a1)
	bsr	stopsound0
	lea	channel2params,a1
	move.w	#-1,channelprocess(a1)
	bsr	stopsound0
	rts
******************************************
dosound:
	lea	channel0params,a1
	bsr	dosoundstuff
	lea	channel1params,a1
	bsr	dosoundstuff
	lea	channel2params,a1
dosoundstuff:
	tst.w	channelprocess(a1)
	bmi	noch0
	tst.w	channelcmp(a1)
	beq	still0
	subq.w	#1,channellife(a1)
	bpl	still0
	move.w	#-1,channelprocess(a1)
	bra	stopsound0
still0:
	tst.w	channelwaveform(a1)	;does it need shaping
	bmi	skip0waveforms
	subq.w	#1,channelspeed2(a1)
	tst.w	channelspeed2(a1)
	bpl	skip0waveforms
	move.w	channelspeed(a1),channelspeed2(a1)
	cmpi.w	#0,channelwaveform(a1)
	bne	ch0p1
	move.w	channelvolume(a1),d1
	addq.w	#1,d1
	cmpi.w	#15,d1
	blt	ch0pl
	moveq	#14,d1
ch0pl:
	bra	finalwaveform
ch0p1:
	cmpi.w	#1,channelwaveform(a1)
	bne	ch0p2
	move.w	channelvolume(a1),d1
	subq.w	#1,d1
	cmpi.w	#0,d1
	bge	ch0pu
	moveq	#0,d1
ch0pu:
	bra	finalwaveform
ch0p2:
	cmpi.w	#2,channelwaveform(a1)
	bne	ch0p3
	move.w	channelvolume(a1),d1
	move.w	channelvel(a1),d2
	add.w	d2,d1
	cmpi.w	#0,d1
	bgt	ch0saw1
	neg.w	channelvel(a1)
	bra	ch0saw2
ch0saw1:
	cmpi.w	#14,d1
	blt	ch0saw2
	neg.w	channelvel(a1)
ch0saw2:
	bra	finalwaveform
ch0p3:
	cmpi.w	#3,channelwaveform(a1)
	bne	ch0p4
	move.w	channelvolume(a1),d1
	addq.w	#1,d1
	cmpi.w	#15,d1
	blt.s	ch0p3b
	moveq	#0,d1
ch0p3b:
	bra	finalwaveform
ch0p4:
	move.w	channelvolume(a1),d1
	subq.w	#1,d1
	bpl	finalwaveform
	moveq	#14,d1
finalwaveform:
	move.w	d1,channelvolume(a1)
	move.w	channelvolreg(a1),d0
	bsr	writedata
skip0waveforms:
	moveq	#0,d7
	move.w	channelreg(a1),d7
	bmi	noch0
	move.w	channelreg2(a1),d2
	move.w	(a1,d2.w),d1
	add.w	channeladd(a1),d1
	cmp.w	channelcmp(a1),d1
	bne	not0end
	move.w	#-1,channelprocess(a1)
	bsr	stopsound0
not0end:
	move.w	d1,(a1,d2.w)
	move.w	d7,d0
	bsr	writedata
noch0:
	rts
stopsound0:
	moveq	#0,d1
	move.w	channelvolreg(a1),d0
	bsr	writedata
	move.b	mymixer,d1
	or.w	channeloff(a1),d1	;reg
	move.b	d1,mymixer
	move.b	#7,d0
	bsr	writedata
	rts


writedata:
	move.b	d0,$ff8800
	cmp.b	#7,d0
	bne	wd2
	and.b	#$3f,d1
	move.b	$ff8800,d0
	and.b	#$c0,d0
	or.b	d0,d1
wd2:
	move.b	d1,$ff8802
	rts
*****************************************
*	Pass ad of soundata in a6	*
*****************************************
startsound:
	movem.l	d0-d1/a0,-(sp)
	cmpi.w	#0,channelprocess(a6)
	bne	start1
	lea	channel0params,a0
	bra	startit
start1:
	cmpi.w	#1,channelprocess(a6)
	bne	start2
	lea	channel1params,a0
	bra	startit
start2:
	lea	channel2params,a0
startit:
	move.l	a0,-(sp)
	move.l	(a6)+,(a0)+
	move.l	(a6)+,(a0)+
	move.l	(a6)+,(a0)+
	move.l	(a6)+,(a0)+
	move.l	(a6)+,(a0)+
	move.w	#-1,(a0)+
*	addq.l	#2,a1		;skip channelprocess
	move.w	(a6)+,d0	;same as above only quicker
	move.w	(a6)+,(a0)+
	move.l	(a6)+,(a0)+
	move.l	(a6)+,(a0)+
	move.l	(a6)+,(a0)+
	move.l	(a6)+,(a0)+
	move.l	(sp)+,a0
	move.w	channelfine(a0),d1
	move.w	channelfinereg(a0),d0
	bsr	writedata
	move.w	channelcoarse(a0),d1
	move.w	channelcoarsereg(a0),d0
	bsr	writedata
	move.w	channelvolume(a0),d1
	move.w	channelvolreg(a0),d0
	bsr	writedata
	move.w	channelnoise(a0),d1
	beq.s	nonoise
	moveq	#6,d0
	bsr	writedata
	move.w	channelmixa(a0),d1
	bclr	d1,mymixer
	bra.s	skipkl
nonoise:
	move.w	channelmixa(a0),d1
	bset	d1,mymixer
skipkl:
	move.w	channelmixb(a0),d1
	bclr	d1,mymixer
	move.b	mymixer,d1
	moveq	#7,d0
	bsr	writedata
	move.w	#1,channelprocess(a0)
	movem.l	(sp)+,d0-d1/a0
	rts


***************************************
doenminedrop:
	lea	enemysp0,a0
	tst.w	tankplanee(a0)
	bpl.s	demd
	tst.w	cactive(a0)
	bmi.s	demd
	move.w	#1000,d0
	bsr	randomplus
	cmpi.w	#5,d0
	bgt.s	demd
	bsr	doenemymine2
demd:
	lea	enemysp0,a1
	tst.w	tankplanee(a0)
	bpl.s	demd2
	tst.w	cactive(a0)
	bmi.s	demd2
	move.w	#1000,d0
	bsr	randomplus
	cmpi.w	#5,d0
	bgt.s	demd2
	bsr	doenemymine2
demd2:
	rts


***************************************
doenemy:
	lea	enemysp0,a0
	bsr	doenmove
	lea	enemysp1,a0
	bsr	doenmove
	rts

doenmove:
	tst.w	cactive(a0)
	bmi	deov
	bsr	doenemyspin
	bsr	doenemyspinning
	tst.w	cspritefight(a0)	;is he being chicken
	bmi.s	findnextbb
	tst.w	tankspine(a0)
	bpl	amsp
	move.w	cspritesub(a0),d0
	beq	findnexta		;zero is a prob
	sub.w	d0,cspritegoing(a0)
	bmi	findnexta
	move.w	cspritexvel(a0),d0
	move.w	cspriteyvel(a0),d1
	add.w	d0,cspritex(a0)
	add.w	d1,cspritey(a0)
amsp:	bsr	preparesprite
deov:	rts

findnexta:
	move.l	cspriteheading(a0),cspritelocation(a0)
	subq.w	#1,cspritefollow(a0)
	bpl.L	findnext
findnextb:
noflee:
	move.w	#1,cspritefight(a0)
	bra.s	dolist

findnextbb:
	move.l	cspritelocation(a0),cspriteheading(a0)
	move.l	cspriteheading(a0),a6
	move.w	cspritex(a0),d6
	move.w	cspritey(a0),d7
	cmpi.w	#-2,cspritefight(a0)
	beq.s	runwellaway
	move.w	#0,cspritefight(a0)	;go back one place
	bra	fudge	
runwellaway:
	move.w	#0,cspritefight(a0)	;go back one place
	bsr	getrandlist
	move.l	a1,cspritelistad(a0)
	move.w	#12,cspritefollow(a0)
	bra	fudge


headingto:
	dc.l	0
mylocation:	dc.l	list
listad:	dc.l	-1
bdelay:	dc.w	0
going:	dc.w	-1
*************************************************
*	Sqroot routine courtesy of Armin	*
*	Input:	d0.l	number to get root of	*
*		d1	answer			*
*************************************************
sqrt:
	movem.w	d2/d3,-(sp)
	moveq	#5,d4
	lsr.l	#1,d0
	move.l	d0,d1
	lsr.l	#1,d1
sqloop:
	move.w	d1,d2
	lsr.l	#1,d2
	move.l	d0,d3
	divu	d1,d3
	sub.l	d2,d1
	add.w	d3,d1
	dbf	d4,sqloop
	movem.w	(sp)+,d2/d3
	rts
*******************************************
dolist:
	lea	list,a6
	lea	mesp,a5
	move.w	cspritex(a5),d2
	move.w	cspritey(a5),d3
	move.l	#25000,d7	;shortest
getloop:
	tst.b	(a6)
	bmi.s	pfindnext
	cmp.w	8(a6),d2	;tlx
	blt.s	glnext
	cmp.w	10(a6),d3	;tly
	blt.s	glnext
	cmp.w	12(a6),d2	;tlx
	bgt.s	glnext
	cmp.w	14(a6),d3	;tly
	bgt.s	glnext
	move.l	a6,cspritelistad(a0)
	bgt.s	pfindnext
glnext:
	lea	16(a6),a6
	bra.s	getloop
pfindnext:
	move.w	#2,cspritefollow(a0)
findnext:
	move.l	cspritelocation(a0),a1
	move.l	cspritelistad(a0),a2
	move.b	1(a1),d0
	cmp.b	1(a2),d0
	bne.s	thirdok1		;if on right track dont rev
	move.b	2(a1),d1
	cmp.b	2(a2),d1
	beq.s	thirdok			;if on right track dont rev
thirdok1:
	move.b	3(a1),d2		;third lev
	beq.s	thirdok			;if 0 must be at 2nd lev node
	subq.b	#1,d2
	move.b	2(a1),d1
	bra.L	findentry
thirdok:
	move.b	1(a1),d0
	cmp.b	1(a2),d0
	beq.s	secok		;if on right track dont rev
	move.b	2(a1),d1
	beq.s	secok
	subq.b	#1,d1
	move.b	3(a1),d2
	bra.L	findentry
secok:
	move.b	1(a1),d0
	cmp.b	1(a2),d0
	beq.s	dosec
	move.b	1(a2),d1
	sub.b	d0,d1
	tst.b	d1
	bpl.s	ffn1
	subq.b	#1,d0		;first number
	move.b	2(a1),d1		;second
	move.b	3(a1),d2		;third
	bra.L	findentry
ffn1:
	addq.b	#1,d0
	move.b	2(a1),d1		;second
	move.b	3(a1),d2		;third
	bra.L	findentry
dosec:
	move.b	2(a1),d1
	cmp.b	2(a2),d1
	beq.s	dothird
	move.b	2(a2),d3
	sub.b	d1,d3
	tst.b	d3
	bpl.s	dos1
	subq.b	#1,d1		;first number
	move.b	1(a1),d0		;second
	move.b	3(a1),d2		;third
	bra.L	findentry
dos1:
	addq.b	#1,d1
	move.b	1(a1),d0		;second
	move.b	3(a1),d2		;third
	bra.L	findentry
dothird:
	move.b	3(a1),d2
	cmp.b	3(a2),d2
	beq.s	imthere
	move.b	3(a2),d3
	sub.b	d2,d3
	tst.b	d3
	bpl.s	dot1
	subq.b	#1,d2		;first number
	move.b	1(a1),d0		;second
	move.b	2(a1),d1		;third
	bra.L	findentry
dot1:
	addq.b	#1,d2
	move.b	1(a1),d0		;second
	move.b	2(a1),d1		;third
	bra.s	findentry
imthere:
	move.w	#-1,cspritegoing(a0)
	tst.w	cspriterotate(a0)	;time to rotate 45
	bmi.s	itb
	move.w	#-1,cspriterotate(a0)
	moveq	#0,d0
	move.b	whichmee(a0),d0
	addq.w	#1,d0
	cmpi.w	#8,d0
	blt.s	itb1
	moveq	#0,d0
itb1:
	move.l	d0,d1
	addq.b	#8,d1
	move.b	d0,whichmee(a0)
	asl.w	#2,d0
	lea	velslist,a1
	move.w	(a1,d0.w),cspritexvel(a0)
	move.w	2(a1,d0.w),cspriteyvel(a0)
	lea	enemysprites,a2
	mulu	#5120,d1
	add.l	d1,a2
	move.l	a2,cspritead(a0)
itb:
	bsr	preparesprite
	rts

velslist:
	dc.w	0,-2,2,-2,2,0,2,2,0,2,-2,2,-2,0,-2,-2


findentry:
	lea	list,a6
fel:
	tst.b	(a6)
	bmi.L	feover
	cmp.b	1(a6),d0
	bne.L	feover1
	cmp.b	2(a6),d1
	bne.L	feover1
	cmp.b	3(a6),d2
	bne.L	feover1
	move.l	a6,cspriteheading(a0)
	move.l	cspritelocation(a0),a1
	move.w	4(a1),cspritex(a0)
	move.w	6(a1),cspritey(a0)
	move.w	4(a1),d6
	move.w	6(a1),d7
**********************************
*	when I jump here put my x,y in d6,d7
*	put enspad in a0 and csprite heading in a6
fudge:
	moveq	#50,d4
	moveq	#0,d5
	move.w	4(a6),d0	;x head
	move.w	6(a6),d1
	sub.w	d6,d0
	bmi.s	xneg
	beq.s	xzero
	move.w	d0,d4		;counter
	move.w	cspritevels(a0),d2		;xvel
	move.w	cspritevels(a0),d5
	bra.s	doy
xzero:
	moveq	#0,d2
	bra.s	doy
xneg:
	neg.w	d0
	move.w	d0,d4		;counter
	move.w	cspritevels(a0),d2		;xvel
	move.w	cspritevels(a0),d5
	neg.w	d2
*	moveq	#-v,d2		;xvel
*	moveq	#v,d5
doy:
*	sub.w	6(a1),d1		;y2-y1
	sub.w	d7,d1
	bmi.s	yneg
	beq.s	yzero
	move.w	d1,d4		;counter
	move.w	cspritevels(a0),d3		;xvel
	move.w	cspritevels(a0),d5
*	moveq	#v,d3		;yvel
*	moveq	#v,d5
	bra.s	velsdone
yzero:
	moveq	#0,d3
	bra.s	velsdone
yneg:
	neg.w	d1
	move.w	d1,d4		;counter
	move.w	cspritevels(a0),d3		;xvel
	move.w	cspritevels(a0),d5
	neg.w	d3
*	moveq	#-v,d3
*	moveq	#v,d5
velsdone:
	move.w	d2,cspritexvel(a0)
	move.w	d3,cspriteyvel(a0)
*	subq.w	#1,d4
	move.w	d4,cspritegoing(a0)
	move.w	d5,cspritesub(a0)

	moveq	#0,d4
	tst.w	d2
	beq.s	ed1
	tst.w	d3
	beq.s	ed2
	bpl.s	ed3
ed4:
	tst.w	d2
	bpl.s	ed4a
	moveq	#7,d4
	bra.s	dirdone
ed4a:
	moveq	#1,d4
	bra.s	dirdone
ed3:
	tst.w	d2
	bpl.s	ed3a
	moveq	#5,d4
	bra.s	dirdone
ed3a:
	moveq	#3,d4
	bra.s	dirdone
ed2:
	tst.w	d2
	bpl.s	ed2a
	moveq	#6,d4
	bra.s	dirdone
ed2a:
	moveq	#2,d4
	bra.s	dirdone
ed1:
	tst.w	d3
	bpl.s	ed1a
	moveq	#0,d4
	bra.s	dirdone
ed1a:
	moveq	#4,d4
*	bra.s	dirdone
dirdone:
	lea	enemysprites,a2
	tst.w	tankplanee(a0)
	bpl.s	dd2
	addq	#8,d4
dd2:
	move.b	d4,whichmee(a0)
	mulu	#5120,d4
	add.l	d4,a2
	move.l	a2,cspritead(a0)
	bra	doenmove
feover1:
	lea	16(a6),a6
	bra.L	fel
feover:
	rts
************************************
domines:
	lea	mymine1,a0
	bsr	dominestuff
	lea	mymine2,a0
	bsr	dominestuff
	lea	mymine3,a0
	bsr	dominestuff
	lea	mymine4,a0
	bsr	dominestuff

	lea	enmine1,a0
	bsr	dominestuff2
	lea	enmine2,a0
	bsr	dominestuff2
	lea	enmine3,a0
	bsr	dominestuff2
	lea	enmine4,a0
	bsr	dominestuff2
	rts


dominestuff:
	tst.w	mineact(a0)
	bmi.s	nomine
	subq.w	#1,minelife(a0)
	bpl.s	nomine
	move.w	#-2,mineact(a0)
	lea	minesp,a0
	lea	minexylist,a1
	addq.w	#1,mines
	move.w	mines,d0
*	asl.w	#1,d0
	add.w	d0,d0
	move.w	(a1,d0.w),(a0)
	bsr	putsprite
nomine:
	rts

dominestuff2:
	tst.w	mineact(a0)
	bmi.s	nomine2
	subq.w	#1,minelife(a0)
	bpl.s	nomine2
	move.w	#-2,mineact(a0)
nomine2:
	rts

*************************************
plotplayers:
	lea	mapsplist2,a4
	move.w	enemynum,d7
	addq.w	#3,d7			;for me
pplc:
	move.l	(a4)+,a0
	tst.w	(a0)
	bmi.s	noplpl			;not at all active
	bsr	putsprite		;remove old
noplpl:
	dbf	d7,pplc
here1:
	lea	mapsplist,a1		;put em in
	lea	mapsplist2,a4
	move.w	enemynum,d7
	addq.w	#1,d7			;for me
pplcb:
	move.l	(a1)+,a2
	move.l	(a4)+,a0
	tst.w	cactive(a2)
	bmi.s	noplplb			;not at all active
	move.w	cspritex(a2),d0
	move.w	cspritey(a2),d1
	asr.w	#3,d0		;div by 8
	asr.w	#3,d1
	add.w	#80,d0
	add.w	#29,d1
	move.w	d0,(a0)
	move.w	d1,2(a0)
	bsr	putsprite
	dbf	d7,pplcb
	bra.s	wepbits
noplplb:
	move.w	#-1,(a0)
	dbf	d7,pplcb
wepbits:
	lea	mywep,a2
	move.l	(a4)+,a0
	tst.w	mineact(a2)
	bmi.s	dw2			;not at all active
	move.w	minex2(a2),d0
	move.w	miney2(a2),d1
	asr.w	#3,d0		;div by 8
	asr.w	#3,d1
	add.w	#80,d0
	add.w	#29,d1
	move.w	d0,(a0)
	move.w	d1,2(a0)
	bsr	putsprite
	bra.s	dw2a
dw2:
	move.w	#-1,(a0)
dw2a:
	lea	enwep,a2
	move.l	(a4)+,a0
*	lea	enwepsp,a0
	tst.w	mineact(a2)
	bmi.s	nomap			;not at all active
	move.w	minex2(a2),d0
	move.w	miney2(a2),d1
	asr.w	#3,d0		;div by 8
	asr.w	#3,d1
	add.w	#80,d0
	add.w	#29,d1
	move.w	d0,(a0)
	move.w	d1,2(a0)
	bsr	putsprite
	rts
nomap:
	move.w	#-1,(a0)
	rts


*************************************
plotplayersm:
	lea	mapsplist2m,a4
	moveq	#3,d7
pplcm:
	move.l	(a4)+,a0
	tst.w	(a0)
	bmi.s	noplplm			;not at all active
	bsr	putsprite		;remove old
noplplm:
	dbf	d7,pplcm
here1m:
	lea	mapsplistm,a1		;put em in
	lea	mapsplist2m,a4
	moveq	#1,d7
pplcbm:
	move.l	(a1)+,a2
	move.l	(a4)+,a0
	tst.w	cactive(a2)
	bmi.s	noplplbm			;not at all active
	move.w	cspritex(a2),d0
	move.w	cspritey(a2),d1
	asr.w	#3,d0		;div by 8
	asr.w	#3,d1
	add.w	#80,d0
	add.w	#29,d1
	move.w	d0,(a0)
	move.w	d1,2(a0)
	bsr	putsprite
	dbf	d7,pplcbm
	bra.s	wepbitsm
noplplbm:
	move.w	#-1,(a0)
	dbf	d7,pplcbm
wepbitsm:
	lea	mywep,a2
	move.l	(a4)+,a0
	tst.w	mineact(a2)
	bmi.s	dw2m			;not at all active
	move.w	minex2(a2),d0
	move.w	miney2(a2),d1
	asr.w	#3,d0		;div by 8
	asr.w	#3,d1
	add.w	#80,d0
	add.w	#29,d1
	move.w	d0,(a0)
	move.w	d1,2(a0)
	bsr	putsprite
	bra.s	dw2am
dw2m:
	move.w	#-1,(a0)
dw2am:
	lea	enwep,a2
	move.l	(a4)+,a0
*	lea	enwepsp,a0
	tst.w	mineact(a2)
	bmi.s	nomapm			;not at all active
	move.w	minex2(a2),d0
	move.w	miney2(a2),d1
	asr.w	#3,d0		;div by 8
	asr.w	#3,d1
	add.w	#80,d0
	add.w	#29,d1
	move.w	d0,(a0)
	move.w	d1,2(a0)
	bsr	putsprite
	rts
nomapm:
	move.w	#-1,(a0)
	rts

mapsplist:
	dc.l	mesp,enemysp0,enemysp1
mapsplistm:
	dc.l	mesp,enemysp0
mapsplist2:
	dc.l	memapsp,enmapsp0,enmapsp1,mewepsp,enwepsp
mapsplist2m:
	dc.l	memapsp,enmapsp0,mewepsp,enwepsp
*************************************
subshot:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	barclearsp,a0
	move.w	shots,d0
	add.w	#32,d0
	move.w	d0,(a0)		;x-y already set
	bsr	putsprite
	tst.w	shots
	bgt	ssb
	lea	mywep,a6
	bsr	handlewep
ssb:
	movem.l	(sp)+,d0-d7/a0-a6
	rts
subdamage:
	movem.l	d0/a0,-(sp)
	tst.w	cheatmode
	bpl.s	sksd
	lea	barclearsp2,a0
	moveq	#12,d0
	sub.w	mehits,d0
	asl.w	#2,d0
	add.w	#144,d0
	move.w	d0,(a0)		;x-y already set
	bsr	putsprite
sksd:
	movem.l	(sp)+,d0/a0
	rts


checkblock2:
	lea	mymine1,a0
	bsr	cb2
	lea	mymine2,a0
	bsr	cb2
	lea	mymine3,a0
	bsr	cb2
	lea	mymine4,a0
	bsr	cb2

	lea	enmine1,a0
	bsr	cb2
	lea	enmine2,a0
	bsr	cb2
	lea	enmine3,a0
	bsr	cb2
	lea	enmine4,a0
	bsr	cb2
	lea	enwep,a0
	bsr	cb2
	lea	mywep,a0
	bsr	cb2
	rts
cb2:
	cmpi.w	#-1,mineact(a0)
	beq.s	noblockmatch2
	cmp.w	minex(a0),d0
	bne.s	noblockmatch2
	cmp.w	miney(a0),d1
	bne.s	noblockmatch2
	addq.l	#8,sp
	bra.s	wrong
noblockmatch2:
	rts

******************************
*	pass ad of block in a6
handlewep:
wrong:
	moveq	#33,d0
	bsr	randomplus
	add.w	#10,d0
	move.w	d0,d1
	moveq	#48,d0
	bsr	randomplus
	add.w	#12,d0
	move.w	d0,d2
	move.w	d1,d3
	mulu	#80,d3
	add.w	d2,d3
	lea	gamemap,a0
	cmpi.b	#16,(a0,d3.w)
	bge.s	wrong
	bsr	checkblock2
	move.w	d0,minex(a6)
	move.w	d1,miney(a6)
	move.b	#1,wepdrop
handlewep2:
	move.w	d0,d2
	move.w	d1,d3
	lea	scr,a5
	asl.w	#4,d2		;gives actual screen x y
	asl.w	#4,d3
	move.w	d2,minex2(a6)
	move.w	d3,miney2(a6)
*	mulu	#640,d3
	swap	d3
	clr.w	d3
	swap	d3
	lsl.l	#7,d3
	adda.l	d3,a5		;add to screen base address
	lsl.l	#2,d3
	adda.l	d3,a5		;add to screen base address
	asr.w	#1,d2		;divide it by 2
	and.w	#$fff8,d2	;turn off lower 3 bits
	adda.w	d2,a5		;add to screen address register
	move.l	a5,minead(a6)

	mulu	#80,d1
	add.w	d0,d1
	lea	gamemap,a2
	lea	blocks,a3
	moveq	#0,d0
	move.b	(a2,d1.w),d0
	asl.w	#7,d0
	add.w	d0,a3
	move.l	a3,minerestore(a6)
	move.w	#1,mineact(a6)
	rts

doenemywep:
	lea	enwep,a6
	move.w	minex(a6),d0
	move.w	miney(a6),d1
	bsr	handlewep2
	rts

putmore:
	lea	getwepsound,a6
	bsr	startsound
	move.w	#64,shots
	lea	bar1sp,a0
	bsr	putsprite
	rts
wepdrop:	dc.b	-1
even

******************************
docollisions:
	lea	enshotlist,a0	;enemyshots hit me
	move.w	enemynum,d7
	addq.w	#1,d7
	asl.w	#2,d7
	subq.w	#1,d7
*	moveq	#3,d7
	lea	mesp,a1
	tst.w	cactive(a1)
	bmi.s	docollisionsme
	move.w	cspritex(a1),d0
	move.w	cspritey(a1),d1
	move.w	d0,d2
	move.w	d1,d3
	add.w	#16,d2
	add.w	#16,d3
dcloop:
	move.l	(a0)+,a1
	tst.w	cactive(a1)
	bmi.s	nogo
	move.w	cspritex(a1),d4
	move.w	cspritey(a1),d5
	cmp.w	d4,d2
	blt.s	nogo
	cmp.w	d5,d3
	blt.s	nogo
	addq.w	#3,d4
	addq.w	#3,d5
	cmp.w	d4,d0
	bgt.s	nogo
	cmp.w	d5,d1
	bgt.s	nogo
	cmpi.w	#0,enemynum
	beq.s	colfudge
	move.w	#-1,cactive(a1)
colfudge:
	move.w	#$0f50,$ff8240
	addq.w	#1,mehits
	bsr	subdamage
nogo:
	dbf	d7,dcloop
docollisionsme:
	move.w	enemynum,d7	;my shots hit enemy
	lea	enemylist,a0
dcml:
	move.l	(a0)+,a1
	tst.w	cactive(a1)
	bmi.s	dcml2
	move.w	cspritex(a1),d0
	move.w	cspritey(a1),d1
	move.w	d0,d2
	move.w	d1,d3
	add.w	#15,d2
	add.w	#15,d3
	bsr	checkenemy
dcml2:	dbf	d7,dcml
collisionseach:
	move.w	enemynum,d7	;we collide
	lea	enemylist,a0
	lea	mesp,a1
	move.w	cspritex(a1),d0
	move.w	cspritey(a1),d1
	add.w	xvel,d0
	add.w	yvel,d1
	move.w	d0,d2
	move.w	d1,d3
	add.w	#15,d2
	add.w	#15,d3
cel:
	move.l	(a0)+,a1
	tst.w	cactive(a1)
	bmi.s	nogoea
	move.w	cspritex(a1),d4
	move.w	cspritey(a1),d5
	cmp.w	d4,d2
	blt.s	nogoea
	cmp.w	d5,d3
	blt.s	nogoea
	add.w	#15,d4
	add.w	#15,d5
	cmp.w	d4,d0
	bgt.s	nogoea
	cmp.w	d5,d1
	bgt.s	nogoea
*	bsr	dowall
	lea	hitwallsound,a6
	bsr	startsound
	neg.w	xvel
	neg.w	yvel
	move.w	#-1,cspritefight(a1)
nogoea:
	dbf	d7,cel
checkmines:
	lea	mesp,a1			;I collide with mine
	move.w	cspritex(a1),d0
	move.w	cspritey(a1),d1
	move.w	d0,d2
	move.w	d1,d3
	add.w	#15,d2
	add.w	#15,d3
	lea	enminelist,a0
	bsr	checkem
	tst.w	d6
	bmi.s	nomhm
	move.w	#13,mehits
nomhm:
	lea	enemysp0,a1	;enemy collides with mine
	tst.w	cactive(a1)
	bmi	noe2
	move.w	cspritex(a1),d0
	move.w	cspritey(a1),d1
	move.w	d0,d2
	move.w	d1,d3
	add.w	#15,d2
	add.w	#15,d3
	lea	myminelist,a0
	bsr	checkem
	tst.w	d6
	bmi	noe2
	lea	enemysp0,a1	;enemy collides with mine
	move.w	#13,cspritehits(a1)
	lea	minesp,a0
	lea	minexylist,a1
	addq.w	#1,mines
	move.w	mines,d0
*	asl.w	#1,d0
	add.w	d0,d0
	move.w	(a1,d0.w),(a0)
	bsr	putsprite
noe2:
	lea	enemysp1,a1	;enemy collides with mine
	tst.w	cactive(a1)
	bmi	nohmh
	move.w	cspritex(a1),d0
	move.w	cspritey(a1),d1
	move.w	d0,d2
	move.w	d1,d3
	add.w	#15,d2
	add.w	#15,d3
	lea	myminelist,a0
	bsr	checkem
	tst.w	d6
	bmi	nohmh
	lea	enemysp1,a1	;enemy collides with mine
	move.w	#13,cspritehits(a1)
	lea	minesp,a0
	lea	minexylist,a1
	addq.w	#1,mines
	move.w	mines,d0
*	asl.w	#1,d0
	add.w	d0,d0
	move.w	(a1,d0.w),(a0)
	bsr	putsprite
nohmh:
	lea	mywep,a0	;check for me run over wep cash
	lea	mesp,a1
	bsr	checktwo
	tst.w	d6
	bmi	cho
	move.w	#-2,mineact(a0)
	bsr	putmore
cho:
	lea	enwep,a0	;check for enemy over wep
	lea	enemysp0,a1
	bsr	checktwo
	tst.w	d6
	bmi	cho2
	move.w	#-2,mineact(a0)
*	move.w	#64,cshots(a0)
cho2:
	rts

checkem:
	moveq	#3,d7
celc:
	move.l	(a0)+,a1
	tst.w	mineact(a1)
	bmi.s	nogoec
	move.w	minex2(a1),d4
	move.w	miney2(a1),d5
	cmp.w	d4,d2
	blt.s	nogoec
	cmp.w	d5,d3
	blt.s	nogoec
	add.w	#15,d4
	add.w	#15,d5
	cmp.w	d4,d0
	bgt.s	nogoec
	cmp.w	d5,d1
	bgt.s	nogoec
	move.w	#-2,mineact(a1)
	moveq	#1,d6
	rts
nogoec:
	dbf	d7,celc
	moveq	#-1,d6
	rts

checkenemy:
	lea	myshotlist,a2
	moveq	#3,d6
checken:
	move.l	(a2)+,a3
	tst.w	cactive(a3)
	bmi.s	nogoe
	move.w	cspritex(a3),d4
	move.w	cspritey(a3),d5
	cmp.w	d4,d2
	blt.s	nogoe
	cmp.w	d5,d3
	blt.s	nogoe
	addq.w	#3,d4
	addq.w	#3,d5
	cmp.w	d4,d0
	bgt.s	nogoe
	cmp.w	d5,d1
	bgt.s	nogoe
	move.w	#-1,cactive(a3)
	addq.w	#1,cspritehits(a1)
	cmpi.w	#5,cspritehits(a1)
	blt.s	nogoe
	move.w	#-2,cspritefight(a1)	;run away
nogoe:
	dbf	d6,checken
	rts
checktwo:
	tst.w	mineact(a0)
	bmi.s	chtb
	move.w	cspritex(a1),d0
	move.w	cspritey(a1),d1
	move.w	d0,d2
	move.w	d1,d3
	add.w	#15,d2
	add.w	#15,d3
	move.w	minex2(a0),d4
	move.w	miney2(a0),d5
	cmp.w	d4,d2
	blt.s	chtb
	cmp.w	d5,d3
	blt.s	chtb
	add.w	#15,d4
	add.w	#15,d5
	cmp.w	d4,d0
	bgt.s	chtb
	cmp.w	d5,d1
	bgt.s	chtb
	moveq	#1,d6
	rts
chtb:
	moveq	#-1,d6
	rts


enemycollision:
	lea	enemysp0,a5
*	tst.w	tankspine(a5)
*	bpl.s	ecback
	move.w	cspritex(a5),d0
	move.w	cspritey(a5),d1
	tst.w	cspritegoing(a5)
	bmi.s	skxy1
	add.w	cspritexvel(a5),d0
	add.w	cspriteyvel(a5),d1
skxy1:	move.w	d0,d2
	move.w	d1,d3
	add.w	#16,d2
	add.w	#16,d3
	lea	enemysp1,a1
	tst.w	cactive(a1)
	bmi.s	nogoee
*	tst.w	tankspine(a1)
*	bpl.s	ecback
	move.w	cspritex(a1),d4
	move.w	cspritey(a1),d5
	tst.w	cspritegoing(a1)
	bmi.s	skxy2
	add.w	cspritexvel(a1),d4
	add.w	cspriteyvel(a1),d5
skxy2:	cmp.w	d4,d2
	blt.s	nogoee
	cmp.w	d5,d3
	blt.s	nogoee
	add.w	#16,d4
	add.w	#16,d5
	cmp.w	d4,d0
	bgt.s	nogoee
	cmp.w	d5,d1
	bgt.s	nogoee
*	bsr	dowall
	lea	hitwallsound,a6
	bsr	startsound
	tst.w	cspritegoing(a1)
	bmi.s	tg1
	tst.w	tankspine(a1)
	bpl.s	nogoee
	move.w	#-2,cspritefight(a1)
	rts
tg1:
	tst.w	tankspine(a5)
	bpl.s	nogoee
	move.w	#-2,cspritefight(a5)
nogoee:
ecback:
	rts

enminelist:	dc.l	enmine1,enmine2,enmine3,enmine4
myminelist:	dc.l	mymine1,mymine2,mymine3,mymine4
myshotlist:
	dc.l	meshot1,meshot2,meshot3,meshot4,-1

midibuff:	dc.l	0
setflag:	dc.w	0
novbl:	dc.w	-1
even
sorm:	dc.w	-1
**************************************
establishcoms:
	bsr	clearmidi
	bsr	cleartext
	lea	miditext1,a0
	bsr 	gemprint
	lea	miditext2,a0
	bsr	gemprint
	bsr	keymidi
	cmpi.w	#master,sorm
	beq	icontrol
	cmpi.w	#single,sorm
	beq	onlyme
amslave:
waitstart:
	move.w	#3,-(sp)	;midi device
	move.w	#1,-(sp)
	trap	#13		;is there a char waiting
	addq.l	#4,sp
	tst.w	d0
	beq	waitstart

	move.w	#midiport,-(sp)
	move.w	#2,-(sp)
	trap	#13		;get and discard midi dat
	addq.l	#4,sp
	bra	setupall
icontrol:
*	bsr	cleartext
	lea	mastertext2,a0
	bsr	gemprint
waitk:
	move.w	#$ff,-(sp)
	move.w	#6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0		;wait for keypress
	beq	waitk

	move.b	#0,startstring
	move.l	#startstring,-(sp)
	move.w	#0,-(sp)
	move.w	#12,-(sp)
	trap	#14		;send start message
	addq.l	#8,sp
	bra	setupall

onlyme:
	bsr	cleartext
	lea	singletext,a0
	bsr	gemprint
	lea	singletext2,a0
	bsr	gemprint
	move.w	#1,enemynum
waitks:
	move.w	#$ff,-(sp)
	move.w	#6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0
	beq	waitks

	lea	poslist,a0
	move.w	#4,d0
	bsr	randomplus
	lsl.w	#2,d0
	move.w	(a0,d0.w),screenx
	move.w	2(a0,d0.w),screeny
	move.w	#0,mehits
	move.w	#-1,tankplane
	lea	mesp,a0
	move.w	screenx,d1
	move.w	screeny,d2
	add.w	#128-8,d1
	add.w	#64-8,d2
	move.w	d1,cspritex(a0)
	move.w	d2,cspritey(a0)
	move.l	#metanksprites,cspritead(a0)
	move.w	#1,cactive(a0)
	move.b	#8,whichme
	move.w	#-1,tankspin
	move.w	#-yv8,shotyvel
	move.w	#0,shotxvel


	lea	enemysp0,a0
	bsr	getrandlist
	move.l	a1,cspritelocation(a0)
	move.l	a1,cspriteheading(a0)
	move.l	a1,cspritelistad(a0)
	move.w	#-1,cspritegoing(a0)
	move.w	#1,cactive(a0)
	move.w	#-1,cspritefollow(a0)
	move.w	#1,cspritefight(a0)
	move.w	#0,cspritehits(a0)
	move.w	#-1,cspriteexploding(a0)
	move.l	a1,a6
	bsr	dolist

	lea	enemysp1,a0
da:	bsr	getrandlist
	cmp.l	a6,a1
	beq.s	da
	move.l	a1,cspritelocation(a0)
	move.l	a1,cspriteheading(a0)
	move.l	a1,cspritelistad(a0)
	move.w	#-1,cspritegoing(a0)
	move.w	#1,cactive(a0)
	move.w	#-1,cspritefollow(a0)
	move.w	#1,cspritefight(a0)
	move.w	#0,cspritehits(a0)
	move.w	#-1,cspriteexploding(a0)
	bsr	dolist

	bsr	dosmallmap
	bsr	makemap
	bsr	putbarsandbits
	move.w	#-1,novbl
*	move.w	#189,my
	bra	gamesingle

setupall:
	move.w	#0,enemynum
	lea	poslist,a0
	move.w	#4,d0
	bsr	randomplus
	lsl.w	#2,d0
	move.w	(a0,d0.w),screenx
	move.w	2(a0,d0.w),screeny
	move.w	#0,mehits
	move.w	#-1,tankplane
	lea	mesp,a0
	move.l	#metanksprites,cspritead(a0)
	move.w	#1,cactive(a0)
	move.b	#8,whichme
	move.w	#-1,tankspin
	move.w	#-yv8,shotyvel
	move.w	#0,shotxvel
	bsr	testc
	bsr	sendme
	bsr	doothers
testd:
	lea	enemysp0,a0
	lea	mesp,a1
	move.w	cspritex(a1),d0
	cmp.w	cspritex(a0),d0
	bne.s	ok1
	move.w	cspritey(a1),d0
	cmp.w	cspritey(a0),d0
	bne.s	ok1
	lea	poslist,a0
	move.w	#4,d0
	bsr	randomplus
	lsl.w	#2,d0
	move.w	(a0,d0.w),screenx
	move.w	2(a0,d0.w),screeny
	lea	mesp,a0
	bsr	testc
	bra.s	testd
ok1:
	bsr	sendme
	bsr	dosmallmap
	bsr	makemap
	bsr	putbarsandbits
	move.w	#-1,novbl
*	move.w	#189,my
	bra	gamemulti

getrandlist:
	lea	list,a1
	moveq	#75,d0
	bsr	randomplus
	asl.w	#4,d0
	add.w	d0,a1
	rts


*****************************************
putbarsandbits:
	lea	bar1sp,a0
	bsr	putsprite
	lea	bar2sp,a0
	bsr	putsprite

	lea	minesp,a0
	move.w	#224,(a0)
	move.w	#1,12(a0)	;treat as proper sprite
	bsr	putsprite
	move.w	#232,(a0)
	bsr	putsprite
	move.w	#240,(a0)
	bsr	putsprite
	move.w	#248,(a0)
	bsr	putsprite
	move.w	#-1,12(a0)	;treat as proper sprite

	lea	tanksp,a0
	move.w	#288,(a0)
	move.w	#1,12(a0)	;treat as proper sprite
	bsr	putsprite
	move.w	#296,(a0)
	bsr	putsprite
	move.w	#304,(a0)
	bsr	putsprite
	move.w	#-1,12(a0)
	rts


startstring:
	dc.b	0
miditext1:
	dc.b	91,34,'SPACE BAR TO BEGIN MIDI',0
miditext2:
	DC.B	100,40,'ANY OTHER FOR SINGLE',0
singletext:
	DC.B	106,34,'SINGLE PLAYER GAME',0
singletext2:
	DC.B	82,40,'SELECTED, ANY KEY TO START',0
even
clearmidi:
	move.w	#3,-(sp)	;midi device
	move.w	#1,-(sp)
	trap	#13		;is there a char waiting
	addq.l	#4,sp
	tst.w	d0
	beq	clearback	;already clear
	move.w	#midiport,-(sp)
	move.w	#2,-(sp)
	trap	#13
	addq.l	#4,sp
	bra	clearmidi
clearback:
	rts

midistring:
	blk.b	60,0
midistring2:
	blk.b	60,0

medeadtext1:
	dc.b	91,34,'YOU HAVE BEEN DEFEATED !',0
medeadtext2:
	dc.b	82,41,'AWAITING VICTOR TO RESTART',0
even
medead:
	move.w	#1,novbl
*	move.w	#1,my
	move.b	screen+1,$ff8201
	move.b	screen+2,$ff8203
	addq.l	#4,sp
	move.b	#$cc,(a0)+
	move.b	#$cc,(a0)+
	bsr	nowd2		;send I'm dead
	bsr	cleartext
	lea	medeadtext1,a0
	bsr	gemprint
	lea	medeadtext2,a0
	bsr	gemprint
	bsr	clearmidi
	move.w	#midiport,-(sp)
	move.w	#2,-(sp)
	trap	#13
	addq.l	#4,sp		;get and discard midi dat
	bra	dorestart

******************************
sendme:
	lea	midistring,a0
	move.l	a0,a2
	move.b	(a0)+,d0	;addq.l	#1
	tst.w	tanks
	bge.s	no
	bra.s	medead
no:
	move.b	whichme,(a0)+		;playerimage and a not over byte
	lea	mesp,a1			;above replaced by count
	move.w	cactive(a1),d0
	bpl.s	plact
	move.b	d0,(a0)+
	bra.s	sendshot1
plact:
	move.b	cspritex(a1),(a0)+	;x
	move.b	cspritex+1(a1),(a0)+	;x
	move.b	cspritey(a1),(a0)+	;y
	move.b	cspritey+1(a1),(a0)+	;y
sendshot1:
	lea	meshot1,a1
	move.w	cactive(a1),d0
	bpl.s	shact1
	move.b	d0,(a0)+
	bra.s	sendshot2
shact1:
	move.b	cspritex(a1),(a0)+	;x
	move.b	cspritex+1(a1),(a0)+	;x
	move.b	cspritey(a1),(a0)+	;y
	move.b	cspritey+1(a1),(a0)+	;y
sendshot2:
	lea	meshot2,a1
	move.w	cactive(a1),d0
	bpl.s	shact2
	move.b	d0,(a0)+
	bra.s	sendshot3
shact2:
	move.b	cspritex(a1),(a0)+	;x
	move.b	cspritex+1(a1),(a0)+	;x
	move.b	cspritey(a1),(a0)+	;y
	move.b	cspritey+1(a1),(a0)+	;y
sendshot3:
	lea	meshot3,a1
	move.w	cactive(a1),d0
	bpl.s	shact3
	move.b	d0,(a0)+
	bra.s	sendshot4
shact3:
	move.b	cspritex(a1),(a0)+	;x
	move.b	cspritex+1(a1),(a0)+	;x
	move.b	cspritey(a1),(a0)+	;y
	move.b	cspritey+1(a1),(a0)+	;y
sendshot4:
	lea	meshot4,a1
	move.w	cactive(a1),d0
	bpl.s	shact4
	move.b	d0,(a0)+
	bra.s	sendshot5
shact4:
	move.b	cspritex(a1),(a0)+	;x
	move.b	cspritex+1(a1),(a0)+	;x
	move.b	cspritey(a1),(a0)+	;y
	move.b	cspritey+1(a1),(a0)+	;y
sendshot5:
	move.b	minedrop,(a0)+
	tst.w	minedrop
	bmi	nokd
	move.b	#-1,minedrop
nokd:
	tst.b	wepdrop
	bmi	nowd
	move.b	#-1,wepdrop
	lea	mywep,a1
	move.b	minex(a1),(a0)+
	move.b	minex+1(a1),(a0)+
	move.b	miney(a1),(a0)+	
	move.b	miney+1(a1),(a0)+
	bra.s	nowd2
nowd:
	move.b	#-1,(a0)+
nowd2:
	lea	$ffffffc04,a1
	moveq	#1,d4
	sub.l	a2,a0
	subq.w	#1,a0
	move.w	a0,d3		;counter of chars to write to midi
	ext	d3
	move.b	d3,(a2)		;count to send
	sub.b	#1,(a2)
miditest:
	move.b	(a1),d2
	btst	d4,d2
	beq.s	miditest
	move.b	(a2)+,2(a1)
	dbf	d3,miditest
*	move.w	#$0444,$ff8240
	rts

minedrop:	dc.b	-1
even
************************
enshotlist:
	dc.l	enemyshot00,enemyshot01,enemyshot02,enemyshot03
	dc.l	enemyshot10,enemyshot11,enemyshot12,enemyshot13,-1
enemylist:
	dc.l	enemysp0,enemysp1,-1	;,enemysp1,enemysp2,enemysp3
enemynum:	dc.w	0
**************************************
midiport:	equ	3
mygetmidi:
	move.l	midibuff,a0
	moveq	#0,d0
	lea	midistring2,a4
mgm1:
	lea	6(a0),a2
	lea	8(a0),a3
	cmpm.w	(a3)+,(a2)+
	bne.s	mgm2
	bra.s	mgm1
mgm2:
	move.w	sr,-(sp)
	or.w	#$700,sr
	move.w	6(a0),d1
	cmp.w	8(a0),d1
	beq.s	mgm4
	addq.w	#1,d1
	cmp.w	4(a0),d1
	bcs.s	mgm3
	moveq	#0,d1
mgm3:
	move.l	0(a0),a1
	move.b	0(a1,d1.w),d0
	move.w	d1,6(a0)
mgm4:
	move.w	(sp)+,sr
	tst.b	d0
	bmi.s	nobytes
mgm1a:
	lea	6(a0),a2
	lea	8(a0),a3
	cmpm.w	(a3)+,(a2)+
	bne.s	mgm2a
	bra.s	mgm1a
mgm2a:
	move.w	sr,-(sp)
	or.w	#$700,sr
	move.w	6(a0),d1
	cmp.w	8(a0),d1
	beq.s	mgm4a
	addq.w	#1,d1
	cmp.w	4(a0),d1
	bcs.s	mgm3a
	moveq	#0,d1
mgm3a:
	move.l	0(a0),a1
	move.b	0(a1,d1.w),(a4)+
	move.w	d1,6(a0)
mgm4a:
	move.w	(sp)+,sr
	dbf	d0,mgm1a
nobytes:
	rts

doothers:
	bsr	mygetmidi
	lea	midistring2,a0
	moveq	#0,d1
	move.b	(a0)+,d1
	cmpi.b	#$cc,d1		;special status byte
	beq	startover
	lea	enshotlist,a6
	lea	enemysp0,a4
dootloop:
	move.b	(a0)+,d0
	bmi.s	noshotactp
	move.b	d0,cspritex(a4)
	move.b	(a0)+,cspritex+1(a4)	;that makes x
	move.b	(a0)+,cspritey(a4)
	move.b	(a0)+,cspritey+1(a4)	;that makes y
	lea	enemysprites,a1
*	moveq	#12,d2
*	lsl.l	d2,d1
*	add.l	d1,a1
*	lsl.l	#2,d1
	mulu	#5120,d1
	add.l	d1,a1
	move.l	a1,cspritead(a4)
	move.w	#1,cactive(a4)
	bra.s	getshots
noshotactp:
	move.w	#-1,cactive(a4)	;this one aint active for 1st time
getshots:
	moveq	#3,d6		;4 shots for each player
gsloop:
	move.l	(a6)+,a4
shotdata:
	move.b	(a0)+,d0
*	tst.b	d0
	bmi.s	noshotact
	move.b	d0,cspritex(a4)
	move.b	(a0)+,cspritex+1(a4)	;that makes x
	move.b	(a0)+,cspritey(a4)
	move.b	(a0)+,cspritey+1(a4)	;that makes x
	move.w	#1,cactive(a4)
	dbf	d6,gsloop
	bra.s	domineot
noshotact:
	move.w	#-1,cactive(a4)	;this one aint active for 1st time
	dbf	d6,gsloop
domineot:
	tst.b	(a0)+
	bmi.s	nonewmine
	movem.l	d0-d7/a0-a6,-(sp)
	bsr	doenemymine
	movem.l	(sp)+,d0-d7/a0-a6
nonewmine:
	move.b	(a0)+,d0
*	tst.b	d0
	bmi.s	nonewwep
	lea	enwep,a4
	move.b	d0,minex(a4)
	move.b	(a0)+,minex+1(a4)
	move.b	(a0)+,miney(a4)
	move.b	(a0)+,miney+1(a4)
	movem.l	d0-d7/a0-a6,-(sp)
	bsr	doenemywep
	movem.l	(sp)+,d0-d7/a0-a6
nonewwep:
putothers:
	lea	enemysp0,a0
	bsr	preparesprite
	lea	enemyshot00,a0
	bsr	preparesprite
	lea	enemyshot01,a0
	bsr	preparesprite
	lea	enemyshot02,a0
	bsr	preparesprite
	lea	enemyshot03,a0
	bra	preparesprite
	rts
startover:
	bsr	stopallsound
	move.w	#1,novbl
	move.b	screen+1,$ff8201
	move.b	screen+2,$ff8203
	addq.l	#4,sp
	bsr	clearmidi
	bsr	cleartext
	lea	mewintext1,a0
	bsr	gemprint
	lea	mewintext2,a0
	bsr	gemprint
	bsr	clearkeyboard
waitko:
	move.w	#$ff,-(sp)
	move.w	#6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0		;wait for keypress
	beq	waitko
	move.l	#masterstring,-(sp)
	move.w	#0,-(sp)
	move.w	#12,-(sp)
	trap	#14
	addq.l	#8,sp		;send sig to restart
	bra	dorestart

clearkeyboard:
cleark:
	move.w	#$ff,-(sp)
	move.w	#6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0		;wait for keypress
	bne	cleark
	rts

mewintext1:
	dc.b	100,34,'YOU ARE VICTORIOUS !',0
mewintext2:
	dc.b	103,40,'ANY KEY TO RESTART',0
even
*************************************
stch:
	move.w	buttondat,d0
	cmp.w	lastb,d0
	beq	nochange
	move.w	#-1,changestate
	move.w	d0,lastb
	rts
nochange:
	move.w	#1,changestate
	rts
changestate:
	dc.w	-1


doenemyshots:
	lea	enemysp0,a1
	tst.w	cactive(a1)
	bmi.s	deso1
	subq.w	#1,cspriteshotdel(a1)
	bpl	deso1
	move.w	#-1,cspriteshotdel(a1)
	tst.w	tankplanee(a1)
	bpl.s	deso1
	tst.w	tankspine(a1)
	bpl.s	deso1
*	cmpi.w	#2,cspritevels(a1)
*	bgt.s	deso1
	lea	enemyshot00,a0
	tst.w	cactive(a0)
	bpl.s	dsa1
	bsr	doeshotavail
	bra.s	deso1
dsa1:
	lea	enemyshot01,a0
	tst.w	cactive(a0)
	bpl.s	dsa2
	bsr	doeshotavail
	bra.s	deso1
dsa2:
	lea	enemyshot02,a0
	tst.w	cactive(a0)
	bpl.s	dsa3
	bsr	doeshotavail
	bra.s	deso1
dsa3:
	lea	enemyshot03,a0
	tst.w	cactive(a0)
	bpl.s	deso1
	bsr	doeshotavail
deso1:
	lea	enemysp1,a1
	tst.w	cactive(a1)
	bmi.s	deso2
	subq.w	#1,cspriteshotdel(a1)
	bpl	deso2
	move.w	#-1,cspriteshotdel(a1)
	tst.w	tankplanee(a1)
	bpl.s	deso2
	tst.w	tankspine(a1)
	bpl.s	deso2
*	cmpi.w	#2,cspritevels(a1)
*	bgt.s	deso2
	lea	enemyshot10,a0
	tst.w	cactive(a0)
	bpl.s	dsb1
	bsr	doeshotavail
	bra.s	deso2
dsb1:
	lea	enemyshot11,a0
	tst.w	cactive(a0)
	bpl.s	dsb2
	bsr	doeshotavail
	bra.s	deso2
dsb2:
	lea	enemyshot12,a0
	tst.w	cactive(a0)
	bpl.s	dsb3
	bsr	doeshotavail
	bra.s	deso2
dsb3:
	lea	enemyshot13,a0
	tst.w	cactive(a0)
	bpl.s	deso2
	bsr	doeshotavail
deso2:
	lea	enemyshot00,a0
	bsr	domoves
	bsr	preparesprite
	lea	enemyshot01,a0
	bsr	domoves
	bsr	preparesprite
	lea	enemyshot02,a0
	bsr	domoves
	bsr	preparesprite
	lea	enemyshot03,a0
	bsr	domoves
	bsr	preparesprite
	lea	enemyshot10,a0
	bsr	domoves
	bsr	preparesprite
	lea	enemyshot11,a0
	bsr	domoves
	bsr	preparesprite
	lea	enemyshot12,a0
	bsr	domoves
	bsr	preparesprite
	lea	enemyshot13,a0
	bsr	domoves
	bsr	preparesprite
	rts

doeshotavail:
*	bsr	doshoot
	lea	enemyshootsound,a6
	bsr	startsound
	move.w	#8,cspriteshotdel(a1)
	move.w	cspritexvel(a1),d0
	move.w	cspriteyvel(a1),d1
	move.w	d0,d2
	bpl.L	dsaa
	neg.w	d2
dsaa:
	cmpi.w	#2,d2
	bgt.s	dsab
	move.w	d1,d2
	bpl.s	dsaab
	neg.w	d2
dsaab:
	cmpi.w	#2,d2
	bgt.s	dsab
	add.w	d0,d0
	add.w	d1,d1
	move.w	d0,cspritexvel(a0)
	move.w	d1,cspriteyvel(a0)
	move.w	cspritex(a1),cspritex(a0)
	move.w	cspritey(a1),cspritey(a0)
	add.w	#8-1,cspritex(a0)
	add.w	#8-1,cspritey(a0)
	move.w	#1,cactive(a0)
	move.w	#150,cspritelife(a0)
	move.w	#1,cspriterotate(a1)
dsab:	rts

***************************************
doshots:
	tst.w	tankplane
	bpl	noshot
	tst.w	changestate
	bpl.L	movemyshots
	tst.w	buttondat
	beq.L	movemyshots
	tst.w	shots
	ble	movemyshots
	lea	meshot1,a0
	tst.w	cactive(a0)
	bpl.s	isshot2
	bsr	doshotavail
	bra.s	movemyshots
isshot2:
	lea	meshot2,a0
	tst.w	cactive(a0)
	bpl.s	isshot3
	bsr	doshotavail
	bra.s	movemyshots
isshot3:
	lea	meshot3,a0
	tst.w	cactive(a0)
	bpl.s	isshot4
	bsr	doshotavail
	bra.s	movemyshots
isshot4:
	lea	meshot4,a0
	tst.w	cactive(a0)
	bpl.s	movemyshots
	bsr	doshotavail

movemyshots:
	lea	meshot1,a0
	bsr.L	domoves
	bsr	preparesprite
	lea	meshot2,a0
	bsr.L	domoves
	bsr	preparesprite
	lea	meshot3,a0
	bsr.L	domoves
	bsr	preparesprite
	lea	meshot4,a0
	bsr.L	domoves
	bsr	preparesprite
	rts

domoves:
	tst.w	cactive(a0)
	bmi.L	dmback
	subq.w	#1,cspritelife(a0)
	bmi.L	endofshot
	move.w	cspritexvel(a0),d3
	move.w	cspriteyvel(a0),d4
	move.w	cspritex(a0),d1
	move.w	cspritey(a0),d2
	add.w	d3,d1
	add.w	d4,d2
	move.w	d1,d5
	move.w	d2,d6

	tst.w	d3
	beq.L	upordown
	tst.w	d4
	beq.L	leftorright
	tst.w	d3
	bmi	goingleft
goingright:
	move.w	#-1,hits2
	tst.w	d4
	bmi	ru
rd:
	bsr	chrights
	bsr	chbots
	tst.w	hits2
	bgt	endofshot
	add.w	d3,cspritex(a0)
	add.w	d4,cspritey(a0)
noshot:
	rts
ru:
	bsr	chrights
	bsr	chtops
	tst.w	hits2
	bgt	endofshot
	add.w	d3,cspritex(a0)
	add.w	d4,cspritey(a0)
	rts
hits2:	dc.w	-1
goingleft:
	move.w	#-1,hits2
	tst.w	d4
	bmi	lu
ld:
	bsr	chlefts
	bsr	chbots
	tst.w	hits2
	bgt	endofshot
	add.w	d3,cspritex(a0)
	add.w	d4,cspritey(a0)
	rts
lu:
	bsr	chlefts
	bsr	chtops
	tst.w	hits2
	bgt	endofshot
	add.w	d3,cspritex(a0)
	add.w	d4,cspritey(a0)
	rts


leftorright:
	tst.w	d3
	bmi.s	left
	bsr	chrights
	add.w	d3,cspritex(a0)
	add.w	d4,cspritey(a0)
	rts
left:
	bsr	chlefts
	add.w	d3,cspritex(a0)
	add.w	d4,cspritey(a0)
	rts
upordown:
	tst.w	d4
	bmi.s	up
	bsr	chbots
	add.w	d3,cspritex(a0)
	add.w	d4,cspritey(a0)
	rts
up:
	bsr	chtops
	add.w	d3,cspritex(a0)
	add.w	d4,cspritey(a0)
	rts
	
chstops:
	add.w	d3,cspritex(a0)
	add.w	d4,cspritey(a0)
	rts

chlefts:
	move.w	d5,d1
	move.w	d6,d2
	subq.w	#1,d1
	addq.w	#2,d2
	move.w	d1,pixelx
	move.w	d2,pixely
	bsr	mygetpix
	tst.w	d0
	beq.s	ishita
	cmpi.w	#3,d0
	blt.s	chlback
	cmpi.w	#7,d0
	bge.s	chlback
ishita:
	neg.w	cspritexvel(a0)
	neg.w	d3
	addq.w	#1,hits2
chlback:
	rts

chrights:
	move.w	d5,d1
	move.w	d6,d2
	addq.w	#4,d1
	addq.w	#2,d2
	move.w	d1,pixelx
	move.w	d2,pixely
	bsr	mygetpix
	tst.w	d0
	beq.s	ishitb
	cmpi.w	#3,d0
	blt.s	chrback
	cmpi.w	#7,d0
	bge.s	chrback
ishitb:
	neg.w	cspritexvel(a0)
	neg.w	d3
	addq.w	#1,hits2
chrback:
	rts
chtops:
	move.w	d5,d1
	move.w	d6,d2
	addq.w	#1,d1
	subq.w	#1,d2
	move.w	d1,pixelx
	move.w	d2,pixely
	bsr	mygetpix
	tst.w	d0
	beq.s	ishitc
	cmpi.w	#3,d0
	blt.s	chtback
	cmpi.w	#7,d0
	bge.s	chtback
ishitc:
	neg.w	cspriteyvel(a0)
	neg.w	d4
	addq.w	#1,hits2
chtback:
	rts

chbots:
	move.w	d5,d1
	move.w	d6,d2
	addq.w	#5,d2
	addq.w	#1,d1
	move.w	d1,pixelx
	move.w	d2,pixely
	bsr	mygetpix
	tst.w	d0
	beq.s	ishitd
	cmpi.w	#3,d0
	blt.s	chbback
	cmpi.w	#7,d0
	bge.s	chbback
ishitd:
	neg.w	cspriteyvel(a0)
	neg.w	d4
	addq.w	#1,hits2
chbback:
	rts
endofshot:
	move.w	#-1,cactive(a0)
dmback:
	rts
doshotavail:
	lea	meshootsound,a6
	bsr	startsound
*	bsr	doshoot
	subq.w	#1,shots
	bsr	subshot
	move.w	shotxvel,d0
	move.w	shotyvel,d1
	move.w	d0,cspritexvel(a0)
	move.w	d1,cspriteyvel(a0)
	lea	mesp,a1
	move.w	cspritex(a1),cspritex(a0)
	move.w	cspritey(a1),cspritey(a0)
	add.w	#8-1,cspritex(a0)
	add.w	#8-1,cspritey(a0)
	move.w	#1,cactive(a0)
	move.w	#150,cspritelife(a0)
	rts

tankplane:	dc.w	-1
tankspin:	dc.w	100
tankimage:	dc.l	metanksprites
tankstart:	dc.l	metanksprites
tankadd:	dc.l	0
whichmehigh:	dc.b	0
whichmestart:	dc.b	0

doenemyspinning:
	tst.w	cactive(a0)
	bmi	normalmee
	tst.w	tankspine(a0)
	bmi.L	normalmee
	subq.w	#1,tankspine(a0)
	bpl.s	nospece
	tst.w	tankplanee(a0)
	bpl.s	isplanee
	move.b	whichmestarte(a0),d0
	add.b	#8,d0
	move.b	d0,whichmee(a0)
	lea	enemytanksprites,a2
	add.l	tankadde(a0),a2
	move.l	a2,cspritead(a0)
	bra.s	normalmee
isplanee:
	move.b	whichmestarte(a0),d0
	subq.b	#8,d0
	move.b	d0,whichmee(a0)
	lea	enemysprites,a2
	add.l	tankadde(a0),a2
	move.l	a2,cspritead(a0)
	bra.s	normalmee
nospece:
	addq.b	#1,whichmee(a0)
	move.b	whichmehighe(a0),d0
	cmp.b	whichmee(a0),d0
	bgt.s	whm1e
	move.b	whichmestarte(a0),whichmee(a0)
whm1e:
*	lea	mesp,a1
	move.l	tankimagee(a0),cspritead(a0)
	move.l	tankstarte(a0),d0
	add.l	#8*5120,d0
	add.l	#5120,tankimagee(a0)
	cmpi.l	tankimagee(a0),d0
	bgt.s	normalmee
	move.l	tankstarte(a0),tankimagee(a0)
normalmee:
	rts
***************************************
dome:
	tst.w	tankspin
	bmi.L	normalme
	subq.w	#1,tankspin
	bpl.s	nospec
	lea	mesp,a1
	tst.w	tankplane
	bpl.s	isplane
	move.b	whichmestart,d0
	add.b	#8,d0
	move.b	d0,whichme
	lea	metanksprites,a0
	add.l	tankadd,a0
	move.l	a0,cspritead(a1)
	bra.s	normalme
isplane:
	move.b	whichmestart,d0
	subq.b	#8,d0
	move.b	d0,whichme
	lea	mesprites,a0
	add.l	tankadd,a0
	move.l	a0,cspritead(a1)
	bra.s	normalme
nospec:
	addq.b	#1,whichme
	move.b	whichmehigh,d0
	cmp.b	whichme,d0
	bgt.s	whm1
	move.b	whichmestart,whichme
whm1:
	lea	mesp,a1
	move.l	tankimage,cspritead(a1)
	move.l	tankstart,d0
	add.l	#8*5120,d0
	add.l	#5120,tankimage
	cmpi.l	tankimage,d0
	bgt.s	normalme
	move.l	tankstart,tankimage
normalme:
	tst.w	tankplane
	bpl.s	plane
	moveq	#2,d0
	moveq	#-2,d1
	bra.s	realstuff
plane:
	moveq	#8,d0
	moveq	#-8,d1
realstuff:
	move.w	xvel,d3
	move.w	yvel,d4
	cmp.w	d0,d3
	ble.s	dm1
	move.w	d0,d3
	move.w	d0,xvel
	bra.s	dm2
dm1:
	cmp.w	d1,d3
	bge.s	dm2
	move.w	d1,d3
	move.w	d1,xvel
dm2:
	cmp.w	d0,d4
	ble.s	dm3
	move.w	d0,d4
	move.w	d0,yvel
	bra.s	dm4
dm3:
	cmp.w	d1,d4
	bge.s	dm4
	move.w	d1,d4
	move.w	d1,yvel
dm4:
	movem.w	d3-d4,-(sp)
	lea	mesp,a0
	move.w	screenx,d1
	move.w	screeny,d2
	add.w	d3,d1
	add.w	d4,d2
	move.w	d1,d5
	move.w	d2,d6
	add.w	#128-9,d1	;151
	add.w	#64,d2		;100
	tst.w	d3
	bge.s	chright
	move.w	d1,pixelx
	move.w	d2,pixely
	bsr	mygetpix
	tst.w	d0
	beq.s	ishit1
	cmpi.w	#3,d0
	blt.s	chtop
	cmpi.w	#7,d0
	bge.s	chtop
ishit1:
	neg.w	xvel
	moveq	#0,d3
	bra.s	chtop
chright:
	add.w	#17,d1
	tst.w	d3
	beq.s	chtop
	move.w	d1,pixelx
	move.w	d2,pixely
	bsr	mygetpix
	tst.w	d0
	beq.s	ishit2
	cmpi.w	#3,d0
	blt.s	chtop
	cmpi.w	#7,d0
	bge.s	chtop
ishit2:
	neg.w	xvel
	moveq	#0,d3
chtop:
	move.w	d5,d1
	move.w	d6,d2
	add.w	#64-9,d2		;91
	add.w	#128-1,d1		;159
	tst.w	d4
	bgt.s	chbot
	beq.s	chstop
	move.w	d1,pixelx
	move.w	d2,pixely
	bsr	mygetpix
	tst.w	d0
	beq.s	ishit3
	cmpi.w	#3,d0
	blt.s	chstop
	cmpi.w	#7,d0
	bge.s	chstop
ishit3:
	neg.w	yvel
	moveq	#0,d4
	bra.s	chstop
chbot:
	add.w	#17,d2
	move.w	d1,pixelx
	move.w	d2,pixely
	bsr	mygetpix
	tst.w	d0
	beq.s	ishit4
	cmpi.w	#3,d0
	blt.s	chstop
	cmpi.w	#7,d0
	bge.s	chstop
ishit4:
	neg.w	yvel
	moveq	#0,d4
chstop:
	movem.w	(sp)+,d0-d1
	cmp.w	d0,d3
	beq.s	chs1
*	bsr	dowall
	lea	hitwallsound,a6
	bsr	startsound
	bra.s	chs2
chs1:
	cmp.w	d1,d4
	beq.s	chs2
*	bsr	dowall
	lea	hitwallsound,a6
	bsr	startsound
chs2:
	add.w	d3,screenx
	add.w	d4,screeny
testc:
	move.w	screenx,d1
	move.w	screeny,d2
	add.w	#128-8,d1
	add.w	#64-8,d2
	move.w	d1,cspritex(a0)
	move.w	d2,cspritey(a0)
	move.w	#1,cactive(a0)
	bsr	preparesprite
	rts
****************************************
whichme:	dc.b	0
even
****************************************
joydir:
	lea	mesp,a0
	tst.w	tankplane
	bpl.s	plim
	lea	metanksprites,a1
	move.w	#8,d7
	bra.s	joystart
plim:	lea	mesprites,a1
	move.b	#0,d7
joystart:
	move.l	a1,tankstart
	tst.b	joyport1
	beq	jdback2aa
	move.b	d7,whichme
	move.b	joyport1,d0
north2:
	cmpi.b	#1,d0
	bne	neast2
	sub.w	#nsamount2,yvel
	move.w	#-yv8,shotyvel
	move.w	#0,shotxvel
	move.l	a1,cspritead(a0)
	add.b	#0,whichme
	bra.L	jdback2a
neast2: cmpi.b	#9,d0
	bne	east2
	sub.w	#nsamount2,yvel
	add.w	#nsamount2,xvel
	move.w	#-yv8,shotyvel
	move.w	#xv8,shotxvel
	lea	5120*1(a1),a1
	move.l	a1,cspritead(a0)
	add.b	#1,whichme
	bra.L	jdback2
east2:	cmpi.b	#8,d0
	bne	seast2
	add.w	#nsamount2,xvel
	move.w	#0,shotyvel
	move.w	#xv8,shotxvel
	lea	5120*2(a1),a1
	move.l	a1,cspritead(a0)
	add.b	#2,whichme
	bra.L	jdb2
seast2: cmpi.b	#10,d0
	bne	south2
	add.w	#nsamount2,yvel
	add.w	#nsamount2,xvel
	move.w	#yv8,shotyvel
	move.w	#xv8,shotxvel
	lea	5120*3(a1),a1
	move.l	a1,cspritead(a0)
	add.b	#3,whichme
	bra.L	jdback2
south2: cmpi.b	#2,d0
	bne	swest2
	add.w	#nsamount2,yvel
	move.w	#yv8,shotyvel
	move.w	#0,shotxvel
	lea	5120*4(a1),a1
	move.l	a1,cspritead(a0)
	add.b	#4,whichme
	bra.L	jdback2a
swest2: cmpi.b	#6,d0
	bne	west2
	add.w	#nsamount2,yvel
	sub.w	#nsamount2,xvel
	move.w	#yv8,shotyvel
	move.w	#-xv8,shotxvel
	lea	5120*5(a1),a1
	move.l	a1,cspritead(a0)
	add.b	#5,whichme
	bra.s	jdback2
west2:	cmpi.b	#4,d0
	bne	nwest2
	sub.w	#nsamount2,xvel
	move.w	#0,shotyvel
	move.w	#-xv8,shotxvel
	lea	5120*6(a1),a1
	move.l	a1,cspritead(a0)
	add.b	#6,whichme
	bra.s	jdb2
nwest2: cmpi.b	#5,d0
	bne	jdback2
	sub.w	#nsamount2,yvel
	sub.w	#nsamount2,xvel
	move.w	#-yv8,shotyvel
	move.w	#-xv8,shotxvel
	add.l	#5120*7,a1
	move.l	a1,cspritead(a0)
	add.b	#7,whichme
jdback2:
	rts

jdback2a:
	tst.w	xvel
	bmi.s	jdb1
	beq.s	jdb2a
	subq.w	#1,xvel
	bra.s	jdb2a
jdb1:
	addq.w	#1,xvel
jdb2a:
	rts

jdback2aa:
	tst.w	xvel
	bmi.s	jdb1aa
	beq.s	jdb2
	subq.w	#1,xvel
	bra.s	jdb2
jdb1aa:
	addq.w	#1,xvel
jdb2:
	tst.w	yvel
	bmi.s	jdb3
	beq.s	jdbb
	subq.w	#1,yvel
	rts
jdb3:
	addq.w	#1,yvel
jdbb:
	rts

firebutton:	blk.w	1,-1
*****************************************
*	set up joystick handler 	*
*****************************************
joystuff:
	move.w	#34,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,a0
	adda.l	#24,a0
	move.l	(a0),old_packh		;save the old handler
	move.l	#joy_packet,(a0)	;put in mine
	rts
*****************************************	
*	this is the joy pak handler	*
*****************************************
joy_packet:
	movem.l a0/a1,-(sp)
	lea	joyport0,a1
	move.b	1(a0),(a1)
	move.b	2(a0),1(a1)
	movem.l (sp)+,a0/a1
	rts

joyport0:	blk.b	1,0
joyport1:	blk.b	1,0
	even

res_mouse:
	move.w	#34,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,a0
	adda.l	#24,a0
	move.l	old_packh,(a0)

rs2:	move.w	#128,-(sp)
	move.w	#4,-(sp)
	move.w	#3,-(sp)
	trap	#13
	addq.l	#6,sp

	move.w	#1,-(sp)
	move.w	#4,-(sp)
	move.w	#3,-(sp)
	trap	#13
	addq.l	#6,sp
	rts

old_packh:	blk.l	1,0

drawlist:
	dc.w	13
	dc.l	mesp,meshot1,meshot2,meshot3,meshot4
	dc.l	enemysp0,enemyshot00,enemyshot01,enemyshot02,enemyshot03
	dc.l	enemysp1,enemyshot10,enemyshot11,enemyshot12,enemyshot13

*****************************************
*	precalc all add stuff		*
*****************************************
preparesprite:
	move.b	#-1,cspriteclipflag(a0)
	move.w	cspritex(a0),d2 	;get x relative
	move.w	cspritey(a0),d1 	;get y
	add.w	#32,d2
	add.w	#18,d1
	move.w	cspriteheight(a0),d3
	move.b	d3,cspritecliph(a0)
	sub.w	screeny,d1
	moveq	#18,d0			;initial y to check
	sub.w	d3,d0
	cmp.w	d0,d1
	blt.L	makenoton
	cmpi.w	#18+128,d1
	bgt.L	makenoton
	sub.w	currentscreenx,d2
	moveq	#32,d0
	sub.w	d3,d0
	cmp.w	d0,d2
	blt.L	makenoton
	cmpi.w	#272+16,d2
	bge.L	makenoton
	move.w	#1,cspritevisflag(a0)
	move.w	d2,d0		;d2=x
	move.w	d1,d5		;d1=y
	moveq	#17,d7		;ymin
	sub.w	d5,d7
	bmi.s	notopclip
	move.w	d3,d6
	sub.w	d7,d6		;number of lines left
	move.b	d6,cspritecliph(a0)
	moveq	#18,d1
	mulu	#20,d7
	bra.s	finclip
notopclip:
	move.w	#128+18,d7		;ymin
	sub.w	d3,d7
	sub.w	d5,d7
	bpl.s	noclip
	move.w	d3,d6
	add.w	d7,d6		;number of lines left
	move.b	d6,cspritecliph(a0)
noclip:
	moveq	#0,d7
finclip:
	and.w	#15,d2			;get last 4 bits=offset
	move.w	d2,d4
	move.l	hiden,a6
	swap	d1
	clr.w	d1
	swap	d1
*	mulu	#160,d1
	lsl.w	#5,d1
	add.w	d1,a6			;=*160 gives line add
	lsl.w	#2,d1
	add.w	d1,a6
	and.w	#$fff0,d0		;word
clipa:
	cmpi.w	#$10,d0
	bne.s	clipb
	move.b	#0,cspriteclipflag(a0)
	add.w	#$10,d0
	bra.s	clipc
clipb:
	cmpi.w	#$110,d0
	bne.s	clipc
	move.b	#1,cspriteclipflag(a0)
clipc:
	lsr.w	#1,d0
	add.w	d0,a6			;a6 has actual screen address
	move.l	a6,cquickaddress(a0)	;for actual put

	cmpi.w	#4,d3
	bne.s	spcl4
	move.l	cspritead(a0),a1
	lsl.w	#4,d4		;*16
	add.w	d4,a1		;a1 has ad of final sprite data
	lsl.w	#2,d4
	add.w	d4,a1
	bra.s	extrastuff
spcl4:
	cmpi.w	#8,d3
	bne.s	spcl5
	move.l	cspritead(a0),a1
	lsl.w	#5,d4		;*16
	add.w	d4,a1		;a1 has ad of final sprite data
	lsl.w	#2,d4
	add.w	d4,a1
	bra.s	extrastuff
spcl5:
	move.l	cspritead(a0),a1
	lsl.w	#6,d4		;*128
	add.w	d4,a1		;a1 has ad of final sprite data
	lsl.w	#2,d4
	add.w	d4,a1
extrastuff:
	tst.w	d7
	beq.s	skipclip
	add.w	d7,a1
skipclip:
	move.l	a1,cquickspaddress(a0)

noprepare:
	rts
makenoton:
	move.w	#-1,cspritevisflag(a0)
	rts

*********************************
drawclipped:
	move.l	cquickaddress(a0),a2
	move.l	cquickspaddress(a0),a1
	moveq	#0,d4
	move.b	cspritecliph(a0),d4
	beq	clipover
doallsprite:
	subq.w	#1,d4
	tst.b	cspriteclipflag(a0)
	bge	clipleft
doallloop:
	movem.w	(a2),d0-d3
	and.w	(a1),d0 	;mask word
	and.w	(a1),d1 	;mask word
	and.w	(a1),d2 	;mask word
	and.w	(a1)+,d3	;mask word
	or.w	(a1)+,d0	;or the sprite image in the hole
	or.w	(a1)+,d1	;we just cut
	or.w	(a1)+,d2
	or.w	(a1)+,d3
	move.w	d0,(a2)+	;put the picture in th picture
	move.w	d1,(a2)+
	move.w	d2,(a2)+
	move.w	d3,(a2)+
	movem.w	(a2),d0-d3
	and.w	(a1),d0 	;mask word
	and.w	(a1),d1 	;mask word
	and.w	(a1),d2 	;mask word
	and.w	(a1)+,d3	;mask word
	or.w	(a1)+,d0	;or the sprite image in the hole
	or.w	(a1)+,d1	;we just cut
	or.w	(a1)+,d2
	or.w	(a1)+,d3
	move.w	d0,(a2)+	;put the picture in th picture
	move.w	d1,(a2)+
	move.w	d2,(a2)+
	move.w	d3,(a2)+
	lea	160-16(a2),a2
	dbf	d4,doallloop
clipover:
	rts

clipleft:
	bgt	clipright
	lea	10(a1),a1
doallleft:
	movem.w	(a2),d0-d3
	and.w	(a1),d0 	;mask word
	and.w	(a1),d1 	;mask word
	and.w	(a1),d2 	;mask word
	and.w	(a1)+,d3	;mask word
	or.w	(a1)+,d0	;or the sprite image in the hole
	or.w	(a1)+,d1	;we just cut
	or.w	(a1)+,d2
	or.w	(a1)+,d3
	move.w	d0,(a2)+	;put the picture in th picture
	move.w	d1,(a2)+
	move.w	d2,(a2)+
	move.w	d3,(a2)+
	lea	160-8(a2),a2
	lea	10(a1),a1
	dbf	d4,doallleft
	rts
clipright:
doallright:
	movem.w	(a2),d0-d3
	and.w	(a1),d0 	;mask word
	and.w	(a1),d1 	;mask word
	and.w	(a1),d2 	;mask word
	and.w	(a1)+,d3	;mask word
	or.w	(a1)+,d0	;or the sprite image in the hole
	or.w	(a1)+,d1	;we just cut
	or.w	(a1)+,d2
	or.w	(a1)+,d3
	move.w	d0,(a2)+	;put the picture in th picture
	move.w	d1,(a2)+
	move.w	d2,(a2)+
	move.w	d3,(a2)+
	lea	160-8(a2),a2
	lea	10(a1),a1
	dbf	d4,doallright
	rts

****************************************
mesp:
	dc.w	50,50		;x,y
	dc.l	mesprites	;address of bank of 16 prerotated sprites
	dc.w	16		;height
	dc.w	16		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
meshot1:
	dc.w	50,50		;x,y
	dc.l	shotsprites	;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	-1
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0		;x y vel 
	dc.w	0		;life
meshot2:
	dc.w	50,50		;x,y
	dc.l	shotsprites	;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	-1
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0
	dc.w	0	
meshot3:
	dc.w	50,50		;x,y
	dc.l	shotsprites	;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	-1
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0
	dc.w	0	
meshot4:
	dc.w	50,50		;x,y
	dc.l	shotsprites	;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	-1
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0
	dc.w	0	
enemysp0:
	dc.w	50,50		;x,y
	dc.l	enemysprites	;address of bank of 16 prerotated sprites
	dc.w	16		;height
	dc.w	16		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0,0		;xvel,yvel,x2,y2,
	dc.l	0		;mylocation
	dc.l	0		;headingto
	dc.w	-1		;going
	dc.l	0		;listad
	dc.w	0		;cspritefollow
	dc.w	0,0		;fight hits
	dc.w	-1,-1		;tankspine,tankplane
	dc.l	0,enemytanksprites,0		;ti,ts,ta
	dc.l	en0shotlist
	dc.b	0,0,0,0		;whichme,whichmest,whichmeh
	dc.w	2		;cspritevels
	dc.w	0		;shotdel
	dc.w	0		;cspriteexploding
	dc.w	0		;rotate
en0shotlist:
	dc.l	enemyshot00,enemyshot01,enemyshot02,enemyshot03
enemyshot00:
	dc.w	50,50		;x,y
	dc.l	shotsprites+1280;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0
enemyshot01:
	dc.w	50,50		;x,y
	dc.l	shotsprites+1280;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0
enemyshot02:
	dc.w	50,50		;x,y
	dc.l	shotsprites+1280;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0
enemyshot03:
	dc.w	50,50		;x,y
	dc.l	shotsprites+1280;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0
enemysp1:
	dc.w	50,50		;x,y
	dc.l	enemysprites	;address of bank of 16 prerotated sprites
	dc.w	16		;height
	dc.w	16		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0,0		;xvel,yvel,x2,y2,
	dc.l	0		;mylocation
	dc.l	0		;headingto
	dc.w	-1		;going
	dc.l	0		;listad
	dc.w	0		;cspritefollow
	dc.w	0,0		;fight hits
	dc.w	-1,-1		;tankspine,tankplane
	dc.l	0,enemytanksprites,0		;ti,ts,ta
	dc.l	en1shotlist
	dc.b	0,0,0,0		;whichme,whichmest,whichmeh
	dc.w	2
	dc.w	0		;shotdel
	dc.w	0		;cspriteexploding
	dc.w	0
even
en1shotlist:
	dc.l	enemyshot10,enemyshot11,enemyshot12,enemyshot13

enemyshot10:
	dc.w	50,50		;x,y
	dc.l	shotsprites+1280;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0
enemyshot11:
	dc.w	50,50		;x,y
	dc.l	shotsprites+1280;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0
enemyshot12:
	dc.w	50,50		;x,y
	dc.l	shotsprites+1280;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0
enemyshot13:
	dc.w	50,50		;x,y
	dc.l	shotsprites+1280;address of bank of 16 prerotated sprites
	dc.w	4		;height
	dc.w	4		;width
	dc.w	-1		;cactive
	dc.l	0
	dc.l	0		;quickaddress
	dc.l	0		;quickspaddress
	dc.w	0,0,0
***************************************
makemap:
	bsr	stopallsound
	lea	blocks,a2
	lea	scr,a1
	lea	gamemap,a0
	moveq	#49,d0		;down
mml:
	moveq	#79,d1		;across
	move.l	a1,a6
mml2:
	moveq	#0,d2
	move.b	(a0)+,d2
	asl.w	#7,d2		;*128
	move.l	a2,a3	;block ad
	add.w	d2,a3
	bsr	putblock
	add.l	#8,a6
	dbf	d1,mml2
	add.l	#640*16,a1
	dbf	d0,mml
	rts

putblock:
	move.l	a6,a4		;copy screen ad
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	move.l	(a3)+,(a4)+
	move.l	(a3)+,(a4)+
	lea	640-8(a4),a4
	rts


***************************************
dosmallmap:
	lea	gamemap,a6
	moveq	#29,d4		;y
	moveq	#49,d0		;down
mmls:
	moveq	#79,d1		;across
	move.w	d1,d3		;x
*	move.l	a1,a6
mml2s:
	moveq	#0,d2
	move.b	(a6)+,d2
	bsr	putminiblock
	addq.w	#2,d3		;advance x
	dbf	d1,mml2s
	addq.w	#2,d4		;advance y
	dbf	d0,mmls
	rts

putminiblock:
	cmpi.b	#16,d2
	bge.s	wallblock
	lea	floorsp,a0
	move.w	d3,(a0)
	move.w	d4,2(a0)
	bsr	putsprite
	rts
wallblock:
	lea	wallsp,a0
	move.w	d3,(a0)
	move.w	d4,2(a0)
	bsr	putsprite
	rts

*********************************************************
*	New sprite routine				*
*	New version give ad of sprite structure in A0	*
*********************************************************
putsprite:
	movem.l	d0-d7/a0-a6,-(sp)
	move.w	(a0),d2
	move.w	d2,d0
	move.w	2(a0),d1
	and.w	#15,d2
	move.l	screen,a6
	lsl.w	#5,d1
	add.w	d1,a6
	lsl.w	#2,d1
	add.w	d1,a6
	and.w	#$fff0,d0
	lsr.w	#1,d0
	add.w	d0,a6
	move.l	a6,a2
*************CODE TO ROTATE A SPRITE IMAGE***********************
shiftimages:
	move.w	4(a0),d1
	move.l	8(a0),a1
	lea	gtemp,a2
ssi1:
	move.w	6(a0),d0
	clr.l	(a2)
	clr.l	4(a2)
ssi0:	
	moveq	#0,d4
	moveq	#0,d5
	moveq	#0,d6
	moveq	#0,d7
	move.w	(a1)+,d4
	move.w	(a1)+,d5
	move.w	(a1)+,d6
	move.w	(a1)+,d7
	ror.l	d2,d4
	ror.l	d2,d5
	ror.l	d2,d6
	ror.l	d2,d7
	or.w	d4,(a2)+
	or.w	d5,(a2)+
	or.w	d6,(a2)+
	or.w	d7,(a2)+
	swap	d4
	swap	d5
	swap	d6
	swap	d7
	move.w	d4,(a2)
	move.w	d5,2(a2)
	move.w	d6,4(a2)
	move.w	d7,6(a2)
	dbf	d0,ssi0
	addq.l	#8,a2
	dbf	d1,ssi1
	tst.w	12(a0)
	bmi	specsprite
smake_mask:
	move.w	4(a0),d1
	lea	gtemp,a1
	lea	gmask,a2
smm1:
	move.w	6(a0),d0
	addq.w	#1,d0
smm0:	move.w	(a1)+,d2
	or.w	(a1)+,d2
	or.w	(a1)+,d2
	or.w	(a1)+,d2
	move.w	d2,d3
	swap	d2
	move.w	d3,d2
	eor.l	#-1,d2
	move.l	d2,(a2)+
	dbf	d0,smm0
	dbf	d1,smm1

*********code to put sprite on screen********************
sdraw:
	move.w	4(a0),d1
	lea	gtemp,a1
	lea	gmask,a2
	move.l	a6,a3
sdi1:	move.w	6(a0),d0
	addq.w	#1,d0
	move.l	a6,a5
sdi0:
	move.l	(a2)+,d3
*	move.l	(a1)+,d6
*	move.l	(a1)+,d7
	movem.l	(a1)+,d6-d7
*	move.l	(a3)+,d4
*	move.l	(a3)+,d5
	movem.l	(a3)+,d4-d5
	and.l	d3,d4
	and.l	d3,d5
	or.l	d6,d4
	or.l	d7,d5
	move.l	d4,(a5)+
	move.l	d5,(a5)+
	dbf	d0,sdi0
	lea	160(a6),a6
	move.l	a6,a3
	dbf	d1,sdi1
	movem.l	(sp)+,d0-d7/a0-a6
	rts

*********code to put sprite on screen********************
specsprite:
	move.w	4(a0),d1
	lea	gtemp,a1
sdi1s:
	move.w	6(a0),d0
	addq.w	#1,d0
	move.l	a6,a5
sdi0s:
	move.l	(a1)+,d6
	move.l	(a1)+,d7
	eor.l	d6,(a5)+
	eor.l	d7,(a5)+
	dbf	d0,sdi0s
	lea	160(a6),a6
	dbf	d1,sdi1s
	movem.l	(sp)+,d0-d7/a0-a6
	rts

wallsp:
	dc.w	0,0
	dc.w	1,0
	dc.l	walldat
	dc.w	1
walldat:
	dc.w	$c000,$c000,0,0
	dc.w	$c000,$c000,0,0

floorsp:
	dc.w	0,0
	dc.w	1,0
	dc.l	floordat
	dc.w	1
floordat:
	dc.w	$c000,0,0,0
	dc.w	$c000,0,0,0
memapsp:
	dc.w	-1,0
	dc.w	1,0
	dc.l	medat
	dc.w	-1
medat:
	dc.w	$0,$c000,0,$c000
	dc.w	$0,$c000,0,$c000

barclearsp:
	dc.w	0,3
	dc.w	3,0
	dc.l	bcdat
	dc.w	1
bcdat:
	dc.w	$0,$8000,$8000,0
	dc.w	$0,$8000,$8000,0
	dc.w	$0,$8000,$8000,0
	dc.w	$0,$8000,$8000,0

barclearsp2:
	dc.w	0,3
	dc.w	3,0
	dc.l	bcdat2
	dc.w	1
bcdat2:
	dc.w	$0,$f000,$f000,0
	dc.w	$0,$f000,$f000,0
	dc.w	$0,$f000,$f000,0
	dc.w	$0,$f000,$f000,0
enmapsp0:
	dc.w	-1,0
	dc.w	1,0
	dc.l	endat
	dc.w	-1
enmapsp1:
	dc.w	-1,0
	dc.w	1,0
	dc.l	endat
	dc.w	-1
endat:
	dc.w	$0,0,$c000,$c000
	dc.w	$0,0,$c000,$c000

mewepsp:
	dc.w	-1,0
	dc.w	1,0
	dc.l	mewdat1
	dc.w	-1
mewdat1:
	dc.w	$0000,$8000,$0000,$8000
	dc.w	$0000,$4000,$0000,$4000
enwepsp:
	dc.w	-1,0
	dc.w	1,0
	dc.l	enwdat1
	dc.w	-1
enwdat1:
	dc.w	$0000,$0000,$8000,$8000
	dc.w	$0000,$0000,$4000,$4000

bar1sp:
	dc.w	32,3
	dc.w	3,3
	dc.l	shotsbar
	dc.w	1		;eor or proper
bar2sp:
	dc.w	144,3
	dc.w	3,2
	dc.l	damagebar
	dc.w	1		;eor or proper
minesp:
	dc.w	144,2
	dc.w	5,0
	dc.l	mineimg
	dc.w	-1		;eor or proper
tanksp:
	dc.w	144,3
	dc.w	4,0
	dc.l	tankimg
	dc.w	1		;eor or proper

***************************************
oldmouse:	dc.l	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
**************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	#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
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    .S extra1
        move.w	#mminx,d0
        bra    .S extra2
extra1: cmpi.w   #mmaxx,d0
        ble    .S extra2
        move.w  #mmaxx,d0
extra2:	cmpi.w  #mminy,d1
        bge    .S extra3
        move.w  #mminy,d1
        bra	extra4
extra3: cmpi.w   #mmaxy,d1
        ble    .S extra4
        move.w  #mmaxy,d1
extra4:
        rts

buttondat:	dc.w	0
mx:		dc.w	0
my:		dc.w	189

mminx:	equ	0	;13
mmaxx:	equ	960
mminy:	equ	1	;3
mmaxy:	equ	189	; 13 123
******************************************
keymidi:
	move.w	#$ff,-(sp)
	move.w	#6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0
	beq	anydata
	swap	d0
midistart:
	cmpi.w	#$39,d0
	bne	singlegame		;become master

	bsr	cleartext
	lea	mgs,a0
	bsr	gemprint	;print 'midi game selected
	lea	mastertext,a0	;this machine becomes boss'
	bsr	gemprint

	move.w	#master,sorm
	move.l	#masterstring,-(sp)	;send master message
	move.w	#0,-(sp)
	move.w	#12,-(sp)
	trap	#14
	addq.l	#8,sp		;now wait for responses
waitresp:
	move.w	#midiport,-(sp)
	move.w	#2,-(sp)
	trap	#13
	addq.l	#4,sp		;get and discard midi dat
	rts

singlegame:
	move.w	#single,sorm
	rts

anydata:
	move.w	#3,-(sp)	;midi device
	move.w	#1,-(sp)
	trap	#13		;is there a char waiting
	addq.l	#4,sp
	tst.w	d0
	beq	keymidi
	move.w	#midiport,-(sp)
	move.w	#2,-(sp)
	trap	#13
	addq.l	#4,sp
	cmpi.b	#master,d0	;has a machine become master
	bne	keymidi

	bsr	cleartext
	lea	mgs,a0
	bsr	gemprint
	lea	slavetext,a0
	bsr	gemprint
	lea	slavetext2,a0
	bsr	gemprint

	move.l	#slavestring,-(sp)	;send slave message
	move.w	#0,-(sp)
	move.w	#12,-(sp)
	trap	#14
	addq.l	#8,sp
	move.w	#slave,sorm
	rts

slavestring:
	dc.b	slave
masterstring:
	dc.b	master
mgs:
	DC.B	106,34,'MIDI GAME SELECTED',0
mastertext:
	DC.B	85,40,'THIS MACHINE BECOMES BOSS',0
mastertext2:
	DC.B	112,46,'ANY KEY TO START',0
slavetext:
	dc.b	82,40,'THIS MACHINE BECOMES SLAVE',0
slavetext2:
	DC.B	85,46,'WAITING FOR BOSS TO BEGIN',0
even
*****************************************
clearallsprites:
	lea	enemylist,a0
	bsr	doclear
	lea	enshotlist,a0
	bsr	doclear
	lea	myshotlist,a0
	bsr	doclear
	lea	mesp,a0
	move.w	#-1,cactive(a0)
	move.w	#-1,memapsp
	move.w	#-1,enmapsp0
	move.w	#-1,enmapsp1
	lea	enmine1,a0
	move.w	#-1,mineact(a0)
	lea	enmine2,a0
	move.w	#-1,mineact(a0)
	lea	enmine3,a0
	move.w	#-1,mineact(a0)
	lea	enmine4,a0
	move.w	#-1,mineact(a0)
	lea	mymine1,a0
	move.w	#-1,mineact(a0)
	lea	mymine2,a0
	move.w	#-1,mineact(a0)
	lea	mymine3,a0
	move.w	#-1,mineact(a0)
	lea	mymine4,a0
	move.w	#-1,mineact(a0)
	lea	enwep,a0
	move.w	#-1,mineact(a0)
	lea	mywep,a0
	move.w	#-1,mineact(a0)
	move.b	#-1,wepdrop
	move.b	#-1,minedrop
	rts

doclear:
	move.l	(a0)+,d0
	bmi	dcback
	move.l	d0,a1
	move.w	#-1,cactive(a1)
	bra.s	doclear
dcback:
	rts

****************************************
keyboard:
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     keyback
        swap    d0
quit:   cmpi.w  #$10,d0
        bne     spacep
        bra     gem
spacep:
	cmpi.w	#$39,d0
	bne	dropmine
	tst.w	tankspin
	bpl	alrs
setspin:
	neg.w	tankplane
	move.w	#5*8,tankspin
	move.b	whichme,whichmestart
	cmpi.b	#7,whichme
	ble.s	whm2
	lea	spinupsound,a6
	bsr	startsound
	move.b	#15,whichmehigh
	bra	whm3
whm2:
	move.b	#7,whichmehigh
	lea	spindownsound,a6
	bsr	startsound
whm3:
	lea	mesp,a0
	move.l	cspritead(a0),d0
	move.l	d0,tankimage
	sub.l	tankstart,d0
	move.l	d0,tankadd
	lea	myshotlist,a0
	moveq	#3,d0
loopsc:
	move.l	(a0)+,a1
	tst.w	cactive(a1)
	bmi.s	loopsc2
	move.w	#-1,cactive(a1)
loopsc2:
	dbf	d0,loopsc
alrs:
	rts
dropmine:
	cmpi.w	#$32,d0
	bne.s	pkey
	lea	mesp,a0
	lea	mymine1,a1
	cmpi.w	#-1,mineact(a1)
	beq.L	dodrop
	lea	mymine2,a1
	cmpi.w	#-1,mineact(a1)
	beq.s	dodrop
	lea	mymine3,a1
	cmpi.w	#-1,mineact(a1)
	beq.s	dodrop
	lea	mymine4,a1
	cmpi.w	#-1,mineact(a1)
	beq.s	dodrop
	rts
pkey:
	cmpi.w	#$19,d0
	bne.s	mapkey
	bra	paused
mapkey:
	cmpi.w	#$62,d0
	bne.s	keyback
	neg.w	displaymap
	rts
keyback:
	rts

displaymap:	dc.w	-1
paused:
	lea	cheatlist,a6
paused1:
	move.w  #7,-(sp)
	trap    #1
	addq.l  #2,sp
	cmpi.b	#80,d0		;P
	beq.s	pauseover
	cmp.b	#112,d0		;p
	beq.s	pauseover
	move.b	(a6)+,d7
	bmi.s	paused2
	addq.b	#1,d7
	cmp.b	d0,d7
	bne.s	paused
	bra	paused1
paused2:
	neg.w	cheatmode
pauseover:
	rts

cheatlist:
	dc.b	'h'-1,'o'-1,'n'-1,'e'-1,'y'-1,'b'-1,'u'-1,'n'-1,-1
even
dodrop:
	lea	scr,a6
	moveq	#0,d0		;zero result register
	moveq	#0,d1
	move.w	cspritex(a0),d0
	move.w	cspritey(a0),d1
	addq.w	#8,d0
	addq.w	#8,d1
	move.l	d0,d2
	and.w	#$fff0,d1
	move.l	d1,d3
	swap	d3
	clr.w	d3
	swap	d3
*	mulu	#640,d3
	lsl.l	#7,d3
	adda.l	d3,a6		;add to screen base address
	lsl.l	#2,d3
	adda.l	d3,a6		;add to screen base address
	asr.w	#1,d2		;divide it by 2
	and.w	#$fff8,d2	;turn off lower 3 bits
	adda.w	d2,a6		;add to screen address register
	move.l	a6,minead(a1)
	and.w	#$fff0,d0
	move.w	d0,minex2(a1)
	move.w	d1,miney2(a1)
	asr.w	#4,d0
	asr.w	#4,d1
	bsr	checkblock
	move.w	#1500,minelife(a1)
	move.w	d0,minex(a1)
	move.w	d1,miney(a1)
	mulu	#80,d1
	add.w	d0,d1
	lea	gamemap,a2
	lea	blocks,a3
	moveq	#0,d0
	move.b	(a2,d1.w),d0
	asl.w	#7,d0
	add.w	d0,a3
	move.l	a3,minerestore(a1)
	move.w	#1,mineact(a1)
	lea	minesp,a0
	move.w	mines,d0
	lea	minexylist,a1
*	asl.w	#1,d0
	add.w	d0,d0
	move.w	(a1,d0.w),(a0)
	bsr	putsprite
	subq.w	#1,mines
	move.b	#1,minedrop
	rts

checkblock:
	lea	mymine1,a0
	bsr	cb
	lea	mymine2,a0
	bsr	cb
	lea	mymine3,a0
	bsr	cb
	lea	mymine4,a0
	bsr	cb

	lea	enmine1,a0
	bsr	cb
	lea	enmine2,a0
	bsr	cb
	lea	enmine3,a0
	bsr	cb
	lea	enmine4,a0
	bsr	cb
	lea	enwep,a0
	bsr	cb
	lea	mywep,a0
	bsr	cb
	rts
cb:
	cmpi.w	#-1,mineact(a0)
	beq.s	noblockmatch
	cmp.w	minex(a0),d0
	bne.s	noblockmatch
	cmp.w	miney(a0),d1
	bne.s	noblockmatch
	addq.l	#8,sp		;remove 2 ret ad
noblockmatch:
	rts


doenemymine:
	lea	enemysp0,a0
doenemymine2:
	lea	enmine1,a1
	cmpi.w	#-1,mineact(a1)
	beq.s	dodrope
	lea	enmine2,a1
	cmpi.w	#-1,mineact(a1)
	beq.s	dodrope
	lea	enmine3,a1
	cmpi.w	#-1,mineact(a1)
	beq.s	dodrope
	lea	enmine4,a1
	cmpi.w	#-1,mineact(a1)
	beq.s	dodrope
	rts
dodrope:
	move.w	#1500,minelife(a1)
	lea	scr,a6
	moveq	#0,d0		;zero result register
	moveq	#0,d1
	move.w	cspritex(a0),d0
	move.w	cspritey(a0),d1
	addq.w	#8,d0
	addq.w	#8,d1
	move.l	d0,d2
	and.w	#$fff0,d1
	move.l	d1,d3
	swap	d3
	clr.w	d3
	swap	d3
*	mulu	#640,d3
	lsl.l	#7,d3
	adda.l	d3,a6		;add to screen base address
	lsl.l	#2,d3
	adda.l	d3,a6		;add to screen base address
	asr.w	#1,d2		;divide it by 2
	and.w	#$fff8,d2	;turn off lower 3 bits
	adda.w	d2,a6		;add to screen address register
	move.l	a6,minead(a1)
	and.w	#$fff0,d0
	move.w	d0,minex2(a1)
	move.w	d1,miney2(a1)
	asr.w	#4,d0
	asr.w	#4,d1
	bsr	checkblock
	move.w	d0,minex(a1)
	move.w	d1,miney(a1)
	mulu	#80,d1
	add.w	d0,d1
	lea	gamemap,a2
	lea	blocks,a3
	moveq	#0,d0
	move.b	(a2,d1.w),d0
	asl.w	#7,d0
	add.w	d0,a3
	move.l	a3,minerestore(a1)
	move.w	#1,mineact(a1)
	rts


doenemyspin:
	tst.w	cactive(a0)
	bmi	alrse
	tst.w	tankspine(a0)
	bpl.L	alrse
	move.l	cspritelistad(a0),a1
	move.l	cspritelocation(a0),a2
	move.b	1(a1),d0
	sub.b	1(a2),d0
	move.b	2(a1),d1
	sub.b	2(a2),d1
	move.b	3(a1),d2
	sub.b	3(a2),d2
	tst.b	d0
	bpl.s	t1
	neg.b	d0
t1:
	tst.b	d1
	bpl.s	t2
	neg.b	d1
t2:
	tst.b	d2
	bpl.s	t3
	neg.b	d2
t3:
	add.b	d1,d0
	add.b	d2,d0		;d0 is number of moves away
	cmpi.b	#2,d0
	bgt.s	plok1
	tst.w	tankplanee(a0)
	bmi.s	alrse		;close and already tank
	move.w	#2,cspritevels(a0)
	bra.s	setspine
plok1:
	tst.w	tankplanee(a0)
	bpl.s	alrse		;far away and already plane
	move.w	#6,cspritevels(a0)
setspine:
	neg.w	tankplanee(a0)
	move.w	#5*8,tankspine(a0)
	move.b	whichmee(a0),whichmestarte(a0)
	cmpi.b	#7,whichmee(a0)
	ble.s	whm2e
	move.b	#7,whichmehighe(a0)
whm2e:
	move.b	#15,whichmehighe(a0)
whm3e:
	move.l	cspritead(a0),tankimagee(a0)
	move.l	tankimagee(a0),d0
	sub.l	tankstarte(a0),d0
	move.l	d0,tankadde(a0)
	move.l	enshotlistp(a0),a1
	moveq	#3,d0
loopsce:
	move.l	(a1)+,a2
	tst.w	cactive(a2)
	bmi.s	loopsc2e
	move.w	#-1,cactive(a2)
loopsc2e:
	dbf	d0,loopsce
alrse:
	rts


minex:		equ	0
miney:		equ	2
mineact:	equ	4
minead:		equ	6
minerestore:	equ	10
minelife:	equ	14
minex2:		equ	16
miney2:		equ	18
mines:		dc.w	3	;mines avail
minexylist:
	dc.w	224,232,240,248
tankxylist:
	dc.w	288,296,304
mymine1:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2
mymine2:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2
mymine3:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2
mymine4:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2

enmine1:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2
enmine2:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2
enmine3:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2
enmine4:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2

enwep:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2
mywep:
	dc.w	0,0		;x,y in block coords
	dc.w	-1		;mineact
	dc.l	0		;address to put
	dc.l	0		;minerestore
	dc.w	0		;minelife
	dc.w	0,0		;x,y,2
***********************************
mydocolors:
	lea	bluepalette,a0
mydocolors3:
saver:
	move.l	#$ff8240,a1
	moveq	#15,d0
mdcloop2:
	move.w	(a0)+,(a1)+
	dbf	d0,mdcloop2
	rts
mydocolors2:
	lea	textpalette,a0
	bra.s	saver

************get screen address***************
getscrn:move.w  #2,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,screen
	subi.l	#32000+[10*512],d0
	move.l	d0,seen
	sub.l	#32000,d0
	move.l	d0,hiden
	rts
seen:	dc.l	0
hiden:	dc.l	0
screen:	dc.l	0

flip_scrmidi:
	tst.w	displaymap
	bpl	showmap
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
	move.b	seen+1,$ff8201
	move.b	seen+2,$ff8203
*	move.w	#$0222,$ff8240
	rts


flip_scr:
	tst.w	displaymap
	bpl	showmap
	move.l	seen,d1
	move.l	d1,d2
	add.l	#2000,d1
	add.l	#28000,d2
skloop:
	move.l	#$ff8205,a0
	moveq	#0,d0
	move.b	(a0),d0
	asl.l	#8,d0
	addq.l	#2,a0
	move.b	(a0),d0
	asl.l	#8,d0
	addq.l	#2,a0
	move.b	(a0),d0
	cmp.l	d1,d0
	blt.s	skloop
	cmp.l	d2,d0
	bgt.s	skloop
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
	move.b	seen+1,$ff8201
	move.b	seen+2,$ff8203
*	move.w	#$0222,$ff8240
	rts
showmap:
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
	move.b	screen+1,$ff8201
	move.b	screen+2,$ff8203
	rts

dltvbl:
	movem.l	d0-d7/a0-a6,-(sp)
	tst.w	novbl
	bpl	donodlt
	move.l	screen,a0
	move.l	a0,vbltemp
	move.b	vbltemp+1,$ff8201
	move.b	vbltemp+2,$ff8203
	bsr	dodlt
	bra.s	realend
donodlt:
	cmpi.w	#2,novbl
	bne	realend
	move.l	lacepal1,d0
	move.l	lacepal2,lacepal1
	move.l	d0,lacepal2
	move.l	lacepal1,a0
	bsr	mydocolors3
	move.l	specscreen1,d0
	move.l	specscreen2,specscreen1
	move.l	d0,specscreen2
	move.b	specscreen1+1,$ff8201
	move.b	specscreen1+2,$ff8203
realend:
	movem.l	(sp)+,d0-d7/a0-a6
tgooldvbl:
	jmp	$0

dodlt:
	move.l	dltmemcount,a0
	move.l	screen,a1
	move.w	(a0)+,d0
	beq	dltover
	subq.w	#1,d0
dodltloop:
	move.w	(a0)+,d1
	move.l	(a0)+,d2
	eor.l	d2,(a1,d1.w)
	dbf	d0,dodltloop
	move.l	a0,dltmemcount
nodlt:
	rts

dltover:
	move.l	dltsave,dltmemcount
	bra	dodlt

screenxlist:
	dc.w	80,96,304		;if between 0 and 240 then 0
	dc.w	288,304,512	;240,464,224
	dc.w	496,512,720
	dc.w	704,720,928
	dc.w	912,928,1136
currentscreenx:	dc.w	0

testcopy:
	move.w	screeny,d1
	move.w	mesp+cspritex,d2
	lea	screenxlist,a1
	moveq	#4,d7
tcl:
	move.w	(a1)+,d0
	cmp.w	(a1)+,d2
	bge.s	tcl1
	move.w	(a1)+,d3
	bra.s	tcls
tcl1:
	cmp.w	(a1)+,d2
	blt.s	tcl2
tcls:
	dbf	d7,tcl
tcl2:
	move.w	d0,currentscreenx
	lea	scr,a0
	swap	d1
	clr.w	d1
	swap	d1
*	mulu	#160*4,d1
	lsl.l	#7,d1
	adda.l	d1,a0		;correct y
	lsl.l	#2,d1
	adda.l	d1,a0		;correct y
	asr.w	#1,d0
	and.w	#$fff8,d0
	add.w	d0,a0
	moveq	#15,d7		;y's
	move.l	hiden,a1	;place to put
	lea	2896(a1),a1
normalcopy:
	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)+
	lea	8*4(a1),a1
	lea	[160*3]+[8*4](a0),a0
	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)+
	lea	8*4(a1),a1
	lea	[160*3]+[8*4](a0),a0
	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)+
	lea	8*4(a1),a1
	lea	[160*3]+[8*4](a0),a0
	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)+
	lea	8*4(a1),a1
	lea	[160*3]+[8*4](a0),a0
	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)+
	lea	8*4(a1),a1
	lea	[160*3]+[8*4](a0),a0
	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)+
	lea	8*4(a1),a1
	lea	[160*3]+[8*4](a0),a0
	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)+
	lea	8*4(a1),a1
	lea	[160*3]+[8*4](a0),a0
	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)+
	lea	8*4(a1),a1
	lea	[160*3]+[8*4](a0),a0
	dbf	d7,normalcopy
	rts

dsave:	dc.w	0
framevbl:
	movem.l	d0-d7/a0-a6,-(sp)
	move.w	#-1,setflag
	move.w	#$0000,$ff8240
	tst.w	novbl
	bpl	diskhappenning
	move.w	#$0004,$ff8240+4
	move.b	seen+1,$ff8201
	move.b	seen+2,$ff8203
	tst.w	displaymap
	bmi.s	here
	move.b	screen+1,$ff8201
	move.b	screen+2,$ff8203
	move.w	#$0003,$ff8240+4
here:
	tst.w	$43e
	bne.s	diskhappenning
	bsr	dosound
	move.l	colorwhere,a0
	move.w	(a0)+,$ff825e
	cmp.l	#colorend,a0
	ble.s	cvblok
	lea	colors,a0
cvblok:
	move.l	a0,colorwhere
diskhappenning:
	movem.l	(sp)+,d0-d7/a0-a6
gooldvbl:
	jmp	$0

colorwhere:	dc.l	colors
colors:
	dc.w	$0f00,$0611,$0522,$0433,$0344,$0255,$0166,$00ff
	dc.w	$0166,$0255,$0344,$0433,$0522
colorend:
	dc.w	$0611

drawsprites:			;first either restore or end restore
	lea	mymine1,a0
	bsr	handlemine
	lea	mymine2,a0
	bsr	handlemine
	lea	mymine3,a0
	bsr	handlemine
	lea	mymine4,a0
	bsr	handlemine

	lea	enmine1,a0
	bsr	handlemine2
	lea	enmine2,a0
	bsr	handlemine2
	lea	enmine3,a0
	bsr	handlemine2
	lea	enmine4,a0
	bsr	handlemine2
	lea	enwep,a0
	bsr	handlemine3
	lea	mywep,a0
	bsr	handlemine4
drawloop:
	lea	drawlist,a6
	move.w	(a6)+,d7		;number to draw
dspl3:
	move.l	(a6)+,a0	;if its here its active
	tst.w	cspritevisflag(a0)
	bmi.s	nod
	tst.w	cactive(a0)
	bmi.s	nod
	bsr	drawclipped
nod:	dbf	d7,dspl3
*	rts

	move.l	screen,a0
	move.l	hiden,a1
	lea	190*160(a1),a1
	moveq	#9,d0
bitl:
	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)+
	dbf	d0,bitl
	rts

handlemine4:
	lea	mywepons,a1
	bra.s	dom2
handlemine3:
	lea	enemywepons,a1
	bra.s	dom2
handlemine2:
	lea	enemymine,a1
	bra.s	dom2
handlemine:
	lea	mymine,a1
dom2:
	cmpi.w	#-1,mineact(a0)
	beq.L	domine2
	cmpi.w	#0,mineact(a0)
	beq	domine2		;no action necessary
	cmpi.w	#-2,mineact(a0)
	beq.L	restoremine
	move.w	#0,mineact(a0)
	move.l	minead(a0),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
domine2:
	rts

restoremine:
	move.w	#-1,mineact(a0)
	move.l	minerestore(a0),a1
	move.l	minead(a0),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	move.l	(a1)+,(a2)+
	move.l	(a1)+,(a2)+
	lea	640-8(a2),a2
	rts

alternate:	dc.w	-1
vbltemp:
	dc.l	0
*****************************************
*	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
even
******************************************
*               RETURN TO GEM
gem:
*	move.b	oldieb,ieb
*	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.l	oldvbl1,$70
*	bsr	restoremfp

	move.w  #34,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,a0
	move.l	oldmouse,16(a0)

	bsr	res_mouse
	move.b  #7,$484
	move.l	trappoke+2,$84


	move.w	#0,$ff820c
	move.b	#0,$ff820f
	move.b	#0,$ff8265
	move.b	screen+1,$ff8205
	move.b	screen+2,$ff8207
	move.b	screen+3,$ff8209

        move.w  ressave,-(sp)
        move.l  screen,-(sp)
        move.l  screen,-(sp)
        move.w  #5,-(sp)
        trap    #14
        addi.l  #12,sp

        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp

gem3:	move.l  savesup,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
gem2:
illegal
	clr.w	-(sp)
	trap	#1


rvsave:	dc.l	0
resave:	dc.l	0
palsave:	blk.w	16,0
***********************************
alertout:
	lea	alerttext1,a0
	bsr	doalert
	bra	gem3
doalert:
	move.w	#52,opcode
	move.w	#1,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#1,intin
	move.l	a0,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts

alerttext1:
	dc.b	'[3][This game only runs on a| |'
	dc.b	    '    1 MEG ATARI STE]'
	dc.b	'[SORRY]',0,0
*********************************************************
mygetpix:
	movem.l	d1-d3/a1,-(sp)
	lea	scr,a1
	moveq	#0,d0		;zero result register
	move.w	pixely,d3	;get Y coordinate
	swap	d3
	clr.w	d3
	swap	d3
*	mulu	#640,d3		;multiply by 160 (# of bytes per scan line)
	lsl.l	#7,d3
	adda.l	d3,a1		;add to screen base address
	lsl.l	#2,d3
	adda.l	d3,a1		;add to screen base address
	move.w	pixelx,d1	;get X coordinate
	move.w	d1,d2		;duplicate it in D2
	asr.w	#1,d1		;divide it by 2
	and.w	#$fff8,d1	;turn off lower 3 bits
	adda.w	d1,a1		;add to screen address register
	move.w	(a1),d3		;grab screen word
	and.l	#15,d2		;mask X to 0-15
	move.w	#$8000,d1	;set up bit mask
	lsr.w	d2,d1		;shift bit mask 0-15 bits
	and.w	d1,d3		;mask off bit 0
	beq.s	bit0b		;bit's off, go get next color bit
	move.w	#1,d0		;turn on bit 0 in result

bit0b:
	move.w	2(a1),d3		;get screen word for bit 1 of color
	and.w	d1,d3		;get bit 1
	beq.s	bit0c		;it's off, try bit 2
	or.w	#2,d0		;turn on bit 1 in result
bit0c:
	move.w	4(a1),d3		;get screen word for bit 2
	and.w	d1,d3		;get bit 2
	beq.s	bit0d		;it's off, try bit 3
	or.w	#4,d0		;turn on bit 2 in result
bit0d:
	move.w	6(a1),d3		;get word for bit 3
	and.w	d1,d3		;get bit 3
	beq.s	getx0		;it's off!
	or.w	#8,d0		;turn on bit 3 in result
getx0:
	movem.l	(sp)+,d1-d3/a1
	rts

*********************************************************
*       my routines for loading in the screens          *
*********************************************************
loadscr:move    #0,-(SP)        ;Open file
        move.l  filename,-(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
	move.l  wheretoload,-(SP)    ;load it straight onto screen
        move.l  #300000,-(SP)    	;length to read in
        move    D0,-(SP)        ;Handle
        move    #$3F,-(SP)      ;bios number
        trap    #1              ;Read file in
        addi.l   #12,SP

        move    #$3E,-(SP)      ;Handle already on stack
        trap    #1              ;Close file
        addq.l  #4,SP
	rts

mytrap:
	MOVE.L	A0,L2DDB0
	BTST	#5,(A7)
	BNE.S	L2DA36
	MOVE.L	USP,A0
	BRA.S	L2DA3A
L2DA36:	move.L	A7,A0
	ADDQ.L	#6,A0
L2DA3A:	CMPI.W	#$3F,(A0)
	BEQ.S	L2DAA8
	CMPI.W	#$42,(A0)
	BEQ.S	L2DA94
	CMPI.W	#$4E,(A0)
	BEQ.S	L2DA80
	CMPI.W	#$2F,(A0)
	BEQ.S	L2DA6C
	CMPI.W	#$1A,(A0)
	BNE.S	L2DAC0
	MOVE.L	2(A7),L2DAE2+2
	MOVE.L	#L2DAD8,2(A7)
	BRA	L2DAC0
L2DA6C:	MOVE.L	2(A7),L2DAD4+
	MOVE.L	#L2DACC,2(A7)
	BRA	L2DAC0
L2DA80:	MOVE.L	2(A7),L2DB58+2
	MOVE.L	#L2DAE6,2(A7)
	BRA	L2DAC0
L2DA94:	MOVE.L	2(A7),L2DC1E+2
	MOVE.L	#L2DB5E,2(A7)
	BRA	L2DAC0
L2DAA8:	MOVE.L	8(A0),L2DDBC
	MOVE.L	2(A7),L2DD7c+2
	MOVE.L	#L2DC22,2(A7)
L2DAC0:	move.L	L2DDB0,A0
trappoke:
	JMP	0
L2DACC:	MOVE.L	D0,L2DDEC
l2dad4:
	JMP	0
L2DAD8:	MOVE.L	2(A7),L2DDEC
l2dae2:	JMP	0
L2DAE6:	TST.L	D0
	BNE	L2DB58
	MOVE.L	D0,L2DDE4
	MOVE.L	A0,L2DDE8
	MOVE.L	2(A7),L2DDF0
	MOVE.W	#2,-(A7)
	MOVE.L	L2DDF0,-(A7)
	MOVE.W	#$3D,-(A7)
	TRAP	#1
	ADDQ.L	#8,A7
	MOVE.W	D0,L2DDE0
	MOVE.W	#2,-(A7)
	MOVE.W	D0,-(A7)
	MOVE.L	#0,-(A7)
	MOVE.W	#$42,-(A7)
	TRAP	#1
	ADDA.L	#$A,A7
	move.L	L2DDEC,A0
	ADDA.L	#$1A,A0
	MOVE.L	D0,(A0)
	MOVE.W	L2DDE0,-(A7)
	MOVE.W	#$3E,-(A7)
	TRAP	#1
	ADDQ.L	#4,A7
	MOVE.L	L2DDE4,D0
	move.L	L2DDE8,A0
L2DB58:	JMP	0
L2DB5E:	CMPI.W	#2,8(A7)
	BNE	L2DC14
	CMPI.L	#0,2(A7)
	BNE	L2DC14
	MOVE.W	6(A7),L2DDD2
	MOVE.L	D0,L2DDD4
	MOVE.L	A0,L2DDD8
	CMP.L	#$A,D0
	BLT	L2DC08
	MOVE.L	L2DC1E,L2DDDC
	MOVE.W	#2,-(A7)
	MOVE.W	L2DDD2,-(A7)
	MOVE.L	#$FFFFFFF8,-(A7)
	MOVE.W	#$42,-(A7)
	TRAP	#1
	ADDA.L	#$A,A7
	ADDQ.L	#8,D0
	MOVE.L	D0,L2DDF6
	MOVE.W	#1,L2DDD0
	MOVE.L	#L2DDA8,-(A7)
	MOVE.L	#8,-(A7)
	MOVE.W	L2DDD2,-(A7)
	MOVE.W	#$3F,-(A7)
	TRAP	#1
	ADDA.L	#$C,A7
	MOVE.L	L2DDDC,L2DC1E
	CMPI.L	#$5359534A,L2DDAC
	BNE	L2DC08
	MOVE.L	L2DDA8,D0
	BRA	L2DC0E
L2DC08:	MOVE.L	L2DDD4,D0
L2DC0E:	move.L	L2DDD8,A0
L2DC14:	MOVE.W	#0,L2DDD0
l2dc1e:	JMP	0
L2DC22:	TST.W	2(A7)
	BMI	L2DD7C
	MOVEM.L	D0-d7/A0-a6,-(A7)
	MOVE.L	D0,L2DDC8
	MOVE.L	D0,L2DDB4
	BTST	#0,D0
	BNE	L2DD6A
	CMPI.W	#1,L2DDD0
	BEQ	L2DD6A
	move.L	L2DDBC,A0
	ADDA.L	D0,A0
	MOVE.L	-(A0),D0
	CMP.L	#$5359534A,D0
	BEQ	L2DC66
	BRA	L2DD6A
L2DC66:	MOVE.L	-(A0),L2DDB4
	MOVE	SR,D1
	BTST	#$D,D1
	BNE	L2DC90
	CLR.L	-(A7)
	MOVE.W	#$20,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	LEA	L2DDC4,A6
	MOVE.L	D0,(A6)
	MOVE.W	#1,L2DDC0
L2DC90:
	MOVE.W	$FFF8240,L2DDCC
	SUBQ.L	#4,L2DDC8
	move.L	L2DDBC,A0
	ADDA.L	L2DDC8,A0
	move.L	L2DDBC,A1
	move.L	-(A0),A2
	ADDA.L	A1,A2
	MOVE.L	-(A0),D5
	MOVE.L	-(A0),D0
	EOR.L	D0,D5
L2DCBC:	LSR.L	#1,D0
	BNE.S	L2DCC4
	BSR	L2DD82
L2DCC4:	BCS.S	L2DD06
	MOVEQ	#8,D1
	MOVEQ	#1,D3
	LSR.L	#1,D0
	BNE.S	L2DCD2
	BSR	L2DD82
L2DCD2:	BCS.S	L2DD32
	MOVEQ	#3,D1
	CLR.W	D4
L2DCD8:	BSR	L2DD8E
	MOVE.W	D2,D3
	ADD.W	D4,D3
L2DCE0:	MOVEQ	#7,D1
L2DCE2:	LSR.L	#1,D0
	BNE.S	L2DCEA
	BSR	L2DD82
L2DCEA:	ROXL.L	#1,D2
	DBF	D1,L2DCE2
	MOVE.B	D2,-(A2)
*	MOVE.W	A2,$FFF8240
	DBF	D3,L2DCE0
	BRA	L2DD40
L2DD00:	MOVEQ	#8,D1
	MOVEQ	#8,D4
	BRA.S	L2DCD8
L2DD06:	MOVEQ	#2,D1
	BSR	L2DD8E
	CMP.B	#2,D2
	BLT.S	L2DD28
	CMP.B	#3,D2
	BEQ.S	L2DD00
	MOVEQ	#8,D1
	BSR	L2DD8E
	MOVE.W	D2,D3
	MOVE.W	#$C,D1
	BRA	L2DD32
L2DD28:	MOVE.W	#9,D1
	ADD.W	D2,D1
	ADDQ.W	#2,D2
	MOVE.W	D2,D3
L2DD32:	BSR	L2DD8E
L2DD36:	SUBQ.W	#1,A2
	MOVE.B	0(A2,D2.W),(A2)
	DBF	D3,L2DD36
L2DD40:	CMPA.L	A2,A1
	BLT	L2DCBC
*	MOVE.W	L2DDCC,$FFF8240
	CMPI.W	#1,L2DDC0
	BNE	L2DD6A
	MOVE.L	L2DDC4,-(A7)
	MOVE.W	#$20,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
L2DD6A:	MOVE.W	#0,L2DDC0
	MOVEM.L	(A7)+,D0-d7/A0-a6
	MOVE.L	L2DDB4,D0
L2DD7C:	JMP	0
L2DD82:	MOVE.L	-(A0),D0
	EOR.L	D0,D5
	MOVE.B	#$10,CCR
	ROXR.L	#1,D0
	RTS
L2DD8E:	SUBQ.W	#1,D1
	CLR.W	D2
L2DD92:	LSR.L	#1,D0
	BNE.S	L2DDA0
	MOVE.L	-(A0),D0
	EOR.L	D0,D5
	MOVE.B	#$10,CCR
	ROXR.L	#1,D0
L2DDA0:	ROXL.L	#1,D2
	DBF	D1,L2DD92
	RTS

L2DDA8:	DC.W	0,0,
l2ddac:	dc.w	0,0
L2DDB0:	DC.W	0,0,
l2ddb4:	dc.w	0,0
	DC.W	0,0
l2ddbc:	dc.w	0,0
L2DDC0:	DC.W	0,0,
l2ddc4:	dc.w	0,0
L2DDC8:	DC.W	0,0,
l2ddcc:	dc.w	0,0
L2DDD0:	DC.W	0,
l2ddd2:	dc.w	0,
l2ddd4:	dc.w	0,0
L2DDD8:	DC.W	0,0,
l2dddc:	dc.w	0,0
L2DDE0:	DC.W	0,0,
l2dde4:	dc.w	0,0
L2DDE8:	DC.W	0,0,
l2ddec:	dc.w	0,0
L2DDF0:	DC.W	0,0,0
l2ddf6:	dc.w	0
***************************************
safe:		dc.w	0

*****************************************
rnd:	blk.l	5,0
*******************************************************************
randomseed:	ADD.L	D0,D1
		MOVEM.L D0/D1,RND
LongRnd:	MOVEM.L D1-D3,-(SP)	
		MOVEM.L RND,D0/D1
		ANDI.B	#$0E,D0
		ORI.B	#$20,D0
		MOVE.L	D0,D2
		MOVE.L	D1,D3
		ADD.L	D2,D2
		ADDX.L	D3,D3
		ADD.L	D2,D0
		ADDX.L	D3,D1
		SWAP	D3
		SWAP	D2
		MOVE.W	D2,D3
		CLR.W	D2
		ADD.L	D2,D0
		ADDX.L	D3,D1
		MOVEM.L D0/D1,RND
		MOVE.L	D1,D0
		MOVEM.L (SP)+,D1-D3
		RTS
random: 	MOVE.w	D2,-(SP)
		MOVE.W	D0,D2
		BEQ.S	r1
		BSR.S	LongRnd
		CLR.W	D0
		SWAP	D0
		ext.l	d0
		DIVs	D2,D0
		CLR.W	D0
		SWAP	D0
r1:		MOVE.w	(SP)+,D2
		RTS

randomplus:	MOVE.w	D2,-(SP)
		MOVE.W	D0,D2
		BEQ.S	r2
		BSR.S	LongRnd
		CLR.W	D0
		SWAP	D0
		DIVu	D2,D0
		CLR.W	D0
		SWAP	D0
r2:		MOVE.w	(SP)+,D2
		RTS

*****************************************
prtnum: 
	movem.l	d0/d6/d7/a0/a5/a1/a2,-(sp)
        moveq  	#0,d7
        move.w  number,d7
        andi.l  #$ffff,d7
        lea	lineout,a5
	tst.w	d7
	bpl	dodec2
	neg.w	d7
dodec2:
	move.l  d7,d6
        divu    #10,d6
        move.w  d6,d7
        swap    d6
        move.b  d6,(a5)+
	subq.w	#1,d0
        tst.w  d7
        bne     dodec2
clearnums:
	lea	numbers,a3
	move.w	numwhere,d6
out2:
	cmpa.l  #lineout,a5
        beq     decback2
	moveq	#0,d7
        move.b  -(a5),d7
	mulu	#52,d7
	move.l	a3,a0
	add.w	d7,a0
	moveq	#12,d0
	move.l	screen,a2
	adda.w	d6,a2
oloop2:
	move.b	(a0)+,(a2)
	move.b	(a0)+,2(a2)
	move.b	(a0)+,4(a2)
	move.b	(a0)+,6(a2)
	lea	160(a2),a2
	dbf	d0,oloop2
	btst	#0,d6
	beq	oh2
	addq.w	#6,d6
oh2:	addq.w	#1,d6
	bra	out2
decback2:
	movem.l	(sp)+,d0/d6/d7/a0/a5/a1/a2
	rts


doclearnums:
	movem.l	d0/d6/d7/a0/a5/a1/a2,-(sp)
	move.w	#4001,numwhere
	lea	lineout,a5
	move.b	#10,(a5)+
	move.b	#10,(a5)+
	move.b	#10,(a5)+
	move.b	#10,(a5)+
	move.b	#10,(a5)+
	bra	clearnums

safe2:	dc.w	0
lineout:	blk.l	5
times:		dc.w	0
number:		dc.w	0
numwhere:	dc.w	0



setupgem:
	move.l	a7,a6
        move.l  savesup,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
	move.l	a6,a7
	move.l	#0,ap1resv
	move.l	#0,ap2resv
	move.l	#0,ap3resv
	move.l	#0,ap4resv
	move.w	#10,opcode
	move.w	#0,sintin
	move.w	#1,sintout
	move.w	#0,saddrin
	move.w	#0,saddrout
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	move.w	#77,opcode
	move.w	#0,sintin
	move.w	#5,sintout
	move.w	#0,saddrin
	move.w	#0,saddrout
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	move.w	intout,grhandle
	move.w	#100,opcode
	move.w	#0,contrl+2
	move.w	#11,contrl+6
	move.w	grhandle,contrl+12
	move.w	#1,intin
	move.w	#1,intin+2
	move.w	#1,intin+4
	move.w	#1,intin+6
	move.w	#1,intin+8
	move.w	#1,intin+10
	move.w	#1,intin+12
	move.w	#1,intin+14
	move.w	#1,intin+16
	move.w	#1,intin+18
	move.w	#1,intin+20
	move.l	#vdipb,d1
	move.w	#$73,d0
	trap	#2
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
*        move.l  D0,savesup
	rts
*********************************
*	call with color in d0	*
*********************************
setgemcolor:
	move.l  #0,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
	move.w	#22,contrl		;color
	move.w	#0,contrl+2
	move.w	#1,contrl+6
	move.w	grhandle,contrl+12
	move.w	#1,intin		;which color
	move.l	#vdipb,d1
	move.w	#$73,d0
	trap	#2
setgemeffects:
	move.w	#106,contrl		;effects
	move.w	#0,contrl+2
	move.w	#1,contrl+6
	move.w	grhandle,contrl+12
	move.w	#0,intin
	move.l	#vdipb,d1
	move.w	#$73,d0
	trap	#2
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
	rts

setwrtmode:
	move.l  #0,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
	move.w	#32,contrl		;write mode
	move.w	#0,contrl+2
	move.w	#1,contrl+6
	move.w	grhandle,contrl+12
	move.w	d7,intin
	move.l	#vdipb,d1
	move.w	#$73,d0
	trap	#2
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
	rts

setgemsize:
        move.l  #0,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
	move.w	#107,contrl
	move.w	#0,contrl+2
	move.w	#1,contrl+6
	move.w	grhandle,contrl+12
	move.w	#6,intin		;small chars
	move.l	#vdipb,d1
	move.w	#$73,d0
	trap	#2
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
	rts
	
*****************************************
*	output string using gem		*
*	call with a0 ad of string	*
*	null termn.			*
*	x,y in d0,d1			*
*****************************************
gemprint:
	move.w	#$0fff,$ff825e
	move.l	a0,a6
        move.l  #0,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
	move.l	a6,a0
	moveq	#0,d0
	move.b	(a0)+,d0
	move.w	d0,ptsin
	moveq	#0,d0
	move.b	(a0)+,d0
	move.w	d0,ptsin+2
	lea	intin,a1		;put text in and count
	moveq	#-1,d7
loop1:
	addq.w	#1,d7
	move.b	#0,(a1)+
	move.b	(a0)+,(a1)+
	bne.s	loop1
	move.w	#8,contrl	;text
	move.w	#1,contrl+2	;number of pairs of coords
	move.w	d7,contrl+6	;length of intin
	move.w	grhandle,contrl+12
	move.l	#vdipb,d1
	move.w	#$73,d0
	trap	#2
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
*        move.l  D0,savesup
	rts

cleartext:
	move.w	#1,d7
	bsr	setwrtmode
	lea	ct1,a0
	bsr	gemprint
	lea	ct2,a0
	bsr	gemprint
	lea	ct3,a0
	bsr	gemprint
	lea	ct4,a0
	bsr	gemprint
	lea	ct5,a0
	bsr	gemprint
	lea	ct6,a0
	bsr	gemprint
	lea	ct7,a0
	bsr	gemprint
	lea	ct8,a0
	bsr	gemprint
	move.w	#2,d7
	bsr	setwrtmode
	rts
ct1:
	dc.b	79,33,'                          ',0
ct2:
	dc.b	79,39,'                          ',0
ct3:
	dc.b	79,45,'                          ',0
ct4:
	dc.b	79,51,'                          ',0
ct5:
	dc.b	233,33,' ',0
ct6:
	dc.b	233,39,' ',0
ct7:
	dc.b	233,45,' ',0
ct8:
	dc.b	233,51,' ',0
even
aespb:
	dc.l	contrl,global,intin,intout,addrin,addrout
contrl:
opcode:	dc.w	10
sintin:	dc.w	0
sintout:dc.w	1
saddrin:dc.w	0
saddrout:dc.l	0
	blk.w	5,0

global:
apversion:	dc.w	0
apcount:	dc.w	0
apid:		dc.w	0
apprivate:	dc.l	0
apptree:	dc.l	0
ap1resv:	dc.l	0
ap2resv:	dc.l	0
ap3resv:	dc.l	0
ap4resv:	dc.l	0

intin:
	blk.w	128,0
ptsin:
	blk.w	128,0
intout:
	blk.w	128,0
ptsout:
	blk.w	128,0
addrin:
	blk.w	128,0
addrout:
	blk.w	128,0
vdipb:
	dc.l	contrl,intin,ptsin,intout,ptsout
grhandle:	dc.w	0
specscreen1:	dc.l	0
colortable1:	dc.l	0
specscreen2:	dc.l	0
colortable2:	dc.l	0
dltmemcount:	dc.l	0
dltsave:	dc.l	0
dotitle:
	move.w	#1,novbl
	move.l	#scr,d0
	add.l	#388368,d0
	move.l	d0,wheretoload
	move.l	#filedlt,filename
	jsr	loadscr
	move.l	wheretoload,d0
	move.l	d0,dltmemcount
	move.l	d0,dltsave
	move.l	screen,d0
	move.l	d0,wheretoload
	move.l	#fileload,filename
	jsr	loadscr
	lea	blackpal,a0
	bsr	mydocolors3
	move.l	$70,oldvbl1
	move.l	$70,tgooldvbl+2
	move.l	#dltvbl,$70
	move.w	#-1,novbl

	move.l	#filetitmus,filename	;load title music
	move.l	#scr,wheretoload
	jsr	loadscr

	lea	gamemap,a0
dtl1:
	move.l	a0,d0
	divu	#512,d0
	swap	d0
	tst.w	d0
	beq.s	dtl2
	addq.l	#2,a0
	bra	dtl1
dtl2:
	move.l	a0,specscreen1
	add.l	#32000,a0
dtl3:
	move.l	a0,d0
	divu	#512,d0
	swap	d0
	tst.w	d0
	beq.s	dtl4
	addq.l	#2,a0
	bra	dtl3
dtl4:
	move.l	a0,specscreen2
	add.l	#32000,a0
	move.l	#filetit1,filename
	move.l	specscreen1,wheretoload
	jsr	loadscr
	move.l	#filetit2,filename
	move.l	specscreen2,wheretoload
	jsr	loadscr
	bsr	altersound
	move.l	#lacep1,lacepal1
	move.l	#lacep2,lacepal2
	move.w	#2,novbl
	bsr	initialisedigi
	move.l	#scr,d0
	move.l	d0,-(sp)
	add.l	#284160/2,d0
	move.l	d0,-(sp)
	move.w	#1,-(sp)	;loop
	bsr	startsampsound
	add.l	#10,sp
laceloop:
laceloop2:
	move.w	#$ff,-(sp)
	move.w	#6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0		;wait for keypress
	beq	laceloop2
	move.w	#1,novbl
	bsr	stopsound
	bsr	oldmfp
	lea	blackpal,a0
	bsr	mydocolors3
	rts

altersound:
	lea	scr,a0
	move.l	a0,a1
	move.l	#[284160/2]-1,d7
asloop:
	moveq	#0,d0
	move.l	d0,d1
	move.b	(a0)+,d0
	add.b	#127,d0
	move.b	(a0)+,d1
	add.b	#127,d1
	add.w	d1,d0
	lsr.w	#1,d0
	move.b	d0,(a1)+
	subq.l	#1,d7
	bpl	asloop
	rts


***************************************
initialisedigi:
	BSR	SAVEMFP
	MOVE.W	#$2700,SR
	move.l	$114,old200
	move.l	#my200,$114
	LEA	INULL,A0
	BSR	SETINT
	MOVEQ	#1,D0		;freq=5k
	BSR	SETFREQ
	BSR	ENABMFP
	BSR	SETSND
	MOVE.W	mysr,SR	;ENABLE THE INTERRUPTS
	rts
my200:
	addq.l	#1,$4ba
	rte

*****************************************************************
startsampsound:
	move.w	4(sp),hr			;get the stuff off the stack
	move.l	#moff,-(sp)
	clr.w	-(sp)
	move.w	#25,-(sp)
	trap	#14
	addq.l	#8,sp
	move.l	10(sp),currentsad
	move.l	10(sp),soundstart
	move.l	6(sp),soundend
	bsr	setsnd
	lea	ireplay,a0
	bsr	setint
	rts
stopsound:
	move.l	#mon,-(sp)
	clr.w	-(sp)
	move.w	#25,-(sp)
	trap	#14
	addq.l	#8,sp
	lea	inull,a0
	bsr	setint
	rts


****************************************
*     THE NULL INTERRUPT ROUTINE       *
****************************************
inull:
	rte		;when not playing just return
****************************************
*       REPLAY FROM MEMORY             *
****************************************
IREPLAY:
	movem.l	d0/d3/d4/d5/d7/a0/a3/a4/a6,-(sp)
	move.w	#$2500,sr
	MOVEQ	#0,D7
	move.l	currentsad,a6	;current sample address
	MOVE.B	(A6)+,D7	;get the sample
	CMP.L	soundend,A6	;is it past the end
	BGT.S	haltorrepeat	;you betcha
	move.l	a6,currentsad
	bra.s	INTOUTP		;ELSE OUTPUT IT
haltorrepeat:
	tst.w	hr		;should it stop or repeat
	bmi.s	onceonly
	move.l	soundstart,currentsad
	movem.l	(sp)+,d0/d3/d4/d5/d7/a0/a3/a4/a6
	RTE
onceonly:
	lea	inull,a0
	bsr	setint
	movem.l	(sp)+,d0/d3/d4/d5/d7/a0/a3/a4/a6
	RTE

INTOUTP:
	lea	screg,a4
	MOVE.B	#7,(a4)		;SET UP CHANNEL MIXING & PORT 'A' I/O
	MOVE.B	#$FF,SCDATA
	lea	snd_out,a3
	AND.W	#$00FF,D7	;MASK OFF RUBBISH
	ADD.B	#$80,D7		;COMPLENT VALUE
	LSL.W	#3,D7		;DOUBLE LONG WORD OFFSET
	MOVE.L	0(A3,D7.W),d5	;GET DATA #1
	MOVE.W	4(A3,D7.W),D4	;GET DATA #2
	MOVEP.L	D5,0(A4)	;PLAY #1
	MOVEP.W	D4,0(A4)	;PLAY #2
	move.w	#$2000,sr
	movem.l	(sp)+,d0/d3/d4/d5/d7/a0/a3/a4/a6
	RTE

savemfp:
	move.w	sr,mysr
	MOVE.B	IERA,MFPMEM		;save all this shit for later
	MOVE.B	IERB,MFPMEM+1
	MOVE.B	IMRA,MFPMEM+2
	MOVE.B	IMRB,MFPMEM+3
	MOVE.B	TADR,MFPMEM+4
	MOVE.B	TACR,MFPMEM+5
	MOVE.B	VECTOR,MFPMEM+6
	rts
oldmfp:
	move.l	old200,$114
	MOVE.B	MFPMEM+6,VECTOR		;put back what we found
	MOVE.B	MFPMEM+5,TACR
	MOVE.B	MFPMEM+4,TADR
	MOVE.B	MFPMEM+3,IMRB
	MOVE.B	MFPMEM+2,IMRA
	MOVE.B	MFPMEM+1,IERB
	MOVE.B	MFPMEM,IERA
	move.w	mysr,sr
	RTS

setint:
	MOVE.W	SR,D0
	MOVE.W	#$2700,SR	;interrupts begone
	MOVE.L	A0,ISRVEC
	MOVE.W	D0,SR
	RTS
setfreq:
	MOVE.B	#0,TACR
	AND.W	#7,D0
	LEA	FREQTAB,A0
	LSL.W	#1,D0
	MOVE.W	0(A0,D0.W),D0
	MOVE.B	D0,TACR
	LSR.W	#8,D0
 	MOVE.B	D0,TADR
	RTS
enabmfp:
	bset	#5,IMRA
	bset	#5,IERA
	BCLR	#3,VECTOR
	RTS
setsnd:
	MOVE.B	#0,SCREG	;CHANNEL A
	MOVE.B	#0,SCDATA
	MOVE.B	#1,SCREG
	MOVE.B	#0,SCDATA

	MOVE.B	#2,SCREG	;CHANNEL B
	MOVE.B	#0,SCDATA
	MOVE.B	#3,SCREG
	MOVE.B	#0,SCDATA

	MOVE.B	#4,SCREG	;CHANNEL C
	MOVE.B	#0,SCDATA
	MOVE.B	#5,SCREG
	MOVE.B	#0,SCDATA

	MOVE.B	#7,SCREG	;SET UP CHANNEL MIXING & PORT 'A' I/O
	MOVE.B	#$FF,SCDATA

	MOVE.B	#8,SCREG	;SET ALL VOLUMES TO ZERO
	MOVE.B	#0,SCDATA
	MOVE.B	#9,SCREG
	MOVE.B	#0,SCDATA
	MOVE.B	#10,SCREG
	MOVE.B	#0,SCDATA
	RTS



filedlt:	dc.b	'loading.dl2',0
fileload:	dc.b	'load.d2',0
filetitmus:	dc.b	'atmos.img',0
filetit1:	dc.b	'stlace1.img',0
filetit2:	dc.b	'stlace2.img',0
filefb:		dc.b	'game3.dat',0
fileme:		dc.b	'mep2.img',0
fileshots:	dc.b	'shot2.img',0
filemetank:	dc.b	'met2.img',0
fileenemy:	dc.b	'ep2.img',0
fileenemytank:	dc.b	'et2.img',0
filesounds:	dc.b	'sounds.img',0
filemap:	dc.b	'midimap.img',0
filemap1:	dc.b	'game1.map',0
fileintel:	dc.b	'intel1.img',0
filemain:	dc.b	'main.d2',0
even
savesup:	dc.l	0
ressave:	dc.w	0
filename:	dc.l	0
lacepal1:	dc.l	lacep1
lacepal2:	dc.l	lacep2
lacep2:
	dc.w	$0000,$0600,$0325,$0446,$0007,$0203,$0122,$0567
	dc.w	$0300,$0407,$0422,$0140,$0443,$0060,$0073,$0176
lacep1:
	dc.w	$0000,$0600,$0214,$0446,$0007,$0567,$0300,$0407
	dc.w	$0321,$0234,$0140,$0021,$0543,$0060,$0073,$0176

bluepalette:
	dc.w	$0000,$0005,$0004,$0fff,$0445,$0223,$0112,$0310
	dc.w	$0420,$0541,$0f62,$00f0,$0030,$0f00,$0300,$0707
blackpal:
	dc.w	$0000,$000f
blackpal2:
	blk.w	16,0
textpalette:
	dc.w	$0000,$0005,$0004,$0fff,$0445,$0223,$0112,$0310
	dc.w	$0420,$0541,$0f62,$00f0,$0030,$0f00,$0300,$0fff
gtemp:	blk.w	100,0
gsave:	blk.w	100,0
gmask:	blk.w	100,0

gamemap:
	blk.b	4000,0
mesprites:
	blk.b	40960,0
metanksprites:
	blk.b	40960,0
enemysprites:
	blk.b	40960,0
enemytanksprites:
	blk.b	40960,0
shotsprites:
	blk.b	2560,0

screenx:	dc.w	0
screeny:	dc.w	0
blocks:
	blk.b	6400,0
xvel:	dc.w	0
yvel:	dc.w	0
pixelx:	dc.w	0
pixely:	dc.w	0
wheretoload:	dc.l	0
shotxvel:	dc.w	0
shotyvel:	dc.w	0
mehits:		dc.w	0
tanks:		dc.w	0
shotsbar:
	 dc.w	$FFFF,$0000,$FFFF,$FFFF,$0000,$FFFF,$0000,$FFFF
	 dc.w	$03FF,$FFFF,$0000,$FFFF,$FFFF,$FFFF,$0000,$FFFF
	 dc.w	$FFFF,$0000,$FFFF,$FFFF,$0000,$FFFF,$0000,$FFFF
	 dc.w	$03FF,$FFFF,$0000,$FFFF,$FFFF,$FFFF,$0000,$FFFF
	 dc.w	$FFFF,$0000,$FFFF,$FFFF,$0000,$FFFF,$0000,$FFFF
	 dc.w	$03FF,$FFFF,$0000,$FFFF,$FFFF,$FFFF,$0000,$FFFF
	 dc.w	$FFFF,$0000,$FFFF,$FFFF,$0000,$FFFF,$0000,$FFFF
	 dc.w	$03FF,$FFFF,$0000,$FFFF,$FFFF,$FFFF,$0000,$FFFF
damagebar:
	dc.w	$FFF0,$000F,$FFF0,$FFFF,$0007,$FFFF,$0000,$FFFF
	dc.w	$FFFF,$FFFF,$0000,$FFFF,$FFF0,$000F,$FFF0,$FFFF
	dc.w	$0007,$FFFF,$0000,$FFFF,$FFFF,$FFFF,$0000,$FFFF
	dc.w	$FFF0,$000F,$FFF0,$FFFF,$0007,$FFFF,$0000,$FFFF
	dc.w	$FFFF,$FFFF,$0000,$FFFF,$FFF0,$000F,$FFF0,$FFFF
	dc.w	$0007,$FFFF,$0000,$FFFF,$FFFF,$FFFF,$0000,$FFFF
mineimg:
	 dc.w	$7800,$0400,$0000,$FC00,$8400,$8800,$B000,$7C00
	 dc.w	$D400,$C000,$8800,$7C00,$E400,$E000,$A800,$5C00
	 dc.w	$F400,$F000,$C000,$3C00,$F800,$F800,$F800,$0400
tankimg:
	 dc.w	$7000,$6000,$4000,$3000,$E800,$B000,$8000,$7800
	 dc.w	$E800,$B000,$8000,$7800,$F800,$A000,$8000,$7800
	 dc.w	$7000,$7000,$5000,$2000
shots:	dc.w	64	;number of shots

mymine:
	 dc.w	$7FFE,$0001,$0000,$FFFF,$BFFD,$8002,$8000,$7FFF
	 dc.w	$D00B,$C004,$CFF0,$3FFF,$E817,$E008,$E7E0,$1FFF
	 dc.w	$F7EB,$F010,$D004,$2FFF,$F833,$F800,$CBCC,$37FF
	 dc.w	$F813,$F840,$CFAC,$37FF,$FA13,$FA00,$CDEC,$37FF
	 dc.w	$FA13,$FA00,$CDEC,$37FF,$F993,$F980,$CE6C,$37FF
	 dc.w	$FC13,$FC00,$CFCC,$33FF,$FFEB,$FFE0,$DFE4,$201F
	 dc.w	$FFF7,$FFF0,$F810,$07EF,$FFFB,$FFF8,$F008,$0FF7
	 dc.w	$FFFD,$FFFC,$FFFC,$0003,$FFFE,$FFFE,$FFFE,$0001
enemymine:
	 dc.w	$7FFE,$0001,$0000,$FFFF,$BFFD,$8002,$8000,$7FFF
	 dc.w	$D00B,$CFF4,$CFF0,$3FFF,$E817,$E7E8,$E7E0,$1FFF
	 dc.w	$F7EB,$D014,$F004,$2FFF,$F833,$CBCC,$FBCC,$37FF
	 dc.w	$F813,$CFEC,$FFAC,$37FF,$FA13,$CDEC,$FFEC,$37FF
	 dc.w	$FA13,$CDEC,$FFEC,$37FF,$F993,$CE6C,$FFEC,$37FF
	 dc.w	$FC13,$CFCC,$FFCC,$33FF,$FFEB,$DFE4,$FFE4,$201F
	 dc.w	$FFF7,$F810,$FFF0,$07EF,$FFFB,$F008,$FFF8,$0FF7
	 dc.w	$FFFD,$FFFC,$FFFC,$0003,$FFFE,$FFFE,$FFFE,$0001
mywepons:
	 dc.w	$7FFE,$0001,$0000,$FFFF,$BFFD,$8002,$8000,$7FFF
	 dc.w	$C003,$C000,$FFFC,$3FFF,$C003,$C000,$FFFC,$3FFF
	 dc.w	$CC33,$CC30,$F3CC,$3FFF,$C813,$C810,$F7EC,$3FFF
	 dc.w	$C813,$C810,$F7EC,$3FFF,$C813,$C810,$F7EC,$3FFF
	 dc.w	$C993,$C990,$F66C,$3FFF,$CBD3,$CBD0,$F42C,$3FFF
	 dc.w	$CE73,$CE70,$F18C,$3FFF,$CC33,$CC30,$F3CC,$3FFF
	 dc.w	$C003,$C000,$FFFC,$3FFF,$C003,$C000,$FFFC,$3FFF
	 dc.w	$FFFD,$FFFC,$FFFC,$0003,$FFFE,$FFFE,$FFFE,$0001
enemywepons:
	 dc.w	$7FFE,$0001,$0000,$FFFF,$BFFD,$8002,$8000,$7FFF
	 dc.w	$C003,$FFFC,$FFFC,$3FFF,$C003,$FFFC,$FFFC,$3FFF
	 dc.w	$CC33,$F3CC,$FFFC,$3FFF,$C813,$F7EC,$FFFC,$3FFF
	 dc.w	$C813,$F7EC,$FFFC,$3FFF,$C813,$F7EC,$FFFC,$3FFF
	 dc.w	$C993,$F66C,$FFFC,$3FFF,$CBD3,$F42C,$FFFC,$3FFF
	 dc.w	$CE73,$F18C,$FFFC,$3FFF,$CC33,$F3CC,$FFFC,$3FFF
	 dc.w	$C003,$FFFC,$FFFC,$3FFF,$C003,$FFFC,$FFFC,$3FFF
	 dc.w	$FFFD,$FFFC,$FFFC,$0003,$FFFE,$FFFE,$FFFE,$0001
myprt:
	rts

numbers:
	 dc.b	$78,$00,$FF,$78,$B4,$00,$FF,$B4
	 dc.b	$CC,$00,$FF,$CC,$CC,$00,$FF,$CC
	 dc.b	$CC,$00,$FF,$CC,$84,$30,$FF,$B4
	 dc.b	$00,$78,$FF,$78,$84,$30,$FF,$B4
	 dc.b	$CC,$00,$FF,$CC,$CC,$00,$FF,$CC
	 dc.b	$CC,$00,$FF,$CC,$B4,$00,$FF,$B4
	 dc.b	$78,$00,$FF,$78,$00,$78,$FF,$78
	 dc.b	$04,$B0,$FF,$B4,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$04,$B0,$FF,$B4,$00,$78,$FF,$78
	 dc.b	$04,$B0,$FF,$B4,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$04,$B0,$FF,$B4,$00,$78,$FF,$78
	 dc.b	$78,$00,$FF,$78,$34,$80,$FF,$B4
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$34,$80,$FF,$B4
	 dc.b	$78,$00,$FF,$78,$B0,$04,$FF,$B4
	 dc.b	$C0,$0C,$FF,$CC,$C0,$0C,$FF,$CC
	 dc.b	$C0,$0C,$FF,$CC,$B0,$04,$FF,$B4
	 dc.b	$78,$00,$FF,$78,$78,$00,$FF,$78
	 dc.b	$34,$80,$FF,$B4,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$34,$80,$FF,$B4,$78,$00,$FF,$78
	 dc.b	$34,$80,$FF,$B4,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$34,$80,$FF,$B4,$78,$00,$FF,$78
	 dc.b	$00,$78,$FF,$78,$84,$30,$FF,$B4
	 dc.b	$CC,$00,$FF,$CC,$CC,$00,$FF,$CC
	 dc.b	$CC,$00,$FF,$CC,$B4,$00,$FF,$B4
	 dc.b	$78,$00,$FF,$78,$34,$80,$FF,$B4
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$04,$B0,$FF,$B4
	 dc.b	$00,$78,$FF,$78,$78,$00,$FF,$78
	 dc.b	$B0,$04,$FF,$B4,$C0,$0C,$FF,$CC
	 dc.b	$C0,$0C,$FF,$CC,$C0,$0C,$FF,$CC
	 dc.b	$B0,$04,$FF,$B4,$78,$00,$FF,$78
	 dc.b	$34,$80,$FF,$B4,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$34,$80,$FF,$B4,$78,$00,$FF,$78
	 dc.b	$78,$00,$FF,$78,$B0,$04,$FF,$B4
	 dc.b	$C0,$0C,$FF,$CC,$C0,$0C,$FF,$CC
	 dc.b	$C0,$0C,$FF,$CC,$B0,$04,$FF,$B4
	 dc.b	$78,$00,$FF,$78,$B4,$00,$FF,$B4
	 dc.b	$CC,$00,$FF,$CC,$CC,$00,$FF,$CC
	 dc.b	$CC,$00,$FF,$CC,$B4,$00,$FF,$B4
	 dc.b	$78,$00,$FF,$78,$78,$00,$FF,$78
	 dc.b	$34,$80,$FF,$B4,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$04,$B0,$FF,$B4,$00,$78,$FF,$78
	 dc.b	$04,$B0,$FF,$B4,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$04,$B0,$FF,$B4,$00,$78,$FF,$78
	 dc.b	$78,$00,$FF,$78,$B4,$00,$FF,$B4
	 dc.b	$CC,$00,$FF,$CC,$CC,$00,$FF,$CC
	 dc.b	$CC,$00,$FF,$CC,$B4,$00,$FF,$B4
	 dc.b	$78,$00,$FF,$78,$B4,$00,$FF,$B4
	 dc.b	$CC,$00,$FF,$CC,$CC,$00,$FF,$CC
	 dc.b	$CC,$00,$FF,$CC,$B4,$00,$FF,$B4
	 dc.b	$78,$00,$FF,$78,$78,$00,$FF,$78
	 dc.b	$B4,$00,$FF,$B4,$CC,$00,$FF,$CC
	 dc.b	$CC,$00,$FF,$CC,$CC,$00,$FF,$CC
	 dc.b	$B4,$00,$FF,$B4,$78,$00,$FF,$78
	 dc.b	$34,$80,$FF,$B4,$0C,$C0,$FF,$CC
	 dc.b	$0C,$C0,$FF,$CC,$0C,$C0,$FF,$CC
	 dc.b	$34,$80,$FF,$B4,$78,$00,$FF,$78
	 dc.b	$00,$78,$FF,$78,$00,$B4,$FF,$B4
	 dc.b	$00,$CC,$FF,$CC,$00,$CC,$FF,$CC
	 dc.b	$00,$CC,$FF,$CC,$00,$B4,$FF,$B4
	 dc.b	$00,$78,$FF,$78,$00,$B4,$FF,$B4
	 dc.b	$00,$CC,$FF,$CC,$00,$CC,$FF,$CC
	 dc.b	$00,$CC,$FF,$CC,$00,$B4,$FF,$B4
	 dc.b	$00,$78,$FF,$78
mymixer:	dc.b	0
even
spinupsound:
	dc.w	$000B,$FFF1,$0038,$FFFF,$FFFF,
	dc.w	$0000,$0000,$0002,$0054,$0001,
	dc.w	$0001,$0000,$000A,$0000,$0004,
	dc.w	$0009,$0002,$0003,$0012,$0001,
spindownsound:
	dc.w	$000B,$FFF1,$0034,$FFFF,$FFFF,
	dc.w	$0000,$0000,$0002,$0057,$0001,
	dc.w	$0001,$0000,$000A,$0000,$0004,
	dc.w	$0009,$0002,$0003,$0012,$0001,
meshootsound:
	dc.w	$000E,$0001,$001F,$0002,$0002,
	dc.w	$0080,$0001,$0002,$008E,$0001,
	dc.w	$0001,$0000,$000A,$0000,$0004,
	dc.w	$0009,$0002,$0003,$0012,$0001,
bigboomsound:
	dc.w	$000E,$0001,$007E,$000E,$000E,
	dc.w	$00C0,$0000,$0005,$000D,$0001,
	dc.w	$0002,$0090,$000C,$0000,$0005,
	dc.w	$000A,$0004,$0005,$0024,$0002,
tankmovesound:
	dc.w	$000A,$FFF1,$0000,$FFFF,$FFFF,
	dc.w	$0000,$0008,$0005,$000C,$0000,
	dc.w	$0002,$0000,$000C,$0000,$0005,
	dc.w	$000A,$0004,$0005,$0024,$0002,
getwepsound:
	dc.w	$000E,$0001,$003F,$0005,$0005,
	dc.w	$0039,$0000,$0002,$0040,$0050,
	dc.w	$0001,$0000,$000A,$0000,$0004,
	dc.w	$0009,$0002,$0003,$0012,$0001,
enemyshootsound:
	dc.w	$000E,$0001,$001F,$0001,$0001,
	dc.w	$0008,$0001,$0000,$0025,$0001,
	dc.w	$0000,$0000,$000A,$0000,$0003,
	dc.w	$0008,$0000,$0001,$0009,$0000,
hitwallsound:
	dc.w	$000E,$0001,$0017,$0002,$0002,
	dc.w	$0000,$0000,$0001,$0004,$0001,
	dc.w	$0000,$0000,$000C,$0000,$0003,
	dc.w	$0008,$0000,$0001,$0009,$0000,

SND_OUT:
	DC.W	$80C,$90B,$A09,0,$80C,$90B,$A09,0
	DC.W	$80D,$908,$A08,0,$80B,$90B,$A0B,0
	DC.W	$80D,$909,$A05,0,$80C,$90B,$A08,0
	DC.W	$80D,$909,$A02,0,$80D,$908,$A06,0
	DC.W	$80C,$90B,$A07,0,$80D,$907,$A07,0
	DC.W	$80C,$90B,$A06,0,$80C,$90A,$A09,0
	DC.W	$80B,$90B,$A0A,0,$80C,$90B,$A02,0
	DC.W	$80C,$90B,$A00,0,$80C,$90A,$A08,0

	DC.W	$80D,$906,$A04,0,$80D,$905,$A05,0
	DC.W	$80D,$905,$A04,0,$80C,$909,$A09,0
	DC.W	$80D,$904,$A03,0,$80B,$90B,$A09,0
	DC.W	$80C,$90A,$A05,0,$80B,$90A,$A0A,0
	DC.W	$80C,$909,$A08,0,$80B,$90B,$A08,0
	DC.W	$80C,$90A,$A00,0,$80C,$90A,$A00,0
	DC.W	$80C,$909,$A07,0,$80B,$90B,$A07,0
	DC.W	$80C,$909,$A06,0,$80B,$90B,$A06,0

	DC.W	$80B,$90A,$A09,0,$80B,$90B,$A05,0
	DC.W	$80A,$90A,$A0A,0,$80B,$90B,$A02,0
	DC.W	$80B,$90A,$A08,0,$80C,$907,$A07,0
	DC.W	$80C,$908,$A04,0,$80C,$907,$A06,0
	DC.W	$80B,$909,$A09,0,$80C,$906,$A06,0
	DC.W	$80A,$90A,$A09,0,$80C,$907,$A03,0
	DC.W	$80B,$90A,$A05,0,$80B,$909,$A08,0
	DC.W	$80B,$90A,$A03,0,$80A,$90A,$A08,0

	DC.W	$80B,$90A,$A00,0,$80B,$909,$A07,0
	DC.W	$80B,$908,$A08,0,$80A,$90A,$A07,0
	DC.W	$80A,$909,$A09,0,$80C,$901,$A01,0
	DC.W	$80A,$90A,$A06,0,$80B,$908,$A07,0
	DC.W	$80A,$90A,$A05,0,$80A,$909,$A08,0
	DC.W	$80A,$90A,$A02,0,$80A,$90A,$A01,0
	DC.W	$80A,$90A,$A00,0,$809,$909,$A09,0
	DC.W	$80A,$908,$A08,0,$80B,$908,$A01,0

	DC.W	$80A,$909,$A06,0,$80B,$907,$A04,0
	DC.W	$80A,$909,$A05,0,$809,$909,$A08,0
	DC.W	$80A,$909,$A03,0,$80A,$908,$A06,0
	DC.W	$80A,$909,$A00,0,$809,$909,$A07,0
	DC.W	$809,$908,$A08,0,$80A,$908,$A04,0
	DC.W	$809,$909,$A06,0,$80A,$908,$A01,0
	DC.W	$809,$909,$A05,0,$809,$908,$A07,0
	DC.W	$808,$908,$A08,0,$809,$909,$A02,0

	DC.W	$809,$908,$A06,0,$809,$909,$A00,0
	DC.W	$809,$907,$A07,0,$808,$908,$A07,0
	DC.W	$809,$907,$A06,0,$809,$908,$A02,0
	DC.W	$808,$908,$A06,0,$809,$906,$A06,0
	DC.W	$808,$907,$A07,0,$808,$908,$A04,0
	DC.W	$808,$907,$A06,0,$808,$908,$A02,0
	DC.W	$807,$907,$A07,0,$808,$906,$A06,0
	DC.W	$808,$907,$A04,0,$807,$907,$A06,0

	DC.W	$808,$906,$A05,0,$808,$906,$A04,0
	DC.W	$807,$906,$A06,0,$807,$907,$A04,0
	DC.W	$808,$905,$A04,0,$806,$906,$A06,0
	DC.W	$807,$906,$A04,0,$807,$905,$A05,0
	DC.W	$806,$906,$A05,0,$806,$906,$A04,0
	DC.W	$806,$905,$A05,0,$806,$906,$A02,0
	DC.W	$806,$905,$A04,0,$805,$905,$A05,0
	DC.W	$806,$905,$A02,0,$805,$905,$A04,0

	DC.W	$805,$904,$A04,0,$805,$905,$A02,0
	DC.W	$804,$904,$A04,0,$804,$904,$A03,0
	DC.W	$804,$904,$A02,0,$804,$903,$A03,0
	DC.W	$803,$903,$A03,0,$803,$903,$A02,0
	DC.W	$803,$902,$A02,0,$802,$902,$A02,0
	DC.W	$802,$902,$A01,0,$801,$901,$A01,0
	DC.W	$802,$901,$A00,0,$801,$901,$A00,0
	DC.W	$801,$900,$A00,0,$800,$900,$A00,0

	DC.W	$80E,$90D,$A0C,0,$80F,$903,$A00,0
	DC.W	$80F,$903,$A00,0,$80F,$903,$A00,0
	DC.W	$80F,$903,$A00,0,$80F,$903,$A00,0
	DC.W	$80F,$903,$A00,0,$80E,$90D,$A0B,0
	DC.W	$80E,$90D,$A0B,0,$80E,$90D,$A0B,0
	DC.W	$80E,$90D,$A0B,0,$80E,$90D,$A0B,0
	DC.W	$80E,$90D,$A0B,0,$80E,$90D,$A0B,0
	DC.W	$80E,$90D,$A0A,0,$80E,$90D,$A0A,0

	DC.W	$80E,$90D,$A0A,0,$80E,$90D,$A0A,0
	DC.W	$80E,$90C,$A0C,0,$80E,$90D,$A00,0
	DC.W	$80D,$90D,$A0D,0,$80D,$90D,$A0D,0
	DC.W	$80D,$90D,$A0D,0,$80D,$90D,$A0D,0
	DC.W	$80D,$90D,$A0D,0,$80D,$90D,$A0D,0
	DC.W	$80E,$90C,$A0B,0,$80E,$90C,$A0B,0
	DC.W	$80E,$90C,$A0B,0,$80E,$90C,$A0B,0
	DC.W	$80E,$90C,$A0B,0,$80E,$90C,$A0B,0

	DC.W	$80E,$90C,$A0B,0,$80E,$90C,$A0B,0
	DC.W	$80E,$90C,$A0A,0,$80E,$90C,$A0A,0
	DC.W	$80E,$90C,$A0A,0,$80E,$90C,$A0A,0
	DC.W	$80D,$90D,$A0C,0,$80D,$90D,$A0C,0
	DC.W	$80E,$90C,$A09,0,$80E,$90C,$A09,0
	DC.W	$80E,$90C,$A05,0,$80E,$90C,$A00,0
	DC.W	$80E,$90C,$A00,0,$80E,$90B,$A0B,0
	DC.W	$80E,$90B,$A0B,0,$80E,$90B,$A0B,0

	DC.W	$80E,$90B,$A0B,0,$80E,$90B,$A0A,0
	DC.W	$80E,$90B,$A0A,0,$80E,$90B,$A0A,0
	DC.W	$80D,$90D,$A0B,0,$80D,$90D,$A0B,0
	DC.W	$80D,$90D,$A0B,0,$80E,$90B,$A09,0
	DC.W	$80E,$90B,$A09,0,$80E,$90B,$A09,0
	DC.W	$80D,$90C,$A0C,0,$80D,$90D,$A0A,0
	DC.W	$80E,$90B,$A07,0,$80E,$90B,$A00,0
	DC.W	$80E,$90B,$A00,0,$80D,$90D,$A09,0

	DC.W	$80D,$90D,$A09,0,$80E,$90A,$A09,0
	DC.W	$80D,$90D,$A08,0,$80D,$90D,$A07,0
	DC.W	$80D,$90D,$A04,0,$80D,$90D,$A00,0
	DC.W	$80E,$90A,$A04,0,$80E,$909,$A09,0
	DC.W	$80E,$909,$A09,0,$80D,$90C,$A0B,0
	DC.W	$80E,$909,$A08,0,$80E,$909,$A08,0
	DC.W	$80E,$909,$A07,0,$80E,$908,$A08,0
	DC.W	$80E,$909,$A01,0,$80C,$90C,$A0C,0

	DC.W	$80D,$90C,$A0A,0,$80E,$908,$A06,0
	DC.W	$80E,$907,$A07,0,$80E,$908,$A00,0
	DC.W	$80E,$907,$A05,0,$80E,$906,$A06,0
	DC.W	$80D,$90C,$A09,0,$80E,$905,$A05,0
	DC.W	$80E,$904,$A04,0,$80D,$90C,$A08,0
	DC.W	$80D,$90B,$A0B,0,$80E,$900,$A00,0
	DC.W	$80D,$90C,$A06,0,$80D,$90C,$A05,0
	DC.W	$80D,$90C,$A02,0,$80C,$90C,$A0B,0

	DC.W	$80C,$90C,$A0B,0,$80D,$90B,$A0A,0
	DC.W	$80D,$90B,$A0A,0,$80D,$90B,$A0A,0
	DC.W	$80D,$90B,$A0A,0,$80C,$90C,$A0A,0
	DC.W	$80C,$90C,$A0A,0,$80C,$90C,$A0A,0
	DC.W	$80D,$90B,$A09,0,$80D,$90B,$A09,0
	DC.W	$80D,$90A,$A0A,0,$80D,$90A,$A0A,0
	DC.W	$80D,$90A,$A0A,0,$80C,$90C,$A09,0
	DC.W	$80C,$90C,$A09,0,$80C,$90C,$A09,0

	DC.W	$80D,$90B,$A06,0,$80C,$90B,$A0B,0
	DC.W	$80C,$90C,$A08,0,$80D,$90B,$A00,0
	DC.W	$80D,$90B,$A00,0,$80C,$90C,$A07,0
	DC.W	$80C,$90C,$A06,0,$80C,$90C,$A05,0
	DC.W	$80C,$90C,$A03,0,$80C,$90C,$A01,0
	DC.W	$80C,$90B,$A0A,0,$80D,$90A,$A05,0
	DC.W	$80D,$90A,$A04,0,$80D,$90A,$A02,0
	DC.W	$80D,$909,$A08,0,$80D,$909,$A08,0

**************************************
*       MFP/FREQUENCY TABLE          *
**************************************
	EVEN
FREQTAB:
	DC.W	$0506	;4.9 KHZ
	DC.W	$0406	;7.68 KHZ
	DC.W	$0405	;9.6 KHZ
	DC.W	$2901	;14.99 KHZ
	DC.W	$1F01	;19.8 KHZ
	DC.W	$0802	;30.7 KHZ
	DC.W	$0106	;DUMMY	
	DC.W	$0106	;DUMMY

**************************************
*	DEFINE PROGRAM STORAGE       *
**************************************
MFPMEM:	
	dc.l	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
old200:	dc.l	0

mon:	dc.b	$08
moff:	dc.b	$12

hr:		dc.w	-1	;once only
currentsad:	blk.l	1,0
soundend:	blk.l	1,0
soundstart:	blk.l	1,0
mysr:
	dc.w	0

enemydead:
	dc.w	0
cheatmode:
	dc.w	-1
channel0params:	blk.w	20,0
channel1params:	blk.w	20,0
channel2params:	blk.w	20,0

list:	blk.b	2024,-1

scr:
*	blk.b	512000,0	;as we are given all memory this should
				;be sufficient
