PROCEDURE	<MISCS - Misc. RUNOFF support subroutines>,020002
;+
; Copyright (C) 1976
; Digital Equipment Corporation, Maynard, Mass.
;
; This software is furnished under  a license for use only  on  a
; single computer system and may be  copied only with  the inclu-
; sion of  the  above  copyright notice.  This software,  or  any
; other copies thereof, may not be  provided  or  otherwise  made
; available to any other person except  for  use  on  such system
; and to  one who agrees  to  these license  terms.  Title to and
; ownership of the software shall at all times remain in DEC.
;
; The information in this software  is  subject to change without
; notice and should not be construed  as  a commitment by Digital
; Equipment Corporation.
;
; DEC assumes no responsibility for the use or reliability of its
; software on equipment which is not supplied by DEC.
;
; Written: 01-Jun-72, -1.0.0-, L. Wade
;
; Modified: 12-Jan-80, -2.0.0-, Henry R. Tumblin
;	Produced Duke supported version
;
; Verified: 12-Jan-80, -2.0.0-, Henry R. Tumblin
;
; Modified: 15-Oct-80, -2.0.1-, John D. Leonard
;	Added Overbar initialization
;
; Modified: 22-Dec-80, -2.0.2-, John D. Leonard
;	Added SAVLIB and RESLIB - save/restore line buffer parameters and
;	contents.
;-

	CODE	MISCS

	.SBTTL	INITIALIZE FOR A NEW LINE

; subroutine to initialize counts and pointers for a new line

LINSET::MOV	RMARG,R2	; compute real width of line
	SUB	LMARG,R2	; as difference of margins
	SUB	INDCT,R2	; minus indenting
	MOV	R2,LINBK	; store in line-break count
	MOV	#-1,SPCNT	; initial counts of spacing
	CLR	NSPCH		; and non-spacing chars
	CLR	CPOS		; carriage position is far left
	.IF	DF	A$$RAP
	CLR	VPOS		; vertical position
	CLR	OBCPOS		; Overbar carriage postion
	MOV	HSDEF,HSPACE	; Re-init half-space word for alternation
	.ENDC
	CLR	LINNSC		; no non-spacing characters
	MOV	LIBUF+BF.ADR,LIBUF+BF.PTR ; clear line input buffer
	CLR	LIBUF+BF.LEN	; reset length
	MOV	LIBUF+BF.ADR,LSTSP ; Set last spacing character here
;	DEC	LSTSP		; minus one, so off start of buffer
	.IF	DF	A$$RAP
	CALL	ULBSET		; Reset underline buffer
	CALL	OBBSET		; Reset overbar buffer
	RETURN			;

	.ENDC
ULBSET::MOV	#ULPBF,ULPOS	; reset underline position buffer
	RETURN			;
	.IF	DF	A$$RAP

OBBSET::MOV	#OBPBF,OBPOS	; reset overbar position buffer
	RETURN
	.ENDC
	.if	df	a$$rap

	.sbttl	SAVLIB - save LIBUF parameters etc.

SAVLIB::
	SAVE	R0,R1,R2		;
	MOV	LINBK,-(SP)		;
	MOV	SPCNT,-(SP)		;
	MOV	NSPCH,-(SP)		;
	MOV	LINNSC,-(SP)		;
	MOV	LSTSP,-(SP)		;
	MOV	LIBUF+BF.PTR,-(SP)	;
	MOV	LIBUF+BF.LEN,-(SP)	;
	TST	-(SP)			; Leave space for buffer address
	MOV	LIBUF+BF.LEN,R1		; Length of space to allocate for save
	BLE	50$			; Buffer empty - skip copy etc
	MOV	R1,R0			; and for loop control
	CALL	ALLOC			; R1 is temp buffer address
	MOV	R1,(SP)			; Save the buffer address
	MOV	LIBUF+BF.ADR,R2		; Copy from here
10$:
	MOVB	(R2)+,(R1)+		;
	SOB	R0,10$			; Loop till done
50$:
;
;	Break page
;
	CALL	BPAGE			;
;
	MOV	(SP),R1			; buffer address
	MOV	LIBUF+BF.ADR,R2		; and restore to  LIBUF
	MOV	2(SP),R0		; BF.len
	BLE	200$			; Length 0, nothing to copy
100$:
	MOVB	(R1)+,(R2)+		;
	SOB	R0,100$			; Loop till copied back and restore
	MOV	(SP),R1			; Free scratch area
	CALL	FREE			;
200$:
	TST	(SP)+			; word for scratch area address
	MOV	(SP)+,LIBUF+BF.LEN	;
	MOV	(SP)+,LIBUF+BF.PTR	;
	MOV	(SP)+,LSTSP		;
	MOV	(SP)+,LINNSC		;
	MOV	(SP)+,NSPCH		;
	MOV	(SP)+,SPCNT		;
	MOV	(SP)+,LINBK		;
	UNSAVE	R0,R1,R2		;
	RETURN				;
	.ENDC

	.SBTTL	FORCE TO LOGICAL END OF COMMAND
;+
; $FRCND-force to logical end of command
;-

$FRCND::CALL	CCIN		; read character from file
	BITB	#CHASP,CHATBL(R1) ; Is it a spacing character?
	BNE	$FRCND		; NE - yes
	CMPEQ	#SEMI,R1,10$	; semicolon?
	MOVB	R1,GCSCH	; save break character
10$:	RETURN			;


	.SBTTL	TABB - FIND NEXT TABSTOP

; routine to find next tabstop for outlin routine.

TABB::	CLR	R0		; start at first tabstop
	BR	20$		; pre-endcheck, in case none.
10$:	MOVB	TABTAB-1(R0),R4	; get current tab stop
	CMP	R2,R4		; this stop beyond current pos?
	BLO	40$		; yes.  get difference
20$:	CMP	R0,NTABS	; looked at all tab stops?
	BHIS	30$
	INC	R0		; advance to next entry
	BR	10$
30$:	MOV	RMARG,R4	; yes.  assume a tabstop at right end
40$:	SUB	R2,R4		; get distance to tabstop
	MOV	R4,R2		; answer in a
	RETURN			;
	.END
