
	.TITLE	STYLE
	.SBTTL	/BL1.0/
;
;	This module contains the following commands
;
;	LAYOUT
;	AUTOSUBTITLE
;	DISPLAY commands
;	LOCK
;	STYLE
;	TOC	Table of contents commands
;	NUMBER commands
;
	.PSECT	$TABL,RO,D,CON,LCL
LAYTB:	.BYTE	7			; Max value
	.BYTE	0			; 0 layout
	.BYTE	LAY.NB!LAY.CT!LAY.CP	; 1
	.BYTE	LAY.NB!LAY.CP!LAY.LR	; 2
	.BYTE	LAY.NB!LAY.CP		; 3
	.BYTE	LAY.NB			; 4
	.BYTE	LAY.NB!LAY.CT		; 5
	.BYTE	LAY.NB!LAY.CT!LAY.LR	; 6
	.BYTE	LAY.NB!LAY.LR		; 7
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
	.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

	.PSECT	$CODE,RO,I,LCL,CON
;
;	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::	BIC	#SW.DIS,$TOCSW		; Enable TOC
	RETURN
DSTOC::	BIS	#SW.DIS,$TOCSW		; Disable TOC
	RETURN
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
	BIS	#SW.TDS,$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
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.TDS,$CHPSW		; Allow chapter numbers
	MOVB	#2,BEGLV		; Reset level spacing
	MOVB	#1,ENDLV		; Reset level spacing
	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

;
;	STYLE HEADERS COMMAND
;
STYHD:: MOV	#LINLV,-(SP)	; Current variable
	MOV	(SP),R1		; Variables
	MOV	#STHDTB,R0	; Constants to default to
	MOV	#9.,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
	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	; old appendix value
	CALL	NUPAG		; 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	; current chapter number
	CALL	NUPAG		; GET CHAPTER NUMBER
	CMP	R3,#255.	; LEGAL CHAPTER NUMBER?
	BHIS	NUMER		; yes
	MOVB	R3,CHPNX	; SET FOR NEXT CHAPTER COMMAND
	BITNE	#LCKF,F.1,20$	; parameters locked
	CLRB	$CHPSW		; enable chapter numbers
20$:	RETURN			; 
NOCHP:: BITNE	#LCKF,F.1,10$	; params locked?
	BISB	#SW.DIS,$CHPSW	; disable chapter numbers
	CLR	CHPTN		; turn off chapter/appendix numbers
	CLR	APNDN
10$:	RETURN
;
; PAGE NUMBER SELECTION COMMANDS
;
NUMON:: MOV	PAGENO,R3	; get original page number
	CALL	NUPAG		; Get new page number
	CMP	R3,#4000.	; Too big?
	BHIS	NUMER		; yes
	MOV	R3,PAGNX	; next page number
	BITNE	#LCKF,F.1,10$	; params locked?
	MOV	SP,$NUMSW	; TURN ON FLAG TO CAUSE NUMBERING
10$:	RETURN			; 
NUMOF::	BITNE	#LCKF,F.1,10$	; params locked?
	CLR	$NUMSW		; TURN OFF NUMBERING.
10$:	RETURN			; 
NUMER:	JMP	ERRHI		; Numbering error
;
;	number subpage
;
NSPAG::	MOV	SUBNX,R3	; current subpage
	CALL	NUPAG		; get new value
	CMP	R3,#255.	; too big?
	BHIS	NUMER		; yes
	MOV	R3,SUBNX	; save next subpage number
	MOV	SP,$SBPSW	; start subpage
	RETURN
;
;	NUMBER LEVEL command
;
NLEVL::	MOV	#CHPTN+1,-(SP)	; First level address
10$:	MOVB	@(SP),R3	; Current value
	CALL	NUPAG		; Get number
	BCS	30$		; None?
	CMP	R3,#255.	; Too big ?
	BHIS	NUMER		; yes
	INC	R3		; Set to next value
20$:	MOVB	R3,@(SP)	; Save number
	INC	(SP)		; Next one
	CMP	(SP),#CHPTN+6	; Last one?
	BLOS	10$		; No
30$:	MOV	(SP)+,R0	; Get current level
	SUB	#CHPTN+1,R0	; Level number
	BEQ	NUMER		; None ?
	MOVB	R0,LEVEL	; Save it
	DECB	CHPTN(R0)	; Set current level to correct value
40$:	RETURN
;
;	NUMBER LIST
;
NULST::	MOV	LSTCT,R3	; Current value
	CALL	NUPAG		; Get next value
	BCS	10$
	CMP	R3,#4000.	; Too big?
	BHIS	NUMER		; yes
	MOV	R3,LSTCT	; Save it
10$:	RETURN
;
;	get new page/chapter/appendix number
;
NUPAG::	MOV	R3,-(SP)
	CALL	SKPSP		; Null param?
	BCS	30$		; Yes
	CALL	BKSPI		; No
	CALL	ALPGT		; get letter code?
	BCS	20$		; none
10$:	TST	(SP)+		; pop saved value
	TSTEQ	R3,NUMER	; Bad value for number ??
	CLC			; Success
	RETURN
20$:	MOV	(SP),R3		; saved value for increment
	CALL	RCNR		; get numeric value
	  JMP	30$		; none
	BR	10$		; success
30$:	MOV	(SP)+,R3	; keep old value
	SEC			; No success
	RETURN

;
;	DISPLAY ELEMENTS command
;
DSELE::  MOV	LSTKP,R4	; Current list
	CALL	GETLIT		; Get a literal
	BCS	10$		; None!
	CLRB	(R4)		; Clear in case null
	TSTEQ	R1,10$		; Null literal?
	MOVB	(R2),(R4)	; save character
10$:	INC	R4
	CALL	DSPGT0		; Get Display value
	SWAB	R3		; Get value in lower byte
	MOVB	R3,(R4)+	; Save display format
	CALL	GETLIT		; Final literal
	BCS	20$		; none
	CLRB	(R4)		; Clear in case null
	TSTEQ	R1,20$		; Null literal?
	MOVB	(R2),(R4)	; save character
20$:	RETURN
;
;	DISPLAY LEVELS COMMAND
;
DSLEV::	MOV	#CHPDSP+2,R4	; First level display format
10$:	CALL	DSPGT0		; get display
	SWAB	R3		; get lower byte
	MOVB	R3,(R4)+	; Save display format
	CMP	R4,#CHPDSP+8.	; Done?
	BLOS	10$		; no
	RETURN
;
;	DISPLAY NUMBER command
;
DSNUM::	CALL	GETLIT		; Get a literal
	BCS	50$		; None!
	MOV	#PAGHD,R0	; Chapter header text
	CMP	R1,#CH.HD1	; Too big?
	BHI	DSPERR		; Yes?
	CALL	MOVNUM		; Move chars to buffer
50$:	CALL	DSPGT0		; Get Display value
	MOV	R3,PAGDSP	; save it
	CALL	GETLIT		; Final literal
	BCS	90$		; none
	MOV	#PAGH2,R0	; Chapter header text
	CMP	R1,#CH.HD2	; Too big?
	BHI	DSPERR		; Yes?
	CALL	MOVNUM		; Move characters to buffer
90$:	RETURN
MOVNUM:	TSTEQ	R1,40$
20$:	MOVB	(R2)+,R3	; Get character
	CMPB	R3,#SPC		; Less than space?
	BHI	30$		; No
	MOVB	#SPC,R3		; Make it non expandable space
30$:	MOVB	R3,(R0)+	; Save it
	SOB	R1,20$		; Continue till done
40$:	CLRB	(R0)		; Make last char null
	RETURN
;
;	DISPLAY CHAPTER command
;
DSCHP::	CALL	GETLIT		; Get a literal
	BCS	50$		; None!
	MOV	#CHPMG,R0	; Chapter header text
	CMP	R1,#CH.HD1	; Too big?
	BHI	DSPERR		; Yes?
	CALL	MOVCHP		; Move chars to buffer
50$:	CALL	DSPGT0		; Get Display value
	MOV	R3,CHPDSP	; save
	CALL	GETLIT		; Final literal
	BCS	90$		; none
	MOV	#CHPM2,R0	; Chapter header text
	CMP	R1,#CH.HD2	; Too big?
	BHI	DSPERR		; Yes?
	CALL	MOVCHP		; Move chars to buffer
90$:	RETURN
;
;	Routine to move chars for DISPLAY CHAPTER/APPEN
;
MOVCHP:	TSTEQ	R1,40$
20$:	MOVB	(R2)+,R3	; Get character
	CMPB	R3,#SPC		; Less than space?
	BHI	30$		; No
	MOVB	#NXS,R3		; Make it non expandable space
30$:	MOVB	R3,(R0)+	; Save it
	SOB	R1,20$		; Continue till done
40$:	CLRB	(R0)		; Make last char null
	RETURN
DSPERR:	JMP	ERRHI		; Bad params
;
;	DISPLAY APPENDIX command
;
DSAPN::	CALL	GETLIT		; Get a literal
	BCS	50$		; None!
	MOV	#APNMG,R0	; Chapter header text
	CMP	R1,#CH.HD1	; Too big?
	BHI	DSPERR		; Yes?
	CALL	MOVCHP		; Move chars to buffer
50$:	MOV	LU,R3		; default letters upper
	CALL	DSPGT		; Get the type
	MOV	R3,APNDSP	; save
	CALL	GETLIT		; Final literal
	BCS	90$		; none
	MOV	#APNM2,R0	; Chapter header text
	CMP	R1,#CH.HD2	; Too big?
	BHI	DSPERR		; Yes?
	CALL	MOVCHP		; Move chars to buffer
90$:	RETURN
;
;	Display subpage command
;
DSSUBP:: MOV	LU,R3		; default
	CALL	DSPGT
	MOV	R3,SUBDSP	; save type
	RETURN
;
;	routine to parse display command
;
DSPGT0:	MOV	DSPTAB,R3	; Decimal default
DSPGT:	CALL	ALPGT		; get 2 char sequence
	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$:	MOV	(R0),R3		; get code
20$:	RETURN
	.END
