Google
 

Trailing-Edge - PDP-10 Archives - steco_19840320_1er_E35 - 10,5676/teco/newsrc/tecunv.mac
There are 3 other files named tecunv.mac in the archive. Click here to see a list.
	SUBTTL	Text Editor and COrrector		4-October-1979
	REMARK	RC CLEMENTS/PMH/CAM
	REMARK	Non-DEC people/JMP/GSB/CBD/JCS/Nothead/NB/RCMcQ
	SUBTTL	Introduction

; This version of TECO was designed to be upward compatiable with
; DEC TECO versions 21-24.
; Copyright (c) 1980 Stevens Institute of Technology,
; Hoboken, New Jersey, 07030


; This software may be used and copied provided that this copyright notice
;is included, and provided that copies of all modifications are sent to:
;
;	TECO Project
;	Computer Center
;	Stevens Institute of Technology
;	Castle Point Station
;	Hoboken, New Jersey    07030
;
;
; The information in this software is subject to change without notice
; and should not be construed as a commitment by the authors or their
; employers.
; Version number

	TECVER==200		; Major version number
	TECMIN==1		; Minor version number
	TECEDT==1171		; Edit level
	TECWHO==0		; Who last edited it

; Universals

	SEARCH	MAC		; DEC-10 macro defintitions

; Directives

;	.DIREC	.NOBIN		; No binary file generation

; Generate the TITLE

	TITLE.	TEC,TECUNV,<Text editor and corrector universal>
	TECUNV			; Generate the TITLE
	TECPTX			; Generate the PRINTX
	SUBTTL	Table of Contents

;+
;.pag.lit

;		Table of Contents for TECUNV - Universal file
;
;
;			   Section			      Page
;   1. Text Editor and COrrector. . . . . . . . . . . . . . .    1
;   2. Introduction . . . . . . . . . . . . . . . . . . . . .    1
;   3. Table of Contents. . . . . . . . . . . . . . . . . . .    3
;   4. Revision History . . . . . . . . . . . . . . . . . . .    4
;   5. Default assembly parameters. . . . . . . . . . . . . .    5
;   6. Macro definitions
;        6.1.   LOWVER. . . . . . . . . . . . . . . . . . . .    6
;        6.2.   STOPCD. . . . . . . . . . . . . . . . . . . .    7
;        6.3.   TXTPTR. . . . . . . . . . . . . . . . . . . .    8
;        6.4.   ADJSP . . . . . . . . . . . . . . . . . . . .    9
;        6.5.   DOSTR - Macro to define string tables . . . .   10
;        6.6.   DPUT and DGET . . . . . . . . . . . . . . . .   11
;        6.7.   QRGIDX. . . . . . . . . . . . . . . . . . . .   12
;        6.8.   DEFAULT . . . . . . . . . . . . . . . . . . .   12
;        6.9.   $SAVE . . . . . . . . . . . . . . . . . . . .   13
;        6.10.  PROLOGUE. . . . . . . . . . . . . . . . . . .   14
;        6.11.  $IMPURE, $CODE, $TEXT, $TXTPTR, $ONCE . . . .   15
;        6.12.  CHKEO, ERROR. . . . . . . . . . . . . . . . .   16
;        6.13.  ERRTXT. . . . . . . . . . . . . . . . . . . .   17
;        6.14.  GLOBS . . . . . . . . . . . . . . . . . . . .   18
;        6.15.  DOSWTCH, KEYS . . . . . . . . . . . . . . . .   19
;        6.16.  CRTINI, CRTENT, CRTEND. . . . . . . . . . . .   20
;        6.17.  QRGNAM - Special Q-register names . . . . . .   21
;   7. Macro defintions
;        7.1.   DUMTRM. . . . . . . . . . . . . . . . . . . .   22
;   8. Text output processing
;        8.1.   Flags . . . . . . . . . . . . . . . . . . . .   23
;        8.2.   Function types. . . . . . . . . . . . . . . .   24
;        8.3.   $STRING macro . . . . . . . . . . . . . . . .   25
;        8.4.   CTEXT. macros . . . . . . . . . . . . . . . .   27
;   9. Accumulator assignments. . . . . . . . . . . . . . . .   28
;  10. Flags
;       10.1.   F (Control flags) . . . . . . . . . . . . . .   29
;       10.2.   S (Control flags) . . . . . . . . . . . . . .   30
;       10.3.   CR (CRT Flags). . . . . . . . . . . . . . . .   31
;  11. Data Base Definitions
;       11.1.   BLK - Core block header . . . . . . . . . . .   32
;       11.2.   BLK - Text buffer header. . . . . . . . . . .   33
;       11.3.   CDT - Character dispatch table. . . . . . . .   34
;       11.4.   CRT - CRT block . . . . . . . . . . . . . . .   36
;       11.5.   CST - Cost blocks . . . . . . . . . . . . . .   37
;       11.6.   ERR - Error index block . . . . . . . . . . .   38
;       11.7.   FDB - File descriptor block . . . . . . . . .   39
;       11.8.   FIL - Fill time blocks. . . . . . . . . . . .   40
;       11.9.   LDB - Line data block . . . . . . . . . . . .   41
;       11.10.  SPB - Switch pointer block. . . . . . . . . .   42
;       11.11.  SYM - Symbol table entry
;            11.11.1.    General. . . . . . . . . . . . . . .   43
;            11.11.2.    Label. . . . . . . . . . . . . . . .   44
;            11.11.3.    Q-register . . . . . . . . . . . . .   45
;       11.12.  TPT - Text buffer pointer . . . . . . . . . .   46
;       11.13.  QRG - Pre-defined Q-register pointer. . . . .   47
;       11.14.  WIN - Window. . . . . . . . . . . . . . . . .   48
;  12. Symbols
;       12.1.   Command states. . . . . . . . . . . . . . . .   49
;       12.2.   F$OPEN function codes . . . . . . . . . . . .   50
;       12.3.   File errors . . . . . . . . . . . . . . . . .   51
;       12.4.   Terminal speeds . . . . . . . . . . . . . . .   52
;  13. Misc parameters. . . . . . . . . . . . . . . . . . . .   53
;  14. Special symbols
;       14.1.   TRUE/FALSE. . . . . . . . . . . . . . . . . .   53
;       14.2.   Characters. . . . . . . . . . . . . . . . . .   53
;  15. OPDEFS
;       15.1.   Screen mode checks. . . . . . . . . . . . . .   54
;       15.2.   True/False checks . . . . . . . . . . . . . .   54
;  16. End of TECUNV. . . . . . . . . . . . . . . . . . . . .   55

;.end lit.pag
;-
	SUBTTL	Revision History

COMMENT	|
Start of version 200

1000	Start of this version.

1002	By: Robert McQueen		On: 16-July-1980
	- Start some work on a -20 interface and making KAs work with TECONC
	- Fix a core management problem/symbol table problem defining the first
	  symbol
	Modules: TECUNV,TECSYM,TECONC

1004	By: Robert McQueen		On: 21-July-1980
	The O command would cause ?ill mem ref if the tag was null.  Give a better
	error message for the O command.
	Modules: TECUNV,TECCMD,TECERR

1006	By: Nick Bush		On: 28-July-1980
	1. EE files get "Not a save file" from monitor. The byte size specified in
	   TECUNV was getting expanded as 36 octal, not decimal.
	
	2. EW was using the wrong address for calling F$RSET when there already was
	   an output file. Make it use the FDB address, not the text buffer address.
	Modules: TECUNV,TECECM

1007	By: Nick Bush		On: 30-July-1980
	1) Make CHKTYI work a little better on slow speed (<=600 baud) 
	   terminals. It will now wait until the output buffer is empty before
	   returning the no input return.
	
	2) Put the cursor in a better position to indicate the location of PT
	   when PT = Z. The only time the cursor will now be over the prompt
	   is when PT = Z and the last line of the buffer is terminated by an
	   end of line character, and is on the last line of the window.
	Modules: TECUNV,TECVID,TECTRM

1010	By: Robert McQueen		On: 31-July-1980
	%TECSUP error message gave junk for the file specification.
	Modules: TECUNV,TECERR

1032	By: Robert McQueen		On: 22-August-1980
	Make TECMEM assemble for KI-10s.
	Modules: TECUNV,TECMEM

1034	By: Nick Bush		On: 24-August-1980
	If an error occurs during the execution of TECONC, error processing
	blows up. Set up a flag to indicate whether TECONC has finished yet.
	If it is still set, error processing will skip writing the message
	into the Q-reg.
	Modules: TECUNV,TECUUO,TECONC

1037	By: Robert McQueen		On: 26-August-1980
	Fix edit 1030 for defaulting.
	Modules: TECUNV,TECFIL

1055	By: Robert McQueen		On: 18-November-1980
	Add two new :^T commands to put the terminal into packed image mode and to
	take it out again.
		:-3^T - Put into packed image mode
		:-4^T - Take it out of packed image mode
	Modules: TECUNV,TECFIL,TECCMD,TECMVM

1061	By: Nick Bush		On: 18-December-1980
	1) Finish and debug Tektronix 4025 support.
	2) Add FW command.
	3) Add capability of logging screen update info in log file.
	Modules: TECUNV,TECTEK,TECSRH,TECTBL,TECECM,TECVID,TECERR

1064	By: Robert McQueen		On: 23-December-1980
	VT100s are strange in that after clearing the screen the cursor is left on
	the bottom of the screen.  Add a new word to the $CRxxx blocks $CRERY to
	be the Y position after the screen is erased.
	Modules: TECUNV,TECDEC,TECVID

1065	By: Robert McQueen		On: 29-December-1980
	Remove the previous edit since it is easier to just add a home sequence
	after the erase function.  The erase sequence is now: <esc>[2J<esc>[H
	Modules: TECUNV,TECDEC,TECVID

1070	By: Nick Bush		On: 6-January-1981
	Add three words to the text buffer headers.  These are for use by the
	video updating routines to remember the END of the buffer when updating
	is done, the first position modified between updates and the last
	position modified between updates.
	Modules: TECUNV

1071	By: Nick Bush		On: 10-January-1981
	Add F$RBUF and F$WBUF routines to improve I/O performance.
	Also add /MODE:DUMP for all file commands.
	Modules: TECUNV,TECFIL,TECCMD,TECECM

1076	By: Nick Bush		On: 30-January-1981
	Add a default mode to be mode type 0. This will allow /MODE:ASCII
	to really be such with LSA files. Also make /MODE: properly default
	from ER/EW to EB and vice versa.
	Modules: TECUNV,TECCMD,TECFIL,TECECM

1077	By: Nick Bush		On: 6-Febuary-1981
	1) Add routine do delete all tags for a given text buffer, and have it
	   called anytime the buffer becomes editable, or is destroyed.
	
	2) Reset CUREDT to point at TXTBUF anytime the q-register which it points
	   at becomes disassociated with it.
	Modules: TECUNV,TECPRS,TECCMD,TECECM,TECSYM

1106	By: Nick Bush		On: 13-May-1981
	Improve screen updating for times when the new screen has portions which
	are identical with the old.  This will also fix most cases of wrapped
	around lines on the top of the section of the screen.
	Also fix some random /MODE:DUMP bugs.
	Modules: TECUNV,TECVID,TECCMD,TECECM,TECUUO,TECMEM

1125	By: Robert McQueen		On: 29-September-1981
	- Make symbol table entries movable blocks.
	- Use the new linked list processing.
	- Initial work to make TECSYM run in non-zero section.
	Modules: TECUNV,TECECM,TECSYM,TECMEM

1126	By: Robert McQueen		On: 8-October-1981
	Make stopcodes more useful.  Create a U$STOP routine to type out more 
	information when a STOPCODE is encountered.  Save the registers in a place
	FILDDT can get at and do other good things.
	Modules: TECUNV,TECUUO

Start of Version 200A(1126)

1127	By: Nick Bush@SIT, Robert C. McQueen@SIT		On: 15-October-1981
	Add the following new features:
	- String arguments.  {...} is a string argument.
	- Make I take them, = and == return them.
	- Implement the FC command to define immediate command tables
	- Implement the E? command to return various items.
	- Start doing some work so that TECO will work on TOPS-20
	- Start doing some work so that TECO some day may run in a section
	  besides zero.
	Modules: TECUNV,TECERR,TECPRS,TECCMD,TECSRH,TECMEM,TECUUO,TECECM,TECMVM,TECCOM,TECINI

1132	By: Nick Bush		On: 10-December-1981
	1) Add Q-register data types for the sake of FC(Q-reg)SAVE$ and
	FC(Q-reg)RESTORE$ commands.
	2) Fix FC(q-reg)REPLACE$ to correctly replace the ALWAYS and OTHER options.
	Modules: TECUNV,TECCMD,TECECM,TECMEM,TECPRS,TECMVM

1145	By: Nick Bush		On: 8-Febuary-1982
	Re-write command input routines to implement FI command. As part of this
	allow user to set prompt by storing the prompt text for normal commands in
	the Q-register 'COMMAND-PROMPT'.
	Modules: TECUNV,TECPRS,TECCIN,TECFCM,TECVID,TECUPD

1151	By: Nick Bush		On: 24-March-1982
	Add Q-register 'EXIT-BUFFER' to be executed whenever TECO is exiting.
	Also remove the string to set VT-100's to smooth scroll on exit.  This
	can now be done by putting the correct macro in 'EXIT-BUFFER'.
	Modules: TECUNV,TECECM,TECPRS,TECTBL,TECDEC

1161	By: Nick Bush		On: 13-May-1982
	Add new code to support peek-ahead for immediate (FC table) commands and
	for a new form of the control-T command.
	Add the new form of the control-T command to allow macros to peek at
	input, and to make use of timed input.  Also add the Q-register
	TERMINAL-INPUT-BUFFER to hold the text being peeked at, with the side
	effect of allowing macros to store text into the Q-register, and have
	it be treated as input typed on the terminal.
	Also change the space command to just pass through the arguments unless
	EO is set to 4 or less.
	Modules: TECUNV,TECVID,TECUPD,TECMVM,TECPRS,TECTRM,TECCMD,TECTBL

1162	By: Nick Bush		On: 14-May-1982
	Add a new flag for Q-regs to indicate that the Q-reg may not become the
	current editing buffer with the E. command.  This keeps TERMINAL-INPUT-BUFFER
	from causing problems
	Modules: TECUNV,TECECM,TECCMD

1171	By: Nick Bush		On: 29-June-1982
	Fix * and ? from screwing up after an error when a long prompt is being used.
	Modules: TECUNV,TECPRS,TECUUO
|
	SUBTTL	Default assembly parameters

; Feature tests

ND	FTDEBUG,0		; Debugging code
ND	FTRSCN,	0		; Rescan the initial command line
ND	FTXADR,	0		; Extended addressing

; Processor feature tests

ND	FTKI,	0		; For KI-10s
ND	FTKL,	-1		; Assemble for KL-10
				; Includes ADJSP instructions and EXTEND
				; instructions

; Operating system feature tests

ND	FT10,	-1		; Assemble for TOPS-10
 DEFINE TOPS10,<IFN FT10>	; Handy macro
ND	FT20,	0		; Assemble for TOPS-20
 DEFINE	TOPS20,<IFN FT20>	; Handy macro


; Search the correct universal now

TOPS10,<
	SEARCH	UUOSYM		; TOPS-10 UUO symbol definitions
	DEFINE	SYSPRM(SYM,T10,T20)<SYM==T10>
>; End of TOPS10

TOPS20,<
	SEARCH	MONSYM		; TOPS-20 JSYS symbol defintions
	DEFINE	SYSPRM(SYM,T10,T20)<SYM==T20>
>; End of TOPS20
; Debugging constants

SYSPRM	DDTADR,	.JBDDT,	770000	; Word containing starting address of DDT

; Default values

ND	AUTOFS,	0		; Default is non-autotype after searches
ND	TYCASW,	0		; Default type-out mode causes flagging of
				; characters in the lower case range with '
ND	SRCHSW,	0		; Default prevailing search mode is accept
				; either LC or UC alphabetics as a match
ND	D.XPDL,	200		; Number of words on the execution stack
ND	D.PDLL,	^D400		; 400 word pdl
ND	LPF,	2*40		; Note: Q regs take two words each
				; on the stack
ND	EOVAL,	5		; The standard setting of the EO flag for
				; this is version 4
	INTERN	EOVAL		; Make global so conflicts show
ND	D.TXTS, ^D3000		; Number of characters to allocate for initial
				;  text buffer
ND	D.CMDS,	^D250		; Number of characters to allocate for initial command buffer
ND	D.MINC,	^D1000		; Amount of initial free core wanted
ND	D.MXFW,	20		; Number of words free
ND	D.MXFR,	^D4000		; Max number of free chars before free chars
				; from text block will be reclaimed.
ND	D.EPIS,^D250		; Initial size of text buffer to read EP/EI
				; file into
ND	D.HASH,^D29		; First hash table size

ND	$CHQOT,.CHCNR		; Quoting character for many things
TOPS10<
ND	D.TPRO,	110		; Temporary file protection
ND	D.NBUF,	^D5		; Default number of disk buffers
>; End of TOPS10
TOPS20<
ND	D.TPRO,	000000		; Temporary file protection
>; End of TOPS20
IFN FTXADR<
ND	D.CSEC,	1		; Section to run the code in
ND	D.DSEC,	2		; Section to start the data in
ND	D.ESEC,	2		; Last section to run the data in
>; End of IFN FTXADR

IFN FTKI+FTKL+1,<PRINTX ?Processor features messed up>
IFN FTKI&FT20,<PRINTX ?FTKI on with FT20>
IFN <FTKI!FT10>&FTXADR,<PRINTX ?Extended addressing on TOPS-20 only>

DEFINE	TELLON(TEST,Text)<IF2 <IFN FT'TEST,<PRINTX TECO: Text>>>
TELLON	(10,<DECsystem-10 version>)
TELLON	(20,<DECSYSTEM-20 version>)
TELLON	(DEBUG,<Debugging version>)
TELLON	(KL,<KL processor version>)
TELLON	(KI,<KI processor version>)
TELLON	(XADR,<Extended addressing version>)
	SUBTTL	Macro definitions -- LOWVER

;+
;.HL1 LOWVER
; This macro will define a symbol for the low segment version number
;of the given module.
;.b.literal
; Usage:
;	LOWVER(xxx,version)
;
; Where xxx is the module suffix, and version is the version number
;for the modules low segment.
;
;.end literal
;-

DEFINE LOWVER(POST,VER),<%LV'POST==:VER>


	EXTERN	%TECV1, %TECV2, %TECV3, %TECV4, %TECV5
	EXTERN	%TECT1, %TECT2, %TECT3

; Define overall lowsegment version number defined this way because
; MACRO 53A cannot generate polish for a symbol which is
; the sum of more than 7 external symbols.
; %TECVn are defined in TECONC using the macro below

%TECOV==:33+%TECV1+%TECV2+%TECV3
%TECTV==:%TECT1+%TECT2+%TECT3


; Macro to define %TECV1 and %TECV2. These two symbols should be
; the sum of the low segment version numbers of the various modules
; of TECO. These are used to define %TECOV (the overall low segment version)
; since MACRO cannot handle the necessary polish in one step.


DEFINE DEFLVR<
	EXTERN %LVINI, %LVTRM, %LVVID, %LVMEM, %LVSYM, %LVUUO
	EXTERN %LVPRS, %LVCMD, %LVSRH, %LVECM, %LVFIL, %LVCOM
	EXTERN %LVUPD, %LVMVM, %LVCIN, %LVFCM
	EXTERN %LVMSC, %LVACT, %LVADM, %LVADS, %LVBEE, %LVCDC
	EXTERN %LVDEC, %LVDTM, %LVDTP, %LVHEA, %LVHZL, %LVHP
	EXTERN %LVTVI, %LVRAY, %LVTEK

%TECV1==:%LVINI+%LVTRM+%LVVID+%LVMEM+%LVSYM+%LVUUO
%TECV2==:%LVPRS+%LVCMD+%LVSRH+%LVECM+%LVFIL+%LVCOM
%TECV3==:%LVMVM+%LVUPD+%LVCIN+%LVFCM

; Terminal dependent low segments. Note that a separate version
;number is generated for these modules. This is because there
;is no storage in these modules that needs to be saved in the EE file.

%TECT1==:%LVMSC+%LVACT+%LVADM+%LVADS+%LVBEE+%LVCDC
%TECT2==:%LVDEC+%LVDTM+%LVDTP+%LVHEA+%LVHZL+%LVHP
%TECT3==:%LVTVI+%LVRAY+%LVTEK
>
	SUBTTL	Macro definitions -- STOPCD

; This macro will normally just generate a HALT.  If FTDEBUG is on
;it will first type out the error message and then HALT.

DEFINE	STOPCD(XXX,TEXT),<
S..'XXX::
    IFN FTDEBUG,<
	PUSHJ	P,U$STOP		;; Call the STOPCODE processor
	JUMP	[EXP	%%.MOD		;; Generate the module name
		XWD	''XXX'',0	;; Generate the stopcode name
		ASCIZ	|TEXT|]		;; Generate the text
    >;; End of IFN FTDEBUG
    IFE FTDEBUG,<HALT	''XXX''>
> ; End of STOPCD macro definition
	SUBTTL	Macro definitions -- TXTPTR

;+
;.HL1 TXTPTR
;This routine will generate a byte pointer and a character count.  This is
;used for calling the M$INSS routine in TECMEM.  The main purpose of this routine
;is to make imediate commands work easly.
;.literal
;
; Usage:
;	DMOVE	T1,[TXTPTR(Text to move)]
;.end literal
;-

DEFINE	TXTPTR(TEXT),<
	...CNT==0
	.XCREF	...CNT
	IRPC <TEXT>,<...CNT==...CNT+1>
	POINT 7,[ASCIZ |TEXT|]
	EXP	...CNT
	SUPPRESS ...CNT
>; End of TXTPTR macro definition
	SUBTTL	Macro definitions -- ADJSP

;+
;.HL1 ADJSP
;This macro will generate the instructions needed to simulate the
;ADJSP instruction on either KS-10 or KL-10 processors.
;-

IFE FTKL,<
	DEFINE ADJSP(AC,E),<
		IFL <E>,<SUB AC,[XWD -<E>,-<E>]>
		IFG <E>,<ADD AC,[XWD <E>,<E>]>
		IFE <E>,<PRINTX ?Fix ADJSP AC,E>
	>
> ; End of IFE FTKL
	SUBTTL	Macros definitions -- $ADJSP

;+
;.hl1 $ADJSP
;This macro is used to generate the ADJSP instruction trapping the stack
;overflows.  This macro is only a single instruction on the KL-10/KS-10
;processors and two instructions on the KI-10 processor.
;-

IFE FTKL,<
	DEFINE	$ADJSP(AC,E)<
		ADJSP	(AC,E)
	IFG <E>,<
		JUMPGE	AC,[MOVEI T1,.	;; Get the address of the instruction
			JRST	TRPPDL]	;; Call the trap routine
	> ;; End of IFG <E>
	>; End of $ADJSP
>; End of IFE FTKL

IFN FTKL<
	SYN	ADJSP,$ADJSP
>; End of IFN FTKL
	SUBTTL	Macro definitions -- $POINT - Point pseudo-op

;+
;.hl2 $POINT
;This pseudo-op is used to build byte pointer.
;-

IFE FTXADR,DEFINE $POINT(SIZE,ADDRSS,OFFSET)<POINT SIZE,ADDRSS,OFFSET>
IFN FTXADR,DEFINE $POINT(SIZE,ADDRSS,OFFSET)<PRINTX ?Fix me>
	SUBTTL	Macro defintions -- BLDBPT - Build a byte pointer

;+
;.HL1 BLDBPT
;This macro will build a byte pointer depending on the type of addressing
;we are doing.  It will either build the single word local byte pointer for
;the non-extended addressing version or the single word global byte pointer
;for the extended addressing version.  This macro assumes that it can
;use register and register plus one for operations.
;.literal
;
; Usage:
;	BLDBPT(Register,Address)
;
; Where:
;	Register - Character address to build the pointer to.
;	Address  - Address of the text block.
;
;.end literal
;-

DEFINE	BLDBPT(REG,ADDR)<
    IFE FTXADR,<
	IDIVI	REG,5		;; Compute the word and offset
	HLL	REG,BTAB-1(REG+1) ;; Build the pointer to it
	ADDI	REG,.BKTLN'ADDR	;; Point to the correct address
    >;; End of IFE FTXADR
    IFN FTXADR,<
	PRINTX ?Write BLDBPT
    >;; End of IFN FTXADR
>; End of BLDBPT macro definition
	SUBTTL	Macro definitions -- $DBP - Decrement the byte pointer

;+
;.hl1 $DBP
;This macro will decrement a byte pointer.  This routine will work for
;both extended and non-extended addressing.
;.literal
;
; Usage:
;	$DBP	(Reg,Scratch Reg)
;
; Where:
;	Reg 	- Contains the byte pointer
;	Scratch - Scratch pad register
;
;.end literal
;-

DEFINE	$DBP(REG,SCRATCH,%1)<
    IFE FTXADR,<
	ADDX	REG,<INSVL.(7,BP.PFL)>	;; Back up the position
	JUMPG	REG,%1			;; Go over a word boundary?
	SOJ	REG,			;; Decrement the address
	TXZ	REG,BP.PFL		;; Clear out the position
	TXO	REG,<INSVL.(1,BP.PFL)>	;; Put the position to one
%1:!
    >;; End of IFE FTXADR
    IFN FTXADR,<
	MOVX	SCRATCH,-1		;; Amount to move the byte pointer
	ADJBP	SCRATCH,REG		;; Adjust the register
	MOVE	REG,SCRATCH		;; Get the result
    >;; End of IFN FTXADR
>; End of $DBP macro definition
	SUBTTL	Macro definitions -- ADDRESS - Macro for structures

;+
;.hl1 ADDRESS
;This address macro is used to allocate an address word in one of the
;data structures that are built by the INTSTR/ENDSTR/WORD/HALF/BYT/...
;macro definitions.  This macro will be redefined to either a HALF
;macro or a WORD macro depending on the value of the FTXADR feature
;test.
;-

IFE FTXADR,<
    DEFINE ADDRESS(POSTFIX)<HALF(POSTFIX)>
>; End of IFE FTXADR

IFN FTXADR,<
    DEFINE ADDRESS(POSTFIX)<WORD (POSTFIX)>
>; End of IFN FTXADR
	SUBTTL	Macro definitions -- DOSTR - Macro to define string tables

;+
;.HL1 DOSTR
;This macro will define the string tables for the FNDSTR routine.  It
;will take two arguments.  The first argument is the name of the
;string to store in the table and the second is an argument that is
;passed to a STRSUB macro.  This will allow routines to use this
;macro without extra tables.
;.literal
;
; Example:
;
;	DEFINE	STRTBL,<
;	STR	string.to.look.for,ARG
;	>
;	DOSTR	(xxx)
;
;.end literal
;-

; Define the structure for accessing the table items

	INTSTR	STR,SR,$
	WORD	BPT		; Byte pointer to name
	WORD	CNT		; Character count
	ENDSTR			; End the structure

DEFINE	DOSTR(LBL),<
LBL'TBL:

    DEFINE STR(STRING,ARG),<
	.XCREF		;; Turn off CREFing
	%%..=0
	.CREF		;; Turn it back on
	.XCREF	%%..	;; Don't cref this symbol
	IRPC <STRING>,<%%..==%%..+1>
	[POINT	7,[ASCIZ |STRING|]
	EXP	%%..
	STRSUB	(ARG)
	]
	IF2, PURGE	%%..
    >;; End of STR macro argument

	STRTBL		;; Expand the macro
LBL'LEN==.-LBL'TBL
>; End of DOSTR macro definition
	SUBTTL	Macro definitions -- DPUT and DGET

;+
;.HL1 DPUT and DGET
; These macros are for storing and getting items from storage that
;may be possible to fetch or store with a DMOVE or DMOVEM instruction.
;These macros will not work with externals.
;-

DEFINE	DPUT(AC,A,B),<
 IFN <<A>-<B>+1>,<
	MOVEM	AC,A		;; Store the first word
	MOVEM	AC+1,B		;; Store the second word
 >
 IFE <<A>-<B>+1>,<
	DMOVEM	AC,A		;; Store the two words
 >
>; End of DPUT macro definition


DEFINE	DGET(AC,A,B),<
 IFN <<A>-<B>+1>,<
	MOVE	AC,A		;; Fetch the first word
	MOVE	AC+1,B		;; Fetch the second word
 >
 IFE <<A>-<B>+1>,<
	DMOVE	AC,A		;; Fetch the two words
 >
>; End of DGET macro definition
	SUBTTL	Macro definitions -- QRGIDX

; This macro will give the index for a Q register given the name.

	DEFINE	QRGIDX(CHAR)<QRGI..(\<"CHAR">)>
	DEFINE	QRGI..(VAL),<.QR'VAL'*$QRLEN>




	SUBTTL	Macro definitions -- DEFAULT

;+
;.HL1 DEFAULT
;This macro will default parameters for TECO.
;.literal
;
; Usage:
;	DEFAULT	VALUE,LOCATION
;.end literal
;-


DEFINE	DEFAULT(VALUE,LOCATION)<STORE(T1,LOCATION,,VALUE)>
	SUBTTL	Macro definitions -- $SAVE

;+
;.HL2 $SAVE
; This macro is used to save things during the execution of a routine
;called by a PUSHJ P,. It will save the given list on the stack and restore
;them when the routine returns.
;-

 
DEFINE	$SAVE(LIST,%1),<
	.XCREF					;; Turn off cref
	DEFINE	..PSH(VALUE,COUNT),<
		.%S'COUNT==VALUE		;; Copy the address to save
		IFE COUNT-1,<			;; First thing saved?
			CAIA			;; Yes, make this thing skipable
			 JRST	%1>		;;  .  .  .
		PUSH	P,.%S'COUNT		;; Save the thing
		..VRCNT==..VRCNT+1>		;; And bump the counter

	DEFINE	..POP(COUNT),<
		POP	P,.%S'COUNT		;; Restore it
		PURGE	.%S'COUNT		;; And destory the symbol
		..VRCNT==..VRCNT-1>		;; Count down the number

	IFNDEF .COND,<SEARCH MAC>
	..VRCNT==0		;; Counter for variables
	..ACMSK==0		;; Mask for which ac's to save
	$$$VAL==0		;; Initialize the thing to save
	..RFLG==0		;; No routine to call
	..RTN==0		;;  .  .  .
 
	IRP	LIST,<		;; Loop for all the things to save
		$$$VAL==LIST		;; Copy the address
		.COND(<<<..TSAC($$$VAL)>,<..PSH($$$VAL,\<..VRCNT+1>)>>,
			<<0>,<..ACMSK==..ACMSK!1B<$$$VAL>>>>)
 
			>	;; End of IRP
 
		IFN ..ACMSK,<	;; Have a correct routine?
			.COND(<<<..ACMSK-<17B<T4>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SAVET>>,
				<<..ACMSK-<7B<T3>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SAVT3>>,
				<<..ACMSK-<3B<T2>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SAVT2>>,
				<<..ACMSK-<1B<T1>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SAVT1>>,
				<<..ACMSK-<17B<P4>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SAVE4>>,
				<<..ACMSK-<7B<P3>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SAVE3>>>)
		    IFE ..VRCNT,<	;; Don't call other ac routines if need pushes anyway
			.COND(<<<..ACMSK-<3B<P2>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SAVE2>>,
				<<..ACMSK-<1B<P1>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SAVE1>>,
				<<..ACMSK-<3B<A2>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SAVEA>>,
				<<..ACMSK-<1B<CH>>>,<..ACMSK==0
							..RFLG==-1
							..RTN==.SVCH>>>)
				> ;; End of IFE ..VRCNT
		> ;; End of IFN ..ACMSK
		    IFN ..ACMSK,<		;; Any ac's left to save?
			..CNTR==0		;; Yes, clear the counter
			REPEAT ^D16,<		;; And loop for all the ac's
				IFN ..ACMSK&<1B<..CNTR>>,<
					..PSH(..CNTR,\<..VRCNT+1>)>
					..CNTR==..CNTR+1>	;; Step to next ac
			SUPPRESS ..CNTR 	;; Make the counter go away later
		> ;; End of IFN ..ACMSK
 
		    IFN ..VRCNT,<		;; Save anything on the stack?
			PUSH	P,[[CAIA		;; Stack the restore routine
				AOS	-..VRCNT(P)	;; Propagate the skip return
			REPEAT ..VRCNT,<..POP(\..VRCNT)> ;; Generate the restores
				POPJ	P,]]>		;; And the return
	IFN ..RFLG,<PUSHJ	P,..RTN>	;; If we need an ac save routine also
						;; the generate it here
 
%1:
	SUPPRESS %1		;; Make this go away later
	PURGE ..VRCNT,..ACMSK,$$$VAL,..RFLG,..RTN ;; Make the symbols go away when done
	.CREF					;; Turn CREFing back on
> ; End of $SAVE definition
	SUBTTL	Macro definitions -- PROLOGUE

;+
;.HL2 PROLOGUE
; This macro is used as the prologue of each module.  It will define
;the universals that are search, it will generate the TITLE for the module
;and a PRINTX on pass2 to display the name and the version number.
;.literal
;
; Usage:
;	PROLOGUE(UUO,<TECO LUUO processing>)
;
;.end literal
;-

DEFINE	PROLOGUE(POSTFIX,TEXT),<
	SALL			;; Suppress macro expansions
	.DIREC	.XTABM		;; Exclude tabs from macro arguments
	.DIREC	FLBLST		;; List the first line of binary only

	SEARCH	MAC		;; Search the standard macro definitions
TOPS10,	SEARCH	UUOSYM		;; Search the TOPS-10 UUO symbol definitions
TOPS20,	SEARCH	MONSYM		;; Search the TOPS-20 JSYS defs

	TITLE.	TEC,TEC'POSTFIX',<'TEXT'>
	TECTTL			;; Generate the TITLE
	TECPTX			;; Generate the PRINTX
	%%.MOD==<SIXBIT /TEC'POSTFIX/> ;; Define the module name
	GLOBS			;; Request any global routines
	$INIPS			;; Initialize the PSECT
> ; End of the PROLOGUE macro definition
	SUBTTL	Macro definitions -- $IMPURE, $CODE, $TEXT, $TXTPTR, $ONCE

;+
;.HL2 $IMPURE, $CODE, $TEXT, $TXTPTR, $ONCE
;These macros generate the PSECT statements for the different sections
;that code is generated into.  The $IMPURE is for the impure data
;segment, $CODE is for the high segment code, $TEXT is for the error
;message text and $TXTPTR is for the text pointers to the error text.
;-

DEFINE	$IMPURE,<
	$ENDPS(\'..PSEC)	;; End the current PSECT
	.PSECT	IMPURE/CONCAT	;; Set the next PSECT
	..PSEC=='IMPURE'	;; Set the new name
	SUPPRES	..PSEC		;; Suppress the symbol
> ; End of $IMPURE macro definition

DEFINE	$CODE,<
	$ENDPS(\'..PSEC)	;; End the current PSECT
	.PSECT	CODE/CONCAT	;; Set the new one
	..PSEC=='CODE'		;; Set the new name
	SUPPRES	..PSEC		;; Suppress the symbol
> ; End of $CODE macro definition

DEFINE	$TEXT,<
	$ENDPS(\'..PSEC)	;; End the current PSECT
	.PSECT	.TEXT./CONCAT	;; Set the new one
	..PSEC=='.TEXT.'	;; Set the new name
	SUPPRES	..PSEC		;; Suppress the symbol
> ; End of $TEXT macro definition

DEFINE	$TXTPTR,<
	$ENDPS(\'..PSEC)	;; End the current PSECT
	.PSECT	.TXTPT/CONCAT	;; Text pointer PSECT
	..PSEC=='.TXTPT'	;; Set the name
	SUPPRES	..PSEC		;; Suppress the symbol
> ; End of $TXTPTR macro definition

DEFINE	$ENDPS(NAME),<
	.ENDPS	NAME		;; Set the name
> ; End of $ENDPS macro definition

DEFINE	$INIPS,<
	.PSECT	IMPURE/CONCAT	;; Initial PSECT
	..PSEC=='IMPURE'	;;  Set the name
	SUPPRES	..PSEC		;; Suppress the symbol
>; End of $INIPS


DEFINE	$ONCE,<
	$ENDPS(\'..PSEC)	;; End the current PSECT
	.PSECT	.ONCE/CONCAT	;; Once only PSECT
	..PSEC=='.ONCE'		;; Set the name
	SUPPRES	..PSEC		;; Suppress the symbol
> ; End of $ONCE macro definition
	SUBTTL	Macro definitions -- CHKEO, ERROR

;.hl2 CHKEO(EO,ADDR)
;This macro will expand as a call to the CEO routine.  This will check
;the current EO level against the one specified.  If the EOFLAG greater
;than the EO level specified then CEO will return to the next instruction,
;else it will branch to the address specified.
;.literal
;
; Usage:
;	CHKEO	EODEC,FOODEC	; Check for DEC EO level & branch to FOODEC
;.end literal
;-

DEFINE	CHKEO(EO,ADDR)<
	XCT	EOXCTS+EO-1	;; Execute the proper instruction
	 TRNA			;; Didn't skip (allows CHKEO to be skipped over)
	  JRST	ADDR		;; Skipped, go to the old code.
> ; End of CHKEO macro definition

 ; CHKEO levels that are valid

	EO21==	1		; Turn off special version 22+ features
	EODEC==	2		; Same for version 124+
	EO124==	3		; Same for version 200+
	EO200==	4		; Turn off post 200 features (and/or checks)

; General error LUUO

	OPDEF	.ERR[1B8]
	OPDEF	.WRN[2B8]		; Warning LUUO

;TYPE ERROR MSG: ERROR	E.XXX
;TYPE MESSAGE CORRESPONDING TO 'XXX'
;THEN GO TO GO

;THE FOLLOWING IS THE DEFINITION OF THE REGULAR ERROR UUO

	DEFINE	ERROR(X),<
	.ERR	X'##
	> ; End of ERROR definition

	DEFINE	WARN(X),<
	.WRN	X'##
	> ; End of WARN definition
	SUBTTL	Macro definitions -- ERRTXT

;+
;.hl1 Macro Definitions
;.hl2 ERRTXT
; This macro is used to generate the text of the error messages. It also
;generates symbols for use in generating the index.
;-


	DEFINE ERRTXT(LEVEL,COD,TEXT,CONTXT,%1,%2),<
	PRINTX	COD=LEVEL		;; Print out the prefix and it's level

	$TEXT				;; Set for the text
%1:!	$STRING(<TEXT>)			;; Generate the text
%2:!	$STRING(<CONTXT>)		;; Generate the continuation messages
	$TXTPT				;; Set to text pointers
	E.'COD==:.-PTRBEG		;; This is the offset for this message
	$BUILD(ERR,$ERLEN)		;; Initialize for the error index
	$SET	FLG,0			;; Clear the flags
	$SET	LVL,LEVEL		;; Set the level
	$SET	PFX,<SIXBIT |   COD|>	;; Set the prefix
	$SET	FST,%1			;; Set the first line
	$SET	CON,%2			;; Set the continuation
	$EOB				;; End the block

	.XCREF	%1,%2
	SUPPRESS %1,%2

	> ; End of ERR definition
	SUBTTL	Macro definitions -- GLOBS

;+
;.HL2 GLOBS
; This macro will define the global storage and routines in TECO.  The
;macro is arranged so that the items are grouped with the module that
;the routine or storage is defined in.  This macro is expanded in the
;PROLOGUE macro.
;-

DEFINE	GLOBS,<

;; TECINI - Initialization
GLOB <	TECO,	I$JOB,	PDLSAV,	PDL,	QRGSTK,	PFL,	SIXJOB,	CPFLAG,	AUTOF>
GLOB <	CCLSW,	IMPBEG,	CODBEG,	TXTBEG,	PTRBEG,	ONCBEG,	JIFSEC,	PHYSON,	FSTCMD>

;; TECFIL - File processing
GLOB <	F$INIT,	F$OPEN,	F$PARS,	F$READ,	F$WRIT,	F$CLOS,	F$RENM,	F$USET>
GLOB <	F$ERR,	MYPATH,	MYJOB,	MYNODE,	MYPPN,	F$SETI,	F$SXBT,	F$CHKP>
GLOB <	F$RSET,	F$DFLT,	LASFDB,	LASSXB,	LASOCT,	LASSWT,	SWTIMD,	SWTOMD>
GLOB <	F$EB,	F$KEY,	F$CORE,	F$COPY,	RTN,	FPTH,	DEFPTR,	LASSWP>
GLOB <	FFIFDB,	FFIPTH,	F$ENQ,	F$DEQ,	F$RBUF,	F$WBUF,	GNBCHR>

;; TECCOM - Common routines
GLOB <	.SAVE1,	.SAVE2,	.SAVE3,	.SAVE4,	.SAVET,	.SAVEA,	.SVCH,	.SV11>
GLOB <	.POPJ,	.POPJ1,	.T1PJ,	.T1PJ1,	DISPAT,	DISP1,	NDISPT,	.T2PJ>
GLOB <	NDISP1,	.T2PJ1,	CKSYM,	LOKNAM,	LASNAM,	.RET0,	.RET1,	.RET2>
GLOB <	FNDSTR,	FNDKWD,	.SAVT3,	.SAVT2,	.SAVT1,	.INSRT,	INSCHR,	INSQRG>
GLOB <	SCNKEY,	SCNKWD,	LASSPT,	.IDECW,	.IOCTW,	.ZCHNK,	.SKTPT>

;; TECSYM - Symbol table management
GLOB <	S$INIT,	S$CINI,	S$LABL,	S$QREG,	S$CMPS,	S$QRGC,	S$TAGC,	QRGLNK>

;; TECPRS - Command parsing
GLOB <	CHRLEN,	P$INIT,	C$INIT,	CB$INI,	CB$MOV,	CB$STO,	C$XCT,	SAVEP>
GLOB <	CMDSTA,	RCH,	SKRCH,	REE,	VALRET,	COMND,	RETZER,	RTONES>
GLOB <	SKAN,	REEAT,	XCTBUF,	CMDSVP,	CMDSTR,	LSTCMD,	CPMLEN>
GLOB <	XCTING,	SYL,	NUMB,	DLIM,	EQM,	ETVAL,	PASRET,	XSPDL>
GLOB <	ALTMOD,	CAND,	CDNUM,	CLOSEP,	COMMA,	COR,	MINUS,	OCTIN>
GLOB <	OPENP,	PLUS,	SLASH,	STOP,	TIMES,	UAR,	AUTBUF,	AUTCNT>
GLOB <	C$SCMD,	SKANST,	VALRT2,	STRRET,	STRARG,	GETSTR,	SARG$1,	SARG$2>
GLOB <	CPYAG1,	CPYAG2,	C$XCTI,	CLNXS,	XITQRG,	CTCQRG,	DOXITQ,	SPCCMD>

;; TECCIN - Command input
GLOB <	C$CINI,	C$INPT,	C$DLCH,	C$BLIN,	BACKUP,	CINQRG,	PMTLEN>
GLOB <	C$PRMT,	C$ICHE,	C$RPRT,	C$HPOS>

;; TECTRM - Terminal processing
GLOB <	T$INIT,	T$CINI,	T$SRTN,	T$IBUF,	T$OCHR,	T$TCHR,	T$ACHR>
GLOB <	T$TYPE,	T$ERTY,	TYPEAC,	TTYOUT,	T$SECH,	T$CECH,	TRMTYP>
GLOB <	.TCRLF,	ALTEO,	ALTCNV,	ECHOFF,	TRMSOP,	TRMOCH,	TRMTOC>
GLOB <	TTYFDB,	TRMUDX,	TRMSPD,	TYCASF,	TY.OBY,	TY.IBY,	TY.OST,	TY.IST>
GLOB <	TRMWID,	TRMLEN,	TTIBUF,	T$READ,	T$ICHS,	T$CTYI,	T$PEEK,	T$CHKI>
GLOB <	T$REDN,	T$PEKW,	T$RBUF,	T$WAIT,	ICHINS>

;; TECCMD - Command execution routines
GLOB <	ACMD,	ATSIGN,	BAKSL,	BELDMP,	CASE,	CKNCC,	CVTSPC,	WRTBUF>
GLOB <	CHARAC,	CLOSEB,	CMNT,	CNTRUP,	COLON,	DELETE,	LASQRG,	RQRGTB>
GLOB <	END1,	EOF,	EXCLAM,	FFEED,	KILL,	GETFDO,	GETCMD,	GETTXT>
GLOB <	GETFDI,	GRTH,	GTIME,	HOLE,	INSERT,	INSE.0,	INSE.I,	IUSET,	JMP>
GLOB <	LAT,	LINE,	LOWCAS,	LSSTH,	MAC,	MJRST,	OG,	OPENB,	PCNT>
GLOB <	PNT,	PRNT,	PUNCHA,	QGET,	QPAGE,	QREG,	QUESTN,	QYANK,	REVERS>
GLOB <	SEMICL,	SETMCH,	SPTYI,	SQUOTE,	STDCAS,	TAB,	TYPE,	TYPE.1,	USE>
GLOB <	VCMD,	XCMD,	YANKER,	PUNSCH,	YANK,	FFDCMD,	LASLBL,	QTXTST>
GLOB <	BTAB,	CKEOL,	SCNQRG,	QREGV2,	QTXTEI,	C.W,	C.V,	QTAB>
GLOB <	SETINC,	PUTINC,	GETINC,	MAC.0,	REDQRG,	JMP1,	QNMLEN,	QNMTBL>
GLOB <	QRNTPT,	DQ.A,	DQ.C,	DQ.D,	DQ.E,	DQ.F,	DQ.G,	DQ.G>
GLOB <	DQ.L,	DQ.N,	DQ.S,	DQ.T,	DQ.U,	DQ.V,	DQ.W>
GLOB <	ANGLVL,	CTGBUF,	CTGLVL,	INSRCH,	INSREE,	ITERCT,	LOPADR>
GLOB <	OLDINR,	OLDREE,	STAINS>

;; TECECM
GLOB <	E$INIT,	E$RANG,	E$LANG,	MODKEY,	DECDMP,	LOGCHR,	SWTBUF,	CUREDT>
GLOB <	OPNWRA,	EBCMD,	ECCMD,	EDCMD,	EECMD,	CLOSEF,	EGCMD,	ERRSET>
GLOB <	EICMD,	EKILL,	MAKLOG,	EMTAPE,	ENCMD,	OLDMOD,	EPCMD,	CRTGEN>
GLOB <	EQCMD,	OPNRD,	AUTOTY,	TYOCTL,	TYCASE,	OPNWR,	FINISH,	CLSFIL>
GLOB <	ZERDIR,	CRTPTR,	PARPTR,	EOMAX,	MODPTR,	PRMERR,	EJCMD,	LOGC.0>
GLOB <	RUNDEV,	RUNNAM,	RUNPTH,	RST,	EOXCTS,	EQUEST>

;; TECFCM - F commands
GLOB <	FC$INI,	FICMD>

;; TECUUO - LUUO processing
GLOB <	ERRQUE,	ERRIDX,	ERFCNT,	ERRSLH,	ERRDTM,	ONCFLG>
GLOB <	U$INIT,	U$CINI,	U$PDLO,	CEO,	ERRFDB,	U$STOP>
GLOB <	ERRLEN,	ERRSTS,	ERRPT,	EOFLAG,	ERRCH,	TRPPDL>
;; TECMEM - Memory management
GLOB <	M$INIT,	M$XPND,	M$GBLK,	M$GTXT,	M$RBLK,	M$USEB,	M$RELB,	M$INSS>
GLOB <	M$SRNK,	M$MSTR,	M$GC,	M$ZBLK,	M$ACHR,	M$XMOV,	M$RTPT,	CPYCTB>
GLOB <	ERRQRG,	CMDBUF,	TXTBUF,	FSTBLK,	DELTXT,	M$DCTB,	DELCND,	M$CPCN>
GLOB <	M$LINK,	M$ULNK,	M$APPD,	M$MLNK,	M$MCOR,	M$CPGS,	CPMQRG>
;; TECSRH - Searches and pattern matching
GLOB <	SR$INI,	SERCH,	N$CMD,	FND2,	SERCHJ,	LARR>
GLOB <	SRHMOD,	STAB,	SRHCTR,	SRHARG,	VVAL,	SFINDF>
GLOB <	FDSRCH,	FKSRCH,	FNSRCH,	FSSRCH,	FW$CMD,	SRHLEN>
;; TECVID & TECUPD - Video processing routines
GLOB <	SC$RVD,	SC$RTM,	SC$RST,	SC$FIN,	SC$POS,	SC$STR,	SC$PT,	SC$UPD>
GLOB <	SC$BEG,	VIDEO,	SETWIN,	CRTFNC,	SC$CHR,	SCRNAD,	SC$GSC,	SC$ERS>
GLOB <	SC$MES,	CRTTYP,	MESFLG,	CURPOS,	SC$DEL,	SC$CLR,	SC$UPS,	SC$CLS>
GLOB <	V$ICHR,	V$OCHR,	V$ECHO,	V$CINI,	V$ASK,	SETCRT,	CMDPOS,	SC$SCR,	CLRLDB>
GLOB <	OLDCRT,	CRTSAV,	SC$REF,	SC$CIL,	SC$CDL,	SC$FIL,	SC$CFL,	V$DELC>
GLOB <	V$UPCM,	V$CTRG,	GETVID,	SC$IMG,	SC$IM0,	SETLIN,	RTNLIN,	CKTRM>
GLOB <	ASKPOS,	OUTFLG,	TYIFLG,	FLSLDB,	FNDLDB,	SC$WLN,	SC$WRT,	VIDPOS,	FNDCHP>
GLOB <	FNCLST,	CSTLST,	FNCBLK,	SUPDAD,	PTPOS,	LINWDS,	CPSTBL,	CLRL.0,	VIDP.0>
GLOB <	CHKTYI,	CHKTY0,	NOTYIA,	VINADR,	SC$SSR,	CRTWID,	CRTLEN,	SCRWID,	SCRNLN>
;; TECTBL - Static tables
GLOB <	CHRTBL,	CHRFLG,	ECMTBL,	ECMFLG,	FCMTBL,	FCMFLG>
GLOB <	CRTTAB,	NUMCRT,	CRTDSP>
;; TECMVM - Magic video mode (Immediate mode)
GLOB <	I$INIT,	I$SIMG,	I$CIMG,	IMGFLG,	CDCMD,	FCCMD,	UPDBND,	I$PRSC>
GLOB <	KEYLEN,	KEYTBL,	CTYLEN,	CTYTBL,	CTYPTR,	TRMLEN,	TRMTBL,	VV$CMD>
;; TECONC
GLOB <	IMPEND>
> ; End of GLOBS macro definition
	SUBTTL	Macro definitions -- DOSWTCH, KEYS

;+
;.HL1 DOSWTCH
;This macro will expand a switch table.
;.literal
;
; Usage:
;	DEFINE	SWTCHS,<
;	SW	NAME,POINTR,ROUTINE,VALUE,FLAGS
;	>
;
;	DOSWTCH(XXX,SWTCHS)
;.end literal
;.HL1 KEYS
; This macro will expand the different keywords for the DOSWTCH
;-

DEFINE	DOSWTCH(XXX,SWTCHS)<

    DEFINE SW(NAME,PTR,RTN,VALUE,FLAGS)<EXP SIXBIT /NAME/>

XXX'N:	SWTCHS		;; Expand the names of the switches

  XXX'L==.-XXX'N	;; Define the length of the block

DEFINE SW(NAME,PTR,RTN,VALUE,FLAGS)<
	PTR
>

XXX'P:	SWTCHS		;; Expand the pointers

DEFINE	SW(NAME,PTR,RTN,VALUE,FLAGS),<EXP VALUE>

XXX'V:	SWTCHS		;; Expand the values

DEFINE	SW(NAME,PTR,RTN,VALUE,FLAGS<0>),<
    IFNB <RTN>,<XWD RTN,FLAGS>
    IFB  <RTN>,<XWD 0,FLAGS>
>
XXX'R:	SWTCHS		;; Expand the routines and the flags
>; End of DOSWTCH macro definition

INTFLG	SW,RH.ALF,.		; Initialize the switch flags

	FLAG	VRQ		; Value required
	FLAG	KEY		; Keyword switch
	SUBTTL	Macro definitions -- CRTINI, CRTENT, CRTEND

;+
;.HL1 CRTINI, CRTENT, CRTEND
;These macros are used to define the CRT blocks for a terminal.  These
;macros must be changed for each new item that is defined in the CRT
;block that is a routine or string requiring a default.
;.literal
;
; Usage:
;	CRTINI	VV52
;	CRTENT	WID,^D80
;	CRTEND
;.end literal
;-

DEFINE	CRTINI(NAM)<
    .XCREF			;; Turn off CREFing
    DEFINE ..CRT(LIST),<
	IRP <LIST>,<
	    ...'LIST==0
	    .XCREF ...'LIST
	>;; End of IRP <LIST>
    > ;; Define helper macro
    ..CRT(<INT,WVT,WFF,BCK,SPC,DBS,DLF,DVT,DFF,DCR,CRB,CBS,CTU,FIN,ERS,DEL,DSP,XYP,DLL,INL,ICH,DCH,TCH,SCR,LIN,WID,CIN,CPP,CDC,CIC,CDL,CIL,CRP,CDE,SDN,SUP>)
    PURGE ..CRT			;; Purge the helper macro
    .CREF			;; Turn CREFing back on
    INTERN NAM'TBL		;; Make the name of the table internal
    TABDEF (NAM,$CR,0)

;; Macro to finish off the CRT block.  This macro will fill in the defaults
;; for a CRT block.

DEFINE	CRTEND<
;; Define the flags

	NAM'FLG==:IFN <...CTU><CR$CTU>!IFN <...DLF><CR$DLF>

    DEFINE ...CRT(NAME,DEFAULT),<
	IFE ...'NAME,<
	    TABENT (NAME,<DEFAULT>)
	> ;; End of IFE ...'NAME
    > ;; End of ...CRT macro definition

;; Fill in the default values

	LSTOF.				;; Turn off the listing
	...CRT(INT,<JFCL>)		;; Default initialization routine
	...CRT(CTU,<PUSHJ P,.TCRLF>)	;; Default control U routine
	...CRT(CIN,<SETZ T1,>)		;; Default initial cost routine
	...CRT(CDE,<MOVE T1,T1>)	;; Cost routine defaults
	...CRT(CRP,<MOVX T1,.INFIN>)	;; . . .
	...CRT(CIL,<MOVX T1,.INFIN>)	;; . . .
	...CRT(CDL,<MOVX T1,.INFIN>)	;; . . .
	...CRT(CIC,<MOVX T1,.INFIN>)	;; . . .
	...CRT(CDC,<MOVX T1,.INFIN>)	;; . . .
	...CRT(CPP,<MOVX T1,.INFIN>)	;; . . .
	...CRT(DEL,<PUSHJ P,SC$DEL>)	;; Delete to the end of line
	...CRT(XYP,<JFCL>)		;; X/Y positioning
IFE ...SDN,	...CRT(DLL,<JFCL>)		;; Delete line
IFE ...SUP,	...CRT(INL,<JFCL>)		;; Insert line
	...CRT(ICH,<JFCL>)		;; Insert character
	...CRT(DCH,<JFCL>)		;; Delete character
	...CRT(TCH,<PUSHJ P,SC$CHR>)	;; Type a character
	...CRT(DLF,<JFCL>)		;; Delete a line feed
	...CRT(DVT,<JFCL>)		;; Delete a vertical tab
	...CRT(DFF,<JFCL>)		;; Delete a form feed
	...CRT(FIN,<JFCL>)		;; Routine to finish up (i.e. reset terminal)
	LSTON.				;; Turn the listing back on

;; Clean up

    DEFINE ...CRT(LIST),<
	.XCREF		;; Turn off CREFing
	IRP <LIST>,<IF2, PURGE ...'LIST>
	.CREF		;; Turn the CREFing back on
    > ;; End of ...CRT macro definition
    ...CRT(<INT,WVT,WFF,BCK,SPC,DBS,DLF,DVT,DFF,DCR,CRB,CBS,CTU,FIN,ERS,DEL,DSP,XYP,DLL,INL,ICH,DCH,TCH,SCR,LIN,WID,CIN,CPP,CDC,CIC,CDL,CIL,CRP,CDE,SDN,SUP>)
    PURGE ...CRT		;; Purge the helper macro
    TABEND		;; Cause the table to end
>;; End of CRTEND macro definition
>; End of CRTINI macro definition


; Macro to store items in the table

DEFINE	CRTENT(NAM,ITEM)<
	...'NAM==-1		;; Flag item stored
	TABENT	NAM,<ITEM>	;; Store the item
>; End of CRTENT macro definition
	SUBTTL	Macro definitions -- QRGNAM - Special Q-register names

;+
;.HL1 QRGNAM
;This macro defines the special Q-register names that can not be written
;into or otherwise messed up.  They are here only for items being
;displayed or read-only parameters.
;-

DEFINE	QRGNAM,<
STR	<AUTO-BUFFER>,<AUTBUF,QR$FCT>	;; Automatic command buffer
STR	<AUTO-COMMAND>,<AUTBUF,QR$FCT>	;; Synonym for AUTO-BUFFER
STR	<AUTO-COUNT>,<AUTCNT,QR$DIS!QR$TXT!QR$FCT> ;; Count for how often to execute AUTO-BUFFER
STR	<COMMAND-BUFFER>,<CMDBUF,QR$WRT!QR$DLC!QR$FCT!QR$EDT>
STR	<COMMAND-PROMPT>,<CPMQRG,QR$FCT>
STR	<CONTROL-C-INTERCEPT-COMMAND>,<CTCQRG,QR$FCT>
STR	<EXIT-COMMAND>,<XITQRG,QR$FCT>
STR	<ERROR-TEXT>,<ERRQRG,QR$VLU!QR$FCT>
STR	<TERMINAL-INPUT-BUFFER>,<TTIBUF,QR$VLU!QR$FCT!QR$DIS!QR$EDT>
STR	<TEXT-BUFFER>,<TXTBUF,QR$VLU!QR$WRT!QR$FCT!QR$EDT>
>
	SUBTTL	Macro defintions -- DUMTRM


; This macro is used to define the necessary symbols to avoid
;including a terminal support module.
; The call is of the form:
;	DUMTRM(XXX,<TLIST>)
;
; Where XXX is the module prefix and TLIST is a list of terminal
;names defined by that module.
;

DEFINE	DUMTRM(XXX,TLIST),<
	PROLOG	(XXX,<Dummy table defs for XXX terminals>)

	LOWVER(XXX,0)		; Define to indicate the low segment is
				; not included.

	IRP TLIST,<
		ENTRY	V'TLIST'TBL	; Define the entry name for this terminal
		V'TLIST'TBL==VCRTTBL##	; Define the table name
		V'TLIST'FLG==:VCRTFLG##	; Define the flags
	> ; End of IRP
> ; End of DUMTRM defintion
	SUBTTL	Text output processing -- Flags

;+
;.hl1 Text output processing
; These are the definitions of the symbols for the error, warning, and
;informational text processing.
;.hl2 Flags
; These are the flags for the text processing routines.
;.b.ls1
;-

	INTFLG	TF,LH.ALF,$	; Generate left half flags TF$xxx

	FLAG	ARG		;&.le;TF$ARG - Routine requires an argument
	FLAG	IMM		;&.le;TF$IMM - Immediate mode address field

	TF$NAG==0		;&.le;TF$NAG - Dummy flag to say no arg needed
				;&.els

	SUBTTL	Text output processing -- Function types

;+
;.hl2 Function types
; The following are the function types allowable in a text string.
;Note that those marked internal may not be used in the macro calls.
;.sl ;+-;
;.b.ls1
;-

DEFINE TXTTYP,<
 TT(BEG,TF$NAG,)		;;.le;BEG - Internal, next byte is code
 TT(0,TF$NAG,)			;;.le;0 - End with a null
 TT(5,TF$ARG,<word>)		;;.le;5 - ASCII word
 TT(6,TF$ARG,<character>)	;;.le;6 - SIXBIT character
 TT(7,TF$ARG,<character>)	;;.le;7 - ASCII character
 TT(8,TF$ARG,<character>)	;;.le;8 - Image ASCII character
 TT(A,TF$NAG,)			;;.LE;A - Left angle bracket
 TT(B,TF$ARG,<string>)		;;.le;B - Byte pointer to ASCIZ string
 TT(C,TF$ARG,<string>)		;;.le;C - Type string containing funny characters
 TT(D,TF$ARG,<Decimal number>)	;;.le;D - Decimal number
 TT(E,TF$ARG,<List>)		;;.le;E - DOSTR table
 TT(F,TF$ARG,<File specification>) ;;.le;F - File descriptor block (FDB)
 TT(G,TF$ARG,<Q-register name>)	;;.le;G - Q-register name
 TT(I,TF$ARG!TF$IMM,)		;;.le;I - Move left margin to value (Insert)
 TT(J,TF$NAG,)			;;.le;J - Line feed
 TT(K,TF$NAG,)			;;.le;K - Vertical tab
 TT(L,TF$NAG,)			;;.le;L - Form feed
 TT(M,TF$NAG,)			;;.le;M - Carriage return
 TT(N,TF$NAG,)			;;.le;N - No crlf at end of string
 TT(O,TF$ARG,<Octal number>)	;;.le;O - Octal number (unsigned)
 TT(P,TF$ARG,<Path>)		;;.le;P - PPN or PATH
 TT(Q,TF$NAG,)			;;.le;Q - Type a double quote
 TT(R,TF$NAG,)			;;.le;R - Type right angle bracket
 TT(S,TF$ARG,<String>)		;;.le;S - Type a $STRING string
 TT(T,TF$ARG,<String>)		;;.le;T - ASCIZ string
 TT(V,TF$ARG,<Version number>)	;;.le;V - Version number
 TT(W,TF$ARG,<Word>)		;;.le;W - SIXBIT word
 TT(X,TF$ARG!TF$IMM,)		;;.le;X - Set type out routine 
 TT(Z,TF$ARG,)			;;.le;Z - Type a switch table
 TT(INS,TF$NAG,)		;;.le;1 - Internal string to follow
 TT(EOS,TF$NAG,)		;;.le;3 - Internal, end of string
> ; End of TXTTYP definition

;;.els.sl ;+-&
;-

	INTNUM	TF,1,177,$	; Define $TFxxx symbols
	DEFINE TT(CHAR,ARG,STRING),<
	NUM	CHAR		;; Define the index
		$TF'CHAR==$TF'CHAR!ARG	;; Add in the flags
	> ; End of TT definition

	TXTTYP			; Expand the macro
	ENDNUM			; Defin te max of the $TF symbols
	SUBTTL	Text output processing -- $STRING macro


;+
;.hl2 $STRING macro
; This is the macro that builds the strings for the text output routines.
;-

DEFINE $STRING(TEXT),<
	.XCREF			;; Turn this off.
	CTEXT.
	..FRST==0		;; Clear the string length
	..TYPE==0		;; Clear the types
	..AFLG==0		;; Flag not in an address
	..QFLG==0		;; No up-arrow seen yet
	..LFLG==0		;; Initialize the loop flag
	..CFLG==0		;; Next character should be make a control character
	..WCNT==0		;; Number of characters in a word count
	..WORD==0		;; Initialize the word
	IRPC TEXT,<
	..LFLG==0		;; Flag nothing found yet
	..CVAL==<ASCII TEXT>_-<^D36-7>
	IFN ..QFLG,<IFN <..CVAL-"_">,<
			$GTTYP(<TEXT>)
		..LFLG==-1>>
	IFE ..LFLG,<IFN ..AFLG,<$ADBLD(<TEXT>)
			..LFLG==-1>>
	IFE ..LFLG,<IFN ..TYPE&TF$ARG,<IFN <..CVAL-"/">,<PRINTX ? Missing address in string message>
			..AFLG==1
			..LFLG==-1>>
	IFE ..LFLG,<IFE ..QFLG,<IFE <..CVAL-"_">,<..CFLG==-1
				..LFLG==-1>>
				..QFLG==0>

	IFE ..LFLG,<IFE ..CFLG,<IFE <..CVAL-"^">,<..QFLG==-1
				..AFLG==0
				..TYPE==0
				..LFLG==-1>>>
	IFE ..LFLG,<
		IFE ..FRST,<.WORD.	$TFBEG
			.WORD.	$TFINS
			..FRST==1>
		IFN ..TYPE&177,<.WORD.	$TFBEG
				.WORD.	$TFINS
				..TYPE==$TFINS>
		IFN ..CFLG,<
		    IFL <..CVAL>-"A",<PRINTX ? Illegal control character _TEXT>
		    ..CVAL==<<..CVAL&137>-100>
		    ..CFLG==0>
		.WORD.	(\..CVAL)>
	> ;; End of IRPC
	.WORD.	$TFBEG
	.WORD.	$TFEOS
	.EWRD.
	SUPPRESS	..FRST,..AFLG,..QFLG,..TYPE,..LFLG,..CFLG
	SUPPRESS	..WCNT,..WORD,..CVAL
	.CREF			;; Turn this back on again
> ; End of $STRING definition

DEFINE	.WORD.(VALUE),<
IFE ..WCNT-5,<
	EXP	..WORD
	..WORD==0
	..WCNT==0
>
	..WORD==..WORD!<VALUE>B<<7*..WCNT>+6>
	..WCNT==..WCNT+1
>; End of .WORD. definition

DEFINE	.EWRD.	<
IFN <..WCNT>,<
	EXP	..WORD
	..WORD==0
	..WCNT==0>>
; Helper macros

DEFINE	$GTTYP(CHAR),<
	...FLG==0
	.XCREF ...FLG
	..QFLG==0
	IFIDN <CHAR>,<^>,<.WORD. <"CHAR">
		...FLG==-1>
	IFE ...FLG,<IFNDEF $TF'CHAR,<PRINTX ? Unknown text type out code CHAR
			...FLG==-1>>
	IFE ...FLG,<IFE $TF'CHAR&TF$ARG,<.WORD.	$TFBEG
				.WORD.	<$TF'CHAR&177>
				..TYPE==$TF'CHAR
				...FLG==-1>>
	IFE ...FLG,<	.WORD.	$TFBEG
			DTEXT.(..TYPE)
			..TYPE==$TF'CHAR>
	SUPPRESS ...FLG
> ; End of $GTTYP definiition

DEFINE	$ADBLD(CHAR),<
	IFIDN <CHAR>,</>,<..AFLG==0
			DTEXT.(..TYPE)>
	IFDIF <CHAR>,</>,<..AFLG==..AFLG+1
		XTEXT. ATEXT.,<CHAR>
		IFE ..AFLG-^D31,<PRINTX ? Address too long>>
> ; End of $ADBLD definition
	SUBTTL	Text output processing -- CTEXT. macros

;+
;.hl2 CTEXT., XTEXT., and ATEXT.
; These macros are used to accumulate text. Note that XTEXT.(ATEXT.,foo)
;cannot be called more than 30 times without dumping the text and clearing
;the text.
;-

; Macro to clear the text


DEFINE	CTEXT.,<
	DEFINE XTEXT.(OPCODE,TEXT),<
	OPCODE	<<TEXT>>>>

; Macro to add to the text

DEFINE	ATEXT.(OLD),<
	DEFINE	XTEXT.(OPCODE,TEXT),<
	OPCODE	<OLD,<TEXT>>>>


; Macro to strip off a level of angle brackets by calling lower level.

DEFINE	TEXT.(TEXT),<TEXT1.	(TEXT)>



; Macro to dump accumulated text

DEFINE	DTEXT.(TYPE),<
IFN TYPE&TF$ARG,<
	DEFINE	TEXT1.(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,ZZ,AA,BB,CC,DD,EE),<
	.CREF			;; Turn this back on
	EXP <<Z A'B'C'D'E'F'G'H'I'J'K'L'M'N'O'P'Q'R'S'T'U'V'W'X'Y'ZZ'AA'BB'CC'DD'EE>_1>!<<TYPE&177>B6>
	.XCREF			;; Turn it back off
	> ;; End of DEFINE TEXT1.
	XTEXT.	TEXT.
	CTEXT.
> ;; End of IFN TYPE&TF$ARG
IFE TYPE&TF$ARG,<
	.EWRD.
> ;; End of IFE TYPE&FT$ARG
	..TYPE==0
	..FRST==0
> ; End of DEFINE DTEXT.
	SUBTTL	Accumulator assignments

	F=	0		; Flags

	T1=	1		; First temp
	T2=	2		; Second temp
	T3=	3		; Third temp
	T4=	4		; Fourth temp

	P1=	5		; Non temps
	P2=	6		; . . .
	P3=	7		; . . .
	P4=	10		; . . .

	A1=	11		; First argument
	A2=	12		; Second argument

	CH=	13		; Character register
	S=	14		; Second set of flags

	XS=	15		; Execution stack
	CRT=	16		; CRT function block
	P=	17		; Main stack

; Redefinitions for the CRT processing

	X=	A1+$OFSX	; Redefine the argument ACs
	Y=	A1+$OFSY	; . . .
SUBTTL	Flags -- F (Control flags)

	INTFLG	F,FW.ORD,.	; Initialize for F.xxxx flags

	FLAG	ARG2		; There is a second argument
	FLAG	ARG		; There is a first argument
	FLAG	SRCH		; Replacement search (FS or FN)
	FLAG	SLSL		; @ seen
	FLAG	NSRH		; N or FN search
				; (Also used as no free form feeds)
	FLAG	COLN		; Colon seen
	FLAG	LARW		; _ search
	FLAG	TRAC		; Command trace mode
	FLAG	PMAT		; Prevailing match mode
	FLAG	FKSH		; FK search in progress
	FLAG	TYOF		; Need to output a buffer
	FLAG	DONE		; Finished processing command
	FLAG	ECHO		; Screen mode should echo
	FLAG	RUN		; Must run a program on EX (ED was done)
				;  or an EG command so run COMPIL
	FLAG	MCCM		; Within a multi-character command, so don't change error pointer
	FLAG	OP		; Operation pending
	FLAG	ACLN		; Argument is from a colon'ed command
	FLAG	SFFI		; Suppress File found in message
	FLAG	CREC		; Carriage return was the last thing seen
				;  by V$ECHO
	FLAG	DUJ		; Display an ^J since ^M was not the last character
	FLAG	EB		; EB defaulting
	FLAG	ECMD		; EC command in progress
	FLAG	STR1		; First argument is a string
	FLAG	STR2		; Second argument is a string
	FLAG	FCON		; Immediate command processing turned on
	FLAG	INCM		; In command portion of rescanned command
	FLAG	INFI		; In an FI command, don't put cursor on PT

; Flags to clear before command dispatch.

F.CCLR==F.MCCM!F.ARG!F.ARG2!F.COLN!F.LARW!F.SLSL!F.OP!F.ACLN
F.GOCL==F.SRCH!F.NSRH!F.FKSH!F.INFI
	SUBTTL	Flags -- S (Control flags)

	INTFLG	S,FW.ORD,.	; Initialize for S.xxxx flags


	FLAG	SCRN		; Doing very fancy CRT processing
	FLAG	CTLV		; Control V seen inside of text
	FLAG	CTVV		; Double control V seen inside text
	FLAG	CTLW		; Control W seen inside of text
	FLAG	CTWW		; Double control W seen inside of text
	FLAG	XMAT		; Exact match search mode
	FLAG	EMAT		; Temporarily accept either upper or lower case
	FLAG	LCTT		; Lower case terminal
	FLAG	NTRC		; Disable tracing
	FLAG	NCCT		; No control commands in text except ^T amd ^R
	FLAG	LCAS		; Convert upper case to lower case by default
	FLAG	UCAS		; Convert lower case to upper case by default
	FLAG	CTLN		; Control N in search argument
	FLAG	NALT		; Don't convert old altmodes to escapes
	FLAG	NRAD		; Null replacement altmode delimited
	FLAG	LOPN		; Log file open
	FLAG	DOIT		; M<file> as opposed to just HX*<file>
	FLAG	MINS		; Minus search (Backwards)
	FLAG	DELS		; FD search
	FLAG	SLOG		; Suppress log file output
	FLAG	OLOG		; Output to the log file only at TYOA
	FLAG	LIN		; Put type in in LOG file
	FLAG	LOUT		; Put type out in LOG file
	FLAG	LVID		; Log video info
	FLAG	SCRL		; Scroll command section if possible
	FLAG	LIIN		; Log image of input
	FLAG	XNXF		; If on, monitor traps XON's/XOFF's
	FLAG	RVRS		; Reverse search should leave position at beginning

	S.YANK==S.NRAD		; Overload S.NRAD flag

; S flags to clear before command dispatch
	S.CCLR==S.NCCT!S.CTLV!S.CTVV!S.CTLW!S.CTWW!S.NRAD!S.OLOG!S.SLOG!S.MINS!S.DOIT!S.DELS
	SUBTTL	Flags -- CR (CRT Flags)

; The following are used to denote the type and characteristics
; of a CRT.

	INTFLG	CR		; Initialize the flags
	FLAG	NRM		; TECO defined CRT
	FLAG	CRT		; This is a CRT
	FLAG	NCR		; No free CRs
	FLAG	RUB		; Special rubout processing
	FLAG	WAP		; Wrap around
	FLAG	NWP		; Negative wrap around for backspacing
	FLAG	TAB		; Terminal has hardware tabs
	FLAG	TTY		; Terminal is really a TTY
	FLAG	DIC		; Terminal has delete/insert character
	FLAG	DIL		; Terminal has delete/insert line
	FLAG	SCR		; Terminal has scrolling options
	FLAG	DLF		; Terminal has delete line feed string
	FLAG	CTU		; Terminal has control U processing
				;  implies terminal has delete to end of line
	FLAG	RLF		; Terminal has reverse line feed

; Random symbols used for screen processing

	D$CPW==	5		; Number of characters per word

	$OFSX==0		; Offset to the X position
	$OFSY==1		; Offset to the Y position
	SUBTTL	Data Base Definitions -- BLK - Core block header

; The following is the general header which is present on all dynamically
;allocated blocks.

;; !=========================================================================!
;; !Block type !Flags! Next page number !         Size of the block          !
;; !=========================================================================!
;; \                                                                         \
;; \                                  Data                                   \
;; \                                                                         \
;; !=========================================================================!


	INTSTR	BLK,BK,.

	BYT	TYP,	6	; The type of block
		INTNUM	BT,0,BK.TYP,.	; Define .BTxxx symbols for the block types
		NUM	JNK		; Junk block, may be collected
		NUM	GEN		; General core usage, may not be moved
		NUM	BUF		; I/O buffers, may not be moved
		NUM	TXT		; A text buffer, may be moved
		NUM	SYM		; Symbol table entry
		NUM	FDB		; FDB's for open files
		NUM	CTB		; Command table
		NUM	CND		; Command node
		NUM	MOV		; General movable block
		ENDNUM			; Define the max

	BYT	FLG,	3	; Flag bits
		INTFLG	BF,BK.FLG,.	; Define BF.xxx symbols for the flags
		FLAG	LST		; Block is the last block on a page
	BYT	NXT,	9	; The page number of the next page after
				; this block if this is the last block in a page
	BYT	SIZ,	18	; The size of this block
	ENDSTR
	SUBTTL	Data Base Definitions -- Movable block header

;+
;.hl2 Movable block header
;This header is used for those blocks in the data base that are movable.
;-

;; !=========================================================================!
;; \                                                                         \
;; \                              Block header                               \
;; \                                                                         \
;; !=========================================================================!
;; !                Address of the 'static' pointer for TPTs.                !
;; !=========================================================================!


	INTSTR	BLK,BK,.,.BKLEN

	LHALF	FRW		; Number of free words in this block
	RHALF	ADR		; Address of the TPT pointer list
	ENDSTR	MLN
	SUBTTL	Data Base Definitions -- BLK - Text buffer header

; The following is the definition of the additional header for a text
;buffer.

;; !=========================================================================!
;; \                                                                         \
;; \                        General core block header                        \
;; \                                                                         \
;; !=========================================================================!
;; !               Flags                !                                    !
;; !-------------------------------------------------------------------------!
;; !            Pointer list            !   Line offset   !Window line number!
;; !-------------------------------------------------------------------------!
;; !             Output FDB             !             Input FDB              !
;; !-------------------------------------------------------------------------!
;; !            The offset of the editing pointer for this buffer            !
;; !-------------------------------------------------------------------------!
;; !                Total number of characters in this buffer                !
;; !-------------------------------------------------------------------------!
;; !              The number of free characters in this buffer               !
;; !-------------------------------------------------------------------------!
;; !                Byte pointer to the text being processed                 !
;; !=========================================================================!
;; \                                                                         \
;; \                                The text                                 \
;; \                                                                         \
;; !=========================================================================!


	INTSTR	BLK,BK,.,.BKMLN

	LHALF	TFL		; Flags for this buffer
		INTFLG	TF,BK.TFL,.	; Make TF.xxx flags
		FLAG	OPI		; File opened for input associated with this buffer
		FLAG	OPO		; File opened for output associated with this buffer
		FLAG	IMD		; Immediate window updating
		FLAG	FFD		; Buffer needs a form feed after it
		FLAG	VID		; This text buffer is being displayed
	RHALF	TMP		; FDB for the temp file
	BYT	COL,	^D9	; Current column number for ^D command (actually column+1)
	HALF	PLN		; Prompt length
	LHALF	FDO		; Output FDB for this block
	RHALF	FDI		; FDB for input
	WORD	PT 		; The offset of the editing pointer for this buffer
	WORD	END		; Total number of characters in this buffer
	WORD	FRE		; The number of free characters in this buffer
	WORD	PTR		; Byte pointer to the text being processed
	WORD	OED		; Old end (for screen updating)
	WORD	FST		; First position modified
	WORD	LST		; Last position modified (actually OED-last position)
	ENDSTR	TLN		; Lend of the text header

	SUBTTL	Data Base Definitions -- CDT - Character dispatch table

;; !=========================================================================!
;; !               Flags                !Q reg index! Arg type  !Value return!
;; !=========================================================================!


;; !=========================================================================!
;; !        User defined command        !       Normal command address       !
;; !=========================================================================!


	INTSTR	CDT,CD,.

	BYT	FLG,	14	; Character flags
		INTFLG	CF,CD.FLG,.	; Character flags
		FLAG	PAR		; On if the parity bit is required to make this
					; character have odd parity
		FLAG	LC		; Lower case
		FLAG	EOL		; End of line
		FLAG	QRG		; Q register name
		FLAG	ALP		; Alphabetic
		FLAG	1ST		; Special processing if the first character
		FLAG	NUM		; Numeric
		FLAG	ECA		; Extended command address
		FLAG	SYM		; Valid symbol character
		FLAG	RST		; Restore the old command table
		FLAG	CLN		; Don't clear the colon flag
		FLAG	AT		; Don't clear atsign
	BYT	PST,	4	; Post command argument type
		INTNUM	CP,0,CD.PST,.	; .CPxxx symbols
		NUM	NON		; No post command argument
		NUM	QRG		; Q-register name
		NUM	ALT		; Altmode terminated string
		NUM	CHR		; Single character
		NUM	DEL		; String terminated by same character
		NUM	INS		; Insert string (^R and @ prefix allowed)
		NUM	SRH		; Search string (^R, ^Q and @ prefix allowed)
		NUM	SIN		; Search string, then insert string
		NUM	AT		; @ prefix
		NUM	PW		; Possible "W" following "P"
		NUM	SAG		; String argument (terminated by })
		ENDNUM			; Define the max
	BYT	QRI,	6	; Q register index
	BYT	AG1,	6	; First argument type
		INTNUM	CA,0,CD.AG1,$	; Initialize the arguments
		NUM	ARG		; This is part of an argument
		NUM	MBN		; Must have one numeric argument
		NUM	MBS		; Must have one string argument
		NUM	DF1		; Numeric argument, default to 1 if not supplied
					; (only applies to first argument)
		NUM	NON		; No arguments allowed
		NUM	OPN		; Optional numeric argument
		NUM	OPS		; Optional string argument
		NUM	OSN		; Optional string or numeric argument
		NUM	MNS		; Must be numeric or string
		ENDNUM			; Define the max for the field
	BYT	AG2,6			; Second argument type
	ENDSTR
	INTSTR	CDT,CD,.
	LHALF	UDC		; User defined command address
	RHALF	CMD		; Normal command routine address
	ENDSTR	DLN
; The following macro will define all the valid Q registers in TECO.
; Lower case letters are special in that they are converted to use the
; upper case Q registers.  (See character table if you wish to change that).
; To add a Q register, just add it to the end of the list given in the macro
; call below.

DEFINE	QRGSTR(QREGS),<
	INTNUM	QR,0,CD.QRI,.
	XLIST				;; Don't list this
	IRPC <QREGS>,<
		.XCREF			;; Turn off CREFing
		$$$VAL=="QREGS"
		.XCREF	$$$VAL		;; Don't CREF this
		.CREF			;; Turn it back on
		NUM	(\$$$VAL)>
	ENDNUM			; Define the max for the field
	PURGE	$$$VAL		;; Delete unwanted symbols
	LIST			;; Turn the listing back on
>

QRGSTR(0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*%?.)
	SUBTTL	Data Base Definitions -- CND - Command node

;+
;.hl2 CND
;This block is pointed to by other CNDs and CDTs.
;-

;; !=========================================================================!
;; \                                                                         \
;; \                        Movable core block header                        \
;; \                                                                         \
;; !=========================================================================!
;; !                         Next CND in linked list                         !
;; !-------------------------------------------------------------------------!
;; !                            Last word in use                             !
;; !-------------------------------------------------------------------------!
;; !                          Number of free words                           !
;; !-------------------------------------------------------------------------!
;; \                                                                         \
;; \                          Index allocation bits                          \
;; \                                                                         \
;; !=========================================================================!
;; \                                                                         \
;; \                         Index allocation bytes                          \
;; \                                                                         \
;; !=========================================================================!
;; \                                                                         \
;; \                         Transition information                          \
;; \                                                                         \
;; !=========================================================================!


	INTSTR	CND,CN,$,.BKMLN

	WORD	CND,	$LKLEN	; Next CND in the linked list
	HALF	FLG		; CND flags
		INTFLG	CN,CN$FLG,$	; Generate CN$xxx flags
		FLAG	MRK		; Mark bit for general use
		FLAG	STR		; This state is from a "*"
		FLAG	PLS		; This state is from a "+"
		CN$LOP==CN$STR!CN$PLS	; Loop state is either of the above
	HALF	END		; Last word in use
	WORD	BTS,	4	; Index allocation bits
	WORD	BYT,	<^D128/4> ; Bytes
	WORD	INF,	0	; Byte dependent information
	ENDSTR

; Number of bytes per word

	$CNBPW==4		; Number of byte per word

; Each byte has the following format:

	CB$TRN==400		; Index is for a transfer
	CB$XCT==200		; Index is for an execute
	CB$DEF==CB$TRN!CB$XCT	; Index is defined for this character
				; If both bits are on, this is a transfer
				; around a state for the "*" operator
	CB$IDX==177		; Index for the information

; The following is the format of the information

;; !=========================================================================!
;; \                                                                         \
;; \                               TPT pointer                               \
;; \                                                                         \
;; !=========================================================================!


	INTSTR	CIN,CI,$

	WORD	TRN,	$TPLEN		; Transition pointer
	ENDSTR	TLN


; Execute information
;; !=========================================================================!
;; !                    Character address of the command                     !
;; !-------------------------------------------------------------------------!
;; !            Command type            !           Command length           !
;; !=========================================================================!


	INTSTR	CIN,CI,$

	WORD	CAD		; Character address of the start of the command
	LHALF	CTY		; Command type
		INTNUM	CT,0,CI$CTY,$
		NUM	TEC		; TECO commands
		NUM	BAS		; Base level command table
		NUM	PRV		; Previous level
		NUM	IMD		; Immediate level commands
		ENDNUM			; Define the max
	RHALF	CLN		; Length of the command in characters
	ENDSTR	XLN

; Define the length of the information section

DEFINE	$MAX(SYM,LIST)<
    SYM==0				;; Initialize the symbol
    IRP LIST,<
	IFG <LIST-SYM>,<SYM==LIST>
    >;; End of IRP LIST
>; End of $MAX macro definition

	$MAX	($CILEN,<$CIXLN,$CITLN>)
	SUBTTL	Data Base Definitions -- CRT - CRT block

; The following are the offsets for the CRT control block.  This block
; contains all the information for processing any CRT related function
; There is only one block inuse at a time, but these definitions are
; used to generate the blocks for that different CRTs, which are BLT'd
; into the main CRT block in the low segment.

	INTNUM	CR
	NUM	INT		; Initialization routine for the terminal
	NUM	LIN		; Number of lines on the scope
	NUM	WID		; Width of the scope
	NUM	WVT		; Width of a vertical tab
	NUM	WFF		; Width of a form feed
	NUM	BCK		; Backspace character sequence
	NUM	SPC		; Non-destructive forward cursor, or blank
	NUM	DBS		; Backup and delete sequence
	NUM	DLF		; Delete line feed
	NUM	DVT		; Delete vertical tab
	NUM	DFF		; Delete form feed
	NUM	DCR		; Delete CR string
	NUM	CRB		; String to cancel rubout
	NUM	CBS		; String to cancel backspace
	NUM	DSP		; Destructive space
	NUM	ERS		; Erase the screen

; Routines

	NUM	CTU		; Routine to process control U
	NUM	FIN		; Routine to reset terminal
	NUM	DEL		; Delete to end of line string
	NUM	XYP		; Routine address to do X and Y positioning
	NUM	DLL		; Routine to delete line
	NUM	INL		; Routine to insert line
	NUM	ICH		; Routine to cause a character to be inserted
	NUM	DCH		; Routine to cause a character(s) to be deleted
	NUM	TCH		; Routine to type a character
	$CRSUP==$CRINL		; Cause the screen to scroll up
	$CRSDN==$CRDLL		; Cause the screen to scroll down

; Cost function items

	NUM	CIN		; Return the initial cost
	NUM	CPP		; Cost of moving from point A to B
	NUM	CDC		; Cost of deleting a character
	NUM	CIC		; Cost of inserting a character
	NUM	CDL		; Cost of deleting a line
	NUM	CIL		; Cost of inserting a line
	NUM	CRP		; Cost of replacing a character
	NUM	CDE		; Cost of deleting to the end of the line

; Size of the block

	ENDNUM			; Define the max for the field
	SUBTTL	Data Base Definitions -- CST - Cost blocks

; The following is part of the cost matrix for updating the screen in video
; mode

;; !=========================================================================!
;; !Opr! Repeat count  !Terminal dependent info!            Cost             !
;; !=========================================================================!


	INTSTR	CST,CS,$

	BYT	OPR,	3	; Operation
		INTNUM	OP,0,CS$OPR	; Operation
		NUM	DCH		; Delete a character
		NUM	ICH		; Insert a character
		NUM	RCH		; Replace a character
		NUM	ACH		; Accept a character
		NUM	SUP		; Scroll up
		NUM	SDN		; Scroll down
		NUM	NOP		; No-op
		ENDNUM			; Define the max for the field
	BYT	RPT,	8	; Repeat count
	BYT	DEP,	11	; Terminal dependent informatin
	BYT	CST,	14	; Cost of the functins
	ENDSTR
	SUBTTL	Data Base Definitions -- CTB - Command table block

;+
;.hl2 CTB
;This CTB block is the definition of a command table that the FC TECO
;command defines and causes command input to use.
;-

;; !=========================================================================!
;; \                                                                         \
;; \                        Movable core block header                        \
;; \                                                                         \
;; !=========================================================================!
;; !                   Address of the previous CTB or zero                   !
;; !-------------------------------------------------------------------------!
;; !                  Address of the next CTB on the stack                   !
;; !-------------------------------------------------------------------------!
;; !               Address of the first CND block for commands               !
;; !-------------------------------------------------------------------------!
;; !            Address of the list of CNDs for the command table            !
;; !-------------------------------------------------------------------------!
;; !              TPT of the text block for this command table               !
;; !-------------------------------------------------------------------------!
;; !                 Character address of the ALWAYs option                  !
;; !-------------------------------------------------------------------------!
;; !                   Command type for the ALWAYs option                    !
;; !=========================================================================!


	INTSTR	CTB,CT,$,.BKMLN

	WORD	CTB,	$LKLEN	; Address of the previous CTB or zero
	WORD	STK,	$LKLEN	; Address of the next CTB on the stack
	WORD	CMD,	$TPLEN	; Address of the first CND block for commands
	WORD	CND,	$LKLEN	; Address of the first CND in the CND linked list
	WORD	TPT,	$TPLEN	; TPT for the text block for this command table
	BYT	FLG,	9	; Flags
		INTFLG	CT,CT$FLG,$	; Define CT$xxx flags
		FLAG	ALF		; ALWAYS option given
		FLAG	OTF		; OTHER option given
	HALF	ATY		; ALWAYS command type
	HALF	ALN		; ALWAYS command length
	WORD	ALW		; Character address of the ALWAYS option
	HALF	OTY		; OTHER command type
	HALF	OLN		; OTHER command length
	WORD	OTH		; OTHER command character address
	ENDSTR
	SUBTTL	Data Base Definitions -- ERR - Error index block

;+
; This block describes the entries in the error index.
;-

;; !=========================================================================!
;; !   Level   !         Flags          !               Prefix               !
;; !-------------------------------------------------------------------------!
;; !            Address of the first line (Possible disk address)            !
;; !-------------------------------------------------------------------------!
;; !                     Address of continuation message                     !
;; !=========================================================================!


	INTSTR	ERR,ER,$

	BYT	LVL,	6	; Message level
	BYT	FLG,	12	; Flags
		INTFLG	ER,ER$FLG,$	; Generate the ER$xxx flags
		FLAG	DS1		; First line mesage is in disk file
		FLAG	DSC		; Continuation message is in disk file

	BYT	PFX,	18	; Prefix
	WORD	FST		; Address of the first line
	WORD	CON		; Continuaton message address 
	ENDSTR
	SUBTTL	Data Base Definitions -- FDB - File descriptor block

;+
;This block describes a TOPS-10 file specification.  All file operations
;that create, delete, append to otherwise do things to files (except read
;and write) require a FDB.
;-

;; !=========================================================================!
;; !                                Node name                                !
;; !-------------------------------------------------------------------------!
;; !                               Device name                               !
;; !-------------------------------------------------------------------------!
;; !                                File name                                !
;; !-------------------------------------------------------------------------!
;; !             Extension              !   Protection    !       Mode       !
;; !-------------------------------------------------------------------------!
;; !                           File version number                           !
;; !-------------------------------------------------------------------------!
;; !                        Project Programmer number                        !
;; !-------------------------------------------------------------------------!
;; !                           Sub-file directory                            !
;; !-------------------------------------------------------------------------!
;; !                        Second subfile directory                         !
;; !-------------------------------------------------------------------------!
;; !                         Third subfile directory                         !
;; !-------------------------------------------------------------------------!
;; !                        Fourth subfile directory                         !
;; !-------------------------------------------------------------------------!
;; !                         Fifth subfile directory                         !
;; !-------------------------------------------------------------------------!
;; !                                  Flags                                  !
;; !-------------------------------------------------------------------------!
;; ! Channel number  !      Flags       !             Error code             !
;; !-------------------------------------------------------------------------!
;; !                           Monitor I/O status                            !
;; !-------------------------------------------------------------------------!
;; !                       First word of buffer header                       !
;; !-------------------------------------------------------------------------!
;; !                        Byte pointer into buffer                         !
;; !-------------------------------------------------------------------------!
;; !                      Byte count for current buffer                      !
;; !-------------------------------------------------------------------------!
;; !           Address of FD            !Address of block containing buffers !
;; !-------------------------------------------------------------------------!
;; !                          Line sequence number                           !
;; !=========================================================================!


	INTSTR	FDB,FD,.,

	WORD	NOD		; This is the node name for the file (Make DECnet come true)
	WORD	DEV		; This is the device name for the file.
	WORD	NAM		; This is name of the file
	BYT	EXT,	18	; This is the file extension
	BYT	PRO,	9	; This is the file protection
	BYT	MOD,	9	; This is the mode of the file
		INTNUM	FM,0,FD.MOD	; Initialize the file modes
		DEFINE	FM$KEY,<
		FK	DFT,.ASCII,^D7	;; Default is ASCII
		FK	ASC,ASCII,^D7	;; ASCII
		FK	SXB,SIXBIT,^D6	;; SIXBIT
		FK	LSA,LSA,^D7	;; Line sequenced ascii
		FK	TRM,.TRM,^D7	;; Terminal mode
		FK	ERR,.ERR,^D7	;; For TECO.ERR
		FK	BIN,.BIN,^D36	;; Binary (internal only)
		FK	PIM,.PIM,^D8	;; Packed image mode
		FK	DMP,DUMP,^D36	;; Dump mode
		>; End of FM$KEY macro definition
		DEFINE	FK(A,B,C),<NUM (A)>
		FM$KEY			; Define the offsets
		ENDNUM			; Define the max for the field
	WORD	VER		; This is the file version number
	WORD	PPN		; This is the project-programmer number
	WORD	SFD		; First sub-file directory
	WORD	SF2		; Second sub file directory word
	WORD	SF3		; Third subfile directory
	WORD	SF4		; Fourth subfile directory word
	WORD	SF5		; Fifth subfile directory word
	WORD	FLG		; Flags
		FD.OPN==1B0		; File is open. Must be sign bit.
		INTFLG	FD,FD.FLG&^-FD.OPN,.	; Initialize the flags
		FLAG	HEX		; We have an extension
		FLAG	PTH		; We have a path
		FLAG	HPR		; Protection given
		FLAG	DEF		; Clear sticky defaults first
		FLAG	NDF		; Don't store any defaults
		FLAG	INP		; Edit the file INPLACE
		FLAG	NOI		; No TTY input from TTY in LOG file
		FLAG	NOL		; No LSN output
		FLAG	NOO		; No terminal type out to LOG file
		FLAG	SCN		; /SCAN in PATH block
		FLAG	TMP		; File is really from TMPCOR
		FLAG	IN		; File is open for input
		FLAG	OUT		; File is open for output
		FLAG	EOF		; End of file encountered
		FLAG	EOL		; Last thing output was an EOL
		FLAG	PAG		; Start of a page
		FLAG	EB		; EB in effect for this FDB
		FLAG	ENQ		; The file on this channel was ENQ.'ed
		FLAG	NDP		; File was not in the default path
		FLAG	NLS		; Need an line sequence number
		FLAG	TMD		; TMP file going to disk (TMPCOR
					; copy may need to be deleted)
		FLAG	NTT		; This is "TTY" but not controlling TTY

	BYT	CHN,	9	; The channel number for this file
	BYT	ERR,	9	; I/O error code
	RHALF	BUF		; Address of block containing buffers
	WORD	IOS		; Monitor I/O status
	WORD	BRH		; First word of monitor buffer header
	WORD	PTR		; Byte pointer into buffer
	WORD	CTR		; Byte count for current buffer
	WORD	LSN		; Current line sequence number
		.FDRCN==.FDLSN		; Overload LSN for SIXBIT files
		FD.RCN==FD.LSN		; Record number fo the SIXBIT files
		DEFST.	(FDBRCN,.FDRCN,FD.RCN) ; Define for LOAD./STOR. etc
	RHALF	FFC		; Form feed count (Page number)
	WORD	BLK		; Current block number
	WORD	SIZ		; Size of file in bytes
	ENDSTR


; Instructions to check if FDB has file open

;	OPDEF	SKPOPN	[SKIPL	.FDFLG] ; Skip if file open
;	OPDEF	SKPCLS	[SKIPGE	.FDFLG] ; Skip if file closed
;The above OPDEFs are the preferred method of doing this, but MACRO
;can't hack them with inter-PSECT symbol references. Until it is fixed
;the following macros will have to do.

	DEFINE SKPOPN(ADDR)<SKIPL .FDFLG+ADDR>
	DEFINE SKPCLS(ADDR)<SKIPGE .FDFLG+ADDR>
	SUBTTL	Data Base Definitions -- FIL - Fill time blocks

;+
;.HL1 Fill time block
; The fill time blocks are used by terminals which require fill characters
;to be sent while they are performing certain functions. This block
;gives the time the terminal takes to perform the functions (in milli-seconds)
;This information is used to determine the number of fill characters that
;must be sent after the function code.
;-
;; !=========================================================================!
;; !          Insert line time          !          Delete line time          !
;; !-------------------------------------------------------------------------!
;; !       Insert character time        !       Delete character time        !
;; !-------------------------------------------------------------------------!
;; !          Positioning time          !     Delete to end of line time     !
;; !-------------------------------------------------------------------------!
;; !         Erase screen time          !                                    !
;; !=========================================================================!


	INTSTR	FIL,FL,$

	LHALF	INL		; Time needed to insert a line
	RHALF	DLL		; Time needed to delete a line
	LHALF	INC		; Time needed to insert a character
	RHALF	DLC		; Time needed to delete a character
	LHALF	POS		; Time needed to do a positioning operation
	RHALF	DEL		; Time needed to delete to the end of a line
	LHALF	ERS		; Time needed to erase the screen
	ENDSTR

; Macro to define a fill table

DEFINE FILTBL(INSLIN,DELLIN,INSCHR,DELCHR,POSITN,DELEOL,ERASES),<

	$BUILD	FIL,$FLLEN	;; Initialize the macro
	IFNB <INSLIN>,<$SET(INL,^D<INSLIN>)> ;; Put in insert line time
	IFNB <DELLIN>,<$SET(DLL,^D<DELLIN>)> ;; And delete line time
	IFNB <INSCHR>,<$SET(INC,^D<INSCHR>)> ;; And insert character time
	IFNB <DELCHR>,<$SET(DLC,^D<DELCHR>)> ;; Delete character time
	IFNB <POSITN>,<$SET(POS,^D<POSITN>)> ;; Position cursor time
	IFNB <DELEOL>,<$SET(EOL,^D<DELEOL>)> ;; Delete to end of line time
	IFNB <ERASES>,<$SET(ERS,^D<ERASES>)> ;; Erase whole screen
	$EOB			;; End the block
> ; End of FILTBL macro
	SUBTTL	Data Base Definitions -- LDB - Line data block

;+
;.HL1 LDB
;A line data block is associated with each line displayed on the screen
;in video mode.
;.literal
;; !=========================================================================!
;; !              Text buffer address associated with this line              !
;; !-------------------------------------------------------------------------!
;; !             Character address of the beginning of the line              !
;; !-------------------------------------------------------------------------!
;; !                Character address of the end of the line                 !
;; !-------------------------------------------------------------------------!
;; !                    Address of the text on this line                     !
;; !=========================================================================!
;.end literal
;-


	INTSTR	LDB,LD,$

	WORD	BEG		; Character address of the beginning of the line
	WORD	END		; Character address of the end of the line
	HALF	QRG		; Address of the QRG block for this LDB
	HALF	LIN		; Line number on the screen
	HALF	TXT		; Address of the text on this line
	HALF	FLG		; Flags
		INTFLG	LD,LD$FLG,$	; Make LD$xxx symbols
		FLAG	WAP		; This line wraps around to the next
		FLAG	CRLF		; This line ends in a CRLF
		FLAG	SCR		; Line scrolled
		FLAG	FSC		; First line of command
		FLAG	CR		; Line ends with just a CR
		FLAG	CMD		; Line is part of command section
					; Set even in lines which scrolled
		FLAG	SME		; Line has not been changed for this update
					; used to avoid do char/char compares
		FLAG	ICA		; Invalid character addresses are stored on this line
	WORD	NUM		; Number of characters on this line
	ENDSTR
	SUBTTL	Data Base Definitions -- LNK - Linked list sub-block

;+
;.hl2 LNK
;This block is used for all linked lists.  It currently is used in the
;CDT and CND blocks.
;-

;; !=========================================================================!
;; !                        Previous pointer address                         !
;; !-------------------------------------------------------------------------!
;; !                          Next pointer address                           !
;; !=========================================================================!


	INTSTR	LNK,LK,$

	WORD	PRV		; Previous pointer addrss
	WORD	NXT		; Next pointer address
	ENDSTR
	SUBTTL	Data Base Definitions -- SPB - Switch pointer block

; The following is used to call the file specificatin parser.

;; !=========================================================================!
;; !                           IOWD switch pointer                           !
;; !-------------------------------------------------------------------------!
;; !      Address of the pointers       !       Address of the values        !
;; !-------------------------------------------------------------------------!
;; !      Routines to call address      !                                    !
;; !=========================================================================!


	INTSTR	SPB,SP,.

	WORD	NAM		; IOWD pointer to the switch names
	LHALF	PTR		; Address of the pointers to store the value
	RHALF	VAL		; Addrss of the values to store
	LHALF	RTN		; Address of the routines to call
	ENDSTR


DEFINE	SWTPTR(XXX),<
	$BUILD	SPB,.SPLEN	; Initialize the switch pointer block
	$SET	NAM,<XWD -'XXX'L,XXX'N> ; Set the name pointer
	$SET	VAL,XXX'V	; Store the address of the values
	$SET	PTR,XXX'P	; Store the address of the pointers
	$SET	RTN,XXX'R	; Store the routine table address
	$EOB			; Generate the block
>; End of SWTPTR macro definition
	SUBTTL	Data Base Definitions -- SYM - Symbol table entry -- General


;; !=========================================================================!
;; !                  Linked list pointer for the same type                  !
;; !-------------------------------------------------------------------------!
;; !                     Hash table overflow linked list                     !
;; !-------------------------------------------------------------------------!
;; !            Flags            ! Type !          Character count           !
;; !-------------------------------------------------------------------------!
;; !                        Text buffer pointer (TPT)                        !
;; !-------------------------------------------------------------------------!
;; !                      Symbol dependent information                       !
;; !-------------------------------------------------------------------------!
;; !                        Start of the symbol name                         !
;; !=========================================================================!


	INTSTR	SYM,SY,$,.BKMLN

	WORD	LNK,	$LKLEN	; Linked list pointer for the same symbol type
	WORD	NXT,	$LKLEN	; Hash table overflow linked list pointer
	BYT	FLG,	15	; Flags
	BYT	TYP,	3	; Symbol type
		INTNUM	SY,0,SY$TYP,$	; Initialize the types
		NUM	LBL		; Label (!xxxx!)
		NUM	REG		; Q-register
		ENDNUM			; Define the max for the field
	BYT	CNT,	18	; Character count
	WORD	TPT,	$TPLEN	; Pointer to the text buffer
	WORD	DEP		; Symbol dependent information
	WORD	NAM		; Start of the symbol name
	ENDSTR
	SUBTTL	Data Base Definitions -- SYM - Symbol table entry -- Label



;; !=========================================================================!
;; !            Character index into the text buffer of the label            !
;; !=========================================================================!


	INTSTR	SYM,SY,$,$SYDEP

	WORD	IDX		; Character index into the text buffer of the label
	ENDSTR	LLN
	SUBTTL	Data Base Definitions -- SYM - Symbol table entry -- Q-register

;+
;.hl2 Q-register dependent information
;The only Q-register dependent information s the address of the QRG block
;that this symbol table entry is associated with.
;-


;; !=========================================================================!
;; !                            QRG block address                            !
;; !=========================================================================!


	INTSTR	SYM,SY,$,$SYDEP
	WORD	QRG		; QRG block address
	ENDSTR	QLN
	SUBTTL	Data Base Definitions -- TPT - Text buffer pointer

; The following is the definition of the pointer word which points to a text
;buffer.

;; !=========================================================================!
;; !      Pointer to next pointer       !          Address of block          !
;; !=========================================================================!


	INTSTR	TPT,TP,$

	LHALF	NXT		; Pointer to next pointer to this text block
	RHALF	ADR		; The address of this text block
	ENDSTR
	SUBTTL	Data Base Definitions -- QRG - Pre-defined Q-register pointer

; This is the definition of the blocks for predefined Q-registers

;; !=========================================================================!
;; \                                                                         \
;; \                           Text pointer (TPT)                            \
;; \                                                                         \
;; !=========================================================================!
;; !   Line offset   ! Number of lines  !               Flags                !
;; !-------------------------------------------------------------------------!
;; !                  Value if this is a numeric Q-register                  !
;; !=========================================================================!


	INTSTR	QRG,QR,$

	WORD	TPT,	$TPLEN	; Text pointer
	BYT	OFS,	9	; Line offset on screen
	BYT	NLN,	9	; Number of lines on screen
	BYT	FLN,9		; Relative line to fix position on if QR$FIX is on
	BYT	DTP,9		; Data type of storage
		INTNUM	DT,0,QR$DTP,$	; Define $DTxxx symbols
		NUM	NUM		; Numeric value
		NUM	TXT		; Text value
		NUM	FCT		; FC command table
		ENDNUM			; Define the max, etc.
	WORD	FLG		; Flags
		INTFLG	QR,QR$FLG,$	; Define QR$xxx flags
		FLAG	VID		; Being displayed
		FLAG	UPD		; Bounds must be updated
		FLAG	DIS		; Can't be displayed
		FLAG	WRT		; Can't be written into
		FLAG	VLU		; Can't store a value into it
		FLAG	TXT		; Can't store text into it
		FLAG	DLC		; Display last CRLF if at Z
		FLAG	FIX		; Q-reg is fixed display
					; $QRVAL contains character address of
					; first character to be displayed
		FLAG	SHF		; Same as QR$FIX, but once only
		FLAG	FCT		; Can't store an FC table into it
		FLAG	PRD		; Predefined Q-reg
		FLAG	LQR		; Long Q-register name
		FLAG	EDT		; E. not allowed
	WORD	VAL		; Q-register value
	WORD	PDB,$TPLEN	; Pointer to previously displayed text
	WORD	QRN,$TPLEN	; Q-register name pointer
				; Either single character Q-reg name (QR$PRD+QR$LQR=0)
				; or byte pointer (QR$PRD=1)
				; Or TPT to symbol table entry (QR$LQR=1)
	ENDSTR
	SUBTTL	Data Base Definitions -- VIN - Video information blocks

; The following defines the block used to store the information which was
;set by an E$ command(s).  It stores the information on what is displayed
;where on the screen.

;; !=========================================================================!
;; !                      Number of lines in the block                       !
;; !=========================================================================!
;; !                               QRG address                               !
;; !=========================================================================!
;; \                                                                         \
;; \                            Rest of QRG info                             \
;; \                                                                         \
;; !=========================================================================!


	INTSTR	VIN,VI,$,.BKMLN

	WORD	NLN		; Number of lines in the block that follows
	WORD	QRG		; QRG address
	ENDSTR
	SUBTTL	Data Base Definitions -- XSB - XS stack entries

; The following defines the entries which are found on the XS stack.
;Note that this block is defined with negative offsets, so it can be
;used with the data still on the stack.

;; !=========================================================================!
;; !                                  Flags                                  !
;; !-------------------------------------------------------------------------!
;; !                    Loop count/error address/argument                    !
;; !-------------------------------------------------------------------------!
;; !                    Loop/buffer address or operation                     !
;; !-------------------------------------------------------------------------!
;; !                               Entry type                                !
;; !=========================================================================!


	INTSTR	XSB,XS,$,-4

	WORD	SVC		; Saved character for Q-reg scanning
	WORD	FLG		; Flags from F
		SYNSTR	FLG,GCH		; Get a character routine for Q-reg scanning
	WORD	ITC		; Loop iteration count
		SYNSTR	ITC,QRG		; Address of Q-reg to fetch chars from if Q-reg scan
		SYNSTR	ITC,ERA		; Also error address
		SYNSTR	ITC,ARG		; Argument for pending operator
	WORD	LOP,$TPLEN	; Loop address
		SYNSTR	LOP,BUF		; Text buffer address
		SYNSTR	LOP,OPR		; Pending operator
		SYNSTR	LOP,QAD		; Address of Q-reg TPT for $XEIQG
	WORD	TYP		; Entry type ($XExxx)
		INTNUM	XE		; Define $XExxx symbols
		NUM	NOP		; No operation
		NUM	PAR		; From open paren
		NUM	MAC		; From macro (M or EI commands)
		NUM	LOP		; From loop
		NUM	IQG		; From ^G level in insert string
		NUM	QQG		; From ^G level in Q-register name
		NUM	MEM		; Movable block pointer from TECMEM
		ENDNUM			; Define the max for the field
	IFN $XSTYP,<PRINTX ? Fix XSB defintion - $XSTYP is non-zero>
	ENDSTR

; Lengths of blocks for each type

	$XSPLN==<-$XSFLG>+1		; For $XEPAR blocks
	$XSMLN==<-$XSFLG>+1		; For $XEMAC blocks
	$XSLLN==<-$XSITC>+1		; For $XELOP blocks
	$XSQLN==<-$XSQAD>+1		; For $XEIQG blocks
	$XSNLN==<-$XSSVC>+1		; For $XEQQG blocks
	$XSCLN==<-$XSBUF>+1		; For $XEMEM blocks

; Macro to allocate a block on the XS stack.
; Usage:
;	ALCXSB(TYP,LEN)
; Note that this macro uses ac T1

DEFINE ALCXSB(TYP,LEN),<
	$ADJSP	XS,$XS'LEN	;; Allocate the space on the stack
	STORI.	$XE'TYP,T1,XSBTYP,(XS) ;; Store the block type
> ; End of ALCXSB

; Macro to allocate a TPT on the XS stack that will be returned when the
;current routine returns.
; This operates something like the FRAME. macro.

DEFINE STKTPT(ADDRESS,NAME),<
	DEFINE NAME<$XSBUF(XS)>
IFDIF <ADDRESS>,<T1>,<MOVE	T1,ADDRESS>
	PUSHJ	P,.SKTPT	;; Set up the TPT
> ; End of STKTPT definition

DEFINE	STKTPS(ARGS,%1,%2),<
	DEFINE	$$$STK(ADDRESS),<$STKTP(ADDRESS,\%1)>
	DEFINE	$STKTP(ADDRESS,NAME,OFFSET)
<	DEFINE NAME<$XSBUF+OFFSET-%2(XS)>
		IFB <ADDRESS>,<SETZ T1,>
		IFNB <ADDRESS>,<IFDIF <ADDRESS>,<T1>,<MOVE T1,ADDRESS>>
		PUSHJ	P,.SKTPT	;; Call the routine to generate the stack info
> ; End of $STKTP definition
	%1==0
	.XCREF	%1
	IRP <ARGS>,<$$$STK ARGS
		%1==%1+$XSCLN	;; Generate the new offset
		> ;; End of IRP ARGS
	%2==%1-$XSCLN
	.XCREF	%2
	SUPPRESS %1,%2

> ; End of STKTPS definition
	SUBTTL	Symbols -- Command states

; The following is the states for the first command.  This is done this
;way so the error recovery, and immediate commands.

	INTNUM	CS		; Command states

	NUM	NRM		; Normal state
	NUM	QUE		; Only question mark allowed (after error)
	NUM	QS1		; Question mark and first slash
	NUM	QS2		; Question mark and second slash
	ENDNUM			; Define the max for the field
	SUBTTL	Symbols -- F$OPEN function codes

	INTNUM	IO,0,FW.ORD,$	; Initialize

	NUM	REA		; Read a file
	NUM	WRI		; Write a file
	NUM	WRS		; Write a file / no superceed
	NUM	APP		; Append to a file
	NUM	DEL		; Delete a file
	ENDNUM			; Define the max for the field
	SUBTTL	Symbols -- File errors

;+
;.HL2 FERRORS
; This macro will define the various file errors for the F$xxxx routines.
;The second argument of the macro determines if there is a routine to process
;the error.
;-

DEFINE	FERRORS,<
FER	(NAD)		; File not on a disk
FER	(REA)		; Attempt to read from a file not opern for reading
FER	(WRI)		; Save as REA, except for writting
FER	(MON,R)		; Monitor error
FER	(NNS)		; No network support in this monitor
FER	(OPN)		; This file is not open
FER	(PRO)		; Protection is out of range
FER	(IVN)		; Illegal version number
FER	(IPS)		; Illegal path specification
FER	(DNN)		; Double node name is illegal
FER	(DDN)		; Double device name is illegal
FER	(SNT)		; SFDs nested too deeply
FER	(ELS)		; Extension longer than six characters
FER	(DEI)		; Double extension illegal
FER	(NSS)		; Null SFD specified
FER	(DFN)		; Double file name illegal
FER	(SRV)		; Switch requires a value
FER	(AMS)		; Ambigious switch name
FER	(UNS)		; Unknown switch name
FER	(UKW)		; Unknown keyword
FER	(AKW)		; Ambigious keyword
FER	(IMD)		; Illegal mode for device
FER	(NXD)		; Non-existent device
FER	(ITS)		; Illegal TMP: file specification
FER	(ITF)		; Illegal TMP: function
FER	(EOF)		; End of file encountered on input
FER	(CRS)		; Can not rename across structures
FER	(IVC)		; Illegal character in file specification
FER	(DIP)		; Device implies path, but a path was given
FER	(FAE)		; File already being edited
FER	(IOD)		; Illegal operation for dump mode file
>; End of FERRORS macro definition

	$FEMIN==100		; Minimum value
	INTNUM	FE,$FEMIN,FW.ORD,$	; Initialize
	DEFINE	FER(XXX),<NUM	(XXX)>
	FERRORS			; Expand the macro
	ENDNUM			; Define the max for the field
	SUBTTL	Symbols -- FC term types

; The following are the symbols for the different term types for the FC
;command.

	INTNUM	FT,0,RH.ALF,$	; Generate $FTxxx symbols
	NUM	CHR		; Character(s), mask in CHRMSK
	NUM	OTH		; OTHER keyword
	NUM	ALW		; Always keyword
	NUM	PLS		; A plus operator
;	NUM	STR		; A star operator
	NUM	ORB		; An or bar operator
	NUM	CLN		; A colon to start the command type/string
	ENDNUM			; Define the max
	SUBTTL	Symbols -- Terminal speeds

; The following symbols are defined for the different terminal speed.
;These were defined here since there were no symbols in UUOSYM.

DEFINE TSPEED,<
 ENT(50,4,.TO005)		;; 4 cps for 50 baud
 ENT(75,7,.TO007)		;; 6 cps for 75 baud
 ENT(110,10,.TO011)		;; 10 cps for 110 baud
 ENT(134,13,.TO013)		;; 13 cps for 134.5 baud
 ENT(150,15,.TO015)		;; 15 cps for 150 baud
 ENT(200,20,.TO020)		;; 20 cps for 200 baud
 ENT(300,30,.TO030)		;; 30 cps for 300 baud
 ENT(600,60,.TO060)		;; 60 cps for 600 baud
 ENT(1200,120,.TO120)		;; 120 cps for 1200 baud
 ENT(1800,180,.TO180)		;; 180 cps for 1800 baud
 ENT(2400,240,.TO240)		;; 240 cps for 2400 baud
 ENT(4800,480,.TO480)		;; 480 cps for 4800 baud
 ENT(9600,960,.TO960)		;; 960 cps for 9600 baud
 ENT(EXA,1000,.TOEXA)		;; assume about 1000 cps for external A
 ENT(EXB,1000,.TOEXB)		;; and external B
>; End of TSPEED macro defintion

DEFINE	ENT(NAM,CPS,IDX),<.TS'NAM'=='IDX>
	TSPEED		; Determine the speeds

	.TSMAX==17		; Max speed
	SUBTTL	Misc parameters

	; Search special symbol definitions

	BEGPAG==200		; Fake ASCII character -- Beginning of buffer
	ENDPAG==201		; Fake ASCII character -- End of buffer if not
				;   no EOL at end
	SPCTAB==202		; Fake ASCII character -- Signal to search
				;  for string of space/tabs

	SMATLN==^D131		; Number of characters in the search matricies
	BITMLN==SMATLN/^D36+1	; Number of words needed to hold SMATLN bits

	SUBTTL	Special symbols -- TRUE/FALSE

; The following are the true and false values used in this editor.
; These are the values stored for switches, returned from routines that return
; true and false and other miscellanious things.


	.TRUE==	1		; Item is true
	.FALSE==0		; Item is not true


	SUBTTL	Special symbols -- Characters

; These symbols are used for special characters

	.CHSPC==" "		; Space
	.CHLAB=="<"		; Left angle bracket
	.CHRAB==">"		; Right angle bracket
	.CHLPR=="("		; Left paren
	.CHRPR==")"		; Right paren
	SUBTTL	OPDEFS -- Screen mode checks

; These two opdefs are tests for special CRT processing

	OPDEF	JMPS	[JUMPL	S,]	; Jump if doing special screen stuff
	OPDEF	JMPNS	[JUMPGE	S,]	; Jump if not doing specail screen stuff
	OPDEF	SKPS	[TLNN	S,(S.SCRN)] ; Skip if screen mode
	OPDEF	SKPNS	[TLNE	S,(S.SCRN)] ; Skip if not screen mode

	IFG S.SCRN,<PRINTX ? S.SCRN must be 1B0 for JMPS and JMPNS to work>


	SUBTTL	OPDEFS -- True/False checks

; The following are macros that make checking the true and false flags
;very simple

	OPDEF	SKPT	[SKIPN]		; Skip if the value is true
	OPDEF	JMPT	[JUMPN]		; Jump if the value is true

	OPDEF	SKPF	[SKIPE]		; Skip if the value is false
	OPDEF	JMPF	[JUMPE]		; Jump if the value is false
	SUBTTL	OPDEFS -- Operating system dependent

; The following OPDEF the exit UUO and the HALTF JSYS, so that a single
; instruction can be used

TOPS10<
	OPDEF	$HALT	[MONRT.]	; Continuable exit
>; End of TOPS10

TOPS20<
	OPDEF	$HALT	[HALTF]		; Continuable exit
>; End of TOPS20
	SUBTTL	End of TECUNV

	END			; End of TECUNV