	.TITLE RESMON
 
/ .... EDIT #26 .... 2 JUN 70
 
/	COPYRIGHT 1969, 1970 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/	PDP-9
/	BACKGROUND/FOREGROUND MONITOR SYSTEM
/	RESIDENT MONITOR.
/
/	J.J. MURPHY, JR./D.E. LENEY/J.C. PROTEAU
/	THE CAL HANDLER PROCESSES ALL
/	MONITOR CALLS AND THEN DISPATCHES
/	TO THE APPROPRIATE FUNCTION PROCESSOR
/	IN THE CONTROL MONITOR OR IN AN
/	I/O HANDLER.
/	THE CAL HANDLER FUNCTIONS AT THE
/	HIGHEST SOFTWARE LEVEL IN AN API
/	ENVIRONMENT AND SHOULD NOT BE CALLED
/	(EXCEPT UNDER CONTROLLED CIRCUMSTANCES)
/	FROM ANY HARDWARE LEVEL. ALSO, IT
/	IS PROTECTED SOFTWAREWISE TO PREVENT RE-ENTRY BEFORE THE CAL
/	LEVEL PROCESSING IS COMPLETE.
 
	.ABS
.MED=3
.IOPS=20
.SYSLD=14000		/START & LOAD ADDRESS OF SYSTEM LOADER.
BF9BGN=12000		/START & LOAD ADDRESS OF NON-RES. MONITOR.
BF9BLK=102		/START BLOCK # FOR NON-RES. MONITOR.
IDX=ISZ			/USED WHEN SKIP NOT INTENDED.
SET=ISZ			/USED TO SET REGISTER NON-ZERO.
 
	.EJECT
	.TITLE PARAMS
 
/CONDITIONAL ASSEMBLY PARAMETERS:
 
/	FOR EACH PARAMETER LISTED BELOW, A DEFAULT ASSUMPTION
/	IS MADE IF THE PARAMETER IS NOT DEFINED OR IF IT IS DEFINED
/	WITH AN ILLEGAL VALUE.
/	PARAMETERS FOR THE RESIDENT SYSTEM DEVICE HANDLER
/	(DTA. OR DKA.) ARE NOT LISTED BELOW.
 
/ 1.	TYPE OF SYSTEM: IF 'DK' IS DEFINED, THE SYSTEM DEVICE IS AN
/	RB09 DISK. OTHERWISE, THE SYSTEM DEVICE IS DECTAPE.
 
/ 2.	TYPE OF SYSTEM: IF 'PI' IS DEFINED, THE SYSTEM ASSUMES THAT
/	THE MACHINE DOES NOT HAVE API. OTHERWISE, PRESENCE OF API
/	IS ASSUMED.
 
/ 3.	CAPABILITY: IF 'NOAPI' IS DEFINED, THE CODE TO HANDLE API
/	SOFTWARE LEVELS 5,6 AND 7 WILL BE CONDITIONALIZED OUT OF
/	THE SYSTEM. IF 'PI' IS DEFINED, 'NOAPI' IS ASSUMED.
 
	.IFDEF PI
NOAPI=0			/NO NEED FOR API SOFTWARE LEVELS.
	.ENDC
 
/ 4.	CORE SIZE: IF 'BANK'=1,2 OR 3, CORE SIZE IS 16K,24K OR 32K,
/	RESPECTIVELY. IF BANK IS UNDEFINED OR IF IT IS DEFINED AS
/	OTHER THAN 1,2 OR 3, BANK=1 IS ASSUMED.
 
	.IFUND BANK
BANK=1
	.ENDC
	.IFNZR BANK-1
	.IFNZR BANK-2
	.IFNZR BANK-3
BANK=1
	.ENDC
	.ENDC
	.ENDC
 
	.EJECT
/ 5.	.SCOM+4 (CONFIGURATION WORD): BITS IN .SCOM+4 ARE CONDITIONALLY
/	ASSEMBLED IN. 'CHAN9', IF DEFINED, SPECIFIES 9-CHANNEL
/	MAGTAPE. IF UNDEFINED, 7-CHANNEL IS ASSUMED. IF 'DRUM' IS
/	UNDEFINED, NO DRUM IS ASSUMED. IF DRUM=1,2,3,4 OR 5, THE DRUM
/	SIZE IS 32K,65K,131K,262K OR 524K, RESPECTIVELY. IF DRUM IS
/	DEFINED BUT NOT = 1,2,3,4 OR 5, NO DRUM IS ASSUMED.
 
SCOM4=201010		/EAE, NO ^QAREA AND B/F (SEE .SCOM+4).
	.IFUND PI
SCOM4=SCOM4+400000		/ADD 'API' BIT.
	.ENDC
	.IFDEF CHAN9
SCOM4=SCOM4+4000		/ADD '9-CHANNEL' BIT.
	.ENDC
	.IFUND DRUM
DRUM=0
	.ENDC
	.IFNEG DRUM
DRUM=0
	.ENDC
	.IFNEG 5-DRUM
DRUM=0
	.ENDC
SCOM4=SCOM4+DRUM		/"NO DRUM" OR "DRUM SIZE" BITS.
 
/ 6.	SIZE OF .IOIN TABLE: EACH ENTRY REQUIRES 2 WORDS. THE
/	MINIMUM NUMBER OF ENTRIES ALLOWED IS 14. IF 'IOINSZ'
/	IS UNDEFINED, IOINSZ=30 IS ASSUMED, MEANING 30 ENTRIES.
/	IF IOINSZ IS DEFINED LESS THAN 14, IOINSZ=14 IS ASSUMED.
 
	.IFUND IOINSZ
IOINSZ=30			/30 OCTAL ENTRIES.
	.ENDC
	.IFNEG IOINSZ-14
IOINSZ=14			/14 ENTRIES MINIMUM.
	.ENDC
 
/ 7.	SIZE OF 339 PUSHDOWN LIST: EACH ENTRY RQUIRES 1 WORD. IF
/	'PDLSIZ' IS UNDEFINED, PDLSIZ=30 IS ASSUMED. IF PDLSIZ
/	IS DEFINED LESS THAN 1, PDLSIZ=1 IS ASSUMED. IF PDLSIZ
/	IS DEFINED GREATER THAN 100, PDLSIZ=100 IS ASSUMED.
 
	.IFUND PDLSIZ
PDLSIZ=30
	.ENDC
	.IFNEG PDLSIZ-1
PDLSIZ=1
	.ENDC
	.IFPNZ PDLSIZ-100
PDLSIZ=100
	.ENDC
 
	.EJECT
/ 8.	SIZE OF .BFTAB: EACH ENTRY REQUIRES 2 WORDS. THE MINIMUM
/	NUMBER OF ENTRIES ALLOWED IS 10. IF 'BFTBSZ' IS UNDEFINED,
/	BFTBSZ=20 IS ASSUMED. IF BFTBSZ IS DEFINED LESS THAN 10,
/	BFTBSZ=10 IS ASSUMED. IF BFTBSZ IS DEFINED GREATER THAN
/	30, BFTBSZ=30 IS ASSUMED.
 
	.IFUND BFTBSZ
BFTBSZ=20
	.ENDC
	.IFNEG BFTBSZ-10
BFTBSZ=10
	.ENDC
	.IFPNZ BFTBSZ-30
BFTBSZ=30
	.ENDC
 
/ 9.	SIZE OF CLOCK QUEUE: EACH ENTRY REQUIRES 2 WORDS. THE
/	MINIMUM NUMBER OF ENTRIES ALLOWED IS 2. IF 'CLKQSZ' IS
/	UNDEFINED, CLKQSZ=5 IS ASSUMED. IF CLKQSZ IS DEFINED
/	LESS THAN 2, CLKQSZ=2 IS ASSUMED. IF CLKQSZ IS DEFINED
/	GREATER THAN 30, CLKQSZ=30 IS ASSUMED.
 
	.IFUND CLKQSZ
CLKQSZ=5
	.ENDC
	.IFNEG CLKQSZ-2
CLKQSZ=2
	.ENDC
	.IFPNZ CLKQSZ-30
CLKQSZ=30
	.ENDC
 
/ 10.	SIZE OF API LEVEL 4 QUEUE: EACH ENTRY REQUIRES 1 WORD. THE
/	MINIMUM NUMBER OF ENTRIES ALLOWED IS 4. IF 'LV4QSZ' IS
/	UNDEFINED, LV4QSZ=4 IS ASSUMED. IF LV4QSZ IS DEFINED LESS
/	THAN 4, LV4QSZ=4 IS ASSUMED. IF LV4QSZ IS DEFINED GREATER
/	THAN 10, LV4QSZ=10 IS ASSUMED.
 
	.IFUND LV4QSZ
LV4QSZ=4
	.ENDC
	.IFNEG LV4QSZ-4
LV4QSZ=4
	.ENDC
	.IFPNZ LV4QSZ-10
LV4QSZ=10
	.ENDC
 
	.EJECT
/ 11.	SIZE OF API QUEUE: EACH ENTRY REQUIRES 1 WORD. THE MINIMUM
/	NUMBER OF ENTRIES ALLOWED IS 6. IF 'NOAPI' IS DEFINED, THE
/	API QUEUE IS CONDITIONALIZED OUT OF THE SYSTEM. IF 'APIQSZ'
/	IS UNDEFINED, APIQSZ=14 IS ASSUMED. IF APIQSZ IS DEFINED
/	LESS THAN 6, APIQSZ=6 IS ASSUMED. IF APIQSZ IS DEFINED
/	GREATER THAN 40, APIQSZ=40 IS ASSUMED.
 
	.IFUND APIQSZ
APIQSZ=14
	.ENDC
	.IFNEG APIQSZ-6
APIQSZ=6
	.ENDC
	.IFPNZ APIQSZ-40
APIQSZ=40
	.ENDC
 
/ 12.	SIZE OF TRANSFER VECTOR TABLE AND ASSOCIATED IOT SKIP LITERAL
/	TABLE: BOTH TABLES ARE THE SAME SIZE. THE MINIMUM SIZE OF
/	EACH IS 20. IF 'TVSIZE' IS UNDEFINED, TVSIZE=24 IS ASSUMED.
/	IF TVSIZE IS DEFINED LESS THAN 20, TVSIZE=20 IS ASSUMED.
/	IF TVSIZE IS DEFINED GREATER THAN 40, TVSIZE=40 IS ASSUMED.
 
	.IFUND TVSIZE
TVSIZE=24
	.ENDC
	.IFNEG TVSIZE-20
TVSIZE=20
	.ENDC
	.IFPNZ TVSIZE-40
TVSIZE=40
	.ENDC
 
	.EJECT
/ 13.	SIZE OF FOREGROUND AND BACKGROUND NON-TERMINAL ERROR QUEUES:
/	EACH ENTRY REQUIRES 2 WORDS. BOTH QUEUES WILL BE THE SAME
/	SIZE. THE MINIMUM NUMBER OF ENTRIES IS 2. IF 'ERRQSZ' IS
/	UNDEFINED, ERRQSZ=2 IS ASSUMED. IF ERRQSZ IS DEFINED LESS
/	THAN 2, ERRQSZ=2 IS ASSUMED. IF ERRQSZ IS DEFINED GREATER
/	THAN 20, ERRQSZ=20 IS ASSUMED.
 
	.IFUND ERRQSZ
ERRQSZ=2
	.ENDC
	.IFNEG ERRQSZ-2
ERRQSZ=2
	.ENDC
	.IFPNZ ERRQSZ-20
ERRQSZ=20
	.ENDC
 
/ 14.	# OF TTY'S ON MACHINE: IF 'TTYS' IS UNDEFINED, TTYS=6 IS
/	ASSUMED. IF TTYS IS DEFINED LESS THAN 2, TTYS=2 IS
/	ASSUMED. IF TTYS IS DEFINED GREATER THAN 21, TTYS=21 IS
/	ASSUMED. THIS PARAMETER AFFECTS REGISTERS RESERVED FOR
/	TTY UNITS IN THE TELETYPE HANDLER.
 
	.IFUND TTYS
TTYS=6
	.ENDC
	.IFNEG TTYS-2
TTYS=2
	.ENDC
	.IFNEG 21-TTYS
TTYS=21
	.ENDC
 
/ 15.	KEYBOARD INPUT RING BUFFER SIZE: THE MINIMUM SIZE, AT 1
/	WORD PER ENTRY, IS THE NUMBER OF TTYS TIMES 2. IF 'KBDRSZ'
/	IS UNDEFINED, KBDRSZ=TTYS*3 IS ASSUMED. IF KBDRSZ IS
/	DEFINED LESS THAN TTYS*2, KBDRSZ=TTYS*2 IS ASSUMED.
 
	.IFUND KBDRSZ
KBDRSZ=TTYS*3
	.ENDC
	.IFPNZ TTYS*2-KBDRSZ
KBDRSZ=TTYS*2
	.ENDC
 
	.EJECT
	.TITLE LAYOUT
 
/PHYSICAL LAYOUT OF RESMON.
 
/ 1.	.SCOM REGISTERS
/ 2.	.IOIN TABLE
/ 3.	.DATF TABLE
/ 4.	.DATB TABLE
/ 5.	.PD339 TABLE
/ 6.	CAL ENTRY DISPATCHER
/ 7.	.IDLE PROCESSOR
/ 8.	.RLXIT PROCESSOR
/ 9.	CALMSG ERROR PRINTER
/ 10.	GETBUF SUBR.
/ 11.	.BFTAB TABLE
/ 12.	RESBUF (RESIDENT SYSTEM DEVICE BUFFER: CONTAINS MONITOR
/		INITIALIZATION CODE WHICH SETS UP REGISTERS 0-77
/		AND CONTAINS TABLES WITH DEVICE AND IOT SKIP NAMES
/		ASSOCIATED WITH THE INTERRUPT TRANSFER VECTORS)
/ 13.	LOAD BFKM9 ROUTINE
/ 14.	.TIMER PROCESSOR
/ 15.	CLOCKQ
/ 16.	CLOCK INTERRUPT SERVICE
/ 17.	I/O CAL DISPATCHER
/ 18.	CALXIT
/ 19.	.WAIT & .WAITR PROCESSOR
/ 20.	.ERROR CAL PROCESSOR
/ 21.	.EXIT PROCESSOR
/ 22.	NEWBGD (NEW BGD JOB)
/ 23.	NEWFGD (NEW FGD JOB)
/ 24.	.BOOT (RESIDENT BOOTSTRAP LOADER)
/ 25.	GETARGS SUBR. FOR I/O DISPATCHER
/ 26.	API LEVEL 4 INTERRUPT SERVICE
/ 27.	IOBUSY SUBR.
/ 28.	REALTP SUBR.
/ 29.	CALL4 SUBR.
/ 30.	API LEVEL 5 INTERRUPT SERVICE
/ 31.	ENTERQ SUBR.
/ 32.	APIQ
/ 33.	GETQ SUBR.
/ 34.	API LEVEL 6 INTERRUPT SERVICE
/ 35.	API LEVEL 7 INTERRUPT SERVICE
/ 36.	MEMORY PROTECT VIOLATION PROCESSOR
/ 37.	TRANSFER VECTOR TABLE & ASSOCIATED IOT SKIP LITERAL TABLE
/ 38.	.IOSK (PI IOT SKIP CHAIN)
/ 39.	.SETUP SUBR.
/ 40.	FERQUE (FGD ERROR QUEUE)
/ 41.	BERQUE (BGD ERROR QUEUE)
/ 42.	ERRORQ SUBR.
/ 43.	FGDERR SUBR.
/ 44.	^Q PROCESSOR.
/ 45.	BGDERR SUBR.
/ 46.	TTA. (MULTIUNIT TELETYPE HANDLER)
/ 47.	SYSTEM DEVICE HANDLER (DTA. OR DKA.)
 
	.EJECT
	.TITLE .SCOMS
 
/SYSTEM COMMUNICATION TABLE (.SCOM) FOR
/	BACKGROUND/FOREGROUND MONITOR SYSTEM
/	<F> MEANS FIXED
/	<S> MEANS SWAPPED FOR BGD AND FGD
/	<U> MEANS UNUSED OR UNSPECIFIED
/	<V> MEANS VARIABLE
 
	.LOC	100
.SCOM	BANK*20000+17777	/<F>	/(0)HIGHEST CORE ADDRESS
	.SIZE		/<S>	/(1)REGISTER ABOVE RESIDENT
				/MONITOR(IN FGD)-USED BY LINK LOADER
				/DDT AND PIP.
	.SIZE		/<S>	/(2)LOWEST FREE REGISTER.
	.SYSLD-1		/<S>	/(3)HIGHEST FREE REGISTER.
	SCOM4			/(4)CONFIGURATION WORD
			/<F>	/(BIT0)0 IF NO API,1 IF API
			/<F>	/(BIT1)0 IF NO EAE, 1 IF EAE
				/IF NO EAE, THIS BIT CLEARED
				/DURING MONITOR INITIALIZATION.
			/<F>	/(BITS 2-5) RESERVED.
			/<V>	/(BIT6) 0 IF 7 CHANNEL MAGTAPE,
				/1 IF 9 CHANNEL MAGTAPE
			/<F>	/(BIT7) 0 MEANS BANK MODE ADDRESSING
				/(8K, IMPLYING PDP-9 MODE).
			/<F>	/(BIT8) 1 MEANS NO ^Q AREA ON
				/UNIT 0 OF THE SYSTEM DEVICE.
			/<U>	/(BITS9-13) UNASSIGNED
			/<F>	/(BIT14) 1 MEANS BGD/FGD SYSTEM.
			/<F>	/(BITS15-17) 0=NO DRUM.
				/1=32K DRUM. 2=65K DRUM.
				/3=131K DRUM. 4=262K DRUM.
				/5=524K DRUM.
	RESINT		/<V>	/(5) INITIALLY POINTS TO MONITOR
				/INITIALIZATION ROUTINE, TRANSFERRED
				/TO BY THE PAPERTAPE BOOTSTRAP.
				/SYSTEM LOADER CODE WORD
				/AND SYSTEM PROGRAM START
	0		/<V>	/(6)LINK LOADER AND DDT CODE
		 		/WORD AND USER PROGRAM START
				/(BIT0)0 IS LINK LOADER,1 IS
				/DDT OR DDTNS
				/(BIT1)0 IS WAIT 1 IS GO(GLOAD)
				/(BIT2)0 IS LOAD SYMBOL TABLE,
				/1 IS NO SYMBOLS
	0		/<V>	/(7)L,XM,MP+PC SAVED ON ^T.
	0		/<S>	/(10)L,XM,MP+PC SAVED ON ^P.
	JMP .BOOT		/<F>	/(11) BOOTSTRAP RESTART LOCATION.
	.PD339		/<F>	/(12)339 PUSH-DOWN LIST POINTER.
	.IOIN		/<F>	/(13)POINTER TO I/O IN CORE
				/TABLE.
	0		/<F>	/(14)POINTER TO MULTI - UNIT
				/DEVICE TABLE -
				/BUILT BY NON-RESMON BEFORE
				/STARTING IN FOREGROUND.
	.BFTAB		/<F>	/(15)POINTER TO BUFFER TABLE
	.DATF		/<F>	/(16)POINTER TO FOREGROUND DEVICE
				/ASSIGNMENT TABLE.
	.DATB		/<F>	/(17)POINTER TO BACKGROUND DEVICE
				/ASSIGNMENT TABLE.
	0		/<U>	/(20)RESERVED FOR PDP-15.
	0		/<U>	/(21)UNUSED.
	0		/<V>	/(22)MAGTAPE CONTINUE AFTER DELAY.
	-TVSIZE		/<F>	/(23)2'S COMPLEMENT SIZE OF THE
				/TRANSFER VECTOR TABLE (FOR .SGEN).
	.TVTAB		/<F>	/(24)POINTER TO TRANSFER VECTOR TABLE.
	17777		/<V>	/(25)MUST INITIALLY CONTAIN AN ADDRESS
				/HIGHER THAN THAT OF THE .SETUP CALL IN
				/THE RESIDENT SYSTEM DEVICE HANDLER SO
				/THAT THE TRANSFER VECTOR(S) WILL BE
				/ASSIGNED TO FOREGROUND. LATER, USED AS
				/FREE CORE REQUIREMENT FOR FOREGROUND
				/(>=2), THEN FIRST FREE REGISTER
				/ABOVE FOREGROUND JOB
	0		/<S>	/(26)RUNNING MODE. 0 IS
				/FOREGROUND, 1 IS BACKGROUND.
	.SKTAB		/<F>	/(27)POINTER TO SKIP LITERAL TABLE.
	.IOSK		/<F>	/(30)POINTER TO PI SKIP CHAIN.
	0		/<V>	/(31)SOFTWARE PROTECT BOUND
	0		/<V>	/(32)HARDWARE PROTECT BOUND
	NEWBGD+200000	/<V>	/(33)BACKGROUND PROGRAM COUNTER.
	TTA.		/<F>	/(34)POINTER TO MULTI-UNIT
				/TELETYPE HANDLER
	0		/<V>	/(35)IN INTERRUPT SERVICE
				/ROUTINE FLAG
	0		/<F>	/(36)TELETYPE TAB FLAGS-
				/EACH BIT 0 IF 33, 1 IF 35.
	CALER		/<F>	/(37)POINTER TO CAL* ERROR ROUTINE.
	0		/<V>	/(40)IN CAL ROUTINE FLAG
	0		/<V>	/(41)BACKGROUND PROGRAM
				/(WHICH ONE) RUNNING
				/INDICATOR FOR MEMORY
				/PROTECT VIOLATION PROCESSOR
	0		/<V>	/(42)API LEVEL 5 BUSY REGISTER
	0		/<V>	/(43)API LEVEL 6 BUSY REGISTER
	0		/<V>	/(44)API LEVEL 7 BUSY REGISTER
	0		/<V>	/(45)MAINSTREAM BUSY REGISTER
	0		/<V>	/(46)API LEVEL 5 I/O SATISFIED
				/REGISTER
	0		/<V>	/(47)API LEVEL 6 I/O
				/SATISFIED REGISTER
	0		/<V>	/(50)API LEVEL 7 I/O
				/SATISFIED REGISTER
	REALTP		/<F>	/(51)POINTER TO REAL-TIME PROCESSING
				/ROUTINE.
	IOBUSY		/<F>	/(52)POINTER TO I/O BUSY
				/TESTER.
	LV4Q		/<F>	/(53)POINTER TO API LEVEL 4
				/QUEUE.
	CALL4		/<F>	/(54)POINTER TO SUBROUTINE TO
				/INITIATE LEVEL 4 REQUEST.
	.SETUP		/<F>	/(55)POINTER TO
				/SETUP ROUTINE.
	GETBUF		/<F>	/(56)POINTER TO FETCH
				/BUFFER ROUTINE.
	0		/<V>	/(57) FOREGROUND MAINSTREAM
				/REAL TIME SUBROUTINE
				/POINTERS - FSUBR1
	0		/<V>	/(60) FSUBRN+1
	0		/<V>	/(61) BACKGROUND MAINSTREAM
				/REAL TIME SUBROUTINE
				/POINTERS: BSUBR1
	0		/<V>	/(62) BSUBRN+1
	0		/<V>	/(63) API ISA WORD, 0= NOTHING PENDING
	CR.QR		/<F>	/(64) ENTRY PT OF ^R QUEUER.
	0		/<V>	/(65) FOREGROUND USER FLAG
				/SET TO NON-0 ON EXIT
				/FROM FGRD LOADER.
				/SET TO 0 ON CONTROL C
				/FROM FGRD CONTROL TELETYPE
	ERRORQ		/<F>	/(66) TRANSFER VECTOR TO ENTRY POINT
				/OF ERRORQ ROUTINE.
	FCTL.C		/<F>	/(67) POINTER TO FGRD CONTROL
				/CHAR. TABLE.
	BCTL.C		/<F>	/(70) POINTER TO BGRD CONTROL
				/CHAR. TABLE.
	0		/<V>	/(71) ERROR FLAG.
	FGDERR+200000	/<F>	/(72) ENTRY PT. TO FGRD ERROR ROUTINE
	BGDERR+200000	/<F>	/(73) ENTRY PT. TO BGRD ERROR ROUTINE.
	0		/<V>	/(74) RESTORATION AC FOR ERROR ROUTINE ISA.
	JMS IGNORE	/<F>	/(75) DUMMY API INTERRUPT SERVICE.
	-TTYS		/<F>	/(76) - # OF TELETYPES ON MACHINE.
	0		/<V>	/(77) $SHARE FLAG.  0=DON'T SHARE.
	.IFDEF	NOAPI
	0
	.ENDC
	.IFUND	NOAPI
	ENTERQ		/<F>	/(100) POINTER TO ENTER API QUEUE ROUTINE.
	.ENDC
	0		/<V>	/(101) 0 MEANS MEM. PROT. BOUND
				/IS SET FROM .SCOM+32 (BGD USER
				/MODE). 1 MEANS MEM. PROT. BOUND
				/IS SET TO ZERO, WHICH ALLOWS BGD
				/TO ACCESS ALL OF CORE. BGD IOT'S
				/WILL ALSO BE ALLOWED.
	0		/<U>	/(102) UNUSED.
	0		/<U>	/(103) UNUSED.
	0		/<U>	/(104) UNUSED.
	.IOSK-IOSKND	/<F>	/(105) SIZE OF SKIP CHAIN (NUMBER
				/OF REGISTERS AVAILABLE).
	0		/<F>	/(106) ADDRESS ABOVE MONITOR (FOR
				/CHAIN)(SET UP BY BFKM9).
	0		/<V>	/(107) THREE REGISTERS FOR FILE
	0		/<V>	/(110) NAME AND EXTENSION OF XCT
	0		/<V>	/(111) FILE FOR EXECUTE IN FGD.
	0		/<V>	/(112) THREE REGISTERS FOR FILE
	0		/<V>	/(113) NAME AND EXTENSION OF XCT
	0		/<V>	/(114) FILE FOR EXECUTE IN BGD.
	TTYS		/<F>	/(115) MAX # OF TTYS (FOR .SGEN).
	0		/<V>	/(116) FGD MAGTAPE STATUS
	0		/<V>	/(117) BGD MAGTAPE STATUS
	.EJECT
	.TITLE .IOIN
 
/I/O IN CORE TABLE (.IOIN)
 
.IOIN	-3		/# OF ENTRIES (CURRENT)
	-IOINSZ		/# OF ENTRIES (MAXIMUM)
	-3		/# OF ENTRIES (FGD AND MONITOR)
	.IFUND DK
	4*200+4		/DTA0
	DTA./4+400000
	.ENDC
	.IFDEF DK
	5*200+5		/DKA0
	DKA./4+400000
	.ENDC
FGDCTL	200001		/TTA1
L4HTHO	400000
BGDCTL	200000		/TTA0
	400000
	.BLOCK	IOINSZ-3*2
 
	.EJECT
	.TITLE .DATF
 
	.IFUND DK
 
/FOREGROUND DEVICE ASSIGNMENT TABLE (.DATF)
 
DATFBG	2*20000	4*200+4		/(-15) DTA2
	1*20000	4*200+4		/(-14) DTA1
	2*20000	4*200+4		/(-13) DTA2
	10*200+10			/(-12) LPA
	1*20000	4*200+4		/(-11) DTA1
	6*200+6			/(-10) PRA
	DTA./4+400000		/(-7) DTA0
	3*20000	4*200+4		/(-6) DTA3
	0			/(-5) NONE
	2*20000	4*200+4		/(-4) DTA2
	600001			/(-3) TTA1
	600001			/(-2) TTA1
	4*200+4			/(-1) DTA0
.DATF	DATFND			/POINTS TO END
	3*20000	4*200+4		/(1) DTA3
	4*20000	4*200+4		/(2) DTA4
	5*20000	4*200+4		/(3) DTA5
	200001			/(4) TTA1
	6*200+6			/(5) PRA
	7*200+7			/(6) PPA
	10*200+10			/(7) LPA
	0			/(10) NONE
DATFND	DATFBG			/POINTS TO BEGINNING
 
	.ENDC
	.EJECT
	.IFDEF DK
 
/FOREGROUND DEVICE ASSIGNMENT TABLE (.DATF)
 
DATFBG	6*20000	5*200+5		/(-15) DKA6
	4*20000	5*200+5		/(-14) DKA4
	5*20000	5*200+5		/(-13) DKA5
	10*200+10			/(-12) LPA
	4*20000	5*200+5		/(-11) DKA4
	6*200+6			/(-10) PRA
	DKA./4+400000		/(-7) DKA0
	6*20000	5*200+5		/(-6) DKA6
	0			/(-5) NONE
	5*20000	5*200+5		/(-4) DKA5
	600001			/(-3) TTA1
	600001			/(-2) TTA1
	5*200+5			/(-1) DKA0
.DATF	DATFND			/POINTS TO END
	4*20000	5*200+5		/(1) DKA4
	5*20000	5*200+5		/(2) DKA5
	1*20000	4*200+4		/(3) DTA1
	2*20000	4*200+4		/(4) DTA2
	6*200+6			/(5) PRA
	7*200+7			/(6) PPA
	10*200+10			/(7) LPA
	200001			/(10) TTA1
DATFND	DATFBG			/POINTS TO BEGINNING
 
	.ENDC
	.EJECT
	.TITLE .DATB
 
/BACKGROUND DEVICE ASSIGNMENT TABLE (.DATB)
/INITIALIZED BY THE NON-RESIDENT MONITOR.
 
DATBBG	0			/-15
	0			/-14
	0			/-13
	0			/-12
	0			/-11
	0			/-10
	.IFUND DK
	DTA./4+400000		/(-7) DTA0
	.ENDC
	.IFDEF DK
	DKA./4+400000		/(-7) DKA0
	.ENDC
	0			/-6
	0			/-5
	0			/-4
	600000			/(-3) TTA0
	600000			/(-2) TTA0
	0			/-1
.DATB	DATBND			/POINTS TO END
	0			/1
	0			/2
	0			/3
	0			/4
	0			/5
	0			/6
	0			/7
	0			/10
DATBND	DATBBG			/POINTS TO BEGINNING
 
	.EJECT
	.TITLE .PD339
 
/339 PUSH DOWN LIST - MUST RESIDE IN LOWEST 4K
 
	.REPT	100
.PD339	0
 
	.LOC	.PD339
	.BLOCK	PDLSIZ
 
	.EJECT
	.TITLE CAL
 
/ENTERED WITH MEMORY PROTECT DISABLED
/AND AT LEVEL 4 IF API IS PRESENT.
/	CAL HANDLER
 
CAL9	DAC	.T4		/SAVE AC
	LAC	.IOPS
	DAC	.T3		/CAL+1 ADDRESS.
	TAD	SIX7S		/777777 (-1)
	DAC	.MED		/CAL ADDRESS.
	DAC	CALAUX		/FOR ERROR MSG
	LAC	.SCOM+37		/SET IN CAL FLAG
	DAC	.SCOM+40		/AND RESTORE 20
	DAC	.IOPS		/TO CALER TO TRAP CAL*.
 
/IF CALFLG (.SCOM+40) DOES NOT EQUAL 0 OR
/REGISTER 20 DOES NOT CONTAIN CALER,
/WE ARE IN THE CAL HANDLER.
 
	.IFDEF PI
	LAC CALION
	.ENDC
	.IFUND PI
	IORS			/REMEMBER STATE
	SMA!CLA			/OF PIC FOR
	LAW	17740		/RESTORATION
	TAD	CALION		/ON EXIT FROM
	.ENDC
	DAC	CALSWH		/CAL.
	LAC*	.T3
	AND	(77777
	DAC	.T2		/FUNCTION NUMBER.
	SNA
	JMP	CALMSG		/0 IS ILLEGAL FUNCTION (.ERR 000)
	TAD	.COMTB		/1'S COMP. NO. OF LEGAL FUNCTIONS
	SMA!CLA
	JMP	CALMSG		/ILLEGAL FUNCTION (.ERR 000)
	LAW	-13
	TAD	.T2
	SNA!SPA			/SKIP IF NON 0 AND POSITIVE
	JMP	.IODIS		/I/O FUNCTION
 
/NON-I/O TYPE FUNCTION.
 
	TAD	(JMP* .COMTB	/JMP* .COMTB
	DAC	.+2
	ISZ	.T3		/POINT TO WORD AFTER FUNCTION CODE.
.T2	XX			/GO TO FUNCTION PROCESSOR.
 
	.EJECT
	.TITLE .IDLE
 
/ROUTINE TO PROCESS THE MONITOR CAL
/FUNCTION (17) .IDLE. THIS IS THE
/MEANS BY WHICH A FOREGROUND JOB
/CAN RELINQUISH CONTROL TO LOWER
/LEVELS OF THE FOREGROUND JOB OR
/TO THE BACKGROUND JOB.
/	IF THE .IDLE IS ISSUED AT A
/	FOREGROUND API SOFTWARE LEVEL, IT
/	EFFECTS A DBR FROM THE HANDLER
/	AT THAT LEVEL. OTHER ROUTINES
/	IN THE APIQ FOR THAT LEVEL WILL
/	BE DEFERRED UNTIL A HARDWARE
/	INTERRUPT IS REQUESTED FOR THAT
/	LEVEL AGAIN.
/	IF THE .IDLE IS ISSUED AT FOREGROUND
/	MAINSTREAM, IT EFFECTS AN I/O BUSY
/	SITUATION (EXCEPT THAT NO BUSY FLAG IS SET) AND CONTROL GOES TO
/	THE BACKGROUND JOB.
/	IF THE .IDLE IS ISSUED AT BACKGROUND
/	MAINSTREAM, IT EFFECTS AN I/O BUSY
/	SITUATION AND CONTROL IS RETURNED
/	TO THE .IDLE CAL.
 
.IDLEZ	LAC	.SCOM+26		/0=FGRD JOB
	SZA			/1=BGRD JOB
	JMP	CALXIT		/BACKGROUND .IDLE.
	.IFUND	NOAPI
	705512			/READ API STATUS
	RTR
	RAR
	SZL!RAL			/LEVEL 5 IS
	JMP	LEV5D		/HIGHEST ACTIVE.
	SZL!RAL
	JMP	LEV6D		/LEVEL 6 IS HIGHEST.
	SZL
	JMP	LEV7D		/LEVEL 7 IS HIGHEST
	.ENDC
	LAC	.SCOM+65
	SNA
	JMP	CALXIT		/BACKGROUND JOB NOT IN CORE YET.
	LAW	1000		/FOREGROUND MAINSTREAM.
	AND*	.MED		/CHECK FOR .IDLEC
	SNA
	JMP	CAL41		/.IDLE
	LAC	.T3		/LOC+2=>
	JMP	CAL411		/SAVED FGRD PC
	.EJECT
	.TITLE .RLXIT
 
/ROUTINE TO PROCESS THE MONITOR CAL
/FUNCTION (20) WHICH IS THE EXIT
/MECHANISM FROM ALL REAL TIME
/SUBROUTINES.
/CALLING SEQUENCE:	LAC	SAVEAC		/SAVED AC
/		CAL	ADDR		/ADDRESS OF SUBROUTINES
/		20
 
RLEXIT	LAC	.MED		/ADDRESS OF CAL
	AND	(60000
	XOR*	.MED		/MANUFACTURE 15-BIT
	DAC	.T2		/ADDRESS OF SUBROUTINE.
	JMS	CHKADR		/VALIDATE SUBROUTINE ADDRESS.
	TAD	.SCOM+32		/HARDWARE PROTECT BOUND
	LAC*	.T2
	AND	(477777
	DAC	.T3		/LINK AND RETURN ADDRESS.
	JMS	CHKADR		/VALIDATE RETURN ADDRESS.
	TAD	.SCOM+32		/HARDWARE PROTECT BOUND
	LAC	.MED
	AND	(300000		/(XM,MP)
	XOR	.T3
	DAC	.MED
	DZM*	.T2		/CLEAR SUBROUTINE ENTRY.
	LAC	.T4		/AC
	JMP	CALXIT
	.EJECT
	.TITLE CALMSG
 
/ ROUTINE TO SET UP ERRORQ CALLING SEQUENCE AS A
/ RESULT OF A CAL LEVEL TERMINAL ERROR. ENTER WITH ERROR
/ NUMBER IN AC, RIGHT JUSTIFIED, THE REST OF AC CLEAR.
 
CALMSG	DAC	CALLAW		/SAVE ERROR #
	LAC	.SCOM+26		/0=FGD,1=BGD
	SZA
	LAC	(3000		/BGRD ERROR
	XOR	LW5THO		/FGRD ERROR
	XOR	CALLAW		/ERROR #
CAL.ER	DAC	CALLAW
	.IFUND PI
	LAC	(400200		/RAISE TO API 0 AND PI OFF
	ISA
	.ENDC
	IOF
CALLAW	XX			/LAW CODE(BITS 6-17)
	JMS	ERRORQ
CALAUX	XX			/AUXILLARY INFO. (6 DIGITS)
FNOBCK=.
	.IFUND PI
	DBK
	.ENDC
	ION
	JMP	CALXIT
	.EJECT
	.TITLE GETBUF
 
/SUBROUTINE WHICH INTERROGATES .BFTAB
/AND ACQUIRES BUFFER INFORMATION FOR THE
/CALLER. THE ADDRESS OF GETBUF IS IN
/.SCOM+56.
/	CALLING SEQUENCE:
/	LAC	(400200		/RAISE TO API
/	ISA			/LEVEL 0.
/	IOF			/TURN PIC OFF.
/	JMS	GETBUF
/	ARGUMENT			/BIT 0 0=FGRD
/				/      1=BGRD
/				/BITS 1-5 0
/				/BITS 6-17 BUFFER SIZE
/	(RETURN WITH ADDRESS OF 1ST WORD OF
/	.BFTAB ENTRY IN AC)
/	ION			/TURN ON PIC.
/	DBK			/FROM LEVEL 0.
 
GETBUF	0
	DZM	GBFNOW		/INITIALIZE FREE ENTRY POINTER.
	LAC*	GETBUF
	AND	(7777
	DAC	GBFTMP		/BUFFER SIZE TO BE FOUND.
	LAC*	GETBUF
	AND	L4HTHO		/400000
	DAC	GBFCOM		/BIT 0:0=FGRD,1=BGRD
	LAC	.BFTAB		/INITIALIZE ENTRY COUNTER
	DAC	GBFCNT		/TO 2'S COMP. # OF ENTRIES
	ISZ	GBFCNT		/PLUS 1.
	JMP	GBFMR1
GBFSYS	LAC	.BFBEG		/CHECK AVAILABILTY OF
	AND	L2HTHO		/SYSTEM DEVICE BUFFER.
	SNA
	JMP	GBFOK1		/NOT BUSY.
GBFERR	LAC	GETBUF
	DAC	GBFAUX
	LAC*	GETBUF
	SPA!CLA
	LAC	(3000		/BGRD
	XOR	(LAW 5055
	JMS	ERRORQ
GBFAUX	XX
	CLA
	JMP	GBFXIT
GBFMR1	LAC	(.BFNOT		/INITIALIZE ENTRY POINTER.
	DAC	GBFPNT		/TO 1ST NON-PERMANENT ENTRY.
	LAC	GBJCNT		/JMP GBFBK2
	DAC	GBSWCH		/TO SWITCH REGISTER.
GBFBK1	LAC*	GBFPNT		/WORD0 OF ENTRY.
	AND	(600000
	SAD	GBFCOM
	JMP	GBFFND		/CORRECT OWNER AND NOT BUSY.
GBFBK2	ISZ	GBFPNT		/PUSH POINTER TO
	ISZ	GBFPNT		/NEXT ENTRY.
	ISZ	GBFCNT		/ARE WE AT END OF TABLE.
	JMP	GBFBK1		/NO.
	LAC	GBFNOW
	SNA
	JMP	GBFSYS		/ONLY SYS.DEV. BUFFER LEFT.
GBFOUT	LAC*	GBFNOW		/BEST ENTRY ADDRESS IN GBFNOW
	XOR	L2HTHO		/200000
	DAC*	GBFNOW		/SET BUFFER IN USE BIT.
	LAC	GBFNOW
GBFXIT	ISZ	GETBUF		/EXIT WITH ADDRESS OF
	JMP*	GETBUF		/1ST WORD OF ENTRY IN AC OR 0
GBFOK1	LAC	GBJERR		/JMP GBFERR
	DAC	GBSWCH		/TO SWITCH REGISTER
	LAC	(.BFBEG		/.BFBEG
	DAC	GBFPNT
	LAC	GBFCOM
	SMA
	JMP	GBFOK2
	LAC*	GBFPNT
	AND	(377777
	XOR	L4HTHO		/(400000
	DAC*	GBFPNT		/SET BGD BIT IN RESBUF ENTRY.
	JMP	GBFFND
GBFOK2	LAC	.SCOM+65		/FOREGROUND USER
	SZA			/CANNOT USE SYS.
GBJERR	JMP	GBFERR		/DEVICE BUFFER.
 
/ENTRY HAS CORRECT OWNER AND IS NOT BUSY.
 
GBFFND	LAC*	GBFPNT		/WORD 0 OF ENTRY.
	AND	(7777
	DAC	GBFTP2		/BUFFER SIZE OF CURRENT ENTRY.
	CMA
	TAD	GBFTMP		/BUFFER SIZE TO BE FOUND.
	SMA
	XCT	GBSWCH		/BUFFER NOT LARGE ENOUGH.
	SAD	SIX7S		/777777
	JMP	GBFPER		/EXACT BUFFER SIZE.
	LAC	GBFNOW
	SNA
	JMP	GBFIST		/1ST BUFFER LARGE ENOUGH.
	LAC*	GBFNOW		/CLOSEST ENTRY SO FAR.
	AND	(7777
	TAD	GBFTP2		/CURRENT BUFFER SIZE.
	SMA
GBJCNT	JMP	GBFBK2		/CURRENT NOT SMALLER.
GBFIST	LAC	GBFPNT		/CURRENT ENTRY IS
	DAC	GBFNOW		/BEST SO FAR.
	LAC	GBSWCH
	SAD	GBJCNT
	JMP	GBFBK2
GBFPER	LAC	GBFPNT		/EXACT BUFFER SIZE.
	DAC	GBFNOW
	JMP	GBFOUT
GBFNOW	0			/ADDRESS OF BEST ENTRY SO FAR.
GBFCNT	0			/# OF ENTRIES COUNTER.
GBFPNT	0			/ENTRY POINTER.
GBFCOM	0			/OWNER: BIT0=0(FGRD),1(BGRD)
GBFTMP	0			/BUFFER SIZE TO BE FOUND.
GBFTP2	0			/BUFFER SIZE OF CURRENT ENTRY.
GBSWCH	0			/JMP GBFBK2 OR JMP GBFERR
	.EJECT
	.TITLE .BFTAB
 
/TABLE THAT CONTAINS POINTERS TO A POOL OF I/O BUFFERS
/REQUIRED BY N-FILE I/O HANDLERS.
 
.BFTAB	-1			/2'S COMPLEMENT COUNT OF
				/# OF 2-WORD ENTRIES
				/THAT HAVE BEEN SET UP.
	-BFTBSZ			/2'S COMPLEMENT COUNT OF
				/MAXIMUM # OF 2-WORD
				/ENTRIES ALLOWED.
	-1			/2'S COMPLEMENT COUNT OF
				/THE # OF FGRD BUFFERS
				/+1 (RESIDENT BUFFER)
				/WORD 0 OF EACH ENTRY
				/CONTAINS:
				/BIT0  0=FGRD BUFFER
				/      1=BGRD BUFFER
				/BIT1  0=BUFFER FREE
				/      1=BUFFER IN USE
				/BITS 2-5  0
				/BITS 6-17 BUFFER SIZE
				/WORD 1 OF EACH ENTRY
				/CONTAINS:
				/BITS 0-2  0
				/BITS 3-17 BUFFER ADDRESS.
.BFBEG	600			/ENTRY1(PERMANENT)-SYSTEM DEVICE
	RESBUF			/BUFFER.
/START OF NON-PERMANENT ENTRIES.
	.REPT	56
.BFNOT	0
	.LOC	.BFNOT
	.BLOCK	BFTBSZ-1*2
	.EJECT
	.TITLE RESBUF
 
/RESIDENT BUFFER - SIZE MUST BE SUFFICIENT FOR LOADERS' INPUT DEVICES.
 
RESBUF=.
	.BLOCK	600
RESBND=.
	.EJECT
	.TITLE RESINT
 
/RESIDENT MONITOR INITIALIZATION - LIVES IN BUFFER
 
	.LOC	RESBUF
 
/SYSTEM GENERATOR INFORMATION.
 
	CHNREG			/POINTER FOR BFSGEN TO IMAGE
				/OF CHANNEL REGISTER 0.
	.IFUND DK
	0			/TELL BFSGEN IT'S A DECTAPE SYSTEM.
	.ENDC
	.IFDEF DK
	1			/TELL BFSGEN IT'S A DISK SYSTEM.
	.ENDC
	JMP	MPVERR		/INFO FOR BFSGEN ABOUT SKIP CHAIN -
	.IFDEF PI
	JMP	CLKPIC		/WANTS JMP'S FOR MPSK AND CLSF -
	.ENDC
	.IFUND PI
	0
	.ENDC
	JMS	KBDPI		/ALSO WANTS LT09 JMS'S FOR KBD AND TPR.
	JMS	TPRPI
	JMP	ERR		/END OF SKIP CHAIN INSTRUCTION.
 
/END OF SYSTEM GENERATOR INFO.
 
RESINT	LAW	-100		/MOVE PI, CAL, AND API REGS
	LAC*	RESINL
	DAC*	RESINM
	ISZ	RESINL
	ISZ	RESINM
	ISZ	RESINT		/ANY MORE?
	JMP	.-5		/YES
TTBITS	LAC .SCOM+76		/- # OF TTYS ON THIS MACHINE.
TTCNT	DAC .
	LAC LACTT0		/LAC (LAC TTY0
	DAC TTGET
	LAC .SCOM+36		/WHICH TTYS ARE 33 OR 35.
	SKP
TTLOOP	LAC TTBITS		/SET UP 1ST DATA REGISTER
	RAL			/FOR ALL TELETYPES TO
	DAC TTBITS		/INDICATE MODEL 33 OR 35.
TTGET	XX
	SZL
	XOR	(10000
	DAC* TTGET
	LAC TTGET
	TAD (10
	DAC TTGET
	ISZ TTCNT
	JMP TTLOOP
	CLL!CLC			/TEST IF MACHINE HAS EAE OR NOT.
	660000
	SZL
	JMP HASEAE
	LAC LNOP			/(NOP
	DAC LLACQ
	DAC LLACS
	DAC LLMQ
	LAW
	DAC LAND
	LAC LJAER
	DAC EAE29
	LAC .SCOM+4		/CLEAR EAE BIT.
	AND L5777S		/(577777
	DAC .SCOM+4
HASEAE	CLOF			/TURN OFF CLOCK IN CASE IT WAS ON.
	LAC	L4HTHO		/(400000
	ISA
	ION
	LAC	.SCOM
	AND	(60000
	DAC	RESBNK		/BANK BITS FOR NON-RES MONITOR
	LAC	RESBGN		/START OF NON-RES MONITOR
	XOR	RESBNK
	DAC	.SCOM+5
	AND	(77777
	DAC	RESTRN+3
	LAC	NEWBGS
	XOR	RESBNK
	DAC	NEWBGS
	LAC	.SCOM+3
	XOR	RESBNK
	DAC	.SCOM+3
	LAW	-6
	TAD	.SCOM		/SETUP CORE SIZE FOR
	CMA			/^Q .TRAN .
	DAC	CORSIZ
	LAW	-2
	TAD	.SCOM
RESFLG	DAC	.		/POINTER TO TOP OF CORE -2.
	DAC	CTFPTR		/CTL TTYS FLAG POINTER.
	LAC*	RESFLG		/NON-0 MEANS LOADED BY
	SZA			/PAPERTAPE BOOTSTRAP.
	JMP	RES1ST		/IF SO, DON'T RESET CTL TTYS.
	ISZ	RESFLG
	LAC*	RESFLG
	DAC	.IOIN+5		/FGD CTL TTY .IOIN ENTRY
	TAD	L4HTHO
	DAC	SAVEF3		/SAVE C(.DATF-3) TEMPORARILY.
	ISZ	RESFLG
	LAC*	RESFLG
	DAC	.IOIN+7		/BGD CTL TTY .IOIN ENTRY
	TAD	L4HTHO
	DAC	.DATB-3
	DAC	.DATF-3		/LET FGD TALK TO BGD CTL TTY.
 
	CAL	2775		/.WRITE -3 ON BGD CTL TTY.
	11
	ABORT			/ABORT MESSAGE.
SAVEF3	0			/TEMP C(.DATF-3)
 
	CAL	775		/.WAIT -3
	12
 
	LAC	SAVEF3		/RESTORE .DATF-3
	DAC	.DATF-3
RES1ST	SET	FCTL.C		/ENABLE FGD ^C.
	SET	FCTL.Q		/ENABLE FGD ^Q.
	JMP	RESBGX
ABORT=.-2
	.ASCII	/ABORT/<15>
	.LOC	.-1
LJAER	JMP MPVAER
L5777S	577777
	.EJECT
/IMAGE OF REGISTERS 0 THRU 77: PI INTERRUPT,CAL,API CHANNEL REGS.
 
RESINX	0
	EEM
	JMP	.IOSK
	0
	HLT
	.REPT	13
	0
	CALER
	JMP	CAL9
	.REPT	16
	0
CHNREG	JMS	LV4INT		/40 API LEVEL 4
	.IFDEF	NOAPI
	JMS	IGNORE		/41
	JMS	IGNORE		/42
	JMS	IGNORE		/43
	.ENDC
	.IFUND	NOAPI
	JMS	LV5INT		/41 API LEVEL 5
	JMS	LV6INT		/42 API LEVEL 6
	JMS	LV7INT		/43 API LEVEL 7
	.ENDC
	.IFUND	PI
	JMS*	DTDFTV		/44 DECTAPE (TC02)
	JMS*	MTSFTV		/45 MAGTAPE (TC59)
	JMS	ERR		/46 DRUM (RM09)
	JMS*	DSSFTV		/47 DISK (RB09)
	JMS*	RSFTV		/50 PAPERTAPE READER
	JMS	CLKAPI		/51 CLOCK
	JMS	ERR		/52 POWER FAIL (KP09)
	JMS	ERR		/53 PARITY ERROR (MP09)
	JMS*	SPDFTV		/54 339 DISPLAY
	JMS*	RCSDTV		/55 CARD READER (CR01E/CR02B/CR03B)
	JMS*	LSDFTV		/56 LINE PRINTER (647)
	.REPT	15
	JMS	ERR
	JMS	TPRAPI		/74 TELEPRINTERS (LT19)
	JMS	KBDAPI		/75 KEYBOARDS (LT19)
	.REPT	2
	JMS	ERR
	.ENDC
	.IFDEF	PI
	.REPT	34
	JMS	IGNORE
	.ENDC
 
/DEVICE TABLE USED BY THE SYSTEM GENERATOR. THIS TABLE CONSISTS OF
/.SIXBT 2-LETTER DEVICE MNEMONICS. EACH SLOT INDICATES WHICH DEVICE
/USES WHICH TRANSFER VECTOR. THE TABLE SIZE IS THE SAME AS THE SKIP
/LITERAL TABLE AND THE TRANSFER VECTOR TABLE.
 
DVCNAM	.SIXBT /DT/
	.SIXBT /DT/
	.SIXBT /DK/
	.SIXBT /PR/
	.SIXBT /PP/
	.SIXBT /LP/
	.SIXBT /CD/
	.SIXBT /CD/
	.SIXBT /MT/
	.SIXBT /DY/
	.REPT 26
DVCRPT	0
	.LOC DVCRPT
	.BLOCK TVSIZE-.+DVCNAM
 
/SKIP IOT MNEMONICS TABLE CORRESPONDING TO THE IOTS IN .SKTAB. THIS
/TABLE IS USED BY THE SYSTEM GENERATOR. IN AN API SYSTEM, IF A DEVICE
/IS ON API, SYSTEM GENERATOR EXPECTS THE 1ST WORD TO CONTAIN ZERO AND
/THE 2ND WORD TO CONTAIN THE API CHANNEL NUMBER (0-37).
 
	.IFDEF PI
SKPNAM	.SIXBT /DTDF@@/
	.SIXBT /DTEF@@/
	.SIXBT /DSSF@@/
	.SIXBT /RSF@@@/
	.SIXBT /PSF@@@/
	.SIXBT /LSDF@@/
	.SIXBT /RCSF@@/
	.SIXBT /RCSD@@/
	.SIXBT /MTSF@@/
	.SIXBT /SPDF@@/
	.ENDC
	.IFUND PI
SKPNAM	0
	4			/DTDF - CHNL 4
	0
	4			/DTEF - CHNL 4
	0
	7			/DSSF - CHNL 7
	0
	10			/RSF - CHNL 10
	.SIXBT /PSF@@@/
	0
	16			/LSDF - CHNL 16
	0
	15			/RCSF - CHNL 15
	0
	15			/RCSD - CHNL 15
	0
	5			/MTSF - CHNL 5
	0
	14			/SPDF - CHNL 14
	.ENDC
	.REPT 54
SKPRPT	0
	.LOC SKPRPT
	.BLOCK TVSIZE*2+SKPNAM-.
 
RESINL	RESINX
RESINM	0
RESBNK	0
RESBGN	BF9BGN+200000
	.EJECT
	.TITLE NONRES
 
/ROUTINE TO LOAD IN THE NON-RESIDENT MONITOR (BFKM9).
 
	.LOC	RESBND
 
RESBGX	.INIT	-7,0
 
RESTRN	.TRAN	-7,0,BF9BLK,BF9BGN,0
 
	.LOC	.-1
	BF9BGN-20000		/-SIZE OF BFKM9.
 
	.WAIT	-7
 
	DBR
	JMP*	.SCOM+5
 
	.EJECT
	.TITLE .TIMER
 
 
CLOF=700004
CLON=700044
 
/.TIMER (14) FUNCTION PROCESSOR.
 
.TIMRZ	LAC	L.T2		/FAKE OUT GTREAL
	DAC	.T4		/SUBROUTINE
 
/CHECK VALIDITY OF SUBROUTINE ADDRESS AND PLACE
	JMS	GTREAL		/IT ALONG WITH CORRECT PRIORITY CODE IN .T2
	LAW	1000		/ABORT .TIMER?
	AND*	.MED
	SZA
	JMP	CKABRT		/ABORT
	LAC*	.T3		/IF 0 TIME INTERVAL,
	SNA			/IMMEDIATE
	JMP	IMMREQ		/TRANSFER.
	CLOF
	LAC	CLOKON
	SZA!CMA
	JMP	QTIME		/INTERVAL IN PROGRESS
	DAC	CLOKON		/SET IN PROGRESS.
USENEW	LAC	.T2		/LEVEL, ADDR
	DAC	CLKRTN
	LAC*	.T3		/INITIALIZE CLOCK
	DAC	7		/WITH INTERVAL
TSTCRG	LAC	7		/ADJUSTMENT IN CASE CLOCK INTERVAL
	SNA!CMA			/ELAPSED ON CLOF INSTRUCTION.
	DAC	7
USEOLD	CLON			/ENABLE CLOCK.
	ISZ	.T3
	JMP	AFTRCL		/EXIT FROM CALXIT.
QTIME	LAC*	.T3		/CHECK RELATIONSHIP OF
	SMA!CMA			/NEW AND OLD INTERVALS.
	JMP	POSINT
	DAC	.T4		/TEMPORARY
	ISZ	.T4
	LAC	7		/CURRENT INTERVAL
	SNA
	CMA
	DAC	7
	SMA
	JMP	NEWINT
CHKREL	TAD	.T4
	SMA
	JMP	OLDINT
NEWINT	LAC	7		/NEW INTERVAL SHORTER.
	TAD	.T4		/ADJUST OLD
	DAC	CLCKW1		/INTERVAL.
	JMS	INCRW1		/UPDATE CLOCKQ INTERVALS
	LAC	CLKRTN
	DAC	CLCKW0
	JMS	PUTCLK		/PLACE OLD INTERVAL IN CLOCKQ
	JMP	USENEW
OLDINT	LAC	7		/OLD INTERVAL IS SHORTER.
	CMA
	TAD*	.T3
	TAD	(1
	SNA
	CMA			/0 TO 777777
	DAC	CLCKW1
	LAC	.T2
	DAC	CLCKW0
	JMS	PUTCLK
	JMP	TSTCRG
 
/CONTROL COMES HERE WHEN THE INTERVAL
/SPECIFIED IS 0 WHICH INDICATES
/THAT IMMEDIATE SERVICE (NO WAITING
/ON THE CLOCK) IS DESIRED.
 
IMMREQ=.
	.IFUND PI
	LAC	(400200		/RAISE TO LEVEL 0
	ISA
	.ENDC
	IOF
L.T2	LAC	.T2		/LEVEL, ADDR
	JMS	REALTP		/SET UP REAL TIME ENTRY.
	.IFUND PI
	DBK			/FROM LEVEL 0
	.ENDC
LION=.				/(ION
CALION	ION
	JMP	USEOLD+1
 
/NEW INTERVAL POSITIVE.
 
POSINT	DAC	.T4
	LAC	7
	SNA
	CMA
	DAC	7
	SPA
	JMP	OLDINT		/OLD INTERVAL NEGATIVE
	ISZ	.T4
	JMP	CHKREL
 
	.EJECT
	.TITLE CLOCKQ
 
CLOKON	0			/0 = NO INTERVAL IN PROGRESS.
/				NON 0 = INTERVAL IN PROGRESS.
CLKRTN	0			/CONTAINS SUBROUTINE
/				ADDRESS OF CURRENT INTERVAL
/				IN BITS 3-17 AND
/				PRIORITY LEVEL CODE IN
/				BITS 0-2
/				     0   BGRD MAINSTREAM
/				     1   FGRD MAINSTREAM
/				     5   FGRD API LEVEL 5
/				     6   FGRD API LEVEL 6
/				     7   FGRD API LEVEL 7
/
	.REPT 60
CLOCKQ	0			/THIS Q CONTAINS THE
				/2 WORD ENTRIES OF
				/ALL THE .TIMER
				/REQUESTS THAT ARE
				/STILL OUTSTANDING
				/WORD 0 IS IDENTICAL
				/IN FORMAT TO CLKRTN
				/WORD 1 CONTAINS
				/THE DESIRED INTERVAL
				/WHICH IS MODIFIED
				/AS A FUNCTION OF
				/THE CURRENT CONTENTS
				/OF THE REAL TIME CLOCK.
	.LOC CLOCKQ
	.BLOCK CLKQSZ*2
CLCKQN	CLOCKQ+400000
CLCKW0	0
CLCKW1	0
	.EJECT
	.TITLE CLKSVC
 
/SUBROUTINE TO INCREMENT WORD 1 OF
/EVERY ENTRY IN CLOCKQ BY THE
/CONTENTS OF CLCKW1.  IF THE RESULT
/IS 0, IT IS CHANGED TO 777777.
 
CLKTMP=.
INCRW1	0
	LAC	CLCKQN		/POINTER TO 1ST
	DAC	CLCKW0		/WORD OF CLOCKQ
NXTINC	LAC*	CLCKW0
	SAD	CLCKQN
	JMP*	INCRW1		/ALL DONE
	ISZ	CLCKW0		/WORD 1 OF ENTRY
	LAC*	CLCKW0
	TAD	CLCKW1
	SNA
	CMA			/0 TO 777777
	DAC*	CLCKW0
	ISZ	CLCKW0
	JMP	NXTINC		/NEXT ENTRY
 
/ROUTINE TO ABORT ALL .TIMER REQUESTS
/THAT HAVE SAME SUBROUTINE ADDRESS AND
/PRIORITY LEVEL AS CURRENT .TIMER (ABORT) CALL.
 
CKABRT	CLOF
	LAC	CLOKON
	SNA
	JMP	USEOLD+1
	LAC	.T2		/ABORT SUBR./LEVEL
	SAD	CLKRTN
	DZM	CLKRTN		/ABORT CURRENT INTERVAL
	LAC	CLCKQN
	DAC	CLCKW0		/1ST WORD OF Q.
CKBACK	LAC*	CLCKW0
	SAD	CLCKQN
	JMP	TSTCRG		/ALL DONE.
	SAD	.T2
	DZM*	CLCKW0		/ABORT THIS ENTRY.
	ISZ	CLCKW0
	ISZ	CLCKW0		/POINT TO NEXT ENTRY.
	JMP	CKBACK
 
	.EJECT
/SUBROUTINE TO PLACE AN ENTRY IN
/CLOCKQ.  THE ENTRY IS IN CLCKW0
/AND CLCKW1. IF THE Q IS FULL,
/A FOREGROUND REQUEST WILL REPLACE
/A BACKGROUND (CODE 0) ENTRY AND
/A BACKGROUND ERROR MESSAGE WILL
/BE ISSUED.
 
PUTCLK	0
	LAW	-1
	DAC	.T6
	LAC	CLCKQN		/POINTER TO 1ST
	DAC	.T5		/WORD OF CLOCKQ
PUTAGN	LAC*	.T5
	SAD	CLCKQN
	JMP	CQFULL
	DAC	CKAUX		/IN CASE OF ERROR
	AND	.T6		/777777 OR 700000
	SNA
	JMP	MTSLOT		/EMPTY SLOT
	ISZ	.T5		/PUSH TO NEXT
	ISZ	.T5		/ENTRY
	JMP	PUTAGN
MTSLOT	LAC	CLCKW0
	DAC*	.T5
	ISZ	.T5
	LAC	CLCKW1
	DAC*	.T5
	ISZ	.T6
	JMP	BGRDER
	JMP*	PUTCLK
 
CQFULL	LAC	CLCKW0
	DAC	CKAUX
	AND	(700000
	SZA
	JMP	FCLOCK		/FOREGROUND REQUEST
BGRDER	LAW	2051		/BACKGROUND REQUEST CAN'T FIT OR
	JMP	CKERR		/FOREGROUND REPLACING BGRD.
FCLOCK	ISZ	.T6
	JMP	FGRDER		/2ND TRY FAILED.
	LAC	(700000
	JMP	PUTCLK+2
 
/CLOCKQ FULL OF FOREGROUND REQUESTS
 
FGRDER	LAC	CALAUX
	DAC	CKAUX
	LAW	1050
CKERR	DAC	CKERL
	.IFUND PI
	LAC	(400200
	ISA
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
CKERL	XX
	JMS	ERRORQ
CKAUX	XX
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	JMP*	PUTCLK
 
	.EJECT
	.TITLE CLKINT
 
/SECTION TO SERVICE CLOCK INTERRUPT.
 
	.IFDEF PI
CLKPIC	DAC	CLKACS		/PI ENTRY, SAVE AC.
	LAC	0		/PC, L, XM, MP
	DAC	CLKWD7
	LAC	CLKION		/ION
	JMP	CLKDEP
	.ENDC
CLKWD7	0
	.IFUND PI
CLKAPI	0			/PC, L, XM, MP
	DAC	CLKACS		/API ENTRY, SAVE AC
	LAC	CLKAPI
	DAC	CLKWD7
	IORS			/REMEMBER STATE OF
	SMA!CLA			/PIC FOR RESTORATION
	LAW	17740		/ON EXIT.
	TAD	CLKION
	.ENDC
CLKDEP	DAC	CLKWD5
	CLOF
	LAC	.SCOM+35		/SAVE IN INTERRUPT
	DAC	CLKS35		/ROUTINE FLAG.
	CLA!CMA			/SET IN INTERRUPT
	DAC	.SCOM+35		/ROUTINE FLAG.
	.IFDEF PI
	DZM	0		/PIC ENTRY
	.ENDC
CLKION	ION
	LAC	CLKRTN		/IGNORE
	SNA			/CURRENT
	JMP	NXTINT		/REQUEST.
	AND	(700000		/PRIORITY CODE 3
	SAD	(300000		/IS RESERVED FOR
	SKP			/SPECIAL MONITOR
	JMP	.+3		/FUNCTIONS.
	JMS*	CLKRTN
	JMP	NXTINT
	.IFUND PI
	LAC	(400200
	ISA
	.ENDC
CLKIOF	IOF
	LAC	CLKRTN
	JMS	REALTP
	.IFUND PI
	DBK
	.ENDC
	ION
	.EJECT
/THIS ROUTINE SEARCHES CLOCKQ FOR
/THE NEXT SHORTEST INTERVAL.  ON
/FINDING IT, THE FOLLOWING EVENTS
/TAKE PLACE:
/	THE INTERVAL IS PLACED IN THE
/	REAL TIME CLOCK.
/	PRIORITY LEVEL/SUBROUTINE ADDRESS
/	IS PLACED IN CLKRTN.
/	THE ENTRY IS CLEARED IN CLOCKQ.
/	ALL THE OTHER ENTRIES ARE
/	UPDATED (INCREMENTED BY 2'S COMPLEMENT
/	OF NEW INTERVAL).
/	THE CLOCK IS ENABLED.
/IF THERE ARE NO MORE ENTRIES IN
/CLOCKQ. CLOKON IS SET TO 0.
 
NXTINT	LAC	CLCKQN		/POINTER TO 1ST
	DAC	CLCKW0		/WORD OF CLOCKQ.
	DZM	CLCKW1		/INITIAL INCREMENT.
NXTCPL	LAC*	CLCKW0
	ISZ	CLCKW0		/WORD 1
	SZA
	JMP	VALIDN
 
TSTMRE	ISZ	CLCKW0		/EMPTY SLOT.
	JMP	NXTCPL
VALIDN	SAD	CLCKQN
	JMP	ENDOFQ		/END OF Q.
	LAC*	CLCKW0		/INTERVAL.
	SMA
	JMP	INTPOS		/INTERVAL POSITIVE
	LAC	CLCKW1
	SPA!CLA!CMA
	JMP	TSTTAD		/CHK INTERVALS OF LIKE SIGNS
 
NUSHRT	TAD	CLCKW0
	DAC	CLKTMP		/POINTER TO W0 OF ENTRY
	LAC*	CLCKW0		/CURRENT SHORTEST
	DAC	CLCKW1		/INTERVAL
	JMP	TSTMRE
 
INTPOS	LAC	CLCKW1
	SPA
	JMP	TSTMRE		/WE ALREADY HAVE SHORTER
 
TSTTAD	LAC*	CLCKW0
	CMA
	TAD	CLCKW1
	SMA!CLA!CMA
	JMP	TSTMRE		/OLD INTERVAL IS SHORTER
	JMP	NUSHRT		/NEW INTERVAL IS SHORTER
 
ENDOFQ	LAC	CLCKW1
	SZA
	JMP	ANOTHR		/ANOTHER INTERVAL OUTSTANDING
	LAC	CLKIOF		/IOF
	JMP	CLKOUT
 
ANOTHR	DAC	7
	CMA
	TAD	(1
	DAC	CLCKW1
	LAC*	CLKTMP
	DAC	CLKRTN		/LEVEL ADDR.
	DZM*	CLKTMP		/CLEAR THIS ENTRY IN CLOCKQ.
	JMS	INCRW1		/MODIFY OTHER CLOCKQ ENTRIES.
	LAC	USEOLD		/CLON
CLKOUT	DAC	CLKIOT
CLKIO=.
	.IFUND PI
	LAC	(400200		/TURN OFF PIC.
	ISA			/RAISE TO API
	.ENDC
CKIOF	IOF			/LEVEL 0
	LAC	CLKIOT
	SAD	CLKIOF
	DZM	CLOKON		/CLEAR INTERVAL IN PROGRESS FLAG
	JMS	CALL4
	CLKWD7
	CLKS35
	LAC	CLKS35		/RESTORE .SCOM+35
	DAC	.SCOM+35
	LAC	CLKACS		/RESTORE AC.
CLKIOT	XX			/IOF OR CLON
	.IFUND PI
	DBK			/FROM LEVEL 0
	.ENDC
CLKWD5	XX			/ION OR IOF, STATUS ON ENTRY.
	DBR			/FROM HARDWARE LEVEL.
	XCT	.+1
	XCT	.+1
	JMP*	CLKWD7
CLKACS	0			/SAVED AC.
CLKS35	0			/SAVED .SCOM+35
	.EJECT
	.TITLE .IOCAL
 
/I/O TYPE FUNCTION.
/.SCOM+16 CONTAINS ADDRESS OF FOREGROUND
/	.DAT TABLE (.DATF)
/.SCOM+17 CONTAINS ADDRESS OF BACKGROUND
/	.DAT TABLE (.DATB)
/.SCOM+26 CONTAINS 0 IF FOREGROUND JOB
/	OR 1 IF BACKGROUND JOB
 
.IODIS	LAC	.SCOM+26		/F OR B MODE
	TAD	(.SCOM+16		/POINTER TO .DATF
	DAC	.DAT
	LAC*	.DAT
	DAC	.DAT		/.DATF OR .DATB
	LAC*	.MED		/DAT SLOT BITS 9-17
	AND	(777
	SNA
	JMP	ERR02		/0 ILLEGAL DAT (.ERR 2 ERROR)
	DAC	.T1
	AND	(400
	SZA!CLA
TTY7HT	777000			/NEGATIVE DAT SLOT
	XOR	.T1
	DAC	DATNO		/.DAT SLOT #
	TAD	.DAT
	DAC	.T1		/ADDRESS OF DAT SLOT
	CMA
	TAD*	.DAT		/1ST ILLEGAL ADDRESS
	SPA			/ON HIGH SIDE.
	JMP	ERR02		/ILLEGAL DAT SLOT (.ERR 2 ERROR)
	LAC*	.DAT
	DAC	.DAT
	LAC	.T1
	CMA
	TAD*	.DAT		/LOWEST LEGAL
	SMA			/ADDRESS.
	JMP	ERR02		/ILLEGAL DAT SLOT (.ERR 2 ERROR)
	LAC*	.T1		/.DAT SLOT ENTRY.
	DAC	.T5		/TEMPORARY.
	SMA!CLL!RAL
	JMP	ERR02		/SLOT NOT SET UP. (.ERR 2 ERROR)
	SPA!CLL!RAL
	JMP	LTSLOT		/LT19 .DAT SLOT
	DAC	.T7		/NOT LT19
	AND	(700000
	DAC	.T5
	XOR	.T7
	DAC	.T1		/ADDRESS OF HANDLER
	LAC	.MED		/CAL ADDRESS
	AND	(77777
	XOR	.T5		/UNIT #
	JMP	.T5SET
LTSLOT	LAC	.SCOM+34		/ADDRESS OF LT19 HANDLER
	DAC	.T1
	LAC	.MED
	AND	(77777
	DAC	DATNO
	LAC	.T5		/LT19 UNIT #.
	AND	(77777
.T5SET	DAC	.T5
	DZM	WAITR
	LAC	.T2		/FUNCTION #
	SAD	L12
	JMP	WAIT		/.WAIT OR .WAITR
JOBCHK	LAC	.SCOM+26		/F=0, B=1
	SNA
	JMP	.FJOB		/FOREGROUND JOB.
	TAD	.T1
	DAC	.DATFJ		/POINTER TO F BUSY REGISTER.
	TAD	(1
	DAC	.DAT		/POINTER TO B BUSY REGISTER
	TAD	(34		/ALLOW ENTRY INTO CORE TO
	DAC	.T7		/CORE HANDLER
	LAC*	.T7		/EVEN WHEN
	SAD	(1		/FGRD JOB IS
	SKP			/BUSY ON THIS
	JMP	.+3		/DEVICE --- 1 IS THE HANDLER ID FOR COR.
	LAC	LZERO
	DAC	.DATFJ
	LAC	.T1
	SAD	.SCOM+34
	JMP	LTTAG1		/LT19
	LAC*	.DAT
	SNA
	JMP	FNTBSY		/BACKGROUND NOT BUSY.
 
/.MED CONTAINS EXIT POINT.
 
	SAD	DATNO
	SKP
	JMP	CALXIT		/B BUSY, NOT SAME DAT SLOT
	LAC	.T2		/SAME DAT SLOT
	SAD	(1
	SKP!CLC
	JMP	CALXIT		/NOT .INIT
	SAD*	.T7		/PART OF TEMP CODE TO FIX
	JMP	FRCEIN		/DOUBLE INIT PROBLEM.
	JMP	CALXIT
TINIT	LAC	.T2		/.INIT TO
	SAD	(1		/.DAT SLOT THAT
RESSKP	SKP			/IS ALREADY
	JMP	FBUSY		/BEING SERVICED
FNOT	ION
	.IFUND PI
	DBK
	.ENDC
FNTBSY	LAC	.T2
	SAD	L12
	JMP	AFTRCL		/.WAIT OR .WAITR
	.EJECT
/PUT ARGUMENTS OF CAL IN I/O HANDLERS
/BACKUP REGISTERS.
 
FRCEIN=.
GETARG	JMS	GTARGS
	IOF			/TURN OFF PIC
	.IFUND PI
	LAC	(400200		/RAISE TO LEVEL
	ISA			/0 OF API
	.ENDC
	LAC	.T2
	SAD	(6
	JMP	FCLOSE		/.CLOSE
	SAD	(2
	JMP	FCLOSE		/.OPER
	LAC	.DAT		/CLEAR .CLOSE FLAG
	TAD	(2
	DAC	.T7
	DZM*	.T7
	LAC	.T3
	DAC	.MED
	LAC	.T1
	SAD	.SCOM+34
	JMP	HANENT		/LT19
	LAC	DATNO		/SET B BUSY
	DAC*	.DAT		/FLAG WITH .DATSLOT #
	LAC*	.DATFJ
	SZA
	JMP	CALXIT		/FOREGROUND BUSY
HANENT	LAC	.T1		/F NOT BUSY
	TAD	(5		/ION (IOF) TO
	DAC	.T7		/WORDS 5 AND 6
	LAC	CALSWH
	DAC*	.T7		/WORD 5
	ISZ	.T7
	DAC*	.T7		/WORD 6
	ISZ	.T7
	LAC	(CALXIT
	DAC*	.T7		/WORD 7
	LAC*	.T1
	AND	(17777		/SIMULATE EXECUTION OF
	DAC	.T7		/WORD 0 OF HANDLER.
	LAC	.T1
	AND	(60000
	XOR	.T7
	DAC	.T7
	JMS*	.T7
	LAC	.T1
	TAD	(33
	DAC	.T7
	LAC	.SCOM+35		/SAVE IN INTERRUPT ROUTINE FLAG.
	DAC*	.T7
	LAC	.T1
	TAD	L17		/GIVE CONTROL TO
	TAD	.T2		/APPROPRIATE ENTRY
	DAC	.T7		/IN HANDLERS FUNCTION
	JMP*	.T7		/DISPATCH TABLE.
 
FCLOSE	LAC	.T1
	SAD	.SCOM+34
	JMP	LTTAG3		/LT19
	LAC*	.DATFJ
	SZA
	JMP	CALXIT
LTTAG3	LAC	.DAT		/FOREGROUND NOT BUSY.
	TAD	(2
	DAC	.T7		/CLOSE REGISTER
	LAC*	.T7
	SZA!CLA!CMA
	JMP CLOSET
	DAC*	.T7		/.CLOSE NOT IN PROGRESS. SET CLOSE FLAG.
	LAC	.T1
	SAD	.SCOM+34
	JMP	HANENT		/LT19
	LAC	DATNO
	DAC*	.DAT		/SET BUSY FLAG
	JMP	HANENT
CLOSET	TAD*	.T7
	DZM*	.T7		/CLEAR .CLOSE FLAG
	DAC	.T7
AFTRCL	LAC	.T3
	DAC	.MED
	LAC	.T7
	JMP	CALXIT
 
/FOREGROUND CAL.
 
.FJOB	LAC	.T1		/ADDRESS OF HANDLER
	TAD	(1
	DAC	.DAT		/POINTER TO F BUSY REGISTER
	LAC	LZERO
	DAC	.DATFJ
	LAC	.T1
	SAD	.SCOM+34
	JMP	LTTAG2		/LT19
	.IFUND PI
	LAC	(400200
	ISA
	.ENDC
	IOF
	LAC*	.DAT
	SNA
	JMP	FNOT		/FOREGROUND NOT BUSY
	SAD	DATNO
	SKP
	JMP	FBUSY
	LAC	.T1
	TAD	(36
	DAC	.T7
	LAW	-1
	SAD*	.T7
	JMP	TINIT
FBUSY	LAC	WAITR
	SZA
	JMP	FNOBCK		/WAITR- GO TO ADDR.
	.IFUND	NOAPI
	705512			/READ API STATUS
	RTR
	RAR
	SZL!RAL
	JMP	LEV5		/LEVEL 5 HIGHEST ACTIVE
	SZL!RAL
	JMP	LEV6		/LEVEL 6 ACTIVE
	SZL
	JMP	LEV7		/LEVEL 7 ACTIVE
	.ENDC
LVMBSY=.SCOM+45			/MAINSTREAM FGRD BUSY REGISTER
	LAC	.T1		/MAINSTREAM BUSY
	DAC	LVMBSY		/F MAINSTREAM BUSY REG
	LAC	.SCOM+65		/HANG ON FGRD BUSY CAL
	SNA			/IF BGRD JOB NOT
	JMP	FNOBCK		/RUNNING YET.
	ION
	.IFUND PI
	DBK
	.ENDC
	.EJECT
/SAVE FOREGROUND REGISTERS.
 
CAL41	LAC	.MED		/ADDRESS OF CAL
CAL411	DAC	FPC		/L,XM,MP
EAE1	XCT	LLACQ
	DAC	FMQ		/MQ
EAE2	XCT	LLACS
	DAC	FSC		/SC
	JMS	LVMSWP		/AUTO INDEX REG SWAP
	BAUTO
	LAC	.SCOM+1
	DAC	FSCM01
	LAC	.SCOM+2		/LOWER BOUND
	DAC	FSCM02
	LAC	.SCOM+3		/UPPER BOUND
	DAC	FSCM03
	LAC	.SCOM+10		/SAVED ^P PC
	DAC	FSCM10
 
/RESTORE BACKGROUND REGISTERS.
 
	LAC	BSC
	XOR	(77		/STEP COUNTER
	TAD	(640402
EAE2.1	XCT	LAND		/AND (640477 OR LAW
	DAC	.+1
	XX
	LAC	BMQ
EAE3	XCT	LLMQ
	LAC	BSCM01
	DAC	.SCOM+1
	LAC	BSCM02
	DAC	.SCOM+2		/LOWER BOUND.
	LAC	BSCM03
	DAC	.SCOM+3		/UPPER BOUND
	LAC	BSCM10
	DAC	.SCOM+10		/SAVED ^P PC
	LAC	.SCOM+33		/BACKGROUND PC,
	DAC	.MED		/L,XM,MP
	LAC	BAC		/BGRD AC
	ISZ	.SCOM+26		/BGRD MODE
	.EJECT
	.TITLE CALXIT
 
/EXIT ROUTINE FOR ALL CAL'S.
/ENTERED AT LEVEL 4 WITH PC,L,XM,MP
/IN .MED.
CALXIT	DAC	CALAC		/EXIT AC
	.IFUND PI
	LAC	(400200		/RAISE TO API LEVEL 0
	ISA
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
	DZM	.SCOM+40		/CLEAR CAL FLAG.
	JMS	CALL4		/INITIATE LEVEL
	.MED			/4 REQUEST.
	.SCOM+35
	LAC	CALAC		/AC
CALSWH	XX			/ION OR IOF
	.IFUND PI
	DBK			/FROM LEVEL 0
	.ENDC
	DBR			/FROM LEVEL 4
	XCT	.+1
	XCT	.+1
	JMP*	.MED
	.IFUND	NOAPI
LEV5	LAC	.T1		/ADDRESS OF HANDLER.
	DAC	LV5BSY		/L5 API BUSY REG.
	DAC	LV5SAT		/L5 API SATISFIED FLAG.
	ION
	DBK
/SAVE REGISTERS FOR THIS LEVEL
EAE4	XCT	LLACQ
	DAC	BLV5MQ
EAE5	XCT	LLACS
	DAC	BLV5SC
	JMS	LV5TRN		/AUTO INDEX REGS.
	10
	BLV5AR
	LAC	.T2		/FUNCTION CODE.
	XOR	L12
	SNA!CLA
	LAC	(2		/.WAIT (CAL+2)
	TAD	.MED		/ADDRESS OF CAL
	DAC	BLV5PC		/PC
LEV5D	LAC	.MED		/.IDLE ENTRY
	AND	(700000
	XOR	(LV5RGS
BSYOUT	DAC	.MED
	JMP	CALXIT
LEV6	LAC	.T1		/ADDRESS OF HANDLER.
	DAC	LV6BSY		/L6 BUSY REG
	DAC	LV6SAT		/L6 SATISFIED REG.
	ION
	DBK
	.EJECT
/SAVE REGISTERS FOR THIS LEVEL
 
EAE6	XCT	LLACQ
	DAC	BLV6MQ		/MQ
EAE7	XCT	LLACS
	DAC	BLV6SC		/SC
	JMS	LV6TRN		/AUTO INDEX REGS.
	10
	BLV6AR
	LAC	.T2		/FUNCTION CODE.
	XOR	L12
	SNA!CLA
	LAC	(2		/.WAIT (CAL+2)
	TAD	.MED		/ADDRESS OF CAL
	DAC	BLV6PC		/PC
LEV6D	LAC	.MED		/.IDLE ENTRY
	AND	(700000
	XOR	(LV6RGS
	JMP	BSYOUT
LEV7	LAC	.T1		/ADDRESS OF HANDLER.
	DAC	LV7BSY		/L7 BUSY REG.
	DAC	LV7SAT		/L7 SATISFIED REG.
	ION
	DBK
 
/SAVE REGISTERS FOR THIS LEVEL.
 
EAE8	XCT	LLACQ
	DAC	BLV7MQ
EAE9	XCT	LLACS
	DAC	BLV7SC		/SC
	JMS	LV7TRN		/AUTO INDEX REGS.
	10
	BLV7AR
	LAC	.T2		/FUNCTION CODE.
	XOR	L12
	SNA!CLA
	LAC	(2		/.WAIT (CAL+2)
	TAD	.MED		/ADDRESS OF CAL
	DAC	BLV7PC		/PC
LEV7D	LAC	.MED		/.IDLE ENTRY
	AND	(700000
	XOR	(LV7RGS
	JMP	BSYOUT
	.ENDC
CALAC	0			/AC ON EXIT FROM CALXIT
LTTAG1	LAC*	.DAT		/WORD 2 OF LT19 HANDLER
	DAC	.T7		/CONTAINS ADDRESS OF BGRD INTERNAL
	LAC	.T5		/BUSY TESTER
	JMS*	.T7
	JMP	CALXIT		/BUSY RETURN
	JMP	FNTBSY		/NOT BUSY RETURN
LTTAG2	LAC*	.DAT		/WORD 1 OF LT19 HANDLER
	DAC	.T7		/CONTAINS ADDRESS OF FGRD
	.IFUND PI
	LAC	(400200
	ISA
	.ENDC
	IOF
	LAC	.T5		/INTERNAL BUSY TESTER.
	JMS*	.T7
	SKP			/BUSY RETURN
	JMP	FNOT		/NOT BUSY RETURN.
	LAC	.T5		/UNIT #
	XOR	(600000
	DAC	.T1		/BUSY FLAG.
	JMP	FBUSY
 
/REGISTERS SAVED AT FOREGROUND
/MAINSTREAM I/O BUSY.
 
FPC	0			/FOREGROUND PC,L,XM,MP
FSC	0			/STEP COUNTER
FMQ	0			/MQ
FSCM01	0
FSCM02	0			/.SCOM+2
FSCM03	0			/SCOM+3
FSCM10	0			/.SCOM+10
 
/REGISTERS SAVED WHEN FOREGROUND JOB
/TAKES CONTROL FROM BACKGROUND JOB.
 
BMQ	0			/MQ
BSC	0			/STEP COUNTER
BSCM01	0
BSCM02	0			/.SCOM+2
BSCM03	0			/.SCOM+3
BSCM10	0			/.SCOM+10
BAC	0			/AC (ONLY SAVED IF HARDWARE LEVEL SWAP)
BAUTO	.BLOCK	10		/AUTO INDEX REGS
	.EJECT
	.TITLE .WAIT
 
/.WAIT OR .WAITR
 
WAIT	LAW	1000
	AND*	.MED
	ISZ	.T3		/CAL+2
	SNA
	JMP	JOBCHK		/.WAIT
	LAC*	.T3
	JMS	CHKADR		/VALIDATE ADDRESS.
	TAD	.SCOM+32		/HARDWARE PROTECT BOUND.
	ISZ	.T3
	LAC	.T3
	AND	(700000
	XOR	ADR15B		/15-BIT ADDR
	DAC	.MED		/ADDR,L,XM,MP
	DAC	WAITR
	JMP	JOBCHK
WAITR	0			/NON-ZERO IF .WAITR
 
/SUBROUTINE TO VALIDATE BACKGROUND
/JOB'S 15-BIT ADDRESS CAL ARGUMENTS.
/ENTER WITH 15-BIT ADDRESS IN AC
/ERROR IF ADDRESS IS BELOW MEMORY
/PROTECT BOUND OR IN NON EXISTANT MEMORY (.IOPS 36). RETURN
/WITH ADDRESS IN AC, BITS 0-2=0
/CALLING SEQUENCE:
/	JMS	CHKADR
/	TAD	.SCOM+31 (OR .SCOM+32)
 
CHKADR	0
	AND	(77777
	DAC	ADR15B
	LAC	.SCOM+101		/IF BGD EXEC MODE,
	SZA
	JMP	CHKNXM		/CHECK ONLY FOR NON-EX MEM.
	SAD	.SCOM+26		/F=0,B=1
	JMP	CHKNXM		/FOREGROUND.
	LAC	.MED		/ONLY CHECK FOR NON-EX MEM
	AND	(100000		/IF BGD ROUTINE IS RUNNING
	SNA			/WITH MP OFF.
	JMP	CHKNXM
	LAC	ADR15B
	CMA
	XCT*	CHKADR		/1ST LOC. ABOVE SOFT OR HARDWARE PROTECTED CORE
	SMA
	JMP	CHKBAD
CHKNXM	LAC	.SCOM		/HIGHEST CORE ADDRESS.
	CMA
	TAD	ADR15B
	SMA
	JMP	CHKBAD		/NON-EXISTANT MEMORY.
CHKOK	LAC	ADR15B		/NO MEMORY VIOLATION.
	ISZ	CHKADR
	JMP*	CHKADR
 
/MEMORY VIOLATION
 
CHKBAD	LAC	(36		/.ERR 36
	JMP	CALMSG		/WITH ADDRESS OF CAL.
ADR15B	0
CALER	0			/CAL*
	LAC	CALER		/ERROR
	TAD	SIX7S		/ROUTINE.
	DAC	CALAUX		/.ERR 1
	LAC	(1
	DAC	.SCOM+40		/SET IN CAL FLAG.
	DZM	CALER
	JMP	CALMSG
 
/SUBROUTINE TO ROTATE AC RIGHT
/9 BITS.
 
ROT9R	0
.T8=ROT9R
	RAR
	RTR
	RTR
	RTR
	RTR
	JMP*	ROT9R
 
/SUBROUTINE TO VALIDATE WORD COUNTS.
/SA IN .T5, 2'S COMP WC IN AC
 
CHKCNT	0
	DAC	.T8		/-WC
	SMA
	JMP	CHKERR
	LAW	-2
	TAD	.T5
	CMA
	TAD	.SCOM		/TOP OF CORE.
	TAD	.T8		/-WC
	SMA
	JMP*	CHKCNT		/OK
CHKERR	LAC	(23		/ILLEGAL WORD COUNT
	JMP	CALMSG		/.ERR 23
 
/SUBROUTINE TO SWAP 8 AUTO INDEX REGISTERS
/WITH 8 WORD BLOCK SPECIFIED BY SUBROUTINE
/ARGUMENT.
/CALLING SEQUENCE:  JMS LVMSWP
/		A
 
LVMSWP	0
	LAC*	LVMSWP
	DAC	LMTMP1		/A
	ISZ	LVMSWP		/SET UP FOR RETURN
	LAC	(10
	DAC	LMTMP2		/10 (AUTO INDEX REG.)
	LAW	17770
	DAC	LMTMP3		/COUNTER (8)
LVMAGN	LAC*	LMTMP1
	DAC	LMTMP4		/A TO A+7
	LAC*	LMTMP2
	DAC*	LMTMP1		/10 TO 17
	LAC	LMTMP4
	DAC*	LMTMP2
	ISZ	LMTMP1
	ISZ	LMTMP2
	ISZ	LMTMP3
	JMP	LVMAGN
	JMP*	LVMSWP
LMTMP1	0
LMTMP2	0
LMTMP3	0
LMTMP4	0
ERR02	LAC	(2
	JMP	CALMSG
.COMTB	777757
	.TIMRZ			/14
	.EXITZ			/15
	.ERROR			/16
	.IDLEZ			/17
	RLEXIT			/20
	.EJECT
	.TITLE .ERROR
 
/ CAL ROUTINE TO PUT ERROR IN ERROR QUEUE -
/ CALLED FROM SYSTEM PROGRAMS ON TERMINAL ERRORS
 
.ERROR	LAC*	.MED		/GET ERROR CODE
	AND	(1000
	SNA			/IS IT FGD ERROR?
	JMP	.+4		/NO - NO CHECKS
	LAC	.SCOM+26
	SZA			/IS FGD RUNNING?
	JMP	.ERRER		/NO - ILLEGAL CAL
	LAC	.MED		/YES - ANYTHING OK
	DAC	CALAUX
	DAC	LDRERR		/SET "IF IN BGD, THEN ERROR EXIT
				/FROM LOADER OCCURRED" FLAG.
	LAC*	.MED		/GET ERROR CODE
	AND	(3777
	XOR	LAWTRM		/(LAW 4000 - FORCE TERMINAL ERROR
	JMP	CAL.ER
.ERRER	LAC	(56
	JMP	CALMSG		/TERMINAL CAL ERROR
	.EJECT
	.TITLE .EXIT
 
/ EXIT FROM SYSTEM AND USER PROGRAMS
 
MPLD=701704
 
.EXITZ	LAC	.SCOM+65		/FGD USER RUNNING?
	SNA!CLA
	JMP	.+3		/NO.
	SAD	.SCOM+26		/YES. FGD USER EXIT?
	JMP	.EXITF		/YES.
	LAC	.SCOM+41		/WHO'S RUNNING FLAG.
	SPA			/IS IT A LOADER?
	JMP	.EXIT1		/YES - CHECK FOR BLOCK TRANSFERS
	LAC*	.MED		/IS EXIT WORD 0
	SZA
	JMP	.EXIT2		/NO - ILLEGAL EXIT
	LAC	.SCOM+26
	SZA
	JMP	.EXIT3		/BGD
.EXITF	LAC	.EXFGD		/FGD USER EXIT
	DZM	FCTL.P		/DISABLE FGD ^P
.EXIT4	DAC	.MED
	JMP	CALXIT
.EXIT3	LAW	-1
	DAC	BCTL.C		/SET DUMMY BGD ^C
	.IFUND PI
	LAC	(400200		/RAISE TO LEVEL 0
	ISA
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
	LAC*	.SCOM+73		/TEST BGDERR ENTRY PT.
	SZA
	JMP	.+4		/ALREADY CALLED.
	LAW	6000		/CALL BGDERR ROUTINE WITH
	JMS	ERRORQ		/DUMMY TERMINAL ERROR.
	XX			/ARGUMENT UNIMPORTANT.
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	LAC	.EXBGD		/BGD - GO GET NON-RES MONITOR
	JMP	.EXIT4
.EXIT2	LAC	(57
	JMP	CALMSG		/TERMINAL CAL ERROR
TVCLR	0
	LAW	-TVSIZE
	DAC	.T1
	LAC	LSETTV
	DAC	.T2
TVLOOP	LAC*	.T2
	XCT*	TVCLR		/NOP OR RAL
	SMA
	JMP	.+3
	LAC	LERR
	DAC*	.T2
	ISZ	.T2
	ISZ	.T1
	JMP	TVLOOP
	JMP*	TVCLR
.EXIT1	SAD	(400013		/EXECUTE IN BGD?
	JMP	.EXIT6		/YES.
	JMS	TVCLR
	RAL			/ARGUMENT TO SUBR.
	LAC*	.MED
	SAD	(1000
	JMP	.EXIT5		/.SYSLD EXIT TO .LOAD
	AND	(777
	XOR	TTY7HT		/(777000
	DAC	.T1		/1'S COMP BLOCK TRANSFER COUNT
.EXIT7	ISZ	.T1		/ANY MORE BLOCKS?
	SKP			/YES
	JMP	.EXIT6		/NO
	LAC*	.T3
	ISZ	.T3
	JMS	CHKADR		/CHECK START OF OLD BLOCK
	TAD	.SCOM+25		/MUST BE ABOVE FGD JOB
	DAC	.T2
	LAC*	.T3
	ISZ	.T3
	JMS	CHKADR		/END OF OLD BLOCK
	TAD	.SCOM+25
	DAC	.T5
	LAC*	.T3
	ISZ	.T3
	JMS	CHKADR		/START OF NEW BLOCK
	TAD	.SCOM+25
	DAC	.T7
.EXIT8	LAC*	.T2		/MOVE REGISTERS
	DAC*	.T7
	LAC	.T2		/IS TRANSFER DONE?
	SAD	.T5
	JMP	.EXIT7		/YES
	ISZ	.T2		/NO
	ISZ	.T7
	JMP	.EXIT8
.EXIT5	LAC	.SCOM+5
.EXT51	AND	(77777
	XOR	(300000		/SET EXM AND MP
.EXIT0	DAC	.MED
.EXT01	LAC	.SCOM+101		/NON-0 MEANS BGD EXEC MODE.
	SNA!CLA
	LAC	.SCOM+32		/SET HARDWARE BOUND
	MPLD
	JMP	CALXIT
.EXIT6	LAC	.SCOM+41		/CLEAR "LOADER RUNNING" FLAG.
	AND	(77777
	DAC	.SCOM+41
	LAC	.SCOM+26
	SZA!CLA!CMA		/FGD OR BGD?
	JMP	.EXIT9		/BGD
	DAC	.SCOM+65		/SET FGD USER RUNNING
	LAC	.SCOM+6
	AND	(77777
	XOR	L2HTHO		/(200000 - SET EXM
	DAC	.MED
	LAC	.SCOM+6		/CHECK FOR $LOAD
	RAL
	SPA
	JMP	.EXT01
	JMP	.EXTFG		/YES. DO A ^S
.EXIT9	LAC	.SCOM+41
	SZA			/SYSTEM OR USER PROGRAM?
	JMP	.EXIT5		/SYSTEM
	LAC	.SCOM+6		/USER OR DDT
	SMA!RAL			/SKIP IF DDT
	JMP	.EXITU
	LAC*	.SCOM+5		/^T ADDR + EM+MP
	DAC	BCTL.T
	ISZ	.SCOM+5
	JMP	.EXIT5
.EXITU	SPA!RAR
	JMP	.EXT51		/GLOAD
.EXTFG	LAC	.SCOM+26		/0=FGD;1=BGD
	RAR
	LAC	SLOADL		/WHERE TO GO ON ^S.
	SZL
	DAC	BCTL.S		/ENABLE BGD ^S.
	SNL
	DAC	FCTL.S		/ENABLE FGD ^S.
	LAC	SLOADR		/EXIT FROM CAL LEVEL TO
	JMP	.EXIT0		/SLOAD1 AT MAINSTREAM.
SLOADL	SLOAD2+200000
SLOADR	SLOAD1+200000
SLOAD=.-2
	.ASCII /^S/<175>
SLOAD1	.WRITE	-3,2,SLOAD,0
SLOADT=.-1
	JMP	.		/WAIT FOR USER TO TYPE ^S.
SLOAD2	DZM	FCTL.S		/USER TYPED ^S.
	DZM	BCTL.S		/DISABLE ^S.
	.CLOSE	-3		/PRINT C.R. LIN. FD.
	LAC	.SCOM+6
	AND	(77777
	DAC	SLOADT		/USER'S START ADDRESS.
	LAC	.SCOM+26
	SZA
	LAC	(100000		/MP BIT FOR BGD.
	TAD	L2HTHO		/(200000 EX MEM BIT.
	TAD	SLOADT
	DAC	SLOADT
	DBR
	XCT	.+1
	XCT	.+1
	JMP*	SLOADT
.EXBGD	NEWBGD+200000
.EXFGD	NEWFGD+200000
	.EJECT
	.TITLE NEWJOB
 
NEWBGD	DZM	BGDIN		/CLEAR "BGD IN CORE" FLAG.
	LAC	.SCOM+25		/CHANGE MP BOUND.
	DAC	.SCOM+31
	TAD	(1777
	AND	(776000
	DAC	.SCOM+32
	LAC	.SCOM+101		/NON-0 MEANS BGD EXEC MODE.
	SNA!CLA
	LAC	.SCOM+32
	MPLD
	LAC	RESTRN+3		/START OF BFKM9 (BF9BGN)
	CMA
	TAD	.SCOM+32		/HMPB
	SPA
	JMP	BGFITS		/OK - IT WILL FIT
	DZM	BCTL.C		/DISABLE BGD ^C
	DZM	BCTL.Q		/AND ^Q.
	.WRITE	-3,2,NOROOM,0
BGDIN=.-1				/BGD-IN-CORE FLAG.
MPVJPT	JMP	.		/MPV RETURNS HERE ON BGD HLT OR NEXM.
NOROOM=.-2
	.ASCII	/SORRY, NO ROOM FOR BGD/<15>
BGFITS	LAC	NEWBGS		/START OF NON-RES MONITOR
	DAC	.SCOM+5
	LAC	(17777		/SET MONITOR RUNNING
	DAC	.SCOM+41
	LAW	-7
	TAD	.SCOM+17
	DAC	BGDIN		/PTR TO .DATB-7  (ALSO SETS FLAG)
	LAC	.SCOM+13
	TAD	(4
	DAC	SLOADT		/PTR TO .IOIN+4(SYSDEV)
	LAC*	SLOADT
	DAC*	BGDIN		/SETUP .DATB-7
	LAC	(1
	DAC	BCTL.C		/ENABLE ^C AND ^Q
	DAC	BCTL.Q		/FOR BGD.
	JMP	RESBGX		/GO LOAD MONITOR
NEWBGS	BF9BGN+300000
NEWFGD	LAC	BGDIN		/BGD IN?
	SNA
	JMP	.BOOT		/NO. NO MSG - NO IDLE
	.WRITE	-3,2,NEWFGS,12
	JMP	.IDLE.		/.IDLE
NEWFGS=.-2
	.ASCII	/FGD EXIT; ^C TO KILL BGD/<15>
	.EJECT
	.TITLE .BOOT
 
/RESIDENT DECTAPE OR DISK BOOTSTRAP.
 
CTFPTR	0		/POINTER TO TOP OF
			/CORE-2 (CONTROL
			/TELETYPE FLAG)
/SAVE CONTROL TELETYPES AT TOP OF CORE
 
.BOOT	DZM*	CTFPTR	/CLEAR FLAG
	ISZ	CTFPTR
	LAC	.IOIN+5	/FGD CTL TTY ENTRY
	DAC*	CTFPTR
	ISZ	CTFPTR
	LAC	.IOIN+7	/BGD " "
	DAC*	CTFPTR
.BOOT1	JMS	.IOCLR	/CLEAR I/O
 
	.IFUND DK
 
/M. SIFNAS 7-26-67
/PDP-9 ADV. S. S. DECTAPE BOOTSTRAP .UNIT 0
/IF ENTERED VIA .DTBEG OR.DTOUT, 5 CELLS MUST BE SET--
/.DTBLK=STARTING BLOCK# OF AREA TO BE LOADED
/.DTCA=CA-1 OF CORE AREA TO BE LOADED
/.DTWC=-WC (2'S COMP) OF CORE AREA TO BE LOADED
/.DTSRC=UNIT(0-2)+21000
/.SCOM+5=START ADDR. WHEN LOAD COMPLETE
 
	LAC	(60000	/MOVE REVERSE TO BOT
	JMS	.DRUN	/XCT DTA IOT AND FLAG WAIT
	RTL		/STATUS B IN AC
	SMA!RTR		/EOT--OK, START SEARCH
	JMP	.DSTOP	/OTHER DECTAPE ERROR
 
/FOR NON-KM-9 LOAD, START AT .DTBEG
 
	JMS	.IOCLR	/CLEAR I/O
	LAC	.DTCA	/SET CA-1
	DAC*	.DK931
	DZM*	.DK930	/CLEAR WC FOR SEARCH
	DZM	.DTDIR	/DIREC. SWITCH=FORWARD(+)
	LAC	.DSMA	/SMA!CLA FOR FORW. SEARCH
	DAC	.DCHKC
	LAC	.DTBLK
	DAC	.DTBLC	/SET SEARCH BLOCK
 
/FOR .SAVE NEXT INSTR. SHOULD BE LAC .DTSRC
 
	LAC	.DTSRC	/SEARCH FORW., N.M.
.DTBGA	JMS	.DRUN
	SMA		/DTA ERR. DURING SEARCH
	JMP	.DCHKB	/CHECK BL#
.DSTOP	HLT
	JMP	.BOOT1	/RESTART
 
/IF ERROR OCCURRED WHEN ENTERED VIA .DTBEG
/CONT. SWITCH SHOULD NOT BE USED
/INSTEAD, .DTBEG IN ADDR. SWITCHES, I/O RESET, START
/BLOCK #CHECK
 
.DCHKB	LAC*	.DTCA	/BLK. # JUST READ
	SAD	.DTBLC	/" " " SEARCHED FOR
	JMP	.DCHKF	/MAYBE-CHECK DIRECTION
	SNA!CMA
	JMP	.DSTOP	/BLK.#0 REQUESTED AND NOT FOUND
	TAD	.DTBLC	/BLK.# SEARCHED FOR-BLK#READ
.DCHKC	SMA!CLA		/OVERSHOOT-FORW.,SPA!CLA-REVERSE
	JMP	.DTBGA	/CONT. SEARCH, SAME DIRECTION
	LAC	.DTDIR	/FORWARD?
.DSMA	SMA!CLA		/NO-REV
	LAW	17776	/-2
	DAC	.DTDIR	/FLIP DIRECT. SWITCH
.DCHKD	TAD	.DTBLK	/REQUESTED BLK#-2 IF REVERSE
	DAC	.DTBLC	/INTO BLOCK# TO SEARCH FOR
	LAC	.DCHKC	/SWITCH SKIP SENSE
	XOR	(1000	/SMA!CLA OR SPA!CLA (REVERSE)
	DAC	.DCHKC
	LAC	(40000	/REVERSE SEARCH DIRECTION
	JMP	.DTBGA
 
/BLOCK # FOUND
 
.DCHKF	LAC	.DTDIR	/FORWARD SEARCH?
	SPA!CLA
	JMP	.DSMA+2	/NO-REVERSE AGAIN
 
/LOAD CORE
 
.DRED	LAC	.DTWC	/SET WC(CELL 30) FOR LOAD
	DAC*	.DK930
 
/FOR .SAVE NEXT INSTR. SHOULD B LAC .DTTR
 
	LAC	.DTTR	/READ OR WRITE  FORW., CM
	JMS	.DRUN
NEWPCX	SPA		/DATA OK
	JMP	.DSTOP
	CAF		/CLEAR GO BIT
	JMP	RESINT	/EXIT (KM-9 OR USER START ADDR)
 
/I/O CLEAR SUBR.
 
.IOCLR	0
	EEM		/ENTER EXTEND MODE
	CAF		/CLEAR ALL FLAGS
	IOF+10		/PI OFF
	.IFUND PI
	ISA		/API OFF
	.ENDC
	DTCA		/CLEAR DTA STATUS A
	JMP*	.IOCLR
 
/XCT DTA IOT AND FLAG CHECK
/.DRUN ALSO USED DO TEMP. STORE STATUS B
 
.DRUN	NEWPCX
	DTXA		/AC XOR STATUS A
	DTEF!DTRB		/ERR. FLAG
	SKP!CLA
	JMP*	.DRUN	/EXIT-ERR., AC=TATUS B
	DTDF		/DONE FLAG
	JMP	.-4
	JMP*	.DRUN	/OK EXIT
.DK930	30		/ABS. LOC 30=DTA WC
.DK931	31		/ABS. LOC 31=DTA CA
DTCA=707541
DTDF=707601
DTEF=707561
DTRB=707572
DTXA=707544
.DTBLK	0		/REQUESTED BLOCK #
.DTCA	77		/CORE ADDR-1
.DTWC	760100		/2'S COMP W.C.
.DTDIR	0		/SEARCH DIRECTION SWITCH
			/+=FORWARD; -=REVERSE
.DTBLC	0		/BLOCK # BEING SEARCHED FOR
.DTSRC	21000		/UNIT (0-2)+21000
.DTTR	013000		/READ OR WRITE STATUS A BITS
	.ENDC
	.EJECT
	.IFDEF DK
 
/RESIDENT DISK BOOTSTRAP
 
	STL
	EEM+10		/ENTER EXTEND MODE AND CLEAR AC.
	RTR		/AC=0; L=1
	DAC .DUNIT	/200000
	LAC .DTSRC	/UNIT 3 MAPPED INTO 1; 7 INTO 5.
	SMA!RTL		/UNIT 4-6
	DZM .DUNIT	/UNIT 0-2
	SNL!RAL		/UNIT 2 OR 6
	SZL!CLA!STL	/UNIT 0 OR 4
	LAC (30000	/2,6
	SNL		/0,4
	TAD (30000	/1,5
	TAD .DUNIT
	DAC .DUNIT
	LAC .DTWC
	DSLW		/LOAD WC
	LAC .DTCA
	JMP .+3
.DSTOP	HLT
	JMP .BOOT1	/RESTART
	TAD (1
	DSLM		/LOAD CA
	LAC .DTBLK	/LOGICAL BLOCK #
	DZM .TRACK	/COMPUTE BCD TRACK & SECTOR ADDR.
.FINDT	TAD (-24		/20 (DEC.) 256 WD BLK PER TRACK
	SPA!STL
	JMP .FINDS	/FOUND TRACK
	ISZ .TRACK
	JMP .FINDT
.FINDS	TAD (24		/GO BACK 1 TRACK
	RTL
	JMS TOBCD		/CONVERT SECTOR TO BCD
	DAC .SECTR	/TEMP
	LAC .TRACK
	JMS TOBCD		/CONVERT TRACK TO BCD
	RTL
	RTL
	RTL
	RTL
	XOR .SECTR
	TAD .DUNIT
	DSLD		/LOAD SECTOR & TRACK ADDR.
	LAC .DTTR		/LOAD STATUS (READ OR WRITE)
	DSCS!DSLS
	DSSF!DSRS		/SKIP ON FLAGS & READ STATUS
	JMP .-1
NEWPCX	SPA		/DATA OK
	JMP .DSTOP
	CAF		/CLEAR GO BIT
	JMP RESINT	/GO TO MONITOR
 
/I/O CLEAR SUBR.
 
.IOCLR	0
	EEM
	CAF
	IOF+10
	.IFUND PI
	ISA		/API OFF
	.ENDC
	DSCS
	JMP* .IOCLR
 
/CONVERT # IN AC TO BCD.
 
TOBCD	0
	DZM .HOD		/HIGH ORDER DIGIT
	SKP
BCDLP	ISZ .HOD
	DAC .OCTN		/REMAINDER (+)
	TAD (-12
	SMA!CLL
	JMP BCDLP
	LAC .HOD		/COMBINE DIGITS
	RTL
	RTL
	XOR .OCTN
	JMP* TOBCD
.SECTR	0
.TRACK	0
.DUNIT	0
.DTBLK	0		/REQUESTED BLOCK #
.DTCA	77		/CORE ADDR-1
.DTWC	760100		/2'S COMP. W.C.
.OCTN	0		/TEMP NUMBER STORE
.HOD	0		/HIGH ORDER DIGIT
.DTSRC	0
.DTTR	2000
DSLW=707124
DSLM=707142
DSLD=707104
DSCS=707141
DSLS=707144
DSSF=707121
DSRS=707132
EEM=707702
	.ENDC
	.EJECT
	.TITLE GTARGS
 
/SUBROUTINE TO PARSE THE ARGUMENTS
/OF THE CAL CALLING SEQUENCE AND
/PLACE THEM IN THE I/O HANDLERS
/BACKUP REGISTERS.
/THE CONTENTS OF .MED IS NOT CHANGED
/AND .T3 MOVES TO RETURN POINT AFTER
/ARGUMENT STRING.
 
GTARGS	0
	LAC	.T1		/I/O HANDLERS-WORD0
	TAD	(10		/10 (OCTAL)
	DAC	.T4		/POINTER TO WORD 10
	TAD	(7
	TAD	.T2		/FUNCTION: 1-13(8)
	AND	(17777
	XOR	(600000		/JMP
	DAC*	.T4		/WORD 10 - JMP FUNC
	ISZ	.T4		/WORD 11
	LAC	.SCOM+26
	DAC*	.T4		/F=0, B=1
	ISZ	.T4		/WORD 12
	LAC	DATNO
	DAC*	.T4		/.DAT SLOT# (18-BITS)
	ISZ	.T4		/WORD 13
	LAC	.T5
	DAC*	.T4		/UNIT #
	ISZ	.T4		/WORD 14
	LAC	.T2		/FUNCTION: 1-13(8)
	TAD	(JMP FTABLE-1	/JMP FTABLE-1
	DAC	.+1
.T7	XX			/FUNCTION
FTABLE	JMP	INIT		/1
	JMP	OPER		/2
	JMP	SEEK		/3
	JMP	ENTER		/4
SIX7S	777777			/5 - .CLEAR
	JMP	CLEAR		/6 - .CLOSE
	JMP	MTAPE		/7
	JMP	READ		/10 - (ALSO .REALR)
	JMP	READ		/11 - (.WRITE,.REALW)
.T4	XX			/12 - .WAIT (.WAITR)
	LAC*	.MED		/13 - .TRAN
	JMS	ROT9R		/ROTATE 9 BITS RIGHT
	AND	(3
	DAC*	.T4		/WORD 14
	ISZ	.T4		/WORD 15
	ISZ	.T3		/CAL+2
	LAC*	.T3		/DEVICE ADDRESS.
	DAC	.T7		/TEMPORARY
	ISZ	.T3		/CAL+3
	LAC*	.T3
	JMS	CHKADR		/VALIDATE ADDRESS.
	TAD	.SCOM+31		/SOFT. BOUND
	DAC*	.T4		/CORE STARTING ADDRESS.
	DAC	.T5
	ISZ	.T3		/CAL+4
	ISZ	.T4		/WORD 16
	LAC*	.T3		/WORD COUNT
	DAC*	.T4
	ISZ	.T4		/WORD 17
	JMS	CHKCNT
	LAC	.T7
CMBINE	DAC*	.T4		/DEVICE ADDRESS.
CLEAR	ISZ	.T3		/CAL+5
	JMP*	GTARGS
	.EJECT
/.INIT PROCESSOR
 
INIT	LAC*	.MED
	JMS	ROT9R
	AND	(1
	DAC*	.T4		/FILE TYPE TO WORD 14
	ISZ	.T4		/WORD 15
	ISZ	.T3		/CAL+2
	LAC	.T1		/HANDLER ADDRESS
	XOR	.SCOM+34		/LT19
	SNA!CLL!CML
	CLL
	LAC*	.T3
	DAC*	.T4
	SZL!SNA			/AND CONDITION
	JMP	INITNX
	AND	(700000
	SAD	(300000
	JMP	INITNX		/IGNORE
	LAC*	.T3
	JMS	CHKADR		/VALIDATE RESTART ADDRESS IF LT19
	TAD	.SCOM+32
INITNX	ISZ	.T3		/CAL+3
INITND	ISZ	.T4		/WORD 16
	LAC	.T3		/CAL+3 ADDRESS FOR STAN.BUF.SIZE
	JMS	CHKADR
	TAD	.SCOM+31		/SOFT. BOUND.
	JMP	CMBINE
 
/.OPER PROCESSOR (.DLETE,.RENAM,.FSTAT)
 
OPER	LAC*	.MED
	JMS	ROT9R
	AND	(3
	SNA
	JMP	ERR07		/ILLEGAL SUBFUNCTION CODE
	DAC*	.T4		/WORD 14
	ISZ	.T4		/WORD 15
	ISZ	.T3		/CAL+2
	LAC*	.T3		/FILE DIRECTORY POINTER
	JMS	CHKADR		/VALIDATE ADDRESS.
	TAD	.SCOM+31
	DAC*	.T4		/WORD 15
	ISZ	.T4		/WORD 16
	JMP	INITND
 
/.SEEK AND .ENTER PROCESSOR
 
SEEK=.
ENTER	ISZ	.T4		/WORD 15
	ISZ	.T3		/CAL+2
	LAC*	.T3		/FILE DIRECTORY POINTER.
	AND	(77777
	JMP	CMBINE
 
	.EJECT
/.MTAPE PROCESSOR
 
MTAPE	LAC*	.MED
	JMS	ROT9R
	AND	L17		/FUNCTION TO WORD 14
	JMP	CMBINE
 
/.READ AND .REALR PROCESSOR(ALSO .WRITE AND .REALW)
 
READ	LAC*	.MED
	JMS	ROT9R
	AND	(7
	DAC	.T7		/TEMPORARY - DATA MODE
	DAC*	.T4		/WORD 14
	LAC	.T1		/SET TO POINT TO HANDLER ID
	TAD	(36
	DAC	.T8
	ISZ	.T4		/WORD 15
	ISZ	.T3		/CAL+2
	LAC	.T2
	SAD	(10		/.READ
	JMP	GTSA
	LAC	.T7
	SAD	(4
	JMP	GTSA		/MODE 4
	LAC*	.T8
	SAD	(2
	JMP	GTSKP		/339 DISPLAY HANDLER
GTSA	LAC*	.T3
	JMS	CHKADR
	TAD	.SCOM+31		/SOFT. PROTECT BOUND.
	DAC*	.T4
	DAC	.T5		/SA
GTSKP	ISZ	.T3		/CAL+3
	ISZ	.T4		/WORD 16
	LAC	.T2		/FUNCTION CODE
	SAD	(10
	JMP	STRWC		/.READ OR .REALR
	LAC*	.T8		/IGNORE COUNT IF 339 
	SAD	(2		/DISPLAY
	JMP	GTIGNR		/HANDLER
	SAD	(3
	SKP			/TTA.
	JMP	.+4
	LAC	.T7
	SAD	(2
	JMP	TTIOPS		/.IOPS ASCII OUTPUT TO LT19
	LAC	.T7		/.WRITE OR REALW
	SAD	(4
	JMP	STRWC		/DUMP MODE
	SAD	(5
	JMP	STRWC		/MAGTAPE MODE
	LAC*	.T5
	JMS	ROT9R
	CLL!RAL
	AND	(777
	CMA			/CONVERT WORD PAIR COUNT
	TAD	(1		/TO 2'S COMPLEMENT WORD
	SKP			/COUNT
STRWC	LAC*	.T3
	DAC*	.T4
	JMS	CHKCNT		/SA+WC OK
	JMP	GTIGNR
TTIOPS	LAW	-3		/FORCE WORD COUNT OF -3
	DAC*	.T4		/FOR .ASCII .WRITE TO TTA.
GTIGNR	ISZ	.T4		/WORD 17
	ISZ	.T3		/CAL+4
 
/.MED CONTAINS ADDRESS OF CAL.
/.T3 CONTAINS ADDRESS OF CAL+4
/.T4 CONTAINS ADDRESS OF WORD17
/THIS ROUTINE SETS UP APPROPRIATE
/REAL TIME PRIORITY LEVEL CODES.
 
	LAW	10000		/REAL TIME BIT
	AND*	.MED
	DZM*	.T4		/NOT REAL TIME IF 0
	SZA
	JMS	GTREAL		/ADJUST PRIORITY CODE.
	JMP*	GTARGS
	.EJECT
/SUBROUTINE TO SET UP CORRECT PRIORITY
/LEVEL CODE BASED ON FGRD OR BGRD JOB
/AND PRESENCE OF API.
 
GTREAL	0
	LAC*	.T3
	JMS	CHKADR		/VALIDATE ADDRESS.
	TAD	.SCOM+32
	DAC*	.T4		/ADDR TO WORD17
	LAC	.MED		/CODE 3
	AND	(100000		/ONLY ALLOWED
	SZA			/WHEN MEMORY
	JMP	.+5		/PROTECT
	LAC*	.T3		/IS DISABLED.
	AND	(700000
	SAD	(300000
	JMP	CODE11
	LAC	.SCOM+26
	SZA
	JMP	XITKCK		/BACKGROUND CAL (CODE 0)
	.IFUND	NOAPI
	705512			/READ API STATUS
	DAC	.T7		/TEMPORARY
	SPA
	JMP	APIPRS		/API ON.
	.ENDC
CODE1	LAC	(100000
CODE11	XOR*	.T4
	DAC*	.T4
XITKCK	ISZ	.T3
	JMP*	GTREAL
	.IFUND	NOAPI
APIPRS	LAC*	.T3
	AND	(700000
	SNA
	JMP	CODE1
	SAD	L4HTHO		/400000
	SKP
	JMP	CODE11
	LAC	.T7		/CODE 4--
	RAR			/SET CODE TO
	RTR			/CALLING LEVEL.
	SZL!RAL			/1,5,6, OR 7
	JMP	CODE5		/LEVEL 5 CAL
	SZL!RAL
	JMP	CODE6		/LEVEL 6 CAL
	SNL
	JMP	CODE1		/MAINSTREAM CAL
	LAC	(700000		/LEVEL 7 CAL
	JMP	CODE11
CODE6	LAC	(600000
	JMP	CODE11
CODE5	LAC	(500000
	JMP	CODE11
	.ENDC
ERR07	LAC	(7		/.ERR 7
	JMP	CALMSG
.T1	0			/ADDRESS OF HANDLER.
.T3	0			/L,XM,MP,ADDRESS AFTER CALL.
.T5	0
.T6	0
.DAT	0			/.DATF OR .DATB
DATNO	0			/DAT SLOT NO. (18 BITS)
.DATFJ	0			/POINTER TO FGRD BUSY FLAG
LZERO	(0			/FAKE OUT ON FGRD CALS.
 
/DUMMY API SERVICE ROUTINE
 
IGNORE	0
	.IFUND PI
	DBR
	XCT	.+1
	XCT	.+1
	JMP*	IGNORE
	.ENDC
	.IFDEF PI
	HLT			/HARDWARE MALFUNCTION.
	.ENDC
	.EJECT
	.TITLE LV4INT
 
/LEVEL 4 SOFTWARE LEVEL INTERRUPT
/HANDLER. THIS LEVEL IS RESERVED FOR
/SYSTEM USAGE.
 
	.IFDEF PI
LV4PIC	DAC	LV4AC		/PIC
	JMP	L4STAT		/ENTRY.
	.ENDC
LV4INT	0			/PC,LINK,XMODE,MEM.PROTECT.
	DAC	LV4AC		/AC
 
/THE MQ, STEP COUNTER AND AUTO INDEX
/REGISTERS ARE NOT SAVED BY THIS HANDLER.
/SUBROUTINES WILL HAVE TO SAVE AND RESTORE
/ANY OF THESE THAT THEY USE.
/CAL'S SHOULD NOT BE EXECUTED FROM
/THIS LEVEL.
 
	LAC	.SCOM+35		/SAVE .SCOM+35
	DAC	L4SC35
	CLA!CMA			/SET .SCOM+35
	DAC	.SCOM+35		/TO -1.
	.IFUND PI
L4STAT	IORS			/SAVE STATUS
	SMA!CLA			/OF PIC
	LAW	17740
	TAD	LV4ION
	.ENDC
	.IFDEF PI
L4STAT	LAC	LV4ION
	.ENDC
	DAC	LV4SWH
LV4AGN	LAC	LV4Q
	DAC	LV4CNT		/2'S COMPLEMENT OF Q SIZE
	LAC	LLV4Q
	DAC	LV4PNT		/LV4Q+1
	.IFUND PI
	LAC	(400200		/RAISE TO API
	ISA			/LEVEL 0.
	.ENDC
	IOF			/TURN PIC OFF.
LV4BCK	LAC*	LV4PNT		/LOOK FOR PENDING
	SPA			/ENTRY IN LV4Q
	JMP	LV4FND		/FOUND ONE.
	ISZ	LV4PNT
	ISZ	LV4CNT
	JMP	LV4BCK
 
/NO PENDING ENTRIES IN LV4Q.
 
	LAC	CALER
	SZA
	JMP	LV4OUT		/CAL* IN PROGRESS.
	LAC	.SCOM+40		/CAL FLAG.
	SZA
	JMP	LV4OUT		/IN CAL.
	LAC	20
	SAD	.SCOM+37
	SKP			/NOT IN CAL.
	JMP	LV4OUT		/IN CAL.
	.IFUND PI
	LAC	0
	SZA
	JMP	LV4OUT		/PIC INTERRUPT IN PROG.
	.ENDC
	LAC	L4SC35		/SAVED .SCOM+35.
	SZA
	JMP	LV4OUT		/INTERRUPT IN PROGRESS.
	LAC	.SCOM+22
	SZA
	JMP	MTDLAY
	.IFUND PI
	705512			/READ API STATUS.
	AND	(7407
	SZA			/LOWER OR EQUAL API LEVELS
	JMP	LV4SK3		/ACTIVE OR REQUESTED.
	.ENDC
	LAC	.SCOM+26		/0=FGRD, 1=BGRD
	SNA
	JMP	LV4SKP		/FGRD MODE ALREADY.
/NOTE IN FOLLOWING CODE THAT, ALTHOUGH .SCOM+63 IS USED AS AN ARGUMENT
/TO AN ISA INSTRUCTION, IT MUST BE USED IN PI SYSTEMS TO INDICATE WHEN
/A FGD MAINSTREAM I/O BUSY SITUATION HAS BEEN CLEARED UP (IOBUSY SETS
/BIT 0 OF .SCOM+63).
	LAC	.SCOM+63
	SZA
	JMP	LV4DBK		/FGD REQUESTS PENDING
	LAC	.SCOM+45
	SZA
	JMP	LV4.ER		/FGRD MAINSTREAM BUSY
/FGD MAINSTREAM NOT BUSY WITH BGD RUNNING MEANS FGD MAINSTREAM IS
/SITTING ON A .IDLE OR .IDLEC (SINCE .SCOM+63 IS ZERO).
	LAC	.SCOM+57
	SNA
	JMP	LV4.ER		/NO FGRD MAIN RTR REQUESTED
/SET RUNNING MODE TO FGD AND SWAP COMMON REGISTERS.
LV4DBK=.
	.IFUND PI
	DBK			/FROM LEVEL 0
	.ENDC
	ION			/TURN PIC ON.
	DZM	.SCOM+26		/SET FGRD RUNNING MODE
 
/SAVE BACKGROUND REGISTERS.
 
	LAC	LV4INT		/SAVE BGRD PC,
	DAC	.SCOM+33		/L, XMODE, MEM.PROT.
EAE10	XCT	LLACQ
	DAC	BMQ		/MQ
EAE11	XCT	LLACS
	DAC	BSC		/STEP COUNTER
	LAC	LV4AC
	DAC	BAC		/AC
	LAC	.SCOM+1
	DAC	BSCM01
	LAC	.SCOM+2
	DAC	BSCM02		/LOWER BOUND
	LAC	.SCOM+3
	DAC	BSCM03		/UPPER BOUND
	LAC	.SCOM+10		/^P SAVED PC
	DAC	BSCM10
 
/SWAP AUTO INDEX REGS.
 
	LAC	(BAUTO
	DAC	LV4TP1		/BAUTO
	LAC	(10
	DAC	LV4TP2
	LAW	17770		/-10 (OCTAL) COUNTER.
	DAC	LV4TP3
SWPAGN	LAC*	LV4TP1
	DAC	LV4TP4
	LAC*	LV4TP2
	DAC*	LV4TP1
	LAC	LV4TP4
	DAC*	LV4TP2
	ISZ	LV4TP1
	ISZ	LV4TP2
	ISZ	LV4TP3
	JMP	SWPAGN
 
/RESTORE FOREGROUND REGISTERS.
 
	LAC	FSC
	XOR	(77
	TAD	(640402
EAE12	XCT	LAND		/AND (640477 OR LAW
	DAC	.+1
LV4TP4	XX			/STEP COUNTER
	LAC	FMQ
EAE13	XCT	LLMQ
	LAC	FSCM01
	DAC	.SCOM+1
	LAC	FSCM02
	DAC	.SCOM+2		/LOWER BOUND
	LAC	FSCM03
	DAC	.SCOM+3		/UPPER BOUND
	LAC	FSCM10
	DAC	.SCOM+10		/^P SAVED PC
	LAC	FPC
	DAC	LV4INT		/FGRD PC,L,XM,MP.
	JMP	LV4AGN
LV4SKP	JMS	L4TEST
	JMS	FR.MSG		/CHECK FGD NOT READY MESSAGE.
	LAC	.SCOM+67		/PTR TO FGD CTRL CHARS.
	TAD	(1
	DAC	LV4CNT
	LAC*	LV4CNT		/FGD ^P REGISTER MINUS?
	SPA
	JMP	LV4.FP		/YES.
	ISZ	LV4CNT
	LAC*	LV4CNT		/HOW ABOUT FGD ^S?
	SPA
	JMP	LV4.B		/YES.
LV4.E	LAC	.SCOM+26		/0=FGRD, 1=BGRD
	CLL!RAL
	TAD	(.SCOM+57		/.SCOM+57
	DAC	LV4CNT		/.SCOM+57 OR 61
	SAD	(.SCOM+57
	JMP	LV4FGD		/FGRD MODE
LV4FOK	LAC*	LV4CNT
	SNA
	JMP	LV4ISA		/NO SUBS. PENDING
	DAC	LV4PNT		/CONTENTS OF .SCOM+57 OR 61
	LAC	LV4INT		/PC,L,XM,MP TO
	DAC*	LV4PNT		/SUBROUTINE ENTRY POINT.
	DZM*	LV4CNT		/0 TO .SCOM+57 0R 61
	ISZ	LV4CNT		/.SCOM+60 OR 62
	AND	(700000		/L,XM,MP AND SUBRN
	XOR*	LV4CNT		/TO EXIT ADDRESS
	DAC	LV4INT
LV4ISA=.
	.IFUND PI
	LAC	.SCOM+63
	SZA
	ISA			/API INTERRUPT REQUEST.
	.ENDC
	DZM	.SCOM+63		/MUST BE DONE EVEN ON PI MACHINE.
LV4OUT=.
LV4.6=.
LV4RES	LAC	LV4INT		/C(LV4INT) TO
	DAC	LV4PNT		/TEMPORARY .
	DZM	LV4INT		/0 TO LV4INT (FREE FOR FUTURE ENTRY)
	LAC	L4SC35		/RESTORE .SCOM+35
	DAC	.SCOM+35
	LAC	LV4AC		/RESTORE AC
	.IFUND PI
	DBK			/FROM LEVEL 0
	.ENDC
LV4SWH	XX			/ION OR IOF
LV4DBR	DBR			/FROM LEVEL 4
	XCT	.+1		/EXIT
	XCT	.+1
	JMP*	LV4PNT
LV4.FP	LAC	LV4INT
	DAC	.SCOM+10
	LAC*	LV4CNT
LV4.B	DZM	.SCOM+45
	DZM	.SCOM+57
	DAC	LV4INT
	XOR	L4HTHO
	DAC*	LV4CNT
	JMP	LV4ISA
LV4FGD	LAC	.SCOM+45		/FGRD MAINSTREAM BUSY.
	SZA
	JMP	LV4ISA
	JMP	LV4FOK
 
/.TIMER DELAY FOR MAGTAPE SETTLING DOWN TIME HAS EXPIRED.
 
MTDLAY=.
	.IFUND PI
	DBK				/FROM LEVEL 0 TO 4.
	.ENDC
	ION
	JMS*	.SCOM+22		/GO TO MAGTAPE HANDLER.
	JMP	LV4AGN			/RECHECK QUEUE.
 
/SUBROUTINE TO CHECK IF FGRD ERROR FLAG IS ON
 
LV4TP3=.
L4TEST	0
	LAC	.SCOM+71		/IS FGRD ERROR FLAG (BIT 1
	RAL			/OF .SCOM+71) ON?
	SMA
	JMP*	L4TEST		/NO.
	LAC	.SCOM+72		/IS THE CONTENTS
	DAC	LV4CNT		/OF FGDERR (ENTRY
	LAC*	LV4CNT		/PT. OF FGRD ERROR
	SZA			/ROUTINE) = 0?
	JMP	LV4.6		/NO. ROUTINE IN PROGRESS ALREADY
	.IFUND PI
	705512			/YES. READ API STATUS
	DAC	.SCOM+74		/SAVE FOR RESTORATION BY ERROR ROUTINE
	LAC	(400200
	DBK			/FROM LEVEL 0
	DBK			/FROM HANDLER LEVEL
	.IFUND	NOAPI
	DBK			/FROM LEVEL 5
	DBK			/FROM LEVEL 6
	DBK			/FROM LEVEL 7
	.ENDC
	ISA			/RAISE BACK TO LEVEL 0
 
/SOFTWARE LEVELS 5,6,AND 7 HAVE NOW BEEN DEACTIVATED.
 
	.IFUND NOAPI
	LAC	.SCOM+75		/JMS IGNORE
	DAC	41		/TO CHAN. REGS.
	DAC	42		/OF SOFTWARE LEVELS
	DAC	43		/5,6 AND 7.
	.ENDC
	.ENDC
 
/PENDING INTERRUPTS ON SOFTWARE LEVELS
/5,6 AND 7 WILL NOW BE IGNORED.
 
LV4.F	LAC	LV4INT		/CONTENTS OF WORD7
	DAC*	LV4CNT		/TO FGRD(BGRD) ERROR ROUTINE
	ISZ	LV4CNT		/ENTRY PT. 
	LAC	LV4CNT		/FGDERR(BGDERR)+1 (WITH XM BIT)
	DAC	LV4INT		/TO WORD7
	JMP	LV4.6
LV4.ER	LAC	.SCOM+71		/IS FGRD ERROR
	RAL			/FLAG ON?
	SPA
	JMP	LV4DBK		/YES.
	JMS	FR.MSG		/CHECK FGD NOT READY MESSAGE.
	LAC	.SCOM+67		/NO. IS FGRD ^P REGISTER MINUS?
	TAD	(1
	DAC	LV4CNT
	LAC*	LV4CNT
	SPA
	JMP	LV4DBK		/YES.
	ISZ	LV4CNT		/^S?
	LAC*	LV4CNT
	SPA
	JMP	LV4DBK		/YES.
LV4.D	LAC	.SCOM+71		/IS BGRD ERROR
	SMA			/FLAG ON?
	JMP	LV4.G1		/NO.
	LAC	.SCOM+73		/YES. IS THE
	DAC	LV4CNT		/CONTENTS OF BGDERR
	LAC*	LV4CNT		/(ENTRY PT. OF BGRD
	SZA			/ERROR ROUTINE) = 0?
	JMP	LV4.6		/NO.
	JMP	LV4.F		/YES.
LV4.G1	LAC	BRWRIT		/BGD ^R MSG FLAG.
	SNA
	JMP	LV4.G		/NO ^R MSG PENDING.
	LAC	.DATB-3
	AND	(77777		/GET BGD CTL TTY UNIT #.
	DZM	.T2		/CLEAR SO TTA. WON'T THINK IT'S A .INIT.
	JMS	BSYTST		/TTA BUSY TESTER.
	JMP	LV4.G		/UNIT BUSY.
	.IFUND PI
	LAC	(400060
	DBK			/FROM LEVEL 0 TO 4.
	ISA			/RAISE TO LEVEL 3 AND 2.
	.ENDC
 
	CAL	2775		/.WRITE NOT READY MSG
	11			/TO BGD CTL TTY.
	BRDATA-2			/TTA WILL DBK TO 3; CALXIT WILL DBK TO 4.
BRWRIT	0			/BGD ^R MSG FLAG.
 
	DZM	BRWRIT		/CLEAR FLAG.
	JMP	LV4AGN
LV4.G	LAC	.SCOM+70		/IS BGRD ^P
	TAD	(1		/REGISTER MINUS?
	DAC	LV4CNT
	LAC*	LV4CNT
	SPA
	JMP	LV4.BP		/YES.
	ISZ	LV4CNT		/HOW ABOUT ^S?
LV4.T	LAC*	LV4CNT
	SPA
	JMP	LV4.B1		/YES.
	ISZ	LV4CNT		/HOW ABOUT ^T?
	LAC*	LV4CNT
	SMA
	JMP	LV4.E		/NO.
	LAC	LV4INT
	DAC	.SCOM+7		/^T SAVED PC
	JMP	LV4.T
LV4.BP	LAC	LV4INT
	DAC	.SCOM+10		/^P SAVED PC
	JMP	LV4.T
LV4.B1	DZM	.SCOM+61		/CLEAR BG MAIN. RTR.

	DAC	LV4INT		/SET EXIT ADDR.
	XOR	L4HTHO		/CLEAR SIGN BIT
	DAC*	LV4CNT
	JMP	LV4OUT
	.IFUND PI
LV4SK3	AND	(4000
	SZA
	JMP	LV4OUT		/LVL 4 INT. PENDING
	JMS	L4TEST
	JMS	FR.MSG		/CHECK FGD NOT READY MESSAGE.
	JMP	LV4ISA
	.ENDC
LV4FND	AND	(77777		/CLEAR BIT 0
	DAC*	LV4PNT		/OF ENTRY.
	DAC	LV4PNT
	.IFUND PI
	DBK			/FROM LEVEL 0
	.ENDC
LV4ION	ION
	JMS*	LV4PNT		/JMS TO REQUESTED SUBR.
	JMP	LV4AGN		/CHECK FOR MORE ENTRIES.
	.EJECT
/SUBROUTINE TO CHECK FOR FGD ^R MESSAGE (AT LEVEL 0).
/NOTE THAT RUNNING MODE MAY BE BACKGROUND.
 
FR.MSG	0
 
	LAC	FRWRIT		/FGD ^R MSG FLAG.
	SNA
	JMP*	FR.MSG		/NO ^R MSG PENDING.
	LAC	.DATF-3
	AND	(77777		/GET FGD CTL TTY UNIT #.
	DZM	.T2		/CLEAR SO TTA WON'T THINK IT'S A .INIT.
	JMS	BSYTST		/TTA BUSY TESTER.
	JMP*	FR.MSG		/TTY UNIT BUSY.
	LAC	.DATB-3
	DAC	FR.MSG		/SAVE C(.DATB-3).
	LAC	.DATF-3		/SET SO WRITE TO FGD CTL TTY
	DAC	.DATB-3		/WILL OCCUR EVEN IF BGD RUNNING.
	.IFUND PI
	LAC	(400060
	DBK			/FROM LEVEL 0 TO 4.
	ISA			/RAISE TO LEVELS 3 AND 2.
	.ENDC
 
	CAL	2775		/.WRITE TO FGD CTL TTY
	11			/FGD NOT READY MSG.
	FRDATA-2			/TTA WILL DBK TO 3; CALXIT WILL DBK TO 4.
FRWRIT	0			/FGD ^R MSG FLAG.
 
	LAC	FR.MSG
	DAC	.DATB-3		/RESTORE .DATB-3.
	DZM	FRWRIT		/CLEAR FLAG.
	JMP	LV4AGN
 
	.EJECT
	.TITLE IOBUSY
 
/SUBROUTINE TO CHECK FOR I/O BUSY
/TERMINATION.
/CALLING SEQUENCE:
/	IOBUSY MUST BE CALLED PROTECTED
/	(AT API LEVEL 0, PIC OFF) WITH
/	THE ADDRESS OF WORD 0 OF
/	THE DEVICE HANDLER IN THE
/	AC(TELETYPE UNIT # + 600000
/	IF LT19 HANDLER)
/LOC	JMS	IOBUSY		/THE ADDRESS OF
/				/IOBUSY IS IN
/				/.SCOM+52
/LOC+1	(RETURN)
 
IOBUSY	0
	.IFUND	NOAPI
	DAC	IOBSYT		/SAVE ARGUMENT.
	SAD	.SCOM+42		/LV5 BUSY REG.
	JMP	IOBSY5
IOTST6	SAD	.SCOM+43		/LV6 BUSY REG.
	JMP	IOBSY6
IOTST7	SAD	.SCOM+44		/LV7 BUSY REG.
	JMP	IOBSY7
	.ENDC
IOTSTM	SAD	.SCOM+45		/MAINSTREAM
	SKP
	JMP*	IOBUSY		/NOT INVOLVED IN BUSY SITUATION.
	DZM	.SCOM+45		/MAINSTREAM
/FOLLOWING MUST BE DONE EVEN IN PI MACHINE TO SIGNAL LEVEL 4 HANDLER
/THAT FGD MAINSTREAM NOW NO LONGER I/O BUSY AND THAT SWAP FROM BGD TO
/FGD RUNNING MODE MUST TAKE PLACE.
	LAC	L4HTHO		/400000
	.IFUND PI
	JMS	LV0IOR		/INCLUSIVE OR TO .SCOM+63
	.ENDC
	.IFDEF PI
	DAC	.SCOM+63
	.ENDC
	JMP*	IOBUSY
	.IFUND	NOAPI
IOBSY5	LAC	(402000		/REQUEST INTERRUPT
	JMS	LV0IOR		/AT LEVEL 5
	DZM	.SCOM+46		/LV5 SATISFIED FLAG
	LAC	IOBSYT		/RESTORE ARGUMENT.
	JMP	IOTST6
IOBSY6	LAC	(401000		/REQUEST INTERRUPT
	JMS	LV0IOR		/AT LEVEL 6
	DZM	.SCOM+47		/LV6 SATISFIES FLAG
	LAC	IOBSYT		/RESTORE ARGUMENT
	JMP	IOTST7
IOBSY7	LAC	(400400		/REQUEST INTERRUPT
	JMS	LV0IOR		/AT LEVEL 7
	DZM	.SCOM+50		/LV7 SATISFIED FLAG
	LAC	IOBSYT		/RESTORE ARGUMENT
	JMP	IOTSTM
	.ENDC
	.EJECT
	.TITLE REALTP
 
REALT3=IOBUSY
 
/SUBROUTINE TO PROCESS REAL-TIME
/REQUESTS.
/CALLING SEQUENCE:
/	REALTP MUST BE CALLED
/	PROTECTED (AT API LEVEL 0,
/	PIC OFF) WITH THE API
/	LEVEL DESIGNATOR
/	0=BGRD
/	1=FGRD MAINSTREAM
/	5=FGRD API LEVEL 5
/	6=FGRD API LEVEL 6
/	7=FGRD API LEVEL 7
/	IN BITS 0-2 OF AC AND
/	THE REAL-TIME SUBROUTINE
/	ADDRESS IN BITS 3-17 OF AC.
/LOC	JMS	REALTP		/THE ADDRESS
/				/OF REALTP IS IN
/				/.SCOM+51
/LOC+1	(RETURN)
 
REALTP	0
	DAC	REALT1		/SAVE REQUEST.
	AND	(700000
	.IFUND	NOAPI
	SMA			/API REQUEST?
	JMP	REALNK		/NO.
	SAD	(500000		/YES.
	LAC	(402000		/INCLUSIVE OR
	SAD	(600000		/APPROPRIATE
	LAC	(401000		/API LEVEL REQUEST
	SAD	(700000		/BITS TO
	LAC	(400400		/SAVED ISA
	JMS	LV0IOR		/WORD (.SCOM+63)
	LAC	REALT1		/PLACE ENTRY
	JMS	ENTERQ		/IN APIQ
	JMP*	REALTP
	.ENDC
REALNK	SNA!CLA			/SET REALT2 TO
	LAC	(2		/FGRD=.SCOM+57
	TAD	(.SCOM+57		/BGRD=.SCOM+61
	DAC	REALT2		/SET REALT3 TO
	DAC	REALT3		/FGRD=.SCOM+60
	ISZ	REALT3		/BGRD=.SCOM+62
	LAC*	REALT1		/CHECK IF SUBROUTINE
	SZA!CMA			/ALREADY ENTERED.
	JMP	REALER		/AVOID RE-ENTRANCY.
	DAC*	REALT1		/PROTECT AGAINST RE-ENTRANCE
	LAC*	REALT2		/IS THIS IST
	SZA			/LINKAGE?
	DAC	REALT3		/NO.
	LAC	REALT1		/YES. ADDR. OF
	AND	(77777		/SUBROUTINE ENTRY
	DAC*	REALT2		/POINT TO .SCOM+57(61)
	TAD	(1		/ADDR. OF 2ND WORD
	DAC*	REALT3		/OF SUBROUTINE TO
	JMP*	REALTP		/.SCOM+60(62) OR PREVIOUS SUBROUTINE
REALER	LAC	REALT1		/OUTPUT NON-
	AND	(700000		/TERMINAL ERROR
	SNA!CLA			/MESSAGE.
	LAC	(3000		/BGRD
	XOR	LW1052		/(LAW 1052
	JMS	ERRORQ
REALT1	XX			/LEV./SUBR. ADDR.
	JMP*	REALTP
	.EJECT
	.TITLE CALL4
 
CALL4T=REALTP
 
/SUBROUTINE TO INITIATE A LEVEL 4
/INTERRUPT (SIMULATED IN PI ONLY
/SYSTEMS)
/CALLING SEQUENCE:
/	CALL4 MUST BE CALLED DURING
/	THE PROTECTED EXIT (AT API
/	LEVEL 0, PIC OFF) OF A
/	DEVICE HANDLER'S INTERRUPT
/	SERVICE
/LOC	JMS	CALL4		/THE ADDRESS OF CALL4
/				/ IS IN .SCOM+54
/LOC+1	PCSAVE			/15-BIT ADDRESS OF REGISTER
/				/ THAT CONTAINS RETURN
/				/PC,L,XMODE,MEM.PROT.
/LOC+2	SAVE35			/15-BIT ADDRESS OF
/				/REGISTER THAT CONTAINS
/				/ SAVED .SCOM+35
/LOC+3	(RETURN)
 
REALT2=.
IOBSYT=.
CALL4	0
	.IFDEF PI
	JMP	CALL4P		/NO-PI SYSTEM.
	.ENDC
	.IFUND PI
	LAC	(404000		/YES. REQUEST
	ISA			/LEVEL 4 API INTERRUPT
	.ENDC
CALL4R	ISZ	CALL4
	ISZ	CALL4
	JMP*	CALL4		/EXIT TO LOC+3
	.IFDEF PI
CALL4P	LAC	LV4INT		/IS LEVEL 4
	SZA			/HANDLER IN PROGRESS?
	JMP	CALL4R		/YES.
	LAC*	CALL4		/NO. HANDLER'S
	DAC	CALL4T		/RETURN PC,L,XM,MP
	LAC*	CALL4T		/TO LV4INT
	DAC	LV4INT
	LAC	(LV4PIC+200000	/HAVE HANDLER
	DAC*	CALL4T		/EXIT TO LV4PIC.
	ISZ	CALL4
	LAC*	CALL4		/HANDLER'S SAVED
	DAC	CALL4T		/.SCOM+35 TO
	LAC*	CALL4T		/LEVEL 4'S SAVED
	DAC	L4SC35		/.SCOM+35.
	CLA!CMA			/-1 TO HANDLER'S
	DAC*	CALL4T		/SAVED .SCOM+35
	JMP	CALL4R+1
	.ENDC
	.EJECT
	.IFUND PI
/LV0IOR
/SUBROUTINE TO INCLUSIVE OR THE
/CONTENTS OF THE AC WITH .SCOM+63
/AND PLACE THE RESULTS IN .SCOM+63
/	LV0IOR MUST BE CALLED
/	PROTECTED (AT API LEVEL 0, PIC OFF)
 
LV0IOR	0
	DAC	LV0TMP		/TEMPORARY
	CMA
	AND	.SCOM+63
	XOR	LV0TMP
	DAC	.SCOM+63
	JMP*	LV0IOR
LV0TMP	0
	.ENDC
 
/LEVEL 4 QUEUE:
/WHEN THE LEVEL 4 HANDLER IS ENTERED
/VIA AN INTERRUPT, IT WILL INTERROGATE
/THIS Q FOR PENDING REQUESTS.
/THE ADDRESS OF LV4Q IS IN .SCOM+53
 
LV4Q	-LV4QSZ			/2'S COMPLEMENT OF Q SIZE.
TTY4Q	INT1		/LT19	/AN ENTRY CONSISTS
	1		/339	/OF THE 15-BIT ADDRESS
	.REPT 6			/OF THE LEVEL 4
	0			/SUBROUTINE IN BITS
				/3-17 AND BIT 0
				/SET TO 1 IF THIS
				/SUBROUTINE IS NOW
				/DESIRED.
	.LOC TTY4Q
	.BLOCK LV4QSZ
LLV4Q	LV4Q+1
LV4TP1=.
LV4CNT	0
LV4TP2=.
LV4PNT	0
LV4AC	0
L4SC35	0			/LEVEL 4 SAVED .SCOM+35
	.EJECT
	.TITLE LV5INT
 
	.IFUND	NOAPI
/LEVEL 5 API SOFTWARE LEVEL
/INTERRUPT HANDLER.
 
LV5INT	0			/PC,LINK,XMODE,MEM.PROT.
	DAC	LV5AC		/AC
EAE14	XCT	LLACQ
	DAC	LV5MQ		/MQ
EAE15	XCT	LLACS
	DAC	LV5SC		/STEP COUNTER
	JMS	LV5TRN		/SAVE AUTO INDEX
	10			/REGISTERS IN
	LV5AIR			/LV5AIR.
	LAC	LV5BSY
	SZA
	JMP	LV5BND		/I/O BOUND
LV5BCK	JMS	GETQ		/GET LEVEL 5
	500000			/ENTRY FROM Q.
	SNA			/AC IS 0 IF
	JMP	LV5RGS		/Q EMPTY FOR THIS LEVEL.
	DAC	LV5DEF		/JMS TO ADDRESS
	JMS*	LV5DEF		/SPECIFIED IN ENTRY
	JMP	LV5BCK		/CHECK FOR MORE ENTRIES.
LV5RGS	LAC	LV5SC		/RESTORE REGISTERS---ENTRY FROM CAL HANDLER
	JMS	LV5RES		/STEP COUNTER
	LAC	LV5MQ
EAE16	XCT	LLMQ
	JMS	LV5TRN		/AUTO INDEX
	LV5AIR			/REGISTERS.
	10
	705512			/READ API STATUS
	AND	(3403
	SZA
	JMP	LV5DBK		/LOWER LEVELS ACT. OR REQ.
	LAC	(400200		/RAISE TO LEVEL
	ISA			/0 OF API.
	JMS	CALL4		/INITIATE
	LV5INT			/LEVEL 4
	.SCOM+35			/CALL.
	LAC	LV5AC		/RESTORE AC.
	JMP	L5DBK
LV5DBK	LAC	LV5AC		/RESTORE AC
	SKP
L5DBK	DBK			/DEBREAK FROM LEVEL 0
	DBR			/DEBREAK AND RESTORE
	XCT	.+1		/FROM LEVEL 5
	XCT	.+1
	JMP*	LV5INT
LV5BND	LAC	LV5SAT
	SZA
	JMP	LV5RGS
LV5CAL	DZM	LV5BSY		/CLEAR BUSY FLAG.
	LAC	BLV5SC		/RESTORE REGISTERS
	JMS	LV5RES		/THAT WERE SAVED
	LAC	BLV5MQ		/AT CAL TIME
EAE17	XCT	LLMQ		/WHEN THIS LEVEL
	JMS	LV5TRN		/WAS I/O BOUND.
	BLV5AR
	10
	JMP*	BLV5PC		/RETURN TO CAL.
/REGISTERS SAVED ON ENTRY TO LEVEL 5.
LV5AC	0			/AC.
LV5MQ	0			/MQ.
LV5SC	0			/STEP COUNTER.
LV5AIR	.BLOCK 10			/AUTO INDEX REGISTERS
LV5SAT=.SCOM+46			/0=I/O REQUEST SATISFIED.
/REGISTERS SAVED AT CAL TIME IF I/O BUSY.
BLV5MQ	0			/MQ
BLV5SC	0			/STEP COUNTER
BLV5AR	.BLOCK 10
BLV5PC	0			/PC (ADDRESS OF CAL OR CAL+2 IF .WAIT)
 
/ROUTINE TO RESTORE STEP COUNTER.
/ENTER WITH SAVED STEP COUNTER IN AC
LV5RES	0
LV5TMP=LV5RES
	XOR	(77
	TAD	(640402
EAE18	XCT	LAND		/AND (640477 OR LAW
	DAC	.+1
LV5DEF	XX
	JMP*	LV5RES
 
/ROUTINE TO MOVE A BLOCK OF 8 REGISTERS
/TO ANOTHER BLOCK OF 8 REGISTERS
/CALLING SEQUENCE:	JMS	LV5TRN
/TIME: 124 MICROSECS.	A	/FROM
/	COMPARED TO 32	B	/TO
/	IF DONE IN LINE.
/	SAVES 33(10) REGISTERS BASED ON 4 CALLS TO LV5TRN.
LV5TRN	0
	LAC*	LV5TRN
	DAC	L5TMP1		/FROM BLOCK A
	ISZ	LV5TRN
	LAC*	LV5TRN
	DAC	L5TMP2		/TO BLOCK B
	LAW	17770		/-10 (8)
	DAC	L5TMP3
LV5AGN	LAC*	L5TMP1		/FROM
	DAC*	L5TMP2		/TO
	ISZ	L5TMP1
	ISZ	L5TMP2
	ISZ	L5TMP3
	JMP	LV5AGN		/MORE TRANSFERS.
	ISZ	LV5TRN
	JMP*	LV5TRN
L5TMP1	0
L5TMP2	0
L5TMP3	0
	.EJECT
	.TITLE ENTERQ
 
/SUBROUTINE TO PLACE AN ENTRY IN
/THE API SOFTWARE LEVELS Q (APIQ).
/THE MAXIMUM TIME AT LEVEL 0
/IS 141(10) MICRO SECONDS. THE CALLER
/MUST REQUEST THE INTERRUPT AT THE LEVEL.
/ON RETURN FROM ENTERQ.
/CALLING SEQUENCE:	LAC	(400200	/RAISE TO
/		ISA		/LEVEL 0.
/		LAC	(LEVEL	/SUBR. ADDRESS
/		JMS*	(ENTERQ
/		DBK		/DBK FROM 0
 
ENTERQ	0
	DAC	TEMP		/SAVE ENTRY.
	LAC*	ENTRY		/POINTER MAY ALREADY CONTAIN
	SNA			/ADDRESS OF FREE SLOT.
	JMP	FOUND
	LAC	APIQND		/INITIALIZE POINTER
	DAC	ENTRY		/TO START OF APIQ.
BACK	ISZ	ENTRY
	LAC*	ENTRY
	SAD	APIQND
	JMP	FULL		/API SOFT. LEVEL Q FULL.
	SZA
	JMP	BACK
FOUND	LAC	TEMP		/DEPOSIT
	DAC*	ENTRY		/ENTRY
	ISZ	ENTRY		/UPDATE POINTER
	JMP*	ENTERQ		/FOR NEXT TIME.
	.EJECT
	.TITLE APIQ
 
 
/API SOFTWARE LEVELS Q
/	THE ENTRIES ARE INITIALLY 0.
/	WHICH INDICATES A FREE SLOT.
/	BITS 0-2 OF EACH ENTRY
/	CONTAIN THE SOFTWARE LEVEL
/	NUMBER:
/		5=API LEVEL 5
/		6=API LEVEL 6
/		7=API LEVEL 7
/	BITS 3-17 CONTAIN THE
/	ADDRESS OF THE SUBROUTINE
/	TO BE ENTERED AT THE
/	SPECIFIED LEVEL.
 
	.REPT	40
APIQ	0
	.LOC	APIQ
	.BLOCK	APIQSZ
APIQND	APIQ-1+400000
FULL	LAW	1053		/IOPS ERROR 53
	JMS	ERRORQ
TEMP	XX			/API LEVEL 0 TEMPORARY CELL.
	JMP*	ENTERQ
ENTRY	APIQ			/API Q POINTER.
	.EJECT
	.TITLE GETQ
 
 
/ROUTINE TO GET AN ENTRY FROM THE
/API SOFT. LEVELS Q FOR LEVEL N.
/CALLING SEQUENCE:		LAC	(400004		/RAISE TO
/			ISA			/LEVEL 5.
/			JMS	GETQ
/			N00000			/N=5,6,OR7
/			DBK			/DBK FROM 5.
/			ENTRY IS IN AC OR AC=0
 
GETQ	0			/IF NO ENTRY FOR THIS LEVEL
	LAC	APIQND		/POINTER TO
	DAC	ENTRYO		/START OF Q
.NXT	ISZ	ENTRYO
	LAC*	ENTRYO
	AND	(700000
	SAD*	GETQ
	JMP	FENTRY		/FOUND ENTRY.
	XOR	L4HTHO		/400000
	SZA
	JMP	.NXT		/NOT AT END OF Q
OUT	ISZ	GETQ		/BYPASS ARGUMENT.
	JMP*	GETQ		/EXIT.
FENTRY	LAC	ENTRYO		/SET UP FOR
	DAC	ENTRY		/ENTRY ROUTINE.
	LAC*	ENTRYO		/ENTRY TO AC.
	DZM*	ENTRYO		/CLEAR ENTRY
	JMP	OUT
ENTRYO	0			/API LEVEL 5 TEMPORARY CELL.
 
/FOREGROUND I/O BUSY REGISTERS--0=NOT BUSY---ADDRESS OF BUSY DEVICE=BUSY.
 
LV5BSY=.SCOM+42			/API LEVEL 5
LV6BSY=.SCOM+43			/API LEVEL 6
LV7BSY=.SCOM+44			/API LEVEL 7
	.EJECT
	.TITLE LV6INT
 
/LEVEL 6 API SOFTWARE LEVEL
/INTERRUPT HANDLER.
 
LV6INT	0			/PC,LINK,XMODE,MEM.PROT.
	DAC	LV6AC		/AC
EAE19	XCT	LLACQ
	DAC	LV6MQ		/MQ
EAE20	XCT	LLACS
	DAC	LV6SC		/STEP COUNTER
	JMS	LV6TRN		/SAVE AUTO INDEX
	10			/REGISTERS IN
	LV6AIR			/LV6AIR.
	LAC	LV6BSY
	SZA
	JMP	LV6BND		/I/O BOUND
LV6BCK	LAC	(400004		/RAISE TO LEVEL 5
	ISA
	JMS	GETQ		/GET LEVEL 6
	600000			/ENTRY FROM Q.
	DBK
	SNA			/AC IS 0 IF
	JMP	LV6RGS		/Q EMPTY FOR THIS LEVEL.
	DAC	LV6DEF		/JMS TO ADDRESS
	JMS*	LV6DEF		/SPECIFIED IN ENTRY
	JMP	LV6BCK		/CHECK FOR MORE ENTRIES.
LV6RGS	LAC	LV6SC		/RESTORE REGISTERS---ENTRY FROM CAL HANDLERS.
	JMS	LV6RES		/STEP COUNTER
	LAC	LV6MQ
EAE21	XCT	LLMQ
	JMS	LV6TRN		/AUTO INDEX
	LV6AIR			/REGISTERS.
	10
	705512			/READ API STATUS
	AND	(1401
	SZA
	JMP	LV6DBK		/LOWER LEVEL ACT. OR REQ.
	LAC	(400200		/RAISE TO API
	ISA			/LEVEL 0.
	JMS	CALL4		/INITIATE LEVEL
	LV6INT			/4 CALL.
	.SCOM+35
	LAC	LV6AC		/RESTORE AC
	JMP	L6DBK
LV6DBK	LAC	LV6AC		/RESTORE AC
	SKP
L6DBK	DBK			/FROM LEVEL 0
	DBR			/DEBREAK AND RESTORE
	XCT	.+1		/FROM LEVEL 6
	XCT	.+1
	JMP*	LV6INT
LV6BND	LAC	LV6SAT
	SZA
	JMP	LV6RGS
LV6CAL	DZM	LV6BSY		/CLEAR BUSY FLAG.
	LAC	BLV6SC		/RESTORE REGISTERS
	JMS	LV6RES		/THAT WERE SAVED
	LAC	BLV6MQ		/AT CAL TIME
EAE22	XCT	LLMQ		/WHEN THIS LEVEL
	JMS	LV6TRN		/WAS I/O BOUND.
	BLV6AR
	10
	JMP*	BLV6PC		/RETURN TO CAL.
/REGISTERS SAVED ON ENTRY TO LEVEL 6.
LV6AC	0			/AC.
LV6MQ	0			/MQ.
LV6SC	0			/STEP COUNTER.
LV6AIR	.BLOCK 10			/AUTO INDEX REGISTERS
LV6SAT=.SCOM+47			/0=I/O REQUEST SATISFIED.
/REGISTERS SAVED AT CAL TIME IF I/O BUSY.
BLV6MQ	0			/MQ
BLV6SC	0			/STEP COUNTER
BLV6AR	.BLOCK 10
BLV6PC	0			/PC (ADDRESS OF CAL OR CAL+2 IF .WAIT)
/ROUTINE TO RESTORE STEP COUNTER.
/ENTER WITH SAVED STEP COUNTER IN AC
LV6RES	0
LV6TMP=LV6RES
	XOR	(77
	TAD	(640402
EAE23	XCT	LAND		/AND (640477 OR LAW
	DAC	.+1
LV6DEF	XX
	JMP*	LV6RES
/ROUTINE TO MOVE A BLOCK OF 8 REGISTERS
/TO ANOTHER BLOCK OF 8 REGISTERS
/CALLING SEQUENCE:	JMS	LV6TRN
/TIME: 124 MICROSECS.	A	/FROM
/	COMPARED TO 32	B	/TO
/	IF DONE IN LINE.
/	SAVES 33(10) REGISTERSBASED ON 4 CALLS TO LV6TRN
LV6TRN	0
	LAC*	LV6TRN
	DAC	L6TMP1		/FROM BLOCK.
	ISZ	LV6TRN
	LAC*	LV6TRN
	DAC	L6TMP2		/TO BLOCK
	LAW	17770		/-10 (8)
	DAC	L6TMP3
LV6AGN	LAC*	L6TMP1		/FROM
	DAC*	L6TMP2		/TO
	ISZ	L6TMP1
	ISZ	L6TMP2
	ISZ	L6TMP3
	JMP	LV6AGN		/MORE TRANSFERS.
	ISZ	LV6TRN
	JMP*	LV6TRN
L6TMP1	0
L6TMP2	0
L6TMP3	0
	.EJECT
	.TITLE LV7INT
 
/LEVEL 7 API SOFTWARE LEVEL INTERRUPT HANDLER.
LV7INT	0			/PC,LINK,XMODE,MEM.PROT.
	DAC	LV7AC		/AC
EAE24	XCT	LLACQ
	DAC	LV7MQ		/MQ
EAE25	XCT	LLACS
	DAC	LV7SC		/STEP COUNTER
	JMS	LV7TRN		/SAVE AUTO INDEX
	10			/REGISTERS IN
	LV7AIR			/LV7AIR.
	LAC	LV7BSY
	SZA
	JMP	LV7BND		/I/O BOUND
LV7BCK	LAC	(400004		/RAISE TO LEVEL 5
	ISA
	JMS	GETQ		/GET LEVEL 7
	700000			/ENTRY FROM Q.
	DBK
	SNA			/AC IS 0 IF
	JMP	LV7RGS		/Q EMPTY FOR THIS LEVEL.
	DAC	LV7DEF		/JMS TO ADDRESS
	JMS*	LV7DEF		/SPECIFIED IN ENTRY
	JMP	LV7BCK		/CHECK FOR MORE ENTRIES.
LV7RGS	LAC	LV7SC		/RESTORE REGISTERS---ENTRY FROM CAL HANDLER
	JMS	LV7RES		/STEP COUNTER
	LAC	LV7MQ
EAE26	XCT	LLMQ
	JMS	LV7TRN		/AUTO INDEX
	LV7AIR			/REGISTERS.
	10
	705512
	AND	(400
	SZA
	JMP LV7DBK
LV7DNE=.
LV7TO0	LAC	(400200		/RAISE TO LEVEL 0
	ISA
	JMS	CALL4
	LV7INT
	.SCOM+35
	LAC	LV7AC
	JMP	L7DBK
LV7DBK	LAC	LV7AC		/RESTORE AC
	SKP
L7DBK	DBK			/DEBREAK FROM LEVEL 0
	DBR			/DEBREAK AND RESTORE
	XCT	.+1		/FROM LEVEL 7
	XCT	.+1
	JMP*	LV7INT
LV7BND	LAC	LV7SAT
	SZA
	JMP	LV7RGS
LV7CAL	DZM	LV7BSY		/CLEAR BUSY FLAG.
	LAC	BLV7SC		/RESTORE REGISTERS
	JMS	LV7RES		/THAT WERE SAVED
	LAC	BLV7MQ		/AT CAL TIME
EAE27	XCT	LLMQ		/WHEN THIS LEVEL
	JMS	LV7TRN		/WAS I/O BOUND.
	BLV7AR
	10
	JMP*	BLV7PC		/RETURN TO CAL.
/REGISTERS SAVED ON ENTRY TO LEVEL 7.
LV7AC	0			/AC.
LV7MQ	0			/MQ.
LV7SC	0			/STEP COUNTER.
LV7AIR	.BLOCK 10			/AUTO INDEX REGISTERS
LV7SAT=.SCOM+50			/0=I/O REQUEST SATISFIED.
/REGISTERS SAVED AT CAL TIME IF I/O BUSY.
BLV7MQ	0			/MQ
BLV7SC	0			/STEP COUNTER
BLV7AR	.BLOCK 10
BLV7PC	0			/PC (ADDRESS OF CAL OR CAL+2 IF .WAIT)
/ROUTINE TO RESTORE STEP COUNTER.
/ENTER WITH SAVED STEP COUNTER IN AC
LV7RES	0
LV7TMP=LV7RES
	XOR	(77
	TAD	(640402
EAE28	XCT	LAND		/AND (640477 OR LAW
	DAC	.+1
LV7DEF	XX
	JMP*	LV7RES
/ROUTINE TO MOVE A BLOCK OF 8 REGISTERS
/TO ANOTHER BLOCK OF 8 REGISTERS
/CALLING SEQUENCE:	JMS	LV7TRN
/TIME: 124 MICROSECS.	A	/FROM
/	COMPARED TO 32	B	/TO
/	IF DONE IN LINE.
/	SAVES 33(10) REGISTERS BASED ON 4 CALLS TO LV7TRN
LV7TRN	0
	LAC*	LV7TRN
	DAC	L7TMP1		/FROM BLOCK.
	ISZ	LV7TRN
	LAC*	LV7TRN
	DAC	L7TMP2		/TO BLOCK
	LAW	17770		/-10 (8)
	DAC	L7TMP3
LV7AGN	LAC*	L7TMP1		/FROM
	DAC*	L7TMP2		/TO
	ISZ	L7TMP1
	ISZ	L7TMP2
	ISZ	L7TMP3
	JMP	LV7AGN		/MORE TRANSFERS.
	ISZ	LV7TRN
	JMP*	LV7TRN
L7TMP1	0
L7TMP2	0
L7TMP3	0
	.ENDC
	.EJECT
	.TITLE MPVERR
 
/MEMORY PROTECT VIOLATION PROCESSOR
/
/DISPATCHES TO VARIOUS ROUTINES BASED ON OPCODE
/	CAL = ALWAYS ERROR
/	DAC = OK IF AUTO-INDEX OR BGD CORE
/	JMS = SPECIAL TEST FOR XCT STRING
/	DZM = OK IF AUTO-INDEX OR BGD CORE
/	LAC = ALWAYS OK
/	XOR = ALWAYS OK
/	ADD = ALWAYS OK
/	TAD = ALWAYS OK
/	XCT = XCT STRING TEST
/	ISZ = OK IF AUTO-INDEX OR BGD
/	AND = ALWAYS OK
/	SAD = ALWAYS OK
/	JMP = SPECIAL TEST FOR XCT STRING
/	EAE = ALWAYS OK
/	IOT = ALWAYS ERROR, EXCEPT IN BGD EXEC MODE
/	OPR = PAUSE IF HLT, OK IF OAS
/
/SPECIAL NOTE:
/	CERTAIN SYSTEM PROGRAMS MAY
/	MODIFY THE VARIOUS TABLES IN
/	THE RESIDENT MONITOR
/	1)PIP - .DATB
/	2).SYSLD - .DATB,.SCOM,.IOIN,.MUD,.BFTAB
/	3).LOAD - .DATB,.SCOM,.IOIN,.MUD,.BFTAB
/	4)BFKM9 - .DATB,.SCOM,.IOIN,.MUD,.BFTAB
MPSNE=701741
MPCV=701702
MPCNE=701744
 
MPVERR	DAC	MPVAC		/PIC ENTRY ALWAYS
	LAC	0
	DAC	MPVPC
	LAC	.SCOM+35		/INT SERV FLAG
	DAC	MPVFLG		/SAVE
	CLA!CMA
	DAC	.SCOM+35
	DZM	0
	MPCV
	ION
	LAW	-2
	DAC	MPVXSW		/SET TO ALLOW 1 XCT
	LAW	-1		/SET TO POINT TO ILLEGAL INSTRUCTION
	TAD	MPVPC
	AND	(77777
	DAC	MPVADR
	MPSNE			/IS IT NON-EXM?
	JMP	MPVIOP		/NO - PROCESS
	MPCNE			/YES - CLEAR FLAG
	LAW	6031		/.ERR 31 (NONEXMEM) BGD TERM ERROR.
	JMP	MPVSER
MPVIOP	LAC	MPVADR		/GET BANK BITS
	AND	(60000
	DAC	MPVBNK
	LAC	MPVPC		/GET PC CONTENTS
	AND	(77777
	CMA
	TAD	(1
	TAD	.SCOM+32		/HARDWARE BOUND
	SMA			/WAS PC BELOW BOUND?
	JMP	MPVBEX		/YES. POSSIBLY NOT AN ERROR.
MPBXMD	LAC*	MPVADR		/GET OPERAND
	AND	(17777
	DAC	MPVOPN		/SAVE AS 13 BITS
	LAC*	MPVADR
	AND	(20000
	SNA			/WAS IT INDIRECT?
	JMP	MPVNTI		/NO
LMIN10	LAW -10
	AND MPVOPN
	SAD	(10
	JMP .+4			/AUTOINDEX-DON'T ADD BANK BITS
	LAC MPVOPN
	XOR MPVBNK
	DAC MPVOPN
	LAC*	MPVOPN
	DAC	MPVOPN		/NEW OPERAND
MPVNTI	LAC*	MPVADR		/GO GET OPCODE
	RTL
	RTL
	RAL
	AND	L17		/(17
	TAD	MPVDIS		/JMP MPVTAB
	DAC	.+1
	XX			/MODIFIED JMP
MPVDIS	JMP	.+1
	JMP	MPVAER		/CAL
	JMP	MPVAIX		/DAC
	JMP	MPVXCS		/JMS
	JMP	MPVAIX		/DZM
	JMP	MPVAOK		/LAC
LW5THO	LAW	5000		/XOR
LAWTRM	LAW	4000		/ADD
	JMP	MPVAOK		/TAD
	JMP	MPVXCT		/XCT
	JMP	MPVAIX		/ISZ
LW1052	LAW	1052		/AND
	JMP	MPVAOK		/SAD
	JMP	MPVXCP		/JMP
EAE29	JMP	MPVOK1		/EAE (JMP MPVAER IF NO EAE)
	JMP	MPVIOT		/IOT
	LAC*	MPVADR		/OPR
	AND	(HLT
	SAD	(HLT		/IS IT A HALT?
	JMP	MPVAER		/YES.
	LAC	MPVAC		/MUST BE AN OAS
	OAS			/NOTE: OAS MICRO-PROGRAMMED
MPVOUT	DAC	MPVAC		/WITH ANY SKIP WON'T WORK
	.IFUND PI
MPVIO	LAC	(400200		/RAISE TO API
	ISA			/LEVEL 0
	.ENDC
	.IFDEF PI
MPVIO	IOF
	.ENDC
	JMS	CALL4
	MPVPC
	MPVFLG
	LAC	MPVFLG		/RESTORE INTERRUPT FLAG
	DAC	.SCOM+35
	LAC	MPVAC		/RESTORE AC
	.IFDEF PI
	ION
	.ENDC
	DBR			/RESTORE L,XM,MP
	XCT	.+1
	XCT	.+1
	JMP*	MPVPC		/RETURN
MPVXCS	SKP!CLA!CMA		/JMS
MPVXCP	CLA			/JMP
	DAC	MPVJMX		/JMP OR JMS SWITCH
	LAC	MPVOPN		/IS EFFECTIVE ADDRESS BELOW
	CMA			/HARDWARE BOUND?
	TAD	(1
	TAD	.SCOM+32
	SMA!SZA
	JMP	MPVXER		/YES - ERROR
	LAC	MPVOPN		/NO - BUILD PROPER EXIT
	AND	(77777		/GET 15 BIT ADDRESS
	DAC	MPVOPN
	LAC	MPVJMX		/JMP/JMS SWITCH
	RAL
	LAC	MPVPC		/INTERRUPT PC
	SZL
	DAC*	MPVOPN		/SAVE JMS ENTRY
	SZL
	ISZ	MPVOPN		/BUMP PC FOR JMS
	AND	(700000
	XOR	MPVOPN
	DAC	MPVPC		/NEW PC FOR JMP OR JMS
	JMP	MPVIO
MPVXCT	LAC	MPVOPN		/GET EFFECTIVE ADDRESS
	DAC	MPVADR		/MAKE IT NEW ADDRESS FOR TESTS
	ISZ	MPVXSW		/MORE THAN 1 XCT?
	JMP	MPVIOP		/NO - GO TRY THIS INSTRUCTION
MPVXER	LAW	-1		/YES - TOO MANY
	TAD	MPVPC
	DAC	MPVADR
	JMP	MPVAER
MPVIOT	LAC	.SCOM+101		/IOT'S ARE LEGAL ONLY
	SNA			/IN BGD EXEC MODE - NOT
	JMP	MPVAER		/IN USER MODE.
	JMP	MPVOK1
MPVAOK	LAC*	MPVADR		/GET INSTRUCTION
	AND	(20000
	SNA
	JMP	MPVOK1		/NOT INDIRECT.
	LAC*	MPVADR		/GET ADDRESS
	AND	(17777
	DAC	MPVTMP
	AND	LMIN10		/(-10
	SAD	(10
	SKP!CLC
	JMP	MPVOK1
 
/SINCE THE INSTRUCTION WILL BE EXECUTED, FIRST DECREMENT THE AX REGISTER.
 
	TAD*	MPVTMP		/POINTING AT THE AX REGISTER.
	DAC*	MPVTMP
MPVOK1	LAC	MPVPC		/RESTORE THE LINK
	RAL
	LAC	MPVPC
	AND	(377777
	DAC	MPVPC		/CLEAR LINK BIT 0
	LAC	MPVAC		/RESTORE THE AC
	XCT*	MPVADR		/EXECUTE INSTRUCTION
	SKP
	ISZ	MPVPC		/SIMULATE SKIP
	DAC	MPVAC		/SAVE THE AC
	CLA!RAR
	XOR	MPVPC
	DAC	MPVPC		/SAVE THE LINK
	JMP	MPVIO
MPVAIX	LAW	-10		/AUTOINDEX REFERENCE?
	AND	MPVOPN
	SAD	(10
	JMP	MPVAOK		/YES - OK
	LAC	MPVOPN		/NO - BELOW SOFTWARE
	CMA			/BOUNDARY?
	TAD	(1
	TAD	.SCOM+31
	SPA!SNA
	JMP	MPVAOK		/NO - OK
MPVSEX	LAC	.SCOM+41		/YES - SPECIAL SYSTEM
	SPA			/PROGRAM CHECK
	JMP	MPVAOK		/OK - A LOADER
	SAD	(3
	JMP	MPVAOK		/OK - PIP
	SAD	(17777
	JMP	MPVAOK		/OK - MONITOR
MPVAER	LAW	6032		/ERROR MESSAGE - BGD TERMINAL
MPVSER	DAC	MPVLAW
	.IFUND PI
	LAC	(400200
	ISA
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
MPVLAW	XX
	JMS	ERRORQ
MPVADR	XX
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	LAC	(MPVJPT+200000	/RETURN BGD TO A JMP .
DACPC	DAC	MPVPC
	JMP	MPVIO
MPVBEX	LAC	.SCOM+101		/NON-0 INDICATES BGD EXEC MODE.
	SZA
	JMP	MPBXMD		/YES.
	JMP	MPVAER		/NO. ERROR DUE TO A JMP.
MPVPC	0			/PC ON INTERRUPT
MPVAC	0			/AC ON INTERRUPT
MPVFLG	0			/IN SERVICE FLAG
MPVBNK	0			/BANK BITS
MPVOPN	0			/OPERAND
MPVTMP	0
MPVXSW	0			/EXECUTE COUNT
MPVJMX	0			/JMP OR JMS
	.EJECT
	.TITLE IOTS
 
/IOT DEFINITIONS
 
DTDF=707601
CLSF=700001
MPSK=701701
SPDF=700662
RS1=700602
SPMI=700722
CFD=701601
LSDF=706501
RSF=700101
PSF=700201
KSF0=700301
KSF1=704101
KSF2=704121
KSF3=704141
KSF4=704161
KSF5=704301
KSF6=704321
KSF7=704341
KSF10=704361
KSF11=704501
KSF12=704521
KSF13=704541
KSF14=704561
KSF15=704701
KSF16=704721
KSF17=704741
KSF20=704761
TSF0=700401
TSF1=704001
TSF2=704021
TSF3=704041
TSF4=704061
TSF5=704201
TSF6=704221
TSF7=704241
TSF10=704261
TSF11=704401
TSF12=704421
TSF13=704441
TSF14=704461
TSF15=704601
TSF16=704621
TSF17=704641
TSF20=704661
DTEF=707561
SPFAL=703201
RCSF=706701
RCSD=706721
SPE=702701
DSSF=707121
MTSF=707341
	.EJECT
	.TITLE .TVTAB
 
/TRANSFER VECTORS
 
/BIT0 = 0 IF FGD
/BIT0 = 1 IF BGD
/BIT1 = 1 IF FOR LOADER
 
LSETTV	.+1
.TVTAB=.
DTDFTV	ERR
DTEFTV	ERR
DSSFTV	ERR
RSFTV	ERR
PSFTV	ERR
LSDFTV	ERR
RCSFTV	ERR
RCSDTV	ERR
MTSFTV	ERR
SPDFTV	ERR
	.REPT	26	/SPACE FOR USER T.V.S
TVREPT	ERR
	.LOC	TVREPT
	.BLOCK	TVSIZE-.+.TVTAB
 
	.EJECT
	.TITLE .SKTAB
 
/SKIP LITERALS
 
LSETSK	.+1
.SKTAB=.
LTDTDF	DTDF
LTDTEF	DTEF
LTDSSF	DSSF
LTRSF	RSF
LTPSF	PSF
LTLSDF	LSDF
LTRCSF	RCSF
LTRCSD	RCSD
LTMTSF	MTSF
LTSPDF	SPDF
	.REPT	26	/SPACE FOR USER SKIPS.
SKREPT	0
	.LOC	SKREPT
	.BLOCK	TVSIZE-.+.SKTAB
LERR	ERR		/LITERAL ALSO USED BY .SGEN.
	.EJECT
	.TITLE SKPCHN
 
/SKIP CHAIN
 
.IOSK=.
 
/SIZE OF SKIP CHAIN = 3 TIMES # OF ENTRIES. # OF ENTRIES = # OF
/TRANSFER VECTORS + (2 TIMES # OF TELETYPES MAX.) + 2 (FOR MPSK
/AND CLSF). MEMORY PROTECT, THE CLOCK, AND THE TELETYPES DO NOT
/NEED TRANSFER VECTORS; THEY GO DIRECTLY TO ROUTINE.
 
	.BLOCK	TVSIZE+2+TTYS+TTYS*3
IOSKND=.
	.LOC	.IOSK
	MPSK			/MEMORY PROTECT VIOLATION.
	SKP
	JMP	MPVERR
	.IFDEF PI
	DTDF			/DECTAPE DONE.
	SKP
	JMP*	DTDFTV
	SPDF			/339 DISPLAY DONE.
	SKP
	JMP*	SPDFTV
	MTSF			/MAG TAPE.
	SKP
	JMP*	MTSFTV
	RCSF			/CARD READER DATA READY.
	SKP
	JMP*	RCSFTV
	RCSD			/CARD READER DONE.
	SKP
	JMP*	RCSDTV
	DSSF			/RB09 DISK.
	SKP
	JMP*	DSSFTV
	LSDF			/LINE PRINTER DONE.
	SKP
	JMP*	LSDFTV
	CLSF			/CLOCK.
	SKP
	JMP	CLKPIC
	RSF			/PAPER TAPE READER.
	SKP
	JMP*	RSFTV
	.ENDC
	PSF			/PAPER TAPE PUNCH.
	SKP
	JMP*	PSFTV
	KSF0			/TTY KEYBOARD 0.
	SKP
	JMS	KBDPI
	KSF1
	SKP
	JMS	KBDPI
	.IFPOZ TTYS-3
	KSF2
	SKP
	JMS	KBDPI
	.ENDC
	.IFPOZ TTYS-4
	KSF3
	SKP
	JMS	KBDPI
	.ENDC
	.IFPOZ TTYS-5
	KSF4
	SKP
	JMS	KBDPI
	.ENDC
	.IFPOZ TTYS-6
	KSF5
	SKP
	JMS	KBDPI
	.ENDC
	.IFPOZ TTYS-7
	KSF6
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-10
	KSF7
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-11
	KSF10
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-12
	KSF11
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-13
	KSF12
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-14
	KSF13
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-15
	KSF14
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-16
	KSF15
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-17
	KSF16
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-20
	KSF17
	SKP
	JMS KBDPI
	.ENDC
	.IFPOZ TTYS-21
	KSF20
	SKP
	JMS KBDPI
	.ENDC
	TSF0			/TTY PRINTER 0.
	SKP
	JMS	TPRPI
	TSF1
	SKP
	JMS	TPRPI
	.IFPOZ TTYS-3
	TSF2
	SKP
	JMS	TPRPI
	.ENDC
	.IFPOZ TTYS-4
	TSF3
	SKP
	JMS	TPRPI
	.ENDC
	.IFPOZ TTYS-5
	TSF4
	SKP
	JMS	TPRPI
	.ENDC
	.IFPOZ TTYS-6
	TSF5
	SKP
	JMS	TPRPI
	.ENDC
	.IFPOZ TTYS-7
	TSF6
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-10
	TSF7
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-11
	TSF10
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-12
	TSF11
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-13
	TSF12
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-14
	TSF13
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-15
	TSF14
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-16
	TSF15
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-17
	TSF16
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-20
	TSF17
	SKP
	JMS TPRPI
	.ENDC
	.IFPOZ TTYS-21
	TSF20
	SKP
	JMS TPRPI
	.ENDC
	.IFDEF PI
	DTEF			/DECTAPE ERROR.
	SKP
	JMP*	DTEFTV
	.ENDC
	JMP	ERR
	.LOC	IOSKND
/REGISTER AT END OF EXISTING SKIP CHAIN AND REGISTER AT END OF MAXIMUM
/SIZED SKIP CHAIN CONTAIN JMP ERR (USED BY SYSTEM GENERATOR).
	JMP	ERR
	.EJECT
/ILLEGAL INTERRUPT.
 
ERR	NOP		/MAY JMS HERE IF API CHAN REG NOT SET UP.
	DAC ERR.AC	/SAVE AC
	.IFUND PI
	LAC (400200	/RAISE TO LEVEL 0
	ISA
	LAC ERR
	DAC ERR.PC	/IN CASE IT WAS API INTERRUPT
	LAC LNOP		/(NOP
	SAD ERR		/API JMS TO ERR?
	JMP ERRPI		/NO.
	DAC ERR		/YES. RESTORE ENTRY POINT
	JMP .ERR3
	.ENDC
ERRPI	LAC 0
	DAC ERR.PC	/SAVE PC
	DZM 0
	LAC LION		/(ION
.ERR3	DAC ERRION
	LAW 7003		/FGD AND BGD TERM .ERR 3
	JMS ERRORQ
ERR.PC	XX		/ARGUMENT
	LAC ERR.AC
ERRION	XX		/NOP OR ION
	CAF		/CLEAR ALL FLAGS.
	.IFUND PI
	DBK		/FROM 0
	.ENDC
	DBR		/FROM API INTERRUPT
	XCT .+1
	XCT .+1
	JMP* ERR.PC	/DISMISS INTERRUPT
ERR.AC	0		/SAVED AC
	.IFUND PI
CLKPIC=ERR
	.ENDC
	.IFDEF PI
CLKAPI=ERR
	.ENDC
	.EJECT
	.TITLE .SETUP
 
/.SETUP SUBROUTINE
.SETUP	0
	LAW	-TVSIZE
	DAC	.SETT1
	LAC	LSETTV		/PTR TO 1ST T.V.
	DAC	.SETT2
	LAC	LSETSK		/PTR TO 1ST IOT SKIP.
	DAC	.SETT3
.SETNX	LAC*	.SETUP		/GET SKIP IOT
	SAD*	.SETT3		/IS IT THIS ONE?
	JMP	.SETOK		/YES
	ISZ	.SETT3		/NO - SET TO NEXT
	ISZ	.SETT2
	ISZ	.SETT1		/ANY MORE?
	JMP	.SETNX		/YES - GO TRY NEXT
	LAC .SETUP		/ILLEGAL .SETUP
	DAC .SETT1
	AND (77777
	CMA!CLL
	TAD .SCOM+25		/FGD BOUND
	LAW 5005			/FGD TERMINAL ERROR 5
	SNL
	LAW 6005			/BGD TERMINAL ERROR 5
	JMS ERRORQ
.SETT1	XX			/ARG: PC FROM .SETUP
	.IFUND PI
	DBK
	.ENDC
	JMP CALXIT
.SETOK	ISZ	.SETUP		/POINTS TO TV
	LAC*	.SETUP
	ISZ	.SETUP
	AND	(77777
	DAC*	.SETT2		/IN TRANSFER VECTOR
	CMA
	TAD	(1
	TAD	.SCOM+25
	SMA!CLA			/TV>C(.SCOM+25) - BGD TV?
	JMP	.SETFG		/NO - FGD
	LAC*	.SETT2		/YES - BGD
	XOR	L4HTHO		/(400000
	DAC*	.SETT2		/SET BGD BIT
.SETLD	LAC	.SCOM+41
	SMA			/LOADER RUNNING?
	JMP*	.SETUP		/NO - RETURN
	LAC*	.SETT2		/YES
	XOR	L2HTHO		/(200000
	DAC*	.SETT2		/SET LOADER SPECIAL BIT
	JMP*	.SETUP		/RETURN
.SETFG	SAD	.SCOM+65		/HAS FGD USER'S PROGRAM STARTED?
	JMP	.SETLD		/NO - CHECK FOR LOADER
	JMP*	.SETUP		/YES - RETURN
.SETT2	0
.SETT3	0
	.EJECT
	.TITLE FGDERQ
 
/ERROR QUEUES (1 FOR FGD AND 1 FOR BGD)
/	EACH INCLUDES SPACE FOR NON-TERMINAL
/	ERRORS, AN ERRORS-DISCARDED COUNT, AND ROOM FOR
/	ONE TERMINAL ERROR. IF A TERMINAL ERROR HAS
/	BEEN ENTERED, ALL OTHER ERRORS ARE IGNORED.
 
/FGD REGISTERS AND QUEUE
 
FERCNT	LAW	0		/# OF FGD NON-TERMINAL ERRORS
FERDIS	0			/# OF DISCARDED NON-TERMINAL ERRORS
FERNXT	FERQUE			/ENTRY POINT FOR NEXT NON-TERM ERROR
FERTRM	0			/BLOCK FOR TERMINAL ERROR
	0
	.REPT	40
FERQUE	0			/FGD QUEUE
	.LOC	FERQUE
	.BLOCK	ERRQSZ*2
FERQPT	FERQUE+400000		/END OF QUEUE (BIT0=1) AND POINTER TO BEGINNING
 
	.EJECT
	.TITLE BGDERQ
 
/BGD REGISTERS AND QUEUE
 
BERCNT	LAW	0
BERDIS	0
BERNXT	BERQUE
BERTRM	0
	0
	.REPT	40
BERQUE	0
	.LOC	BERQUE
	.BLOCK	ERRQSZ*2
BERQPT	BERQUE+400000
 
	.EJECT
	.TITLE ERRORQ
 
/ERRORQ ROUTINE TO  PROCESS ERRORS FROM EITHER THE
/	CAL OR INTERRUPT PORTIONS OF THE MONITOR.
/	IT IS ALWAYS CALLED AT LEVEL 0 WITH THE PI
/	OFF AND WITH THE ERROR CODE IN THE AC.
/	THE ERROR INFORMATION IS POINTED AT BY ERRORQ.
 
ERRORQ	0
	AND	(7777
	DAC	ERSAV		/SAVE ERROR CODE
	RTL
	RTL
	RTL			/TERMINAL BIT IN SIGN POSITION
	SPA!RTL			/IS IT TERMINAL ERROR
	JMP	ERTERM		/YES
	SML!RAL			/BGD ERR - NON TERMINAL TYPE.
	JMP	ERRNBN		/NO - NOT BGD NON-TERM
	LAC	BERTRM		/YES - IS BGD TERM ERROR? - NOTE LINK NOT CHANGED
	SZA			/FROM HERE TO ERRNBN
	JMP	ERRNBN		/YES  - IGNORE THIS NON-TERM
	LAC	.SCOM+71		/NO - ENTER INTO QUEUE(BGD)
	AND	(377777
	XOR	L4HTHO		/(400000
	DAC	.SCOM+71		/SET BGD ERROR FLAG
	LAW	ERRQSZ
	SAD	BERCNT		/IS QUEUE FULL?
	JMP	ERRBFL		/YES - GO INDEX ERROR DISCARD COUNT
	LAC	ERSAV		/NO - GET ENTRY AC
	DAC*	BERNXT		/PUT CODE IN QUEUE
	ISZ	BERNXT
	LAC*	ERRORQ		/GET INFO FOR QUEUE
	DAC*	BERNXT
	ISZ	BERNXT		/SETUP FOR NEXT CALL
	LAC*	BERNXT		/CHECK FOR END OF QUEUE
	SPA
	DAC	BERNXT		/RESTART AT BEGINNING
	ISZ	BERCNT		/BUMP QUEUE COUNT
	SKP
ERRBFL	ISZ	BERDIS		/DISCARDED ERROR COUNT
ERRNBN	SML			/IS IT FGD?
	JMP	ERROUT		/NOT FGD NON-TERM
	LAC	FERTRM
	SZA			/ANY FGD TERM ERR
	JMP	ERROUT		/YES - IGNORE THIS NON-TERM
	LAC	.SCOM+71		/NO - ENTER IN QUEUE(FGD)
	AND	(577777
	XOR	L2HTHO		/(200000
	DAC	.SCOM+71		/SET FGD ERROR FLAG
	LAW	ERRQSZ
	SAD	FERCNT		/IS QUEUE FULL?
	JMP	ERRFFL		/YES - GO INDEX DISCARD COUNT
	LAC	ERSAV		/NO - GET ENTRY AC
	DAC*	FERNXT		/PUT CODE IN QUEUE
	ISZ	FERNXT
	LAC*	ERRORQ		/GET INFO FOR QUEUE
	DAC*	FERNXT
	ISZ	FERNXT		/SETUP FOR NEXT CALL
	LAC*	FERNXT		/CHECK FOR END OF QUEUE
	SPA
	DAC	FERNXT		/RESTART AT BEGINNING
	ISZ	FERCNT		/BUMP QUEUE COUNT
	SKP
ERRFFL	ISZ	FERDIS		/DISCARDED ERROR COUNT
ERROUT	ISZ	ERRORQ		/BUMP PAST ERROR INFO
	JMP*	ERRORQ		/RETURN AT LEVEL 0 WITH PI OFF
ERTERM	SML!RAL			/IS IT BGD ERROR? - NOTE: LINK SET FOR ERRNBT
	JMP	ERRNBT		/NO - NOT BGD TERM ERROR
	LAC	BERTRM		/YES - IS BGD TERM ERROR IN PROGRAM
	SZA
	JMP	ERRNBT		/YES - IGNORE THIS ERROR
	LAC	ERSAV		/NO - 1ST BGD TERMINAL
	DAC	BERTRM		/SAVE TERM ERROR CODE
	LAC*	ERRORQ
	DAC	BERTRM+1		/AND ALSO ERROR INFO
	LAC	.SCOM+71
	AND	(277777
	XOR	(500000
	DAC	.SCOM+71		/SET BGD TERM ERR FLAG
ERRNBT	SML			/IS IT FGD?
	JMP	ERROUT		/NO - ALL DONE
	LAC	FERTRM		/YES - ANY FGD TERM ERROR IN
	SZA
	JMP	ERROUT		/IGNORE SINCE FGD TERM ERROR CODE
	LAC	ERSAV		/SAVE TERM ERROR CODE
	DAC	FERTRM
	LAC*	ERRORQ		/AND ALSO ERROR INFO
	DAC	FERTRM+1
	LAC	.SCOM+71
	AND	(537777
	XOR	(240000
	DAC	.SCOM+71		/SET FGD TERM ERR FLAG
	JMP	ERROUT		/ALL DONE
 
ERSAV	0			/TEMP FOR CODE
 
	.EJECT
	.TITLE FGDERR
 
/FOREGROUND ERROR TYPEOUT ROUTINE - FGD MAINSTREAM
 
FGDERR	0
	DAC	FGDERA		/SAVE AC FOR EXIT
	LAC	FERQPT		/INITIALIZE QUEUE POINTER
	DAC	FERPNT
	.IFUND PI
FERL0R	LAC	(400200		/RAISE TO API 0
	ISA
	.ENDC
	.IFDEF PI
FERL0R	IOF
	.ENDC
FERCTS	LAC	FCTL.Q
	SPA
	JMP	FERCTQ		/^Q WAS TYPED.
	LAW	0
	SAD	FERCNT		/ANYTHING IN QUEUE
	JMP	FGDEDS		/NO - CHECK DISCARD COUNT
	.IFUND PI
	DBK			/YES - PRINT ERROR
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	LAC*	FERPNT		/GET ERROR CODE
	DAC	.+6
	ISZ	FERPNT
	LAC*	FERPNT		/GET ERROR INFO
	DAC	.+4
	ISZ	FERPNT
	JMS	FERBER		/BUILD FGD ERROR MSG AND TYPE IT
	XX			/ERROR CODE BITS 9-17
	XX			/ERROR INFO BITS 0-17
	.IFUND PI
	LAC	(400200		/RAISE TO API 0
	ISA
	.ENDC
	.IFDEF PI
	IOF			/PIC OFF
	.ENDC
	LAW	-1
	TAD	FERCNT
	DAC	FERCNT		/DECREMENT COUNT
	JMP	FERCTS		/GO TEST FOR EMPTY QUEUE
FGDEDS	LAC	FERDIS		/ANY ERRORS DISCARDED?
	SNA
	JMP	FERTET		/N0 - GO TEST TERMINAL ERROR
	DZM	FERDIS
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	DAC	.+3		/SAVE COUNT
	JMS	FERBER		/BUILD+PRINT
	LAW	62		/ERROR CODE 62
	XX			/COUNT=INFO
	JMP	FERL0R		/GO SEE IF ANY MORE ENTERED
FERTET	LAC	FERTRM		/TERMINAL ERROR REGISTER
	SNA
	JMP	FEROUT		/EXIT FROM ERROR ROUTINE
	.IFUND PI
FERCTQ	DBK
	.ENDC
	.IFDEF PI
FERCTQ	ION
	.ENDC
 
/CALL ALL HANDLERS IN .DATF TO STOP FGD I/O
 
	DZM	FCTL.R		/DISABLE FGD ^R.
	LAC*	.SCOM+16
	DAC	FERTP1		/POINTS TO .DATND
	LAC*	FERTP1
	DAC	FERTP2		/POINTS TO .DATBG
FERDTL	LAC	FERTP2		/GET .DAT SLOT POINTER
	SAD	.SCOM+16		/IS IT .DAT+0?
	JMP	FERDTI		/YES - IGNORE ENTRY
	SAD	FERTP1		/IS IT END OF .DAT TABLE?
	JMP	FERDTD		/YES - ALL I/O FINISHED
	LAC*	FERTP2		/GET .DAT SLOT CONTENTS
	SMA!CLL!RAL		/IS THE .DAT SLOT SETUP?
	JMP	FERDTI		/NO - IGNORE THIS ENTRY
	SPA!CLL!RAL		/IS IT A TTA ENTRY?
	JMP	FERDTI		/YES - IGNORE
	TAD	(34
	DAC	FERTP3		/SAVE POINTER TO WD 34 OF I/O HANDLER
	LAC*	FERTP3		/GET JMS ENTRY TO STOP I/O
	DAC	FERTP3
	JMS*	FERTP3		/GO STOP FGD I/O
FERDTI	ISZ	FERTP2		/NEXT .DAT ENTRY
	JMP	FERDTL		/GO PROCESS
FERDTD	JMS*	TTA.+34		/CLEAR FGD TT I/O.
 
/REMOVE ALL FGD ENTRIES FROM CLOCKQ, APIQ, AND
/	CLEAR ALL FGD I/O BUSY REGS.
 
	CLOF
	LAC	CLOKON		/ANY CLOCK INTERVALS
	SNA
	JMP	FERNQE
	LAC	CLKRTN
	AND	(700000
	SAD	(300000
	CLA			/MAY BE BACKGROUND.
	SZA			/IS IT BGD?
	DZM	CLKRTN		/NO - TURN IT OFF
	LAC	CLCKQN		/GET BEGINNING OF QUEUE
	DAC	FERTP1
FERNCL	LAC*	FERTP1		/GET QUEUE ENTRY
	AND	(700000
	SAD	L4HTHO		/(400000
	JMP	FERNCK		/END OF QUEUE
	SAD	(300000
	CLA			/MAY BE BACKGROUND.
	SZA			/IS IT BGD?
	DZM*	FERTP1		/NO - CLEAR ENTRY
	ISZ	FERTP1		/BUMP TO NEXT ENTRY
	ISZ	FERTP1
	JMP	FERNCL		/GO TEST NEXT
FERNCK	LAC	7
	SNA!CMA
	DAC	7
	CLON
	.IFUND	NOAPI
FERNQE	LAC	APIQND		/APIQ-1
	TAD	(1
	DAC	FERTP1
	LAC*	FERTP1		/GET API ENTRY
	SAD	APIQND		/IS IT END?
	JMP	.+4		/YES
	DZM*	FERTP1		/NO - CLEAR ENTRY
	ISZ	FERTP1		/GO TRY NEXT ENTRY
	JMP	.-5
	DZM	.SCOM+42		/CLEAR LEVEL 5 BUSY
	DZM	.SCOM+43		/CLEAR LEVEL 6 BUSY
	DZM	.SCOM+44		/CLEAR LEVEL 7 BUSY
	DZM	.SCOM+45		/CLEAR MAINSTREAM BUSY
	DZM	.SCOM+46		/CLEAR LEVEL 5 I/O SAT.
	DZM	.SCOM+47		/CLEAR LEVEL 6 I/O SAT.
	DZM	.SCOM+50		/CLEAR LEVEL 7 I/O SAT.
	.ENDC
	.IFDEF	NOAPI
FERNQE	DZM	.SCOM+45		/CLEAR MAINSTREAM BUSY.
	.ENDC
	DZM	.SCOM+57		/CLEAR MAINSTREAM
	DZM	.SCOM+60		/SUBROUTINES
	DZM	FRWRIT		/CLEAR FGD ^R MSG FLAG.
	.IFUND PI
	DZM	.SCOM+63		/CLEAR API REQUESTS
	DZM	.SCOM+74		/CLEAR API ERROR LEVELS
	.ENDC
	LAC	FCTL.Q
	SPA
	JMP	FERCQ1		/^Q WAS TYPED. NO ERROR MSG.
	.CLOSE	-3		/PRINT CAR. RET. LINE FEED.
	LAC	FERTRM
	DAC	.+4		/SAVE ERROR CODE
	LAC	FERTRM+1
	DAC	.+3		/SAVE ERROR INFO
	JMS	FERBER		/BUILD+PRINT ERROR
	XX			/ERROR CODE
	XX			/ERROR INFO
	.IFUND PI
FERCQ1	LAC	(400200		/RAISE TO ZERO (API)
	ISA
	.ENDC
	.IFDEF PI
FERCQ1	IOF			/PI OFF
	.ENDC
	LAC	.SCOM+71
	AND	(537777
	DAC	.SCOM+71
	LAW	0		/CLEAR QUEUE
	DAC	FERCNT
	LAC	FERQPT		/RESET NEXT TO BEGINNING
	DAC	FERNXT
	DZM	FERDIS		/CLEAR DISCARDED ENTRIES
	DZM	FERTRM
	DZM	FGDERR
	.IFUND	NOAPI
	LAC	(JMS LV5INT
	DAC	41
	LAC	(JMS LV6INT
	DAC	42
	LAC	(JMS LV7INT
	DAC	43
	.ENDC
	LAC	FCTL.Q
	SPA
	JMP	DOCTLQ
	LAC	.SCOM+65		/FGD USER RUNNING?
	SNA
	JMP	.BOOT		/NO.
	JMP	DBKIDL
FEROUT=.
	.IFUND	NOAPI
	LAC	.SCOM+74		/RAISE TO PROPER API LEVELS+LEVEL 0
	AND	(7		/AND REQUEST INTERRUPTS AT 5,6,7
	XOR	(403600
	DBK
	ISA
	LAC	(JMS LV5INT
	DAC	41
	LAC	(JMS LV6INT
	DAC	42
	LAC	(JMS LV7INT
	DAC	43
	.ENDC
	LAC	.SCOM+71
	AND	(537777
	DAC	.SCOM+71
	LAC	FGDERA		/AC ON ENTRY TO ERROR ROUTINE
	.IFUND PI
	DBK			/FROM 0
	.ENDC
	.IFDEF PI
	ION			/PI ON
	.ENDC
	CAL	FGDERR		/.RLXIT
	20
FERBER	0			/PRINT ERROR
	LAC	(FERBUF+10
	DAC	FERTP1		/POINTS TO 1ST OCTAL DIGIT
	LAW	-3
	DAC	FERTP2		/3 DIGITS 1ST TIME
	LAC*	FERBER		/GET ERROR CODE
	ISZ	FERBER
	RTL			/9 LEFT
	RTL
	RTL
	RTL
	RAL
	JMS	FERFBF		/FILL BUFFER WITH 3 DIGITS
	ISZ	FERTP1		/SKIP SPACE
	LAW	-6
	DAC	FERTP2		/6 DIGITS THIS TIME
	LAC*	FERBER		/GET ERROR INFO
	ISZ	FERBER
	JMS	FERFBF		/PUT LAST 6 IN BUFFER
	.WRITE	-3,3,FERBUF,20
	.WAIT	-3
	JMP*	FERBER		/RETURN
FERFBF	0			/FILL BUFFER WITH DIGITS
	DAC	FERTP3		/SAVE WORD
FERFBL	LAC	FERTP3		/POSITION FOR CONVERSION
	RTL			/TO OCTAL
	RAL
	DAC	FERTP3		/SAVE FOR NEXT DIGIT
	RAL
	AND	(7
	XOR	(60		/MAKE OCTAL
	DAC*	FERTP1		/PUT INTO BUFFER
	ISZ	FERTP1
	ISZ	FERTP2		/ANY MORE?
	JMP	FERFBL		/YES
	JMP*	FERFBF		/RETURN
/
FERTP1	0			/TEMP
FERTP2	0			/TEMP
FERTP3	0			/TEMP
FGDERA	0			/ENTRY AC
FERPNT	0			/POINTER
FERBUF	12003;	0
	40			/SPACE
	56			/.
	105			/E
	122			/R
	122			/R
	40			/SPACE
	XX			/0
	XX			/0
	XX			/0
	40			/SPACE
	XX			/0
	XX			/0
	XX			/0
	XX			/0
	XX			/0
	XX			/0
L15	15			/CR
L12	12			/LF
	.EJECT
	.TITLE CNTRLQ
 
/FGD AND BGD CONTROL Q PROCESSING.
 
DOCTLQ	DZM FCTL.P
	DZM FCTL.S
	DZM BCTL.C
	DZM BCTL.P
	DZM BCTL.T
	DZM BCTL.S
	DZM .SCOM+65		/ALLOW FGD TO USE RESBUF.
	.IFUND DK
	JMS* DTA.+35		/CALL DTA TO STOP BGD I/O
	.ENDC
	.IFDEF DK
	JMS* DKA.+35
	.ENDC
	LAC (MPVJPT+200000		/ADDRESS OF A JMP .
	DAC .SCOM+33		/TO BGD SAVED PC.
BGD.Q=.
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
 
QWRITE	CAL 2775		/.WRITE -3 IOPS ASCII.
	11
	QMSG
QTEMP	0
 
	CAL 3776		/.READ -2 IMAGE ALPHA.
	10
	QBUF
	-3		/1 CHAR + 2 WORD HEADER.
 
	CAL 776		/.WAIT -2
	12
 
	LAW -61		/IS CHAR 1 THRU 7?
	TAD QBUF+2
	SPA
	JMP QWRITE	/NO. <61. TRY AGAIN.
	TAD MINUS7
	SMA!STL		/NEXT TAD WILL CML ON OVERFLOW.
	JMP QWRITE	/>67. TRY AGAIN.
	TAD (10		/LINK IS CLEARED HERE.
	RTR
	RTR
	RTR
	TAD .IOIN+3	/SYS DEVICE ENTRY.
	DAC QTEMP		/SYS DEV ENTRY + UNIT #.
 
/SEARCH THRU .IOIN TABLE TO MAKE SURE THAT THE FGD ^Q
/IS NOT TO A BGD UNIT AND VICE VERSA, UNLESS THE $SHARE
/FLAG IS ON.
 
	LAC .SCOM+77	/$SHARE FLAG
	SZA
	JMP QSHARE
	SAD .SCOM+26	/FGD=0; BGD=1.
	JMP QFGD
 
/CHECK THAT BGD ^Q IS NOT TO A FGD UNIT.
 
	LAC (.IOIN+3	/PTR TO 1ST FGD/MONITOR ENTRY.
	DAC QPTR
	LAC .IOIN+2	/COUNT OF FGD/MONITOR ENTRIES.
	JMP QIOIN
 
/CHECK THAT FGD ^Q IS NOT TO A BGD UNIT.
 
QFGD	LAC .IOIN+2	/COUNT OF FGD/MONITOR ENTRIES.
	CMA
	TAD (1
	DAC QCNT
	RCL		/TIMES 2. 2 WORDS PER ENTRY.
	TAD (.IOIN+3	/PTR TO 1ST FGD/MONITOR ENTRY.
	DAC QPTR		/PTR TO 1ST BGD ENTRY.
	LAC QCNT		/+COUNT OF FGD/MONITOR ENTRIES.
	TAD .IOIN		/-COUNT OF ALL ENTRIES.
	SNA
	JMP QSHARE	/O.K. NO BGD ENTRIES.
QIOIN	DAC QCNT
QIOLP	LAC* QPTR		/GET .IOIN ENTRY.
	SAD QTEMP		/SAME UNIT ON SYS DEVICE?
	JMP QWRITE	/YES. IGNORE AND TRY AGAIN.
	IDX QPTR
	IDX QPTR
	ISZ QCNT
	JMP QIOLP
QSHARE	LAC .SCOM+26	/FGD=0; BGD=1.
	TAD (.SCOM+16
	DAC QPTR
MINUS7	LAW -7
	TAD* QPTR
	DAC QPTR		/PTR TO .DATF-7 OR .DATB-7
	LAC QTEMP
	AND (160000	/SAVE UNIT #
	TAD .IOIN+4	/(DTA./4+400000) OR (DKA./4+400000).
	DAC* QPTR		/SET UP .DATF-7 OR .DATB-7.
 
	CAL 775		/.CLOSE -3
	6		/TO PRINT CAR RET LINE FD.
 
	CAL 1771		/.TRAN OUT FWD THRU -7
	13
	101		/BLOCK 101
	6		/STARTING WITH REGISTER 6.
CORSIZ	0		/CORE SIZE.
 
	CAL 771		/.WAIT -7
	12
 
	LAC .SCOM+26
	SNA
	JMP .BOOT		/FGD. GO TO BOOTSTRAP.
	DAC BCTL.Q	/CLEAR BIT 0 IN BGD ^Q REGISTER.
 
	CAL		/BGD .EXIT.
	15
 
QMSG=.-2
	.ASCII /^Q/<175>
QBUF	.BLOCK 4		/.READ BUFFER FOR ^Q UNIT #.
QCNT	0
QPTR	0
	.EJECT
	.TITLE BGDERR
 
/BACKGROUND ERROR TYPEOUT ROUTINE- FGD MAINSTREAM
 
BGDERR	0
	DAC	BGDERA		/SAVE AC FOR EXIT
	LAC	BERQPT		/INITIALIZE QUEUE POINTER
	DAC	BERPNT
	.IFUND PI
BERL0R	LAC	(400200		/RAISE TO API 0
	ISA
	.ENDC
	.IFDEF PI
BERL0R	IOF
	.ENDC
BERCTS	LAC*	.SCOM+70		/^C
	RAL
	LAC	BCTL.Q		/^Q
	SZL!SPA
	JMP	BGDCX0
	LAW	0
	SAD	BERCNT		/ANYTHING IN QUEUE
	JMP	BGDEDS		/NO - CHECK DISCARD COUNT
	.IFUND PI
	DBK			/YES - PRINT CODE
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	LAC*	BERPNT		/GET ERROR CODE
	DAC	.+6
	ISZ	BERPNT
	LAC*	BERPNT		/GET ERROR INFO
	DAC	.+4
	ISZ	BERPNT
	JMS	BERBER		/BUILD BGD ERROR MSG AND TYPE
	XX			/ERROR CODE BITS 9-17
	XX			/ERROR INFO BITS 0-17
	.IFUND PI
	LAC	(400200		/RAISE TO API 0
	ISA
	.ENDC
	.IFDEF PI
	IOF			/PIC OFF
	.ENDC
	LAW	-1
	TAD	BERCNT
	DAC	BERCNT		/DECREMENT COUNT
	JMP	BERCTS		/GO TEST FOR EMPTY QUEUE
BGDEDS	LAC	BERDIS		/ANY ERRORS DISCARDED?
	SNA
	JMP	BERTET		/N0 - GO TEST TERMINAL ERROR
	DZM	BERDIS
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	DAC	.+3		/SAVE COUNT
	JMS	BERBER		/BUILD+PRINT
	LAW	62		/ERROR CODE 62
	XX			/COUNT=INFO
	JMP	BERL0R
BERTET	LAC	BERTRM		/TERMINAL ERROR REGISTER
	SNA
	JMP	BEROUT		/EXIT FROM ERROR ROUTINE
	.IFUND PI
BGDCX0	DBK
	.ENDC
	.IFDEF PI
BGDCX0	ION
	.ENDC
 
/CALL HANDLERS IN .DATB TO STOP BGD I/O
 
	DZM	BCTL.R		/DISABLE BGD ^R.
	LAC	LDRERR		/IF ERROR EXIT FROM LOADER, DON'T
	SZA			/STOP I/O -- HANDLERS MAY NOT BE
	JMP	BERDTD		/WHERE .DATB SAYS THEY ARE.
	LAC*	.SCOM+17
	DAC	BERTP1		/POINTS TO .DATND
	LAC*	BERTP1
	DAC	BERTP2		/POINTS TO .DATBG
BERDTL	LAC	BERTP2		/GET .DAT SLOT POINTER
	SAD	.SCOM+17		/IS IT .DAT+0?
	JMP	BERDTI		/YES - IGNORE ENTRY
	SAD	BERTP1		/IS IT END OF .DAT TABLE?
	JMP	BERDTD		/YES - ALL I/O FINISHED
	LAC*	BERTP2		/GET .DAT SLOT CONTENTS
	SMA!CLL!RAL		/IS THE .DAT SLOT SETUP?
	JMP	BERDTI		/NO - IGNORE THIS ENTRY
	SPA!CLL!RAL		/IS IT A TTA ENTRY?
	JMP	BERDTI		/YES - IGNORE
	TAD	(35
	DAC	BERTP3		/SAVE POINTER TO WD 35 OF I/O HANDLE
	LAC*	BERTP3		/GET JMS ENTRY TO STOP I/O
	DAC	BERTP3
	JMS*	BERTP3		/GO STOP BGD I/O
BERDTI	ISZ	BERTP2		/NEXT .DAT ENTRY
	JMP	BERDTL		/GO PROCESS
BERDTD	JMS*	TTA.+35		/CLEAR BGD TT I/O.
	DZM	LDRERR		/CLEAR "LOADER ERROR EXIT" FLAG.
 
/REMOVE ALL BGD ENTRIES FROM CLOCKQ
 
	.IFUND PI
	LAC	(400200		/RAISE TO 0 AND PIC OFF
	ISA
	.ENDC
	CLOF
	.IFDEF PI
	IOF
	.ENDC
	LAC	CLOKON		/ANY CLOCK INTERVALS
	SNA
	JMP	BERNCX
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	LAC	CLKRTN
	AND	(700000
	SNA			/IS IT FGD?
	DZM	CLKRTN		/NO - TURN IT OFF
	LAC	CLCKQN		/GET BEGINNING OF QUEUE
	DAC	BERTP1
BERNCL	LAC*	BERTP1		/GET QUEUE ENTRY
	AND	(700000
	SAD	L4HTHO		/(400000
	JMP	BERNCK		/END OF QUEUE
	SNA			/IS IT FGD?
	DZM*	BERTP1		/NO - CLEAR ENTRY
	ISZ	BERTP1		/BUMP TO NEXT ENTRY
	ISZ	BERTP1
	JMP	BERNCL		/GO TEST NEXT
BERNCK	LAC	7
	SNA!CMA
	DAC	7
	CLON
	.IFUND PI
BERNCX	LAC	(400200		/RAISE TO 0 AND PIC OFF
	ISA
	.ENDC
	.IFDEF PI
BERNCX	IOF
	.ENDC
	DZM	.SCOM+61		/CLEAR MAINSTREAM REAL-TIME
	DZM	.SCOM+62		/SUBROUTINES
	DZM	BRWRIT		/CLEAR BGD ^R MSG FLAG.
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	LAC*	.SCOM+70		/^C
	RAL
	LAC	BCTL.Q		/^Q
	SZL!SPA
	JMP	BGDCX1
	.CLOSE	-3		/PRINT CAR. RET. LINE FEED.
	LAC	BERTRM
	DAC	.+4		/SAVE ERROR CODE
	LAC	BERTRM+1
	DAC	.+3		/SAVE ERROR INFO
	JMS	BERBER		/BUILD+PRINT ERROR
	XX			/ERROR CODE
	XX			/ERROR INFO
	.IFUND PI
BGDCX1	LAC	(400200		/RAISE TO ZERO (API)
	ISA
	.ENDC
	.IFDEF PI
BGDCX1	IOF
	.ENDC
	LAC	.SCOM+71
	AND	(277777
	DAC	.SCOM+71
	LAW	0		/CLEAR QUEUE
	DAC	BERCNT
	LAC	BERQPT		/RESET NEXT TO BEGINNING
	DAC	BERNXT
	DZM	BERDIS		/CLEAR DISCARDED ENTRIES
	DZM	BERTRM
	DZM	BGDERR		/CLEAR ENTRY POINT
	LAC*	.SCOM+70		/^C
	RAL
	LAC	BCTL.Q		/^Q
	SZL!SPA
	JMP	BGDCX2
	LAC	.SCOM+41		/LOADER RUNNING?
	SPA
	JMP	BGDCX2		/YES.
	.IFUND PI
DBKIDL	DBK
	.ENDC
	.IFDEF PI
DBKIDL	ION
	.ENDC
.IDLE.	CAL			/.IDLE
L17	17			/WAIT FOR ^P,^C,^S,^T
BEROUT	LAC	.SCOM+71
	AND	(277777
	DAC	.SCOM+71
	LAC	BGDERA		/AC ON ERROR ENTRY
	.IFUND PI
	DBK			/FROM 0
	.ENDC
	.IFDEF PI
	ION			/PI ON
	.ENDC
	CAL	BGDERR		/.RLXIT
	20
BGDCX2	DZM	BCTL.P		/DISABLE BGD ^P,^T,^S
	DZM	BCTL.T
	DZM	BCTL.S
	LAC*	.SCOM+70		/^C
	SPA
	JMP	.+4
	LAC	BCTL.Q		/^Q
	SPA
	JMP	BGD.Q
	LAC	(1
	DAC*	.SCOM+70		/CLEAR ^C BIT 0.
	DAC	BCTL.Q		/CLEAR ^Q BIT 0.
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
	.WRITE	-3,2,C.C,4
	JMS	TVCLR		/CLEAR BGD I/O T.V.'S
LNOP	NOP			/ARGUMENT
	JMP	NEWBGD
C.C=.-2
	.ASCII	/^C/<175>
BERBER	0			/PRINT ERROR
	LAC	(BERBUF+10
	DAC	BERTP1		/POINTS TO 1ST OCTAL DIGIT
	LAW	-3
	DAC	BERTP2		/3 DIGITS 1ST TIME
	LAC*	BERBER		/GET ERROR CODE
	ISZ	BERBER
	RTL			/9 LEFT
	RTL
	RTL
	RTL
	RAL
	JMS	BERFBF		/FILL BUFFER WITH 3 DIGITS
	ISZ	BERTP1		/SKIP SPACE
	LAW	-6
	DAC	BERTP2		/6 DIGITS THIS TIME
	LAC*	BERBER		/GET ERROR INFO
	ISZ	BERBER
	JMS	BERFBF		/PUT LAST 6 IN BUFFER
	.WRITE	-3,3,BERBUF,20
	.WAIT	-3
	JMP*	BERBER		/RETURN
BERFBF	0			/FILL BUFFER WITH DIGITS
	DAC	BERTP3		/SAVE WORD
BERFBL	LAC	BERTP3		/POSITION FOR CONVERSION
	RTL			/TO OCTAL
	RAL
	DAC	BERTP3		/SAVE FOR NEXT DIGIT
	RAL
	AND	(7
	XOR	(60		/MAKE OCTAL
	DAC*	BERTP1		/PUT INTO BUFFER
	ISZ	BERTP1
	ISZ	BERTP2		/ANY MORE?
	JMP	BERFBL		/YES
	JMP*	BERFBF		/RETURN
/
BERTP1	0			/TEMP
BERTP2	0			/TEMP
BERTP3	0			/TEMP
BGDERA	0			/ENTRY AC
BERPNT	0			/POINTER
BERBUF	12003;	0
	40			/SPACE
	56			/.
	105			/E
	122			/R
	122			/R
	40			/SPACE
	XX			/0
	XX			/0
	XX			/0
	40			/SPACE
	XX			/0
	XX			/0
	XX			/0
	XX			/0
	XX			/0
	XX			/0
	15			/CR
	12			/LF
LDRERR	0			/FLAG IS SET NON-0 WHEN LOADER
				/DOES AN .ERROR EXIT.
	.EJECT
/THE FOLLOWING REGISTERS ARE XCT'ED IN THE MONITOR TO SAVE AND RESTORE
/REGISTERS ASSOCIATED WITH EAE. IF THE MACHINE HAS NO EAE, DETERMINED
/DYNAMICALLY BY THE MONITOR, THESE REGISTERS ARE ALTERED AS INDICATED
/IN THE COMMENTS.
 
LLACQ	LACQ		/NOP
LLACS	LACS		/NOP
LLMQ	LMQ		/NOP
LAND	AND (640477	/LAW
 
	.EJECT
	.TITLE TTA.
 
/ COPYRIGHT 1969, 1970 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
 
/ JEAN-CLAUDE P. PROTEAU
/ PDP-9 BACKGROUND/FOREGROUND SYSTEM MULTIUNIT TELETYPE HANDLER.
 
/ PHYSICAL LAYOUT OF THE TELETYPE HANDLER.
/
/ 1.	COMMON ENTRY REGISTERS AT BEG. OF HANDLER
/
/ 2.	CAL LEVEL PROCESSING:
/
/	-BUSY TEST SUBR.
/	-INIT PROCESSOR
/	-WRITE PROCESSOR
/	-READ PROCESSOR
/	-CLOSE PROCESSOR
/	-COMMON CAL EXIT
/	-CAL LEVEL SUBRS.
/
/ 3.	ERROR PROCESSING
/
/ 4.	INTERRUPT SERVICE (HARDWARE LEVEL):
/
/	-KEYBOARD API
/	-KEYBOARD PI
/	-TELEPRINTER API
/	-TELEPRINTER PI
/	-COMMON INTERRUPT SERVICE EXIT
/
/ 5.	INTERRUPT SERVICE (SOFTWARE LEVEL):
/
/	-INPUT PROCESSING
/	-CONTROL CHARACTERS
/	-CONTROL R QUEUER
/	-FGD AND BGD STOPIO SUBRS.
/	-OUTPUT PROCESSING
/	-I/O DONE
/	-PROTECTED EXIT
/
/ 6.	DATA VARIABLES
/ 7.	CONTROL CHARACTER TABLES
/ 8.	TELETYPE UNIT STATUS REGISTERS
/ 9.	INPUT & OUTPUT RING BUFFERS
 
	.EJECT
RPL=705512
IDX=ISZ		/USED WHEN NO SKIP INTENDED.
SET=ISZ		/USED TO SET A FLAG NON-ZERO.
TTA.=.
 
WD0	JMS TTSWAP
WD1	BSYTST		/T.V. FOR CAL HANDLER TO BUSY TEST ROUTINE.
WD2	BSYTST		/SAME (USED FOR BACKGROUND).
WD3	0		/FGD .CLOSE: 0=NO; NON-0=YES.
WD4	0		/BGD .CLOSE: SAME.
WD5	0		/ION OR IOF (STATE OF PIC ON CAL ENTRY).
WD6	0		/SAME AS WORD 5.
WD7	0		/RETURN POINTER FROM CAL.
WD10	0		/JMP WD20 - JMP WD32
WD11	0		/0=FGD CAL; 1=BGD CAL.
WD12	0		/CAL ADDRESS.
WD13	0		/UNIT # IN BITS 2-17.
WD14	0		/MODE BITS.
WD15	0		/^P RESTART OR LINE BUFFER ADDRESS.
WD16	0		/REGISTER TO PUT STANDARD BUFFER SIZE IN OR WRD CNT.
WD17	0		/REAL RETURN ADDRESS + LEVEL BITS.
WD20	JMP INIT.
WD21	-203		/.OPER - LITERAL.
WD22	-100		/.SEEK - LITERAL.
WD23	-177		/.ENTER - LITERAL.
WD24	JMP FORGET	/.CLEAR
WD25	JMP CLOSE
WD26	JMP FORGET	/.MTAPE
WD27	JMP READ.
WD30	JMP WRITE
WD31	24		/.WAIT AND .WAITR NEVER GET HERE. (LITERAL)
WD32	JMP ILLCAL	/.TRAN - ILLEGAL CAL FUNCTION.
WD33	0		/.SCOM+35 SAVED BY CAL HANDLER.
WD34	STOP.F
WD35	STOP.B
WD36	3		/SPECIAL HANDLER I.D. - ALSO USED AS LITERAL..
 
	.EJECT
	.TITLE TT.BSY
 
/ SUBROUTINE BSYTST: CALLED BY THE CAL HANDLER WITH THE UNIT # IN THE
/ AC (BITS 0,1=0) TO TEST IF UNIT IS BUSY. SKIP ON RETURN IF NOT BUSY.
 
BSYTST	0
 
	DAC UNIT.		/SAVE UNIT #.
	TAD .SCOM+76	/- # OF TTYS ON THIS MACHINE.
	SMA!CLA		/SKIP IF # IS LEGAL.
	JMP NONBUSY	/LET THE CAL COME IN. ERROR WILL THEN
	LAC UNIT.		/BE DETECTED.
	RCL
	RTL		/UNIT # TIMES 8.
	TAD LACTT0	/(LAC TTY0
	DAC TEMP1
TEMP1	XX		/GET WORD 1 FOR TTY #N.
	SPA!RTL		/UNIT ALWAYS BUSY IF ECHOING
	JMP* BSYTST	/A CONTROL CHARACTER.
	RTL		/UNIT NON-BUSY IF BIT 3=0.
	SNL!RAL
	JMP NONBUSY
	LAC .T2		/I/O CAL FUNCTION CODE.
	SAD (1		/.INIT?
	SZL		/YES. UNIT DOING A .READ?
	SKP		/NO. DON'T LET CAL IN.
NONBUSY	IDX BSYTST
	JMP* BSYTST
 
/ NOTE: THE CODE TO INITIALIZE EACH TTY UNIT TO MODEL 33 OR 35
/ IS LOCATED IN RESBUF WITHIN RESMON.
 
	.EJECT
	.TITLE TT.CAL
 
/ CAL PROCESSING.
 
INIT.	JMS USETUP	/SETUP TO PROCESS THIS UNIT.
	64000		/ARGUMENT: BUSY, OUTPUT, INIT.
	LAC (42		/PUT STANDARD BUFFER SIZE (34
	DAC* WD16		/DECIMAL) IN CAL SEQUENCE.
	LAC WD15		/^P ADDRESS + CODE BITS.
	AND (77777
	DAC TEMP1		/SAVE ADDRESS.
	LAC FGDCTL	/IS IT FGD CTL TTY?
	XOR UNIT.
	AND (77777
	SZA
	JMP .+3
	LAC (FCTL.P	/YES. PTR TO FGD NORMAL ^P REGISTER.
	JMP SAVCTP
	LAC BGDCTL	/NO. IS IT BGD CTL TTY?
	XOR UNIT.
	AND (77777
	SNA!CLA
	LAC (BCTL.P	/YES. PTR TO BGD NORMAL ^P REGISTER.
SAVCTP	DAC BSYTST	/TEMP STORE.
	.IFUND PI
	LAC (400020	/RAISE TO LEVEL 3.
	ISA
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
	LAC WD15		/^P ADDR + CODE BITS.
	AND (700000
	SZA
	JMP TEST3		/CODE NON-0 = REAL-TIME ^P OR NO CHANGE.
	SAD BSYTST
	JMP ZERWD6	/NOT A CTL TTY.
	SAD TEMP1		/IF IT WAS 0, DISABLE ^P.
	JMP ZERCTP
	LAC WD11		/FGD OR BGD .INIT?
	SZA
	LAC (100000	/BGD. ADD MEM PROT BIT.
	TAD L200K		/ADD EXT MEM BIT. (200000
	TAD TEMP1
ZERCTP	DAC* BSYTST	/SETUP NORMAL ^P REGISTER.
ZERWD6	DZM* CALWD6	/DISABLE REAL-TIME ^P FOR THIS UNIT.
	JMP DROP
 
TEST3	SAD (300000	/CODE 3 MEANS DON'T CHANGE STATUS
	JMP DROP		/OF CONTROL P (NEEDED BY DDT).
 
	.EJECT
/ REAL-TIME ^P API LEVEL CODES: 1,2=MAINSTREAM; 4=CURRENT LEVEL;
/ 5,6,7=LEVELS 5,6,7. BGD ALWAYS FORCED TO MAINSTREAM.
 
REAL.P	LAC WD11		/0=FGD CAL; 1=BGD CAL.
	.IFUND NOAPI
	SZA!CLA
	JMP B.MAIN	/BGD MAINSTREAM CODE = 0.
	LAC WD15
	AND (700000	/^P API LEVEL CODE BITS.
	SMA
	JMP F.MAIN	/1,2,3=FGD MAINSTREAM.
	SAD (400000
	SKP!CLA		/REQUEST AT LEVEL CAL WAS ISSUED.
	JMP B.MAIN	/5,6,7 CODES STAY THE SAME.
	RPL		/CHECK API STATUS FOR ACTIVE LEVELS.
	RTR
	RTR
	AND (700000	/LOOK FOR 5,6,7 ACTIVE.
	SPA!RCL
	LAC (120000	/LEVEL 5.
	SPA!RCL
	LAC (300000	/LEVEL 6.
	SPA!RCL
	LAC (700000	/LEVEL 7.
	SMA		/IF NONE ACTIVE, NO SKIP.
	.ENDC
	.IFDEF NOAPI
	SNA!CLA
	.ENDC
F.MAIN	LAC (100000	/FGD MAINSTREAM CODE = 1.
B.MAIN	XOR TEMP1		/ADD ^P ADDRESS.
	DAC* CALWD6	/SETUP UNIT'S REAL-TIME ^P REGISTER.
	LAC BSYTST	/IS UNIT A CTL TTY?
	SZA
	DZM* BSYTST	/DISABLE CTL TTY NORMAL ^P REGISTER.
DROP=.
	.IFUND PI
	DBK
	.ENDC
	XCT WD5		/RESTORE PIC.
	JMP SETTAB
 
	.EJECT
WRITE	JMS MODE		/CHECK DATA MODE; THEN SETUP UNIT.
SIXTYK	60000		/ARGUMENT: BUSY, OUTPUT. (LITERAL).
	LAC (400000	/SET ECHO BIT IN TEMP WORD
	DAC WD7TMP	/FOR ECHO REGISTER.
	DZM CRNULL	/NULL MEANS .WRITE.
	JMP XITCAL
 
READ.	JMS MODE		/CHECK DATA MODE; THEN SETUP UNIT.
FORTYK	40000		/ARGUMENT: BUSY, INPUT. (LITERAL).
	LAC WD14		/DATA MODE:2=IOPS ASCII;3=IMAGE ASCII.
	TAD (1000		/SETUP UNIT'S WORD 8: THE COMPUTED
	IDX CALWD6	/HEADER WITH WORD PAIR COUNT = 1.
	IDX CALWD6
	DAC* CALWD6
REDUND	LAC WD5		/REDUNDANT ION OR IOF TO
	DAC DO.TLS	/PRESERVE IOT STRING.
	JMP NOTNUL	/SET CRNULL NON-0 (NOT A .WRITE).
 
CLOSE	JMS USETUP	/SETUP TO PROCESS THIS UNIT.
	62000		/ARGUMENT: BUSY,OUTPUT,CLOSE.
 
/ COMMON CODE FOR INIT AND CLOSE.
 
SETTAB	777407		/MASK OUT OLD TAB COUNT,
	AND WD1TMP	/0 THE LINE FEED SWITCH,
	TAD (100		/AND SET TAB COUNT=8 DECIMAL.
	DAC WD1TMP
	LAC* CALWD7	/ECHOING?
	SMA
	JMP SETECO	/NO.
	AND (100000	/SAVE HUNG-ON-ECHO BIT.
	TAD (440000	/SET ECHO AND ^U BITS.
	DAC WD7TMP	/^U BIT WILL CAUSE CAR RET LINE FEED.
	JMP REDUND
SETECO	LAC (600212	/SETUP FOR ECHO REGISTER:
	DAC WD7TMP	/ECHO, IODONE, COUNT=1, CHAR=LINE FEED.
NOTNUL	LAC (15		/PREPARE TO PRINT A CAR. RET.
	DAC CRNULL
 
	.EJECT
/ COMMON EXIT FOR INIT, CLOSE, WRITE, AND READ.
 
	.IFUND PI
XITCAL	LAC (400020	/RAISE TO LEVEL 3.
	ISA
	.ENDC
	.IFDEF PI
XITCAL	IOF
	.ENDC
	LAC WD1TMP	/SETUP UNIT'S WORD 1.
	DAC* CALWD1
	LAC WD7TMP	/SETUP UNIT'S ECHO REGISTER.
	DAC* CALWD7
	LAC CRNULL	/CAR. RET. OR NULL.
	SZA
	JMP DO.TLS	/NOT A .WRITE.
	LAW -2		/SIMULATE A TPR INTERRUPT:
	TAD DO.TLS	/CHANGE TLS TO TCF AND
	DAC* TPRPUT	/STORE IN TPR RING BUFFER.
	LAC TPRPUT	/UPDATE RING STORE POINTER.
	TAD (1
	SAD TPREND
	LAC TPRBEG
	DAC TPRPUT
	LAC (XCT INT1	/SETUP TTY'S SLOT IN LEVEL 4 QUEUE
	DAC TTY4Q		/TO CALL LEVEL 4 INTERRUPT SECTION.
	SKP
DO.TLS	XX		/TLS TO UNIT N, ION, OR IOF.
	.IFUND PI
	DBK
	.ENDC
FORGET	XCT WD5		/ION OR IOF TO RESTORE PIC.
	XCT .+1
	XCT .+1
	JMP* WD7		/GO TO CALXIT.
 
	.EJECT
/ SUBROUTINE TTSWAP: CALLED BY CAL HANDLER, BUT SWAP UNNECESSARY.
 
TTSWAP	0
 
	.IFUND PI
	DBK		/DBK FROM LEVEL 0.
	.ENDC
	XCT WD5		/RESTORE PIC: ION OR IOF.
	JMP* TTSWAP
 
/ SUBROUTINE MODE: FOR READ AND WRITE, MAKE SURE THE DATA MODE IS
/ EITHER IMAGE ALPHA OR IOPS ASCII. THEN SETUP THE UNIT FOR I/O.
 
MODE	0
 
	LAC WD14		/DATA MODE BITS.
	SAD (2
	JMP MODE2
	SAD WD36		/(3
	JMP MODE3
	LAW 007		/ILLEGAL DATA MODE.
	JMP FATAL
 
MODE3	CLA!SKP		/IMAGE ALPHA.
MODE2	LAC (400		/IOPS ASCII.
	TAD* MODE		/ADD READ OR WRITE MODE BITS.
	DAC .+2
	JMS USETUP	/SETUP TO PROCESS THIS UNIT.
	XX
	LAC WD15		/POINTER TO LINE BUFFER HEADER.
	DAC* CALWD2
	TAD (2
	IDX CALWD2
	DAC* CALWD2	/POINTER TO 1ST DATA WORD.
	LAC WD16		/SUBTRACT 2 FROM WORD COUNT
	TAD (2		/TO EXCLUDE HEADER PAIR.
	IDX CALWD2
	DAC* CALWD2
	SMA
	JMP ILLCNT	/WORD PAIR COUNT OF 0 OR 1 ILLEGAL.
	LAC WD17		/SAVE POSSIBLE REAL-TIME REQUEST
	IDX CALWD2	/(0 IF NOT REAL-TIME).
	DAC* CALWD2
	DZM WD7TMP	/SETUP TO 0 THE ECHO REGISTER.
	IDX MODE
	JMP* MODE
 
	.EJECT
/ SUBROUTINE USETUP: TEST LEGALITY OF UNIT #. IF O.K., SETUP POINTERS
/ TO UNIT'S DATA WORDS AND COMPUTE THE TLS TO THAT UNIT.
 
USETUP	0
 
	LAC .SCOM+76	/- # OF TTYS ON THIS MACHINE.
	TAD WD13		/UNIT #.
	SMA
	JMP ILUNIT	/ILLEGAL UNIT (TOO LARGE).
	LAC WD13
	RCL
	RTL
	TAD LACTT0	/(LAC TTY0
	DAC CALWD1
	TAD (1
	DAC CALWD2
	TAD WD36		/(3
	DAC CALWD6
	DZM* CALWD6	/0 WORD 5:REAL-TIME REQUEST.
	IDX CALWD6
	TAD (2
	DAC CALWD7
CALWD1	XX		/LAC TTYN'S WORD 1.
	AND (10370	/PRESERVE "33/35" BIT, LINE FEED SWITCH,
			/AND TAB COUNT.
	XOR* USETUP	/ADD FUNCTION'S CODE BITS.
	AND (677777	/MASK OUT BGD/FGD BIT.
	DAC WD1TMP	/SAVE NEW WORD 1 'TIL EXIT.
	LAC WD11		/0=FGD CAL; 1=BGD CAL.
	SZA
	LAC (100000
	XOR WD1TMP
	DAC WD1TMP	/ADD IN THE BGD/FGD BIT.
	LAW -1
	TAD WD13		/UNIT #.
	SMA!RCL
	JMP .+3
	LAC (700404	/TLS TO UNIT 0.
	JMP DACTLS
	DAC DO.TLS
	AND (30
	TAD DO.TLS
	RTL
	RAL
	XOR (704004
DACTLS	DAC DO.TLS	/SAVE TLS INSTRUCTION.
	IDX USETUP
	JMP* USETUP
 
	.EJECT
	.TITLE TT.ERR
 
/ ERROR PRINTOUT.
 
ILLCNT	LAW 023		/WORD PAIR COUNT OF 0 OR 1 ILLEGAL.
	SKP
ILLCAL	LAW 006		/ILLEGAL FUNCTION: .TRAN.
	SKP
ILUNIT	LAW 200		/ILLEGAL TTY UNIT.
FATAL	DAC ARG1
	LAC WD11		/0=FGD CAL; 1=BGD CAL.
	SZA
	LAC (1000
	TAD (5000
	TAD ARG1
	DAC ARG1
	LAC WD12		/CAL ADDRESS.
	DAC ARG2
	.IFUND PI
	LAC (400200	/RAISE TO LEVEL 0.
	ISA
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
ARG1	XX
	JMS* .SCOM+66	/CALL ERRORQ ROUTINE.
ARG2	XX
	.IFUND PI
	DBK
	.ENDC
	JMP FORGET	/EXIT FROM CAL.
 
	.IFUND PI
ILLINT	LAC KBDAPI	/ILLEGAL INTERRUPT.
	DAC ARG3		/PASS ON PC
	LAC (400200	/RAISE TO LEVEL 0.
	ISA
	LAW 7003		/TERMINAL .ERR 003 FOR BOTH JOBS.
	JMS* .SCOM+66	/CALL ERRORQ ROUTINE.
ARG3	XX
	DBK
	JMP NOQUEUE	/EXIT FROM HARDWARE LEVEL.
	.ENDC
 
	.EJECT
	.TITLE TT.INT
 
/ KEYBOARD API INTERRUPT ENTRY POINT (LEVEL 3).
 
KBDAPI	0		/L,EM,MP + RETURN PC.
 
	.IFUND PI
	DAC LVL3AC	/SAVE AC.
	JMS TTYAPI
	XCT KBDKSF-1
	JMP KBD
 
/ SUBROUTINE TTYAPI IS COMMON CODE FOR KBDAPI AND TPRAPI.
 
TTYAPI	0
 
	LAC PIC-1		/SINCE API INTERRUPT DOES NOT CHANGE THE STATE
	DAC PIC		/OF THE PIC, NO NEED TO RESTORE IT ON EXIT.
	LAC .SCOM+76	/- # OF TTYS ON THIS MACHINE.
	DAC TEMPC		/SAVE LOOP COUNT.
	LAC* TTYAPI	/GET ARGUMENT.
	IDX TTYAPI
	DAC .+2
XLOOP	IDX .+1
	XX		/XCT THE NEXT KSF OR TSF TO UNIT N.
	JMP .+3
	LAC* .-2		/PICKUP THE SKIP IOT.
	JMP* TTYAPI
	ISZ TEMPC		/NO SKIP. ANYMORE?
	JMP XLOOP
	JMP ILLINT	/NO. ILLEGAL INTERRUPT.
 
KBDKSF	704101		/KSF1: SKIP IF TTY1 HAS A CHARACTER.
	.IFPOZ TTYS-3
	704121		/KSF2
	.ENDC
	.IFPOZ TTYS-4
	704141		/KSF3
	.ENDC
	.IFPOZ TTYS-5
	704161		/KSF4
	.ENDC
	.IFPOZ TTYS-6
	704301		/KSF5
	.ENDC
	.IFPOZ TTYS-7
	704321		/KSF6
	.ENDC
	.IFPOZ TTYS-10
	704341		/KSF7
	.ENDC
	.IFPOZ TTYS-11
	704361		/KSF10
	.ENDC
	.IFPOZ TTYS-12
	704501		/KSF11
	.ENDC
	.IFPOZ TTYS-13
	704521		/KSF12
	.ENDC
	.IFPOZ TTYS-14
	704541		/KSF13
	.ENDC
	.IFPOZ TTYS-15
	704561		/KSF14
	.ENDC
	.IFPOZ TTYS-16
	704701		/KSF15
	.ENDC
	.IFPOZ TTYS-17
	704721		/KSF16
	.ENDC
	.IFPOZ TTYS-20
	704741		/KSF17
	.ENDC
	.IFPOZ TTYS-21
	704761		/KSF20
	.ENDC
	.ENDC
 
	.EJECT
/ SUBROUTINE PINTRY IS COMMON CODE FOR KBDPI AND TPRPI.
 
PINTRY	0
 
	DAC ACTEMP	/SAVE AC.
	LAC (400020	/IF API IS ENABLED,
	ISA		/THIS RAISES TO LEVEL 3.
	LAC ACTEMP
	DAC LVL3AC
	LAC .ION		/SETUP TO TURN PIC BACK ON
	DAC PIC		/BEFORE EXIT.
L2HTHO=.
L200K	LAC 0		/SAVE L,EM,MP + RETURN PC. (LITERAL).
	DAC KBDAPI	/IN COMMON EXIT REGISTER.
	DZM 0
	XCT* PINTRY	/GET (ADDR OF KSF OR TSF)+3.
	AND (17777
	TAD (177775	/(LAC-3
	DAC .+1
TEMPC	XX		/GET SKIP IOT.
	IDX PINTRY
	JMP* PINTRY
 
/ KEYBOARD PI INTERRUPT ENTRY POINT (LEVEL 7+1/2).
 
KBDPI	0		/JMS FROM KBD PI SKIP CHAIN.
 
	JMS PINTRY
	LAC KBDPI		/PICKUP (ADDRESS OF KSF)+3.
 
KBD	TAD (1		/CHANGE KSFN TO KRBN.
	DAC XCTKRB
	AND (7760		/MASK TO SAVE DEVICE CODE.
	RCL
	RTL		/MAKE ROOM FOR THE CHARACTER.
	RAL
XCTKRB	XX		/OR IN THE 8-BIT CHAR. CODE.
	DAC* KBDPUT	/SAVE DEVICE CODE + CHAR. IN RING BUFFER.
	LAC KBDPUT	/MOVE POINTER TO NEXT SLOT,
	TAD (1		/UNLESS THE BUFFER IS FULL.
	SAD KBDEND
	LAC KBDBEG
	SAD KBDGET	/IS BUFFER FULL?
	JMP NOQUEUE	/YES. IGNORE THIS CHARACTER.
	DAC KBDPUT
	JMP DROP24	/IF IN API, DROP FROM LEVEL 3 TO 4.
 
	.EJECT
	.IFUND PI
 
/ TELEPRINTER API ENTRY POINT (LEVEL 3).
 
TPRAPI	0		/L,EM,MP + RETURN PC.
 
	DAC LVL3AC	/SAVE AC.
	LAC TPRAPI	/SAVE L,EM,MP + RETURN PC
	DAC KBDAPI	/IN COMMON EXIT REGISTER.
	JMS TTYAPI
	XCT TPRTSF-1
	JMP TPR
TPRTSF	704001		/TSF1
	.IFPOZ TTYS-3
	704021		/TSF2
	.ENDC
	.IFPOZ TTYS-4
	704041		/TSF3
	.ENDC
	.IFPOZ TTYS-5
	704061		/TSF4
	.ENDC
	.IFPOZ TTYS-6
	704201		/TSF5
	.ENDC
	.IFPOZ TTYS-7
	704221		/TSF6
	.ENDC
	.IFPOZ TTYS-10
	704241		/TSF7
	.ENDC
	.IFPOZ TTYS-11
	704261		/TSF10
	.ENDC
	.IFPOZ TTYS-12
	704401		/TSF11
	.ENDC
	.IFPOZ TTYS-13
	704421		/TSF12
	.ENDC
	.IFPOZ TTYS-14
	704441		/TSF13
	.ENDC
	.IFPOZ TTYS-15
	704461		/TSF14
	.ENDC
	.IFPOZ TTYS-16
	704601		/TSF15
	.ENDC
	.IFPOZ TTYS-17
	704621		/TSF16
	.ENDC
	.IFPOZ TTYS-20
	704641		/TSF17
	.ENDC
	.IFPOZ TTYS-21
	704661		/TSF20
	.ENDC
	.ENDC
	.IFDEF PI
TPRAPI=ERR
	.ENDC
/ TELEPRINTER PI INTERRUPT ENTRY POINT (LEVEL 7+1/2).
 
TPRPI	0		/JMS FROM TPR PI SKIP CHAIN.
 
	JMS PINTRY
	LAC TPRPI		/PICKUP (ADDRESS OF TSF)+3.
TPR	TAD (1		/CHANGE TSFN TO TCFN.
	DAC* TPRPUT	/STORE IN RING BUFFER.
	XCT* TPRPUT	/CLEAR TELEPRINTER FLAG.
	LAC TPRPUT	/MOVE PUT POINTER TO NEXT SLOT.
	TAD (1
	SAD TPREND
	LAC TPRBEG
	DAC TPRPUT
 
	.EJECT
/ IN API, EXIT FROM LEVEL 3 AND DROP TO LEVEL 4 TO CONTINUE INTERRUPT
/ PROCESSING. FOR PI INTERRUPT, EXIT AFTER TURNING PIC BACK ON.
 
/ TO DROP TO LEVEL 4 YOU MUST MAKE AN ENTRY IN THE LEVEL 4 QUEUE
/ IN CASE YOU'VE INTERRUPTED FROM THAT LEVEL.
 
DROP24	LAC (XCT INT1	/SETUP RETURN POINTER IN
	DAC TTY4Q		/LEVEL 4 QUEUE (TTY'S SLOT).
 
/ ILLEGAL INTERRUPT ENTERS HERE AFTER SETTING UP ERROR MESSAGE.
 
NOQUEUE=.
	.IFUND PI
	LAC (400200	/RAISE TO LEVEL 0.
	ISA
	.ENDC
	JMS* .SCOM+54	/JMS TO CALL4 IN RESMON.
	KBDAPI		/POINTER TO INTERRUPTED PC ETC.
	.SCOM+35		/POINTER TO SAVED .SCOM+35 (WASN'T ALTERED).
 
	LAC LVL3AC	/RESTORE THE AC.
PIC	XX		/ION (FOR PI) OR C(PIC-1) (FOR API).
	.IFUND PI
	DBK		/DBK FROM LEVEL 0 TO 3.
	.ENDC
	DBR
	XCT .+1
	XCT .+1
	JMP* KBDAPI
 
	.EJECT
	.TITLE TT.LV4
 
/ LEVEL 4 ENTRY TO INTERRUPT PROCESSORS CALLED FROM LEVEL 4 QUEUE
/ ROUTINE BY A JMS.
 
INT1	0		/L,EM,MP + RETURN PC.
 
/ ALTHOUGH THIS IS THE INITIAL ENTRY TO THIS SECTION, BOTH KEYBOARD
/ AND TELEPRINTER INTERRUPTS CAN HAVE OCCURRED. IN GENERAL, KEYBOARD
/ PROCESSING TAKES PRECEDENCE. PIC SHOULD BE ON NOW.
 
INPUT	LAC KBDGET
	DAC KBDGT1
	DZM HUNG		/CLEAR INPUT-HUNG-ON-ECHO FLAG.
	JMP NEXT		/TEST IF RING BUFFERS ARE EMPTY.
 
NXIN	LAC* KBDGT1	/GET KBD RING BUFFER ENTRY.
	SNA!CLL
	JMP SLOT0
	DAC TEMP0
	AND (177
	DAC CHAR		/SAVE INPUT CHARACTER.
	LAW -400
	AND TEMP0
	JMS ROT4R
	DAC DVCCOD	/SAVE DEVICE CODE.
	JMS ROT4R		/GOT DEVICE CODE.
	SAD (14		/CONVERT TO UNIT # (0 - 20).
	CLA!SKP		/UNIT 0.
	TAD WD21		/(-203
	JMS GETUNIT
 
/ TEST FOR SPECIAL CONTROL CHARACTERS.
 
	LAC CHAR
	SAD WD36		/^C (3
	JMP CTRL.C
	SAD (20		/^P
	JMP CTRL.P
	SAD (25		/^U
	JMP CTRL.U
	SAD (22		/^R
	JMP CTRL.R
	SAD (23		/^S
	JMP CTRL.S
	SAD WD31		/^T (24
	JMP CTRL.T
	SAD (21		/^Q
	JMP CTRL.Q
 
	.EJECT
TTYWD1	XX		/LAC TTYN + 0.
	AND SIXTYK	/UNIT MUST BE BUSY (60000)
	SAD FORTYK	/(I/O UNDERWAY) FOR INPUT. (40000)
	JMP ECOCHK	/YES.
DISCARD	DZM* KBDGT1	/0 WORD IN RING BUFFER.
	JMP SLOT0		/IGNORE CHARACTER.
ECOCHK	LAC* TTYWD7	/UNIT BUSY ON ECHO?
	SPA!RAL
	JMP BUSY	
	DZM* KBDGT1	/0 WORD IN RING BUFFER.
	JMS NXNTRY
	JMP INPROC	/PROCESS THE INPUT.
BUSY	SPA!RAR		/IS I/O DONE?
	JMP DISCARD	/YES.
HANGUP	AND (677777	/SET FLAG IN ECHO REGISTER
	XOR (100000	/TO INDICATE UNIT HUNG ON ECHO.
	DAC* TTYWD7
	DAC HUNG		/SET INPUT-HUNG-ON-ECHO FLAG.
SLOT0	JMS NXNTRY
	JMP NEXT
 
/ SUBROUTINE NXNTRY: MOVE KEYBOARD RING BUFFER POINTERS
/ AHEAD ONE SLOT.
 
NXNTRY	0
 
	LAC KBDGT1
	TAD (1
	SAD KBDEND
	LAC KBDBEG
	DAC KBDGT1
	LAC HUNG		/DON'T MOVE KBDGET IF "HUNG" FLAG
	SZA		/IS ON. THIS PREVENTS KEYBOARD
	JMP* NXNTRY	/INPUT FROM RUNNING INTO CHARACTERS
	LAC KBDGT1	/NOT YET PROCESSED IN THE BUFFER.
	DAC KBDGET
	JMP* NXNTRY
 
	.EJECT
	.TITLE TT.IN
 
/ INPUT CHARACTER PROCESSING.
 
INPROC	LAC CHAR
	SAD (4		/^D
	JMP CTRL.D
	SAD (176		/CHANGE ALT MODES (176 OR 33 ON SOME
	LAC (175		/MODELS) TO STANDARD FORM (175).
	SAD (33
	LAC (175
	DAC CHAR
 
/ IS INPUT IN IMAGE ALPHA OR IN IOPS ASCII?
 
	XCT TTYWD1
	AND (400
	SZA
	JMP INIOPS
 
/ INPUT MODE IS IMAGE ALPHA.
 
TTYWD3	XX		/LAC TTYN + 2.
	DAC TEMP0		/POINTS AT USER'S BUFFER.
	LAC CHAR
	DAC* TEMP0	/CHAR. TO USER'S BUFFER.
	IDX* TTYWD3	/INCREMENT STORAGE POINTER.
TTYWD8	XX		/LAC TTYN + 7.
	TAD (400		/ADD 1/2 TO WORD PAIR COUNT
	DAC* TTYWD8	/IN TEMP. HEADER ACCUMULATOR.
	JMS ECHO		/ECHO, IF NECESSARY.
	ISZ* TTYWD4	/DECREMENT BUFFER SIZE.
	JMP NEXT		/PROCESS ANOTHER CHARACTER.
 
/ INPUT COMPLETE.
 
TTYWD2	XX		/LAC TTYN + 1.
	DAC TEMP0		/POINTS AT USER'S BUFFER HEADER.
	LAC* TTYWD8	/GET TEMPORARY HEADER.
	TAD (400		/ADD 1/2 TO WORD PAIR COUNT.
	AND MIN401	/GET RID OF EXTRA 1/2. (777377)
	DAC* TEMP0	/NEW HEADER TO USER'S BUFFER.
TTYWD7	XX		/LAC TTYN + 6.
	SMA		/SKIP IF ECHOING.
	JMP IODONE
	XOR L200K		/SET I/O DONE FLAG. (200000)
DACTT7	DAC* TTYWD7
	JMP NEXT
 
	.EJECT
/ CONTROL D TYPED ON A .READ IS END-OF-FILE.
 
CTRL.D	LAC* TTYWD2	/POINTER TO USER'S BUFFER HEADER.
	DAC TEMP0
	LAC (1005		/SET HEADER WORD PAIR COUNT
	DAC* TEMP0	/TO 1 AND SET EOF BITS.
	JMS ECHO		/ECHO ^D
	JMP TTYWD7	/INPUT COMPLETED.
 
/ CONTROL U INPUT WHILE DOING AN IOPS .WRITE WILL ABORT
/ PRINTING THE REMAINDER OF THE DATA FOR THIS CAL.
 
CTRL.U	LAC* TTYWD1
	SPA		/IGNORE IF ECHOING
	JMP DISCARD	/A CONTROL CHAR.
	AND (66400
	SAD (60400
	SKP		/BUSY ON AN IOPS .WRITE.
	JMP TTYWD1
	LAC (640000	/SET ECHO, IODONE, AND ^U FLAGS
	DAC* TTYWD7	/TO TERMINATE THE .WRITE.
	777400
	AND* TTYWD1
	XOR (100
	DAC* TTYWD1	/RESET LINE FEED SWITCH TAB AND BYTE COUNTS.
	JMP DISCARD
 
	.EJECT
/ INPUT IS IN IOPS ASCII.
 
INIOPS	LAC CHAR
	SAD (25		/^U
	JMP U.CTRL
	SAD (177
	JMP RUBOUT
	LAC* TTYWD2	/POINTER TO USER'S BUFFER HEADER.
	CMA
	TAD* TTYWD4	/BUFFER SIZE (2'S) EXCLUDING HEADER.
	TAD* TTYWD3	/COMPARE WITH STORAGE POINTER.
	SPA!SNA		/SKIP ON BUFFER OVERFLOW.
	JMP NOOVFL
	LAC* TTYWD2
	DAC TEMP0		/POINTER TO USER'S HEADER.
	LAC* TTYWD8	/TEMPORARY HEADER.
	TAD (60		/ADD BUFFER OVERFLOW BITS.
	DAC* TEMP0	/NEW HEADER TO USER'S BUFFER.
	JMP IODONE
 
/ INSERT CHARACTER IN USER'S BUFFER.
 
NOOVFL	LAC* TTYWD3	/GET STORAGE POINTER.
	DAC TEMP0
	LAC* TTYWD1
	AND (7		/GET 5/7 BYTE COUNT.
	IDX* TTYWD1	/INCREMENT STORED BYTE COUNT.
	TAD (JMP PUT	/COMPUTE DISPATCH JUMP.
	DAC .+3
	LAC CHAR
	RCL
J12345	XX		/JMP .+1 TO JMP .+5
PUT	JMP PUT1
	JMP PUT2
	JMP PUT3
PUT4	SKP!RTL
JMPUT5	JMP PUT5
	RTL
PUT2	RTL
	RAL
PUT5	XOR* TEMP0
	JMP PUT.IT
PUT1	RAR
	JMS ROT4R
	JMP PUT13
PUT3	JMS ROT4R
	AND (17		/ONLY NEED TO ZERO BITS 0,1.
	XOR* TEMP0
	DAC* TEMP0	/1ST WORD OF PAIR IS DONE.
	IDX TEMP0
	IDX* TTYWD3	/MOVE POINTER TO WORD 2.
 
	.EJECT
	LAC CHAR
	CLL
PUT13	JMS ROT4R
	AND BYTE3		/(774000
PUT.IT	DAC* TEMP0
	LAC* J12345	/WAS THIS CHAR. # 5?
	SAD JMPUT5
	JMP NXPAIR	/YES.
	SAD PUT		/WAS THIS CHAR. # 1?
	SKP		/YES.
	JMP TESTCH
	LAC* TTYWD8	/ADD 1 TO WORD PAIR COUNT
	TAD (1000		/IN TEMPORARY HEADER.
	DAC* TTYWD8
	JMP TESTCH
NXPAIR	LAW -10
	AND* TTYWD1
	DAC* TTYWD1	/RESET 5/7 BYTE COUNT TO 0.
	IDX* TTYWD3	/MOVE POINTER TO NEXT WORD PAIR.
TESTCH	JMS ECHO		/ECHO, IF NECESSARY.
	LAC CHAR
	SAD (175		/ALT MODE?
	JMP TTYWD2	/YES. INPUT COMPLETE.
	SAD (15		/CAR. RET.?
	JMP TTYWD2	/YES. INPUT COMPLETE.
	JMP NEXT		/PROCESS ANOTHER CHARACTER.
 
/ CONTROL U IN IOPS ASCII INPUT ERASES THE ENTIRE LINE.
 
U.CTRL	JMS ECHO		/ECHO @.
	LAC* TTYWD2	/POINTER TO USER'S HEADER.
	TAD (2
	DAC* TTYWD3	/RESET POINTER TO 1ST DATA WORD IN BUFFER.
	LAC (777		/REINITIALIZE TEMPORARY
	AND* TTYWD8	/HEADER TO WORD PAIR COUNT=1.
	TAD (1000
	DAC* TTYWD8
	LAW -10
	AND* TTYWD1
	JMP DACWD1	/RESET BYTE COUNT TO 0.
 
	.EJECT
/ RUBOUT IN IOPS ASCII INPUT ERASES ONE CHAR. PREVIOUSLY TYPED IN.
 
RUBOUT	777000
	AND* TTYWD8	/CHECK TEMP. HEADER TO
	SAD (1000		/SEE IF BUFFER IS EMPTY.
	JMP NEXT		/YES. NO NEED TO ECHO \.
	JMS ECHO		/ECHO \.
	LAC* TTYWD3
	DAC TEMP0
	LAC* TTYWD1
	AND (7		/GET BYTE COUNT.
	SNA
	JMP BYTE1
	SAD (1
	JMP BYTE2
	SAD (2
	JMP BYTE3
	SAD WD36		/(3
	JMP BYTE4
BYTE5	LAC* TEMP0	/NULL OUT THE 4TH CHARACTER.
	AND (700000
	JMP SUB2
BYTE4	DZM* TEMP0	/NULL OUT 2ND 1/2 OF 3RD CHAR.
	LAW -1		/MOVE POINTER BACK 1 WORD.
	TAD TEMP0
	DAC TEMP0
	DAC* TTYWD3
	LAW -20		/NULL OUT 1ST 1/2 OF 3RD CHAR.
	SKP
BYTE3	774000		/NULL OUT 2ND CHARACTER. (LITERAL).
	AND* TEMP0
SUB2	DAC* TEMP0
	JMP SUB1
BYTE2	DZM* TEMP0	/NULL OUT 1ST CHARACTER.
	LAW -1000		/SUBTRACT 1 FROM TEMP. HEADER
	TAD* TTYWD8	/WORD COUNT.
	DAC* TTYWD8
SUB1	LAW -1		/DECREMENT THE BYTE COUNT.
TADWD1	TAD* TTYWD1
DACWD1	DAC* TTYWD1
	JMP NEXT		/PROCESS ANOTHER CHARACTER.
BYTE1	LAW -1		/MOVE POINTER BACK 1 WORD.
	TAD TEMP0
	DAC TEMP0
	DAC* TTYWD3
	LAW -400		/NULL OUT THE 5TH CHARACTER.
	AND* TEMP0
	DAC* TEMP0
	LAC (4		/RESET BYTE COUNT TO 4.
	JMP TADWD1
 
	.EJECT

/ SUBROUTINE ECHO: CALLED, DURING CHARACTER
/ PROCESSING, TO ECHO, IF NECESSARY, TO SET
/ AND RESET THE INITIAL LINE FEED SWITCH,
/ AND TO UPDATE THE TAB COUNT.
 
ECHO	0
 
	LAC CHAR		/SAVE CHAR AS
	DAC CHARAC	/INITIAL ECHO CHAR, WHICH
			/MAY CHANGE (E.G. RUBOUT=\)
	LAC* TTYWD1	/SET UP THE LINK SUCH THAT
	AND (400		/L=0=IMAGE ALPHA
	SZA!CLL		/L=1=IOPS ASCII.
	STL
	LAC CHAR
	SAD (12
	JMP LNFEED
	SAD (15
	JMP CARRET
 
/ SINCE, IN IOPS ASCII, A CARRIAGE RETURN CAUSES
/ A LINE FEED TO BE ECHOED, A SWITCH MUST BE
/ CLEARED TO NOT ECHO THE NEXT CHARACTER IF IT IS
/ A LINE FEED. RESET THAT SWITCH.
 
MIN201	777577		/LITERAL USED ELSEWHERE.
	AND* TTYWD1	/TURN LINE FEED SWITCH
	TAD (200		/BACK ON.
	DAC* TTYWD1
	LAC CHAR
	SAD (11
	JMP HORTAB
	SAD (13
	JMP VERTAB
	SAD (14
	JMP FMFEED
 
/ ECHO SUBROUTINE WILL NOT SEE RUBOUT, CONTROL U, CONTROL D
/ IF CHAR. CAME FROM .WRITE BUFFER.
 
	SAD (177		/RUBOUT.
	JMP ERASE
	SAD (25		/^U
	JMP UPAROU
	SAD (4		/^D
	JMP UPAROD
 
	.EJECT
/ ALL OTHER CHARACTERS ARE ECHOED ON
/ FULL DUPLEX UNITS FOR INPUT; ALWAYS ON OUTPUT.
	LAW -40
	TAD CHAR
	SPA		/SKIP IF CHAR. >OR=40.
	JMP NONSPC	/NON-SPACING CHAR.
	TAD WD22		/(-100
	SPA		/SKIP IF CHAR > OR= 140.
	JMS TAB1		/IT'S A SPACING CHARACTER.
NONSPC	JMS ECOTST
ECHO1	LAW
ECHOIT	AND (407777
	DAC* TTYWD7	/SETUP THE ECHO REGISTER.
	LAW
	DAC ECHO1		/RESET TO NO ECHO.
	LAC* TTYWD1	/IF IT'S AN INPUT ECHO,
	SPA		/OR IF ECHOING A
	JMP BUILD		/CONTROL CHARACTER,
	AND (20000	/THE TLS MUST BE BUILT.
	SZA
	JMP DOIT		/OUTPUT ECHO.
BUILD	LAC DVCCOD
	SAD (300		/UNIT 0?
	TAD (200
	TAD (677706	/(IOT 6)-100
	DAC XCTTLS	/CONVERTED TO A TLS.
DOIT	LAC  CHARAC
	AND (177
	XCT XCTTLS	/TLS TO UNIT N.
	JMP* ECHO
 
/ SUBROUTINE TAB1: CHANGE TAB COUNT FOR A SPACING CHAR.
 
TAB1	0
	LAW -10		/SUBTRACT 1
	TAD* TTYWD1	/FROM TAB COUNT.
	DAC* TTYWD1
	AND (170
	SNA		/SKIP IF COUNT NON-0.
	JMS NEWTAB	/RESET COUNT TO 8 DECIMAL.
	JMP* TAB1
LNFEED	LAC* TTYWD1
	AND (200		/GET AND SAVE
	DAC TEMP0		/LINE FEED SWITCH.
	XOR* TTYWD1	/SET THE SWITCH.
	XOR (200
	DAC* TTYWD1
	JMS ECOTST
	SNL!CLA		/SKIP IF MODE IS IOPS ASCII.
	JMP ECHO1
	SAD TEMP0
	JMP* ECHO		/LINE FEED SWITCH SAYS NO ECHO.
	JMP ECHO1
 
	.EJECT
CARRET	JMS NEWTAB	/RESET TAB COUNT TO 8 (DEC).
	AND MIN201	/CLEAR LINE FEED SWITCH. (777577)
	DAC* TTYWD1
	SZL
	JMP CAR57		/IOPS ASCII.
	JMS ECOTST
	LAW 200		/ECHO 1 NULL CHAR. AFTER
	JMP ECHOIT	/THE CAR. RET. IS ECHOED.
CAR57	LAC* TTYWD1	/ECHO ONLY A LINE FEED
	AND (20000	/IF UNIT 0 AND INPUT.
	SAD UNIT
	JMP HAF57		/UNIT 0 IS 1/2 DUPLEX.
	LAW 212		/ECHO CAR. RET. THEN A
	JMP  ECHOIT	/LINE FEED.
HAF57	LAW 12		/ECHO JUST A LINE FEED.
ONLY1	DAC CHARAC
	JMP ECHO1
 
/ SUBROUTINE NEWTAB: RESET TAB COUNT TO 8 DECIMAL.
 
NEWTAB	0
 
	777607		/MASK OUT TAB COUNT.
	AND* TTYWD1
	TAD (100		/SET COUNT TO 8 DECIMAL.
	DAC* TTYWD1
	JMP* NEWTAB
 
/ HORIZONTAL TAB.
 
 
HORTAB	LAW -10		/GET TAB COUNT,
	TAD* TTYWD1	/SUBTRACT 1 IN CASE
	AND (170		/YOU MUST ECHO SPACES,
	DAC TEMP0		/AND SAVE IT.
	JMS NEWTAB	/RESET TAB COUNT TO 8 DECIMAL.
	LAC* TTYWD1
	AND (10000
	SZA
	JMP MDL35		/MODEL 35 TELETYPE.
LAW40	LAW 40		/SPACE. (LITERAL).
	DAC CHARAC	/1ST CHAR. TO ECHO.
	LAC TEMP0		/TAB COUNT -1 (TIMES 8)
	SNA!CLL
	JMP ECHO1		/ECHO JUST ONE SPACE.
	RTL		/MOVE REPEAT COUNT INTO
	RTL		/POSITION.
	XOR LAW40		/ECHO SPACES.
	JMP ECHOIT
MDL35	JMS ECOTST
	LAW 400		/ECHO TAB FOLLOWED BY
	JMP ECHOIT	/2 NULLS.
 
	.EJECT
/ FOR THE PRESENT, VERTICAL TAB AND FORM
/ FEED WILL NOT BE SIMULATED ON MODEL 33'S
/ AND CAN THEREFORE BE TREATED IDENTICALLY.
 
VERTAB=.
FMFEED	JMS ECOTST
	LAC* TTYWD1
	AND (10000
	SNA
	JMP* ECHO		/NO ECHO ON MODEL 33.
	LAW 2400		/ECHO THE V.TAB OR F.FEED
	JMP ECHOIT	/FOLLOWED BY 10(DEC)NULLS.
 
/ RUBOUT.
 
ERASE	SNL
	JMP* ECHO		/NO ECHO IN IMAGE MODE.
ERASE1	JMS TAB1
	LAW 134		/\
	JMP ONLY1		/ECHO ONE BACKSLASH.
 
/ CONTROL U.
 
UPAROU	SNL
	JMP* ECHO		/NO ECHO IN IMAGE MODE.
	JMS TAB1
	LAW 100		/@
	JMP ONLY1		/ECHO ONE AT-SIGN.
 
/ CONTROL D.
 
UPAROD	LAW 136		/^
	DAC CHARAC
	JMS TAB1
	JMS TAB1
	LAW 304		/ECHO ^ THEN D.
	JMP ECHOIT
 
/ SUBROUTINE ECOTST: ON OUTPUT, RETURN. ON INPUT, RETURN IF FULL DUPLEX.
 
ECOTST	0
 
	LAC* TTYWD1
	SPA
	JMP* ECOTST	/ECHOING A CONTROL CHAR.
	AND (20000	/TEST INPUT-OUTPUT BIT.
	SAD UNIT		/UNIT 0 IS 1/2 DUPLEX.
	JMP* ECHO		/NO ECHO TO UNIT 0 ON INPUT.
	JMP* ECOTST
 
	.EJECT
	.TITLE TT.CTL
 
/ PROCESSING OF CONTROL C.
 
CTRL.C	JMS TSTCTL
	JMP FGCTLC
 
/ CONTROL C ON BGD CTRL TTY.
 
	LAC BCTL.C	/WAS ^C ALREADY TYPED IN OR
	SPA!SNA		/IS IT NOT SETUP?
	JMP DISCARD	/YES. IGNORE.
	XOR (400000
	DAC BCTL.C	/NO. SET BIT0=1.
	JMS TOZERO	/RAISE TO LEVEL 0.
	LAW 6000		/DUMMY ARG.: BGD TERMINAL ERROR.
DUMYER	JMS* .SCOM+66	/CALL ERRORQ ROUTINE.
MIN401	777377		/DUMMY ARG AND LITERAL.
	JMP DISCARD
 
/ CONTROL C ON FGD CTRL TTY.
 
FGCTLC	LAC FCTL.C	/IS ^C ENABLED?
	SPA!SNA
	JMP DISCARD	/NO. IGNORE.
	JMS CCECHO	/ECHO ^C
	0
	JMS TOZERO	/RAISE TO LEVEL 0.
	JMP .BOOT
 
	.EJECT
/ PROCESSING OF CONTROL P.
 
CTRL.P	LAC* TTYWD6	/UNIT'S REAL-TIME ^P REGISTER.
	SNA
	JMP NORM.P	/NOT REAL-TIME; TRY NORMAL ^P.
 
/ DO A REAL-TIME CONTROL P.
 
	DAC* TTYWD5	/SETUP UNIT'S REAL-TIME REQUEST REG.
	JMS CCECHO	/ECHO ^P.
	0
	JMP IODONE	/TERMINATE I/O.
 
/ TEST IF NORMAL CONTROL P IS SETUP.
 
NORM.P	JMS TSTCTL
	JMP FGCTLP
BGCTLP	LAC BCTL.P	/BGD ^P REGISTER.
	SPA!SNA
	JMP DISCARD	/^P DISABLED (0) OR IN PROGRESS (-). IGNORE.
	JMS CCECHO	/ECHO ^P.
	0
	LAC BCTL.P
	XOR (400000	/SET ^P IN PROGRESS BIT.
	DAC BCTL.P
	DZM* TTYWD7	/0 THE ECHO REGISTER.
	JMS STOP.B	/STOP BGD TTY I/O.
	JMP P.STOP
FGCTLP	LAC FCTL.P	/FGD ^P REGISTER.
	SPA!SNA
	JMP DISCARD
	JMS CCECHO	/ECHO ^P.
	0
	LAC FCTL.P
	XOR (400000	/SET ^P IN PROGRESS BIT.
	DAC FCTL.P
	DZM* TTYWD7	/0 THE ECHO REGISTER.
	JMS STOP.F	/STOP FGD TTY I/O.
P.STOP	LAC HUNG		/IF INPUT WAS HUNG ON AN ECHO,
	SNA		/GO THRU INPUT RING BUFFER TO
	JMP NEXT		/DISCARD CHARACTERS.
	JMP INPUT
 
	.EJECT
/ PROCESSING OF CONTROL S.
 
CTRL.S	JMS TSTCTL	/RETURN IF IT'S A CTRL TTY.
	JMP FGCTLS
 
/ CONTROL S ON BGD CTRL TTY.
 
	LAC BCTL.S	/WAS ^S ALREADY TYPED IN OR
	SPA!SNA		/IS IT DISABLED?
	JMP DISCARD	/YES. IGNORE.
	JMS CCECHO	/ECHO ^S.
	0
	LAC BCTL.S
	XOR (400000
	DAC BCTL.S	/NO. SET ^S IN PROGRESS.
	JMP CKHUNG
 
/ CONTROL S ON FGD CTRL TTY.
 
FGCTLS	LAC FCTL.S	/SAME COMMENTS AS ABOVE.
	SPA!SNA
	JMP DISCARD
	JMS CCECHO	/ECHO ^S.
	0
	LAC FCTL.S
	XOR (400000
	DAC FCTL.S
	JMP CKHUNG
 
/ PROCESSING OF CONTROL T.
 
CTRL.T	JMS TSTCTL
	JMP DISCARD	/IGNORE ^T - NOT FROM BGD CTRL TTY.
	LAC BCTL.T
	SPA!SNA		/^T IN PROGRESS OR DISABLED?
	JMP DISCARD	/YES. IGNORE.
	JMS CCECHO	/ECHO ^T.
CTTXIT	0
	LAC BCTL.T
	XOR (400000
	DAC BCTL.T	/SET ^T IN PROGRESS.
	JMP* CTTXIT	/RETURN TO DOECHO SUBR.
 
	.EJECT
/ PROCESSING OF CONTROL R.
 
CTRL.R	JMS TSTCTL
	JMP FGCTLR
 
/ CONTROL R ON BGD CTRL TTY.
 
	LAC BCTL.R	/IS ^R DISABLED?
	SNA
	JMP DISCARD	/YES. IGNORE.
	DAC CRTMP1	/SAVE ENTRY POINT + API LEVEL.
	LAC (BCTL.R
	JMP CRPTR
 
/ CONTROL R ON FGD CTRL TTY.
 
FGCTLR	LAC FCTL.R	/IS ^R DISABLED?
	SNA
	JMP DISCARD	/YES. IGNORE.
	DAC CRTMP1	/SAVE ENTRY POINT + API LEVEL.
	LAC (FCTL.R
CRPTR	DAC CRTMP2	/POINTER TO ^R REGISTER.
	JMS CCECHO	/ECHO ^R
CTRXIT	0
	.IFUND PI
	DZM CRLV0		/FLAG 0 MEANS DO A DBK.
	LAC CRTMP1	/GET API LEVEL CODE.
	AND (300000
	SAD (300000	/LEVEL 3?
	LAC (20
	SAD L200K		/LEVEL 2?
	LAC (40
	SAD (100000	/LEVEL 1?
	LAC (100
	SNA		/LEVEL 0?
	SET CRLV0		/SET FLAG FOR NO DBK.
	TAD (400200
	ISA		/RAISE TO LEVELS N AND 0.
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
	DZM* CRTMP2	/CLEAR ^R REGISTER.
	.IFUND PI
	LAC CRLV0		/IF HANDLER PROCESSES ^R AT LEVEL 0,
	SNA		/DON'T DBK.
	DBK
	.ENDC
	JMS* CRTMP1	/CALL HANDLER'S ^R ROUTINE.
	JMP* CTRXIT	/RETURN TO TTA ECHO ROUTINE.
	.IFUND PI
CRLV0	0		/NON-0 MEANS SUBR IS TO BE ENTERED AT
	.ENDC		/LEVEL 0. THEREFORE, DON'T DBK.
 
	.EJECT
/ SUBROUTINE TSTCTL: TEST FOR A CONTROL TELETYPE.
 
TSTCTL	0
 
	LAC FGDCTL	/.IOIN ENTRY FOR FGD CTRL TTY.
	XOR UNIT
	AND (77777
	SNA
	JMP* TSTCTL	/RETURN NO SKIP FOR FGD.
	LAC BGDCTL	/.IOIN ENTRY FOR BGD CTRL TTY.
	XOR UNIT
	AND (77777
	SZA
	JMP DISCARD	/IGNORE. NOT A CTRL TTY.
	IDX TSTCTL	/SKIP ON RETURN FOR BGD.
	JMP* TSTCTL
 
/ PROCESSING OF CONTROL Q.
 
CTRL.Q	JMS TSTCTL
	JMP FGCTLQ
 
/ CONTROL Q ON BGD CTRL TTY.
 
	LAC BCTL.Q	/WAS ^Q ALREADY TYPED
	SPA!SNA		/OR IS IT DISABLED?
	JMP DISCARD	/YES. IGNORE.
	LAW 6000		/DUMMY ARG: BGD TERMINAL ERROR.
	DAC BCTL.Q	/SET BGD ^Q REGISTER MINUS.
	JMP DUMYER	/SET UP DUMMY ERROR.
 
/ CONTROL Q ON FGD CTRL TTY.
 
FGCTLQ	LAC FCTL.Q	/WAS ^Q ALREADY TYPED
	SPA!SNA		/OR IS IT DISABLED?
	JMP DISCARD	/YES. IGNORE.
	LAW 5000		/DUMMY ARG: FGD TERMINAL ERROR.
	DAC FCTL.Q	/SET FGD ^Q REGISTER MINUS.
	DZM BCTL.Q	/DISABLE BGD ^Q.
	JMP DUMYER	/SET UP DUMMY ERROR.
 
	.EJECT
/ SUBROUTINE CCECHO: CALLED BY SPECIAL CONTROL CHARACTERS THAT WANT TO
/ BE ECHOED, E.G., ^P. IF TTY UNIT IS ECHOING, DON'T PROCESS
/ CHARACTER YET. IF NOT ECHOING, START UP THE ECHO; AND SET A FLAG BIT
/ TO INDICATE THIS STATE SO THAT .INIT WILL NOT BE ALLOWED TO FORCE
/ ITS WAY IN AND SO THAT I/O CAN RESUME AFTER THE ECHO.
 
CCECHO	0
 
	LAC* TTYWD7	/ECHOING?
	SPA
	JMP HANGUP	/YES. WAIT 'TIL FREE.
	LAC (400000
	XOR* TTYWD1	/SET CTRL CHAR ECHO BIT.
	DAC* TTYWD1
	LAC* TTYWD6	/SAVE ^P ADDR TEMPORARILY IN
	DAC* CCECHO	/REGISTER FOLLOWING JMS CCECHO.
	LAC CCECHO	/REPLACE WITH POINTER TO RETURN ADDR.
	DAC* TTYWD6
	LAW 300		/SETUP TO ECHO THE CHARACTER AFTER
	TAD CHAR		/THE ^.
	DAC ECHO1
	LAC (136		/^
	DAC CHAR
	JMS TAB1		/UPDATE TAB COUNT BY 1.
	JMS ECHO
	JMP DISCARD
 
	.EJECT
/ CONTROL R QUEUER: CALLED AT API LEVEL 0 WITH PIC OFF TO INITIATE
/ A "DEVICE NOT READY" CYCLE. ONLY ONE ^R CYCLE PER JOB IS ALLOWED
/ AT ONE TIME.
 
/ CALLING SEQUENCE:
 
/	LAC* (.SCOM+64	/ADDRESS OF CONTROL R QUEUER.
/	DAC TEMP
/	LAC (400200	/RAISE TO API LEVEL 0.
/	ISA
/	IOF		/PIC OFF.
/	JMS* TEMP
/	XX		/ARG 1: 0=FGD; 1=BGD.
/	.ASCII /XX/	/ARG 2: XX=DEVICE NAME.
/	.LOC .-1
/	"UNIT"		/ARG 3: UNIT # IN BITS 0-2.
/	C+FRA		/ARG 4: LEVEL+FGD ^R RETURN ENTRY
/	C+BRA		/ARG 5: LEVEL+BGD ^R RETURN ENTRY.
/	(RETURN ON ERROR)	/^R ALREADY IN PROGRESS FOR THIS JOB.
/	(RETURN IF O.K.)
 
CR.QR	0
 
	LAC* CR.QR	/GET ARG 1.
	AND (1
	DAC CR.FB		/0=FGD; 1=BGD.
	RCL
	RTL		/0=FGD; 8=BGD.
	TAD (DAC FRDATA	/FRDATA+8=BRDATA.
	DAC CR.DP		/^R DATA SAVE POINTER.
	LAC (LAC FCTL.R	/FGD ^R REG. IN CTRL CHAR TABLE.
	DAC CR.REG
	LAC CR.FB		/0=FGD; 1=BGD.
	SNA
	JMP CR.REG	/FGD.
	LAC (LAC BCTL.R	/BGD ^R REG. ...
	DAC CR.REG
CR.REG	XX		/EXAMINE ^R REGISTER.
	IDX CR.QR		/POINT AT ARG 2.
	SZA		/^R IN PROGRESS?
	JMP CR.ER		/YES. ERROR.
	LAC* CR.QR	/ARG 2: .ASCII /XX/.
CR.DP	XX		/STORE DATA FOR PRINTING.
	IDX .-1
	IDX CR.QR		/POINT AT ARG 3.
	LAC* CR.QR	/UNIT # IN BITS 0-2.
	RTL
	RTL
	AND (7
	TAD (60		/CONVERT TO ASCII.
	RCL		/POSITION AS CHAR #5 IN WORD PAIR.
	XCT CR.DP		/STORE DATA.
	IDX CR.QR		/POINT AT ARG 4.
 
	.EJECT
	LAC CR.FB
	SZA!RAR		/L=0=FGD; L=1=BGD.
	IDX CR.QR		/POINT AT ARG 5.
	LAC* CR.QR	/^R RETURN ENTRY + API LEVEL.
	AND (377777	/BIT 0 OFF.
	DAC* CR.REG	/SETUP ^R REGISTER.
	SNL!CLC
	DAC FRWRIT	/SET FGD ^R MSG FLAG.
	SZL
	DAC BRWRIT	/SET BGD ^R MSG FLAG.
	SNL		/IF FGD, POINT AT ARG 5.
CR.XIT	IDX CR.QR
	IDX CR.QR
	IDX CR.QR
	JMP* CR.QR	/RETURN.
 
CR.ER	LAC* CR.QR	/ARG 2: .ASCII /XX/.
	DAC CR.AUX
	LAC CR.FB		/0=FGD; 1=BGD.
	SZA
	LAC (1000		/CONVERT TO BGD ERROR.
	TAD (LAW 5004	/FGD TERMINAL .ERR 004.
	JMS ERRORQ
CR.AUX	XX		/.ASCII /XX/=DEVICE NAME.
	IDX CR.QR		/POINT AT ARG 3.
	JMP CR.XIT	/ERROR RETURN.
 
FRDATA	0		/.ASCII /XX/<0><0>/"UNIT"/
	0
	.ASCII / NOT READY/<15>
	.LOC .-1
CR.FB	0		/0=FGD; 1=BGD.
BRDATA	0		/.ASCII /XX/<0><0>/"UNIT"/
	0
	.ASCII / NOT READY/<15>
	.LOC .-1
CR.TMP	0
 
	.EJECT
	.TITLE TTSTOP
 
/ SUBROUTINE STOP.F: CALLED AT MAINSTREAM (OR AT LEVEL 4) TO STOP ALL FGD TTY I/O.
STOP.F	0
	LAC .SCOM+76	/- # OF TTYS ON THIS MACHINE.
	DAC FCOUNT
	LAC LACTT0	/(LAC TTY0
F.LOOP	DAC F.TTY1
	TAD (4
	DAC F.TTY5
	TAD (2
	DAC F.TTY7
F.TTY1	XX		/GET TTY'S WORD 1.
	AND (100000	/TEST IF OWNED BY FGD.
	SZA
	JMP F.NEXT	/NO.
	.IFUND PI
	LAC (400020	/RAISE TO LEVEL 3.
	ISA
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
F.TTY7	XX		/YES. GET ECHO REGISTER.
	SPA
	JMP STOP.E	/ECHOING.
	LAC* F.TTY1
	AND (737777
	DAC* F.TTY1	/SET UNIT NON-BUSY.
	.IFUND PI
	LAC (400200
	ISA
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
	LAC .SCOM+76	/-# OF TTYS ON MACHINE.
	CMA		/COMPUTE UNIT #.
	TAD FCOUNT
	TAD (600001	/MAKE IT LOOK LIKE .DAT ENTRY.
	JMS* .SCOM+52	/CALL IOBUSY.
	.IFUND PI
	DBK		/FROM LEVEL 0 TO 3.
	.ENDC
	JMP .+4
STOP.E	AND (500000	/SAVE ECHO- AND HUNG-ON-ECHO FLAGS.
	XOR L200K		/SET IODONE FLAG IN ECHO REGISTER. (200000)
	DAC* F.TTY7
	DZM* F.TTY5	/ZERO OUT REAL-TIME ADDRESS.
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
F.NEXT	LAC F.TTY7	/MOVE ON TO NEXT UNIT.
	TAD (2
	ISZ FCOUNT
	JMP F.LOOP
	JMP* STOP.F
FCOUNT	0
F.TTY5	0
	.EJECT
/ SUBROUTINE STOP.B: CALLED AT MAINSTREAM (OR AT LEVEL 4) TO STOP ALL BGD TTY I/O.
 
STOP.B	0
 
	LAC .SCOM+76	/- # OF TTYS ON THIS MACHINE.
	DAC BCOUNT
	LAC LACTT0	/(LAC TTY0
B.LOOP	DAC B.TTY1
	TAD (4
	DAC B.TTY5
	TAD (2
	DAC B.TTY7
B.TTY1	XX		/GET TTY'S WORD 1.
	AND (100000	/TEST IF OWNED BY BGD.
	SNA
	JMP B.NEXT	/NO.
	.IFUND PI
	LAC (400020	/RAISE TO LEVEL 3.
	ISA
	.ENDC
	.IFDEF PI
	IOF
	.ENDC
B.TTY7	XX		/YES. GET ECHO REGISTER.
	SPA
	JMP .+5		/ECHOING.
	LAC* B.TTY1
	AND (737777
	DAC* B.TTY1	/SET UNIT NON-BUSY.
	JMP .+4
	AND (500000	/SAVE ECHO- AND HUNG-ON-ECHO FLAGS.
	XOR L200K		/SET IODONE FLAG IN ECHO REGISTER. (200000)
	DAC* B.TTY7
	DZM* B.TTY5	/ZERO OUT REAL-TIME ADDRESS.
	.IFUND PI
	DBK
	.ENDC
	.IFDEF PI
	ION
	.ENDC
B.NEXT	LAC B.TTY7	/MOVE ON TO NEXT UNIT.
	TAD (2
	ISZ BCOUNT
	JMP B.LOOP
	JMP* STOP.B
BCOUNT	0
B.TTY5	0
 
	.EJECT
	.TITLE TT.OUT
 
/ OUTPUT INTERRUPT PROCESSING.
 
NXOUT	LAC* TPRGET	/GET TCF N FROM TPR RING BUFFER.
	TAD (2		/CONVERT TO A TLS.
	DAC XCTTLS
	JMS ROT4R
	AND (377
	DAC TEMP0		/SAVE DEVICE CODE.
	LAC TPRGET	/MOVE GET POINTER TO NEXT SLOT.
	TAD (1
	SAD TPREND
	LAC TPRBEG
	DAC TPRGET
	LAC TEMP0		/CONVERT DEVICE CODE TO UNIT # (0-20).
	SAD (20
	CLA!SKP		/UNIT 0.
	TAD WD23		/(-177
	JMS GETUNIT
	LAC* TTYWD1	/UNIT MUST BE BUSY.
	AND (440000
	SNA
	JMP DACTT7	/NOT BUSY.
	LAC* TTYWD1
	AND (60000	/.WRITE?
	SAD (60000
	JMP OUTPUT	/YES.
	JMS DOECHO	/RETURN IF ECHO COMPLETED, NOT HUNG,
	JMP NEXT		/AND I/O NOT DONE.
 
	.EJECT
/ TELEPRINTER INTERRUPT WAS FROM AN ECHO.
 
DOECHO	0
 
	LAC* TTYWD7	/GET ECHO COUNT.
	AND (7600
	SNA
	JMP CTZERO
	LAW -200		/DECREMENT ECHO COUNT.
	TAD* TTYWD7
	DAC* TTYWD7
	AND (177		/GET ECHO CHARACTER.
XCTTLS	XX		/TLS TO UNIT N.
	JMP NEXT		/PROCESS NEXT CHARACTER.
CTZERO	LAC* TTYWD7
	AND (40000	/^U FLAG SET?
	SNA
	JMP ECODONE	/NO.
	LAC (600212	/ECHO 1 LINE FEED WITH IODONE.
	DAC* TTYWD7
	LAC (15		/CAR. RET.
	JMP XCTTLS
ECODONE	LAC* TTYWD1	/FINISHED CTRL CHAR ECHO?
	SMA
	JMP ECDONE	/NO.
	AND (377777
	DAC* TTYWD1	/YES. CLEAR CTRL CHAR ECHO BIT.
	LAC* TTYWD6	/POINTER TO SAVED ^P ADDR.
	DAC CHARAC	/TEMP REG.
	LAC* CHARAC	/GET SAVED ^P ADDR.
	DAC* TTYWD6	/RESTORE IT.
	JMS* CHARAC	/PROCESS CTRL CHAR. SOME WON'T RETURN.
ECDONE	LAC* TTYWD7	/COUNT=0. ECHO FINISHED.
	RTL
	SZL		/IS I/O DONE FOR THIS UNIT?
	JMP IODONE	/YES.
	DZM* TTYWD7	/0 THE ECHO REGISTER.
	SPA		/WAS INPUT HUNG ON THIS ECHO?
	JMP INPUT		/YES. GO TO KEYBOARD PROCESSOR.
	JMP* DOECHO
 
	.EJECT
/ OUTPUT PROCESSING.
 
OUTPUT	LAC* TTYWD7	/SKIP IF NOT ECHOING.
	SPA
	JMS DOECHO	/RETURN IF ECHO DONE, NOT HUNG, AND
			/I/O NOT DONE.
 
/ SHOULD'NT GET HERE ON .INIT OR .CLOSE, SO THIS MUST BE A .WRITE.
 
NEXTCH	LAC* TTYWD3	/GET RUNNING BUFFER POINTER.
	DAC TEMP0
	LAC* TTYWD1	/IMAGE OR IOPS?
	AND (400
	SZA
	JMP WRIOPS
 
/ OUTPUT IN IMAGE MODE.
 
	LAC* TEMP0	/GET CHARACTER.
	JMS REVERB	/ECHO.
	IDX* TTYWD3	/MOVE BUFFER POINTER AHEAD 1.
	ISZ* TTYWD4	/DECREMENT BUFFER SIZE.
	SKP
	JMP TTYWD7	/OUTPUT COMPLETED.
	LAC* TTYWD7
	SMA
	JMP NEXTCH	/NOT ECHOING. GET ANOTHER CHAR.
	JMP NEXT
 
/ OUTPUT IN IOPS ASCII.
 
WRIOPS	LAC* TTYWD1
	AND (7		/GET 5/7 BYTE COUNT.
	TAD (JMP GET
	DAC DISPAT
	IDX* TTYWD1	/ADD 1 TO 5/7 BYTE COUNT.
	LAC* TTYWD1
	AND (7
	SAD (5
	JMP ZERBYT
	SAD WD36		/(3
	JMP NEXWRD
	JMP UNPACK
ZERBYT	XOR* TTYWD1	/0 BYTE COUNT.
	DAC* TTYWD1
NEXWRD	IDX* TTYWD3	/MOVE BUFFER POINTER AHEAD 1.
UNPACK	JMS TSTNXM	/GET BUFFER WORD.
DISPAT	XX		/JMP .+1 TO JMP .+5
GET	JMP GET1
	JMP GET2
	JMP GET3
	JMP GET4
 
	.EJECT
GET5	RAR
	JMP GOT
GET4	JMS ROT4R
GET2	JMS ROT4R
	JMP GOT
GET1	RTL
	RTL
	RTL
	RTL
	JMP GOT
GET3	RAL
	RTL
	AND (170
	DAC DISPAT	/SAVE HIGH-ORDER 4 BITS.
	IDX TEMP0
	JMS TSTNXM	/GET NEXT WORD.
	RTL
	RTL
	AND (7		/GET LOW-ORDER 3 BITS.
	XOR DISPAT	/HAVE CHAR. 3 ASSEMBLED.
GOT	JMS REVERB	/ECHO.
	LAC* TTYWD7
	SMA		/SKIP IF ECHOING.
	JMP NEXTCH
	LAC CHAR
	SAD (15		/CAR. RET.?
	JMP TTYWD7	/YES. OUTPUT DONE.
	SAD (175		/ALT MODE?
	JMP TTYWD7
	JMP NEXT		/NO. PROCESS ANOTHER CHARACTER.
 
	.EJECT
/ SUBROUTINE TSTNXM: IF CARRIAGE RETURN OR ALTMODE HAS NOT BEEN
/ FOUND WHILE UNPACKING FOR IOPS ASCII OUTPUT AND THE END OF
/ MEMORY IS REACHED, PRINT CARRIAGE RETURN LINE FEED AND TERMINATE
/ THE OUTPUT.
 
TSTNXM	0
 
	LAC .SCOM
	CMA
	TAD TEMP0
	SMA
	JMP .+3
	LAC* TEMP0
	JMP* TSTNXM
	LAC (15
	JMP GOT
 
/ SUBROUTINE REVERB: DON'T PRINT NULL, RUBOUT, CONTROL U, OR CONTROL D.
/ OTHERWISE, JMS ECHO.
 
REVERB	0
 
	AND (177
	SAD (177		/RUBOUT?
	JMP* REVERB	/YES. DON'T PRINT.
	SAD (25		/^U?
	JMP* REVERB	/YES. DON'T PRINT.
	SAD (4		/^D?
	JMP* REVERB	/YES. DON'T PRINT.
	SNA		/NULL?
	JMP* REVERB	/YES. DON'T PRINT.
	DAC CHAR
	JMS ECHO
	JMP* REVERB
 
	.EJECT
/ SUBROUTINE GETUNIT: FINISH CONVERTING
/ THE DEVICE CODE TO A UNIT # (0-20).
/ THEN SETUP 8 DATA POINTERS.
 
GETUNIT	0
 
	DAC UNIT
	AND (30
	RCR
	CMA
	TAD (1
	TAD UNIT
	DAC UNIT		/UNIT # (0-20).
	RCL
	RTL		/TIMES 8.
	TAD LACTT0	/SETUP FETCH POINTERS TO 8 DATA (LAC TTY0)
	DAC TTYWD1	/REGISTERS FOR THIS UNIT.
	TAD (1
	DAC TTYWD2
	TAD (1
	DAC TTYWD3
	TAD (1
	DAC TTYWD4
	TAD (1
	DAC TTYWD5
	TAD (1
	DAC TTYWD6
	TAD (1
	DAC TTYWD7
	TAD (1
	DAC TTYWD8
	JMP* GETUNIT
 
/ SUBROUTINE TOZERO: RAISE TO API LEVEL 0.
 
TOZERO	0
 
	.IFUND PI
	LAC (400200
	ISA
	.ENDC
	IOF
	JMP* TOZERO
 
/ SUBROUTINE ROT4R: ROTATE AC 4 RIGHT.
 
ROT4R	0
 
	RTR
	RTR
	JMP* ROT4R
 
	.EJECT
	.TITLE TTDONE
 
/ I/O COMPLETED FOR THIS UNIT. SETUP LINKAGE IF IT WAS A REAL-TIME
/ REQUEST. UNBUSY ALL FGD LEVELS THAT ARE IOBOUND ON THIS UNIT.
 
IODONE	LAC* TTYWD1
	AND (737777
	DAC* TTYWD1	/SET UNIT NON-BUSY.
	JMS TOZERO	/RAISE TO LEVEL 0.
	LAC (600000
	TAD UNIT
	JMS* .SCOM+52	/CALL FGD I/O BUSY TESTER.
	.IFUND PI
	DBK
	.ENDC
	ION
TTYWD5	XX		/LAC TTYN+4
	SNA
	JMP CKHUNG	/NOT A REAL-TIME REQUEST.
	JMS TOZERO	/RAISE TO LEVEL 0.
	XCT TTYWD5	/PICKUP REAL-TIME REQUEST.
	JMS* .SCOM+51	/CALL REALTP IN RESMON.
DRPNXT=.
	.IFUND PI
	DBK
	.ENDC
.ION	ION
CKHUNG	LAC* TTYWD7
	DZM* TTYWD7
	RTL
	SPA
	JMP INPUT		/HUNG ON ECHO.
 
	.EJECT
/ PROTECTED EXIT.
 
NEXT	JMS TOZERO	/RAISE TO LEVEL 0.
NEXT1	LAC KBDGT1	/IS THE KBD RING BUFFER
	SAD KBDPUT	/EFFECTIVELY EMPTY?
	JMP NEXTPR
	.IFUND PI
	DBK		/DROP BACK TO LEVEL 4.
	.ENDC
	ION
	JMP NXIN		/PROCESS NEXT INPUT CHARACTER.
NEXTPR	LAC TPRGET	/IS TPR RING BUFFER EMPTY?
	SAD TPRPUT
	JMP NEXMTY	/YES. BOTH EMPTY.
	.IFUND PI
	DBK		/DROP BACK TO LEVEL 4.
	.ENDC
	ION
	JMP NXOUT		/PROCESS NEXT TPR INTERRUPT.
NEXMTY	ION
	.IFUND PI
	DBK		/DROP BACK TO LEVEL 4.
	.ENDC
	JMP* INT1		/RETURN TO LEVEL 4 HANDLER.
 
	.EJECT
	.TITLE TTREGS
CRNULL	0
CALWD2	0
CALWD6	0
CALWD7	0
WD1TMP	0
WD7TMP	0
LVL3AC	0
HUNG	0
DVCCOD	0
CHAR	0
CHARAC	0
TEMP0	0
TEMP2	0
ACTEMP	0
TTYWD4	0
TTYWD6	0
UNIT	0
UNIT.	0
CRTMP1	0
CRTMP2	0
 
/ CONTROL CHARACTER TABLES. PROGRAMS WILL RELY ON THE FACT THAT
/ SPECIFIC CONTROL CHARACTER REGISTERS ARE IN A FIXED POSITION
/ RELATIVE TO THE BEGINNING OF THE TABLE. ZERO CONTENTS MEANS
/ THAT THE CONTROL CHARACTER FUNCTION IS DISABLED -- THE CHARACTER
/ WILL BE DISCARDED IF TYPED IN. WHEN THE FUNCTION IS ENABLED,
/ BIT 0 IS SET WHEN THE CONTROL CHARACTER HAS BEEN TYPED.
 
/ FOREGROUND CONTROL CHARACTER TABLE.
 
FCTL.C	0		/ENABLED AT END OF RESINT.
FCTL.P	0
FCTL.S	0
LACTT0	LAC TTY0		/LITERAL.
FCTL.R	0
FCTL.Q	0		/ENABLED AT END OF RESINT.
 
/ BACKGROUND CONTROL CHARACTER TABLE.
 
BCTL.C	0		/ENABLED AT CODE IN NEWBGD.
BCTL.P	0
BCTL.S	0
BCTL.T	0
BCTL.R	0
BCTL.Q	0		/ENABLED AT CODE IN NEWBGD.
 
	.EJECT
	.TITLE TTSTAT
 
/ DATA REGISTER BLOCK FOR EACH TELETYPE UNIT (8 WORDS PER UNIT).
 
/ WORD 1:	   0=		   1=
/ BIT 0	NO CTRL CHAR ECHO	CTRL CHAR ECHO
/     1	UNUSED
/     2	FGD		BGD
/     3	NOT BUSY		I/O UNDERWAY
/     4	INPUT		OUTPUT
/     5	MODEL 33		MODEL 35
/     6	NOT .INIT		.INIT
/     7	NOT .CLOSE	.CLOSE
/     8	UNUSED
/     9	IMAGE ALPHA	IOPS ASCII
/    10	NEW LINE		LINE STARTED
/ 11-14	* * * TAB COUNT * * *
/ 15-17	* * * 5/7 ASCII BYTE COUNT * * *
 
/ WORD 2:	POINTER TO USER'S DATA BUFFER
/ WORD 3:	RUNNING DATA BUFFER POINTER
/ WORD 4:	BUFFER SIZE (2'S COMPLEMENT) EXCLUDING HEADER
/ WORD 5:	REAL-TIME ADDRESS + API LEVEL BITS (0 FOR BGD; 1 FOR FGD MAINSTREAM)
/ WORD 6:	CONTROL P TRANSFER ADDRESS
/ WORD 7: OUTPUT ECHO REGISTER
/ BIT 0	1=ECHO IN PROGRESS
/     1	1=I/O DONE EXCEPT FOR ECHO
/     2	1=I/O HUNG ON THIS ECHO
/     3	1=CONTROL U FLAG
/  7-10	* * * ECHO COUNT * * *
/ 11-17	* * * CHARACTER TO BE ECHOED * * *
 
/ WORD 8: TEMP. ACCUMULATOR FOR HEADER WORD 0.
 
	.REPT 60		/8 REGISTERS PER UNIT.
TTY0	0
	.LOC TTY0
	.BLOCK TTYS*10
 
/ KEYBOARD INPUT RING BUFFER. AS CHARACTERS COME IN FROM THE KEYBOARDS,
/ THEY AND THE DEVICE CODES ARE STORED IN THE BUFFER.
 
KBDGET	KBDRING		/FETCH POINTER.
KBDGT1	KBDRING		/FETCH POINTER.
KBDPUT	KBDRING		/STORE POINTER.
KBDBEG	KBDRING
KBDRING	.BLOCK KBDRSZ
KBDEND	.
 
/ TELEPRINTER RING BUFFER. AS PRINTER FLAGS COME UP INDICATING PRINTER
/ UNIT IS FREE, THE TCF IOT IS STORED IN THE RING BUFFER.
 
TPRGET	TPRRING		/FETCH POINTER.
TPRPUT	TPRRING		/STORE POINTER.
TPRBEG	TPRRING
TPRRING	.BLOCK TTYS
TPREND	.
 
	.EJECT
	.END
