	TITLE DTADDT

	INTERNAL BEGIN,PAUSE1,PAUSE2,PAUSE3,WORD0,BLK1,CLR,CLW
	INTERNAL UNIT,BLOCK,INI,COMPAR
	EXTERNAL DDT,JOBREL,JOBSYM,JOBSA,JOBFF,JOBREN

;ACCUMULATOR ASSIGNMENTS:
	UNIT==1			;DECTAPE UNIT
	BLOCK==2		;DECTAPE BLOCK
	TAC==3			;GENERAL-PURPOSE ACCUMULATOR
	TAC1==4			;GENERAL-PURPOSE ACCUMULATOR

;CALLI ARGUMENTS:
	RESET=0
	CORE=11
	EXIT=12

;UUO TRAP:
	OPDEF ERROR	[001B8]	;ERROR UUO
	LOC 41
	JSR ERROR.		;ALL ERRORS WILL TRAP AS UUO'S

;VERSION NUMBER:
	LOC 137
	OCT 3			;VERSION NUMBER
;MAIN PROGRAM
	RELOC 0
BEGIN:	CALLI RESET
	JSR INI			;INITIALIZE DECTAPE
	USETI (BLOCK)		;SET BLOCK TO READ
GETCOR:	MOVE TAC,JOBREL		;HIGHEST AVAILABLE LOC IN MEMORY
	CAILE TAC,WORD0-1	;COMPARE WITH LOWEST ADDRESS FOR INPUT
	JRST GOTCOR		;O.K.:	WE CAN INPUT AT LEAST ONE WORD
	ADDI TAC,2000		;INCREASE OUR CORE SIZE BY 1K
	CALLI TAC,CORE		;CORE UUO
	ERROR TAC,NOCORE	;CORE NOT AVAILABLE
	JRST GETCOR		;NOW SEE IF WE HAVE ENOUGH
GOTCOR:	SUBI TAC,WORD0-1	;PUT AVAILABLE MEMORY AREA INTO TAC
	MOVEI TAC1,1101+1	;FIRST UNAVAILABLE DECTAPE BLOCK
	SUB TAC1,BLOCK		;PUT MAX # OF BLOCKS TO READ INTO TAC1
	IMULI TAC1,200		;MAKE IT # OF WORDS
	CAML TAC1,TAC		;SEE IF WE CAN READ REST OF TAPE
	MOVE TAC1,TAC		;NO.:	WE ARE LIMITED BY CORE SIZE
	MOVN TAC1,TAC1		;MAKE WORD COUNT NEGATIVE
	HRLM TAC1,CLR		;CONSTRUCT COMMAND LIST
	INPUT CLR		;READ THE DECTAPE
	STATZ 740000		;CHECK FOR ERRORS
	TTCALL 3,READERROR	;PRINT MESSAGE IF APPROPRIATE
PAUSE1:	JSR INI			;INITIALIZE DECTAPE FOR WRITING
	USETO (BLOCK)		;SET BLOCK TO WRITE
	OUTPUT CLW		;WRITE ONE BLOCK ONLY
	STATZ 740000		;CHECK FOR ERRORS
	TTCALL 3,WRITEERROR	;PRINT MESSAGE IF APPROPRIATE
PAUSE2:	JRST BEGIN
;SUBROUTINES

INI:	0			;JSR HERE TO INITIALIZE DECTAPE CHANNEL
	SKIPL UNIT		;TEST UNIT NUMBER
	CAILE UNIT,7		;TEST UNIT NUMBER
	ERROR UNIT,NOTAVL	;UNIT NUMBER OUT OF RANGE
	SKIPL BLOCK		;GET BLOCK NUMBER
	CAILE BLOCK,1101	;CHECK FOR END OF TAPE
	ERROR BLOCK,BADBLK	;BLOCK NUMBER OUT OF RANGE
	DPB UNIT,[POINT 3,NAME,23]	;FORM SIXBIT UNIT NUMBER
	INIT 0,137		;INITIALIZE DECTAPE IN DUMP MODE
NAME:	SIXBIT .DTA0.		;NAME STORED HERE
	0			;NO BUFFERS
	ERROR UNIT,NOTAVL	;DECTAPE NOT AVAILABLE
	JRST @INI		;RETURN
;COMPARE FIRST AND SECOND BLOCKS.   I.E. WORD0 UP AND BLK1 UP.
COMPAR:	SETZM TAC		;INITIALIZE COMPARISON
CONT:	MOVE TAC1,WORD0(TAC)	;PICK UP WORD IN ONE BLOCK.
	CAME TAC1,BLK1(TAC)	;COMPARE WITH CORRESPONDING WORD.
PAUSE3:	JFCL			;NOT IDENTICAL
	MOVEI TAC1,BLK1+1(TAC)	;GET TOP ADDRESS
	CAIGE TAC1,@JOBREL	;TEST FOR TOP OF MEMORY
	AOJA TAC,CONT		;O.K. TO CONTINUE
	JRST DDT		;NOT O.K.
ERROR.:	0			;JSR HERE FROM UUO TRAP
	TTCALL 3,@40		;PRINT ERROR MESSAGE
	JRST DDT		;RETURN TO DDT
;DATA AREA

CLR:	IOWD 200,WORD0		;COMMAND LIST FOR READING
	0
CLW:	IOWD 200,WORD0		;COMMAND LIST FOR WRITING ONE BLOCK
	0
BADBLK:	ASCIZ .BLOCK?
.
NOTAVL:	ASCIZ .UNIT?
.
READER:	ASCIZ .READ ERROR
.
WRITEE:	ASCIZ .WRITE ERROR
.
NOCORE:	ASCIZ .NO CORE
.
	LIT
	VAR
;ONCE-ONLY PROCEDURE.
;
;FIRST FIND VALUE OF SETUP1 REQUIRED BELOW.
;AND ENSURE THAT THE LIBRARY TAPE HAS THE SHORT VERSION OF JOBDAT ON IT
;(I.E. WITH ONLY THOSE SYMBOLS USED BY USER)
;
;RUN THE LOADER AND TYPE THE LOADING STRING THUS:
;	R LOADER
;	*(DWE)DEV:DTADDT$
;
;	LOADER 5K CORE
;
;PROGRAM THEN WILL LOAD, START AND GO TO DDT.
;USE DDT TO MAKE THE FOLLOWING MODIFICATIONS BEFORE SAVING :
;
;	(CHANGE DDT'S SEARCH LIMITS TO OUR DATA AREA:)
;	(IT WON'T TYPE THESE SYMBOLS BECAUSE WE DIDN'T LOAD THEM)
;	UDDT$:		SETUP1+3/	MOVE T,@SYMP	MOVE T,@JOBREL
;			SETUP1+15/	MOVEI R,0	MOVEI R,WORD0
;
;	(INSERT BREAKPOINTS:)
;	DTADDT$:	PAUSE1$B	PAUSE2$B	PAUSE3(3)$B
;	^C
;
;	.SAVE DEV DTADDT 2
;	JOB SAVED
;	^C
;
;	.
START:	HRLI 0,FF		;COVER UP TO DATA AREA
	HRRI 0,DDT		;SET STARTING ADDRESS TO DDT
	MOVEM 0,JOBSA		;NEW STARTING ADDRESS NEXT TIME
	HLRZM 0,JOBFF		;RESET WOULD HAVE DONE THIS ANYWAY
	HRRZM 0,JOBREN		;IN CASE WE WANT TO RE-ENTER

;MOVE SYMBOL TABLE DOWN BELOW THE DATA.
	HLRZ 1,JOBSYM		;GET LENGTH OF SYMBOL TABLE
	CAIGE 1,START-SYMTOP	;WILL IT FIT?
	MOVEI 1,START-SYMTOP	;NO.:REDUCE THE LENGTH OF THE S.T.
	ANDI 1,-2		;ENSURE S.T. LENGTH IS EVEN.
				;NOW HAVE NEGATIVE S.T. LENGTH IN RIGHT
	HRLI 1,SYMTOP+1(1)	;PUT NEW S.T. ADDRESS IN LEFT HALF
	MOVS 1,1		;NEW S.T. ADDR NOW IN RIGHT HALF
	EXCH 1,JOBSYM		;POINT TO NEW SYMBOL TABLE
	AOBJN 1,.		;FIND TOP OF OLD S.T.
	MOVS 1,1		;TOP OF OLD S.T. IN LEFT HALF
	ADD 1,JOBSYM		;MAKE BLT WORD FOR TRANSFER.
	MOVE 2,[BLT 1,SYMTOP]	;SET TO TRANSFER
	MOVEI 0,<FF-1>!1777	;SET FOR MINIMUM CORE BEFORE SAVING
	MOVE 3,[CALLI 0,CORE]	;SET TO CHANGE TO MINIMUM CORE
	MOVE 4,[HALT .]		;IN CASE OF ERROR RETURN FROM CORE UUO
	MOVE 5,[MOVEI UNIT,0]	;REALISTIC UNIT
	MOVE 6,[MOVEI BLOCK,144];DIRECTORY BLOCK TO START
	MOVE 7,[JRST DDT]	;SET TO RETURN TO DDT.
	JRST 2			;GO TO BLT,CORE-UUO,EXIT

	WORD0=4000		;WORD ZERO OF THE DATA
	BLK1=WORD0+200		;WORD ZERO OF NEXT BLOCK
	SYMTOP=WORD0-2		;ALLOW TWO WORDS IN CASE BUFFERS USED
	FF=SYMTOP+1		;FIRST FREE IS JUST AFTER S.T.
	END START
