/9 TECO INITIALIZATION MODULE

/ 08-APR-79	PASS INITIAL COMMAND TO TECO.INI IN Q-REGISTER Z
/		DON'T NEED SYS WRITE ENABLED ON STARTUP
/		FIXED BUG HAVING TO DO WITH / IN 8K
/		FIX -3EJ COMMAND IN 12K
/ 10-APR-79	CONDITIONALIZED IN EXTENDED MATCH CONTROL INITIALIZATION

	.ENABLE 7BIT

	MTWO=CLL STA RAL

	.GLOBAL ERR30,TECO35,TCINIT,JTECO
	.GLOBAL CDF4A,CDF4B,CDF4C,TWLVKP,VT05C,VT52D
	.EXTERNAL XERBAS,IOVRLC,QOVRLC,ERRXX,ERRYY
	.EXTERNAL QPUTS,GETQX,ASR33,QSIZE
	.ZTERNAL MQ,CACR,XR,INXR,Z377,QP,SCHAR
	.EXTERNAL NWRUSR,MQMAX,COLCT,CHKCTC
	.EXTERNAL INHNDL,PUTT,L16K
	.EXTERNAL Q12MAX,QLIMIT,KSFWT,DISPLY,TSFWT,VT52B,TYI1,CHTECO
	.ZTERNAL QZ,MEMSIZ
	.EXTERNAL SCAPE,EUFLAG,ETFLAG,EU1,EU2,INRSIZ,INCTLW,INPCNT
	.EXTERNAL I2,IC,J12K1,J12K2,L12K1,L12K2,OUTSIZ,BUFIN
	.EXTERNAL T0A,TECO1,HLPADR,TECOS,QPUT,POUTHT,SCPBIT,RUBY
	.ZTERNAL TEMPT
	.EXTERNAL SCOPY,BLSP1,BLSP2,BLSP3,BLSP4,TYPE,QPNTR
	.EXTERNAL CDSP,CHR.W,C.W,INHNDL,OUHNDL,SRHLEN,MEMLOC,NEWERR
	.EXTERNAL OVREAD
	.ZTERNAL Z7400,Z4,Z40,Z200
	.EXTERNAL	CORTST

	JSBITS=7746
	XTNDED=0	/NO EXTENDED MATCH CONTROL
	.ASECT TECINI

	*5200

/	INITIALIZATION SECTION
/	ENTER HERE AT 5200 TO MODIFY TECO TO USE A MODEL 35 TELETYPE

TECO35,	ISZ	JTECO	/IF CALLED VIA "R" OR "RUN"
	TAD	(-10	/MOVE IN ASR35 ROUTINE
	JMS I	(MOVE
	CDF	10
	ASR35-1
	CDF	0
	ASR33-1
	TAD	(ASR33+1
	DCA I	(POUTHT
	TAD	(TECOS
	DCA I	(7745	/CHANGE STARTING ADDRESS IN CASE WE'RE RESTARTED
			/AND FALL INTO INITIALIZATION ROUTINE

TCINIT,	CLA STL
	6141		/ENTER LINC MODE (MAYBE)
	4		/ESF - SET SMALL CHARACTERS FOR SCOPE
	0261		/ROL I 1 - ROTATE LINK INTO AC11
	0002		/BACK TO PDP-8 MODE
	SNA CLA		/AC NON-ZERO IF WE ARE A PDP-12
	JMP	1$	/NO, JUST AN ORDINARY 8
	JMS	CHANGE	/TRADE OFF TWO PAGE HANDLERS FOR A SCOPE
	PDP12
	TAD I	(ETFLAG
	TAD	(2000	/SET VR12 BIT
	DCA I	(ETFLAG
1$:	TAD I COR1
	AND COR70
	SZA
	JMP	SOFCOR
COR0,	CDF 0		/NEEDED FOR PDP-8L
	TAD CORSIZ	/GET FIELD TO TEST
	RTL
	RAL
	AND COR70	/MASK USEFUL BITS
	TAD COREX
	DCA .+1		/SET UP CDF TO FIELD
COR1,	7777		/N IS FIELD TO TEST
	TAD I CORLOC	/SAVE CURRENT CONTENTS
COR2,	NOP		/HACK FOR PDP-8!
	DCA COR1
	TAD COR2	/7000 IS A "GOOD" PATTERN
	DCA I CORLOC
COR70,	70		/HACK FOR PDP-8, NOP
	TAD I CORLOC	/TRY TO READ BACK 7000
CORX,	7400		/HACK FOR PDP-8, NOP
	TAD CORX	/GUARD AGAINST WRAP-AROUND
	TAD CORV	/TAD (1400
	SZA CLA
	JMP COREX	/NON-EXISTENT FIELD EXIT
	TAD COR1	/RESTORE CONTENTS DESTROYED
	DCA I CORLOC
	ISZ CORSIZ	/TRY NEXT HIGHER FIELD
	JMP COR0

COREX,	CDF 0		/LEAVE WITH DATA FIELD 0
COR992,	TAD	(-2	/CAN'T BE MTWO
	TAD CORSIZ	/HIGHEST EXISTING FIELD
	CIF CDF	10
	JMS I	(CORTST	/MAY SKIP RETURN
	JMP	JTECOM	/8K
	TAD	(-7	/MORE THAN 8K
	JMS I	(MOVE
	CDF	10
	QPUT12-1
	CDF	0
	QPUTS-1
	TAD	(-7
	JMS I	(MOVE
	CDF	10
	QGET12-1
	CDF	0
	GETQX-1
	JMS	CHANGE	/AND CHANGE A WHOLE MESS OF LOCATIONS
	TWLVEK
JTECOM,	JMS I	(OVINIT	/WRITE OUT OVERLAYS
	CDF	10
	TAD I	(SCPBIT
	CDF	0
	AND	Z200
	SNA CLA
	JMP	JTECO
	JMS	CHANGE
	SCOPE
JTECO,	JMP I	.+1	/INCREMENTED IF WE WERE'NT CHAINED TO
	CHINIL
	TECO1

CORLOC,	CORX		/ADDRESS TO TEST IN EACH FIELD
CORV,	1400		/7000+7400+1400=0
CORSIZ,	1		/CURRENT FIELD TO TEST

SOFCOR,	CLL RAR
	RTR
	JMP	COR992
/CHAINED INIT CODE - MOVE 17600 INTO Q-REGISTER SPACE

CHINIL,	CIF CDF 10
	JMP I	(CHINI2	/GO TO FIELD 1 CHAIN INITIALIZATION

XQPUT,	0
	QPUT		/QPUT ROUTINE CALLABLE FROM FIELD 1
	CIF CDF	10
	JMP I	XQPUT

CHANGE,	0		/ROUTINE TO CHANGE SPECIFIC LOCATIONS
	STA
	TAD I	CHANGE
	ISZ	CHANGE
	DCA	XR	/STORE TABLE POINTER
L$:	CDF	10
	TAD I	XR	/GET LOCATION
	CDF	0
	SNA
	JMP I	CHANGE	/END OF LIST - RETURN
	DCA	TEMPT
	CDF	10
	TAD I	XR	/GET CONTENTS
	CDF	0
	DCA I	TEMPT	/ZAP!
	JMP	L$

/CHECK FOR OS/8 SCOPE BIT, IF ON, PATCH TECO
/ALSO SEND ESC SEQ TO TERMINAL TO SEE IF VT05 OR VT5X.
	PAGE
OVINIT,	0		/WRITE OUT OVERLAYS
	CIF CDF	10
	JMS I	(MOREI	/DO MORE INITIALIZATION
/IF MORE THAN 12K, MOVE OVERLAYS TO FIELD 3
	MTWO
	TAD	MEMSIZ
TWLVKP,	SPA CLA
	JMP	L16KK	/LESS THAN 16K
	TAD	Z7400
	JMS	MOVE
	CDF	0
	3200-1
CDF4A,	CDF	30
	MEMLOC-1
	TAD	(-2000
	JMS	MOVE
	CDF	0
	5600-1
CDF4B,	CDF	30
	MEMLOC+400-1
	TAD	(-5
	JMS	MOVE
	CDF	10
	NEWERR-1
	CDF	0
	OVREAD-1
	TAD	(-3200
	JMS	MOVE
	CDF	10
	XERBAS-1
CDF4C,	CDF	30
	XERBAS-1
	JMP	G16K
L16KK,	JMS I	(7607
	4200
	3200		/WRITE OUT I/O-OVERLAY
	IOVRLC
	JMP	OVERR	/ERROR WRITING OVERLAY
	JMS I	(7607
	5000		/4 OVERLAYS
	5600		/WRITE OUT Q-OVERLAY AND E-OVERLAY
	QOVRLC
	JMP	OVERR	/ERROR WRITING OUT OVERLAY
	STA
	DCA I	(L16K
G16K,	DCA I	(ERRXX
	.IF NE XTNDED <
	TAD	(-200	/MOVE EXTENDED MATCH CONTROL INTO INPUT BUFFER
	JMS	MOVE
	CDF	10
	3200-1
	CDF	0
	7200-1
	>
	JMP I	OVINIT	/RETURN

OVERR,	TAD	Z7400	/SWAP IN ERROR OVERLAY FROM CORE AND MAKE SURE
	JMS	MOVE	/WE RETURN TO MONITOR
	CDF	0
	6200-1
	CDF	0
	3200-1
	TAD I	(ETFLAG
	AND	(7577
	TAD	Z200	/SET FATAL SWITCH
	DCA I	(ETFLAG
ERR30,	JMP I	(ERRYY	/CALL ERROR MESSAGE PROCESSOR
MOVE,	0
	DCA	MQ
	TAD I	MOVE
	DCA	1$
	ISZ	MOVE
	TAD I	MOVE
	DCA	INXR
	ISZ	MOVE
	TAD I	MOVE
	DCA	2$
	ISZ	MOVE
	TAD I	MOVE
	DCA	XR
	ISZ	MOVE
1$:	HLT
	TAD I	INXR
2$:	HLT
	DCA I	XR
	CDF	0
	ISZ	MQ
	JMP	1$
	JMP I	MOVE
	PAGE
	.ASECT	TECPAT
	FIELD	1
	*3400

	/LIST OF PATCHES TO ENABLE VT52 "WATCH" COMMAND

	.GLOBAL	VPATCH
	.SECREF SWATCH,VTCHKC,VTYI,VTGETQ

	CUR=30

VPATCH,	CHR.W		/ADDR
	-4		/-SIZE
			/ALTER WATCH ROUTINE
	CLA
	CIF CDF	CUR
	CHR.W+3&177+5600/JMP I	.+1
	SWATCH

	CDSP+127	/ADDR
	-1		/-SIZE
	C.W		/ALTER COMMAND DISPATCH TO ALLOW WATCH COMMAND

	VT52B		/ADDR
	-3		/-SIZE
			/ALTER CONTROL C INTERCEPT FOR TYPE AHEAD
	CIF CDF	CUR	/WAS KSF
	VT52B+2&177+5600/JMP I	.+1	/WAS JMP I CHKCTC
	VTCHKC		/WAS KRS

	TYI1		/ADDR
	-4		/-SIZE
	CIF CDF	CUR	/WAS KSF
	TYI1+2&177+5600	/JMP I	.+1	/WAS JMP .-1
	VTYI		/WAS CTCCHK
	NOP		/WAS KRB

/	VT52D		/ADDR
/	-4		/-SIZE
/	0
/	CIF CDF	CUR	/WAS DCA CHKCTC
/	GETQX+3&177+5600/JMP I	.+1	/WAS CDF 20
/	VTGETQ		/WAS TAD I CHKCTC

	0		/END OF LIST
/LOCATIONS TO CHANGE IF WE'RE RUNNING ON A PDP-12

PDP12,	KSFWT;	DISPLY	/FIX KEYBOARD AND PRINTER WAITS
	TSFWT;	DISPLY	/SO THEY DISPLAY WHILE WAITING
	CDSP+127;C.W	/ENABLE W COMMAND
	INHNDL;	7200	/ONE PAGE INPUT HANDLER ONLY
	OUHNDL;	7400	/DITTO OUTPUT HANDLER
	SRHLEN;	-40	/SHORTEN SEARCH BUFFER TO 40 CHARACTERS
	0
/LOCATIONS TO CHANGE IF CONSOLE TERMINAL IS A SCOPE

SCOPE,	RUBY;	SCOPY		/MAKE SCOPE RUBOUTS WORK
	BLSP1;	TAD CACR	/MAKE BELL SPACE WORK
	BLSP2;	TYPE		/AND MORE RUBOUTS
	BLSP3;	SCAPE&177+4600	/JMS I (ESCAPE
	BLSP4;	VT05C,113	/MORE BELL SPACE
	EUFLAG;	-1		/SET EU TO -1
	EU1;	CLA
	EU2;	TAD Z40
	0

/LOCATIONS TO CHANGE MUST BE CHANGED IN OVERLAY IMAGE
/BEFORE OVERLAY IS WRITTEN OUT

/LOCATIONS TO CHANGE IF WE HAVE 12K OF CORE

TWLVEK,	INRSIZ;	4	/INPUT BUFFER GROWS TO 4 BLOCKS LONG
	INCTLW;	1021	/AND LIVES IN FIELD 2
	INPCNT;	5000
	I2;	CDF 20
	IC;	CDF 0	/THIS WAS A NOP TO SPEED UP RTS-8 OPERATION
	L12K1;	J12K1	/SPEED UP TEXT MOVE ROUTINES,
	L12K2;	J12K2	/SINCE Q-REGISTERS DON'T SIT ON TOP OF TEXT.
	OUTSIZ;	6777	/OUTPUT BUFFER TAKES OVER OLD INPUT BUFFER SPACE
	BUFIN;	5600
	NWRUSR;	TAD Z4	/LET USR BE CALLED WITHOUT SAVING CORE
	MQMAX;	-Q12MAX	/ALLOW MORE Q-REGISTER STORAGE
	QLIMIT;	12-Q12MAX
	QSIZE-3200+6600;Q12MAX/FIX -3EJ COMMAND
	0
/ALTERNATE Q-REGISTER GET AND PUT ROUTINES FOR USE IN 12K

QPUT12,	0		/12K Q-REGISTER PUT ROUTINE
	AND	Z377
	CDF 20
	DCA I	QP
	CDF 0
	ISZ	QP
	QPUTS&177+5600

VT52D,
QGET12,	0		/*VT52 12K Q-REGISTER GET ROUTINE
	CHKCTC&177+3200	/*VT52
	CDF 20		/*VT52
	CHKCTC&177+1600	/*VT52
	CDF 0
	AND	Z377
	GETQX&177+5600

/ALTERNATE ROUTINE TO USE IF WE HAVE AN ASR35

ASR35,	ASR33+6&177+5200/ FORM FEED/VERT. TAB - USE 8/4 FILLERS
	COLCT&177+1200	/GET COLUMN COUNTER
	RTR
	RAR
	CLA CMA RAL	/OUTPUT 2 FILLERS IF MORE THAN 4 CHARS TO TAB
	COLCT&177+3200	/OTHERWISE 1 (COLCT IS A MODULO 8 COUNTER)
	TAD	SCHAR	/GET CONTROL CHAR TO TYPE
	PUTT		/AND TYPE IT - WE WILL NOW FILL WITH NULLS
	PAGE
	*3600

/ENTER AT CHINI2
/MOVE INITIAL COMMAND INTO COMMAND-LINE Q-REGISTER SPACE

CHINI2,	TAD I	(7600
	SZA CLA
	JMP	3$	/REGULAR TECO COMMAND
	TAD	(PSTKMD
	DCA	PST	/CCL COMMAND
	TAD	(INIKMD
	DCA	PTR$
	JMP	3$
1$:	DCA	4$	/FIRST 0 MEANS SWITCH TO POST COMMAND
	TAD	PST
2$:	DCA	PTR$	/STORE NEW POINTER
3$:	TAD I	PTR$	/GET A CHARACTER
	ISZ	PTR$	/POINT TO NEXT IN SEQUENCE
	SNA		/IS IT 0?
	JMP	4$	/YES, END OF INITIAL COMMAND STRING
	SPA		/NO, IS IT NEGATIVE?
	JMP	2$	/YES, IT IS A POINTER TO THE NEXT PART OF THE BUFFER
	CIF CDF	0	/LINK TO FIELD 0
	JMS I	(XQPUT	/DO A PUT
	ISZ	KNT$	/COUNT HOW MANY CHARACTERS THERE WERE
	JMP	3$	/REITERATE
4$:	JMP	1$	/LOC GETS ZERO'ED
	TAD	KNT$
	CIF CDF 0
	DCA I	(QZ
	TAD	KNT$
	DCA I	(QPNTR
	JMP I	(CHTECO

KNT$:	0		/NUMBER OF CHARACTERS IN CHAINED INIT COMMAND
PTR$:	INICMD		/POINTS TO INITIAL COMMAND
PST,	PSTCMD

/IF 07600 IS 0, THEN CCL COMMAND FOLLOWS
/PASSED IN TEXT BUFFER TO TECO.TEC WHICH EXECUTES FROM Q-REGISTER V
/ADDITIONAL INITIALIZATION COMMANDS:

MOREI,	0
	TLS
	TAD	.-1
	CDF	0
	DCA I	(TECOS
	TAD	JMPT0A
	DCA I	(TECO1
	TAD	(2001	/NOTHING IMPORTANT ANYMORE DOWN THERE
	DCA I	(JSBITS	/SO DON'T SWAP USR
	CDF	10
	CLA IAC		/SYS
	JMS I	(7700	/CALL THE USR
	2		/TO DO A LOOKUP
B$:	HLP$		/ON SYS:TECHLP.TXT
	0		/GETS NEGATIVE OF LENGTH
	SKP CLA		/FILE NOT FOUND
	TAD	B$	/GET ADDRESS
	DCA I	(HLPADR	/SAVE AWAY ITS STARTING ADDRESS
	TAD I	(SCPBIT
	AND	(200
	CLL RTR
	RTR
	RTR
	CIF CDF	0
	TAD I	(ETFLAG
	DCA I	(ETFLAG	/TURN ON SCOPE BIT IF SCOPE
	JMP I	MOREI

HLP$:	FILENAME TECHLP.TXT

JMPT0A,	T0A&177+5200	/JMP T0A

	PAGE
	*4000		/2 PAGES AVAILABLE

	.ENABLE	ASCII,NOFILL
	.NOLIST BE

INICMD,	TEXT	%@:ER/SYS:TECO.INI/"SYHXWHK'@^UZ%
	200
	7600		/CONTINUE WITH USER'S COMMAND STRING

PSTCMD,	200
	TEXT	%MW+0ES.,.XWMZ^[0,0XZES"N0ESMX'%<33><33>
	0

INIKMD,	TEXT	%@I%
	200
	7601
PSTKMD,	200
	TEXT	%@:ER/SYS:TECO.TEC/"F^ACan't find SYS:TECO.TEC%
	TEXT	<15><12><1>
	TEXT	<3><3>%'A.,ZXV.,ZKMV.,.XV%<33><33>
	0

	.ENABLE SIXBIT,FILL
	.LIST BE
