	.TITLE	INIT
	.IDENT	/BL1.0/
	.if df rt11
	.mcall	.date
	.iff
	.MCALL	GTIM$S
	.endc
;
;	Routine to initialize all the variables
;	and the FLAG set up routines
;
;
	.PSECT	$TABL,RO,D,LCL,CON
CLRTAB:	.WORD	FOTBF,TTLBF,STLBF,INXBF,IFBF	; Buffers to clear
	.WORD	TXDBF,IBUF1,ESCBF,0
DISTAB:	.WORD	$PERSW,$HSPSW,$KEEPT,$CONT,0	; Bytes to set to SW.DIS
;
;	DEFAULT FLAG TABLE
;		+100000=Flag disabled
;
FLTAB:	.WORD	'_		; FLAG ACCEPT
	.WORD	'<+100000	; FLAG CAPITALIZE ENABLE
	.WORD	'&		; UNDERLINE SWITCH
	.WORD	'\		; LOWERCASE SWITCH
	.WORD	'^		; UPPERCASE SHIFT SWITCH
	.WORD	'#		; QUOTED SPACE SWITCH
	.WORD	'%+100000	; OVERSTRIKE FLAG ENABLE
	.WORD	'>+100000	; INDEX FLAG ENABLE
	.WORD	'>+100000	; subindex flag enable
	.WORD	'=+100000	; FLAG HYPHENATE
	.WORD	'++100000	; Period flag
	.WORD	100000		; ESCAPE FLAG	
	.WORD	'$+100000	; substitute flag
	.WORD	'|+100000	; break flag
	.WORD	100000		; Special flag switch
	.WORD	'{+100000	; Equation flag
	.WORD	11		; Tabs flag
	.WORD	'.		; Control flag	
;
;	Addresses of flags
;
FLADD:	.WORD	$AFLSW
	.WORD	$CFLSW
	.WORD	$UFLSW
	.WORD	$LFLSW
	.WORD	$SFLSW
	.WORD	$QFLSW
	.WORD	$OFLSW
	.WORD	$IFLSW
	.WORD	$SIFSW
	.WORD	$HFLSW
	.word	$PFLSW		;Period flag
	.WORD	$EFLSW		; Escape flag
	.WORD	$SBFSW
	.WORD	$BRFSW
	.WORD	$SPFSW		; Special flag switch
	.WORD	$EQFSW		; Equation flag address
	.WORD	$TBFSW		; Tab flag \
	.WORD	$NFLSW		; Control  /  These must be last 2 entries!!
FLCHR:
NFLAG=<FLCHR-fladd>/2		; Number of flags
AFL=.-FLCHR
	.BYTE	GC.AFL
CFL=.-FLCHR
	.BYTE	GC.CFL
UFL=.-FLCHR
	.BYTE	GC.UFL
LFL=.-FLCHR
	.BYTE	GC.LFL
SFL=.-FLCHR
	.BYTE	GC.SFL
QFL=.-FLCHR
	.BYTE	GC.QFL
OFL=.-FLCHR
	.BYTE	GC.OFL
IFL=.-FLCHR
	.BYTE	GC.IFL
	.BYTE	GC.IFL
HFL=.-FLCHR
	.BYTE	GC.HFL
PFL=.-FLCHR
	.byte	GC.PFL		; Period flag
EFL=.-FLCHR
	.BYTE	GC.EFL
SBF=.-FLCHR
	.BYTE	GC.SUB
BRF=.-FLCHR
	.BYTE	GC.BRK
	.BYTE	GC.SPF
	.BYTE	GC.EQ1
TBF=.-FLCHR
	.BYTE	GC.TAB
	.BYTE	GC.MSC
	.BYTE	0
;
;	Table of default hyphenation punctuation
;
DEFPUN:	.byte	177
	.ASCIZ	0 /\.,()"@0
;
;	Default period puctuation
;
	.ASCIZ	/.;:?!/
;
;	Default equation flags
;
EQTAB:	.ASCIZ	/{}/
	.even
;
;	DEFAULT ESCAPE TABLE
;
;	The table consists of:
;		byte 1 = char count = n
;		byte 2+3 = escape key characters
;		bytes 4-n = escape controls
;		bytes n-m = escape sequence
;
ESTAB:	.IFDF	$FLORD
	.BYTE	6,'^,'>,ES.VSP,-1,ESC,'D	; 1/2 UP SHIFT
	.BYTE	6,'^,'<,ES.VSP,1,ESC,'U		; 1/2 DOWN SHIFT
	.BYTE	6,'^,'(,ES.VSP,-2,ESC,12	; Shift up by 1
	.BYTE	5,'^,'),ES.VSP,2,12		; Shift down by 1
	.BYTE	6,'^,'1,0,ESC,'I,2		; SELECT FONT #1
	.BYTE	6,'^,'2,0,ESC,'I,3		; FONT 2
	.BYTE	6,'^,'3,0,ESC,'I,4		; FONT 3
	.BYTE	6,'^,'4,0,ESC,'I,5		; FONT 4
	.BYTE	6,'^,'5,0,ESC,'I,6		; FONT 5
	.BYTE	6,'^,'8,0,ESC,'I,9.		; FONT 8
	.BYTE	6,'^,'*,ES.CHR!ES.LCK!ES.CHR,0,ESC,'W ; BEGIN SHADOW PRINT
	.BYTE	6,'\,'*,ES.LCK!ES.CHR,100,ESC,'&	; END SHADOW/BOLD PRINT
	.BYTE	6,'^,'=,ES.HSP!ES.PSP!ES.LCK!ES.CHR,0,2,16 ; SO BEGIN ELONGATED
	.BYTE	6,'\,'=,ES.HSP!ES.PSP!ES.LCK!ES.CHR,100,1,17	; SI END ELONGATED
	.ENDC
	.IFDF	$DIAB
	.BYTE	6,'^,'>,ES.VSP,-1,ESC,'D	; 1/2 UP SHIFT
	.BYTE	6,'^,'<,ES.VSP,1,ESC,'U		; 1/2 DOWN SHIFT
	.BYTE	6,'^,'(,ES.VSP,-2,ESC,12	; Shift up by 1
	.BYTE	5,'^,'),ES.VSP,2,12		; Shift down by 1
	.BYTE	6,'^,'!,ES.LCK,0,ESC,'3		; START GRAPHICS MODE
	.BYTE	6,'\,'!,ES.LCK,100,ESC,'4	; STOP GRAPHICS MODE
	.ENDC
ESEND:	.BYTE	0
LEVTAB:	.BYTE	3,1,LEVSIZ,LEVSIZ+1,LEVSIZ+1
	.byte	4,2,14,2,LEVSIZ		; Default style headers
	.byte	1,LEVSIZ,LEVSIZ		; Default autosubtit,enable lev.
CHTAB:	.BYTE	24.,2,6,-1,-1,0		; Default chapter style
CHPMP:	.ASCIZ	/CHAPTER /		; Chapter header prototype
	.ASCIZ	/APPENDIX /		; Appendix header prototype
	.ASCIZ	/Page  /		; Page pre-header
	.EVEN
TIMTB:	.WORD	HOUIN,MININ,SECIN,DAYIN,MONIN,YEAIN
MONTB:	.WORD	JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC
JAN:	.ASCIZ	/January/
FEB:	.ASCIZ	/February/
MAR:	.ASCIZ	/March/
APR:	.ASCIZ	/April/
MAY:	.ASCIZ	/May/
JUN:	.ASCIZ	/June/
JUL:	.ASCIZ	/July/
AUG:	.ASCIZ	/August/
SEP:	.ASCIZ	/September/
OCT:	.ASCIZ	/October/
NOV:	.ASCIZ	/November/
DEC:	.ASCIZ	/December/
;
;	Table of default up/down escape sequences
;
UPTAB:	.BYTE	ESC,'D,0
DNTAB:	.BYTE	ESC,'U,0
VSTAB:						; Variable spacing definition
	.ifndf	$12pt
	.BYTE	6,33,37,3,40,33,37,13.,0	; Varsp Diablo 10 
	.endc
	.ifdf	$12pt
	.BYTE	5,33,37,3,40,33,37,10.,0	; Varsp Diabl0 12 pitch
	.endc
	.even
	.PSECT	$VARS,RW,D,LCL,CON
SUBTAB:	.WORD	DATE-SUBTAB			; Scratch area
DATE:	.WORD	TIME0-SUBTAB
	.ASCIZ	/$DATE/
DATIN:	.BLKB	10.
TIME0:	.BYTE	YEAR-SUBTAB,0
	.ASCIZ	/$TIME/
TIMIN:	.BLKB	9.
YEAR:	.BYTE	MONTH-SUBTAB,0
	.ASCIZ	/$YEAR/
	.ASCII	/19/
YEAIN:	.BLKB	3
MONTH:	.BYTE	DAY-SUBTAB,0
	.ASCIZ	/$MONTH/
MONIN:	.BLKB	10.
DAY:	.BYTE	HOUR-SUBTAB,0
	.ASCIZ	/$DAY/
DAYIN:	.BLKB	3
HOUR:	.BYTE	MINUTE-SUBTAB,0
	.ASCIZ	/$HOURS/
HOUIN:	.BLKB	3
MINUTE:	.BYTE	SECOND-SUBTAB,0
	.ASCIZ	/$MINUTES/
MININ:	.BLKB	3
SECOND:	.BYTE	0,0
	.ASCIZ	/$SECONDS/
SECIN:	.BLKB	3
SECFIN:
	.EVEN
	.if df rt11
timblk:	.word	1		; One subroutine argument
	.word	timin		; Time string address
	.iff
DAYTIM:	.BLKW	8.
	.endc
	.PSECT	$CODE,I,RO,LCL,CON
;
; **- INITL-Initialize RUNOFF VARIABLES
;-
;
;	First clear whole list of variables
;
INITL::	MOV	#VARBEG,R0	; First variable
10$:	CLR	(R0)+		; Clear variables
	CMP	R0,#VAREND	; Done?
	BLO	10$		; No
	DECB	$FIRPG		; Make this the first page of document
	MOV	#JUSTF+PJUSTF+FILLF,F.1	;Initial FLAGS
;
;	Reset the FLAG characters in character table
;
	MOV	#127.,R0	; NUMBER OF ASCII CHARS
20$:	BICB	#CH.BRK!CH.FLG!CH.UNL!CH.PNC!CH.PER,CHTABL(R0)	; Clear all busy bits
	BITEQB	#CH.FLC,CHTABL(R0),30$	; NOT A FLAGGABLE CHARACTER?
	MOVB	#GC.MSC,GCTABL(R0)	; YES CLEAR ANY EXISTING FLAGS
30$:	SOB	R0,20$			; TILL DONE
;
;	Set permanent bits
;
	BISB	#CH.UNL+CH.BRK,CHTABL+32.	; Set space not underlinable
	BISB	#CH.UNL,CHTABL+NXS	; Set NXS not underlinable
	MOV	#CH.PNC,R2		; Set up punctuation
	MOV	#DEFPUN,R1		; Table
	CALL	TABSET			; set up bits in table
	MOV	#CH.PER,R2		; Set up period designation
	CALL	TABSET
;
;	Setup the FLAG characters
;
	CLR	R1		; Word pointer
	CLR	R0		; Nother pointer (byte)
50$:	MOV	FLTAB(R1),R3	; Get flag
	MOV	R3,@FLADD(R1)	; Load flag
	BLT	60$		; Flag disabled ?
	BISB	#CH.FLG,CHTABL(R3)	; Mark char as flag char
	MOVB	FLCHR(R0),GCTABL(R3)	; Set up branch to flag char.
60$:	ADD	#2,R1		; Next flag
	INC	R0		; Next flag
	TSTNEB	FLCHR(R0),50$	; Not done ?
;
;	ENABLE/DISABLE SWITCHES
;
	MOVB	#-1,$TOCSW	; Totally disable TOC
	MOVB	#SW.TDS,$UNLSW	; UNDERLINING ENABLED/OFF
	MOVB	#300,$CBRSW	; SET CHANGE BAR DISABLED/OFF
	MOVB	#SW.TDS,$HDRSW	; No header on first page
	MOV	#DISTAB,R0	; Disable table
65$:	MOV	(R0)+,R1	; Get entry to disable
	BEQ	66$		; None
	MOVB	#SW.DIS,(R1)	; Disable it
	BR	65$
;
;	Initialize various parameters
;
66$:	MOV	#3,HYPSV	; Potential savings by hyphenation
	MOV	#2,HYPLO	; Hyphenate after 2 chars only
	MOV	#3,HYPHI	; Hyphenate before 3 chars only
	MOV	#-5,HYPSZ	; Min size char for hyphenation
	MOV	IUL,ULSWT	; Initialize UNDERLINE MODE
	MOV	#HWPLN,LPPG	; SET DEFAULT HARDWARE PAGE SIZE
	MOV	#INLPG,PNLPG	; SET Initial LENGTH OF PAGE
	MOV	#IHSPAC*LINSP,HSPAC; Initial header spacing
	MOV	#ILMRG,PLMRG	; Permanent left margin
	MOV	#IRMRG,PRMRG	; Initial Permanent margin
	MOV	#ILMRG,LMARG	; Initial LEFT margin
	MOV	#IRMRG,RMARG	; Right margin
	MOV	#1,PHSP		; Set permanent horiz. spacing
	MOV	#1,LPHSP	; And last permanent
	MOV	#1,PHSPOU	; Set output horiz. spacing
	MOVB	#-1,CHLAY	; No chapter layout initially
	MOV	#100000,APNDSP	; appendix display format
	MOV	#100000,SUBDSP	; subpage display format
	MOV	#1,R0		; Next page number etc.
	MOV	R0,PAGENO	; SET Initial PAGE NUMBER
	MOV	R0,PAGNX	; And next page number
	MOV	R0,SUBNX	; Next subpage
	MOV	R0,CHPNX	; Next chapter
	MOV	R0,APNNX	; Next appendix
	MOV	#EQSTK+2,EQSTK	; Current equation stack pointer
;
;	Set up header level style
;
	MOV	#LEVTAB,R1	; Level default table
	MOV	#LINLV,R0	; Header level data table
	MOV	#13.,R2		; Number of params
70$:	MOVB	(R1)+,(R0)+	; Set levels to default
	SOB	R2,70$		; Set all of em
;
;	Set up default chapter style
;
	MOV	#CHTAB,R1
	MOV	#CHSK1,R0
	MOV	#6,R2
80$:	MOVB	(R1)+,(R0)+
	SOB	R2,80$
	MOV	#LSTK,LSTKP	; Reset stack pointer
	MOV	#CHPMG,R0	; Initialize chapter header
	MOV	#CHPMP,R1	; Header prototype
90$:	MOVB	(R1)+,(R0)+	; Move text
	BNE	90$		; Not null ?
	MOV	#APNMG,R0	; Appendix header
91$:	MOVB	(R1)+,(R0)+	; Move text
	BNE	91$		; Not null ?
	MOV	#PAGHD,R0	; Initialize PAGE HEADING PROTOTYPE
92$:	MOVB	(R1)+,(R0)+	; Move text
	BNE	92$		; Not null ?
	MOV	#ISPNG*LINSP,NSPNG; SET Initial SPACING
	MOV	NSPNG,PSPNG	; And permanent spacing
	MOV	#IPARTP,PARPT	; SET Initial PARAGRAPH PAGE TEST COUNT
	MOV	#IPARTP,PARTT2	; SET Initial PARAGRAPH PAGE TEST COUNT
	MOV	#IPARVS,PARSP	; SET Initial PARAGRAPH SPACING COUNT
	MOV	#IPARIN,PARIND	; Initial PARAGRAPH INDENTING
	MOV	#1,CPOS		; Current character position
;
;	Set up tab stops every 8 spaces
;
	MOV	#TABBF,R3	; Tab buffer
	CALL	CLRBF
	MOV	#8.,R4		; SET Initial TAB STOP VALUE
	MOV	#20.,R5		; Number of tabs to set
100$:	MOV	R4,R1		; Then tab stop number
	CALL	PWRD		; Put into table
	ADD	#8.,R4		; ADVANCE TO NEXT TAB STOP
	CLR	R1		; Zero status
	CALL	PBYT		; Into buffer
	SOB	R5,100$		; Continue till done
	MOV	BUFADD,BUFAD	; Input buffer address
	MOV	#-1,HGHPAG
	MOV	#-1,HGHCHP	; hi chapter limit
	MOV	#-1,HGHAPN	; default highest appendix #
	CALL	HDSVST		; Save all header status
	CLRB	$HDSTS		; Set autostatus enabled
;
;	SET BUFFERS TO EMPTY
;
	CALL	ULBSET		; RESET UNDERLINE BUFFER
	MOV	#CLRTAB,R2	; Table of buffers to clear
205$:	MOV	(r2)+,R3	; Buffer to clear
	BEQ	206$		; None ?
	CALL	CLRBF		; Clear it
	BR	205$
206$:	CLRB	SUBSTK		; no substitution in progress
	MOVB	#SUBLEV*2,SUBSTK+1	; Set up stack
;
;	Set up default escape sequences
;
	MOV	#UPTAB,R0	; Source
	MOV	#UPMOV,R1	; Destination
	CALL	SAVIT
	MOV	#DNTAB,R0	; Source
	MOV	#DNMOV,R1	; Destination
	CALL	SAVIT
	MOV	#VSTAB,R0
	MOV	#VARESC,R1	; Variable spacing escape table
	CALL	SAVIT
	MOV	#ESCTAB,R4
	MOV	#17.,R0		; Number of char to clear
102$:	CLRB	(R4)+		; Clear char
	SOB	R0,102$		; Till done
;
;	Set up default escape sequences
;
	MOV	#ESCBF,R3	; escape table buffer
	MOV	#ESTAB,R2	; default escape sequences
	MOV	#ESCTAB,R4	; To save locked sequences
101$:	MOVB	(R2)+,R1	; Count ?
	BEQ	109$		; Done ?
	MOV	R1,R5		; Save counter
	CALL	PBYT		; Save in buffer
	DEC	R5
	MOVB	(R2)+,R1	; Get byte first char
	CALL	PBYT		; Save it
	DEC	R5
	MOVB	(R2)+,R1	; Get byte second escape char
	MOVB	R1,(R4)		; Save character
	CALL	PBYT		; Save in buffer
	DEC	R5
	MOVB	(R2)+,R1	; Options character
	CALL	PBYT		; Save it
	BITEQB	R1,#ES.LCK,105$	; Not lock ?
	DEC	R5
	MOVB	(R2)+,R1	; Get lock byte
	BNE	103$		; Already defined ?
	INC	R4		; Point to next empty slot
103$:	ADD	R4,R1
	SUB	#ESCTAB+1,R1	; Get index
	CLC
	ASL	R1		; 2 word index
	CALL	PBYT
105$:	MOVB	(R2)+,R1	; Get 1 char
	CALL	PBYT		; And save it
	SOB	R5,105$		; Continue with rest of escape seq
	CMP	R2,#ESEND	; At end of seq
	BLO	101$		; Not yet
109$:	CLRB	(R4)
	MOV	INI$SW,$SWTCH	; Initial SWITCH SETTINGS
	.ifdf	$PASS
	BITEQB	#SW.DIS,$OUTSW,210$; First or only pass ?
	RETURN
	.endc
210$:	MOV	#SUBF0,R3	; Clear main subs. buffer
	CALL	CLRBF
;
;	Set up default substitutions
;
	.if df rt11
	mov	#timblk,r5	; Point r5 to time argument block
	call	time		; Call SYSLIB subroutine for ASCII time
;
	mov	#datin,r5		;Point r5 to ascii string address
	.date				;Return system date in r0
;
;	Form ASCII day
;
	mov	r0,r3			;Put date word in r3
	beq	111$			;Invalid date
	ash	#-5.,r3			;Right justify day of month
	bic	#^C37,r3		;Clear all but lower 5 bits
	clr	r2			;Clear upper 16 bits for divide
	div	#10.,r2			;Divide day of month by ten
	beq	1$			;Day of month less than 10
	add	#'0,r2			;Make tens digit ascii
	movb	r2,(r5)+		;Save ascii number in string
1$:	add	#'0,r3			;Make ones digit ascii
	movb	r3,(r5)+		;Save ascii number in string
	movb	#'-,(r5)+		;Insert dash
;
;	Form ASCII month
;
	mov	r0,r3			;Put date word in r3
	ash	#-9.,r3			;Almost Right justify month of year
	bic	#^C36,r3		;Clear all but bits 1-4
	mov	montb-2(r3),r2		;Point r2 to ascii month
	mov	r2,r1			;Point r1 to month
	movb	(r2)+,(r5)+		;Save ascii characters in string
	movb	(r2)+,(r5)+		;Save ascii characters in string
	movb	(r2)+,(r5)+		;Save ascii characters in string
	movb	#'-,(r5)+		;Insert dash
;
;	Form ASCII year
;
	mov	r0,r3			;Put date word in r3
	bic	#^C37,r3		;Clear all but lower 5 bits
	add	#72.,r3			;Form last two digits of year
	clr	r2			;Clear upper 16 bits
	div	#10.,r2			;Divide year by ten
	add	#'0,r2			;Make tens digit ascii
	movb	r2,(r5)+		;Save ascii number in string
	add	#'0,r3			;Make ones digit ascii
	movb	r3,(r5)+		;Save ascii number in string
	clrb	(r5)			;Make string ASCII
	.iff
	GTIM$S	#DAYTIM
	MOV	#DATIN,R0	; Location for date
	MOV	#DAYTIM,R1	; Date time table
	CALL	$DAT		; Get date
	CLRB	(R0)+		; Chock with null
	MOV	#TIMIN,R0	; Location for time
	MOV	#3,R2		; Convert to HR:MIN:SEC
	CALL	$TIM		; Convert
	CLRB	(R0)+		; Chock with null
	MOV	DAYTIM+G.TIMO,R1 ; Get month
	ASL	R1		; Byte reference
	BEQ	111$		; Bad month ?
	MOV	MONTB-2(R1),R1	; Points to month
	.endc
	MOV	#MONIN,R0	; Will be month
110$:	MOVB	(R1)+,(R0)+	; Move month
	BNE	110$		; Till all done
111$:	MOV	#TIMIN,R0	; Location of time
	MOV	#TIMTB,R2	; Table of time conversion
120$:	MOV	(R2)+,R1	; Next location to move time to
121$:	MOVB	(R0)+,R3	; Get char
	BEQ	124$		; Done ?
	CMPEQB	R3,#':,123$	; End of chars ?
	MOVB	R3,(R1)+	; Save char
	BR	121$
123$:	CLRB	(R1)+		; Mark end
	BR	120$
124$:	CLRB	(R1)+		; Mark end
	MOV	#DATIN,R0
	MOV	(R2)+,R1	; Next location to move date to
	MOVB	(R0)+,(R1)+	; Move day
	CLRB	(R1)		; Clear next byte in case
	CMPEQB	(R0),#'-,125$	; No more day ?
	MOVB	(R0)+,(R1)+	; Move day
125$:	MOVB	#' ,(R0)+	; Insert blank
	MOV	(R2)+,R1	; Next location to move date to
	MOVB	(R1)+,(R0)+	; Move month
	MOVB	(R1)+,(R0)+	; Move month
	MOVB	(R1)+,(R0)+	; Move month
	MOVB	#' ,(R0)+	; Insert blank
	MOV	(R2)+,R1	; Next location to move date to
	MOVB	(R0)+,(R1)+	; Move year
	MOVB	(R0)+,(R1)+	; Move year
	MOV	#SUBF0,R3	; Buffer to put substitution in
	MOV	#SUBTAB,R4	; Buffer to transfer
130$:	MOVB	(R4)+,R1	; Byte to transfer
	CALL	PBYT		; Into substitution buffer
	CMP	R4,#SECFIN	; Done ?
	BLO	130$		; Not yet ?
	CALL	BEGBF		; Back at beginning
	RETURN			; 
;
;	Subroutine to move string (R0) to (R1) stop at zero byte
;
SAVIT:	MOVB	(R0)+,(R1)+	; Move bytes
	BNE	SAVIT		; Non zero byte ?
	RETURN
;
;	Sets up table bits
;
TABSET:	MOVB	(R1)+,R0	; Get next entry
	BNE	10$		; Not last ?
	RETURN
10$:	BISB	R2,CHTABL(R0)	; Set bit in table
	BR	TABSET		; Continue till done
;
;	FLAGS ACCEPT COMMANDS (QUOTING CHARACTERS)
;
ENACFL:: MOV	#AFL,R5		; ACCEPT FLAG	
	BR	NEWFLG		; GET AND ENABLE IT
DSACFL::MOV	#AFL,R5		; DISABLE ACCEPT FLAG
	BR	KILFLG
 
;
;	FLAGS SPACE COMMANDS    (QUOTED SPACE)
;
ENQFL::	MOV	#QFL,R5		; QUOTED SPACE FLAG
	BR	NEWFLG		; GET AND ENABLE FLAG
DSQFL::	MOV	#QFL,R5		; DISABLE QUOTED SPACE
	BR	KILFLG
;
;	FLAGS UNDERLINE COMMANDS
;
ENUFL::	MOV	#UFL,R5		; UNDERLINE FLAG
	BR	NEWFLG		; GET AND ENABLE NEW FLAG
DSUFL::	MOV	#UFL,R5		; DISABLE UNDERLINE FLAG
	BR	KILFLG
;
;	FLAGS INDEX
;
ENIFL::	MOV	#IFL,R5
	BR	NEWFLG		; ENABLE INDEX FLAG
DSIFL::	MOV	#IFL,R5		; DISABLE INDEX FLAG
	BR	KILFLG
;
;	FLAGS SUBSTITUTE commands
;
ENSBFL:: MOV	#SBF,R5		; substitution flag enable
	BR	NEWFLG
DSSBFL:: MOV	#SBF,R5		; substitutuion flag disable
	BR	KILFLG
;
;	Flags period commands
;
ENPRFL:: MOV	#PFL,R5		; Period flag enable
	BR	NEWFLG
DSPRFL:: MOV	#PFL,R5		; Period flag disable
	BR	KILFLG
;
;	FLAGS OVERSTRIKE COMMANDS
;
ENOFL::	MOV	#OFL,R5		; ADDRESS TO PUT NEW FLAG
NEWFLG:	CALL	KILFLG		; FIRST KILL OLD FLAG
	CALL	SKPSP		; Get character
NEWF1:	BCS	10$		; None ?
	BITEQB	#CH.FLC,CHTABL(R1),2$ ; NOT LEGIT FOR FLAG??
	BITEQB	#CH.FLG,CHTABL(R1),5$ ; CHAR FREE FOR FLAGGING?
	MOV	#25.,R0		; Char already in use as flag
	BR	3$
2$:	MOV	#26.,R0		; Character may not be used as flag
3$:	JMP	ILCMA
5$:	MOVB	R1,(R2)		; SAVE NEW FLAG	
	BR	10$		; COMPLETE PROCESS
10$:	MOV	#FL.DIS,R4	; ENABLE FLAG BITS
	MOVB	(R2),R0		; flag character
	BISB	#CH.FLG,CHTABL(R0) ; SET FLAG THIS CHAR
NWFLG:	BIC	R4,(R2)		; CLEAR DISABLE BITS
	TSTNEB	1(R2),10$	; FLAG NOT ENABLED?
	MOVB	(R2),R0		; GET FLAG CHAR
	BEQ	10$		; NONE SO SKIP REST
	MOVB	FLCHR(R5),GCTABL(R0)	; Flag code into service table
10$:	RETURN					
DSOFL::	MOV	#OFL,R5		; DISABLE OVERSTRIKE FLAG
KILFLG: MOV	R5,R2
	ASL	R2		; Now is byte pointer
	MOV	FLADD(R2),R2	; Now have flag address
	MOVB	(R2),R0		; GET OLD FLAG
	BEQ	10$		; NONE
	MOVB	#GC.MSC,GCTABL(R0) ; KILL FLAG IN TABLE
	CMPNEB	R0,#TAB,5$	; Not tab ?
	MOVB	#GC.SPC,GCTABL(R0) ; Make it space
5$:	BICB	#CH.FLG,CHTABL(R0) ; SET NO FLAG THIS CHAR
10$:	BIS	#FL.DIS,(R2)	; NOW KILL THE FLAG
	RETURN
;
;	FLAGS CAPITALIZE commands
;
DSCFL::	MOV	#CFL,R5		; DISABLE WORD CAPITALIZE
	BR	KILFLG
ENCFL::	MOV	#CFL,R5		; SET UP FOR NEW FLAG
	CALL	UPCAS		; CLEAR CASE CONVERSION VALUE
	BR	NEWFLG		; SET NEW FLAG	
;
;	FLAGS UPPERCASE COMMANDS
;
ENSFL::	MOV	#SFL,R5		; UPPERCASE SHIFT FLAG
	BR	NEWFLG		; GET FLAG AND SET IT ON
DSSFL::	MOV	#SFL,R5		; DISABLE UPPERCASE FLAG
	BR	KILFLG
;
;	FLAGS BREAK
;
ENBRFL:: MOV	#BRF,R5		; enable break flag
	BR	NEWFLG
DSBRFL:: MOV	#BRF,R5		; disable break flag
	BR	KILFLG
;
;	FLAGS LOWERCASE COMMANDS
;
ENLFL::	MOV	#LFL,R5		; LOWER CASE SHIFT FLAG 
	BR	NEWFLG		; GET FLAG AND SET IT 
DSLFL::	MOV	#LFL,R5		; DISABLE LOWERCASE FLAG		
	BR	KILFLG
;
;	FLAGS ESCAPE
;
ENEFL::	MOV	#EFL,R5		; GGET ESCAPE FLAG
	BR	NEWFLG
DSEFL::	MOV	#EFL,R5		; DISABLE ESCAPE FLAG
	BR	KILFLG
;
;	CONTROL FLAG
;
ENNFL::	CALL	SKPSP		; Get character
	BCS	10$		; None ?
	BITEQB	#CH.FLC,CHTABL(R1),20$ ; NOT LEGIT FOR FLAG??
	MOVB	R3,$NFLSW	; CONTROL FLAG
10$:	RETURN
20$:	MOV	#26.,R0		; Character may not be used as flag
	JMP	ILCMA
DSNFL::	MOV	#-1,$NFLSW	; DISABLE CONTROL FLAG (NO MORE COMMANDS)
	RETURN
;
;	FLAGS HYPHENATE COMMANDS
;
ENHFL::	MOV	#HFL,R5		; HYPHENATE FLAG
	BR	NEWFLG		; GET NEW FLAG AND ENABLE
DSHFL::	MOV	#HFL,R5		; DISABLE HYPHENATION
	BR	KILFLG
;
;	FLAGS TAB
;
ENTBFL:: MOV	#TBF,R5		; enable TAB flag
	CALL	KILFLG
10$:	CALL	CCIN		; Get next input char
	CMPEQB	R1,#SPC,10$	; Space ?
	CMPEQ	R1,$NFLSW,20$	; Command flag ?
	CMPEQB	R1,#SEMI,20$	; Semicolon
	CMPEQB	R1,#CR,20$	; Carriage return
	CLC			; Char ok
	BR	40$
20$:	CALL	BKSPI		; Backspace over char
30$:	SEC			; Null result
40$:	JMP	NEWF1
DSTBFL:: MOV	#TBF,R5		; disable TAB flag
	JMP	KILFLG
;
;	FLAGS SPECIAL
;
ESPFL::	CALL	SKPSP		; Get character
	BCS	20$		; None ?
	BITEQB	#CH.FLC,CHTABL(R1),30$ ; NOT LEGIT FOR FLAG??
	BITNEB	#CH.FLG,CHTABL(R1),40$ ; Char not free for flagging ?
	MOVB	#GC.SPF,GCTABL(R1)		; Set special flag
	BISB	#CH.FLG,CHTABL(R1)		; And set flag allocated
	BR	ESPFL		; Look for another
20$:	BIC	#FL.DIS,$SPFSW			; Set special flag enabled
	RETURN
30$:	MOV	#26.,R0		; Char is illegal as flag
	BR	41$
40$:	MOV	#25.,R0		; Char is already flag
41$:	JMP	ILCMA
DSPFL::	CALL	SKPSP		; Get character
	BCS	20$		; None ?
10$:	CMPNEB	GCTABL(R1),#GC.SPF,30$	; Not already special flag ?
	MOVB	#GC.MSC,GCTABL(R1)		; Kill special flag
	BICB	#CH.FLG,CHTABL(R1)		; And set flag free
	CALL	SKPSP		; Get another character
	BCC	10$		; got one ?
	RETURN
20$:	BIS	#FL.DIS,$SPFSW	; Set special flag disabled
	RETURN
30$:	MOV	#34.,R0
	JMP	ILCMA
;
;	FLAGS SUBINDEX commands
;
ENSIFL::CALL	SKPSP		; Get character
	BCS	20$		; None ?
	BITEQB	#CH.FLC,CHTABL(R1),30$ ; NOT LEGIT FOR FLAG??
	MOVB	R1,$SIFSW
20$:	BIC	#FL.DIS,$SIFSW	; Set subindex flag enabled
	RETURN
30$:	MOV	#26.,R0		; Char is illegal as flag
	JMP	ILCMA
DSSIFL::BIS	#FL.DIS,$SIFSW	; Set subindex  flag disabled
	RETURN
;
;	FLAGS ALL commands
;
ENAFL:: MOV	#FL.ALL,R4	; BITS TO CLEAR
ENAFL1:	MOV	#NFLAG-2,R5	; Kill all flags except for last
	MOV	#FLADD,R2	; Flag address
10$:	BIC	R4,@(R2)+	; NOW KILL THE FLAG
	SOB	R5,10$		; Not done ?
	RETURN
;
;	DISABLE FLAGS ALL or NO FLAGS ALL
;
DSAFL::	MOV	#FL.ALL,R4	; BITS TO SET/RESET
DSAFL1:	MOV	#NFLAG-2,R5	; Kill all flags except for last
	MOV	#FLADD,R2	; Flag address
10$:	BIS	R4,@(R2)+	; NOW KILL THE FLAG
	SOB	R5,10$		; Not done ?
	RETURN			;
;
;	LITERAL command
;
LITRL::	MOV	F.1,LITSV	; SAVE CURRENT FLAGS WORD
	BIS	#LITFG,F.1 	; SET LITERAL FLAG
	MOV	#ELCMD,CMADR	; SET ADDRESS OF EXPECTED COMMAND
	CLR	CMADR+2
	BIC	#FILLF+JUSTF,F.1 ;TURN OFF FILLING AND JUSTIFYING
	BISB	#20,$KEEPL	; Set to keep lines
	MOV	#FL.LIT,R4	; DISABLE FLAGS BITS
	BR	DSAFL1		; KILL THEM
;
;	END LITERAL command
;
ELTRL::	BITEQ	#LITFG,F.1,20$	; Not in literal mode?
	MOV	LITSV,F.1	; RESTORE PREVIOUS FLAGS WORD
	BICB	#20,$KEEPL	; Set to not keep lines
	MOV	#FL.LIT,R4	; FLAGS BITS TO CLEAR
	BR	ENAFL1		; ENABLE FLAGS AGAIN
20$:	MOV	#31.,R0		; Literal error
	JMP	ILCMA		; No .LIT commmand
;
;	SAVE	HEADER
;
HDSVST::CALL	SSTATS		; Save status
	MOV	#SW.DIS,R0
	BISB	R0,$TABSW	; Turn off tabs
	BISB	R0,$HDSTS	; Turn off auto header save
	MOV	#HDSTAT,R2	; Address of save buffer
	JMP	SSTAT		; Save status
;
;	ENABLE EQUATION
;
ENEQU::	BICB	#SW.DIS,$EQUSW		; Enable equations
	CALL	(R4)			; Get equation index
	JMP	50$			; No params
	CMP	R3,#6			; Too big ?
	BHI	EQERR0			; Yes ?
	MOV	R3,EQSPC		; Set equation spacing
50$:	RETURN
;
;	DISABLE EQUATION
;
DSEQU::	BISB	#SW.DIS,$EQUSW		; Disable equations
	RETURN
;
;	EQUATION/END EQUATION commands
;
BEGEQ::	BISB	#SW.DIS,$SEQSW		; Enable separated equations
	RETURN
ENDEQ::	BICB	#SW.DIS,$SEQSW		; Disable separated equations
	RETURN
;
;	FLAGS EQUATION
;
EQERR0:	JMP	ILCM			; Illegal command error
ENEQFL::MOV	#EQTAB,R0		; Equation character table
	TSTB	$EQFSW+1		; Flags already enabled ?
	BGE	50$			; Yes ?
10$:	MOVB	(R0)+,R1		; First character
	BEQ	20$			; Done ?
	BITNEB	#CH.FLG,CHTABL(R1),60$	; Already in use ?
	BR	10$			; Try next
20$:	MOV	#EQTAB,R0		; Table again
30$:	MOVB	(R0)+,R1		; Character
	BEQ	40$			; Done ?
	BISB	#CH.FLG,CHTABL(R1)	; Set it as flag character
	BR	30$
40$:	MOV	#EQTAB,R0		; Now set up first character as trigger
	MOVB	(R0)+,R1		; Left braces
	MOVB	#GC.EQ1,GCTABL(R1)	; First flag character
	MOVB	(R0),R1			; right braces
	MOVB	#GC.EQ2,GCTABL(R1)	; second flag character
	BIC	#100000,$EQFSW
50$:	RETURN
60$:	MOV	#25.,R0			; Error message
	JMP	ILCMA
;
;	NO FLAGS EQUATION command
;
DSEQFL::TSTB	$EQFSW+1		; Flag set ?
	BLT	50$			; No
	BIS	#100000,$EQFSW		; Set equation flag off
	MOV	#EQTAB,R0		; Get character table
10$:	MOVB	(R0)+,R1		; Get character
	BEQ	50$			; Done ?
	BICB	#CH.FLG,CHTABL(R1)	; Reset flag characters
	MOVB	#GC.MSC,GCTABL(R1)	; And pointers
	BR	10$
50$:	RETURN
;
;	ENABLE/DISABLE FLAGS ACCEPT COMMANDS (QUOTING CHARACTERS)
;
EFACFL:: MOV	#$AFLSW,R5		; ACCEPT FLAG
ENABLF:	BIC	#FL.ALL,(R5)		; GET AND ENABLE IT
	RETURN
DFACFL::MOV	#$AFLSW,R5		; DISABLE ACCEPT FLAG
DISABF:	BIS	#FL.ALL,(R5)		; GET AND DISABLE IT
	RETURN
;
;	ENABLE/DISABLE FLAGS EQUATION
;
EFEQFL:: MOV	#$EQFSW,R5		; EQUATION FLAG
	BR	ENABLF
DFEQFL::MOV	#$EQFSW,R5		; DISABLE EQUATION FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS period
;
EFPFL:: MOV	#$PFLSW,R5		; Period FLAG
	BR	ENABLF
DFPFL::	MOV	#$PFLSW,R5		; DISABLE period FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS SPACE COMMANDS    (QUOTED SPACE)
;
EFQFL::	MOV	#$QFLSW,R5		; QUOTED SPACE FLAG
	BR	ENABLF		; GET AND ENABLE FLAG
DFQFL::	MOV	#$QFLSW,R5		; DISABLE QUOTED SPACE
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS UNDERLINE COMMANDS
;
EFUFL::	MOV	#$UFLSW,R5		; UNDERLINE FLAG
	BR	ENABLF			; GET AND ENABLE NEW FLAG
DFUFL::	MOV	#$UFLSW,R5		; DISABLE UNDERLINE FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS INDEX
;
EFIFL::	MOV	#$IFLSW,R5
	BR	ENABLF			; ENABLE INDEX FLAG
DFIFL::	MOV	#$IFLSW,R5		; DISABLE INDEX FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS SUBINDEX
;
EFSIFL::MOV	#$SIFSW,R5
	BR	ENABLF			; ENABLE INDEX FLAG
DFSIFL::MOV	#$SIFSW,R5		; DISABLE INDEX FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS SPECIAL
;
EFSPFL::MOV	#$SPFSW,R5
	BR	ENABLF			; ENABLE SPECIAL FLAG
DFSPFL::MOV	#$SPFSW,R5		; DISABLE SPECIAL FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS SUBSTITUTE commands
;
EFSBFL:: MOV	#$SBFSW,R5		; substitution flag enable
	BR	ENABLF
DFSBFL:: MOV	#$SBFSW,R5		; substitutuion flag disable
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS TABS
;
EFTBFL::MOV	#$TBFSW,R5
	BR	ENABLF			; ENABLE TABS FLAG
DFTBFL::MOV	#$TBFSW,R5		; DISABLE TABS FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS OVERSTRIKE COMMANDS
;
EFOFL::	MOV	#$OFLSW,R5		; ADDRESS TO PUT NEW FLAG
	BR	ENABLF			; SET NEW FLAG	
DFOFL::	MOV	#$OFLSW,R5		; DISABLE OVERSTRIKE FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS CAPITALIZE commands
;
DFCFL::	MOV	#$CFLSW,R5		; DISABLE WORD CAPITALIZE
	BR	DISABF
EFCFL::	MOV	#$CFLSW,R5		; SET UP FOR NEW FLAG
	BR	ENABLF			; SET NEW FLAG	
;
;	ENABLE/DISABLE FLAGS UPPERCASE COMMANDS
;
EFSFL::	MOV	#$SFLSW,R5		; UPPERCASE SHIFT FLAG
	BR	ENABLF			; GET FLAG AND SET IT ON
DFSFL::	MOV	#$SFLSW,R5		; DISABLE UPPERCASE FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS BREAK
;
EFBRFL:: MOV	#$BRFSW,R5		; enable break flag
	BR	ENABLF
DFBRFL:: MOV	#$BRFSW,R5		; disable break flag
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS LOWERCASE COMMANDS
;
EFLFL::	MOV	#$LFLSW,R5		; LOWER CASE SHIFT FLAG 
	BR	ENABLF			; GET FLAG AND SET IT 
DFLFL::	MOV	#$LFLSW,R5		; DISABLE LOWERCASE FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS ESCAPE
;
EFEFL::	MOV	#$EFLSW,R5		; GGET ESCAPE FLAG
	BR	ENABLF
DFEFL::	MOV	#$EFLSW,R5		; DISABLE ESCAPE FLAG
	BR	DISABF
;
;	ENABLE/DISABLE FLAGS HYPHENATE COMMANDS
;
EFHFL::	MOV	#$HFLSW,R5		; HYPHENATE FLAG
	BR	ENABLF			; GET NEW FLAG AND ENABLE
DFHFL::	MOV	#$HFLSW,R5		; DISABLE HYPHENATION
	BR	DISABF
	.END
