	.TITLE	COPYRIGHT
/
/COPYRIGHT (C) 1975
/DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
/
/THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY
/ON A SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH
/THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS
/SOFTWARE, OR ANY OTHER COPIES THEREOF, MAY NOT BE PRO-
/VIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON
/EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO AGREES TO
/THESE LICENSE TERMS.  TITLE TO AND OWNERSHIP OF THE
/SOFTWARE SHALL AT ALL TIMES REMAIN IN DEC.
/
/THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE
/WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COM-
/MITMENT BY DIGITAL EQUIPMENT CORPORATION.
/
/DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
/OF ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DEC.
	.EJECT
	.TITLE	LEGEND
/
/ MACIMG - A MACRO-11 DISK IMAGE BUILDER
/
/ THIS PROGRAM READS IN AN OBJECT PAPER TAPE OF MACRO-11 AND BUILDS
/ A DISK IMAGE OF IT ON DISK UNDER THE SYSTEM FILE NAME OF MAC11.
/ PROGRAM MUST BE RUN WITH API OFF.
/
/ IT CHECKS TO SEE IF "40" OCTAL BLOCKS ARE RESERVED ON THE DISK FOR MAC11
/ SYSTEM PROGRAM. THIS SPACE IS TO PERMIT EXPANSION OF MAC11, PROVIDE
/ FLEXIBILITY IN MAC11 LOAD ADDRESS & START ADDRESS, PROVIDE ROOM FOR PATCH
/ SPACE ETC.. IF THE NUMBER OF BLOCKS ALLOCATED IS LESS THAN 40 OCTAL, AN
/ ERROR MESSAGE IS ISSUED AND IMAGE BUILDING OPERATION IS ABORTED. ALSO
/ CHECK IS MADE TO ENSURE THAT THE MAXIMUM HIGHEST ADDRESS(ON THE PDP-15)
/ IS BELOW THE BOOTSTRAP START ADDRESS(37637) IN BANK 1 OF A 16K SYSTEM.
/ THIS IS TO ENSURE THAT THE ENTIRE PDP-11 MAC11 CODE IS WITHIN THE COMMON
/ MEMORY SPACE(CMS).
/
/
/ DOS-11 LOAD MODULE RECORD FORMAT:
/
/	BYTE	0:	1
/		1:	0
/		2:	BYTE COUNT
/		3:	BYTE COUNT
/		4:	LOAD ADDRESS
/		5:	LOAD ADDRESS
/		6:	DATA
/		7:	DATA
/		10:	.
/		.	.
/		BYTE COUNT - 1:	DATA
/	BYTE COUNT:	CHECKSUM
/
/SIZE OF DATA IS DETERMINED USING BYTE COUNT WHICH IS A TOTAL
/COUNT OF ALL BYTES IN THE RECORD EXCLUDING THE CHECKSUM BYTE.
/
/CHECKSUM IS USED AS A DOUBLE CHECK AGAINST BYTE COUNT AND AS
/A CHECK OF TAPE INTEGRITY.
/
/THE FIRST RECORD OF THE LOAD MODULE PAPER TAPE CONTAINS THE
/GLOBAL SYMBOL DIRECTORY. IT DOES NOT CONTAIN ANY LOAD DATA.
/
/
/ COPYRIGHT: DIGITAL EQUIPMENT CORPORATION, 1972,73 MAYNARD, MASS.
/EDIT #004	JAN. 20, 73
/	005	SK	6-DEC-73	4K,12K IMAGE BUG FIX
/	006	SK	11-JUN-74	1. CHECK MAC11 BLOCK SIZE = 40
/					2. CHECK HIGHEST ADDRESS ON PDP-15<37637
/					3. TAKE MAC11 SIZE FROM SYSBLK
/	007	GAR	19-SEP-74	FIX SO THAT .TRAN WILL WORK
/					CORRECTLY ON A 16K CONFIGURATION.
/	008	BLR	15-JUL-75	ALLOW API ON
/	009	BLR	16-JUL-75	AUTOMATE MEMSIZ/STOP CLOBBER OF MACINT
/	010	MJH	20-AUG-75	DISCLAIMER
DBI=705522		/DISABLE API (BR-009)
EBI=705521		/ENABLE API (BR-009)
/
	.TITLE	IMAGE BUILDER
DBI=705522
EBI=705521
/
BUF	.BLOCK	400	/EDIT 007 GAR
MAC000	NOP		/ENTRY POINT (BR-009)
	.IODEV	-14	/LOAD RK HANDLER
	.INIT	-3,1,MAC000	/INIT TTY (BR-009)
	.WRITE	-3,2,HI,34	/SAY HELLO (BR-009)
MAC050	.INIT	-14,0,0	/INITIALIZE "TRAN" PROCESSOR
	.TRAN	-14,0,34,BUF,256	/READ IN SYSBLK FROM SYSTEM DEV-GAR 007
	.WAIT	-14
	LAC	PARAM	/LOOK THROUGH SYSBLK FOR "MAC11"
	TAD	(1
	DAC	TEMP1
	DAC	TEMP2
MAC001	LAC*	TEMP1	/NAMES MATCH?
	SAD	MACP1	/NO:  LOOK AT NEXT THEN
	SKP		/LOOK AT 2ND HALF OF NAME NOW
	JMP	MAC002
	ISZ	TEMP1
	LAC*	TEMP1	/DOES 2ND HALF MATCH?
	SAD	MACP2	/NO:  LOOK AT NEXT ENTRY
	JMP	MAC003	/A MATCH WAS FOUND
MAC002	LAC	TEMP2	/LOOK AT NEXT ENTRY
	TAD	(7
	DAC	TEMP1
	DAC	TEMP2
	CMA		/END OF NAMES IN SYSBLK?
	TAD*	PARAM
	TAD	PARAM
	SMA		/YES:  TELL USER AND EXIT
	JMP	MAC001	/LOOK AT THIS ENTRY
/
	.WRITE	-3,2,ERR2,34
	JMP	EXIT
/
MAC003	DZM	HIGH	/INITIALIZE HIGHEST LOCATION USED
	ISZ	TEMP1	/BUMP TO FIRST BLOCK #
	LAC*	TEMP1	/SAVE IT FOR OUTPUT
	DAC	BLOCK
	ISZ	TEMP1	/BUMP TO NB
	LAC*	TEMP1	/CHECK IF NB=40?
	SAD	(40
	JMP	LD2	/YES. CONTINUE
	.WRITE	-3,2,ERR3,34	/NO. REPORT & ABORT OPERATION.
	JMP	EXIT
/
	.EJECT
/
/ LOOK FOR BEGINNING OF A BLOCK. IGNORE THE VERY FIRST RECORD SINCE IT CONTAINS
/ GARBAGE
/
LD2	DZM	CKSUM	/INITIALIZE CHECKSUM
	JMS	READ	/READ A FRAME
	LAC	BYTE
	SAD	(1	/CHECK FOR +1 (START OF A BLOCK)
	SKP
	JMP	LD2	/LOOK UNTIL +1 IS FOUND
	ISZ	ONCELY	/YES. SET ONCE ONLY SWITCH TO SKIP FIRST RECORD
	JMS	READ	/READ ANOTHER FRAME
/
/ INPUT AND SAVE BYTE COUNT. IF BYTE COUNT = 6, GO TO PROCESS
/ JUMP BLOCK.
/
	JMS	GETWRD	/GET FULL BYTE COUNT
	TAD	(-4	/SUBTRACT 4 TO MAKE BYTE COUNT CORRECT
	DAC	BYTECT
	SAD	(2	/WAS BYTE COUNT = 6?
	JMP	LJMP	/JUMP IF NO DATA (I.E. - JMP BLOCK)
	JMS	GETWRD	/GET LOAD ADDRESS
	DAC	ODD
	LAC	ONCELY	/FIRST TIME THRO,?
	SAD	(1
	JMP	LD3	/YES. FORGET LOADING
	SAD	(2	/IS THIS THE FIRST ACTUAL DATA BLOCK (BR-009)
	SKP		/SKIP IF YES (BR-009)
	JMP	LD21	/NO - CONTINUE (BR-009)
	LAC	ODD	/GET STARTING ADDRESS (BR-009)
	AND	(160000	/SAVE MEMORY SIZE BITS (BR-009)
	DAC	MEMSIZ	/AND STORE IT (BR-009)
	SAD	(100000	/IS MAC11 8K VERSION (BR-009)
	JMP	LD19	/YES - SAY SO (BR-009)
	SAD	(120000	/IS MAC11 12K VERSION (BR-009)
	JMP	LD20	/YES - SAY SO (BR-009)
	.WRITE	-3,2,LBADK,34	/TELL USER BAD TAPE (BR-009)
	JMP	EXIT	/LEAVE - FATAL ERROR (BR-009)
LD19	.WRITE	-3,2,L8K,34	/SAY 8K MAC11 (BR-009)
	JMP	LD21	/CONTINUE (BR-009)
LD20	.WRITE	-3,2,L12K,34	/SAY 12K MAC11 (BR-009)
LD21	LAC	MEMSIZ		/ADJUST FOR PDP-11 LOCAL MEMORY SIZE
	CMA
	ADD	ODD
	RCR		/15'S MEMORY ADDRESS = 11'S / 2
	AND	(17777	/CLEAR JUNK
	TAD	(-1	/FUDGE FOR PATCH-15 PROBLEM WITH FA=0
	TAD	BASE	/ALWAYS STARTS LOADING BEGINNING AT
	DAC	LADD	/BANK 1.
	LAC	ONCELY	/GET BLOCK COUNT SWITCH (BR-009)
	SAD	(2	/IS THIS THE FIRST ACTUAL DATA BLOCK (BR-009)
	SKP		/SKIP IF YES (BR-009)
	JMP	LD22	/NO - CONTINUE (BR-009)
	LAC	LADD	/GET FIRST MEMORY ADR. (BR-009)
	IAC		/POINT TO SECOND WORD (BR-009)
	DAC	LADSAV	/SAVE IT FOR CLEANUP (BR-009)
			/THIS POINTS TO PLACE WHERE MEMSIZ WILL BE
			/SAVED IN THE IMAGE (BR-009)
LD22	JMS	CHECK	/CHECK ADDRESS LIMITS
	.EJECT
/
/
/ READ IN REMAINDER OF DATA.  IF LOADER HALTS WITH AC= -1, A CHECKSUM
/ ERROR HAS OCCURRED.
/
LD3	JMS	READ	/READ A FRAME
	SMA		/SKIP IF NO MORE DATA REMAINS
	JMP	LD4
	LAC	CKSUM	/IF CHECKSUM IS CORRECT, THEN CONTINUE
	SNA
	JMP	LD2	/CORRECT:  CONTINUE
LBAD	.WRITE	-3,2,ERR1,34	/TELL USER THAT A CHECKSUM ERROR
EXIT	.WAIT	-3		/    OCCURRED.
	.EXIT		/RETURN TO DOS
/
LD4	LAC	ONCELY	/FIRST TIME THRO,?
	SAD	(1
	JMP	LD3	/YES. FORGET LOADING
	LAC	ODD	/STORE 8 BITS AT A TIME, THEN RE-LOOP
	RAR
	SNL
	JMS	EC		/CLEAR THE EVEN BYTE
	SZL
	JMS	OC		/CLEAR THE ODD BYTE
	LAC	BYTE	/ODD BYTE GETS PUT IN BITS 3-9
	SZL!CLL
	ALS+10		/ODD BYTE
	XOR*	LADD	/COMBINE BYTE WITH PREVIOUS ONE (IF ANY)
	DAC*	LADD
	LAC	ODD	/NOW ADJUST ADDRESS
	RAR		/ODD BYTE FORCES BUMP OF ADDRESS
	SZL
	ISZ	LADD
	LAC	LADD
	JMS	CHECK	/CHECK ADDRESS LIMITS
	ISZ	ODD	/(FOR NEXT TIME)
	JMP	LD3	/DO NEXT BYTE
EC	0		/ROUTINE TO CLEAR THE EVEN BYTE. ODD BYTE LEFT UNTOUCHED
	LAC	(177400
	AND*	LADD
	DAC*	LADD
	JMP*	EC
OC	0		/ROUTINE TO CLEAR THE ODD BYTE. EVEN BYTE LEFT UNTOUCHED
	LAC	(377
	AND*	LADD
	DAC*	LADD
	JMP*	OC
/
	.EJECT
/
/ INPUT A FRAME, DECREMENT BYTE COUNT, AND ACCUMULATE CHECKSUM.
/
RSF=700101
RCF=700102		/CLEAR READER FLAG (BR-007)
RSA=700104
RRB=700112
READ	0
	DBI		/DISABLE API INTS (BR-009)
	IOF		/TURN OFF INTERRUPTS FOR A SECOND
	RSA		/READ IN ALPHANUMERIC MODE
SPO005	IORS		/CHECK FOR EOT ERROR (BR-05)
	AND	(1000	/DITTO (BR-05)
	SNA		/SKIP IF EOT (BR-009)
	JMP	SPO006	/CONTINUE READ (BR-009)
	RCF		/CLEAR READER FLAG - IF SET (BR-009)
	ION		/ENABLE INTS (BR-009)
	EBI		/ENABLE API BREAKS (BR-009)
	JMP	LBAD	/SAY SO AND EXIT (BR-05)
SPO006	RSF		/WAIT FOR IT (BR-05)
	JMP	SPO005	/NO FLAG - STAY IN LOOP (BR-05)
	RRB		/READ IN BYTE
	AND	(377	/MASK OFF JUNK BITS
	DAC	BYTE	/SAVE BYTE
	TAD	CKSUM	/ADD TO CHECKSUM
	AND	(377	/USE ONLY 8 BITS OF CHECKSUM
	DAC	CKSUM
	ION		/TURN INTERRUPTS BACK ON
	EBI		/ENABLE API INTS (BR-009)
	LAW	-1	/DECREMENT BYTE COUNT BY ONE
	TAD	BYTECT
	DAC	BYTECT
	JMP*	READ	/RETURN
	.EJECT
/
/ ASSEMBLE ONE FULL WORD OF DATA
/
GETWRD	0
	JMS	READ	/GET ONE CHARACTER
	LAC	BYTE	/SAVE BYTE TEMPORARILY
	DAC	TEMP
	JMS	READ	/GET ANOTHER FRAME
	LAC	BYTE	/PLACE THIS FRAME IN THE HIGHER ORDER BYTE
	CLL
	ALS+10
	XOR	TEMP	/ASSEMBLE BOTH FRAMES INTO A COMPLETE WORD
	JMP*	GETWRD	/RETURN
	.EJECT
/
/ PROCESS JUMP BLOCK
/
LJMP	LAC	MEMSIZ	/GET 11 LOCAL MEM SIZE INDICATOR (BR-009)
	SAD	(120000	/IS IT 12K
	LAC	(60000	/YES LOAD ACTUAL MEMSIZ (BR-009)
	SAD	(100000	/IS IT 8K (BR-009)
	LAC	(40000	/YES LOAD ACTUAL MEMORY SIZE (BR-009)
	DAC*	LADSAV	/SAVE IT IN IMAGE - WORD 2 (BR-009)
	.TRAN	-14,1,0,20000,7168	/WRITE IMAGE TO DISK (BR-009)
BLOCK=.-3
SIZE=.-1		/SIZE SPECIFIED IN SYSBLK
	.WAIT	-14		/WAIT FOR IT
	.WRITE	-3,2,DONE,34	/TELL USER THE OPERATION IS COMPLETE
	JMP	EXIT
/
/ CHECK ADDRESS LIMITS. HIGHEST PDP-15 ADDRESS SHOULD BE BELOW THE BOOTSTRAP
/ START ADDRESS.
/
CHECK	0
	DAC	GETWRD	/AC HAS CURRENT ADDRESS (SAVE IT TEMP)
	CMA		/DETERMINE IF THIS ADDRESS IS HIGHER
	TAD	(1
	TAD	HIGH
	SMA
	JMP*	CHECK	/OLD HIGH LIMIT IS STILL LARGER
	LAC	BASE	/CHECK IF HIGH LIMIT EXCEEDED
	CMA
	TAD	GETWRD
	ADD	SIZE
	SMA
	JMP	TOOBIG	/YES. REPORT & ABORT OPERATION.
	LAC	GETWRD	/NO. SAVE NEW HIGH
	DAC	HIGH
	JMP*	CHECK	/RETURN
/
/ SIZE OF MAC11 TOO BIG; REPORT ERROR AND ABORT OPERATION
/
TOOBIG	.WRITE	-3,2,ERR4,34
	JMP	EXIT
	.EJECT
/
HIGH	0		/HIGHEST LOAD ADDRESS(PDP-15)
ONCELY	0		/ONCE ONLY SWITCH
ODD	0		/EVEN/ODD BYTE SWITCH
BYTECT	0		/RECORD BYTE COUNT
CKSUM	0		/RECORD CHECKSUM
TEMP	0
TEMP1	0
TEMP2	0
BYTE	0		/DATA BYTE STORAGE
LADD	0		/POINTER TO LOAD ADDRESS
MACP1	.SIXBT	/MAC/
MACP2	.SIXBT	/11@/
BASE	20000
MEMSIZ	0	/PDP-11 LOCAL MEMORY SIZE INDICATOR (BR-009)
PARAM	 BUF	/EDIT 007-GAR
LADSAV	0	/LOCATION OF STORAGE FOR MEMSIZ INDICATOR IN IMAGE (BR-009)
	.EJECT
/
/ MESSAGES
/
ERR1	405002
	0
	.ASCII	/CHECKSUM ERROR/<15><12>
/
ERR2	406002
	0
	.ASCII	/MAC11 NOT ON SYS DEV/<15><12>
/
ERR3	411002
	0
	.ASCII	/MAC11 SIZE ON DISK NOT = 40 BLOCKS/<15><12>
/
ERR4	410002
	0
	.ASCII	/HIGHEST MAC11 ADDRESS NOT IN CMS/<15><12>
HI	405002
	0
	.ASCII	'MCLOAD XVM V1A000'<15><12>
L8K	410002
	0
	.ASCII	<12>'LOADING MAC11 FOR 8K UNICHANNEL'<15><12>
L12K	410002
	0
	.ASCII	<12>'LOADING MAC11 FOR 12K UNICHANNEL'<15><12>
LBADK	410002
	0
	.ASCII	'ERROR: MAC11 NOT 8K OR 12K VERSION'<15><12>
/
DONE	403002
	0
	.ASCII	/DONE/<15><12>
/
	.END	MAC000
