Google
 

Trailing-Edge - PDP-10 Archives - custsupcuspmar86_bb-x130b-sb - lined.mac
There are 6 other files named lined.mac in the archive. Click here to see a list.
TITLE	LINED	VERSION 13B	
SUBTTL	LINE EDITOR FOR DISK FILES		LARRY WADE/WJM/PMH/CAM



;COPYRIGHT (C) 1974,1978,1979 BY
;DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
;
;
;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
;ONLY  IN  ACCORDANCE  WITH  THE  TERMS  OF  SUCH LICENSE AND WITH THE
;INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY  OTHER
;COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
;OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF THE  SOFTWARE  IS  HEREBY
;TRANSFERRED.
;
;THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT  NOTICE
;AND  SHOULD  NOT  BE  CONSTRUED  AS A COMMITMENT BY DIGITAL EQUIPMENT
;CORPORATION.
;
;DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY  OF  ITS
;SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.

EDIT==22
VERSION==XWD 1302,EDIT

;COPYRIGHT 1970,1971,1974, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.



;DEFAULT DEFINITIONS FOR ASSEMBLY SWITCHES
;THESE YIELD A REENTRANT LINED WITH CCL & TMPCOR UUO CAPABILITY

IFNDEF PURE,<PURE==1>
IFNDEF CCLSW,<CCLSW==1>
IFNDEF TEMP,<TEMP==1>

;FOR ANY OTHER VERSION ASSEMBLE AS FOLLOWS:
;.R MACRO
;*LINED_TTY:,DSK:LINED.MAC
;PURE=0				((IF NON-REENTRANT LINED WANTED))
;CCLSW=0			((IF CCL NOT WANTED))
;TEMP=0				((IF TMPCOR UUO NOT AVAILABLE))
;^Z
;^Z



LOC	137
	VERSION
RELOC	0

IFN PURE,<
	TWOSEG
RELOC	400000
	>
;	
;	GENERAL-
;	LINED IS A DERVIATIVE OF
;	DREDIT (DRUM EDITOR) WHICH WAS WRITTEN BY WILLIAM MEIR OF APPLIED
;	LOGIC CORPORATION AND EXISTS AS PART OF THE DECUS LIBRARY.
;	LINED'S COMMAND STRUCTURE IS SIMILIAR TO DEC'S "EDITOR"
;	BUT WORKS WITH FILES WHICH RESIDE ON THE DISK INSTEAD OF
;	ON DEC TAPE.
;	
;	
;	
;	PURPOSE-
;	
;	THIS MEMO WILL DESCRIBE THE CAPABILITIES AND RESTRICTIONS OF 
;	LINED AND OUTLINE THE CHANGES NECESSARY TO MAKE LINED A PART 
;	OF DEC'S SOFTWARE.
;	
;	A MAJOR FEATURE OF LINED IS THE ABILITY TO
;	REFERENCE ANY LINE AT ANY TIME, WITHOUT FIRST HAVING TO
;	CLOSE AND THEN REOPEN THE FILE.
;	
;	COMMAND STRUCTURE-
;
;	IN THE FOLLOWING DESCRIPTION, A POINT (.) OR DOT REFERS TO THE
;	LAST LINE WHICH WAS TYPED, THE LAST LINE DELETED, OR THE LAST
;	LINE INSERTED.
;	
;	1. TO OPEN AN EXISTING FILE FOR EDITING.
;	
;		S<FILENAME.EXT><CR>
;	
;	2. TO CREATE A NEW FILE.
;	
;		S<FILENAME.EXT><ALTMODE>
;	
;	3.TO INSERT TEXT
;	
;		I
;		I N1
;		I N1,N2		INSERT THE TEXT WHICH FOLLOWS AT LINE
;				N1 AND ASSIGN SEQUENCE NUMBERS IN
;				INCREMENTS OF N2 FOR EACH LINE AFTER THE
;				FIRST. IF LINE N1 EXISTS IT WILL BE
;				REPLACED. IF N1 IS NULL A VALUE OF 10 IS
;				ASSUMED. N1 MAY BE SPECIFIED AS A POINT (.).
;				IF N2 IS NULL EITHER A VALUE OF 10
;				IS ASSUMED OR THE VALUE LAST SPECIFIED IN
;				AN INSERT COMMAND IS USED.
;				AN ALTMODE IS TYPED TO RETURN TO LINED
;				COMMAND LEVEL.
;	
;	4. TO PRINT TEXT.
;	
;		P N1
;		P N1,N2		PRINT LINE N1 OR LINES N1 THROUGH N2
;				N1 MAY BE SPECIFIED AS A POINT (.).
;				N2 MAY ALSO BE SPECIFIED AS A POINT AS
;				LONG AS N1<N2.
;				AN ALTMODE WILL CAUSE THE NEXT LINE
;				TO BE TYPED.
;	
;	5. TO DELETE TEXT
;	
;		D N1
;		D N1,N2		DELETE LINE N1 OR LINES N1 THROUGH N2
;				N1 MAY BE SPECIFIED AS A POINT (.)
;				UNLESS AN INSERT WAS JUST PERFORMED.
;				N2 MAY ALSO BE SPECIFIED AS A POINT AS
;				LONG AS N1<N2.
;	
;	6. TO CLOSE A FILE
;	
;		E<CR>
;	
;	RESTRICTIONS-
;	
;	1.	WHEN IN INSERTION MODE, THE ALTMODE RETURNS TO LINED 
;		COMMAND LEVEL. IF THE ALTMODE IS ALSO USED TO TERMINATE
;		A LINE OF TEXT TO BE INSERTED, THE LINE OF TEXT IS 
;		IGNORED.
;	
;	2.	LINED ASSUMES ALL BLOCKS ON THE DISK FILE HAVE AN
;		INTEGRAL NUMBER OF LINES. TO GUARANTEE THIS THE USER
;		SHOULD USE THE "A" SWITCH (LINE BLOCKING) WITH PIP TO PUT A FILE ON
;		THE DISK.
;	
;	3.	LINED AND TECO ARE INCOMPATIBLE AND THE SAME  FILE
;		SHOULD NOT BE EDITED BY BOTH UNLESS SEQUENCE
;		NUMBERS ARE EITHER ADDED OR DELETED.
;
;	4.	LINE NUMBER 0 IS ILLEGAL.
;	
;	
;	ERROR HANDLING-
;	
;	WHEN AN ERROR IS DETECTED, A MEANINGFUL MESSAGE IS TYPED.
;	IF IT IS AN I/O ERROR, WE EXIT. OTHERWISE WE
;	RETURN TO COMMAND LEVEL.
;	
;	NOTE: THE OLD *ILR* AND *ILS* MESSAGES HAVE BEEN REMOVED.
;		INSTEAD OF THEM LINED WORKS AS FOLLOWS:
;		IF INSERTION AT A GIVEN LINE NUMBER WILL CAUSE
;		REPLACEMENT OF AN EXISTING LINE, THE LINE# IS
;		FOLLOWED BY A SINGLE TIC (').
;		IF THE INSERTION LINE# INCREMENT IS SUCH THAT
;		INSERTION AT A GIVEN LINE WILL CAUSE AN EXISTING
;		LINE TO BE SKIPPED, THE LINE NUMBER IS
;		FOLLOWED BY A DOUBLE TIC ("). SEE EXAMPLE 4.
;		(THIS CHANGE EFFECTIVE AS OF V.010)
;	
;	CONCISE COMMAND LANGUAGE INTERFACE-
;	
;	THE CCL COMMANDS "CREATE" AND "EDIT" WILL BE USED TO ACCESS
;	LINED. THE "CREATE" COMMAND WILL EFFECTIVELY GENERATE THE SEQUENCE
;	
;		R LINED
;		S<FILENAME><ALTMODE>
;	
;	THE "EDIT" COMMAND WILL EFFECTIVELY GENERATE THE SEQUENCE
;	
;		R LINED
;		S<FILENAME><CR>
;	
;	THE CCL CUSP WILL GENERATE A TEMPORARY DISK FILE WITH THE NAME
;	
;		###EDT.TMP
;	
;	IN ORDER TO PASS THE ABOVE COMMANDS.
;	
;	
;	
;	EXAMPLE-1
;	
;		.R PIP<CR>
;		*DSK:(ASX)_DTA0:FILE.ONE<CR>
;		*^C
;		.R LINED <CR>
;		*SFILE.ONE<CR>
;		*P10,30<CR>
;		00010	THIS IS THE FIRST LINE
;		00020	THIS IS THE SECOND LINE
;		00030	THIS IS THE THIRD LINE
;		*I20<CR>
;		00020'	THIS IS THE NEW LINE
;		*D30<CR>
;		*P10,30<CR>
;		00010	THIS IS THE FIRST LINE
;		00020	THIS IS THE NEW LINE
;		*E<CR>
;		*^C
;		.
;	
;	EXAMPLE-2
;	
;		.CREATE PROGRAM
;		*I<CR>
;		00010	THE PROGRAM IS
;		00020	INSERTED HERE
;		00030
;		  .
;		  .
;		  .
;		  .
;		000XX	<ALTMODE>
;		*E<CR>
;		*^C
;		.
;	
;	
;	EXAMPLE-3
;			VALID FORMS OF THE INSERT COMMAND
;
;		I
;		I10
;		I10,2
;		I.
;		I,1
;		I.,1
;
;
;	EXAMPLE-4	NEW INDICATION OF REPLACEMENT & SKIPPING
;
;		*SFOO<ALT>
;		*I10
;		00010	A
;		00020	B
;		00030	C
;		00040	D
;		00050	<ALT>
;		*I20,5
;		00020'	BB
;		00025	XX
;		00030'	CC
;		00035	<ALT>
;		*I30,20
;		00030'	CCC
;		00050"	EEE
;		00070	<ALT>
;		*
;
;	IMPLEMENTATION-
;	
;	EACH LINE OF TEXT IS STORED IN THE WORKING BUFFER WITH A LINE
;	HEADER WHICH HAS TWO ITEMS.  IN THE LEFT HALF IS THE SEQUENCE
;	NUMBER IN BINARY AND IN THE RIGHT HALF IS THE NUMBER OF WORDS
;	(INCLUDING THE LINE HEADER) WHICH ARE NEEDED TO STORE THE 
;	LINE OF TEXT.  THUS TO FIND THE NEXT LINE OF TEXT IT IS JUST
;	NECESSARY TO TAKE THE ADDRESS OF THE CURRENT LINE HEADER AND
;	ADD THE WORD COUNT.
;	
;	SEVERAL POINTER WORDS ARE USED TO KEEP TRACK OF THE LINES IN
;	THE WORKING BUFFER.  WRTLST CONTAINS THE SEQUENCE NUMBER OF THE
;	LAST LINE WHICH WAS JUST PASSED THROUGH THE WORKING BUFFER.
;	SEQLST CONTAINS THE HIGHEST SEQUENCE NUMBER OF THE HIGHEST
;	LINE IN THE BUFFER.  SN CONTAINS THE SEQUENCE NUMBER OF THE LINE
;	CURRENTLY BEING HANDLED IN A COMMAND.
;	
;	WHEN THE PROGRAM DISCOVERS THAT SN IS GREATER THAN WRTLST IT
;	KNOWS THAT THE LINE BEING SOUGHT HAS ALREADY PASSED THROUGH
;	THE WORKING BUFFER AND IS NOT DIRECTLY ACCESSIBLE SINCE THERE
;	IS NO WAY TO READ A FILE BACKWARDS.  CONSEQUENTLY, IT IS NEC-
;	ESSARY TO CLOSE THE FILE AND THEN REOPEN IT.  THIS PROCESS OF
;	GOING AROUND FROM WHERE WE ARE, TO THE END OF THE FILE, TO
;	THE BEGINNING OF THE FILE AND FINALLY TO THE LINE BEING SOUGHT
;	IS DONE.
;	
;	TO CLOSE THE FILE IT IS NECESSARY TO PASS ALL REMAINING TEXT
;	THROUGH THE WORKING BUFFER AND TO THE TEMPORARY OUTPUT FILE
;	(CALLED ###LIN.TMP).  THIS IS DONE BY GIVING THE SUBROUTINE
;	FNDLIN (FIND A LINE WHOSE SEQUENCE NUMBER IS IN SN) THE 
;	HIGHEST POSSIBLE SEQUENCE NUMBER, 99999.  NEXT THE ORIGINAL 
;	FILE IS RENAMED TO ###TMP.TMP, THE TEMPORARY OUTPUT FILE
;	IS RENAMED TO THE ORIGINAL FILE NAME, AND THE ###TMP.TMP FILE
;	IS DELETED.  THEN WE GIVE FNDLIN THE SEQUENCE NUMBER CURRENTLY
;	BEING LOOKED FOR AND THE PROGRAM CONTINUES WITH THE ORIGINAL
;	COMMAND.
; AC DEFINITIONS

FF=0	; FLAGS
CH=1	; ASCII CHARACTER
SN=2	; SEQUENCE NUMBER
P=3	; PDL POINTER
TAC=4	; TEMPORARY AC'S
TAC1=5	;
LP=6	; ADDR OF CURRENT LINE
N1=7	; ARGS FOR COMMANDS
N2=10	;
NUM=11	; FOR NUMBER CONVERSION
AC1=12	; SCRATCH
AC2=13	;    "
AC3=14	;    "
AC4=15	;    "
OC=16	;
PS=17	;PREVIOUS SEQUENCE NUMBER

; MORE DEFINITIONS
	ALTMOD==33	;DEFINITION OF AN ALTMODE
	ETTY==0
	EICHL==1	;EDIT DEVICE CHANNELS
	EOCHL==2
	EMDE==10	;EDIT DEVICE MODE
	CCLC==3		;CCL DSK CHANNEL
	PJOB==30	;CALLI ARGUMENTS
	TMPCOR==44
	RESET==0
	EXIT==12

;RH FLAGS (SET AND CLEARED DURING CMD EXECUTION)
	NARG==1		;1=TWO ARGS SEEN
	ER==2		;TRYING AGAIN ON ERROR
	TFLG==10	;AN EXISTING LINE HAS BEEN REPLACED ONCE ALREADY
	DARG==20	;USED IN DCOM
	FILFLG==40	;
	IFLG==100	;INSERTION CMD IN PROGRESS
	ILRFLG==200	;INSERT LINE FOUND
	ILSFLG==400	;INSERT SKIPS EXISTING LINE
	EOL==1000	;END-OF-LINE SEEN

;LH FLAGS (CLEARED ONLY BY E COMMAND)
	FILACT==1	;DENOTES ACTIVE FILE
	NFILE==2	;0=NEW FILE ONLY
	ROUND==4	;=1 IF IN THE PROCESS OF GOING AROUND TO THE
			;BEGINNING OF THE FILE
	NDFIL==10	;END OF INPUT FILE OR NO INPUT FILE IF =0
	CCLF==100	;=1 IF ENTERED VIA CCL
;  INITIALIZATION

START:
IFN CCLSW,<
	TLZA	FF,CCLF
	TLO	FF,CCLF
	>
CSETUP:
IFN PURE,<
	MOVSI	TAC,ENDP	;IF REENTRANT, SET FIRST
	HLLM	TAC,.JBSA##		;FREE LOC. IN LOW SEG.
	>
	CALLI	RESET		;INITIALIZE 
	MOVE	TAC,.JBFF##	;ASSIGN CORE FOR DATA
	ADDI	TAC,2000
	CALLI	TAC,11
	JRST	NOCORE
	SETZM	DATA		;CLR DATA SEGMENT
	MOVE	TAC,[XWD DATA,DATA+1]
	BLT	TAC,ENDP-1
	MOVE	TAC,[JRST ERROR2]	;INIT DATA SEG. CONSTANTS
	MOVEM	TAC,ERROR1
	MOVE	TAC,[MOVEI TAC,DOFIL1]
	MOVEM	TAC,FILL1
	MOVE	TAC,[HRRZI TAC,DOFIL2]
	MOVEM	TAC,FILL2
	MOVE	TAC,[MOVE AC1,(AC2)]
	MOVEM	TAC,MOV1
	MOVE	TAC,[MOVEM AC1,(AC2)]
	MOVEM	TAC,MOV2
	MOVE	TAC,[MOVEM AC3,(AC2)]
	MOVEM	TAC,M2
	MOVE	TAC,[MOVE AC4,(AC2)]
	MOVEM	TAC,M1
	MOVE	TAC,[HRLI AC1,(LP)]
	MOVEM	TAC,DCM1
	MOVE	TAC,[SKIPE AC1,(TAC)]
	MOVEM	TAC,LNCNT1
	MOVE	TAC,[BLT AC1,(TAC)]
	MOVEM	TAC,OUTLN1
IFN CCLSW,<
	MOVE	TAC,[JRST CCLHR2]
	MOVEM	TAC,CCLHR3
IFN TEMP,<
	MOVSI	TAC,SIXBIT/   EDT/
	MOVEM	TAC,TMPFIL
	MOVSI	TAC,777600	;XWD -200,0
	MOVEM	TAC,TMPFIL+1
	>>
	MOVEI	TAC,SIXBIT/   TMP/
	HRRZM	TAC,ZDIRC
	HRLZM	TAC,ZDIRC+1
	HRLZM	TAC,ODIRC+1
IFN CCLSW,<
	HRLZM	TAC,CCLDIR+1
	MOVEI	TAC,SIXBIT/   EDT/
	HRRZM	TAC,CCLDIR
	>
	MOVEI	TAC,SIXBIT/   LIN/
	HRRZM	TAC,ODIRC
	MOVEI	TAC,SIXBIT/   BAK/
	HRLZM	TAC,ZILCH+1
	MOVEI	TAC,3		;GET PPN AND STORE IN DIRECTORYS
	CALLI	AC1,PJOB
CCLHR1:	IDIVI	AC1,12
	ADDI	AC2,"0"-40
	LSHC	AC2,-6
	SOJG	TAC,CCLHR1
IFN CCLSW,<
	HLLM	AC3,CCLDIR
	>
	HLLM	AC3,ODIRC
	HLLM	AC3,ZDIRC
	HRRI	COMCLR
	HRRM	.JBREN##	;SET UP ALTERNATE ENTRY POINT
	TRZ	FF,ER
CSET9:	INIT	ETTY,0
	SIXBIT	/TTY/
	XWD	TYOBF,TYIBF
	JRST	NOTTY
TIBUF:	INBUF	ETTY,1
TOBUF:	OUTBUF	ETTY,1
	MOVE	TAC,.JBFF
	MOVEM	TAC,SVJBFF
	SETZM	SN
IFN CCLSW,<
	AND	FF,[XWD CCLF,0]
	TLNE 	FF,CCLF
	JSR	CCLHRE
	>

COMCLR:	MOVE	P,[XWD -PDSIZ1,PDL-1]	;CLEAR PDL LIST

COMRET:	PUSH	P,.		; FOR RETURN (NEVER "JRST" HERE)
	TRZ	FF,777777	;CLEAR FLAGS
IFN CCLSW,<
	TLNN	FF,CCLF
	>
	PUSHJ	P,ASKOUT

;NOW FALL INTO DISPATCH ROUTINE
; DISPATCH ROUTINE

COMRT1:	PUSHJ	P,GETCH1
	CAIN	CH,15
	JRST	GETCHR
	CAIE	CH,"S"
	CAIN	CH,"E"
	JRST	ARWCOM
	TLNN	FF,FILACT	;ACTIVE FILE ?
	JSR	NFO,ERROR	;NO
	CAIN	CH,ALTMOD	;CHECK FOR ALTMODE
	JRST	SPLPRT		;ALMODE SEEN
	MOVE	AC4,CH
	PUSHJ	P,GETARG
	CAIN	AC4,"I"
	JRST	ICOM
	CAIN	AC4,"D"
	JRST	DCOM
	CAIN	AC4,"P"
	JRST	PCOM
	JSR	ILC,ERROR

SPLPRT:	AOJG	SN,PDCOM	;PRINT THE NEXT LINE
	JRST	COMCLR		;ZERO SN

;TELETYPE INITIALIZATION ERROR

NOTTY:	TRON	FF,ER		;TRIED TWICE?
	JRST	CSET9		;NO, TRY AGAIN
	TTCALL	3,EMTTY		;YES, DIAGNOSTIC
	CALLI	EXIT		;NO TTY IS FATAL

EMTTY:	ASCIZ	/
?CANNOT INIT TTY/
; ROUTINE TO PICK UP ARGS FROM COMMAND
;  RETURNED IN N1,N2 (N2=0 FOR 1 ARG)
;  SPACES IGNORED

GETARG:	SETZB	N2,NUM
	MOVEI	TAC,5		; COUNT
GTARG2:	PUSHJ	P,GETCHR	; GET INPUT CHAR.
	CAIG	CH,"9"		; NUMBER?
	CAIGE	CH,"0"
	JRST	GTARG3		; NO
	PUSHJ	P,NCHCON	; YES - CONVERT
	SOJGE	TAC,GTARG2	; AGAIN
	JSR	ILC,ERROR	; NO
GTARG3:	CAIN	CH,40		; SPACE?
	JRST	GTARG2		; YES
	CAIE	CH,"."
	JRST	.+3
	MOVE	NUM,SN
	PUSHJ	P,GETCHR
	TRNE	FF,NARG		; 2ND TIME?
	SKIPA	N2,NUM		; YES
	MOVE	N1,NUM		; NO
	CAIN	CH,15		; CR
	JRST	GETCHR		; YES - DISCARD LF+RETURN
	CAIN	CH,ALTMOD	;CHECK FOR ALTMODE
	POPJ	P,
	CAIN	CH,","		; TWO ARGS?
	TROE	FF,NARG		; YES - ALLOWABLE?
	JSR	ILC,ERROR	; NO OR BAD CHAR
	JRST	GETARG		; YES

CON033:	MOVEI	CH,33		;MAKE IT STANDARD
	POPJ	P,		;RETURN
; INSERT COMMAND

; (N1=SN WANTED)
; (N2=STEP SIZE)

ICOM:	SKIPE	N2		;NEW STEP SIZE?
	MOVEM	N2,STPSIZ	;YES
	SKIPN	SN,N1		;GET SEQ# IF SPECIFIED
	PUSHJ	P,SET10		;ASSUME SN OF 10 IF NONE SPECIFIED
	PUSHJ	P,LPSET		;SET LINE PTR & PREV. SEQ#
ICOM1:	MOVEI	TAC1,AC4	; GET ASCII SEQ.#
	PUSHJ	P,RDXA		; CONVERT TO ASCII
	PUSHJ	P,FNDLIN	; FIND LOCATION OF LINE
	JRST	ICOM2		; NOT FOUND
	TRO	FF,ILRFLG	;SET REPLACEMENT FLAG
	TRO	FF,TFLG		;SET "EXISTING" FLAG
ICOM2:	TRON	FF,IFLG
	JRST	.+3
	CAME	PS,AC3
	TRO	FF,ILSFLG	;INSERT HAS SKIPPED A LINE
	AOS	TYOBF1
	MOVEM	AC4,@TYOBF1	; SEQ # TO TYO BUFFER
	MOVEI	CH,42		;TYPE " IF SKIPPING A LINE
	TRZE	FF,ILSFLG
	PUSHJ	P,PUTCHR
	MOVEI	CH,"'"		;TYPE ' IF REPLACING A LINE
	TRZE	FF,ILRFLG
	PUSHJ	P,PUTCHR
	MOVEI	CH,11		; TAB
	PUSHJ	P,P1CHR		; OUTPUT BUFFER
	PUSHJ	P,TYGTLN	; READ IN LINE
	JRST	IFIX		;SPECIAL HANDLING FOR .
	CAILE	SN,^D99999	;GOING OVER LINE 99999?
	JSR	WRP,ERROR	;YES
	CAMLE	SN,SEQLST	;UPDATE SEQLST ?
	MOVEM 	SN,SEQLST	;YES
	TRZE	FF,TFLG		;GOOD RETURN
	PUSHJ	P,DCOM2		; DELETE EXISTING LINE
	AOS	TAC,AC3		; NEW WD COUNT (+1 FOR HEADER)
	CAMLE	TAC,FREWDS	; ROOM?
	PUSHJ	P,ICOM3		; NO
	HRRM	LP,MOV1
	HRRZ	AC1,LP
	ADD	AC1,AC3
	HRRM	AC1,MOV2
	HRRZ	AC2,PNTR
	SUBI	AC2,(LP)
DOMOV1:	XCT	MOV1		;MOVE AC1,(AC2)
DOMOV2:	XCT	MOV2		;MOVEM AC1,(AC2)
	SOJGE	AC2,DOMOV1
	ADDM	AC3,PNTR
	MOVN	TAC,AC3		; UPDATE POINTERS
	ADDM	TAC,FREWDS	; NEW FREE WD NUMBER
	HRL	AC3,SN		;HEADER WORD
	MOVSI	AC4,44000	;TAB
	MOVSI	AC2,(TAC)	;COUNT
	HRRM	LP,M2		;"TO"
	HRRZ	TAC1,TYIBF1	;"FROM"
	HRRM	TAC1,M1
	JRST	DOM2
DOM1:	XCT	M1		;MOVE AC4,(AC2)
	LSHC	AC3,^D28	;4 CHARS
	LSH	AC3,1		;CLEAR BIT 35
DOM2:	XCT	M2		;MOVEM AC3,(AC2)
	LSHC	AC3,^D7
	SOSL	@TYIBF1		;CHECK "REAL" COUNT
	AOBJN	AC2,DOM1
	AOBJN	AC2,DOM1+1	;(IF LAST WORD HAS FIVE CHARS)
	MOVE	AC3,SN		;SAVE PREVIOUS SN
	ADD	SN,STPSIZ	; NEXT LINE
	MOVE	N1,SN		;FOR RDXA
	JRST	ICOM1
ICOM3:	PUSHJ	P,FNLN2A	;OUTPUT AND DELETE
	JRST	FNDLIN		;FIND LOC AGAIN

IFIX:	CAME	N2,SN		;ALLOWS FOR POSSIBILITY OF GIVING AN I
				;COMMAND BUT NOT GIVING ANY DATA
	SUB	SN,STPSIZ
	JRST	CARRET

; SET UP FOR LINE 00010

SET10:	MOVEI	SN,12		;SEQUENCE # = 10
	MOVEI	N1,12		;SAVE COPY FOR FIRST LINE # TYPEOUT
	MOVEI	AC4,"10"
	POPJ	P,
; ROUTINE TO DELETE A LINE (OR LINES)
; FROM TEXT BUFFER
;	N1    ADR  OF FIRST LINE TO DELETE
;	N2    ADR  OF LAST LINE TO DELETE

DCOM:	SKIPE	AC4,N2		;TEST AND SAVE
	CAMGE	N1,N2		;LEGAL ?
	SKIPN	SN,N1		;YES,SET FOR FNDLIN
	JSR	ILC,ERROR
	PUSHJ	P,LPSET		;SET UP LP AND PS
	PUSHJ	P,FNDLIN	;SEARCH (PS CONTAINS SN OF PREVIOUS LINE UPON RETURN)
	JSR	NLN,ERROR
	JUMPE	AC4,DCOM5
	MOVE	SN,AC4
	MOVE	AC4,LP
	HRL	AC4,PS		;SAVE SN OF PREVIOUS LINE
	PUSHJ	P,FDL1A		;FIND 2ND LINE(WON'T ADVANCE PAGE)
	SKIPA			;NOT FOUND
	JRST	DCOM1		;FOUND
	CAMLE	SN,SEQLST	;IN BUFFER?
	JRST	DCOM3		;NO DELETE ALL REST OF BUFFER
	SETZ	TAC,		;YES TEMOVE EXTRANEOUS
;NOW FALL INTO DCOM1
; BASIC ROUTINE TO REMOVE A LINE FROM
; TEXT BUFFER
;  GIVEN:  ADR OF LINE TO REMOVE
;	; # WORDS TO CLEAR
;	C(TAC)=WORD COUNT
;	C(LP)=ADR OF LINE

;AC1 CONTAINS SN OF LINE BEING DELETED

DCOM1:	CAMN	SN,SEQLST
	HLRM	AC4,SEQLST
	ADDI	TAC,(LP)
	SUBI	TAC,(AC4)
	MOVEI	LP,(AC4)
DCOM2:	HRRM	TAC,DCM1	; FROM=TO+WD COUNT
DODCM1:	XCT	DCM1		;HRLI AC1,(LP)
	HRR	AC1,LP		; TO
	HRRZ	AC2,PNTR
	SUBI	AC2,(TAC)	; LAST DEST 
	BLT	AC1,(AC2)	; MOVE
	HRRM	AC2,PNTR
	ADDM	TAC,FREWDS
	POPJ	P,		;RETURN
DCOM3:	HLRM	AC4,SEQLST
	HRRZ	AC1,PNTR	;REST. FIRST FREE
	SUBI	AC1,(AC4)
	HRRM	AC4,PNTR
	SETZM	(AC4)
	ADDM	AC1,FREWDS
DCOM4:	CAMGE	SN,NUM
	JRST	FNLN1A
	PUSHJ	P,MVLIN1
	TLNE	FF,NDFIL
	PUSHJ	P,GETLIN	;LOOK FOR LINE WE WANT
	POPJ 	P,		;NO MORE
	JRST	DCOM4

DCOM5:	CAMN	SN,SEQLST	;LAST SN OF BUFFER ?
	MOVEM	PS,SEQLST
	JRST	DCOM2

; ROUTINE TO PRINT LINES
; WILL ONLY PRINT ONE LINE AT A TIME

PCOM:	SKIPN	SN,N1
	MOVEI	SN,12		;ASSUME 10 IF NONE SPECIFIED
	SKIPN	AC4,N2
	JRST	PCOM11
	CAMLE	N1,N2
	JSR	ILC,ERROR
PCOM11:	PUSHJ	P,LPSET
	PUSHJ	P,FNDLIN	;FIND IT
	JRST	PCOM2		;NOT FOUND
PCOM1:	PUSHJ	P,FNDLIN
	MOVE	SN,AC1
	HLRZ	A,(LP)		;GET SEQ NUM
	JUMPE	A,ENDTTY
	JUMPE	AC4,PCOMC1	;DON'T CHK FOR SINGLE LINES
	CAILE	A,(AC4)		;DON'T TYPE BEYOND (N2)
	JRST	ENDTTY
PCOMC1:	MOVEI	TAC,5
	CAML	TAC,TYOBF2
	PUSHJ	P,ENDTTY	;OUTPUT BUFFER
	MOVE	TAC1,TYOBF1
	PUSHJ	P,RDX1		;CONVERT & OUTPUT
	MOVEM	TAC1,TYOBF1	;FIX UP HDR POINTER
	MOVNI	TAC,5
	ADDM	TAC,TYOBF2
	HRRI	TAC1,1(LP)
	HRLI	TAC1,440700	;FORM BP
	ILDB	CH,TAC1
	PUSHJ	P,PUTCHR
	CAIG	CH,14
	CAIG	CH,11
	JRST	.-4
	CAML	SN,AC4
	JRST	ENDTTY
	AOJA	SN,PCOM1

PDCOM:	SETZI	AC4,
	TLNN	FF,NFILE	;CREATING?
	CAILE	SN,1		;AND NOTHING IN YET?
	JRST	PCOM1		;NO, PROCEED
	JRST	CARRET		;YES, NOTHING TO DO

PCOM2:	HLRZ	SN,(LP)		;START AT NEXT LINE ABOVE (N1)
	JUMPN	SN,PCOM1	;THERE ISN'T ANY
	JSR	NLN,ERROR
; BUFFER STRUCTURE
; TEXT IS STORED LINE BY LINE IN A SEQUENTIAL MANNER
; THE CONTENTS OF THE FIRST WORD OF LINE ARE AS FOLLOWS:
;   C(LH)= SEQUENCE NUM (BIN)
;   C(RH)= NUMBER OF WORDS
;     IN LINE (INCLUDING HDR WORD)
;		C(HEADER)=0 INDICATES END OF BUFFER

; LINE SEARCH ROUTINE
; GIVEN
;    ADR OF BEG. OF SEARCH IN LP
;    SEQ.NUMBER SOUGHT IN SN

; RETURN
;    A) FOUND: VIA A JRST CPOPJ1
;        LP CONTAINS ADR OF LINE
;        TAC CONTAINS WORD COUNT OF LINE
;        SN CONTAINS SEQ. NUM.

;    B) NOT FOUND - VIA A POPJ,
;       AS ABOVE EXCEPT LP CONTAINS  ADR OF THE FIRST LINE WITH
;       A SEQUENCE NUMBER HIGHER  THAN THE ONE SOUGHT

; A GENERAL ROUTINE TO 
; FIND A LINE AT ITS APPROXIMATE LOCATION
; UPON RETURN:
;	LP CONTAINS LOCATION
;	TAC CONTAINS WORD COUNT

; CALLED WITH SEQ. NUM. IN SN

FDL1A:	TRO	FF,FILFLG
FNDLIN:	PUSHJ	P,QKCHEK	;CHECK LIMITS
	TLNN	FF,NDFIL	;VIRGIN FILE ??
	JRST	LNSRCH		;FIND EXACT LOC.
				;AND RETURN
FNDLN1:	PUSHJ	P,GETLIN	;GET WD COUNT
	JRST 	LNSRCH
FNLN1A:	CAMLE	TAC,FREWDS	;ROOM?
	PUSHJ	P,FNDLN2	;NO - OUTPUT
FNDLNA:	HRL	AC1,TAC1	;FROM
	HRR	AC1,PNTR
	PUSHJ	P,MOVLIN	;MOVE IT
	HRRM	TAC1,PNTR
	SETZM	(TAC1)
	MOVN	AC1,TAC
	ADDM	AC1,FREWDS
	MOVEM	NUM,SEQLST
	CAMG	SN,NUM		;THE ONE WE WANT?
	JRST	LSCHLP		;YES
	JRST	FNDLN1		;NO
; HERE WE OUTPUT AN ARBITRARY # OF
; LINES & THEN DELETE THEM

FNDLN2:	TRZE	FF,FILFLG
	JRST	TPOPJ
FNLN2A:	SETZI	AC2,		;ZERO AC2
	PUSH	P,TAC1		;SAVE COUNT
	PUSH	P,TAC		;SAVE ADR
	HLRZ	TAC1,PNTR
FNDLN3:	PUSHJ	P,OUTLIN
	ADD	AC2,TAC
	ADD	TAC1,TAC
	CAML	AC2,(P)		;BIG ENOUGH HOLE ?
	CAMGE	AC2,OUTWRD	;OUTPUT ENOUGH?
	JRST	FNDLN3		;NO
	MOVE	TAC,AC2		;YES - FOR DCOM
	HLRZ	LP,PNTR
	PUSHJ	P,DCOM2		;DELETE OUTPUT
	POP	P,TAC
TPOPJ:	POP	P,TAC1
	POPJ	P,

;	LP - ADR OF LINE
;	SN - NUMBER WANTED
; C(RH)	TAC - WD COUNT
;	AC1 - SCRATCH - CONTAINS NEW SEQ.# ON RETURN

LSCHLP:	PUSHJ	P,LPSET
LNSRCH:	SKIPN	TAC,(LP)	;GET & CHECK
	POPJ	P,		;"VIRGIN" FILE RETURN
	HLRZ	AC1,TAC		;SEQ.#
	CAMN	SN,AC1		;CHECK IT
	AOSA	(P)		;FOUND
	CAMG	SN,AC1
	JRST	CLRTAC
	ADDI	LP,(TAC)	;UPDATE
	HRRZ	PS,AC1
	JRST	LNSRCH		;AROUND AGAIN
CLRTAC:	HRRZS	TAC
	POPJ	P,
; QUICK CHECK ROUTINE TO DETERMINE WHETHER A LINE WITH SN
;	 LIES WITHIN THE BUFFER.

;	POPJ	P,		;PAST END
;	JRST	CPOPJ1		;O.K.
; ALSO AN EXIT FOR BEFORE BUFFER
; CALL WITH SN SET

QKCHEK:	CAMG	SN,WRTLST	;LAST WRITTEN
	PUSHJ	P,GORND
	CAMG	SN,SEQLST	;PAST END
CPOPJ1:	AOS	(P)		;O.K.
CPOPJ:	POPJ	P,		;RETURN

; SET LINE POINTER & PREVIOUS SEQUENCE #

LPSET:	MOVE	PS,SEQLST	;INIT PREV SEQ# = HIGHEST IN CURRENT BUFFER
	HLRZ	LP,PNTR		;INIT CUR LINE PTR = FIRST FREE LOC IN BUFR
	POPJ	P,


GORND:	TRNN	FF,FILFLG
	JRST	.+3
	POP	P,CH
	JRST	CPOPJ
	PUSH	P,SN
	PUSH	P,AC4
	MOVEM	P,PSAVE
	TLO	FF,ROUND
	PUSHJ	P,CLOSE0
GORND1:	MOVE	P,PSAVE
	MOVEI	CH,015
	PUSHJ	P,ARWOLD
	TLZ	FF,ROUND
	PUSHJ	P,LPSET
	POP	P,AC4
	POP	P,SN
	POPJ	P,
; TELETYPE I/O ROUTINES

; BASIC TTY INPUT
; (NON-CCL VERSION)
; ENTER AT GETCHR TO READ CHARS FROM NORMAL LINES
; ENTER AT GETCH1 TO READ A CHAR FROM AN UNTERMINATED LINE

IFE CCLSW,<
GETCHR:	SOSGE	TYIBF2		;INPUT WHEN BUF CTR GOES .LT. 0
GETCH1:	INPUT	ETTY,0
	ILDB	CH,TYIBF1	;GET A 7-BIT CHAR FROM BUF
	JUMPE	CH,GETCHR	;IGNORE NULL CHARS
	POPJ	P,
	>

; BASIC TTY INPUT
; (CCL VERSION)
; ENTER AT GETCHR TO READ CHARS FROM NORMAL LINES
; ENTER AT GETCH1 TO READ A CHAR FROM AN UNTERMINED LINE

IFN CCLSW,<
GETCHR:	TLNE	FF,CCLF		;NORMAL OR CCL MODE?
	JRST	CCLCHR		;READ CCLBF
	JRST	TTYCHR		;READ TYIBF

GETCH1:	TLNE	FF,CCLF
	JRST	CCLCHR
	JRST	TTYCH1		;READ CHAR FROM UNFINISHED LINE

; READ TYIBF

TTYCHR:	SOSGE	TYIBF2		;INPUT WHEN BUF CTR GOES .LT. 0
TTYCH1:	INPUT	ETTY,
	ILDB	CH,TYIBF1	;GET 7-BIT CHAR FROM BUF
	JUMPE	CH,TTYCHR	;IGNORE NULL CHARS
	CAIN	CH,032		;IGNORE ^Z
	JRST	TTYCHR
TTYCH2:	CAIE	CH,176		;CHANGE OLD ALTMODES TO NEW FORM
	CAIN	CH,175
	MOVEI	CH,033
	CAIL	CH,140		;CONVERT LOWER CASE TO UPPER
	TRZ	CH,040
	POPJ	P,
; READ CCLBF

CCLCHR:	SOSGE	CCLBF2		;INPUT WHEN BUF CTR GOES .LT. 0
CCLCH1:	PUSHJ	P,[IFN TEMP,<
		SKIPE TMPFLG	;IS TMPCOR UUO IN PROGRESS?
		CALLI 12	;YES, EXIT
		>
		IN CCLC,	;INPUT ON CCL CHANNEL
		POPJ P,		;NORMAL RET
		JSR CCL,ERROR]	;ERROR RET
	ILDB	CH,CCLBF1	;GET 7-BIT CHAR FROM BUF
	JUMPE	CH,CCLCHR	;IGNORE  NULL CHARS
	CAIN	CH,032		;IGNORE ^Z
	JRST	CCLCHR
	JRST	TTYCH2		;FINISH CLEAN-UP AND RETURN
	>


; READ LINE ON TTY & CHECK TERMINATING CHARACTER
; CALL:	PUSHJ P,TYGTLN
;	ALTMODE RETURN
;	NORMAL RETURN

TYGTLN:	INPUT	ETTY,0		;GET LINE
	TRZ	FF,EOL		;CLR EOL FLAG
	MOVE    AC1,TYIBF1	;AIM BYTE PTR AT LINE HEADER
	ADD	AC1,(AC1)	;ADD WORD CT FOR THE LINE
	SOS	AC1		;ADJUST PTR TO LAST WORD OF THE LINE
TYG1:	ILDB	CH,AC1		;GET A 7-BIT CHAR FROM LAST WORD
	CAIN	CH,33
	POPJ	P,
	CAIE	CH,175		;IF ALTMODE, SET TO 033 & RET VIA POPJ
	CAIN	CH,176
	JRST	CON033
	CAIG	CH,14		;EOL SEEN?
	CAIG	CH,11
	SKIPA			;NOT YET
	TRO	FF,EOL		;YES
	TLNE	AC1,700000	;WATCH FOR END OF WORD
	JRST	TYG1		;NOT YET, TRY NEXT CHAR
	TRZN	FF,EOL		;END-OF-LINE SEEN?
	JSR	LTL,ERROR	;NO, LINE TOO LONG
	MOVE	AC3,@TYIBF1	;GET WD COUNT FOR THE LINE
	CAIG	CH,14
	CAIG	CH,11
	JRST	CPOPJ1		;INCREMENT RET PTR & POPJ
	AOJA	AC3,CPOPJ1	;EXCEPT IF LAST CHAR IS LF, VT, FF ALSO INCR WD CT
; BASIC TTY OUTPUT

PUTCHR:	SOSG	TYOBF2		;OUTPUT WHEN BUF CTR GOES TO 0
PUTCH1:	OUTPUT	ETTY,0
	SKIPE	CH		;AVOID NULL OUTPUT
	IDPB	CH,TYOBF1	;STORE NEW 7-BIT CHAR IN BUF
	POPJ	P,

; SINGLE CHARACTER TTY OUTPUT

ASKOUT:	MOVEI	CH,"*"		;TYPE ASTERISK
P1CHR:	PUSHJ	P,PUTCHR	;SENT CH TO TYOBF
ENDTTY:	OUTPUT	ETTY,0		;FORCE OUTPUT
	POPJ	P,

; TTY MESSAGE OUTPUT
;CALL	PUSHJ	P,MESSAG
;	ASCIZ	/MESSAGE/
;	RETURN

MESSAG:	MOVSI	TAC,(POINT 7,0)	;INIT BYTE PTR WITHOUT ADDR
	HRR	TAC,(P)		;NOW THE ADDRESS
MESS2:	ILDB	CH,TAC		;GET CHAR.
	JUMPE	CH,MESSGO	;QUIT AT THE 0
	PUSHJ	P,PUTCHR	;PRINT
	JRST	MESS2		;GET NEXT
MESSGO:	AOS	TAC		;FIX UP PDL FOR PROPER RETURN
	HRRM	TAC,(P)
	POPJ	P,
ARWCOM:	TLZE	FF,FILACT
	JRST	CLOSE0
	SETZM	IFILNM
	SETZM	IFILXT
	PUSHJ	P,FILNAM
	SKIPN	IFILNM
	JSR	ILC,ERROR
	MOVE	TAC1,IFILNM
	MOVEM	TAC1,ZILCH
	CAIN	CH,"."
	PUSHJ	P,FILEXT
	TLZ	FF,NFILE!NDFIL
ARWOLD:	PUSHJ	P,SETUP
	CAIN	CH,ALTMOD
	JRST	INITO
TRZFFE:	TRZ	FF,ER
	HLRZ	TAC,IDIRC+1	;CHECK EXTENSION
	CAIN	TAC,(SIXBIT /BAK/)
	JSR	BAK,ERROR	;CAN'T EDIT .BAK FILE
	INIT	EICHL,EMDE
	SIXBIT	/DSK/
	EXP	EDIBF
	PUSHJ	P,UNA		;NO DISK???
	TLO	FF,NFILE!NDFIL
	LOOKUP	EICHL,IDIRC
	JSR	NCF,ERROR
	LDB	TAC,[POINT 9,IDIRC+2,8]	;GET PROTECTION OF INPUT FILE
	MOVEM	TAC,PROTEC
	INBUF	EICHL,2
INITO:	TRZ	FF,ER
	INIT	EOCHL,EMDE
	SIXBIT	/DSK/
	XWD	EDOBF,0
	PUSHJ	P,UNA		;NO DISK
	TLNN	FF,NFILE
	PUSHJ	P,[	LOOKUP EOCHL,IDIRC
			POPJ P,
			JSR FAU,ERROR]
	TRZ	FF,ER
	ENTER	EOCHL,ODIRC
	PUSHJ	P,UNA		;CANT ENTER???
EOBUF:	OUTBUF	EOCHL,2
	PUSHJ	P,EWRITE	;SET UP HEADER
	TLO	FF,FILACT
DOFIL1:	XCT	FILL1		;MOVEI TAC,.
	MOVEM	TAC,FREWDS
DOFIL2:	XCT	FILL2		;HRRZI TAC,.
	HRRZM	TAC,PNTR
	HRLS	PNTR
	SETZM	(TAC)
	MOVEI	TAC,12
	TLNN	FF,ROUND
	MOVEM	TAC,STPSIZ
	SETZM	WRTLST
	SETZM	SEQLST
	TLNE	FF,NFILE
	POPJ	P,
CARRET:	PUSHJ	P,MESSAG
	ASCIZ	/
/
	JRST	ENDTTY

;DISK INITIALIZATION OR ENTER ERROR

UNA:	TRON	FF,ER		;TRIED TWICE?
	JRST	UNA2		;NO
	PUSHJ	P,MESSAG	;YES, DIAGNOSTIC
	ASCIZ	/
?CANNOT ACCESS DISK/
	JRST	EREXIT		;FATAL CONDITION

;UUO ERROR RETRY ROUTINE
;ASSUMES TRZ FF,ER PRECEDES THE UUO
;IT SHOULD ANYWAY BECAUSE AN EARLIER
;UUO MAY SUCCEED ON THE SECOND TRY

UNA2:	MOVNI	TAC,3		;TO TRY AGAIN BACK UP RETURN POINTER
	ADDM	TAC,(P)
	SETZ	TAC1,
	MOVE	TAC,@(P)	;LOOK FOR THE TRZ FF,ER
	CAMN	TAC,TRZFFE	;IF NO, WE WERE ON AN INIT
	MOVEI	TAC1,2		;YES, WE WERE ON A LOOKUP OR RENAME
	SUBI	TAC1,1		;MOVE POINTER TO THE ACTUAL UUO
	ADDM	TAC1,(P)	;-1 IN CASE OF INIT, +1 IN CASE OF LOOKUP
	POPJ	P,
CLOSE0:	SKIPN	IFILNM
	JSR	ILC,ERROR
	MOVEI	SN,^D10		;FIND SOMETHING
	PUSHJ	P,LPSET
	MOVEI	SN,^D99999
	PUSHJ	P,FNDLIN
	HRRZ	TAC,FILL1
	PUSHJ	P,FNLN2A
CLOSE1:	RELEASE	EICHL,0
	RELEASE	EOCHL,0
	TRZ	FF,ER
	INIT	EICHL,0
	SIXBIT	/DSK/
	0
	PUSHJ	P,ERA1		;CANT
	LOOKUP	EICHL,IDIRC
	JRST	CLOSE2
	CLOSE	EICHL,0
	MOVE	TAC,PROTEC	;KEEP SAME PROT. ON TMP.TMP
	DPB	TAC,[POINT 9,ZDIRC+2,8]
	LDB	TAC,[POINT 23,IDIRC+2,35]
	DPB	TAC,[POINT 23,ZDIRC+2,35]	;SAVE CREATION DATE
	LDB	TAC,[POINT 3,IDIRC+1,20]	;GET HIGH PART OF DATE
	DPB	TAC,[POINT 3,ZDIRC+1,20]	;AND SAVE IT
	TRZ	FF,ER
	RENAME	EICHL,ZDIRC
	PUSHJ	P,ERA1		;CANT
CLOSE2:	TRZ	FF,ER
	INIT	EOCHL,0
	SIXBIT	/DSK/
	0
	PUSHJ	P,ERA2		;CANT
	TRZ	FF,ER
	LOOKUP	EOCHL,ODIRC
	PUSHJ	P,ERA2		;CANT
	CLOSE	EOCHL,0
	LDB	TAC,[POINT 9,ODIRC+2,8]	;STD PROT FOR NEW FOO IF CREATING
	TLNE	FF,NFILE	;SKIP IF CREATING
	MOVE	TAC,PROTEC	;NEW FOO GETS SAME PROTECTION AS OLD FOO
	DPB	TAC,[POINT 9,IDIRC+2,8]	; OR STANDARD IF NO INPUT FILE
	LDB	TAC,[POINT 23,ODIRC+2,35]
	DPB	TAC,[POINT 23,IDIRC+2,35]	;SAVE CREATION DATE
	LDB	TAC,[POINT 3,ODIRC+1,20]	;GET HIGH PART OF DATE
	DPB	TAC,[POINT 3,IDIRC+1,20]	;AND SAVE IT
	TRZ	FF,ER
	RENAME	EOCHL,IDIRC
	PUSHJ	P,ERA2		;CANT
	TRZ	FF,ER
	INIT	EICHL,0
	SIXBIT	/DSK/
	0
	PUSHJ	P,ERA3		;CANT
	LOOKUP	EICHL,ZILCH
	JRST	CLOSE3
	CLOSE	EICHL,0
	TRZ	FF,ER
	RENAME	EICHL,DELDIR	;THIS AVOIDS A RENAME ERROR WITH .BAK
	PUSHJ	P,ERA3		;CANT
CLOSE3:	TRZ	FF,ER
	INIT	EICHL,0
	SIXBIT	/DSK/
	0
	PUSHJ	P,ERA3		;CANT
	LOOKUP	EICHL,ZDIRC
	JRST	NOIFIL
	CLOSE	EICHL,0
	MOVE	TAC,PROTEC	;FOO.BAK GETS SAME PROTECTION AS FOO
	DPB	TAC,[POINT 9,ZILCH+2,8]
	LDB	TAC,[POINT 23,ZDIRC+2,35]
	DPB	TAC,[POINT 23,ZILCH+2,35]
	LDB	TAC,[POINT 3,ZDIRC+1,20]	;GET HIGH PART OF DATE
	DPB	TAC,[POINT 3,ZILCH+1,20]	;AND SAVE IT
	TRZ	FF,ER
	RENAME	EICHL,ZILCH
	PUSHJ	P,ERA3		;CANT
NOIFIL:	RELEASE	EICHL,0
	RELEASE	EOCHL,0
	TLNE	FF,ROUND
	JRST	GORND1
	SETZM	IFILNM
	SETZM	IFILXT
	JRST	COMCLR
;ERROR IN RENAME PROCESS

ERA1:	MOVE	AC1,[POINT 6,IDIRC]
	JRST	ERA4
ERA2:	MOVE	AC1,[POINT 6,ZDIRC]
ERA4:	MOVE	AC2,[POINT 6,ODIRC]
	JRST	ERA
ERA3:	MOVE	AC1,[POINT 6,ZDIRC]
	MOVE	AC2,[POINT 6,IDIRC]
ERA:	TRON	FF,ER		;TRIED TWICE?
	JRST	UNA2		;NO, TRY AGAIN
	PUSHJ	P,MESSAG	;YES, PRINT DIAGNOSTIC
	ASCIZ	/
?ERROR IN RENAME PROCESS.
INPUT FILE CLOSED WITH NAME /
	PUSHJ	P,MES61		;INPUT FILE NAME
	PUSHJ	P,MESSAG
	ASCIZ	/
OUTPUT FILE CLOSED WITH NAME /
	PUSHJ	P,MES62		;OUTPUT FILE NAME
	JRST	EREXIT

;6-BIT FILNAM.EXT PRINTOUT

MES62:	MOVE	AC1,AC2		;SWITCH TO OUTPUT FILE NAME POINTER
MES61:	MOVEI	TAC,11		;NAME CHAR. CTR
MES60:	ILDB	CH,AC1
	ADDI	CH,40		;CHANGE 6-BIT TO ASCII
	PUSHJ	P,PUTCHR
	CAIN	TAC,4
	PUSHJ	P,DOTOUT
	SOJN	TAC,MES60
	POPJ	P,
DOTOUT:	MOVEI	CH,"."
	JRST	PUTCHR
; A ROUTINE TO RETURN A DESCRIPTOR. RETURNS WITH
; FIRST NON LEGAL CHAR IN AC CH. NAME (IN SIXBIT) WILL
; BE IN AC TAC UPON RETURN.

FILNAM:	SKIPA	TAC1,[POINT 6,IFILNM]
FILEXT:	MOVE	TAC1,[POINT 6,IFILXT]
	JRST	SXNAM2
SXNAM1:	SUBI	CH,40
	TLNE	TAC1,770000	;FULL ?
	IDPB	CH,TAC1		;STASH
SXNAM2:	PUSHJ	P,GETCHR	;GET
	CAIN	CH," "		;SPACE ?
	JRST	.-2
	CAIL	CH,60
	CAILE	CH,"Z"
	POPJ	P,
	CAILE	CH,"9"
	CAIL	CH,101
	JRST	SXNAM1
	POPJ	P,

	
; ROUTINE TO MOVE LINE, FIX UP COUNT & POINTER (OF HEADER)
;    C(TAC1) = (FROM) TO
;    C(TAC)   = WD COUNT

MOVLIN:	MOVE	TAC1,TAC
	ADDI	TAC1,(AC1)
	BLT	AC1,-1(TAC1)
MVLIN1:	MOVN	N1,TAC
	ADDM	N1,EDIBF2
	ADDM	TAC,EDIBF1
	POPJ	P,

;GETLIN ROUTINE

GETLIN:	HRRZ	TAC1,EDIBF1
	SKIPLE	N1,EDIBF2
	SKIPN	(TAC1)
	JRST	EDREAD
LNCNT:	MOVEI	TAC,1
	HRRM	TAC1,LNCNT1
DOLNCT:	XCT	LNCNT1		;SKIPE AC1,(TAC)
	TRNE	AC1,1
	JRST	.+2
	AOJA	TAC,.-3
	CAMLE	TAC,N1
	MOVE	TAC,N1
	PUSHJ	P,NUMCON
	HRRM	TAC,(TAC1)
	JRST	CPOPJ1

EDREAD:	INPUT	EICHL,0
	AOS	EDIBF1
	STATO	EICHL,760000
	JRST	GETLIN
	STATZ	EICHL,20000
	JRST	EOF
	TLZ	FF,FILACT
	JRST	INERR		;INPUT ERROR
EOF:	TLZ	FF,NDFIL
	POPJ	P,		;"NO MORE" RETURN

INERR:	PUSHJ	P,MESSAG
	ASCIZ	/
?IN/
	JRST	PUTERR
OUTERR:	PUSHJ	P,MESSAG
	ASCIZ	/
?OUT/
PUTERR:	PUSHJ	P,MESSAG
	ASCIZ	/PUT ERROR.
INCOMPLETE OUTPUT FILE CLOSED WITH NAME /
	MOVE	AC1,[POINT 6,ODIRC]	;FILE NAME
	PUSHJ	P,MES61
EREXIT:	PUSHJ	P,ENDTTY	;QUIT & LET USER DECIDE WHAT TO DO
	RELEAS	EOCHL,0
	RELEAS	EICHL,0
	CALLI	EXIT
; OUTPUT
; GIVEN
; ADR OF LINE IN TAC1
; ACTION
; GET WORD COUNT
; CONVERT SEQ.# TO ASCII


OUTLIN:	SKIPN	(TAC1)		;END OF BUFFER
	JRST 	CLOSE1		;YES (END OF FILE)
	HRRZ	TAC, (TAC1)	; GET COUNT
	CAMLE	TAC,OC		; ROOM?
	PUSHJ	P,EWRITE	; NO
	SUB	OC,TAC		; UPDATE COUNT
	HLRZ	A,(TAC1)	; SEQ. NUM.
	MOVEM	A,WRTLST
	PUSHJ	P,RDX		; CONVERT SEQ #  TO ASCII
	HRL	AC1,TAC1	; FROM
	HRR	AC1,EDOBF1	; TO
	HRRM	AC1,OUTLN1	; END
	AOS	AC1
DOUTL1:	XCT	OUTLN1		;BLT AC1,(TAC)
	ADDM	TAC,EDOBF1	; NEW LCN
	POPJ	P,
EWRITE:	OUTPUT	EOCHL,0
	STATZ	EOCHL,740000
	JRST	OUTERR		;OUTPUT ERROR
	HRRZ	OC,EDOBF2
	POPJ	P,

; ASCII CHAR TO BIN NUMBER CONVERSION ROUTINE (NUMBER IS DECIMAL)
;	PUSHJ	P,NUMCON
; WHERE
;	CH - CONTAINS CHAR. TO BE CONV.
;	NUM - CONTAINS BIN NUM. UPON RETURN

NCHCON:	IMULI	NUM,12		; DECIMAL
	ADDI	NUM,-60(CH)
	POPJ	P,

; TO CONVERT 5 CHAR 7 BIT ASCII
; TO A BINARY NUMBER
NUMCON:	SETZI	NUM,
	HRLI	TAC1,440700
	ILDB	CH,TAC1
	PUSHJ	P,NCHCON
	TLNE	TAC1,700000	; FINISHED
	JRST	NUMCON+2	; NO
	HRLM	NUM, (TAC1)	; YES
	POPJ	P,		; RETURN
; SUBROUTINE TO INITIALIZE PROGRAM

SETUP:	MOVE	TAC1,SVJBFF
	MOVEM	TAC1,.JBFF
	MOVE	AC3,.JBREL##
	MOVEI	AC2,407*2
	ADD	TAC1,AC2
	HRRM	TAC1,FILL2	;FIRST FREE LOC
	SUB	AC3,TAC1
	HRRM	AC3,FILL1	;# FREE WORDS
	IDIVI	AC3,^D10
	MOVEM	AC3,OUTWRD
IFE CCLSW,<
	POPJ	P,
	>
IFN CCLSW,<
	TLNE	FF,ROUND
	POPJ	P,
	TLZN	FF,CCLF
	POPJ	P,
	SETZM	CCLDIR
IFN TEMP,<
	SKIPE	TMPFLG		;IS A TMPCOR UUO IN PROGRESS
	POPJ	P,		;YES, DON'T TRY A RENAME
	>
	RENAME	CCLC,CCLDIR
	JSR	CCL,ERROR
	POPJ	P,

CCLHR2:
IFN TEMP,<
	HRRZ	TAC,.JBFF	;READ DATA INTO A BUFFER AT .JBFF
	HRRM	TAC,TMPFIL+1	;STORE IN TMPCOR READ BLOCK
	HRLI	TAC,440700	;DUMMY UP BYTE POINTER
	MOVEM	TAC,CCLBF1	;IN BUFFER HEADER
	SOS	TMPFIL+1	;GET PROPER IOWD FORMAT
	MOVE	TAC,[XWD 2,TMPFIL]
	CALLI	TAC,TMPCOR	;READ AND DELETE EDT FILE FROM CORE
	JRST	TMPEND		;FILE NOT FOUND, TRY DISK
	ADD	TAC,.JBFF	;CALCULATE END OF BUFFER
	MOVEM	TAC,SVJBFF	;SAVE NEW .JBFF
	SUB	TAC,.JBFF
	IMULI	TAC,5		;CALCULATE CHARACTER COUNT
	MOVEM	TAC,CCLBF2	;FINISH DUMMYING HEADER
	SETOM	TMPFLG		;MARK THAT A TMPCOR UUO WAS USED
	JRST	@CCLHRE		;RETURN

TMPEND:	>
	INIT	CCLC,0
	SIXBIT/DSK/
	XWD	0,CCLBF
	JSR	CCL,ERROR
	SETZM	CCLDIR+3
	LOOKUP	CCLC,CCLDIR
	JSR	CCL,ERROR
	MOVE	TAC,.JBFF
	MOVEM	TAC,SVJBFF
	INBUF	CCLC,1
	JRST	@CCLHRE
	>
; BIN TO BCD CONVERSION ROUTINE
; ADAPTED FROM ANY RADIX PRINT IN MANUAL F-64PX  (8/64)

; A CALL TO THIS ROUTINE WILL CONVERT A BINARY SEQ. 
; NUMBER TO A  5 CHAR ASCII WORD WITH HEADING ZEROS

; CALL
;	PUSHJ	P,RDX
; WHERE TAC1 CONTAINS ADR FOR RESULT
; A CONTAINS BINARY # TO BE CONVERTED

A=N1
A1=A+1

RDX:	SETOM	(TAC1)		; SET SN BIT
RDXA:	HRLI	TAC1,440700	; FORM POINTER
RDX1:	MOVEI	AC1,5		; 5 DIGITS
RADIX:	IDIVI	A,12		; RADIX IS DECIMAL
	HRLM	A1,(P)		; SAVE REMAINDER
	SOSE	AC1		; FINISHED
	PUSHJ	P,RADIX		; NO
	HLRZ	A,(P)
	ADDI	A,60		; FORM ASCII
	IDPB	A,TAC1		; DEPOSIT IN WORD
	POPJ	P,		; RETURN SOMEPLACE

; ERROR ROUTINE
; DECIPHERS ERROR # AND PRINTS  MESSAGE

ERROR2:	TLZ	FF,CCLF		;CLEAR CCL FLAG SO LOOPING DOES NOT OCCUR
	SOS	ERROR
	LDB	TAC,EPNT1	; GET ERR #
	MOVE	TAC,EMT(TAC)
ERROR4:	ILDB	CH,TAC		; GET CHAR
	JUMPE	CH,ERROR3
	PUSHJ	P,PUTCHR	; TO BUFFER
	JRST	ERROR4
ERROR3:	PUSHJ	P,ENDTTY	; OUTPUT WORD
	JRST	COMCLR		; NEXT COMMAND

EPNT1:	POINT	4,@ERROR,12

NOCORE:	TTCALL	3,NOCOR
	CALLI	EXIT

NOCOR:	ASCIZ	/
?NO CORE AVAILABLE FOR DATA SEGMENT/
;ERROR MESSAGE NUMBERS

NFO==0
ILC==1
NLN==2
CCL==3
NCF==4
FAU==5
WRP==6
LTL==7
BAK==10

;ERROR MESSAGE ADDRESS TABLE

EMT:	POINT	7,EMNFO
	POINT	7,EMILC
	POINT	7,EMNLN
	POINT	7,EMCCL
	POINT	7,EMNCF
	POINT	7,EMFAU
	POINT	7,EMWRP
	POINT	7,EMLTL
	POINT	7,EMBAK

;ERROR MESSAGES

EMNFO:	ASCIZ	/?FILE NOT SPECIFIED
/
EMILC:	ASCIZ	/?ILLEGAL COMMAND
/
EMNLN:	ASCIZ	/?LINE REFERENCED DOES NOT EXIST
/
EMCCL:	ASCIZ	/?SYSTEM ERROR READING COMMAND FILE
/
EMNCF:	ASCIZ	/?INPUT FILE NOT FOUND
/
EMFAU:	ASCIZ	/
?FILE NAME ALREADY IN USE
/
EMWRP:	ASCIZ	/?CANNOT INSERT ABOVE LINE 99999
/
EMLTL:	ASCIZ	/?LINE TOO LONG
/
EMBAK:	ASCIZ	/?CANNOT EDIT BACKUP FILE
/

	LIT
PATCH:
IFN PURE,<RELOC>

DATA:
; I/O DATA
; MACRO TO SET UP HEADERS ETC.

DEFINE AREA (A,N)
<SEQ (A,N,0123456789)
>
DEFINE SEQ (A,N,NUM,%K)
<%K=0
IRPC	NUM,
<IFG	N-%K,
<IFE	%K,
<	A:	BLOCK 1
>
IFN	%K,
<	A'NUM:	BLOCK 1
>>
%K=%K+1
>
>

AREA	(TYIBF,3)
AREA	(EDOBF,3)
AREA	(EDIBF,3)
REPEAT 0,<
AREA	(EDRCO,4)
AREA	(EDRCI,4)
>
AREA	(TYOBF,3)

; STORAGE

ERROR:	BLOCK	1		; FOR JSR AC,ADR
ERROR1:	BLOCK	1		;JRST ERROR2
FILL1:	BLOCK	1
FILL2:	BLOCK	2
MOV1:	BLOCK	1
MOV2:	BLOCK	1
M1:	BLOCK	1
M2:	BLOCK	1
DCM1:	BLOCK	1
LNCNT1:	BLOCK	1
OUTLN1:	BLOCK	1
IFN CCLSW,<
CCLHRE:	BLOCK 1
CCLHR3:	BLOCK	1
IFN TEMP,<
TMPFIL:	BLOCK 1		;SIXBIT /EDT/
	BLOCK	1		;XWD -200,0
TMPFLG:	BLOCK	1
	>>
PSAVE:	BLOCK	1
FREWDS:	BLOCK	1		; NUMBER OF FREE WDS
PNTR:	BLOCK	1		;LH-FIRST FREE
			;RH-ADDR OF LAST HEADER
WRTLST:	BLOCK	1		; SN LAST WRITTEN
STPSIZ:	BLOCK	1		; STEP SIZE FOR INSERT
SVJBFF:	BLOCK	1		; STORAGE
PROTEC:	BLOCK	1		;SAVE PROTECTION FOR OUTPUT FILE
OUTWRD:	BLOCK	1
SEQLST:	BLOCK	1		;LAST SN IN CURRENT PAGE BUFFER

IFILNM:
IDIRC:	BLOCK	1
IFILXT:	BLOCK	3

OFILNM:
ODIRC:	BLOCK	1		;SIXBIT	/###LIN/
	BLOCK	1		;SIXBIT	/TMP/
	BLOCK	2


PDSIZ=^D25
PDSIZ1=PDSIZ+1
PDL:	BLOCK	PDSIZ


IFN CCLSW,<
	AREA	(CCLBF,3)	


CCLDIR:	BLOCK	1		;SIXBIT/###EDT/
	BLOCK	1		;SIXBIT/TMP/
	BLOCK	2
	>
ZDIRC:	BLOCK	1		;SIXBIT	/###TMP/
	BLOCK	1		;SIXBIT	/TMP/
	BLOCK	2
ZILCH:	BLOCK	1
	BLOCK	1		;SIXBIT /BAK/
	BLOCK	2

DELDIR:	BLOCK	4

DSKST:	BLOCK	1000		;FORCE INTO 2K
ENDP: END START