Google
 

Trailing-Edge - PDP-10 Archives - klad_sources - klad.sources/magmon.mac
There are no other files named magmon.mac in the archive.
;[toed.xkl.com]DXX:<KLAD.SOURCES>MAGMON.MAC.2, 18-Apr-96 16:55:49, Edit by GORIN
;Changed code in SELECT to determine the processor type (setting KLFLG)
;Old code used a form of BLT which is indeterminate.

;*MAINDEC-10-MAGMON (DDQDE)

DECVER=014
MCNVER=000

	XLIST
DEFINE	NAME	(MCNVER,DECVER),<

TITLE	MAGMON	[DDQDE] DECSYSTEM DIAGNOSTIC MAGTAPE MONITOR, VERSION MCNVER'.'DECVER >
	LIST
	LALL

NAME	\MCNVER,\DECVER


;*THIS PROGRAM PROVIDES THE PROGRAM LOADING CAPABILITY FOR PDP-10
;*DIAGNOSTICS.  PROVIDES FOR LOADING AND RUNNING SINGLE DIAGNOSTICS OR
;*CHAIN EXECUTION OF A SERIES OF DIAGNOSTICS.

;*THIS PROGRAM WILL EXECUTE PDP-10 DIAGNOSTICS AND RELIABILITY
;*PROGRAMS THAT ARE CAPABLE OF BEING RUN UNATTENDED.
;*RUNS ON KL10, KI10 & KA10 PROCESSORS

;*IT PROVIDES FOR CONTINUOUS TESTING FOR EQUIPMENT CHECKOUT
;*AND/OR FAST ITERATION OPERATION FOR MARGIN TESTING.

;*ALSO PROVIDES SPECIAL USER MODE OPERATION FOR KL10 & KI10
;*AND MARGIN OPERATION FOR KI10.

;*COPYRIGHT 1976,1977,1978,1979,1980
;*DIGITAL EQUIPMENT CORPORATION
;*MARLBORO, MASS. 01752

;*JOHN R. KIRCHOFF

	LOC	137
MCNVER,,DECVER

	NOSYM

;ASSEMBLE AS FOLLOWS
;	MAGMON.MAC,MAGLDR.MAC

INLEND=27770	;COMMAND LIST END ADDRESS
SUBTTL	PARAMETERS

;*ACCUMULATORS

DPNTR=	5				;DISK CMD LIST INPUT POINTER
LET=	6				;LETTERS TYPIN FLAG
NAM=	7				;NAME GENERATION AC'S
NAM1=	10
NAM2=	11
DIGIT=	12				;DIGIT GENERATION AC'S
DIGITA=	13
DIGIT1=	14
DIGIT2=	15
IP=	16				;COMMAND INDEX POINTER
P=	17				;PUSHDOWN POINTER

LDCHN=	16				;USER LOAD CHANNEL

;*COMMAND DEFINITIONS

JOBSA=	120				;JOB STARTING ADDRESS
JOBFF=	121				;JOB FIRST FREE ADDRESS
JOBREL=	44				;JOB HIGHEST RELATIVE ADDRESS
FSELNK=	27772				;FILE SELECT LINK
FRDLNK=	27773				;FILE READ LINK
LDLNK=	27774				;LOAD LINK
DDTLNK=	27775				;DDT LINK
MODLNK=	27776				;MODE CHECK LINK
SUBLNK=	27777				;SUBROUTINE LINK

CHNCMD=	476				;CHANNEL COMMAND LIST

OPDEF	GO	[PUSHJ	P,0]
OPDEF	RTN	[POPJ	P,]
OPDEF	PUT	[PUSH	P,0]
OPDEF	GET	[POP	P,0]
OPDEF	PNTMSG	[GO	$PSIX]
OPDEF	PNTAL	[GO	TOUT]
OPDEF	TTICHR	[GO	TTYIN]
OPDEF	TTIOCT	[GO	TTYOCT]
OPDEF	SWITCH	[GO	$SWITCH]
;*DIAGNOSTIC SPECIAL ADDRESSES

SUBRTN=	1005				;"SUBRTN" IDENTIFICATION WORD
DIAGNOS=30000				;DIAGNOSTIC START ADDRESS
DIAGMN=	30002				;PROG START ADDRESS
RETURN=	30012				;RETURN ADR STORAGE
$EMODE=	30031				;EXEC ALLOWED
$UMODE=	30032				;USER ALLOWED
ITRCNT=	30024				;PROG ITERATIONS
MONCTL=	30043				;DIAG MON CONTROL FLAG
RANDBS=	30022				;PROG RANDOM BASE
MONFLG=	30042				;SPECIAL USER CONTROL FLAG
MONTEN=	30044				;LOADED BY DIAMON FLAG
MARGIN=	30055				;KI10 MARGIN WORD
KLDDT=	10000				;KLDDT PROGRAM START ADDRESS

.LOC=	20000				;STARTING ADDRESS

;*SPECIAL DIAGNOSTIC START ADDRESSES

SFSTRT=	30004				;SPECIAL FEATURE START
PFSTRT=	30005				;POWER FAIL RESTART
REENTR=	30006				;PROGRAM REENTER START
DDT=	30007				;DDT START
START1=	30013				;START 1
START2=	30014				;START 2
START3=	30015				;START 3
START4=	30016				;START 4
START5=	30017				;START 5
;*DTE20 EPT PARAMETERS

$STD=	440				;PDP-10 DIAGNOSTIC START ADDRESS
$DDT=	441				;PDP-10 DDT START ADDRESS
$STL=	442				;PDP-10 LOADER START ADDRESS
$STM=	443				;PDP-10 MONITOR START ADDRESS

$DTFLG=	444				;OPERATION COMPLETE FLAG
$DTCLK=	445				;CLOCK INTERRUPT FLAG
$DTCI=	446				;CLOCK INTERRUPT INSTRUCTION
$DTT11=	447				;10 TO 11 ARGUMENT
$DTF11=	450				;10 FROM 11 ARGUMENT
$DTCMD=	451				;TO 11 COMMAND WORD
$DTSEQ=	452				;OPERATION SEQUENCE NUMBER
$DTOPR=	453				;OPERATIONAL DTE #
$DTCHR=	454				;LAST TYPED CHARACTER
$DTMTD=	455				;MONITOR TTY OUTPUT COMPLETE FLAG
$DTMTI=	456				;MONITOR TTY INPUT FLAG
$DTSWR=	457				;10 SWITCH REGISTER

	LOC	442
JRST	START

;*PROCESSOR CONTROL BITS

IOCLR=	200000				;APR, I/O CLEAR
PICLR=	10000				;PI, PI CLEAR
USERF=	10000				;USER MODE FLAG

TRPENB=	020000				;ENABLE TRAPS
USERF=	10000				;USER MODE FLAG
PAG=	010				;PAGING I/O DEVICE CODE
MUUO=	424				;MUUO STORAGE
MUUOPC=	425				;C(PC) OF MUUO STORAGE
UPMP=	17000				;USER PAGE MAP PAGE
;*KL10 PROCESSOR BIT ASSIGNMENTS

DTE=	200				;DTE20 DEVICE CODE
LLDUSB=	140000				;LOAD KL10 USER BASE REGISTER

;*KI10 PROCESSOR BIT ASSIGNMENTS

LDEXCB=	400000				;LOAD EXEC BASE REGISTER
LDUSRB=	400000				;LOAD USER BASE REGISTER
SMLUSR=	040000				;SMALL USER
USRCMP=	020000				;USER COMPARE
IMGNOF=	2000				;VOLTAGE MARGINS OFF
IMGNON=	1000				;VOLTAGE MARGINS ON
ISPDOF=	10000				;SPEED MARGINS OFF
IMGINM=	2000				;MARGIN SWITCH
ISPDON=	4000				;SPEED MARGINS ON
VOLT5=	31				;MARGIN 5 VOLT SETTING
VOLTLM=	^D12				;MARGIN +- LIMITS

;*SWITCH ASSIGNMENTS, RH SW'S NOT USED BY CALLED PROG

LPTSW=	20000				;SW 4, PRINT ON LPT
RELIAB=	400				;SW 9, RELIABILITY MODE
CHAIN=	4				;SW 15, INHIBIT PROGRAM TITLE PRINT

XPAND=	400000				;SW 18, EXPANDED CONTROL SEQUENCING

DEFINE	MSG	(ARG),<[SIXBIT\ARG'_\]>

DEFINE	PMSG	(ARG),<
	MOVEI	[SIXBIT\ARG'_\]
	PNTMSG>
SUBTTL	CONTROL SECTION

	LOC	.LOC

;*START - STARTING ADDRESS AND CONTROL FLAGS

START:	JRST	SELECT
RESTRT:	JRST	RUN
TITLE:	JRST	WHAT
RERUN:	JRST	RERUN1
ONETIM:	JRST	ONETM1
ITERAT:	0
USER:	0
CONSW:	0				;USER MODE SWITCHES
KLFLG:	0
KAIFLG:	0
SUSERF:	0
PASS:	0
ONCE:	0
RANBAS:	0
TTYSPD:	0				;TTY BAUD RATE

;*ONETM1 - STARTUP & PROCESSOR TYPE DETERMINATION

ONETM1:	MOVE	JOBREL			;SAVE "DIAMON" MAX SIZE
	MOVEM	SVJBREL#
;*SELECT - START/RESTART INITIALIZATION

SELECT:	SETZM	USER
	JSP	0,.+1
	TLNE	0,USERF
	SETOM	USER			;USER MODE
	SKIPE	USER
	JRST	.+3
	CONO	PI,PICLR
	CONO	APR,IOCLR
	MOVE	P,[-40,,PLIST]
	SETZM	KLFLG
	SETZM	KAIFLG
	SETZ	1,			;[REG] Source 0, Destination 0
	BLT	1,0			;[REG] Copy 1 word from 0 to 0
	SKIPE	1,			;[REG] BLT changes AC on KL10
	SETOM	KLFLG
	MOVNI	1,1
	AOBJN	1,.+1
	SKIPN	1			;KA10 IF (AC) = 1,,0
	SETOM	KAIFLG			;KI10 IF (AC) = 0,,0
	SKIPE	KLFLG
	GO	DTEINT			;KL10, INIT DTE20
	SKIPE	USER
	GO	USRINT			;USER INITIALIZATION
	MOVE	PGNAME
	SKIPE	USER
	SETNAM				;USER, SET NAME BACK
	SKIPE	ONCE
	JRST	SELX			;NOT FIRST TIME
	SKIPN	KLFLG
	GO	TYBAUD			;KA/KI, COMPUTE BAUD RATE
	MOVEI	HEADER
	PNTAL				;PRINT HEADER
	GO	DEVSEL			;SELECT LOAD DEVICE
;*SELX - DIAMON LINKAGE SETUP

SELX:	MOVEI	30001			;SETUP $START AS
	MOVEM	27774			;LOAD LINK
	MOVEI	FSELECT			;SETUP FILE SELECT LINK
	MOVEM	FSELNK
	MOVEI	FREAD			;SETUP FILE READ LINK
	MOVEM	FRDLNK
	SETZM	PGMGO
	MOVE	[PGMGO,,PGMGO+1]
	BLT	RACKF
	MOVE	[SIXBIT/SUBRTN/]
	CAMN	SUBRTN			;IS "SUBRTN" LOADED ?
	JRST	SELX1			;YES
;*AUTOMATICALLY LOAD REQUIRED "SUBRTN" AND "KLDDT"
;*	USER - LOAD "SUBUSR" AND "KLDDT"
;*	EXEC - KL10 - LOAD "SUBKL" AND "KLDDT"
;*	EXEC - KA/KI - LOAD "SUBRTN" AND "KLDDT"

	SKIPN	USER
	JRST	SELX4			;EXEC
	MOVEI	IP,[SIXBIT/SUBUSR/
		    0]
	GO	DIAGLD-5		;DON'T REPORT CAN'T FIND
	JRST	SELX3			;TRY "SUBRTN" THEN
	JRST	SELX2
SELX4:	SKIPN	KLFLG
	JRST	SELX3			;NOT KL-10
	MOVEI	IP,[SIXBIT/SUBKL/
		    0]
	GO	DIAGLD-5		;DON'T REPORT CAN'T FIND
	JRST	.+2			;TRY "SUBRTN" THEN
	JRST	SELX2
SELX3:	MOVEI	IP,[SIXBIT/SUBRTN/
		    0]
	GO	DIAGLD-2		;NO, LOAD IT THEN
	JRST	SELX1			;CAN'T FIND, ALREADY REPORTED
SELX2:	MOVEI	IP,[SIXBIT/KLDDT/
		    0]
	GO	DIAGLD-2		;LOAD DDT ALSO
	JRST	SELX1
	MOVEI	$DDT
	MOVEM	74			;SET DDT START ADDRESS
	SKIPE	USER
	SETDDT				;SET USER DDT START ADDRESS
;*PROCESS OPERATOR COMMAND

SELX1:	SETOM	ONCE
	MOVE	P,[-40,,PLIST]
	MOVEI	IP,SELSTR
	GO	CRLF1			;TYPE A CARRIAGE AND LINE FEED
	MOVE	A,PGNAME		;GET PROGRAM NAME
	GO	SIXBP			;PRINT IT
	PMSG	< CMD - >
	GO	FLNAME			;GET COMMAND OR FILE NAME
	JFCL
	MOVEI	IP,SELSTR
	SETZM	1
	MOVE	(IP)

CMDLP:	SKIPN	CMDLST(1)		;CHECK FOR SPECIAL COMMANDS
	AOJA	1,CMDLP1		;NOT IN FIRST PART OF LIST
	CAMN	CMDLST(1)
	JRST	CMDEX			;FOUND
	AOJA	1,CMDLP

CMDEX:	MOVE	0,CMDADR(1)		;GET START ADDRESS
	JRST	@0			;GO TO COMMAND ROUTINE

CMDLP1:	SKIPN	CMDLST(1)		;SPECIAL START COMMANDS
	JRST	RUNPR2			;NOT FOUND, MUST BE PROGRAM NAME
	CAMN	CMDLST(1)
	JRST	CMDEX1			;FOUND
	AOJA	1,CMDLP1

CMDEX1:	MOVE	0,CMDADR(1)		;GET SPECIAL START ADDRESS
	HRRM	SADR			;SET FOR START
	JRST	SADRQ			;GO START
SUBTTL	RUNPRG - RETRIEVE AND RUN SINGLE PROGRAM

RUNPRG:	PMSG	<^FILE.EXT - >
	MOVEI	IP,INLIST
	GO	FLNAME			;GET FILE NAME
	JFCL
RUNPR1:	MOVEI	IP,INLIST
	HLRZ	(IP)
	CAIN	(SIXBIT/G/)
	JRST	SADRQ
	SKIPN	(IP)
	JRST	EX4			;NO PROGRAM TO RUN
	MOVEM	IP,SAVEIP
	SETOM	PGMGO			;SET LOAD & GO FLAG
	GO	DIAGLD			;GO GET PROGRAM
	JRST	.+2
	JRST	DEVCM1			;MUST BE DEVICE COMMAND LIST
	SKIPN	ALTMFLG			;ALTMODE SELECTION ?
	JRST	SELECT			;NO, ERROR
	SETZM	ALTMFLG
	JRST	RUNPRG			;YES, ASK FOR NEXT PROGRAM

RUNPR2:	MOVE	SELSTR
	MOVEM	INLIST
	MOVE	SELSTR+1
	MOVEM	INLIST+1
	SETZM	INLIST+3
	JRST	RUNPR1

TT2CHR:	TTICHR				;INPUT 1ST CHAR
	CAIN	12
	RTN				;ONLY A CR
	MOVEM	0,LET
	TTICHR				;INPUT 2ND CHAR, SHOULD BE CR
	CAIE	12
	JRST	SELECT			;WASN'T
	MOVE	0,LET			;GET 1ST CHAR BACK
	JRST	CPOPJ1			;SKIP RETURN

SELXR:	GO	DEVSEL			;SELECT DEVICE
	JRST	SELX

CMDLST:	SIXBIT/H/
	SIXBIT/I/
	SIXBIT/T/
	SIXBIT/D/
	SIXBIT/S/
	SIXBIT/F/
	SIXBIT/L/
	SIXBIT/G/
	SIXBIT/X/
	SIXBIT/R/
	0
	SIXBIT/STD/
	SIXBIT/STL/
	SIXBIT/STM/
	SIXBIT/DDT/
	SIXBIT/START/
	SIXBIT/SFSTRT/
	SIXBIT/PFSTRT/
	SIXBIT/REE/
	SIXBIT/START1/
	SIXBIT/START2/
	SIXBIT/START3/
	SIXBIT/START4/
	SIXBIT/START5/
	0

CMDADR:	CMDHLP
	STORED
	TTYCMD
	DEVCMD
	RUNPRG
	DIRECT
	LIST1
	SADRQ
	SAXPN
	SELXR
	0
	$STD
	$STL
	$STM
	$DDT
	DIAGNOS
	SFSTRT
	PFSTRT
	REENTR
	START1
	START2
	START3
	START4
	START5
;*WHAT - IDENTIFY LAST PROGRAM

WHAT:	MOVE	P,[-40,,PLIST]
	GO	CRLF1
	MOVE	IP,SAVEIP
	GO	NAMPNT			;PRINT TITLE OF LAST PROGRAM
	JRST	START

;*NAMPNT - PRINT FILE NAME AND EXTENSION

NAMPNT:	MOVE	A,(IP)
	GO	SIXBP
	MOVEI	"."
	GO	PRINT
	HLLZ	A,1(IP)
	GO	SIXBP
	GO	CRLF1
	RTN

;*SIXBP - SIX BIT PRINTER

SIXBP:	MOVEI	B,0			;SO DON'T SHIFT IN JUNK
	SETZM	F
	LSHC	F,6			;GET A SIXBIT CHAR
	ADDI	F,40			;MAKE IT ASCII
	GO	PRINT			;TYPE IT
	JUMPN	A,SIXBP			;IF ANY MORE, TYPE THEM
CPOPJ:	RTN

;*PNT16 - PRINT ASCII CHAR IN AC16

PNT16:	PUT	0
	MOVE	0,16
	GO	PRINT
	GET	0
	RTN

;*CMDHLP, PRINT HELP TEXT

CMDHLP:	SKIPE	HLPCLR#			;HAS HELP BEEN OVERWRITTEN ?
	JRST	.+4			;YES
	MOVEI	HELP			;PRINT HELP
	PNTAL
	JRST	START
	PMSG	<NO HELP>
	JRST	START
SUBTTL	COMMAND LIST PROCESSING

;*STORED - USE INTERNAL COMMAND LIST

STORED:	SETZM	LPTFLG
	GO	CXPND			;SETUP EXPANDED OPERATIONS
	JRST	EX

;*TTYCMD - TELETYPE INPUT COMMAND LIST

TTYCMD:	PMSG	<^NAME]PASSES]RH SWS]ITERATIONS^>
CMNCMD:	MOVEI	IP,INLIST
	GO	FLNAME
	JRST	.-1			;INPUT TILL ^Z
	JRST	STORED

;*DEVCMD - DEVICE COMMAND LIST

DEVCMD:	SETOM	DEVFLG			;SET DEVICE CMD LIST FLAG
	JRST	RUNPRG			;GET COMMAND FILE

DEVCM1:	SETZM	DEVFLG			;CLEAR DEVICE CMD LIST FLAG
	SETOM	DINFLG			;SET "READ" FOR DEVICE IN
	SETZM	PGMGO			;CLEAR FOR COMMAND OPERATION
	MOVE	DPNTR,[POINT 7,31000]
	JRST	CMNCMD			;GO RUN COMMAND LIST

DEVCM2:	MOVE	13,[POINT 7,31000]
	GO	LDACHR			;READ A CHAR
	JRST	.+3			;EOF
	IDPB	16,13
	JRST	.-3
	MOVEI	16,177			;FLAG END OF INPUT
	IDPB	16,13
	GO	STOP			;STOP DEVICE
CPOPJ1:	AOS	(P)			;DONE, RETURN TO "DEVCM1"
	RTN

DEVRD:	ILDB	0,DPNTR			;GET CHARS FROM 31000 UP
	JUMPE	0,.-1			;IGNORE NULLS
	CAIN	0,177
	JRST	CPOPJ1			;177 BYTE SIGNIFIES END
	JRST	READ1			;FOR "READ"
SUBTTL	FLNAME - FILE NAME AND CONTROL INFO INPUT

FLNAME:	SETZM	SCFLAG
	SETZM	SUSERF
	TLO	LET,400000		;SET LETTERS FLAG
	SETZ	NAM1,			;CLEAR CONTROLS
	SETZB	NAM,DIGIT
	MOVEI	NAM2,^D30		;SETUP CHAR POSITIONING

;*FLNMLP - INPUT AND PROCESS CHARACTERS

FLNMLP:	GO	READ
	CAIN	32
	JRST	CPOPJ1			;^Z, LOGICAL END OF INPUT
	CAIN	12
	JRST	CRRTN			;CR, (ACTUALLY LF) COMPLETES LINE
	SKIPE	SCFLAG
	JRST	FLNMLP			;<;> TYPED, IGNORE REST OF LINE
	CAIN	73
	JRST	SCSET			;<;>
	CAIN	177
	JRST	RBOUT			;RUBOUT
	CAIN	55			;MINUS IS SPECIAL USER MODE FLAG
	JRST	MINUS
	CAIN	11
	JRST	TTAB			;TAB IS FIELD SEPARATOR
	JUMPE	FLNMLP			;REJECT 0'S
	JUMPGE	LET,FLNAM2		;JUMP IF ASSEMBLE DIGITS

;*FLNAM1 - FILE NAME PROCESS

FLNAM1:	CAIN	56
	JRST	PERIOD			;DOT, NAME.EXT SEPARATOR
	SUBI	40			;CONVERT TO 6BIT
	JUMPL	RBOUT			;CNTL CHAR, TREAT AS RUBOUT
	JUMPE	RBOUT			;0 IS ERROR
	LSH	0,(NAM2)		;POSITION CHAR
	IOR	NAM,0			;MERGE INTO NAME
	SUBI	NAM2,6			;CHANGE POSITIONING FOR NEXT
	JRST	FLNMLP			;GET NEXT CHAR
;*PERIOD - STORE FILE NAME, GO PROCESS EXTENSION

PERIOD:	MOVEM	NAM,NAM1		;SAVE FILE NAME
	JRST	FLNAME+4		;PROCESS EXTENTION

;*FLNAM2 - PROCESS DIGITS

FLNAM2:	MOVE	DIGITA,0
	LSH	DIGITA,^D33
	LSHC	DIGIT,3			;ASSEMBLE DIGITS
	JRST	FLNMLP

;*TTAB - FIELD SEPARATOR, STORE PREVIOUS FIELD

TTAB:	MOVEM	DIGIT1,DIGIT2
	MOVEM	DIGIT,DIGIT1
	SETZB	LET,DIGIT
	JRST	FLNMLP-1

;*MINUS - SET SPECIAL USER MODE

MINUS:	SETOM	SUSERF			;MINUS, SET SPECIAL USER FLAG
	JRST	FLNAME+3

;*SCSET - SEMICOLON, REST IS COMMENT

SCSET:	SETOM	SCFLAG
	JRST	FLNMLP

;*ZEROAC - ZERO AC'S BEFORE STARTING PROGRAM

ZEROAC:	MOVSI	16,-16
	SETZM	0(16)
	AOBJN	16,.-1
	SETZM	16
	RTN

RBOUT:	PMSG	<XXX^>
	JRST	FLNAME
;*COMMAND LIST FORMAT
;*	NAME
;*	EXT,,ITERATIONS	(BIT 18 SET IF SPEC USER)
;*	PASSES,,SWITCHES

;*CRRTN - CR, STORE COMMAND LIST INFORMATION

CRRTN:	SETZM	SCFLAG
	SKIPN	NAM
	JUMPE	NAM1,FLNAME		;REPEAT IF JUST CR
	SKIPN	NAM1			;NAME ONLY ?
	EXCH	NAM,NAM1		;YES
	MOVEM	NAM1,(IP)		;STORE THE FILE NAME
	HLLZM	NAM,1(IP)		;AND EXTENSION
	TRZ	DIGIT,400000
	SKIPE	SUSERF
	TRO	DIGIT,400000		;SET SPEC USER BIT
	HRRM	DIGIT,1(IP)		;ITERATIONS (IF SPEC USER BIT 18 SET)
	HRL	DIGIT1,DIGIT2		;PASSES,,SWITCHES
	MOVEM	DIGIT1,2(IP)
	ADDI	IP,3			;INCREMENT POINTER
CRRTN1:	SETZM	(IP)			;CLEAR LAST WORD
	CAIL	IP,HELP			;OVERWITTEN HELP MESSAGE ?
	SETOM	HLPCLR			;YES, NO MORE HELP AVAILABLE
	CAIGE	IP,INLEND
	RTN

FULL:	PMSG	<^CMDLST TOO LONG>
	JRST	START

EXNOE:	PMSG	<^USER ONLY>
	JRST	EXBAD

EXNOU:	PMSG	<^EXEC ONLY>

EXBAD:	MOVEI	0,1			;SET CMD LIST PASS COUNT TO INHIBIT
	HRLM	0,2(IP)			;FURTHER REQUEST OF THIS PROGRAM
	PMSG	<^UNCHAINABLE->
	GO	NAMPNT			;INCORRECT FORMAT
	JRST	RET
SUBTTL	EXECUTE THE INPUT COMMAND LIST

;*EX - INITIALIZATION

EX:	SETZM	PASS
	GO	CRLF1
	SKIPE	USER
	GO	LHSWS			;GET LH CONTROL SWITCHES
EX5:	SETZM	RUNCTL
	MOVEI	IP,INLIST		;INIT LIST POINTER
	AOS	PASS

;*EX1 - START PASS

EX1:	MOVEM	IP,SAVEIP
	SETZM	SUSERF
	SKIPN	(IP)
	JRST	EX4			;NO PROGRAMS TO RUN
	HLRZ	1,2(IP)			;GET PASSES TO RUN
	JUMPE	1,.+3			;0, RUN ALWAYS
	CAMGE	1,PASS			;RUN FOR REQUESTED PASSES
	JRST	RET
	MOVE	1(IP)			;PROG RUN IN SPECIAL
	TRNE	400000
	SETOM	SUSERF			;USER MODE ?

;*EX2 - PRINT NAME AND LOAD PROGRAM

EX2:	SWITCH				;READ SWITCHES
	TLNN	0,CHAIN			;INHIBIT TITLE PRINT ?
	GO	NAMPNT
	GO	DIAGLD-2		;GET THE PROGRAM
	JRST	RET			;PROGRAM NOT FOUND

;*EX3 - SETUP PROGRAM OPERATION PARAMETERS

EX3:	MOVE	IP,SAVEIP
	HRRZ	1,1(IP)			;GET THE ITERATION COUNT
	TRZ	1,400000		;CLEAR SPEC USER, IF SET
	SWITCH				;READ SWITCHES
	TLNN	0,RELIAB		;RELIABILITY MODE ?
	LSH	1,-6			;NO, 100(8):1 REDUCTION
	SKIPN	1
	ADDI	1,1			;ALWAYS ALLOW 1 ITERATION
	MOVEM	1,ITERAT
	MOVN	PASS
	HRL	2(IP)			;SETUP MONITR CONTROL
	MOVE	1,30002
	CAME	1,[JRST	@27774]
	JRST	EXBAD			;INCORRECT FORMAT
	SKIPE	USER			;IN USER MODE ?
	JRST	EXUSR			;YES
EXEXEC:	SKIPE	$EMODE			;EXEC, THIS PROG RUN IN EXEC ?
	JRST	EXNEW			;YES
	JRST	EXNOE			;NO
EXUSR:	SKIPE	$UMODE			;USER, THIS PROGRAM RUN IN USER ?
	JRST	EXNEW			;YES
	JRST	EXNOU			;NO

EXNEW:	SETOM	RUNCTL
	MOVSM	MONCTL			;LH = -PASS COUNT, RH = RH SWITCHES
	MOVE	0,RANBAS		;GENERATE PROG RANDOM BASE NUMBER
	ADD	0,[165742335216]
	ROT	0,-1
	EQVB	0,RANBAS
	MOVEM	0,RANDBS		;PUT IN PROG DATA AREA

;*RERUN1 - DISPATCH TO EXPANDED SETUP

RERUN1:	JRST	XPNRUN

;*RUN - PROGRAM RUN, CLEAR PROCESSOR FOR NEXT

RUN:	SKIPE	USER
	JRST	.+3
	CONO	PI,PICLR
	CONO	APR,IOCLR
	MOVE	P,[-40,,PLIST]
	MOVE	IP,SAVEIP
	SKIPE	KLFLG			;CHECK IF KL10
	GO	DTEINT			;CLEAR DTE

;*RET - ANY MORE PROGRAMS ON COMMAND LIST

RET:	ADDI	IP,3			;INCREMENT POINTER TO NEXT COMMAND
	SKIPE	(IP)
	JRST	EX1			;RUN NEXT PROGRAM
	SKIPN	RUNCTL			;ANY PROGRAMS RUN THIS PASS ?
	JRST	EX4			;NO
	GO	CRLF1			;PRINT A CARRIAGE RETURN AND LINE FEED
	MOVE	A,PGNAME		;GET PROGRAM NAME
	GO	SIXBP			;PRINT IT
	PMSG	< PASS >
	MOVE	PASS			;PRINT PASS COUNTER
	GO	PNTDEC
	GO	CRLF1
	JRST	EX5

;*EX4 - ALL FINISHED

EX4:	PMSG	<^CMD'S REQUIRED>
	JRST	SELECT
SUBTTL	EXPANDED COMMAND FORMAT SETUP

;*CXPND - EXPANDED ALLOWED

CXPND:	SKIPE	USER
	RTN				;NO EXPANDED FEATURES IN USER MODE
	SKIPN	KLFLG
	SKIPE	KAIFLG
	JRST	CXPND1			;EXEC KL10 OR KI10
	RTN				;NO FEATURES FOR KA10

CXPND1:	SWITCH
	TRNN	XPAND			;ALLOW EXPANDED FEATURES ?
	RTN				;NO

;*STRD2 - CLOCK MARGINS

STRD2:	SKIPE	KLFLG
	JRST	STRD3
	PMSG	<^Y FOR CLOCK MARGINS - >
	GO	TT2CHR
	JRST	STRD3			;CR, NO CLOCK MARGINS
	CAIN	"Y"
	SETOB	0,CLKFLG		;IF Y SET FLAG
	JUMPGE	0,STRD2+2		;OTHER IS GOOF

;*STRD3 - SPECIAL USER MODE

STRD3:	PMSG	<^Y OR A FOR SPECIAL USER MODE - >
	GO	TT2CHR
	JRST	STRD4			;CR, NO SPECIAL USER
	CAIN	"Y"
	SETOB	0,USRFLG		;IF Y SET FLAG
	CAIN	"A"			;A, USER AFTER 1ST PASS
	JRST	STRD3A
	JUMPGE	0,STRD3			;OTHER IS GOOF
;*STRD4 - CONCEALED, PUBLIC OR ALTERNATE

STRD4:	SKIPN	USRFLG
	JRST	STRD5
	PMSG	<^C=CONCEALED,P=PUBLIC,A=ALTERNATE->
	GO	TT2CHR
	JRST	STRD4+2			;CR ONLY, ERROR
	CAIN	"C"
	SETOB	0,CNSFLG		;IF C SET FLAG
	CAIN	"A"			;A, ALTERNATE PUBLIC
	JRST	STRD4A			;& CONCEAL
	CAIN	"P"
	SETOM	0			;P, RUN PUBLIC
	JUMPGE	0,STRD4+2		;OTHER IS GOOF
	JRST	STRD5

STRD3A:	MOVEM	0,USRFLG		;USRFLG + ='S
	JRST	STRD4			;SPECIAL USER AFTER 1ST PASS

STRD4A:	MOVEM	0,CNSFLG		;CNSFLG + ='S
	JRST	STRD5			;ALTERNATE PUBLIC & CONCEAL
;*STRD5 - VOLTAGE MARGINS

STRD5:	SKIPE	KLFLG
	JRST	STRD7
	SETZB	1,2
	PMSG	<^L,S,I,R FOR VOLTAGE MARGINS->
	GO	TT2CHR			;TELETYPE INPUT
	JRST	STRD5C			;CR, NO MARGINS
	CAIN	"L"
	TRO	1,1			;L-LIMITS
	CAIN	"S"
	TRO	1,2			;S-SWEPT
	CAIN	"I"
	TRO	1,4			;I-SPECIFY INCREMENT
	CAIN	"R"
	TRO	1,10			;R-SPECIFY RACK
STRD5C:	MOVEM	1,MGNFLG#
	MOVEI	2,VOLTLM		;L- 31+-12, 4.75 TO 5.25V
	TRNN	1,1
	MOVEI	2,1			;V- MARGIN INCREMENT = 1
STRD5A:	MOVEM	2,MGNINC#
	TRZN	1,4			;SPECIFY INCREMENT ?
	JRST	STRD6			;NO
	PMSG	<^MARGIN INCREMENT(1 TO 17)->
	TTIOCT
	JRST	STRD5A+3
	JUMPE	DIGIT,STRD5A+3		;INPUT COMPLETE
	CAIL	0,20			;LIMIT TO 1-20
	JRST	STRD5A+3
	MOVE	2,0
	JRST	STRD5A			;SAVE
STRD6:	TRNN	1,10			;SPECIFY RACK ?
	JRST	STRD7			;NO
	PMSG	<^RACK(0 TO 37)->
	TTIOCT
	JRST	STRD6+2
	CAIL	0,40			;LIMIT TO 0-37
	JRST	STRD6+2
	MOVEM	0,MGNADR
	SETOM	RACKF			;SET RACK SELECTED FLAG
STRD7:	SKIPN	MGNFLG			;MARGINS ?
	JRST	STRD8			;NO
	MOVEI	MGNMSG
	PNTMSG
	TTICHR
	CONI	APR,0			;READ STATUS
	TLNN	0,IMGINM
	JRST	STRD7			;MARGIN ENABLE NOT SET !

STRD8:	RTN

MGNMSG:	SIXBIT\^SET MARGIN SELECT OFF^SET MARGIN ENABLE^TYPE CR WHEN READY^_\

;*MUUOER & USRERR - USER ERROR REPORTING

MUUOER:	MOVEI	MSG	<^MUUO ERROR^>
	JRST	.+3

USRERR:	0
	MOVEI	MSG	<^USER TRAP ERROR^>
	PNTMSG
	HALT	START
SUBTTL	SPECIAL RUN SEQUENCING

;*XPNRUN - DETERMINE AND SETUP FOR SPECIAL OPERATIONS

XPNRUN:	SETZM	MGNWRD
	SETZM	MGNCNT
	SKIPN	RACKF
	SETZM	MGNADR
	SETZM	MRGNF#
	MOVE	ITERAT
	MOVEM	MGNITR#
	MOVEM	USRITR#
	SKIPE	MGNFLG			;VOLTAGE MARGIN ?
	JRST	MRGNCK			;YES
XPNRN1:	SKIPE	USER
	JRST	XPNRN2			;USER MODE
	MOVE	0,MGNWRD
	SKIPE	CLKFLG			;CLOCK MARGINS ?
	TRO	0,ISPDON		;YES, SET CLOCK MARGIN BIT
	MOVEM	0,MARGIN
	SKIPN	KLFLG
	DATAO	APR,MARGIN		;OUTPUT TO MARGIN SYSTEM
	SKIPE	MRGNF			;MARGINS ?
	DATAO	PI,MGNITR		;YES, DISPLAY MARGIN ITERATIONS
	SKIPE	USRFLG
	JRST	USRRUN			;SPECIAL USER MODE OPERATION
XPNRN2:	MOVE	0,ITERAT
	MOVEM	0,ITRCNT
	MOVEI	USSR2
	MOVEM	RETURN
XPNRN3:	GO	ZEROAC
	SETZM	17
	JRST	DIAGMN			;GO TO PROGRAM
;*USRRUN - SPECIAL USER MODE RUN SEQUENCING

USRRUN:	SKIPN	SUSERF			;ALLOW SPECIAL USER ?
	JRST	XPNRN2			;NO, RUN IN EXEC
	SKIPE	KLFLG
	JRST	.+3			;KL10
	SKIPN	MRGNF			;MARGINNING ?
	DATAO	PI,USRITR		;NO, DISPLAY USER ITERATIONS
	MOVEI	1
	MOVEM	ITERAT			;RETURN TO DIAMON AFTER EACH PASS
	SKIPG	USRFLG			;USRFLG - ='S RUN ALL
	JRST	.+4			;PASSES
	MOVE	2,PASS			;USRFLG + AND PASS 1 ='S
	CAIN	2,1			;RUN IN EXEC MODE
	JRST	XPNRN2
	MOVE	ITERAT
	MOVEM	ITRCNT
	SETZM	MONFLG			;CLEAR MONFLG
	MOVSI	1,-400			;SETUP USER PAGE MAP
	MOVE	0,[757776,,757777]
	SKIPE	CNSFLG			;IF CONCEAL, DON'T SET PUBLIC
	MOVE	0,[557776,,557777]
	SKIPG	CNSFLG			;CNSFLG + ='S
	JRST	.+4			;ALTERNATE PUBLIC & CONCEALED
	MOVE	2,PASS
	TRNE	2,1			;ODD/EVEN PASS ?
	MOVE	0,[757776,,757777]
;*SETUP PAGE MAP AND TRAPS

	ADD	0,[2,,2]
	MOVEM	0,UPMP(1)
	AOBJN	1,.-2
	MOVE	0,[UPMP+160,,UPMP+400]	;SET EPPM SAME AS USER 340-377
	BLT	0,UPMP+417
	MOVE	0,[JSR USRERR]
	MOVEM	0,UPMP+420
	MOVEM	0,UPMP+422
	MOVEM	0,UPMP+423
	MOVSI	0,(JFCL)
	MOVEM	0,UPMP+421
	MOVEI	0,MUUOER
	MOVEM	0,UPMP+430
	MOVEM	0,UPMP+431
	MOVEM	0,UPMP+432
	MOVEM	0,UPMP+433
	MOVEI	0,MUUOH			;SETUP FOR HANDLER
	MOVEM	0,UPMP+434
	MOVEM	0,UPMP+435
	MOVEM	0,UPMP+436
	MOVEM	0,UPMP+437
	SKIPE	KLFLG
	GO	PAGKL			;KL10
	DATAO	PAG,[LDUSRB!USRCMP!<UPMP_-^D9>,,LDEXCB!TRPENB]
	JRSTF	@.+1
	USERF,,.+1			;ENTER USER MODE
	JRST	1,.+1			;ENTRY
	MOVEI	USSR1
	MOVEM	RETURN
	JRST	XPNRN3			;GO TO PROGRAM

;*USSR1 - PROGRAM COMPLETION CONTROL

USSR1:	77B8				;MUUO 77, RETURN TO EXEC MODE
USSR2:	MOVE	P,[-40,,PLIST]		;RESTORE STACK
	SKIPE	USER
	JRST	RESTRT			;USER MODE, COMPLETED
	SKIPE	KLFLG
	JRST	USSR3
	DATAO	APR,[IMGNOF,,ISPDOF]	;CLEAR CLOCK & VOLTAGE MARGINS
	DATAO	PAG,[LDUSRB,,LDEXCB]	;CLEAR BASE REGISTER
	SKIPN	MRGNF			;MARGINNING ?
	JRST	USSR4			;NO, CHECK SPECIAL USER
	JRST	MRGIN			;YES, SETUP MARGINS
PAGKL:	MOVEI	0,USRERR+1
	MOVEM	0,UPMP+427
	CONO	PAG,TRPENB
	DATAO	PAG,[LLDUSB,,400000!<UPMP_-^D9>]
	JRST	CPOPJ1

USSR3:	CONO	PAG,TRPENB
	DATAO	PAG,[LLDUSB,,400000]

USSR4:	SKIPE	SUSERF			;RUNNING SPECIAL USER ?
	SOSN	USRITR			;YES, FINISHED USER ITERATIONS ?
	JRST	RESTRT			;FINISHED ALL ITERATIONS
	JRST	XPNRN1			;NOT FINISHED, CONTINUE

MRGNCK:	CONI	APR,0
	TLNE	0,IMGINM		;MARGIN ENABLE SET ?
	JRST	MRGIN			;YES, GO MARGIN
	MOVEI	MSG <^'MARGIN ENABLE' NOT SET ?^>
	SKIPN	MGNONC			;MESSAGE BEEN PRINTED ?
	PNTMSG
	SETOM	MGNONC
	JRST	XPNRN1
SUBTTL	VOLTAGE MARGINNING ROUTINE

MRGIN:	SETOM	MRGNF
	MOVE	1,MGNWRD		;GET PREVIOUS VALUE
	ANDI	1,77
	MOVE	2,MGNINC
	MOVE	MGNCNT
	ANDI	3
	JUMPN	0,VCNT1-2
VCNT0:	MOVEI	0,VOLT5			;MGNCNT=0, INITIALIZE
	HRL	0,MGNADR		;APR DATAO WORD
	TLO	0,IMGNON
	MOVEM	0,MGNWRD
	MOVE	0,MGNADR
	SKIPN	RACKF			;RACK SPECIFIED ?
	AOS	0			;NO, INC MARGIN ADDRESS
	ANDI	0,37
	MOVEM	0,MGNADR
	AOS	MGNCNT
	MOVEI	0,1
	MOVEM	ITERAT			;PROG, 1 PASS PER VALUE
	JRST	XPNRN1			;GO RUN
	CAIE	0,1
	JRST	VCNT2-2
VCNT1:	CAIG	1,VOLT5-VOLTLM		;MGNCNT=1, MARGIN POSITIVE
	JRST	.+4			;COMPLETED SWING !
MGNGO2:	MOVN	2,2			;NEGATE INCREMENT FOR
	ADDM	2,MGNWRD		;CORRECT VALUE CHANGE
	JRST	XPNRN1
MGNGO:	AOS	MGNCNT			;CHANGE COUNTER
	JRST	MRGIN
	CAIE	0,2
	JRST	VCNT3
VCNT2:	CAIL	1,VOLT5+VOLTLM		;MGNCNT=2, MARGIN NEGATIVE
	JRST	MGNGO			;COMPLETED SWING !
	ADDM	2,MGNWRD		;NO, CHANGE MARGIN VALUE
	JRST	XPNRN1			;GO RUN
VCNT3:	CAIE	1,VOLT5			;MGNCNT=3, BACK TO 5V
	JRST	MGNGO2
MGNGO1:	AOS	MGNCNT
	SKIPE	RACKF			;ONLY ONE RACK ?
	JRST	.+3			;YES
	SKIPE	MGNADR			;CYCLED ALL RACKS ?
	JRST	MRGIN			;NO
	SOSN	MGNITR			;YES, COMPLETED ITERATIONS ?
	JRST	RESTRT			;YES, THIS PROGRAM COMPLETED
	JRST	MRGIN			;NO, MAKE ANOTHER MARGIN PASS
SUBTTL	SPECIAL USER MODE I/O HANDLER

MUUOH:	MOVEM	0,ACS0#			;SAVE AC0 AND AC1
	MOVEM	1,ACS1#
	HLRZ	1,UPMP+MUUO		;GET MUUO INSTRUCTION FIELD
	LSH	1,-^D9
	CAIN	1,257
	JRST	EXC			;IF MAP, DO AS MUUO FOR KL10
	MOVE	1,UPMP+MUUO		;GET MUUO
	JUMPGE	1,JRSTX			;A JRST, JEN OR MUUO
	TLNN	1,077000
	JRST	CPI			;AN I/O TO CP OR PI
CP2:	TLNN	1,200
	JRST	DB			;DATAI, DATAO, OR BLOCK
	TLNE	1,40			;A CONO, CONI, CONSZ, CONSO
	JRST	RL			;CONI
EXC:	MOVE	1,ACS1			;RESTORE AC1
	XCT	UPMP+MUUO		;EXECUTE
	SKIPA
	AOS	UPMP+MUUOPC		;INC RETURN IF CONSO, CONSZ SKIP
EXC1:	MOVEM	1,ACS1			;RESAVE AC1
	SKIPE	KLFLG
	JRST	EXC4
	DATAO	PAG,[LDUSRB!USRCMP!<UPMP_-^D9>,,LDEXCB!TRPENB]
EXC5:	MOVE	1,UPMP+MUUOPC		;SETUP RETURN
	TLO	1,USERF
	HLLM	1,EXC2			;SETUP FLAGS
	HRRM	1,EXC3			;SETUP RETURN PC
	MOVE	1,ACS1			;RESTORE AC1
	JRSTF	@.+1			;RESTORE FLAGS, GO TO USER
EXC2:	0,,.+1
EXC3:	JRST	1,0			;ENTRY

EXC4:	CONI	PAG,1
	TRO	1,TRPENB
	CONO	PAG,(1)
	DATAO	PAG,[LLDUSB,,400000!<UPMP_-^D9>]
	JRST	EXC5
CPI:	TLNN	1,200			;AN I/O TO CP OR PI SYSTEM
	TLNN	1,100
	TLNN	1,140
	JRST	EXC			;CONO, DATAO, BLOCK
	JRST	CP2

DB:	TLON	1,40			;IS IT A BLK I/O ?
	JRST	DB1			;YES
RL:	JRST	EXC			;NO NEED TO RELOCATE

DB1:	HLLM	1,UPMP+MUUO
	BLKO	774,(1)			;UPDATE THE POINTER
	SKIPA				;NO SKIP
	AOS	UPMP+MUUOPC		;INC RETURN FOR SKIP
	JRST	RL

JRSTX:	TLNE	1,700000
	JRST	JRSTX1
	TLC	1,077000
	TLCE	1,077000
	JRST	MUUOER			;INCORRECT MUUO
	JRST	USSR2			;MUUO 77, RETURN TO DIAG MON
JRSTX1:	TLNE	1,200
	HALT	@UPMP+MUUOPC		;HALT, POINTING TO ACTUAL HALT
	JRST	10,.+1			;JEN, DISMISS INTERRUPT
	JRST	EXC1

;*SAXPN - STANDALONE EXPANDED RUNNING
;*	  SPECIAL USER AND/OR MARGINS

SAXPN:	SKIPE	USER
	JRST	SELECT			;ILLEGAL IN USER MODE
	SKIPN	KLFLG
	SKIPE	KAIFLG
	JRST	.+2
	JRST	SELECT			;ILLEGAL ON KA10
	SETOM	ITERAT			;RUN PROGRAM FOREVER
	SWITCH
	HRLI	-1
	MOVEM	MONCTL			;LH = -PASS CNT, RH = RH SWS

	GO	STRD2			;SETUP 	EXPANDED FEATURES

	SKIPE	USRFLG			;IF SPECIAL USER WAS SELECTED
	SETOM	SUSERF			;SET FLAG TO RUN THAT WAY

	JRST	XPNRUN			;GO RUN PROGRAM
SUBTTL	MESSAGE PRINTER

;*PNTMSG - PRINT SIXBIT MESSAGES

$PSIX:	PUT	2
	PUT	3
	PUT	4
	HRRZ	4,0			;MESSAGE ADDRESS

$PSIX1:	MOVEI	3,6			;6 CHARS PER 6BIT WORD
	MOVE	1,(4)			;GET FIRST/NEXT WORD OF MESSAGE

$PSIX2:	SETZ	2,
	ROTC	1,6			;C(AC2)= CHAR TO BE PRINTED
	CAIN	2,77
	JRST	$PSIX5			;"BACKARROW", DONE
	CAIN	2,76
	JRST	$PSIX4			;"UPARROW", CR/LF
	CAIN	2,75
	MOVEI	2,151			;"BRACKET", CHANGE TO TAB
	MOVEI	0,40(2)			;CHANGE TO ASCII
	GO	PRINT			;PRINT CHAR
$PSIX3:	SOJN	3,$PSIX2		;PRINTED ALL CHARS FROM THIS WORD ?
	AOJA	4,$PSIX1		;YES, DO NEXT WORD

$PSIX4:	MOVEI	15
	GO	PRINT			;PRINT CR
	MOVEI	12
	GO	PRINT			;PRINT LF
	JRST	$PSIX3

$PSIX5:	GET	4
	GET	3
	GET	2
	RTN

;*PNTAL - PRINT ASCII MESSAGES

TOUTA:	AOSA	.+2			;INCREMENT MSG ADDRESS
TOUT:	HRRM	0,.+1			;C(0) = ADR OF MSG
	MOVE	1,0			;GET CHARACTERS
	TRO	1,1			;SET FLAG BIT
	LSHC	0,7			;CHAR TO 0
	ANDI	177			;MASK
	SKIPN	0			;IF NULL, EXIT
	RTN
	GO	PRINT			;PRINT C(0)
	CAME	1,[400000,,0]
	JRST	TOUT+3			;GET NEXT CHAR IN WORD
	JRST	TOUTA			;GET NEXT WORD
;*PNTOCT - PRINT OCTAL NUMBERS

PNTOCT:	MOVEI	2,6			;OCTAL PRINT
	HRL	1,0
	MOVEI	0,6
	LSHC	0,3
	GO	PRINT
	SOJG	2,PNTOCT+2
	RTN

;*PNTDEC - PRINT DECIMAL NUMBERS

PNTDEC:	IDIVI	0,^D10			;DECIMAL PRINTER
	HRLM	1,(P)
	SKIPE	0
	GO	PNTDEC
	HLRZ	0,(P)
	ADDI	0,"0"
	JRST	PRINT

;*PRINT - PRINT AN ASCII CHARACTER

PRINT:	AOS	CHRCTR
	MOVEM	1,SAVAC1
	ANDI	177
	MOVEM	0,SAVAC0
	HRRZM	0,1
	TRC	0,200			;COMPUTE CHAR PARITY
	ANDI	1,-1(1)
	JUMPN	1,.-2
	CAIE	11
	JRST	PRINT1			;NOT TAB
	SOS	CHRCTR
	MOVEI	240
	GO	PRINT1
	AOS	1,CHRCTR		;OUTPUT REQUIRED SPACE'S FOR TAB FUNCTION
	TRNE	1,7
	JRST	.-4
	JRST	PRINT2
PRINT1:	CAIN	0,12			;LF ?
	SETZM	CHRCTR			;YES, CLEAR CHAR COUNTER
	CAIN	0,14			;FORM FEED ?
	SETZM	CHRCTR			;YES, CLEAR CHAR COUNTER
	SKIPE	LPTFLG
	JRST	PNTLPT			;PRINT ON LINE PRINTER
	SKIPE	USER
	JRST	PRINT4
	SKIPE	KLFLG
	JRST	PRINT3
	SKIPN	CNTLOF			;CONTROL O'ED ?
	DATAO	TTY,0			;TYPE CHAR
	GO	TTYCHK			;CHECK FOR OPERATOR CONTROL
	CONSO	TTY,10
	JRST	.-2
	CAIN	215
	JRST	FILLCR			;FILL CR
	CAIN	12
	JRST	FILLLF			;FILL LF
PRINT2:	MOVE	1,SAVAC1
	MOVE	0,SAVAC0
	RTN				;EXIT

PRINT3:	ANDI	0,177			;KL10 PRINT
	GO	$DTEXX
	JRST	PRINT2

PRINT4:	OUTCHR
	JRST	PRINT2

;*MISCELLANEOUS

CRLF1:	PMSG	<^>
	RTN

FILLCR:	SETZM	CNTLOF#			;CLEAR CONTROL O FLAG
	MOVE	1,FCRCNT		;GET CR FILL COUNT
	JRST	FILLX+2			;SEND EXTRA CR

FILLLF:	MOVE	1,FLFCNT		;GET LF FILL COUNT
FILLX:	SOJL	1,PRINT2
	MOVEI	0,0			;USE 000 AS FILLER
	DATAO	TTY,0
	CONSO	TTY,10
	JRST	.-1
	JRST	FILLX
;*PNTLPT - LINE PRINTER DRIVER

PNTLPT:	MOVEI	1,^D<<1000*750>/7>
	ANDI	0,177
	LSH	0,1
	DATAO	LPT,0
	SKIPN	KLFLG
	GO	TTYCHK			;CHECK FOR ABORT
	CONSO	LPT,100			;WAIT APPROX 750 MS
	SOJG	1,.-3
	SKIPG	1			;DID LPT RESPOND ?
	GO	LPTOFL			;ASK OPERATOR TO REENABLE IT
	JRST	PRINT2

;*LPTOFL - LINE PRINTER OFF-LINE

LPTOFL:	PUT	0
	PUT	1
	PUT	SAVAC0
	PUT	SAVAC1
	PUT	CHRCTR
	SETZM	LPTFLG			;SEND MESSAGE TO TTY
	MOVE	1,[POINT 7,LOFMSG]
	ILDB	0,1
	JUMPE	0,.+3
	GO	PRINT
	JRST	.-3
	TTICHR				;WAIT FOR OPERATOR
	CAIE	12
	JRST	.-2
	SETOM	LPTFLG			;REENABLE LINE PRINTER
	GET	CHRCTR
	GET	SAVAC1
	GET	SAVAC0
	GET	1
	GET	0
	RTN
;*TTYCHK - TELETYPE CHECK ROUTINE

TTYCHK:	SKIPE	TTYCFLG#		;INPUT CHECKING ALLOWED ?
	RTN				;NO
	CONSO	TTY,40			;ANY TYPEIN ?
	RTN				;NO
	PUT	0
	DATAI	TTY,0			;GET CHAR
	ANDI	0,177
	CAIN	0,003
	JRST	SELECT			;^C, START OVER
	CAIN	0,004
	JRST	TTYIND			;^D, START DDT
	CAIN	0,017
	SETOM	CNTLOF			;^O, INHIBIT OUTPUT
	GET	0
	RTN

LOFMSG:	ASCIZ/
LPT OFF-LINE, TYPE CR WHEN READY - /
SUBTTL	TELETYPE  INPUT

;*TTICHR - INPUT A TELETYPE CHARACTER

TTYIN:	SETZM	CNTLOF
	SETOM	TTYCFLG			;PREVENT INPUT CHECKS ON ECHO
	SKIPE	USER
	JRST	TTYINU
	SKIPE	KLFLG
	JRST	TTYKL
	CONSO	TTY,40			;WAIT FOR TYPEIN
	JRST	.-1
	DATAI	TTY,0			;READ CHAR

;*TTYINX - CHECK FOR SPECIAL CHAR PROCESS

TTYINX:	ANDI	177			;CLEAR PARITY BIT
	CAIN	003
	JRST	SELECT			;^C, START OVER
	CAIE	004
	JRST	.+5

;*TTYIND - TRANSFER TO DDT

TTYIND:	MOVE	KLDDT+1			;GET DDT IDENTIFIER
	CAMN	[ASCII/DDT/]
	JRST	$DDT			;^D, START DDT
	JRST	SELECT			;NOT THERE, START OVER
	CAIN	177
	JRST	TTYEXT			;RUBOUT
	SKIPE	SCFLAG			;IN COMMENT ?
	JRST	TTYINA
	CAIN	40			;SPACE, CHANGE TO TAB
	MOVEI	11
;*TTYINA - COMPLETE CHARACTER PROCESS

TTYINA:	CAIN	33
	JRST	TTALTM			;ALTMODE
	CAIN	176
	JRST	TTALTM			;ALTMODE
	CAIN	175
	JRST	TTALTM			;ALTMODE
	SKIPN	USER
	GO	PRINT
	CAIL	140			;CONVERT TO UPPER CASE
	TRZ	40
	CAIE	15			;IF CR
	JRST	TTYEXT
	MOVEI	12			;PRINT AND EXIT WITH LF
	SETZM	CHRCTR
	JRST	TTYINA

TTYEXT:	SETZM	TTYCFLG
	RTN

;*TTYKL - KL10 CHARACTER INPUT

TTYKL:	MOVEI	3400			;USE DDT MODE
	GO	$DTEXX
	ANDI	0,177
	JUMPE	0,TTYKL			;WAIT FOR RESPONSE
	JRST	TTYINX

;*TTYINU - USER MODE CHARACTER INPUT

TTYINU:	INCHWL
	CAIE	0,15
	JRST	TTYINX
	SETZM	CHRCTR
	INCHRW				;IF CR, GET LF
	JRST	TTYINX
;*USER MODE LH SWITCHES FOR CHAIN OPERATION

LHSWS:	PMSG	<LH SWS - >
	TTIOCT
	JRST	LHSWS
	HRLZM	0,CONSW
	RTN

;*TTIOCT - TELETYPE OCTAL NUMBER INPUT

TTYOCT:	SETZB	DIGIT,DIGITA
TTYOC1:	TTICHR				;INPUT A CHAR
	CAIN	12			;CR(LF), DONE
	JRST	TTYOC2

	CAIL	"0"			;A VALID DIGIT ?
	CAILE	"7"
	JRST	TTYOC3			;NO

	MOVE	DIGITA,0
	LSH	DIGITA,^D33
	LSHC	DIGIT,3			;INSERT NEW OCTAL
	JRST	TTYOC1

TTYOC2:	MOVE	0,DIGIT			;PUT NUMBER IN AC0
	JRST	CPOPJ1

TTYOC3:	SKIPE	USER
	CLRBFI				;CLEAR USER INPUT
	RTN
;*READ - COMMAND FILE READ PROCESS

READ:	SKIPE	DINFLG			;DEVICE COMMAND LIST
	JRST	DEVRD			;YES
	JRST	TTYIN			;TTY REQUESTED
READ1:	ANDI	177
	CAIN	177
	RTN				;RUBOUT
	SKIPE	SCFLAG			;IN COMMENT ?
	JRST	.+3			;YES
	CAIN	40			;SPACE, CHANGE TO TAB
	MOVEI	11
	SKIPE	TAPEPF			;PRINT TAPE ?
	GO	PRINT			;YES
	CAIL	140			;CONVERT TO UPPER CASE
	TRZ	40
	CAIN	12			;IF LF IGNORE
	JRST	READ
	CAIN	14			;IF FF IGNORE
	JRST	READ
	CAIN	15			;IF CR CHANGE TO LF
	MOVEI	12
	JRST	TTYEXT

;*TTALTM - ALTMODE PROCESS

TTALTM:	SETOM	ALTMFLG			;SET ALTMODE FLAG
	MOVEI	"$"			;PRINT $ CR/LF
	SKIPN	USER			;DON'T PRINT $ IF USER
	GO	PRINT
	GO	CRLF1
	MOVEI	12			;RETURN WITH LF
	RTN

PNTTAB:	MOVEI	"	"
	JRST	PRINT			;PRINT A TAB & RTN
SUBTTL	SPECIAL ROUTINES

;*SWITCH - READ CONSOLE SWITCHES

$SWITCH:SKIPE	USER
	JRST	$SWU
	SKIPE	KLFLG
	JRST	.+3
	DATAI	APR,0			;KA/KI, READ CONSOLE SWITCHES
	RTN
	MOVEI	1400			;KL10, GET SWITCHES FROM PDP-11
	JRST	$DTEXX

$SWU:	MOVE	0,CONSW			;GET STORED SWITCHES
	RTN

;*DTEINT - KL10 DTE20 INITIALIZATION

DTEINT:	SKIPE	USER
	RTN
	SETZM	$DTFLG
	SETZM	$DTCLK
	SETZM	$DTCI
	MOVE	$DTOPR			;GET OPERATIONAL DTE #
	ORM	$$DTE0			;INSERT IN DTE I/O INST
	MOVE	[540000,,540001]	;SET UP PAGE TABLES
	MOVSI	1,-160			;TO RESET CONDITION
	MOVEM	600(1)
	ADD	[2,,2]			;SO PAGING
	AOBJN	1,.-2			;CAN BE TURNED ON
	RTN

;*$DTEXX - KL10 DTE20 COMMUNICATIONS

$DTEXX:	MOVEM	0,$DTCMD		;SETUP COMMAND WORD
	AOS	$DTSEQ
$$DTE0:	CONO	DTE,20000		;DONG PDP-11
	SKIPN	$DTFLG
	JRST	.-1			;WAIT FOR REPLY
	SETZM	$DTFLG
	MOVE	0,$DTF11		;GET RESPONSE
	RTN

;*DTECLR - KL10 DTE20 TELETYPE CLEAR

DTECLR:	SKIPE	USER
	RTN
	SKIPN	KLFLG
	RTN
	MOVEI	3000			;CLEAR DDT INPUT MODE
	GO	$DTEXX
	RTN