	.TITLE	EDI.NN - RSX MULTI EDITOR - ASSEMBLY PARAMETERS
/
/  22 SEP 76 (002; PDH) DELETE CONDITIONALS AND UNWANTED CODE
/  21 SEP 76 - PAUL HENDERSON
/
	.DEC
RSX=0
COPY=5		/ IT WOULD BE NICE TO BE ABLE TO DEFINE COPY=NN
		/ FOR EDI.00 AND EDI.01, BUT THIS IS NOT POSSIBLE
		/ BECAUSE OF THE WAY THE EDITOR IS WRITTEN.  SINCE
		/ WE HAVE ONLY TERMINAL FACILITIES FOR 00 TO 04,
		/ DEFINE COPY=5+NN FOR 00 & 01, AND COPY=NN FOR
		/ 02, 03, 04.
DAT15=50	/ DAT15=50+NN (DISK SCRATCH FILE)
DAT14=40	/ DAT14=40+NN (FILE INPUT/OUTPUT)
DAT3=30		/ DAT3=30+NN (TERMINAL I/O)
DAT2=DAT3	/ SAME TERMINAL
	.OCT
/
	.TITLE EDIT15  ( EDIT#034   12-26-73)
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO 
/ CHANGE WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED
/ AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED TO THE PURCHASER UNDER A LICENSE FOR USE ON
/ A SINGLE COMPUTER SYSTEM AND CAN BE COPIED (WITH
/ INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR 
/ USE IN SUCH SYSTEM, EXCEPT AS MAY OTHERWISE BE PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
/COPYRIGHT 1971,1972,1973 DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
/PDP-9/15 TEXT EDITOR, VERSION 20A.
/
/LAST EDIT NUMBER 033   DATE OF LAST EDIT DEC 26,1973
/E. MARISON
/R. MCLEAN - RSX-15
/M. HEBENSTREIT
/
/
/
///
///	THIS SOURCE CAN PRODUCE THE FOLLOWING VERSIONS
///
/ASSEMBLY PARAMETER ASSIGNMENTS:
/
/  III.	FOR THE RSX VERSION
/	A. RSX=0
/	B. DATN=X WHERE N CORRESPONDS TO THE ADVANCED MONITOR
/		DATSLOTS AND X IS THE LUN SLOT
/	D. COPY=N WHERE N IS THE COPY NUMBER OF THIS EDITOR
/		IN A MULTIPLE EDITOR SYSTEM. DEFAULT IS 1.
/		COPY*2 IS ADDED TO THE TEMPORARY FILE NAMES
/		TO ELIMINATE SIMULTANEOUS TEMPORARY FILE REFERENCES.
/		COPY=2 USES ".TFIL3 EDT" AND ".TFIL4 EDT" TEMP FILES.
/
BUFLEN=46			/READ-WRITE LINE BUFFER SIZE.
X10=10	/AUTO XR 10
ECLA=641000
	.IFUND	DAT15
	.END	DAT15 MUST BE DEFINED
	.ENDC
	.IFUND	DAT14
	.END	DAT14
	.ENDC
	.IFUND	DAT10
DAT10=24		/ SECONDARY INPUT DEFAULTS TO LUN 20
	.ENDC
	.IFUND	DAT3
	.END	DAT3
	.ENDC
	.IFUND	DAT2
	.END	DAT2
	.ENDC
	.IFUND COPY
	.END	COPY
	.ENDC
	.TITLE INITIALIZE VARIABLES,INPUT & EDIT MODE PROC.
/
LINSIZ=BUFLEN-2/2*5+1	/MAXIMUM CHARACTERS PER LINE.
QUESMK=77			/QUESTION MARK.
NUM	0		/TEMP STORAGE
BEGIN	JMP SETBNK	/SET EPC BITS FOR CURRENT BANK.
	LAC	(DAT15)
	JMS	ATTACH
	LAC	(DAT14)
	JMS	ATTACH
	LAC NOPLIT	/CLEAR EXIT SWITCHS
	DAC EXITSW
	DAC EXITRQ
	DZM INPSW
	DZM OUTPSW	/SET OUTPUT AND
/	DZM VERISW	/VERIFY TO "ON". LEAVE ALONE FOR TV
ALTMOD	175\777777	/1'S COMPLEMENT ALT MODE TERMINATOR.
	DAC BRFSW		/SET BRIEF TO OFF.
	DAC OPEN		/ALLOW USE OF OPEN AND
	DAC SAVESW	/TURN OFF SAVE OPTION.
	DAC OUTSW1	/INDICATE NOTHING IN OUTPUT FILE.
	DAC NAMSW		/INDICATE NO NAME PRESENT.
	LAC JMSCLS	/PERMIT CLOSE SEQUENCE TO USE
	DAC CLOSE1	/SUBROUTINE CLSOUT.
	LAC	(DAT15)	/SET UP OUTPUT LUN SLOT
	DAC OUTPCL	/INITIAL OUTPUT DAT SLOT IS -15.
	LAC	(DAT14)	/SET UP INPUT LUN SLOT
	DAC INPTCL	/SET UP INPUT DAT SLOT.
	DZM DIRSW		/INITIAL TRANSFER DIRECTION (READ -14, WRITE -15).
	LAC TFILE1	/SET UP DEFAULT EDIT FILE NAME (.TFIL2 EDT).
	DAC INNAME	/..
	LAC TFILE1+1	/..
	AAC COPY+COPY-2	/ONE TIME CODE TO MODIFY TEMP FILE NAMES
	DAC TFILE1+1	/TO ELIMINATE SIMULTANEOUS REFERENCES
			/IN A MULTIPLE EDITOR SYSTEM
	DAC INNAME+1	/..
	ISZ INNAME+1	/MAKE IT .TFIL2.
	LAC EDNAM		/"EDT"
	DAC INNAME+2	/EXTENSION FOR DEFAULT FILE NAME.
FSTFL1	JMS IOINIT
	JMS FSTAT		/GO SEE IF .TFIL1 EDT IS PRESENT.
	XCT TFILE1	/BIT 0 = 1 MEANS CHECK THE OUTPUT DEVICE.
	DAC LOOPCT	/SAVE RESULTS OF FSTAT.
	LAW EDTMES
	JMS TYPOUT	/PRINT "PGM NAME VNN".
	LAC LOOPCT	/PICK UP RESULTS OF PREVIOUS FSTAT.
	SNA		/FILE MAY BE PRESENT.
	JMP FND6		/NOT FOUND, OK.
TFIFND	SAD FENCE		/TEMP FILE FOUND, IS OUTPUT DEVICE FILE-STRUCTURED?
	JMP FND6		/NO, THEN GO START UP AS USUAL.
	JMS	ATTTY	/ATTACH INPUT OUTPUT TTY'S
	LAW TFILE1	/YES, INFORM USER OF DIFFICULTY.
	JMS TYNAME	/"FILE .TFIL1 EDT"
	LAW TWOFIL	/COMPLETE THE COMMENT.
	JMS TYPOUT	/"IS PRESENT ON OUTPUT DEVICE."
	LAW TWOFL0	/TYPE NEXT LINE OF COMMENT.
	JMS TYPOUT	/"PLEASE DELETE OR RENAME IT."
	JMS	DETTY	/DETACH TTY'S
	JMP FND6		/GO READ A CONTROL REQUEST (SHOULD BE DELETE OR RENAME).
QUITA	0
/TURN ON INPUT MODE.
INPUT	JMS	ATTTY	/ATTACH INPUT OUTPUT TTY'S
	LAW	INPTM	/TYPE CONTROL MODE NOW IN EFFECT
	JMS TYPOUT	/"INPUT"
/MAIN PROCESSING LOOP FOR INPUT MODE.
RDNPUT	LAW TYLINE	/PUT LINE TO BE TYPED IN TYLINE.
	JMS TYPEIN	/THEN GO READ THE KEYBOARD.
	LAC	QUIT	/ROLE OF QUIT REVERSED 1= QUIT
	SZA		/IS IT QUIT?
	JMP TTRS		/IF SO, GO RETURN CARRIAGE, CHANGE MODES.
	JMS UNPACK	/NORMAL INPUT LINE, GO UNPACK IT.
EDLAD1	TYLINE		/FROM TYLINE...
EDLADR	EDLIN		/TO EDLIN.
	SNA		/LENGTH COMES BACK IN AC.
	JMP EDIT1A	/LINE IS EMPTY (JUST CR ISSUED), CHANGE MODES.
	ADD EDLADR	/START OF LINE PLUS LENGTH.
	DAC	QUITA	/ADDRESS OF TERMINATOR
	LAC*	QUITA
	SAD ALTMOD	/ALT MODE?
	JMS TYPRTN	/YES, GO RETURN CARRIAGE.
	JMS PUTLIN	/PUT AWAY THE PREVIOUS CURRENT LINE.
	LAC EDLADR	/NORMAL RETURN; GET ADDRESS OF CURRENT-LINE BUFFER.
	DAC NXTPTR	/SET UP NEXT-CHARACTER POINTER.
	DAC INPSW
	DZM LENGTH	/ZERO TOTAL CHARACTERS IN CURRENT LINE.
	LAC SKPLIT	/SET EXIT SWITCH
	DAC EXITSW
	JMS APPEND	/THEN GO MOVE TYPED INPUT LINE TO INLINE ARRAY.
	JMP RDNPUT	/READ ANOTHER INPUT LINE.
/TURN ON EDIT MODE.
EDIT1A=.
EDIT	JMS	DETTY	/DETACH TTY ON ENTRY TO EDIT MODE
	LAW	EDTM	/TYPE CONTROL-MODE INDICATION.
	JMS TYPOUT	/"EDIT"
	JMP FND6		/GO TYPE A RIGHT ANGLE BRACKET.
/MAIN PROCESSING LOOP FOR EDIT MODE.
RDLIN	DZM QUIT		/INDICATE NO FILE PROCESSING GOING ON NOW.
	DZM	NOPKSW	/RESET NO REPACK SW
	LAW TYLINE	/READ NEXT REQUEST FROM TELETYPE.
	JMS TYPEIN	/INPUT-LINE AREA.
	JMS	DETTY	/DETACH TTY AFTER READING A LINE
	DZM BOTTSW	/INDICATE BOTTOM NOT IN PROCESS (GETLIN)
	JMS UNPACK	/UNPACK THE TYPED LINE.
ADR002	TYLINE		/FROM TYLINE...
	EDLIN		/...TO EDLIN.
	SNA		/SKIP IF TOTAL CHARS IN LINE .G. 0.
	JMP INPUT		/CARRIAGE RETURN ONLY, CHANGE MODE.
	TAD EDLADR	/CHECK TERMINATOR
	DAC NUM
	LAC* NUM
	SAD ALTMOD	/IF AN ALTMODE GIVE A <CR-LF>
	JMS TYPRTN
	LAC EDLADR	/EDLADR POINTS TO EDLIN (WHERE TYPED LINE IS).
	DAC NXTPTR	/SET INITIAL POINTER IN NXTCHR.
	JMS GETCOM	/GO EXTRACT CONTROL WORD FROM INPUT LINE.
  
/DECODE WHAT IS PRESUMED TO BE AN EDITING CONTROL WORD (IN CWD ARRAY)
/AND TAKE ACTION IF LEGAL. IF NOT, IGNORE INPUT LINE, COMPLAIN ON
/TELEPRINTER, AND REENTER EDIT MODE READ SEQUENCE AT FND6.
  
DECODE	LAW CWDTBL-TABEND	/TOTAL ENTRIES IN CWD TABLE (2'S COMPLEMENT).
	DAC LOOPCT	/SET UP COUNT OF CONTROL WORDS TO EXAMINE.
	LAC CWDTOP	/GET BEGINNING OF CONTROL WORD TABLE.
CWDLP1	DAC SCN1		/SET UP NEXT CALL TO UNPACK.
	JMS UNPACK	/UNPACK NEXT CONTROL WORD.
SCN1	0		/MODIFIED EACH TIME TO POINT TO NEW ENTRY.
ADR003	TYLINE		/USE TYLINE AS OUTPUT ARRAY.
	JMS SCAN		/COMPARE INPUT COMMAND WITH CURRENT ENTRY.
CWDLIT	CWD		/TYPED COMMAND IS IN CWD...CWD+7.
	TYLINE		/CURRENT TABLE ENTRY HAS JUST BEEN UNPACKED INTO TYLINE.
SKPLIT	SKP		/NO MATCH.
	SKP		/END STRING 1.
	JMP CWDLP2	/FAILED COMPARE, GET NEXT TABLE ENTRY.
	LAC* STR2		/POSSIBLE MATCH, GET NEXT WORD FROM TYLINE.
	SMA!CLL!CML	/MATCH IF NEXT WORD IN TYLINE IS NEGATIVE...
	SKP!CLA!RAL	/...OR IF TOTAL CHARS IN CWD .E. 1.
	JMP CWDISP	/FULL CONTROL WORD, GO DISPATCH.
	SAD NCHARS	/CHECK FOR ABBREVIATION (AC .E. 1 NOW).
	JMP CWDISP	/NCHARS .E. 1, GO DISPATCH.
CWDLP2	LAW -1		/MATCH FAILED, SET UP NEW ARG TO UNPACK...
FENCE=CWDLP2
	TAD* C12		/...USING A POINTER INTERNAL TO UNPACK.
	ISZ LOOPCT	/COUNT ENTRIES IN CONTROL WORD TABLE.
	JMP CWDLP1	/MORE TO DO, CONSIDER NEXT ENTRY.
/UNRECOGNIZED CONTROL WORD COMES HERE.
ILLCWD	LAC BRFSW		/IS BRIEF MODE IN EFFECT?
	SMA		/NOT IF BRFSW IS NEGATIVE.
	JMP TYQUES	/BRIEF MODE ON, JUST PRINT A QUESTION MARK.
	JMS	ATTTY	/ATTACH TTY WHILE PRINTING SINGLE CHARACTERS
	LAW ERREQM	/BRIEF MODE IS OFF, PRINT FULL ERROR MESSAGE.
	JMS TYPOUT	/"NOT A REQUEST:"
	LAW 40		/PRINT A LEADING
	JMS TYONCH	/BLANK CHARACTER.
	JMS PACK		/REPACK INPUT LINE.
ADR004	EDLIN		/FROM HERE.
	TYLINE		/TO HERE.
	LAW TYLINE	/PRINT OFFENDING INPUT LINE.
	JMS TYPOUT	/..
	JMS	DETTY	/DETACH FROM TTY
	JMP FND6		/GO BACK TO READ SOME MORE.
TYQUES	LAW QUESMK	/BRIEF IS ON, GET QUESTION MARK.
	JMS TYONCH	/GO TYPE IT OUT.
	JMS TYPRTN	/PRINT CARRIAGE RETURN, LINE FEED.
	JMP FND6		/READ NEXT COMMAND.
CWDISP	LAC TABEND	/GET END OF DISPATCH TABLE.
	TAD LOOPCT	/CALCULATE OUR CURRENT POSITION IN IT.
	ADD XCTZRO	/INSERT AN XCT AS TABLE REFERENCE.
	DAC CWDXCT	/GIVE TO DISPATCHER.
/GO TO SERVICE SECTION FOR THIS CONTROL WORD.
CWDXCT	XX		/RESULTS IN XCT OF PROPER TABLE ENTRY (JMP OR JMS).
	JMP FND4		/IN CASE TABLE ENTRY WAS A JMS.
QUIT	0	/QUIT = 0 COMMAND PROCESSING IS IN PROGRESS
	.TITLE CONTROL WORD AND DISPATCH TABLE
/TABLE OF CONTROL WORDS FOR COMPARE AGAINST TYPED EDIT COMMANDS.
/CONTROL WORDS ARE LIMITED TO SEVEN CHARACTERS IN LENGTH.
CWDTOP	.-1
	.ASCII 'PRINT'<15>
	.LOC .-1
C104	104
	.ASCII 'NEXT'<15>
	.ASCII 'FIND'<15>
	.ASCII 'LOCATE'<15>
	.LOC .-1
C122	122
	.ASCII 'LC'<15>
	.ASCII 'GET'<15>
	.ASCII 'INSERT'<15>
	.LOC .-1
C111	111
	.ASCII 'DELETE'<15>
NAMSW=.-1		/0, FILE NAME GIVEN IN OPEN REQUEST; -1, NO NAME GIVEN.
	.ASCII 'OVERLAY'<15>
	.ASCII 'CHANGE'<15>
NAMSW1=.-1
	.ASCII 'CONVERT'<15>
	.ASCII 'VERIFY'<15>
STR1=.-1
	.ASCII 'TOP'<15>
	.ASCII 'BOTTOM'<15>
STR2=.-1		/POINTER FOR CHANGE REQUEST.
	.ASCII 'BRIEF'<15>
NCHARS=.-1
	.ASCII 'RETYPE'<15>
	.ASCII 'APPEND'<15>
CURPUT=.-1
	.ASCII 'KEEP'<15>
	.ASCII 'RENEW'<15>
	.LOC .-1
C77	77
CURGET
	.ASCII 'MODIFY'<15>
DIRSW
	.ASCII 'OUTPUT'<15>
ERRSW=.-1
	.ASCII 'EXIT'<15>
	.ASCII 'OPEN'<15>
	.ASCII 'CLOSE'<15>
BTEMP=.-1		/GETNUM: TEMPORARY STORAGE.
	.ASCII 'ICLOSE'<15>
	.EJECT
/TABLE OF DISPATCHERS TO CONTROL-WORD SERVICE SECTIONS. ENTRIES ARE
/EITHER "JMP"S OR "JMS"S AND ARE REFERENCED BY AN XCT (AT CWDXCT)
/OF THE APPLICABLE TABLE LOCATION AFTER COMMAND DECODING. NOTE THAT
/ENTRIES ARE SO ORDERED AS TO CORRESPOND WITH ASCII ENTRIES IN TABLE
/OF CONTROL WORDS ABOVE. FOR BOTH TABLES, NOTE THAT ANY CONTROL WORD
/WHICH CAN LEGALLY BE ABBREVIATED MUST PRECEDE ANY OTHER CONTROL WORD
/HAVING THE SAME INITIAL CHARACTER (THUS "BOTTOM" PRECEDES "BRIEF").
		/MAY COMMAND BE ABBREVIATED?
CWDTBL	JMP PRINT		/YES -- "P"
	JMP NEXT		/YES -- "N"
	JMP FIND		/YES -- "F"
	JMP LOCATE	/YES -- "L"
	JMP LNCONV	/NO!  //LINE CONVERT
	JMP GET		/YES -- "G"
	JMP INSERT	/YES -- "I"
	JMP DELETE	/YES -- "D"
	JMP OVRLAY	/YES -- "O"
	JMP CHANGE	/YES -- "C"
	JMP CONVRT	/NO!
	JMP VERIFY	/YES -- "V"
	JMP TOP		/YES -- "T"
	JMP BOTTOM	/YES -- "B"
	JMP BRIEF		/NO!
	JMP RETYPE	/YES -- "R"
	JMS APPEND	/YES -- "A"
	JMP KEEP		/YES -- "K"
	JMP MODIFY	/YES
	JMP OUTPUT	/NO!
	JMP EXIT		/COULD BE, BUT NOT ADVERTISED.
	JMP OPEN		/NO!
	JMP CLOSE		/NO!
	JMP ICLOSE	/NO!
TABEND	CAL TABEND	/13-BIT END-OF-TABLE DEFINITION.
	.TITLE CMD PROC--PRINT,DELET,NEXT,FIND&LOCATE
/
/PRINT N LINES FROM EDIT FILE.
/
PRINT	JMS GETNUM	/GET ARGUMENT.
	DAC LOOPCT	/N LINES TO PRINT.
PRLIN	LAC LENGTH	/GET TOTAL CHARS IN CURRENT LINE.
	SNA		/PRINT ONLY IF LINE IS NON-EMPTY.
	JMP PRT1		/OTHERWISE IGNORE IT.
	JMS PACK		/PACK THE CURRENT LINE.
ADR005	INLINE		/FROM INLINE...
	TYLINE		/TO TYLINE.
	LAW TYLINE	/THEN PRINT THIS DATA LINE.
	JMS TYPOUT	/..
PRT1	ISZ LOOPCT	/COUNT LINES TO BE PRINTED.
	SKP		/MORE TO DO.
	JMP FND4		/ALL DONE, RETURN TO COMMAND READER.
	JMS PUTLIN	/WRITE OUT THIS LINE.
	LAC	ONE
	DAC	NOPKSW	/SET NO REPACK SW
	JMS GETLIN	/GET NEXT LINE.
	INLINE
	JMP EOF		/RETURN IF EOF ENCOUNTERED.
	JMP PRLIN		/GO PRINT NEW CURRENT LINE.
/DELETE N OR 1 LINES.
DELETE=.
	CLA		/SET DELSW TO ZERO.
/MOVE POINTER DOWN N OR 1.
NEXT	DAC DELSW		/SET DELSW. AC IS GUARANTEED NON-ZERO.
	JMS GETNUM	/GET ARGUMENT.
	DAC LOOPCT	/N LINES TO SKIP OVER.
NXTLIN	LAC DELSW		/GET DELETE-NEXT INDICATOR.
	SNA		/DELSW .E. 0, OPERATION IS "DELETE."
	DAC LENGTH	/DELETE, FORESTALL WRITE OF THIS LINE.
	JMS PUTLIN	/NEXT, SAVE CURRENT LINE.
	LAC	ONE	/SET NO REPACK SW
	DAC	NOPKSW
	JMS GETLIN	/GET NEXT LINE.
	INLINE		/..
	JMP EOF		/..
	ISZ LOOPCT	/COUNT LINES CONSIDERED.
	JMP NXTLIN	/MORE LINES TO SKIP.
	JMP FND4		/ALL FINISHED, RETURN TO MAIN LINE.
/FIND A LINE.
FIND	LAC NXTPTR	/GET POINTER TO CURRENT CHAR IN COMMAND LINE.
	DAC FND2  	/INSERT IN ARGUMENT LIST.
FND1	JMS PUTLIN	/OUTPUT CURRENT LINE.
	LAC	ONE	/SET THE NO REPACK SWITCH
	DAC	NOPKSW	/THIS WILL JUST SWAP BUFFER'S
	JMS GETLIN	/GET NEXT LINE.
	INLINE		/..
	JMP EOF		/IF END-OF-FILE.
	JMS SCAN		/CALL STRING COMPARER.
FND2	0		/SEARCH FOR THIS STRING...
	INLINE		/...IN THIS LINE.
	SKP		/NOT FOUND.
	SKP		/EOL, STRING 1.
	JMP FND1		/GO BACK TO SEARCH SOME MORE.
/DESIRED LINE HAS BEEN LOCATED. ASCERTAIN WHETHER OR NOT CONFIRMATORY
/PRINT SHOULD BE UNDERTAKEN.
FND3	LAC LENGTH
	DZM	NOPKSW	/CLEAR THE NO REPACKING SWITCH
	SNA
	JMP FND6
	LAC INLADR
	DAC NXTPTR
	ADD LENGTH
	DAC APPEND
	LAC* APPEND
	DAC LOC2
	LAW -3
	DAC TABCT
	LAC BRFSW
	SMA
FNDLP1	JMS NXTCHR
	JMP FND5
	SAD BLANK
	JMP TABFND
	SAD TAB
	JMP TABFND
	SAD SLASH
	JMP FND5-2
	LAC NXTPTR
	DAC APPEND
	LAC* APPEND
	DAC LOC2
	JMP FNDLP1
TABFND	ISZ TABCT
	JMP FNDLP1
	CLA!CMA
	DAC* APPEND
FND5	LAC VERISW
	SPA
	JMP FNDRS
	JMS PACK
ADR006	INLINE
	TYLINE
	LAW TYLINE
	JMS TYPOUT
FNDRS	LAC LOC2
	DAC* APPEND
FND4=.
	DZM ERRSW		/CLEAR READ ERROR SWITCH
	LAC QUIT
	SZA		/SWITCH IS REVERSED FOR RSX
	JMP TTRS
FND6	JMS	ATTTY	/ATTACH TTY'S
	LAW	76	/PRINT >
	JMS TYONCH
	JMP RDLIN
/LOCATE A LINE.
LOCATE	LAC NXTPTR	/GET ADDRESS OF NEXT CHAR IN COMMAND LINE.
	DAC LOC2		/GIVE TO SCAN ARGUMENT LIST.
LOC5	JMS PUTLIN	/WRITE THE CURRENT LINE.
	LAC	ONE	/SET THE NO REPACK SWITCH
	DAC	NOPKSW
	JMS GETLIN	/READ THE NEXT LINE.
	INLINE		/TO CURRENT-LINE AREA.
	JMP EOF		/END-OF-FILE RETURN.
	LAC INLADR 	/GET START ADDRESS OF NEW LINE.
	DAC LOC4		/INSERT AS SCAN ARGUMENT #2.
LOC1	JMS SCAN		/CALL SCAN.
LOC2	0		/STRING TO LOOK FOR.
LOC4	0		/WHERE TO LOOK FOR IT.
TABCT=LOC4		/COUNT OF TABS AND BLANKS FOR BRIEF MODE SERVICER.
	JMP LOC3		/NOT FOUND THIS TRY.
	JMP FND3		/FOUND.
	JMP LOC5		/NOT FOUND ANYWHERE IN THIS LINE.
LOC3	ISZ LOC4		/BUMP SCAN ARG TO NEW STRING IN CURRENT LINE.
	JMP LOC1		/THEN GO SEARCH THE NEW STRING.
	.TITLE CMD PROC--VERIFY,BLOCK,BRIEF,OUTPUT&TV
/
/SET VERIFY SWITCH
/
VERIFY	JMS DCODSW	/GO INTERPRET NEXT WORD IN LINE.
VERISW	0		/VERIFY ON-OFF SWITCH.
	JMP FND4
/SET BRIEF MODE SWITCH.
BRIEF	JMS DCODSW	/INTERPRET NEXT CONTROL WORD.
BRFSW	-1		/BRIEF IS OFF INITIALLY.
	JMP FND4
/SET OUTPUT-SUPPRESSION INDICATOR.
OUTPUT	JMS DCODSW	/CHECK ARGUMENT.
OUTPSW	0		/OUTPUT IS "ON" IF ZERO.
	JMP FND4
	.TITLE CMD PROC--INSERT,RETYPE & APPEND
/
/INSERT A LINE AFTER CURRENT LINE.
/
INSERT	JMS PUTLIN	/WRITE CURRENT LINE.
	DZM LENGTH	/ZERO TOTAL CHARACTERS.
	JMS APPEND	/CALL APPEND.
	LAC LENGTH	/GET CALCULATED LENGTH.
	SNA		/WAS THERE ANY STUFF AFTER THE COMMAND?
	JMP INPUT		/NO, CHANGE TO INPUT MODE.
	DAC INPSW
	JMP FND4		/YES, GET NEXT COMMAND. LINE INSERTED IS NOW THE CURRENT LINE.
/REPLACE CURRENT INLINE WITH CONTENTS OF EDLIN.
RETYPE	DZM LENGTH	/ZERO TOTAL CHARACTERS PRESENTLY IN CURRENT LINE,
	JMS APPEND	/...THEN PERFORM A NORMAL APPEND.
	DAC INPSW
	JMP FND4		/GO GET NEXT COMMAND.
/ADD SOME DATA TO THE CURRENT LINE.
APPEND	0		/APPEND IS REACHED VIA JMS.
APPND1	LAC INLADR	/GET START OF CURRENT LINE.
	ADD LENGTH	/BUMP BY TOTAL DATA CHARACTERS.
	DAC POINTR	/GIVE TO NEXT-CHARACTER INDICATOR
	LAW -3		/ENSURE THAT THIS CHAR WILL FIT.
	TAD MAXLEN	/MAXLEN=(LINSIZ.
	CMA
	TAD LENGTH
	SMA
	JMP APPTRN
	JMS NXTCHR	/GET NEXT CHARACTER FROM INPUT STREAM
NOPLIT	NOP		/IGNORE NXTCHR END-OF-LINE RETURN.
	DAC* POINTR	/INSERT IN LINE.
	SPA		/END-OF-LINE?
	JMP	APPOUT	/YES, RETURN TO CALLER.
	ISZ LENGTH	/NO, BUMP TOTAL CHARACTERS.
	JMP APPND1	/GO GET ANOTHER CHARACTER.
APPOUT	DAC	QUOTE		/SAVE TERMINATOR
	JMP*	APPEND	/RETURN
/
APPTRN	JMS NXTCHR	/IS NEXT CHAR A TERMINATOR
	JMP NOPLIT	/YES --OK
	LAW TRNMES	/GIVE USER MESSAGE
	JMS TYPOUT
	CLC
	JMP NOPLIT
/
	.TITLE CMD PROC--LINE CONVERT,CHANGE & CONVERT
/
/
/CONVERT STRING#1 TO STRING#2 FOR
/THE SPECIFIED NUMBER OF LINES IN THE
/FILE OR BLOCK BUFFER.
/LINE CONVERT PROCESSING GETS THE NUMBER
/OF LINES TO CONVERT AN SETS UP LOOPCT
/TO THAT VALUE. IT THEN SETS LINCSW TO NOP
/AND GOES TO CONVERT PROCESSING
/WHICH TESTS LINCSW.
/
/
LNCONV	JMS GETNUM
	DAC LOOPCT
	LAC NOPLIT
	DAC LINCSW
	JMP CONVRT
/
/
/
/REPLACE STRING 1 WITH STRING 2.
/CHANGE REQUEST PROCESSING
/SET SWITCH AND GO TO CONVERT
/PROCESSING WHICH TESTS THE SWITCH
/
CHANGE	LAC NOPLIT	/GET A NOP
	DAC CHGREQ	/AND SET SWITCH
/
/CONVERT STRING#1 TO STRING#2 THRU OUT
/THE FILE OR BLOCK BUFFER IF IN BLOCK MODE.
/STRING#1 IS DELIMITTED AS IN "CHANGE"
/BY QUOTE CHARACTERS. STRING#2 CAN BE
/DELIMITTED BY EITHER THE APPERANCE OF
/THE QUOTE CHARACTER OR A TERMINATOR
/
CONVRT	JMS TOPBOM	/ARE WE AT THE TOP OR BOTTOM OF THE PAGE
	DZM CONVLT	/GET A LINE IF SO---ZERO COUNTER
	DZM NUM		/INDICATE LINE NAS NOT BEEN ALTERED
	LAC	(TYLINE-1)	/SET UP POINTER TO TYLINE FOR A.I. REG
	DAC TYLNPT
	TAD MAXLEN
	TAD MTWO		/SET OVERFLOW ADDRESS
	DAC OVFLAD
	JMS NXTCHR	/GET 1'ST QUOTE CHAR
	JMP NOSTNG	/NO STRING---COMPLAIN
	DAC QUOTE
	LAC NXTPTR	/GIVE POINTER OF NEXT CHAR
	DAC STRG1		/TO CALL FOR SCAN
GETCHR	JMS NXTCHR	/COUNT CHARS. IN STRING
	JMP NOSTNG
	SAD QUOTE
	JMP QUCHR
	ISZ CONVLT
	JMP GETCHR
QUCHR	LAC CONVLT	/IS THERE A STRING
	SNA
	JMP NOSTG1	/NO!
CHNOSG	LAW -1
	TAD NXTPTR	/DECREMENT POINTER
	DAC NXTPTR
	CLC		/STORE A TERMINATOR IN
	DAC* NXTPTR	/PLACE OF 2'ND QUOTE CHAR
/
/MAJOR LOOP FOR CONVERT, EVERY
/SEARCH OF A NEW LINE STARTS HERE.
/
CVBACK	LAC TYLNPT	/SET UP POINTERS
	DAC* C12
	LAC	(INLINE-1)
	DAC INLNPT
	DAC STRG2
	ISZ STRG2
	JMP CVSCAN	/BYPASS CHANGE TEST FOR 1'ST TIME THRU
/
/MINOR LOOP FOR CONVERT, LOOPS BACK
/HERE AFTER PROCESSING OF EITHER
/NO MATCH FOUND, OR A MATCH FOUND
/
SCANCT	XCT CHGREQ	/WAS THIS A CHANGE REQUEST
	JMP CHGEX1	/YES 
CVSCAN	JMS SCAN		/GO SCAN LINE FOR STRING#1
STRG1	0
STRG2	0
	JMP NOMTCH
	JMP MTCHFD
/
/END OF LINE BEING SEARCHED FOUND COMES HERE
/THIS IS THE EXIT PROCESSING FOR
/THE MINOR LOOP. ON LINE OVERFLOW
/THIS SECTION IS ENTERED AT "TRANL"
/ALSO, NORMAL EXIT FROM THE CONVERT
/COMMAND PROCESSING IS DONE HERE
/
CHGEX1	CLC		/TRANSFER REST OF
	JMS SGTRAN	/INLINE TO TYLINE
TRANL	JMS LINESW	/NOW SWAP TYLINE
	TYLINE-1	/BACK TO INLINE
	INLINE-1
	XCT CHGREQ	/WAS THIS A CHANGE
	JMP CHGEX2	/YES GO EXIT FOR CHANGE
	XCT LINCSW	/WAS THIS A LINE CONVERT
	JMP LINCEX	/YES
LNCVBK=.
	JMS PUTLIN	/PUT LINE AWAY
	LAC	ONE	/SET NO REPACK SW
	DAC	NOPKSW	/**IF A CHANGE HAS BEEN MADE (IE MATCH FOUND)
			/THE SWITCH IS RESET
	JMS GETLIN	/GO GET ANOTHER LINE
	INLINE		/PUT IT HERE
	JMP COVEX4	/NO MORE LINES TO GET***DONE**EXIT
	JMP CVBACK	/ENTER MAJOR LOOP
/
/EXIT FOR CHANGE COMMAND
/
CHGEX2	LAC SKPLIT	/GET SKP
	DAC CHGREQ	/RESET SWITCH
	JMP	FND3
/
/EXIT FROM LINE CONVEERT
/
LINCEX	ISZ LOOPCT	/ARE WE DONE
	JMP LNCVBK	/NO
	LAC SKPLIT	/RESET SWITCH
	DAC LINCSW
	JMS CONCHK	/HAS A LINE BEEN CHANGED
	JMP	FND3
/
/
/EXIT FROM CONVERT END OF FILE
/
COVEX4	XCT LINCSW	/WAS THIS A LINE CONVERT
	JMP COVEX5
	JMS CONCHK
	JMP FND6		/NO EXIT
COVEX5	LAC SKPLIT	/RESET SWITCH
	DAC LINCSW
	JMS CONCHK
	JMP EOF		/TELL USER
/NOTE ONLY PART OF THE COMMAND STRING
/UP TO BUT NOT INCLUDING THE SECOND
/QUOTE CHAR. WILL BE DISPLAYED
/
/
/SUBROUTINE TO CHECK IF STRING#1 WAS EVER FOUND
/
CONCHK	0
	LAC SCN1		/WAS A MATCH FOUND
	SNA
	JMP* CONCHK	/YES--OK
	LAW FILN1
	JMS TYPOUT	/NO--TELL USER
	JMP* CONCHK
/
/
/NO MATCH COMES HERE
/LOOPS BACK TO SCAN
/
NOMTCH	LAC* C12	/WILL LINE OVERFLOW
	SAD OVFLAD
	JMP LNOVFL	/YES HANDLE
	LAC* STRG2	/NO  PUT CHAR IN TYLINE
	DAC* 12
	ISZ STRG2	/BUMP ADDR FOR SCAN
	JMP CVSCAN	/GO BACK AN SCAN
/
/A MATCH FOUND COMES HERE
/LOOPS BACK TO SCAN
/
MTCHFD	CLA		/GO TRANSFER REPLACEMENT
	DAC SCN1		/INDICATE A MATCH FOUND
	DZM	NOPKSW	/RESET NO REPACK SW
	JMS SGTRAN	/STRING TO TYLINE
	LAC STRG2	/UPDATE "SCAN" ADDRESS POINTER
	TAD CONVLT
	DAC STRG2
	ISZ NUM		/INDICATE LINE HAS BEEN ALTERED
	JMP SCANCT	/GO BACK AN SCAN
/
/COMES HERE WHEN A LINE WILL OVERFLOW
/
LNOVFL	CLC		/PUT TERMINATOR
	DAC* 12		/IN TYLINE
	XCT CHGREQ	/WAS THIS A CHANGE
	JMP CHGOVF	/YES JUST PRINT "TRUNCATED"
	LAC	(TYLINE)	/SET UP FOR PACK
	DAC FROMA
	LAC	(INLINE)
	DAC TOB
	JMS PACK	/GO PACK LINE
FROMA	0
TOB	0
	LAW INLINE	/TYPE IT OUT
	JMS TYPOUT
CHGOVF	LAW TRNMES	/TELL USER IT IS TRUNCATED
	JMS TYPOUT	/GO TO EXIT PROCESSING FROM MINOR LOOP
	JMP TRANL
/
/SUBROUTINE SGTRAN TRANSFERS EITHER
/REPLACEMENT STRING OR REST OF INLINE
/(CURRENT LINE) TO TYLINE
/CALL	CLA	/AC=0 TRANSFER REPLACEMENT STRING
/OR	CLC	/AC NOT .EQ. 0 TRANSFER REST OF INLINE
/	JMS SGTRAN
/	NORMAL RETURN	/GOES TO LNOVFL IF TYLINE WILL OVERFLOW
/
SGTRAN	0
	SNA!CLC		/TEST WHICH LINE AN
	JMP RPLSG	/SET SWITCH AND A.I.REG 13
	DAC SGTSW
	TAD STRG2
	SKP
RPLSG	LAC NXTPTR
	DAC* C13
TRMORE	LAC* C12	/CHECK FOR OVERFLOW
	SAD OVFLAD
	JMP OVFLCD	/HANDLE IT
	LAC SGTSW
	SZA
	JMP INLNTR
	LAC* 13		/GET DATA
	SPA		/IS IT A TERMINATOR
	JMP SGEXIT	/YES EXIT
	SAD QUOTE	/CHECK FOR QUOTE CHAR
	JMP SGEXIT
TRANCH	DAC* 12		/NO STORE IT
	JMP TRMORE	/GO BACK FOR MORE
INLNTR	LAC* 13		/GET DATA
	SMA		/IA IT A TERMINATOR
	JMP TRANCH	/NO
STORCH	DAC* 12		/YES STORE IT AND EXIT
SGEXIT	DZM SGTSW
	JMP* SGTRAN
/COMES HERE ON POSSIBLE TYLINE OVERFLOW
OVFLCD	LAC SGTSW	/CHECK SWITCH
	SMA
	JMP RPLINE	/REPLACEMENT STRING
	LAC* 13		/GET CHAR IS IT A TERMINATOR
	SPA
	JMP STORCH	/YES--LUCKY GO STORE AND EXIT
OFEXIT	DZM SGTSW
	JMP LNOVFL	/INFORM USER
RPLINE	LAC* 13		/GET DATA
	SPA		/IS IT A TERMINATOR
	JMP SGEXIT	/YES -- LUCKY
	SAD QUOTE	/IS IT THE QUOTE CHAR
	JMP SGEXIT	/YES LUCKY
	JMP OFEXIT	/NOT EITHER -- TO BAD
/
/ERROR MESSAGE FOR NO STRING TO CONVERT
NOSTG1	XCT CHGREQ	/IS THIS A CHANGE
	JMP CHNOSG	/YES---GO PROCESS
NOSTNG	LAW NOSTGM
	JMS TYPOUT
	JMP FND4
	.EJECT
/
/SUBROUTINE LINESW TRANSFER DATA FROM AN ARRAY
/TO ANOTHER ARRAY. TRANSFER TERMINATES
/ON A NEG. DATA WORD (TERMINATOR)
/CALL	JMS LINESW
/	.DAS ARRAY1-1	/FROM ARRAY1
/	.DSA ARRAY2-1	/TO ARRAY2
/	RETURN
/
LINESW	0
	LAC* LINESW	/GET ADDR POINTER TO INPUT ARRAY
	.IFUND	RSX
	JMS GETBNK
	.ENDC
	DAC* C12	/SET UP A.I. REG.
	ISZ LINESW	/BUMP TO ARG. TWO
	LAC* LINESW	/GET POINTER TO OUTPUT ARRAY
	.IFUND	RSX
	JMS GETBNK
	.ENDC
	DAC* C13	/SET UP A.I. REG.
	ISZ LINESW	/BUMP TO RETURN
	DZM LENGTH	/ZERO LENGTH
CONSWP	LAC* 12		/GET DATA
	SPA		/IS IT A TERMINATOR
	JMP SWPDON	/YES WERE DONE ALMOST
	DAC* 13		/STORE IT
	ISZ LENGTH	/COUNT IT
	JMP CONSWP	/GO BACK FOR MORE
SWPDON	DAC* 13		/STORE TERMINATOR
	JMP* LINESW	/RETURN TO CALLER
/
/SUBROUTINE TOPBOM  CHECKS TO SEE
/IF WE ARE AT THE TOP OR END OF THE
/FILE OR BLOCK BUFFER
/
TOPBOM	0
	LAC	LENGTH		/ARE WE AT TOP OR
	SZA			/END OF FILE
	JMP*	TOPBOM		/NO--EXIT
	JMS	GETLIN		/ GET A LINE
	INLINE			/PUT IT HERE
	JMP	EOF		/AT END OF FILE
	JMP*	TOPBOM		/EXIT
/
/
	.TITLE CMD PROC MODIFY
/
/
/PROCESSING FOR MODIFING A LINE
/WITH THE TERMINATOR OF THE TYPED IN
/LINE DETERMINING IF THE REST OF THE
/CURRENT LINE IS TRUNCATED.
/LINE IS TRUNCATED ON A <CR> AND
/APPENDED ON AN ALTMODE
/
/
MODIFY	LAC NXTPTR	/GIVE ADDR OF STRING
	DAC MDSTG1	/TO SEARCH FOR TO SCAN
	DZM LOOPCT
	JMS TOPBOM	/CHECK FOR TOP OR END OF FILE
CNTMOR	JMS NXTCHR	/COUNT HOW MANY CHAR
	JMP CNTDON	/IN THE STRING
	ISZ LOOPCT
	JMP CNTMOR
CNTDON	LAC LOOPCT	/CHECK FOR PRESENTS
	SNA		/OF A STRING
	JMP FND6	/EXIT  NO STRING
	LAC	(INLINE)
	DAC MDSTG2
MDSCAN	JMS SCAN	/LINE FOR STRING
MDSTG1	0
MDSTG2	0
	JMP MDNMCH	/NO MATCH
	JMP MDMACH	/MATCH FOUND
	JMP FND6	/EXIT NO MATCH IN LINE
/
/NO MATCH COMES HERE
/
MDNMCH	ISZ MDSTG2	/BUMP ADDR
	JMP MDSCAN	/SCAN SOMEMORE
/
/MATCH FOUND COMES HERE
/
MDMACH	LAC MDSTG2	/CALCULATE ADDR OF 1'ST CHAR
	TAD LOOPCT	/AFTER STRING
	DAC MDSTG1	/SAVE IT
	LAC* MDSTG1	/GET CHAR
	DAC NUM		/SAVE IT
	LAW -176	/PUT ALTMODE TERMINATOR IN LINE
	DAC* MDSTG1
	JMS PACK	/GO PACK 1'ST HALF
ADR014	INLINE		/OF INLINE
	TYLINE
	LAW TYLINE	/TYPE OUT 1'ST
	JMS TYPOUT	/HALF OF INLINE
	LAW TYLINE	/GET NEW INPUT ON TTY
	JMS TYPEIN
	JMS UNPACK	/UNPACK IT TO EDLIN
ADR013	TYLINE
	EDLIN
	LAC NUM		/RESTORE CHAR TO INLINE
	DAC*	MDSTG1
	LAW	-1	/SET UP FROM ADDR
	TAD	MDSTG1	/FOR "LINESW"
	DAC MDFROM
	JMS LINESW	/SWAP 2'ND PART OF
MDFROM	0		/INLINE TO TYLINE
	TYLINE-1
	LAC	(INLINE-1)	/CALCULATE NEW INLINE LENGTH
	CMA
	TAD MDSTG1
	DAC LENGTH	/STORE IT
	LAC	(EDLIN)	/SET UP NXTPTR FOR "APPEND"
	DAC NXTPTR
	JMS APPEND	/APPEND NEW DATA TO INLINE
	CMA		/IS TERMINATOR A <CR>
	SAD C15
	JMP FND6
	LAW	-1	/DECREMENT POINTER FOR STORING
	TAD	POINTR	/DATA IN "APPEND"
	DAC POINTR
	LAC	(TYLINE)	/SET UP POINTER FOR GETTING DATA
	DAC NXTPTR	/IN "APPEND"
	JMS APPEND	/REST OF ORG. INLINE
	JMS PACK	/TYPE OUT REST OF
ADR015	TYLINE		/ORGINAL INLINE
	EDLIN
	LAW EDLIN
	JMS TYPOUT
	JMP FND6	/EXIT
	.TITLE CMD PROC -- OVERLAY, OPEN & KEEP
/
/
/CHANGE N LINES.
OVRLAY	JMS GETNUM	/GET TOTAL LINES TO REPLACE.
	DAC LOOPCT	/SAVE AS COUNTER.
OVRLP1	DZM LENGTH	/FORESTALL WRITE OF FINAL LINE SKIPPED OVER.
	ISZ LOOPCT	/COUNT CURRENT LINE.
	SKP		/MORE TO DO, GET NEXT LINE.
	JMP INPUT		/DONE, GO CHANGE TO INPUT MODE.
	JMS GETLIN	/READ NEXT LINE FROM FILE OR INPUT BUFFER.
	INLINE		/..
	JMP EOF		/END-OF-FILE RETURN FROM GETLIN.
	JMP OVRLP1	/READ WAS SUCCESSFUL, PROCESS THIS LINE.
BLANK	40
TTRS	JMS TYPRTN
	DZM	NOPKSW	/CLEAR THE PACKING SWITCH
	JMP EDIT
/OPEN AN INPUT FILE FOR EDITING.
OPEN	NOP		/OR JMP ILLCWD, IF OPEN SEQUENCE ALREADY EXECUTED.
	LAC INDEV		/IS INPUT DEVICE FILE-STRUCTURED?
	SPA		/INDEV IS POSITIVE IF SO.
	JMP FND4		/NON-FILE-STRUCTURED, IGNORE OPEN REQUEST.
	JMS GETCOM	/GET FILE NAME FROM COMMAND STRING.
	SNA		/SKIP IF A NAME WAS IN FACT TYPED.
	JMP NONAM1	/NO NAME FURNISHED, PUBLISH ERROR.
	LAW -2		/FILE NAME GIVEN, PACK INTO FIRST
	JMS PK6BT		/TWO WORDS OF DEB.
	CWD		/..
INNADR	INNAME		/..
	LAC SRCNAM	/USE "SRC" AS DEFAULT EXTENSION.
	DAC INNAME+2	/..
	JMS GETCOM	/THEN GO GET TYPED EXTENSION, IF PRESENT.
	SNA!CLA!CMA	/SKIP IF AN EXTENSION WAS TYPED.
	JMP DZMNAM	/OTHERWISE, ASSUME "SRC" IS WANTED.
	JMS PK6BT		/NOW PACK UP THE EXTENSION TYPED.
	CWD		/..
	INNAME+2		/INTO THIRD WORD OF DEB.
DZMNAM	DZM NAMSW		/INDICATE THAT A FILE NAME HAS BEEN FURNISHED.
	JMS IOINIT		/INIT INPUT AND OUTPUT DEVICE.
	JMS FSTAT		/NOW GO LOOK FOR THE NAMED FILE.
	INNAME		/FILE NAME IS IN INNAME...INNAME+2.
	SNA		/SKIP IF FILE IS PRESENT ON INPUT DEVICE.
	JMP NTFND		/FILE NOT FOUND, COMMENT.
	DZM INFILE	/INDICATE THAT AN INPUT FILE IS PRESENT.
	JMS SEEK		/GO OPEN THE INPUT FILE FOR READING.
	INNAME		/..
	LAC BADARG	/GET A TRANSFER TO ILLCWD
	DAC OPEN		/AND SHUT OUT FURTHER ACCESS TO OPEN
	LAC SKPLIT	/SET EXITSW TO INDICATE
	DAC EXITSW	/A FILE IS OPEN
	JMP EDIT		/THEN GO PREPARE TO EDIT THE FILE JUST OPENED.
INNAME	.BLOCK 3
NONAM1	JMS	ATTTY	/ATTACH TTY'S
	LAW	NOFLNM	/ADDR OF NAME OF ABSENT FILE
	JMS TYPOUT
	JMP FND4
NTFND	LAW INNAME	/ADDR OF NAME OF ABSENT FILE.
	JMS TYNAME	/TYPE OUT FILE NAME.
	LAW FILN1		/COMPLETE THE COMMENT.
	JMS TYPOUT	/"NOT FOUND."
	LAC BADARG	/DON'T ALLOW OPEN
	DAC OPEN	/OR CALL SEQUENCES
	LAC SKPLIT	/SET EXITSW TO INDICATE
	DAC EXITSW	/A FILE IS OPEN
	JMS	DETTY	/DETACH TTY'S
	JMP INPUT		/ACCEPT SOME INPUT.
/SERVICE KEEP REQUEST.
KEEP	LAC DIRSW		/ARE WE GOING FROM -14 TO -15?
	SMA		/IF NOT, SKIP; COULD BE TROUBLE.
	JMP KEEP1		/YES, OK.
	JMS DEVCHK
	JMP KEEP1		/SAME UNIT FOR BOTH DAT SLOTS, OK. HONOR REQUEST.
	LAW TOPRQM	/TWO UNITS AND GOING WRONG WAY, COMMENT.
	JMS TYPOUT	/"TOP REQUEST NEEDED."
	JMP FND6		/GET NEXT COMMAND.
KEEP1	JMS GETCOM	/GET FILE NAME WANTED.
	SNA		/SKIP IF A FILE NAME WAS GIVEN.
	JMP NONAM1	/IF NOT, GO COMPLAIN.
	JMS GETSNM
SETSAV	DZM SAVESW	/INDICATE A SAVE IS WANTED.
	JMP FND6		/THEN REENTER MAIN LINE.
/
/SUBROUTINE GETSNM WILL MAKE UP THE DIRECTORY
/ENTRY BLOCK (DEB) IN SAVNAM WITH WHAT THE USER
/HAS TYPED FOR A FILE NAME AND EXTENSION. IF NO
/EXTENSION WAS TYPED SRC WILL BE USED.
/
/CALL	JMS	GETCOM		/GET FILE NAME INTO CWD
/	JMS	GETSNM
/	RETURN
/
GETSNM	0
	LAW	-2		/PACK 2 WORDS
	JMS	PK6BT		/IN SIXBT
	CWD
	SAVNAM
	LAC	SRCNAM		/PUT SRC IN DEB
	DAC	SAVNAM+2
	JMS	GETCOM		/GET EXIT IF ONE
	SNA!CLC			/PACK ONE WORD
	JMP*	GETSNM		/EXIT
	JMS	PK6BT
	CWD
	SAVNAM+2
	JMP*	GETSNM		/EXIT
/
	.TITLE CMD PROC--ICLOSE,SCLOSE & CLOSE
/CLOSE INPUT FILE ONLY.
ICLOSE	CLA		/INDICATE CURRENT INPUT DAT SLOT IS TO BE REFERENCED.
	DAC ICLSW	/INDICATE ICLOSE REQUEST FOR OPEN
	JMS CLSFIL	/GO CLOSE THE INPUT FILE.
	LAC NOPLIT	/GET A NOP CODE.
	DAC OPEN		/ALLOW ENTRY TO "OPEN" SEQUENCE.
	DAC RDFNOP	/AND SET UP TO FILL BOTH INPUT BUFFERS ON NEXT READ.
	DAC NAMSW		/INDICATE NO FILE NAME HAS BEEN PROVIDED.
	LAC INDEV		/IS INPUT DEVICE FILE-STRUCTURED?
	SPA!CMA		/INDEV .G. 0, YES; SET AC NEGATIVE.
	CLA		/INDEV .L. 0, NO; SET AC POSITIVE.
	DAC INFILE	/INFILE NEGATIVE MEANS NO INPUT FILE PRESENT.
	LAC TFILE1	/PUT DEFAULT INPUT FILE NAME
	DAC INNAME	/IN INNAME DEB
	LAC TFILE1+1
	DAC INNAME+1
	ISZ INNAME+1	/**.TFIL2 EDT**
	LAC EDNAM
	DAC INNAME+2
	JMP FND4		/GO READ NEXT COMMAND.
/
/
CLOSE	LAC OUTDEV
	SMA
	JMP CLOSE2
JMSCLS	JMS CLSOUT
	JMP EXITCH	/GO CHECK FOR EXIT REQUEST
CLOSE2	JMS GETCOM
	DZM NAMSW1
	SZA!CLA		/SKIP IF NO NAME TYPED IN CLOSE REQUEST.
	JMP NAME1A	/A NAME WAS TYPED.
	SAD NAMSW		/SKIP IF NO NAME GIVEN IN OPEN REQUEST.
	JMP CLOS1A	/AT LEAST ONE NAME HAS BEEN PROVIDED.
	LAW NOFLNM
	JMS TYPOUT
	JMP FND4
NAME1A	JMS GETNNM
/
/DETERMINE IF WE ARE AT THE TOP A FILE
/AND IF BOTH INPUT AND OUTPUT DEVICES
/ARE FILE STRUCTURED. ALSO, IF WE ARE
/NOT IN BLOCK MODE AND IF BOTH INPUT
/AND OUTPUT FILES ARE ON THE SAME
/DEVICE AND UNIT NUMBER.
/ALSO, THAT INPUT MODE HAS NOT BEEN ENTERED
/AND A SAVE IS NOT WANTED (IE A KEEP)
/IF ALL THE ABOVE CONDITIONS ARE MEET
/THEN THE OUTPUT FILE IS DELETED (.TFIL1 EDT)
/AND THE INPUT FILE CLOSED. ALSO,IF A NAME
/WAS TYPED IN THE CLOSE (SCLOSE,EXIT)
/COMMAND THE INPUT FILE WILL BE RENAMED.
/
CLOS1A	LAC SAVESW
	SNA
	JMP CLOSE1	/A SAVE IS WANTED
	LAC INPSW	/HAS INPUT MODE BEEN ENTERED
	SZA
	JMP CLOSE1	/YES--TOO BAD
	LAC FILSTR
	SPA
	JMP CLOSE1	/BOTH INPUT AND OUTPUT ARE NOT FILE STRUCT.
	JMS DEVCHK
	SKP
	JMP CLOSE1	/NOT SAME DEVICE AND UNIT
	LAC RDFNOP
	SAD RDFJMP
	JMP CLOSE1	/NOT AT TOP OF FILE
	AND OUTSW1
	SMA
	JMP CLOSE1	/NOT AT TOP OF FILE
	JMS DELFIL	/DELETE .TFIL1 EDT FROM
	XCT TFILE1	/OUTPUT DEVICE
	CLA
	JMS CLSFIL	/CLOSE INPUT FILE
	LAC NAMSW1	/WAS NAME TYPED IN COMMAND
	SNA
	JMP EXITCH	/NO--DONE
	JMP CKNAM		/GO DO RENAME
/
/
CLOSE1	JMS CLSOUT	/CLOSE I/O FILES
	LAC INDEV	/IS INPUT DEVICE FILE ORIENTED IE--(FOD)
	SPA
	JMP GETNM2	/NO
	JMS DEVCHK	/YES--SAME DEVICE UNIT #
	JMP GETNM2	/YES
	LAC DIRSW	/SCLOSE WANTED
	SMA
	JMP GETNM2	/NO
	JMS SEEK
	INNAME
	JMP CLOSE1
GETNM2	LAC NAMSW1	/IS A RENAME WANTED
	SNA
	JMP EXITCH	/GO CHECK FOR EXIT REQUEST
CKNAM	LAC INDEV	/YES-- LINK=1 IF INPUT (FOD)
	RAL
	LAC CKNM1	/GET ADDR OF NEWNAM DEB
	AND CL0777	/SET BIT 0 TO A 1 IF INPUT NOT (FOD)
	SZL
	ADD XCTZRO
	DAC CKNM1	/STORE RESULT
	LAC CKNM2	/DO THE SAME FOR INNAME AS FOR NEWNAM
	AND CL0777
	SZL
	ADD XCTZRO
	DAC CKNM2
	LAC NAMSW	/NAMESW=0 NAME WAS TYPED IN OPEN REQ
	SNA!CLA!CMA	/SKIP IF SO AC=-1
	JMP CKNM3
CKNM0	JMS FSTAT	/SEE IF NAME IS OK TO USE
CKNM1	NEWNAM
	SZA
	JMP NMERR2	/NO -- TELL USER AND REQUEST ANOTHER NAME
RNM2	JMS RENAME	/RENAME FILE
CKNM2	INNAME
	NEWNAM
	JMP EXITCH	/GO CHECK FOR EXIT REQUEST
/NAMES GIVEN BOTH IN OPEN AND CLOSE REQUESTS. FIND OUT IF TWO
/NAMES ARE IDENTICAL. IF SO, ACCEPT CLOSE REQUEST.
CKNM3	TAD CKNM1	/AC=-1 WHEN WE GET HERE
	DAC* C12
	CLA!CMA
	TAD CKNM2
	DAC* C13
	LAW -3
	DAC	APPEND
CKNM4	LAC* 12	/CHECK NAMES
	SAD* 13
	SKP
	JMP CKNM0	/NOT THE SAME
	ISZ	APPEND
	JMP CKNM4
	JMP EXITCH	/GO CHECK FOR EXIT REQUEST
/
/A NAME ERROR HAS OCCURED INFORM USER
/AN ASK FOR ANOTHER NAME.  DO THIS
/UNTIL THE USER HAS TYPED
/A GOOD NAME
/
NMERR2	JMS	ATTTY	/ATTACH TTY
	LAW	BADNAM	/INFORM USER OF TROUBLE
	JMS	TYPOUT
	LAW 76
	JMS TYONCH
	LAW	TYLINE		/GET NEW NAME
	JMS	TYPEIN
	JMS	UNPACK		/UNPACK TO 7BIT ASCII
ADR017	TYLINE
	EDLIN
	SNA			/DID HE TYPE ANYTHING
	JMP	NMERR2		/NO--GO BACK AN COMPLAIN
	JMS	DETTY	/DETACH TTY
	LAC EDLADR
	DAC NXTPTR
	JMS	GETCOM		/MAKE UP DEB IN NEWNAM
	JMS	GETNNM
	JMP	CKNAM		/GO CHECK NAME
/
/
/SUBROUTINE GETNNM---GET NAME TYPED BY
/USER AND MAKE UP THE DEB IN NEWNAM
/
/CALL	JMS	GETCOM
/	JMS	GETNNM
/	RETURN
/
GETNNM	0
NAMEIN	LAW	-2		/PACK TWO WORDS
	JMS	PK6BT
	CWD
	NEWNAM
	LAC	SRCNAM		/PUT SRC IN FOR EXTENSION
	DAC	NEWNAM+2
	DAC	NAMSW1	/INDICATE A NEW NAME IS WANTED
	JMS	GETCOM		/GET EXTENSION IF THERE IS ONE
	SNA!CLC
	JMP*	GETNNM		/NO EXT--EXIT
	JMS	PK6BT		/PACK ONE WORD
	CWD
	NEWNAM+2
	JMP*	GETNNM
/
/
NEWNAM	.BLOCK 3		/NEW NAME DEB
	.TITLE CMD PROC--TOP,BOTTOM,GET,RENEW,WRITE & READ
/
/SERVICE TOP COMMAND.
/
TOP	LAC FILSTR
	SPA
	JMP ILLCWD
	LAC INPSW
	SZA
	JMP TOPFL1
	LAC RDFNOP
	SAD RDFJMP
	JMP TOPFL1
	AND OUTSW1
	SPA
	JMP FND4
TOPFL1	JMS CLSOUT
	JMS SEEK
	INNAME
TOPFL2	DZM INPSW
	JMP FND4
/MOVE POINTER TO LAST LINE OF FILE OR BUFFER.
BOTTOM	ISZ BOTTSW	/INDICATE BOTTOM IN PROCESS
BOTT1	LAC LENGTH
	DAC LEN1
	JMS GETLIN	/GET NEXT LINE.
	EDLIN		/SAVE TEMPORARILY IN EDLIN ARRAY.
	JMP FND3		/ALL DONE IF END OF FILE.
	LAC LEN1
	DAC LENGTH
	JMS PUTLIN	/NOT YET, OUTPUT CURRENT LINE.
	DZM LENGTH	/MOVE EDLIN TO INLINE.
	LAC EDLADR
	DAC NXTPTR
	JMS APPEND
	LAC ERRSW		/WERE THERE ANY READ ERRORS IN GETLIN
	SNA
	JMP BOTT1		/NO -- GO BACK FOR NEXT LINE
	DZM ERRSW		/CLEAR ERROR SW
	SAD C60		/GIVE CORRECT ERROR MESSAGE
	JMP TYTRN		/TRUNCATED
	JMP TYPAR		/READ ERROR
/
/
BOTTSW	0
/
/READ SOME LINES FROM SUBSIDIARY DEVICE.
GET	JMS GETNUM
	DAC LOOPCT
	LAC	(DAT10)	/ATTACH THE DEVICE FOR GET
	JMS	ATTACH
SBREAD	CAL	RDIN2
	JMS	WFEV	/WAIT FOR EVENT VARIABLE AND CHECK VALIDITY OF EV
	LAC	(DAT10) /LUN OON WHICH WAIT IS DONE
	LAC SBUFF
	AND C7
	SAD C5
	SKP
	SAD C6
	JMP GETEOF
	JMS PUTLIN
	JMS UNPACK
ADR008	SBUFF
	INLINE
	DAC LENGTH
	LAC SBUFF
	AND C60
	SAD C60
	JMP	TYTRNA	/DETACH BEFORE EXITING
	SZA
	JMP TYPAR
	DAC INPSW
	ISZ LOOPCT
	JMP SBREAD
	LAC	(DAT10)	/DETACH DEVICE BEFORE EXITING
	JMS	DETACH
	JMP FND4
TYTRNA	LAC	(DAT10)	/DETACH DEVICE
	JMS	DETACH
	JMP	TYTRN
/
GETEOF	LAC	(DAT10)	/DETACH DEVICE
	JMS	DETACH
	LAW	EOMRM
	JMS TYPOUT
	JMP EOFCOM
	.TITLE SUBROUTINES RDFILE & WRFILE
/
C5	5
C777	777
C175	175
/SUBROUTINE RDFILE, DOUBLE-BUFFERED READ-INPUT-FILE. BEFORE
/FIRST CALL, RDFNOP MUST CONTAIN SOME INSTRUCTION PERMITTING
/CONTROL TO FALL THROUGH TO RDFNOP+1.
/CALL:	JMS RDFILE
/	LINE BUFFER ADDRESS
/	RETURN IF NO MORE LINES (EOF CODE IN AC)
/	NORMAL RETURN
RDFILE	0
	LAC INFILE	/IS THERE AN INPUT FILE PRESENT?
	SMA		/THERE IS NOT IF INFILE IS NON-ZERO.
	JMP .+4		/IF INFILE .E. ZERO, THERE IS AN INPUT FILE.
	LAW NOFIL1	/NO FILE, COMPLAIN.
	JMS TYPOUT	/"NO INPUT FILE PRESENT."
	JMP FND4		/GO READ NEXT COMMAND.
	LAC* RDFILE	/GET LINE OUTPUT ADDRESS.
	ISZ RDFILE	/BUMP TO RETURN.
	DAC RDUP02	/GIVE OUT ADDRESS TO UNPACKER.
RDFUPD	LAC RDCAL2	/GET LAST BUFFER READ.
	DAC RDUP01	/UNPACK THAT BUFFER.
	LAC RDALTB	/READ INTO THE OTHER BUFFER.
	DAC RDCAL2	/..
	LAC RDUP01	/UPDATE OTHER-BUFFER POINTER.
	DAC RDALTB	/..
	CAL	WFEVR	/WAIT FOR READ TO COMPLETE DOUBLE BUFFERED
	LAC	EVR	/PICK UP EVENT VARIABLE
	SMA		/IS IT LEGAL?
	JMP	RDCOK	/READ OK PROCEED
	JMS	IOERR	/NO I/O ERROR GO TELL USER
	LAC	(DAT10)	/LUN OF ERROR
RDCOK	CAL	RDINP	/YES -- IT IS LEGAL DO THE NEXT READ
RDFNOP	NOP		/MODIFIED AFTER FIRST TIME THROUGH.
	LAC RDFJMP	/ONE-TIME SECTION TO PRIME READ BUFFERS.
	DAC RDFNOP
	JMP RDFUPD	/READ AGAIN FIRST TIME ONLY.
RDFJMP	JMP .+1
	LAC* RDUP01	/GET BUFF HEADER.
	AND C7		/THROW AWAY JUNK.
	SAD C5		/END OF FILE?
	SKP		/YES, SO INDICATE.
	SAD C6		/OR END OF MEDIUM?
	JMP RDFEOF	/YES, TAKE EOM RETURN.
	LAC* RDUP01	/CHECK FOR READ AND LONG-LINE ERRORS, GET BUFFER HEADER.
	AND C60		/EXTRACT ERROR BITS.
	DAC ERRSW		/SAVE AS ERROR-PRESENT INDICATOR.
	JMS UNPACK	/CALL UNPACK.
RDUP01	0		/CURRENT READ BUFFER ADDRESS.
RDUP02	0		/CALLER'S LINE BUFFER AREA.
	ISZ RDFILE	/INDEX TO RETURN.
	JMP* RDFILE	/RETURN TO CALLER.
RDFEOF	LAC NOPLIT
	DAC RDFNOP
	JMP* RDFILE	/RETURN TO CALLER.
RDALTB	RDBUF1
/SUBROUTINE WRFILE, DOUBLE-BUFFERED WRITE-OUTPUT-FILE.
/CALL:	JMS WRFILE
/	RETURN
WRFILE	0
	LAC OUTPSW	/IS OUTPUT WANTED? (OUTPSW SET BY OUTPUT ON/OFF COMMAND.
	SZA		/SKIP IF OUTPUT IS ON.
	JMP* WRFILE	/OTHERWISE IGNORE THIS CALL.
	LAC WRPAK2	/EXCHANGE BUFFER ADDRESSES. GET BUFFER USED LAST.
	DAC RDFILE	/SAVE THAT ADDRESS TEMPORARILY.
	LAC WRALTB	/GET START OF ALTERNATE BUFFER.
	DAC WRPAK2	/USE THAT BUFFER FOR PACKING THIS LINE.
	DAC WRCAL2	/WRITE FROM THAT BUFFER ALSO.
	LAC RDFILE	/NOW GET THE FIRST BUFFER AGAIN.
	DAC WRALTB	/AND SAVE AS ALT BUFFER FOR NEXT TIME.
	LAC	NOPKSW	/CHECK NO PACKING SWITCH
	SZA
	JMP	PACKA	/SET DON'T PACK THE LINE JUST SWAP THE BUFFER
	JMS PACK		/GO PACK THE OUTPUT LINE.
INLADR	INLINE		/LINE TO BE PACKED IS ALWAYS IN INLINE.
WRPAK2	WRBUF2		/MODIFIED EACH TIME TO POINT TO "CURRENT" BUFFER.
PKFIN=.
	LAC OUTSW1
	SZA
	JMS OUTENT	/GO CLEAN UP OUTPUT DEVICE AND ENTER FILE
	CAL	WFEVW	/WAIT FOR LAST READ TO COMPLETE DOUBLE BUFFERED
	LAC	EVW	/PICK UP THE EVENT VARIABLE
	SMA		/IS IT LEGAL?
	JMP	WROV5	/WRITE OK PROCEED
	JMS	IOERR	/NOT LEGAL GO TELL USER
	LAC	OUTPCL	/LUN ON WHICH ERROR OCCURRED
WROV5	CAL	WROUT	/YES -- IT IS LEGAL DO THE NEXT WRITE
	DZM OUTSW1	/INDICATE SOMETHING WRITTEN INTO OUTPUT FILE.
	JMP* WRFILE	/NO WAIT REQUIRED AFTER WRITING.
WRALTB	WRBUF1		/MODIFIED EACH TIME TO POINT TO "OTHER" BUFFER.
/
/ PACKA SWITCHES THE INPUT AND OUTPUT BUFFERS TO SAVE
/REPACKING
/
PACKA	LAC	RDALTB	/PICK UP THE INPUT LINE ADDRESS
	DAC	RDFILE	/SAVE IT TEMPORARILY
	LAC	WRPAK2	/PICK UP THE OUTPUT FILE BUFFER
	DAC	RDALTB	/SET IT UP FOR THE NEXT READ
	LAC	RDFILE	/PICK UP THE BUFFER TO BE OUTPUT
	DAC	WRPAK2	/SET IT IN THE BUFFER POINTER
	DAC	WRCAL2	/SET UP WRITE CAL
	JMP	PKFIN	/FINISHED RETURN
NOPKSW	0	/NO PACK SWITCH JUST SWITCH LINE BUFFER'S
/
/SUROUTINE OUTENT 
/DELETE .TFIL1 EDT ON OUTPUT
/DEVICE IF DISK OR DISK PACK
/AND THEN ENTER .TFIL1 EDT
/ON THE OUTPUT DEVICE
/
OUTENT	0
OUTFST	JMS FSTAT
	XCT TFILE1
	SNA
	JMP OUTETR
DELEFL	JMS DELFIL
	XCT TFILE1
	JMP OUTFST
OUTETR	JMS ENTER
TFLDEB	TFILE1
	JMP* OUTENT
/
/
	.TITLE SUBROUTINES DCODSW,SCAN,PUTLIN & GETLIN
/
/SUBROUTINE DCODSW, DECODE CONTROL WORDS "OFF" AND "ON". ON EXIT,
/C(C(DCODSW)) .E. 0 IF ON, -1 IF OFF. IF NO ARGUMENT IS PRESENT, APPROPRIATE
/SWITCH IS SET TO "ON" (0). 
DCODSW	0
	JMS GETCOM	/GET PARAMETER TYPED.
	SNA!CLA		/SKIP IF A PARAMETER WAS PRESENT.
	JMP SETSW 	/IF NO PARAMETER GIVEN, GO TREAT AS "ON".
	JMS SCAN		/CALL STRING COMPARER.
	CWD		/TYPED PARAMETER IS HERE.
	OFF		/COMPARE WITH "OFF".
	JMP DCOD01	/NO MATCH THIS TIME.
	SKP		/POSSIBLE MATCH.
	JMP ILLCWD	/ILLEGAL PARAMETER.
	LAC* STR2		/END OF STRING 2 FOUND?
	SPA!CLA!CMA	/NO, SKIP.
	JMP SETSW		/YES, SET SWITCH TO "OFF" (-1).
DCOD01	JMS SCAN		/COMPARE AGAIN.
	CWD		/PARAMETER IS STILL HERE.
	ON		/THIS TIME, TRY "ON".
	SKP		/NOT FOUND.
	SKP		/POSSIBLE HIT.
	JMP ILLCWD	/NO MATCH, GO COMPLAIN.
	LAC* STR2		/ENSURE END OF STRING 2 REACHED.
	SMA!CLA		/SKIP IF SO.
	JMP ILLCWD	/IF NOT, COMPLAIN.
SETSW	DAC* DCODSW	/AC IS EITHER 0 OR 777777 HERE.
	ISZ DCODSW
	JMP* DCODSW
OFF	117		/"O"
	106		/"F"
	106		/"F"
XCTZRO	XCT 0		/BIT 0 = 1 TO TURN OFF STRING COMPARE IN SCAN.
ON	117		/"O"
	116		/"N"
CL7770	777000
/SCAN, ATTEMPT TO MATCH TWO CHARACTER STRINGS.
/CALL:	JMS SCAN
/	ADDRESS OF STRING TO SEARCH FOR.
/	ADDRESS OF STRING UPON WHICH SEARCH IS TO BE PERFORMED.
/	RETURN IF STRING NOT FOUND.
/	RETURN IF END OF STRING1 FOUND.
/	RETURN IF END OF STRING2 FOUND.
SCAN	0
	LAC* SCAN
	DAC STR1
	ISZ SCAN
	LAC* SCAN
	DAC STR2
	ISZ SCAN
SLOOP1	LAC* STR1
	SPA
	JMP SLP1
	LAC* STR2
	SPA
	JMP SLP2
	SAD* STR1
	SKP
	JMP* SCAN
	ISZ STR1
	ISZ STR2
	JMP SLOOP1
SLP2	ISZ SCAN
SLP1	ISZ SCAN
	JMP* SCAN
/
/  SUBROUTINE PUTLIN, INSERT A LINE IN THE OUTPUT FILE.
/
/PUTLIN ALWAYS GET LINE FROM INLINE
/
/CALL:	JMS PUTLIN
/	NORMAL RETURN.
PUTLIN	0
	LAC LENGTH
	SNA
	JMP*	PUTLIN
	LAC	QUIT	/CHECK FOR ABORT
	SZA
	JMP TTRS
	JMS	WRFILE
	DZM LENGTH
	JMP*	PUTLIN
/
/GETLIN, RETURN NEXT LINE FROM CURRENT BUFFER OR FROM INPUT FILE.
/GETLIN GETS THE POINTER TO THE NEXT LINE FROM THE CHECKSUM
/WORD OF THE CURRENT LINE BLOCK MODE ONLY
/
/CALL:	JMS GETLIN
/	 BUFF
/	RETURN IF NO MORE LINES TO GET.
/	NORMAL RETURN
GETLIN	0
	LAC QUIT
	SZA
	JMP TTRS
	LAC* GETLIN	/GET LINE ADDRESS.
	DAC RDCAL+1	/AND TO FILE READER.
	ISZ GETLIN	/BUMP TO RETURN.
EMPBUF	ISZ GETLIN	/..
	JMP* GETLIN
RDCAL	JMS RDFILE
PWRD3	0
	JMP EMPBUF
	DAC LENGTH
	LAC BOTTSW	/IF BOTTOM IN PROGRESS DON'T GIVE
	SZA		/ERROR MESSAGE NOW IF THERE IS AN ERROR
	JMP EMPBUF-1
	LAC ERRSW
	SAD C60
	JMP TYTRN
	SNA
	JMP EMPBUF-1
TYPAR	LAW PRTYMS
	JMS TYPOUT
	JMP FND3
TYTRN	LAW TRNMES
	JMS TYPOUT
	JMP FND3
	.TITLE CHARACTER PACKING & UNPACKING SUBROUTINES
/
/CLOSED SUBROUTINES FOR CHARACTER PACKING AND UNPACKING.
  
  
/SUBROUTINE UNPACK, IOPS ASCII TO ONE CHAR PER WORD. ON RETURN,
/IOPS LINE IS UNPACKED IN "TO" ARRAY AS 7-BIT CHARACTERS, ONE PER
/WORD, RIGHT-ADJUSTED WITH LEADING ZEROES. INITIAL LINE FEED (IF
/ANY) AND TERMINATING CARRIAGE RETURN (OR ALT MODE) ARE DELETED. IN PLACE
/OF THE TERMINATING CHARACTER IS INSERTED ITS 1'S COMPLEMENT (I.E.,
/000015 BECOMES 777762). THE ACCUMULATOR AND REGISTER "TOTCHR" HOLD POSITIVE
/TOTAL NUMBER OF DATA CHARACTERS UNPACKED, EXCLUSIVE OF THE TERMINATOR.
/NOTA BENE: UNPACK USES AUTOINDEX REGISTERS 3 AND 4 (LOCATIONS 12 AND 13)
/AS INPUT AND OUTPUT POINTERS.
/CALL:	JMS UNPACK	/GO TO UNPACK.
/	FROM		/15-BIT ADDRESS OF WORD 0 OF LINE BUFFER HEADER.
/	TO		/15-BIT ADDRESS OF FIRST CHAR OF OUTPUT LINE.
UNPACK	0		/ENTRY TO UNPACK.
PKFROM=UNPACK		/PACK, PK6BT: POINTER TO NEXT CHARACTER IN INPUT ARRAY.
	LAC* UNPACK	/GET ADDRESS OF INPUT LINE.
	DAC* C12		/SAVE AS INPUT POINTER (IN LOC 12).
	ISZ* C12		/ADJUST TO POINT TO FIRST DATA PAIR.
	ISZ UNPACK	/BUMP TO SECOND ARGUMENT.
	LAW	-1		/ARG 2 IS ADDRESS OF OUTPUT LINE.
	TAD*	UNPACK		/DECREMENT BY ONE.
	DAC*	C13		/SAVE AS POINTER TO OUTPUT ARRAY (IN LOC 15).
	ISZ UNPACK	/BUMP TO RETURN.
	DZM TOTCHR	/ZERO TOTAL CHARACTERS IN LINE.
	DZM FSTSW		/INDICATE NO DATA ENCOUNTERED YET.
/ENTER MAJOR LOOP TO GET NEW WORD PAIR FROM INPUT LINE AND
/RESET CHARACTER COUNTER (PK5CHR) TO 5.
UNPLP1	LAC* 12		/GET NEXT WORD FROM LINE BUFFER.
	DAC	PWRD1
	LAC* 12		/PICK UP NEXT WORD.
	DAC	PWRD2
	LAW -5		/SET UP TO EXTRACT 5 CHARACTERS FORM THIS PAIR.
	DAC PK5CHR	/..
	LAC	(UNPKJP	/SET UP THE POINTER TO THE JUMP TABLE
	DAC	UNPKJS	/TO UNPACK 5/7 ASCII
/ENTER INNER LOOP TO GET NEXT CHARACTER FROM CURRENT WORD PAIR,
/STORE IT IN OUTPUT ARRAY, AND CHECK FOR COMPLETION.
UNPLP2	XCT*	UNPKJS	/UNPACK A CHARACTER
	ISZ	UNPKJS	/MOVE POINTER FORWARD ONE
	AND C177		/TAKE ONLY RIGHTMOST SEVEN BITS.
	SNA		/ACCEPT ONLY IF NON-NULL.
	JMP UNPB5C	/NULL CHARACTER, IGNORE.
	SAD C12		/LINE FEED?
	JMP UNPLNF	/YES, GO IGNORE ONLY IF FIRST CHARACTER IN LINE.
	SAD C175		/ALT MODE TYPE TERMINATOR?
	JMP UNPCR		/YES, TREAT JUST LIKE CARRIAGE RETURN.
	SAD C15		/CARRIAGE RETURN?
	JMP UNPCR		/YES, LINE IS COMPLETE.
UNPDAC	DAC* 13		/REAL ASCII CHAR, DEPOSIT IN OUTPUT ARRAY.
	DAC FSTSW		/INDICATE SOME DATA ENCOUNTERED.
	ISZ TOTCHR	/BUMP TOTAL DATA CHARACTERS SEEN.
	LAC TOTCHR	/GET TOTAL CHARACTERS SEEN.
	TAD TWO		/WILL WE OVERFLOW NEXT TIME?
	SAD MAXLEN	/SKIP IF NOT.
	JMP UNPOFL	/OTHERWISE, STOP NOW.
UNPB5C	ISZ PK5CHR	/COUNT 5 CHARACTERS FROM CURRENT PAIR.
	JMP UNPLP2	/NOT FINISHED WITH THIS PAIR, GET NEXT CHARACTER.
	JMP UNPLP1	/CURRENT PAIR EXHAUSTED, GET NEXT ONE.
UNPOFL	LAC C15		/TOO MANY CHARS, GET CARRIAGE RETURN.
UNPCR	CMA		/LINE FINISHED, GET TERMINATOR.
	DAC* 13		/INSERT AS LAST WORD OF OUTPUT LINE.
	LAC TOTCHR	/PICK UP TOTAL DATA CHARACTERS PROCESSED.
	JMP* UNPACK	/RETURN TO CALLER.
UNPLNF	LAC FSTSW		/LINE FEED FOUND. IS IT LEADING?
	SNA		/SKIP IF NOT.
	JMP UNPB5C	/YES, WELL GO IGNORE IT.
	LAC C12		/NO, WELL ACCEPT IT THEN.
	JMP UNPDAC
  
/SUBROUTINE PACK, RIGHT-ADJUSTED 7-BIT CHARACTER ARRAY TO HEADERED
/IOPS ASCII. TERMINATES ON NEGATIVE WORD IN INPUT ARRAY.
/NOTE: USES AUTOINDEX REGISTER 3 (LOCATION 12) AS POINTER TO
/OUTPUT LINE.
/CALL:	JMS PACK		/GO TO PACK.
/	FROM		/15-BIT ADDRESS OF FIRST CHAR OF INPUT ARRAY.
/	TO		/15-BIT ADDRESS OF FIRST WORD OF OUTPUT LINE.
PACK	0		/ENTRY TO PACK.
	LAC* PACK		/PICK UP START OF INPUT ARRAY.
	DAC PKFROM	/GIVE TO INPUT POINTER.
	ISZ PACK		/BUMP ENTRY TO ARG 2.
	LAC* PACK		/GET ADDRESS OF LINE BUFFER TO FILL.
	DAC PLBH		/SAVE AS ADDRESS OF WORD 0 OF HEADER.
	DAC* C12		/AND ALSO IN OUTPUT POINTER.
	ISZ* C12		/SET LOC 12 TO POINT TO CHECKSUM.
	DZM* PLBH		/SET INITIAL VALUE OF HEADER WORD 0.
	DZM LSTSW		/INDICATE TERMINATOR NOT SEEN YET.
	ISZ PACK		/BUMP TO RETURN.
/ENTER MAJOR LOOP TO UPDATE WORD-PAIR COUNT IN LINE BUFFER HEADER
/(LOCATION POINTED TO BY "PLBH") FOR WORD-PAIR JUST CONSTRUCTED
/(OR FOR HEADER PAIR ON FIRST TIME THROUGH) AND TO RESET CHARACTER
/COUNTER (PK5CHR) TO -5.
PLOOP1	LAC C1000		/TURN ON BIT 8.
	ADD* PLBH		/ADD IN WORD PAIR COUNT DEVELOPED SO FAR.
	DAC* PLBH		/NEW WORD 0.
	LAW -5		/SET UP TO PUT 5 CHARACTERS IN THE NEW PAIR.
	DAC PK5CHR	/..
/ENTER INNER LOOP TO GET NEXT CHARACTER FROM INPUT LINE, CHECK FOR
/COMPLETION, AND INSERT IN CURRENT PAIR.
PLOOP2	LAC* PKFROM	/GET NEXT CHARACTER FROM INPUT ARRAY.
	SPA		/TERMINATOR? (NEGATIVE IF SO.)
	JMP PCLOSE	/YES, GO TRY TO CLOSE THE OUTPUT LINE.
	ISZ PKFROM	/NO, BUMP POINTER TO NEXT CHARACTER.
PLOOP6	AND	(177)	/MASK OFF CHARACTER
	XCT*	PKJMS	/GO PACK A CHARACTER
PLOOP7	ISZ	PKJMS	/UPDATE PACK POINTER
	ISZ	PK5CHR	/COUNT 5 CHARACTERS PER PAIR
	JMP	PLOOP2	/NOT FINISHED WITH THIS PAIR
	JMP PLOOP1	/GO REINITIALIZE FOR NEXT PAIR.
/COME HERE ON TERMINATOR FOUND IN INPUT ARRAY.
PCLOSE	SAD LSTSW		/HAVE WE BEEN HERE BEFORE? (LSTSW = 0 IF NOT.)
	JMP PKNULL	/YES, GO FILL CURRENT PAIR WITH NULLS.
	DAC LSTSW		/NO, SET LSTSW TO ENABLE BYPASS NEXT TIME THROUGH.
	CMA		/INVERT TERMINATOR.
	SNA		/IS IT NOW A NULL CHARACTER?
	LAC C15		/IF SO, GET CARRIAGE RETURN.
	JMP PLOOP6	/GO PUT CARRIAGE RETURN OR ALT MODE AWAY.
/COME HERE TO PAD WORD-PAIR WITH NULLS AFTER TERMINATING CHARACTER
/HAS BEEN INSERTED.
PKNULL	LAW -5		/FIRST, SEE IF PAIR IS ALREADY FULL.
	XOR PK5CHR	/..
	SZA!CLA!CLL!CML	/PAIR IS FULL IF PK5CHR .E. -5.
	JMP PLOOP6	/PAIR IS NON-FULL, INSERT NULL JUST GENERATED.
	RTL		/FULL, SET IOPS ASCII INDICATOR (AC = 2).
	ADD* PLBH		/INSERT MODE IN HEADER.
	DAC* PLBH		/RESTORE HEADER IN LINE BUFFER AREA.
	JMP* PACK		/ALL DONE, EXIT.
/
/ EAE SUBROUTINE TO UNPACK 5/7 ASCII -- THIS ROUTINE
/RETURNS THE CHARACTER  IN THE RIGHTMOST 7 BITS
/
UNPKJP	JMP	VPW1	/UNPACK WORD1
	LLS	7	/UNPACK CHARACTER 2
	JMP	VPW3	/UNPACK CHARACTER 3
	LLS	7	/UNPACK CHARACTER 4
	LLS	7	/UNPACK CHARACTER 5 -- SAME AS UNPACKING CHARACTER 4
/
VPW1	LAC	PWRD1	/PICK UP THE FIRST WORD
	LRS	13	/MOVE THE DESIRED 7 BITS TO 11-17 OTHERS TO MQ
	JMP	UNPLP2+1 /RETURN TO CALLER
/
/
VPW3	LAC	PWRD2	/PICK UP THE LAST 4 BITS
	LMQ		/SAVE IT IN MQ
	LAC	PWRD1	/PICK UP THE FIRST WORD FOR 4 BITS
	LLS	3	/FORM A CHARACTER
	JMP	UNPLP2+1 /RETURN
/
PWRD1;PWRD2
UNPKJS	0	/UNPACKING AND PACKING POINTER
PKJMS=UNPKJS
/
PKJMPT	JMP	PKWD1	/PACK THE FIRST CHARACTER
	JMP	PKWD2	/PACK THE ECOND CHARACTER
	JMP	PKWD3
	JMP	PKWD4
	JMP	PKWD5
/
PKWD1	ALSS	7	/ALREADY MASKED PUT INTO BITS 5-10
	DAC	PWRD1	/SAVE FOR NXT CHARACTER
	JMP	PLOOP7	/RETURN FOR NEXT CHARACTER
PKWD2	XOR	PWRD1	/ADD IN LAST CHARACTER
	ALSS	4	/MOVE OVER FOR 3RD CHARACTER
	DAC	PWRD1
	JMP	PLOOP7	/RETURN
PKWD3	LRSS	3	/SAVE THE RIGHT 3 BITS
	XOR	PWRD1	/ADD IN SAVED WORD
	DAC*	12	/PUT IT IN THE LINE BUFFER
	LLS	12	/MOVE THE 3 SAVED CHARACTERS TO BITS 8-10
	AND	(1600)	/MASK OFF THE WORD
	DAC	PWRD1	/SAVE IT FOR THE NEXT PASS
	JMP	PLOOP7	/RETURN FOR NEXT CHARACTER
PKWD4	XOR	PWRD1	/ADD IN 3 BITS FROM LAST CHARACTER
	ALSS	7	/SHIFT FOR 5TH CHARACTER
	DAC	PWRD1
	JMP	PLOOP7
PKWD5	XOR	PWRD1	/MASK IN CHARACTERS 3,4
	CLL!RAL		/BIT 17 = 0
	DAC*	12	/STORE IN WORD COUNT
	JMP	PLOOP7
/
  
/SUBROUTINE PK6BT, RIGHT-ADJUSTED 7-BIT CHARACTERS TO 3-6 TRIMMED
/ASCII, ZERO-FILLED. TERMINATES ON END CODE (BIT 0 = 1) IN INPUT ARRAY
/OR WORD COUNT OVERFLOW (COUNT -- 2'S COMPLEMENT -- IN AC AT CALL).
/CALL:	LAW -MAXWDS	/2'S COMPLEMENT WORDS TO FILL.
/	JMS PK6BT		/CALL PK6BT.
/	FROM		/START OF INPUT ARRAY.
/	TO		/START OF OUTPUT ARRAY.
PK6BT	0		/ENTRY TO PK6BT.
TOTCHR=PK6BT		/UNPACK: TOTAL CHARS IN OUTPUT LINE.
	DAC PK6WDC	/SAVE COUNT OF  TOTAL WORDS TO FILL.
	LAC* PK6BT	/GET START OF INPUT ARRAY.
	DAC PKFROM	/GIVE TO INPUT POINTER.
	ISZ PK6BT		/BUMP TO OUTPUT ADDRESS.
	LAC* PK6BT	/GET START OF OUTPUT ARRAY.
	DAC PK6TO		/GIVE TO OUTPUT POINTER.
	ISZ PK6BT		/BUMP TO RETURN.
PK6LP1	LAW -3		/THREE CHARS PER WORD.
	DAC PK6CT1	/SET UP 3-CHARACTER COUNTER.
	DZM* PK6TO	/ZERO NEW OUTPUT WORD.
PK6LP2	LAC* PKFROM	/GET NEXT CHARACTER FROM INPUT ARRAY.
	SPA!CLL		/IS THIS THE ARRAY TERMINATOR? (NEGATIVE IF SO.)?
	JMP PK6CLS	/YES, GO GENERATE A NULL CHARACTER.
	AND C77		/NO, EXTRACT RIGHTMOST SIX BITS.
	DAC PK6CHR	/THEN SAVE AS CURRENT CHARACTER.
	ISZ PKFROM	/BUMP INPUT POINTER FOR NEXT TIME.
PK6LP3	LAC* PK6TO	/GET 3-6 WORD GENERATED SO FAR.
	RTL		/SHIFT IT SIX BITS LEFT TO MAKE ROOM FOR CURRENT CHAR.
	RTL		/..
	RTL		/..
	ADD PK6CHR	/THEN INSERT CURRENT CHARACTER.
	DAC* PK6TO	/SAVE NEW 3-6 WORD.
	ISZ PK6CT1	/COUNT 3 CHARACTERS PACKED IN THIS WORD.
	JMP PK6LP2	/MORE TO DO, GET NEXT CHARACTER.
	ISZ PK6TO		/ALL DONE WITH THIS WORD, BUMP OUTPUT POINTER.
	ISZ PK6WDC	/COUNT MAXIMUM WORDS IN OUTPUT ARRAY.
	JMP PK6LP1	/MORE ROOM IN OUTPUT ARRAY, SET UP NEW WORD.
PK6RET	JMP* PK6BT	/OUTPUT ARRAY IS FULL, RETURN TO CALLER.
/COME HERE ON TERMINATOR FOUND IN INPUT ARRAY. FILL REMAINDER OF OUTPUT
/ARRAY WITH NULL (00) CHARACTERS.
PK6CLS	DZM PK6CHR	/MAKE CURRENT CHAR A NULL.
	JMP PK6LP3	/AND PUT IT AWAY. NEXT INPUT CHAR WILL BE SAME TERMINATOR
	.TITLE FILE PROCESSING SUBROUTINES
/
/
/	FILE PROCESSING FOR RSX  
/		ONLY EDITING ON THE DISK IS LEGAL
/		OTHER DEVICES ARE NOT PERMITTED
/		I/O ERRORS CAUSE TERMINATION OF EDITING A FILE
/
/ATTACH A LUN
/
ATTACH	0
	DAC	ATLUN
	CAL	ATCH
	JMP*	ATTACH
/
/	DETACH A LUN
DETACH	0
	DAC	DETLUN
	CAL	DTCH
	CAL	WFEVTA
	JMP*	DETACH
/
WFEV	0
	CAL	WFEVTA	/WAIT FOR EVENT VARIABLE
	LAC	EVTA
	SMA		/WAS REQUEST OK?
	JMP*	WFEV	/YES RETURN
	XCT*	WFEV	/PICK UP THE BAD LUN
	DAC	WFEV+1	/SAVE IT FOR I/O ERROR MESSAGE
	LAC	EVTA	/PICK UP THE EVENT VARIABLE
	JMS	IOERR	/I/O ERROR
	LAC	WFEV+1	/LUN OF I/O ERROR -- FATAL ERROR
/
/
/
/
/ EXECUTE SEEK ON NAMED FILE
/	JMS SEEK
/	POINTER TO DEB
/	RETURN
/
SEEK	0
	LAC	INPTCL	/PICK UP THE INPUT LUN SLOT
	DAC	SEKCAL	/SAVE IT IN THE SEEK REQUEST
	LAC*	SEEK	/PICK UP THE POINTER TO THE FILE NAME
	ISZ	SEEK	/MOVE SEEK POINTER
	JMS	MOVENM	/MOVE FILE NAME
	SEEKNM		/POINTER TO SEEK REQUEST
	CAL	SEKFI	/SEEK REQUEST
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	DZM	INFILE	/CLEAR THE FILE NOT OPEN SWITCH
	LAC	EVA	/PICK UP EVENT VARIABLE TO SEE IF LEGAL
	SMA
	JMP*	SEEK	/LEGAL FILE MUST HAVE BEEN FOUND
	JMS	IOERR	/ILLEGAL FILE NOT PRESENT OR OTHER ERROR
	LAC	SEKCAL	/LUN ON WICH ERROR OCCURRED
/
/EXECUTE ENTER ON NAMED FILE.
/	JMS ENTER
/	POINTER TO DEB
/	RETURN
/
ENTER	0
	LAC	OUTPCL	/PICK UP THE OUTPUT LUN SLOT
	DAC	ENTECL	/SAVE IT IN THE ENTER CAL
	LAC*	ENTER	/PICK UP THE FILE NAME POINTER
	ISZ	ENTER	/MOVE POINTER PAST FILE NAME POINTER
	JMS	MOVENM	/MOVE THE FILE NAME
	ENTENM		/POINTER TO ENTER REQUEST NAME
	CAL	ENTFI	/ENTER REQUEST
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	LAC	EVA	/PICK UP THE EVENT VARIABLE
	SMA		/IS IT LEGAL?
	JMP*	ENTER	/YES -- ENTER DONE
	JMS	IOERR	/NO -- ERROR EXIT FILE
	LAC	OUTPCL	/LUN ON WHICH ERROR OCCURRED
/
/EXECUTE SIMULATED FSTAT ON FILE
/	OPEN FILE THEN CLOSE FILE TO DETERMINE IF IT EXISTS
/
FSTAT	0
	LAC*	FSTAT	/DETERMINE THE FILE TYPE
	RAL		/PUT IT IN THE LINK
	LAC	OUTPCL	/PICK UP THE OUTPUT LUN
	SNL		/IS IT OUTPUT?
	LAC	INPTCL	/NO MUST BE INPUT
	DAC	SEKCAL	/SET IT IN THE SEEK CAL
	DAC	CLOCL	/SET IT IN THE CLOSE CAL LUN
	LAC*	FSTAT	/PICK UP THE FILE NAME POINTER
	ISZ	FSTAT	/MOVE OVER FILE NAME
	JMS	MOVENM	/MOVE THE FILE NAME
	SEEKNM		/POINTER TO THE SEEK REQUEST
	CAL	SEKFI	/ISSUE A SEEK REQUEST
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	LAC	EVA	/PICK UP EVENT VARIABLE
	SAD	(-13)
	JMP	FSTNF	/FILE NOT FOUND
	SPA!CLA!CMA		/WAS THE FILE FOUND?
	JMP*	FSTAT	/NO RETURN -1 FOR FILE NOT FOUND
	CAL	CLOSCA	/CLOSE THE FILE
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	LAC	EVA	/CLOSE OK?
	SMA
	JMP*	FSTAT	/YES RETURN AC +1
	JMS	IOERR	/NO I/O ERROR
	LAC	SEKCAL	/LUN ON WHICH ERROR OCCURRED
/
FSTNF	CLA		/FILE NOT FOUND
	JMP*	FSTAT
/
/EXECUTE CLOSE ON IN OR OUT FILE
/	JMS CLSFIL	(AC .EQ. 0 IF INPUT OR BIT 0 =1 IF OUTPUT)
/
CLSFIL	0
	RAL		/SET INPUT OR OUTPUT IN LINK
	LAC	INPTCL	/PICK UP INPUT LUN
	SZL		/IS IT INPUT?
	LAC	OUTPCL	/NO MUST BE OUTPUT
	DAC	CLOCL	/SET IN CLOSE LUN
	CAL	CLOSCA	/ISSUE CLOSE REQUEST
	CAL	WFEVA	/WAIT FOR CLOSE
	LAC	EVA	/PICK UP EVENT VARIABLE
	SMA		/WAS IT OK?
	JMP*	CLSFIL	/YES RETURN
	SAD	(-11)	/WAS THE EVENT VARIABLE -11?
	JMP*	CLSFIL	/YES MUST BE OK
	JMS	IOERR	/NO -- I/O ERROR
	LAC	CLOCL	/LUN ON WHICH ERROR OCCURRED
/
/EXECUTE DELETE FILE ON NAMED FILE
DELFIL	0
	LAC*	DELFIL
	JMS	MOVENM	/MOVE NAME
	DELNAM		/DELETE NAME
	LAC*	DELFIL	/PICK UP THE INPUT  OR OUTPUT BIT
	RAL
	ISZ	DELFIL	/SKIP OVER POINTER
	LAC	OUTPCL	/IS IT OUTPUT
	SNL
	LAC	INPTCL	/NO MUST BE INPUT
	DAC	DELLUN	/SET IN DELETE LUN
	CAL	DEFILE	/EXECUTE DELETE REQUEST
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	LAC	EVA	/PICK UP EVENT VARIABLE
	SMA		/WAS IT LEGAL?
	JMP*	DELFIL	/YES RETURN
	SAD	(-13)	/NOT FOUND?
	JMP*	DELFIL	/YES -- OK IT IS DELETED 
	JMS	IOERR	/NO I/O ERROR
	LAC	DELLUN	/LUN ON WHICH ERROR OCCURRED
/
/RENAME A FILE
/	JMS RENAME
/	DEB1	/(BIT0 =0 IF INPUT : 1 IF OUTPUT
/	DEB2
/
RENAME	0
	LAC*	RENAME
	JMS	MOVENM	/MOVE NAME TO RSEEK REQUEST
	RENMSK		/RENAME SEEK
	LAC*	RENAME	/SETUP THELINK FOR INPUT OR OUTPUT
	RAL
	LAC	INPTCL	/PICK UP INPUT LUN
	SZL
	LAC	OUTPCL	/MUST BE OUTPUT CAL
	DAC	RENSK	/STORE IN REQUEST
	DAC	CLOCL
	CAL	RENCAL	/ISSUE RENAME SEEK
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	LAC	EVA	/PICK UP EVENT VARIABLE
	SPA		/WAS REQUEST OK?
	JMP	IOERRA	/NO I/O ERROR
	ISZ	RENAME
	LAC*	RENAME	/PICK UP SECOND NAME
	JMS	MOVENM
	CLONAM		/MOVE TO CLOSE REQUEST
	ISZ	RENAME
	CAL	CLOSCA	/ISSUE CLOSE WITH RENAME REQUEST
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	LAC	EVA	/PICK UP EVENT VARIABLE
	SMA		/IS IT POSITIVE
	JMP*	RENAME	/YES MUST BE OK
IOERRA	JMS	IOERR	/NO I/O ERROR
	LAC	CLOCL	/LUN ON WHICH ERROR OCCURRED
/
MOVENM	0
	JMS	GETBNK	/GET BANK BITS FOR XCT NAME
	DAC	TEMPA	/SAVE FROM ADDRESS
	LAC*	MOVENM	/PICK UP THE TO ADDRESS
	DAC	TEMPB	/SAV IT
	ISZ	MOVENM	/INCREMENT PAST TO POINTER
	LAW	-3	/MOVE ONLY THREE CHARACTERS
	DAC	TEMPC
MOVELP	LAC*	TEMPA	/PICK UP A WORD
	DAC*	TEMPB	/SAVE IT
	ISZ	TEMPA	/MOVE POINTERS
	ISZ	TEMPB
	ISZ	TEMPC
	JMP	MOVELP	/NOT FINISHED TRY NEXT ONE
	JMP*	MOVENM	/FINISHED RETURN
/
ATTTY	0	/ATTACH TELETYPES
	LAC	(DAT2)	/ATTACH INPUT TTY
	JMS	ATTACH
	LAC	(DAT3)	/ATTACH OUTPUT TTY
	JMS	ATTACH
	JMP*	ATTTY	/RETURN TO CALLER
/
DETTY	0	/DETACH FROM TTY'S
	LAC	(DAT2)	/DETACH FROM INPUT TTY
	JMS	DETACH
	LAC	(DAT3)	/DETACH FROM OUTPUT TTY
	JMS	DETACH
	JMP*	DETTY	/RETURN TO CALLER
/
/
/	I/O CPB'S
/
PREA14	2300	/PREALLOCATE LUN14
	EVA
	DAT14
/
PREA15	2300	/PREALLOCATE LUN15
	EVA
	DAT15
/
/
/
/
ENDPAR	0
SEKFI	3200	/SEEK REQUEST
	EVA	/EVENT VARIABLE
SEKCAL	0	/LOGICAL UNIT
SEEKNM	.BLOCK	3	/FILE NAME
/
ATCH	2400
	0
ATLUN	0
/
DTCH	2500
	EVTA
DETLUN	0
/
ENTFI	3300	/ENTER REQUEST
	EVA	/EVENT VARIABLE
ENTECL	0	/LOGICAL UNIT NUMBER
ENTENM	.BLOCK	3	/FILE NAME
/
CLOSCA	3400	/CLOSE REQUEST
	EVA	/EVENT VARIABLE ADDRESS
CLOCL	0	/LOGICAL UNIT NUMBER
CLONAM	.BLOCK	3	/FILE NAME FOR CLOSE WITH RENAME
/
DEFILE	3500	/DELETE REQUEST
	EVA	/EVENT VARIABLE 
DELLUN	0	/LOGICAL UNIT NUMBER
DELNAM	.BLOCK	3	/FILE NAME
/
RENCAL	3700	/OPEN TO RENAME CAL
	EVA	/EVENT VARIABLE ADDRESS
RENSK	0	/LOGICAL UNIT NUMBER
RENMSK	.BLOCK	3	/FILE NAME
/
EVA	0	/EVENT VARIABLE
WFEVA	20	/WAIT FOR REQUEST
	EVA
/
/
CRLF	2700	/WRITE
	EVTA	/EVENT VARIABLE
	DAT3	/LUN SLOT
	3	/IMAGE ASCII
	CHRMSG	/LINE
WRIMG	2700	/WRITE
	EVTA	/EVENT VARIABLE
	DAT3	/LUN SLOT
	3	/IMAGE ASCII
ADR000	CHRMS	/LINE
/
WFEVTA	20	/WAITFOR
	EVTA	/EVENT VARIABLE
EVTA	0
HINFA	3600	/HANDLER INFORMATION
	EVTA	/EVENT VARIABLE
	DAT14	/INPUT LUN
HINFB	3600	/HANDLER INFORMATION
	EVTA	/EVENT VARIABLE
	DAT15	/OUTPUT LUN
/
RDIN2	2600	/INPUT
	EVTA	/EVENT VARIABLE ADDRESS
	DAT10	/LUN SLOT
	2	/MOVE
SBADR	SBUFF	/DATA BUFFER
	BUFLEN	/MAX WORD COUNT
/
WFEVR	20	/WAIT FOR
	EVR
EVR	1
RDINP	2600	/INPUT
	EVR	/EVENT VARIABLE
INPTCL	0	/LUN SLOT
	2	/ASCII
RDCAL2	RDBUF2	/LINE BUFFER
	BUFLEN	/MAX WORD COUNT
/
WFEVW	20	/WAIT FOR
	EVW
EVW	1
WROUT	2700	/WRITE
	EVW	/EVENT VARIABLE
OUTPCL	0	/LUN SLOT
	2	/MODE
WRCAL2	0	/BUFFER ADDRESS
/
WRCAL3	2700	/WRITE TTY
	EVTA	/EVENT VARIABLE ADDRESS
	DAT3	/LUN SLOT
	2	/IOPS ASCII
TTOUT	0	/BUFFER ADDRESS
/
RDCALT	2600	/READ
	EVTA	/EVENT VARIABLE ADDRESS
	DAT2	/LUN SLOT
	2	/IOPS ASCII
TTIN	0	/BUFFER ADDRESS
	BUFLEN	/WORD COUNT
/
/
/	TEMPORARY STORAGE AND CONSTNTS
/
CHRMSG	2003	/CRLF MESSAGE
	0
C12	12	/LF
	15	/CR
TAB	11	/TAB
LOOPCT	0
POINTR	0
SRCNAM	.SIXBT	'SRC'
OUTDEV	1
INDEV	1
FSTSW=SEEKNM
LSTSW=SEEKNM
PK7BTS=SEEK
PK6WDC=SEEK
PK6CHR=SEEKNM
PK6TO=SEEKNM+2
C1000	1000
C15	15
C6	6
ONE	1
CHRCT	0
TEMPA	0
TEMPB	0
TEMPC	0
/
/
/	I/O ERROR HAS OCCURRED OUTPUT TO USER
/		EDT-I/O ERROR LUN XX YYYYYY
/
IOERR	0
	TCA		/COMPLEMENT EVENT VARIABLE TO MAKE IT POSITIVE
	LMQ		/SAVE IT IN MQ
	LAW	-6	/DECODE6 DIGITS
	DAC	TEMPA	/SAVE COUNT
	LAC	(IOER-1)	/SET UP MESSAGE POINTER
	DAC*	(X10)
DECOD	ECLA!LLS 3	/DECODE MQ - EVENT VARIABLE
	AAC	60	/ADD 60 TO DIGIT
DECODS	SAD	(60)	/IS IT A ZERO?
	JMP	NDECOD	/YES -- SUPPRESS LEADING ZEROES
	PAL		/SAVE AC
	LAC	DECRRA	/SET UP TO JUMP OVER ZERO SUPPRESSING
	DAC	DECODS	/SET JUMP
	PLA		/RESTORE AC
DECODR	DAC*	X10	/STORE CHARACTER
	ISZ	TEMPA	/FINISHED?
	JMP	DECOD	/NO DECODE IT
	LAC	(IOERL-1)	/SET UP TO DECODE LUN
	DAC*	(X10)
	XCT*	IOERR	/PICK UP LUN
	IDIV		/DIVIDE BY 10 TO FIND DECIMAL LUN
	12
	PAX		/SAVE REMAINDER
	LACQ		/PICK UP THE QUOTENT
	AND	(17)	/MASK OFF NUMBER
	AAC	60	/ADD 60
	DAC*	X10	/STORE IT
	PXA		/PICK UP REMAINDER AGAIN
	AND	(17)	/MASK IT OFF ALSO
	AAC	60	/ADD 60
	DAC*	X10	/STORE IT IN THE MESSAGE
	CAL	WRIOER	/WRITE ERROR ON OUTPUT TTY
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	JMP	EXIT1	/EXIT EDITOR
/
NDECOD	CLA		/SUPPRESS PRINTING
DECRRA	JMP	DECODR	/RETURN
/
IOERMS	ERMSE-IOERMS/2*1000+3
	0
	105	/E
	104	/D
	124	/T
	055	/-
	111	/I
	057	//
	117	/O
	040	/SP
	105	/E
	122	/R
	122	/R
	117	/O
	122	/R
	040	/SP
	114	/L
	125	/U
	116	/N
	040	/SP
IOERL	0	/LUN XX
	0
	040	/SP
IOER	.BLOCK	6	/EVENT VARIABLE
	000	/NULL
	015	/CR
	012	/LF
ERMSE=.
/
WRIOER	2700	/WRITE I/O ERROR MESSAGE
	EVA	/EVENT VARIABLE
	DAT3	/OUTPUT DEVICE
	3	/IMAGE ASCII
	IOERMS	/BUFFER ADDRESS
/
/
/
	.TITLE SUBR,CLSOUT FOR CLOSE PROC & EXIT PROC
/
/SUBROUTINE CLSOUT, CLOSE INPUT AND OUTPUT FILES.
CLSOUT	0
	JMS PUTLIN	/TRANSFER CURR LINE TO OUTPUT
	LAC	INFILE	/ IS THERE AN INPUT FILE PRESENT?
	SPA		/ SKIP IF SO.
	JMP CLS01A	/IF NOT, GO TRY TO CLOSE OUTPUT FILE.
CLS01B	JMS PUTLIN	/WRITE OUT THE CURRENT LINE.
	LAC	ONE	/SET UP NOPACKING SWITCH
	DAC	NOPKSW
	JMS GETLIN
	INLINE
	SKP!CLA
	JMP CLS01B	/MORE TO DO, GO WRITE THIS LINE.
	DZM	NOPKSW	/CLEAR THE NO PACKING SWITCH
	JMS CLSFIL	/CLOSE THE INPUT FILE.
CLS01A	LAC OUTSW1	/HAS ANYTHING BEEN PUT INTO THE OUTPUT FILE?
	SPA!CLA!CMA	/SKIP IF SO.
	JMP EMPFIL	/NOTHING IN FILE, GO COMMENT.
	JMS CLSFIL
	LAC INFILE	/IS THERE AN INPUT FILE PRESENT?
	SPA		/SKIP IF SO.
	JMP CLS03		/IF NOT, GO DEAL WITH OUTPUT FILE.
	LAC OUTDEV	/IS THE OUTPUT DEVICE FILE-STRUCTURED?
	SPA		/SKIP IF SO.
	JMP* CLSOUT	/OTHERWISE, RETURN TO CALLER.
	LAC SAVESW	/IS A SAVE WANTED?
	SZA		/SKIP IF SO.
	JMP CLS02		/IF NOT, GO CLOSE AS USUAL.
SAVBCK	JMS FSTAT		/CHECK FOR PRESENCE OF SAVNAM.
	SAVNAM		/..
	SZA		/NOT FOUND, SKIP.
	JMP SAVERR	/SAVNAM IS IN USE, COMPLAIN.
	JMS RENAME	/NAME IS OK, RENAME THE INPUT FILE.
	INNAME		/..
	SAVNAM		/..
	LAW -1		/TURN OFF SAVESW.
	DAC SAVESW	/..
	JMP CLS03
CLS02	JMS DELFIL
	INNAME
CLS03	JMS FSTAT
	XCT INNAME
	SZA
	JMP CLSERR
	JMS RENAME
	XCT TFILE1
	INNAME
	LAC FILSTR
	SMA		/SKIP IF NON-FILE-ORIENTED.
	JMS CHDAT		/FILE-ORIENTED, GO EXCHANGE DAT ASSIGNMENTS.
	JMP* CLSOUT	/AND RETURN TO CALLER.
/COME HERE ON FILE-NAME DIFFICULTIES DURING CLOSE SEQUENCE.
CLSERR	LAC TFLDEB	/ADDRESS OF .TFIL1 EDT DIR ENTRY BLOCK.
	DAC CLSENT	/SET UP TO USE THAT NAME.
	LAC FILSTR	/BOTH DEVICES FILE-STRUCTURED?
	SPA		/SKIP IF SO.
	JMP SETF1		/IF NOT, SKIP ALL THIS STUFF.
	JMS DEVCHK
	JMP SETF1		/SAME UNIT, DON'T BOTHER SWITCHING.
	LAC DIRSW		/WHICH DIRECTION ARE WE GOING?
	SPA		/SKIP IF GOING FROM -14 TO -15.
	JMP SETF1		/GOING BACK TO -14, EVERYTHING OK.
/COME HERE ON TROUBLE TRYING TO CLOSE ON -15.
	JMS CHDAT		/GO CHANGE DAT SLOTS AROUND.
	JMS FSTAT		/IS THERE A .TFIL1 EDT ON -14?
	XCT TFILE1	/-14 IS NOW THE OUTPUT DAT SLOT.
	SZA		/SKIP IF .TFIL1 EDT IS NOT PRESENT.
	JMP SETF1		/.TFIL1 EDT IS THERE, GO COMMENT.
	JMS FSTAT		/MAYBE ORIGINAL FILE NAME IS THERE.
CLSINN	XCT INNAME	/..
	SZA		/SKIP IF INNAME IS OK FOR -14.
	JMP CLSSK		/NOT OK, USE .TFIL1 EDT.
	LAC CLSINN	/USE INNAME.
	DAC CLSENT	/..
CLSSK	JMS SEEK		/SEEK THE INPUT FILE.
	TFILE1
	JMS ENTER		/OPEN UP THE OUTPUT FILE.
CLSENT	0		/INNAME OR .TFIL1
	DZM OUTSW1	/FORESTALL ANOTHER ENTER.
CLSRD	JMS RDFILE	/READ A LINE.
	INLINE
	JMP CLSCLS	/IF EOF ENCOUNTERED.
	JMS WRFILE	/WRITE THE LINE READ.
	JMP CLSRD		/GO FOR MORE.
/COME HERE ON COMPLETE FILE TRANSFERRED.
CLSCLS	CLA!CMA
	JMS CLSFIL	/CLOSE THE OUTPUT FILE.
	CLA
	JMS CLSFIL	/CLOSE THE INPUT FILE, TOO.
	JMS DELFIL	/THEN DELETE THE INPUT FILE.
	TFILE1		/..
SETF1	JMS	ATTTY	/ATTACH TTY'S
	LAW	INNAME
	JMS TYNAME
	LAW TWOFIL
	JMS TYPOUT
	LAW NUFIL1
	JMS TYPOUT
	LAC OUTPCL
	RTR
	LAW 64
	SZL
	ADD ONE
	JMS TYONCH
	LAW NUFIL2
	JMS TYPOUT
	LAC CLSENT
	JMS TYNAME
	JMS TYPRTN
	LAW OLDEL
	JMS TYPOUT
	JMS	DETTY	/DETACH TTY'S
	JMP EXITCH	/CHECK FOR EXIT REQUEST
SAVERR	JMS	ATTTY	/ATTACH TTY'S
	LAW	SAVNAM	/GIVE USER ERROR MESSAGE
	JMS	TYNAME		/ABOUT SAVNAM BEING ON
	LAW	TWOFL1		/INPUT DEVICE
	JMS	TYPOUT
	LAW	BADNAM
	JMS	TYPOUT
	LAW 76
	JMS TYONCH
	LAW	TYLINE
	JMS	TYPEIN		/READ IN NEW NAME
	LAW	-1		/RESET SAVE SW
	DAC	SAVESW
	JMS	DETTY	/DETACH TTY'S
	JMS	UNPACK		/UNPACK IT TO EDLIN
ADR016	TYLINE
	EDLIN
	SNA			/IF NO NAME TYPED
	JMP	CLS02		/DO NOT SAVE INPUT FILE
	LAC	EDLADR
	DAC	NXTPTR
	JMS	GETCOM		/GET FILE NAME
	JMS	GETSNM		/AND MAKE UP DEB
	JMP	SAVBCK		/GO BACK AND CKECK NEW NAME
EMPFIL	LAW EMPFLM
	JMS TYPOUT
	JMS DELFIL	/DELET TFILE1
	XCT TFILE1	/FROM OUTPUT DEVICE
	JMP EXITCH	/CHECK FOR EXIT REQUEST
SAVNAM	.BLOCK 3
/
/
/COMMON EXIT ROUTINE.
/
/
EXIT	LAC SKPLIT	/SET REQUEST SWITCH
	DAC EXITRQ
	XCT EXITSW	/IS THERE A FILE OPEN
	JMP EXIT1	/NO  GO AN EXIT
	JMP CLOSE	/YES GO AN CLOSE OUT FILES
EXITCH	XCT EXITRQ	/COME HERE AFTER CLOSING FILES
	JMP BEGIN	/IF THIS WAS NOT AN EXIT REQUEST
EXIT1	LAC	(DAT14)	/DETACH ALL LUN'S
	JMS	DETACH
	LAC	(DAT15)
	JMS	DETACH
	LAC	(DAT10)
	JMS	DETACH
	LAC	(DAT3)
	JMS	DETACH
	LAC	(DAT2)
	JMS	DETACH
	CAL	(10)	/EXIT
	.TITLE TELETYPE I/O SUBROUTINES
/CLOSED SUBROUTINES FOR TYPEWRITER INPUT AND OUTPUT.
  
  
/SUBROUTINE TYPOUT, SET UP AND ISSUE CAL FOR IOPS ASCII OUTPUT MESSAGE.
/CALL:	LAW OUTMSG	/START ADDRESS (HEADER WORD 0) OF MESSAGE TO PRINT.
/	JMS TYPOUT	/GO TO TYPOUT.
TYPOUT	0		/ENTRY TO TYPOUT.
	JMS GETBNK	/GET SOME EPC BITS.
	DAC TTOUT		/INSERT 15-BIT ADDRESS IN CAL SEQUENCE.
	CAL	WRCAL3	/WRITE TTY OUTPUT
	JMS	WFEV	/WAIT FOR EVENT VARIABLE AND CHECK VALIDITY
	LAC	(DAT3)	/LUN OF ERROR
	JMP* TYPOUT	/RETURN TO CALLER.
  
/SUBROUTINE TYPEIN, SET UP AND ISSUE CAL FOR IOPS ASCII INPUT LINE.
/CALL:	LAW INBUFF	/WHERE TO PUT INCOMING LINE.
/	JMS TYPEIN	/GO TO TTY READER.
TYPEIN	0		/ENTRY TO TYPEIN.
	JMS GETBNK	/INSERT EXTENDED-MEMORY BITS.
	DAC TTIN		/GIVE TRUE (15-BIT) ADDRESS TO CAL SEQUENCE.
	CAL	RDCALT	/READ TTY INPUT
	JMS	WFEV	/WAIT FOR EVENT VARIABLE AND CHECK VALIDITY
	LAC	(DAT2)	/LUN OF ERROR
	JMP* TYPEIN	/RETURN TO CALLER.
  
/SUBROUTINE TYNAME, TYPE OUT FILE NAME STORED IN DEB FORMAT.
/CALL:	LAW DEBADR	/START ADDRESS OF DEB TO TYPE OUT.
/	JMS TYNAME	/GO PRINT IT.
TYNAME	0		/ENTRY TO TYNAME.
	JMS GETBNK	/13-BIT ADDRESS OF DEB IS IN AC AT CALL.
	DAC ERNAME	/SAVE 15-BIT ADJUSTED ADDRESS.
	LAW FILMES	/TYPE "FILE".
	JMS TYPOUT	/..
	JMP LAWBLK	/THEN PRINT OUT A BLANK.
TYNSW1	LAW -3		/WILL BE -2 WHEN CONTROL FIRST COMES HERE.
	DAC LOOPCT	/COUNT TWO WORDS (FILE NAME) OR ONE WORD (EXT).
TYNLP1	LAW -3		/COUNT THREE CHARACTERS EACH WORD.
	DAC CHRCT		/..
	LAC* ERNAME	/GET NEXT WORD FROM DIRECTORY ENTRY BLOCK.
	DAC ERWORD	/SAVE AS CURRENT WORD.
TYNLP2	LAC ERWORD	/GET CURRENT WORD. NEXT CHAR IS IN BITS 0-5.
	RTL		/SHIFT OUT SIX BITS.
	RTL		/..
	RTL		/..
	DAC ERWORD	/SAVE REMAINDER FOR NEXT TIME.
	RAL		/GET SIXTH BIT FROM LINK.
	AND C77		/THROW AWAY JUNK.
	XOR C77		/COMPLEMENT RIGHT SIX BITS ONLY.
	SAD C77		/NULL CHARACTER?
	JMP TYNLP3	/YES, IGNORE.
	TAD LAWBLK	/GENERATE SEVENTH (LEFTMOST) BIT.
	XOR C77		/RESTORE RIGHTMOST FIVE BITS.
	XOR LAWBLK	/RESTORE SIXTH BIT.
	JMS TYONCH	/GO TYPE OUT THIS CHARACTER.
TYNLP3	ISZ CHRCT		/COUNT CHARS PER WORD.
	JMP TYNLP2	/MORE CHARS IN THIS WORD, GO GET NEXT ONE.
	ISZ ERNAME	/CURRENT WORD EMPTY, SERVICE NEXT ONE.
	ISZ LOOPCT	/COUNT WORDS IN THIS PORTION OF DEB.
	JMP TYNLP1	/ANOTHER WORD TO TREAT, DO SO.
LAWBLK	LAW 40		/FILE NAME OR EXT FINISHED, GET BLANK.
	JMS TYONCH	/TYPE IT OUT.
	ISZ TYNSW1	/COUNT THREE BLANK CHARS TYPED.
	JMP TYNSW1	/ANOTHER GROUP TO DO.
	LAW -3		/ALL DONE, RESET TYNSW1 FOR NEXT TIME.
	DAC TYNSW1	/..
	JMP* TYNAME	/RETURN TO CALLER.
FILMES	002002		/HEADER WORD 1: 2 PAIRS, IOPS ASCII.
C2000	2000		/CHECKSUM -- IGNORED BY TELETYPE HANDLER.
	.ASCII 'FILE'<175>
/SUBROUTINE TYONCH, OUTPUT SINGLE CHARACTER IN AC.
/NO WAIT REQUIRED BEFORE STORING C(AC) IN SINGCH.
/CALL:	LAW CHAR  	/CHARACTER TO BE TYPED IN AC(11-17).
/	JMS TYONCH	/GO TO TYONCH.
TYONCH	0		/ENTRY TO TYONCH.
	DAC SINGCH	/STORE CHAR TO TYPE IN IMAGE ASCII LINE BUFFER.
	CAL	WRIMG	/WRITE MESSAGE
	JMS	WFEV	/WAIT FOR EVENT VARIABLE
	LAC	(DAT3)	/LUN OF ERROR
	JMP* TYONCH	/RETURN TO CALLER.
CHRMS	002003		/HEADER WORD 0: 2 PAIRS, IMAGE ASCII.
C3000	3000		/CHECKSUM -- IGNORED BY TELETYPE HANDLER.
SINGCH	0		/CHARACTER TO BE TYPED IN BITS 11-17.
C177	177		/RUBOUT WILL TURN OFF TYPING.
C13	13	/CONSTANT 13 FOR AUTO XR'S
  
/SUBROUTINE TYPRTN, PRODUCE CARRIAGE-RETURN AND LINE-FEED ON TELETYPE.
/CALL:	JMS TYPRTN
TYPRTN	0		/ENTRY TO TYPRTN.
OCTNUM=TYPRTN		/GETOCT: RESULTS REGISTER.
	CAL	CRLF	/RETURN CARRAGE
	JMS	WFEV	/WAIT FOR EVENT VARIABLE AND CHECK VALIDITY
	LAC	(DAT3)	/LUN IN ERROR
	JMP* TYPRTN	/RETURN TO CALLER.
	.TITLE MESSAGES
/MESSAGES OUT.
EDTMES	ENDED1-.*400+2
	0
	.ASCII /EDITRSX V20A/<15>
ENDED1=.
ERREQM	ENDERQ-.*400+2
BNUM	0	/PARTIAL RESULT DURING RADIX CONVERT OF NUMERIC ARGS.
PK5CHR=BNUM	/5-CHARACTER COUNTER FOR PACK-UNPACK.
PK6CT1=BNUM
	.ASCII 'NOT A REQUEST:'<15>
ENDERQ=.
INPTM	ENDINM-.*400+2
FINDSW	0	/INDICATOR FOR FIND AND LOCATE SEQUENCES.
	.ASCII 'INPUT'<15>
OUTSW1=.-1		/-1 IF OUTPUT FILE IS EMPTY, 0 OTHERWISE.
ENDINM=.
EOFRM	ENDEFM-.*400+2
NUMPTR	0	/POINTER TO CURRENT DIGIT IN ARGUMENT STRING.
PLBH=NUMPTR	/POINTER TO LINE BUFFER HEADER, WORD 0.
	.ASCII 'END OF FILE REACHED BY:'<15>
ENDEFM=.
EOMRM	ENDEMM-.*400+2
MAXLEN	LINSIZ
	.ASCII 'END OF MEDIUM REACHED BY:'<15>
ENDEMM=.
NXTPTR	0	/POINTER TO NEXT CHARACTER IN CONTROL WORD STRING.
NOFIL1	ENDNF1-.*400+2
	.ASCII 'NO INPUT FILE PRESENT.'<15>
ENDNF1=.
NOFLNM	ENDNFN-.*400+2
QRETN	0	/QRETN MAY NEVER BE USED EXCEPT FOR ^P PC STORAGE.
	.ASCII 'NO FILE NAME GIVEN.'<15>
ENDNFN=.
TOPRQM	ENDTRQ-.*400+2
BNKMSK	060000
	.ASCII 'TOP REQUEST NEEDED.'<15>
ENDTRQ=.
TWOFIL	ENDTF-.*400+2
GBADR	0
	.ASCII 'IS PRESENT ON OUTPUT DEVICE.'<15>
ENDTF=.
TWOFL0	ENDTF0-.*400+2
EXITRQ	0		/EXIT REQUEST SWITCH
	.ASCII 'PLEASE RENAME IT OR IT WILL BE DELETED.'<15>
ENDTF0=.
TWOFL1	ENDTF1-.*400+2
SAVESW	-1
	.ASCII 'IS PRESENT ON INPUT DEVICE.'<15>
ENDTF1=.
BADNAM	ENDBDN-.*400+2
QUOTE	0		/QUOTE CHARACTER FOR CHANGE REQUEST.
	.ASCII 'PLEASE TYPE IN ANOTHER NAME.'<15>
ERWORD=QUOTE
ENDBDN=.
FILN1	ENDFN1-.*400+2
DELSW	0		/INDICATOR FOR NEXT AND DELETE SEQUENCES.
ERNAME=DELSW
	.ASCII 'NOT FOUND.'<15>
	.LOC .-1
C7	7
ENDFN1=.
EMPFLM	ENDEMF-.*400+2
LEN1	0
	.ASCII 'NOTHING IN FILE.'<15>
	.LOC .-1
C17	17
ENDEMF=.
PRTYMS	ENDPMS-.*400+2
CONVLT	0
	.ASCII 'READ ERROR:'<15>
	.LOC .-1
ADRMSK	017777
ENDPMS=.
TRNMES	ENDTRN-.*400+2
CL0777	077777
	.ASCII 'TRUNCATED:'<15>
	.LOC .-1
C60	60
ENDTRN=.
CL7000	700000
NUFIL1	ENDNF1-.*400+2
EXITSW	0		/INDICATES OPEN FILE FOR EXIT ROUTINE
	.ASCII 'YOUR EDITED FILE IS ON .DAT -1'<175>
	.LOC .-1
TWO	2
ENDNF1=.
OLDEL	ENDOLD-.*400+2
TYLNPT	0
	.ASCII 'ORIGINAL FILE DELETED.'<15>
ENDOLD=.
NUFIL2	ENDNF2-.*400+2
INLNPT	0
	.ASCII ' AS '<175>
ENDNF2=.
SLASH	57	/SLASH (/) FOR BRIEF MODE SERVICER.
ENDSVM=.
NOSTGM	NENGMS-.*400+2
OVFLAD	0
	.ASCII 'NO STRING'<15> ;NENGMS=.
SGTSW	0		/LINE SWITCH FOR "SGTRAN"
	.LOC .-1
CHGREQ	SKP		/SWITCH FOR CHANGE COMMAND
MTWO	-2
LINCSW	SKP		/SWITCH FOR LINE CONVERT
TFILE1	.SIXBT '.TFIL1'
EDNAM	.SIXBT 'EDT'
EDTM	002002
LENGTH	0	/TOTAL DATA CHARACTERS IN CURRENT LINE.
	.ASCII 'EDIT'<15>
	.TITLE GETBNK,GETCOM & GETNUM
/SUBROUTINE GETBNK, ADD EXTENDED MEMORY BITS REFERENCING CURRENT
/BANK TO 13-BIT ADDRESS IN AC.
/CALL:	LAW ADDR		/GET ADDRESS TO BE MODIFIED.
/	JMS GETBNK	/CALL GETBNK.
/FOR BANK MODE VERSION
/IE 13 BIT ADDRESSING
/ADRMSK=017777 AND BNKMSK=060000
/
GETBNK	0		/ENTRY TO GETBNK.
CWCHRC=GETBNK		/GETCOM: MAXIMUM CHARACTERS POSSIBLE IN LEGAL COMMAND WORD.
	AND ADRMSK	/EXTRACT 13-BIT ADDRESS FROM AC.
	DAC GBADR		/SAVE TEMPORARILY.
	LAC GETBNK	/GET ENTRY.
	AND BNKMSK	/GET BANK BITS
	ADD GBADR		/NOW RETRIEVE 13-BIT ADDRESS.
	JMP* GETBNK	/EXIT WITH 15-BIT ADDRESS IN AC.
/SUBROUTINE GETCOM, EXTRACT CONTROL WORD FROM TYPED INPUT LINE.
/IGNORES LEADING BLANKS IN STRING AND TERMINATES ON FIRST FOLLOWING
/BLANK OR END-OF-LINE. IF STRING BEING EXTRACTED EXCEEDS SEVEN CHARACTERS
/IN LENGTH, THE RIGHTMOST OVERFLOW CHARACTERS ARE THROWN AWAY. TOTAL
/CHARACTERS IN STRING EXTRACTED IS RETURNED TO THE CALLER IN THE AC.
GETCOM	0		/ENTRY TO GETCOM.
	LAC CWDLIT	/POINTER TO START OF CONTROL-WORD ARRAY.
	DAC CWDPTR	/SAVE AS CURRENT-CHARACTER POINTER.
FIVE70	LAW -10		/LENGTH OF CONTROL-WORD ARRAY (CWD).
	DAC CWCHRC	/SAVE AS MAXIMUM-CHARACTERS COUNTER.
	DZM NCHARS	/ZERO TOTAL CHARACTERS IN CONTROL-WORD STRING.
	CLL!CML		/INDICATE NO CHARACTERS ENCOUNTERED YET.
GTNXT	JMS NXTCHR	/GET NEXT CHARACTER FROM INPUT LINE.
	JMP GTCLOS	/NO MORE CHARACTERS, CLOSE OUT ARRAY.
	SAD BLANK		/SUCCESS. IS CHARACTER A BLANK?
	JMP BLKFND	/YES, MAKE SURE SOME DATA PRECEDED IT.
	SAD	(54	/IS THE CHAR A COMMA? IF SO, JMP TO COMMA.
	JMP	COMMA
	CLL		/NO, INDICATE SOME NON-BLANK CHARACACTER HAS BEEN FOUND.
	ISZ CWCHRC	/BUMP MAXIMUM-CHARACTERS-ALLOWED.
	JMP GTCPUT	/NO OVERFLOW YET, PUT CHARACTER AWAY.
	CLC		/SEVEN CHARACTERS INSERTED, DON'T ALLOW ANY MORE.
	DAC CWCHRC	/RESET CWCHRC TO -1.
	JMP GTNXT		/THEN GO LOOK FOR BLANK OR TERMINATOR.
/COME HERE TO INSERT DATA CHARACTER IN CWD ARRAY.
GTCPUT	DAC* CWDPTR	/PUT CHARACTER AWAY.
	ISZ CWDPTR	/BUMP POINTER FOR NEXT TIME.
	ISZ NCHARS	/AND BUMP CHARACTERS PROCESSED.
	JMP GTNXT		/THEN GO FOR NEXT CHARACTER.
/COME HERE ON BLANK FOUND IN INPUT LINE.
BLKFND	SZL!CLA!CMA	/SKIP IF THIS  S NOT A LEADING BLANK.
	JMP GTNXT		/LEADING BLANK, IGNORE IT.
GTCLOS	DAC* CWDPTR	/NOT LEADING BLANK, THEN TERMINATE STRING (AC = -1 NOW).
	LAC NCHARS		/PICK UP TOTAL CHARACTERS IN STRING.
	JMP* GETCOM	/AND RETURN TO CALLER.
COMMA	CLC	/A COMMA HAS BEEN FOUND TREAT IT LIKE A DELIMETER
	JMP	GTCLOS
CWD	.BLOCK 10	/ROOM FOR LONGEST LEGAL CONTROL WORD AND TERMINATOR.
/SUBROUTINE NXTCHR, RETURN NEXT 7-BIT CHARACTER FROM UNPACKED INPUT
/ARRAY. NXTPTR MUST BE SET TO BEGINNING OF ARRAY BEFORE FIRST CALL.
/CALL:	JMS NXTCHR	/GO TO NXTCHR.
/	JMP DONE		/RETURN HERE IF END-OF-LINE ENCOUNTERED.
/	DAC CHAR		/RETURN HERE WITH CHARACTER IN AC.
NXTCHR	0		/ENTRY TO NXTCHR.
TNUM=NXTCHR		/GETNUM: TEMPORARY STORAGE.
	LAC* NXTPTR	/GET NEXT CHARACTER.
	SPA		/TERMINATOR?
	JMP* NXTCHR	/YES, RETURN IMMEDIATELY.
	ISZ NXTPTR	/OTHERWISE BUMP POINTER FOR NEXT TIME.
	ISZ NXTCHR	/AND BUMP RETURN ADDRESS.
	JMP* NXTCHR	/THEN RETURN TO CALLER WITH CHARACTER IN AC 11-17.
/SUBROUTINE GETNUM, RETURN BINARY VALUE IN AC OF THE DECIMAL
/ARGUMENT IN THE CONTROL WORD STRING. NUMBER IS RETURNED IN NEGATIVE (2'S
/COMPLEMENT) FORM. IF NO PARAMETER IS PRESENT, AC = 777777. THE
/APPEARANCE OF ANY NON-NUMERIC IN THE PARAMETER STRING CAUSES
/TRANSFER OF CONTROL TO ILLCWD AND SUBSEQUENT DISREGARD OF THE
/ENTIRE COMMAND.
GETNUM	0		/ENTRY TO GETNUM.
	JMS GETCOM	/GET NEXT CONTROL-WORD STRING.
	LAC CWDLIT	/SET DIGIT POINTER TO
	DAC NUMPTR	/BEGINNING OF CONTROL-WORD STRING.
	DZM BNUM		/SET INITIAL RESULT TO ZERO.
GTNLP	LAC* NUMPTR	/ENTER MAIN LOOP, GET NEXT DIGIT FROM INPUT STREAM.
	SPA		/TERMINATOR CHARACTER?
	JMP GTNRTN	/YES, GO TO RETURN.
	AND C17		/NO, MASK OFF NUMERICS.
	DAC TNUM		/SAVE NUMERICS.
	CMA
	TAD C12
	SPA
	JMP ILLCWD
	LAC TNUM
	XOR* NUMPTR	/ZERO NUMERICS, REINSERT ZONE BITS.
	XOR C60		/THEN ZERO ZONE BITS. THIS ONLY SEEMS TEDIOUS.
	SZA		/BITS 2 AND 3 ON, BIT 1 OFF: NUMBER PRESENT.
BADARG	JMP ILLCWD	/NON-NUMBER OTHERWISE. GO COMMENT.
	LAC BNUM		/GET VALUE COMPUTED SO FAR, THEN MULTIPLY BY 10.
	CLL!RAL		/FORM BNUM * 2.
	RTL		/BNUM * 8.
	ADD BNUM		/BNUM * 9.
	ADD BNUM		/BNUM * 10.
	ADD TNUM		/BNUM PLUS CURRENT DIGIT.
	DAC BNUM		/NEW VALUE.
	ISZ NUMPTR	/BUMP POINTER TO NEXT DIGIT.
	JMP GTNLP		/LOOP TILL DONE.
GTNRTN	LAC BNUM		/ALL FINISHED, GET FINAL VALUE.
	SZA!CMA		/IF BNUM .E. 0, BNUM = 1.
	TAD ONE		/IF BNUM .G. 0, FORM 2'S COMPLEMENT.
	JMP* GETNUM	/RETURN TO CALLER WITH RESULT IN AC.
	.TITLE EOF PROC,I/O .INIT SUBR & CHDAT SUBR
/COME HERE ON EOF ENCOUNTERED IN INPUT FILE.
EOF	LAW	EOFRM
	JMS	TYPOUT
EOFCOM	JMS PACK
ADR010	EDLIN
	TYLINE
	LAW TYLINE
	JMS TYPOUT
	JMP FND4
/
/
IOINIT	0
CWDPTR=IOINIT
	LAC ICLSW	/CHECK TO SEE IF ICLOSE WAS
	SMA!CLA!CMA	/REQUESTED
	JMP ICLREQ
	DZM LENGTH	/DON'T ZERO IF ICLOSE REQ
	LAW -1
	DAC OUTSW1	/INDICATE NOTHING WRITTEN YET IN OUTPUT FILE
ICLREQ	DAC RDFNOP	/IF ICLOSE REQ LEAVE OUTSW1 ALONE
	DAC INFILE
	DAC OWFLSW
	DZM	OUTDEV	/INDICATE FILE STRUCTURED
	DZM	INDEV
	LAC INFILE
	TAD OWFLSW
	SAD NAMEIN
	SKP!CLA
	CLA!CMA
	DAC FILSTR
	LAW -1
	DAC ICLSW	/RESET ICLOSE SWITCH
	JMP* IOINIT
ICLSW	-1
INFILE	-1
OWFLSW	-1
FILSTR	0
INPSW	0
/
/SUBROUTINE TO CHECK IF BOTH INPUT
/AND OUTPUT DAT SLOTS ARE ASSIGNED
/TO THE SAME DEVICE AND UNIT NUMBER
/
/ALSO, FOR DOS15 CHECK FOR SAME UIC.
/
/CALL	JMS DEVCHK
/	RETURN	/ALL THINGS THE SAME
/	RETURN	/NOT THE SAME
/
/
DEVCHK	0
	CAL	HINFA
	JMS	WFEV
	LAC	(DAT14)	/LUN IN ERROR
	LAC	EVTA
	AND	(7777)	/MASK OFF DEVICE AND UNIT TYPE
	DAC	TEMPB	/SAVE THE DEVICE CODES
	CAL	HINFB	/FIND OUT ABOUT THE OUTPUT DEVICE
	JMS	WFEV	/WAIT FOR EVENT VARIABLE
	LAC	(DAT15)	/LUN IN ERROR
	LAC	EVTA	/PICK UP EVENT VARIABLE
	AND	(7777)	/MASK OFF THE DEVICE AND UNIT CODES
	SAD	TEMPB	/ARE THEY THE SAME?
	JMP* DEVCHK	/SAME  EXIT
NOGO	ISZ DEVCHK	/BUMP TO NOT SAME EXIT
	JMP* DEVCHK	/EXIT
/
/
/SUBROUTINE CHDAT, CHANGE DAT SLOTS AROUND.
CHDAT	0
	LAC DIRSW
	CMA
	DAC DIRSW
	LAC OUTPCL
	DAC RENAME
	LAC INPTCL
	DAC OUTPCL
	LAC RENAME
	DAC INPTCL
	DZM OUTPSW
	JMS IOINIT
	JMP* CHDAT
/
/
	.LTORG
	.TITLE	BUFFERS
/
/DEFINE BUFFERS USED BY THE EDITOR
/
EDLIN=.			/CURRENT COMMAND STRING ARRAY.
INLINE=EDLIN+LINSIZ	/CURRENT INPUT LINE FROM FILE OR KEYBOARD.
TYLINE=INLINE+LINSIZ
/DEFINE TEMPORARY STORAGE REGISTERS RESIDING IN TYLINE AREA.
SBUFF=TYLINE+LINSIZ
RDBUF1=SBUFF+BUFLEN
RDBUF2=RDBUF1+BUFLEN	/..
WRBUF1=RDBUF2+BUFLEN
WRBUF2=WRBUF1+BUFLEN
LABUF=WRBUF2+BUFLEN-1
/
/
	.LOC LABUF
	0
/
/
	.TITLE ONE TIME SECTION
	.LOC EDLIN
/ONE-TIME SECTION TO SET UP CONSTANT ADDRESSES WITH EPC BITS
/TO REFERENCE PROPER (CURRENT) BANK; CALCULATE START OF BLOCK
/BUFFERS. CODING RESIDES IN READ-WRITE LINE BUFFER AREAS AND SETS "BEGIN"
/TO NOP TO AVOID FURTHER CALLS.
SETBNK	LAC NOPLIT
	DAC BEGIN
	CAL	PREA14	/PREALLOCATE
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	LAC	EVA
	SMA	
	JMP	PRE15	/OK TRY NEXT ONE
	SAD	(-6)	/NOT IMPLEMENTED?
	JMP	PRE15	/YES -- IGNORE
	JMS	IOERR	/NO I/O ERROR
	LAC	(DAT14)	/ERROR LUN
PRE15	CAL	PREA15	/PREALLOCATE LUN 15
	CAL	WFEVA	/WAIT FOR EVENT VARIABLE
	LAC	EVA
	SMA
	JMP	BEGIN	/OK PREALLOCATION
	SAD	(-6)	/NOT IMPLEMENTED?
	JMP	BEGIN	/YES OK
	JMS	IOERR	/NO I/O ERROR
	LAC	(DAT15)	/LUN OF ERROR
	.LTORG
LAONCE=.-1
	.END	BEGIN
