OBJNAM JOBMAP.LIT  ; originally by David F. Pallman, modified by Irv Bromberg

IF EQ,1	; Edit history:
24-Apr-83  created by DFP
18-Apr-85  fixed address error that occurred when job's memory not allocated
	   by testing for non-zero JOBBAS(JCB), abort if 0.  ILB
1-Nov-85   corrected free memory total for non-zero JOBCMZ(JCB)  ILB
29-Dec-85  deleted reference to CRT.UNV, changed code not to need it.  ILB
29-Dec-85  skip over JOBMAP temporary modules (JOBMAP.LIT & JOBMAP.IMP)  ILB
29-Dec-85  don't show address of free space because JOBMAP modules make it
	   invalid.  ILB
02-Jan-86  show PHDR attributes for all programs with first WORD minus, not
	   just LIT files; VCVT output of program version too.  ILB
04-Jan-86  show JOBBAS(JCB) and JOBSIZ(JCB) at startup  ILB
ENDC

SEARCH	SYS
SEARCH	SYSSYM
SEARCH	TRM

	VMINOR=3
	VMAJOR=2
	VEDIT=106.

	PHDR	-1,0,PH$REE!PH$REU

;equates

JCB=A0
IMP=A5				;impure area index

Number=D1
CrtCmd=D1
CMDSIZ=D3

Cmd=^H0FF00
HIGH=Cmd!12.
LOW=Cmd!11.

;memory management definitions

	MM$SIZ=0			;memory module size word
	MM$FLG=4			;memory module flags
	MM$NAM=6			;memory module filename
	MM.HDR=14			;module header size

;macros

DEFINE	BITW	SRC,DST
	MOVW	SRC,D7
	ANDW	DST,D7
	ENDM

;impure area

.OFINI
.OFDEF	JNAME,4				;job name to dump
.OFDEF	MCOUNT,4			;module dump count
.OFDEF	BUFFER,12.			;RAD50 unpacking buffer
.OFDEF	MEMFRE,4			;free memory count
.OFSIZ	IMPSIZ

;initialization

INITIA:	GETIMP	IMPSIZ,IMP,EXIT
	MOV	IMP,A3
	MOVW	#[IMP],-(A3)
	MOVW	#[MAP],-(A3)
	MOVW	#[JOB],-(A3)
	CLR	MCOUNT(IMP)

;scan cmd line for job name

SCNLIN:	BYP
	LIN
	BEQ	100$
	FILNAM	JNAME(IMP),XXX
	MOV	JOBTBL,A3
	BR	110$

100$:	MOV	JOBCUR,JCB
	BR	SCNJOB

110$:	MOV	(A3)+,D0
	BEQ	110$
	BMI	BADJOB
	MOV	D0,JCB
	CMM	JOBNAM(JCB),JNAME(IMP)
	BNE	110$

;scan job's partition
SCNJOB:	
	MOV	JOBBAS(JCB),Number
	BEQ	Zippo			; no allocated memory [ILB]
	MOV	Number,A3
	TYPE	<JOBBAS=>
	OCVT	0,OT$TRM
	TYPE	<	JOBSIZ=>
	MOV	JOBSIZ(JCB),Number
	MOV	Number,MEMFRE(IMP)
	DCVT	0,OT$TRM!OT$TSP
	TYPE	<bytes	JOBEND=>
	ADD	A3,Number
	SUB	#2,Number		; calculate JOBEND addr
	OCVT	0,OT$TRM
	CRLF
	BR	MODULE

Zippo:	TYPECR	<?Job has no memory allocated>  ; [ILB]
	JMP	EXIT

;user entered non-existant job name

BADJOB:	TYPESP	<?Job not found>
	JMP	EXIT

;list module or quit

MODULE:	CTRLC	EXIT
	TST	MM$SIZ(A3)		;end of partition?
	JEQ	DONE			; yes
	TSTW	MM$FLG(A3)		; temporary module?
	BNE	MDLNAM			; no
	CMP	MM$NAM(A3),#<<[JOB]_16.>+[MAP]> ; is it a JOBMAP module?
	JEQ	NXTMOD			; yes, skip it!
MDLNAM:	LEA	A1,MM$NAM(A3)		;set up for RAD50 unpacking
	LEA	A2,BUFFER(IMP)
	UNPACK				;unpack filename
	UNPACK
	MOVB	#40,(A2)+		;embed space in text
	UNPACK				;unpack extension
	MOVB	#40,(A2)+		;embed space in text
	CLRB	@A2

	BITW	#FIL,MM$FLG(A3)		;FGD bit set?
	BEQ	100$
	MOVW	#HIGH,CrtCmd		; [ILB]
	TCRT
	BR	110$

100$:	MOVW	#LOW,CrtCmd		; [ILB]
	TCRT

110$:	TTYL	BUFFER(IMP)

MDLSIZ:	MOV	MM$SIZ(A3),D1		;output module size
	SUB	#MM.HDR,D1		;correct size
	DCVT	7,OT$TRM!OT$ZER!OT$TSP

MDLBAS:	MOV	A3,D1			;output module base
	TYPE	<bytes at>
	ADD	#MM.HDR,D1
	OCVT	0,OT$TRM!OT$LSP!OT$TSP

	BITW	#FIL,MM$FLG(A3)		;FIL bit set?
	BEQ	100$			; no
	TYPESP	FIL			; yes

100$:	BITW	#FGD,MM$FLG(A3)		;FGD bit set?
	BEQ	110$			; no
	TYPESP	FGD			; yes

110$:	BITW	#LOK,MM$FLG(A3)		;LOK bit set?
	BEQ	120$			; no
	TYPESP	LOK			; yes

120$:	TSTW	MM.HDR(A3)		; program file with PHDR? (<0) [ILB]
	JPL	160$			; no [ILB]
	VCVT	MM.HDR+2(A3),OT$TRM!OT$TSP	; yes, output version [ILB]
	MOVW	MM.HDR+10(A3),D0	; get program attributes word

	BITW	#PH$REE,D0		;reentrant?
	BEQ	130$			; no
	TYPESP	REE			; yes

130$:	BITW	#PH$REU,D0		;reusable?
	BEQ	140$			; no
	TYPESP	REU			; yes

140$:	BITW	#PH$L12,D0		;requires [1,2] log?
	BEQ	150$			; no
	TYPESP	L12			; yes

150$:	BITW	#PH$OPR,D0		;requires OPR: log?
	BEQ	160$			; no
	TYPESP	OPR			; yes

160$:	CRLF

	MOV	MM$SIZ(A3),D0
	SUB	D0,MEMFRE(IMP)

	INC	MCOUNT(IMP)		;update module count
NXTMOD:	ADD	MM$SIZ(A3),A3		;advance to next module
	JMP	MODULE

DONE:	MOVW	#HIGH,CrtCmd		; [ILB]
	TCRT
	TYPE	<free       >
	MOV	MEMFRE(IMP),D1
	SUB	#2,D1
	CLR	CMDSIZ			; pre-clear for word move
	MOVW	JOBCMZ(JCB),CMDSIZ	; correct free count for JOBCMZ
	SUB	CMDSIZ,D1
	DCVT	7,OT$TRM!OT$ZER!OT$TSP
	TYPECR	<bytes>			; cannot show address because JOBMAP
	TSTW	CMDSIZ			; temporary modules may make it invalid
	BEQ	EXIT
	
	MOVW	#LOW,CrtCmd		; [ILB]
	TCRT
	TYPE	<command file>
	MOV	CMDSIZ,Number
	DCVT	6,OT$TRM!OT$ZER!OT$TSP
	TYPE	<bytes at>
	MOV	A3,Number
	ADD	MEMFRE(IMP),Number
	SUB	CMDSIZ,Number
	OCVT	0,OT$TRM!OT$LSP
	CRLF

EXIT:	MOVW	#HIGH,CrtCmd		; [ILB]
	TCRT
	EXIT

	END