	.TITLE	STYLE
	.SBTTL	/BL1.0/
;
;	This module contains the following commands
;
;	AUTOSUBTITLE
;	AUTOBREAK
;	DISPLAY commands
;	LAYOUT
;	LOCK
;	NUMBER commands
;	PAGING
;	SAVE STATUS
;	STYLE
;	TOC	Table of contents commands
;	UNDERLINE
;
	.PSECT	$TABL,RO,D,CON,LCL
CRTAB:	.BYTE	CR,LF
LAYTB:	.BYTE	16.			; Max value
	.BYTE	0			; 0 layout
	.BYTE	LAY.NB!LAY.CP!LAY.CT	; 1
	.BYTE	LAY.NB!LAY.CP!LAY.OT	; 2
	.BYTE	LAY.NB!LAY.CP		; 3
	.BYTE	LAY.NB			; 4
	.BYTE	LAY.NB!LAY.CT		; 5
	.BYTE	LAY.NB!LAY.OP!LAY.CT	; 6
	.BYTE	LAY.NB!LAY.OP!LAY.OT	; 7
	.BYTE	LAY.NB!LAY.OP
	.BYTE	LAY.NB!LAY.OT
	.BYTE	LAY.NB!LAY.LP!LAY.CT
	.BYTE	LAY.NB!LAY.LP!LAY.OT
	.BYTE	LAY.NB!LAY.LP
	.BYTE	LAY.NB!LAY.RT!LAY.LP
	.BYTE	LAY.NB!LAY.RT!LAY.CP
	.BYTE	LAY.NB!LAY.RT!LAY.OP
	.BYTE	LAY.NB!LAY.RT
TOCTB1:	.BYTE	2,-1,-1,0,2,0
TOCTB2:	.BYTE	24.,2,6,-1,-1,0
STHDTB:	.Byte	3,1,6,7,7,4,2,7,2,6
	.EVEN
;
;	display table of formats
;
DSPTAB:	.RAD50	/  D/
	.WORD	0
LU:	.RAD50	/ LU/
	.WORD	100000
	.RAD50	/ LL/
	.WORD	120000
	.RAD50	/ LM/
	.WORD	130000
	.RAD50	/ RU/
	.WORD	140000
	.RAD50	/ RL/
	.WORD	160000
	.RAD50	/ RM/
	.WORD	170000
	.WORD	0		; end of table
APTAB:	.WORD	APNMG,APNDSP+1,APNM2
CHTAB:	.WORD	CHPMG,CHPDSP+1,CHPM2
NUTAB:	.WORD	PAGHD,PAGDSP+1,PAGH2
TTTAB:	.WORD	TTLHD1,0,TTLHD2
STTAB:	.WORD	STLHD1,0,STLHD2
LVTAB:	.WORD	1,LVHD1A,CHPDSP+2,LVHD1B
	.WORD	2,LVHD2A,CHPDSP+3,LVHD2B
	.WORD	3,LVHD3A,CHPDSP+4,LVHD3B
	.WORD	4,LVHD4A,CHPDSP+5,LVHD4B
	.WORD	5,LVHD5A,CHPDSP+6,LVHD5B
	.WORD	6,LVHD6A,CHPDSP+7,LVHD6B
	.WORD	0			; End of table

	.PSECT	$CODE,RO,I,LCL,CON
;
;	AUTOBREAK command
;
AUBRK::	BICB	#SW.DIS,$AUBRK	; Set autobreak on
	MOV	#CH.BRK+100000,R4	; Set autobreak
	BR	UNL1
NAUBRK::BISB	#SW.DIS,$AUBRK
	MOV	#CH.BRK,R4	; Clear autobreak
	BR	UNL1
;
;	UNDERLINE/NO UNDERLINE commands
;
UNLCH::	MOV	#CH.UNL,R4	; Set underline
	BR	UNL1
UNLNC::	MOV	#CH.UNL+100000,R4 ; Set no underline
UNL1:	CALL	GETLIT		; Get literal
	BCS	UNLEND		; No characters ?
10$:	MOVB	(R2)+,R0	; Get character specified
	CMP	R0,#SPC		; Printable char ?
	BLT	20$		; No ?
	TST	R4		; Type of action
	BMI	15$		; Set bit ?
	BICB	R4,CHTABL(R0)	; Clear bit
	BR	20$
15$:	BISB	R4,CHTABL(R0)	; Set bit
20$:	SOB	R1,10$		; Continue till done
UNLEND:	MOVB	CHTABL+32.,CHTABL+NXS	; Space and NXS have same attributes
	RETURN
UNLSP::	BICB	#CH.UNL,CHTABL+32.	; Set underline
	BR	UNLEND
UNLNS::	BISB	#CH.UNL,CHTABL+32.	; Set no underline
	BR	UNLEND
;
;	PAGING command
;
PGNG::	BICB	#SW.DIS,$PAGNG		; Turn on paging
	RETURN
;
;	NO PAGING command
;
NOPGNG::BISB	#SW.DIS,$PAGNG		; Turn off paging
	CLRB	$PAGPD			; No page pending
	MOVB	#-1,$PAGBR		; Not at top of page
	RETURN
;
;	SAVE STATUS
;
SAVU::	MOV	#USTAT,R2		; Address of user status
SSAV:	JMP	SSTAT			; Save it
;
;	RESTORE STATUS
;
RSTU::	MOV	#USTAT,R2		; Address of user status
	JMP	RSTAT
;
;	SAVE CHAPTER
;
CHSVST::MOV	#CHSTAT,R2		; Save chapter status
	BR	SSAV
;
;	SAVE APPENDIX
;
APSVST::MOV	#APSTAT,R2		; Save appendix status
	BR	SSAV
;
;	SAVE LEVEL
;
LVSVST::MOV	#LVSTAT,R2		; Save level status
	BR	SSAV
;
;	SEND TOC command
;
SENTC::	TSTNEB	$TOCSW,20$		; No TOC ?
	CALL	CCIN
	CMPEQB	R1,#SPC,SENTC		; Skip over spaces
	CMPEQB	R1,#TAB,SENTC		; And tabs
	MOV	BUFADD,R0		; Get input buffer address
	MOV	BF.ADD(R0),R1		; Get current address
	MOV	BF.CNT(R0),R2		; String count
	DEC	R2			; Omit CR,LF
	CALL	OUTTOC			; Output to TOC file
20$:	JMP	LCR
;
;	Enable/disable TOC
;
ENTOC::	BICB	#SW.DIS,$TOCSW		; Enable TOC
	RETURN
DSTOC::	BISB	#SW.DIS,$TOCSW		; Disable TOC
	RETURN
;
;	TOC command
;
BETOC::	MOVB	#-1,$TOCBE		; Signal TOC on
	MOV	#8.,LIDLV		; Left level indentation
	MOV	#8.,RIDLV		; Right indentation
	CLRB	BEGLV			; No spaces between levels
	CLRB	ENDLV			; No spaces between levels
	CLRB	TPGLV			; Clear level test page
	BISB	#SW.DIS,$CHPSW		; No chapter numbers
	CLR	NTABS			; Reset tabs
	BISB	#2,$TABLF		; Set for tab right
	MOV	#TOCTB1,R1		; Input table
	BIS	#FILLF,F.1		; Set fill
	BIC	#JUSTF,F.1
TOC1:	MOV	#CHSK1,R0		; Output table
	MOV	#6,R2			; Entries
10$:	MOVB	(R1)+,(R0)+		; SET IT UP
	SOB	R2,10$
	MOVB	#1,APNNX		; Next appendix number
	CLRB	APNDN
	MOVB	#1,CHPNX		; Next chapter number
	CLRB	CHPTN
	RETURN
;
;	END TOC command
;
ENDTOC:: MOV	#TOCTB2,R1		; New chapter format
	CLR	LIDLV			; No left margin for levels
	CLR	RIDLV			; No right margin for levels
	BICB	#2,$TABLF		; Set for tab left
	CLRB	$TOCBE			; Signal TOC off
	BICB	#SW.DIS,$CHPSW		; Allow chapter numbers
	MOVB	#2,BEGLV		; Reset level spacing
	MOVB	#1,ENDLV		; Reset level spacing
	MOVB	#7,TPGLV		; Restore level test page
	BIS	#JUSTF,F.1
	BR	TOC1

;
;	AUTOTITLE command
;
AUTTL::	BICB	#SW.DIS,$AUTTL	; Enable auto-title
	RETURN
NAUTL::	BISB	#SW.DIS,$AUTTL	; Disable auto-title
	RETURN
;
;	AUTOSUBTITLE commands
;
AUSTL::	BISB	#SW.DIS,$AUSTL	; Enable auto subtittle
	MOVB	STLLV,R3	; Get initial value
	CALL	(R4)		; Get input
	  MOVB	STLLV,R3	; Default
	MOVB	R3,STLLV	; Subtitle level number
	RETURN
NAUSTL:: BICB	#SW.DIS,$AUSTL	; Disable auto subtittle
	RETURN
;
;	lock parameters command
;
LOCKP::	BIS	#LCKF,F.1	; lock many params to current value
	RETURN
;
;	LAYOUT	command
;
LAYOU::	CALL	LAY		; Get layout + size
	BGT	10$		; No ?
	CLR	R0		; Set layout 0 as default
10$:	MOVB	R0,NXLAY	; Next layout
	MOVB	R0,PRLAY	; Permanent layout
	TST	R3		; Check for default
	BGE	20$		; Not default ?
	CLR	R3
	TSTEQB	R0,20$		; Layout 0 ?
	MOV	#3*LINSP,R3	; Reserve 3 lines
20$:	MOV	R3,NXEPSP	; Next End of page space
	MOV	R3,PREPSP	; Permanent page spacing
	RETURN
ERRGT:	MOV	#1,R0
	BR	ERR
ERRHI:	MOV	#8.,R0		; Number too big or negative
ERR:	JMP	ILCMA		; Output the error message
;
;	Subroutine to get layout,spacing
;		R0=layout	R3=spacing
;		-1=None specified
;
LAY:	CALL	(R4)		; Get layout number
	  JMP	10$		; No chapter layout
	CMPB	R3,LAYTB	; Too big?
	BHI	ERRHI		; Bad ?
	MOVB	LAYTB+1(R3),-(SP)	; Get layout
	BR	20$		; And complete layout
10$:	MOV	#-100,-(SP)	; Default layout
20$:	CALL	(R4)		; Get end-of-page spacing
	  MOV	#-10,R3		; Default
	INC	R3		; Add 1 to account for number
	CALL	CVSP		; Convert vertical spacing
	CMP	R3,#<MAXPS+1>*LINSP	; Check size
	BGT	ERRGT		; Too big ?
	MOVB	(SP)+,R0	; Restore Layout
	RETURN
;
;	CHAPTER LAYOUT
;
CLAYOU:: CALL	LAY		; Get layout + spacing
	MOVB	R0,CHLAY	; Get chapter layout
	BMI	20$
	TST	R3		; Spacing ?
	BGE	10$		; Not default
	MOVB	PREPSP,R3	; Get regular spacing
10$:	MOVB	R3,CHEPSP	; Next End of page space
20$:	RETURN

;
;	Trace command
;
TRACE::	CALL	(R4)
	JMP	100$		; No params
100$:	MOV	#42.,R0		; Message to output
	JMP	ILCMA
;
;	STYLE HEADERS COMMAND
;
STYHD:: MOV	#LINLV,-(SP)	; Current variable
	MOV	(SP),R1		; Variables
	MOV	#STHDTB,R0	; Constants to default to
	MOV	#10.,R2		; Number of variables
10$:	MOVB	(R0)+,(R1)+	; Transfer 1 value
	SOB	R2,10$		; Till done
	MOVB	TPGLV,R0	; Get test page
	ADD	PARPT,R0	; Add on paragraph test page
	MOVB	R0,TPGLV	; Now is default test page
	CALL	GETP1		; Get header level # 1 Max run in title
	CALL	GETP1		; Get header level # 2 Max all uppercase
	CALL	GETP1		; Get header level # 3 Max capitalized
	CALL	GETP1		; Get header level # 4 Min no seq numbers
	CALL	GETP1		; Get header level # 5 Min flush left
	CALL	GETP0		; Get blank lines befor section head
	CALL	GETP0		; Blank lines after section head
	CALL	GETP1		; Test page count
	CALL	GETP1		; Spaces between number and title
	CALL	GETP1		; Highest level as a.b
	TST	(SP)+		; Pop
	RETURN
;
;	INDENT LEVELS command
;
INDLV:: MOV	#LIDLV,-(SP)	; Current variable
10$:	CALL	(R4)		; Get header level number
	  MOVB	@(SP),R3	; keep old value as default
	TST	R3		; Waste 1 instruction
	CMP	R3,#20.		; Too big?
	BHI	ERRHI		; Yes
	MOVB	R3,@(SP)	; Save it
	ADD	#2,(SP)		; Next variable
	CMP	(SP),#RIDLV	; End?
	BLOS	10$		; Not yet
	TST	(SP)+		; Pop
	RETURN
;
;	STYLE CHAPTER
;
GETNUM:	CALL	(R4)		; Get header level number
	  JMP	10$		; Default
	CMP	R3,#20.		; Too big?
	BGT	ERRGT		; Yes
	CMP	R3,#-20.	; Too small?
	BLT	ERRLT		; Yes
	RETURN
10$:	TST	(SP)+		; Dump return
	BR	GETP3
GETP0:	CALL	GETNUM		; Get number
	TST	R3
	BLE	GETP2		; Negative ?
	CALL	CVSP
	BR	GETP2
GETP1:	CALL	GETNUM		; get number
GETP2:	MOVB	R3,@2(SP)	; Save it
GETP3:	INC	2(SP)		; Next var
	RETURN
STYCH:: MOV	#CHSK1,-(SP)	; Current variable
	CALL	GETP0		; Get spacing
	CALL	GETP0		; Get spacing
	CALL	GETP0		; Get spacing
	CALL	GETP1		; Get indentation
	CALL	GETP1		; Get indentation
	CALL	GETP1		; Get indentation
	TST	(SP)+		; Pop address
	RETURN
ERRLT:	MOV	#2,R0		; Param too small
	JMP	ILCMA
;
;	ENABLE LEVELS
;
ENALV::	MOVB	OUTLV,R3	; First value
	CALL	(R4)		; Get new value
	  MOV	#6,R3		; Default
	MOVB	R3,OUTLV	; Set up new levels to enable
	MOVB	TOCLV,R3	; First value
	CALL	(R4)		; Get new value
	  MOV	#6,R3		; Default
	MOVB	R3,TOCLV	; Set up new levels to enable
	RETURN


;
; NUMBER APPENDIX COMMAND
;
NAPDX::	MOVB	APNNX,R3	; next appendix value
	CALL	NUPAGB		; get new value
	CMP	R3,#255.	; too big
	BHIS	NUMER		; yes
	MOVB	R3,APNNX	; save next value
	RETURN			; 
;
;	NUMBER CHAPTER COMMAND
;
NCHPT::	MOVB	CHPNX,R3	; next chapter number
	CALL	NUPAGB		; GET CHAPTER NUMBER
	CMP	R3,#255.	; LEGAL CHAPTER NUMBER?
	BHIS	NUMER		; yes
	MOVB	R3,CHPNX	; SET FOR NEXT CHAPTER COMMAND
	BITNE	#LCKF,F.1,10$	; parameters locked
	BICB	#SW.TDS,$CHPSW	; enable chapter numbers
10$:	RETURN			; 
NOCHP:: BITNE	#LCKF,F.1,10$	; params locked?
	BISB	#SW.TDS,$CHPSW	; disable chapter numbers
	CLR	CHPTN		; turn off chapter/appendix numbers
	CLR	APNDN
10$:	RETURN
;
;	ENABLE NUMBERING CHAPTER
;
ENMCH::	BICB	#SW.TD2,$CHPSW	; Enable chapter numbering
	RETURN
DNMCH::	BISB	#SW.TD2,$CHPSW	; Disable chapter numbering
	RETURN
;
;	NUMBER PAGE commands
;
NUMON:: MOV	PAGNX,R3	; get next page number
	CALL	NUPAG0		; Get new page number
	CMP	R3,#4000.	; Too big?
	BHIS	NUMER		; yes
	INCB	$SETPG		; Note page renumbered
	MOV	R3,PAGNX	; next page number
	BITNE	#LCKF,F.1,10$	; params locked?
	BICB	#SW.TDS,$NUMSW	; TURN on NUMBERING.
10$:	RETURN			; 
NUMOF::	BITNE	#LCKF,F.1,10$	; params locked?
	BISB	#SW.TDS,$NUMSW	; TURN OFF NUMBERING.
10$:	RETURN			; 
NUMER:	JMP	ERRHI		; Numbering error
;
;	ENABLE NUMBERING
;	DISABLE NUMBERING
;
ENMPG::	BICB	#SW.TD2,$NUMSW	; Enable page numbering
	RETURN
DNMPG::	BISB	#SW.TD2,$NUMSW	; Enable page numbering
	RETURN
;
;	number subpage
;
NSPAG::	MOV	SUBNX,R3	; next subpage
	CALL	NUPAGB		; get new value
	CMP	R3,#255.	; too big?
	BHIS	NUMER		; yes
	MOVB	R3,SUBNX	; save next subpage number
	BISB	#SW.DIS,$SBPSW	; start subpage
	RETURN
;
;	NUMBER LEVEL command
;
NLEVL::	MOV	#CHPTN+1,-(SP)	; First level address
10$:	MOVB	@(SP),R3	; Current value
	INC	R3
	CALL	NUPAGB		; Get number
	BCS	30$		; None?
	CMP	R3,#255.	; Too big ?
	BHIS	NUMER		; yes
20$:	MOVB	R3,@(SP)	; Save number
	INC	(SP)		; Next level
	CMP	(SP),#CHPTN+6	; Last one?
	BLOS	10$		; No
30$:	MOV	(SP)+,R0	; Get current level
	SUB	#CHPTN+1,R0	; Level number
	BLE	40$		; None ?
	MOVB	R0,LEVEL	; Save it
	DECB	CHPTN(R0)	; Set current level to correct value
	RETURN
40$:	MOVB	R3,LEVEL	; Set current level to 1
	CLRB	CHPTN+1		; Next level is 1.0
	RETURN
;
;	NUMBER LIST
;
NULST::	MOV	@LSTKP,R3	; Current value
	CALL	NUPAG		; Get next value
	CMP	R3,#4000.	; Too big?
	BHIS	NUMER		; yes
	DEC	R3
	MOV	R3,@LSTKP	; Save it
10$:	RETURN
;
;	get new page/chapter/appendix number
;
NUPAGB:	BIC	#177400,R3	; Clear out extra bits
NUPAG0:	DEC	R3		; Now is current value
NUPAG:	MOV	R3,-(SP)
	CALL	SKPSP		; Null param?
	BCS	30$		; Yes
	CALL	BKSPI		; No
	CALL	ALPGT		; get letter code
	BCC	20$		; found one ?
	MOV	(SP),R3		; saved value for increment
	CALL	RCNR		; get numeric value
	  JMP	30$		; none
20$:	TST	(SP)+		; pop saved value
	TST	R3		; Check value found
	BLE	NUMER		; Bad value ?
	CLC			; Success
	RETURN
30$:	TST	(SP)+		; Pop saved value
	MOV	#1,R3		; Default value
	SEC			; No success
	RETURN

;
;	DISPLAY ELEMENTS command
;
DSELE::  MOV	LSTKP,R4	; Current list
	CALL	GETLIT		; Get a literal
	BCS	10$		; None!
	CLRB	LS.PRE(R4)	; Clear in case null
	TSTEQ	R1,10$		; Null literal?
	MOVB	(R2),LS.PRE(R4)	; save character
10$:	MOV	R4,R3
	ADD	#LS.FMT,R3	; Format address
	CALL	DSPGT		; Get Display value
	CALL	GETLIT		; Final literal
	BCS	20$		; none
	CLRB	LS.PST(R4)	; Clear in case null
	TSTEQ	R1,20$		; Null literal?
	MOVB	(R2),LS.PST(R4)	; save character
20$:	RETURN
;
;	DISPLAY LEVELS COMMAND
;
DSLEV::	MOV	#LVTAB,R4	; get the table
1$:	CALL	RCNO		; Get a number
	MOV	(R4),R3		; Get the default level
	BEQ	20$		; Done ??
	TST	R3
	BLE	DSPERR		; Too small
	CMP	R3,#6		; Is it too big
	BHI	DSPERR		; Yes ?
	TST	(R4)+		; Entry
	ASL	R3		; Word pointer
	ASL	R3		; Double word
	ASL	R3		; Quad word
	ADD	#LVTAB-6,R3
	MOV	R3,R4		; Now correct in table
	CALL	DSP		; Save entry
	BR	1$
20$:	RETURN
;
;	Move literal to buffer
;
MOVNUM:	TSTEQ	R1,40$
20$:	MOVB	(R2)+,R3	; Get character
	CMPB	R3,#SPC		; Less than space?
	BHI	30$		; No
	MOVB	#SPC,R3		; Make it space
30$:	MOVB	R3,(R0)+	; Save it
	SOB	R1,20$		; Continue till done
40$:	CLRB	(R0)		; Make last char null
	RETURN
;
;	DISPLAY NUMBER command
;
DSNUM::	MOV	#NUTAB,R4
	BR	DSP
;
;	DISPLAY CHAPTER command
;
DSCHP::	MOV	#CHTAB,R4
DSP:	CALL	GETLIT		; Get a literal
	BCS	50$		; None!
	MOV	(R4),R0		; Chapter header text
	BEQ	DSPERR		; None allowed ??
	CMP	R1,#CH.HD1	; Too big?
	BHI	DSPERR		; Yes?
	CALL	MOVNUM		; Move chars to buffer
50$:	TST	(R4)+
	MOV	(R4)+,R3	; Address of display
	BEQ	60$		; None ??
	CALL	DSPGT		; Get Display value
60$:	CALL	GETLIT		; Final literal
	BCS	90$		; none
	MOV	(R4),R0		; Post header
	BEQ	DSPERR		; None allowed ??
	CMP	R1,#CH.HD2	; Too big?
	BHI	DSPERR		; Yes?
	CALL	MOVNUM		; Move chars to buffer
90$:	TST	(R4)+		; Next entry
	RETURN
DSPERR:	JMP	ERRHI		; Bad params
;
;	DISPLAY APPENDIX command
;
DSAPN::	MOV	#APTAB,R4
	BR	DSP
;
;	Display subpage command
;
DSSUBP::MOV	#SUBDSP+1,R3	; default
	CALL	DSPGT
	RETURN
;
;	Display title command
;
DSTTL::	MOV	#TTTAB,R4
	BR	DSP
;
;	Display subtitle command
;
DSSTL::	MOV	#STTAB,R4
	BR	DSP
;
;	routine to parse display command
;
DSPGT:	MOV	R3,-(SP)	; Save default
	CLR	R3		; Clear it
	CALL	ALPGT		; get 2 char sequence
	TSTEQ	R3,20$		; none ?
	MOV	#DSPTAB,R0	; table to search
10$:	TST	(R0)		; at end of table?
	BNE	15$		; no
17$:	JMP	ILCM		; bad input
15$:	CMPEQ	R3,(R0)+,18$	; match?
	TST	(R0)+		; NO
	BR	10$		; continue
18$:	MOVB	1(R0),@(SP)		; get code
20$:	TST	(SP)+		; Pop
	RETURN
;
;	TYPE command
;
TYPE::	MOV	#TTBF,R3	; Get terminal temporary buffer
	CALL	CLRBF		; Clear it
	MOV	#74.,R4		; Max number of chars
	MOV	#2,R2		; Initially zero count
10$:	CALL	CCIN		; Get a char
	CMP	R1,#SPC		; Compare with space
	BEQ	10$		; Space to skip
	BR	21$		; Save this char
20$:	CALL	CCIN		; Get a char
21$:	CMPEQB	R1,#CR,30$	; End of line ?
	CMPEQB	R1,#LF,30$	; End of line ?
	INC	R2		; Count number of char
	CALL	PBYT		; Save it
	SOB	R4,20$		; Continue till count done
30$:	MOV	CRTAB,R1	; Put in "return"
	CALL	PWRD
	MOV	#TTBUF,R1	; Address of buffer
	JMP	TTOUT		; Output the line
	.END
