/ EDIT #23
/
/ COPYRIGHT 1969, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/ EXECUTE V1A             26 JAN 70             H. KREJCI
/
/ EXECUTE IS WRITTEN TO RUN AS A RELOCATABLE SYSTEM PROGRAM
/ ON A PDP-15 UNDER THE KEYBOARD MONITOR.  DEFINING THE FOLLOWING
/ PARAMETERS WILL CONDITIONIALIZE EXECUTE FOR OTHER ENVIRONMENTS.
/
/ PDP9=0	PDP-9
/ BF=0	B/F MONITOR
/ PTP=0	I/O (PAPER TAPE) MONITOR
/	WHEN ASSEMBLING FOR A PAPER TAPE MONTIOR, THE SYSTEM
/	CORE SIZE MUST BE SPECIFIED AS FOLLOWS.
/	FOR A PDP-15, DEFINE:
/	PAGE=N	WHERE N IS ONE LESS THAN THE NUMBER OF 4K PAGES
/	FOR A PDP-9, DEFINE:
/	BANK=N	WHERE N IS ONE LESS THAN THE NUMBER OF 8K PAGES
/
	.IFDEF	PTP
	.ABS
	.IFUND	PDP9
	.IFUND	PAGE
	.END	ERR -- PAGE MUST BE DEFINED
	.ENDC
	.LOC	2510
	.ENDC
	.IFDEF	PDP9
	.IFUND	BANK
	.END	ERR -- BANK MUST BE DEFINED
	.ENDC
	.LOC	2501
	.ENDC
	.ENDC
/
	.IFDEF	BF
BFM=0
	.ENDC
/
.SCOM=100
/
	.IFUND	SCOM20	/FOR INTERIM DISPLACEMEMT OF
SCOM20=.SCOM+20		/.SCOM+20 (UNTIL .DAT-15 IS MOVED)
	.ENDC
TO=-3
ID=-4
/
INPBUF=.		/BEGINNING OF 34 (DEC) WORD BUFFER
/
MES1	.ASCII	/-----EXECUTE V2A/<15>
/
/ INITIAL ENTRY
/
EXECUT	.INIT	TO,1,EXIT		/EXIT IF ^P TYPEIN
	JMS	TYPE		/TYPE NAME & VERSION NUMBER
	MES1
INIT	.INIT	ID,0,0		/INITIALIZE INPUT DEVICE HANDLER,0
	LAC	INIT+3		/SET "FODIND" IF FILE-ORIENTED
	AND	(700)		/DEVICE (BUFSIZE>63)
	DAC	FODIND
	.IFDEF	PDP9		/SET "TOPADR" TO HIGHEST ADDRESS
	CLA			/(IGNORE BOOTSTRAP, CHAIN HAS 
	.ENDC			/AVOIDED IT)
	.IFUND	PDP9
	LAC*	(SCOM20)
	.ENDC
	RAL
	LAC*	(.SCOM+3)
	AND	(070000)
	XOR	(007777)
	SZL			/EXTRA 4K IF PDP-15 AND
	TAD	(010000)		/.SCOM+20 BIT-0 IS SET
	DAC	TOPADR
	.IFUND	BFM		/MOVE XCT FILE NAME TO
	LAC	(.SCOM+7)		/SKDATA & SKDATA+1
	.ENDC
	.IFDEF	BFM		/ENVIRONMENT	LOCATION
	LAC*	(.SCOM+26)	/ KYBD MON	 .SCOM+7
	RCL			/ FOREGROUND	.SCOM+107
	TAD*	(.SCOM+26)	/ BACKGROUND	.SCOM+112
	TAD	(.SCOM+107)
	.ENDC
	DAC	TEMP1
	LAC*	TEMP1
	DAC	SKDATA
	ISZ	TEMP1
	LAC*	TEMP1
	DAC	SKDATA+1
/
	JMS	FIND		/FIND LINK #377777 (XCT FILE)
	ISZ	SKDATA+2		/CHANGE EXTENSION FROM XCT TO XCU
/
	.IFUND	BFM		/CHECK FOR PROPER ENVIRONMENT AND
				/SET .SCOM+3 UNLESS B/F MONITOR.
	LAC	INPBUF+12		/BIT-17  0:BGD::1:FGD
	RTR			/BIT-16  0:PDP-15::1:PDP-9
	SPA
	JMP	CNTRUN		/CAN'T RUN (FGD)
	.IFDEF	PDP9
	SNL
	.ENDC
	.IFUND	PDP9
	SZL
	.ENDC
	JMP	CNTRUN		/CAN'T RUN (WRONG MACHINE)
/
	LAC	INPBUF+11		/CAN CHAIN FIT IN AVAILABLE CORE?
	JMS	TWC
	TAD	TOPADR
	SPA
	JMP	CNTFIT		/CAN'T FIT
	LAC*	(.SCOM+2)
	JMS	TWC
	TAD	INPBUF+10
	SPA
	JMP	CNTFIT		/CAN'T FIT
	LAW	-1		/SET .SCOM+3
	TAD	INPBUF+10
	DAC*	(.SCOM+3)
	.ENDC
/
	LAC	INPBUF+4		/RECORD BASE OF BLANK COMMON
	DAC	COMMON
	LAC	INPBUF+5		/SAVE MAIN PROG ENTRY
	DAC	LTBX1
	LAC	INPBUF+6		/RECORD BOUNDS OF LINK TABLE
	DAC	LTBBSE
	LAC	INPBUF+7
	DAC	LTBTOP
	SAD	LTBBSE		/DON'T LOAD A LINK TABLE IF ZERO
	JMP	LRES		/LENGTH (RESIDENT CODE ONLY)
	JMS	LOAD		/LOAD LINK TABLE
	LAC	LTBTOP		/SETUP 'JMS* (EXU)' INSTRUCTION
	AND	MASK1
	XOR	(120000)
	DAC	JMSEXU
	LAC	(EXU)		/SET TRANSFER VECTOR TO EXECUTE
	DAC*	LTBTOP		/AT TOP OF LINK TABLE
LRES	DZM	LNKNUM		/LOAD RESIDENT CODE
	JMS	FIND
	JMS	LOAD
	JMP*	LTBX1		/TO MAIN PROGRAM
/
/ ENTER HERE WHENEVER A NON-RESIDENT SUBROUTINE IS CALLED
/
EXU	0
	RAR			/SAVE AC EXTENSION (NORMALLY CALLED
	DAC	ACEBUF		/LINK)
	LAC	EXU		/SAVE RETURN POINT IN LINK TABLE
	TAD	(-1)		/AND FETCH THE LINK NUMBER, MIN
	DAC	TOLINK		/ADDRESS, AND MAX ADDRESS OF THE LINK
	TAD	(006)		/TO BE LOADED
	DAC	BUFX
	JMS	GETW
	DAC	LNKNUM
	JMS	GETW
	DAC	MINADR
	DAC	TEMP1
	JMS	GETW
	DAC	MAXADR
	DZM*	TEMP1		/CLEAR LINK'S CORE
	LAC	TEMP1
	SAD	MAXADR
	JMP	.+3
	ISZ	TEMP1
	JMP	.-5
	JMS	FIND		/LOAD LINK
	JMS	LOAD
	LAC	LTBBSE
	DAC	LTBX1
LTBSCN	LAC	LTBX1		/SCAN LINK TABLE FOR ENTRIES FOR
	SAD	LTBTOP		/THE LINK JUST LOADED AND FOR ENTRIES
	JMP	RSACE		/FOR LINKS THAT HAVE BEEN OVERLAYED
	TAD	(010)
	DAC	LTBX2
	TAD	(003)
	DAC	LTBX1
	LAC*	LTBX2		/TEST FOR ENTRY FOR JUST LOADED LINK
	SAD	LNKNUM
	JMP	LTBSN1
	ISZ	LTBX2
	LAC	MAXADR		/LINK NOT OVERLAYED IF ITS MINADR
	JMS	TWC		/IS GREATER THAN MAXADR OF THE LINK
	TAD*	LTBX2		/JUST LOADED
	ISZ	LTBX2
	SMA!SZA
	JMP	LTBSCN
	LAC*	LTBX2		/LINK IS NOT OVERLAYED IF ITS MAXADR
	JMS	TWC		/IS LESS THAN THE MINADR OF THE LINK
	TAD	MINADR		/JUST LOADED
	SMA!SZA
	JMP	LTBSCN
/
	LAC	LTBX2		/ENTRY FOR OVERLAYED LINK, SET THE
	TAD	(-10)		/SECOND WORD TO: JMS* (EXU)
	DAC	LTBX2
	LAC	JMSEXU
	DAC*	LTBX2
	JMP	LTBSCN
/
LTBSN1	LAC	LTBX2		/ENTRY FOR THE LINK JUST LOADED,
	TAD	(-6)		/SET THE SECOND WORD TO: LAC .-2
	DAC	LTBX2
	TAD	(-2)
	AND	MASK1
	XOR	(200000)
	DAC*	LTBX2
	JMP	LTBSCN
/
RSACE	LAC	ACEBUF		/RESTORE AC EXTENSION AND
	RAL			/GO TO NEWLY LOADED LINK
	JMP*	TOLINK
/
/ FIND--SUBROUTINE TO FIND THE LINK WHOSE NUMBER IS IN "LNKNUM"
/
FIND	0
	LAC	LNKNUM		/HAS REQUIRED LINK BEEN PASSED?
	JMS	TWC
	TAD	PRVNUM
	SPA
	JMP	FINSP		/NO -- READ THRU FILE FOR REQUIRED LINK
	LAC	FODIND		/YES -- FILE-ORIENTED DEVICE?
	SZA
	JMP	RWD		/YES -- "REWIND"
	JMS	WFCP		/NO -- TYPE "LD & ^P" AND 
				/      WAIT FOR ^P TYPEIN
	JMP	FINSP		/FILE RELOADED, READ THRU
				/FILE FOR REQ'D LINK
/
RWD	.CLOSE	ID		/YES -- RETURN TO BEGINING OF FILE
	.SEEK	ID,SKDATA
FINSP	LAC	LNKNUM
	DAC	PRVNUM
FINRD	JMS	READ		/READ RECORD
	LAC	(100000)		/CODE-ONE RECORD?
	JMS	CODCHK
	JMP	FINRD		/NO--READ NEXT RECORD
	LAC	INPBUF+3		/YES--IS THIS THE REQUESTED LINK?
	SAD	LNKNUM
	JMP*	FIND		/YES--EXIT WITH LINK NUMBER IN AC
	JMP	FINRD		/NO--READ NEXT RECORD
/
/ LOAD--SUBROUTINE TO LOAD A LINK FOUND BY "FIND"
/
LOAD	0
LDRD	JMS	READ		/READ A RECORD
	LAC	(200000)		/CONTIGUOUS BLOCK (CODE 2) REC?
	JMS	CODCHK
	JMP	LDPT1		/NO--ASSUME PATCH (CODE 3) RECORD
	LAC	(INPBUF+2)	/YES--LOAD CONTIGUOUS BLOCK (S)
	DAC	BUFX
LDCB1	JMS	GETW		/GET SUB-RECORD HEADER
	SPA			/END OF RECORD?
	JMP	LDRD		/YES--READ NEXT RECORD
	AND	(077777)		/NO--SET BLOCK SIZE COUNT
	JMS	TWC
	DAC	CNT1
	JMS	GETW		/GET ADDRESS OF FIRST WORD IN BLOCK
	DAC	ADDR
	JMS	GETW		/GET-WORD/STORE-WORD THRU BLOCK
	JMS	STOW
	ISZ	CNT1
	JMP	.-3
	JMP	LDCB1		/TO NEXT SUB-RECORD
LDPT1	JMS	TWC		/PATCH RECORD FOUND--SAVE TOTAL
	SNA			/NUMBER OF PATCHES COUNT
	JMP*	LOAD		/EXIT IF ZERO
	DAC	CNT2
	JMP	LDPT3
LDPT2	JMS	READ		/READ RECORD
LDPT3	LAC	INPBUF+3		/SET COUNT OF PATCHES THIS RECORD
	JMS	TWC
	DAC	CNT1
	LAC	(INPBUF+4)
	DAC	BUFX
LDPT4	JMS	GETW		/GET ADDRESS & PATCH CODE
	DAC	ADDR
	AND	(700000)
	SNA
	JMP	LDPT5
	SAD	(100000)
	JMP	LDPT6
	JMS	GETW		/PATCH CODE = 2 -- ADD BASE OF
	TAD	COMMON		/BLANK COMMON TO WORD AND
	JMP	LDPT7		/STORE WORD
LDPT5	JMS	GETW		/PATCH CODE = 0 -- STORE WORD
	JMP	LDPT7
LDPT6	JMS	GETW		/PATCH CODE = 1 -- REPLACE ADDRESS
	DAC	TEMP1		/FIELD AT ADDR
	LAC*	ADDR
	AND	MASK2
	XOR	TEMP1
LDPT7	DAC*	ADDR
	ISZ	CNT2		/EXIT IF ALL PATCHES HAVE BEEN MADE
	SKP
	JMP*	LOAD
	ISZ	CNT1		/END OF RECORD?
	JMP	LDPT4		/NO--NEXT PATCH
	JMP	LDPT2		/YES--NEXT RECORD
/
GETW	0
	LAC*	BUFX
	ISZ	BUFX
	JMP*	GETW
/
STOW	0
	DAC*	ADDR
	ISZ	ADDR
	JMP*	STOW
/
/ CODCHK--SUBROUTINE TO COMPARE AC BITS 0-2 WITH
/	 THE INPUT RECORD CODE (BITS 0-2 OF INPBUF+2)
/	 MATCH -- RETURN AT JMS+2
/	 MISMATCH -- RETURN AT JMS+1
/
CODCHK	0
	XOR	INPBUF+2
	AND	(700000)
	SNA
	ISZ	CODCHK
	LAC	INPBUF+2
	AND	(077777)
	JMP*	CODCHK
/
/ TWC -- SUBROUTINE TO REPLACE AC WITH ITS TWO'S COMPLIMENT
/
TWC	0
	CMA
	TAD	(001)
	JMP*	TWC
/
/ READ -- SUBROUTINE TO READ A RECORD -- EXIT TO MONITOR IF ERROR
/
READ	0
READ1	.READ	ID,0,INPBUF,34
	.WAIT	ID
	LAC	INPBUF
	AND	(77)
	SNA
	JMP*	READ		/NORMAL READ -- RETURN
/				/ABNORMAL READ -- TEST FOR
/				/EOF, EOM, OR ERR.
	SAD	(05)
	JMP	READ1		/EOF -- IGNORE, READ NEXT RECORD
	AND	(57)
	SAD	(06)
	JMP	READ2		/EOM -- WAIT FOR ^P, READ NEXT RECORD
	JMS	TYPE		/READ ERROR -- EXIT TO MONITOR
	MES5-2
EXIT	.EXIT			/EXIT TO MONITOR
READ2	JMS	WFCP		/EOM -- TYPE "LD & ^P", WAIT
	JMP	READ1		/FOR ^P TYPEIN, AND READ AGAIN
/
/ WFCP -- SUBROUTINE TO TYPE "LD & ^P" AND WAIT FOR ^P TYPEIN
/
WFCP	0
	.INIT	TO,1,CPTD		/TO "CPTD" IF ^P TYPEIN
	LAC	LNKNUM		/TYPE "LD [---] & ^P"
	DAC	TEMP2
	JMS	LS4
	AND	(000160)
	XOR	(301413)
	DAC	MES2+2
	JMS	LS4
	AND	(034000)
	XOR	MES2+2
	DAC	MES2+2
	JMS	LS4
	RTL
	AND	(000016)
	XOR	(055540)
	DAC	MES2+1
	JMS	TYPE
	MES2-2
	JMP	.		/WAIT FOR ^P TYPEIN
	/^P TYPED IN
CPTD	.INIT	TO,1,EXIT		/RTN CAR & EXIT IF ^P TYPEIN
	JMP*	WFCP
/
LS4	0
	LAC	TEMP2
	RTL
	RTL
	DAC	TEMP2
	JMP*	LS4
/
	.IFUND	BF
CNTRUN	JMS	TYPE		/TYPE "CAN'T RUN" & EXIT
	MES3-2
	JMP	EXIT
/
CNTFIT	JMS	TYPE		/TYPE "CAN'T FIT" & EXIT
	MES4-2
	JMP	EXIT
	.ENDC
/
/ TYPE -- SUBROUTINE TO TYPE A MESSAGE
/
TYPE	0
	LAC*	TYPE
	DAC	.+3
	.WRITE	TO,2,XX,0
	.WAIT	TO
	ISZ	TYPE
	JMP*	TYPE
/
MES2	.ASCII	/LD [000] & ^P /<175>
	.IFUND	BFM
MES3	.ASCII	/CAN'T RUN/<015>
MES4	.ASCII	/CAN'T FIT/<015>
	.ENDC
MES5	.ASCII	/READ ERR/<015>
SKDATA	.SIXBT	/------XCT/
LNKNUM	377777			/LINK NUMBER
PRVNUM	377777			/PREVIOUS LINK
COMMON	0			/BASE ADDRESS OF BLANK COMMON
LTBTOP	0			/TOP OF LINK TABLE (LTB)
LTBBSE	0			/BASE OF LTB
LTBX1	0			/LTB INDEX
LTBX2	0			/LTB INDEX
TEMP1	0
TEMP2	0
MINADR	0			/MIN ADR OF LINK BEING LOADED
MAXADR	0			/MAX ADR OF LINK BEING LOADED
TOPADR	0			/TOP ADDRESS
FODIND	0			/FILE-ORIENTED DEVICE IND
ACEBUF	0			/AC EXTENSION BUFFER
TOLINK	0			/TRANS VECTOR TO LINK TABLE (TO LINK)
JMSEXU	0			/JMS* (EXU) INSTRUCTION
	.IFDEF	PDP9
MASK1	017777
MASK2	760000
	.ENDC
	.IFUND	PDP9
MASK1	007777
MASK2	770000
	.ENDC
ADDR	0
CNT1	0
CNT2	0
BUFX	0
/
	.IFDEF	PTP
	.IFUND	PDP9
	.END	PAGE+1/2*2-1*10000+7720
	.ENDC
	.IFDEF	PDP9
	.END	BANK*20000+17720
	.ENDC
	.ENDC
	.IFUND	PTP
	.END	EXECUT
	.ENDC
