TITLE WAR 44
RELOCATABLE
P"=1
A"=2
B=3
C=4
D=5
T=6
TT=7
MP1=10
MP2=11
XFLAG=13
Q=14

DISCHN==7
FLGCHN==6
APRCHN==5

ZZZ=.
LOC APRCHN*2+40
	JSR APRBRK
LOC FLGCHN*2+40
	JSR RECYC
LOC DISCHN*2+40
	BLKO DIS,DISPNR'
	JSR BKWRAP
LOC 41
	JSR 60
LOC 61
	JRST 4,34000
LOC ZZZ

IF1 DPP=0
IF2 DPP=SDISTB
NSHIPS==2

DEFINE SSFIX A,B
	MULI A,400
	TSC A,A
	ASH A+1,-243+19.!B(A)
	TERMIN
;WORKS ONLY FOR + NUMBERS
DEFINE SFIX A,B
	MULI A,400
	ASH A+1,-243+19.!B(A)
	TERMIN

DEFINE INST IN,CO,ADR
IFSE CO,X,[IN D,ADR
	TLO D,2000
	HLRM D,DPP(T)
]
IFSE CO,Y,[IN C,ADR
	DPB A,[341000,,C]
	HLLM C,DPP(T)
	DPP=DPP+1
]
TERMIN

DEFINE CONC A,B
A!B!TERMIN


DEFINE BACKGROUND
	MOVE T,BKGTSP
	FADRB T,BKTMF'
	SFIX T,-19.
	MOVEM TT,BKTIME'
TERMIN


;VECTOR OF MYSTERIES

EGT:	120.	;DLY AT END OF GAME
TNO:	40	;# OF TORPS
TVL:	4.0	;TORP VEL
RLT:	MOVEI T,35	;TORP RELOAD TIME IN 30THS
TLF:	MOVEI T,110.	;TORP LIFE IN 30THS
NFU:	7.0	;FUEL SUPPLY
MAA:	.0005	;ANGULAR ACCEL
SAC:	.0001	;SPACESHIP ACCEL
SVL:	1.0	;CONST BETWEEN DX AND X
STR:	12.5	;STAR CAPTURE RADIUS
ME1:	12.5	;MAX COLL RADIUS
GRV:	300.0	;GRAV CONST
RAN:	(105*105)105+105
TXTM:	MOVEI T,4	;TORP EXPLODE TIME IN 30THS
EXSCL:	0	;EXPLOSION SCALE
GRVMX:	5.0	;MAX ACCEL BY GRAVITY
BKGTSP:	0.05	;RATE OF STAR FLOW
SSBRI:	21034	;SS BRIGHTNESS (RT 3 BITS)
TORBRI:	21037	;TORP BRIGHTNESS (")
HYPT1:	120.	;TIME INVISIBLE IN HYPERSPACE
HYPT2:	110.	;TIME AS HYPERSPACE STAR
HYPT3:	120.	;HYPERSPACE RELOAD TIME
HYPBO:	10	;HYPERSPACE LOSE RATE (FRACTION OF 100)
GSSBX:	1	;CONTROL SELECTION: 0=DS, 1=CONSOLES
SERL:	5	;SCOREKEEPER SERIES LENGTH (0=NO SCORING)

SEXPL:	40	;EXPLOSION OF SS
FATAL:	JRST 4,34000

APRBRK:	0
	CONSO 1000
	JRST 4,34000
	SETCMM APRTM'
	SKIPL APRTM
	SETOM CLKSNK'
	PUSH P,A
	MOVE A,DISPNR
	EXCH A,DISPNS
	CAMN A,DISPNS'
	CONO PI,4002
APRB2:	POP P,A
	CONO 3000+APRCHN
	JRST 12,@APRBRK

DEFINE LIMIT X,Y
	FADR X,Y(MP1)
	SKIPGE X
	FADR X,[1024.0]
	CAML X,[1024.0]
	FSBR X,[1024.0]
	MOVEM X,Y(MP1)
TERMIN

DEFINE SHIP A,B
	DPPI=DPP
	D!A=DPP
A:	IRPC C,,[B]
	IFSE [C]1,[INST SUB,X,XCOS
	INST SUB,Y,XSIN
]
	IFSE [C]2,[INST ADD,X,SXSIN
	INST SUB,Y,SXCOS
]
	IFSE [C]3,[INST SUB,X,XCOS45
	INST SUB,Y,SXSIN45
]
	IFSE [C]4,[INST SUB,X,SXSIN
	INST ADD,Y,SXCOS
]
	IFSE [C]5,[INST SUB,X,XSIN45
	INST ADD,Y,SXCOS45
]
	IFSE [C]6,[INST ADD,X,XCOS
	INST ADD,Y,XSIN
]
	IFSE [C]7,[INST ADD,X,XCOS45
	INST ADD,Y,SXSIN45
]
	IFSE [C]8,[INST ADD,X,XSIN45
	INST SUB,Y,SXCOS45
]
	IFSE [C]S,[	PUSH P,D
	PUSH P,.QUOTE ?.QUOTE /C/?
]
	IFSE [C]U,[	POP P,.QUOTE ?.QUOTE /C/?
	POP P,D
]
TERMIN
	JUMPN T,CPOPJ
	MOVNS SXSIN
	MOVNS SXCOS
	MOVE TT,XCOS45
	EXCH TT,XSIN45
	MOVEM TT,XCOS45
	MOVN TT,SXCOS45
	EXCH TT,SXSIN45
	MOVNM TT,SXCOS45
	MOVEI T,DPP-DPPI
	L!A=-2*<DPP-DPPI>
	DPP=DPP*2-DPPI
	MOVE C,SYCOR
	MOVE D,SXCOR
	JRST A
TERMIN

NOB=50.

GO:	MOVEI P,PDL
	CONO 633550+APRCHN
	CONO PI,12207
	SETZM BKTMF'
	SETZM BKTIME'
	SETZM BKTS'
	SETZM BKX'
	MOVE A,BKSTP
	MOVEM A,BKSTRT'
	SETZM RE1'
	SETOM SCNDF'
	CLEARM SCOREF'
	MOVEI A,SDISE-1
	MOVEM A,DISPNR
	MOVE A,SSBRI
	MOVEM A,SDIS
	CONO DIS,100+FLGCHN_3+DISCHN

GO0:	MOVSI A,-NSHIPS
	SETZM SCORE(A)
	AOBJN A,.-1

GO1:	MOVE A,SERL
	MOVEM A,SERIES'

GAME:	CLEARM GEFLG'
	MOVE A,TORBRI
	MOVEM A,TORB1
	CLEARM SCOREF'
	MOVE T,[20000,,20000]
	MOVSI A,SDISTB-SDISE
	MOVEM T,SDISTB(A)
	AOBJN A,.-1
	MOVSI A,-NOB
	CLEARM MTB(A)
	AOBJN A,.-1
	MOVEI D,SSS
	MOVSI A,-NSHIPS
	MOVE T,TNO
	MOVN TT,NFU
	MOVEI XFLAG,100
	MOVE C,SEXPL

GLP1:	MOVE B,ITAB(A)
	MOVEM B,MX1(A)
	MOVE B,ITAB+NSHIPS(A)
	MOVEM B,MY1(A)
	MOVEM T,MTR(A)
	MOVEM TT,MFU(A)
	MOVE B,ITAB+2*NSHIPS(A)
	MOVEM B,MTH(A)
	MOVEM C,MB1(A)
	MOVEM D,MTB(A)
	CLEARM MDX(A)
	CLEARM MDY(A)
	CLEARM MTBS(A)
	CLEARM MA1(A)
	CLEARM MTOR(A)
	CLEARM MHYP(A)
	CLEARM GSSSAC(A)
	CLEARM GSSSTS(A)
	MOVEM XFLAG,MHYPP(A)
	AOBJN A,GLP1

GLP1A:	MOVEI A,NSHIPS-1
	HRRZM A,SSING'	;SHIPS IN GAME - 1
	MOVE A,EGT
	MOVEM A,GECNT'	;END GAME DLY
	MOVE A,ME1
	FMPR A,A
	MOVEM A,ME12'
	JRST ML0B


ML0:	MOVE A,DPYP'
	MOVEI B,3000
	MOVEM B,(A)
	MOVEI C,VDIS2-1
	MOVEI B,VDIS1
	CAIGE A,VDIS2
	MOVEI C,VDIS1-1
	MOVEM C,VDPP'
	CLEARM SCNDF'
	CAIGE A,VDIS2
ML0B:	MOVEI B,VDIS2
	MOVE A,SSBRI
	MOVEM A,(B)
	AOS B
	MOVEM B,DPYP
	AOSE CLKSNK	;WAIT FOR CLOCK SYNC
	JRST .-1
	CLEARB MP1,B
	MOVSI A,-NSHIPS
ML0C:	SKIPN MTB(A)
	JRST MDN1	;FLUSH A SHIP
	SKIPL MTOR(A)
ML0AA:	SETOM B
ML0A:	AOBJN A,ML0C
	SKIPN B
	SETOM GEFLG	;ALL SHIPS OUT OF TORP
	SKIPE GEFLG
	JRST GEC1

ML1:	SKIPN MTB(MP1)
	JRST MQ1	;OBJ NOT ACTIVE
	SKIPG MTB(MP1)
	JRST MQ4	;OBJECT NOT COLLIDEABLE
	MOVEI MP2,1(MP1)
ML2:	SKIPG MTB(MP2)
	JRST MQ2	;OBJ CANNOT COLLIDE
	MOVE A,MX1(MP1)
	FSBR A,MX1(MP2)
	FMPR A,A
	MOVE B,MY1(MP1)
	FSBR B,MY1(MP2)
	FMPR B,B
	FADR A,B
	CAMLE A,ME12
	JRST MQ2
ML9:	LDB A,[(270600)MTB(MP1)]
	JUMPE A,ML9A
	LDB B,[(270600)MTB(MP2)]
	CAMN A,B
	JRST MQ2
	JRST ML10

ML9A:	LDB A,[(350600)MTB(MP1)]
	JUMPE A,ML9C
	MOVEI B,1(MP2)
	CAMN A,B
	JRST ML10
	JRST MQ2

ML9C:	LDB A,[(350600)MTB(MP2)]
	JUMPE A,ML10
	MOVEI B,1(MP1)
	CAME A,B
	JRST MQ2
ML10:	MOVE A,[SETZ MEX]	;EXPLODE
	MOVEM A,MTB(MP1)
	MOVEM A,MTB(MP2)
	MOVE A,MB1(MP1)
	MOVEM A,MA1(MP1)
	MOVE A,MB1(MP2)
	MOVEM A,MA1(MP2)	;STORE LENGTH OF EXPLOSION
	MOVE T,[20000,,20000]
	MOVSI TT,+(.5)
	CAIL MP1,NSHIPS
	JRST EXPTP
	MOVE B,CLRTB(MP1)
	MOVEM T,(B)
	AOBJN B,.-1
	FMPRM TT,MDX(MP1)
	FMPRM TT,MDY(MP1)
MQ2A:	CAIL MP2,NSHIPS
	JRST EXPTP1
	MOVE B,CLRTB(MP2)
	MOVEM T,(B)
	AOBJN B,.-1
	FMPRM TT,MDX(MP2)
	FMPRM TT,MDY(MP2)
MQ2:	CAIGE MP2,NOB-1
	AOJA MP2,ML2

MQ4:	PUSHJ P,@MTB(MP1)	;UPDATE DISPLAY FOR OBJ
MQ1:	CAIGE MP1,NOB-2
	AOJA MP1,ML1
	AOS MP1
	SKIPE MTB+NOB-1
	PUSHJ P,@MTB+NOB-1

MQ3:	BACKGROUND	;UPDATE
	PUSHJ P,TWINKLE
	JRST ML0

EXPTP:	MOVEM T,TORDIS-NSHIPS(MP1)
	JRST MQ2A

EXPTP1:	MOVEM T,TORDIS-NSHIPS(MP2)
	JRST MQ2

MDN1:	MOVE T,[SETZ CPOPJ]
	MOVEM T,MTB(A)
	SOSG SSING
	SETOM GEFLG
	SKIPE SSING
	JRST ML0A
	MOVE B,HYPT1
	ADD B,HYPT2
	MOVSI T,-NSHIPS
	HRRZ TT,MTB(T)
	CAIE TT,HYPI
	CAIN TT,HYPO
	MOVEM B,GECNT
	AOBJN T,.-4
	JRST ML0A
PIE=3.14159263694

SSS:	PUSHJ P,@GETAB(MP1)	;UPDATE SPACE SHIP
	MOVEM B,GSSSAC(MP1)
	AND T,[(4000)]
	MOVEM T,GSSSTS(MP1)
	SOS MHYP(MP1)
	TLNE C,200000
	JRST HYPGO
	TLNE C,100000
	JRST SEXP

SSNHYP:	TLC B,232000
	FAD B,B
	FMPR B,SAC
	MOVEM B,SACL'
	MOVEM C,SFLGS'
	TLC A,232000	;A ANG CHANGE
	FAD A,A	;B ACCEL
	FMPR A,MAA	;C 4.9=TORPS 4.8=HYPER 4.7=DESTRUCT
		; 4.6=BEACON 4.5=TIME 0 4.6=TIME K
	FADR A,MTH(MP1)
	PUSHJ P,SSANGL
	PUSHJ P,CGRAV
	JUMPN XFLAG,FALL
	SKIPE T,SACL
	SKIPLE MFU(MP1)
	JRST SSNACL	;NOT ACCEL

	FADRM T,MFU(MP1)
	MOVE T,SACL
	FMPR T,FSIN
	FADR B,T
	MOVE T,SACL
	FMPR T,FCOS
	FADR C,T

SSNACL:	FADRB C,MDX(MP1)
	FADRB B,MDY(MP1)
	FMPR B,SVL
	FMPR C,SVL
	LIMIT B,MY1
	LIMIT C,MX1
	SKIPE T,SACL
	SKIPLE MFU(MP1)
	JRST FELL
	PUSH P,C
	PUSH P,B
	PUSHJ P,RANDOM
	SSFIX T,-17.
	ANDI A,17
	ADD A,TT
	MOVN B,SLTBL(MP1)
	MOVE C,B
	FMPR B,FCOS
	FMPR C,FSIN
	FADR B,MX1(MP1)
	FADR C,MY1(MP1)
	SSFIX C,-1
	SSFIX B,-1
	PUSHJ P,DPY
	SUB D,XSIN
	SUB C,XCOS
	SOJG A,.-3
	POP P,B
	POP P,C
FELL:	PUSHJ P,SSDIS	;Y IN B, X IN C
	SOSG MA1(MP1)
	SKIPL SFLGS
	JRST SNOTORP
	SOSGE MTR(MP1)
	JRST SNOT1

	MOVE C,TVL
	MOVE B,C
	FMPR C,FCOS
	FADR C,MDX(MP1)
	FMPR B,FSIN
	FADR B,MDY(MP1)
	MOVSI D,-NOB
	SKIPE MTB(D)
	AOBJN D,.-1
	JUMPGE D,FATAL	;TOO MANY OBJECTS
	MOVEI T,TORPCL	;TORP CALC ROUTINE
	MOVEM T,MTB(D)
	MOVE T,SLTBL1(MP1)
	FMPR T,FCOS
	FADR T,MX1(MP1)
	MOVEM T,MX1(D)
	MOVE T,SLTBL1(MP1)
	FMPR T,FSIN
	FADR T,MY1(MP1)
	MOVEM T,MY1(D)
	MOVEM B,MDY(D)
	MOVEM C,MDX(D)
	XCT TLF
	MOVEM T,MA1(D)
	XCT RLT
	MOVEM T,MA1(MP1)
	XCT TXTM
	MOVEM T,MB1(D)
SNOTORP:	MOVE T,SFLGS'
	TLNN T,40000
	JRST SNOBEA
	MOVEI TT,20	;BEACON/HYPERSPACE DISCHARGE RATIO
	ADDM TT,MHYP(MP1)
	MOVE B,XSIN
	IMULI B,3
	MOVEM B,BXSIN'
	MOVE B,XCOS
	IMULI B,3
	MOVEM B,BXCOS'
	MOVE B,SLTBL1(MP1)
	MOVE C,B
	FMPR B,FCOS
	FADR B,MX1(MP1)
	FMPR C,FSIN
	FADR C,MY1(MP1)
	SSFIX C,-1
	SSFIX B,-1
	MOVEI A,114	;LENGTH OF BEACON BEAM
	PUSHJ P,DPY
	ADD D,BXSIN
	ADD C,BXCOS
	SOJG A,.-3

SNOBEA:	POPJ P,

SNOT1:	SETOM MTOR(MP1)
	JRST SNOTORP

GEC1:	SOSLE GECNT
	JRST ML1

MDN:	SETOM SCNDF'	;END OF GAME
	SKIPN SERIES
	JRST GO0
	MOVSI A,-NSHIPS
	MOVEI B,0

MDN11:	HRRZ C,MTB(A)
	CAIE C,SSS
	ADDI B,1
	AOBJN A,MDN11
	MOVSI A,-NSHIPS

MDN2:	HRRZ C,MTB(A)
	CAIN C,SSS
	ADDM B,SCORE(A)
	AOBJN A,MDN2
	SOSLE SERIES
	JRST GAME
	MOVEI B,2
	CAMN B,RE1'
	JRST .-1
	MOVE B,[1150.0]
	MOVEM B,MDN3Y'
	MOVSI MP1,-NSHIPS

MDN3:	MOVE A,[.OP FDVR PIE 2.0]
	PUSHJ P,SSANGL
	MOVEI A,4
	IRP V,,[XSIN,SXSIN,XCOS,SXCOS,XSIN45,SXSIN45,XCOS45,SXCOS45]
	IMULM A,V
	TERMIN

MDN4:	MOVE B,[-200.0]
	FADRB B,MDN3Y
	MOVE C,[100.0]
	PUSHJ P,SSDIS
	AOBJN MP1,MDN4
	MOVEI B,900.	;Y
	MOVSI MP1,-NSHIPS
	MOVEI D,TORB1
	MOVEI C,20140
	MOVEM C,TORB1

MDN5:	MOVE C,[(220000)60300]	;PT MODE TO CHARAC.
	DPB B,[(221200)C]
	PUSH D,C
	HRLI D,600
	PUSHJ P,MDNN
	SUBI B,200.
	MOVEI TT,37
	IDPB TT,D
	AOBJP MP1,MDN6
	MOVEI TT,20000
	MOVEM TT,1(D)
	AOJA D,MDN5

MDN6:	MOVSI TT,3000
	MOVEM TT,1(D)
	SETOM SCOREF'

MDN8:	SETOB MP2,Q
	MOVSI MP1,-NSHIPS

MDN7:	PUSHJ P,@GETAB(MP1)
	TLNN C,20000
	MOVEI MP2,0
	TLNN C,10000
	MOVEI Q,0
	AOBJN MP1,MDN7
	JUMPN Q,.+2
	JUMPE MP2,MDN8
	MOVEI A,120.	;FADEOUT DELAY IN 30THS
	SETZM SCOREF

MDN9:	AOSE CLKSNK
	JRST .-1
	SOJG A,MDN9
	JUMPN Q,GO1
	JRST GO0

FALL:	CLEARB B,C
	CLEARM MX1(MP1)
	CLEARM MY1(MP1)
	CLEARM MDX(MP1)
	CLEARM MDY(MP1)
	JRST FELL


HYPGO:	SKIPLE MHYP(MP1)	;ENTER HYPERSPACE
	JRST SSNHYP
	MOVE T,[20000,,20000]
	MOVE A,CLRTB(MP1)
	MOVEM T,(A)
	AOBJN A,.-1
	MOVE A,[SETZ HYPI]
	MOVEM A,MTB(MP1)
	MOVE A,HYPT1
	MOVEM A,MHYP(MP1)
	POPJ P,


HYPI:	SOSLE MHYP(MP1)	;INVISIBLY IN HYPERSPACE
	POPJ P,
	IRP XORY,,[X,Y]
	PUSHJ P,RANDOM
	ANDI A,1777
	TLC A,232000
	FAD A,A
	MOVEM A,M!XORY!1(MP1)
	TERMIN
	MOVEI A,HYPO
	MOVEM A,MTB(MP1)
	MOVE A,HYPT2
	MOVEM A,MHYP(MP1)
	POPJ P,

HYPO:	SOSG MHYP(MP1)	;VISIBLY IN HYPERSPACE
	JRST HYPO1
	MOVE C,MY1(MP1)
	FADR C,[1.0]
	SFIX C,-1.
	MOVE B,MX1(MP1)
	SFIX B,-1.
	PUSHJ P,DPY
	SUB D,[(2)]
	SUB C,[(1)]
	PUSHJ P,DPY
	ADD C,[(2)]
	JRST DPY

HYPO1:	MOVN B,HYPBO	;BREAK OUT
	ADDB B,MHYPP(MP1)
	PUSHJ P,RANDOM
	ANDI A,77
	CAMG B,A
	JRST SEXP	;LOSE
	MOVEI A,SSS
	MOVEM A,MTB(MP1)
	MOVE A,HYPT3
	MOVEM A,MHYP(MP1)
	PUSHJ P,RANDOM
	HRLI A,232000
	FAD A,A
	FMPR A,[.OP FDVR PIE 131072.0]
	MOVEM A,MTH(MP1)
	IRP XORY,,[X,Y]
	PUSHJ P,RANDOM
	HRLI A,232000
	FAD A,A
	FSBR A,[131072.0]
	FMPR A,[.OP FDVR 0.14142 262144.0]
	FMPR A,NFU
	MOVEM A,MD!XORY(MP1)
	TERMIN
	JRST SSS


SEXP:	MOVE T,[SETZ MEX]
	MOVEM T,MTB(MP1)
	MOVE T,MB1(MP1)
	MOVEM T,MA1(MP1)
	MOVE T,[20000,,20000]
	MOVE A,CLRTB(MP1)
	MOVEM T,(A)
	AOBJN A,.-1
	POPJ P,

CGRAV:	MOVEI XFLAG,0
	MOVE T,MX1(MP1)
	FSBR T,[512.0]
	MOVEM T,T1'
	FMPR T,T
	MOVE TT,MY1(MP1)
	FSBR TT,[512.0]
	MOVEM TT,T2'
	FMPR TT,TT
	FADR T,TT
	MOVE A,T
	PUSHJ P,SQRT"
	CAMG A,STR
	SETOM XFLAG
	FMPR T,A
	FDVR T,GRV
	MOVN B,T2
	FDVR B,T
	MOVN C,T1
	FDVR C,T
	POPJ P,


SSANGL:	CAML A,[.OP FMPR PIE 2.0]
	FSBR A,[.OP FMPR PIE 2.0]
	SKIPGE A
	FADR A,[.OP FMPR PIE 2.0]
	MOVEM A,MTH(MP1)
	PUSHJ P,SIN"
	MOVEM A,FSIN'
	MOVEM A,MPFSIN(MP1)
	SSFIX A,-1
	MOVEM B,XSIN'
	MOVEM B,SXSIN'
	MOVE A,MTH(MP1)
	PUSHJ P,COS"
	MOVEM A,FCOS'
	MOVEM A,MPFCOS(MP1)
	SSFIX A,-1
	MOVEM B,XCOS'
	MOVEM B,SXCOS'
	MOVE A,MTH(MP1)
	FADR A,[.OP FDVR PIE 4.0]
	PUSHJ P,SIN"
	MOVEM A,FSIN45'
	SSFIX A,-1
	MOVEM B,XSIN45'
	MOVEM B,SXSIN45'
	MOVE A,MTH(MP1)
	FADR A,[.OP FDVR PIE 4.0]
	PUSHJ P,COS
	MOVEM A,FCOS45'
	SSFIX A,-1
	MOVEM B,XCOS45'
	MOVEM B,SXCOS45'
	POPJ P,

SSDIS:	MOVE T,SLTBL(MP1)
	FMPR T,FCOS
	FADR C,T
	MOVE T,SLTBL(MP1)
	FMPR T,FSIN
	FADR B,T
	SSFIX C,-1
	SSFIX B,-1
	MOVEI A,220_-1
	TLZ C,776000
	TLZ D,776000
	TLO D,22000
	MOVEM C,SYCOR'
	MOVEM D,SXCOR'
	MOVEI T,0
	JRST @DISTAB(MP1)	;UPDATE DISPLAY LIST


MDNN:	MOVE T,SCORE(MP1)
	IDIVI T,10.
	PUSH P,TT
	SKIPE T
	PUSHJ P,MDNN+1
	POP P,TT
	ADDI TT,60
	IDPB TT,D
	POPJ P,
TORPCL:	SOSGE MA1(MP1)
	JRST TEXP
	PUSHJ P,CGRAV
	JUMPN XFLAG,TEXP
	FADRB B,MDY(MP1)
	FADRB C,MDX(MP1)
	LIMIT B,MY1
	LIMIT C,MX1
	SFIX C,-1
	SFIX B,-1
	TLO C,220000
	TLO D,22000
	HLLM C,TORDIS-NSHIPS(MP1)
	HLRM D,TORDIS-NSHIPS(MP1)
	POPJ P,

TEXP:	MOVE T,[SETZ MEX]
	MOVEM T,MTB(MP1)
	MOVE T,[20000,,20000]
	MOVEM T,TORDIS-NSHIPS(MP1)
	XCT TXTM	;LENGTH OF EXPLOSION
	MOVEM T,MA1(MP1)
CPOPJ:	POPJ P,

DPY:	HLL MP2,D	;X IN C Y IN D
	HLR MP2,C
	ANDCM MP2,[776000,,776000]
	IOR MP2,[220000,,22000]
DPY1:	AOS Q,DPYP
	MOVEM MP2,-1(Q)
	CAIE Q,VDIS2
	CAIN Q,VDIS3
	SOS DPYP
	POPJ P,

TWINKLE:	MOVSI T,1
	MOVSI D,512.
	MOVSI C,512.
	IRP Z,,[AX,AY,SX,SY,[AX,AY],[AX,SY],[SX,AY],[I,SX,SY]]
	PUSHJ P,RANDOM
	ANDI A,7
	LTWNK=.
	IRP W,,[Z]
	IFSE W,AX,ADD D,T
	IFSE W,SX,SUB D,T
	IFSE W,AY,ADD C,T
	IFSE W,SY,SUB C,T
	TERMIN
	PUSHJ P,DPY
	SOJGE A,LTWNK
	IRPC W,,[Z]
	IFSE [W]I,.ISTOP
	IFSE [W]X,MOVSI D,512.
	IFSE [W]Y,MOVSI C,512.
	TERMIN
	TERMIN
	POPJ P,
MEX:	SOSGE MA1(MP1)
	JRST MEXNO
	MOVEI T,200
	IMUL T,MA1(MP1)
	IDIV T,MB1(MP1)
	MOVEI B,1400
	IDIV B,MB1(MP1)
	CAMG T,B
	MOVE T,B
	MOVEM T,EXSIZE'
	MOVE T,MA1(MP1)
	ASH T,@EXSCL
	MOVE B,MDX(MP1)
	MOVE C,MDY(MP1)
	LIMIT B,MX1
	LIMIT C,MY1
	SFIX C,-1
	SFIX B,-1
	MOVEM C,EXX'
	MOVEM D,EXY'
MEX2:	IRPS CORD,,D C
	PUSHJ P,RANDOM
	TLZ A,776000
	IDIV A,EXSIZE
	TRNN B,2
	LSH A,1
	TRNN B,1
	MOVNS A
	ADD CORD,A
	TERMIN
	PUSHJ P,DPY
	HRLS MP2
	PUSHJ P,DPY1
	PUSHJ P,DPY1
	MOVE D,EXY
	MOVE C,EXX
	SOJGE T,MEX2
	POPJ P,
MEXNO:	CLEARM MTB(MP1)
	POPJ P,

RANDOM:	MOVE A,RAN
	FMPB A,RAN
	TSC A,A
	POPJ P,

GSS1:	DATAI T
	MOVSS T
	SKIPN GSSBX
	JRST GSS20
	DATAI 724,T
	MOVSS T
	JRST GSS21

GSS2:	DATAI T
	SKIPN GSSBX
	JRST GSS20
	DATAI 724,T

GSS21:	SETZB A,B
	MOVEI C,0
	TLNE T,20000	;BEACON
	TLO C,40000
	TLNE T,2	;TIME 0
	TLO C,20000
	TLNE T,1	;TIME K
	TLO C,10000
	TLNE T,200000
	JRST GSS29
	TLNE T,100	;SLOWER
	MOVEI B,40
	TLNE T,200	;FASTER
GSS297:	MOVEI B,200
GSS39:	JUMPL T,GSS10
	TLNE T,40	;STBD, CW
GSS10A:	MOVNI A,105	;ROTATION CONST.
	TLNE T,20	;PORT, CCW
	MOVEI A,@GSS10A
GSS11:	TLNE T,10000	;GENERAL CANCEL
	TLO C,100000	;DESTRUCT
	TLNE T,400	;XMIT DATA
	TLO C,400000	;TORPS
	TLNE T,100000
	JRST GSS21A
	TLNE T,10	;BUTTON: TORPS
	TLO C,400000
	TLNE T,4	;PEDAL: HYPERSPACE
	TLO C,200000
	POPJ P,

GSS21A:	TLNE T,10	;BUTTON: HYPERSPACE
	TLO C,200000
	TLNE T,4	;PEDAL: TORPS
	TLO C,400000
	POPJ P,

GSS20:	CLEARB A,B
	MOVSI C,200000
	SKIPGE T
	TLO C,400000
	TLNE T,200000
	MOVEI A,105
	TLNE T,100000
	MOVNI A,@.-2
	TLNE T,40000
	MOVEI B,105
	TLNE T,20000
	TLNN T,10000
	TLZ C,200000
	TLNE T,40000
	TLO C,20000
	TLNE T,20000
	TLO C,10000
	POPJ P,

GSS10:	TLNE T,20	;PORT, CW
	MOVNI A,@GSS10A
	TLNE T,40	;STBD, CCW
	MOVEI A,@GSS10A
	JRST GSS11

GSS29:	MOVE B,GSSSAC(MP1)
	SKIPN GSSSTS(MP1)
	TLNN T,4000
	JRST GSS39
	JUMPE B,GSS297
	MOVEI B,0
	JRST GSS39


RECYC:	0
	PUSH P,A
	SKIPE SCOREF'
	JRST RE3
	SKIPE SCNDF'
	JRST BK3
	SOSL RE1'
	JRST RECYC1
	MOVEI A,2
	MOVEM A,RE1
RE3:	MOVEI A,SDIS-1
RE2:	MOVEM A,DISPNR
	CONO DIS,100+FLGCHN_3+DISCHN
	POP P,A
	JRST 12,@RECYC

RECYC1:	SKIPE RE1
	JRST BK
	MOVE A,VDPP
	JRST RE2

BK3:	SETZM RE1
BK:	MOVE A,BKTIME'
	EXCH A,BKTS'
	SUB A,BKTS

BK0:	ADDB A,BKX'
	JUMPGE A,BK1
	IBP BKSTRT'
	AOS A,BKSTRT
	HRRZS A
	CAIGE A,BKEND
	JRST BK2
	MOVE A,BKSTP
	MOVEM A,BKSTRT

BK2:	LDB A,BKSTRT
	ANDI A,177
	JRST BK0

BK1:	CONO DIS,100
	HRLI A,20100	;PARAM TO PT, SCALE 0
	DATAO DIS,A	;PT TO PARAM, X UNLIT
	MOVE A,BKSTRT
	SKIPL @BKSTRT
	ADDI A,1
	SUBI A,BKEND"
	MOVSS A
	HRR A,BKSTRT
	SKIPGE @BKSTRT
	SUBI A,1
	CONSO DIS,200
	JRST .-1
	JRST RE2

BKWRAP:	0
	PUSH P,A
	MOVE A,[(,BKBEG"-BKEND"+1)BKBEG"-1]
	MOVEM A,DISPNR
	POP P,A
	JRST 12,@BKWRAP

BKSTP:	(222200)BKBEG"

;L=30
SHIP SHIP1,[111131	111111
111111	1111S3	311111
14U111	111114]

;L=22

SHIP SHIP2,[113113	113111
11S313	131111	1U1151
111S33	3U5114]
SDIS:	20135
	221000,,23000	;SUN
SDISTB:	IF1 LOC .+DPP
	IF2 REPEAT DPP-.,20000,,20000
SDISTE:

TORB1:	0	;TORP BRI
TORDIS:	REPEAT NOB-NSHIPS,20000,,20000
SDISE:	3000

DISTAB:	REPEAT NSHIPS,[CONC SHIP,\.RPCNT+1
]
CLRTB:	REPEAT NSHIPS,[CONC LSHIP,\.RPCNT+1,,,CONC DSHIP,\.RPCNT+1
]
GETAB:	REPEAT NSHIPS,[CONC GSS,\.RPCNT+1
]
SLTBL:	15.0
	11.0
SLTBL1:	.OP FMPR 15.0 1.1415
	.OP FMPR 15.0 1.1415
PDL:	BLOCK 20
VDIS1:	BLOCK 6000
VDIS2:	BLOCK 6000
VDIS3:

CONSTANTS
VARIABLES

ITAB:	768.0	;INITIAL X SS1
	256.0	;SS2
	768.0	;INIT Y
	256.0
	.OP FDVR -PIE 2.0	;INIT ANGLE
	.OP FDVR PIE 2.0
;TABLE OF OBJECTS AND THEIR PROPS.

MTB:	BLOCK NOB	;ROUTINE ADR 4.9>NON-COLLIDABLE
		;  1-6 SELECT TARGET IF NON0; 7-12 EXCLUSION CLASS IF NON0
MX1:	BLOCK NOB	;X POS
MY1:	BLOCK NOB	;Y POS
MA1:	BLOCK NOB	;COUNTER FOR LENGTH OF EXPLOSION
MB1:	BLOCK NOB	;LENGTH OF EXPLOSION
MDX:	BLOCK NOB	;XVEL
MDY:	BLOCK NOB	;YVEL
MTBS:	BLOCK NSHIPS	;ANGULAR VEL
MTH:	BLOCK NSHIPS	;ANGLE
MFU:	BLOCK NSHIPS	;FUEL
MTR:	BLOCK NSHIPS	;TORPS
MPFCOS:	BLOCK NSHIPS	;COS MTH
MPFSIN:	BLOCK NSHIPS	;SIN MTH
MTOR:	BLOCK NSHIPS	;OUT OF TORPS FLAG
MHYP:	BLOCK NSHIPS	;HYPERSPACE COUNTER
MHYPP:	BLOCK NSHIPS	;HYPERSPACE SURVIVAL CHANCES
GSSSAC:	BLOCK NSHIPS	;SAVED ACCEL STATUS
GSSSTS:	BLOCK NSHIPS	;SAVED ACCEL FLIPFLOP
SCORE:	BLOCK NSHIPS	;WINS TO CREDIT

END GO
