Google
 

Trailing-Edge - PDP-10 Archives - bb-d549g-sb - camio.mac
There are 3 other files named camio.mac in the archive. Click here to see a list.
TITLE	CAMIO	VERSION 3	
SUBTTL	SOUP I/O ROUTINES		CWRU/CAM

;EDIT==6

;COPYRIGHT 1971, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
	EXTERN	ZOP
	EXTERNAL	PRTOPT
	EXTERN	CMDSPC
	EXTERN	P6WORD
	ENTRY	EOFDIA,CMDLVL
	HISEG		;**********************
	EXTERN	NUMBUF,SAVAC2,SAVE16,SAVEPP,COMPOP,DIASW
	EXTERN	.JBFF,.JBREN
	ENTRY	MRGOUT

	EXTERN XSW,BPAGNO,BASCLN


	IFNDEF	BIGSW,<ENTRY	LOGOUT,LSTOUT>	;*********
						; NOT ASSEMBLED
						; FOR 10K COMPAR


	ENTRY IOERR,NOTAV.,SIXTO7,NOTFNDEOFDIA,PTEOF

	EXTERNAL	MRGDDB,LSTDDB,LOGDDB
	EXTERNAL FED,LOGTTY,LSTTY,INCOPT
	EXTERN MRGSPC,LOGSPC,LSTSPC
	EXTERN LSTBKS,BLOCKS,MRGOPT,MRGIPT,LSTOPT,LSTIPT
	EXTERN	LOGOPT,LOGIPT,LRET,PTRLG,MRET,PTRMRG
	EXTERN SIXBUF,SIXCNT,SCHAR,SFF1,SAVACS,LSTRET,PTRLST,LSTOP
	EXTERN	SIXPTR,SEVPTR,SQVE1,SQVE2,STATE.
	EXTERN	NUMLIN,CRPERR,LINCNT
	EXTERN	ID.,ID.CNT,CRLF,CRLFBF,NUMBUF,NUMBF2,SAVEPP





	; THIS ELEMENT HAS ALL COMMON I/O AND THE COMMAND
	; STRING SCANNER WHICH WILL BE REFERRED TO AS "CSS"
	; IN FURTHER DOCUMENTATION





	; REGISTER ASSIGNMENTS, PROBABLY RELEVANT MOSTLY TO CSS

PP=17				; FOR COMPAR, PUSH DOWN POINTER



CMDLVL:	PUSH	16,16	; ENTRY TO CSS - SAVE 16 ON STACK
	JRST	CMDPUR	; AND GO SCAN THE STRING



	IFDEF	BIGSW,<JOBTTY:JOBDDB:	POPJ	16,>



	; THE FOLLOWING THREE HERALDED CHARACTERS ARE THE
	; BREAK CHARACTERS THAT DEFINE THE END OF A LINE TO CAM & FED

FF=13	
LF=12
VT=14	



SIXCT=0			; HOLDS CONCATENATION COUNT
OPT=1			; POINTS TO OPTION BUFFER
REG6=2			;  POINTS TO SIXBYT
STOP=3			; HOLDS CHAR THAT STOPPED SCANNER
SIXBYT=4		; HOLDS CONCATENATED SIXBIT
LIST=5			; LOCAL PUSH DOWN POINTER FOR CSS
PDP=6			; ANOTHER PDP FOR PUSHJ'S
TEMP=7			; TEMP REG FOR ERR MSGS
TEMP.=7			; SPELLING CONVENIENCE 
XX=11			; HOLDS COMMAND STRING CHARS
CHAR=13			; RETURNS CHAR FROM INPUT ROUTINES
RETURN=14		; HOLDS PC TO RETURN FROM IO ROUTINES



	; SOFTWARE I/O CHANNEL ASSIGNMENTS
	; CHANNEL 7 IS GLOBALLY SACRED, DO NOT TOUCH!


MCCHAN=0		; CAM - MANU. CORR. -- FED - CORR. FILE INPUT
ATSGN="@"
LOGCHAN=1		; LOG OUTPUT
MRGCHAN=2		; CAM - MRGED CORR FILE -- FED - NEW SOURCE FILE 
LSTCHN=3		; LISTINGS OUTPUT
UCCHAN=4		; CAM - USER'S CORR. -- FED - OLD SOURCE FILE
BACHAN=5		; COMPAR ONLY, BASE FILE INPUT
USCHAN=6		; COMPAR ONLY, USER'S FILE INPUT
CMDCHAN=7		; ***   COMMANDS FROM HERE   ***
MRGCHN=MRGCHAN		; SPELLING CONVENIENCE
LOGCHN=LOGCHAN
LSTCHAN=LSTCHN
UCHAN=UCCHAN
DTAF=100		; FOR DEVCHR UUO

; MACRO TO CHECK FOR "EDIT10" SEQUENCE NUMBERS, DELETE THEM
DEFINE CHKLN (ROUT,HDR,FLG) <
	PUSH	16,TEMP		;NEED A REGISTER
	MOVE	TEMP,@HDR+1	;GET FULL WORD FROM WHICH BYTE WAS TAKEN
	TRZN	TEMP,1		;A SEQUENCE NUMBER?
	 JRST	 ROUT'9		; NO, CONTINUE
	MOVEM	TEMP,@HDR+1	;SEQNO BIT OFF NOW
 IFE FLG-1,<
	MOVEM	TEMP,BASCLN	;SAVE LINE #
>
	PUSH	16,RETURN	;WE WILL RECUR
	CAMN	TEMP,[ASCII /     /] ;ONE EXTRA CHAR FOR PAGE MARK
REPEAT 6,<
	JSP	RETURN,ROUT	;TOSS OUT REST OF LINE NO, TAB
>
	POP	16,RETURN	;GET RETURN ADDR BACK
	POP	16,TEMP		;AND OLD VALUE OF TEMP
	JRST	ROUT		;GO GET THE CHARACTER
ROUT'9:	POP	16,TEMP		;RESTORE VALUE
>


	;	ROUTINE TO OUTPUT LOG MESSAGES

	; FREQUENTLY USED ERROR MESSAGES

	ENTRY	IMPRSP		; USED BY FEDIT
	EXTERN	TSW		; T SWITCH
MRGOER:	ASCIZ/? MRG OUTPUT/
LSTOER:	ASCIZ/? LST OUTPUT/
IMPRSP:	ASCIZ/??? IMPROPER RESPONSE
/
RECIPR:	ASCIZ/NEW FILE ACCEPTED
/
DUPDEV:	ASCIZ/? DUP INPUT DEV
/

	IFNDEF	BIGSW,	<; **********************
JOBTTY:JOBDDB:	CALLI	CHAR,4		; DO DEVCHR UUO
	HLRZS	CHAR		; MAKE LH RH
	XORI	CHAR,10010	; MASK OFF UNDESIRED BITS
	ANDI	CHAR,10010	; AND SEE IF DEV HAS PROPER CHARACTERISTICS
	JUMPE	CHAR,[POPJ 16,]	; RETURN IF IT DOES
	MOVEI	CHAR,3
	ADDM	CHAR,(16)	; POP RETURN 3 IF IT IS NOT USER TTY
	POPJ	16,


	; GENERAL ROUTINE TO DO TTY OUTPUT.  CSS AND OUTPUT
	; ROUTINES DECIDE IF INFO IN DDB MEANS TO USE USER'S TTY.
	; IF SO, EVERYTHING IS SHOVELED OUT HERE TO AVOID
	; ASSIGNING TTY TO SEVERAL CHANNELS ( WITH DISASTEROUS
	; RESULTS!!!)

TTYOUT:	SKIPE	CHAR,@0(14)	; IS THE CHAR COUNT 0?
	JRST	TYTX		; NO, STRING OUTPUT
	MOVE	CHAR,@1(14)	; YES, GET CHAR
	TTCALL	1,CHAR		; OUTPUT FROM REG
	JRST	2(14)		; RETURN
TYTX:	HRRZM	14,LRET		; SAVE RETURN ADDR
	MOVEI	14,@1(14)	; GET STRING ADDR
	SOJ	14,		; FIX FOR BYTE POINTER
	HRLI	14,(POINT 7,0,35)
	MOVEM	14,PTRLG	; MAKE POINTER
	MOVE	14,@LRET
	MOVE	14,0(14)	; GET CHAR COUNT
TYXX:	ILDB	CHAR,PTRLG	; NOW GET FIRST  ONE
	TTCALL	1,CHAR		; AND TYPE IT OUT
	SOJG	14,TYXX		; DECR COUNT
	MOVEI	14,2		; WENT TO 0, NOW FIX FOR RETURN
	ADDM	14,LRET		; TO PC+2
	JRST	@LRET		; AND THEN GO BACK


	; ROUTINE TO OUTPUT LOG MESSAGES. ALL OTHER OUTPUT ROUTINES
	; WORK BASICALLY LIKE THIS ONE, EXCEPT WHEN INITIALIZING
 		; FILE RETRIEVAL INFORMATION FOR THE MONITOR.  THE USER CALLS
	; FOR ALL OUTPUT ROUTINES ARE AS FOLLOWS:


			; JSP	14,***OUT
			; ARG #1
			; ARG #2
			; RETURNS HERE


	; C(ADDR GIVEN AS ARG #1) IS:


			;0  INDICATING THAT A SINGLE CHARACTER
			;   RIGHT JUSTIFIED IN ADDRESS ARG #2 IS TO
;			;   BE OUTPUT

	;	OR:
			; GTR 0, INDICATING THAT A STRING OF
			;C(ADDR GIVEN BY ARG #2) CHARS IS TO BE OUTPUT



LOGOUT:	SKIPL	LOGDDB+6		; CHANNEL OPEN?
	JRST OPENLG		; NO, OPEN IT
	SKIPE	LOGTTY		; IS THIS A TTY?
	JRST	TTYOUT		; THEN USE TTCALL
LOGC:	SKIPE	CHAR,@0(14)	; GET  C(ARG #1)
	JRST	NXTX		; NON 0 MEANS STRING OUTPUT
	MOVE	CHAR,@1(14)	; SINGLE CHAR, LOAD IT
	SOSG	LOGOPT+2	; IO BUFFER FULL?
	OUTPUT	LOGCHAN,	; YES, OUTPUT IT
	IDPB	CHAR,LOGOPT+1	; PACK CHAR AWAY
	JRST	2(14)		; THEN RETURN
NXTX:	HRRZM	14,LRET		; SAVE RETURN ADDR
	MOVEI	14,@1(14)	; LOAD STRING ADDR
	SOJ	14,		; FIX FOR BYTE POINTER
	HRLI	14,(POINT 7,0,35)	; MAKE IT A POINTER
	MOVEM	14,PTRLG	; PUT IT IN CORE
	MOVE	14,@LRET	; NOW GET CHAR COUNT
	MOVE	14,0(14)	; IN REG 14
LOGX:	SOSG	LOGOPT+2	; BUFFER FULL?
	JRST 	MTLOG		; YES, EMPTY IT
LOGXX:	ILDB	CHAR,PTRLG	; FETCH SOMETHING
	IDPB	CHAR,LOGOPT+1	; PUT IN BUFFER
	SOJG	14,LOGX		; DECR COUNT
	MOVEI	14,2		; DONE, FIX RETURN
	ADDM	14,LRET		; TO CALLING PC+2
	JRST	@LRET		; GO HOME
MTLOG:	OUT	LOGCHAN,	;  OUTPUT BUFFER
	JRST	LOGXX		; DO MORE WORK IF NO ERRORS
	PUSHJ	16,IOERR	; TELL OPR AN IO ERROR HAS OCCURED
	XWD	[ASCIZ/?LOG OUTPUT/],LOGDDB
	JRST	MTLOG		; OPR DID SOMETHING, TRY AGAIN
OPENLG:	MOVE	CHAR,LOGDDB	; GET DEV NAME
	PUSHJ	16,JOBTTY	; IS IT A USER TTY?
	SETOM	LOGTTY		; YES, SET TTY FLAG
	SETOM	LOGDDB+6	; AND CHANNEL OPEN FLAG
	JRST	TTYOUT		; AND TYPE OUT STRING
	SKIPE	LOGDDB+6	; NEW FILE NAME?
	JRST	NEWLOG		; YES, DO NOT RE-INIT
	MOVE	CHAR,LOGDDB	; GET DEV NAME AGAIN
	MOVEM	CHAR,LOGSPC+1	; PUT WHERE MONITOR WILL SEE IT
INITLG:	OPEN	LOGCHAN,LOGSPC	; TRY TO OPEN CHANNEL
	JRST	.+2		; FAILURE
	JRST	LOGOK		; SUCCESS
	PUSHJ	16,NOTAV.	; TELL OPR DEV NOT AVAILABLE
	XWD	[ASCIZ/?LOG/],LOGDDB
	JRST	INITLG-1	; HE HAS FIXED THINGS
LOGOK:
NEWLOG:	SKIPN	LOGDDB+2	; IS THERE A FILE NAME?
	JRST	NOFILE		; NO, DO NO ENTER
	HRRZI	CHAR,SAVACS	; PREPARE TO SAVE REGS
	BLT	CHAR,SAVACS+3	; IN SAVAC REGION
	HRLZI	CHAR,LOGDDB+2	; THEN LOAD FILENAME.EXT[X,X]
	BLT	CHAR,3		; INTO REGS 0-3
	ENTER LOGCHAN,0		; AND ENTER NEW FILE
	JRST	LOGNF		; UNLESS DIRECTORY FULL
	HRLZI	CHAR,SAVACS	; NOW GET THE USER'S REGS
	BLT	CHAR,3		; BACK IN ORDER
NOFILE:	OUTPUT	LOGCHAN,		; NOW DO FIRST OUT
	SETOM	LOGDDB+6	; AND SET CHANNEL OPEN
	JRST	LOGC		; AND RETURN TO DO WORK
LOGNF:	PUSHJ	16,NOTFND	; TELL OPR FILE CANNOT BE WRITTEN
	XWD	[ASCIZ/?CANNOT ENTER LOG OUTPUT FILE /],LOGDDB
	JRST	NEWLOG		; OPR KNOWS BETTER, TRY AGAIN
	>



	; ROUTINE TO OUTPUT MERGED CORRECTION FILE
	; THIS ROUTINE IS NEARLY IDENTICAL TO LOGOUT, SO ONLY
	; DIFFERENCES WILL BE NOTED HERE.


MRGOUT:	SKIPL	MRGDDB+6	
	PUSHJ	16,OPNMRG	; OPEN CHAN AND COUNT FREE BLKS
MRGC:	SKIPE	CHAR,@0(14)
	JRST	NXTX1
	MOVE	CHAR,@1(14)
	SOSG	MRGOPT+2
	JRST	MTMRG2
PUTC:	IDPB	CHAR,MRGOPT+1
		JRST	2(14)
NXTX1:	HRRZM	14,MRET
	MOVEI	14,@1(14)
	HRLI	14,(POINT 7,0,35)
	SOJ	14,
	MOVEM	14,PTRMRG
	MOVE	14,@MRET
	MOVE	14,0(14)
MRGX:	SOSG	MRGOPT+2
	JRST	MTMRG
MRGXX:	ILDB	CHAR,PTRMRG
	IDPB	CHAR,MRGOPT+1
	SOJG	14,MRGX
	MOVEI	14,2
	ADDM	14,MRET
	JRST	@MRET
MTMRG:	SOSG	BLOCKS		; HERE WE MUST BOOKKEE BLOCKS USED
	PUSHJ	16,MTF.		; NONE LEFT, ASK OPR FOR MORE TAPE
	OUT	MRGCHAN,	; PLENTY LEFT, OUTPUT BUFFER
	JRST	MRGXX		; SUCCESS
	PUSHJ	16,IOERR	; INFORM OPR HE MAY NEED REPAIR MAN
	XWD	MRGOER,MRGDDB
	JRST	MTMRG		; REPAIR MAN CAME AND LEFT
MTMRG2:	MOVEM	CHAR,SCHAR	; SAVE CHAR TO BE OUTPUT
	SOSG	BLOCKS		; BEFORE CHECKING FOR FULL TAPE
	PUSHJ	16,MTF.		; TAPE FULL, COMPLAIN
	MOVE	CHAR,SCHAR	; PICK UP LAST CHAR
	OUT	MRGCHAN,	; NOW OUTPUT THE BLOCK
	JRST	PUTC		; AND GO BACK IF NO ERRORS
	PUSHJ	16,IOERR	; TROUBLE
	XWD	MRGOER,MRGDDB
	JRST	MTMRG2		; OPR WANTS TO TRY AGAIN

	;	ROUTINE TO COUNT BLOCKS AND INIT MRG DEVICE

OPNMRG:	SKIPE	MRGDDB+6	; NEW FILE NAME ONLY?
	JRST NEWMRG		; YES
	HRLOI	CHAR,377777	; NO, SET FREE BLOCKS TO MAX
	MOVEM	CHAR,BLOCKS
	MOVE	CHAR,MRGDDB	; NOW FIND OUT IF DTA OR DSK
	CALLI	CHAR,4
	TLNN	CHAR,DTAF
	JRST	OMITDI		; NOT A DECTAPE, DON'T COUNT BLOCKS
	MOVE	CHAR,.JBFF	; IT IS A DETAPE, SAVE OLD .JBFF
	MOVEM	CHAR,SFF1
	MOVEI	CHAR,14		; SET INPUT MODE TO BINARY
	MOVEM	CHAR,MRGSPC
	MOVE	CHAR,MRGDDB	; GET DEV NAME
	MOVEM	CHAR,MRGSPC+1
	MOVEI	CHAR,MRGIPT	; MAKE DEV DO INPUT
	HRRM	CHAR,MRGSPC+2
INMRG1:	OPEN	MRGCHAN,MRGSPC	; OPEN DEV
	PUSHJ	16,MRGNA	; OR COMPLAIN
	USETI	MRGCHAN,144	; READ DIRECTORY
	INPUT	MRGCHAN,
	SETZM	BLOCKS		; ZERO FREE BLOCKS
	HRLZI	CHAR,(POINT 5,0,35)	; MAKE POINTER COUNT SLOTS
	HLLM	CHAR,MRGIPT+1	; 5 BITS BIG (SEE MONITOR MANUAL)
	MOVEM	CHAR+1,SQVE1	; SAVE US AN EXTRA REGISTER
	MOVEI	CHAR+1,^D577	; WE WISH TO SEE WHICH BLOCKS NOT USED
NXSLOT:	ILDB	CHAR,MRGIPT+1	; IS THIS TAPE BLOCK USED?
	JUMPN	CHAR,.+2	; SKIP IF IT IS
	AOS	BLOCKS		; TOTAL NUMBER OF FREE BLOCKS
	SOJG	CHAR+1,NXSLOT	; BE SURE TO COUNT ONLY 577 BLOCKS
	MOVE	CHAR,BLOCKS	; GET THE TOTAL WHEN DONE
	SUBI	CHAR,24		; AND SUBTRACT A FEW FOR SAFETY
	MOVEM	CHAR,BLOCKS	; PUT BACK SAFE NUMBER OF FREE BLOCKS
	JUMPG	CHAR,TAPEOK	; IF >0 THE TAPE CAN BE USED
	TTCALL	3,[ASCIZ/?MRG TAPE TOO FULL
/]
	CALLI	1,12		; EXIT AND WAIT
	RELEAS	MRGCHAN,		; RELEASE AND
	JRST	INMRG1		; TRY AGAIN
TAPEOK:	MOVE	CHAR+1,SQVE1	; RESTORE THE REGISTER USED
	RELEAS	MRGCHN,		; DESTROY INPUT SIDE OF CHAN
	MOVE	CHAR,SFF1	; GET PREVIOUS .JBFF
	MOVEM	CHAR,.JBFF	; RESTORE .JBFF
OMITDI:	MOVE	CHAR,MRGDDB	; AND NOW IT LOOKS LIKE NOTHING HAPPENED
	MOVEM	CHAR,MRGSPC+1	; REINIT FOR OUTPUT ONLY
	SETZB	CHAR,MRGSPC	; IN ASCII MODE
	HRRM	CHAR,MRGSPC+2	; AND PREVENT INPUT SIDE FROM BEING OPENED
	OPEN	MRGCHAN,MRGSPC	; OPEN IT
	PUSHJ	16,MRGNA	; DEVICE NOT AVAILABLE
	SKIPE	FED
	OUTBUF	MRGCHAN,5	; ROOM FOR FED
NEWMRG:	SKIPN	MRGDDB+2	; NO FILE NAME
	JRST	NOFILM		; NO SKIP
	HRRZI	CHAR,SAVACS	
	BLT	CHAR,SAVACS+3	; SWAP REGS 0-3
				; WITH FILE RETRIEVAL INFO
	HRLZI	CHAR,MRGDDB+2
	BLT	CHAR,3
	ENTER	MRGCHAN,	; WITH FILE INFO AND DO ENTER
	JRST	MRGNOEN		; CAN'T WRITE
	HRLZI	CHAR,SAVACS	; EVERYTHING OK NOW, RESTORE REGS
	BLT	CHAR,3
NOFILM:	OUTPUT	MRGCHAN,	; NOW DO FIRST OUTPUT
	SETOM	MRGDDB+6
	POPJ	16,		; AND RETURN TO CALLER
MRGNA:	PUSHJ	16,NOTAV.	; TELL OPR DEV NOT AVAIL
	XWD	[ASCIZ/?MRG/],MRGDDB
	SOS	(16)
	SOS	(16)
	POPJ	16,		; RETURN TO PC-2 (OPEN UUO)
MRGNOEN:	PUSHJ	16,NOTFND	; TELL OPR WRITING NOT POSSIBLE
	XWD	[ASCIZ/?CANNOT ENTER MRG OUTPUT FILE /],MRGDDB
	JRST	NEWMRG		; RETRY
	IFNDEF	BIGSW,<




	; LSTOUT IS SO SIMILAR TO MRGOUT , IT COULD HAVE BEEN
	; GENERATED BY A MACRO.  HOWEVER, IT WORRIES ABOUT 
	; OUTPUTTING TO THE USER'S TTY TOO, LIKE LOGOUT

LSTOUT:	SKIPL	LSTDDB+6	
	PUSHJ	16,OPNLST
	SKIPE	LSTTY		; HAVE WE GOT A TTY?
	JRST	TTYOUT		; THEN USE TTCALL
LSTC:	SKIPE	CHAR,@0(14)
	JRST	NXTX2
	MOVE	CHAR,@1(14)
	SOSG	LSTOPT+2
	JRST	MTLST2
PUTL:	IDPB	CHAR,LSTOPT+1
	JRST	2(14)
NXTX2:	HRRZM	14,LSTRET
	MOVEI	14,@1(14)
	HRLI	14,(POINT 7,0,35)
	SOJ	14,
	MOVEM	14,PTRLST
	MOVE	14,@LSTRET
	MOVE	14,0(14)
LSTX:	SOSG	LSTOPT+2
	JRST	MTLST
LSTXX:	ILDB	CHAR,PTRLST
	IDPB	CHAR,LSTOPT+1
	SOJG	14,LSTX
	MOVEI	14,2
	ADDM	14,LSTRET
	JRST	@LSTRET
MTLST:	SOSG	LSTBKS
	PUSHJ	16,MTF2. 
	OUT	LSTCHAN,
	JRST	LSTXX
	PUSHJ	16,IOERR
	XWD	LSTOER,LSTDDB
	JRST	MTLST
MTLST2:	MOVEM	CHAR,SCHAR
	SOSG	LSTBKS
	PUSHJ	16,MTF2.
	MOVE	CHAR,SCHAR
	OUT	LSTCHAN,
	JRST	PUTL
	PUSHJ	16,IOERR
	XWD	LSTOER,LSTDDB
	JRST	MTLST2+2
CKFED:	SKIPN	FED
	JRST	CKFAIL
	POP	16,CHAR		; POP OLD RETURN PC OFF LIST
	JRST	2(14)		; IF FED IS RUNNING, AND LSTOP IS FALSE,
				; LSTOUT DOES NO I/O
OPNLST:	SKIPN	LSTOP
	JRST	CKFED
CKFAIL:	SKIPE	LSTDDB+6
	JRST	NEWLST
	HRLOI	CHAR,377777
	MOVEM	CHAR,LSTBKS
	MOVE	CHAR,LSTDDB
	CALLI	CHAR,4
	TLNN	CHAR,DTAF
	JRST	OMITD2
	MOVE	CHAR,.JBFF
	MOVEM	CHAR,SFF1
	MOVE	CHAR,LSTDDB
	MOVEM	CHAR,LSTSPC+1
	MOVEI	CHAR,14
	MOVEM	CHAR,LSTSPC
	MOVEI	CHAR,LSTIPT
	HRRM	CHAR,LSTSPC+2
NLST:	OPEN	LSTCHAN,LSTSPC
	PUSHJ	16,LSTNA
	USETI	LSTCHAN,144
	INPUT	LSTCHAN,
	SETZM	LSTBKS		; MAKE FREE BLOCKS APPEAR IN LSTBKS
	HRLZI	CHAR,(POINT 5,0,35)
	HLLM	CHAR,LSTIPT+1
	MOVEM	CHAR+1,SQVE2
	MOVEI	CHAR+1,^D577
NNXSLT1:	ILDB	CHAR,LSTIPT+1
	JUMPN	CHAR,.+2
	AOS	LSTBKS		; COUNT THE FREE BLOCKS
	SOJG	CHAR+1,NNXSLT1
	MOVE	CHAR,LSTBKS
	SUBI	CHAR,24
	MOVEM	CHAR,LSTBKS
	JUMPG	CHAR,TAPOK2	; ENOUGH LEFT, LET PROGRAM CONTINUE
	TTCALL	3,[ASCIZ/?LST TAPE TOO FULL
/]
	CALLI	1,12		; EXIT AND WAIT
	RELEASE	LSTCHAN,	; RELEASE AND
	JRST	NLST		; TRY AGAIN
TAPOK2:	MOVE	CHAR+1,SQVE2
	RELEAS	LSTCHN,
	MOVE	CHAR,SFF1
	MOVEM	CHAR,.JBFF
OMITD2:	MOVE	CHAR,LSTDDB
	PUSHJ	16,JOBDDB	; IS THIS A USER TTY?
	SETOM	LSTTY		; YES, SET LSTTY FLAG
	SETOM	LSTDDB+6	; AND STATUS
	POPJ	16,		; AND RETURN 
	MOVE	CHAR,LSTDDB
	MOVEM	CHAR,LSTSPC+1
	SETZB	CHAR,LSTSPC	; ERASE FOOTPRINTS FROM READING
	HRRM	CHAR,LSTSPC+2	; DIRECTORY
INLST1:	OPEN	LSTCHAN,LSTSPC
	PUSHJ	16,LSTNA
	SKIPE	FED
	OUTBUF	LSTCHAN,5	; MORE BUFFERS FOR FED
NEWLST:	SKIPN	LSTDDB+2
	JRST	NOFIL1
	HRRZI	CHAR,SAVACS
	BLT	CHAR,SAVACS+3
	HRLZI	CHAR,LSTDDB+2
	BLT	CHAR,3
	ENTER	LSTCHAN,	; DO ENTER WITH INFO IN REGS
	JRST	LSTNOEN
	HRLZI	CHAR,SAVACS
	BLT	CHAR,3
NOFIL1:	OUTPUT	LSTCHAN,	; DO FIRST OUTPUT HERE
	SETOM	LSTDDB+6	; SET STATUS TO FULL THROTTLE
	POPJ	16,
LSTNA:	PUSHJ	16,NOTAV.
	XWD	[ASCIZ/?LST/],LSTDDB
	SOS	0(16)
	SOS	(16)
	POPJ	16,
LSTNOEN:	PUSHJ	16,NOTFND
	XWD	[ASCIZ/?CANNOT ENTER LST OUTPUT FILE /],LSTDDB
	JRST	NEWLST
		>



	; SIXBIT TO ASCIZ CONVERSION ROUTINE.  PUSHJ TO SIXTO7
	; AND STORE INFO IN SPECIAL PARAMETER WORD P6WORD,
	; IN FOLLOWING FORMAT:

	;	LH		RH

	;	-1	ADDR OF SIXBIT	EDITS " " AT END
	;	0	ADDR OF SIXBIT	EDITS "." AT END OF ASCII
	;	1	ADDR OF SIXBIT	EDITS CR-LF AT END OF ASCII

	; NUMBER OF CHARACTERS CONVERTED STORED IN SIXCNT
	; ASCIZ IS FOUND IN SIXBUF


SIXTO7:	HRRZ	CHAR,P6WORD	; GET ADDR OF SIXBIT
	SOJ	CHAR,		; -1 TO MAKE POINTER WORK
	HRLI	CHAR,(POINT 6,0,35)
	MOVEM	CHAR,SIXPTR	; MAKE UP 6 BIT EXTRACTER
	SETZM	SIXCNT		; ZERO CHAR COUNT
	MOVE	CHAR,[POINT 7,SIXBUF-1,35]
	MOVEM	CHAR,SEVPTR	; MAKE UP 7 BIT CONCATENATOR
	SETZM	SIXBUF		
	SETZM	SIXBUF+1	; ZERO BUFFER FOR ASCIZ
CONV67:	ILDB	CHAR,SIXPTR	; GET SIXBIT CHAR 
		JUMPE	CHAR,CONVFI	; ZERO MEANS DONE
	ADDI	CHAR,40		; ADD 40 TO MAKE IT ASCII
	IDPB	CHAR,SEVPTR	; PUT IT IN BUFFER
	AOS	CHAR,SIXCNT	; AND INCR COUNT
	CAIG	CHAR,5		; DO NOT CONVERT MORE THAN 5
	JRST	CONV67
CONVFI:	HLRE	CHAR,P6WORD	; NOW FIND OUT WHAT TO EDIT
	JUMPE	CHAR,WANTS.	; 0 PUT OUT A "."
	JUMPL	CHAR,SPACE.	; -1 PUT OUT A " "
	MOVEI	CHAR,15		; DEFAULT, PUT OUT CR-LF
	IDPB	CHAR,SEVPTR
	MOVEI	CHAR,12
	IDPB	CHAR,SEVPTR
	MOVEI	CHAR,2
	ADDM	CHAR,SIXCNT	; MAKE CHAR COUNT AGREE
	POPJ	16,		; RETURN
POP.:	AOS	(16)		
	POPJ	16,		; GENERAL PURPOSE POP RETURN
WANTS.:	MOVEI	CHAR,"."
	IDPB	CHAR,SEVPTR
	AOS	SIXCNT
	POPJ	16,
SPACE.:	MOVEI	CHAR," "
	IDPB	CHAR,SEVPTR
	AOS	SIXCNT
	POPJ	16,

		


	; IOERR HANDLES IO ERRORS. ENTER WITH A PUSHJ 16,
	; FOLLOWED BY A PARAMETER WORD FORMULATED
	; THUS:

	;	XWD [ASCIZ/<TEXT TO BE PRINTED>/], ADDR OF DEV NAME

	; AND IOERR WILL RETURN UPON SUCCESSFUL DIALOGUE
	; WITH USER




IOERR:	PUSH	16,TEMP.		; SAVE TEMP 
	PUSH	16,TEMP.+1	; AND TEMP+1
	HRRZ	TEMP.,@-2(16)	; GET ADDR OF DEV NAME IN SIXBIT
	HLRZ	TEMP.+1,@-2(16)	; AND ADDR OF TEXT
	TTCALL	3,@TEMP.+1	; TYPE TEXT OUT
	TTCALL	3,[ASCIZ/ ERROR FROM /]
	HRROM	TEMP.,P6WORD
	PUSHJ	16,SIXTO7	; CONVERT DEV NAME TO ASCIZ
	TTCALL	3,SIXBUF	; TYPE IT
	ADDI	TEMP.,2		; GET FILE NAME
	HRRZM	TEMP,P6WORD
	PUSHJ	16,SIXTO7	; CONVERT TO ASCIZ
	TTCALL	3,SIXBUF	; AND TYPE
	AOJ	TEMP.,		; NOW MAKE EXT APPEAR
	TLO	TEMP.,1
	MOVEM	TEMP.,P6WORD
	PUSHJ	16,SIXTO7
	TTCALL	3,SIXBUF	; ON TTY
	PUSHJ	16,GPDIA	; DO DIALOGUE
	POP	16,TEMP.+1	; RETURN ON USER'S OK
	POP	16,TEMP.	; RESTORE TEMP,TEMP+1
	JRST	POP.		; GO BACK TO I/O ROUTINE



	; NOTAV. IS CALLED SIMILARLY, WHENEVER
	; A BAD DEVICE WAS SPECIFIED.  WHEN THE USER ASSIGNS THE
	; DEVICE, IT WILL RETURN TO CALLER



NOTAV.:	PUSH	16,TEMP.	
	PUSH	16,TEMP.+1	; SAVE TEMP AND TEMP+1
	HRRZ	TEMP.,@-2(16)	; GET DDB ADDR
	HLRZ	TEMP.+1,@-2(16)	; AND TEXT ADDR
	TTCALL	3,@TEMP.+1	; TYPE TEXT
	TTCALL	3,[ASCIZ/ DEV /]
	HRROM	TEMP.,P6WORD
	PUSHJ	16,SIXTO7
	TTCALL	3,SIXBUF	; TYPE NAME OF DEVICE
	TTCALL	3,[ASCIZ/NOT AVAILABLE
/]
	PUSHJ	16,GPDIA	; REQUEST RESPONSE FROM USER
	POP	16,TEMP+1
	POP	16,TEMP.	; RESTORE REGS
	JRST	POP.		; POP RETURN



	; NOTFND IS CALLED LIKE IOERR WHENEVER A FILE 
	; CANNOT BE FOUND OR CANNOT BE ENTERED.  THE
	; FORMAT OF THE ERROR MESSAGE IS A LITTLE FREER
	; AND CAN BE USED FOR OTHER PURPOSES, BESIDES



NOTFND:	HRRZ	TEMP.,@0(16)	; GET DDB ADDR
	HLRZ	TEMP.+1,@0(16)	; AND TEXT ADDR
	TTCALL	3,@TEMP.+1	; TYPE TEXT
	ADDI	TEMP.,2		; AND FILENAME.EXT (CR-LF)
	HRRZM	TEMP.,P6WORD
	PUSHJ	16,SIXTO7
	TTCALL	3,SIXBUF
	AOJ	TEMP.,
	TLO	TEMP.,1
	MOVEM	TEMP.,P6WORD
	PUSHJ	16,SIXTO7
	TTCALL	3,SIXBUF
	PUSHJ	16,GPDIA	; DIALOGUE
	JRST	POP.		; POP RETURN IF OK



	; PAPER TAPE READER EOF ROUTINE.  CONTROL GETS
	; TO HERE WHEN ANY INPUT ROUTNE USING PTR HITS
	; EOF, AT WHICH POINT MORE TAPE IS REQUESTED


PTEOF:	MOVEI	CHAR,0
	AOSGE	6(TEMP)
	JRST	RETN
	SOS	6(TEMP)
	TTCALL	3,[ASCIZ/*** END OF PAPER TAPE	
/]				; TYPE OUT MSG
	IFDEF REENT,<
	MOVEI CHAR,REENPT	; SET UP FOR REEN COMMAND
	MOVEM	CHAR,.JBREN	; ADJUST .JBDAT AREA
		>		; DO NOT TAMPER UNLESS SWITCH ON
	CALL 1,[SIXBIT/EXIT/]	; SPECIAL EXIT
REENPT:	TTCALL 3,[ASCIZ/*/]	; RETURN HERE FROM MONITOR MODE
	TTCALL	4,CHAR		; GET USER'S REPLY
	CAIN	CHAR,"D"
	JRST	RET.		; D MEANS MORE TO COME
	CAIN	CHAR,15
	JRST	RETX.		; CR MEANS PHYSICAL EOF
	TTCALL	11,0		; MEANINGLESS INPUT FLUSHED
	TTCALL	3,IMPRSP	; TYPE IMPROPER RESPONSE
	JRST REENPT		; TRY FOR SOMETHING SENSIBLE
RETN:	POP	16,CHAR
	POP	16,TEMP
	MOVEI	CHAR,0
	JRST	0(RETURN)
RET.:	TTCALL	11,0		; FLUSH ANYTHING ELSE TYPED
	TTCALL	3,RECIPR	; RECOVERY IN PROGRESS
	POPJ	16,		; GO BACK TO I/O
RETX.:	TTCALL	11,0		; FLUSH ANYTHING ELSE
	MOVEI	CHAR,0		; GIVE  BACK NULL
	SOS	6(TEMP)		; SET STATUS TO PEOF
	JRST	RETN		; WHICH SHOULD STOP EVERYTHING



	; MTF. AND MTF2. ARE CALLED WHEN MRG OR LST TAPES
	; RESPECTIVELY ARE FILLED.  MORE TAPE IS REQUESTED.


MTF.:	RELEAS	MRGCHAN,	; RELEASE ASSOCIATED CHANNEL
	PUSHJ	16,FTAPE.	; INFORM USER WHAT'S WHAT
	XWD	0,MRGDDB	; AND WHERE IT'S AT
	SETZM	MRGDDB+6	; RENEW VIRGIN STATUS
	PUSH	16,TEMP+1
	MOVEI	TEMP+1,MRGDDB+3	; WHERE???
	PUSHJ	16,INCEXT	; INCREMENT EXT. IF NUMERIC
	POP	16,TEMP+1	; RESTORE THE REG
	PUSHJ	16,OPNMRG	; OPEN NEW TAPE UP
	POPJ	16,		; PUT THINGS IN THE NEW FILE
	IFNDEF	BIGSW,<
MTF2.:	RELEAS	LSTCHAN,	; DITTO FOR LST DEVICE
	PUSHJ	16,FTAPE.
	XWD	0,LSTDDB
	SETZM	LSTDDB+6
	PUSH	16,TEMP+1
	MOVEI	TEMP+1,LSTDDB+3
	PUSHJ	16,INCEXT
	POP	16,TEMP+1
	PUSHJ	16,OPNLST
	POPJ	16,
		>


	; INCEXT INCREMENTS THE RIGHTMOST TERMINATING NUMERIC
	; IF FOUND IN THE EXTENSION IN THE DDB.  IT WILL 
	; NOT INCREMENT SIXBIT/9/


INCEXT:	SKIPE	INCOPT		; SHOULD WE INCREMENT?
	POPJ	16,		; NO
	HLLZ	CHAR,0(TEMP+1)	; TEMP+1 POINTS TO EXT IN DDB
	TLNE	CHAR,77		; LAST CHAR NULL?
	JRST	GETL.		; NO, SEE IF NUMERIC
	AOJ	CHAR,		; INCR. SCANNER COUNT
	TLNE	CHAR,7700	; SECOND LAST NULL?
	JRST	GETL.		; NO, EXAMINE FURTHER
	AOJ	CHAR,		; INCR. SCANNER COUNT
	TLNE	CHAR,770000	; THIRD (LEFTMOST) NULL?
	JRST	GETL.		; NO
	AOJ	CHAR,		; YES
	POPJ	16,		; SO NO POINT IN INCR NULL EXT
GETL.:	LDB	TEMP.,BTAB(CHAR); GET THE CHAR
	CAIG	TEMP.,17	; IS IT GTR SIXBIT/0/-1?
	POPJ	16,		; NOT NUMERIC
	CAIL	TEMP.,31	; HOW ABOUT LESS SIXBIT/9/?
	POPJ	16,		; NO
	AOJ	TEMP.,		; INCREMENT THE NUMERIC CHAR
	DPB	TEMP.,BTAB(CHAR); PUT IT BACK
	POPJ	16,		; AND RETURN
BTAB:	POINT	6,0(TEMP+1),17	; POINTS TO RIGHTMOST CHAR
	POINT	6,0(TEMP+1),11	; POINTS TO SECOND CHAR
	POINT	6,0(TEMP+1),5	; POINTS TO LEFT MOST



	; FTAPE. ASKS FOR MORE TAPE IN ENGLISH

FTAPE.:	HRRZ	CHAR,@0(16)	; LOAD DDB ADDR
	TLO	CHAR,1		; TERMINATE STRING WITH CR-LF
	MOVEM	CHAR,P6WORD	; MAKE DEV NAME ASCII
	PUSHJ	16,SIXTO7
	TTCALL	3,[ASCIZ/*** PUT FRESH TAPE ON /]	; ENGLISH
	TTCALL	3,SIXBUF	; DEV NAME TYPED OUT
	IFDEF	REENT,<	;****** ONLY IF DESIRED!!
	MOVEI	CHAR,RENPT1	; SETUP FOR REEN
	MOVEM	CHAR,.JBREN
		>		; OPTIONAL CODE
	CALL	1,[SIXBIT/EXIT/]; SPECIAL EXIT
RENPT1:	TTCALL	3,[ASCIZ/*/]	; MY WISH
	TTCALL	4,CHAR		; IS YOUR COMMAND
	CAIN	CHAR,"D"
	JRST	DONE.		; GET THE NEXT TAPE READY
	CAIN	CHAR,15
	JRST	ALLOV.		; ABORT JOB
	TTCALL	11,0		; EH?
	TTCALL	3,IMPRSP
	JRST	RENPT1		; TRY AGN
DONE.:	TTCALL	11,0		; FLUSH COMMENT
	JRST	POP.		; RETURN TO PC+1
ALLOV.:	CALL	[SIXBIT/EXIT/]	; BYE BYE, SEE YOU SOON



	; GENERAL EOF DIALOGUE, CALLED WHENEVER ANY INPUT
	; ROUTINE SEES EOF ON A DIRECTORY DEVICE, AND IT
	; IS PROBABLE THAT USER WANTS TO CONCATENATE FILES


EOFDIA:	MOVE	CHAR,@0(16)
	MOVE	CHAR,6(CHAR)
	AOJL	CHAR,RETS
	TTCALL	3,[ASCIZ/*** END OF CORRECTION FILE /]	
	HRRZ	CHAR,@0(16)	; GET ADDR OF DDB
	ADDI	CHAR,2		; FIND FILENAME
	HRRZM	CHAR,P6WORD
	PUSHJ	16,SIXTO7
	TTCALL	3,SIXBUF	; TELL TTY
	MOVE	CHAR,P6WORD
	AOJ	CHAR,
	HRROM	CHAR,P6WORD
	PUSHJ	16,SIXTO7
	TTCALL	3,SIXBUF	
	TTCALL	3,[ASCIZ/ ON /]
	HRRZ	CHAR,P6WORD
	SUBI	CHAR,3
	TLO	CHAR,1
	MOVEM	CHAR,P6WORD
	PUSHJ	16,SIXTO7
	TTCALL	3,SIXBUF	; SAY WHERE
	IFDEF	REENT,<	;****** CONDITIONAL
	MOVEI	CHAR,RENPT3	; SET UP FOR REENTER
	MOVEM	CHAR,.JBREN
		>		; OPTIONAL
	CALLI	1,12		; EXIT FOR A WHILE
RENPT3:	TTCALL	3,[ASCIZ/*/]	; YES MASTER?
	TTCALL 	4,CHAR		; VERY GOOD, SIR
	CAIN	CHAR,"D"	; D FOR CONCATENATE
	JRST	RET1
	CAIN	CHAR,15		; CR FOR NO MORE
	JRST	RET2
	TTCALL	11,0		; EH?
	TTCALL	3,IMPRSP
	JRST	RENPT3
RETS:	POP	16,CHAR
	MOVEI	CHAR,0
	JRST	0(14)
RET1:	TTCALL	11,0
	TTCALL	3,RECIPR	; LET USER KNOW SOMETHING'S DOING
	JRST	POP.		; RETURN PAST PARAMETER WORD
RET2:	HRRZ	CHAR,@0(16)	; GET DDB ADDR
	TTCALL	11,0
	SOS	6(CHAR)		; MAKE STATUS -2 FOR PEOF
	POP	16,CHAR
	MOVEI	CHAR,0		; AND GIVE EOF NULL
	JRST	0(RETURN)



	; GENERAL PURPOSE DIALOGUE. RETURNS IF D IS TYPED,
	; OTHERWISE IT SEREPTITIOUSLY RESTARTS PROGRAM.


GPDIA:	SKIPE	DIASW		; DIASW SET SOMETIMES TO PREVENT 
	POPJ	16,		; DIALOGUE
	IFDEF	REENT,<		;****** OPTIONAL
	MOVEI	TEMP,REP3	; SETUP FOR REEN
	MOVEM	TEMP,.JBREN	; THUS
		>
	CALLI	1,12		; SPECIAL EXIT
REP3:	TTCALL	3,[ASCIZ/*/]	; WHAT?
	TTCALL	4,CHAR		; I HEAR YOU NOW
	TTCALL	11,0		; FLUSH
	CAIN	CHAR,15
	JRST	GETCMD		; CR - RESTART
	CAIN	CHAR,"D"
	POPJ	16,		; RETURN IF DESIRED
	TTCALL	3,IMPRSP
	JRST	REP3
GETCMD:	EXTERN	.JBSA
	HRRZ	CHAR,.JBSA
	JRST	0(CHAR)		; NO MATTER WHAT, THIS WILL RESTART PRGM
	ENTRY	ACTAB
	IFNDEF	BIGSW,<ENTRY	MCIN,UCIN>
	EXTERN	MCSPEC,UCSPEC
	EXTERN	UCIPT
	EXTERN	USEDDB
	EXTERN	BASDDB
	EXTERN	CRPERR
	EXTERN	UCIPTF
	EXTERN	ATFLAG
	EXTERN	BADDB
	EXTERN	BASIPT
	EXTERN	CAMOPT
	EXTERN	CMDDDB
	EXTERN	CMDIPT
	EXTERN	COMBUF
	EXTERN	COMCNT
	EXTERN	CONFLA
	EXTERN	CRLF
	EXTERN	FED
	EXTERN	FIRST.
	EXTERN	ID.
	EXTERN	ID.CNT
	EXTERN	INCOPT
	EXTERN	LAST.
	EXTERN	LISTB
	EXTERN	LOGDDB
	EXTERN	LOGOPT
	EXTERN	LSTDDB
	EXTERN	LSTIPT
	EXTERN	LSTOP
	EXTERN	LSTOPT
	EXTERN	MATQUO
	EXTERN	MCDDB
	EXTERN	MCIPT
	EXTERN	MRGDDB
	EXTERN	MRGIPT
	EXTERN	MRGOPT
	EXTERN	NUMLIN
	EXTERN	OLDCNT
	EXTERN	OPTION
	EXTERN	PDL
	EXTERN	PPROGW
	EXTERN	SAVACS
	EXTERN	SAVEXX
	EXTERN	SFMODE
	EXTERN	UCDDB
	EXTERN	UCIPTF
	EXTERN	USDDB
	EXTERN	USEIPT
	IFNDEF	BIGSW,	<		;**************************




	; MCIN AND UCIN ARE QUITE THE SAME.  THEY ARE CALLED BY
	; A JSP	RETURN,**IN.  A NULL IS RETURNED AT PHYSICAL EOF 
	; ONLY, ALL OTHERS ARE FLUSHED.  THE CHARACTER THEY EVENTUALLY
	; FIND WILL BE IN REGISTER CHAR


MCIN:	SKIPL	MCDDB+6		; CHANNEL OPEN?
	JRST	OPENMC		; NO, OPEN IT
MCX:	SOSG	MCIPT+2		; YES, IS BUFFER EMPTY?
	JRST	FILLMC		; THEN GO FILL IT
MCXX:	ILDB	CHAR,MCIPT+1	; PICK UP THE CHARACTER
	CHKLN	(MCIN,MCIPT,0) ;DELETE "EDIT10" SEQUENCE NUMBERS
	JUMPE	CHAR,MCX	; DUMP THE NULLS
	CAIN	CHAR,32		; ^Z??
	JRST	CTRLZ		; GO HANDLE IT
	JRST	0(RETURN)	; GO BACK TO CALLER
CTRLZ:	SKIPN	ZOP		; Z OPTION?
	JRST	0(RETURN)	; NOPE
	IN	MCCHAN,
	JRST	.-1
	JRST	FILLMC+2
FILLMC:	IN	MCCHAN,		; TRY TO FILL BUFFER	
	JRST	MCXX		; GOT DATA, SO FIRE AWAY
	GETSTS	MCCHAN,CHAR	; SOMETHING FISHY
	TRNE	CHAR,20000	; AN ERROR?
	JRST	NULLMC		; PHEW! ONLY EOF
	PUSHJ	16,IOERR	; I AM SICK
	XWD	[ASCIZ/?M.C. READ/],MCDDB
	JRST	FILLMC		; I AM WELL AGAIN
NULLMC:	MOVEI	CHAR,0		; GET A NULL
	SKIPE	FED		; IF THIS IS FED, QUIT
	JRST	0(RETURN)
	MOVE	CHAR,MCDDB	; WHAT DEVICE?
	CALLI	CHAR,4		; WHAT IS IT?
	TLNE	CHAR,200
	JRST	PTAPE1		; PAPER TAPE READER
	PUSHJ	16,EOFDIA	; TELL OPR TANK IS EMPTY
	XWD	0,MCDDB
	RELEAS	MCCHAN,		; RELEAS THE CHAN
	SETZM	MCDDB+6		; ZERO STATUS
	JRST	MCIN		; MORE TO BUSY OURSELVES WITH
PTAPE1:	PUSH	16,TEMP
	MOVEI	TEMP,MCDDB
	PUSHJ	16,PTEOF	; TELL OPR
	POP	16,TEMP		; RESTORE TEMP
	RELEAS	MCCHAN,		; RELEAS IT
	SETZM	MCDDB+6
	JRST	MCIN		; MORE TAPES READIED


	; TINY SBRT TO INITIALIZE INPUT CHANNEL


OPENMC:	MOVE CHAR,MCDDB		; GET DEV NAME
INITMC:	MOVEM	CHAR,MCSPEC+1	; PUT IN PLAIN VIEW OF MONITOR
	OPEN	MCCHAN,MCSPEC	; OPEN IF POSSIBLE
	JRST	MCERR1
NEWMC:	HRRZI	CHAR,SAVACS	; SWAP REGS 0-3
	BLT	CHAR,SAVACS+3
	HRLZI	CHAR,MCDDB+2	; WITH RETRIEVAL INFORMATION
	BLT	CHAR,3
	LOOKUP 	MCCHAN,0	; LOOKUP WITH STUFF IN REGS
	JRST	MCERR2		; IT AIN'T OUT THERE
	HRLZI	CHAR,SAVACS
	BLT	CHAR,3		; RESTORE REGS
	SETOM	MCDDB+6		; SET STATUS TO FULL THROTTLE
	INPUT	MCCHAN,		; GET FIRST BUFFER
	JRST	MCXX		; GO CRAWL OVER DATA
MCERR1:	PUSHJ	16,NOTAV.	; TELL SOMEONE DEVICE NOT AV.
	XWD	[ASCIZ/?M.C./],MCDDB
	JRST	INITMC-1	; AND TRY AGAIN
MCERR2:	PUSHJ	16,NOTFND	; NO SUCH FILE
	XWD	[ASCIZ/?CANNOT FIND M.C. FILE /],MCDDB
	JRST	NEWMC		; MAYBE THERE IS NOW



	; UCIN WORKS SAME AS MCIN, BUT INPUT FROM DIFF FILE


UCIN:	SKIPL	UCDDB+6	
	JRST	OPENUC
UCX:	SOSG	UCIPTF+2
	JRST	FILLUC
UCXX:	ILDB	CHAR,UCIPTF+1
	CHKLN	(UCIN,UCIPTF,1) ;DELETE "EDIT10" SEQUENCE NUMBERS
	JUMPE	CHAR,UCX
	CAIN	CHAR,32
	JRST	CTRLZ1
	CAIN	CHAR,14		;FORM FEED?
	AOS	BPAGNO		; YES, COUNT PAGES
	JRST	0(RETURN)
CTRLZ1:	SKIPN	ZOP

	JRST	0(RETURN)
	IN	UCCHAN,
	JRST	.-1
	JRST	FILLUC+2
FILLUC:	IN	UCCHAN,
	JRST	UCXX
	GETSTS	UCCHAN,CHAR
	TRNE	CHAR,20000
	JRST	NULLUC
	PUSHJ	16,IOERR
	XWD	[ASCIZ/?U.C. READ/],UCDDB
	JRST	FILLUC
NULLUC:	MOVEI	CHAR,0
	SKIPE	FED
	JRST	0(RETURN)
	MOVE	CHAR,UCDDB
	CALLI	CHAR,4
	TLNE	CHAR,200
	JRST	PTAPE2
	PUSHJ	16,EOFDIA	
	XWD	0,UCDDB
	RELEAS	UCCHAN,
	SETZM	UCDDB+6
	JRST	UCIN
PTAPE2:	PUSH	16,TEMP
	MOVEI	TEMP,UCDDB
	PUSHJ	16,PTEOF
	POP	16,TEMP		; RESTOR TEMP
	SETZM	UCDDB+6
	RELEAS	UCCHAN,
	JRST	UCIN
OPENUC:	SKIPE	UCDDB+6
	JRST 	NEWUC
	MOVE CHAR,UCDDB
INITUC:	MOVEM	CHAR,UCSPEC+1
	OPEN	UCCHAN,UCSPEC
	JRST	UCERR1
	SKIPE	FED
	INBUF	UCCHAN,5		; MORE ROOM FOR FED
NEWUC:	HRRZI	CHAR,SAVACS
	BLT	CHAR,SAVACS+3
	HRLZI	CHAR,UCDDB+2
	BLT	CHAR,3
	LOOKUP 	UCCHAN,0
	JRST	UCERR2
	HRLZI	CHAR,SAVACS
	BLT	CHAR,3
	SETOM	UCDDB+6
	INPUT	UCCHAN,
	JRST	UCXX
UCERR1:	PUSHJ	16,NOTAV.
	XWD	[ASCIZ/?U.C./],UCDDB
	JRST	INITUC-1
UCERR2:	PUSHJ	16,NOTFND
	XWD	[ASCIZ/?CANNOT FIND U.C. INPUT FILE /],UCDDB
	JRST	NEWUC
	>
PERIOD="."
COLON=":"



	; FCBUF PLACES ONE COMMAND STRING IN COMBUF IN ASCIZ
	; FORM, ALWAYS WITH A CR AT THE END OF THE STRING
	; THE COMMAND STRING IS C(COMCNT) CHARACTERS LONG.
	; FCBUF ALSO DOES SOME PREPROCESSING, LIKE FINDING
	; @'S AND ;'S AND MAPPING TABS TO SPACES.


BUFUL:	TTCALL	3,[ASCIZ/?GAG? TTY BUFFER FULL/]
	TTCALL	3,CRLF
	JRST	CMDPUR
FCBUF:	MOVEM	XX,SAVEXX			; SAVE REG XX
	MOVE	XX+1,[POINT 7,COMBUF-1,35]	; POINTER TO COMBUF
	MOVE	XX,[XWD COMBUF,COMBUF+1]	; TO ZERO COMBUF
	SETZM	COMBUF		; FIRST ZERO
	BLT	XX,COMBUF+30	; NOW ALL ARE ZEROES
	SETZM	COMCNT		; AND SO IS COMCNT
	AOS	COMCNT		; THERE WILL BE AT LEAST 1
	SKIPE	ATFLAG		; READING FROM DSK OR DTA?
	JRST	OTHDEV		; YES
	TTCALL 3,[ASCIZ/*/]	; NO, TYPE * AND WAIT FOR INPUT
NXCHAR:	TTCALL	4,XX		; GET A CHAR
	CAIN	XX,";"		; START OF COMMENT?
	JRST	FLUSH1		; FLUSH INPUT LINE
	AOS	COMCNT		; BOOKKEEP CHAR COUNT
	CAIN	XX,11		; TABS
	MOVEI	XX,40		; ARE CONVERTED TO SPACES
	IDPB	XX,XX+1		; PUT CHAR IN BUFFER
	SKIPE	COMBUF+30	; OVERFLOW YET?
	JRST	BUFUL		; YEP!!
	CAIN	XX,ATSGN	; WAS THAT AN @?
	JRST	ATPROC		; PROCEED TO GET COMMAND FILE
	HLRZ	XX,ACTAB(XX)	; WAS IT A BREAK CHAR? 
	JUMPE	XX,NXCHAR	; LOOP IF NOT
	MOVEI	XX,15		; IT WAS, SO PLACE CR TO STOP SCAN
	DPB	XX,XX+1
	MOVE	XX+1,[POINT 7,COMBUF-1,35]	; RESET POINTER
	TTCALL	11,0	; 
	MOVE	XX,COMCNT	; GET NUMBERS
	MOVEM	XX,OLDCNT	; FOR FLOATING ^ ROUTINE
	MOVE	XX,SAVEXX	; RESTORE XX
	POPJ	PDP,		; RETURN
FLUSH1:	TTCALL	11,0		; GET RID OF TYPED LINE
	JRST	NXCHAR-1	; AND ASK FOR MORE
ATPROC:	MOVEI	15		; REPLACE @ WITH CR
	DPB	XX+1
	MOVE	XX+1,[POINT 7,COMBUF-1,35]	; RESET POINTER
	PUSHJ	PDP,ELT		; SCAN OFF FIRST ELT
	CAIE	STOP,15		; ENDED WITH A CR?
	JRST	CMDERR		; NO, NOT LEGAL
	MOVEI	TEMP,CMDDDB	; LEGAL COMMAND RECEIVED
	PUSHJ	PDP,XFER	; TRANSFER INFO INTO DDB
	SETOM	MRGDDB		;  FUDGE SO NO ERROR REPORTED
	PUSHJ	PDP,OPSCAN	; SCAN OPTIONS
	SETZM	MRGDDB		; MAKE THE FUDGE GO AWAY
	SETOM	ATFLAG		; SET THIS SWITCH FOREVER
	MOVE	XX+1,[POINT 7,COMBUF-1,35]	; POINT TO BEGINNNING
	SETZM	COMCNT		; SET COUNT TO 0
	TTCALL	11,0		; FLUSH TTY INPUT BUFFER
OTHDEV:	JSP	RETURN,CMDIN	; GET A CHARACTER FROM CMD FILE
FLSH:	CAIN	CHAR,";"	; FLUSH COMMENTS
	JRST	FLUSH2
	CAIN	CHAR,11
	MOVEI	CHAR,40		; CONVERT TABS TO SPACES
	IDPB	CHAR,XX+1	; PACK CHARS AWAY
	AOS	COMCNT		; BOOKKEEP PROPERLY
	SKIPE	COMBUF+30
	JRST	BUFUL		; BUFFER OVERFLOW
	CAIN	CHAR,ATSGN	; DO NOT ALLOW NESTED FILES
	JRST	CMDERR
	HLRZ	CHAR,ACTAB(CHAR); FEED?
	JUMPE	CHAR,OTHDEV
	MOVEI	CHAR,15		; REPLACE WITH CR
	DPB	CHAR,XX+1
	TTCALL	11,0		; FLUSH AGAIN
	MOVE	XX,COMCNT
	MOVEM	XX,OLDCNT	; SAVE ORIGINAL CHAR COUNT FOR ^
	MOVE	XX+1,[POINT 7,COMBUF-1,35]	; RESET POINTER
	MOVE	XX,PRTOPT	; SHOULD WE PRINT NEW COMMAND?
	JUMPE	XX,.+3
	TTCALL	3,COMBUF	; PRINT IT
	TTCALL	3,CRLF		; FOLLOWED BY CRLF TO BE NEAT
	POPJ	PDP,		; RETURN TO SCANNER WITH COMMAND
FLUSH2:	JSP	RETURN,CMDIN	; FLUSH CHARACTERS
	HLRZ	CHAR,ACTAB(CHAR)
	JUMPE	CHAR,FLUSH2
	JRST	OTHDEV		; UNTIL A FEED SHOWS UP



	; STUFF IS THE HEART OF THE SCANNER. IT LOOKS AT
	; THE CHARACTERS IN COMBUF AND WHEN IT HEARS A
	; STOPPING CHARACTER LIKE :,.[] OR CR, IT STOPS
	; LEAVING A CONCATENATED IDENTIFIER IN SIXBIT FORM
	; IN REGISTER SIXBYT, AND THE STOPPING CHARACTER IN
	; REGISTER STOP.  IF A PROJ, PROG IS FOUND, IT IS 
	; STORED IN OCTAL FORM IN PPWORD. IF OPTION LETTERS 
	; ARE FOUND, THEY ARE BUFFERED UP IN OPTION AND
	; SCANNED LATER BY OPSCAN.


STUFF:		
	MOVE	REG6,[POINT 6,SIXBYT-1,35]	; SET POINTER
	MOVEI	SIXCT,6		; ONLY SIX CHARS CAN FIT 
	MOVEI	SIXBYT,0	; BLANK OUT ID HOLDER
NX1:	SOSG	COMCNT		; BUFFER EMPTY
	PUSHJ	PDP,FCBUF	; THEN FILL IT (SHOULD NEVER HAPPEN)
	ILDB	STOP,XX+1	; LOAD THE CHAR
	JRST	@ACTAB(STOP)	; DISPATCH TO PROPER ROUTINE
LETTR:	SOJL	SIXCT,NX1	; CHAR A LETTER OR DIGIT, CONCATENATE
	SUBI	STOP,40		; MAKE ASCII SIXBIT
	CAIL	STOP,100	; WORRY ABOUT LOWER CASE, TOO
	SUBI	STOP,40
	IDPB	STOP,REG6	; STUFF BYTE INTO IDENTIFIER
	JRST	NX1		; GET THE NEXT ONE
SLASH:	SOSG	COMCNT		; GET ONE OPTION CHARACTER
	PUSHJ	PDP,FCBUF
	ILDB	STOP,XX+1
	CAIGE	STOP,"0"	; IF NUMERIC,
	JRST	CMDERR
	CAILE	STOP,"9"
	JRST	STORIT		; IT SHOULD BE CONVERTED
	SUBI	STOP,60
	SOJ	STOP,
	MOVEM	STOP,NUMLIN	; AND STORED AS NUMBER OF LINES FOR MATCH
	JRST	NX1
STORIT:	CAILE	STOP,140	; OTHERWISE, IF ALPHABETIC
	SUBI	STOP,40
	IDPB	STOP,OPT	; PUT IT IN OPTION BUFFER
	JRST	NX1		; AND GET OTHER DATA
LPAR:	SOSG	COMCNT		; ( MEANS GET MANY OPTIONS
	PUSHJ	PDP,FCBUF
	ILDB	STOP,XX+1
	CAIN	STOP,")"	; AND KEEP STORING THEM UNTIL ) APPEARS
	JRST	NX1
	IDPB	STOP,OPT
	JRST	LPAR
LBRACK:	MOVEI	XX,","		; TELL OCTAL ROUTINE WHAT TO LOOK FOR
	PUSHJ	PDP,OCTAL	; SCAN AND CONVERT PROJ NO.
	HRLZM	TEMP+1,PPROGW	; PUT IN RIGHT PLACE
	MOVEI	XX,"]"		; TELL OCTAL WHAT TO EXPECT
	PUSHJ	PDP,OCTAL	; SCAN AND CONVERT PROG NO.
		HRRM	TEMP+1,PPROGW	; AND PUT IT AWAY
	JRST	STOPP		; ] ENDS ELEMENT, SO STOP SCAN
STOPP:	POPJ	PDP,		; RETURN ON RECEIPT OF STOP CHAR



	; ASCII TO OCTAL INTEGER ROUTINE.  OCTAL SCANS
	; UNTIL IT FINDS THE CHARACTER SPECIFIED IN REGISTER
	; TEMP.  THE NUMBER IT FINDS IS LEFT IN TEMP+1
	; IT WILL NOT ACCEPT ANYTHING BUT 0-7.


OCTAL:	MOVEI	TEMP+1,0	; ZERO INTEGER HOLDER
	SOSG	COMCNT
	PUSHJ	PDP,FCBUF
	ILDB	STOP,XX+1	; LOAD THE NEXT 
	CAIN	STOP,0(XX)	; IS IT THE STOPPING CHAR?
	POPJ	PDP,		; THEN RETURN
	SUBI	STOP,60		; CONVERT TO INTEGER
	JUMPL	STOP,CMDERR	; ANNOYED WITH NON-NUMERICS
	CAIL	STOP,10
	JRST	CMDERR		; OR 7,8, OR 9
	LSH	TEMP+1,3	; MULTIPLY OLD INTEGER BY 8
	ADD	TEMP+1,STOP	; ADD NEW INTEGER
	JRST	OCTAL+1		; LOOK FOR MORE



	; FLOATING ^ ROUTINE. THE ^ WILL POINT TO THE ILLEGAL
	; CHARACTER OR TO THE INCORRECT STOPPING CHARACTER FOUND
	; LATER ON.


CMDERR:	TTCALL	3,[ASCIZ/? COMMAND STRING ERROR/]	
	MOVE	TEMP,OLDCNT
	SUB	TEMP,COMCNT
	SUBI	TEMP,2		; FIND OUT HOW MANY SPACES NEEDED 
	TTCALL	3,CRLF		; SEND OUT CR-LF
	TTCALL	3,COMBUF	; THEN COMMAND
	TTCALL	3,CRLF		; THEN MORE CR-LF
	JUMPL	TEMP,.+3	; NO SPACES?
	TTCALL 1,[" "]		; SEND SPACES ONE AT A TIME
	SOJGE	TEMP,.-1	; TO BE IRRITABLE
	TTCALL 1,["^"]		; NOW THE ^
	TTCALL	3,CRLF		; AND A CR-LF
	TTCALL	11,0		; FLUSH INPUT BUFFER
	SETZM	COMCNT		; ZERO  COUNT
	SETZM	OLDCNT
	JRST	CMDPUR	; TRY FOR A GOOD COMMAND



	; ACTAB IS A DISPATCH TABLE INDEXED BY ASCII
	; VALUE OF CHARACTER.  THE RH OF EACH WORD
	; IS AN ADDRESS TO GO TO, AND THE LH IS
	; NON-ZERO IF THE CHARACTER IS ALSO A 
	; BREAK CHARACTER.  THIS TABLE IS USED BY FED
	; AND IN MANY OTHER PLACES TO FIND BREAK CHARS


ACTAB:	REPEAT	12,<NX1>	
	REPEAT	3,<XWD 100000,NX1>
	STOPP
	REPEAT	16,<NX1>
	REPEAT	4,<XWD 0,NX1>
	XWD	0,NX1
	REPEAT	7,<XWD 0,CMDERR>
	XWD	0,LPAR
	CMDERR
	LETTR
	CMDERR
	STOPP
	CMDERR
	STOPP
	SLASH
	REPEAT 12,<LETTR>
	STOPP
	CMDERR
	CMDERR
	REPEAT	3,<CMDERR>
	STOPP
	REPEAT	^D26,<LETTR>
	LBRACK
	REPEAT	3,<CMDERR>
	STOPP
	NX1
	REPEAT	^D26,<LETTR>
	REPEAT	10,<CMDERR>



	; ELT IS A HIGH LEVEL SCANNER THAT FINDS AND
	; PROCESSES ONE ELEMENT OF THE FORM
	; UNIT:FILENAME.EXT[PROJ,PROG]
	; PLACING ALL SUCH DATA IN THE PROPER FORM
	; IN LISTB, AND DOING ALL SYNTAX CHECKS AS WELL


ELT:	MOVE	LIST,[IOWD	5,LISTB]	
	SETZM	LISTB		; ZERO LISTB AND LOCAL STORAGE
	MOVE	TEMP,[XWD LISTB,LISTB+1]
	BLT	TEMP,LISTB+3
	SETZM	PPROGW
	PUSHJ	PDP,STUFF	; GET FIRST IDENTIFIER
	SKIPE	PPROGW
	JRST	ELT1
	JUMPN	SIXBYT,ELT1	; IF THERE IS ONE, IT MUST END WITH :
	CAIN	STOP,","	; IF NULL, 
	JRST	POP4		; A COMMA MEANS ELEMENT IS NULL
	CAIN	STOP,"_"
	JRST	POP4		; SAME FOR _
	CAIN	STOP,15
	JRST	POP4		; AND ALSO A CR
ELT1:
	CAIE	STOP,":"
	JRST	DEFDEV		;USE DSK AS DEFAULT
	JUMPE	SIXBYT,CMDERR	; IF ENDED BY A : BUT ID NULL, COMPLAIN
	PUSH	LIST,SIXBYT	; EVIDENTLY A DEV NAME HAS BEEN FOUND
	CALLI	SIXBYT,4	; FIND OUT IF DEV HAS DIR
	TLNN	SIXBYT,4
	JRST	NODIR		; NO DIR IMPLIES NO FILE NAME OR EXT
	PUSHJ	PDP,STUFF	; LOOK FOR FILENAME
ELT2:	CAIN	STOP,","
	JRST	POP3		; A , MEANS THAT EXT AND PROJ,PROG MISSING
	CAIN	STOP,15		; SO DOES A CR
	JRST	POP3
	CAIN	STOP,"_"	; EVEN MORESO FOR A _
	JRST	POP3
	CAIN	STOP,"]"	; THIS MEANS NO NAME.EXT, BUT P.PROG
	JRST	POP2
	CAIE	STOP,"."	; THIS INDICATES EXT FOLLOWS
	JRST	CMDERR		; ANYTHING ELSE REEKS
	JUMPE	SIXBYT,CMDERR	; A NULL FILENAME IS NO GOOD
	PUSH	LIST,SIXBYT	; BUT ANYTHING ELSE WILL DO
	PUSHJ	PDP,STUFF	; TRY FOR EXT
	CAIN	STOP,15
	JRST	POP1		; CR MEANS NO EXT OR P,PROG
	CAIN	STOP,","	; COMMA IS END OF ELT TOO
	JRST	POP1
	CAIN	STOP,"_"	 ; SO IS _
	JRST	POP1
	CAIE	STOP,"]"	; P.PROG IS ONLY THING LEFT
	JRST	CMDERR
	JUMPE	SIXBYT,CMDERR	; IF INFO IS NULL, IT HURTS
	PUSH	LIST,SIXBYT	; OTHERWISE LET IT PASS
	PUSH	LIST,PPROGW	; AND PUSH THIS ON FOR GOOD MEASURE
	PUSHJ	PDP,STUFF	; WE FOUND EVERYTHING XCPT TERMINATOR
	CAIN	STOP,"_"	; _ WILL DO
	POPJ	PDP,
	CAIN	STOP,54		; SO WILL ,
	POPJ	PDP,
	CAIE	STOP,15		; AND EVEN CR
	JRST	CMDERR		; BUT NOTHING ELSE
	POPJ	PDP,
POP1:
POP4:
POP3:	PUSH	LIST,SIXBYT	; PUT ID INTO BUFFER
	POPJ	PDP,
POP2:	PUSH	LIST,SIXBYT	; STORE ID
	AOBJN	LIST,.+1	; POINT IT PAST MISSING EXT
	PUSH	LIST,PPROGW	; PUT IN P,PROG
	PUSHJ	PDP,STUFF	; LOOK FOR ELEMENT TERMINATOR
	CAIN	STOP,"_"
	POPJ	PDP,
	CAIN	STOP,","
	POPJ	PDP,
	CAIE	STOP,15		; AS ABOVE
	JRST	CMDERR
	POPJ	PDP,
NODIR:	PUSHJ	PDP,STUFF	; IF NO DIRECTORY,
	CAIN	STOP,15
	POPJ	PDP,
	CAIN	STOP,"_"
	POPJ	PDP,
	CAIE	STOP,","	; LOOK FOR TERMINATOR
	JRST	CMDERR
	POPJ	PDP,

DEFDEV:	PUSH	LIST,[SIXBIT /DSK/]
	JRST	ELT2		;ALWAYS DSK DEFAULT AT STANFORD


	; CMDIN READS CHARACTERS FROM THE DEVICE SPECIFIED BY 
	; THE @ CONSTRUCTION. IT WORKS EXACTLY LIKE MCIN AND UCIN,
	; BUT TAKES SPECIAL ACTION ON EOF


CMDIN:	SKIPL	CMDDDB+6	
	JRST	OPENCMD
CMDX:	SOSG	CMDIPTF+2
	JRST	FILLCMD
CMDXX:	ILDB	CHAR,CMDIPTF+1
	CHKLN	(CMDIN,CMDIPTF,0);DELETE "EDIT10" SEQUENCE NUMBERS
	JUMPE	CHAR,CMDX
	JRST	0(RETURN)
FILLCMD:	IN	CMDCHAN,
	JRST	CMDXX
	GETSTS	CMDCHAN,CHAR
	TRNE	CHAR,20000
	JRST	NULLCMD
	PUSHJ	16,IOERR
	XWD	[ASCIZ/?CMD READ/],CMDDDB
	JRST	FILLCMD
NULLCMD:	MOVEI	CHAR,0
	TTCALL	3,[ASCIZ/COMMAND FILE EXHAUSTED
/]				; TELL USER EVERYTHING DONE
	SETZM	PRTOPT
	SETZM	ATFLAG
	MOVE	[XWD	CMDDDB,CMDDDB+1]
	SETZM	CMDDDB		; ZERO LOCAL OPTIONS
	BLT	CMDDDB+6	; AND PREPARE
	CALLI			; FOR TTY INPUT
	JRST	CMDPUR	; GO READ NEXT COMMAND
OPENCMD:	SKIPE	CMDDDB+6
	JRST 	NEWCMD
	MOVE CHAR,CMDDDB
INITCMD:	MOVEM	CHAR,CMDSPC+1
	OPEN	CMDCHAN,CMDSPC
	JRST 	CMDER1
	AOS CMDDDB+6
NEWCMD:	HRRZI	CHAR,SAVACS
	BLT	CHAR,SAVACS+3
	HRLZI	CHAR,CMDDDB+2
	BLT	CHAR,3
	LOOKUP 	CMDCHAN,0
	JRST	CMDER2
	HRLZI	CHAR,SAVACS
	BLT	CHAR,3
	SETOM	CMDDDB+6
	INBUF	CMDCHAN,2
	INPUT	CMDCHAN,
	MOVE	.JBFF		
	EXTERN	SAVFF
	MOVEM	SAVFF		; SAVE AND RESTORE .JBFF
	EXTERNAL .JBFF,.JBREL
	JRST	CMDXX
CMDER1:	SETOM	DIASW
	EXTERN	DIASW
	PUSHJ	16,NOTAV.
	XWD	[ASCIZ/?CMD/],CMDDDB
	SETZM	DIASW
	SETZM	ATFLAG
	SETZM	CMDDDB+6
	JRST	CMDPUR
CMDER2:	SETOM	DIASW
	PUSHJ	16,NOTFND
	XWD	[ASCIZ/?CANNOT FIND CMD FILE /],CMDDDB
	SETZM	DIASW
	SETZM	ATFLAG
	SETZM	CMDDDB+6
	JRST	CMDPUR



	; XFER TRANSFERS INFORMATION IN LISTB INTO 
	; DDB WHOSE ADDRESS IS IN REF TEMP


XFER:	MOVE	TEMP+1,LISTB		; PICK UP DEV NAME
	MOVEM	TEMP+1,0(TEMP)	; PUT IN FIRST WORD OF DDB
	HRLZI	TEMP+1,LISTB+1
	HRRI	TEMP+1,2(TEMP)
	BLT	TEMP+1,3(TEMP)	; PUT FILENAME AND EXT IN WRDS 3&4
	MOVE	TEMP+1,LISTB+3	; PUT PROJ,PROG IN WORD 5
	MOVEM	TEMP+1,5(TEMP)
	SETZM	6(TEMP)		; SET STATUS TO 0
	POPJ	PDP,		; THEN RETURN



	; GENERAL RETURN FROM THE COMMAND STRING SCANNER


CMDRTN:	POP	16,16		; RESTORE REG 16
	POPJ	16,		; GO TO CALLER




	; ACTUAL COMMAND STRING SCANNER STARTS
	; HERE.  WHEN THIS ROUTINE IS ENTERED AT CMDLVL, IT
	; WILL NOT RETURN UNTIL IT HAS ACCEPTED A SYNTACTICALLY
	; LEGAL COMMAND STRING FROM SOME SOURCE.  ENTRY SHOULD
	; BE MADE BY A PUSHJ 16,CMDLVL.  ALL DDB'S WILL BE FILLED
	; WITH THE FOLLOWING INFORMATION IF SUPPLIED:

	;	WORD		CONTENTS

	;	  1	DEVICE NAME IN SIXBIT, ZERO FILLED
	;	  2	XWD	<INPUT BUFF HDR>,<OUTPUT BUFF HDR>
	;	  3	FILENAME IN SIXBIT, ZERO FILLED
	;	  4	EXTENSION IN SIXBIT
	;	  5	XWD	<PROJECT>,<PROGRAMMER>
	;	  6	STATUS - 0  -DEVICE HAS NOT BEEN USED YET
	;			-1  -DEVICE IS READY FOR IO
	;			-2  -PHYSICAL EOF

	; A ZERO IN ANY WORD EXCEPT 2 AND 6 INDICATE THAT THE
	; INFORMATION WAS NOT SPECIFIED NOR WERE ANY
	; ASSUMPTIONS TO BE MADE


CMDPUR:	MOVE	OPT,[POINT 7,OPTION-1,35]	; INITIALIZE OPTION POINTER
	MOVE	PDP,[IOWD 5,PDL]; AND LOCAL PDP
	SETZM	COMCNT
	SETZM	OLDCNT
	MOVE	[XWD FIRST.,FIRST.+1]
	SETZM	FIRST.
	BLT	LAST.		; ZERO LOCAL STORAGE
	PUSHJ	PDP,FCBUF	; FILL COMMAND BUFFER
	SKIPN	SAVFF		; HAS .JBFF BEEN SAVED YET?
	JRST	CORSV		; THEN GO SAVE IT
	MOVE	SAVFF
	MOVEM	.JBFF
CORSV:
	MOVSI	TEMP+1,-9
	MOVE	TEMP,TAB2(TEMP+1)	; INITIALIZE DDB'S
	MOVEM	TEMP,@TAB1(TEMP+1)	; FROM DATA TABLES
	AOBJN	TEMP+1,.-2
	IFNDEF	BIGSW,<	; DON'T NEED WHOLE THING FOR COMP10!!!
	PUSHJ	PDP,ELT		; LOCAL INITIALIZATION DONE, SCAN
	CAIN	STOP,"_"	; ELT ENDED WITH _
	JRST	FUDGE3		; THEREFORE MAKE 3 ASSUMPTIONS
	CAIN	STOP,15		; CR?
	JRST	CMDERR		; VERY UNFORTUNATE
	CAIE	STOP,","	; COMMA MEANS MORE FOLLOWS
	JRST	CMDERR		; ANYTHING ELSE IS $%&*!
	MOVSI	TEMP+1,-3	; REPLACE ALL ZEROES IN LISTB
	SKIPN	LISTB+2		; NULL MRG EXT?
	SETOM	LISTB+2		; SET TO -1 FOR FUDGE
TST1:	SKIPE	LISTB(TEMP+1)
	JRST	CKFIN1
	MOVE	TEMP,MRGFDG(TEMP+1)	; WITH ASSUMED VALUES
	MOVEM	TEMP,LISTB(TEMP+1)	; AS THE SPECS REQUIRE
CKFIN1:	AOBJN	TEMP+1,TST1
	MOVEI	TEMP,MRGDDB	; LEFTMOST ELEMENT ALWAYS
	PUSHJ	PDP,XFER	; SPECIFIES INFO FOR MRGDDB
	PUSHJ	PDP,ELT		; GET NEXT ELEMENT
	CAIN	STOP,"_"	; NO LIST OR LOG DESIRED
	JRST	FUDGE2
	CAIN	STOP,15
	JRST	CMDERR		; NOT ENOUGH TO PLAY WITH
	CAIE	STOP,","	; LIST DEV SPECIFIED?
	JRST	CMDERR
	MOVSI	TEMP+1,-3
TST2:	SKIPE	LISTB(TEMP+1)
	JRST	CKFIN2
	MOVE	TEMP,LSTFDG(TEMP+1)
	MOVEM	TEMP,LISTB(TEMP+1)	; MAKE ASSUMPTIONS
CKFIN2:	AOBJN	TEMP+1,TST2
	MOVEI	TEMP,LSTDDB	; TRANSFER INFO TO LSTDDB
	PUSHJ	PDP,XFER
	PUSHJ	PDP,ELT		; AND LOOK FOR LOG SPECS
	CAIN	STOP,15
	JRST	CMDERR		; STILL NOT ENOUGH INFO
	CAIE	STOP,"_"	; MORE THAN 3 DEV ON LEFT OF _?
	JRST	CMDERR		; THAT'S A NO NO
	MOVSI	TEMP+1,-3
TST3:	SKIPE	LISTB(TEMP+1)
	JRST	CKFIN3
	MOVE	TEMP,LOGFDG(TEMP+1)
	MOVEM	TEMP,LISTB(TEMP+1)	; MAKE ASSUMPTIONS FOR LOG DEV
	CKFIN3:	AOBJN	TEMP+1,TST3
	MOVEI	TEMP,LOGDDB	; AND TRANSFER INFO
	PUSHJ	PDP,XFER	; TO LOGDDB
	JRST	RTSIDE		; PROCESS THE RIGHT SIDE OF _
FUDGE3:	SKIPN	LISTB+2
	SETOM	LISTB+2		; FUDGE NULL MRG EXT
	MOVSI	TEMP+1,-3
TST4:	SKIPE	LISTB(TEMP+1)
	JRST	CKFIN4
	MOVE	TEMP,MRGFDG(TEMP+1)	; FUDGE SPECS FOR MRGDDB
	MOVEM	TEMP,LISTB(TEMP+1)
CKFIN4:	AOBJN	TEMP+1,TST4
	MOVEI	TEMP,MRGDDB
	PUSHJ	PDP,XFER
	MOVE	TEMP,[XWD LSTFDG,LISTB]
	BLT	TEMP,LISTB+3
	MOVEI	TEMP,LSTDDB
	PUSHJ	PDP,XFER		; DITTO FOR LSTDDB
FDGLST:	MOVE	TEMP,[XWD LOGFDG,LISTB]	; AND LOGDDB
	BLT	TEMP,LISTB+3
	MOVEI	TEMP,LOGDDB
	PUSHJ	PDP,XFER
	JRST	RTSIDE		; GO DO RIGHT SIDE 
FUDGE2:	MOVSI	TEMP+1,-3
TST5:	SKIPE	LISTB(TEMP+1)
	JRST	CKFIN5
	MOVE	TEMP,LSTFDG(TEMP+1)
	MOVEM	TEMP,LISTB(TEMP+1)	; FUDGE LIST SPECS
CKFIN5:	AOBJN	TEMP+1,TST5
	MOVEI	TEMP,LSTDDB
	PUSHJ	PDP,XFER
	JRST	FDGLST>



	; PREVIOUS CODING NEEDED ONLY FOR CAM. THE 
	; FOLLOWING CODING IS USEFUL ONLY FOR 10K
	; VERSION OF COMPAR WITH BIG BUFFERS, ETC.

	IFDEF	BIGSW,<

	PUSHJ	PDP,ELT		; SCAN FIRST THING
	CAIE	STOP,"_"	; MUST BE ALONE ON THE LEFT
	JRST	CMDERR		; ELSE I AM ANNOYED
	MOVEI	TEMP,MRGDDB	; WHERE TO PUT INFO
	PUSHJ	PDP,XFER	; HERE IT GOES
	PUSHJ	PDP,ELT		; GET MORE
	CAIE	STOP,","	; MUST BE MORE
	JRST	CMDERR		; ELSE STRING IS FOR BIRDS
	MOVEI	TEMP,BASDDB	; HERE'S WHERE IT GOES
	PUSHJ	PDP,XFER	; AUF WEIDER SEHEN
	PUSHJ	PDP,ELT		; MORE OF SAME
	CAIE	STOP,15		; MUST BE LAST ON LINE
	JRST	CMDERR		; OR OPR IS DIZZY
	MOVEI	TEMP,USDDB
	PUSHJ	PDP,XFER
	PUSHJ	PDP,OPSCAN	; PICK OFF OPTIONS
	MOVE	TEMP,BASDDB
	CAME	TEMP,USDDB	; MAKE SURE SOME NUT DOES NOT
				; TRY TO READ TWO FILES OFF 
				; THE SAME TAPE
	JRST	CMDRTN		; APPARENTLY NOT
	CALLI	TEMP,4		; DSK CAN PERFORM THE FEAT
	TLNE	TEMP,200000	; WHAT  IS IT?
	JRST	CMDRTN		; OK IT'S A DSK
	TTCALL	3,[ASCIZ/? TWO INPUT FILES FROM SAME UNIT
DOESN'T MAKE IT WITH THE MONITOR
/]
	JRST	CMDPUR		; DUMBELL>

TAB1:	MCDDB+1			; THINGS IN THIS TABLE
	UCDDB+1
	USEDDB+1
	BASDDB+1
	MRGDDB+1
	LOGDDB+1
	LSTDDB+1
	CMDDDB+1
	NUMLIN
	CRPERR
TAB2:	MCIPT			; ARE SET TO THE VALUES IN THIS TABLE
	UCIPT
	USEIPT
	BASIPT
	XWD	MRGOPT,MRGIPT
	XWD	LOGOPT,0
	XWD	LSTOPT,LSTIPT
	CMDIPT
	2
		5
	IFNDEF	BIGSW,<
DEFINE	X(A)
<	SIXBIT/A/	>
MRGFDG:	0			; HERE ARE THE ASSUMPTIONS
	X(MERCOR)		; FOR ANY MISSING INFORMATION
	X(C01)
	0
LSTFDG:	0
	X(LIST)
	X(L01)
	0
LOGFDG:	X(TTY)
	X(LOG)
	X(L01)
	0
RTSIDE:	SKIPE	FED
	JRST	CRGNLY		; IF FED IS RUNNING, DISPATCH HERE
	PUSHJ	PDP,ELT		; GET AN ELEMENT
	CAIE	STOP,","	; IT MUST NOT BE THE LAST
	JRST	CMDERR
	SKIPN	LISTB		; IF DEV NOT SPECIFIED
	JRST	CRGNLY		; ELEMENT MUST BE NULL
	SKIPN	LISTB+1		; IF FILENAME NOT SPECIFIED,
	SETOM	SFMODE		; WE ARE NOT IN SINGLE FILE MODE
	MOVEI	TEMP,BADDB	; IF THE FIRST ELT NOT NULL
	PUSHJ	PDP,XFER	; THE SPECS GO INTO BASDDB
	PUSHJ	PDP,ELT		; GET USDDB SPECS
	CAIN	STOP,15		; IF COMMAND TERMINATED
	JRST	COMNLY		; COMPAR ONLY IS TO BE RUN
	CAIE	STOP,","	; IF NOT, CAM IS RUNNING
	JRST	CMDERR
	PUSHJ	PDP,CKMODE	; CHECK IF SINGLE OR MULTIFILE MODE
	MOVEI	TEMP,USDDB	; OK
	PUSHJ	PDP,XFER	; TRANSFER INFO TO DDB
	AOS	CAMOPT		; SET CAMOPT TO CAM TOGETHER
GTMCOR:	PUSHJ	PDP,ELT		; NOW GET MANUF. CORR. SPECS
	CAIE	STOP,15		; WHICH MUST TERMINATE STRING
	JRST	CMDERR
	SKIPN	LISTB+1
	JRST	.+3
	SKIPN	LISTB+2
	SETOM	LISTB+2
	MOVSI	TEMP+1,-3
TST6:	SKIPE	LISTB(TEMP+1)
	JRST	CKFIN6
	MOVE	TEMP,MCFDG(TEMP+1)
	MOVEM	TEMP,LISTB(TEMP+1); MAKE ASSUMPTIONS
CKFIN6:	AOBJN	TEMP+1,TST6
	MOVEI	TEMP,MCDDB
	PUSHJ	PDP,XFER
	SKIPE	SFMODE
	JRST	.+5
	SKIPG	CAMOPT		; IF CAM RUNNING AND SINGLE FILE TRUE
	JRST	.+3
	TTCALL	3,[ASCIZ/? WRONG MODE FOR CAM
/]
	JRST	CMDERR
	PUSHJ	PDP,OPSCAN	; SCAN OPTIONS
	MOVE	XX,MCDDB
	SKIPE	FED
	JRST	UCOMP		; IF FED, SEE THAT UCIN&MCIN
	SKIPGE	CAMOPT		; USE DIFFERENT DEVICES
	JRST	UCOMP		; TO PREVENT READING 2 FILES FROM
	CAMN	XX,USDDB	; SAME DECTAPE
	JSP	XX+1,DUPCHK	; WITH DISASTEROUS RESULTS!
	CAMN	XX,BADDB	; PERFORM CHECK ON ALL INPUTS
	JSP	XX+1,DUPCHK	; IF THE NAME IS THE SAME
	MOVE	XX,USDDB	; AND THE DEVICE IS NOT
	CAMN	XX,BADDB	; DSK, THE STRING IS IN ERROR
	JSP	XX+1,DUPCHK
	JRST	.+3
UCOMP:	CAMN	XX,UCDDB
	JSP	XX+1,DUPCHK
 	JRST	CMDRTN
DUPCHK:	CALLI	XX,4
	TLNE	XX,200000
	JRST	(XX+1)
	TTCALL	3,DUPDEV
	JRST	CMDPUR	; IS NOT LEGAL FOR INPUT UNITS
DUP1:	CALLI	TEMP,4
	TLNE	TEMP,200000
	JRST	DUPOK1
	TTCALL	3,DUPDEV
	JRST	CMDPUR
COMNLY:	PUSHJ	PDP,CKMODE	; COMPAR ONLY
	MOVE	TEMP,LISTB
	CAMN	TEMP,BADDB
	JRST	DUP1
DUPOK1:	MOVEI	TEMP,USDDB
	PUSHJ	PDP,XFER
	PUSHJ	PDP,OPSCAN	; SCAN OPTIONS
	JRST	CMDRTN		; RETURN
CRGNLY:	PUSHJ	PDP,ELT		; COMERGE ONLY
	CAIE	STOP,","
	JRST	CMDERR
	SKIPN	LISTB
	JRST	CMDERR
	SKIPN	LISTB+1
	SETOM	SFMODE		; SET MULTIFILE MODE
	MOVEI	TEMP,UCDDB
	SETOM	CAMOPT		; SET CAMOPT TO COMERGE ONLY
	PUSHJ	PDP,XFER
	JRST	GTMCOR		; GET MANU. CORR. DEV
MCFDG:	X(PTR)			; OTHER ASSUMPTIONS TO BE MADE
	X(DECCOR)
	X(C01)
	0
			>	; PREVIOUS CODE NOT NECESSARY
				; FOR 10K COMPAR


	; OPSCAN SCANS THE CHARACTERS DEPOSITED
	; BY STUFF IN OPTION.  IT PICKS UP THE ID FOR
	; CORRECTION LINES FOR COMPAR AND SETS SWITCHES
	; AND PERFORMS MISCELLANEOUS CLEANUP OPERATIONS


OPSCAN:	MOVE	[BYTE (7)11,11,11,11,11]	
	MOVEM	ID.-1		; PUT TABS IN THE ID BUFFER
	SETZM	LSTTY		; CLEAR THIS
	SETZM	LOGTTY		; AND THAT
	AOS	MRGDDB+3	; FIND OUT IF MRG EXT NUL
	SKIPE	MRGDDB+3	; ZERO MEANS YES
	SOS	MRGDDB+3	; RE DECREMENT BY 1
	AOS	MCDDB+3
	SKIPE	MCDDB+3
	SOS	MCDDB+3
	SETZM	OLDCNT
	SKIPN	MRGDDB		; IF NO MRG DEV SPEC, FATAL ERR
	JRST	CMDERR
	SKIPE	LSTDDB
	SETOM	LSTOP		; FIND OUT OF LST DEV SPECIFIED
	MOVE	[SIXBIT/TTY/]
	SKIPN	LSTDDB
	MOVEM	LSTDDB		; ENSURE TTY OUTPUT IF IT WASN'T
	MOVE	CHAR,LOGDDB
	PUSHJ	16,JOBTTY	; IS LOG DEV TTY?
	SETOM	LOGTTY
	JFCL
	JFCL
	MOVE	CHAR,LSTDDB
	PUSHJ	16,JOBTTY	; IS LST DEV A USER TTY?
	SETOM	LSTTY
	JFCL
	JFCL
	MOVE	TEMP,[POINT 7,OPTION-1,35]	; INIT POINTER TO OPTIONS
	EXTERNAL	ASTRFL
	MOVE	CHAR,LSTDDB+2
	CAMN	CHAR,[SIXBIT/*     /]
	SETOM	ASTRFL		; SET SPECIAL SWITCH
OPCHR:	ILDB	CHAR,TEMP	; LOAD FIRST CHAR
	JUMPE	CHAR,[POPJ	PDP,]	; NULL MEANS NONE LEFT
	SKIPE	MATQUO		; LOOKING FOR MATCHING QUOTES?
	JRST	ID.PUT		; YES, STORE ID AWAY
	CAIN	CHAR,"H"
	SETOM	HEADSW
	EXTERN	HEADSW
	CAIN	CHAR,"I"
	SETOM	INCOPT		; NO INCREMENTING EXTENSIONS
	CAIN	CHAR,"Z"
	SETOM	ZOP
	CAIN	CHAR,"P"
	SETOM	PRTOPT		; PRINT COMMANDS AS THEY ARE READ
	CAIN	CHAR,"T"	; TIME MSG FOR FED?
	SETOM	TSW		; SET FLAG
	CAIN	CHAR,"X"	; PRINT EXCEPTIONS ONLY IN FED?
	SETOM	XSW		;YES, INDEEDY
	CAIE	CHAR,42
	JRST	OPCHR
	SETOM	MATQUO		;  " FOUND, SO LOOK FOR MATCHING

	MOVE	TEMP+1,[POINT 7,ID.-1,35]
	MOVEI	CHAR,11		; PUT A TAB IN THE ID
	IDPB	CHAR,TEMP+1
	JRST	OPCHR		; LOOK FOR MORE TO PACK AWAY
ID.PUT:	CAIE	CHAR,42
	JRST	PUTIT
	SETZM	MATQUO
	JRST	OPCHR		; IF THE MATCHING QUOTE FOUND, SCAN ANEW
PUTIT:	AOS	XX,ID.CNT
	CAIG	XX,3		; ENSURE ONLY 3 CHARACTERS IN ID
	IDPB	CHAR,TEMP+1
	JRST	OPCHR		; GET MORE



	; CHECKS THAT USER DOES NOT CONFUSE SINGLE AND
	; MULTIFILE MODES


CKMODE:	SKIPE	LISTB+1	
	JRST	TMODE1
	SKIPL	SFMODE
	JRST	CMDERR
	POPJ	PDP,
TMODE1:	SKIPE	SFMODE
	JRST	CMDERR
	POPJ	PDP,
	END;			THAT'S ALL