	TITLE	SWR--SPACE WAR FOR TVS

A=1		;SUN BEING CONSIDERED
N=2		;SHIP BEING CONSIDERED
X=3		;POSITION
XT=4
Y=5
YT=6
T1=10		;TEMPORARIES
T2=11
TT=12
T3=13
T4=14
T5=15
D=16
SP=17		;STACK POINTER
IN=1		;INPUT CHANNEL
TYO=3		;OUTPUT CHANNEL
TVBFR=24000	;TOP OF TV
NDIREC==100
INCH==2		;INPUT CHNL FOR DISK
MAXSHP==3
MAXSUN==2
TORP==1
MAXOBJ==600

LOC 42
	JSR TSINT	;OLD-STYLE INTERRUPT HANDLER IN THIS LOCATION.
	
LOC 100
ST:	.OPEN	IN,OPNIN	;TTY INPUT, NO-WAIT MODE
		.VALUE
	.OPEN	TYO,OPNOUT	;TTY OUTPUT, 3 LINE ECHO AREA
		.VALUE
	.CALL	TVSCRN		;TV BUFFER MAP
		.VALUE
	.CALL	INSHIP		;OPEN THE DISK AND READ IN THE SHIP PATTERNS
		.VALUE	[ASCIZ/:NO SHIP FILES/]
	.IOT	INCH,PNTR
	.CLOSE	INCH,
	.CALL	INSINE		;OPEN THE DISK AND READ IN THE SINE WAVE
		.VALUE	[ASCIZ/:NO SINE WAVE FILE/]
	.IOT	INCH,PNTR1
	.CLOSE	INCH,
	.RTIME	TT,		;INITIALIZE THE RANDOM NUMBER
	MOVEM	TT,RANNUM
	MOVE	TT,TVBFR+20000	;GET TV ALU
	MOVEM	TT,TVALU

RESTRT:	MOVE	TT,TVALU
	MOVEM	TT,TVBFR+20000	;RESTORE TV ALU TO ORIGINAL
	HRRZI	TT,442.*18.-1	;CLEAR THE SCREEN
	SETZM	TVBFR(TT)
	SOJG	TT,.-1
	HRLZI	TT,22000	;TV SCREEN INTO XOR MODE
	XORM	TT,TVBFR+20000
NEWGAM:	MOVEI	SP,STACK
	SETZM	OBJLEN
	SKIPG	N,NSHIP
	JRST	NOSHPS
RANL:	SETZM	SWITCH-1(N)
	SKIPN	RANPOS
	JRST	NORAN
	PUSHJ	SP,RAND
	M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.VALUE [ASCIZ/:.REALT FAILED TO SKIP.VP /]
	JRST	RHJFCL
REHANG:	SKIPE	TEST		;IN REALTIME MODE?
	JRST	TSTSLP
	.DISMISS TSINT+1
		.VALUE [ASCIZ/:GACK!  THESE OLD TIME INTERRUPTS ARE WIERD!/]
RHJFCL:	JFCL
	.HANG

INTMSK:	%PIRLT

TSINT:	0			;PC, ETC. GO HERE
	0
	PUSHJ	SP,CRASH	;CHECK FOR COLLISIONS
	PUSHJ	SP,SMACK
	PUSHJ	SP,HIT
	PUSHJ	SP,DFND
	SOS	SHOTTM
	SOS	SHOTTM+1
	PUSHJ	SP,SCORE
	MOVE	N,NSHIP
LOOP:	SKIPGE	SHPSTS-1(N)
	JRST	LOPOK
	SKIPG	SHPSTS-1(N)
	JRST	LOPEND
	SOS	SHPSTS-1(N)
	JRST	LOPDED
LOPOK:	PUSHJ	SP,REPOS	;DO ANOTHER TIME INCREMENT
	PUSHJ	SP,CLRSHP
	PUSHJ	SP,VELPOS
	PUSHJ	SP,PUTSHP
LOPEND:	SOJG	N,LOOP
	PUSHJ	SP,DISOBL
	SKIPE	TEST		;IN REALTIME MODE?
	JRST	TSTSLP
	.DISMISS TSINT+1
		.VALUE [ASCIZ/:GACK!  THESE OLD TIME INTERRUPTS ARE WIERD!/]
TSTSLP:	MOVE	TT,TIME		;NOT IN REALTIME, SO JUST SLEEP ON IT
	.SLEEP	TT,
	JRST	TSINT+2

LOPDED:	PUSHJ	SP,REPOS
	PUSHJ	SP,VELPOS
	MOVE	TT,SHPSTS-1(N)
	TRNN	TT,1
	JRST	PUTDWN
	JRST	PUTUP
PUTDWN:	PUSHJ	SP,CLRSHP
	JRST	LOPEND
PUTUP:	PUSHJ	SP,PUTSHP
	JRST	LOPEND

SCORE:	SKIPG	N,NSHIP
	JRST	SCRL
SCRLP:	MOVE	TT,SHPSTS-1(N)
	CAIE	TT,1
	JRST	SCRNXT
	SKIPG	TT,NSHIP
	JRST	SCRNXT
	SKIPGE	SHPSTS-1(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4,32.
CLRLP:	SKIPE	T2,CLRS+1(T3)
	MOVEM	T2,TVBFR(T1)
	SKIPE	T2,CLRS+2(T3)
	MOVEM	T2,TVBFR+1(T1)
	ADDI	T3,2
	ADDI	T1,18.
	SOJG	T4,CLRLP
	POPJ	SP,

PUTSHP:	MOVE	T3,N		;REGENERATE A CLRS FIELD
	SUBI	T3,1
	MOVE	T4,T3
	IMULI	T3,70.
	IMULI	T4,NDIREC*10
	ADD	T4,DIRECT-1(N)
	LSH	T4,-3
	IMULI	T4,32.
	SETZM	CLRS+1(T3)
	HRRZI	TT,CLRS+2(T3)
	HRLI	TT,CLRS+1(T3)
	BLT	TT,CLRS+64.(T3)
	MOVE	T1,PX-1(N)
	LSH	T1,-6
	ADDI	T1,16.
	IDIVI	T1,32.
	MOVNS	T2
	MOVE	TT,PY-1(N)
	LSH	TT,-6
	SUBI	TT,16.
	IMULI	TT,18.
	ADD	T1,TT
	MOVEM	T1,CLRS(T3)
	MOVEI	TT,32.
PUTSLP:	SETZ	XT,
	MOVE	X,SHPBFR(T4)
	LSHC	X,-4(T2)
	LSH	X,4
	MOVEM	X,CLRS+1(T3)
	MOVEM	XT,CLRS+2(T3)
	ADDI	T3,2
	ADDI	T4,1
	SOJG	TT,PUTSLP
	JRST	CLRSHP

TIME:	4			;REPEAT FRAME TIME (60THS), OR DELAY TIME
	2			;WHEN REALTIME IS SUPPRESSED
	0
	0

TEST:	-1			;TEST-MODE SWITCH, SUPPRESSES REALTIME
OPNIN:	1044,,646471		;TTY INPUT NO-WAIT ECHO AREA
OPNOUT:	15,,646471		;TTY OUTPUT, 3 LINE ECHO AREA

PNTR:	-32.*MAXSHP*NDIREC,,SHPBFR	;DISK INPUT OF SHIPS POINTER

INSHIP:	SETZ			;DISK OPEN INFO FOR SHIPS PATERNS
	SIXBIT	/OPEN/
	[6,,INCH]
	[SIXBIT	/DSK/]
	[SIXBIT	/SWR/]
	[SIXBIT	/SHIPS/]
	SETZ	[SIXBIT	/GJD/]

PNTR1:	-512.,,SIN

INSINE:	SETZ			;DISK OPEN INFO FOR SINE WAVE
	SIXBIT	/OPEN/
	[6,,INCH]
	[SIXBIT	/DSK/]
	[SIXBIT	/SINE/]
	[SIXBIT	/BINARY/]
	SETZ	[SIXBIT	/GJD/]

TVALU:	0			;TV ALU BEFORE CHANGING IT

TVSCRN:	SETZ			;TV MAPPING INFO
	SIXBIT	/CORBLK/
	1000,,600000
	1000,,-1
	TMP
	1000,,-2
	SETZ	TMP2
TMP:	-11,,TVBFR/2000		;8.K TV MEM, START AT PAGE 12 IN PDP10
TMP2:	0

IPX:	40000			;SHIP STARTING POSITIONS
	50000
	50000
IPY:	30000
	40000
	30000
IVX:	300			;SHIP STARTING VELOCITIES
	0
	200
IVY:	0
	250
	100
PX:	BLOCK	MAXSHP		;SHIP DATA DURING A GAME
PY:	BLOCK	MAXSHP
VX:	BLOCK	MAXSHP
VY:	BLOCK	MAXSHP
DIRECT:	BLOCK	MAXSHP
IGRVX:	40000			;SUN STARTING LOCATIONS
	20000
IGRVY:	40000
	40000
GRVX:	BLOCK	MAXSUN		;SUN GAME LOCATIONS
GRVY:	BLOCK	MAXSUN
GRVK:	2			;SUN RELATIVE MASSES
	1
GRAV:	100			;GRAVITY CONSTANT
LEFTF:	4000			;FRINGE POSITIONS, FOR WRAP & BOUNCE
RITEF:	72000
TOPF:	4000
BTMF:	60000
WIDE:	66000			;THE UNIVERSE'S DIMENSIONS
HIGH:	54000
BOUNCE:	0		;-1=BOUNCE, 0=WRAP
RANPOS:	-1		;RANDOM SHIP POSITIONING
RANSUN:	-1		;RANDOM SUN POSITIONING
NSUN:	1		;NUMBER OF SUNS IN THIS GAME
NSHIP:	2		;NUMBER OF SHIPS STARTING THIS GAME
SHPACC:	40		;SHIP ACCELERATION WHEN ENGINES ARE ON
SHPSPN:	20		;RATE OF SPIN WHEN TURNING
XPLODR:	1400		;PROXIMITY FUSE FOR TORPS
XPLDTM:	30		;EXPLOSION TIME
SUNRAD:	1400		;PROXIMITY RADIUS FOR SUNS
TRPVEL:	20		;TORPEDO VELOCITY
TRPLIF:	50		;TORPEDO LIFETIME BEFORE AUTO-DETINATION
RLDTIM:	4		;TORPEDO RELOAD TIME IN FRAMES
SCRTIM:	20		;SCORE DISPLAY TIME AT END OF GAME IN 30ths
MAXVEL:	2000		;MAXIMUM VELOCITY OF THE SHIPS

SWITCH:	BLOCK	MAXSHP	;SHIP COMMAND STORAGE
SHPSTS:	BLOCK	MAXSHP		;0=SHIP NOT ACTIVE, >0=SHIP EXPLODING, -1=SHIP ALIVE
SHOTTM:	BLOCK	MAXSHP		;TORPEDO RELOAD TIME
TALLY:	BLOCK	MAXSHP

CLRS:	BLOCK	MAXSHP*2*40.	;STORAGE BUFFER FOR EACH SHIP ON THE TV

	RADIX	2
SUN:	000000000000000000000000000000000000	;A TYPICAL SUN
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000001000010000000000000000
	000000000000001000100000000000000000
	000000000000100101000111000000000000
	000000000000010110111000000000000000
	000000000000001111000000000000000000
	000000000000001110110000000000000000
	000000000000111010001000000000000000
	000000000011010001000000000000000000
	000000000000100000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000
	000000000000000000000000000000000000


	RADIX 1000

SIN:	BLOCK	512.		;SINEWAVE TABLE, 512. ENTRIES, TO +/-255.

STACK:	BLOCK	20		;STACK AREA, OBVIOUSLY

OBJLEN:	0			;OBJCL POINTER
OBJCL:	BLOCK	MAXOBJ		;STORAGE AREA FOR TORPEDOS

SHPBFR:	BLOCK	32.*MAXSHP*NDIREC

EOM1:	SIXBIT/EOM1/		;A KLUDGE

;THEN COMES THE TV AREA STARTING AT PAGE 12

	END	ST
