	.TITLE	ISD3
	.IDENT	/HAH009/
	.enabl	lc
;
; ISD3 is the routine that takes apart any Internal Symbol Definition entries
; created by a source language compiler, or by TKB when TKB is creating a
; STB file for a program that has a /DA in the command line.
;
; Note that any .OBJ or .STB files that contain ISD entries CANNOT be re-
; assembled by MAC without deleting the ISD information, since MAC does
; not allow ISD records to be created.
;
	.asect
.=1
is.tkb::
	.blkb	1		;TKB generated
is.lan::
	.blkb	1		;Language processor generated
is.rel::
	.blkb	1		;Relocated IS.LAN record
is.txt::
	.blkb	1		;Text record
;
; TKB generated record types
;
.=1
it.seg::
	.blkb	1		;Start of segment
it.tsk::
	.blkb	1		;Task identification
it.lib::
	.blkb	1		;Autoloadable Library entry point
;
; Language generated and TKB modified language generated record types
;
.=1
il.mod::
	.blkb	1		;Module name
il.sym::
	.blkb	1		;Global symbol name
il.psc::
	.blkb	1		;PSECT name
il.pc::
	.blkb	1		;Line number or PC correlation
il.isn::
	.blkb	1		;Internal symbol name

	.psect	rodata,ro,d
isdsr0::
	.ascii	/;  ISD entry, NOTE: This module cannot be reassembled with/
isdsr1::
	.ascii	/;  ISDs in it, since MACRO does not support it./
isdsr2:						;End of second message
isdend::
	.asciz	/;  End of ISD entry/
isden1:						;End of message
isd1.1::
	.asciz	/Start of segment/
isd1.2::
	.asciz	/Task identification/
isd1.3::
	.asciz	/Autoloadable Library Entry Point/
isd2.1::
isd3.1::
	.asciz	/Module name/
isd2.2::
isd3.2::
	.asciz	/Global symbol/
isd2.3::
isd3.3::
	.asciz	/PSECT/
isd2.4::
isd3.4::
	.asciz	/Line number or PC correlation/
isd2.5::
isd3.5::
	.asciz	/Internal symbol name/
isd4.0::
	.asciz	/Literal record/
	.psect	rwdata,rw,d
rel:	.word	0		;0 if is.lan, 1 if is.rel
	.psect	code,ro
;
; Entry conditions:
;	r3 = Address of input record
;	r4 = Length of input record remaining
;
; Exit conditions:
;	Records processed and printed
;
	.enabl	lsb
	.mcall	put$s

isd3::
	sub	#2,r4		;Any record left?
	bmi	10$		;No, error
	put$s	#fdbout,#isdsr0,#isdsr1-isdsr0
	put$s	#fdbout,#isdsr1,#isdsr2-isdsr1
	mov	fdbout+f.nrbd+2,r5	;Get the start of the buffer
	movb	(r3)+,r1	;Get the type code
	inc	r3		;Unused byte
	call	select		;Process the record type
	.byte	is.tkb,is.txt	;Valid limits
	.word	10$		;Illegal type code
	.word	istkb+1		;TKB record
	.word	islan+1		;Language generated record
	.word	isrel+1		;Relocated language generated record
	.word	istxt+1		;TEXT record, output as .WORD or .BYTE
	put$s	#fdbout,#isdend,#isden1-isdend	;Tell user done with entry
	return			;Done
10$:
	trap	objfmt		;Illegal code if we get here
;
; The record is a TKB produced record.  Handle the appropriate record type.
;
istkb::
	sub	#2,r4		;Any record left?
	bmi	10$		;No, error
20$:				;Process next subrecord
	mov	r3,-(sp)	;Save start of subrecord
	movb	(r3)+,r1	;Get the subrecord type
	movb	(r3)+,r0	;Get the subrecord length
	mov	r0,-(sp)	;Save the subrecord length
	sub	#2,r0		;Count header as processed
	ble	10$		;Error in subrecord length
	call	select		;Process the record
	.byte	it.seg,it.lib	;Valid record limits
	.word	10$		;Bad record number
	.word	itseg+1		;Segment name descriptor (called)
	.word	ittsk+1		;Task ID code (called)
	.word	itlib+1		;Autoloadable Library entry point (called)
	mov	(sp)+,r0	;Get the subrecord length back
	mov	(sp)+,r3	;Restore start of this subrecord
	add	r0,r3		;Point to next subrecord
	sub	r0,r4		;Any more to process?
	bgt	20$		;Yes
	return			;Done
;
; Language processor created records
;
islan::
	clr	rel		;Not a relocated record
	br	30$		;Continue
;
; TKB altered language processor created records
;
isrel::
	mov	#1,rel		;A relocated record
30$:
	sub	#2,r4		;Any record left?
	bmi	10$		;No, error
40$:				;Process next subrecord
	mov	r3,-(sp)	;Save the start of the subrecord
	movb	(r3)+,r1	;Get the subrecord type
	movb	(r3)+,r0	;Get the subrecord length
	mov	r0,-(sp)	;Save the subrecord length
	sub	#2,r0		;Count header as processed
	ble	10$		;Error in subrecord length
	call	select		;Process the record
	.byte	il.mod,il.isn	;Valid subrecord limits
	.word	10$		;Bad record number
	.word	il.mod+1		;Module name
	.word	il.sym+1		;Global symbol name
	.word	il.psc+1		;PSECT name
	.word	il.pc+1		;Line number or PC correlation
	.word	il.isn+1		;Internal symbol definition
	mov	(sp)+,r0	;Get the subrecord length back
	mov	(sp)+,r3	;Get the start of the subrecord back
	add	r0,r3		;Point to next subrecord
	sub	r0,r4		;Any more to process?
	bgt	40$		;Yes
	return			;Done
;
; Language processor specific text records (format undefined)
;
istxt:
	return			;Just dump as .WORDs and .BYTEs
;
; TKB produced segment descriptor entry
;
itseg::
	call	outcom		;Put in the semicolon
	mov	#isd1.1,r0	;Identify ourselves
	call	append		;Copy it
	call	print		;And print it
	call	outcom		;Another semicolon
	mov	#itseg1,r0	;Name of segment
	call	append		;Copy it
	mov	r3,r0		;Point to segment name
	call	addr50		;Convert it
	call	print		;Print it
	add	#4,r3		;Point past name
	call	outcom		;Another semicolon
	mov	#itseg2,r0	;Descriptor address
	call	append		;Copy message
	mov	(r3)+,r0	;Get the address
	call	addoct		;Put in the address
	call	print		;Print the line
	return			;Done with the entry

	.psect	rodata
itseg1::
	.asciz	/Segment name = /
itseg2::
	.asciz	/Segment descriptor address = /

	.psect	code
;
; TKB produced task ID block
;
ittsk::
	call	outcom		;Put in leading semicolons
	mov	#isd1.2,r0	;Print our banner
	call	append		;Copy it
	call	print		;Show it
	call	outcom		;Put in a leading semicolon
	mov	#ittsk1,r0	;Say when it was built
	call	append		;Move it into buffer
	mov	r5,r0		;Move up line address
	mov	r3,r1		;Copy the date pointer
	call	$dat		;Convert date to ASCII
	mov	r0,r5		;Copy line pointer back
	mov	#ittsk2,r0	;Next part of message
	call	append		;Copy it
	mov	r5,r0		;Copy line pointer
	add	#6,r3		;Point to time
	mov	r3,r1		;Copy time pointer
	mov	#5,r2		;Print to decimal of a second
	call	$tim		;Translate the time also
	mov	r0,r5		;Put line pointer back
	call	print		;Print it
	add	#12,r3		;Point past time
	add	#4,r3		;Skip these since
	return			; last two words unused

	.psect	rodata
ittsk1::
	.asciz	/Task created on /
ittsk2::
	.asciz	/ at /
ittsk4::
	.asciz	/Last two words:/

	.psect	code
;
; TKB generated autoloadable library entry point
;
;	.if eq, 1
itlib::
	call	outcom		;Put out a semicolon
	mov	#isd1.3,r0	;Get out banner
	call	append		;Put in buffer
	call	print		;Print it
	call	outcom		;Another semicolon
	mov	#itlib1,r0	;Symbol name message
	call	append		;Move it
	mov	r3,r0		;Point to the symbol name
	call	addr50		;Output it
	add	#4,r3		;Point past the symbol name
	call	print		;Print it
	call	outcom		;Another semi
	mov	#itlib2,r0	;Flags banner
	call	append		;Output it
	mov	(r3)+,r0	;Get the flags byte
	call	addoct		;Output it
	call	print		;Print the line
	call	outcom		;Put out a semicolon
	mov	#itlib3,r0	;Offset message
	call	append		;Copy message
	mov	(r3)+,r0	;Get the offset
	call	addoct		;And put in print line
	call	print		;Print the offset
	call	outcom		;Put in another semicolon
	mov	#itlib4,r0	;Segment descr. offset message
	call	append		;Copy it
	mov	(r3)+,r0	;Get the offset
	call	addoct		;And output it
	call	print		;Print the line
	return			;Done

	.psect	rodata
itlib1::
	.asciz	/Symbol name = /
itlib2::
	.asciz	/Flags byte = /
itlib3::
	.asciz	/Entry point offset from library base = /
itlib4::
	.asciz	/Segment descriptor offset from $$SGD1 = /

	.psect	code
;
; Ilmod - Language processor module name record
;
ilmod::

	.psect	rodata
ilmod1::
	.asciz	/Language = /
ilmod2::
	.asciz	/Module name = /
ilnam::
	.enabl	lsb
	.word	10$
	.word	0
	.word	20$
ilmax == <.-ilnam>/2			;Maximum number of supported lang.

10$:	.asciz	/Macro-11/
20$:	.asciz	/Fortran-77/
	.dsabl	lsb

	.psect	code
;
; Outcom - Insert a leading semicolon into a line
;
; Entry:
;	r5 > Start of line
;
outcom::
	movb	#';,(r5)+	;Put in a semicolon
	movb	#11,(r5)+	;Put in a tab
	return			;Done
;
; Print - Print the line to the output file
;
; Entry:
;	r5		> End of line
;	f.nrbd+fdbout+2	> Start of line
;
print:
	sub	f.nrbd+fdbout+2,r5 ;Calculate length of line
	put$s	#fdbout,,r5	; and output it
	mov	f.nrbd+fdbout+2,r5 ;Point to start of next line
	return			;Done

	.psect	rodata
	.even

	.end
