Google
 

Trailing-Edge - PDP-10 Archives - dec-10-omona-u-mc9 - dteldr.mac
There are 6 other files named dteldr.mac in the archive. Click here to see a list.
TITLE	DTELDR BOOTSTRAP/DUMP PDP-11 CONNECTED VIA DTE20  V1(21)
SUBTTL  E. SOCCI/EJW/SMM  3 JAN 77

;COPYRIGHT 1972, 1975, 1976   DIGITAL EQUIPMENT CORP., MAYNARD, MASS., USA
	SEARCH	UUOSYM		;GET SYSTEM SYMBOLS
	.REQUIRE REL:HELPER	;NEED FOR /HELP SWITCH

;LOADING INSTRUCTIONS:
;.R LINK
;*/SEGMENT:LOW DTELDR/GO
;.SAVE DTELDR

;TAKEN FROM BOOT11 %4A(44) ON 20-JUN-76
SALL

.EDTR==0	;DEC DEVELOPMENT
.MAJV==1	;MAJOR VERSION
.MINV==0	;MINOR VERSION
.EDIT==21	;EDIT NUMBER

%%DTLD==.EDTR*1B2+.MAJV*1B11+.MINV*1B17+.EDIT

	LOC	137
	%%DTLD
	RELOC
SUBTTL MACRO DEFINITIONS

	DEFINE	MSG(STRING)<
	OUTSTR	[ASCIZ\STRING
\]
	>
	DEFINE	WARNC	(STRING,AC)<
	PUSHJ	P,[OUTSTR [ASCIZ \% STRING \]
		   ADDI	AC,"0"
		   OUTCHR	AC
		    OUTSTR [ASCIZ\
\]
		   RETURN]
	>
	DEFINE	TELLCR	(STRING)<
	PUSHJ	P,[OUTSTR	[ASCIZ	\" STRING
\]
		   RETURN]
	>

	DEFINE	WARNCR	(STRING)<
	PUSHJ	P,[OUTSTR	[ASCIZ	\% STRING
\]
		   RETURN]
	>

	DEFINE	ERROR	(STRING)<
	JRST	[OUTSTR	[ASCIZ \? STRING
\]
		JRST	ERRXIT]
>

	DEFINE	LERROR	(STRING,BIT,AUTO)<
	JRST	[OUTSTR [ASCIZ \% STRING
\]
		 MOVE	T1,[BIT]
		IFNB <AUTO> <SKIPL ATOFLG>
		 JRST	RETRY
		 IFNB <AUTO> <JRST ERRXIT>]
	>
	DEFINE	ERRORC	(STRING,AC)<	;DISPLAYS UUO FAILURE, INCLUDING CODE
	JRST	[OUTSTR [ASCIZ \? STRING \]
		ADDI	AC,60
		OUTCHR	AC
		OUTSTR	[ASCIZ\
\]
		JRST	ERRXIT]
>

	DEFINE	ERRCH	(NUM)<		;DISPLAYS A CHARACTER & TWO SPACES
	PUSHJ	P,[ADDI	NUM,60
		OUTCHR	NUM
		OUTCHR	["  "]
		RETURN]
>

	DEFINE	USEROR	(STRING)<
	JRST	[OUTSTR	[ASCIZ \? STRING
\]
		JRST	STARTE]
>

	DEFINE	RETURN <
	POPJ	P,
>
SUBTTL DEFINITIONS

;DTE DEVICE CODES

	DTE0==200
	DTE1==204
	DTE2==210
	DTE3==214

;DTE20 CONO BITS (NAMES FROM KL10 EFS CHAP 4.3)


	TO11DB==1B22		;TO -11 DOOR BELL
	CR11B==1B23		;CLEAR RELOAD -11 BUTTO0
	SR11B==1B24		;SET RELOAD -11 BUTTON
	CL11PT==1B26		;CLEAR -11 REQUESTING A 10 INTERRUPT BIT
	TO11ER==1B27		;TO -11 ERROR
	CLTO11==1B29		;CLEAR TO -11 NORMAL TERMINATION FLAG (TO11DN)
	CLTO10==1B30		;CLEAR TO -10 NORMAL TERMINATION FLAG (TO10DN)
	PILDEN==1B31		;ENABLE LOADING PIA
	PI0ENB==1B32		;PI0 ENABLE
	PIA==7B35		;PIA

;DTE20 CONI BITS 
	RM==1B20		;RESTRICTED MODE 11
	DEAD11==1B21		;11 POWER FAILURE
	TO11DB==1B22		;TO -11 DOORBELL PRESSED
	TO10DB==1B26		;TO -10 DOORBELL
	TO11ER==1B27		;ERROR OCCURRED DURING TO-11 XFER (CLEARED BY CLTO11)
	TO11DN==1B29		;TO -11 NORMAL TERMINATION
	TO10DN==1B30		;TO -10 NORMAL TERMINATION
	TO10ER==1B31		;TO -10 ERROR
	PI0ENB==1B32		;PI0 ENABLE
	PIA==7B35		;PIA


;DTE20 DATAO DEFINITIONS

	TO10IB==1B23		;"I" BIT, SAYS INTERRUPT 11 AFTER XFER
	TO10BC==7777B35		;TO-10 BYTE COUNT FIELD

	CLRDTE==CR11B+CL11PT+CLTO11+CLTO10		;CLEAR OUT A DTE WITH CONO THESE BITS
;ERROR.SYS DEFINITIONS

	.DMERR==5		;DAEMON UUO CODE TO APPEND TO ERROR.SYS

	.ERRTR==3		;NUMBER OF RETRIES TO TRY

	.ERERL==31		;11 RELOAD ERROR CODE IN ERROR.SYS ENTRY

	.ERNUM==0		;CPU#,,DTE#
	  ER.MAS==1B0		;MASTER DTE BIT
	.ERSTS==1		;STATUS WORD
	  ER.LOG==1B0		;**DEPEND ON THIS BIT BEING RESERVED FOR
				;  TOPS20 - SAYS TO WRITE AN ERROR LOG
				;  ENTRY JUST FOR THE RELOAD (NO OTHER 
				;  ERRORS ENCOUNTERED
	  ER.DPF==1B2		;DUMP FAILED
	  ER.10E==1B3		;TO-10 ERROR DURING DUMP
	  ER.11E==1B4		;TO-11 ERROR PASSING BOOTSTRAP PROGRAM OVER
	  ER.RLF==1B6		;RELOAD FAILED
	  ER.NPF==1B7		;POWER FAIL FAILED TO COME UP
	  ER.PUF==1B8		;POWER FAIL FAILED TO CLEAR
	  ER.RMF==1B9		;ROM DID NOT SEND DOORBELL TO 10 AFTER IT STARTED
	  ER.BSF==1B10		;BOOT PROGRAM DIDN'T MAKE IT TO 11
	  ER.NRL==1B11 		;11 ROM NEVER CLEARED TO-11 DOORBELL
				;(TEMP BIT ASSIGNMENTS)
	  ER.DHG==1B12		;TO-10 BYTE XFER FOR DUMP HUNG
	  ER.ENF==1B13		;ENTER FAILURE FOR DUMP FILE
	  ER.OPE==1B14		;OPEN FAILURE FOR DUMP OUTPUT DEVICE
	  ER.OUF==1B15		;OUTPUT FAILURE FOR DUMP FILE
	  ER.TT1==1B16		;TO-11 BYTE XFER TIMED OUT
	  ER.RTC==7B35		;RETRY COUNT
	.ERFNM==2		;FILE NAME POINTER WORD
	.ERSIZ==3		;SIZE OF FILE NAME STRING

	.ERLEN==^D20	;ALLOW 100 CHAR STRING
;PARAMETERS
	DTEBSZ==200*10	;8 DISK BLOCK BUFFER
IFG DTEBSZ*2-TO10BC,<PRINTX BUFFER SIZE TOO BIG FOR DTE DATAO>
	DTEMAX==3	;MAXIMUM DTE NUMBER TO LOOK AT ON AUTO RELOADS
	CPUMAX==0	;MAXIMUM CPU NUMBER TO LOOK AT ON AUTO RELOADS
	INDEV==1	;INPUT CHANNEL
	INMODE==17	;INPUT FROM INDEV
	OUTDEV==2	;OUTPUT FOR DUMP
	OUMODE==17	;OUTPUT FROM OUTDEV

	PDSIZ==20	;SIZE OF PUSH DOWN LIST

	ONES11==177777	;=ALL ONES AS FAR AS THE 11 CAN SEE



;DEVCHR BIT DEFINITIONS
	DEVPTR==200,,0	;PAPER TAPE READER

;TRMOP. DEFINITIONS

	.TOOUS==7	;STRING OUTPUT
;AC'S

	T1=1		;SCRATCHED IN SUBROUTINES
	T2=T1+1
	T3=T2+1
	T4=T3+1
	T5=T4+1		;[42]
	P1=T5+1		;PRESERVED IN SUBROUTINES
	P2=P1+1
	P3=P2+1
	P4=P3+1

	BC=P4+1		;BYTE COUNT OF DATA IN GROUP
	BA=BC+1		;OUTPUT BYTE ADDRESS
	BYTE=BA+1	;LAST -11 BYTE READ FROM FILE
	FB=BYTE+1	;MOD 4 POSITION IN INPUT WORD
	RB=FB+1		;RELOCATION FOR -11 BUFFER

	P=17		;CALL STACK
	;DESCRIPTION OF OUTPUT FROM MACX11/P GENERATED ASSEMBLY
	;THAT IS, WHAT INPUT SHOULD LOOK LIKE
	;APPROXIMATELY

;-----------------------------------------------------------------------
;[(0-1)/8-BIT BYTE#2/8-BIT BYTE #1,,(18-19)/8-BIT BYTE #4/8-BIT BYTE #3]
;-----------------------------------------------------------------------

;THE ABOVE IS SO-CALLED PACKED MODE.  IN IMAGE MODE, THEY APPEAR
;ONE BYTE PER WORD IN ASCENDING BYTE ORDER.

;	THE BYTES IN -11 ORDERING (IE, AFTER ABOVE UNTANGLING) ARE:
;		ANY NUMBER OF 0 BYTES (DISCARD)
;		CONSTANT 1
;		CONSTANT 0
;		BCL
;		BCU
;		AL
;		AU
;		BC-6 BYTES OF DATA IN ORDER STARTING WITH THE BYTE FOR A
;		C
;			WHERE BC=BCU*400+BCL	THE BYTE COUNT
;			      A =AU *400+AL	THE FIRST BYTE ADDRESS
;			      C =          	THE CHECKSUM
;	THE ABOVE CAN BE REPEATED INDEFINITELY.
;	THE LAST SUCH GROUP HAS BC=6 AND THE STARTING ADDRESS IS A.

;THE CHECKSUM IS A SIMPLE ADD OF THE BYTES STARTING WITH CONSTANT 1 AND
;INCLUDING THE CHECKSUM--THE RESULT IS 0 IN 8 BITS.
	SUBTTL	LOAD PROGRAM

USTART:	SETZM	ATOFLG		;CLEAR THE PERMANENT FLAG
	JRST	START		;GO START
STARTE:	CLRBFI			;CLEAR TTY INPUT IF ERROR
START:	RESET
	SKIPE	ATOFLG		;JUST FINISHED AUTOMATIC RELOAD?
	JRST	START2		;YES, DON'T CLEAR OUR DATABASE
	SETZM	FWAZER		;CLEAR STORAGE
	MOVE	T1,[FWAZER,,FWAZER+1]
	BLT	T1,LWAZER
	SETOM	FWAONE		;PRESET SWITCH ANSWERS TO -1
	MOVE	T1,[FWAONE,,FWAONE+1]
	BLT	T1,LWAONE
START2:	MOVE	P,[IOWD	PDSIZ,PDLST]

	SKIPE	ATOFLG		;IF NOT DOING /AUTO, GET COMMAND, ELSE
	JRST	ATOWAT		;GO WAIT FOR A FRONT END THAT NEEDS RELOADING
	MOVE	T1,['DSKDSK']	;IN MANUAL MODE, USE DSK AS DEFAULT FOR
	MOVEM	T1,DEFDEV	; LOADING AND DUMPING DEFAULT DEVICES
	PUSHJ	P,GETCOM	;GO GET COMMAND
	SKIPL	A.TERM		;/TERMINATE?
	JRST	IGNORE		;YES
	SKIPL	A.INIT		;/INITIALIZE?
	JRST	STARTP		;YES
	SKIPL	A.RELD		;/RELOAD?
	JRST	RELOAD		;YES
	SKIPGE	A.AUTO		;/AUTOMATIC?
	JRST	START		;NO, NOTHING THEN
	JRST	ATOWAT		;GO DO /AUTO FOR THE FIRST TIME. SET ATOFLG.
SUBTTL /AUTO PROCESSING

ATOWAT:	SKIPE	ATOFLG		;FIRST TIME THROUGH?
	JRST	ATOWT1		;NO,SKIP INITIAL STUFF
	SETOM	ATOFLG		;SET THE PERMANENT AUTO FLAG,
				; ONLY CLEARED WHEN PROGRAM IS MANUALLY
				; RESTARTED
	MOVE	T1,['SYSXPN']	;FOR AUTOMATIC MODE USE SYS AND XPN AS
	MOVEM	T1,DEFDEV	; DEVICE FOR LOADING AND DUMPING
	SETZM	DMPFLG		;ASSUME NO DUMP
	SKIPGE	A.NDMP		;DID HE TYPE /NODUMP?
	SETOM	DMPFLG		;NO, DO A DUMP
	SETOM	A.SEL		;INDICATE THAT SOURCE IS TO COME FROM
				; DEFAULT PLACE.
	SETOM	DTUBLK		;INDICATE THIS JOB IS TO
	MOVE	T1,[.DTERJ,,DTUBLK] ;BE THE AUTO RELOAD JOB
	DTE.	T1,		;DO
	  ERROR	DTE. UUO failed to set reload job

ATOWT1:	SETZB	P1,P2		;ALWAYS START WITH CPU0, DTE0

ATOWT2:	MOVEM	P2,DTUBLK	;DTE# IN RH
	HRLM	P1,DTUBLK	;CPU# IN LH
	MOVE	T1,[.DTEGS,,DTUBLK] ;GET DTE STATUS
	DTE.	T1,
	  JRST	ATOWT3		;IGNORE THE ERROR
	TLNN	T1,(DT.RLD)	;RELOAD THIS ONE?
	JRST	ATOWT3		;NO
	MOVEM	P1,A.CPU	;YES, SETUP CPU NUMBER AND
	MOVEM	P2,A.DTE	;DTE NUMBER
	MOVE	T1,DMPFLG	;GET STATE OF DUMP, -1 MEANS DUMP
	MOVEM	T1,A.NDMP	;SET /NODUMP FLAG ACCORDINGLY
	JRST	ATORLD		;AND GO DO AN AUTO RELOAD.

ATOWT3:	CAIGE	P2,DTEMAX	;MAX DTE# TO LOOK AT PASSED OR DONE?
	AOJA	P2,ATOWT2	;NO, CONTINUE WITH NEXT DTE
	SETZ	P2,		;YES, START WITH DTE 0 AGAIN
	CAIGE	P1,CPUMAX	;MAX CPU# TO LOOK AT PASSED OR JUST DONE?
	AOJA	P1,ATOWT2	;NOT FINISHED YET
	MOVEI	T1,0		;FOREVER, UNTIL DTESER WAKES US UP
	HIBER	T1,
	  ERROR HIBER failure
	JRST	ATOWT1		;WE WOKE UP, SEE WHAT NEEDS TO BE DONE
SUBTTL /RELOAD

;HERE WHEN RETRYING THE RELOAD IN /IMAGE MODE
START6:	RESET			;RECLAIM SPACE IF RE-STARTING
	XCT	START2		;SET UP PUSH DOWN LIST

RELOAD:	SKIPL	A.AUTO		;DID HE TYPE /AUTO?
	USEROR	Cannot use /AUTOMATIC with /RELOAD
	SKIPL	A.TERM		;OR /TERMINATE?
	USEROR	Cannot use /TERMINATE with /RELOAD
	SKIPL	A.INIT		;DID HE TYPE /INITIALIZE?
	USEROR	Cannot use /INITIALIZE with /RELOAD
;HERE ON /AUTO TO BYPASS SYNTAX CHECKING

ATORLD:	PUSHJ	P,SETCOD	;SETUP I/O CODES AND OTHER STUFF
	MOVSI	T1,(ER.RLF+ER.DPF) ;ASSUME DUMP AND RELOAD FAILED - IF
				; THEY SUCCEED, TURN OFF THE BITS
	IORM	T1,ERRWRD
	MOVEI	T1,ATORL1	;GET PC TO RETRY AT
	MOVEM	T1,RTRYPC	;STORE IT
	MOVEI	T1,JSTRLD	;GET PC TO START AT IF RETRIES FAIL
	MOVEM	T1,FAILPC
ATORL1:	PUSHJ	P,STRROM	;START ROM
	PUSHJ	P,DODUMP	;DO A DUMP, IF NECESSARY
	JRST	JSTRL0		;DON'T START ROM UP AGAIN
JSTRLD:	PUSHJ	P,STRROM	;START ROM
JSTRL0:	MOVEI	T1,JSTRLD	;PC TO RETRY AT
	MOVEM	T1,RTRYPC	;STORE FOR RETRY ROUTINE
	MOVEI	T1,ERRXIT	;ROUTINE IF RETRIES FAIL
	MOVEM	T1,FAILPC
JSTRL1:	TELLCR	PDP-11 loading
	SKIPL	T1,A.SEL	;/SELECT:SOMETHING?
	JRST	[CAIN	T1,10
		 JRST	FROM10
		 CAIN	T1,11
		 JRST	FROM11
		 JRST	START]	;NOT SUPPOSED TO HAPPEN


;HERE IF NO /SELECT. IF MASTER, GET RELOAD PROG FROM THE 11
; IF NOT MASTER, GET IT FROM THE 10

	SKIPN	MASTER		;IS THE SPECIFIED FRONT END THE MASTER?
	JRST	FROM10		;NO, GET THE CODE FROM THE 10 VIA DTE
				;YES, FALL INTO FROM11

FROM11:	SKIPN	DEV		;MAKE SURE NO FILESPEC WAS TYPED
	SKIPE	NAME
	USEROR	Cannot specify filespec if /SELECT:11 used
	SKIPN	EXT
	SKIPE	DIRECT
	USEROR	Cannot specify filespec if /SELECT:11 used
	MOVE	P1,[POINT 18,RP4PRG]	;POINT TO RP04 PORT CONTENTION CODE
	PUSHJ	P,GETROM	;GET 11 ROM WORD FROM MONITOR
	TRNN	T1,DT.RP4	;IS CODE TO BE GOTTEN FROM RP04?
	MOVE	P1,[POINT 18,DTAPRG] ;NO, DECTAPE OR FLOPPY.
	HRRM	T1,(P1)		;PUT ROM WORD INTO PROGRAM.
	MOVE	T1,P1		;GET ARG IN T1
	PUSHJ	P,MSGT11	;SEND IT TO ROM WHICH WILL START PROGRAM
	MOVEI	T1,TO11DB	;WAKE UP THE LITTLE PROGRAM
	XCT	DTECNO		;DONG
	PUSHJ	P,DBWAIT	;WAIT FOR DOORBELL WHEN LOADED PROGRAM
				; STARTS, ENTER PRIMARY PROTOCOL AND TELL OPR
	JRST	START		;DONE.


;ROUTINE TO SET T2 TO BE CURRENT TIME OF DAY PLUS C(T3),
; ACCOUNTING FOR MIDNIGHT

SETIME:	MSTIME	T2,
	ADD	T2,T3		;ARG
	CAML	T2,[^D24*^D60*^D60*^D1000] ;PASS MIDNITE?
	SUB	T2,[^D24*^D60*^D60*^D1000] ;YES, ACCOUNT FOR THAT
CPOPJ:	RETURN


;ROUTINE TO SKIP IF ITS PAST THE INCREMENTAL TIME OF DAY AS
; SET BY SETIME.

ISTIME:	MSTIME	T3,
	CAML	T3,T2		;IS IT PAST TIME?
	AOS	(P)		;YES
	RETURN			;RETURN
FROM10:	SKIPL	A.SWIT		;DID HE TRY TO SPECIFY SWITCHES?
	WARNCR	<Reload source is -10, /SWITCH ignored>
	MOVEI	T1,INMODE	;SHOULD BE DUMP MODE (BECAUSE WE'RE LOCKED)
	SKIPN	T2,DEV		;GET DEVICE
	HLLZ	T2,DEFDEV	;GET PRESENT DEFAULT (DSK OR SYS)
	SETZ	T3,		;NO BUFFERS IN DUMP MODE
	OPEN	INDEV,T1	;OPEN FILE
	  USEROR	Can't OPEN the input device
	SETZM	INHDR+2		;SIMULATE OLD BUFFERED MODE IO

	SKIPE	T1,NAME		;GET FILE NAME
	JRST	.+3
	MOVE	T1,['DTEL00']	;DEFAULT
	ADD	T1,A.DTE	;MAKE DEFAULT NAME INCLUDE DTE#
	MOVE	T2,EXT		;GET EXTENSION
	JUMPN	T2,FROM1.	;JUMP IF WE DON'T NEED DEFAULT
	HRLZI	T2,'BIN'	;DEFAULT IF NOT A11
	SKIPL	A.A11		;WAS /A11 SPECIFIED?
	HRLZI	T2,'A11'	;YES, DEFAULT IS A11
FROM1.:	TRZ	T2,-1		;CLEAR NULL FLAG
RELOOK:	MOVEI	T3,0		;CLEAR WORD
	MOVE	T4,DIRECT	;GET DIRECTORY
	LOOKUP	INDEV,T1	;LOOKUP FILE
	  JRST	[SKIPE	EXT	;CHECK ARGUMENT
		 TLZ	T2,-1	;ALL DONE IF NON-ZERO
		 TLZE	T2,-1	;SEE IF DEFAULT EXT AND NO DOT
		 JUMPE	T2,RELOOK  ;YES--IF NOT FOUND TRY NULL EXT.
		 USEROR	LOOKUP failed
		]

STRTLD:	MOVE	T1,[POINT 18,DTEPRG] ;POINT TO DTE LOADER
	PUSHJ	P,MSGT11	;AND GIVE TO ROM
	MOVEI	T1,TO11DB	;RING DOORBELL TO START IT UP
	XCT	DTECNO

	SETOM	FB		;PRESET FILE BYTE POSITION

	;..
	;..
LDGRPL:	SKIPL	A.A11		;A11 FORMAT?
	JRST	LDA11		;YES, GO DO A11 FILE LOAD
	PUSHJ	P,GETBYT	;GET BYTE
	  ERROR	EOF at start of file group
	JUMPE	BYTE,LDGRPL	;LOOP THROUGH NULLS
	CAIN	BYTE,377	;DISCARD DELETES
	JRST	LDGRPL		; ..
	CAIE	BYTE,1		;VERIFY CONSTANT 1
	ERROR	File group has junk instead of constant 1
	MOVEM	BYTE,CHKSUM	;INITIALIZE CHECKSUM
	PUSHJ	P,GETBYT	;GET BYTE
	  ERROR	EOF after file constant 1
	SKIPE	BYTE		;VERIFY CONSTANT 0
	ERROR	file group has junk instead of constant 0
	PUSHJ	P,GETWRD	;GET WORD
	SKIPGE	A.IMAG		;SEE IF IMAGE MODE
	SKIPE	T1		;NO--SEE IF 0
	JRST	LDGRP2		;OK
	WARNCR	File zero byte count--trying again in /IMAGE mode
	SETZM	A.IMAG		;SET /IMAGE SWITCH
	USETI	INDEV,1		;RESTART AT BLOCK 1
	SETZM	INHDR+2		;FORCE REREAD
	JRST	LDGRPL		;LOOKUP FILE AND TRY AGAIN

LDGRP2:	MOVEI	BC,-6(T1)	;GET DATA BYTE COUNT
	SKIPGE	BC		;SEE IF ACCEPTABLE
	ERROR	File group byte count less than 6
	PUSHJ	P,GETWRD	;GET WORD
	MOVEM	T1,ADDRES	;SAVE AS STARTING ADDRESS
	JUMPE	BC,THATAL	;JUMP IF THIS IS THE START BLOCK
;LOOP GETTING DATA AND TRANSFERRING IT TO THE -11
;MESSAGES TRANSFERRED TO THE -11HAVE A 4 BYTE HEADER CONTAINING
;THE BYTE COUNT OF THE THE DATA AFTER THE HEADER AND THE ADDRESS OF
;WHERE TO PUT IT IN THE SECOND 2 BYTES. WHEN THE START BLOCK IS
;READ FROM THE FILE, A 4 BYTE MESSAGE CONSISTING OF 2 ZERO BYTES
;AND 2 BYTES OF START ADDRESS.

DTEMML==DTEBSZ*4-4		;MAXIMUM LOAD MESSAGE WE CAN TRANSFER

LDDATL:	MOVEI	P1,DTEMML	;DO AN LONG A PIECE AS WE CAN
	CAIGE	BC,DTEMML	;MAKE SURE FILE HAS THAT MANY
	MOVE	P1,BC		;NO--USE WHAT IS IN FILE
	MOVE	P2,P1		;SET COUNT FOR FETCH

	MOVE	P3,[POINT 8,DTEBUF] ;START TO ASSEMBLE LOAD MESSAGE
	IDPB	P1,P3		;STORE LOW BYTE OF BYTE COUNT
	ROT	P1,-^D8		;POSITION TO HIGH BYTE
	IDPB	P1,P3		;AND STORE THAT TOO
	ROT	P1,^D8		;RESTORE BYTE COUNT
	MOVE	T1,ADDRES	;GET ADDRESS TO STORE DATA
	IDPB	T1,P3		;AGAIN, LOW BYTE
	LSH	T1,-^D8	
	IDPB	T1,P3		;AND HIGH BYTE

;LOOP FILLING BUFFER FOR ONE TRANSFER TO THE -11
LDDATM:	PUSHJ	P,GETBYT	;GET BYTE
	  ERROR	EOF during data in file group
	IDPB	BYTE,P3		;STORE DATA BYTE
	SOJG	P2,LDDATM	;LOOP FILLING BUFFER
LDDOIT:	MOVE	T1,[POINT 8,DTEBUF] ; POINT TO MESSAGE AGAIN
	PUSHJ	P,MSGT11	;AND SEND TO 11
LDIDIT:	MOVEI	T1,DTEMML	;ADVANCE ADDRESS
	ADDM	T1,ADDRES	; ..
	SUBI	BC,DTEMML	;DECREMENT COUNT TO GO
	JUMPG	BC,LDDATL	;LOOP UNTIL DONE

	PUSHJ	P,GETCHK	;VERIFY CHECKSUM
	JRST	LDGRPL		;GO LOOK FOR NEXT GROUP
;A11 FILE PROCESSOR - THIS IS FOR DIAGNOSTICS

LDA11:	SETZM	CHKSUM		;ZERO CHECKSUM
	PUSHJ	P,A11BYT	;GET FIRST CHAR OF LINE
	  ERROR	Unexpected EOF
	CAIN	BYTE,";"	;IS THIS A COMMENT LINE?
	JRST	A11SKP		;YES, GO SKIP THIS LINE
	CAIE	BYTE,"E"	;NOT COMMENT, IS IT AN E?
	  ERROR	Bad A11 format
	PUSHJ	P,A11BYT	;GET WHAT SHOULD BE A BLANK
	  ERROR	Unexpected EOF
	CAIE	BYTE," "	;IS IT A BLANK?
	  ERROR	Bad A11 format

;THIS IS A REAL DATA LINE

	PUSHJ	P,A11WRD	;GET -11 WORD COUNT
	MOVE	P1,T1		;SAVE
	PUSHJ	P,A11WRD	;NOW GET ADDRESS
	MOVEM	T1,ADDRES	;SAVE
	JUMPN	P1,LDA111	;JUMP IF NOT START BLOCK

;ZERO WORD COUNT SPECIFIES START BLOCK

	PUSHJ	P,A11WRD	;GET CHECKSUM
	MOVE	T1,CHKSUM	; FOR TEST
	TRNE	T1,177777	;IS 16-BIT CHECKSUM = 0?
	  ERROR	START BLOCK Checksum failure
	JRST	LDDONE		;YES, GO FINISH PROCESS

;NOT START BLOCK, SO GET BLOCK OF DATA AND SEND TO -11

LDA111:	LSH	P1,1		;DOUBLE WORD COUNT FOR BYTE COUNT
	MOVE	P3,[POINT 8,DTEBUF]
	IDPB	P1,P3
	ROT	P1,-^D8
	IDPB	P1,P3
	ROT	P1,^D8
	MOVE	T1,ADDRES
	IDPB	T1,P3
	LSH	T1,-^D8
	IDPB	T1,P3
	LSH	P1,-1		;MAKE P1 BE WORD COUNT AGAIN

LDA112:	PUSHJ	P,A11WRD	;GET -11 WORD FROM A11 FILE
	IDPB	T1,P3
	LSH	T1,-^D8
	IDPB	T1,P3
	SOJG	P1,LDA112	;LOOP WHILE THERE'S ANOTHER DATA WORD

;LINE COMPLETE NOW SEND TO -11 IF CHECKSUM IS OKAY

	PUSHJ	P,A11WRD	;GET CHECKSUM WORD
	MOVE	T1,CHKSUM	; FOR TEST
	TRNE	T1,177777	;IS 16-BIT CHECKSUM = 0?
	  ERROR	DATA Checksum failure
	MOVE	T1,[POINT 8,DTEBUF] ;OK,SETUP TO SEND TO -11
	PUSHJ	P,MSGT11	;SEND THE DATA BUFFER
	PUSHJ	P,A11BYT	;CLEAR <LF>
	  JFCL			;IGNORE THIS ONE AS WE'LL FIND IT LATER
	JRST	LDA11		;GO GET NEXT LINE OF DATA
THATAL:	PUSHJ	P,GETCHK	;VERIFY CHECKSUM
	MOVEI	T1,^D10		;TAPE SHOULD HAVE AT LEAST 10 TRAILING NULLS
SKPEND:	SOJL	T1,LDDONE	;IF 10 NULLS THERE, TAPE END IS OK
	PUSHJ	P,GETBYT	;GET NEXT BYTE
	  JRST	LDDONE		;EOF IS OK
	JUMPE	BYTE,SKPEND	;SKIP TRAILING NULLS
	ERROR	Junk after start group

LDDONE:	MOVE	P3,[POINT 8,DTEBUF,23] ;POINT TO LOW BYTE OF START ADDR
	SETZM	DTEBUF		;CLEAR DATA LENGTH TO MARK START MESSAGE
	SKIPGE	T1,A.STRT	;GET ADDRESS USER SUPPLIED IF ANY
	MOVE	T1,ADDRES	;GET STARTING ADDRESS FROM PROGRAM
	DPB	T1,P3		;STORE LOW BYTE
	LSH	T1,-^D8
	IDPB	T1,P3		;AND HIGH BYTE
	MOVE	T1,[POINT 8,DTEBUF]
	PUSHJ	P,MSGT11	;SEND TO -11
	CLOSE	INDEV,		;CLOSE INPUT FILE
	RELEAS	INDEV,		;RELEASE IT
	SKIPGE	T1,A.STRT	;DID USER SAY /LOAD OR /START?
	JRST	LDDON1		;NO, DON'T NEED TO TELL HIM START ADDRESS
	TRNN	T1,1		;DID HE SAY /LOAD?
	JRST	LDDON1		;NO, HE DOESN'T NEED START ADDRESS
	MOVE	T1,ADDRES	;DOES THE PROGRAM HAVE ONE?
	TRNE	T1,1		;ODD SAYS NONE
	JRST	LDDON1		;NO ADDRESS, CAN'T TELL HIM START
	OUTSTR	[ASCIZ\" Start address is \]
	PUSHJ	P,TYPOCT	;PRINT IT
	MSG	<>		;PRINT A CRLF
LDDON1:	SKIPGE	T1,A.STRT	;DID WE START -11?
	MOVE	T1,ADDRES	;USER DIDN'T SPECIFY - GET PROGRAM'S
	TRNN	T1,1		;IF IT DIDN'T START, DON'T WAIT FOR IT
	PUSHJ	P,DBWAIT	;WAIT FOR PROGRAM TO INITIALIZE AND START PRIMARY PROTOCOL
	JRST	START		;GO START AGAIN.
	SUBTTL	LOADER SUBROUTINES

;ROUTINE TO GET AND VERIFY CHECKSUM

GETCHK:	PUSHJ	P,GETBYT	;GET CHECKSUM
	  ERROR	EOF found when looking for checksum
	MOVE	T1,CHKSUM	;GET RESULT
	TRNN	T1,377		;SEE IF OK
	RETURN			;YES
	ERROR	Checksum failure

;ROUTINE TO GET ONE -11 WORD INTO T1

GETWRD:	PUSHJ	P,GETBYT	;GET RH BYTE
	  ERROR	EOF during first byte of a word
	PUSH	P,BYTE		;SAVE AWAY
	PUSHJ	P,GETBYT	;GET LH BYTE
	  ERROR	EOF during second byte of a word
	MOVE	T1,BYTE		;MOVE TO ANSWER
	LSH	T1,8		;POSITION LH BYTE
	IOR	T1,(P)		;INCLUDE RH BYTE
	POP	P,(P)		;DISCARD SAVED BYTE
	RETURN

;ROUTINE TO GET ONE -11 WORD FROM AN A11 FILE TO T1

A11WRD:	SETZ	T1,		;CLEAR WORD
A11WR1:	PUSHJ	P,A11BYT	;GET NEXT BYTE
	  ERROR	Unexpected EOF
	CAIGE	BYTE,75		;IS CHARACTER VALID "ASCII-IZED"
	  RETURN		;NO, MUST BE DONE
	LSH	T1,6		;MOVE -11 WORD OVER FOR NEXT BITS
	TRZ	BYTE,100	;STRIP OFF "ASCII-IZING" BIT
	OR	T1,BYTE		;INSERT BITS
	JRST	A11WR1		;GO GET NEXT BITS

;ROUTINE TO SKIP A COMMENT LINE IN AN A11 FILE

A11SKP:	PUSHJ	P,A11BYT	;GET A CHARACTER
	  RETURN		;JUST RETURN ON EOF,WE'LL CATCH IT LATER
	CAIE	BYTE,12		;LOOK FOR A <LF>
	JRST	A11SKP		;NOT YET, LOOP
	RETURN			;GOT IT, RETURN
;ROUTINE TO GET ONE -11 BYTE FROM FILE INTO BYTE

GETBYT:	SKIPL	A.IMAG		;SEE IF /IMAGE MODE
	JRST	GETBYW		;YES--GET NEXT WORD
	AOS	FB		;ADVANCE FILE BYTE
	ANDI	FB,3		; (MOD 4)
	JUMPN	FB,GETBYC	;IF NOT NEW WORD, JUST FETCH BYTE
GETBYW:	SOSL	INHDR+2		;COUNT DOWN WORDS
	JRST	GETBYA		;STILL SOME THERE SO PROCEED
	MOVE	BYTE,[INLEN,,INBUF-1] ;FIXUP BUFFER HEADER
	HLRZM	BYTE,INHDR+2	;FIRST THE BYTE COUNT
	HRRZM	BYTE,INHDR+1	;AND THEN THE ADDRESS
	IN	INDEV,INIOWD	;GET NEXT BLOCK
	  JRST	GETBYW		;OK--GO TRY AGAIN
	STATZ	INDEV,740000	;SEE IF ERROR
	  ERROR	Input file read error
	RETURN

GETBYA:	AOS	INHDR+1		;ADVANCE TO NEXT WORD
	MOVE	BYTE,@INHDR+1	;GET WORD
	SKIPL	A.IMAG		;SEE IF /IMAGE
	JRST	GETBYI		;YES--GO GET IMAGE WORD
	TLNN	BYTE,(6B2)	;NO--TEST FOR NO JUNK
	TRNE	BYTE,6B20	; IN EITHER HALF
	ERROR	Junk bits in input file
GETBYC:	LDB	BYTE,PTRTAB(FB)	;GET BYTE
	JRST	GETBYR		;GO RETURN DATA
GETBYI:	TDNE	BYTE,[-1-377]	;SEE IF ANY JUNK
	ERROR	Junk in input file--may not be /IMAGE mode
GETBYR:	ADDM	BYTE,CHKSUM	;ACCUMULATE IN CHECKSUM
	AOS	(P)		;SKIP RETURN
RETRET:	RETURN

PTRTAB:	POINT	8,@INHDR+1,17
	POINT	8,@INHDR+1,9
	POINT	8,@INHDR+1,35
	POINT	8,@INHDR+1,27

INIOWD:	IOWD	200,INBUF
	0
;ROUTINE TO GET A BYTE FROM AN A11 FILE TO AC BYTE

A11BYT:	SOSG	INHDR+2		;DECREMENT COUNT
	  JRST	A11BY1		;COUNT NOT +, GET NEW BLOCK
	ILDB	BYTE,INHDR+1	;ELSE, GET NEXT BYTE
CPOPJ1:	AOS	(P)		;INCREMENT RETURN PC ON STACK
	RETURN			;AND MAKE SKIP RETURN

A11BY1:	MOVEI	BYTE,1200	;NUMBER OF 7-BIT BYTES IN NORMAL BLOCK
	MOVEM	BYTE,INHDR+2	;PUT INTO "HEADER"
	MOVE	BYTE,[POINT 8,INBUF] ;GET BYTE POINTER
	MOVEM	BYTE,INHDR+1	;ALSO PUT INTO "HEADER"
	IN	INDEV,INIOWD	;GET NEXT BUFFER
	  JRST	A11BYT		;ALL'S WELL
	STATZ	INDEV,740000	;CHECK FOR ERROR CONDITIONS
	  ERROR	Input file read error
	RETURN			;EOF IS NOT ERROR, JUST GIVE NON-SKP RET
	SUBTTL	/TERMINATE AND /INITIALIZE  PROCESSING

IGNORE:	MOVE	T1,NUMSWT	;MAKE SURE NO MORE SWITCHES
	SOJE	T1,.+2
	USEROR	Illegal switch or switches used with /TERMINATE
	PUSHJ	P,DTECLR	;CLEAR OUT DTE
	TELLCR	PDP-11 shut down
	JRST	START		;LOOP AROUND FOR MORE TO DO.


;HERE TO START PRIMARY PROTOCOL ON A DTE

STARTP:	MOVE	T1,NUMSWT	;MAKE SURE ONLY ONE SWITCH
	SOJE	T1,.+2
	USEROR	Illegal switch or switches used with /INITIALIZE
	PUSHJ	P,STRDTE	;GO START PRIMARY PROTOCOL
	TELLCR	Primary protocol started
	jrst	start		;voile'
	SUBTTL	DUMP ROUTINE

DODUMP:	SKIPL	A.NDMP		;DUMP?
	JRST	DMPEND		;SKIP THE DUMP
	MOVEI	T1,OUMODE	;SET OUTPUT MODE
	HRLZ	T2,DEFDEV	;GET PRESENT DEFAULT (DSK OR XPN)
	MOVSI	T3,OUTHDR	;POINT TO BUFFER HEADER
	OPEN	OUTDEV,T1	;OPEN FILE
	  LERROR <Can't OPEN the output device>,<ER.OPE>

	PUSHJ	P,FNDNAM	;FIND CORRECT NAME TO USE
	SETZB	T3,T4		;CLEAR OUT OTHER STUFF
	ENTER	OUTDEV,T1	;ENTER FILE
	  LERROR	<ENTER failed>,<ER.ENF>
	MOVEM	T4,DMPPPN	;REMEMBER DUMP PPN
	SETZ	P4,		;CLEAR NUMBER OF 11 WORDS DUMPED
	TELLCR	PDP-11 dumping

DMPLUP:	MOVE	T1,[POINT 18,DTEBUF]	;PUT DATA HERE, 18 BIT BYTES
	ADD	T1,BASEAD	;ADD EVM ADDRESS
	PUSHJ	P,SETTBP	;SETUP TO-10 BYTE POINTER TO THAT
	MOVEI	P3,DTEBSZ*2	;ASSUME WHOLE BUFFER
	MOVE	T1,DMPSIZ	;COPY NUMBER OF WORDS XFERRED SO FAR
	SUB	T1,P4		;GET # WORDS LEFT
	CAILE	T1,DTEBSZ*2	;IF # WORDS LEFT IS GREATER THAN BUFFER SIZE,
	JRST	DMPLP1		;NOTHING SPECIAL

;HERE ON LAST DATAO. BYTE COUNT MAY BE LESS THAN BUFFER SIZE, AND
; MUST GIVE THE 11 TO-10 DONE.

	MOVE	P3,T1		;GET THE LAST COUNT IN P3
	TLO	P3,(1B0)	;SET SIGN BIT SAYING ITS THE LAST BUFFER
DMPLP1:				; SIZE IS INTEGRAL NUMBER OF DISK BLOCKS)
	MOVEI	T1,CLTO10	;CLEAR TO-10 DONE
	XCT	DTECNO
	HRRZ	T1,P3		;GET 11 WORD COUNT AGAIN
	MOVNS	T1
	MOVE	T2,T1		;GET COPY OF NEGATIVE COUNT
	ASH	T2,-1		;DIVIDE BY 2
	HRLM	T2,DTEIOW	;SAVE AS DUMP IO WORD
	ANDI	T1,TO10BC	;JUST THE RIGHT BITS
	SKIPGE	P3		;LAST BUFFER?
	TRO	T1,TO10IB	;YES, SET TO-10 DONE FOR 11
	XCT	DTEDTO		;DO THE DATAO TO START XFER
	MOVEI	T1,TO10DN!TO10ER ;DONE OR ERROR
	MOVEI	T3,^D60000	;WAIT ONE MINUTE
	PUSHJ	P,SETIME

DMPLP2:	XCT	DTECSZ		;BITS SET YET?
	JRST	DMPLP3		;YES, SEE WHAT THEY ARE
	PUSHJ	P,ISTIME	;TIME OUT YET?
	  JRST	DMPLP2		;NO, KEEP GOING
	LERROR	<Timeout while waiting for dump transfer to complete>,<ER.DHG>

DMPLP3:	MOVEI	T1,TO10ER	;TO-10 ERROR?
	XCT	DTECSZ		;?
	LERROR	<To-10 error while dumping.>,<ER.10E>
	MOVSI	T1,400000	;FLAG BIT 0 TO DISTINGUISH DTELDR DUMPS
	IORM	T1,DTEBUF	;FROM REAL .BIN FILES
	OUT	OUTDEV,DTEIOW	;OUTPUT DUMP INFO TO FILE
	  JRST	DMPLP4		;OK
	LERROR <Output error for dump file >,<ER.OUF>
DMPLP4:	ADDI	P4,(P3)		;ADD TO NUMBER OF 11 WORDS XFERRED
	JUMPG	P3,DMPLUP	;GO XFER MORE, IF NOT FINISHED.
	CLOSE	OUTDEV,		;CLOSE THE FILE
	RELEAS	OUTDEV,

;HERE AFTER DUMP IS FINISHED, OR NO DUMP IS DONE.

DMPEND:	MOVSI	T1,(ER.DPF)	;DUMP DIDN'T FAIL AFTER ALL, YOU PESSIMIST
	ANDCAM	T1,ERRWRD
	RETURN			;FINISHED.
;ROUTINE CALLED BY DODUMP TO FIND FILE NAME FOR DUMP FILE.
; CALL WITH OUTDEV I/O CHANNEL OPENED.  RETURN WITH
; FILE NAME IN T1, EXTENSION (BIN, B00, B01, . . . , B99)
; IN T2.  IDEA IS TO GENERATE NEW EXTENSIONS TO AVOID DELETING
; EXISTING DUMPS. STORES DUMP FILE NAME AND EXTENSION FOR
; ERROR LOGGING LATER. IF ALL 100 BIN FILES EXIST, THE .B99
; FILE ALWAYS GETS THE NEW DUMP.

FNDNAM:	MOVE	T1,['DTED00']	;FILE NAME USED FOR DUMPS
	ADD	T1,A.DTE	;MAKE DEFAULT NAME INCLUDE DTE#
	MOVE	T2,A.CPU	;GET CPU NUMBER SPECIFIED
	LSH	T2,6		;MOVE TO NEXT TO LAST SIXBIT CHAR
	ADD	T1,T2		;DTEDXY, X=CPU#, Y=DTE#
	MOVSI	T2,'BIN'	;START WITH BIN
	MOVEI	T4,0		;USE JOB'S PPN
	LOOKUP	OUTDEV,T1	;LOOKUP BIN FILE
	  JRST	FNAMOK		;OK, GO CLOSE CHANNEL AND RETURN
	MOVSI	T2,'B00'	;ALREADY EXISTS, START WITH B00
	SETZB	T3,T4

FNDNLP:	LOOKUP	OUTDEV,T1	;B?? EXIST?
	  JRST	FNAMOK		;NO, USE IT
	TRZ	T2,-1		;CLEAR OUT JUNK
	MOVSI	T3,1		;YES, STEP TO NEXT
	ADDB	T2,T3		;EXTENSION
	TLZ	T3,7700		;CLEAR 2ND CHAR AND CHECK FOR
	CAME	T3,[SIXBIT/B :/];OVERFLOW
	JRST	FNDNLP		;EXTENSION STILL OK, CHECK NEW NAME
	ADD	T2,[100,,0]	;OVERFLOWED. CARRY INTO NEXT CHAR
	CAMN	T2,[SIXBIT/B::/];THAT OVERFLOW TOO?
	JRST	[MOVSI	T2,'B99';YES, USE B99 OVER
		 JRST	FNAMOK]	;
	TLZ	T2,77		;NO OVERFLOW. 3RD CHAR HAD CHANGED TO :,
	TLO	T2,'0'		;RESET IT TO 0
	JRST	FNDNLP		;GO LOOK UP

FNAMOK:	CLOSE	OUTDEV,		;CLOSE SO ENTER WILL NOT BE UPDATING
	MOVEM	T1,DMPNAM	;STORE NAME OF DUMP FILE
	HLLZM	T2,DMPEXT	;AND EXTENSION
	RETURN
SUBTTL -11 HANDLER SUBROUTINES

SP.CR0==1			;SPECIFY CPU 0
.STCPU==14			;SET CPU


;ROUTINE TO COMPUTE DTE I/O CODES, GET INTO
; IOT MODE, LOCK AND SET CONTROL C INTERCEPT.

SETCOD:	SKIPE	A.CPU		;FOR NOW, NON-ZERO CPU IS ILLEGAL
	USEROR	Non-zero CPU specification not supported in this version
	MOVEI	T1,DTE0		;PLUS FIRST DEVICE CODE = DEVICE CODE
	LSH	T1,-2		;RIGHT JUSTIFY THE DEVICE CODE IN AC FOR DPB
	ADD	T1,A.DTE	;ADD IN DTE NUMBER

DEFINE X(A)<DPB	T1,[POINT 7,A,9]>	;SET DEVICE CODE MACRO

	X(DTECNO)
	X(DTEDTO)
	X(DTECNI)
	X(DTECSO)
	X(DTECSZ)

;NOW SETUP CONTROL C INTERCEPT, LOCK IN CORE, AND REMEMBER EVA

	MOVE	T1,[.STCPU,,SP.CR0]	;RUN ON CPU0
	SETUUO	T1,		;ASK FOR IT
	JFCL			;AND IGNORE A FAILURE
	MOVEI	T1,CCINT	;SET FOR
	HRRM	T1,.JBINT##	;  ^C TRAP
	SETZB	T4,CCINTP	;KEEP TIMESHARING ON
	TRPSET	T4,		; BUT GIVE SELF IOT
	  ERROR	TRPSET failed

	MOVEI	T4,5		;REQUEST LOCK IN EVM (DONT BOTHER PHYSICALLY)
	LOCK	T4,		;NOW LOCK THAT LOW SEGMENT
	  ERRORC	LOCK failure, T4	;DISPLAY LOCK FAILURE CODE
	ANDI	T4,777		;JUST VIRTUAL PAGE NUMBER
	LSH	T4,^D9		;TURN INTO BASE ADDRESS
	MOVEM	T4,BASEAD	;STORE
	PUSHJ	P,ISMAST	;IS THIS DTE THE MASTER?
	  JRST	.+2		;NO, LEAVE MASTER FLAG ZERO
	SETOM	MASTER		;YES, SET MASTER FLAG
	RETURN			;RETURN
;SUBROUTINE TO CLEAR THE DTE, START THE ROM UP, AND ENABLE PI0
; SO THAT BYTE XFERS CAN PROCEED.

STRROM:	PUSHJ	P,DTECLR	;CLEAR THE DTE
	PUSHJ	P,DTEPRB	;PRESS RELOAD BUTTON TO START THINGS UP
	MOVEI	T1,PILDEN!PI0ENB ;TELL DTE IT'S OKAY TO TRANSFER DATA
	XCT	DTECNO
	RETURN

;SUBROUTINE TO SEND A DATA MESSAGE TO -11. 
;THIS WILL:
;1)	SETUP BYTE POINT IN EPT SO DTE CAN ACCESS DATA
;2)	RING -11'S DOORBELL TO SAY WE'RE READY
;	[PDP-11 SHOULD TRANSFER MESSAGE AT THIS POINT]
;4)	WAIT FOR TO11DN TO SET
;5)	RETURN WITH DTE CLEARED
;THIS WILL ALSO CHECK FOR TRANSFER ERRORS
;CALL:
;T1/	BYTE POINTER TO MESSGE TO SEND

MSGT11:	ADD	T1,BASEAD	;ADD EVM ADDRESS
	PUSHJ	P,SETEBP	;SET TO-11 BYTE POINTER
	MOVEI	T1,CLTO11	;CLEAR TO-11 DONE
	XCT	DTECNO		; . .
	MOVEI	T1,TO11DB	;RING DOORBELL
	XCT	DTECNO		;DONG
	MOVEI	T3,^D5000	;SET T2 TO 5000 MS FROM NOW
	PUSHJ	P,SETIME	; ACCOUNTING FOR MIDNITE
	MOVEI	T1,TO11DN!TO11ER;LOOK FOR TERMINATION OF SOME SORT

MSGT12:	XCT	DTECSZ
	JRST	MSGT13		;TERMINATION HAS ARRIVED
	PUSHJ	P,ISTIME	;IS IT TIME YET?
	  JRST	MSGT12		;NO, LOOP
	LERROR	<Timeout while doing To-11 byte transfer>,<ER.TT1>

MSGT13:	MOVEI	T1,TO11ER	;WAS IT ERROR?
	XCT	DTECSZ		;?
	LERROR	<To-11 error after To-11 byte transfer>,<ER.11E>
	MOVEI	T1,CLRDTE	;CLEAR OUT DTE
	XCT	DTECNO
	RETURN			;ALL DONE, PDP-11 HAS DATA
;SUBROUTINE CALLED TO WAIT FOR THE -11 TO INITIALIZE ITSELF AND SET THE TO10
;DOORBELL TO REQUEST ENTERING PRIMARY PROTOCOL. WHEN THE DOORBEL IS RUNG,
;DBWAIT TELLS THE MONITOR TO ENTER PRIMARY PROTOCOL THEN TELLS THE WORLD
;THAT THE -11 IS RUNNING.

DBWAIT:	TELLCR	PDP-11 initializing
	MOVEI	T3,^D60000	;WAIT ONE MINUTE
	PUSHJ	P,SETIME	;SET TIME TO STOP IN T2
	MOVEI	T1,TO10DB	;NOW WAIT FOR TO-10 DOORBELL
	MOVEI	T4,1		;THIS WILL TAKE A WHILE SO LET'S SLEEP

DBWAI1:	SLEEP	T4,		;GIVE THE -11 A CHANCE TO GET GOING
	XCT	DTECSZ		;WAIT FOR DOORBELL TO SET
	JRST	DBWAI2		;IT HAS
	PUSHJ	P,ISTIME	;IS IT TIME YET?
	  JRST	DBWAI1		;NO, KEEP GOING FOR NOW
	ERROR	Timeout waiting for 11 program to start

DBWAI2:	PUSHJ	P,STRDTE	;START DTE DOING ITS PROTOCOL
	TELLCR	PDP-11 started
	SKIPGE	ATOFLG		;IS /AUTO ON?
	PUSHJ	P,TELOPR	;YES, TELL OPR ABOUT THE RELOAD
	MOVSI	T1,(ER.RLF)	;SAY RELOAD WON
	ANDCAM	T1,ERRWRD	;CLEAR THE BIT
	MOVSI	T1,(ER.LOG)	;TELL ERRLOG TO LOG THIS SUCCESSFUL RELOAD
	IORM	T1,ERRWRD
	JRST	ERRLOG		;CALL ERRLOG AND RETURN
;ROUTINES THAT DO DTE. UUOS

;ROUTINE TO SKIP IF THE SPECIFIED DTE IS THE MASTER

ISMAST:	MOVE	T1,[.DTEGS,,DTUBLK]	;GET DTE STATUS
	PUSHJ	P,DODTEU
	TLNE	T1,(DT.DTM)	;IS THIS MASTER?
	AOS	(P)		;YES, GIVE SKIP
	RETURN

;ROUTINE TO STOP PROTOCOL FROM RUNNING ON AN 11

DTECLR:	MOVE	T1,[.DTECL,,DTUBLK]
	JRST	DODTEU		;DO DTE UUO AND RETURN

;ROUTINE TO PRESS RELOAD BUTTON ON A DTE

DTEPRB:	MOVE	T1,[.DTEPR,,DTUBLK]
	JRST	DODTEU		;DO DTE UUO AND RETURN
;START PROTOCOL ON A DTE/11

STRDTE:	MOVE	T1,[.DTEST,,DTUBLK]
	JRST	DODTEU		;GO DO IT

;SET TO-10 BYTE POINTER

SETTBP:	MOVEM	T1,DTUDAT	;PUT IN DTUBLK+1
	MOVE	T1,[.DTETB,,DTUBLK]
	JRST	DODTEU

;GET ROM WORD IN T1

GETROM:	SKIPL	T1,A.SWIT	;USE VALUE FOR /SWITCH?
	RETURN			;YES, RETURN WITH IT
	MOVE	T1,[.DTERW,,DTUBLK] ;NO, USE WHAT FRONT END TOLD US
	JRST	DODTEU		;DO IT, GET RESULT IN T1, RETURN
;SET TO-11 BYTE POINTER

SETEBP:	MOVEM	T1,DTUDAT
	MOVE	T1,[.DTEEB,,DTUBLK]
DODTEU:	MOVE	T4,A.DTE	;GET DTE NUMBER
	HRL	T4,A.CPU	;CPU#,,DTE#
	MOVEM	T4,DTUBLK	;PUT INTO BLOCK
	DTE.	T1,		;DO IT
	  JRST	.+2		;FALL INTO DTUERR
	RETURN


;HERE TO PRINT A MESSAGE ACCORDING TO WHAT DTE. ERROR CODE
; HAPPENED.  CALL WITH ERROR CODE IN T1. NEVER RETURN.

DTUERR:	CAILE	T1,DTUMLN-1	;IS ERROR CODE IN RANGE?
	MOVEI	T1,-1		;NO, PRINT ERROR CODE OUT OF RANGE
	OUTSTR	[ASCIZ/? /]
	OUTSTR	@DTUERM(T1)	;OUTPUT PROPER MESSAGE
	OUTSTR	[BYTE (7) 15,12,0,0,0] ;CRLF
	MOVSI	T2,(ER.NPF)	;DID -11 POWERFAIL FAIL TO SET?
	CAIN	T1,DTEPT%	;?
	IORM	T2,ERRWRD	;YES, LOG IT
	MOVSI	T2,(ER.RMF)	;DID -11 CLEAR ITS DOORBELL?
	CAIN	T1,DTEDE%	;?
	IORM	T2,ERRWRD
	MOVSI	T2,(ER.NRL)	;IS -11 OBJECT PROGRAM DEAD TO THE WORLD?
	CAIN	T1,DTEDD%	; (SUPPOSED TO GIVE A TO-10 DOORBELL)
	IORM	T2,ERRWRD	;YES, THAT'S THE PROBLEM
	PUSHJ	P,DTEXIT	;CLEAR OUT DTE IF WE CAN
	PUSHJ	P,ERRLOG	;ERROR LOG IF POSSIBLE
	JRST	STARTE		;GO ASK FOR COMMAND AGAIN
;ROUTINE TO TELL OPR THAT A FRONT END HAS BEEN RELOADED.

TELOPR:	MOVEI	T1,[ASCIZ/% [DTELDR] FRONT END NUMBER /]
	PUSHJ	P,SNDOPR
	MOVE	T2,A.CPU
	LSH	T2,7
	ADD	T2,A.DTE
	ADDI	T2,"00"
	LSH	T2,^D36-^D14
	MOVEM	T2,DTUBLK
	MOVEI	T1,DTUBLK
	PUSHJ	P,SNDOPR	;GIVE FRONT END NUMBER
	MOVEI	T1,[ASCIZ/ HAS JUST BEEN RELOADED/]
	PUSHJ	P,SNDOPR
	MOVEI	T1,[BYTE (7) 15,12,0,0,0]
	JRST	SNDOPR
;ROUTINE TO SEND A STRING TO OPR, ADDRESS OF STRING IN T1.

SNDOPR:	MOVE	T3,[SIXBIT/OPR/]
	IONDX.	T3,
	  ERROR	IONDX. ON OPR FAILED
	MOVE	T4,T1		;ADDRESS OF STRING
	MOVEI	T2,.TOOUS	;OUTPUT STRING FUNCTION
	MOVE	T1,[3,,T2]	;THE POINTER
	TRMOP.	T1,
	  WARNCR STRING OUTPUT TO OPR FAILED
	RETURN
;HERE ON ERROR, DON'T EXIT IF /AUTO

ERRXIT:	PUSHJ	P,DTEXIT	;CLEAR OUT DTE IF EXITING
	PUSHJ	P,ERRLOG	;LOG ERROR, IF NECESSARY
	SKIPGE	ATOFLG		;/AUTO IN EFFECT?
	JRST	START		;YES, START AT START INSTEAD OF EXITING.

;HERE WHEN ERROR AND TIME TO GIVE UP
EXITX:	PUSHJ	P,DTEXIT	;CLEAR DTE IF USER I/O IS ON

;HERE TO RETURN TO MONITOR
GOHOME:	RESET			;GO RETURN TO MONITOR
	HLLZM	.JBINT##	;DEACTIVATE ^C INTERCEPT
	EXIT	1,
	EXIT

;HERE TO CLEAR OUT DTE IF WE WERE DOING ANYTHING TO IT.

DTEXIT:	JSP	T1,.+1		;GET PC BITS
	TLNE	T1,(1B6)	;SEE IF I/O MODE
	MOVE	T1,[.DTECL,,T2]
	MOVE	T2,A.DTE	;GET DTE NUMBER
	HRL	T2,A.CPU	;AND CPU NUMBER
	DTE.	T1,		;DO THE UUO
	  JFCL			;IGNORE  POSSIBLE ERROR
	RETURN
SUBTTL ERROR LOGGING ROUTINES


;ROUTINE JRSTED TO IN LERROR MACRO WITH ERROR BIT IN T1

RETRY:	IORM	T1,ERRWRD	;PUT THE BIT IN ERROR WORD
	AOS	T2,RETRYC	;INCREMENT PER EVENT RETRY COUNT
	CAILE	T2,.ERRTR	;SEE IF DONE WITH RETRIES FOR THIS EVENT
	JRST	[MSG	? All retries failed
		 MSG <>
		 SETZM	RETRYC	;CLEAR PER EVENT RETRY COUNT
		 JRST	@FAILPC];GO TO FAIL PLACE
	WARNC	(<Attempting retry>,T2)
	MSG <>
	AOS	RETRYT		;INCREMENT RETRY TOTAL COUNT
	JRST	@RTRYPC


;ROUTINE TO GENERATE AN ENTRY IN ERROR.SYS.  CALLED AT ERRXIT
; AND AFTER SUCCESSFUL TERMINATION OF -11 RELOAD.


ERRLOG:	SKIPE	ERRWRD		;ANYTHING TO LOG?
	SKIPL	A.NLOG		;WANT ERROR LOGGING
	POPJ	P,		;NO, EITHER NOTHING OR DISABLED
	MOVSI	T1,(ER.LOG)	;CLEAR THE BORROWED BIT
	ANDCAM	T1,ERRWRD	;THAT CAUSED US TO LOG A NORMAL RELOAD
	MOVE	P1,RETRYT	;GET TOTAL RETRY COUNT
	ANDI	P1,ER.RTC	;CLEAR ALL BUT GOOD BITS
	IORM	P1,ERRBLK+.ERSTS;PUT INTO MESSAGE
	MOVS	P1,A.CPU
	HRR	P1,A.DTE	;SETUP CPU#,,DTE#
	TLO	P1,(ER.MAS)	;ASSUME MASTER
	SKIPN	MASTER		;IS IT?
	TLZ	P1,(ER.MAS)	;NO
	MOVEM	P1,ERRBLK+.ERNUM;SETUP THAT PART OF ENTRY
	MOVEI	T1,.ERERL	;ELEVEN RELOAD CODE
	MOVEM	T1,ERRCOD	;SET IT UP
	MOVEI	T1,.ERSIZ+1	;GET POINTER TO TEXT
	MOVEM	T1,ERRBLK+.ERFNM;SETUP FOR ENTRY
	SETZ	P2,		;CLEAR BYTE COUNT
	MOVE	P1,[POINT 7,ERRBLK+.ERSIZ+1] ;GET BYTE POINTER
	SKIPE	DMPPPN		;IF NO PPN, DUMP WAS NOT DONE
	SKIPL	A.NDMP		;WAS DUMP DONE?
	JRST	ERRLG2		;NO, SKIP THIS
	MOVE	T1,[SIXBIT/DSK:/];WE USED DSK FOR DUMP DEVICE
	PUSHJ	P,SIXASC	;PUT
	MOVE	T1,DMPNAM		;GET FILE NAME
	PUSHJ	P,SIXASC	;PUT INTO ENTRY
	MOVSI	T1,'.  '	;PUT PERIOD AFTER NAME
	PUSHJ	P,SIXASC
	MOVE	T1,DMPEXT		;GET EXTENSION
	PUSHJ	P,SIXASC	;PUT THAT IN
	MOVSI	T1,'[  '	;NOW FOR P,PN
	PUSHJ	P,SIXASC
	MOVE	P3,DMPPPN	;GET PPN WE DUMPED TO
ERRLG1:	HLRZ	T1,P3		;GET PROJECT NUMBER
	PUSHJ	P,OCTASC	;PUT OCTAL NUMBER IN ENTRY
	MOVSI	T1,',  '	;PUT COMMA IN RIGHT PLACE
	PUSHJ	P,SIXASC
	HRRZ	T1,P3		;NOW PROGRAMMER NUMBER
	PUSHJ	P,OCTASC
	MOVSI	T1,']  '	;CLOSE IT OFF
	PUSHJ	P,SIXASC

ERRLG2:	MOVEM	P2,ERRBLK+.ERSIZ ;PUT SIZE OF STRING IN ENTRY
	MOVEI	T1,.DMERR	;DAEMON APPEND TO ERROR.SYS FUNCTION
	MOVEM	T1,ERRFNC	;PUT INTO THE BLOCK
	MOVE	T1,[ERBSIZ,,ERRFNC]
	DAEMON	T1,
	  WARNCR(<DAEMON CALL failure, no entry made in ERROR.SYS>)
	RETURN
;SUBROUTINES TO CONVERT SIXBIT AND OCTAL INTO ASCII, PLACING
; THE ASCII STRING WITH BYTE POINTER IN P1 AND KEEPING COUNT
; OF THE BYTES IN P2

SIXASC:	MOVE	T2,[POINT 6,T1]
SIXAS1:	ILDB	T3,T2
	JUMPE	T3,CPOPJ
	AOS	P2
	ADDI	T3,"0"-'0'	;CONVERT TO ASCII
	IDPB	T3,P1		;PUT IT IN
	TLNN	T2,770000	;ANY CHARACTERS LEFT IN T1 TO LOOK AT?
	RETURN			;NO, RETURN
	JRST	SIXAS1		;LOOP TILL BLANK IS FOUND


OCTASC:	IDIVI	T1,^D8		;STANDARD STUFF
	HRLM	T2,(P)		;SAVE
	SKIPE	T1		;DONE?
	PUSHJ	P,OCTASC	;NO
	HLRZ	T1,(P)		;YES, GET CHAR
	ADDI	T1,"0"		;CONVERT TO ASCII DIGIT
	IDPB	T1,P1		;PUT
	AOS	P2		;COUNT
	RETURN
	SUBTTL	COMMAND SCANNER

GETCOM:	OUTSTR	[ASCIZ /*/]	;TELL USER WE ARE WAITING
	SETZM	NUMSWT		;CLEAR NUMBER OF SWITCHES SEEN
COMLP:	PUSHJ	P,GETNAM	;GET A SIXBIT NAME
	JRST	.+2
COMFND:	MOVEI	T2,0		;CLEAR NAME
	MOVSI	T4,-BRKLEN	;LOOK FOR BREAK
	HLRZ	T3,BRKTAB(T4)	;TRY NEXT BREAK
	CAME	T1,T3		;SEE IF MATCH
	AOBJN	T4,.-2		;LOOP UNTIL MATCH
	HRRZ	T3,BRKTAB(T4)	;GET DISPATCH ADDRESS
	JRST	(T3)		;JUMP TO HANDLE BREAK

BRKTAB:	" ",,COMNOP		;SPACE IS A NO-OP
	".",,COMEXT		;DOT IS EXTENSION
	":",,COMDEV		;COLON IS DEVICE
	"[",,COMDIR		;BRAKET IS DIRECTORY
	"/",,COMSWT		;SLASH IS SWITCH
	12,,SAVNAM		;RETURN AT END OF LINE, AFTER SAVING FILE NAME
	32,,GOHOME		;IF ^Z
	3,,GOHOME		;IF ^C
BRKLEN==.-BRKTAB
	0,,COMERR		;ELSE, MUST BE ERROR

COMERR:	USEROR	Command error--type /H for help
COMNOP:	PUSHJ	P,SAVNAM	;STORE FILE NAME
	JRST	COMLP		;AND GO AROUND AGAIN

COMEXT:	PUSHJ	P,SAVNAM	;SAVE FILE NAME
	PUSHJ	P,GETNAM	;GET SIXBIT NAME
	HLLOM	T2,EXT		;SAVE EXT WITH FLAG FOR DOT
	JRST	COMFND		;AND GO AROUND AGAIN

COMDEV:	MOVEM	T2,DEV		;SAVE DEVICE
	JRST	COMLP		;GO AROUND AGAIN

COMDIR:	PUSHJ	P,SAVNAM	;SAVE FILE NAME
	PUSHJ	P,GETOCT	;GET OCTAL NOW
	CAIN	T1,"-"		;SEE IF DEFAULT
	JUMPE	T2,[PUSHJ P,GETCHR
		    JRST  COMDIX]
	HRLZ	T2,T2		;POSITION IT
	SKIPN	T2		;SKIP IF SOMETHING THERE
	GETPPN	T2,		;NO--GET FROM SYSTEM
	  JFCL
	HLLZM	T2,DIRECT	;SAVE FOR LATER
	CAIE	T1,","		;VERIFY COMMA
	JRST	COMERR		;NO--GIVE UP IN DISGUST
	PUSHJ	P,GETOCT	;GET PROGRAMMER
	SKIPN	T2		;SKIP IF SOMETHING THERE
	GETPPN	T2,		;ELSE ASK MONITOR
	  JFCL
	HRRM	T2,DIRECT	;STORE FOR LOOKUP
	CAIE	T1,","		;SEE IF SFD COMING
	JRST	COMDIX		;NO--GO FINISH UP
	MOVEI	T2,DIRPTH	;YES--SHIFT TO SFD
	EXCH	T2,DIRECT	; FORMAT
	MOVEM	T2,DIRPTH+2	; ..
	MOVSI	T4,-5		;MAX SFD COUNT
COMDIL:	PUSHJ	P,GETNAM	;GET SFD NAME
	JUMPE	T2,COMERR	;ERROR IF BLANK
	MOVEM	T2,DIRPTH+3(T4)	;STORE
	CAIN	T1,","		;SEE IF MORE
	AOBJN	T4,COMDIL	;YES--GO GET UNLESS TOO MANY
COMDIX:	CAIN	T1,"]"
	JRST	COMLP
	CAIN	T1,12
	JRST	COMFND
	JRST	COMERR

SAVNAM:	SKIPE	T2		;IF NAME,
	MOVEM	T2,NAME		; SAVE FOR LOOKUP
	POPJ	P,		;RETURN
;HERE WHEN SWITCH TO BE PROCESSED

COMSWT:	PUSHJ	P,SAVNAM	;SAVE FILE NAME
	PUSHJ	P,GETNAM	;GET SIXBIT WORD
	MOVEI	T3,0		;PRESET MASK
	MOVSI	T4,770000	;PRESET CHARACTER
	TDNE	T2,T4		;IF CHARACTER,
	IOR	T3,T4		; INCLUDE IN MASK
	LSH	T4,-6		;MOVE OVER ONE
	JUMPN	T4,.-3		;LOOP FOR WORD
	SETO	T4,		;PRESET SUCCESS COUNTER
	MOVSI	P1,-SWTLEN	;PRESET LOOP
SWTLOP:	CAMN	T2,SWTTAB(P1)	;SEE IF EXACT MATCH
	JRST	SWTWIN		;YES--WIN
	MOVE	P2,SWTTAB(P1)	;NO--GET WORD
	XOR	P2,T2		;COMPARE WITH INPUT
	TDNE	P2,T3		;LOOK THROUGH MASK
	JRST	.+3		;NO--KEEP TRYING
	AOS	T4		;COUNT MATCH
	MOVE	P3,P1		;SAVE POINTER
	AOBJN	P1,SWTLOP	;SEE IF DONE YET
	MOVE	P1,P3		;RESTORE WINNER
	JUMPE	T4,SWTWIN	;SEE IF JUST ONE MATCH
	SKIPGE	T4
	USEROR	Unknown switch--type /H for help
	USEROR	Ambiguous switch--type /H for help
SWTWIN:	AOS	NUMSWT		;COUNT SWITCHES SEEN FOR QUICK CHECKING
	PUSHJ	P,@SWTDSP(P1)	;DISPATCH TO SWITCH ROUTINE
	JRST	COMFND		;HANDLE BREAK
SWTTAB:	SIXBIT	/AUTOMA/
	SIXBIT	/HELP/
	<SIXBIT	/TERMINATE/>
	SIXBIT	/IMAGE/
	SIXBIT	/A11/
	SIXBIT	/NODUMP/
	SIXBIT	/RELOAD/
	SIXBIT	/SELECT/
	SIXBIT	/SWITCH/
	SIXBIT	/NOLOG/
	<SIXBIT	/INITIALIZE/>
	SIXBIT	/LOAD/		;ONLY LOAD -11, DON'T START
	SIXBIT	/START/		;SET START ADDRESS FOR FROM10
SWTLEN==.-SWTTAB


SWTDSP:	D.AUTO
	D.HELP
	D.IGNR
	D.IMAG
	D.A11
	D.NDMP
	D.RELD
	D.SEL
	D.SWIT
	D.NLOG
	D.STRP
	D.LOAD
	D.STRT
SUBTTL SWITCH HANDLING

;HERE FOR /HELP

D.HELP:	CAIN	T1,12		;SEE IF AT END OF LINE YET
	JRST	HELP1		;YES--GO DO THE HELP
	PUSHJ	P,GETCHR	;NO--GET ANOTHER CHAR
	JRST	D.HELP		;AND LOOP
HELP1:	MOVE	1,['DTELDR']
	PUSHJ	P,.HELPR##	;CALL HELPER
	JRST	START		;DONE.

;/RELOAD:XY

D.RELD:	CAIE	T1,":"		;VALUE GIVEN?
	USEROR	Must specify front end in /RELOAD
	SETZM	A.RELD		;INDICATE /RELOAD WAS TYPED
SETFE:	PUSHJ	P,GETOCT	;GET FE #
	IDIVI	T2,10		;CPU # IN T2, DTE # IN T2+1
	CAILE	T2+1,3		;DTE CANNOT BE GREATER THAN 3
	USEROR	DTE number too large
	MOVEM	T2,A.CPU
	MOVEM	T2+1,A.DTE	;STORE
	RETURN			;BYE.

;/NODUMP

D.NDMP:	SETZM	A.NDMP
	RETURN

;/IMAGE

D.IMAG:	SKIPL	A.A11		;WAS /A11 ALREADY SPECIFIED?
	 USEROR	<Cannot specify both /A11 and /IMAGE>
	SETZM	A.IMAG
	RETURN

;/A11

D.A11:	SKIPL	A.IMAG		;WAS /IMAGE ALREADY SPECIFIED?
	 USEROR	<Cannot specify both /A11 and /IMAGE>
	SETZM	A.A11		;NO, SET SWITCH ACCORDINGLY
	RETURN

;/SELECT

D.SEL:	CAIE	T1,":"		;BETTER BE VALUE COMING
	USEROR	<Must specify either 10 or 11 for /select>
	PUSHJ	P,GETOCT	;GET OCTAL NUMBER
	CAIE	T2,10		;MUST BE EITHER 10 (TEN)
	CAIN	T2,11		;OR 11 (ELEVEN)
	CAIA			;OK
	USEROR	<Only legal values for /SELECT are 10, 11>
	MOVEM	T2,A.SEL	;PLACE TO RELOAD FROM
	RETURN			;RETURN

;/TERMINATE

D.IGNR:	CAIE	T1,":"		;SOMEONE TYPED /TERMINATE
	USEROR	Must specify front end in /TERMINATE
	SETZM	A.TERM		;/TERMINATE TYPED.
	JRST	SETFE		;GO SET CPU AND DTE NUMBERS


;/AUTOMATIC

D.AUTO:	SETZM	A.AUTO
	RETURN


;/SWITCH:NUMBER

D.SWIT:	CAIE	T1,":"		;VALUE COMING?
	USEROR	Must specify switch value
	PUSHJ	P,GETOCT	;GET OCTAL NUMBER
	CAILE	T2,177777	;LEGAL?
	USEROR	Value for /SWITCH must not exceed 177777
	MOVEM	T2,A.SWIT	;SET THE VALUE
	RETURN			;EXIT.

;/NOLOG - DEFEATS ERROR LOGGING

D.NLOG:	SETZM	A.NLOG
	RETURN

;/INITIALIZE - STARTS PRIMARY PROTOCOL ON A FRONT END

D.STRP:	CAIE	T1,":"		;VALUE COMING?
	USEROR	Must specify front end number for /INITIALIZE
	SETZM	A.INIT		;SAY THAT ITS BEEN TYPED
	JRST	SETFE		;SET UP STUFF AND RETURN


;/START:# - SET -11'S START ADDRESS

D.STRT:	CAIE	T1,":"		;NEED A VALUE
	USEROR	Must specify address for /START
	PUSHJ	P,GETOCT	;GET IT
	TDNE	T2,[-1,,600001]	;LEGAL -11 WORD ADDRESS?
	USEROR	Illegal address for /START
	JRST	SVSTRT		;SAVE AND RETURN


;/LOAD - ONLY LOAD -11, DON'T START

D.LOAD:	MOVEI	T2,1		;SUPPLY FROM10 WITH ILLEGAL ADDRESS
SVSTRT:	MOVEM	T2,A.STRT	;SAVE IT
	RETURN			;AND RETURN
GETNAM:	MOVE	T3,[POINT 6,T2]
	MOVEI	T2,0		;CLEAR NAME
GETNM1:	PUSHJ	P,GETCHR	;GET NEXT CHAR
	CAIL	T1,"A"+40	;SEE IF LC
	CAILE	T1,"Z"+40
	JRST	.+2
	SUBI	T1,40		;YES--MAKE UC
	CAIL	T1,"0"		;SEE IF BREAK
	CAILE	T1,"Z"		; ..
	RETURN
	CAILE	T1,"9"		;OR OK
	CAIL	T1,"A"
	JRST	.+2
	RETURN
	SUBI	T1,40		;CONVERT TO SIXBIT
	TLNE	T3,770000	;SEE IF OVERFLOW
	IDPB	T1,T3		;STORE RESULT
	JRST	GETNM1		;LOOP FOR MORE

GETOCT:	MOVEI	T2,0		;CLEAR RESULT
GETOC1:	PUSHJ	P,GETCHR	;GET NEXT ODGIT
	CAIL	T1,"0"		;SEE IF
	CAILE	T1,"7"		; BREAK
	RETURN
	LSH	T2,3		;MULT BY 8
	ADDI	T2,-"0"(T1)	;INCLUDE ODGIT
	JRST	GETOC1		;LOOP

GETCHR:	INCHWL	T1		;GET NEXT CHARACTER
	JUMPE	T1,GETCHR	;LOOP IF NULL
	CAIE	T1,177		;IF RUB
	CAIN	T1,15		;OR CR
	JRST	GETCHR		;LOOP
	CAIL	T1,175		;IF ALTERNATE ALT MODE
	MOVEI	T1,33		; STANDARDIZE
	CAIN	T1,33		;IF ESCAPE
	MOVEI	T1,12		; MAKE INTO EOL
	CAIE	T1,13		;IF VTAB
	CAIN	T1,14		; OR FORM
	MOVEI	T1,12		; MAKE INTO LF
	CAIN	T1,11		;SEE IF TAB
	MOVEI	T1," "		;YES, CHANGE TO SPACE
	RETURN
SUBTTL	RANDOM SUBROUTINES

;STANDARD ROUTINE TO PRINT STANDARD OCTAL NUMBERS WITH STANDARD AC USAGE
TYPOCT:	IDIVI	T1,^D8		;EXTRACT LEADING OCTIT
	JUMPE	T1,TYPOC1	;IF LAST ONE, LEAVE RECURSIVE LOOP
	HRLM	T2,(P)		;SAVE IT FOR LATER PRINTING
	PUSHJ	P,TYPOCT	;DO PRECEDING
	HLRZ	T2,(P)		;GET IT BACK
TYPOC1:	ADDI	T2,"0"		;ASCIIIZE
	OUTCHR	T2		;REALLY WISH WE HAD BUFFERED IO...
	RETURN
SUBTTL STORAGE
	XLIST	;LITERALS
	LIT
	LIST

CCINT:	EXITX		;^C INTERCEPT BLOCK
	1B34
CCINTP:	Z
	Z


FWAZER:!		;START OF AREA TO CLEAR

PDLST:	BLOCK	PDSIZ+1
DEFDEV:	BLOCK	1		;LH: DEFAULT SOURCE DEVICE
				;RH: DEFAULT DUMP DEVICE
DEV:	BLOCK	1		;DEVICE
NAME:	BLOCK	1		;FILE NAME
EXT:	BLOCK	1		;FILE EXTENSION,,-1 IF . SEEN
DIRECT:	BLOCK	1		;DIRECTORY
DIRPTH:	BLOCK	9		;SFD PATH

NUMSWT:	BLOCK	1		;NUMBER OF SWITCHES TYPED

INBUF:	BLOCK	<INLEN==200>
INHDR:	BLOCK	3		;INPUT HEADER (NOTE THAT WE REALLY USE DUMP MODE)
OUTHDR:	BLOCK	3		;OUTPUT HEADER
MASTER:	BLOCK	1		;SET TO -1 IF DTE WE'RE DOING IS MASTER
ERRFNC:	BLOCK	1		;DAEMON UUO FUNCTION
ERRCOD:	BLOCK	1
ERRBLK:
ERRNUM:	BLOCK	1
ERRWRD:	BLOCK	1
ERRFNM:	BLOCK	1
ERRSIZ:	BLOCK	1
ERRLEN:	BLOCK	.ERLEN		;PLACE FOR FILE NAME
	ERBSIZ==.-ERRFNC

DMPPPN:	BLOCK	1		;PPN FOR DUMP FILE
DMPNAM:	BLOCK	1		;SAVE DUMP FILE NAME
DMPEXT:	BLOCK	1		;AND DUMP FILE EXTENSION
RETRYT:	BLOCK	1		;TOTAL COUNT OF RETRYIES FOR DUMPS AND RELOADS
RETRYC:	BLOCK	1		;TEMPORARY PER EVENT (DUMP, RELOAD) RETRY COUNTER
RTRYPC:	BLOCK	1		;PC TO JRST THRU TO RETRY AN OPERATION
FAILPC:	BLOCK	1		;PC TO JRST THRU WHEN ALL RETRIES FAIL
ADDRES:	BLOCK	1
CHKSUM:	BLOCK	1		;RUNNING CHECKSUM
FIRZER:	BLOCK	1		;FIRST LOCATION OF ZEROS
LASZER:	BLOCK	1		;LAST ..

LWAZER==.-1			;END OF AREA TO CLEAR

FWAONE:!			;START OF AREA TO PRESET TO -1
A.CPU:	BLOCK	1		;CPU NUMBER OF FRONT END
A.DTE:	BLOCK	1		;DTE NUMBER (0-3) OF FRONT END
A.AUTO:	BLOCK	1		;/AUTO
A.NDMP:	BLOCK	1
A.TERM:	BLOCK	1
A.IMAG:	BLOCK	1
A.A11:	BLOCK	1
A.RELD:	BLOCK	1
A.SEL:	BLOCK	1
A.SWIT:	BLOCK	1		;/SWITCH VALUE
A.NLOG:	BLOCK	1	
A.INIT:	BLOCK	1		;/INITIALIZE
A.STRT:	BLOCK	1
LWAONE==.-1			;END OF AREA TO PRESET TO -1
DTECNO:	CONO	(T1)
DTECNI:	CONI	T1
DTEDTO:	DATAO	T1
DTECSZ:	CONSZ	(T1)
DTECSO:	CONSO	(T1)
DTUBLK:	BLOCK	1		;FOR DTE. UUO
DTUDAT:	BLOCK	1		;SAME

BASEAD:	BLOCK	1		;EVA OF THIS PROGRAM AFTER LOCKED IN EVM
ATOFLG:	Z			;PERMANENT FLAG, CLEARED ONLY ON MANUAL
				; RESTART, SAYING THAT DTELDR IS IN /AUTO MODE
DMPFLG:	Z			;PERMANENT FLAG USED TO SPECIFY ON /AUTO
				;WHETHER OR NOT DUMPS WILL BE TAKEN.
DMPSIZ:	^D28*2000		;DUMP 28K OF 11 WORDS
DTEIOW:	DTEBUF-1		;COUNT FILLED IN AT DUMP TIME.
	Z
DTEBUF:	BLOCK	DTEBSZ		;BUFFER USED FOR TO-10 AND TO-11 TRANSFERS.

;MACRO TO PACK PDP-11 WORDS IN -10 MEMORY:
DEFINE	WORD11(A)<
    IRP A,<
	IFN ZZ,<			;;IF NONZERO THEN WE ARE ON RIGHT HALF
	    EXP <ZZ!A>&<177777,,177777>	;;SO STORE IN MEMORY
	    ZZ==0			;;AND CHANGE STAT BACK TO LEFT HALF
	;> ZZ==1B0!<A>B17		;;ELSE SAVE LEFT WORD AND FORCE NONZERO
    >
>;DEFINE WORD11

RP4PRG:	ZZ==0				;INIT WORD11
	WORD11	<12700,0>		;RP4PRG:MOV	#0,R0
	WORD11	<12704,176700>		;	MOV	#RPEXP,R4
	WORD11	<12703,176710>		;	MOV	#RPEXP+10,R3
	WORD11	<12713,40>		;	MOV	#40,@R3
	WORD11	<10005>			;	MOV	R0,R5
	WORD11	<305>			;	SWAB	R5
	WORD11	<42705,177770>		;	BIC	#177770,R5
	WORD11	<110513>		;	MOVB	R5,@R3
	WORD11	<12701,2>		;10$:	MOV	#2,R1
	WORD11	<12714,23>		;20$:	MOV	#23,@R4
	WORD11	<32714,4000>		;	BIT	#DVA,@R4
	WORD11	<1771>			;	BEQ	10$
	WORD11	<5301>			;	DEC	R1
	WORD11	<1371>			;	BNE	20$
	WORD11	<137,173034>		;	JMP	173034
	WORD11	<0>			;FORCE LAST HALFWORD OUT

DTAPRG:	ZZ==0				;INIT WORD11
	WORD11	<12700,0>		;DTAPRG:MOV	#0,R0
	WORD11	<137,173034>		;	JMP	173034
	WORD11	<0>
DTEPRG:	ZZ==0				;PRIME WORD11
	WORD11	<403>			;LODDTE: SEE SOURCE BELOW
	WORD11	<0>
	WORD11	<14,0>
	WORD11	<12700,160000>
	WORD11	<12706,162>
	WORD11	<5740>
	WORD11	<12702,156>
	WORD11	<12703,45>
	WORD11	<14240>
	WORD11	<77302>
	WORD11	<10002>
	WORD11	<5742>
	WORD11	<110>

	WORD11	<240>
	WORD11	<32711,4000>		;LODBLK: SEE SOURCE BELOW
	WORD11	<1775>
	WORD11	<12711,2100>
	WORD11	<10261,177766>
	WORD11	<12761,27774,177762>
	WORD11	<105711>
	WORD11	<2376>
	WORD11	<11061,177766>
	WORD11	<11203>
	WORD11	<1410>
	WORD11	<5403>
	WORD11	<42703,50000>
	WORD11	<10361,177762>
	WORD11	<105711>
	WORD11	<2376>
	WORD11	<750>

	WORD11	<10261,177766>		;STRT11:
	WORD11	<12761,127777,177762>
	WORD11	<5003>
	WORD11	<77301>
	WORD11	<32710,1>
	WORD11	<1001>
	WORD11	<130>
	WORD11	<0>
	WORD11	<0>			;THIS 0 FORCES OUT THE LAST -10 WORD

	BLOCK	^D128-.+DTEPRG		;RESERVE SPACE DTE WILL READ
COMMENT\	;DTE LOADER SOURCE:
	.TITLE	DTELDR - PDP-11 SIDE OF DTE LOADING PROGRAM
	.SBTTL	RIC WERME, JULY 1976
;COPYRIGHT 1976 DIGITAL EQUIPMENT CORP., MAYNARD, MA. 01752

R0	=%0
R1	=%1
R2	=%2
R3	=%3
R4	=%4
R5	=%5
SP	=%6
PC	=%7

;DTE LOCATIONS AND BIT DEFINITIONS
TO11BC	=174416
 I	=100000			;INTERRUPT -10 AT END OF TO-11 XFER
 TO11BM	=20000			;BYTE MODE TRANSFERS
TO11AD	=174422
STAT	=174434
 TO11DB	=4000			;DOORBELL RINGING
 INT11C	=2000			;CLEAR DOORBELL FLAG
 DON11C	=100			;WE HAVE TO CLEAR TO11 DONE MANUALLY
;THIS PROGRAM EXPECTS THAT R1 IS SETUP WITH THE ADDRESS OF THE STATUS
;WORD FOR THE DTE THAT INITIATED THE RELOAD.

	.ASECT
.	=0			;DTE ROM WILL PUT THIS AT 0

LODDTE:	BR	10$		;BRANCH OVER BUS TRAP VECTOR
	.WORD	0		;SPACE FILLING
	.WORD	20$,0		;BUS TRAP FOR TOP OF MEMORY SEARCH
10$:	MOV	#160000,R0	;ONE WORD PAST TOP OF MEMORY
20$:	MOV	#LASTWD+4,SP	;WE NEED A LITTLE STACK
	TST	-(R0)		;THIS WORD HERE? IF NOT, BACK UP ONE
	MOV	#LASTWD,R2	;MOVE LOADER BOTTOM UP
	MOV	#LODLEN,R3	;# WORDS TO MOVE TO HIGH CORE
30$:	MOV	-(R2),-(R0)	;MOVE LOADER THERE (NOTE - HIGH WORD IS FREE)
	SOB	R3,30$		;DO REST
	MOV	R0,R2		;R2 WILL BE DATLEN, R0 WILL BE DATADR
	TST	-(R2)		;SO POINT IT THERE
	JMP	@R0		;JUMP TO HIGH CORE WHERE THE LOADER IS

DATLEN	=.-2			;BYTE COUNT OF DATA PORTION OF MESSAGE OR 0
FRSTWD:
DATADR:	NOP			;ADDRESS WHERE TO PUT DATA OR START ADDR
LODBLK:	BIT	#TO11DB,@R1	;IS -10 READY FOR US?
	BEQ	LODBLK		;NOT YET
	MOV	#INT11C!DON11C,@R1 ;YES, CLEAR BITS TO SEE THEM SET AGAIN LATER
	MOV	R2,TO11AD-STAT(R1) ;TRANSFER 4 BYTES TO GET WHERE TO PUT DATA
	MOV	#TO11BM!<-4&7777>,TO11BC-STAT(R1)
10$:	TSTB	@R1		;TO11DN SET YET?
	BGE	10$		;NOT YET, WAIT FOR IT
	MOV	@R0,TO11AD-STAT(R1) ;TRANSFER REST OF BLOCK STARTING HERE
	MOV	@R2,R3		;GET LENGTH OF BLOCK
	BEQ	STRT11		;A 0 MEANS START ADDRESS WAS XFERRED
	NEG	R3		;MAKE NEGATIVE # OF BYTES
	BIC	#^C<I!TO11BM!7777>,R3 ;MAKE IT LIKE WHAT DTE WANTS
	MOV	R3,TO11BC-STAT(R1) ;START TRANSFER
20$:	TSTB	@R1		;DONE YET?
	BGE	20$		;NO, WAIT
	BR	LODBLK		;YES, GET ANOTHER

STRT11:	MOV	R2,TO11AD-STAT(R1) ;NEED SAFE PLACE TO
	MOV	#I!TO11BM!7777,TO11BC-STAT(R1) ; XFER AN EXTRA BYTE TO SET DONE
	CLR	R3		;DELAY LONG ENOUGH FOR EVERYTHING TO
	SOB	R3,.		; SETTLE AND FOR THE -10 TO SEE TO11DN
	BIT	#1,@R0		;IF START ADDRESS IS ODD,
	BNE	20$		;THEN SIMPLY HALT
	JMP	@(R0)+		;GO TO START (THE + SAVES A WORD)
20$:	HALT			;NO START ADDRESS SPECIFIED

LASTWD	=.			;END OF PROGRAM FOR COPY LOOP
LODLEN	=.-FRSTWD/2	;# WORDS TO COPY TO HIGH CORE

	.END	LODDTE
\	;END DTE LOADER SOURCE
;DTE ERROR MESSAGES

	[ASCIZ/UNKNOWN DTE. ERROR CODE/]
DTUERM:	[ASCIZ/DTE. ERROR CODE 0 -- DTE. UUO NOT IMPLEMENTED IN THIS MONITOR/]
	[ASCIZ/DTE. ERROR CODE 1 -- MUST HAVE PRIVILEGES TO RUN DTELDR/]
	[ASCIZ/DTE. ERROR CODE 2 -- INTERNAL ERROR - DTE. UUO CALLED WITH BAD FUNCTION NUMBER/]
	[ASCIZ/DTE. ERROR CODE 3 -- BAD FRONT END NUMBER/]
	[ASCIZ/DTE. ERROR CODE 4 -- PRIMARY PROTOCOL STILL RUNNING/]
	[ASCIZ/DTE. ERROR CODE 5 -- -11 POWER FAIL DID NOT SET/]
	[ASCIZ/DTE. ERROR CODE 6 -- -11 ROM PROGRAM FAILED TO START - CHECK HALT SWITCH/]
	[ASCIZ/DTE. ERROR CODE 7 -- TO-10 ERROR DURING BOOTSTRAP SEQUENCE/]
	[ASCIZ/DTE. ERROR CODE 10 -- -11 OBJECT PROGRAM FAILED TO SEND TO-10 DOORBELL/]
	[ASCIZ/DTE. ERROR CODE 11 -- INTERNAL ERROR - BAD JOB NUMBER GIVEN TO DTE. UUO/]
	[ASCIZ/DTE. ERROR CODE 12 -- BAD ERROR CODE FROM DTE. UUO/]
	[ASCIZ/DTE. ERROR CODE 13 -- BAD ERROR CODE FROM DTE. UUO/]
	[ASCIZ/DTE. ERROR CODE 14 -- BAD ERROR CODE FROM DTE. UUO/]
	[ASCIZ/DTE. ERROR CODE 15 -- BAD ERROR CODE FROM DTE. UUO/]
	[ASCIZ/DTE. ERROR CODE 16 -- BAD ERROR CODE FROM DTE. UUO/]
	[ASCIZ/DTE. ERROR CODE 17 -- FAILED TO START PRIMARY PROTOCOL/]
	DTUMLN==.-DTUERM


	END	USTART