;*****************************************
;*	JOBRUN.M68
;*
;*      Scans the system and prints
;*      every defined job to the screen
;*	AND the program they are running.
;*
;*	GREAT for quick JOB status
;*
;*      Usage: JOBRUN
;*
;*	by Dave Heyliger - AMUS Staff	
;*****************************************

	OBJNAM	JOBRUN.LIT		;Define the final product

	SEARCH SYS			;Grab all MACRO definitions
	SEARCH SYSSYM
	SEARCH TRM

	VMAJOR=2.			;Major version number of the program
	VMINOR=0.			;Minor version number of the program
	VEDIT=100.			;the edit number of the program

	.OFINI				;OFfset INItialization:
	.OFDEF	BUFFER,7.		;OFfset DEFinition - "BUFFER"
	.OFSIZ	IMPSIZ			;IMPSIZ is the final size of bytes (7)

DEFINE	TYPEIT	V,B
;+--- 
;| TYPEIT will process a JCB variable that is two words packed RAD50 data
;|        and type this variable to the screen in ascii format.
;| where
;|        V = variable to be UNPACKED
;|        B = buffer area to place unpacked characters
;+--------------------------------------------------------------------------
	LEA	A1,V(A4)		;A1 points to variable to be unpacked
	LEA	A2,B(A5)		;and ^ A2 to byte "0" of "BUFFER"
	UNPACK				;get the letters unpacked
	UNPACK				;  ...for up to full letters
	CLRB	@A2			;Place a "null" after the characters
 	LEA	A2,B(A5)		;Repoint A2 to byte "0" of "BUFFER"
	TTYL	@A2			;Print out all chars until a null
ENDM

DEFINE	PRTTAB	AA,BB
;+---
;| PRTTAB acts just like "PRINT TAB (#,#) from within BASIC
;| where
;|	AA is the first #, BB is the second #
;+------------------------------------------------------------
	MOVB	#AA,D1			;move 1st number into D1
	LSLW	D1,#10			;shift it left 8. bits
	MOVB	#BB,D1			;move in 2nd number
	TCRT				;and perform TCRT call
ENDM

DEFINE	TABDWN	AA,BB
;+---
;| TABDWN - or "TAB DOWN" will place the cursor at the row specified by
;|          AA and the column specified by BB. Assumes a data register
;|          (AA) has been "dedicated" to keep track of which row.
;| where
;|	AA is a dedicated data register holding current row number
;|	BB is the column number
;+----------------------------------------------------------------------
	MOVB	AA,D1			;move in value from dedicated reg.
	LSLW	D1,#10			;shift it left 8. bits
	MOVB	#BB,D1			;move in column number
	TCRT				;and perform TCRT call
	INC	AA			;increment dedicated data register
ENDM


;--- Program initialization and screen format headers etc...
;
	PHDR	-1,0,PH$REE!PH$REU	;Program is Re-entrant & Re-useable
	GETIMP	IMPSIZ,A5		;Reg. A5 now ^'s to byte "0" of BUFFER
	PRTTAB	-1,29.			;cursor OFF
	PRTTAB	-1,0			;clear the screen
	MOV	#3,D4			;initialize dedicated register
	TABDWN	D4,40			;move cursor here
	TYPE	< Job     Program>	;create a header
	TABDWN	D4,40			;again move the cursor
	TYPE	<-------+-------->	;create an underline

;--- First loop: type out both the JOB name and the PROGRAM running
;
LOOP:	CTRLC	EXIT			;quit on a ^C
	MOV	JOBTBL,A0		;Get base of JOB TABLE into A0
NXTJOB:	MOV	(A0)+,A4		;and let A4 point to each JBC
	MOV	A4,D0			;this will set the flags 2 B checked
	BMI	SNOOZE			;end of the JOB TABLE on a "-1"
	BEQ	NXTJOB			;goto the top on a "0"
	TABDWN	D4,40			;adjust cursor
	TYPEIT	JOBNAM,BUFFER		;type out the JOB NAME
	TYPE	<   >			;type some spaces
	TYPEIT	JOBPRG,BUFFER		;type out the PROGRAM NAME
	BR	NXTJOB			;do it again
 
;--- Now for each loop thereafter, just type out the PROGRAM
;
SNOOZE:	PRTTAB	-1,29.			;cursor OFF while sleeping
	SLEEP	#25000.			;sleep for a bit
	CTRLC	EXIT			;quit on a ^C
	MOV	#5,D4			;initialize D4 for TABDWN
	MOV	JOBTBL,A0		;Get base of JOB TABLE into A0
	PRTTAB	-1,28.			;cursor ON for effect
NXTPRG:	MOV	(A0)+,A4		;and let A4 point to each JBC
	MOV	A4,D0			;this will set the flags 2 B checked
	BMI	SNOOZE			;end of the JOB TABLE on a "-1"
	BEQ	NXTPRG			;goto the top on a "0"
 	TABDWN	D4,51			;adjust before each PROGRAM is typed
	TYPEIT	JOBPRG,BUFFER		;type out the PROGRAM NAME
	BR	NXTPRG			;do it again

EXIT:	PRTTAB	-1,28.			;cursor ON
	PRTTAB	-1,0			;clear the screen
	
	EXIT				;return to AMOS

	END