;***************************************************************************;
;									    ;
;				UltraStat 3.x				    ;
;			      JOB STATUS SCREEN				    ;
;									    ;
;***************************************************************************;
;Copyright (C) 1988 UltraSoft Corporation.  All Rights Reserved.
;
;Written by: David Pallmann
;
;All edit history for USTAT is in USYM.M68.

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

;--- Include files

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

;--- Job Scanning Loop

JOB.SCAN::
	MOV	JOBTBL,A0		; point to base of job table
	LEA	JIB,JB.TBL(MEM)
	MOVB	JOB.ROW(MEM),ROW(MEM)	; set starting job row
	CLRB	JOB.UPDATE(MEM)		; clear new arrow row

JOB.BYPASS:
	MOVWL	JOB.OFFSET(MEM),D0
	BEQ	JOB.LOOP
10$:	MOV	(A0)+,D7
	JMI	SNOOZE
	ADD	#JB.SIZ,JIB
	SOB	D0,10$

JOB.LOOP:
	KEY	GET.COMMAND
	BIT	#F$UPDATE,FLAGS(MEM)
	BEQ	10$
	OR	#JB$NEW,JB.FLG(JIB)
10$:	MOV	(A0)+,D7		; get JCB address
	MOV	D7,JCB			; (condition codes unchanged)
	JMI	SNOOZE
	JEQ	DEALLOCATED.JOB		;  handle deallocated job
	JMP	ALLOCATED.JOB		;  handle allocated job

JOB.NEXT::
	ADD	#JB.SIZ,JIB		; 
	INCB	ROW(MEM)		; increment display row
	CMMB	ROW(MEM),LAST.ROW(MEM)	; end of page?
	JLOS	JOB.LOOP		;  no - on to next job
	JMP	SNOOZE

;--- Handle a deallocated job

DEALLOCATED.JOB:
	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	10$			;  yes
	TST	JB.NAM(JIB)		; already deallocated?
	BEQ	20$			;  yes
10$:	CURSOR	ROW(MEM),#2		; position cursor
	LOW				; low intensity
	CLREOL
	CLR	JB.NAM(JIB)
20$:	JMP	JOB.NEXT

;--- Handle an allocated job

ALLOCATED.JOB:
	CALL	JOB.NAME		; update job name
	KEY	10$			;  check for keyboard input
	CALL	JOB.TERM		; update terminal name
	KEY	10$			;  check for keyboard input
	CALL	JOB.PPN			; update log PPN
	KEY	10$			;  check for keyboard input
	CALL	JOB.STATE		; update run state
	KEY	10$			;  check for keyboard input
	CALL	JOB.PROG		; update job program name
	KEY	10$			;  check for keyboard input
	CALL	JOB.MEMORY		; update job memory size
	KEY	10$			;  check for keyboard input
	CALL	JOB.CPU			; update job CPU time
	KEY	10$			;  check for keyboard input
	BIT	#F$USER,FLAGS(MEM)
	BNE	4$
	CALL	JOB.READS		; update job disk reads
	KEY	10$			;  check for keyboard input
	CALL	JOB.WRITES		; update job disk writes
	KEY	10$
	CALL	JOB.PRI
	KEY	10$
	BR	6$
4$:	BIT	#F$32,FLAGS(MEM)	; /32 data structures present?
	BEQ	6$			;  no
	CALL	JOB.USER
	KEY	10$
6$:	BIT	#F$WIDE,FLAGS(MEM)
	JEQ	100$
	CALL	JOB.OWNER
	KEY	10$
	CALL	JOB.LEVEL
	KEY	10$
	CALL	JOB.MEM.BASE
	KEY	10$
	CALL	JOB.JCB.BASE
	KEY	10$
	CALL	JOB.TCB.BASE
100$:	AND	#^C<JB$NEW>,JB.FLG(JIB)	; clear forced update flag
10$:	CALL	ARROW
	JMP	JOB.NEXT

;--- update job name

JOB.NAME:
	MOV	JOBNAM(JCB),D0
	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	10$			;  yes
	CMM	D0,JB.NAM(JIB)		; did name change?
	REQ				;  no
10$:	MOV	D0,JB.NAM(JIB)
	CURSOR	ROW(MEM),#2
	HIGH
	OUTNAM	JB.NAM(JIB)
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	RTN

;--- update job attached terminal name

JOB.TERM:
	CLR	D0
	MOV	JOBTRM(JCB),D6
	BEQ	10$
	MOV	D6,A6
	MOV	-4(A6),D0
10$:	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	20$			;  yes
	CMM	D0,JB.TRM(JIB)		; did term name change?
	REQ				;  no
20$:	MOV	D0,JB.TRM(JIB)
	CURSOR	ROW(MEM),#9.
	HIGH
	OUTNAM	JB.TRM(JIB)
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	RTN

;--- update job log account

JOB.PPN:
	MOVW	JOBUSR(JCB),D0
	MOVW	JOBDEV(JCB),D2
	MOVW	JOBDRV(JCB),D3
	BIT	#JB$NEW,JB.FLG(JIB)
	BNE	11$
	CMPW	D0,JB.PPN(JIB)
	BNE	10$
	CMPW	D2,JB.DEV(JIB)
	BNE	10$
	CMPW	D3,JB.DRV(JIB)
	REQ
10$:	BIT	#F$LOG,FLAGS(MEM)
	BEQ	11$
	DING
11$:	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	MOVW	D0,JB.PPN(JIB)
	MOVW	D2,JB.DEV(JIB)
	MOVW	D3,JB.DRV(JIB)
	CURSOR	ROW(MEM),#16.
	HIGH
	TYPE	<               >
	CURSOR	ROW(MEM),#16.
	TSTW	JB.PPN(JIB)
	JEQ	NOT.LOGGED.IN
	BIT	#F$ERSATZ,FLAGS(MEM)
	BEQ	LOG.PHYSICAL

LOG.ERSATZ:
	SAVE	A0
	LEA	A0,JB.DEV(JIB)
	LEA	A2,TEMP(MEM)
	CALL	PPNERZ
	REST	A0
	BNE	LOG.PHYSICAL
	CLRB	@A2			; 				[103]
	TTYL	TEMP(MEM)
	FCYAN
	RTN

LOG.PHYSICAL:
	OUTDEV	JB.DEV(JIB)
	MOVWL	JB.DRV(JIB),D1
	DCVT	0,OT$TRM
	TYPE	:
	CMP	D1,#10.
	BHI	10$
	TYPESP
10$:	CMPB	JB.PPN+1(JIB),#10
	BHIS	20$
	TYPESP
20$:	CMPB	JB.PPN+1(JIB),#100
	BHIS	30$
	TYPESP
30$:	TYPE	[
	PRPPN	JB.PPN(JIB)
	TYPE	]
	FCYAN
	RTN

NOT.LOGGED.IN:
	FCYAN
	LOW
	TYPE	not logged in
	RTN

;--- update job program name

JOB.PROG:
	MOV	JOBPRG(JCB),D0
	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	11$			;  yes
	CMM	D0,JB.PRG(JIB)		; did name change?
	REQ				;  no
10$:	BIT	#F$PROG,FLAGS(MEM)
	BEQ	11$
	DING
11$:	MOV	D0,JB.PRG(JIB)
	CURSOR	ROW(MEM),#32.
	HIGH
	OUTNAM	JB.PRG(JIB)
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	RTN

;--- update run state

JOB.STATE:
	FCYAN
	MOVWL	JOBSTS(JCB),D1
	LEA	A1,STATE1
	MOV	#1,D0
	CLR	D2
10$:	TSTW	@A1
	BEQ	20$
	INC	D0
	MOVW	(A1)+,D2
	BITW	D2,D1
	BNE	30$
	BR	10$
20$:	MOV	#1,D0
30$:	DEC	D0
	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	40$			;  yes
	CMMW	D0,JB.STS(JIB)		; did run state change?
	REQ				;  no
40$:	MOVW	D0,JB.STS(JIB)		; update run state
	CURSOR	ROW(MEM),#39.
	LEA	A1,STATE2
	MUL	D0,#4
	ADD	D0,A1
	CMPB	@A1,#'a
	BHIS	50$
	HIGH
	FGREEN				; RUN in green
	CMPW	JB.STS(JIB),#1		; IOW?
	BNE	60$			;  no
	FYELLOW				; IOW in yellow
	BR	60$
50$:	LOW
	CMPW	JB.STS(JIB),#2		; in monitor mode?
	BNE	54$			;  no
	FWHITE				; white fgd
	BR	60$
54$:	CMPW	JB.STS(JIB),#9.		; in control-C state?
	BNE	60$			;  no
	FRED				; yes - red
60$:	TTYL	@A1
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	FCYAN
	RTN

;--- update memory

JOB.MEMORY:
	MOV	JOBSIZ(JCB),D0
	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	10$			;  yes
	CMM	D0,JB.MEM(JIB)		; memory changed?
	REQ				;  no
10$:	MOV	D0,JB.MEM(JIB)
	CURSOR	ROW(MEM),#43.
	TST	D0
	BEQ	20$
	HIGH
	MOV	D0,D1
	DIV	D1,#2000
	AND	#177777,D1
	DCVT	4,OT$TRM!OT$ZER
	TYPE	K
	BR	30$
20$:	LOW
	TYPE	< none>
30$:	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	RTN

;--- update job CPU time

JOB.CPU:
	MOV	JOBCPU(JCB),D0
	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	10$			;  yes
	CMM	D0,JB.CPU(JIB)		; did CPU time change?
	REQ				;  no
10$:	MOV	D0,JB.CPU(JIB)		; 
	CURSOR	ROW(MEM),#49.
	HIGH
	MOV	D0,D1
	SUB	A2,A2
	CALL	$OTCPU
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	RTN

;--- update job disk reads

JOB.READS:
	MOV	JOBDSR(JCB),D0
	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	10$			;  yes
	CMM	D0,JB.DSR(JIB)		; did disk reads change?
	REQ				;  no
10$:	MOV	D0,JB.DSR(JIB)		; 
	CURSOR	ROW(MEM),#60.
	TST	D0
	BEQ	20$
	HIGH
	MOV	D0,D1
	DCVT	5,OT$TRM!OT$ZER
	BR	30$
20$:	LOW
	TYPE	< none>
30$:	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	RTN

;--- update job disk writes

JOB.WRITES:
	MOV	JOBDSW(JCB),D0
	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	10$			;  yes
	CMM	D0,JB.DSW(JIB)		; did disk writes change?
	REQ				;  no
10$:	MOV	D0,JB.DSW(JIB)		; 
	CURSOR	ROW(MEM),#66.
	TST	D0
	BEQ	20$
	HIGH
	MOV	D0,D1
	DCVT	6,OT$TRM!OT$ZER
	BR	30$
20$:	LOW
	TYPE	<  none>
30$:	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	RTN

;--- Update job user name

JOB.USER:
	MOVSTR	JOBUSN(JCB),TEMP(MEM)
	BIT	#JB$NEW,JB.FLG(JIB)
	BNE	10$
	CMPSTR	TEMP(MEM),JB.USN(JIB)
	REQ
10$:	MOVSTR	TEMP(MEM),JB.USN(JIB)
	CURSOR	ROW(MEM),#60.
	HIGH
	LEA	A1,JB.USN(JIB)
	MOV	#16.,D2
20$:	MOVB	(A1)+,D1
	BEQ	30$
	TTY
	SOB	D2,20$
	BR	40$
30$:	TYPESP
	SOB	D2,30$
40$:	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	RTN

;--- Update job priority

JOB.PRI:
	MOV	JOBRNQ+20(JCB),D0
	BIT	#JB$NEW,JB.FLG(JIB)
	BNE	10$
	CMPW	D0,JB.PRI(JIB)
	REQ
10$:	MOVW	D0,JB.PRI(JIB)
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	CURSOR	ROW(MEM),#73.
	HIGH
	MOV	D0,D1
	DCVT	3,OT$TRM!OT$ZER
	RTN

;--- Update job owner

JOB.OWNER:
	CLR	D0
	MOV	JOBATT(JCB),D6
	BEQ	10$
	MOV	D6,A6
	MOV	JOBNAM(A6),D0
10$:	BIT	#JB$NEW,JB.FLG(JIB)	; forced update?
	BNE	20$			;  yes
	CMM	D0,JB.OWN(JIB)		; did name change?
	REQ				;  no
20$:	MOV	D0,JB.OWN(JIB)
	CURSOR	ROW(MEM),#78.
	HIGH
	OUTNAM	JB.OWN(JIB)
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	RTN

;--- update job security level (if UltraSafe installed)

JOB.LEVEL:
	RTN

;--- update job memory base

JOB.MEM.BASE:
	MOV	JOBBAS(JCB),D0
	BIT	#JB$NEW,JB.FLG(JIB)
	BNE	10$
	CMP	D0,JB.BAS(JIB)
	REQ
10$:	MOV	D0,JB.BAS(JIB)
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	CURSOR	ROW(MEM),#90.
	HIGH
	MOV	D0,D1
	OCVT	11,OT$TRM!OT$ZER
	RTN

;--- update job JCB base

JOB.JCB.BASE:
	MOV	JCB,D0
	BIT	#JB$NEW,JB.FLG(JIB)
	BNE	10$
	CMP	D0,JB.JCB(JIB)
	REQ
10$:	MOV	D0,JB.JCB(JIB)
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	CURSOR	ROW(MEM),#100.
	HIGH
	MOV	D0,D1
	OCVT	11,OT$TRM!OT$ZER
	RTN

;--- update job TCB base

JOB.TCB.BASE:
	MOV	JOBTRM(JCB),D0
	BIT	#JB$NEW,JB.FLG(JIB)
	BNE	10$
	CMP	D0,JB.TCB(JIB)
	REQ
10$:	MOV	D0,JB.TCB(JIB)
	MOVB	ROW(MEM),JOB.UPDATE(MEM)
	CURSOR	ROW(MEM),#110.
	HIGH
	MOV	D0,D1
	OCVT	11,OT$TRM!OT$ZER
	RTN

STATE1:	WORD	J.IOW			; 1
	WORD	J.MON			; 2
	WORD	J.TOW			; 3
	WORD	J.TIW			; 4
	WORD	J.SLP			; 5
	WORD	J.MSG			; 6
	WORD	J.EXW			; 7
	WORD	J.SMW			; 8
	WORD	J.CCC			; 9
	WORD	J.LOK			; 10
	WORD	J.SUS			; 11
	WORD	J.FIL			; 12
	WORD	0

STATE2:	ASCIZ	/RUN/
	ASCIZ	/IOW/
	ASCIZ	/mon/
	ASCIZ	/tow/
	ASCIZ	/tiw/
	ASCIZ	/slp/
	ASCIZ	/msg/
	ASCIZ	/exw/
	ASCIZ	/smw/
	ASCIZ	/ctc/
	ASCIZ	/lok/
	ASCIZ	/sus/
	ASCIZ	/fil/

	END