;****************************************************************************
;*									    *
;*				UltraStat 3.x				    *
;*			 GENERAL-PURPOSE SUBROUTINES			    *
;*									    *
;****************************************************************************
;Copyright (C) 1988, 1989 UltraSoft Corporation.  All Rights Reserved.
;
;Written by: David Pallmann
;
;All edit history for USTAT is in USYM.M68.

	ASMMSG	"== UltraStat 3.x (SUBROUTINES) =="
	AUTOEXTERN

;--- Include files

	SEARCH	SYS
	SEARCH	SYSSYM
	SEARCH	TRM
	COPY	DSKINF.CPY
	COPY	USYM/L

;--- give up some CPU time so we don't hog the system

SNOOZE::
	AND	#^C<F$UPDATE>,FLAGS(MEM)
;;;;;	CURSOR	JOB.ARROW(MEM),ARROW.COL(MEM)	; erase the
;;;;;	TYPE	<   >				;  old arrow
	MOV	DELAY(MEM),D0
	BEQ	20$
	CMPW	MODE(MEM),#M$DEV
	BNE	10$
	ADD	D0,D0			; double delay for DEV mode
10$:	SLEEP	#2500.			; sleep 1/4th of a second
	KEY	GET.COMMAND
	SOB	D0,10$
20$:	JMP	HEADER.SCAN		; back to header

;--- Update job arrow - do this at the end of each job line update

ARROW::	CMPW	MODE(MEM),#M$JOB	; in job display mode?
	JEQ	ARROW.JOB		;  yes - handled separately
	TSTB	JOB.UPDATE(MEM)		; did job arrow move?
	BEQ	20$			;  no
	CMMB	JOB.UPDATE(MEM),JOB.ARROW(MEM) ; is job arrow the same?
	BEQ	20$			;          yes
	TSTB	JOB.ARROW(MEM)		; was there a previous arrow?
	BEQ	10$			;  no
	CURSOR	JOB.ARROW(MEM),ARROW.COL(MEM)	; erase the
	TYPE	<   >			;  old arrow
10$:	MOVB	JOB.UPDATE(MEM),JOB.ARROW(MEM) ; set new arrow
	CLRB	JOB.UPDATE(MEM)		; clear updated arrow
	CURSOR	JOB.ARROW(MEM),ARROW.COL(MEM)	; draw the
	CALL	PLOT.ARROW
20$:	RTN

PLOT.ARROW:
	CURSOR	ROW(MEM),ARROW.COL(MEM)	; 
	LOW
	FWHITE
	TTYI				;  new
	ASCIZ	"<--"			;  arrow
	EVEN
	FCYAN
	RTN

ARROW.JOB:
	CMPW	JB.STS(JIB),#1		; RUN or IOW?
	BHI	10$			;  no
	CALL	PLOT.ARROW
	BR	20$
10$:	CURSOR	ROW(MEM),ARROW.COL(MEM)	; 
	TYPE	<   >
20$:	RTN

;--- set low intensity

SET.LOW::
	BIT	#F$COLOR,FLAGS(MEM)	; color?
	BNE	10$			;  yes - stay in high always
	BIT	#F$HIGH,FLAGS(MEM)
	BEQ	10$
	LO
	AND	#^C<F$HIGH>,FLAGS(MEM)
10$:	RTN

;--- set high intensity

SET.HIGH::
	BIT	#F$COLOR,FLAGS(MEM)	; color?
	BNE	10$			;  yes - stay in high always
	BIT	#F$HIGH,FLAGS(MEM)
	BNE	10$
	HI
	OR	#F$HIGH,FLAGS(MEM)
10$:	RTN

;--- turn on cursor

SET.CURON::
	BIT	#F$ON,FLAGS(MEM)
	BNE	10$
	CON
	OR	#F$ON,FLAGS(MEM)
10$:	RTN

;--- turn off cursor

SET.CUROFF::
	BIT	#F$ON,FLAGS(MEM)
	BEQ	10$
	COFF
	AND	#^C<F$ON>,FLAGS(MEM)
10$:	RTN

;--- set graphics mode

SET.GRAFIX::
	BIT	#F$GRAFIX,FLAGS(MEM)
	BNE	10$
	GMODE
	OR	#F$GRAFIX,FLAGS(MEM)
10$:	RTN

;--- set text mode

SET.TEXT::
	BIT	#F$GRAFIX,FLAGS(MEM)
	BEQ	10$
	TMODE
	AND	#^C<F$GRAFIX>,FLAGS(MEM)
10$:	RTN

;--- compare string @A0 to string @A1 - set Z bit if identical

CMPSTR::
	TSTB	@A0
	BNE	10$
	TSTB	@A1
	BNE	20$
	LCC	#PS.Z
	RTN
10$:	CMMB	(A0)+,(A1)+
	BEQ	CMPSTR
20$:	LCC	#0
	RTN

;--- display mini-help on line 24 or on status line

LINE24::
	LOW
	BIT	#TD$STS,TERM.FLAGS(MEM)
	BNE	LINE25
	CURSOR	#24.,#1
	BCALL	HLPOUT
	CLREOL
	RTN
LINE25:	BIT	#F$STATUS,FLAGS(MEM)	; did we set status line yet?
	RNE				;  yes - no need to do it again
	OR	#F$STATUS,FLAGS(MEM)	; set status bit for next time
	STSLIN
	TYPESP				; select column 1
	BCALL	HLPOUT
	ENDLIN
	RTN

HLPOUT:	FWHITE				; white fgd
	BIT	#F$OPR,FLAGS(MEM)
	BEQ	110$
	CMPW	MODE(MEM),#M$JOB
	BNE	110$
	TTYL	OPR.HELP
	RTN
110$:	TTYL	SHORT.HELP
	RTN

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;									    ;
;				   PPNERZ				    ;
;	      Translate device, drive, and PPN into ersatz name		    ;
;									    ;
;	Entry:	A2 - buffer to return ersatz name (e.g. xxxxxx:)	    ;
;		A0 - device/drive/PPN to locate (3 words)	    	    ;
;									    ;
;	Exit:	 Z - set to 1 if found, 0 if not defined		    ;
;		A0 - updated by 3 words				    ;
;									    ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

PPNERZ::
	SAVE	A0-A1,A3-A5,D0-D5

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	SEARCH FOR ACCOUNT IN ERSATZ TABLE
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SEARCH:	MOV	ERSATZ,D7		; get addr of ersatz table
	JEQ	PPNERR			;  is none
	MOV	D7,A3			; put in addr reg
10$:	TST	@A3			; end of table?
	JEQ	PPNERR			;  yes - couldn't find ersatz name
	CMMW	EZ.DEV(A3),@A0		; same device?
	BNE	20$			;  no
	CMMW	EZ.UNT(A3),2(A0)	; same drive?
	BNE	20$			;  no
	CMMW	EZ.PPN(A3),4(A0)	; same PPN?
	BEQ	FOUND			;  yes
20$:	ADD	#EZ.SIZ,A3		;  no - point to next table entry
	BR	10$			; loop

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	FOUND ACCOUNT - RETURN ERSATZ NAME
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

FOUND:	LEA	A1,EZ.NAM(A3)
	UNPACK
	UNPACK
10$:	CMMB	-(A2),#40
	BEQ	10$
	INC	A2
	MOVB	#':,(A2)+

PPNRTN:	REST	A0-A1,A3-A5,D0-D5
	LCC	#PS.Z
	RTN

PPNERR:	REST	A0-A1,A3-A5,D0-D5
	LCC	#0
	RTN

;***************
;*  SET.COLOR  *
;***************
;Set foreground color to D1 if true color supported

SET.COLOR::
	BIT	#F$COLOR,FLAGS(MEM)
	BEQ	10$
	AND	#377,D1
	ADDW	#-2_8.,D1
	TCRT
10$:	RTN

	END