	.TITLE	EDI.NN - RSX MULTI EDITOR - ASSEMBLY PARAMETERS
/
/  10 NOV 76 (PDH) RESURRECT MY EDIT 000, LOST DURING A DISK DISASTER
/  21 SEP 76 - PAUL HENDERSON
/
	.DEC
/NN=00		/ DEFINE NN FOR TTY NN
RSX=0
COPY=2+NN	/ 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 CONDITIONALIZED.
		/ HENCE WE DEFINE COPY=2+NN FOR ALL CASES AND
		/ ALL IS WELL.
DAT15=50+NN	/ DISK SCRATCH FILE
DAT14=40+NN	/ FILE INPUT/OUTPUT
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 PROGRAM CONTAINS A 37(8) PATCH
/AREA STARTING AT "PATCHF" AND ENDING
/AT "PATCHL". THIS AREA IS TO BE USED
/FOR PATCHING, WHEN THE PROGRAM IS MADE INTO
/A SYSTEM FILE WITH THE PATCH LOADER
/
/
/
///
///	THIS SOURCE CAN PRODUCE THE FOLLOWING VERSIONS
///
///	VP STORAGE SCOPE VERSION
///	VT15 DISPLAY VERSION
///	STANDARD TEXT EDITOR
///	RSX VERSION
///
/ASSEMBLY PARAMETER ASSIGNMENTS:
/*** THIS SOURCE IS MADE TO PRODUCE A BINARY
/*** FILE WHICH IS MADE INTO A CORE IMAGE
/*** SYSTEM FILE WITH "PATCH"
/
/*** TO GET A BIN FILE WHICH WILL RUN
/*** UNDER THE LINKING LOADER OR DDT
/*** BIN=0  MUST BE DEFINED
/
/   I. FOR THE DOS -15 VERSION
/	NO PARAMETERS NEEDED
/	FOR THE KEYBOARD MONITOR (KM9/15 V5A)
/	DEFINE KMV5A=0 OR ADSS=0
/	FOR THE VT15 VERSION
/	    EDITVT=0
/	MUST BE DEFINED
/	FOR THE VP STORAGE SCOPE VERSION
/	    EDITVP=0
/	MUST BE DEFINED
/
/	THE STD TEXT EDITOR VERSION IS THE DEFAULT
/
/  II.  PAPER TAPE SYSTEMS
/	A. PTP=1.
/	B.  .DAT=N WHERE N IS THE VALUE OF
/	.DAT IN THE OBJECT SYSTEM.
/       NO OTHER PARAMETER ASSIGNMENTS ARE ALLOWED.
/
/  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
/	C. *** NOTE EDITVT AND NONEAE ARE ILLEGAL ***
/	   *** ALSO EDITOR ***
/	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.
/
/   IV.	IF OBJECT MACHINE DOES NOT HAVE EAE
/	THEN NONEAE=0 MUST BE DEFINED.
/
/
///	.ABS
///  ORIGIN-SETTING STATEMENTS WERE DELETED TO MAKE THIS DISPLAY
/// EDITOR RELOCATABLE AND LINK-LOADABLE. THE '.IODEV' STATEMENT WAS
/// INSERTED, ADDING .DAT SLOT 10 FOR THE DISPLAY.
///	.LOC BANK*20000+EDSTRT
/
/
	.IFUND RSX
	.EBREL
/
/*** CALCULATE THE OFFSET ADDRESS TO BE USED WHEN ***
/*** MAKING THIS RELOCATABLE PROGRAM INTO A SYSTEM ***
/*** FILE (CORE IMAGE) WITH THE PATCH LOADER. ***
/
/ *** COMMAND STRING
/ *** READR OFFSET PGM NAME
/
	.IFUND BIN
/
DELTA=LAONCE-LABUF
OFFSET=017636+DELTA
/
	.ENDC
/LABUF = LAST ARRD OF BUFFER AREA
/LAONCE = LAST ADDR OF ONCE ONLY CODE
/017636 = 1'ST FREE ADDR BELOW BOOTSTRAP
/
/
	.IFDEF ADSS
KMV5A=0
	.ENDC
	.IFUND KMV5A
	.IFUND PTP
DOS15=0
	.ENDC
	.ENDC
	.IFUND .DAT
.DAT=141
	.ENDC
	.IFUND PTP
BULKST=1
	.ENDC
	.IFUND EDITVP
	.IFUND EDITVT
EDITOR=0
	.ENDC
	.ENDC
	.IFUND NONEAE
EAE=0
	.ENDC
	.IFUND PTP
	.IFDEF EDITVP
	.IODEV	-10,-14,-15,10	/DAT SLOT 10: VP09 DISPLAY
	.ENDC
	.IFUND EDITVP
	.IODEV -10,-14,-15
	.ENDC
TTICAL=2776		/DAT SLOT -2: KEYBOARD INPUT
TTOCAL=2775		/DAT SLOT -3: TELEPRINTER OUTPUT
INPCAL=2764		/DAT SLOT -14: EDIT FILE INPUT
OUTCAL=2763		/DAT SLOT -15: EDIT FILE OUTPUT
IN2CAL=2770		/DAT SLOT -10: AUXILIARY INPUT
OPOCAL=1763		/DAT SLOT -15: OPEN OUTPUT FILE
OPICAL=0764		/DAT SLOT -14: OPEN INPUT FILE
DATM14=.DAT-14			/ABSOLUTE DAT -14.
DATM15=.DAT-15			/ABSOLUTE DAT -15.
	.ENDC
	.IFDEF PTP
	.IODEV 3,5,6,10
TTICAL=2776		/DAT SLOT -2: KEYBOARD INPUT.
TTOCAL=2775		/DAT SLOT -3: TELEPRINTER OUTPUT.
INPCAL=2003		/DAT SLOT 3: EDIT FILE INPUT.
OUTCAL=2005		/DAT SLOT 5: EDIT FILE OUTPUT.
IN2CAL=2006		/DAT SLOT 6: AUXILIARY INPUT.
OPOCAL=1005		/DAT SLOT 5: OPEN OUTPUT FILE.
OPICAL=3			/DAT SLOT 3: OPEN INPUT FILE.
DATM14=.DAT+3		/ABSOLUTE DAT 3.
DATM15=.DAT+5		/ABSOLUTE DAT 5.
	.ENDC
.SCOM=100			/SYSTEM COMMUNICATION AREA.
	.ENDC
BUFLEN=46			/READ-WRITE LINE BUFFER SIZE.
	.IFDEF	RSX
X10=10	/AUTO XR 10
BULKST=0
EAE=0
DOS15=0
BIN=0		/SO WE WILL GET BUFFERS INCLUDED IN PGM SIZE
EDITVP=0
ECLA=641000
	.IFUND	DAT15
DAT15=22
	.ENDC
	.IFUND	DAT14
DAT14=21
	.ENDC
	.IFUND	DAT10
DAT10=24
	.ENDC
	.IFUND	DATP10
DATP10=20
	.ENDC
	.IFUND	DAT3
DAT3=25
	.ENDC
	.IFUND	DAT2
DAT2=25
	.ENDC
	.IFUND COPY
COPY=1
	.ENDC
	.ENDC
	.IFDEF RSX
	.IFDEF EDITVT
	.END	ILLEGAL PARAMETER COMBINATION
	.ENDC
	.IFDEF EDITOR
	.END	ILLEGAL PARAMETER COMBINATION
	.ENDC
	.IFDEF KMV5A
	.END	ILLEGAL PARAMETER COMBINATION
	.ENDC
	.IFDEF NONEAE
	.END	ILLEGAL PARAMETER COMBINATION
	.ENDC
	.ENDC
	.IFDEF EDITVP
	.IFDEF EDITOR
	.END	ILLEGAL PARAMETER COMBINATION
	.ENDC
	.IFDEF EDITVT
	.END	ILLEGAL PARAMETER COMBINATION
	.ENDC
	.ENDC
	.IFDEF EDITOR
	.IFDEF EDITVT
	.END	ILLEGAL PARAMETER COMBINATION
	.ENDC
	.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.
	.IFUND	RSX
	TTOCAL		/INITIALIZE TELETYPE.
ONE	1		/..
ADR001	RECOUP		/RETURN FROM CONTROL P.
LOOPCT	0		/TEMPORARY STORAGE.
POINTR=LOOPCT		/..
	.ENDC
	.IFDEF	RSX
	LAC	(DAT15)
	JMS	ATTACH
	LAC	(DAT14)
	JMS	ATTACH
	.ENDC
	LAC NOPLIT	/CLEAR EXIT SWITCHS
	DAC EXITSW
	DAC EXITRQ
	DZM MOVESW
	DZM INPSW
	DZM BUFEMP
	DZM OUTPSW	/SET OUTPUT AND
/	DZM VERISW	/VERIFY TO "ON". LEAVE ALONE FOR TV
ALTMOD	175\777777	/1'S COMPLEMENT ALT MODE TERMINATOR.
	DAC PBLKSW	/TURN OFF BLOCK MODE.
	DAC GBLKSW	/..
	DAC BRFSW		/SET BRIEF TO OFF.
	DAC OPEN		/ALLOW USE OF OPEN AND
	DAC CALL		/CALL SEQUENCES.
	DAC SAVESW	/TURN OFF SAVE OPTION.
	DAC OUTSW1	/INDICATE NOTHING IN OUTPUT FILE.
	LAW -67		/55(10).
	DAC BUFSIZ	/DEFAULT BLOCK-BUFFER SIZE.
	DAC NAMSW		/INDICATE NO NAME PRESENT.
	LAC JMSCLS	/PERMIT CLOSE SEQUENCE TO USE
	DAC CLOSE1	/SUBROUTINE CLSOUT.
	.IFUND	RSX
	LAW OUTCAL	/DAT SLOT -15.
	AND ADRMSK	/THROW AWAY JUNK.
	.ENDC
	.IFDEF	RSX
	LAC	(DAT15)	/SET UP OUTPUT LUN SLOT
	.ENDC
	DAC OUTPCL	/INITIAL OUTPUT DAT SLOT IS -15.
	.IFDEF	RSX
	LAC	(DAT14)	/SET UP INPUT LUN SLOT
	.ENDC
	DAC INPTCL	/SET UP INPUT DAT SLOT.
	.IFUND	RSX
	ISZ INPTCL	/INITIAL INPUT DAT SLOT IS -14.
	.ENDC
	DZM DIRSW		/INITIAL TRANSFER DIRECTION (READ -14, WRITE -15).
	LAC TFILE1	/SET UP DEFAULT EDIT FILE NAME (.TFIL2 EDT).
	DAC INNAME	/..
	LAC TFILE1+1	/..
	.IFDEF RSX
	AAC	NN+NN	/ONE TIME CODE TO MODIFY TEMP FILE NAMES
	DAC TFILE1+1	/TO ELIMINATE SIMULTANEOUS REFERENCES
	.ENDC		/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.
	.IFDEF EDITVT
	JMS CTXOFF
	.ENDC
	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.
	.IFDEF	RSX
	JMS	ATTTY	/ATTACH INPUT OUTPUT TTY'S
	.ENDC
	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."
	.IFDEF	RSX
	JMS	DETTY	/DETACH TTY'S
	.ENDC
	JMP FND6		/GO READ A CONTROL REQUEST (SHOULD BE DELETE OR RENAME).
	.IFDEF	RSX
QUITA	0
	.ENDC
/TURN ON INPUT MODE.
	.IFDEF EDITVT
INPUT	JMS CTXOFF
	LAW INPTM
	.ENDC
	.IFUND EDITVT
	.IFUND	RSX
INPUT	LAW INPTM		/TYPE CONTROL MODE NOW IN EFFECT.
	.ENDC
	.ENDC
	.IFDEF	RSX
INPUT	JMS	ATTTY	/ATTACH INPUT OUTPUT TTY'S
	LAW	INPTM	/TYPE CONTROL MODE NOW IN EFFECT
	.ENDC
	JMS TYPOUT	/"INPUT"
	.IFDEF EDITVT
	JMS TYPRTN
	JMS CTLXON	/BUMP SCREEN UP ONE
	JMS TYPRTN
	JMS TVXUT		/THE DELETE IT <CR-LF> FORM SCREEN
	JMS CTLXON
	.ENDC
/MAIN PROCESSING LOOP FOR INPUT MODE.
RDNPUT	LAW TYLINE	/PUT LINE TO BE TYPED IN TYLINE.
	.IFUND	RSX
	DAC QUIT		/INDICATE PROCESSING IS IN PROGRESS.
	.ENDC
	JMS TYPEIN	/THEN GO READ THE KEYBOARD.
	.IFUND	RSX
	CLA		/WAS CONTROL P STRUCK DURING TYPEIN?
	SAD QUIT		/SKIP IF NOT.
	.ENDC
	.IFDEF	RSX
	LAC	QUIT	/ROLE OF QUIT REVERSED 1= QUIT
	SZA		/IS IT QUIT?
	.ENDC
	JMP TTRS		/IF SO, GO RETURN CARRIAGE, CHANGE MODES.
	.IFDEF EDITVT
	ISZ VTFLAG	/SET FLAG FOR INPUT MODE (APPEND)
	.ENDC
	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.
	.IFUND	RSX
	DAC QUIT		/ADDRESS OF TERMINATOR.
	LAC* QUIT		/GET TERMINATOR TYPED.
	.ENDC
	.IFDEF	RSX
	DAC	QUITA	/ADDRESS OF TERMINATOR
	LAC*	QUITA
	.ENDC
	SAD ALTMOD	/ALT MODE?
	JMS TYPRTN	/YES, GO RETURN CARRIAGE.
	JMS PUTLIN	/PUT AWAY THE PREVIOUS CURRENT LINE.
	JMP FULBUF	/FULL BUFFER RETURN.
	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=.
	.IFDEF EDITVT
	JMS TVXUT		/DELETE <CR-LF> FROM SCREEN
	DZM VTFLAG	/INDICATE EDIT MODE IN EFFECT
	JMS CTXOFF	/ ^X OFF DURRING EDIT MODE
	.ENDC
	.IFUND	RSX
EDIT	LAW EDTM		/TYPE CONTROL-MODE INDICATION.
	.ENDC
	.IFDEF	RSX
EDIT	JMS	DETTY	/DETACH TTY ON ENTRY TO EDIT MODE
	LAW	EDTM	/TYPE CONTROL-MODE INDICATION.
	.ENDC
	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
	.IFDEF EDITVT
	JMS CTXOFF
	.ENDC
	LAW TYLINE	/READ NEXT REQUEST FROM TELETYPE.
	JMS TYPEIN	/INPUT-LINE AREA.
	.IFDEF	RSX
	JMS	DETTY	/DETACH TTY AFTER READING A LINE
	.ENDC
	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...
	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.
	.IFDEF	RSX
	JMS	ATTTY	/ATTACH TTY WHILE PRINTING SINGLE CHARACTERS
	.ENDC
	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	/..
	.IFDEF	RSX
	JMS	DETTY	/DETACH FROM TTY
	.ENDC
	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).
	.IFUND	RSX
QUIT=CWDXCT		/QUIT .NE. 0, COMMAND PROCESSING IS IN PROGRESS.
	.ENDC
	JMP FND4		/IN CASE TABLE ENTRY WAS A JMS.
	.IFDEF	RSX
QUIT	0	/QUIT = 0 COMMAND PROCESSING IS IN PROGRESS
	.ENDC
	.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 'SIZE'<15>
	.ASCII 'OVERLAY'<15>
	.ASCII 'CHANGE'<15>
NAMSW1=.-1
	.ASCII 'CONVERT'<15>
	.ASCII 'VERIFY'<15>
STR1=.-1
	.ASCII 'TOP'<15>
	.IFUND EDITOR
	.ASCII 'TV'<15>
	.ENDC
	.ASCII 'BOTTOM'<15>
STR2=.-1		/POINTER FOR CHANGE REQUEST.
	.ASCII 'BRIEF'<15>
PBLKSW=.-1		/OUTPUT BLOCK BUFFER: 0, WRITE BUFFER. -1, WRITE FILE.
	.ASCII 'RETYPE'<15>
GBLKSW=.-1
	.ASCII 'APPEND'<15>
CURPUT=.-1
	.ASCII 'KEEP'<15>
	.ASCII 'RENEW'<15>
	.LOC .-1
C77	77
	.ASCII 'READ'<15>
	.ASCII 'WRITE'<15>
CURGET=.-1
	.ASCII 'MODIFY'<15>
	.ASCII 'MOVE'<15>
	.ASCII 'CALL'<15>
	.ASCII 'FORM'<15>
	.ASCII 'BLOCK'<15>
DIRSW=.-1
	.ASCII 'OUTPUT'<15>
ERRSW=.-1
	.ASCII 'EXIT'<15>
	.ASCII 'OPEN'<15>
	.ASCII 'CLOSE'<15>
BTEMP=.-1		/GETNUM: TEMPORARY STORAGE.
	.ASCII 'ICLOSE'<15>
BUFEND=.-1
	.ASCII 'SCLOSE'<15>
FBUFSW=.-1
	.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 SIZE		/YES -- "S"
	JMP OVRLAY	/YES -- "O"
	JMP CHANGE	/YES -- "C"
	JMP CONVRT	/NO!
	JMP VERIFY	/YES -- "V"
	JMP TOP		/YES -- "T"
	.IFUND EDITOR
	JMP TV		/NO!
	.ENDC
	JMP BOTTOM	/YES -- "B"
	JMP BRIEF		/NO!
	JMP RETYPE	/YES -- "R"
	.IFUND EDITVT
	JMS APPEND	/YES -- "A"
	.ENDC
	.IFDEF EDITVT
	JMS APPD1
	.ENDC
	JMP KEEP		/YES -- "K"
	JMP RENEW		/NO!
	JMS READ		/NO!
	JMS WRITE		/COULD BE, BUT THIS FACT IS NOT ADVERTISED.
	JMP MODIFY	/YES
	JMP MOVE		/NO!
	JMP CALL		/NO!
	JMP FORM		/NO!
	JMP BLOCK		/NO!
	JMP OUTPUT	/NO!
	JMP EXIT		/COULD BE, BUT NOT ADVERTISED.
	JMP OPEN		/NO!
	JMP CLOSE		/NO!
	JMP ICLOSE	/NO!
	JMP SCLOSE	/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.
	JMP FULBUF	/NO MORE ROOM.
	LAC	ONE
	DAC	NOPKSW	/SET NO REPACK SW
	JMS GETLIN	/GET NEXT LINE.
	INLINE
	JMP EOF		/RETURN IF EOF ENCOUNTERED.
	.IFDEF EDITVT
	LAC TVSW	/IF TV IS ON
	SNA
	JMS TYPRTN	/GIVE A <CR-LF> TO TTY
	.ENDC
	.IFUND EDITOR
	JMS	TVCL	/DISPLAY NEW CURRENT LINE.
	.ENDC
	JMP PRLIN		/GO PRINT NEW CURRENT LINE.
/DELETE N OR 1 LINES.
DELETE=.
	.IFUND EDITOR
	JMS	TVXUT	/CROSS OUT CURRENT LINE ON DISPLAY
	.ENDC
	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.
	JMP FULBUF	/..
	LAC	ONE	/SET NO REPACK SW
	DAC	NOPKSW
	LAC INFILE	/IF NO INPUT FILE DON'T
	SNA
	JMP NEXT0
	LAC BLOKSW
	SZA		/GET A LINE
	JMP FND4		/NO NEED TO DO ANYTHING MORE
NEXT0	JMS GETLIN	/GET NEXT LINE.
	INLINE		/..
	JMP EOF		/..
	.IFUND EDITOR
NEXT1	LAC	DELSW	/IF CURRENT OPERATION IS DELETE
	SZA		/DO NOT
	JMS	TVCL	/DISPLAY CURRENT LINE.
	.ENDC
	ISZ LOOPCT	/COUNT LINES CONSIDERED.
	JMP NXTLIN	/MORE LINES TO SKIP.
	.IFUND EDITOR
	LAC	DELSW	/IF CURRENT OPERATION IS 'NEXT'
	SNA		/THE CURRENT LINE HAS ALREADY
	JMS	TVCL	/BEEN DISPLAYED.
	.ENDC
	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.
	JMP FULBUF	/..
	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.
	.IFUND EDITOR
	JMS	TVCL	/DISPLAY CURRENT LINE.
	.ENDC
	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=.
	.IFUND EDITOR
	LAC ERRSW		/HAS A READ ERROR OCCURED
	SZA
	JMS TVCL		/YES -- DISPLAY OFFENDING LINE
	.ENDC
	DZM ERRSW		/CLEAR READ ERROR SWITCH
	LAC QUIT
	.IFUND	RSX
	SNA
	.ENDC
	.IFDEF	RSX
	SZA		/SWITCH IS REVERSED FOR RSX
	.ENDC
	JMP TTRS
	.IFUND	RSX
FND6=.
	.IFDEF EDITVT
	JMS CTXOFF
	.ENDC
	LAW 76
	.ENDC
	.IFDEF	RSX
FND6	JMS	ATTTY	/ATTACH TTY'S
	LAW	76	/PRINT >
	.ENDC
	JMS TYONCH
	JMP RDLIN
/COME HERE ON BUFFER OVERFLOW
FULBUF	LAW BOVFLM
	DZM	NOPKSW	/CLEAR LINE BUFFER SWITCHING SWITCH
	JMS TYPOUT
	JMS PACK
ADR011	INLINE
	TYLINE
	LAW TYLINE
	JMS TYPOUT
	JMP FND4
/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.
	JMP FULBUF	/FULL-BUFFER RETURN.
	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.
	.IFUND EDITOR
	JMS	TVCL	/DISPLAY CURRENT LINE.
	.ENDC
	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 BLOCK-MODE INDICATOR.
BLOCK	JMS DCODSW	/"ON" OR "OFF"?
BLOKSW	-1		/BLOCK MODE ON-OFF SWITCH.
	SNA
	JMP SETPBL-1
	LAC BUFEMP
	SZA!CLA!CMA
	JMP BLOK01
	DAC GBLKSW
SETPBL	DAC PBLKSW
	JMP FND4
BLOK01	LAW BFNEMM
	JMS TYPOUT
	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
/SET DISPLAY-WANTED INDICATOR.
	.IFUND EDITOR
TV	JMS DCODSW	/GET ARGUMENT.
TVSW	-1		/TV IS OFF INITALLY.
	SAD	TVON	/ANY CHANGE IN STATUS?
	JMP	TV2	/NO.
	DAC	TVON	/YES,SAVE NEW STATUS.
	.IFDEF EDITVT
	JMS TVCLR		/CLEAR SCREEN
	.ENDC
	JMS	TVST	/START OR STOP DISPLAY.
	LAC	LENGTH	/IF THERE IS ONE,
	SZA
	JMS	TVCL	/DISPLAY THE CURRENT LINE.
	.IFDEF	RSX
	LAC	TVSW	/PICK UP THE TV SWITCH
	RAR		/SAVE IT'S STATE IN THE LINK
	LAC	(DATP10)	/SET UP TO ATTACH OR DETACH DATP10
	SZL		/TV ON?
	JMP	DETP10	/NO -- DETACH THE TV DEVICE
	JMS	ATTACH	/YES -- ATTACH TV
	SKP		/SKIP OVER DETACH
DETP10	JMS	DETACH	/DETACH THE LISTING DEVICE
	.ENDC
TV2	LAC	TVSW	/IF TV WAS TURNED ON,
	SZA!CLC
	JMP	FND4
	DAC	VERISW
	JMP FND4
	.ENDC
	.TITLE CMD PROC--INSERT,RETYPE & APPEND
/
/INSERT A LINE AFTER CURRENT LINE.
/
INSERT	JMS PUTLIN	/WRITE CURRENT LINE.
	JMP FULBUF	/RETURN HERE IF NO MORE ROOM.
	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,
	.IFUND EDITOR
	JMS	TVXUT	/CROSS OUT CURRENT LINE ON DISPLAY.
	.ENDC
	JMS APPEND	/...THEN PERFORM A NORMAL APPEND.
	DAC INPSW
	JMP FND4		/GO GET NEXT COMMAND.
/ADD SOME DATA TO THE CURRENT LINE.
	.IFDEF EDITVT
APPD1	0
	LAC APPD1		/FAKE CALL TO APPEND
	DAC APPEND
	JMS TVXUT		/DELETE LAST LINE ON DISPLAY
	JMP APPND1	/JUMP INTO APPEND
	.ENDC
APPEND	0		/APPEND IS REACHED VIA JMS.
	.IFDEF EDITVP
	LAC	LENGTH	/IF CURRENT OPERATION IS 'APPEND'
	SZA		/(L>0) PREPARE TO ADD TO CURRENT LINE
	JMS	TVMLF	/BY MOVING DISPLAY LINE POINTER UP ONE.
	.ENDC
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
	.IFDEF EDITVT
	LAC VTFLAG	/IF IN INPUT MODE
	SNA		/DON'T DISPLAY THE LINE AGAIN
	.ENDC
	.IFUND EDITOR
	JMS	TVCL	/DISPLAY CURRENT LINE.
	LAC	QUOTE	/RESTORE TERMINATOR
	.ENDC
	JMP*	APPEND	/RETURN
/
APPTRN	JMS NXTCHR	/IS NEXT CHAR A TERMINATOR
	JMP NOPLIT	/YES --OK
	LAW TRNMES	/GIVE USER MESSAGE
	JMS TYPOUT
	.IFDEF EDITVT
	LAW 12
	JMS TYONCH
	.ENDC
	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
	.IFUND EDITOR
	SAD FENCE		/IF ONLY ONE LINE
	JMS TVXUT		/DELETE LAST LINE ON SCREEN
	.ENDC
	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
	.IFUND	RSX
	LAW TYLINE-1	/SET UP POINTER TO TYLINE FOR A.I.REG
	JMS GETBNK
	.ENDC
	.IFDEF	RSX
	LAC	(TYLINE-1)	/SET UP POINTER TO TYLINE FOR A.I. REG
	.ENDC
	DAC TYLNPT
	.IFUND	RSX
	DAC QUIT		/INDICATE COMMAND PROC. IN PROGRESS
	.ENDC
	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
	.IFUND	RSX
	LAW INLINE-1
	JMS GETBNK
	.ENDC
	.IFDEF	RSX
	LAC	(INLINE-1)
	.ENDC
	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=.
	.IFUND EDITOR
	LAC NUM		/HAS LINE BEEN ALTERED
	SZA
	JMS TVCL		/YES--DISPLAY LINE
	DZM NUM		/RESET FLAG
	.ENDC
	JMS PUTLIN	/PUT LINE AWAY
	JMP FULBUF	/BUFFER OVERFLOW RETURN
	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
	.IFUND EDITOR
	LAC TVSW		/CHECK TO SEE IF TV IS ON
	SZA
	JMP FND3		/TV IS OFF GO CONFIRM ON TTY
	JMS	TVXUT	/CROSS OUT CURRENT LINE ON DISPLAY
CONEX3	JMS	TVCL	/DISPLAY NEW CURRENT LINE
	JMP	FND6	/EXIT
	.ENDC
	.IFDEF EDITOR
	JMP	FND3
	.ENDC
/
/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
	.IFUND EDITOR
	LAC TVSW		/IF TV IS OFF
	SZA
	JMP FND3		/GO CONFIRM ON TTY
	JMP CONEX3	/EXIT
	.ENDC
	.IFDEF EDITOR
	JMP	FND3
	.ENDC
/
/
/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"
	.IFUND	RSX
	LAW TYLINE	/SET UP FOR PACK
	JMS GETBNK
	.ENDC
	.IFDEF	RSX
	LAC	(TYLINE)	/SET UP FOR PACK
	.ENDC
	DAC FROMA
	.IFUND	RSX
	LAW INLINE
	JMS GETBNK
	.ENDC
	.IFDEF	RSX
	LAC	(INLINE)
	.ENDC
	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
	.IFDEF EDITVT
	JMS TYPRTN
	.ENDC
	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
	.TITLE CMD PROC MOVE
/
/
/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
/
/
/PROCESSING FOR THE MOVE COMMAND
/MOVE N LINES TO BEFORE THE LINE
/BEGINING WITH STRING.
/
MOVE	JMS	GETNUM		/GET NUMBER OF LINES TO MOVE
	DAC	NUM		/STORE IT
	.IFUND	RSX
	DAC	QUIT		/INDICATE COMMAND PROC. IN PROGRESS
	.ENDC
	DAC	MOVESW
	DZM	LOOPCT		/ZERO COUNTER
	JMS	TOPBOM		/CHECK FOR TOP OR END OF FILE
	JMS	LINESW		/SAVE CURRENT LINE
	INLINE-1
	TYLINE-1
	.IFUND EDITOR
	JMS	TVXUT		/CROSS OUT CURRENT LINE
	.ENDC
	ISZ	NUM		/COUNT THIS LINE
	SKP			/SKIP IF THERE ARE MORE LINES TO MOVE
	JMP	MVSCN1		/NO MORE LINES GO SEARCH FOR STRING
	LAC	BLOKSW		/ARE WE IN BLOCK MODE
	SNA
	JMP	MVBLPC		/YES - GO PROCESS
	.IFUND	RSX
	LAC*	SCOM3		/NO IN LINE MODE SETUP
	.ENDC
	.IFDEF	RSX
	LAC	ENDPAR	/PICK UP THE END OF THE PARTITION
	.ENDC
	DAC	BUFEND		/POINTERS TO BUFFER AREA
	.IFUND	RSX
	LAC*	SCOM2
	.ENDC
	.IFDEF	RSX
	LAC	EDTSIZ	/PICK UP THE SIZE OF EDIT
	.ENDC
	DAC	CURPUT		/POINTERS FOR "PUTLIN"
	DAC	NXTPUT
	DZM	PBLKSW		/TURN ON BLOCK MODE FOR "PUTLIN"
MVMORE	JMS	GETLIN		/GO GET A LINE
	INLINE			/PUT IT HERE
	JMP	NELERR		/NO MORE LINES TO GET
	JMS	PUTLIN		/NORMAL RETURN - PUT LINE IN BUFFER
	JMP	NEBERR		/BUFFER IS FULL
	ISZ	LOOPCT		/LINE PUT AWAY OK - COUNT IT
	ISZ	NUM
	JMP	MVMORE		/MORE LINES TO MOVE
	LAW	-1		/TURN BLOCK MODE
	DAC	PBLKSW		/OFF FOR PUTLIN
MVSCN1	LAC	NXTPTR		/GET POINTER TO STRING
	DAC	MVSTRG		/TO SEARCH FOR AND GIVE TO SCAN
	.IFUND	RSX
MVSCN2	LAW	INLINE		/SEARCH INLINE
	JMS	GETBNK		/PUT ON BANK BITS
	.ENDC
	.IFDEF	RSX
MVSCN2	LAC	(INLINE) 	/SEARCH INLINE
	.ENDC
	DAC	MVSEAC
	JMS	GETLIN		/GO GET A NEW LINE
	INLINE
	JMP	MVEOFE		/END OF FILE OR BLOCK REACHED
	LAC	ERRSW		/WAS THERE A READ ERROR IN GETLIN
	SZA
	JMS	 MVRDER		/YES -- TELL USER
MVSCAN	JMS	SCAN		/SCAN CURRENT LINE FOR
MVSTRG	0			/THIS STRING
MVSEAC	0			/IN THIS LINE
	JMP	MVNMCH		/NO MATCH
	JMP	MVMACH		/MATCH FOUND
/
/CONTROL COMES HERE IF THE END OF
/THE CURRENT LINE BEING SEARCHED IS FOUND
/OR THERE HAS BEEN NO MATCH
/
MVNMCH	JMS	PUTLIN		/GO PUT LINE AWAY
CRGTSV	0			/BUFFER OVERFLOW CAN NOT HAPPEN
	LAC	ONE	/SE NO REPACK SW
	DAC	NOPKSW
	.IFUND EDITOR
	JMS	TVCL		/DISPLAY LINE
	.ENDC
	JMP	MVSCN2		/GO BACK FOR NEXT LINE
/
/
/CONTROL COMES HERE IF A
/MATCH IS FOUND
/
MVMACH	JMS	LINESW		/GO SAVE THIS
	INLINE-1		/LINE FOR LATER
	EDLIN-1
MVLINE	JMS	LINESW		/GET FIRST LINE
	TYLINE-1		/TO BE MOVED
	INLINE-1
	DZM	NOPKSW	/RESET NO REPACK SW
	JMS	PUTLIN		/GO PUT IT IN OUTPUT
MVEXSW	-1			/OVERFLOW CAN NOT HAPPEN
	.IFUND EDITOR
	JMS	TVCL		/DISPLAY LINE
	.ENDC
	LAC	LOOPCT		/RETURN - SETUP
	.IFUND	RSX
	CMA			/LINE COUNT FOR
	TAD	ONE		/MOVING LINES
	.ENDC
	.IFDEF	RSX
	TCA		/LINE COUNT FOR MOVING LINES
	.ENDC
	SNA			/ARE WE DONE
	JMP	MVEXIT		/YES EXIT
	DAC	LOOPCT		/NO-STORE NEG LOOPCT
	LAC	BLOKSW		/ARE WE IN
	SNA			/BLOCK MODE
	JMP	MVLNBL		/YES
	DZM	GBLKSW		/NO - TURN ON BLOCK MODE
	.IFUND	RSX
	LAC*	SCOM2		/AND SET POINTER FOR "GETLIN"
	.ENDC
	.IFDEF	RSX
	LAC	EDTSIZ	/PICKUP THE SIZE OF THE EDITOR
	.ENDC
	DAC	CURGET
	LAW	-1		/INDICATE BUFFER
	DAC	BUFEMP		/NOT EMPTY
CONTMV	JMS	GETLIN		/GET A LINE FROM BUFFER
	INLINE			/PUT IT HERE
MVESW1	-1			/NO MORE LINES TO GET CANNOT OCCUR
	JMS	PUTLIN		/PUT LINE AWAY
MVESW2	-1			/BUFFER OVERFLOW CAN NOT HAPPEN
	.IFUND EDITOR
	JMS	TVCL		/DISPLAY LINE
	.ENDC
	ISZ	LOOPCT		/COUNT IT
	JMP	CONTMV		/MORE TO MOVE
	LAW	-1
	DAC	GBLKSW		/TURN OFF SWITCH
	DZM	BUFEMP		/INDICATE BUFFER EMPTY
	JMP	MVEXIT		/DONE EXIT
/
/ERROR SWITCHES ARE SET HERE
/
NELERR	LAW	-1		/RESET BLOCK MODE
	DAC	PBLKSW		/FOR PUTLIN
	SKP
MVEOFE	DZM	MVESW2		/END OF FILE FOUND
	DZM	MVEXSW		/NO MORE LINES TO GET
	JMP	MVLINE		/GO TRANSFER MOVED LINES
/
/
NEBERR	DZM	MVESW1		/NOT ENOUGH BUFFER
	LAW	-1		/RESET BLOCK SWITCH
	DAC	PBLKSW		/FOR PUTLIN
	JMP	MVMACH		/SAVE CURRENT LINE & MOVE LINES
/
/
/PROCESSING WHEN IN BLOCK MODE
/
MVBLPC	LAC	CURGET		/SAVE POINTER TO NEXT
	DAC	CRGTSV		/LINE TO GET FOR "GETLIN"
	LAW	-2		/CHECK NUMBER OF LINES TO
	TAD	NUM		/MOVE AGAINST SIZE OF BUFFER
	CMA
	TAD	BUFSIZ
	SMA
	JMP	BTSERR		/BUFFER IS TOO SMALL
BUFFOK	JMS	GETLIN		/GET A LINE
	INLINE			/PUT IT HERE
	JMP	NLBKER		/NO MORE LINES TO GET
	ISZ	LOOPCT		/NORMAL RETURN - COUNT LINES
	ISZ	NUM		/ARE WE DONE
	JMP	BUFFOK		/GO BYPASS ANOTHER LINE
	JMP	MVSCN1		/YES - GO SEARCH LINES FOR STRING
/
/STRING FOUND AND IN BLOCK MODE
/AFTER CURRENT LINE IS SAVED
/AND FIRST LINE TO BE MOVED HAS
/BEEN PLACED IN OUTPUT BUFFER
/CONTROL COMES HERE
/
MVLNBL	LAC	CURGET		/GET POINTER TO NEXT LINE
	DAC	NUM		/AND SAVE IT
	LAC	CRGTSV		/GET POINTER TO LINE TO BE MOVED
	DAC	CURGET		/AND GIVE TO CURGET
MVBLM	JMS	GETLIN		/GO GET A LINE
	INLINE
	NOP			/NO MORE LINES CAN NOT HAPPEN
	JMS	PUTLIN		/RETURN - PUT LINE IN
	NOP			/OUTPUT BUFFER - OVERFLOW CAN NOT HAPPEN
	.IFUND EDITOR
	JMS	TVCL		/DISPLAY LINE
	.ENDC
	ISZ	LOOPCT		/IS THERE MORE TO DO
	JMP	MVBLM		/YES
	LAC	NUM		/DONE RESTORE POINTER FOR
	DAC	CURGET		/GETLIN
/
/COMMON EXIT ROUTINE FOR MOVE
/
MVEXIT	LAC	MVEXSW		/TEST ERROR SWITCH
	DZM	MOVESW
	SNA
	JMP	ERROR1		/THERES AN ERROR
	JMS	LINESW		/GO RESTORE CURRENT LINE
	EDLIN-1			/TO INLINE
	INLINE-1
	LAC	MVESW1		/TEST ERROR SWITCH
	SNA
	JMP	ERROR2		/THERE'S AN ERROR
EXERR2	LAW	-1		/RESET SWITCH
	DAC	MVESW1
	.IFUND EDITOR
	JMS	TVCL		/DISPLAY LINE
	.ENDC
	JMP	FND6		/EXIT FOR NEXT COMMAND
/
ERROR2	LAW	NENGMS		/TELL USER THAT
	JMS	TYPOUT		/NOT ENOUGH BUFFER SPACE
	LAW	BUFSPM
	JMS	TYPOUT
	JMP	EXERR2		/EXIT
/
ERROR1	LAC	MVESW2		/CHECK ERROR SWITCH
	SNA
	JMP	ERROR3		/THERE'S AN ERROR
	LAW	NENGMS		/GIVE USER MESSAGE
	JMS	TYPOUT		/NOT ENOUGH LINES,
	LAW	LINEMS
	JMS	TYPOUT
EXERR1	LAW	-1		/RESET SWITCHES
	DAC MVEXSW
	DAC MVESW2
	JMP	EOF		/EXIT EOF MESS. & NEXT COMMAND
/
ERROR3	LAW	LMEOFM		/GIVE USER MESSAGE - LINES
	JMS	TYPOUT		/MOVED TO END
	JMP	EXERR1		/EXIT
/
/NOT ENOUGH LINES TO MOVE IN BLOCK MODE
NLBKER	LAC	CRGTSV		/RESTORE POINTER FOR
	DAC	CURGET		/GETLINE
	LAW	NENGMS		/TELL USER OF PROBLEM
	JMS	TYPOUT
	LAW	LINEMS
	JMS	TYPOUT
	JMS	LINESW		/SWAP BACK ORG. CURRENT LINE
	TYLINE-1
	INLINE-1
	JMP	MVBEEX		/EXIT FOR NEXT COMMAND
/
/BUFFER SIZE TO SMALL IN BLOCK MODE
/
BTSERR	LAW	BUFTSM		/TELL USER OF PROBLEM
	JMS	TYPOUT
MVBEEX	DZM	MOVESW
	JMP	FND6		/EXIT FOR NEXT COMMAND
/
MOVESW	0
/
/SUBROUTINE  MVRDER
/A READ ERROR HAS OCCURED IN GETLIN
/DETERMINE THE ERROR TYPE AND GIVE USER
/MESSAGE WITH OFFENDING LINE
/THEN CONTINUE THE MOVE
/
MVRDER	0
	SAD C60		/IS IT A TRUNCATED LINE
	JMP MVTRN		/YES
	LAW PRTYMS	/NO -- READ ERROR
	SKP
MVTRN	LAW TRNMES
	JMS TYPOUT	/GIVE MESSAGE
	JMS PACK	/PRINT OFFENDING LINE
ADR018	INLINE
	SBUFF
	LAW SBUFF
	JMS TYPOUT
	.IFDEF EDITVT
	JMS TYPRTN
	.ENDC
	DZM ERRSW		/CLEAR OUT ERROR SW
	DZM	NOPKSW	/RESET NO REPACK SW
	JMP* MVRDER	/GO CONTINUE MOVE
/
	.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
	.IFUND	RSX
	LAW INLINE
	JMS GETBNK
	.ENDC
	.IFDEF	RSX
	LAC	(INLINE)
	.ENDC
	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
	LAC MDSTG1	/SET UP FROM ADDR
	TAD FENCE	/FOR "LINESW"
	DAC MDFROM
	JMS LINESW	/SWAP 2'ND PART OF
MDFROM	0		/INLINE TO TYLINE
	TYLINE-1
	.IFUND	RSX
	LAW INLINE-1	/CALCULATE NEW INLINE LENGTH
	JMS GETBNK
	.ENDC
	.IFDEF	RSX
	LAC	(INLINE-1)	/CALCULATE NEW INLINE LENGTH
	.ENDC
	CMA
	TAD MDSTG1
	DAC LENGTH	/STORE IT
	.IFUND	RSX
	LAW EDLIN	/SET UP NXTPTR FOR
	JMS GETBNK	/"APPEND"
	.ENDC
	.IFDEF	RSX
	LAC	(EDLIN)	/SET UP NXTPTR FOR "APPEND"
	.ENDC
	DAC NXTPTR
	.IFUND EDITOR
	LAC TVSW	/IS TV ON
	SNA
	JMP TVFMD1	/YES HANDLE
	.ENDC
MDAPP1	JMS APPEND	/APPEND NEW DATA TO INLINE
	CMA		/IS TERMINATOR A <CR>
	SAD C15
	.IFUND EDITOR
	JMP TVFMD3	/YES EXIT FOR TV
	.ENDC
	.IFDEF EDITOR
	JMP FND6
	.ENDC
	LAC POINTR	/DECREMENT POINTER FOR STORING
	TAD FENCE	/DATA IN "APPEND"
	DAC POINTR
	.IFUND	RSX
	LAW TYLINE	/SET UP POINTER FOR GETTING DATA
	JMS GETBNK
	.ENDC
	.IFDEF	RSX
	LAC	(TYLINE)	/SET UP POINTER FOR GETTING DATA
	.ENDC
	DAC NXTPTR	/IN "APPEND"
	JMS APPEND	/REST OF ORG. INLINE
	.IFUND EDITOR
	LAC NUM		/WAS TV ON
	SNA
	JMP TVFMD2	/YES -- EXIT FOR TV
	.ENDC
	JMS PACK	/TYPE OUT REST OF
ADR015	TYLINE		/ORGINAL INLINE
	EDLIN
	LAW EDLIN
	JMS TYPOUT
	JMP FND6	/EXIT
	.IFUND EDITOR
/
/HANDLING OF THE DISPLAY WHEN IT IS ON
/FOR THE MODIFY COMMAND
/
TVFMD1	DAC NUM		/SAVE CURRENT TVSW (0)
	CMA
	DAC TVSW	/TURN OFF TV FOR APPEND
	JMP MDAPP1	/GO APPEND NEW DATA
/
TVFMD2	DAC TVSW	/TURN TV BACK ON
	JMS TVXUT	/CROSS OUT CURRENT LINE
	JMS TVCL	/DISPLAY NEW CURRENT LINE
	JMS TYPRTN	/<CR><LF> FOR TTY IN CASE OF ALTMODE
	JMP FND6	/EXIT
/
TVFMD3	LAC NUM		/WAS TV ON
	SZA
	JMP FND6	/NO EXIT
	JMP TVFMD2	/YES EXIT FOR TV ON
/
	.ENDC
	.TITLE CMD PROC--SIZE,OVERLAY,CALL,OPEN & KEEP
/
/
/SET N LINES IN BLOCK BUFFER.
SIZE	JMS GETNUM	/GET DECIMAL ARGUMENT.
	SAD FENCE		/-1?
	JMP ILLCWD	/ILLEGAL IF SO.
	.IFDEF	RSX
	PAL		/SAVE THE REQUESTED SIZE
	TCA		/COMPLEMENT IT TO CHECK IF IT WILL BE LEGAL
	TAD	MAXBUF	/COMPARE AGAINST MAXIMUM ALLOWED
	SMA		/IS IT LEGAL?
	JMP	ILLCWD	/NO REJECT IT
	PLA		/YES RESTORE COUNT
	.ENDC
	DAC BUFSIZ	/ARG .G. 1, SAVE NEW SIZE.
	JMP FND4		/GET NEXT COMMAND.
/CHANGE N LINES.
OVRLAY	JMS GETNUM	/GET TOTAL LINES TO REPLACE.
	DAC LOOPCT	/SAVE AS COUNTER.
	.IFUND EDITOR
	JMS	TVXUT	/CROSS OUT CURRENT LINE ON DISPLAY.
	.ENDC
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.
/SERVICE CALL REQUEST.
CALL	NOP
	JMS GETCOM
	LAC CWD
	SAD C104
	JMP CDEL
	SAD C122
	JMP CREN
	JMP ILLCWD
CDEL	JMS GETDAT
	JMS GETCOM
	SNA
	JMP ILLCWD
	LAW -2
	JMS PK6BT
	CWD
CALLDB	CALDB1
	LAC SRCNAM
	DAC CALDB1+2
	JMS GETCOM
	SNA!CLA!CMA
	JMP CDEL1
	JMS PK6BT
	CWD
	CALDB1+2
CDEL1	LAC CALLDB
	ADD CALDAT
	DAC CDEL2+1
CDEL2	JMS DELFIL
	0
	JMP IOSET
/CALL RENAME..
CREN	JMS GETDAT
	JMS GETCOM
	SNA
	JMP ILLCWD
	LAW -2
	JMS PK6BT
	CWD
	CALDB1
	JMS GETCOM
	SNA!CLA!CMA
	JMP ILLCWD
	JMS PK6BT
	CWD
	CALDB1+2
	JMS GETCOM
	SNA
	JMP ILLCWD
	LAW -2
	JMS PK6BT
	CWD
	CALDB2
	LAC CALDB1+2
	DAC CALDB2+2
	JMS GETCOM
	SNA!CLA!CMA
	JMP CREN2
	JMS PK6BT
	CWD
	CALDB2+2
CREN2	LAC CALLDB
	ADD CALDAT
	DAC CREN1
	JMS RENAME
CREN1	0
	CALDB2
IOSET	JMS IOINIT
	JMP FND6
/GETDAT...
GETDAT	0
	JMS GETCOM
	LAC CWD
	SAD OFF
	JMP COUT
	SAD C111
	JMP CIN
	JMP ILLCWD
CIN	CLA!SKP
COUT	LAC XCTZRO
	DAC CALDAT
	JMP* GETDAT
/PRODUCE A FORM FEED ON PAPER TAPE TO KEEP THE PDP7
/EDITOR HAPPY.
FORM	LAC OUTDEV
	SMA
	JMP FND6
	.IFUND	RSX
	OUTCAL
	11		/WRITE
FEED	FORMFD
	-4
	.ENDC
	JMP FND4
	.IFUND	RSX
FORMFD	002002
	.ENDC
BLANK	40		/CHECKSUM -- IGNORED BY PUNCH HANDLER.
	.IFUND	RSX
	.ASCII <14>
	.ENDC
	.IFUND	RSX
RECOUP	LAC QUIT
	SNA
	JMP BEGIN
	LAC MOVESW
	SZA
	JMP MOVEIP
	DZM QUIT
	LAC NOPLIT
	DAC EXITRQ
MOVEIP=.
	LAC* SCOM16	/RESTORE LINK.
	DAC QRETN		/SAVE RETURN.
	RAL		/..
	LAC* SCOM17	/RESTORE AC.
	JMP* QRETN	/REENTER INTERRUPTED SEGMENT.
	.ENDC
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
	DAC CALL		/AND CALL SEQUENCES.
	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
	.IFUND	RSX
NONAM1	LAW NOFLNM
	.ENDC
	.IFDEF	RSX
NONAM1	JMS	ATTTY	/ATTACH TTY'S
	LAW	NOFLNM	/ADDR OF NAME OF ABSENT FILE
	.ENDC
	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
	DAC CALL
	LAC SKPLIT	/SET EXITSW TO INDICATE
	DAC EXITSW	/A FILE IS OPEN
	.IFDEF	RSX
	JMS	DETTY	/DETACH TTY'S
	.ENDC
	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.
/
/
SCLOSE	LAW -1
	DAC DIRSW
/
/
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
/
/DETERMIN 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 BLOKSW
	SMA
	JMP CLOSE1	/BLOCK MODE ON
	LAC SAVESW
	SNA
	JMP CLOSE1	/A SAVE IS WANTED
	LAC INPSW	/HAS INPUT MODE BEEN ENTERED
	SZA
	JMP CLOSE1	/YES--TO 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 WRITE
CKNM4	LAC* 12	/CHECK NAMES
	SAD* 13
	SKP
	JMP CKNM0	/NOT THE SAME
	ISZ WRITE
	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
/
	.IFUND	RSX
NMERR2	LAW	BADNAM		/INFORM USER OF TROUBLE
	.ENDC
	.IFDEF	RSX
NMERR2	JMS	ATTTY	/ATTACH TTY
	LAW	BADNAM	/INFORM USER OF TROUBLE
	.ENDC
	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
	.IFDEF	RSX
	JMS	DETTY	/DETACH TTY
	.ENDC
	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 PBLKSW
	SZA
	JMP TOPFIL
	JMS RSBUFF
	JMS CHBUFF
	JMP TOPFL2
TOPFIL	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.
	JMP FULBUF
	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
	.IFUND	RSX
SBREAD	IN2CAL
	10
SBADR	SBUFF
	-BUFLEN
	IN2CAL
	12
	.ENDC
	.IFDEF	RSX
	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
	.ENDC
	LAC SBUFF
	AND C7
	SAD C5
	SKP
	SAD C6
	JMP GETEOF
	JMS PUTLIN
	.IFDEF	RSX
	JMP FULBUA
	.ENDC
	.IFUND	RSX
	JMP	FULBUF
	.ENDC
	JMS UNPACK
ADR008	SBUFF
	INLINE
	DAC LENGTH
	.IFUND EDITOR
	JMS	TVCL	/DISPLAY NEW CURRENT LINE.
	.ENDC
	LAC SBUFF
	AND C60
	SAD C60
	.IFUND	RSX
	JMP TYTRN
	.ENDC
	.IFDEF	RSX
	JMP	TYTRNA	/DETACH BEFORE EXITING
	.ENDC
	SZA
	JMP TYPAR
	DAC INPSW
	ISZ LOOPCT
	JMP SBREAD
	.IFDEF	RSX
	LAC	(DAT10)	/DETACH DEVICE BEFORE EXITING
	JMS	DETACH
	.ENDC
	JMP FND4
	.IFUND	RSX
GETEOF	LAW EOMRM
	.ENDC
	.IFDEF	RSX
TYTRNA	LAC	(DAT10)	/DETACH DEVICE
	JMS	DETACH
	JMP	TYTRN
/
FULBUA	LAC	(DAT10)	/DETACH DEVICE
	JMS	DETACH
	JMP	FULBUF
/
GETEOF	LAC	(DAT10)	/DETACH DEVICE
	JMS	DETACH
	LAW	EOMRM
	.ENDC
	JMS TYPOUT
	JMP EOFCOM
/SERVICE RENEW REQUEST.
RENEW	JMS WRITE		/FIRST WRITE OUT THE CURRENT BUFFER.
	JMS READ		/THEN FILL UP THE BUFFER FROM THE INPUT FILE.
	JMP FND4		/AND GO READ ANOTHER REQUEST.
/SERVICE WRITE REQUEST.
WRITE	0		/ENTRY TO WRITE BLOCK BUFFER INTO OUTPUT FILE.
	LAC PBLKSW	/IS BLOCK MODE ON?
	SZA		/SKIP IF IT IS.
	JMP ILLCWD	/IF BLOCK MODE IS OFF, DON'T ACCEPT WRITE REQUEST.
	JMS RSBUFF	/GO FILL UP OUTPUT BUFFER FROM INPUT BUFFER.
	JMS CHBUFF	/THEN CHANGE THE BUFFERS AROUND.
	LAC BLOKSW	/SAVE THE CURRENT STATUS OF BLOKSW.
	DAC LOOPCT	/..
FENCE	LAW -1		/THEN TURN BLOCK MODE OFF.
	DAC PBLKSW	/..
	DAC BLOKSW	/..
	JMS RSBUFF	/NOW GO EMPTY THE INPUT BUFFER, AND THIS TIME WRITE OUTPUT FILE.
	LAC LOOPCT
	DAC BLOKSW
	DZM PBLKSW
	JMS CHBUFF
	DZM BUFEMP
	JMP* WRITE	/RETURN TO CALLER.
/SERVICE READ REQUEST.
READ	0		/ENTRY TO FILL INPUT BUFFER.
	LAC BUFEMP
	SZA
	JMP NEMPBF
	LAC BUFSIZ
	DAC LOOPCT
	LAC BLOKSW
	SZA!CLA!CMA	/SKIP IF BLOCK ON,-1 TO AC
	JMP ILLCWD	/ILLEGAL COMMAND IF NOT.
	DAC PBLKSW	/OFF PUTLIN BLOCK SWITCH.
	JMS PUTLIN	/OUTPUT CURRENT LINE IF ANY.
	JMP FULBUF
	DZM PBLKSW	/RESET PUTLIN BLOCK SWITCH ON.
	JMS CHBUFF
	LAW -1
	DAC GBLKSW
READ1	JMS GETLIN
	INLINE
	JMP EOF
	JMS PUTLIN
	JMP FULBUF
	ISZ LOOPCT
	JMP READ1
	JMS CHBUFF
	JMP* READ
NEMPBF	LAW BFNEMM
	JMS TYPOUT
	JMP* READ
	.TITLE SUBROUTINES RSBUFF,CHBUFF,RDFILE &WRFILE
/
/SUBROUTINE RSBUFF; EMPTY INPUT BUFFER, FILL OUTPUT BUFFER.
RSBUFF	0
NCHARS=RSBUFF		/GETCOM: TOTAL TYPED CHARACTERS IN CURRENT COMMAND.
RSB01	JMS PUTLIN
	JMP FULBUF
	LAC GBLKSW
	SZA
	JMP* RSBUFF
	JMS GETLIN
	INLINE
	JMP* RSBUFF
	JMP RSB01
/SUBROUTINE CHBUFF, EXCHANGE INPUT AND OUTPUT BUFFERS; SET GET
/AND PUT POINTERS TO BUFFER TOPS.
CHBUFF	0
	LAC BBUF1		/GET TOP OF BUFFER 1.
	DAC NXTPUT	/GIVE TO OUTPUT POINTERS.
	DAC CURPUT	/..
	TAD FENCE
	ADD BBUFX
	DAC BUFEND
	LAC BBUF2		/GET TOP OF BUFFER 2.
	DAC CURGET	/GIVE TO INPUT POINTER.
	DAC BBUF1		/SWITCH BUFFERS.
	LAC NXTPUT	/..
	DAC BBUF2		/..
	LAC PBLKSW
	DAC GBLKSW
	LAC BFPTSW	/ANYTHING IN OLD OUTPUT BUFFER?
	SNA		/SKIP IF SO
	DZM CURGET
	DZM BFPTSW	/NOW INDICATE NOTHING IN NEW OUTPUT BUFFER.
	.IFUND EDITOR
/INITIALIZATION FOR DISPLAY BUFFERS.
TVINIT	LAW	-TVNLN	/NUMBER OF LINES TO BUFFER FOR DISPLAY.
	DAC	TVCNT
	LAC	(TVBUF1	/ADDRESS OF 1ST BUFFER IN THE RING.
	DAC	TVSPTR	/SET UP START POINTER.
	DAC	TVCPT2	/SET UP FILL-BUFFERS POINTER.
TVNT10	DAC	TVCPTR	/SET UP TO INITIALIZE BUFFERS.
	DZM*	TVCPTR	/0 1ST WORD MEANS EMPTY BUFFER.
	TAD	(BUFLEN+1	/NEXT BUFFER.
	ISZ	TVCNT	/ALL BUFFERS DONE?
	JMP	TVNT10	/NO,RECYCLE.
	LAC	(JMP TVVP20	/SET SWITCH TO ROUTINE USED TO
	DAC	TVVP10	/FILL UP BUFFERS.
	.IFDEF EDITVP
	LAC	TVSW	/GET STATUS OF TV SWITCH
	DAC	TVCL
	SZA		/IF IT WAS ON,
	JMP	TVOFF
	LAW	-1	/TURN OFF
	DAC	TVSW	/THE DISPLAY SWITCH
	LAC	ICLSW	/WAS ICLOSE REQUESTED
	SZA
	JMS	TVST	/NO--TURN OFF THE DISPLAY.
TVOFF	LAC	TVCL	/THEN RESET THE
	DAC	TVSW	/DISPLAY SWITCH.
	.ENDC
	.IFDEF EDITVT
	LAC	ICLSW	/ IF ICLOSE REQUEST IS PENDING DON'T CLEAR SCREEN
	SZA
	JMS	TVCLR	/GO CLEAR SCREEN
TVOFF=.
	.ENDC
	.ENDC
	JMP* CHBUFF	/RETURN TO CALLER.
C5	5
C777	777
C175	175
BFPTSW	0
/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.
	.IFUND	RSX
	JMS GETBNK	/INSERT BANK BITS.
	.ENDC
	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	/..
	.IFUND	RSX
INPTCL	INPCAL		/ISSUE READ.
	10
RDCAL2	RDBUF2		/MODIFIED AT EACH CALL.
	-BUFLEN
	.ENDC
	.IFDEF	RSX
	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
	.ENDC
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.
	.IFUND EDITOR
	DAC	TVWRFL	/ADD TO DISPLAY BUFFERS.
	.ENDC
	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=.
	.IFUND EDITOR
	JMS	TVVP	/ADD A LINE TO THE DISPLAY RING BUFFERS.
TVWRFL	0		/THIS LINE.
	.ENDC
	LAC OUTSW1
	SZA
	JMS OUTENT	/GO CLEAN UP OUTPUT DEVICE AND ENTER FILE
	.IFUND	RSX
OUTPCL	OUTCAL		/WRITE THE LINE JUST PACKED.
	11
WRCAL2	0		/UPDATED EACH TIME TO CORRESPOND TO WRPAK2.
C1000	1000		/WORD COUNT -- IGNORED BY DEVICE HANDLERS.
	.ENDC
	.IFDEF	RSX
	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
	.ENDC
	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
	.IFUND EDITOR
	DAC	TVWRFL	/ALSO SET THE POINTER TO THE DISPLAY OUTPUT
	.ENDC
	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
	.IFDEF DOS15
OUTFST	JMS FSTAT
	XCT TFILE1
	SNA
	JMP OUTETR
	.IFUND	RSX
	LAC DTYP1
	AND CL7000
	SAD (200000
	JMP DELEFL
	SAD (300000
	JMP DELEFL
	JMP OUTETR
	.ENDC
DELEFL	JMS DELFIL
	XCT TFILE1
	JMP OUTFST
	.ENDC
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"
SCOM17=ON			/.SCOM+17: AC ON TTY INTERRUPTS.
	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
	.IFUND	RSX
	JMS GETBNK
	.ENDC
	DAC STR1
	ISZ SCAN
	LAC* SCAN
	.IFUND	RSX
	JMS GETBNK
	.ENDC
	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 EITHER IN THE CURRENT OUT BUFFER
/OR IN THE OUTPUT FILE ITSELF.
/POINTER TO WHERE THE NEXT LINE WILL BE PACKED IS
/STORED IN THE CHECKSUM WORD OF THE CUURENT LINE
/BLOCK MODE ONLY
/
/PUTLIN ALWAYS GET LINE FROM INLINE
/
/CALL:	JMS PUTLIN
/	RETURN IF BUFFER FULL (LINE NOT INSERTED)
/	NORMAL RETURN.
PUTLIN	0
	LAC LENGTH
	DAC BTEMP
	SNA!CLA!CLL!CML
	JMP PTOFLO-2
	.IFUND	RSX
	SAD QUIT
	.ENDC
	.IFDEF	RSX
	LAC	QUIT	/CHECK FOR ABORT
	SZA
	.ENDC
	JMP TTRS
	SAD PBLKSW	/SKIP IF BLOCK MODE IS OFF.
	SKP!RAL		/BLOCK MODE ON. SET AC = 1.
	JMP WRCAL		/BLOCK MODE OFF, GO OUTPUT LINE.
	DAC NPAIRS	/SET INITIAL WORD-PAIR COUNTER.
	ISZ BTEMP		/ACCOUNT FOR A CARRIAGE RETURN.
COUNT1	ISZ NPAIRS	/COUNT A PAIR.
	LAW -5		/5 CHARS PER PAIR.
	TAD BTEMP		/ADJUST CHARACTER COUNT.
	DAC BTEMP		/SAVE NEW ONE.
	SZA!SMA		/DONE IF ZERO OR MINUS.
	JMP COUNT1	/MORE TO DO.
	LAC NPAIRS	/ALL DONE, GET TOTAL PAIRS REQUIRED BY THIS LINE.
	CLL!RAL		/NPAIRS * 2 TO GIVE TOTAL WORDS THIS LINE.
	ADD NXTPUT	/FORM CURRENT ADDRESS + WORDS THIS LINE.
	DAC BTEMP		/SAVE TEMPORARILY.
	CMA		/2'S COMPLEMENT LAST ADDR REQUIRED.
	TAD BUFEND	/COMPARE WITH LAST ADDRESS AVAILABLE.
	SPA!SNA		/LAST NEEDED .L. LAST AVAILABLE, OK.
	JMP PTOFLO	/ERROR OTHERWISE.
PKCAL	JMS PACK
ADR009	INLINE
NXTPUT	0		/WHERE TO BEGIN WRITING NEXT LINE.
	.IFUND EDITOR
	LAC	NXTPUT	/GET ADDRESS OF
	DAC	.+2
	JMS	TVVP	/A LINE TO ADD TO THE DISPLAY RING BUFFERS.
	0
	.ENDC
	LAC NXTPUT
	SAD CURPUT
	SKP
	DAC* CURPUT
	ADD ONE
	DAC CURPUT
	DZM* CURPUT
	LAC BTEMP
	DAC NXTPUT
	DAC BUFEMP
	DAC BFPTSW
PUTRTN	ISZ PUTLIN	/..
	DZM LENGTH
PTOFLO	JMP* PUTLIN
WRCAL	LAC PBLKSW
	SZA
	JMP WRCAL1
	DZM PBLKSW
	JMP PUTLIN+1
WRCAL1	JMS WRFILE
	JMP PUTRTN
/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
	.IFUND	RSX
	SNA
	.ENDC
	.IFDEF	RSX
	SZA
	.ENDC
	JMP TTRS
	LAC* GETLIN	/GET LINE ADDRESS.
	.IFUND	RSX
	JMS GETBNK	/INSERT HIGH-ORDER BITS.
	.ENDC
	DAC UPKCAL+2	/GIVE TO UNPACKER.
	DAC RDCAL+1	/AND TO FILE READER.
	LAC GBLKSW	/GET BLOCK MODE.
	SZA		/SKIP IF BLOCK IS ON.
	JMP RDCAL		/READ FROM FILE IF NOT.
	LAC BUFEMP
	SNA
	JMP EMPBUF
	LAC CURGET	/GET POINTER TO NEXT LINE
	SNA		/SKIP IF THERE IS ANOTHER LINE TO GET.
	JMP EMPBUF	/NO MORE LINES.
	DAC UPKCAL+1	/GIVE TO UNPACKER.
UPKCAL	JMS UNPACK	/CALL UNPACK.
PWRD1	0		/FROM.
PWRD2	0		/TO.
	DAC LENGTH
	ISZ CURGET
	LAC* CURGET
	DAC CURGET
	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 MOVESW	/IF MOVE IS IN PROGRESS
	SZA		/LET MOVE GIVE MESSAGE IF 
	JMP EMPBUF-1	/THERE IS AN ERROR
	LAC ERRSW
	SAD C60
	JMP TYTRN
	SNA
	JMP EMPBUF-1
TYPAR	LAW PRTYMS
	JMS TYPOUT
	.IFDEF EDITVT
	JMS TYPRTN
	.ENDC
	JMP FND3
TYTRN	LAW TRNMES
	JMS TYPOUT
	.IFDEF EDITVT
	JMS TYPRTN
	.ENDC
	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.
	LAC* UNPACK	/ARG 2 IS ADDRESS OF OUTPUT LINE.
	TAD FENCE		/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.
	.IFUND	EAE
	DAC PWRD2		/SAVE AS FIRST WORD OF PARI.
	.ENDC
	.IFDEF	EAE
	DAC	PWRD1
	.ENDC
	LAC* 12		/PICK UP NEXT WORD.
	.IFUND	EAE
	DAC PWRD3		/SECOND WORD OF NEW CURRENT PAIR.
	.ENDC
	.IFDEF	EAE
	DAC	PWRD2
	.ENDC
	LAW -5		/SET UP TO EXTRACT 5 CHARACTERS FORM THIS PAIR.
	DAC PK5CHR	/..
	.IFDEF	EAE
	LAC	(UNPKJP	/SET UP THE POINTER TO THE JUMP TABLE
	DAC	UNPKJS	/TO UNPACK 5/7 ASCII
	.ENDC
/ENTER INNER LOOP TO GET NEXT CHARACTER FROM CURRENT WORD PAIR,
/STORE IT IN OUTPUT ARRAY, AND CHECK FOR COMPLETION.
	.IFUND	EAE
UNPLP2	JMS PRAL7		/GET NEXT CHAR FROM CURRENT PAIR.
	.ENDC
	.IFDEF	EAE
UNPLP2	XCT*	UNPKJS	/UNPACK A CHARACTER
	ISZ	UNPKJS	/MOVE POINTER FORWARD ONE
	.ENDC
	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	/..
	.IFDEF	EAE
	LAC	(PKJMPT	/SET UP THE JUMP TABLE
	DAC	PKJMS
	.ENDC
/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.
	.IFUND	EAE
PLOOP6	RTR		/SHIFT THIS CHARACTER TO BITS 0-6.
	RTR		/..
	RTR		/..
	RTR		/..
	DAC PWRD3		/ADD TO RIGHT-HAND END OF EMERGING PAIR.
PLOOP7	JMS PRAL7		/GO ROTATE THIS CHARACTER INTO THE PAIR.
	ISZ PK5CHR	/COUNT 5 CHARACTERS PER PAIR.
	JMP PLOOP2	/NOT FINISHED WITH THIS PAIR, GET NEXT CHARACTER.
	LAC PWRD2		/PAIR IS COMPLETE, BUT STILL OFF BY ONE BIT.
	CLL!RAL		/CLEAR PAIR BIT 35.
	DAC PWRD2		/PAIR BIT 17 IS NOW IN LINK.
	LAC PWRD1		/GET FIRST WORD OF PAIR...
	RAL		/...AND MOVE PAIR BIT 17 IN.
	DAC* 12		/PAIR IN PROPER FORMAT; DEPOSIT WORD 1 IN LINE BUFF.
	LAC PWRD2		/PICK UP WORD 2.
	DAC* 12		/STORE IT IN LINE BUFFER ALSO.
	.ENDC
	.IFDEF	EAE
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
	.ENDC
	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.
	.IFUND	EAE
  
/SUBROUTINE PRAL7, ROTATE IOPS ASCII WORD PAIR SEVEN BITS TO THE LEFT.
/DURING UNPACKING, THE WORD PAIR BEING TREATED MUST BE STORED IN REGISTERS
/PWRD2 AND PWRD3; THE NET EFFECT OF PRAL7 IS TO PLACE "THIS" CHARACTER FROM
/THE PAIR IN THE RIGHTMOST SEVEN BITS OF REGISTER PWRD1 AND TO LEAVE THE
/"NEXT" CHARACTER IN THE LEFTMOST SEVEN BITS OF REGISTER PWRD2. DURING PACKING,
/THE CHARACTER TO BE ADDED MUST BE STORED IN THE LEFTMOST SEVEN BITS OF 
/REGISTER PWRD3; THE CHARACTER IS ADDED TO THE RIGHT-HAND END OF THE WORD
/PAIR BEING DEVELOPED. AFTER FIVE CALLS TO PRAL7, THE 5-CHARACTER PAIR,
/SHIFTED ONE BIT TO THE RIGHT, APPEARS IN REGISTERS PWRD1 AND PWRD2.
PRAL7	0
	LAW -7		/SET UP SEVEN-BIT COUNTER.
	DAC PK7BTS	/..
PRALL7	LAC PWRD3		/ROTATE A SINGLE BIT
	RAL		/FROM PWRD3 TO PWRD1.
	DAC PWRD3
	LAC PWRD2
	RAL
	DAC PWRD2
	LAC PWRD1
	RAL
	DAC PWRD1
	ISZ PK7BTS	/COUNT SEVEN BITS TO GET.
	JMP PRALL7	/NOT FINISHED, ROTATE OUT ONE MORE BIT.
	JMP* PRAL7	/ALL DONE, RETURN TO CALLER.
	.ENDC
	.IFDEF	EAE
/
/ 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
/
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
/
	.ENDC
  
/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.
	.IFUND	RSX
	JMS GETBNK	/MAKE IT A 15-BIT ADDRESS.
	.ENDC
	DAC PKFROM	/GIVE TO INPUT POINTER.
	ISZ PK6BT		/BUMP TO OUTPUT ADDRESS.
	LAC* PK6BT	/GET START OF OUTPUT ARRAY.
	.IFUND	RSX
	JMS GETBNK	/MAKE IT 15 BITS LONG ALSO.
	.ENDC
	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
	.IFUND	RSX
/
/EXECUTE SEEK ON NAMED FILE.
/	JMS SEEK
/	POINTER TO DEB
/	RETURN
SEEK	0
PK7BTS=SEEK
PK6WDC=SEEK
	LAC INPTCL
	AND C777
	DAC SKCAL
	LAC* SEEK
	JMS GETBNK
	DAC SKCAL+2
	ISZ SEEK
	DZM INFILE
SKCAL	0
PK6CHR=SKCAL
LSTSW=SKCAL
FSTSW=SKCAL
	3
	0
PK6TO=SKCAL+2
	JMP* SEEK
/EXECUTE ENTER ON NAMED FILE.
/	JMS ENTER
/	POINTER TO DEB
/	RETURN
ENTER	0
	LAC OUTPCL
	AND C777
	ADD C1000
	DAC ENTCAL
	LAC* ENTER
	JMS GETBNK
	DAC ENTCAL+2
	ISZ ENTER
ENTCAL	0
	4
	0
	JMP* ENTER
/EXECUTE FSTAT ON NAMED FILE.
/	JMS FSTAT
/	DEB POINTER	(BIT 0 .E. 0, INPUT FILE.
/			(BIT 0 .E. 1, OUTPUT FILE.)
/	RETURN		(AC .E. -1, NON-FILE-ORIENTED.
/			(AC .E. 0, NOT FOUND)
FSTAT	0
	LAC* FSTAT
	RAL
	LAC OUTPCL
	SNL
	LAC INPTCL
	AND C777
	ADD C3000
	DAC FSTCAL
	LAC* FSTAT
	JMS GETBNK
	DAC FSTCAL+2
	ISZ FSTAT
FSTCAL	0
	2
DTYP1	0		/DIRECTORY TYPE CODE IN BITS 0-3.
	DAC FSTCAL
	LAC DTYP1
	AND CL7000
	SZA!CLA!CMA
	LAC FSTCAL
	JMP* FSTAT
/EXECUTE CLOSE ON IN OR OUT FILE.
/	JMS CLSFIL	(AC .E. 0 IF INPUT, AC BIT 0 .E. 1 IF OUTPUT.)
/	RETURN
CLSFIL	0
	RAL
	LAC INPTCL
	SZL
	LAC OUTPCL
	AND C777
	DAC CLSCAL
CLSCAL	0
	6
	JMP* CLSFIL
/RENAME A FILE.
/	JMS RENAME
/	DEB1		(BIT 0 .E. 0, INPUT; BIT 0 .E. 1, OUTPUT.)
/	DEB2
/	RETURN
RENAME	0
	LAW -2
	DAC RENMCT
	LAC* RENAME
	RAL
	LAC INPTCL
	SZL
	LAC OUTPCL
	AND C777
	ADD C2000
	DAC RNMCAL
	LAW RNMFIL-1
	JMS GETBNK
	DAC* C13
RNMLP1	LAW -3
	DAC RNMWRD
	CLA!CMA
	TAD* RENAME
	ISZ RENAME
	JMS GETBNK
	DAC* C12
RNMLP2	LAC* 12
	DAC* 13
	ISZ RNMWRD
	JMP RNMLP2
	ISZ RENMCT
	JMP RNMLP1
RNMCAL	0
	2
DEB1	RNMFIL
	JMP* RENAME
/EXECUTE DELETE ON NAMED FILE.
DELFIL	0
	LAC* DELFIL
	JMS GETBNK
	DAC DELNAM
	LAC* DELFIL
	RAL
	LAC OUTPCL
	SNL
	LAC INPTCL
	AND C777
	ADD C1000
	DAC DELCAL
DELCAL	0
	2
DELNAM	0
	ISZ DELFIL
	JMP* DELFIL
	.ENDC
	.IFDEF	RSX
/
/
/	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
/
PARSIZ	27	/RASIE PARTITION BOUND TO TOP
	ENDPAR	/EVENT VARIABLE ADDRESS CONTAINS ADDRESS OF BOUND
/
PREA14	2300	/PREALLOCATE
	EVA
	DAT14
/
PREA15	2300	/PREALLOCATE LUN15
	EVA
	DAT15
/
/
REDPAR	37	/READ PARAMETERS FROM TDV
	TDVEV	/EVENT VARIABLE ADDRESS
	LAONCE+2	/PARAMETER BUFFER (NONE)
	44	/WORD COUNT
/
TDVEV	0	/TDV EVENT VARAIBLE
/
REQTDV	1	/REQUEST FOR TDV
	0
	.SIXBT	'TDV...'
	0
/
/
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
/
TVWRA	2700	/WRITE ON AUX OUTPUT DEVICE
	EVTA	/EVENT VARIABLE ADDRESS
	DATP10	/LOGICAL UNIT NUMBER
	2	/IOPS ASCII
TVWRAD	0	/ADDRESS OF I/O
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
	LAC	(2)	/FORCE TDV TO BE CALLED
	DAC	TDVEV
	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=.
/
TDVER	CAL	WRTDVE	/TDV ERROR EXIT
	CAL	WFEVA	/WAIT FOR MESSAGE
	LAC	(2)	/FORCE TDV TO BE CALLED
	DAC	TDVEV
	JMP	EXIT1
/
WRTDVE	2700	/WRITE ERROR MESSAGE
	EVA	/EVENT VARIABLE ADDRESS
	DAT3	/OUTPUT LUN
	2	/IOPS ASCII
	TDVERM	/BUFFER ADDRESS
/
TDVERM	TDVEN-TDVERM/2*1000+2	/HEADER
	0
	.ASCII	/EDI-TDV ERR/<15>
TDVEN=.
/
WRIOER	2700	/WRITE I/O ERROR MESSAGE
	EVA	/EVENT VARIABLE
	DAT3	/OUTPUT DEVICE
	3	/IMAGE ASCII
	IOERMS	/BUFFER ADDRESS
/
/
/
	.ENDC
	.TITLE SUBR,CLSOUT FOR CLOSE PROC & EXIT PROC
/
/SUBROUTINE CLSOUT, CLOSE INPUT AND OUTPUT FILES.
CLSOUT	0
	JMS PUTLIN	/TRANSFER CURR LINE TO OUTPUT
	JMP FULBUF
	LAW -1		/START TURNING OFF BLOCK MODE
	DAC BLOKSW
	JMS RSBUFF
	LAC PBLKSW	/IF 0 WRITE OUT BUFFER
	SZA
	JMP CLS01	/WRITE OUT FILE
	JMS CHBUFF
	LAW -1		/KEEP TURNING OFF BLOCK MODE
	DAC PBLKSW
	JMS RSBUFF
	JMS CHBUFF
	DZM BUFEMP
CLS01	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.
	NOP		/..
	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		/..
	.IFUND	RSX
SETF1	LAW INNAME
	.ENDC
	.IFDEF	RSX
SETF1	JMS	ATTTY	/ATTACH TTY'S
	LAW	INNAME
	.ENDC
	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
	.IFDEF	RSX
	JMS	DETTY	/DETACH TTY'S
	.ENDC
	JMP EXITCH	/CHECK FOR EXIT REQUEST
	.IFUND	RSX
SAVERR	LAW	SAVNAM		/GIVE USER ERROR MESSAGE
	.ENDC
	.IFDEF	RSX
SAVERR	JMS	ATTTY	/ATTACH TTY'S
	LAW	SAVNAM	/GIVE USER ERROR MESSAGE
	.ENDC
	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
	.IFDEF	RSX
	JMS	DETTY	/DETACH TTY'S
	.ENDC
	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
	.IFUND BULKST
	.LOC EXIT
	JMP ILLCWD	/IF PAPER TAPE SYSTEM, DON'T ALLOW EXIT.
	.ENDC
	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
	.IFUND	RSX
	.IFDEF EDITVP
	DZM NUM		/WAIT FOR VP TO ERASE TO AVOID IOPS3 ERROR
	ISZ NUM
	JMP .-1
	.ENDC
	.IFDEF EDITVT
EXIT1	LAC*	SCOMCX
	AND	(1
	SAD	CTRLSV
	JMP	EXIT2
	LAC*	SCOMCX
	JMS	CTLXSD
	.ENDC
	.IFUND EDITVT
EXIT1=.
	.ENDC
	.IFDEF EDITVT
EXIT2=.
	.ENDC
	.EXIT		/EXIT TO MONITOR
C15=.-1
	.ENDC
	.IFDEF	RSX
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
	LAC	(DATP10)
	JMS	DETACH
	.IFNEG COPY-2
	LAC	TDVEV	/DO WE CALL TDV?
	SAD	(2)
	CAL	REQTDV	/YES
	.ENDC
	CAL	(10)	/EXIT
	.ENDC
	.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.
	.IFUND	RSX
	TTOCAL		/IOPS MODE WRITE TO TTY.
TAB	11		/..
TTOUT	0		/START OF LINE BUFFER.
SRCNAM	.SIXBT 'SRC'	/WORD COUNT -- IGNORED BY TELETYPE HANDLER.
	TTOCAL		/WAIT FOR PRINTING TO FINISH.
C12	12		/..
	.ENDC
	.IFDEF	RSX
	CAL	WRCAL3	/WRITE TTY OUTPUT
	JMS	WFEV	/WAIT FOR EVENT VARIABLE AND CHECK VALIDITY
	LAC	(DAT3)	/LUN OF ERROR
	.ENDC
	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.
	.IFUND	RSX
	TTICAL		/ISSUE CAL.
	10		/READ.
TTIN	0		/ADDRESS OF LINE BUFFER.
	-BUFLEN		/DON'T OVERFLOW BUFFER.
	TTICAL		/WAIT FOR USER TO FINISH.
	12		/..
	.ENDC
	.IFDEF	RSX
	CAL	RDCALT	/READ TTY INPUT
	JMS	WFEV	/WAIT FOR EVENT VARIABLE AND CHECK VALIDITY
	LAC	(DAT2)	/LUN OF ERROR
	.ENDC
	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.
	.IFUND	RSX
	TTOCAL+1000	/IMAGE MODE WRITE TO TTY.
	11		/..
ADR000	CHRMS		/ADDRESS OF OUTPUT MESSAGE.
CHRCT	0		/WORD COUNT -- IGNORED BY TELETYPE HANDLER.
	.WAIT -3
	.ENDC
	.IFDEF	RSX
	CAL	WRIMG	/WRITE MESSAGE
	JMS	WFEV	/WAIT FOR EVENT VARIABLE
	LAC	(DAT3)	/LUN OF ERROR
	.ENDC
	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.
	.IFUND	RSX
	TTOCAL		/OUTPUT CAL TO TELETYPE HANDLER.
C6	6		/.CLOSE WILL GENERATE CR/LF.
	.ENDC
	.IFDEF	RSX
	CAL	CRLF	/RETURN CARRAGE
	JMS	WFEV	/WAIT FOR EVENT VARIABLE AND CHECK VALIDITY
	LAC	(DAT3)	/LUN IN ERROR
	.ENDC
	JMP* TYPRTN	/RETURN TO CALLER.
	.IFUND EDITOR
	.TITLE DISPLAY ROUTINES FOR THE GRAPHICS HARDWARE
/SUBROUTINES FOR DISPLAYING OUTPUT ON VP09 STORAGE SCOPE.
/
/
/
/
/START OR STOP DISPLAY, DEPENDING ON TVSW.
/	CALL:	JMS	TVST
/	WILL START THE VP09 AND DISPLAY ALL LINES IN THE RING BUFFERS IF
/	TVSW=0(ON) OR .CLOSE(ERASE) THE DISPLAY IF TVSW=-1(OFF)
/
TVST	XX
	.IFUND EDITVT
/INITIALIZE AND RESET DISPLAY.
	.IFUND	RSX
TVST10	.INIT	TVDAT,1,RECOUP		/INIT DISPLAY
	.ENDC
	DZM	TVLCT	/RESET COUNT OF DISPLAYED LINES
	.ENDC
	LAC	TVSW		/CHECK ON STATUS OF TV SWITCH.
	SZA			/GO DISPLAY BUFFERS IF ON.
	JMP*	TVST		/RETURN IF OFF.
/DISPLAY ALL THE LINES IN THE RING OF BUFFERS
	LAC	TVSPTR		/FIRST LINE IN BUFFERS.
	DAC	TVCPTR
	LAW	-TVNLN		/NUMBER OF BUFFERS.
	DAC	TVCNT
TVST12=.
	.IFDEF EDITVT
	JMS CTXOFF
	.ENDC
	LAC*	TVCPTR		/GET BUFFER POINTER.
	SNA
	JMP*	TVST		/NO MORE LINES IF 0, RETURN.
	DAC	TVTEMP
	.IFDEF EDITVT
	JMS CTLXON
	.ENDC
	ISZ	TVCPTR		/POINT AT HEADER PAIR,
	LAC	TVCPTR
	.IFUND	RSX
	DAC	.+3		/INSERT BUFFER ADDRESS IN WRITE CAL
	.WRITE	TVDAT,2,0,0	/WRITE TO DISPLAY, IOPS ASCII
	.ENDC
	.IFDEF	RSX
	DAC	TVWRAD	/SAVE BUFFER ADDRESS
	CAL	TVWRA	/WRITE TO OUTPUT DEVICE
	JMS	WFEV	/WAIT FOR EVENT VARIABLE
	LAC	(DATP10) /LUN IN ERROR
	.ENDC
	.IFUND EDITVT
	ISZ	TVLCT		/INCREMENT LINE COUNT.
	.ENDC
	LAC	TVTEMP		/RESET POINTER
	DAC	TVCPTR		/TO NEXT BUFFER.
	ISZ	TVCNT		/CHECK BUFFER COUNT.
	JMP	TVST12		/RECYCLE.
	.IFDEF EDITVT
	JMS CTXOFF
	.ENDC
	JMP*	TVST		/ALL LINES DONE, RETURN.
/
/
/DISPLAY THE CURRENT LINE,UNPACKED, FROM INLINE.
/	CALL:	JMS	TVCL
/	WILL DISPLAY THE CURRENT LINE IF TVSW=0(ON)
/
TVCL	XX
	LAC	TVSW		/TV ON OR OFF
	SZA			/0=ON
	JMP*	TVCL		/OFF, NO ACTION.
/PACK LINE TO BE DISPLAYED
	.IFDEF EDITVT
	DZM VTFLAG
	.ENDC
	JMS	PACK		/SACK INTO IOPS ASCII
	INLINE			/FROM (CURRENT LINE)
	TVLINE			/TO
	.IFDEF EDITVT
	JMS CTLXON
	.ENDC
/DISPLAY IS RUNNING,ADD THE LINE TO IT.
	.IFUND EDITVT
	LAW	-70		/CHECK IF SCREEN IS FULL (56 LINES)
	TAD	TVLCT
	SMA
	JMS	TVST		/FULL SCREEN,GO RESTART DISPLAY.
	ISZ	TVLCT		/INCREMENT LINE COUNT.
	.ENDC
	.IFUND	RSX
	.WRITE	TVDAT,2,TVLINE,0	/WRITE THE LINE.
	.WAIT	TVDAT	/WAIT TO AVOID CATCHING UP WITH DISPLAY.
	.IFDEF EDITVT
	JMS CTXOFF
	.ENDC
	.ENDC
	.IFDEF	RSX
	LAC	(TVLINE)
	DAC	TVWRAD	/SET UP I/O REQUEST
	CAL	TVWRA	/DO I/O
	JMS	WFEV	/WAIT FOR EVENT VARIABLE
	LAC	(DATP10) /LUN IN ERROR
	.ENDC
	JMP*	TVCL		/RETURN.
/
/
/ADD A LINE TO THE DISPLAY RING BUFFERS.
/	CALL:	JMS	TVVP
/		BUFFER POINTER
/	WILL ADD THE PACKED LINE AT BUFFER POINTER TO THE DISPLAY RING
/	BUFFERS, REGARDLESS OF TVSW.
/
TVVP	XX
	LAC*	TVVP		/GET ARGUMENT
	ISZ	TVVP		/POINT TO RETURN LOCATION.
	DAC	TVTEMP		/SAVE ARGUMENT.
/INSERT PACKED LINE FROM ARGUMENT INTO DISPLAY BUFFER RING.
TVVP10	XX			/SWITCH FOR BUFFERS FULL OR BEING FILLED.
	/BUFFERS FULL, REPLACE OLD FIRST BY NEW LAST LINE.
	LAC	TVSPTR		/POINTS TO FIRST LINE.
	TAD	(1
	DAC	TVCPTR		/POINTS TO HEADER PAIR.
	LAC*	TVSPTR		/BUFFER POINTER TO NEXT BUFFER,
	DAC	TVSPTR		/WHICH BECOMES NEW FIRST LINE.	
	JMP	TVVP30		/GO MOVE TYLINE TO TVCPTR
	/BUFFERS BEING FILLED.
TVVP20	LAC	TVCPT2		/POINTS TO FIRST EMPTY BUFFER.
	TAD	(1
	DAC	TVCPTR		/POINTS TO HEADER PAIR.
	TAD	(BUFLEN		/POINTS TO NEXT BUFFER.
	SAD	TVBPTR		/IF THIS IS THE LAST BUFFER
	JMP	TVVP24		/GO MAKE IT POINT TO THE FIRST ONE.
TVVP22	DAC*	TVCPT2		/SET BUFFER POINTER
	DAC	TVCPT2		/SET FIRST-EMPTY POINTER.
	JMP	TVVP30		/GO MOVE TYLINE INTO TVCPTR.
TVVP24	LAC	NOPLIT		/NOP INTO BUFFERS-FULL SWITCH
	DAC	TVVP10
	LAC	(TVBUF1		/ADDR OF FIRST BUFFER INTO LAST BUF PTR.
	JMP	TVVP22
	/MOVE LINE INTO BUFFER POINTED AT BY TVCPTR.
TVVP30	LAW	-BUFLEN		/BUFFER LENGTH
	DAC	TVCNT		/INTO COUNTER.
TVVP32	LAC*	TVTEMP		/GET A WORD FROM THE LINE.
	DAC*	TVCPTR		/INSERT INTO BUFFER.
	ISZ	TVTEMP		/NEXT WORD.
	ISZ	TVCPTR		/...
	ISZ	TVCNT		/CHECK COUNT,
	JMP	TVVP32		/RECYCLE.
	JMP*	TVVP		/RETURN.
	/
/
	.IFDEF EDITVP
/
/
/BACK THE DISPLAY LINE COUNTER UP ONE LINE.
/	CALL:	JMS	TVMLF
/	REPOSITIONS THE DISPLAY UP ONE LINE AND REDUCES THE LINE
/	COUNT BY ONE, IF TVSW=0(ON)
/
TVMLF	XX
	LAC	TVSW		/CHECK TV ON OR OFF
	SZA			/0=ON
	JMP*	TVMLF		/OFF,NO ACTIONN
	LAW	-TVLF		/NUMBER OF RASTER UNITS PER LF
	DAC	TVCNT
	LAW	-2021		/TOP OF SCREEN + 1 LINE.
TVMLF2	TAD	TVLCT		/ADD NUMBER OF LINES LF TIMES,IE
	ISZ	TVCNT		/TVLF * TVLCT (TVLCT=NUMBER OF LINES	JMP	TVMLF2	
	JMP	TVMLF2		/DISPLAYED-1)
	CMA; TAD (1		/CHANGE SIGN
	RCR			/REDUCE TO X=0, Y =9 BITS.
	DAC	TVTEMP
	.IFUND	RSX
	AND (777000
	SZA
	JMP TVWR
	.WRITE	TVDAT,14,TVTEMP,1	/PLOT IN NON-STORE MODE (POSITION BEAM)
	.ENDC
TVWR	LAC	TVLCT		/SUBTRACT 1 FROM LINE COUNT.
	TAD	FENCE
	DAC	TVLCT
	JMP*	TVMLF
/
/
/CROSS OUT A LINE ON THE DISPLAY.
/	CALL:	JMS	TVXUT
/	CAUSES A BROKEN LINE TO BE DRAWN THROUGH THE DISPLAY LINE
/	BEFORE THE ONE ABOUT TO BE WRITTEN, IF TVSW=0(ON).
/
TVXUT	XX
	LAC	TVSW		/CHECK TV ON OR OFF
	SZA			/0=ON
	JMP*	TVXUT		/OFF, NO ACTION
	JMS	TVMLF		/BACK UP TO PREVIOUS LINE.
	ISZ	TVLCT		/BUMP LINE COUNT FOR THIS WRITE.
	LAC TVTEMP
	AND (777000
	SZA
	JMP TVWR1
	.IFUND	RSX
	.WRITE	TVDAT,2,TVDASH,0	/CROSS OUT LINE.
	.WAIT	TVDAT
	.ENDC
	.IFDEF	RSX
	LAC	(TVDASH)	/PICK UP THE WRITE ADDRESS
	DAC	TVWRAD	/SET IT IN THE WRITE REQUEST
	CAL	TVWRA	/ISSUE A WRITE REQUEST
	JMS	WFEV	/WAIT FOR EVENT VARIABLE
	LAC	(DATP10) /LUN IN ERROR
	.ENDC
TVWR1	JMP*	TVXUT		/RETURN
/
/
	.ENDC
/
	.IFDEF EDITVT
/
/
/SUBROUTINE "TVCLR" WILL CLEAR THE  ENTIRE
/SCREEN IF VT ON WAS TYPED
/**CODE TO ^X IN MONITOR IS 34(8) <LAW 34>
/
/
TVCLR	0
	XCT CTRLSW	/WAS VT ON TYPED
	JMP* TVCLR	/NO!
	LAC TVSW		/SAVE STATUS OF TVSW
	DAC TVXUT
	DZM TVSW		/TURN TVSW ON
	JMS CTLXON	/TURN ON ^X
	LAW 34
	JMS TYONCH
	JMS CTXOFF	/TURN OFF ^X
	LAC TVXUT		/RESTORE STATUS OF TVSW
	DAC TVSW
	JMP* TVCLR
/
/
/DELETE THE LAST LINE ON THE DISPLAY
/IF THE TV IS ON  IE  TVSW=0
/
/	CALL	JMS TVXUT
/	SENDS ASCII CODE (036) TO THE
/	CONTROL X FEATURE WHICH REMOVES
/	THE LAST LINE FROM THE DISPLAY FILE
/
/
TVXUT	0
	XCT CTRLSW	/WAS VT ON TYPED
	JMP* TVXUT	/NO--EXIT
	LAC TVSW
	SZA
	JMP* TVXUT
	JMS CTLXON	/TURN ^X ON
	LAW 36		/GIVE DELETE CODE TO MONITOR ^X CODE
	JMS TYONCH
	JMS CTXOFF
	JMP* TVXUT
/
/
/TURN ON CTRL X IF VT ON
/WAS TYPED AND TV IS ON
/
CTLXON	0
	LAC TVSW	/IS TV ON
	SZA
	JMP* CTLXON	/NO -- EXIT
	LAW -2
	AND* SCOMCX	/MAKEUP DATA WORD
	JMS CTLXSD
	JMP* CTLXON
/
/
/TURN CTRL X OFF IF VT ON
/WAS TYPED
/
CTXOFF	0
	XCT CTRLSW
	JMP* CTXOFF
	CLA		/GIVE A <LF> TO ^X -- ^X PACKS ON A <LF>
	JMS TYONCH	/AND THIS WILL GIVE IT ONE DUE TO OVERPRINT
	LAW -2		/MAKE UP DATA WORD
	AND* SCOMCX
	XOR (1
	JMS CTLXSD
	JMP* CTXOFF
/
/
/SET CTRL X STATUS REGISTER TO THE
/DATA WORD IN THE AC AND THEN ISSUE
/A CTRL X TO THE MONITOR IF VT ON
/WAS TYPED
/
CTLXSD	0
	XCT CTRLSW	/WAS VT ON TYPED
	JMP* CTLXSD	/NO--EXIT
	DAC* SCOMCX	/SET STATUS REG.
	LAW 30
	JMS* CTRLX	/SEND ^X TO MONITOR
	JMP* CTLXSD
/
/
/
	.ENDC
/
/
/
/
/
/DISPLAY CONSTANTS AND STORAGE.
TVNLN=5
TVSPTR	TVBUF1			/POINTS TO LOGICALLY 1ST BUFFER TO DISPLAY
TVBUF1	.BLOCK	BUFLEN+1*TVNLN	/RING BUFFER FOR TVNLN LINES
TVBPTR	.			/END OF BUFFERS
TVCPTR	0			/CURRENT BUFFER POINTER
TVCPT2	TVBUF1			/...USED BY BUFFER FILLER
TVCNT				/COUNTER
	.IFUND EDITVT
TVLCT				/LINES ON THE SCREEN
	.ENDC
TVON	-1			/DISPLAY ON INDICATOR
TVLF=22				/VP09 LINE FEED, RASTER UNITS
	.IFDEF EDITVP
TVDAT=10				/VP09 .DAT SLOT
TVDASH	TVDEND-.*400+2
TVTEMP	0			/TEMPORARY STORE
	.IFDEF	RSX
	.ASCII	<20>'----'	/OVERPRINT
	.ENDC
	.ASCII	'----------------------------------------'
	.ASCII	'------------------------------'<15>
TVDEND=.
	.ENDC
	.IFDEF EDITVT
TVDAT=-3
VTFLAG	0
TVTEMP	0
	.ENDC
	.ENDC
/
/
	.TITLE MESSAGES
/MESSAGES OUT.
EDTMES	ENDED1-.*400+2
BUFSIZ	-67	/LINES PER BLOCK MODE BUFFER LOAD (INITALLY 55(10)).
	.IFDEF EDITOR
	.ASCII / EDITOR V20A/<15>
	.ENDC
	.IFDEF EDITVP
	.IFUND	RSX
	.ASCII / EDITVP V20A/<15>
	.ENDC
	.ENDC
	.IFDEF EDITVT
	.ASCII / EDITVT V20A/<15>
	.ENDC
	.IFDEF RSX
B.TAG	.ASCII	'EDI.00 - RSX EDITOR'<15> ;E.TAG=.
	.LOC	B.TAG+2
	NN*4000+301005		/ MAGIC TO GENERATE 'EDI.NN'
	.LOC	E.TAG
	.ENDC
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=.
EOBRM	ENDEBM-.*400+2
NXTPTR	0	/POINTER TO NEXT CHARACTER IN CONTROL WORD STRING.
	.ASCII 'END OF BUFFER REACHED BY:'<15>
ENDEBM=.
BOVFLM	ENDBOM-.*400+2
	.IFUND	RSX
SCOM16	.SCOM+16
	.ENDC
	.IFDEF	RSX
	0
	.ENDC
	.ASCII 'BUFFER CAPACITY EXCEEDED BY:'<15>
ENDBOM=.
NOFIL1	ENDNF1-.*400+2
BUFEMP	0
	.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=.
BFNEMM	ENDBNM-.*400+2
CL7000	700000
	.ASCII 'BUFFER NON-EMPTY.'<15>
ENDBNM=.
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	BUFSPM-.*400+2
	.IFUND	RSX
SCOM2	.SCOM+2
	.ENDC
	.IFDEF	RSX
	0
	.ENDC
	.ASCII 'NOT ENOUGH '<175>
BUFSPM	LINEMS-.*400+2
	.IFUND	RSX
SCOM3	.SCOM+3
	.ENDC
	.IFDEF	RSX
	0
	.ENDC
	.ASCII 'BUFFER SPACE'<15>
LINEMS	LMEOFM-.*400+2
SGTSW	0		/LINE SWITCH FOR "SGTRAN"
	.ASCII 'LINES'<15>
	.LOC .-1
CHGREQ	SKP		/SWITCH FOR CHANGE COMMAND
LMEOFM	BUFTSM-.*400+2
MTWO	-2
	.ASCII 'LINES MOVED TO END'<15>
BUFTSM	MESEND-.*400+2
LINCSW	SKP		/SWITCH FOR LINE CONVERT
	.ASCII 'SIZE TOO SMALL'<15>
MESEND=.
TFILE1	.SIXBT '.TFILA'
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.
NPAIRS=GETCOM		/PUTLIN: TEMPORARY STORAGE.
	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	LAC GBLKSW
	SZA
	JMP PRTEOF
	LAC BFPTSW
	DAC BUFEMP
	LAW EOBRM
	SKP
PRTEOF	LAW EOFRM
	JMS TYPOUT
EOFCOM	JMS PACK
ADR010	EDLIN
	TYLINE
	LAW TYLINE
	JMS TYPOUT
	JMP FND4
/
/
IOINIT	0
CWDPTR=IOINIT
	.IFUND	RSX
	LAC INPTCL
	AND C777
	DAC .+1
	OPICAL		/INPUT DEVICE.
UNIT1	1
	0
INDEV	0
	.ENDC
	LAC ICLSW	/CHECK TO SEE IF ICLOSE WAS
	SMA!CLA!CMA	/REQUESTED
	JMP ICLREQ
	DZM LENGTH	/DON'T ZERO IF ICLOSE REQ
	.IFUND	RSX
	LAC OUTPCL
	AND C777
	ADD C1000
	DAC .+1
	OPOCAL		/SCRATCH DEVICE.
UNIT2	1
	0
OUTDEV	0
	.ENDC
	LAW -1
	DAC OUTSW1	/INDICATE NOTHING WRITTEN YET IN OUTPUT FILE
ICLREQ	DAC RDFNOP	/IF ICLOSE REQ LEAVE OUTSW1 ALONE
	DAC INFILE
	DAC OWFLSW
	.IFUND	RSX
	LAW -376
	TAD INDEV
	DAC INDEV
	SPA
	DZM INFILE
	LAC ICLSW	/CHECK ICLOSE SW TO SEE
	SZA		/IF .INIT WAS DONE TO OUTPUT
	LAW -376
	TAD OUTDEV
	SPA
	DZM OWFLSW
	DAC OUTDEV
	.ENDC
	.IFDEF	RSX
	DZM	OUTDEV	/INDICATE FILE STRUCTURED
	DZM	INDEV
	.ENDC
	LAC INFILE
	TAD OWFLSW
	SAD NAMEIN
	SKP!CLA
	CLA!CMA
	DAC FILSTR
	CMA
	DAC BLOKSW
	DAC PBLKSW
	JMS CHBUFF
	DZM BFPTSW
	LAW -1
	DAC ICLSW	/RESET ICLOSE SWITCH
	JMP* IOINIT
ICLSW	-1
INFILE	-1
OWFLSW	-1
FILSTR	0
INPSW	0
BBUF1	0		/START OF BLOCK BUFFER 1.
BBUF2	0		/START OF BLOCK BUFFER 2.
BBUFX	0		/LENGTH OF EACH BLOCK BUFFER.
	.IFDEF EDITVT
CTRLSV	0		/ ^X STATUS ON ENTRY
CTRLX	0		/ADDR OF VTLBUF IN MONITOR
CTRLSW NOP		/CTRL X SWITCH
	.ENDC
	.IFUND	RSX
	.IFDEF EDITVT
	.IFDEF DOS15
SCOMCX	.SCOM+33
	.ENDC
	.IFUND DOS15
SCOMCX	.SCOM+25
	.ENDC
	.ENDC
	.IFDEF PTP
INPDAT	DATM14
	.ENDC
	.IFUND PTP
INPDAT	.SCOM+23
	.ENDC
OUTDAT	DATM15
	.IFDEF DOS15
INPUIC	.SCOM+25
OUTUIC	0
/
/
	.ENDC
	.ENDC
/
/
/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
	.IFUND	RSX
	LAC* INPDAT	/CHECK DAT SLOTS
	SAD* OUTDAT
	SKP
	JMP NOGO
	.IFDEF DOS15
	LAC* INPUIC
	SAD* OUTUIC
	.ENDC
	.ENDC
	.IFDEF	RSX
	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?
	.ENDC
	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
	.IFDEF RSX
MAXBUF 0
EDTSIZ	.SIZE
	.ENDC
	.TITLE PATCH BLOCK
	.IFUND	RSX
/
/
/37(8) WORD AREA
/
	.REPT 36
PATCHF	0		/FIRST PATCH LOCATION
PATCHL	0		/LAST PATCH LOCATION
/
/
/
	.ENDC
/
/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.
RNMFIL=TYLINE
RENMCT=RNMFIL+6
RNMWRD=RENMCT+1
CALDB1=RNMWRD+1
CALDB2=CALDB1+3
CALDAT=CALDB2+3
SBUFF=TYLINE+LINSIZ
	.IFUND EDITOR
TVLINE=SBUFF+BUFLEN	/DISPLAY LINE BUFFER
RDBUF1=TVLINE+BUFLEN
	.ENDC
	.IFDEF EDITOR
RDBUF1=SBUFF+BUFLEN
	.ENDC
RDBUF2=RDBUF1+BUFLEN	/..
WRBUF1=RDBUF2+BUFLEN
WRBUF2=WRBUF1+BUFLEN
LABUF=WRBUF2+BUFLEN-1
/
/
	.IFDEF BIN
	.LOC LABUF
	0
	.ENDC
/
/
	.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
	.IFUND	RSX
	.IFUND PTP
	LAW -15
	TAD* INPDAT
	DAC OUTDAT
	DAC INPDAT
	ISZ INPDAT
	.IFDEF DOS15
	LAW -15
	TAD* INPUIC
	DAC OUTUIC
	DAC INPUIC
	ISZ INPUIC
	.ENDC
	.ENDC
	LAW ADRTBL
	JMS GETBNK
	DAC* C12
ADRLP1	LAC* 12
	JMS GETBNK
	DAC POINTR
	LAC* POINTR
	JMS GETBNK
	DAC* POINTR
	ISZ ACOUNT
	JMP ADRLP1
	LAC* SCOM2
	.ENDC
	.IFDEF	RSX
	.IFNEG COPY-2
	CAL	REDPAR	/CLEAR TDV BUFFER
	LAC	TDVEV	/CHECK THE EVENT VARIABLE TO SEE IF
	SPA		/IT IS LEGAL
	JMP	TDVER	/NO EXIT TASK
	.ENDC
	LAC	EDTSIZ	/PICK UP THE SIZE
	.ENDC
	DAC BBUF1
	.IFUND	RSX
	LAC*	SCOM3
	.ENDC
	.IFDEF	RSX
	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	PREOK	/OK PREALLOCATION
	SAD	(-6)	/NOT IMPLEMENTED?
	JMP	PREOK	/YES OK
	JMS	IOERR	/NO I/O ERROR
	LAC	(DAT15)	/LUN OF ERROR
PREOK	CAL	PARSIZ	/FIND THE SIZE OF THE PARTITION
	LAC	ENDPAR	/PICK UP THE END OF THE PARTITION
	.ENDC
	.IFUND	RSX
	JMS GETBNK
	.ENDC
	CMA
	TAD BBUF1
	CMA
	RAR!CLL
	DAC BBUFX
	TAD BBUF1
	DAC BBUF2
	DZM BFPTSW
	.IFUND	RSX
	LAC*	SCOM3
	.ENDC
	.IFDEF	RSX
	LAC	BBUFX	/PICKUP THE BUFFER SIZE
	CLL		/IN WORDS AND SET UP A 
	IDIV		/REASONABLE BLOCK SIZE
	BUFLEN		/LINE SIZE
	LACQ		/PICK UP THE QUOTENT
	AAC	-1	/SUBTRACT 1 TO BE SAFE
	SPA		/CHECK TO SEE IF POSITIVE
	JMP	LDERR	/NO NOT ENUF CORE
	TCA		/COMPLEMENT TO MAKE NEGATIVE FOR BUFSIZ
	DAC	BUFSIZ	/SET UP BUFFER SIZE MAX
	DAC	MAXBUF	/SET UP MAXIMUM BUFFER'S ALLOWED
	LAC	ENDPAR	/PICK UP THE END OF THE PARTITION
	.ENDC
	.IFUND	RSX
	JMS GETBNK
	.ENDC
	CMA
	.IFUND	RSX
	TAD* SCOM2
	.ENDC
	.IFDEF	RSX
	TAD	EDTSIZ	/ADD THE CODE SIZE
	.ENDC
	SPA!SNA
	JMP OK
	.IFUND	RSX
	LAW LOAD1
	.ENDC
	.IFDEF	RSX
LDERR	LAW	LOAD1
	.ENDC
	JMS TYPOUT
	.IFDEF	RSX
	LAC	(2)	/FORCE TDV TO BE CALLED
	DAC	TDVEV
	.ENDC
	JMP EXIT1
LOAD1	ENDLD1-.*400+2
	0
	.IFUND	RSX
	.ASCII '.SYSLD 1'<15>
	.ENDC
	.IFDEF	RSX
	.ASCII	'EDT-PARTITION TOO SMALL'<15>
	.ENDC
ENDLD1=.
OK	JMS CHBUFF
	.IFDEF EDITVT
	LAW -3	/GET ADDRESS OF EDITVT
	TAD* (.SCOM+23	/MONITOR ^X INTERCONNECTION
	DAC CTRLX		/LOCATED AT TTA.-2
	LAW -2
	TAD* CTRLX
	DAC CTRLX
	LAC* CTRLX
	DAC CTRLX		/WAS VT ON TYPED NON ZERO IF SO
	SNA
	JMP OK1		/NO--DON'T SET SWITCH
	.IFDEF DOS15
	LAC* (.SCOM+52	/IF IN BOSS15 MODE
	SPA			/DON'T SET SWITCH
	JMP OK1
	.ENDC
	LAC SKPLIT
	DAC CTRLSW
OK1	LAC* SCOMCX	/SAVE ENTRY STATE OF ^X
	AND (1
	DAC CTRLSV
	.ENDC
	.IFUND	RSX
	TTICAL
	1
ADR012	RECOUP
	0
	IN2CAL
	1
	0
SBSIZ	0
	LAW -376
	TAD SBSIZ
	SPA
	.ENDC
	JMP BEGIN+1
	.IFUND	RSX
	LAW FSDERM
	JMS TYPOUT
	LAW FSDER1
	JMS TYPOUT
	LAW TYLINE
	JMS TYPEIN
	LAC TYLINE+2
	XOR YES
	SNA
	JMP BEGIN+5
	JMP EXIT1
FSDERM	ENDFSD-.*400+2
	0
	.ASCII '.DAT -10 IS FILE-ORIENTED.'<15>
ENDFSD=.
FSDER1	ENDFR1-.*400+2
	0
	.ASCII 'DO YOU WISH TO CONTINUE'<77><15>
ENDFR1=.
YES	.ASCII 'YES'
	.LOC .-1
ADRTBL=.-1
	CWDLIT
	CWDTOP
	INLADR
	EDLADR
	EDLAD1
	FEED
	SBADR
	RDCAL2
	RDALTB
	WRPAK2
	WRALTB
	DEB1
	CKNM1
	CKNM2
	CKNM2+1
	ADR000
	ADR001
	ADR002
	ADR002+1
	ADR003
	ADR004
	ADR004+1
	ADR005
	ADR005+1
	ADR006
	ADR006+1
	ADR008
	ADR008+1
	ADR009
	ADR010
	ADR010+1
	ADR011
	ADR011+1
	ADR012
	ADR013
	ADR013+1
	ADR014
	ADR014+1
	ADR015
	ADR015+1
	ADR016
	ADR016+1
	ADR017
	ADR017+1
	ADR018
	ADR018+1
ACOUNT	ADRTBL-.+1
	.ENDC
	.LTORG
LAONCE=.-1
	.END BEGIN
