Google
 

Trailing-Edge - PDP-10 Archives - -
There are no other files named in the archive.
COMMENT    VALID 00061 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00006 00002	SWITCHES:
C00012 00003	LEFT HALF FLAGS
C00015 00004	DEVICES, DEVICE CODE DEFINITIONS
C00017 00005		SUBTTL	DDT - SOME STORAGE STUFF
C00021 00006		SUBTTL	DDT - BREAKPOINT LOGIC
C00022 00007	BCOM, XEC0 - BREAKPOINT AND EXECUTE LOGIC
C00027 00008		SUBTTL	SAVE AND RESTORE ACS AND PI SYSTEM
C00035 00009		SUBTTL	EXEC DDT - SWAPPING DDT CODE
C00039 00010	DDTINI		INITIALIZE SWAPPING DDT!!!
C00044 00011	GETDDT   CALLED FROM SAVE TO GET DDT INTO CORE!  DDTMES
C00047 00012	GETBAK   CALLED FROM RESTORE TO UPDATE SYMBOL TABLE AND GET USER CORE BACK!
C00051 00013	EXAMINE & DEPOSIT ROUTINES FOR SWAPPING DDT!
C00054 00014	DCHECK - DEVICE PIA CHECKER - DTEXX, DTOCA, OTOCA, XTKL
C00062 00015		SUBTTL	DDT - INITIALIZATION, MAIN LOOP - DDTA
C00069 00016	NUM:	ANDI	T,17		T HOLDS CHARACTER
C00072 00017	PERIOD:	MOVE	T,LLOC		PERIOD ( . ) SEEN.  USUALLY THIS IS CURRENT LOCATION
C00074 00018	BEGIN UNDEF  SUBTTL	DDT - ASSEMBLY OF UNDEFINED SYMBOLS
C00079 00019		SUBTTL	DDT - SYMBOL MANIPULATION ROUTINE
C00089 00020		LOOK - VALUE TO SYMBOL
C00100 00021		EVAL - SYMBOL TO VALUE
C00104 00022	BEGIN SYMSRT  	SUBTTL	DDT - SORTED SYMBOL TABLE MANIPULATIONS
C00113 00023		SKILL	SSYMD	SYMDEL	SYMINS
C00121 00024		SEVAL	CONVERT SYMBOLIC NAME TO VALUE
C00127 00025		SLOOK	CONVERT VALUE TO SYMBOLIC
C00139 00026		SUBTTL	DDT - TEXT INPUT (ASCII AND SIXBIT)
C00143 00027		SUBTTL	DDT - BYTE INPUT
C00147 00028		SUBTTL	DDT - MORE OF THE WORD ASSEMBLER
C00150 00029		SUBTTL	DDT - REGISTER EXAMINATION LOGIC
C00154 00030		LTAB, TAB, DEPRA, EQUAL, PSYM
C00156 00031		SUBTTL	DDT - OUTPUT MODE CONTROL SWITCHES, UEDDT - JOBSET
C00159 00032		SUBTTL	DDT - GO, EXECUTE, AND BREAKPOINT LOGIC
C00164 00033	SINGLE STEP CODE FROM DEC
C00171 00034	 MUUOs
C00184 00035	INTERPRETATION
C00188 00036	IPUSHJ:	DPB W1,[POINT 4,CPUSHP,12]	STORE AC FIELD INTO A PUSH
C00190 00037		SUBTTL	DDT - PROCESS BREAKPOINT COMMANDS
C00192 00038		SUBTTL	DDT - FETCH AND DEPOSIT INTO MEMORY
C00201 00039		SUBTTL	DDT - PRINT INSTRUCTION.  PIN,LFPIN,RFPIN,CONSYM
C00204 00040		PRINT HALFWORDS, PRINT ADDRESS
C00207 00041		SUBTTL	DDT - $M, $N, $W, $E COMMANDS
C00211 00042		SUBTTL	DDT - $$Z
C00214 00043		SUBTTL	DDT - OUTPUT ROUTINES  TOCC, FTOC, TOC, TOCA
C00216 00044	FLOATING POINT OUTPUT
C00218 00045	FP7:	JUMPE A,FP7A2
C00220 00046		SUBTTL	EXEC DDT - PAPER TAPE MANIPULATIONS
C00223 00047		PAPER TAPE LOADERS
C00225 00048	VERIFY AND CORE (LOAD TAPE INTO CORE)
C00228 00049		SUBTTL	DDT - TTY I/O EXEC MODE  - TOUT
C00236 00050		SUBTTL	DDT - TTY I/O USER MODE
C00239 00051		SUBTTL	DDT - FLAG MODE OUTPUT
C00243 00052		SUBTTL	DDT - BYTE OUTPUT $nO
C00246 00053		SUBTTL	DDT - CHARACTER DISPATCH TABLE
C00249 00054		SUBTTL DDT - OP DECODER
C00255 00055	BEGIN OPDEFS
C00262 00056	PNTR:	INST		POINTER TO BITS IN INST
C00265 00057	DECT:	TRNE F,OUTF
C00268 00058	PATCH:	BLOCK 10
C00269 00059		SUBTTL	UEDDT ROUTINES - COPSYM
C00276 00060		MORE UEDDT
C00283 00061		SUBTTL	DDT User's Guide
C00299 ENDMK
C;

;SWITCHES:
;	EDDT_0 FOR NORMAL, USER DDT (DEFAULT)
;	UEDDTS__1 FOR USER EXEC DDT
;	EXEC DDT SETTINGS:
;		EDDT&1=0		ASSUME UDDT
;		EDDT&2=2		ASSUME EDDT WITH PAPER TAPE
;		EDDT&10=10		ASSUME PDP-10 PAPER TAPE INSTEAD OF PDP-6
;		EDDT&20=20		ASSUME SYSTEM EXEC DDT AND COMPILE SPECIAL CODE!
;		EDDT&40=40		MAKE RELOCATABLE EXEC DDT
;		EDDT&100=100		USE 10/6 INTERFACE INSTEAD OF TTY
;		IF LEFT HALF OF EDDT IS NOT=0, DO A LOC<EDDT-=18>

IFNDEF FTDDT,<FTDDT__-1>
IFN FTDDT,<				;THIS ENTIRE ASSEMBLY IS CONDITIONAL
	IFNDEF FTDSWP,<FTDSWP__0>
	IFNDEF EDDT,<EDDT__0>
	IFE EDDT&20,<FTDSWP__FTXCOR__0>
	IFE EDDT&21-21,<BEGIN DDT>	;IF SYSTEM EXEC DDT

IFNDEF SAVESW,<SAVESW_0>	;SET UP A STARTING ADRESS
IFNDEF UEDDTS,<UEDDTS_0>	;SET UP UEDDT

DEFINE XP' (X.,Y.),<
X.__Y.
>

IFE EDDT&21-1,<TITLE EDDT - EXEC MODE VERSION
	NOLIT
	XALL
	XTITLE__<RADIX50 0,EDDT>>

IFN EDDT,<SUBTTL DDT - EXEC MODE VERSION
	JOBREL__37
	JOBSYM__36
	ZLOW__40
IFNDEF KLEPT,<KLEPT__0>			;DEFAULT LOCATION OF KL10 EXEC PROCESS TABLE
>;IFN EDDT

IFE EDDT!UEDDTS,<TITLE UDDT - USER MODE DDT
	NOLIT
	XALL
	XTITLE__<RADIX50 0,UDDT>>

IFN UEDDTS,<TITLE UEDDT - USER MODE EXEC DDT
	NOLIT
	XALL
	XTITLE__<RADIX50 0,UEDDT>>

IFNDEF XTITLE,<XTITLE__0>

IFN EDDT,<
F__0		;FLAGS
IFE EDDT&20,<P__3>	;SETUP PUSHDOWN POINTER IF NOT SYSTEM
T__5		;TRANSFER DATA
W1__6
W2__7
SCH__10		;MODE CONTROL SWITCH FOR OUTPUT
AR__11		;MODE CONTROL SWITCH FOR OUTPUT
ODF__12		;MODE CONTROL SWITCH FOR OUTPUT - CURRENT RADIX
TT__13		;TEMPORARY
SMB__14		;SYMBOL TABLE POINTER FOR SORTED SYMBOLS
R__A__15	;POINTERS TO TABLES, CORE, ETC.  ABC MUST BE CONSECUTIVE.
S__B__R+1
W__C__R+2	;CONTAINS DISPATCH ADDRESS IN WORD ASSEMBLER
>;IFN EDDT

IFE EDDT,<		;DEFINITIONS FOR NON-EXEC MODE DDT
	EXTERN JOBREL,JOBSYM,JOBSA,JOBHRL,JOBFF
	ZLOW__140
F_0		;FLAGS
P_3		;PUSH DOWN
T_5		;TRANSFER DATA
W1_6
W2_7
SCH_10		;MODE CONTROL SWITCH FOR OUTPUT
AR_11		;MODE CONTROL SWITCH FOR OUTPUT
ODF_12		;MODE CONTROL SWITCH FOR OUTPUT - CURRENT RADIX
TT_13		;TEMPORARY
SMB_14		;SYMBOL TABLE POINTER FOR SORTED SYMBOLS
R_15		;POINTERS TO TABLES, CORE, ETC.
S_R+1
W_R+2		;CONTAINS DISPATCH ADDRESS IN WORD ASSEMBLER
A__R		;ABC MUST BE CONSECUTIVE.
B__R+1
C__R+2

>;IFE EDDT

;DEVICE CODES FOR EXEC MODE VERSION
^APR__0
^PI__4			;PI SYSTEM
^KLPAG__10
^CCA__14
TTYY__120		;CONSOLE TTY
PTRR__104		;PTR
PTPP__100		;PTP

LPDL__50		;MAX LENGTH PUSH DOWN LIST



IFN EDDT,<
IFNDEF SWEEPB,<SWEEPB__200000>
;EXEC PROCESS TABLE (EPT) LOCATIONS
IFNDEF DTE0,<DTE0__200>
IFNDEF DONG11,<DONG11__20000>		;RING 11'S DOORBELL
IFNDEF $DDT,<$DDT__441+KLEPT>		;DDT START ADDRESS
IFNDEF DTFLG,<DTFLG__444>		;DTE20 OP COMPLETE FLAG (RELATIVE TO EPT)
IFNDEF DTF11,<DTF11__450>		;      10 FROM 11 ARGUMENT
IFNDEF DTCMD,<DTCMD__451>		;      TO 11 COMMAND WORD
>;IFN EDDT

IFN EDDT&<-1,,0>,<	LOC	$DDT
			JRST	DDT	>

;LEFT HALF FLAGS

COMF__200000		;COMMA TYPED FLAG
TIF__100000		;TRUNCATE TO 18 BITS -  SET BY SPACE OR COMMA
PTF__100		;+, -, OR * HAS BEEN TYPED
CTF__400
SF__4			;SYLLABLE FLAG
QF__1			;QUANTITY TYPED IN TO WORD ASSEMBLER

CF__40			;$ TYPED
CCF__10000		;$$ TYPED
MF__2			;MINUS SIGN TYPED IN
LTF__20			;LETTER TYPED IN TO CURRENT SYLLABLE
ROF__10			;REGISTER OPEN FLAG
STF__4000
FAF__1000		; < TYPED
SAF__2000		; > TYPED

FPF__20000		;FLOATING POINT -  . TYPED IN
FEF__400000		;FLOATING EXPONENT -  E FLAG

MLF__200		;*FLAG
DVF__40000		;DIVIDE FLAG




;RIGHT HALF FLAGS

ITF__2			;INSTRUCTION TYPED IF ITF=1
OUTF__4			;OUTPUT IF OUTF=1
CF1__400		;OUTPUT 1 REGISTER AS CONSTANT
LF1__2000		;OUTPUT 1 REGISTER AS FORCED SYMBOLIC OR CONSTANT
Q2F__1			;NUMBER TYPED AFTER ALT MODE 
R20F__10		;TEMP FLAG USED IN SETUP
SBF__20
NAF__200		;NEGATIVE ADDRESSES PERMISSABLE
POWF__4000		;ARGUMENT FOR EXPONENT COMING
EQF__20000		;WANTS REAL NUMERIC MODE

GLOBAL__040000		;GLOBAL SYMBOL
LOCAL__100000
PNAME__740000		;PROGRAM NAME
DELI__200000		;DELETE INPUT
DELO__400000		;DELETE OUTPUT

PPID__0			;=0 IF SYMBOL TABLE POINTER IS IN JOBSYM
			;USED AS INDEX FIELD IN SYMP


IFE EDDT&1,<	LOC 74		;JOB DDT  (USER MODE DDT)
		DDT		;DDT'S STARTING ADDRESS
IFN UEDDTS,<	LOC 124
		DDTREN >	;REENTER ADDRESS FOR UEDDT
		RELOC 0 >	;END IFE EDDT&1

IFN EDDT&<XWD -1,0>,<LOC <EDDT>-=18>

INTERN DDT,$M,DDTEND

;THE MAXIMUM NUMBER OF BREAKPOINTS IS =36 (SEE AUTOPI)
NBP__=8					;NUMBER OF BREAKPOINTS
IFN EDDT,<NBP__=30>

IFE UEDDTS,<DEFINE SYMTST<>>
IFN UEDDTS,<DEFINE SYMTST
<	SKIPE SYMLUZ
	PUSHJ P,SYMPR>
MAXPR__400000	;MAX SIZE OF UPPER>

;DEVICES, DEVICE CODE DEFINITIONS

DEFINE DEVICES
<
XQ APR,0
XQ PI,4
XQ KLPAG,10	;KL10 PAGER DEVICE
XQ CCA,14	;KL10 CACHE CLEARER
XQ TIM,20	;KL10 TIMER
XQ MTR,24	;KL10 METER
XQ PAG,24
XQ PTP,100
XQ PTR,104
XQ IOP,110
XQ CTY,120
XQ LPT,124
XQ C1A,140
XQ C1B,144
XQ DTE0,200	;KL10'S 10/11 INTERFACE
XQ DC,204	;DATA CONTROL (136)  NOTE THIS IS NOT THE NORMAL DEVICE CODE!
XQ DTC,210
XQ DTS,214
XQ MTC,220
XQ MTS,224
XQ MTM,230	
XQ ADC,240
XQ DAC,244
XQ DCSA,300
XQ DCSB,304
XQ DKB,310
XQ DCA,320
XQ VDS,340	;EARNEST VIDEO SWITCH
XQ FRM,340	;MOORE DIGITAL SYNTHESIZER
XQ PLT,344	;PLOTTER (P2)
XQ SIX,344	;10/6 INTERFACE
XQ HOT,350	;THERMOMETER
XQ CAR,354
;XQ VOD,360
XQ KIM,360	;PARALYZER (KIM SERIAL INTERFACE)
XQ VMI,364
XQ PK,370
XQ DIL,374
XQ IMP,400
XQ TV,404
XQ ARM,420
XQ AD,424
XQ DPY,430
XQ KBD,434
XQ XGP,440
XQ DSK,444
XQ ELF,470
XQ PMP,500
XQ IBM,504
XQ DDD,510
XQ MPX,530
XQ SAMA,540
XQ SAMB,544
XQ SAMC,550
XQ SAMD,554
XQ PCLK,730
XQ AS,774
>;END DEVICES


IFE EDDT&21-1,<		;COMPILE DEVICE DEFINITION FOR NON-SYSTEM EXEC DDT

DEFINE XQ(A,B)
<A__B
>

DEVICES
>;IFE EDDT&21-1

	SUBTTL	DDT - SOME STORAGE STUFF

DDTBEG:				;FIRST ADDRESS IN DDT
IFN EDDT,<STARTA:	0>	;START ADDRESS FROM PAPER TAPE

IOTLG__0			;ASSUME NO DEVICES

IFN EDDT!UEDDTS,<		;COMPILE DEVICE TABLE FOR EXEC AND UEDDT
IOTBL:				;TABLE OF DEVICE NUMBERS KNOWN TO DDT
DEFINE XQ(A,B)<B>
DEVICES
IOTLG_.-IOTBL			;LENGTH OF DEVICE NUMBERS TABLE

IOTB2:				;TABLE OF RADIX50 DEVICE NAMES
DEFINE XQ (A,B)<RADIX50 0,A>
DEVICES
>;IFN EDDT!UEDDTS

SAVPI:	0
XP $I,SAVPI
	1077			;TURN OFF CHANNELS 2-7
SAVTTY:	0

IFN EDDT&1,<OUTLPT:	0
SAVAPR:	0	>
OUTRTN:0
STRING:	0
MSK:	XWD -1,-1
XP $M,MSK
MXINC:	100
BMASK:	0
FLGPTR:	0
B1ADR:	0			;CELL TO EXAMINE,,ADDRESS OF BREAK
B1SKP:	0			;CONDITIONAL INSTRUCTION - SEE BCOM3
B1CNT:	0			;PROCEDE COUNTER - SEE BCOM2, ALSO $P COMMAND
B1STR:	0			;STRING ADDRESS - SEE RETB

DEFINE DBPNT ! (Z.) <XP $!Z.!B,B1ADR+4*Z.-4>

RADIX =10
FOR QZ_1,NBP
<DBPNT (QZ)
>
RADIX =8
BLOCK	NBP*4-4		;ROOM FOR THE REST OF THE BREAKPOINTS

BNADR__.-4
AUTOPI:	0

AC0:	BLOCK 17

AC17:	0

SCHM:	PIN		;DO NOT CHANGE ORDER
	PADSO
ODFM:	10

SARS:	0
TEM1:	0

PS:	BLOCK LPDL

PRGM:	0		;IOWD POINTER TO SYMBOL TABLE 	- PROGRAM NAME $:
BLOCK:	0		;				- BLOCK NAME   $&
TBLK:	0		;				- TEMPORARY BLOCK BN&S
TEMDDT:	0
SVF:	0
SW1:	0
SVFB:	0
SVTB:	0
BLVL:	0
WRD:	0
WRD2:	0
PRNC:	0

FRASE:	0	;DONT CHANGE ORDER, SEE  SEARC+3
SYL:	0
LWT:	0
TEM2:	0
FRASE1:
TEM3:	0
DENDDT:	0

INSXCT:	XCT	I.NST		;SOME STORAGE FOR $X SINGLE STEP FEATURE.
I.NST:	0
I.NSTAC:0
I.NSTEA:0
I.NSTPC:0
SAV0:	0
XCTS:	0
XTEM:	0
FLAGS:	0
LOCSAV:	0

GETFLG:	0			;non zero once we've tried to auto-open a program

FSV:	0
FHTTMP:	0	;TEMP CELL FOR FLOATING POINT VALUE ACCUMULATION
FHDTMP:	0	;TEMP CELL FOR FLOATING POINT VALUE ACCUMULATION
SYM:	0
SPSAV:	0	;POINTER TO LAST SYMBOL TYPED
DEFV:	0
ULIMIT:	0
LLOC:	0
LLOCO:	0
SAVLOC:	0
IOTFLG:	0
KLFLG:	0	;SET TO -1 IF EXECUTING DDT ON A KL10
KEPTAD:	0	;SET TO THE CORE ADDRESS OF THE KL10 EPT
KLTMON:	0	;STATE OF TTY MONITOR MODE (RESTORED WHEN LEAVING DDT)
SVKLP:	0	;SAVE CONI KLPAG HERE
SYMP:IFN UEDDTS,<EXCSYM;	SO WE CAN DEBUG IT>	XWD PPID,JOBSYM

	SUBTTL	DDT - BREAKPOINT LOGIC

COMMENT %

THE LISTING OF THE FOLLOWING SOURCE CODE IS OMITTED FOR YOUR READING PLEASURE:

BP1:	REPEAT NBP,<
	0		;JSR TO HERE FOR BREAKPOINT
	JSA T, BCOM
	0		;HOLDS INSTRUCTION WHILE BREAKPOINT IS IN PLACE
	0
>

%

	XLIST

BP1:	REPEAT NBP,<
	0		;JSR TO HERE FOR BREAKPOINT
	JSA T, BCOM
	0		;HOLDS INSTRUCTION WHILE BREAKPOINT IS IN PLACE
	0
>

	LIST

B1INS__BP1+2
BPN__.-4		;ADDRESS OF THE LAST BREAKPOINT

;BCOM, XEC0 - BREAKPOINT AND EXECUTE LOGIC

BCOM:	0			;BREAKPOINT LOGIC
	POP	T,LEAV		;MOVE INSTRUCTION TO LEAV
	MOVEI	T,B1SKP-B1INS+1(T)
	HRRM	T,BCOM3		;CONDITIONAL BREAK SETUP
	MOVEI	T,B1CNT-B1SKP(T)
	HRRM	T,BCOM2		;PROCEDE COUNTER SETUP
	MOVE	T,BP1-B1CNT(T)	;GET PC OF TRAP
IFN EDDT&1,<	TLZ T,010000	;TURN OFF USER MODE BIT>
	HLLM	T,LEAV1		;SAVE FLAGS FOR RESTORING
	EXCH	T,BCOM		;RESTORE T
IFN FTDSWP,<
	SKIPP2			;DON'T LET P2 TAKE BREAKS IF NO DDT!
	JRST	BCOM3
	SKIPE	INDDT
	SKIPN	KEEPIN
	HALT	NOBREAK
>
BCOM3:	SKIPN	B1SKP		;ADDR MOD TO LOOK AT COND. INST.
	JRST	BCOM2		;THERE IS NO CONDITIONAL INSTRUCTION
	XCT	@BCOM3		;EXECUTE THE COND. INSTR.  ALL ACS ARE USER'S
	JRST	NOBREAK		;DON'T BREAK IF NO SKIP.
BCOM2:	SOSG	B1CNT		;ADDR MOD TO LOOK AT PROCEED COUNTER
	JRST	BREAK		;PROCEDE COUNTER NON POSITIVE - TAKE A BREAK!
NOBREAK:
	MOVEM	T,AC0+T
	LDB	T,[POINT 9,LEAV,8]	;GET INSTRUCTION
	CAIL	T,264			;JSR
	CAILE	T,266			;JSA,JSP
	TRNN	T,700			;UUO
	JRST	PROC1			;MUST BE INTERPRETED
	CAIE	T,260			;PUSHJ
	CAIN	T,256			;XCT
	JRST	PROC1			;MUST BE INTERPRETED
	MOVE	T,AC0+T
	JRST	2,@LEAV1		;RESTORE FLAGS, GO TO LEAV

LEAV1:	XWD	0,LEAV			;FLAGS STORED IN LH.

PROC1:	MOVE	T,AC0+T			;HERE TO INTERPRET INSTR.
	JSR	SAVE
	JFCL
	JRST	PROC2

LEAV:	0			;INSTRUCTION MODIFIED
	JRST	@BCOM		;DIRECT RETURN
	AOS	BCOM		;INSTRUCTION SKIPPED.
	JRST	@BCOM

BREAK:	JSR	SAVE		;HERE TO TAKE A BREAK
	JRST	BREAKA
	JRST	BREAKB


;THIS CODE GETS US OUT OF DDT AND BACK IN FOR $X AND FOR $G
XEC0:	MOVEM	T,TEMDDT	;SAVE INSTRUCTION TO XCT
	PUSHJ	P,CRF		;TYPE CRLF
	PUSHJ	P,TTYLEV	;RESTORE STATE OF TTY
	PUSHJ	P,INSRTB	;REINSERT BREAKPOINTS
	MOVE	W,TEMDDT	;IN CASE OF INTERUPTS (JS STUFF)
	JSP	T,RESTORE	;RESTORE WILL XCT W
XEC1:	JRST	XEC2		;USED AT PROC0  (NON-SKIP)
	JSR	SAVE		;(SKIP)
	PUSHJ	P,REMOVB
	PUSHJ	P,CHKSYM	;REINITIALIZE SYMBOL TABLE STUFF
	PUSHJ	P,CRF		;OUTPUT AN EXTRA CRLF TO SIGNIFY SKIP.
	JRST	DD1

XEC2:	JSR	SAVE		;NON-SKIP RETURN FROM XCT'ED INSTR. OMIT EXTRA CRLF
	PUSHJ	P,REMOVB
	PUSHJ	P,CHKSYM
	JRST	DD1

; This code for single step logic (pg. 35-6)
; Enter with I.NST containing instruction to be executed,
;  INSXCT containing an XCT (either EXEC or normal) which will
;  be stored in the appropriate XCTBUF. ?This scheme hopefully
;  takes care of the EXEC XCT problem.

DOITA:	MOVEM	F,SAV0
	PUSHJ	P,TTYLEV
	PUSHJ	P,INSRTB
	MOVE	W,INSXCT
	JSP	T,RESTOR
	JRST	DOITB		;INSTRUCTION DIDN'T SKIP
DOITC:	JSR	SAVE		;Skipped
	PUSHJ	P,REMOVB
	PUSHJ	P,CHKSYM
	JRST	SKIP%

DOITB:	JSR	SAVE
	PUSHJ	P,REMOVB
	PUSHJ	P,CHKSYM
	JRST	NOSKIP

; Control is transferred to JMP whenever a conditional jump jumps.
;  It returns to the $X code to simulate the jump.
JMP:	JSR	SAVE
	PUSHJ	P,REMOVB
	PUSHJ	P,CHKSYM
	JRST	JMP1

	SUBTTL	SAVE AND RESTORE ACS AND PI SYSTEM

SAVE:	0		;SAVE THE ACS AND PI SYSTEM
	SKIPN SARS	;SKIP IF ACS ARE ALREADY SAVED
	JRST SAV1	;NOPE
	AOS SAVE	;SKIP RETURN INDICATES WE DON'T REMOVE BREAKPOINTS
	JRST SAV5	;CONTINUE IN SAVE

SAV1:
IFN EDDT&1,<
	CONI APR,SAVAPR		;SAVE APR CONI
	CONI PI,SAVPI		;SAVE OF PI SYSTEM
	CONO PI,@SAVPI+1	;SET STATE OF PI SYSTEM (CH 3-7 OFF)
IFE EDDT&40,<	SETOM DDTFLG	>	;PREVENT P2 FROM DOING CHECKSUM
>;IFN EDDT&1
	MOVEM 17,AC17			;STUFF THE ACS
	HRRZI 17,AC0
	BLT 17,AC0+16

IFN EDDT,<
	SETZM KLFLG		;ASSUME NOT A KL10
	MOVE T,[T,,T]
	BLT T,T
	CAMN T,[T,,T]
	JRST SAV1A
	SETOM KLFLG		;THIS IS A KL10
	CONI KLPAG,T		;GET EBR.
	MOVEM T,SVKLP		;SAVE STATE OF KL10 PAGER
	CONSZ APR,SWEEPB	;WAIT FOR SWEEP BUSY TO FALL
	JRST .-1
	CONSO KLPAG,600000	;IS THE CACHE ON ALREADY?
	JRST SAVX		;NO.
	BLKO CCA,		;VALIDATE CORE
	CONSZ APR,SWEEPB
	JRST .-1
SAVX:	TRZ T,600000		;CLEAR CACHE LOOK AND LOAD
	CONO KLPAG,(T)		;TURN OFF CACHE.
	DATAI CCA,0		;SWEEP CACHE.  INVALIDATE ALL.
	CONSZ APR,SWEEPB	;WAIT FOR SWEEP BUSY TO FALL
	JRST .-1
	ANDI T,17777		;MASK EBR ONLY
	LSH T,9			;SHIFT TO MAKE A CORE ADDRESS
	MOVEM T,KEPTAD		;SAVE EPT ADDRESS.
>;IFN EDDT

SAV1A:	MOVE T,SAVE			;GET THE PC FLAGS
	HLLM T,SAVPI			;STUFF IN LH OF PI CONI WORD
SAV5:	SETOM SARS			;FLAG THAT THE ACS HAVE BEEN SAVED
	MOVEI P,PS			;STACK

IFN FTDSWP&EDDT&1,<	PUSHJ P,GETDDT	;DO THE SWAPPABLE DDT THING! >;FTDSWP&...

IFE EDDT,<		PUSHJ P,TTYRET	;USER MODE. TTY TO DDT MODE >;IFE EDDT

	MOVEI F,0
	MOVE T,[SCHM,,SCH]
	BLT T,ODF			;LOAD THE ACS WITH MODE SWITCHES
	JRST @SAVE			;RETURN

;THE XCTBUF IS 8 COPIES OF THE PROCEDE FROM BREAKPOINT (AND EXECUTE)
;CODE.  8 COPIES CORRESPOND TO THE 7 PI LEVELS PLUS NO PIS IN PROGRESS
;LEVEL.
;ONCE THE PI SYSTEM IS RESTORED, AN INTERRUPT MAY HAPPEN THAT STARTS DDT
;AT SOME HIGHER PRIORITY PI CHANNEL.  IF THIS OCCURS, EXITING THAT HIGHER
;CHANNEL WILL USE A DIFFERENT XCTBUF AND THUS ENSURE THAT ALL INSTRUCTIONS
;HAPPEN CORRECTLY, IN THEIR CORRECT PI CHANNELS.

XCTBUF:
REPEAT <EDDT&1*7>+1,<
	CONO	PI,@SAVPI		;RESTORE STATE OF PI SYSTEM
	0				;INSTRUCTION TO EXECUTE
	SKIPA				;DIDN'T SKIP
	AOS .+1				;INSTR. DID SKIP
	JRST .				;SET ADDRESS TO RETURN TO.
	0				;USED TO SIMULATE PUSHJ
	>

XCTQ__6		;SIZE OF EACH ENTRY IN XCTBUF

;RESTORE - ENTER WITH T CONTAINING THE RETURN ADDRESS AND W AN INSTRUCTION TO XCT
RESTORE:SETOM	TEM3		;RESTORE ACS AND PI SYSTEM (EXIT DDT)
RESTR1:	HRRM	T,SAVE		;HERE TO DO $P TO PROCEDE AT A PUSHJ.  TEM3 IS ZERO

IFN 0&EDDT&1,<			;SYS WRITE REF KLUDGE HAS BEEN REMOVED.
	MOVE	T,SAVAPR
	ANDI	T,SYSCLB!7	
	TRNN	T,SYSCLB
	CONO	APR,CLRCLB(T)	;IF THE SYSTEM WASN'T CLOBBERED WHEN WE CAME 
				;IN, THEN IT ISN'T CLOBBERED NOW.
>

	MOVE	T,SAVPI		;PC FLAGS,,PI STATE
	HLLM	T,SAVE		;STORE PC FLAGS
	MOVEM	W,TEMDDT	;STORE INSTRUCTION TO XCT
	MOVEI	W,XCTBUF	;ASSUME NOT PI IN PROGRESS.

IFN EDDT,<
	AND	T,SAVPI+1	;TURN ON ONLY THOSE CHANNELS WE TURNED OFF
	ANDI	T,177
	IORI	T,2000		;TURN ON CHANNELS
	EXCH	T,SAVPI		;STORE PI CONO BITS.  GET IN PROGRESS BITS.

;WHICH XCTBUF USED DEPENDS ON HIGHEST CHANNEL IN PROGRESS WHEN WE STARTED.
ZZ__7
REPEAT 7,<	TRNE	T,1<17-ZZ>
		MOVEI	W,XCTBUF+<XCTQ*ZZ>
ZZ__ZZ-1>;REPEAT 7

>;IFN EDDT

	HLL	W,SAVE		;GET THE PC FLAGS
	MOVEM	W,RES2		;STORE FLAGS,,ADDRESS OF XCTBUF
IFE EDDT,<AOS	RES2>		;IN USER MODE, SKIP THE CONO PI
	MOVE	T,TEMDDT	;GET THE INSTR. TO XCT
	MOVEM	T,1(W)		;STORE IT WHERE WE'LL RUN OVER IT
	HRRZ	T,SAVE		;GET THE RETURN ADDRESS
	HRRM	T,4(W)		;STUFF IT IN THE JRST
	SKIPGE	TEM3		;IS THIS $P AT A PUSHJ?
	JRST	RES3		;NOPE.
	MOVE	T,BCOM		;GET THE ADDRESS AND FLAGS FROM BREAKPOINT
	MOVEM	T,5(W)		;STUFF IN XCTBUF
	MOVEI	T,5(W)		;CHANGE THE ADDRESS OF THE PUSH TO POINT
	HRRM	T,1(W)		;  AT THE PC AND FLAGS.
				;PUSHJ BECOMES A PUSH AND A JRST
RES3:
IFN EDDT&20,<
	MOVE	TAC,MONPTR	;RECOMPUTE MONITOR CHECKSUM
	PUSHJ	P,CHECK
	SKIPN	STRING		;ONLY IF COMMANDS COMING FROM KEYBOARD!
	MOVEM	TAC1,MONSUM

IFN FTHSYS,<
	MOVE	TAC,HMNPTR	;RECOMPUTE CHECKSUM OF HIGH PART.
	PUSHJ	P,CHECK
	SKIPN	STRING
	MOVEM	TAC1,HMNSUM
>;FTHSYS
IFE EDDT&40,<	SETZM DDTFLG >	;TELL P2 IT'S OK TO CHECKSUM


IFN FTDSWP,<
	PUSHJ	P,GETBAK	;DO THE SWAPPABLE DDT THING
>
>
	MOVSI	17,AC0		;RESTORE USER ACS
	BLT	17,17
	SETZM	SARS
IFE EDDT&1,<	JRST	2,@RES2	;EXIT IF USER DDT.>;IFE EDDT
IFN EDDT&1,<
	SKIPN	KLFLG		;YET MORE WORK TO DO IF THIS IS A KL10.
	JRST	2,@RES2		;RESTORE FLAGS AND JUMP TO XCTBUF
	MOVEM	1,TEM3
	CONO	APR,027760	;CLEAR ALL FLAGS
	LDB	1,[POINT 12,SAVAPR,17]	;GET ORIGINAL APR ENABLES
	CONO	APR,100000(1)		;SET ORIGINAL ENABLES
	LDB	1,[POINT 12,SAVAPR,35]	;GET ORIGINAL FLAGS AND PIA
	IORI	1,20			;SET SWEEP DONE.  CACHE IS CLEAN.
	CONO	APR,10000(1)		;SET ORIGINAL FLAGS AND PIA
	MOVE	1,TEM3
	CONO	KLPAG,@SVKLP		;RESTORE PAGER TO ORIGINAL STATE
	JRST	2,@RES2
>;IFN EDDT&1

RES2:	0

	SUBTTL	EXEC DDT - SWAPPING DDT CODE
IFE EDDT&21-21,<
COMMENT 
INITIALIZATION ROUTINES FOR SWAPPING DDT
SWAPPING DDT CONTROL CELLS AND THEIR MEANINGS:

NOTDDT:		-1	FLUSH DDT ENTIRELY

KEEPIN:		-1	DDT STAYS IN CORE ALWAYS
		0	DDT IS SWAPPABLE

INDDT:		-1	DDT IS IN CORE
		0	DDT IS ON DISK

EXMMAP:		0	EXAMINE & DEPOSIT ACTUAL ADDRESS
		-1	EXAMINE & DEPOSIT VIA EXEC MAP

DDTXCOR:	-1	DDT IS SWAPPED OUT IN EXTRA CORE RATHER THAN DISK

XDDPTR:			AOBJN POINTER TO PAGE TABLE FOR DDT

DDTFLG:		0	THIS IS -1 WHEN DDT IS ACTIVE
			(KEEPS P2 FROM MONITOR CHECKSUMMING)


^^NOTDDT:	0	;START WITH DDT

^^DDTFLG:	0	;SET TO -1 WHEN DDT IS ACTIVE (FOR P2)

^^KEEPIN:	-1	;DDT STAYS IN AT LEAST UNTIL THE FIRST START-UP

^^INDDT:	-1	;DDT STARTS OUT IN CORE!

^^SYMLOC:	0	;SET BY BEGIN TO CONTENTS OF DDTSYM BEFORE ONCE ONLY CODE

^^EXMMAP:	-1	;REFERENCE CORE AT FIRST

^^DDTXCOR:	0	;INITIALIZED IN SYSINI, JUST LIKE DDTSWP

^^XDDPTR:	0	;AOBJN POINTER TO EXEC PAGE TABLE FOR DDT + SYMBOLS

DDSPFW:		0	;SAVED PAGE FAIL WORD

DDSFPC:		0	;SAVE PAGE FAULT PC WORD

DDSNPC:		0	;SAVE PAGE FAULT NEW PC WORD

^^DDTSUM:	0	;CHECKSUM OF DDT

SWPWRD:		0	;PLACE TO KEEP WORD WE ARE DEPOSITING!

^^USROFF:	0	;FIRST WORD ON DISK=ADDRESS DDTA&37=SEC 0 ON 2ND BAND

^^USREND:	0	;WORD AFTER LAST ON DISK=USROFF+SYM LENGTH+DDTEND-DDTA+100

;DDTINI		INITIALIZE SWAPPING DDT!!!

^DDTINI:
IFN FTXCOR,<
	SKIPE DDTXCOR
	JRST SETXC		;SWAP DDT OUT TO EXTRA CORE
>;IFN FTXCOR
DDTIN1:	SETOM KEEPIN
	SETOM INDDT		;DDT IS IN NOW
	HLRE TAC,DDTSYM
	MOVMS TAC
	ADD TAC,DDTSYM
	SKIPN TAC
	MOVEI TAC,DDTEND
	HRRZM TAC,SYSSIZ
	MOVE TAC,DDTSYM
	MOVEM TAC,SYMLOC	;SYMLOC WILL ALWAYS POINT TO SYMBOLS
	SETOM EXMMAP		;EXAMINE MAPPED
	POPJ P,

IFN FTXCOR,<
SETXC:	PUSH P,KLUPT+KLPFNP
	MOVE TAC,[PCU,,SETXCT]
	MOVEM TAC,KLUPT+KLPFNP
	MOVE TAC,[160040,,1000]		;PAGE TABLE POINTER TO 1000000
	MOVE TAC1,[DDTA,,DDTEXP9]	;INITIAL BLT POINTER
	HLRE AC2,DDTSYM
	MOVN AC2,AC2
	ADD AC2,DDTSYM			;ONE PAST LAST SYMBOL
	MOVEI AC2,-DDTA+777(AC2)	;SIZE OF DDT+SYMBOLS+777
	LDB AC2,[POINT 9,AC2,26]	;NUMBER OF PAGES IN DDT+SYMBOLS
	PUSH P,AC2
	BLKI KLPAG,[EXPGT-9  -1]	;SET EXPGT AND USPGT POINTERS IN AC BLOCK 6
SETXC2:	CONO KLPAG,@KLPCON
	MOVEM TAC,EXPGT+DDTEXP		;CLOBBER MAP FOR PAGE DDTEXP TO HIGH CORE
	MOVE AC1,TAC1			;GET BLT POINTER
	BLT AC1,DDTEXP9+777		;MOVE PAGE OF LOW CORE INTO PAGE DDTEXP
	ADD TAC1,[1000,,]		;UPDATE SOURCE OF BLT (DEST. IS DDTEXP9+777)
	ADDI TAC,1			;UPDATE PAGE TABLE POINTER TO HIGH CORE
	SOJG AC2,SETXC2			;LOOP, COUNTING DOWN PAGES MOVED.
;AS A RESULT OF THE ABOVE, DDTA IS COPIED TO 1,,0 AND SYMBOLS ARE AT
;1000000+RH(DDTSYM)-DDTA  (FOR UEDDT, USE SYMLOC, NOT DDTSYM)
	MOVEI AC2,DDTA
	MOVEM AC2,USROFF		;FIRST LOCATION FOR SWPEXM
	MOVE AC2,(P)
	LSH AC2,9
	ADDI AC2,DDTA
	MOVEM AC2,USREND		;1 PAST LAST LOCATION FOR SWPEXM
	POP P,AC2			;GET BACK NUMBER OF DDT+SYMBOLS PAGES
	MOVN AC2,AC2
	HRLZ AC2,AC2
	HRRI AC2,EXPGT+(DDTA-9)	;AOBJN POINTER TO EXEC PAGE TABLE
	MOVEM AC2,XDDPTR
	MOVE AC2,DDTSYM
	MOVEM AC2,SYMLOC
	POP P,KLUPT+KLPFNP
	CONO KLPAG,KLEPT-9		;TURN MAPPING BACK OFF
	SETOM EXMMAP			;DEFAULT IS EXAMINE MAPPED
	SETZM KEEPIN
	SETZM INDDT
	SETZM DDTSYM			;NO SYMBOLS, NOW
	MOVEI TAC,DDGVUS
	MOVEM TAC,SYSSIZ		;GIVE LOSERS ALL THIS CORE!
	POPJ P,

SETXCT:	SETZM DDTXCOR
	CONO KLPAG,KLEPT-9		;TURN MAPPING BACK OFF
	SUB P,[1,,1]
	POP P,KLUPT+KLPFNP
	JRST DDTIN1
>;FTXCOR

;GETDDT   CALLED FROM SAVE TO GET DDT INTO CORE!  DDTMES

GETDDT:	SKIPP1	
	POPJ P,			;CAN'T DO THIS ON P2
	MOVE TAC,KLUPT+KLPFW
	MOVEM TAC,DDSPFW	;SAVE PAGE FAIL WORD
	MOVE TAC,KLUPT+KLPFPC
	MOVEM TAC,DDSFPC	;SAVE PAGE FAIL PC
	MOVE TAC,KLUPT+KLPFNP
	MOVEM TAC,DDSNPC	;SAVE PAGE FAIL NEW PC WORD
	MOVE TAC,[PCU,,DDTTRP]
	MOVEM TAC,KLUPT+KLPFNP	;SET UP NEW PC WORD FOR PAGE FAULTS DURING DDT
REPEAT 0,<
	MOVEI TAC,.		;LET'S SEE WHERE WE ARE.
	CAMGE TAC,37		;HAS 37 BEEN CLOBBERED?
	JRST GETDD2		;I SUPPOSE WE'LL LET IT ALONE.
	CAMGE TAC,RMEMSIZE	;I HOPE THIS ISNT
	MOVE TAC,RMEMSIZE
	SUBI TAC,1
	MOVEM TAC,37
GETDD2:
>;REPEAT 0
	SKIPE INDDT		;IF DDT ALREADY IN ...
	POPJ P,			;...THEN NOTHING ELSE TO DO
IFN FTXCOR,<
	SKIPE DDTXCOR
	JRST GTDDMP		;DDT IS IN HIGH CORE
>;FTXCOR
	JSP TAC,DDTMES
	ASCIZ /CAN'T FIND DDT ANYWHERE
/
	HALT .

IFN FTXCOR,<
GTDDMP:	MOVE TAC,XDDPTR			;AOBJN POINTER TO EXEC PAGE TABLE
	MOVE TAC1,[160040,,1000]
GTDDM1:	MOVEM TAC1,(TAC)
	ADDI TAC1,1
	AOBJN TAC,GTDDM1
	CONO KLPAG,60000+KLEPT-9	;CLEAR PAGER
	MOVE TAC,SYMLOC
	MOVEM TAC,DDTSYM
	SETOM INDDT
	POPJ P,				;SET DDT IN AND CHECK CHECKSUM
>;FTXCOR

;DDTMES   TYPES MESSAGE ON CTY
;CALLING SEQUENCE:
;	JSP TAC,DDTMES
;	ASCIZ/MESSAGE/
;	<RETURNS HERE>

DDTMES:	HRLI TAC,(<POINT 7,0>)
	JSR DDTTYPE
	JRST 1(TAC)		;SEE HOW CLEVER WE ARE!!!!


;GETBAK   CALLED FROM RESTORE TO UPDATE SYMBOL TABLE AND GET USER CORE BACK!

GETBAK:	SKIPP1
	POPJ P,			;P2 DOESN'T DO ANYTHING
	MOVE TAC,DDSPFW
	MOVEM TAC,KLUPT+KLPFW	;RESTORE TRAP STATUS WORD
	MOVE TAC,DDSFPC
	MOVEM TAC,KLUPT+KLPFPC	;AND PAGE FAULT PC WORD
	MOVE TAC,DDSNPC
	MOVEM TAC,KLUPT+KLPFNP	;AND PAGE FAULT NEW PC WORD
	SKIPN KEEPIN		;DDT GOING OUT?
	SKIPN INDDT		;AND IN NOW
	POPJ P,			;NO
	SETZM DDTSYM		;NO DDT, NO SYMBOLS.
	SETZM INDDT		;DDT NO LONGER IN CORE
IFN FTXCOR,<
	SKIPE DDTXCOR
	JRST BKDDMP
>;FTXCOR
	HALT .			;CANT GET HERE

IFN FTXCOR,<
BKDDMP:	MOVE TAC,XDDPTR		;AOBJN POINTER TO PAGE TABLE
BKDDM1:	SETZM (TAC)		;EXEC HAS NO ACCESS THERE!
	AOBJN TAC,BKDDM1
	CONO KLPAG,60000+KLEPT-9	;RESET PAGER
	POPJ P,
>;FTXCOR

;EXAMINE & DEPOSIT ROUTINES FOR SWAPPING DDT!

SWPEXM:	CAIG R,17
	JRST CPOPJ2		;LET SOMEONE ELSE FIGURE OUT HOW TO EXAMINE ACS
	SKIPN EXMMAP		;SKIP IF EXAMINING USING EXISTING MAP
	SKIPP1
	JRST CPOPJ2		;P2 GETS CORE!
	JRST XCREXM

SWPDEP:	MOVEM T,SWPWRD
	PUSHJ P,SWPEXM
	 JRST XCRDEP		;GOT IT IN!
	 POPJ P,		;MAKE BELIEVE IT WON!!
	CAIG R,17
	JRST CPOPJ1		;LET SOMEONE ELSE FIGURE OUT HOW TO EXAMINE ACS.
	SKIPP2			;SKIP IF THIS IS P2
	SKIPN EXMMAP		;SKIP IF EXAMINING USING EXISTING MAP
	JRST CPOPJ1		;NOT USING MAP.  LET SOMEONE ELSE THINK ABOUT IT.

	CONSO KLPAG,1B22	;YES.  SKIP IF KL10 PAGER IS TURNED ON
	JRST CPOPJ1		;DON'T USE MAP
	PUSH P,W
	PUSH P,S
	LDB S,[POINT 13,R,26]	;PAGE NUMBER OF REFERENCE
	MOVEI T,EXPGT(S)	;ADDRESS OF THE EXPGT ENTRY FOR THIS PAGE.
	SKIPN T,(T)		;GET THE EXISTING MAP ENTRY
	JRST DDTTRP		;PAGE FAULT
	HRLI T,160040		;ALLOW US TO WRITE THERE.
	MOVEM T,EXPGT+DDTEXP
	CONI KLPAG,T
	CONO KLPAG,(T)		;CLEAR ARS
	LDB S,[POINT 9,R,35]	;KEEP OFFSET IN PAGE
	MOVE T,SWPWRD		;SETUP T WITH THE DATUM
	MOVEM T,<DDTEXP9>(S)	;STORE DATUM
	POP P,S
	SETZM EXPGT+DDTEXP
	CONI KLPAG,W
	CONO KLPAG,(W)		;CLEAR ARS
	POP P,W
	POPJ P,

XCREXM:	PUSH P,W
	MOVE W,[MOVE T,<DDTEXP9>(S)]
XCRRTN:	PUSH P,S
	LDB S,[POINT 13,R,26]	;PAGE NUMBER OF REFERENCE
	HRLI S,160040
	MOVEM S,EXPGT+DDTEXP
	CONI KLPAG,S
	CONO KLPAG,(S)		;CLEAR ARS
	LDB S,[POINT 9,R,35]	;KEEP OFFSET IN PAGE
	XCT W
XCRFIN:	POP P,S
	CONI KLPAG,W
	CONO KLPAG,(W)		;CLEAR ARS
	POP P,W
	POPJ P,

XCRDEP:	PUSH P,W
	MOVE T,SWPWRD
	MOVE W,[MOVEM T,<DDTEXP9>(S)]
	JRST XCRRTN

DDTTRP:	MOVEI S,[ASCIZ / ?PAGE FAULT /]
	PUSHJ P,ASCOUT
	JRST XCRFIN

;DCHECK - DEVICE PIA CHECKER - DTEXX, DTOCA, OTOCA, XTKL

;CALL WITH JSR DCHECK$X

DCHKPD:	BLOCK 40
DCHKAC:	BLOCK 20
DCHECK:	0
	MOVEM 17,DCHKAC+17
	MOVEI 17,DCHKAC
	BLT 17,DCHKAC+16
	MOVEI P,DCHKPD-1		;GET A PDL
	MOVSI TAC,-NDCHK
DCHEK1:	MOVE TAC1,DCHKTB(TAC)		;GET BYTE POINTER
	MOVE AC2,TAC1			;SAVE ALLOWABLE DEVICE CODES
	LDB J,[POINT 7,TAC1,24]		;GET DEVICE CODE
	HRRI TAC1,AC1			;CONI WILL BE IN AC1
	MOVE DAT,J
	LSH DAT,=26			;SHIFT TO DEVICE CODE FIELD
	IOR DAT,[CONI AC1]
	XCT DAT				;DO THE CONI INTO AC1
	LDB TAC1,TAC1			;GET THE PIA
	MOVEI TEM,3
DCHEK2:	IDIVI AC2,10			;GET NEXT ALLOWABLE PIA IN AC3
	CAIN AC3,(TAC1)			;DOES THE PIA MATCH?
	JRST DCHEK3			;YES, GO ON TO NEXT ENTRY
	SOJG TEM,DCHEK2			;TRY ALL THREE POSSIBLE PIAS
	MOVEI S,[ASCIZ /DEVICE /]	;S=AC2 AND T=DAT GET CLOBBERED
	PUSHJ P,ASCOUT			;BY TYPEOUT
	MOVE W1,DCHKNM(TAC)		;GET DEVICE NAME
	PUSHJ P,SIXOUT
	MOVEI S,[ASCIZ / (/]
	PUSHJ P,ASCOUT
	MOVEI T,(J)			;GET DEVICE CODE BACK
	LSH T,2				;MAKE IT A MULTIPLE OF 4
	PUSHJ P,OTOCA			;TYPE IT, CLOBBERS W1=DDB
	MOVEI S,[ASCIZ /) CONI BITS /]
	PUSHJ P,ASCOUT
	LDB T,[POINT 6,DCHKTB(TAC),11]	;SIZE FIELD OF BYTE POINTER
	LDB AC3,[POINT 6,DCHKTB(TAC),5]	;POSITION FIELD
	ADDI T,(AC3)
	MOVN T,T
	ADDI T,=36
	PUSHJ P,DTOCA			;TYPE IT IN DECIMAL
	MOVEI T,"-"
	PUSHJ P,DTOUT
	MOVEI T,=35
	SUBI T,(AC3)
	PUSHJ P,DTOCA
	MOVEI S,[ASCIZ / ARE /]
	PUSHJ P,ASCOUT
	MOVEI T,(TAC1)			;GET PIA
	PUSHJ P,OTOCA			;AND TYPE IT OUT
	MOVEI S,[ASCIZ / SHOULD BE /]
	PUSHJ P,ASCOUT
	MOVE TEM,[POINT 3,DCHKTB(TAC),26]
	MOVEI AC1,0			;REMEMBER VALUES SEEN
DCHEK4:	ILDB AC3,TEM			;GET AN ALLOWABLE PIA VALUE
	MOVEI AC2,1
	LSH AC2,(AC3)
	TROE AC1,(AC2)
	JRST DCHEK5			;ALREADY TYPED THIS VALUE
	MOVEI S,[ASCIZ / OR /]
	TLOE AC1,400000			;SKIP COMMA FIRST TIME
	PUSHJ P,ASCOUT
	MOVEI T,(AC3)
	PUSHJ P,OTOCA			;TYPE OUT PIA
DCHEK5:	TLNE TEM,770000
	JRST DCHEK4
	MOVEI S,[ASCIZ /
/]
	PUSHJ P,ASCOUT
DCHEK3:	AOBJN TAC,DCHEK1
	MOVEI S,[ASCIZ /DONE CHECKING
/]
	PUSHJ P,ASCOUT
	MOVSI 17,DCHKAC
	BLT 17,17
	JRST 2,@DCHECK

OTOCA:	SKIPA W1,[10]
DTOCA:	MOVEI W1,12
	MOVEM W1,DCKRAD
DKTOCA:	LSHC T,-43
	LSH W1,-1		;W1=T+1
	DIV T,DCKRAD
	HRLM W1,0(P)
	JUMPE T,DTOC2
	PUSHJ P,DKTOCA
DTOC2:	HLRZ T,0(P)
	ADDI T,"0"
	JRST DTOUT

DCKRAD:	10

;ENTRIES IN THE DCHKTB TABLE HAVE THE FOLLOWING FORMAT:
;LH:  LH OF BYTE POINTER TO A FIELD IN THE CONI THAT HAS A PIA
;RH:  BITS 18-24 CONTAIN THE 7 BIT DEVICE CODE
;     BITS 27-29, 30-32 AND 33-35 CONTAIN LEGAL PIA VALUES

DEFINE DCKLST <
	DCHKMC (APR,3,35,APRCHN,APRCHN,APRCHN)
	DCHKMC (MTR,3,35,APRCHN,APRCHN,APRCHN)
	DCHKMC (IOP,3,35,IOPCHN,IOPCHN,0)
	DCHKMC (LPT,3,35,LPTCHN,LPTCHN,0)
	DCHKMC (DTE0,3,35,DTECHN,DTECHN,DTECHN)
	DCHKMC (DC,3,35,DCTCHN,DCTCHN,0)
	DCHKMC (DTC,3,35,DTCCHN,DTCCHN,0)
	DCHKMC (MTC,3,35,MTCCHN,MTCCHN,0)
	DCHKMC (DCSA,3,35,SCNCHN,SCNCHN,SCNCHN)
	DCHKMC (DKB,3,35,SCNCHN,SCNCHN,SCNCHN)
	DCHKMC (DCA,3,35,SCNCHN,SCNCHN,SCNCHN)
	DCHKMC (VMI,3,35,0,0,0)
	DCHKMC (PK,3,35,PKCHN,PKCHN,PKCHN)
	DCHKMC (DIL,3,35,DILCHN,DILCHN,DILCHN)
	DCHKMC (IMP,3,35,IMPCHN,IMPCHN,0)		;OUTPUT
	DCHKMC (IMP,3,32,IMPCHN,IMPCHN,0)		;INPUT
	DCHKMC (IMP,3,29,IMPCHN,IMPCHN,0)		;INPUT END
	DCHKMC (DPY,3,35,DPYCHN,DPYCHN,0)
	DCHKMC (KBD,3,35,0,0,0)				;III KEYBOARD SCANNER
	DCHKMC (DSK,3,35,0,0,0)				;LIBRASCOPE DISK
	DCHKMC (ELF,3,32,ELFCHN,ELFCHN,0)		;ELF ERRORS
	DCHKMC (ELF,3,35,0,0,0)				;ELF DATA
	DCHKMC (PMP,3,35,D2CHN,DSKCHN,0)
	DCHKMC (DDD,3,35,DPYCHN,DPYCHN,0)
	DCHKMC (MPX,3,35,MPXCHN,MPXCHN,MPXCHN)
	DCHKMC (KIM,3,35,KIMCHN,KIMCHN,KIMCHN)
	DCHKMC (SIX,3,35,SIXCHN,SIXCHN,0)
	DCHKMC (SIX,3,29,SIXCHN,SIXCHN,SIXCHN)
>;END DEFINITION OF DCKLST

DEFINE DCHKMC (DEVICE,SIZE,BITPOS,PIA1,PIA2,PIA3) <
	POINT SIZE,<<DEVICE9>!(PIA1*100+PIA2*10+PIA3)>,BITPOS
>

DCHKTB:	DCKLST
NDCHK__.-DCHKTB

DEFINE DCHKMC (DEVICE,SIZE,BITPOS,PIA1,PIA2,PIA3) <
	SIXBIT /DEVICE/
>

DCHKNM:	DCKLST			;ASSEMBLE NAMES OF DEVICES

>;END IFE EDDT&21-21 CONDITIONAL (SEE TOP OF PAGE 9)

IFN EDDT&1,<

ASCOUT:	HRLI S,440700
ASCOU1:	ILDB T,S
	JUMPE T,CPOPJ
	PUSHJ P,DTOUT
	JRST ASCOU1

SIXOUT:	MOVEI T,0
	LSHC T,6
	JUMPE T,CPOPJ
	ADDI T,40
	PUSHJ P,DTOUT
	JRST SIXOUT

DTOUT:	CAIG T,4
	POPJ P,
XTKL:	PUSH P,0		;TRANSMIT CHARACTER IN T TO CTY
	MOVE 0,T
	PUSHJ P,DTEXX
	POP P,0
	POPJ P,

DTEXX:	PUSH P,T
	MOVE T,KEPTAD
	SETZM DTFLG(T)		;CLEAR COMMAND DONE FLAG
	MOVEM 0,DTCMD(T)	;STORE COMMAND WORD FOR 11
	CONO DTE0,DONG11	;RING 11'S DOORBELL
	SKIPN DTFLG(T)		;WAIT FOR RESPONSE
	JRST .-1
	MOVE 0,DTF11(T)		;RETURN 11'S REPONSE WORD
	SETZM DTFLG(T)
	POP P,T
	POPJ P,

>;END IFN EDDT&1

	SUBTTL	DDT - INITIALIZATION, MAIN LOOP - DDTA


CPOPJ2:	AOS (P)
CPOPJ1:	AOS (P)
CPOPJ:	POPJ P,


IFN FTDSWP,<
TMPTAC:	0
DDTP2:	MOVEM TAC,TMPTAC
	MOVE TAC,[POINT 7,[ASCIZ/SORRY, CAN'T GET DDT!
/]]
	JSR DDTTYPE
	MOVE TAC,TMPTAC
	HALT DDT

DDT:	SKIPP2			;ENTER HERE FOR SWAPPING VERSION OF DDT
	JRST	DDTP1
	SKIPE	INDDT
	SKIPN	KEEPIN
	HALT	DDT		;IF IT'S NOT IN CORE, P2 CAN'T GET IT.
DDTP1:	SKIPE	NOTDDT
	JRST	DDTP2
	JSR	SAVE
	JRST	DDTA		;NORMAL ENTRY
	JRST	DDTB		;DDT RESTARTING WITHOUT NORMAL EXIT
;MAKE SURE EVERYTHING WE NEED STAYS IN - LIT AND VAR XLISTED
	XLIST			;OMIT UNSIGHTLY HEAP.
	LIT
	VAR
	LIST
>;FTDSWP

;DDTA IS THE FIRST LOCATION THAT MAY BE SWAPPED OUT!!!!

IFE FTDSWP,<
DDT:	JSR SAVE			;SAVE ACS - NON SWAPPING VERSION OF DDT
>;FTDSWP

IFN EDDT&1,<
DDGVUS:					;GIVE FROM HERE ON TO USERS
IFN FTXCOR,<
LOC <<.-1>&777000>+1000			;NEXT PAGE BOUNDARY
>;FTXCOR
>;EDDT&1
^^DDTA:	PUSHJ P,REMOVB			;REMOVE BREAKPOINTS
DDTB:	PUSHJ P,CHKSYM			;SEE IF SYMBOL TABLE HAS MOVED

IFE EDDT,<	MOVE 	T,JOBOPC^	;CONTINUE THRU JOBOPC
		TLNE	T,10000		;USER MODE PC?
		JRST	DDTC		;NO. ICK!
		HRRZ	T,T		;PC ONLY
		CAIL	T,DDTBEG
		CAILE	T,DDTEND
		JRST	DDTD		;JOBOPC POINTS OUTSIDE OF DDT>

DDTC:	MOVEI	T,XEC1			;MAKE $P CALL DDT
DDTD:	HRRM	T,PROC0			;STUFF IT.
DD1:	TLZ	F,ROF			;CLOSE ANY OPEN REGISTER
	PUSHJ	P,CRF			;ANNOUNCE BY CRLF THAT WE ARE HERE.
DD1.5:	MOVE	T,[XWD SCHM,SCH]
	BLT	T,ODF			;LOAD ACS
	SKIPL	GETFLG			;OPEN A PROGRAM THE FIRST TIME AROUND.
	JRST	GETPGM			;RETURN TO RET OR DD2
DD2:	SETZM	PRNC			;PARENTHESES COUNT
	MOVEI	P,PS			;STACK POINTER
LIS:	MOVE	T,ESTU			;UNDEFINED SYMBOL POINTER
	MOVEM	T,ESTUT			;INIT UNDEFINED SYM ASSEM
	TDZ	F,[XWD 777777-ROF-STF,LF1+CF1+SBF+ITF+EQF+Q2F]
	SETZM	IOTFLG			;NOT AN IOT YET
LIS0:	TDZ	F,[XWD 777777-ROF-STF-FAF-SAF,NAF]
	SETZM	WRD
LIS1:	SETZM	FRASE
LIS2:	MOVEI	T,1
	MOVEM	T,FRASE1
	TLZ	F,MLF+DVF
L1:	TLZ	F,CF+CCF+SF+FPF		;TURN OFF CONTROL, SYL, PERIOD FLAG
	SETZM	SYL
L1RPR:	SETZM	SYM
	MOVEI T,6
	MOVEM T,TEMDDT		;INIT SYMBOL COUNTER
	MOVE T,[POINT 7,TXT]	;SET UP POINTER FOR OPEVAL
	MOVEM T,CHP
	SETZM DENDDT
	SETZM WRD2

L2:	PUSHJ	P,TIN		;PICK UP CHARACTER
	CAIL	T,"A"+40
	CAILE	T,"Z"+40
	SKIPA
	TRC	T,40		;CONVERT LOWER CASE TO UPPER CASE
	TLNE	F,CF		;SKIP UNLESS THIS CHARACTER FOLLOWS ALTMODE.
	JRST	L21		;ALTMODE PRECEDES THIS CHARACTER
	CAIG	T,"Z"		;Z
	CAIGE	T,"A"		;A
	JRST	.+2
	JRST	LET
L21:	MOVE	R,T
	CAILE	T,137		;CHARACTERS ABOVE LOWER CASE "Z" ARE ILLEGAL
	JRST	ERR
	IDIVI	R,3
	LDB	W,BDISP(R+1)
;EEK, GASP!  I THINK THE PRECEDENCE IS BUILT IN TO THE ADDRESSES OF THE THINGS
	CAIGE	W,MULT-DDT	;FIRST EVAL ROUTINE
	JRST	DDT(W)
	MOVE	T,SYL
	TLZN	F,LTF
	JRST	POWER
	MOVE	T,[XWD OPEVAL,EVAL]	;LOOKUP ROUTINES IN CORRECT ORDER
	SKIPN	WRD		;USE SYMBOL TABLE FIRST IF SOMETHING THERE
	MOVSS	T
	MOVEM	T,SAVE
	JRST	L213

L212:	HLRZS	T,SAVE		;TRY NEXT EVALUATION ROUTINE
	JUMPE	T,UND1		;NEITHER ONE
L213:	PUSHJ	P,(T)
	JRST	L212		;TRY NEXT ONE
L4:	TLZE	F,MF
	MOVN 	T,T		;MINUS FLAG WAS SEEN
	TLNN	F,SF
	CAIE	W,LPRN-DDT
	JRST	.+2
	JRST	LPRN		;LEFT PAREN SEEN
	EXCH	T,FRASE1
	TLNN	F,DVF
	IMULB	T,FRASE1
	TLZE	F,DVF
	IDIVB	T,FRASE1
	CAIGE	W,ASSEM-DDT
	JRST	DDT(W)		;MULTIPLY OR DIVIDE
	ADDB	T,FRASE
	CAIGE	W,SPACE-DDT
	JRST	DDT(W)		; + - @ ,
	ADD	T,WRD
	TLNE	F,TIF		;TRUNCATE INDICATOR FLAG
	HLL	T,WRD		;TRUNCATE
	MOVEM	T,WRD
	TLNN	F,QF
	MOVE	T,LWT
	SETZM	R
	MOVE	W1,ESTUT
	CAMN	W1,ESTU		;IF THERE ARE ANY UNDEFINED SYMBOLS IN
	JRST	L5		;THE CURRENT EXPRESSION, ANYTHING EXCEPT
	CAILE	W,CARR-DDT	;FURTHER EXPRESSION INPUT, OR DEPOSITING
	JRST	ERR		;  INTO MEMORY IS ILLEGAL
L5:	CAIG	W,RPRN-DDT
	JRST	DDT(W)
	SKIPE	PRNC
	JRST	ERR
	PUSHJ	P,DDT(W)
RET:	MOVEI	P,PS
	PUSHJ	P,LCT		;TYPE A TAB
	JRST	DD2

ERR:	MOVEI	W1,"?"
	JRST	WRONG1
UNDEF:	MOVEI	W1,"U"
	JRST	WRONG1
WRONG:	MOVE	W1,[ASCII /XXX/]
WRONG1:	MOVEI	P,PS
	PUSHJ	P,TEXT
	PUSHJ	P,LCT		;TYPE TAB
IFN EDDT&1,<	PUSHJ	P,LISTEN
		JFCL>
	JRST	DD2

NUM:	ANDI	T,17		;T HOLDS CHARACTER
	TLNE	F,CF+FPF
	JRST	NM1		;$ OR . SEEN
	MOVE	W,SYL
	LSH	W,3
	ADD	W,T
	MOVEM	W,SYL		;ACCUMULATE OCTAL VALUE
	MOVE	W,DENDDT
	IMULI	W,12		;CONVERT TO DECIMAL
	ADD	W,T
	MOVEM	W,DENDDT	;ACCUMULATE DECIMAL VALUE
LE1:	AOJA	T,LE1A

;FLUSH NEXT LINE, INSERT LABEL "DOLLAR" NEAR "CONTRO", IF YOU WANT $ TO BE ALTMODE
DOLLAR:	SKIPA	T,[46+101-13]	;RADIX 50 $.
PERC:	MOVEI	T,47+101-13	;PERCENT SIGN
LET:	TLC	F,SF+FPF	;EXPONENT IFF LTF'*FEF'*(T=105)*SF*FPF=1
	TLZN	F,LTF+FEF+SF+FPF
	CAIE	T,105		;E
	TLOA	F,LTF
	TLOA	F,FEF		;E SEEN AS EXPONENT
	JRST	LET1
	TLZN	F,MF		;MINUS FLAG?
	SKIPA	W1,SYL		;NOT MINUS
	MOVN	W1,SYL		;GOBBLE NEGATIVE VALUE
	MOVEM	W1,FSV		;SAVE FLOATING POINT VALUE.
	SETZM	DENDDT
LET1:	SUBI	T,101-13	;FORM RADIX 50 SYMBOL
LE1A:	TLO	F,SF+QF
LE2:	MOVE	W,SYM
	MOVEI	R,101-13(T)	;SET UP IN SIXBIT FOR OPEVAL
	IMULI	W,50		;CONVERT TO RADIX 50
	ADD	W,T
	SOSGE	TEMDDT		;IGNORE CHARACS AFTER 6
	JRST	L2		;GO IGNORE
	IDPB	R,CHP		;SAVE FOR OPEVAL
	MOVEM	W,SYM
	JRST	L2

NUM1:	EXCH	T,WRD2		;FORM NUMBER AFTER $
	IMULI	T,12
	ADDM	T,WRD2
	TRO	F,Q2F		;FLAG NUMBER SEEN AFTER ALTMODE
	JRST	L2

NM1:	TLNE	F,CF		;$ SEEN?
	JRST	NUM1		;YES. NOW NUMBER.
	MOVSI	R,204500	;FORM FLOATING POINT NUMBER.  R_10.0
	FMPRM	R,FHDTMP	;MULTIPLY THE DIVISOR BY 10.0
	FMPRM	R,FHTTMP	;MULTIPLY TOTAL ACCUMULATED NUMBER BY 10.0
	MOVSI	R,211000(T)	;UNNORMALIZED VALUE OF THIS DIGIT
	FADRB	R,FHTTMP	;ADD DIGIT TO TOTAL THUS FAR
	FDVR	R,FHDTMP	;DIVIDE BY APPROPRIATE POWER OF 10.0
	MOVEM	R,SYL		;STORE FLOATING VALUE
	AOJA	T,LE1A

POWER:	TLNN	F,FEF
	JRST	L4		;NO EXPONENT
	CAIE	W,PLUS
	CAIN	W,MINUS
	TROE	F,POWF
	TRZA	F,POWF
	JRST	(W)		; E+-

	MOVE	W2,DENDDT
	SETZM	FRASE
	MOVEI	W1,FT-1
	TLZE	F,MF
	MOVEI	W1,FT01
	SKIPA	T,FSV
POW2:	LSH	W2,-1
	TRZE	W2,1
	FMPR	T,(W1)
	JUMPE	W2,L4
	SOJA	W1,POW2

PERIOD:	MOVE	T,LLOC		;PERIOD ( . ) SEEN.  USUALLY THIS IS CURRENT LOCATION
	TLNE	F,SF		;BUT IF A SYLLABLE HAD BEEN STARTED IT MEANS
	MOVE	T,DENDDT	;DECIMAL OR FLOATING POINT
	MOVEM	T,SYL
	TLNE	F,FPF		;FLOATING POINT ON ALREADY?  I.E., ARE THERE 2 PERIODS?
	TLO	F,LTF		;TWO PERIODS.  THIS ONE IS A LETTER!
	TLON	F,FPF+SF+QF	;SET FLOATING POINT.  SKIP IF IN THE MIDDLE OF SYL
	MOVEI	T,0		;AT FRONT OF SYL. DO THE RIGHT THING FOR .69
	IDIVI	T,400		;FLOAT THE VALUE OF T (HOW?)
	SKIPE	T
	TLC	T,243000
	TLC	W1,233000
	FAD	T,[0]
	FAD	W1,[0]
	FADR	T,W1
	MOVEM	T,FHTTMP	;STORE FLOATING VALUE
	MOVSI	T,201400
	MOVEM	T,FHDTMP	;VALUE OF DIVISOR (10.0^<NUMBER OF DIGITS AFTER POINT>)
	MOVEI	T,45		;RADIX 50 PERIOD
	JRST	LE2

QUAN:	SKIPA	T,LWT		;LAST QUANTITY TYPED
PILOC:	MOVEI	T,SAVPI		;$I - PI STATUS
QUAN1:	MOVEM	T,SYL
QUAN2:	TLO	F,SF+QF		;WRD,SYL STARTED
	TLZ	F,CF+CCF
	JRST	L2

CONTRO:				;ALTMODE SEEN
IFN EDDT&1, <	MOVEI	T,"$"		
		PUSHJ	P,TOUT	;ECHO $  SINCE REAL ALTMODE DOESN'T ECHO>
;DOLLAR:			;INSERT LABEL TO TREAT $ AS ALTMODE.
	TLOE	F,CF
	TLO	F,CCF		;SET $$ FLAG IF CF WAS SET BEFORE
	JRST	L2

BEGIN UNDEF  SUBTTL	DDT - ASSEMBLY OF UNDEFINED SYMBOLS
	GLOBAL	F,P,R,S,T,W,W1,W2

;THESE ARE HERE BECAUSE SWAPPING DDT DOESN'T SAVE THE UNDEFINED SYMBOL TABLE
^ESTU:	0
^ESTUT:	0

^UND1:	MOVE	R,ESTUT		;UNDEFINED SYM ASSEMBLER
	HLRE	S,ESTUT
	ASH	S,-1		;SETUP EVAL END TEST
	HRLOI	W1,37777+DELI+LOCAL
	PUSHJ	P,EVAL2
	CAIN	W,ASSEM-DDT
	TLNN	F,ROF
	JRST	UNDEF
	SKIPE	PRNC
	JRST	UNDEF
	MOVEI	T,"#"
	CAIE	W,ASSEM-DDT
	PUSHJ	P,TOUT
	MOVN	R,[XWD 2,2]
	ADDB	R,ESTUT
	MOVE	T,SYM
	TLO	T,GLOBAL
	MOVEM	T,(R)
	HRRZ	T,LLOCO
	TLNE	F,MF
	TLO	T,400000
	MOVEM	T,1(R)
	MOVEI	T,0
	JRST	L4

; ? COMMAND - LIST UNDEFINED SYMBOLS

^QUESTN:PUSHJ	P,CRF		;START WITH CRLF
	MOVE	R,ESTU		;GET POINTER TO UNDEF SYMS
QUEST1:	JUMPGE	R,DD1		;JUMP IF ALL DONE.
	MOVE	T,(R)		;GET NEXT SYMBOL
	SKIPA	W1,ESTU		;
QUEST2:	ADD	W1,[XWD 2,2]	;ADVANCE
	CAME	T,(W1)		;ARE TWO SYMBOLS THE SAME?
	JRST	QUEST2		;NOPE.
	CAME	R,W1		;ARE WE UP TO OURSELVES YET?
	JRST	QUEST4		;NO. THEN WE'VE OUTPUT THIS SYMBOL ALREADY
	PUSHJ	P,SPT		;OUTPUT SYMBOL
	PUSHJ	P,CRF		;AND A CRLF
QUEST4:	ADD	R,[XWD 2,2]	;ADVANCE TO NEXT SYMBOL
	JRST	QUEST1


;KILL AN UNDEFINED SYMBOL
^UKILL:	MOVE	R,ESTU			;REMOVE UNDEFINED SYMS
	JUMPGE	R,UNDEF			;IF NO UNDEFINED SYMS THEN ARG IS UNDEF.
KILL2:	PUSHJ	P,EVAL0
	JRST	RET			;NONE LEFT.
	PUSHJ	P,REMUN			;REMOVE ONE UNDEFINED SYMBOL
	JRST	KILL2

REMUN:	MOVE	S,[XWD 2,2]		;REMOVE ONE UNDEFINED SYMBOL
	ADDB	S,ESTU
	MOVE	W,-2(S)			;MOVE LAST SYMBOL IN TABLE TO
	MOVEM	W,(R)			;CLOBBER THE SYMBOL THAT'S DELETED.
	MOVE	W,-1(S)
	MOVEM	W,1(R)
	POPJ	P,

^DUNDEF:				;DEFINE AN UNDEFINED SYMBOL
	MOVE	R,ESTU
DEF3:	JUMPGE	R,CPOPJ			;PATCH IN VALUE FOR UNDEF SYM ENTRY
	MOVE	T,SYM
	CAME	T,(R)
	JRST	DEF4
	MOVE	S,DEFV
	SKIPGE	1(R)
	MOVN	S,S
	PUSH	P,R
	MOVE	R,1(R)
	PUSHJ	P,FETCH
	JRST	ERR
	ADD	S,T
	HRRM	S,T
	PUSHJ	P,DEP
	POP	P,R
	PUSHJ	P,REMUN			;REMOVE THE NOW DEFINED SYMBOL
DEF4:	ADD	R,[XWD 2,2]		;ADVANCE TO NEXT SYMBOL
	JRST	DEF3

;REMOVED UNDEFINED SYMBOLS THAT WERE REFERENCED AT THIS ADDRESS
^REMAUN:MOVE	R,ESTU
	MOVEM	W1,ESTU
REMAU1:	JUMPGE	R,CPOPJ
	HRRZ	W,1(R)
	CAMN	R,LLOCO
	PUSHJ	P,REMUN
	ADD	R,[2,,2]
	JRST	REMAU1


;EVAL0 - CALLED FROM UNDEFINED SYMBOL KILL
;EVAL2 - CALLED FROM UNDEFINED SYMBOL ASSEMBLER

EVAL0:	HRLOI	W1,37777+DELI
	HLRE	S,@SYMP
	ASH	S,-1		;SETUP END TEST
	JRST	EVAL3

EVAL1:	ADD	R,[XWD 2,2]
EVAL2:	SKIPL	R
	MOVE	R,@SYMP
	AOJG	S,CPOPJ		;TRANSFER IF NO SYMBOL FOUND
EVAL3:	MOVE	T,(R)
	XOR	T,SYM
	TLNN	T,PNAME
	TLOA	W1,LOCAL
	TDNE	T,W1
	JRST	EVAL1
	TLNN	T,340000
	JRST	EVAL1
	MOVE	T,1(R)
	JRST	CPOPJ1		;FOUND SYMBOL, SKIP

BEND	UNDEF

	SUBTTL	DDT - SYMBOL MANIPULATION ROUTINE

;THIS SEQUENCE INITS SYM TABLE LOGIC
CHKSYM: HLRZ	T,ESTU		;0,,-NUMBER OF UNDEFINED SYMBOLS
	SUB	T,ESTU		;T_ NUMBER OF UNDEFINED,,-LAST ADDRESS OF UNDEFINEDS
	MOVE	W,@SYMP
	ADD	T,W		;IF THE TOP OF THE UNDEFINED SYM TAB DOES
	TRNE	T,-1		;NOT POINT TO BOTTOM OF REGULAR SYM TAB,THEN
	HRRZM	W,ESTU		;RE-INIT UNDEFINED SYM TABLE POINTER, ESTU.
	SKIPL	@SYMP		;SKIP IF THERE ARE REALLY SYMBOLS SOMEWHERE
	JRST	CHKSY1
	HRRZ	SMB,@SYMP	;BASE OF SYMBOLS (IF SORTED)
	HLLO	T,(SMB)		;GET FIRST WORD OF THE SYMBOL TABLE
	AOJE	T,SSCHK		;JUMP IF THIS IS NEW FORMAT.
CHKSY1:	MOVEI	SMB,0		;FLAG OLD MODE
	MOVE	T,PRGM
	SUB	T,W		;IF THE SYM TABLE PNTR AND THE PROGRAM
	TSC	T,T		;NAME (PRGM) PNTR DO NOT END UP IN THE
	MOVE	W1,PRGM		;SAME PLACE, OR THEY DO NOT BOTH START ON
	XOR	W1,W		;AN EVEN (OR BOTH ON ODD) LOCATION, OR
	TRNN	W1,1		;PRGM .GE. 0, THEN RE-INIT PRGM.
	JUMPE	T,CPOPJ		;RETURN NOW IF HAPPY
	SETZM	PRGM		;NEED NEW PROGRAM AND BLOCK NAME
	SETZM	BLOCK
	POPJ	P,

KILL:	TLNN	F,LTF			;$K - DELETE SYMBOLS
	JRST	ERR
	PUSHJ	P,EVAL
	JRST	UKILL			;SYMBOL WASN'T DEFINED.  KILL UNDEF SYMS.
	MOVEI	T,DELO/200000		;DELETE OUTPUT
	TLNE	F,CCF			;$$K TYPED?
	IORI	T,DELI/200000		;YES. DELETE BOTH INPUT AND OUTPUT
	JUMPG	SMB,SKILL		;JUMP IF SORTED SYMBOL TABLE.
	DPB	T,[POINT 2,(R),1]	;LEFT 2 BITS IN SYMBOL
	JRST	RET

TAG:	JUMPG	SMB,SRTAG		;HANDLE TAGS IN SORTED SYMBOL TABLE
	TLNN	F,LTF   		;NO LETTERS IS ERROR
	JRST	PNAMES 			;GO SAY ERROR (EXCEPT $: COMMAND)
	TLNE	F,FAF   		;DEFINE SYMBOLS
	JRST	DEFIN			;A<B:
	TLNE	F,CF			;DEFINE SYMBOL AS OPEN REGISTER
	JRST	SETNAM
	MOVE	W,LLOCO
	HRRZM	W,DEFV
DEFIN:	PUSHJ	P,EVAL			;NEW SYMBOL?
	JRST	DEF1			;YES.  ENTER IT.
	JRST	DEF2			;NO, REDEFINE

DEF1:	MOVN	R,[XWD 2,2]		;ADD NEW SYMBOL
	ADDB	R,@SYMP			;MOVE UNDEFINED TABLE 2 REGISTERS
	HRRZ	T,ESTU
	SUBI	T,2
	HRL	T,ESTU
	HRRM	T,ESTU
	SKIPGE	ESTU
	BLT	T,-1(R)
DEF2:	MOVE	T,DEFV
	MOVEM	T,1(R)			;PUT IN NEW VALUE
	MOVSI	T,GLOBAL
	IORB	T,SYM
	MOVEM	T,(R)			;PUT IN NEW SYM AS GLOBAL
	PUSHJ	P,DUNDEF		;DEFINE AN UNDEFINED SYMBOL
	JRST	RET


;$: - LIST NAMES OF PROGRAMS
PNAMES:	TLNN	F,CF			;$: COMMAND?
	JRST	ERR			;NO.  NO LETTERS AND : IS ERROR
	SYMTST
	PUSHJ	P,CRF			;START WITH CRLF
	MOVE	R,@SYMP			;GET POINTER TO SYMS
PPNAM1:	JUMPGE	R,DD1			;JUMP IF ALL DONE.
	SKIPE	T,(R)			;GET NEXT SYMBOL
	TLNE	T,740000		;TYPE BITS ARE ALL ZERO?
	JRST	PPNAM2			;NO
	PUSHJ	P,SPT1			;PRINT NAME
	PUSHJ	P,CRF
PPNAM2:	ADD	R,[XWD 2,2]		;ADVANCE TO NEXT SYMBOL
	JRST	PPNAM1


;FIND A PROGRAM NAME TO OPEN AUTOMATICALLY THE FIRST TIME DDT IS ENTERED.
GETPGM:	SETOM	GETFLG			;prevent coming back here.
	SYMTST
	JUMPG	SMB,SRGPGM		;DIFFERENT IF SORTED TABLE
	SKIPA	R,@SYMP
GETPG1:	ADD	R,[2,,2]		;ADVANCE TO NEXT SYMBOL NAME
	JUMPGE	R,DD2			;JUMP IF FAILURE.
	SKIPE	T,(R)
	TLNE	T,740000		;PROGRAM NAME?
	JRST	GETPG1
	CAME	T,[XTITLE]		;IGNORE OUR OWN PROGRAM NAME.
	CAMN	T,[RADIX50 0,JOBDAT]
	JRST	GETPG1			;IGNORE THE ONES THAT ARE ALWAYS THERE.
	PUSHJ	P,GETPG2		;SUBR TO PRINT THE PROGRAM NAME $ :
	JRST	SET2

GETPG2:	MOVEM	T,SYM
	PUSHJ	P,SPT1			; TYPE WHICH PROGRAM WE`VE OPENED.
	MOVEI	T,"$"
	PUSHJ	P,TOUT
	MOVEI	T,":"
	JRST	TOUT

;SET PROGRAM NAME  NAME$:
SETNAM:	SYMTST
	MOVE	R,@SYMP
SET1:	JUMPGE	R,UNDEF			;JUMP IF WE'VE RUN OUT.
	MOVE	T,(R)
	CAMN	T,SYM
	JRST	SET2			;FOUND ONE!
	ADD	R,[XWD 2,2]
	JRST	SET1			;ADVANCE AND LOOP

SET2:	MOVEM	R,PRGM			;STORE IOWD POINTER TO PROGRAM NAME.
	SETZM	BLOCK			;CLEAR BLOCK NAME
SET3:	CAMN	R,@SYMP			;OFF THE END YET?
	JRST	RET			;YES.
	SUB	R,[XWD 2,2]		;NO.  GET NEXT SYMBOL
	LDB	T,[POINT 4,(R),3]
	JUMPE	T,RET			;RETURN WHEN ANOTHER PROGRAM IS SEEN.
	CAIE	T,3
	JRST	SET3			;LOOP ON SYMBOLS.
	MOVE	T,(R)			;HERE'S A BLOCK NAME.
	XOR	T,SYM			;SEE IF THE BLOCK NAME MATCHES THE PROGRAM
	TLZ	T,740000		;TURN OFF MODE BITS
	JUMPN	T,SET3			;LOOP IF NO MATCH
	JRST	SBPRM			;BLOCK NAME = PROGRAM NAME.
					;STORE R AS CURRENT BLOCK POINTER.

;HERE WE HAVE BNAME$&	OPEN A BLOCK INSIDE CURRENT PROGRAM
;OR WE MAY HAVE BNAME&SNAME - OPEN BLOCK TEMPORARILY.

SETBLK:	JUMPG	SMB,SBLOCK		;JUMP IF NEW FORMAT SYMBOLS
	TLNN	F,LTF
	JRST	PBLKNS			;NO LETTERS. $& COMMAND PRINTS BLOCK NAMES
	SKIPL	R,PRGM			;PROGRAM OPEN YET?
	JRST	ERR			;NO.  ERROR.
	SYMTST
SB1:	CAMN	R,@SYMP			;DONE LOOKING?
	JRST	UNDEF			;YES. CAN'T FIND ONE.
	SUB	R,[XWD 2,2]		;ADVANCE TO NEXT ONE
	LDB	T,[POINT 4,(R),3]
	JUMPE	T,UNDEF			;IF WE REACH ANOTHER PROGRAM, WE'VE LOST
	CAIE	T,3
	JRST	SB1			;IGNORE SYMBOLS OTHER THAN BLOCK NAMES
	MOVE	T,(R)
	XOR	T,SYM
	TLZ	T,740000
	JUMPN	T,SB1			;DOESN'T MATCH.
	TLNE	F,CF			;WE HAVE ONE.  ALTMODE SEEN?
	JRST	SBPRM			;ALTMODE
	MOVEM	R,TBLK			;SET TEMPORARY BLOCK NAME
	JRST	L1RPR

SBPRM:	MOVEM	R,BLOCK			;SET IOWD POINTER TO BLOCK.
	JRST	RET


PBLKNS:	TLNN	F,CF			;$&
	JRST	ERR			;ERROR
	SYMTST
	PUSHJ	P,CRF			;START WITH CRLF
	SKIPGE	R,PRGM			;IS THERE A PROGRAM OPEN?
	CAMN	R,@SYMP
	JRST	DD1			;NO.  NOTHING TO TYPE.
PBLKN1:	SUB	R,[2,,2]
	SKIPN	(R)
	JRST	PBLKN2			;IGNORE ZERO SYMBOL NAMES
	LDB	T,[POINT 4,(R),3]	;GET TYPE BITS
	JUMPE	T,DD1			;EXIT IF WE SEE ANOTHER PROGRAM NAME
	CAIE	T,3			;BLOCK NAME SEEN?
	JRST	PBLKN2			;NO
	LDB	T,[POINT 32,(R),35]	;GET RADIX50 OF BLOCK NAME
	PUSHJ	P,SPT1			;PRINT NAME
	PUSHJ	P,CRF
PBLKN2:	CAMN	R,@SYMP			;AT END OF SYMBOL TABLE YET?
	JRST	DD1			;YES. THEN DONE.
	JRST	PBLKN1			;NO

SYMD:	MOVEI	T,DELO/200000		;$D - DELETE LAST SYM & PRINT NEW
	JUMPE	SMB,.+2			;JUMP UNLESS SORTED SYMBOLS
	PUSHJ	P,SSYMD			;SETUP R AND ALWAYS SKIP ONCE
	HRRZ	R,SPSAV			;PICK UP POINTER TO LAST SYM
	JUMPE	R,ERR			;NO LAST SYMBOL
	DPB	T,[POINT 2,(R),1]	;STORE SEMI-DELETE BITS IN SYMBOL
	MOVEI	T,11
	PUSHJ	P,TOUT
	MOVE	T,LWT			;GET VALUE PART
	PUSHJ	P,CONSYM		;PRINT OUT NEXT BEST SYMBOL
	JRST	RET

;	LOOK - VALUE TO SYMBOL

; SYMBOL TYPE BITS
; 40 - DELETE OUTPUT
; 20 - DELETE INPUT
; 14 - BLOCK TYPE
; 10 - LOCAL
; 04 - GLOBAL
; 00 - PROGRAM NAME


REPEAT 0,<
LOOK:	SKIPL R,PRGM	;LOOK UP SYMBOL
	MOVE R,@SYMP
	HLRE S,@SYMP
	ASH S,-1	;SETUP COUNT FOR LENGTH OF SYM TABLE
	TLZ F,400000
	HRLZI W2,DELO+DELI
	MOVEM T,TEMDDT

LOOK1:	TDNE W2,(R)
	JRST LOOK3
	MOVE T,(R)
	TLNN T,PNAME	;NAME
	TLOA W2,LOCAL
	SKIPA T,TEMDDT
	JRST LOOK3
	MOVE W,1(R)
	XOR W,T
	JUMPL W,LOOK3
	SUB T,1(R)
	JUMPL T,LOOK3
	JUMPGE F,LOOK2
	MOVE W,1(R)
	SUB W,1(W1)
	JUMPLE W,LOOK3
LOOK2:	HRR W1,R		;POINTER BEST VALUE SO FAR
	TLO F,400000
	JUMPE T,SPT0
LOOK3:	ADD R,[XWD 2,2]
	SKIPL R
	MOVE R, @SYMP
	AOJLE S,LOOK1	;TERMINATING CONDITION
	MOVE T,TEMDDT
	TLNE F,400000
	SUB T,1(W1)
	JRST CPOPJ1
>


;ENTER HERE WITH T CONTAINING A VALUE FOR WHICH A SYMBOL IS SOUGHT.
;IF A SYMBOL THAT MATCHES THE VALUE T EXACTLY IS FOUND, IT'S NAME WILL
;BE PRINTED AND THE DIRECT RETURN TAKEN.  IF NO EXACT MATCH IS FOUND,
;THE CLOSEST SYMBOL WHOSE VALUE HAS THE SAME SIGN AS C(T) AND IS SMALLER
;THAN C(T) WILL BE POINTED TO BY W1 AND THE SKIP RETURN TAKEN.
;IF NO MATCH AT ALL IS FOUND, DOUBLE SKIP RETURN.


LOOK:	SETZM	SVFB		;POINTER TO BLOCK WHERE MATCH WAS FOUND
	SETZM	SVTB		;POINTER TO CURRENT BLOCK.
	SETZM	BLVL		;BLOCK LEVEL
	SYMTST
	JUMPG	SMB,SLOOK	;JUMP IF USING SORTED SYMBOL TABLE
	HLRE	S,@SYMP		;-WC OF SYMBOL TABLE
	ASH	S,-1		;-NUMBER OF SYMBOLS
	TLZ	F,600000
	MOVEM	F,SVF		;INITIALZE SVF (USED FOR AVAILABLE SYMBOLS)
	MOVSI	W2,DELO+DELI	;IGNORE SYMBOLS WITH THESE BITS SET
	MOVEM	T,TEMDDT	;SAVE ARGUMENT
	SKIPL	R,PRGM		;IS THERE SOME PROGRAM OPEN?
	JRST	TOPDWD		;NO - SEARCH ENTIRE TABLE.
LOOK1:	SUB	R,[XWD 2,2]	;BACKUP TO NEXT SYMBOL (SKIPS PROGRAM NAME)
	TDNE	W2,(R)		;IS SYMBOL SUPPRESSED?
	JRST	LOOK3		;YES.  LOOK FOR ANOTHER SYMBOL.
	LDB	T,[POINT 4,(R),3]	;GET TYPE BITS
	CAIN	T,3		;TYPE 14 IS A BLOCK NAME
	JRST	BLNME
	JUMPE	T,PNAM		;TYPE 0 IS A PROGRAM NAME
	MOVE	T,TEMDDT	;GET ARGUMENT (VALUE SOUGHT)
	MOVE	W,1(R)		;GET VALUE PART OF THIS SYMBOL
	XOR	W,T
	JUMPL	W,LOOK3		;SIGN BITS DIFFER - THIS MATCH IS NO GOOD
	SUB	T,1(R)		;COMPUTE THE DIFFERENCE
	JUMPL	T,LOOK3		;JUMP IF SYMBOL IS TOO BIG
	JUMPGE	F,LOOK2		;JUMP IF NO PREVIOUS "GOOD" MATCH
	MOVE	W,1(R)		;GET VALUE AGAIN
	SUB	W,1(W1)		;COMPARE WITH PREVIOUS GOOD MATCH
	JUMPLE	W,LOOK3		;JUMP IF PREVIOUS GOOD MATCH WAS BETTER THAN THIS
LOOK2:	HRR	W1,R		;A "BETTER" MATCH HAS BEEN FOUND.
	TLO	F,400000	;FLAG THAT A MATCH EXISTS
	TLNE	F,200000	;IN THE CURRENTLY OPEN BLOCK OR IN A SUPERIOR?
	JRST	LOOK2A		;YES.  DON'T BOTHER REMEMBERING A BLOCK NAME
	MOVE	W,SVTB
	MOVEM	W,SVFB		;POINTER TO BLOCK WHERE WE FOUND THIS SYMBOL
LOOK2A:	TLNE	W2,LOCAL	;ARE WE SEEKING GLOBALS ONLY?
	SETZM	SVFB		;YES.  THEN WHAT WE FOUND HAS NO BLOCK NAME
	JUMPE	T,LOOK4		;JUMP IF EXACT MATCH
LOOK3:	CAMN	R,@SYMP		;AT END OF TABLE YET?
	JRST	TOPDWN		;YES. - SEARCH UNOPENED PROGRAMS NOW.
LOOK3A:	AOJLE	S,LOOK1		;WHILE WORDS ARE LEFT IN SYMTAB, LOOP.
	MOVE	T,TEMDDT	;GET ARGUMENT
	JUMPGE	F,CPOPJ2	;JUMP IF NO MATCH
	SUB	T,1(W1)		;CALCULATE THE DIFFERENCE
	JUMPE	T,SPT0		;IT WAS EXACT MATCH.  PRINT IT AND RETURN.
	JRST	CPOPJ1		;SINGLE SKIP RETURN - INEXACT MATCH

TOPDWD:	TLO	W2,LOCAL	;NO PROGRAM OPEN.  MATCH ONLY GLOBALS
TOPDWN:	HLRE	R,@SYMP		;- WC OF SYMBOL TABLE.
	MOVNS	R		;+WC
	ADD	R,@SYMP		;FOR -WC,,LAST ADDRESS+1
	JRST	LOOK3A
;NOTE THAT THE COUNT S, PREVENTS US FROM RESCANNING AREAS WE'VE SEEN BEFORE

;HERE WHEN A BLOCK NAME IS SEEN.
BLNME:	MOVEM	R,SVTB		;SAVE ADDRESS OF THE BLOCK NAME WE'VE SEEN
	MOVE	T,1(R)		;BLOCK LEVEL
	CAMN	R,BLOCK		;IS THIS THE CURRENTLY OPEN BLOCK?
	JRST	BLNM1		;YES. SET BLVL OF OPEN BLOCK
	CAML	T,BLVL		;IS THIS A SUPERIOR OF CURRENT BLOCK?
	JRST	BLNM2		;NO. NOT A SUPERIOR OF CURRENT BLOCK
BLNM1:	MOVEM	T,BLVL		;STORE CURRENT BLOCK LEVEL
	TLOE	F,200000	;WE ARE COMING INTO AN AVAILABLE BLOCK.  SET FLAG
	JRST	LOOK3		;WE WERE ALREADY IN AN AVAILABLE BLOCK.
	EXCH	F,SVF		;USE ALTERNATE VERSIONS OF F,W1
	EXCH	W1,SW1
	JRST	LOOK3

;ENTERING A BLOCK NOT AVAILABLE TO CURRENTLY OPEN BLOCK
BLNM2:	TLZN	F,200000	;WERE WE IN AN AVAILABLE BLOCK?
	JRST	LOOK3		;NO.
	EXCH	F,SVF		;YES,  PUT F AND W1 BACK WHERE WE CAN FIND THEM
	EXCH	W1,SW1		;   WHEN WE ENTER ANOTHER AVAILABLE BLOCK.
	JRST	LOOK3

;HERE IF WE SEE A PROGRAM NAME.  THIS MEANS THAT WE HAVEN'T FOUND AN EXACT
;MATCH IN THE CURRENTLY OPENED PROGRAM.  ANY FURTHER MATCHES CAN ONLY BE
;GLOBALS.

PNAM:	TLO	W2,LOCAL	;SET MASK TO SELECT GLOBALS ONLY.
	TLNN	F,200000	;WERE WE INSIDE AN AVAILABLE BLOCK?
	JRST	LOOK3		;NO.
	JUMPGE	F,LOOK5		;JUMP IF NO "GOOD" MATCHS FROM AVAILABLE BLOCKS
	MOVE	F,SVF		;GET FLAGS FROM UNAVAILABLE BLOCKS
	JUMPGE	F,PNAM2		;JUMP IF NO "GOOD" MATCHES FROM UNAVAILABLE BLOCKS
	MOVE	T,1(W1)		;GET VALUE OF MATCH FROM AVAILABLE BLOCKS.
	EXCH	W1,SW1		;GET POINTER FROM UNAVAILABLE BLOCK
	CAMGE	T,1(W1)		;WHICH IS BETTER? (LARGEST IS BEST)
	JRST	LOOK5A		;SYMBOL FROM UNAVAILABLE BLOCK IS BETTER
	MOVE	W1,SW1		;RE EXCHANGE,  W1_POINTER TO BEST VALUE
PNAM2:	SETZM	SVFB		;NOT IN ANY BLOCK NOW
	TLO	F,400000	;FLAG WE HAVE A GOOD VALUE
	TLZ	F,200000	;WE ARE NOT IN AN AVAILABLE BLOCK
	JRST	LOOK3

LOOK4:	TLZN	F,200000	;EXACT MATCH.  ARE WE IN AN AVAILABLE BLOCK?
	JRST	LOOK3		;NO.  KEEP LOOKING
	SETZM	SVFB		;CLEAR SAVED BLOCK NAME.
	JRST	SPT0		;GO PRINT SOMETHING

;NO GOOD MATCHES FROM AVAILABLE BLOCKS
LOOK5:	EXCH	F,SVF		;RESTORE F, W1
	EXCH	W1,SW1
LOOK5A:	MOVE	T,1(W1)		;SYMBOL FROM UNAVAILABLE BLOCK IS BETTER
	CAMN	T,TEMDDT
	JRST	SPT0		;EXACT MATCH - PRINT IT.
	TLZ	F,200000	;NO LONGER INSIDE AN AVAILABLE BLOCK
	JRST	LOOK3


;RADIX 50 SYMBOL PRINT
SPT0:	HRRZM	W1,SPSAV	;SAVE POINTER TO TYPED SYM
SPT:	MOVE	T,SVFB		;GET BLOCK NUMBER
	JUMPE	T,SPT1W		;NONE THERE
	CAMN	T,BLOCK		;SAME BLOCK AS THE ONE THAT'S OPEN?
	JRST	SPT1W		;YES.  DON'T TYPE BLOCK NAME
	PUSH	P,W1		;SAVE..
	JUMPE	SMB,SPT1X	;JUMP IF OLD FORMAT SYMBOLS
	ADD	T,1(SMB)	;POINTER TO BLOCK NAMES
	ADDI	T,(SMB)
SPT1X:	LDB	T,[POINT 32,(T),35]	;GET BLOCK NAME (AND NO TYPE BITS)
	PUSHJ	P,SPT1		;TYPE IT.
	MOVEI	T,"&"
	PUSHJ	P,TOUT		;TYPE AMPERSAND
	POP	P,W1
SPT1W:	LDB	T,[POINT 32,(W1),35]	;GET SYMBOL (NO TYPE BITS)
SPT1:	IDIVI	T,50
	HRLM	W1,0(P)
	JUMPE	T,SPT2
	PUSHJ	P,SPT1
SPT2:	HLRZ	T,0(P)
	JUMPE	T,CPOPJ		;FLUSH NULL CHARACTERS
	ADDI	T,260-1
	CAILE	T,271
	ADDI	T,301-272
	CAILE	T,332
	SUBI	T,334-244
	CAIN	T,243
SPT3:	MOVEI	T,256
	JRST	TOUT


;	EVAL - SYMBOL TO VALUE
;GIVEN A SYMBOL NAME IN SYM, RETURN ITS VALUE IN T AND ITS POINTER IN R AND SKIP.
;DIRECT RETURN IF SYMBOL UNDEFINED (IN CURRENT BLOCK AND ITS SUPERIORS)


;THIS IS THE WFW BLOCK STRUCTURE PATCH 
EVAL:	SYMTST
	MOVSI	W1,DELI		;DON'T MATCH KILLED SYMBOLS
	JUMPG	SMB,SEVAL	;USE SPECIAL EVAL IF SORTED.
	HLRE	S,@SYMP
	ASH	S,-1		;- NUMBER OF SYMBOLS IN TABLE
	SKIPL	R,TBLK		;TBLK IS SET BY FOO& (I.E., TEMPORARY BLOCK NAME)
	JRST	EVL1		;NO TEMP. BLOCK NAME SET
	SETZM	TBLK		;USE TEMP BLOCK NAME ONLY ONCE
EVL2:	MOVE	T,1(R)
	MOVEM	T,BLVL
	JRST	EV1

EVL1:	SKIPGE	R,BLOCK		;IS THERE AN OPEN BLOCK?
	JRST	EVL2		;YES. USE IT.
	MOVEI	T,1		;NO BLOCK OPEN. 
	MOVEM	T,BLVL		;SET BLOCK LEVEL TO 1
	SKIPGE	R,PRGM		;IS THERE A PROGRAM OPEN?
	JRST	EV1		;YES. USE IT
EV4:	HLRE	R,@SYMP
	MOVNS	R
	ADD	R,@SYMP		;R _ -WC,,LAST ADDRESS+2 - USE ENTIRE SYMBOL TABLE
	JRST	EV1		;(BUT ONLY MATCH GLOBALS SINCE FIRST THING WE'LL
				;  SEE IS A PROGRAM NAME)

EV3:	CAMN	R,@SYMP		;AT THE END OF PASS1?
	AOJL	S,EV4		;YES.  INITIATE PASS2  (SCAN REMAINDER)
	AOJGE	S,CPOPJ
EV1:	SUB	R,[XWD 2,2]	;ADVANCE
	MOVE	T,(R)		;GET SYMBOL NAME
	TDNE	T,W1		;FLUSHABLE?
	JRST	EV3		;YES.  GET NEXT
	LDB	T,[POINT 4,(R),3]	;GET TYPE BITS
	CAIN	T,3		;BLOCK?
	SOJA	S,EV2		;YES.  (BUGGER S, WILL BE UNBUGGERED LATER)
	SKIPN	T		;PROGRAM NAME
	TLOA	W1,LOCAL	;YES.  SET TO MATCH ONLY GLOBALS NOW
	SKIPA	T,(R)		;ORDINARY SYMBOL.  GET ITS VALUE
	JRST	EV3		;(FOR PROGRAMS, LOOP TO NEXT SYMBOL)
	XOR	T,SYM		;MATCH RADIX50 STUFF
	TLZ	T,740000	;FLUSH TYPE BITS
	JUMPN	T,EV3		;JUMP IF NO MATCH
	MOVE	T,1(R)		;RETURN VALUE IN T
	JRST	CPOPJ1

EV2B:	SUB	R,[2,,2]	;ADVANCE UNTIL WE GET ANOTHER BLOCK NAME
	LDB	T,[POINT 4,(R),3]
	CAIE	T,3
	AOJA	S,EV2B		;LOOP UNTIL A BLOCK NAME IS SEEN
EV2:	MOVE	T,1(R)		;HERE FOR A BLOCK NAME. GET ITS LEVEL
	CAML	T,BLVL		;DOES IT SURROUND THE BLOCK WE'RE IN?
	AOJA	S,EV2B		;NO. THIS IS NOT AN AVAILABLE BLOCK!
	MOVEM	T,BLVL		;STORE BLOCK LEVEL OF SURROUNDING BLOCK
	AOJA	S,EV3		;SCAN MORE.

BEGIN SYMSRT  	SUBTTL	DDT - SORTED SYMBOL TABLE MANIPULATIONS

	GLOBAL	F,P,R,S,T,W,W1,W2,SMB

LASSYM:	0
S.SYM:	BLOCK	3
X.SYM:	BLOCK	3
UNIQ:	0
UNIQP:	0
SYMRNG:	0
TXCT:	0
FFETCH:	0
FNDHI:	0
FNDLO:	0
C3FLG:	0			;SET FOR CLASS3 SYMBOLS IN FNDSYM.

;INITIALIZE PRGM AND BLOCK IF NEEDED.

^SSCHK:	SETOM	TBLK
	SKIPGE	T,PRGM			;IS PRGM SET NON-NEGATIVE?
	JRST	SSCHK1			;NO. INITIALIZE BOTH
	SKIPL	BLOCK			;BLOCK NEGATIVE?
	CAMGE	T,BLOCK			;NO.  THEN BLOCK MUST BE LARGER THAN PRGM
	SKIPA	R,T			;SO FAR, OK.
	JRST	SSCHK1			;SOMETHINGS SCREWED UP.
	ADD	T,1(SMB)
	ADDI	T,(SMB)
	MOVE	T,(T)
	TLNE	T,740000		;SKIP IF THIS IS A PROGRAM NAME.
	JRST	SSCHK1			;LOSE.
	SKIPGE	T,BLOCK			;IS THERE A BLOCK NAME?
	JRST	SSCHK2			;NO. THEN WE'RE DONE
	ADD	T,2(SMB)
	ADDI	T,(SMB)
	HLRZ	T,(T)			;GET POINTER TO THIS BLOCK'S PROGRAM
	CAME	T,PRGM			;BLOCK SHOULD POINT TO PROGRAM
	PUSHJ	P,SPRG3			;AND IT DOESN'T.  REFRESH IT.
	JRST	SSCHK2


SSCHK1:	SETOM	PRGM			;INITIALIZE PRGM AND BLOCK POINTER
	SETOM	BLOCK			;(ZEROS ARE LEGAL VALUES)
SSCHK2:	HRRZ	R,5(SMB)		;POINTER TO CLASS1
	HRRZ	S,11(SMB)		;POINTER TO END OF CLASS4
	SUBM	R,S			;-NUMBER OF WORDS OF SYMBOL-VALUE PAIRS
	HRL	R,S
	ADDI	R,(SMB)			;-COUNT,,ABSOLUTE ADDRESS OF FIRST
	MOVEM	R,SYMRNG		;SAVE IT FOR SEVAL
	POPJ	P,


;HERE WHEN : SEEN.
^SRTAG:	TLNN	F,LTF   		;NO LETTERS IS ERROR
	JRST	SPNAME 			;GO SAY ERROR (EXCEPT $: COMMAND)
	TLNE	F,FAF   		;DEFINE SYMBOLS
	JRST	SRDEF			;A<B:
	TLNE	F,CF			;ALTMODE?
	JRST	SPROG			;YES. OPEN PROGRAM'S SYMBOLS
	MOVE	W,LLOCO			;DEFINE SYMBOL AS OPEN REGISTER
	HRRZM	W,DEFV
SRDEF:	PUSHJ	P,EVAL			;EVALUATE THE SYMBOL THAT WAS NAMED.
	JRST	SRDEF1			;NEW SYMBOL
	PUSHJ	P,SYMDEL		;REDEFINITION.  DELETE OLD.
SRDEF1:	PUSHJ	P,SYMINS		;NOW, INSERT THE NEW DEININTION.
	MOVSI	T,GLOBAL
	IORM	T,SYM			;FIXUP SYM TO BE GLOBAL FOR DUNDEF.
	PUSHJ	P,DUNDEF		;USE NEW DEFINITION TO FIX UNDEFINED SYMS
	JRST	RET

;PRINT PROGRAM NAMES.
SPNAME:	TLNN	F,CF			;$: COMMAND?
	JRST	ERR			;NO.  NO LETTERS AND : IS ERROR
SPROG:	SYMTST				;ENTER HERE WITH LTF SET.
	HRRZ	W1,1(SMB)		;POINTER TO BLOCK NAMES AREA
	ADDI	W1,(SMB)		;DIRECT POINTER TO BN
	HRRZ	W2,2(SMB)		;POINTER TO BLOCK STRUCTURE AREA
	ADDI	W2,(SMB)		;DIRECT POINTER TO BS
	MOVSI	R,W1			;POINTER TO BN
	MOVSI	S,W2			;POINTER TO BS
	TLNE	F,LTF			;ARGUMENT GIVEN TO $: COMMAND?
	JRST	SPRG0			;YES. (NAME$: SEEN)
	PUSHJ	P,CRF			;START WITH CRLF
	CAMG	W2,W1
	JRST	DD1			;NO BLOCK ?
SPNAM1:	MOVE	T,@R			;GET A BLOCK NAME
	PUSH	P,W1
	PUSHJ	P,SPT1
	PUSHJ	P,CRF
	POP	P,W1
	SKIPN	T,@S			;GET LINK FORWARD TO NEXT BLOCK
	JRST	DD1			;DONE.
	HLR	R,T
	HLR	S,T
	JRST	SPNAM1			;LOOP

;SET PROGRAM NAME
SPRG0:	CAMG	W2,W1
	JRST	UNDEF			;NO BLOCK NAMES?
SPRG1:	MOVE	T,@R			;GET A BLOCK NAME
	CAMN	T,SYM			;MATCHES?
	JRST	SPRG2			;YES!
	SKIPN	T,@S			;GET LINK FORWARD TO NEXT BLOCK
	JRST	UNDEF			;UNDEFINED
	HLR	R,T
	HLR	S,T
	JRST	SPRG1			;LOOP

SPRG2:	HRRZM	R,PRGM			;SAVE PROGRAM NAME. (A NUMBER)
	PUSHJ	P,SPRG3			;SETUP INITIAL BLOCK NAME
	JRST	RET

;ROUTINE TO SETUP INITIAL BLOCK FROM OPEN PROGRAM.  CALLED FROM SPRG2 AND SSCHK
SPRG3:	HRL	R,R			;PROGRAM NUMBER IN BOTH HALVES
	SETOM	BLOCK			;INITIALLY NO BLOCK NAME
	SKIPN	T,@S			;GET LINK TO NEXT PROGRAM NAME
	JRST	SPRG4			;THERE IS NO NEXT (GET THE LAST!)
	HLR	S,T
	SUBI	S,1
	CAMN	R,@S			;IS THIS THE WORD WE WANT?
	HRRZM	S,BLOCK			;YES.
	POPJ	P,

SPRG4:	SUBM	W2,W1			;CALCULATE LAST ADDRESS
	HRRI	S,-1(W1)
	CAME	R,@S
	POPJ	P,
	HRRZ	S,S
	CAMLE	S,PRGM
	MOVEM	S,BLOCK
	POPJ	P,

;AUTOMATICALLY OPEN SYMBOL TABLE FOR SOME PROGRAM WHEN DDT IS FIRST STARTED
^SRGPGM:HRRZ	W1,1(SMB)		;POINTER TO BLOCK NAMES AREA
	ADDI	W1,(SMB)		;DIRECT POINTER TO BN
	HRRZ	W2,2(SMB)		;POINTER TO BLOCK STRUCTURE AREA
	ADDI	W2,(SMB)		;DIRECT POINTER TO BS
	MOVSI	R,W1			;POINTER TO BN
	MOVSI	S,W2			;POINTER TO BS
	CAMG	W2,W1
	JRST	DD1			;NO BLOCK NAMES?
SRGPG1:	MOVE	T,@R			;GET A BLOCK NAME
	CAME	T,[XTITLE]		;IGNORE OUR OWN PROGRAM NAME.
	CAMN	T,[RADIX50 0,JOBDAT]
	JRST	.+2
	JRST	SRGPG2			;GOT A GOOD ONE.
	SKIPN	T,@S			;GET LINK FORWARD TO NEXT BLOCK
	JRST	DD1			;DONE.  DIDN'T GET ANY WE LIKED.
	HLR	R,T
	HLR	S,T
	JRST	SRGPG1			;LOOP

SRGPG2:	PUSHJ	P,GETPG2		;STORE T IN SYM.  PRINT NAME$:
	TLO	F,LTF			;SET FLAG FOR SPROG
	JRST	SPROG			;SIMULATE NAME$:

;SET BLOCK NAME  & SEEN   (EITHER BNAME$&, BNAME&SNAME, OR $& COMMANDS)
^SBLOCK:SKIPGE	PRGM
	JRST	ERR		;ERROR IF NO PROGRAM OPEN
	SYMTST
	HRRZ	W1,1(SMB)	;POINTER TO BLOCK NAMES AREA
	ADDI	W1,1(SMB)	;POINTER TO BN+1
	ADD	W1,PRGM		;POINTER TO THE PROGRAM NAME +1
	HRRZ	W2,2(SMB)	;POINTER TO BS AREA
	ADDI	W2,(SMB)	;DIRECT POINTER TO IT.
	TLNN	F,LTF		;LETTER SEEN?
	JRST	SPBNS		;NO.  $& COMMAND PRINTS BLOCK NAMES
SBLK1:	CAMG	W2,W1		;WHEN WE GET TO THE END
	JRST	UNDEF		;IT'S TIME TO QUIT
	MOVE	T,(W1)		;GET RADIX50
	TLZN	T,740000	;SHOULD HAVE SOME TYPE BITS ON FOR A BNAME
	JRST	UNDEF		;THIS MUST BE THE NEXT PROGRAM NAME
	XOR	T,SYM		;COMPARE WITH SYMBOL GIVEN
	JUMPE	T,SBLK2		;JUMP IF WE'VE GOT ONE!
	AOJA	W1,SBLK1

SBLK2:	SUBI	W1,(SMB)
	SUB	W1,1(SMB)
	TLNN	F,CF		;WAS ALTMODE SEEN?
	JRST	SBLK3		;NO. SET TEMPORARY BLOCK NAME
	HRRZM	W1,BLOCK
	JRST	RET

SBLK3:	HRRZM	W1,TBLK		;SET TEMPORARY BLOCK NAME
	JRST	L1RPR

;PRINT BLOCK NAMES
SPBNS:	TLNN	F,CF		;$&
	JRST	ERR		;ERROR
	PUSHJ	P,CRF		;START WITH CRLF
SPBNS1:	CAMG	W2,W1		;WHEN WE GET TO THE END
	JRST	DD1		;IT'S TIME TO QUIT
	MOVE	T,(W1)		;GET RADIX50
	TLZN	T,740000	;SHOULD HAVE SOME TYPE BITS ON FOR A BNAME
	JRST	DD1		;THIS MUST BE THE NEXT PROGRAM NAME
	PUSH	P,W1
	PUSHJ	P,SPT1
	PUSHJ	P,CRF
	POP	P,W1
	AOJA	W1,SPBNS1

;	SKILL	SSYMD	SYMDEL	SYMINS

^SKILL:	MOVE	R,LASSYM		;$K AND $$K COMMANDS.
	DPB	T,[POINT 2,(R),1]	;LEFT 2 BITS IN SYMBOL
	TLNE	F,CCF			;WAS IT $$K ?
	PUSHJ	P,SYMDEL		;YES. EXPUNGE THE DEFINITION.
	JRST	RET

;SUBROUTINE FOR $D COMMAND
^SSYMD:	HRRZ	R,S.SYM+2		;HERE'S WHERE SEVAL PUT IT.
	JRST	CPOPJ1

;DELETE A SYMBOL.  ENTER HERE WITH R=POINTER TO SYMBOL. 
SYMDEL:	PUSHJ	P,GCLASS		;T_CLASS NUMBER (1 TO 4)
	CAIE	T,4			;CLASS 4 IS HARDER.
	JRST	SYMDL2			;NOT CLASS 4.
	MOVEI	W,@1(R)			;GET POINTER TO FULLV SPACE.
	HRLI	W,1(W)			;SOURCE,,DEST. OF DOWNWARDS BLT.
	SOS	S,4(SMB)		;DECREMENT FIRST FREE POINTER.
	ADDI	S,(SMB)			;ABSOLUTE POINTER TO FIRST FREE.
	CAILE	S,(W)			;SKIP BLT IF UNNECESSARY. (LAST C4 SYM)
	BLT	W,-1(S)			;MOVE SOME FULLVS DOWN.
	SETZM	(S)			;ZERO A NEW WORD OF FREE SPACE.
	MOVE	S,11(SMB)
	ADDI	S,-2(SMB)		;POINTER TO LAST CLASS4 SYMBOL
SYMDL1:	CAML	R,S			;ABOVE THE DELETED SYMBOL?
	JRST	SYMDL2			;NO. EVERYTHING'S BEEN FIXED.
	SOS	1(S)			;ADJUST A POINTER TO FULLV SPACE.
	SUBI	S,2
	JRST	SYMDL1			;LOOP THRU C4 SYMBOLS ABOVE DELETED SYM.

SYMDL2:	MOVE	S,5(SMB)		;POINTER TO FIRST C1 SYMBOL.
	ADDI	S,(SMB)			;ABS. POINTER TO FIRST C1 SYMBOL.
	MOVEI	W,(R)
	SUBI	W,(S)			;CALCULATE NUMBER OF WORDS TO MOVE.
	MOVSI	S,377777(W)		;CONTROL COUNT IN LH.
	HRRI	S,-1(R)			;LAST SOURCE WORD IN RH.
	JUMPLE	W,SYMDL3		;JUMP IF THERE'S NOTHING TO MOVE.
	POP	S,2(S)			;MOVE STUFF UPWARDS
	JUMPL	S,.-1			;LOOP
SYMDL3:	SETZM	2(S)			;CLEAR TWO WORDS THAT WERE VACATED.
	SETZM	1(S)
	MOVEI	S,2			;ADJUST CLASS POINTERS.
	MOVEI	R,5(SMB)		;C1 POINTER.
SYMDL4:	ADDM	S,(R)			;ADJUST CLASS POINTER.
	ADDI	R,1			;ADVANCE TO NEXT CLASS.
	SOJG	T,SYMDL4		;DECREMENT COUNT.  LOOP UNTIL DONE.
	MOVE	S,[2,,2]
	ADDM	S,SYMRNG		;ADJUST SYMRNG TO ACCOUNT FOR FEWER SYMS.
	POPJ	P,

;INSERT SYMBOL.  THE SYMBOL NAME IS IN SYM, VALUE IN DEFV.
SYMINS:	MOVE	T,DEFV			;GET THE VALUE
	PUSHJ	P,CCLASS		;GET THE CORRESPONDING CLASS NUMBER.
	MOVEI	T,2			;ASSUME WE NEED TWO WORDS FOR STORAGE.
	CAIN	R,4			;CLASS4?
	MOVEI	T,3			;FOR CLASS4 WE NEED THREE WORDS.
	MOVE	S,5(SMB)		;FIRST CLASS1 ADDRESS.
	SUB	S,4(SMB)		;FIRST FREE SPACE ADDRESS.
	CAIGE	S,(T)			;ENOUGH SPACE LEFT FOR DEFINITION?
	JRST	ERR			;NO ROOM.
	JRST	@.(R)			;SET UP FOR DIFFERENT CLASSES.
	SYMI1
	SYMI2
	SYMI3
	SYMI4

SYMI3:	MOVE	R,7(SMB)
	MOVE	S,10(SMB)
	MOVE	T,DEFV
	HLRZM	T,TEMDDT
	JRST	SYMI1B

SYMI2:	MOVE	R,6(SMB)
	MOVE	S,7(SMB)
	JRST	SYMI1A

SYMI1:	MOVE	R,5(SMB)
	MOVE	S,6(SMB)
SYMI1A:	MOVE	T,DEFV
	MOVEM	T,TEMDDT
SYMI1B:	ADDI	R,(SMB)
	ADDI	S,(SMB)
SYMI1C:	CAIG	S,(R)			;STILL ROOM LEFT?
	JRST	SYMI1D			;R POINTS TO FIRST LARGER SYMBOL
	HRRZ	W1,1(R)			;FETCH DATA
	CAML	W1,TEMDDT		;FOUND THE RIGHT PLACE YET?
	JRST	SYMI1D			;YES.  R POINTS TO LARGER SYMBOL
	ADDI	R,2
	JRST	SYMI1C

SYMI1D:	MOVE	S,5(SMB)		;ALL SYMBOLS BELOW R MUST MOVE DOWN.
	ADDI	S,(SMB)
	CAIL	S,(R)
	JRST	SYMI1E			;JUMP IF NO BLT NEEDED.
	HRLI	S,-2(S)
	MOVS	S,S
	BLT	S,-3(R)
SYMI1E:	MOVE	S,SYM
	TLO	S,GLOBAL
	MOVEM	S,-2(R)
	MOVE	S,TEMDDT
	HRRZM	S,-1(R)
	SKIPG	S,BLOCK			;IS BLOCK SET?
	SKIPL	S,PRGM			;NO. USE PRGM IF SET.
	DPB	S,[POINT 13,-1(R),12]	;STUFF BLOCK CODE INTO SYMBOL.
	MOVE	T,DEFV			;GET THE VALUE
	PUSHJ	P,CCLASS		;GET THE CORRESPONDING CLASS NUMBER.
SYMI5F:	MOVNI	S,2
	MOVEI	T,5(SMB)
SYMI1F:	ADDM	S,(T)
	ADDI	T,1
	SOJG	R,SYMI1F		;LOOP ADJUSTING CLASS ORIGINS
	MOVN	S,[2,,2]
	ADDM	S,SYMRNG		;UPDATE AOBJN POINTER FOR SEVAL.
	POPJ	P,

SYMI4:	MOVE	R,10(SMB)		;CLASS4
	MOVE	S,11(SMB)
	MOVE	T,DEFV
	MOVEM	T,TEMDDT
	ADDI	R,(SMB)
	ADDI	S,(SMB)
SYMI4C:	CAIG	S,(R)			;STILL ROOM LEFT?
	JRST	SYMI4D			;R POINTS TO FIRST LARGER SYMBOL
	MOVE	W1,@1(R)		;FETCH DATA
	CAML	W1,TEMDDT		;FOUND THE RIGHT PLACE YET?
	JRST	SYMI4D			;YES.  R POINTS TO LARGER SYMBOL
	ADDI	R,2
	JRST	SYMI4C

SYMI4D:	MOVE	S,5(SMB)		;ALL SYMBOLS BELOW R MUST MOVE DOWN.
	ADDI	S,(SMB)
	CAIL	S,(R)
	JRST	SYMI4E			;JUMP IF NO BLT NEEDED.
	HRLI	S,-2(S)
	MOVS	S,S
	BLT	S,-3(R)
SYMI4E:	MOVE	S,SYM
	TLO	S,GLOBAL
	MOVEM	S,-2(R)

	AOS	S,4(SMB)		;INCREMENT FREE POINTER
	ADDI	S,(SMB)			;GOBBLE A FREE LOCATION.
	MOVE	T,11(SMB)		;POINTER TO END OF EVERYTHING
	ADDI	T,-2(SMB)		;POINTER TO VERY LAST SYMBOL.
SYMI5A:	CAIGE	T,(R)			;IS THIS A BIG SYMBOL?
	JRST	SYMI5B			;NO.
	AOS	1(T)			;INCREMENT POINTER TO FREE SPACE
	MOVE	W1,-1(S)		;MOVE A FULLWORD VALUE UP.
	MOVEM	W1,(S)
	SUBI	T,2			;DECREMENT SYMBOL POINTERS
	SOJA	S,SYMI5A		;

SYMI5B:	MOVE	T,TEMDDT		;GET DATA
	MOVEM	T,(S)			;STUFF IT.
	SUBI	S,(SMB)			;CONVERT TO RELATIVE.
	HRLI	S,SMB			;SETUP INDEX FIELD
	SKIPG	T,BLOCK			;IS BLOCK SET?
	SKIPL	T,PRGM			;NO. USE PRGM IF SET.
	DPB	T,[POINT 13,S,12]	;STUFF BLOCK CODE INTO SYMBOL.
	MOVEM	S,-1(R)			;STUFF IN TABLE
	MOVEI	R,4			;CLASS 4
	JRST	SYMI5F			;FINISH IT.

;	SEVAL	CONVERT SYMBOLIC NAME TO VALUE

;GIVEN SYMBOL NAME IN SYM.
;DIRECT RETURN IF UNKNOWN, PRINTING "M" IF AMBIGUOUS (MULTIPLE).
;SKIP RETURN WITH R=DIRECT POINTER TO RADIX50, T= VALUE.


^SEVAL:	PUSH	P,BLOCK
	SKIPLE	T,TBLK			;ANY TEMP BLOCK SET?
	MOVEM	T,BLOCK			;YES.  USE IT.
	SETOM	TBLK			;BUT ONLY ONCE
	SKIPGE	R,SYMRNG
	PUSHJ	P,SEVAL0
	CAIA	
	AOS	-1(P)
	POP	P,BLOCK
	POPJ	P,

;ENTER HERE WITH R SETUP TO BE AOBJN POINTER TO SYMBOL PAIRS
SEVAL0:	SETZM	UNIQ			;POINTER TO A GLOBAL OR UNAVAILABLE LOCAL.
	SETZM	UNIQP			;POINTER TO BEST THING IN THE NEST SO FAR
	TLZ	F,600000		;INITIALIZE SOME FLAGS
SEVAL1:	MOVE	W2,(R)			;GET RADIX50 OF A SYMBOL
	TDNE	W2,W1			;SKIP UNLESS A REJECTED TYPE
	JRST	SEVAL2			;GET NEXT
	XOR	W2,SYM
	TLZ	W2,740000		;MASK OFF TYPE BITS
	JUMPN	W2,SEVAL2		;REJECT IF DIFFERENT
	MOVE	W2,(R)			;GET SYMBOL AGAIN.
	TLNE	W2,040000		;GLOBAL? 
	JRST	SEVL1A			;YES. IT'S GLOBAL.  SAVE POINTER TO IT.
	LDB	W2,[POINT 13,1(R),12]	;GET THE BLOCK NUMBER
	CAME	W2,PRGM			;SAME AS CURRENT PROGRAM?
	CAMN	W2,BLOCK		;OR SAME AS CURRENT BLOCK?
	JRST	SEVAL4			;YES. THIS IS THE VERY BEST.
	PUSHJ	P,WCHBLK		;SEE IF W2 IS IN PRESENT BLOCK NEST.
	JRST	SEVL1B			;NO. WRONG NEST OR WRONG PROGRAM!
	SKIPG	T,UNIQP			;WAS ANYTHING YET FOUND IN THE OPEN NEST?
	JRST	SEVL1C			;NO. WE NOW HAVE SOMETHING.
	LDB	T,[POINT 13,1(T),12]	;YES. GET BLOCK NUMBER OF PREVIOUS THING
	LDB	W2,[POINT 13,1(R),12]	;AND BN OF THIS ONE
	CAML	T,W2			;SKIP IF PREVIOUS B. CONATAINED IN THIS B.
SEVL1C:	HRRZM	R,UNIQP			;NEW ONE IS BETTER.  W2 .LT. T
	JRST	SEVAL2

SEVL1B:	SKIPGE	UNIQ			;IS THIS SET WITH A GLOBAL ALREADY?
	JRST	SEVAL2			;YES.  A GLOBAL IS A BETTER MATCH.
	SKIPE	UNIQ			;IS THIS SET WITH SOME UNAVAILABLE LOCAL
	TLOA	F,400000		;YES. THAT MEANS WE HAVE AT LEAST TWO
	HRRZM	R,UNIQ			;SAVE FIRST UNAVAILABLE LOCAL.
	JRST	SEVAL2

SEVL1A:	HRROM	R,UNIQ			;SAVE GLOBAL AS GLOBAL. 
SEVAL2:	ADD	R,[2,,2]
	JUMPL	R,SEVAL1
	SKIPG	R,UNIQP			;SKIP IF SYMBOL FOUND IN CURRENT NEST.
	SKIPGE	R,UNIQ			;NOT IN CURRENT NEST.  SKIP IF NOT GLOBAL
	JRST	SEVAL4			;GOOD MATCH!
	JUMPL	F,SEVAL3		;JUMP IF AMBIGUOUS OUTSIDE OF NEST
	JUMPN	R,SEVAL4		;JUMP IF UNAMBIGOUS MATCH OUTSIDE NEST.
	POPJ	P,			;NOBODY HOME.

SEVAL3:	MOVEI	T,"M"			;MULTIPLY DEFINED OUTSIDE OF NEST.
	JRST	TOUT			;"M" FOR MULTIPLE. CALLER MAY TYPE "U" ?

SEVAL4:	HRRZ	R,R
	HRRZM	R,LASSYM		;SAVE ABSOLUTE POINTER TO SYMBOL
	PUSHJ	P,REVAL			;T_ VALUE FROM POINTER IN R.
	JRST	CPOPJ1

;WCHBLK - CALL WITH W2 CONTAINING A BLOCK NUMBER.  SKIP RETURN IF
;W2 BELONGS TO CURRENTLY OPEN BLOCK NEST.  DIRECT RETURN OTHERWISE.
;CLOBBERS T.

WCHBLK:	SKIPGE	PRGM			;IS THERE A PROGRAM OPEN?
	POPJ	P,			;NO. THERE'S NOTHING IN CURRENT NEST!
	SKIPL	T,BLOCK			;IS THERE A BLOCK OPEN?
	JRST	WCHBL1			;YES.  FOLLOW IT UP THE TREE.
	CAMN	W2,PRGM			;NO BLOCK = NON-BS PRGM.
	AOS	(P)			;W2 MATCHES OPEN PRGM.
	POPJ	P,

WCHBL1:	CAMN	T,W2			;BLOCK INDICES MATCH?
	JRST	CPOPJ1			;YES.
	CAMN	T,PRGM			;BLOCK INDEX MATCHES PRGM?
	POPJ	P,			;YES, MEANING W2 ISN'T IN THE NEST.
	ADD	T,2(SMB)
	ADDI	T,(SMB)
	HRRZ	T,(T)			;GET LINK TO PARENT BLOCK
	JRST	WCHBL1			;AND LOOP.


;ABSOLUTE ADDRESS IN R, SMB SETUP.  RETURN CLASS NUMBER IN T
GCLASS:	MOVEI	T,4			;ASSUME CLASS 4
	SUBI	R,(SMB)			;MAKE RELATIVE.
	CAMGE	R,10(SMB)		;SKIP IF CLASS 4
	SUBI	T,1			;CLASS 3, 2 OR 1
	CAMGE	R,7(SMB)		;SKIP IF CLASS 3 OR 4
	SUBI	T,1			;CLASS 2 OR 1
	CAMGE	R,6(SMB)		;SKIP IF CLASS 2, 3, OR 4
	SUBI	T,1			;CLASS 1
	ADDI	R,(SMB)			;RESTORE TO ABSOLUTE
	POPJ	P,

;ABSOLUTE ADDRESS IN R.  RETURNS ABSOLUTE IN R, VALUE IN T.
REVAL:	PUSHJ	P,GCLASS		;CALCUALTE THE CLASS NUMBER
	XCT	REVAL0-1(T)		;DISPATCH TO THE CLASS EVALUATOR
	POPJ	P,

REVAL0:	HRRZ	T,1(R)
	HRRZ	T,1(R)
	HRLZ	T,1(R)
	MOVE	T,@1(R)

;	SLOOK	CONVERT VALUE TO SYMBOLIC

CCLASS:	JUMPL	T,CCLAS1	;VALUE IN T TO CLASS NUMBER IN R.
	MOVEI	R,1
	CAIG	T,377777
	POPJ	P,		;CLASS 1
	CAIG	T,777777
	AOJA	R,CPOPJ		;CLASS 2
CCLAS1:	MOVEI	R,3
	TRNE	T,777777
	MOVEI	R,4		;CLASS 4
	POPJ	P,


;ENTER HERE WITH T CONTAINING A VALUE FOR WHICH A SYMBOL IS SOUGHT.
;IF A SYMBOL THAT MATCHES THE VALUE T EXACTLY IS FOUND, IT'S NAME WILL
;BE PRINTED AND THE DIRECT RETURN TAKEN.  IF NO EXACT MATCH IS FOUND,
;THE CLOSEST SYMBOL WHOSE VALUE HAS THE SAME SIGN AS C(T) AND IS SMALLER
;THAN C(T) WILL BE POINTED TO BY W1 AND THE SKIP RETURN TAKEN (T WILL CONTAIN
;THE NUMERIC DIFFERENCE).  IF NO MATCH AT ALL IS FOUND, DOUBLE SKIP RETURN.
;W1 WILL POINT TO 3 WORDS AT S.SYM, BEING THE NAME, THE VALUE, AND THE SYMBOL
;TABLE (ABSOLUTE) ADDRESS OF THE SYMBOL ENTRY.

^SLOOK:	MOVEM	T,TEMDDT	;STORE VALUE SOUGHT.
	PUSHJ	P,CCLASS	;CALCULATE CLASS NUMBER
	JRST	@.(R)		;DISPATCH AS APPROPRIATE
	SLC1
	SLC2
	SLC34			;TRY CLASS 3 THEN, CLASS 4
	SLC43			;TRY CLASS 4, THEN CLASS 3

SLC2:	HRRZ	R,6(SMB)	;LOWER BOUND
	HRRZ	S,7(SMB)	;UPPER BOUND
	JRST	SLC1A

SLC1:	HRRZ	R,5(SMB)	;LOWER BOUND
	HRRZ	S,6(SMB)	;UPPER BOUND
SLC1A:	MOVE	T,[HRRZ W1,1(T)]
	MOVEM	T,FFETCH
	SETZM	C3FLG
	JRST	FNDSYM

SLC34:	PUSHJ	P,SLC3		;TRY 3 FIRST
	POPJ	P,		;WIN
	JRST	SLC34A		;STACK RESULT AND CALL SLC4.
	JRST	SLC4		;NOBODY HOME. JUST TRY CLASS 4

SLC34A:	MOVE	T,[S.SYM,,X.SYM]
	BLT	T,X.SYM+2	;SAVE RESULT.
	PUSHJ	P,SLC4		;TRY CLASS 4
	POPJ	P,		;THIS SHOULDN'T HAPPEN
	JRST	SLC34C		;COMPARE WITH PREVIOUS RESULT
SLC34B:	MOVE	T,[X.SYM,,S.SYM]
	BLT	T,S.SYM+2	;USE PREVIOUS RESULT.
SLC34D:	MOVE	T,TEMDDT
	SUB	T,S.SYM+1
	JRST	CPOPJ1

SLC34C:	MOVE	T,S.SYM+1
	CAMGE	T,X.SYM+1
	JRST	SLC34B		;USE OLD RESULT.
	JRST	SLC34D		;USE CURRENT RESULT.


SLC43:	PUSHJ	P,SLC4		;SEEK.
	POPJ	P,		;WIN.
	JRST	SLC43A		;STACK RESULT.
	JRST	SLC3		;LOSE. TRY CLASS 3

SLC43A:	MOVE	T,[S.SYM,,X.SYM]
	BLT	T,X.SYM+2	;SAVE RESULT.
	PUSHJ	P,SLC3
	POPJ	P,		;SHOULDN'T HAPPEN
	JRST	SLC34C		;GO COMPARE WITH SAVED RESULT.
	JRST	SLC34B		;USE SAVED RESULT.


SLC3:	HRRZ	R,7(SMB)	;LOWER BOUND
	HRRZ	S,10(SMB)	;UPPER BOUND
	MOVSS	TEMDDT
	SETOM	C3FLG
	MOVE	T,[HRRZ W1,1(T)]
	MOVEM	T,FFETCH
	PUSHJ	P,FNDSYM
	POPJ	P,		;SUCCESS.  SWAP TEMDDT AND RETURN.
	JRST	CPOPJ1
	JRST	CPOPJ2		;FAILURE.

SLC4:	HRRZ	R,10(SMB)	;LOWER BOUND
	HRRZ	S,11(SMB)	;UPPER BOUND
	MOVE	T,[MOVE W1,@1(T)]
	MOVEM	T,FFETCH
	SETZM	C3FLG
	PUSHJ	P,FNDSYM
	POPJ	P,
	JRST	CPOPJ1
	JRST	CPOPJ2


;ENTER HERE WITH R=LOWER BOUND, S=BEYOND UPPER BOUND,
;TEMDDT=VALUE SOUGHT (EXCEPT FOR CLASS3, WHERE IT IS SWAPPED)
;FFETCH=INSTRUCTION TO XCT TO GET DATA INTO W1, USING T AS DIRECT INDEX.
;DIRECT RETURN = WE PRINTED A NAME.
;1 SKIP = CLOSEST MATCH IS POINTED TO BY W1, T CONTAINS DIFFERENCE.
;2 SKIP = THERE IS NO CLOSEST MATCH.

FNDSYM:	SUBI	S,2		;ADJUST S TO POINT WITHIN RANGE.
	CAMLE	R,S		;COMPARE.
	JRST	FNDXT2		;HOPELESS.  RANGE IS EMPTY.
	ADDI	S,(SMB)
	ADDI	R,(SMB)
	MOVEI	T,(R)
	XCT	FFETCH		;FETCH DATA (LOWEST VALUE IN RANGE)
	CAMLE	W1,TEMDDT	;SKIP IF THERE'S SOME HOPE.
	JRST	FNDXT2		;NO WAY.  SMALLEST VALUE IS TOO LARGE.
	MOVEM	S,FNDHI		;SAVE ORIGINAL BOUNDS FOR LATER.
	MOVEM	R,FNDLO
	MOVEI	T,(S)
	XCT	FFETCH		;FETCH LARGEST VALUE
	CAMGE	W1,TEMDDT	;SKIP IF LARGEST VALUE INCLUDES SOUGHT VALUE.
	JRST	FNDSY3		;NO.  T POINTS TO LARGEST VAL. .LT. SOUGHT VALUE
	TRNN	R,1		;ODD OR EVEN?
	SKIPA	W1,[TRZA T,2]	;EVEN.
	MOVE	W1,[TRNN T,2]
	MOVEM	W1,TXCT		;INSTRUCTION TO ADJUST AVERAGE
FNDSY1:	MOVEI	T,(R)
	ADDI	T,(S)
	XCT	TXCT		;TEST RESULT
	SUBI	T,2		;  ADJUST IF NECESSARY.
	LSH	T,-1		;AVERAGE. (POINTS AT OR BELOW THE MIDDLE.)
	XCT	FFETCH		;FETCH DATA
	CAMN	W1,TEMDDT	;EXACT MATCH?
	JRST	FNDSY3		;YES!
	CAML	W1,TEMDDT	;MIDPOINT SMALL OR LARGE?
	JRST	FNDSY2		;LARGE - USE MIDPOINT AS HIGH BOUND.
	MOVEI	R,2(T)		;SMALL - USE MIDPOINT AS LOW BOUND.
	JRST	.+2
FNDSY2:	MOVEI	S,-2(T)		;USE MIDPOINT AS HIGH BOUND.
	CAMG	R,S
	JRST	FNDSY1		;UNTIL OVERLAP, LOOP.
	MOVEI	T,(S)		;MOVE POINTER TO T.
FNDSY3:	XCT	FFETCH		;T IS BEST POINTER.  EXPAND THE RANGE!
	MOVE	W2,W1		;SAVE BEST VALUE.
	MOVEI	S,(T)
FNDSY4:	MOVEI	R,(T)
	CAMG	R,FNDLO
	JRST	FNDSY5		;CAN'T MOVE DOWN ANYMORE.
	MOVEI	T,-2(R)
	XCT	FFETCH
	CAMN	W2,W1
	JRST	FNDSY4		;EXPAND NUMBER OF MATCHING SYMBOLS.
FNDSY5:	MOVEI	T,(S)
FNDSY6:	MOVEI	S,(T)
	CAML	S,FNDHI
	JRST	FNDSY7		;CAN'T MOVE UP ANY HIGHER.
	MOVEI	T,2(S)
	XCT	FFETCH
	CAMN	W2,W1
	JRST	FNDSY6
FNDSY7:	SETZM	UNIQ		;R AND S POINT TO GROUP OF EQUAL-VALUED SYMBOLS
	SETZM	UNIQP
FNDSY8:	CAMGE	S,R		;LOOK THRU ALL SYMBOLS OF SAME VALUE.
	JRST	FNDSYE		;DONE. 
	MOVE	W2,(S)
	TLNE	W2,DELO+DELI	;IGNORE SYMBOLS WITH THESE BITS SET
	JRST	FNDSY9		;SYMBOL WAS SUPPRESSED.  IGNORE IT.
	TLNE	W2,040000
	JRST	FNDSYA		;SYMBOL IS GLOBAL
	LDB	W2,[POINT 13,1(S),12]	;GET THE BLOCK NUMBER
	CAME	W2,PRGM			;SAME AS CURRENT PROGRAM?
	CAMN	W2,BLOCK		;OR SAME AS CURRENT BLOCK?
	JRST	FNDSYD			;YES. THIS IS THE VERY BEST.
	PUSHJ	P,WCHBLK		;SEE IF W2 IS IN PRESENT BLOCK NEST.
	JRST	FNDSYB			;NO. WRONG NEST OR WRONG PROGRAM!
	SKIPG	T,UNIQP			;WAS ANYTHING YET FOUND IN THE OPEN NEST?
	JRST	FNDSYC			;NO. WE NOW HAVE SOMETHING.
	LDB	T,[POINT 13,1(T),12]	;YES. GET BLOCK NUMBER OF PREVIOUS THING
	LDB	W2,[POINT 13,1(S),12]	;AND BN OF THIS ONE
	CAML	T,W2			;SKIP IF PREVIOUS B. CONATAINED IN THIS B.
FNDSYC:	HRRZM	S,UNIQP			;NEW ONE IS BETTER.  W2 .LT. T
	JRST	FNDSY9

FNDSYB:	SKIPN	UNIQ			;IS THIS SET ALREADY?
FNDSYA:	HRRZM	S,UNIQ			;SAVE FIRST UNAVAILABLE LOCAL, ANY GLOBAL
FNDSY9:	SUBI	S,2
	JRST	FNDSY8

FNDSYD:	HRRZM	S,UNIQP
FNDSYE:	SKIPN	T,UNIQP			;IS THERE ANYTHING IN CURRENT BLOCK NEST?
	SKIPE	T,UNIQ			;ANYWHERE ELSE?
	JRST	FNDSYF			;GOT ONE.
	MOVEI	T,(S)			;NO SYMBOLS OF BEST VALUE WERE PRINTABLE!
	CAML	T,FNDLO			;OFF THE END YET?
	JRST	FNDSY3			;NO. EXPAND NEW RANGE.
					;SHIT! ALL SYMBOLS WERE SUPPRESSED.
FNDXT2:	SKIPE	C3FLG
	MOVSS	TEMDDT			;UNSWAP.
	JRST	CPOPJ2	


FNDSYF:	SETZM	SVFB			;ASSUME NO BLOCK NAME NEEDED.
	SKIPE	UNIQP			;WAS SYMBOL FOUND IN CURRENT NEST?
	JRST	FNDSYG			;YES.  NO BLOCK NAME NEEDED.
	MOVE	W1,(T)
	TLNE	W1,040000		;GLOBAL?
	JRST	FNDSYG			;YES.  WE NEED NO BLOCK NAME.
	LDB	W1,[POINT 13,1(T),12]	;GET BLOCK NUMBER
	MOVEM	W1,SVFB			;SAVE IT WHERE IT WILL BE PRINTED.
	ADD	W1,1(SMB)		;GET THE BLOCK NAME
	ADDI	W1,(SMB)
	MOVE	W1,(W1)
	TLNN	W1,740000		;BLOCK OR PROGRAM NAME?
	JRST	FNDSYG			;PROGRAM NAME.
	MOVE	W1,SVFB			;GET BLOCK INDEX AGAIN.
	ADD	W1,2(SMB)
	ADDI	W1,(SMB)
	HLRZ	W1,(W1)			;GET POINTER BACK TO PROGRAM NAME.
	CAME	W1,PRGM			;SAME AS OPEN PROGRAM?
	MOVEM	W1,SVFB			;NO. OUTPUT PROGRAM NAME & SYMBOL NAME.

FNDSYG:	MOVEM	T,S.SYM+2		;SAVE DIRECT POINTER TO SYMBOL.
	XCT	FFETCH
	MOVEM	W1,S.SYM+1		;SAVE VALUE.
	SKIPN	C3FLG
	JRST	FNDSYH
	MOVSS	TEMDDT
	MOVSS	S.SYM+1
FNDSYH:	MOVE	W1,(T)
	MOVEM	W1,S.SYM		;SAVE SYMBOL NAME.
	MOVEI	W1,S.SYM		;POINTER TO NAME.
	MOVE	T,TEMDDT		;GET THE SOUGHT VALUE
	SUB	T,S.SYM+1		;MINUS THE SYMBOL WE FOUND.
	JUMPE	T,SPT0			;JUMP IF WE HAVE EXACT MATCH
	TLO	F,400000		;ANNOUNCE WE FOUND ONE.
	JRST	CPOPJ1

BEND SYMSRT

	SUBTTL	DDT - TEXT INPUT (ASCII AND SIXBIT)

;INPUT TEXT " SEEN.
;RECOGNIZED FORMS:
;	"<DELIM>TEXT<DELIM>	"/TEXT/		LEFT ADJUSTED ASCII INPUT
;	$"<DELIM>TEXT<DELIM>	$"/TEXT/	LEFT ADJUSTED SIXBIT INPUT
;	"CHR$			"A$		ONE RIGHT ADJUSTED ASCII CHR.
;	$"CHR$			$"A$		ONE RIGHT ADJUSTED SIXBIT CHR.
;	$$7"<DELIM>TEXT<DELIM>	$$7"/ABCDEFG/	LEFT ADJUSTED DELIMITED ASCIZ
;						  IN MULTIPLE WORDS
;	$$n"<DELIM>TEXT<DELIM>	$$6"/ABCDEFG/	LEFT ADJUSTED DELIMITED SIXBIT
;						  IN MULTIPLE WORDS - ENDS WITH
;						  A ZERO BYTE OR WORD.

TEXI:	PUSHJ	P,TEXIN		;GET FIRST CHARACTER TO T.
	MOVEM	T,SYL		;SAVE IT.
	MOVEI	W1,5		;ASSUME  ASCII
	MOVEI	T-1,0		;ACCUMULATE IT HERE
	PUSHJ	P,TEXIN		;GET SECOND CHARACTER.
	TLNE	F,CCF		;WAS IT $$" WE SAW?
	JRST	TEXI4		;YES - PERMIT ALTMODE AS FIRST CHR
	CAIE	T,33		;NOW, HAVE WE AN ALTMODE FOR THE SECOND CHR?
	JRST	TEXI5		;ASSEMBLE NORMALLY.
TEXI1A:	TLNN	F,CF		;ONE RIGHT ADJUSTED CHR.  SIXBIT REQUESTED?
	JRST	QUAN1		;NO.  SYL HAS RIGHT ADJUSTED ASCII
	MOVE	T,SYL
	TRZN	T,100		;TURN OFF 100 BIT
	TRZA	T,40		;100 BIT WAS OFF.  MAKE 40 BIT GO OFF.
	TRO	T,40		;100 BIT WAS ON.  COPY 100 BIT TO 40 BIT.
	ANDI	T,77
	MOVEM	T,SYL
	JRST	QUAN1

TEXI4:	MOVE	R,WRD2		;$$ TYPED.  GET NUMERIC ARG IF ANY.
	CAIE	R,7
	JRST	SIXBIN		;NOT $$7 - DO SIXBIT
	JRST	TEXI6

TEXI5:	TLNE	F,CF		;"<DELIM - NOW IN SYL><CHR NOW IN T>
	JRST	SIXBIN		;$" WAS TYPED.  DO IT FOR SIXBIT.
	SKIPA			;FIRST CHARACTER ALREADY IN T.
TEXI2:	PUSHJ	P,TEXIN
TEXI6:	CAMN	T,SYL
	SOJA	W1,TEXI3	;DELIMITER SEEN
	ROT	T,-7
	LSHC	T-1,7
	SOJG	W1,TEXI2	;LOOP ACCUMULATING TEXT
	TLNN	F,CCF		;END OF WORD.  $$ SEEN?
	JRST	TEXI2		;NO.  LOOP UNTIL WE GET A DELIMITER.
	LSHC	T-1,-43		;MOVE VALUE INTO T.
	PUSH	P,F
	TLZ	F,CF
	TLO	F,QF
	PUSHJ	P,DEPRA		;DEPOSIT
	POP	P,F
	AOS	LLOCO
	MOVEI	T-1,0		;AND PREPARE TO ASSEMBLE THE NEXT.
	MOVEI	W1,5
	JRST	TEXI2

TEXI3:	LSHC	T-1,-43
	JUMPL	W1,QUAN1	;DEPOSIT AFTER IT'S BEEN SHIFTED ENOUGH
	LSH	T,7
	SOJA	W1,.-2

; SIXBIT TEXT INPUT

SIXBI1:	PUSHJ	P,TEXIN    	;INPUT SIXBIT
SIXBIN:	CAMN	T,SYL
	JRST	SIXBI2		;DELIMITER SEEN
	CAIL	T,"A"+40
	CAILE	T,"Z"+40
	JRST	.+2
	SUBI	T,40		;LOWER CASE TO UPPER CASE.
	ANDI	T,77
	TRC	T,40
	ROT	T,-6
	LSHC	T-1,6
	SOJGE	W1,SIXBI1	;LOOP UNTIL FULL
	TLNN	F,CCF		;$$6" MODE?
	JRST	SIXBI1		;NO.  LOOP UNTIL DELIMITER SEEN
	MOVE	T,T-1
	PUSH	P,F
	TLZ	F,CF
	TLO	F,QF
	PUSHJ	P,DEPRA
	POP	P,F
	AOS	LLOCO
	MOVEI	T-1,0
	MOVEI	W1,5
	JRST	SIXBI1

SIXBI2:	MOVE	T,T-1
	JUMPL	W1,QUAN1
	LSH	T,6
	SOJA	W1,.-2

	SUBTTL	DDT - BYTE INPUT

;BYTE INPUT  $n%b1,b2,...,bn$
;IF n=0 THEN THE BYTE MASK, BMASK = $M+2, DEFINES THE BYTE SIZES.

BYTI:	TRZN	F,Q2F		;ALTMODE NUMBER TYPED?
	JRST	PERC		;NO. TREAT THIS AS A LETTER (PERCENT IN RADIX50)
	SETZM	SVBTI1		;ASSEMBLED WORD
	MOVEI	T,=36		;TOTAL NUMBER OF BITS
	MOVEM	T,SVBTI2
	MOVE	T+2,BMASK	;IN CASE OF "BYTE SIZE ZERO" - USING MASK
	MOVEI	T+1,BYTI1A	;ASSUME FIXED SIZE BYTES. - BYTE ASSEMBLY ROUTINE
	SKIPN	T,WRD2		;GET NUMBER OF BITS/BYTE
	SKIPA	T+1,[BYTIM4]	;USE BYTE MASK ASSEMBLY
	MOVEM	T,SVBTI		;SAVE BYTE SIZE
	MOVEM	T+1,SVBTID	;SET DISPATCH ADDRESS USED BY BYTI3
BYTI4:	PUSHJ	P,BYTI3		;INPUT A BYTE.  STORE BYTE.  SKIP IF TERMINATED
	JRST	BYTI4		;LOOP UNTIL A BYTE FOLLOWED BY ALTMODE IS SEEN
	MOVE	T,SVBTI1	;TERMINATES - GET WORD
	LSH	T,@SVBTI2	;SHIFT REST OF WAY
	JRST	QUAN1		;GO PUT IT AWAY

;BYTE DEPOSIT USING MASK.
BYTIM4:	SKIPG	SVBTI2		;ROOM FOR MORE?
	POPJ	P,		;NO, QUIT
	SETZM	SVBTI		;COUNT NUMBER OF BITS THIS POSITION
	SKIPL	T+2		;START WITH 1 BITS IN LEFT
	SETCA	T+2,0		;COMPLIMENT TO MAKE FIELD OF 1'S IN LEFT
BYTIM5:	LSH	T+2,1		;GET NEXT BIT
	ROT	T+1,-1		;MOVE ANOTHER BIT OF NUMBER TO LEFT END
	AOS	SVBTI		;SAVE COUNT
	SOSLE	SVBTI2		;CHECK TO SEE IF WORD FULL
	JUMPL	T+2,BYTIM5	;IS NEXT BIT PART OF SAME FIELD?
	MOVE	T,SVBTI1	;NO, GET WORD
	LSHC	T,@SVBTI	;SHIFT CORRECT NUMBER OF BITS
	MOVEM	T,SVBTI1	;AND SAVE AGAIN
	POPJ	P,		;RETURN

;BYTE DEPOSIT FOR FIXED SIZE BYTES.
BYTI1A:	MOVN	T+2,SVBTI	;GET SIZE
	ROT	T+1,(T+2)	;GET THAT MANY BITS INTO LEFT END
	MOVE	T,SVBTI1	;NOW THE PARTIALLY ASSEMBLED WORD
	MOVE	T+2,SVBTI	;SIZE
	CAMLE	T+2,SVBTI2	;MORE THAN WE NEED?
	MOVE	T+2,SVBTI2	;YES, TAKE SMALLER
	LSHC	T,(T+2)		;SHIFT BITS IN
	MOVEM	T,SVBTI1	;SAVE WORD
	MOVN	T+2,T+2		;UPDATE NUMBER OF BITS STILL NEEDED
	ADDM	T+2,SVBTI2
	POPJ	P,

;READ IN NUMBER.   CALL @SVBTID TO DEPOSIT.  SKIP RETURN WHEN TERMINATOR SEEN
BYTI3:	MOVEI	T+1,0	
BYTI3A:	PUSHJ	P,TEXIN		;NEXT CHR
	CAIN	T,33		;TERMINATOR?
	AOSA	(P)		;YES - SET SKIP RETURN FROM DEPOSIT ROUTINE
	CAIN	T,","		;SEPARATOR?
	JRST	@SVBTID		;CALL BYTE DEPOSIT ROUTINE.
	CAIL	T,"0"		;CHECK FOR DIGIT
	CAILE	T,"7"
	JRST	ERR
	IMULI	T+1,10
	ADDI	T+1,-"0"(T)
	JRST	BYTI3A

SVBTI:	0
SVBTI1:	0			;ASSEMBLED WORD
SVBTI2:	0
SVBTID:	0


	SUBTTL	DDT - MORE OF THE WORD ASSEMBLER
;CAUTION!!! THIS CODE MUST APPEAR AFTER THE SYMBOL TABLE STUFF!

MULT:	TLOA F,PTF+MLF		;*
DIVD:	TLO F,DVF+PTF		;SINGLE QUOTE
	JRST L1

ASSEM:	JRST PLUS		;#
MINUS:	TLO F,MF
PLUS:	TLO F,PTF
	JRST LIS2

LPRN:	CAML P,[XWD LPDL-4,0]	;LEFT PARENTHESIS
	JRST ERR
	PUSH P,F		;RECURSE FOR OPEN PAREN
	PUSH P,WRD
	PUSH P,FRASE
	PUSH P,FRASE1
	AOS PRNC
	JRST LIS

INDIRECT:	HRLZI W,20		;@
	IORB W,WRD
	TLO F,QF
	JRST LIS2

ACCF:	MOVE R,T		;COMMA
	TLOE F,COMF	;A COMMA SEEN, WAS IT SECOND?
	JRST ACCCF	;YES, GO PROCESS
	ADD T,WRD	;GET TOTAL
	HRRM T,ACCCF	;AND SAVE
	HLLZ T,R	;GET LEFT HALF BACK
	LSH R,27
	SKIPE IOTFLG	;IS THIS AN IOT?
	LSH R,1		;THEN SHIFT ONE MORE
	ADD T,R
	ADDB T,WRD
	JRST SPACE+1
ACCCF:	MOVSI T,0	;MODIFIED TO BE LEFT HALF ON ,,
	MOVEM T,WRD
	JRST SPACE+1	;AND GO

SPACE:	TLNE F,QF
	TLO F,TIF
SPAC1:	TLZ F,MF+PTF
	JRST LIS1

RPRN:	TLNN F,QF		;)
	MOVEI T,0
	MOVS T,T
	SOSGE PRNC
	JRST ERR
	POP P,FRASE1
	POP P,FRASE
	POP P,WRD
	POP P,F
	TLNE F,PTF
	TLNE F,SF
	JRST RPRN1
	MOVEM T,SYL
	TLO F,QF+SF
	JRST L1RPR
RPRN1:	ADDB T,WRD
	TLO F,QF
	JRST L1RPR-1

CRN:	MOVEI T,15		;CARRIAGE RETURN
	JRST TOUT

IFE EDDT&1,<
CRNRB:	PUSHJ P,CRN
	MOVEI T,177
	JRST TOUT	>

CRF:	PUSHJ P,CRN
	MOVEI T,12		;LINE FEED
	JRST TOUT

LCT:
IFN EDDT&1,<	PUSHJ	P,TSPC	;EXEC DDT TYPES THREE SPACES INSTEAD OF TAB
		PUSHJ	P,TSPC>	;FALL INTO TSPC
IFE EDDT&1,<	MOVEI	T,11
		JRST	TOUT>

TSPC:	MOVEI T,40		;SPACE
	JRST TOUT

	SUBTTL	DDT - REGISTER EXAMINATION LOGIC

LINEF:	PUSHJ	P,DEPRA		;NEXT REGISTER

IFE EDDT&1,<	PUSHJ	P,CRNRB
		JRST	.+2	>

LI0:	PUSHJ	P,CRF
	AOS	T,LLOC
LI1:	HRRZS	T
	HRRZM	T,LLOC
	HRRZM	T,LLOCO
	PUSHJ	P,PAD
	MOVEI	T,"/"
	TLNE	F,STF
	MOVEI	T,"!"
	PUSHJ	P,TOUT
LI2:	TLZ	F,ROF
	PUSHJ	P,LCT
	MOVE	R,LLOCO
	PUSHJ	P,FETCH
	JRST	ERR
	TLO	F,ROF
	TLNE	F,STF
	JRST	DD2
	JRST	CONSYM		;RETURN IS A POPJ

VARRW:	PUSHJ P,DEPRA		;^
	PUSHJ P,CRF
	SOS T,LLOC
	JRST LI1

IFN UEDDTS,<			;IN UEDDT, DOWN ARROW (CNTL A) MEANS 
				;CARRIAGE RETURN, PLUS WRITE ON L'SCOPE
DARRW:	MOVE R,LLOCO 		;PICK UP ADDRESS TO DEPOSIT
	PUSHJ P,DEPRA		;CLOSE REGISTER, ETC.
	JRST DD1		;RETURN TO MAIN LOOP

>;IFN UEDDTS

CARR:	PUSHJ P,DEPRA		;CLOSE REGISTER
	IFN EDDT&1,<JRST DD1>
	IFE EDDT&1,<JRST DD1.5>


OCON:	TROA F,LF1+CF1		;OPEN AS CONSTANT
OSYM:	TRZ F,CF1		;OPEN SYMBOLICALLY
	TROA F,LF1
SUPTYO:	TLOA F,STF		;SUPPRESS TYPEOUT
SLASH:	TLZ F,STF		;TYPE OUT REGISTER
	TLNN F,CF		;WAS $ USED?
	JRST SLAS2		;NO
	PUSHJ P,EFFECA		;TRY EFFECTIVE ADR
	JRST ERR		;WE LOST
SLAS2:	TLNN F,QF
	JRST SLAS1
	MOVE R,LLOC
	MOVEM R,SAVLOC	;SAVE FOR $CR ETC.
	HRRZM T,LLOC		;QUANTITY TYPED
SLAS1:	HRRZM T,LLOCO
	JRST LI2

ICON:	TLNN F,ROF	;REGISTER OPENED OR ERR
	JRST ERR
	PUSHJ P,DEPRS
	TLNN F,CF		;CHECK FOR ALTMODE
	JRST SLAS1
	PUSHJ P,EFFECA
	JRST ERR	;LOSE
	JRST SLAS1

;	LTAB, TAB, DEPRA, EQUAL, PSYM

LTAB:	MOVSS T		;SWAP HALVES FIRST
	CAIA		;DON'T DEPOSIT WITH SWAPPED HALVES
TAB:	PUSHJ P,DEPRS	;OPEN REGISTER OF Q
	TLNN F,CF
	JRST TAB1
	PUSHJ P,EFFECA
	JRST ERR
TAB1:	MOVEI T,-1(T)
	EXCH T,LLOC
	MOVEM T,SAVLOC		;AGAIN, SAVE IT
	HRROI T,700000
	PUSHJ P,TEXTT
	JRST LI0

DEPRA:	MOVE R,SAVLOC
	TLNE F,CF	;WAS THERE AN ALTMODE?
	EXCH R,LLOC	;RESTORE OLD LOC
	MOVEM R,SAVLOC	;AND SAVE THIS
	TLNE F,ROF		;REGISTER OPEN?
	TLNN F,QF		;YES. BEING CHANGED?
	JRST DEPRS		;NO.
	PUSHJ P,REMAUN		;REMOVE UNDEF SYMBOLS THAT WERE REFERENCED AT
	JRST DEPRS		;    THIS ADDRESS

EQUAL:	TLNE F,CF		;IF $=
	TRO F,EQF		;THEN REAL NUMERIC MODE
	TROA F,CF1		;= OUTPUT 1 REGISTER AS CONSTANT
PSYM:	TRZ F,CF1		;_ OUTPUT SYMBOLIC
	TRO F,LF1		;OUTPUT 1 REGISTER AS FORCED SYMBOLIC OR CONSTANT
	PUSHJ P,CONSYM
	JRST RET

R50PNT:	LSH T,-36	;RADIX 50 SYMBOL PRINTER
	TRZ T,3
	PUSHJ P,TOC
	PUSHJ P,TSPC
	SETZM SVFB	;NO BLOCK NAME
	MOVEI W1,LWT	;SETUP FOR SPT
	JRST SPT

SIXBP:	MOVNI W2,6		;SIXBIT PRINTER
	MOVE W1,LWT
SIXBP1:	MOVEI T,0
	ROTC T,6
	ADDI T,40
	PUSHJ P,TOUT
	AOJL W2,SIXBP1
	POPJ P,

	SUBTTL	DDT - OUTPUT MODE CONTROL SWITCHES, UEDDT - JOBSET

;SET JOB NUMBER TO EXAMINE
IFN UEDDTS,<

JOBSET:	TLZE F,QF		;QUANTITY TYPED BEFORE THE $?
	JRST JOBST2		;YES.
	SKIPL T,WRD2
	CAMLE T,400222		;LEGAL JOB NUMBER?
	JRST UNDEF		;NO
	JUMPG T,JOBST0
	SETOM EXMMAP		;EXAMINE EXEC VIA EXPGT
JOBST1:	SKIPA R,[37]		;THIS IS EXEC JOBREL
JOBST0:	MOVEI R,44		;THIS IS LOSER JOBREL
	MOVEM T,EXJOBN
	PUSHJ P,FETCH
	SETZ T,			;NOT FOUND
	MOVEM T,MEMSIZ		;THIS IS MAX LOC WE ARE LOOKING AT
	SKIPE EXJOBN		;FORCE SYSTEM SYMS IF LOOKING AT SYSTEM
	TLNN F,CCF		;DOES HE WANT USER'S SYMS?
	TDZA T,T		;NO
	SETO T,			;YES
	EXCH T,EXSYMS
	CAMN T,EXSYMS		;CHANGING MODE?
	JUMPE T,RET		;NO, IF STAYING WITH EXEC SYMS, NO RE-INIT
	PUSHJ P,COPSYM		;SETUP SYMBOLS!!!
	JRST DDTB		;FIXUP SYMS!

JOBST2:	MOVE T,SYL		;GET THE ARGUMENT - N$^E TYPED.
	MOVEM T,EXMMAP		;SAVE IT (POSITIVE DENOTES PAGE NUMBER TO EXAMINE)
	MOVEI T,0
	JRST JOBST1

>;IFN UEDDTS

TEXO:	MOVEI R,TEXTT-HLFW	;$T ASSUME 7 BIT ASCII
	MOVE T,WRD2
	CAIN T,6		;CHECK FOR $6T
	MOVEI R,SIXBP-HLFW	;SET MODE SWITCH FOR SIXBIT
	CAIN T,5		;CHECK FOR $5T
	MOVEI R,R50PNT-HLFW	;SET MODE SWITCH FOR RADIX 50
	CAIN T,11		;CHECK FOR $9T
	MOVEI R,TEXTT9-HLFW	;SET MODE SWITCH FOR 9 BIT ASCII
HWRDS:	ADDI R,HLFW-TFLOT	;H
SFLOT:	ADDI R,TFLOT-PIN	;F
SYMBOL:	ADDI R,PIN-TOCC		;S
CON:	ADDI R,TOCC-FTOC	;C
UCON:	ADDI R,FTOC		;U
	HRRZ SCH,R
	JRST BASE1

RELA:	TRZE F,Q2F		;CHANGE ADDRESS MODE TO RELATIE
	JRST BASECH
	MOVEI R,PADSO-TOC
ABSA:	ADDI R,TOC		;A
	HRRZ AR,R
	JRST BASE1

BASECH:	MOVE T,WRD2		;$NR  CHANGE OUTPUT RADIX TO N, N>1
	CAIGE T,2
	JRST ERR
	HRRZ ODF,T
BASE1:	MOVS S,[XWD SCHM,SCH]
	TLNN F,CCF
	JRST LIS1
	BLT S,ODFM	;WITH $$, MAKE MODES PERMANENT
	JRST RET

SEMIC:	MOVEM T,LWT		;SEMICOLON TYPES IN CURRENT MODE
	JRST (SCH)

	SUBTTL	DDT - GO, EXECUTE, AND BREAKPOINT LOGIC

STR:	HRLI	T,254000	;$G.  LOAD JRST INSTRUCTION
	TLOE	F,QF		;WAS THERE AN ARGUMENT?
	JRST	STR1		;YES. USE IT.
IFN EDDT&1,<	HRR T,STARTA>	;LOAD TAPE START ADDRESS
IFE EDDT&1,<	HRR T,JOBSA>	;GET STARTING ADDRESS
	TRNN	T,-1		;WAS THERE ANY REASONABLE ARGUMENT FOUND?
	JRST	ERR		;NO.  DO NOTHING.
	JRST	XEC0		;EXECUTE THE JRST

STR1:	TLNE	F,CCF		;<ARG>$$G?
IFN EDDT&1,<	HRRM T,STARTA>	;YES.  STORE START ADDRESS
IFE EDDT&1,<	HRRM T,JOBSA>	;YES.  STORE START ADDRESS
	JRST	XEC0

XEC:	TLNE	F,QF		;NO ARG
	TLNN	T,777000	;OR ARG NOT INSTRUCTION
	JRST	$X		; =>SINGLE STEP
	JRST	XEC0


BREAKA:	PUSHJ	P,REMOVB	;REMOVE BREAKPOINTS
BREAKB:	PUSHJ	P,CHKSYM	;RESET PRGM AND BLOCK IF SYMBOLS MOVED
	SOS	T,BCOM3
	HRRZS	T		;GET ADDR OF BREAKPOINT JUST HIT
	SUBI	T,B1ADR-4
	IDIVI	T,4
	HRRM	T,BREAK2	;WE WANT IT LATER
	MOVE	W1,BRKNAM-1(T)	;GET THE RIGHT JUNK
	PUSHJ	P,TEXT2		;AND PRINT
;<<<<<<< THESE BALANCE THE >'S IN THE NEXT FEW LINES
	MOVSI	W1,(<ASCIZ />/>)	;TYPE > FOR COND BREAK
	SKIPG	@BCOM2		;TEST PROCEED COUNTER
	MOVSI	W1,(<ASCIZ />>/>)	;TYPE >> FOR PROCEED COUNTER BREAK
	PUSHJ	P,TEXT2
	MOVE	T,BCOM
	HLLM	T,SAVPI		;SAVE PROCESSOR FLAGS
	MOVEI	T,-1(T)
	PUSHJ	P,PAD		;TYPE PC AT BREAK
	HRRZ	T,@BCOM3
	HRRM	T,PROC0		;SETUP ADDRESS OF BREAK
	HLRZ	T,@BCOM3
	JUMPE	T,BREAK1	;TEST FOR REGISTER TO EXAMINE
	PUSHJ	P,LCT		;PRINT TAB
	HLRZ	T,@BCOM3
	PUSHJ	P,LI1		;EXAMINE REGISTER C($NB)LEFT
BREAK1:	MOVSI	S,400000
BREAK2:	ROT	S,0		;WILL BE MODIFIED WITH BREAK NUM
	PUSHJ	P,LISTEN	;DONT PROCEED IF TTY KEY HIT
	TDNN	S,AUTOPI	;DONT PROCEED IF NOT AUTOMATIC
	JRST	RETB		;TAKE A BREAK
	MOVEI	T,2		;COMPENSATE FOR SOS INSTRUCTION
	ADDB	T,@BCOM2
	JUMPL	T,PROCD1	;GO IF STILL LESS THAN
	ANDCAM	S,AUTOPI	;TURN OFF AUTOPI
RETB:	HRRZ	T,BCOM2		;BREAK.  SET UP TEXT STRING FROM BNSTR
	SKIPE	T,1(T)		;IS THERE A POINTER TO A STRING?
	HRLI	T,(<POINT 7,0>)	;YES. MAKE IT A BYTE POINTER
	MOVEM	T,STRING	;STUFF IT WHERE THE TTY READER WILL SEE IT
	JRST	RET

RADIX =10
BRKNAM:	FOR @% I_1,NBP
<	ASCII /$%I%B/
>
RADIX =8

PROCEDE:TLNE	F,QF		;N$P	;PROCEED AT A BREAKPOINT
	JRST	PROC3		;QUANTITY TYPED
	MOVEI	T,1		;IF NO QUANTITY TYPED, USE 1
	TLNE	F,CCF		;IF $$P
	MOVSI	T,200000	;THEN VERY LARGE COUNT
PROC3:	TLNE	F,CCF		;AUTO PROCEDE?
	MOVNS	T		;NEGATE
	MOVEM	T,@BCOM2	;STORE PROCEDE COUNTER
	HRRZ	R,BCOM3
	PUSHJ	P,AUTOP
PROCD1:	PUSHJ	P,CRF
	PUSHJ	P,TTYLEV
PROC0:	HRRZI	R,XEC1		;* MODIFIED TO ADDR OF BREAKPOINT
	PUSHJ	P,FETCH
	JRST	BPLUP1		;ONLY GET HERE IF MEMORY SHRANK
	MOVEM	T,LEAV
	PUSHJ	P,INSRTB
	JRST	PROC2

PROC2:	MOVEI	W,100
	MOVEM	W,TEM1		;SETUP MAX LOOP COUNT
	JRST	IXCT5

SUBTTL	SINGLE STEP CODE FROM DEC

COMMENT	\

	The following code is nearly identical with that distributed
by DEC

$X works as follows:
	$X executes a single instruction then increments the PC.
	   Operands of the instruction are printed out as they exist
	   after the instructions execution.
	  An extra linfeed indicates a skip or jump.  Finally, the
	  instruction now pointed at is printed in symbolic form.
	n$X does $X n times.
	$$X does $X until PC reaches its original state +1 or +2
	  without  printing anything.
	n$$X does n$X but only prints for the nth instruction

\


; Flags indicating things to print:

	FAC__1			; 1 AC
	DFAC__2			; 2 ACs
	FLG__4			; Flags.
	IMM__10			; Instruction is immediate mode.
	EA__20			; Memory referencing.
	DEA__40			; References 2 memory locs.
	FLA__100		; Floating AC used
	FLE__200		; Floating  memory used. 
	PFLG__400		; on  PUSHx or POPx

$X:	TLNN	F,QF		; Any arg from the user ?
	JRST	.+3		; No.
	MOVEM	T,XTEM		; XTEM holds repetition count or
				;is negative for $$x without an arg.
	JUMPG	T,$X00
	HRRZ	T,PROC0
	MOVEM	T,LOCSAV
	SETOM	XTEM
	TLNN	F,CCF		; CCF on  $$ typed
	MOVNS	XTEM
$X00:	PUSHJ	P,CRF		; Give 'em a CRLF to start
$X01:	SOSN	XTEM		; Decrement & test counter
	TLZ	F,CCF		; Zap $$ flag to signal last iteration.
	TLZ	F,QF!CF!STF
	MOVEM	F,FLAGS		; Save flags since we wipe them out
	MOVEI	T,100		; Set max XCT depth
	MOVEM	T,XCTS
	HRRZ	R,PROC0		; RH(PROC0)=Adr of current instruction
	CAIN	R,XEC1		; Cant trace ourselves!
	JRST	ERR
	SKIPL	XTEM
	MOVEM	R,LOCSAV	; Save loc unless $$X
$X02:	PUSHJ	P,FETCH		; Get the instruction
	  JRST	ERR
$X03:	MOVEM	T,I.NST
	JSR	SWAP		; EXCH our ACs with the user's ACs
	MOVEM	T,SAV0
	MOVEI	T,@I.NST
	DPB	T,[POINT 23,I.NST,35]	; Store effective address
	HRRZM	T,I.NSTEA
	MOVE	T,SAV0
	JSR	SWAP		; Make us ourselves again.
	LDB	W1,[POINT 4,I.NST,12]; AC field.
	MOVEM	W1,I.NSTAC
	MOVSI	T,777000
	AND	T,I.NST
	HLRZ	F,T
	CAMLE	T,$XTBL(T)
	AOJA	T,.-1
	JRST	@$XTBL(T)


comment *
	Opcode dispatch table:
	   LH of entry contains largest opcode covered by that entry.
	   RH of entry contains address of routine to dispatch to.

	*

OPDEF	KAFIX	[247B8]	;STANFORD KA10 (AND 166) FIX INSTRUCTION

$XTBL:	SETZB	SET	; 400-403  SETZx
	ORCBB	CHECKI	; 404-473  All logical except SETx
	SETOB	SET	; 474-477  SETOx
	HLRES	CHEKIS	; 500-577  Hxxxx
	TSON	TESTS	; 600-677  Txxx
	777000,,IOTS	; 700-777  I/O
	0,,ERR		; 000
	037000,,USRUUO	; 001-037  LUUOS
	CALL	MONUAE	; 040      CALL
	INIT	MONINI	; 041      INIT
	CALLI	MONUAI	; 042-047  CALLI, SPCWAR, undefined
	TTCALL	MONUE	; 050-051  OPEN,TTCALL
	054000,,MONUAI	; 052-054  Undefined
	OUT	MONUE	; 055-057  RENAME,IN,OUT
	STATO	MONUI	; 060-061  SETSTS,STATO
	GETSTS	MONUE	; 062      GETSTS
	OUTBUF	MONUI	; 063-065  STATZ,INBUF,OUTBUF
	OUTPUT	MONUE	; 066-067  INPUT,OUTPUT
	USETO	MONUI	; 070-075  CLOSE,RELEAS,MTAPE,UGETF,USETI,USETO
	ENTER	MONUE	; 076-077  LOOKUP,ENTER
	104000,,SETI	; 100-104  Undefined
	ADJSP	SETEA	; 105	   ADJSP (KL-10)
	107000,,SETI	; 106-107  Undefined
	DFDV	DFLT	; 110-113  DFAB,DFSB,DFMP,DFDV (KL-10)
	DDIV	DINT	; 114-117  DADD,DSUB,DMUL,DDIV (KL-10)
	DMOVN	DINT	; 120-121  DMOVE,DMOVN
	KIFIX	SETEA	; 122	   FIX
	EXTEND	IEXTND	; 123	   EXTEND (KL-10)
	DMOVNM	DINT	; 124-125  DMOVEM,DMOVNM
	FLTR	SETEA	; 126-127  FIXR,FLTR
	UFA	IUFA	; 130      UFA
	DFN	IDFN	; 131      DFN
	FSC	IFSC	; 132      FSC
	IBP	SKP 	; 133      IBP [or ADJBP (KL-10)]
	DPB	SETEA	; 134-137  xLDB,xDPB
	FDVRB	FLOAT	; 140-177  FADxx,FSBxx,FMPxx,FDVxx
	MOVMS	CHEKIS	; 200-217  MOVxx
	IMULB	CHECKI	; 220-223  IMULx
	DIVB	MULDIV	; 224-237  MULx,xDIVx
	LSH	SETI	; 240-242  ASH,ROT,LSH
	JFFO	IJFFO	; 243      JFFO
	LSHC	DBLI	; 244-246  ASHC,ROTC,LSHC
	KAFIX	SETI	; 247      FIX
	EXCH	SETEA	; 250      EXCH
	BLT	SETI	; 251      BLT
	AOBJN	IAOBJ	; 252-253  AOBJx
	JRST	IJRST	; 254      JRST
	JFCL	IJFCL	; 255      JFCL
	XCT	I.XCT	; 256      XCT
	MAP	SETEA	; 257	   MAP (KL-10)
	PUSHJ	IIPUSHJ	; 260      PUSHJ
	POP	IPUPO	; 261-262  PUSH,POP
	POPJ	IPOPJ	; 263      POPJ
	JSR	I.JSR	; 264      JSR
	JSP	I.JSP	; 265      JSP
	JSA	I.JSA	; 266      JSA
	JRA	IAOBJ	; 267      JRA
	SUBB	CHECKI	; 270-277  ADDx,SUBx
	CAIG	SETI	; 300-307  CAIxx
	CAMG	SETEA	; 310-317  CAMxx
	SOSG	JMPSKP	; 320-377  JUMPxx,SKIPxx,AOJxx,AOSxx,SOJxx,SOSxx

; MUUOs
DEFINE SKPEXC {PUSHJ P,XECDET~	; Assume that EDDT users are in EXEC mode.

IFN EDDT&1,<
MONUAI:	TLO	F,FAC		; Print AC
MONUI:	SKPEXC
	JRST	JUSTI
	JRST	USRUUO		; Trace MUUOs in EXEC mode.

MONUAE:	TLO	F,FAC
MONUE:	SKPEXC
	JRST	JUSTE
	JRST	USRUUO

MONINI:	SKPEXC
	JRST	MONIN1
	JRST	USRUUO

XECDET:	MOVSI	T,010000		; Test for user mode		*******
	TDNN	T,SAVPI
	AOS	(P)
	POPJ	P,
>; IFN EDDT&1

MONIN1:	MOVE	T,I.NST			; Here to interpret INITs
	MOVEM	T,INLINI
	AOS	R,PROC0			; Get first inline arg to INIT
	PUSHJ	P,FETCH
	  JRST	ERR
	MOVEM	T,INLINI+1
	AOS	R,PROC0
	PUSHJ	P,FETCH
	  JRST	ERR
	MOVEM	T,INLINI+2
	EXCH	F,FLAGS
	TLNN	F,CCF
	MOVEM	R,LOCSAV		; Only update original PC if not $$X
	MOVE	T,[JRST INLINI]
	MOVEM	T,I.NST
	JRST	DOITA

INLINI:	0
	0
	0
	JRST	DOITB
	JRST	DOITC

; LUUOs
USRUUO:	MOVEI	R,40
	EXCH	F,FLAGS
	MOVE	T,I.NST
	PUSHJ	P,DEP
	  JRST	ERR
	EXCH	F,FLAGS
	MOVE	T,[XCT 41]
	JRST	$X03			; Simulate the trap

IUFA:	TLOA	F,FLA!FLE!DFAC		; Floating point; uses 2 ACs
IDFN:	TLO	F,FLA!FLE		; Floating point + 1 AC
	JRST	SETEA

DFLT:	TLO	F,FLA!DEA!DFAC!FLE	;Dbl floating memory + double ac
	JRST	SETEA

; Here for floating point instructions.
FLOAT:	ANDI	F,7000
	CAIN	F,1000			; long mode ?
	TLOA	F,DFAC			; Yes; 2 ACs
	CAIN	F,5000			; Immediate mode ?
	TLOA	F,FLA!FLE!FAC!EA	; No; AC, E floating
FLOATI:	TLO	F,FLA!FLE!FAC!IMM	; Yes; AC, E immediate floating
	JRST	DOIT

IJRST:	TLO	F,IMM			; Print E
	TRNE	W1,2
	TLO	F,FLG			; Print flags if JRSTF
IJRST0:	PUSHJ	P,FETCH		; It's so f-----g hard to get at the flags!!!
	  JRST	ERR
	MOVE	W1,T
	LDB	R,[POINT 4,T,17]	; Index AC
	JUMPE	R,IJRST1
	MOVE	T,AC0(R)
	TLZ	T,37		; Clear I,X fields
	ADDI	T,(W1)
	TLZ	F,37
IJRST1:	MOVEI	R,(T)
	TLNE	W1,20
	JRST	IJRST0
; LH T has the flags to restore.
IFN EDDT&1,<
	SKPEXC
	JRST	IJRST3
	MOVE	W1,I.NSTAC
	TRNE	W1,1			; Jump to USER mode ?
	JRST	JRSPRC			; Yes, lose
	TRNE	W1,2			; JRSTF to USER ?
	TLNN	T,(1B5)
	JRST	IJRST3
JRSPRC:	EXCH	F,FLAGS			; Lose.
	TLZ	F,QF!CCF
	JRST	PROCD1			; Treat like $P
>

IJRST3:	HRRI	T,DOITB
	MOVEM	T,BCOM			; Store new PC word
	SOS	T,I.NST
	HRRM	T,PROC0
	HRRI	T,BCOM
	TLO	T,20
	MOVEM	T,I.NST			; JRST @BCOM now
	JRST	DOIT

I.XCT:	IFN EDDT&1,<DPB W1,[POINT 4,INSXCT,12]>; Make sure EXEC XCTs work right
	MOVE	F,FLAGS
	SOSG	XCTS
	JRST	ERR			; Too many XCTs.
	TLNE	F,CCF			; $$X ?
	JRST	IIXCT1
	HRRZ	T,I.NSTEA
	PUSHJ	P,PINST			; Print instruction
	PUSHJ	P,CRF
IIXCT1:	HRRZ	R,I.NSTEA
	JRST	$X02

IIPUSHJ:AOS	T,PROC0
	HLL	T,SAVPI			; PC word a normal PUSHJ would store
	MOVEM	T,I.NSTPC
	MOVSI	T,(1B4)
	ANDCAM	T,SAVPI			; Clear funny flag in PC wd.
	SOS	T,I.NST			; DOIT insists on incrementing the PC
	HRRM	T,PROC0
	HRLZI	T,(<PUSH>-<PUSHJ>)
	DPB	T,[POINT 5,I.NST,17]	; Clear AC,I fields
	JRST	IPOPJ2

IPOPJ:	EXCH	F,FLAGS
	HRRZ	R,AC0(W1)
	PUSHJ	P,FETCH
	  JRST	ERR
	EXCH	F,FLAGS
	HRRI	T,-1(T)			; DOIT increments the PC
	HRRM	T,PROC0
	HRLZI	T,(<POP>-<POPJ>)
IPOPJ2:	ADDM	T,I.NST			; PUSHJPUSH, POPJPOP
	HRRZI	T,I.NSTPC		; PC word to PUSH if PUSHJ
	HRRM	T,I.NST
IPUPO:	TLOA	F,FAC!PFLG
IFSC:	TLO	F,FAC!FLA!IMM		; Floating AC, fixed immediate E
	JRST	DOIT

I.JSA:	AOS	T,PROC0
	HRL	T,I.NSTEA
	EXCH	T,AC0(W1)
	JRST	I.JSR2			; Use JSR code to store old AC

I.JSR:	AOS	T,PROC0
	HLL	T,SAVPI			; Make the PC word
	TLO	F,FAC
	MOVSI	W1,(1B4)
	ANDCAM	W1,SAVPI		; Clear funny bit in flags
I.JSR2:	TLO	F,EA
	EXCH	F,FLAGS
	HRRZ	R,I.NSTEA
	PUSHJ	P,DEP
	  JRST	ERR
	EXCH	F,FLAGS
	HRRZ	T,I.NSTEA
	AOJA	T,I.JSR4

I.JSP:	AOS	T,PROC0
	HLL	T,SAVPI
	MOVEM	T,AC0(W1)
	MOVSI	T,(1B4)
	ANDCAM	T,SAVPI			; Clear funny bit
	HRRZ	T,I.NSTEA
I.JSR4:	HRRM	T,PROC0
	TLC	F,FAC
	EXCH	F,FLAGS
	JRST	TELL			; Simulation complete; do printout

IJFFO:	TLO	F,DFAC			; 2 ACs
JMPSKP:	TRNE	F,10000
	JRST	SKP			; Skip class; no trouble
IAOBJ:	TLOA	F,FAC!IMM
IJFCL:	TLO	F,FLG
	MOVEI	T,JMP
	HRRM	T,I.NST			; Make jump to us if they jump
	JRST	DOIT

JMP1:	EXCH	T,I.NSTEA		; They jumped; now we've got to simulate
	HRRM	T,PROC0			;STORE EFFECTIVE ADDRESS OF JUMP
	EXCH	T,I.NSTEA
	JRST	TELL			;DO PRINTOUT (DON'T INCREMENT PROC0)

SKP:	JUMPN	W1,DOIT
JUSTE:	TLOA	F,EA
DBLI:	TLO	F,FAC!DFAC!IMM		; 2 ACs, immediate mode
	JRST	DOIT

DINT:	TLO	F,DFAC!DEA		;Dbl integer ins. (KL-10)
	JRST	DOIT

IEXTND:	JRST	SETEA			;KL-10 EXTEND instruction--nothing
					; special until somebody uses it.

TESTS:	TRNN	F,10000
	TLOA	F,FAC!IMM		; TRxx or TLxx
	TLO	F,FAC			; TDxx or TSxx
	JRST	DOIT

; I/O instructions
IFN EDDT&1,<
IOTS:	TRNE	W1,4			; Skip if BLKx or DATAx
	CAIN	W1,5			; Skip if not CONI
	TLOA	F,EA>
JUSTI:	TLO	F,IMM
	JRST	DOIT

CHEKIS:	TRC	F,3000
	TRCE	F,3000
	JRST	CHECKI			; Check for immediate mode
	JRST	SKP			; Self mode

SET:	ANDI	F,3000			; SETZx or SETOx come here
	CAIE	F,2000			; Skip if SETZM or SETOM
	TLO	F,FAC
	TRNE	F,2000			; Skip if not SETZM,SETZB,SETOM,SETOB
	TLO	F,EA
	JRST	DOIT

MULDIV:	ANDI	F,3000
	CAIE	F,2000			; Skip if to memory only
	TLO	F,DFAC
CHECKI:	TRNE	F,1000
	TRNE	F,2000
SETEA:	TLOA	F,FAC!EA		; Memory reference instruction
SETI:	TLO	F,FAC!IMM		; Immediate mode instruction
DOIT:	EXCH	F,FLAGS
	JRST	DOITA

IFE EDDT&1,<
	MONUI__JUSTI
	MONUE__JUSTE
	MONUAI__SETI
	MONUAE__SETEA
	MONINI__MONIN1
	IOTS__MONUI
>

SKIP%:	AOS	PROC0
NOSKIP:	AOS	PROC0
TELL:
IFN EDDT&1,<
	MOVEI	T,
	DPB	T,[POINT 4,INSXCT,12]	; Zap AC field so EXEC XCTs only affect 1 instruction.
>
	MOVE	F,SAV0
	TLNE	F,CCF			; Don't print if $$X
	JRST	NXTIT
	EXCH	F,FLAGS
	PUSH	P,SCH			; Save current output mode
	TLNE	F,FLA			; Floating AC to print ?
	MOVEI	SCH,TFLOT
	TLNE	F,FAC
	PUSHJ	P,FAC0			; Print AC
	TLNE	F,DFAC
	PUSHJ	P,DBL0			; Print 2nd AC
	TLNE	F,FLG
	PUSHJ	P,FLG0			; Print the flags
	MOVE	SCH,(P)			; Restore old output mode.
	TLNE	F,FLE
	MOVEI	SCH,TFLOT		; Floating memory to print
;	TLNE	F,IMM
;	PUSHJ	P,IMM0			; Just print E in immediate mode
	TLNE	F,EA
	PUSHJ	P,EA0			; Print (E) if memory referencing instruction
	TLNE	F,DEA
	PUSHJ	P,DEA0			; Print 2nd memory word
	TLNE	F,PFLG
	PUSHJ	P,PFLG0			; Print stack word if PUSHx or POPx
	POP	P,SCH
	EXCH	F,FLAGS
	PUSHJ	P,CRF

; Test whether to continue; print next instruction if required.
NXTIT:	HRRZ	T,PROC0
	MOVEI	W1,1(T)
	HRRZM	W1,BCOM			; Store for $P
	HRRZ	W1,LOCSAV		; Old PC
	SKIPL	XTEM			; $$X with no argument ?
	JRST	NXT0			; No
	CAIE	T,1(W1)
	CAIN	T,2(W1)
	JRST	$XQUIT
NXT0:	PUSHJ	P,LISTEN		; Did he type anything ?
	  JRST	NXT1			; Nope
$XQUIT:	SETZM	XTEM
	TLZ	F,CCF
NXT1:	TLNE	F,CCF			; $$X ?
	JRST	NXT2			; Yes
	HRRZ	T,PROC0
	CAIE	T,1(W1)
	PUSHJ	P,CRF			; Extra CRLF  instruction skipped
	HRRZ	T,PROC0
	PUSHJ	P,PINST			; Print next instruction
	SKIPE	XTEM
	PUSHJ 	P,CRF
NXT2:	SKIPE	XTEM
	JRST	$X01
IFE EDDT&1,<	CLRBFI			; *** Done *** >;IFE EDDT&1
	JRST	DD2

; The sundry output routines
PFLG0:	MOVE	T,I.NSTAC
	HRRZ	T,AC0(T)		; Get adr of stack
	JRST	EA2
DBL0:	AOS	T,I.NSTAC
	TRZA	T,777760		; Modulo 20
FAC0:	MOVE	T,I.NSTAC
	JRST	EA2
FLG0:	PUSHJ	P,LCT			; Print TAB
	HLRZ	T,SAVPI
REPEAT 0,<
	JRST	IMM1
IMM0:	PUSHJ	P,LCT			; Print TAB
	HRRZ	T,I.NSTEA
	TLNE	F,FLE			; Floating memory operand ?
	MOVS	T,T			; Yes; immediate swaps halves
>; REPEAT 0
IMM1:	EXCH	F,FLAGS
	PUSHJ	P,CONSYM		; Type (T)
	JRST	EA6
DEA0:	AOSA	T,I.NSTEA
EA0:	MOVE	T,I.NSTEA		; Address of memory operand
EA2:	EXCH	F,FLAGS
	PUSH	P,T
	PUSHJ	P,LCT			; Print a TAB
	POP	P,T
	PUSHJ	P,LI1			; Print ADR/	CONTENTS
EA6:	EXCH	F,FLAGS
	POPJ	P,
PINST:	PUSH	P,SCH			; Save current output mode
	MOVEI	SCH,PIN			; Force symbolic output
	PUSHJ	P,LI1
	PUSHJ	P,LCT
	POP	P,SCH
	POPJ	P,

; SWAP swaps user's and DDT's ACs or vice-versa
SWAP:	0
	EXCH	0,AC0
	MOVEM	0,SAV0
	MOVE	0,[EXCH 1,AC0+1]
SWAPL:	XCT	0
	ADD	0,[XWD 40,1]
	TLNN	0,1000
	JRST	SWAPL
	MOVE	0,SAV0
	JRST	@SWAP

;INTERPRETATION

IXCT4:				;INTERPRET UUO
IFE EDDT&1,<	SUBI	T,041
		JUMPE	T,IINIT	;INIT UUO HAS TO BE DONE SPECIAL
		AOJGE	T,IXCT6	;JUMP IF SYSTEM UUO.  (DON'T INTERPRET) >
	MOVEM	R,40		;INTERPRET FOR NON-SYSTEM UUOS
	MOVEI	R,41
	JRST	IXCT

;(INTERPRETAION OF EXECUTIVE XCT OF A PC-STORING JUMP WILL STORE WRONG PC)
IIXCT:					;HERE TO INTERPRET XCT.
IFN EDDT&1,<	JUMPN	W1,IXCT6	;JUMP IF EXECUTIVE XCT>
IXCT:	SOSL	TEM1			;COUNT LOOPS THRU INTERPRETER
	PUSHJ	P,FETCH
	JRST	BPLUP			;BREAKPOINT LOOPING OR FETCH FAILED
	MOVEM	T,LEAV			;STORE INSTR. TO EXECUTE.
IXCT5:	LDB	T,[POINT 9,LEAV,8]	;GET INSTRUCTION
	CAIN	T,254			;JRST IS NORMAL
	JRST	IXCT6
	HRLZI	17,AC0			;SETUP ACS TO ALLOW EFFECT ADDRESS CALC.
	BLT	17,17
	MOVEI	T,@LEAV			;CALCULATE EFFECTIVE ADDRESS.
	DPB	T,[POINT 23,LEAV,35]	;STORE EFFECTIVE ADDRESS, CLEAR X AND @
	LDB	W1,[POINT 4,LEAV,12]	;PICK UP AC FIELD
	LDB	T,[POINT 9,LEAV,8]	;PICK UP INSTRUCTION FIELD
	MOVEI	P,PS			;AND GET A STACK
	CAIN	T,260
	JRST	IPUSHJ			;INTERPRET PUSHJ
	CAIN	T,264
	JRST	IJSR			;INTERPRET JSR
	CAIN	T,265
	JRST	IJSP			;INTERPRET JSP
	CAIN	T,266
	JRST	IJSA			;INTERPRET JSA
	MOVE	R,LEAV			;GET ENTIRE INSTR. (INCASE OF UUO OR XCT)
	TRNN	T,700
	JRST	IXCT4			;INTERPRET UUO
	CAIN	T,256
	JRST	IIXCT			;INTERPRET XCT (MAY BE EXEC EXECUTE)
IXCT6:	MOVE	W,LEAV			;FOR RESTORE TO XCT
	MOVEI	T,@BCOM			;GET RETURN ADR
	JRST	RESTORE

BPLUP:	PUSHJ	P,REMOVB		;BREAKPOINT PROCEED ERROR
BPLUP1:	JSR	SAVE
	JFCL
	JRST	ERR

IFE EDDT&1,<			;INTERPRET INIT UUO
IINIT:	MOVE	T,LEAV
	MOVEM	T,INITL		;SET UP TO DO THE INIT HERE
	MOVEI	R,@BCOM		;THE LOC OF INIT+1
	PUSHJ	P,FETCH
	JRST	BPLUP
	MOVEM	T,INITL+1
	ADDI	R,1
	PUSHJ	P,FETCH
	JRST	BPLUP
	MOVEM	T,INITL+2
	MOVEI	T,2
	ADDM	T,BCOM		;INCREMENT RETURN ADR

INITL:	0			;INIT
	0			;DEVICE
	0			;BUFFERS
	SKIPA			;FAILURE RETURN
	AOS	BCOM		;SUCCESS - SKIP RETURN
	MOVEI	T,@BCOM		;GET RETURN ADR
	JRST	IJSR4		;AND MAKE LIKE A JSR
>;IFE EDDT&1

IPUSHJ:	DPB W1,[POINT 4,CPUSHP,12]	;STORE AC FIELD INTO A PUSH
	SETZM TEM3
	MOVE W,CPUSHP		;GET A PUSH INSTR
	MOVE T,LEAV
	JRST RESTR1

CPUSHP:	PUSH

IJSA:	MOVE T,BCOM		;INTERPRET JSA
	HRL T,LEAV
	EXCH T,AC0(W1)
	JRST IJSR2

IJSR:	MOVE T,BCOM		;INTERPRET JSR
	HLL T,SAVPI
IJSR2:	MOVE R,LEAV
	PUSHJ P,DEP
	AOSA T,LEAV
IJSR3:	MOVE T,LEAV
IJSR4:	MOVSI W,(<JFCL>)
	JRST RESTORE

IJSP:	MOVE W,BCOM		;INTERPRET JSP
	HLL T,SAVPI
	MOVEM W,AC0(W1)
	JRST IJSR3

;INSERT BREAKPOINTS

INSRTB:	MOVE S,[JSR BP1]
INSRT1:	SKIPE R,B1ADR-BP1(S)
	PUSHJ P,FETCH
	JRST INSRT3
	MOVEM T,B1INS-BP1(S)
	MOVE T,S
	PUSHJ P,DEP
INSRT3:	ADDI S,4
	CAMG S,[JSR BPN]
	JRST INSRT1
	POPJ P,

;REMOVE BREAKPOINTS

REMOVB:	MOVEI S,BNADR
REMOV1:	MOVE T,B1INS-B1ADR(S)
	SKIPE R,(S)
	PUSHJ P,DEP
	SUBI S,4
	CAIL S,B1ADR
	JRST REMOV1
	IFN EDDT&1,<JRST TTYRET>
	IFE EDDT&1,<POPJ P,>

;IN EXEC MODE, SAVE UP TTY STATUS
;IN USER MODE, DONE BY SAVE

	SUBTTL	DDT - PROCESS BREAKPOINT COMMANDS

;ALL $B COMMANDS OF FORM <A>$<N>B

BPS:	TLZE F,QF
	JRST BPS1
	TRZE F,Q2F
	JRST BPS2
	MOVE T,[XWD B1ADR,B1ADR+1]
	SETZM  B1ADR
	BLT T,AUTOPI	;CLEAR OUT ALL BREAKPOINTS AND AUTO PROCEDE REGESTER
	JRST RET

BPS1:	TRZN F,Q2F
	JRST BPS3
	MOVE R,T
	TRO F,2
BPS2:	MOVE T,WRD2
	CAIL T,1
	CAILE T,NBP
	JRST ERR
	IMULI T,4
	ADDI T,B1ADR-4
	TRZN F,ITF
	JRST MASK2
	EXCH R,T
	JRST BPS5

BPS3:	MOVEI R,B1ADR		;PROCESS THE A$B
BPS4:	HRRZ W,(R)
	CAIE W,(T)
	SKIPN (R)
	JRST BPS5
	ADDI R,4
	CAIG R,BNADR
	JRST BPS4
	JRST ERR
BPS5:	MOVEM T,(R)
	SETZM 1(R)
	SETZM 2(R)
	SETZM 3(R)
IFN EDDT&20,<
	SKIPP1			;BREAKPOINTS CONDITIONAL ON WHO PLANTED THEM
	SKIPA	S,[SKIPP2]
	MOVE	S,[SKIPP1]
	MOVEM	S,B1SKP-B1ADR(R)	;MAKE BREAK POINTS CONDITIONAL!
>
AUTOP:	SUBI R,B1ADR		;AUTO PROCEED SETUP
	IDIVI R,4
	MOVEI S,1
	LSH S,(R)
	ANDCAM S,AUTOPI
	TLNE F,CCF
	IORM S,AUTOPI
	POPJ P,


	SUBTTL	DDT - FETCH AND DEPOSIT INTO MEMORY


DEPRS:	MOVEM	T,LWT		;DEPOSIT REGISTER AND SAVE AS LWT
	MOVE	R,LLOCO		;QUAN TYPED IN REGIS EXAM
	TLZE	F,ROF		;WAS A REGISTER OPEN (SKIP IF NOT)
	TLNN	F,QF		;AND A QUANTITY TYPED?
	POPJ	P,		;NO REGISTER OPEN, OR NO QUANTITY TYPED.
DEP:
IFE UEDDTS,<	TRNN	R,777760	;IS ADDRESS ABOVE ACS?
		JRST	DEP1		;CHANGE THE ACS WE HAVE SAVED. >;NOT UEDDT

	PUSH	P,R
	PUSH	P,T
	HRRZ	R,R
	AOS	-2(P)
	PUSHJ	P,XDEP
	SOS	-2(P)
	POP	P,T
	POP	P,R
	POPJ	P,

XDEP:
IFE UEDDTS,<				;NOT UEDDT
	IFE EDDT&1,<			;USER DDT
		HRRZ	W,JOBREL	;CHECK FOR LOWER SEGMENT ADDRESS
		CAIL	W,(R)
		JRST	DEP0		;ADDRESS OK.
		ADDI	W,1		;FIRST ADDRESS ABOVE LOWER MAY BE IN UPPER
		CAIGE	W,400000	;COMPUTE FIRST ADDRESS IN UPPER.
		MOVEI	W,400000	;
		CAILE	W,(R)		;IS DESIRED ADDRESS ABOVE START OF UPPER?
		POPJ	P,		;ILLEGAL ADDRESS ABOVE LOWER, NOT IN UPPER
		HRRZ	W,JOBHRL	;GET LAST ADDRESS IN UPPER
		CAIL	W,(R)		;DEPOSIT IN BOUNDS?
DEP0:		MOVEM	T,0(R)		;STUFF IT.
		POPJ	P,>		;RETURN.   ;IFE EDDT&1

	IFN EDDT&1,<			;EXEC DDT
	IFN FTDSWP,<			;SWAPPING EXEC DDT
		PUSHJ	P,SWPDEP	;SPECIAL SWAPPING DEPOSIT ROUTINE.
		POPJ	P,	>	;DEPOSIT DONE, OR LOST!
		HRRZ	W,JOBREL	;USE SYSTEM JOBREL FOR EXEC DDT
		CAILE	W,(R)		;DEPOSIT IN BOUNDS?
		MOVEM	T,0(R)		;STUFF IT.
		POPJ	P,>		;RETURN.   ;IFN EDDT&1
>;IFE UEDDTS

IFN UEDDTS,<
	SKIPE	EXJOBN		;EX-DEP IN JOB??
	POPJ	P,		;YES, LOSE
	CAMG	R,MEMSIZ	;ADDRESS IN BOUNDS?
	SKIPN	SPCFLG		;YES. HAS PROGRAM BEEN REENTERED?
	JRST	UDEPLZ		;NO. LOSE.
	MOVEM	T,SPCWRD#	;SAVE DATA FOR SPACEWAR
	MOVEM	R,SPCADR#	;SAVE ADDRESS FOR SPACEWAR
	SKIPN MAINTM		;DON'T LOG CHANGES IF THE SYSTEM IS DOWN
	PUSHJ	P,LOGIT		;LOG INTO UEDDT.LOG
	GETPR2	T,		;GET OLD VALUE OF SECOND PROT/RELOC REGISTER
	PUSH	P,T		;SAVE IT
	MOVE	R,SPCADR	;GET ADDRESS WE'RE STORING INTO
	SKIPN	EXMMAP		;SKIP IF EXAMINE/DEPOSIT VIA EXPGT.
	JRST	UDTDP1		;EX/DEP IN PHYSICAL CORE
	LDB	T,[POINT 9,R,26]	;GET THE PAGE NUMBER OF REQUEST
	SKIPL	EXMMAP
	JRST	DPTHIC			;DEPOSIT IN HIGH PHYSICAL CORE.
	SKIPN	T,EXPGT(T)		;IS THERE AN EXPGT ENTRY FOR IT?
	JRST	UDTDP1			;NO.  EXAMINE PHYSICAL CORE INSTEAD.
DPTHIX:	HRRZ	T,T
	LSH	T,5			;MOVE PAGE NUMBER OVER FOR GETHI
	IOR	T,[1,,20]		;1 PAGE, WRITEABLE.
	GETHI	T,			;ATTACH ONE PAGE AS HIGH-SEG
	JRST	DPTEXL			;LOSE?
	ANDI	R,777			;LEAVE LOW BITS
	MOVE	T,SPCWRD		;GET THE WORD.
	MOVEM	T,400000(R)		;STUFF.
	JRST	UDTDP2			;AND EXIT

DPTHIC:	ADD	T,EXMMAP		;HERE IF EXMMAP IS POSITIVE.  ADD AS OFFSET
	JRST	DPTHIX

DPTEXL:	OUTSTR	[ASCIZ/GETHI failed for deposit
/]
	JRST	UDTDP2

UDTDP0:	HRRZ	T,R
	CAMLE	T,MEMSIZ
	POPJ	P,
	PUSHJ	P,PRSET
UDTDP1:	MOVEI	T,@PROFF
	CAMLE	T,PRMAX
	JRST	UDTDP0
	GETPR2	R,
	TLZ	R,1		;SET WRITEABLE
	SETPR2	R,
	JFCL
	MOVE	R,SPCWRD	;GET THE DATA TO STORE.
	MOVEM	R,400000(T)
UDTDP2:	POP	P,T		;RESTORE OLD SETPR2
	SETPR2	T,
	JFCL
	POPJ	P,

UDEPLZ:	OUTSTR	[ASCIZ/DEPOSIT NOT ENABLED!
/]
	POPJ	P,

>

DEP1:	MOVEM	T,AC0(R)
	POPJ	P,

FETCH:	PUSH	P,R		;SOME CALLERS WANT COUNTS IN THE LEFT
	AOS	-1(P)		;AND SOME ROUTINES BELOW WANT ONLY 18 BITS
	HRRZ	R,R
	PUSHJ	P,XFETCH
	SOS	-1(P)
	POP	P,R
	POPJ	P,

XFETCH:
IFE UEDDTS,<
	IFE EDDT&1,<
		HRRZ	T,JOBREL	;CHECK FOR LOWER SEGMENT ADDRESS
		CAIL	T,(R)
		JRST	FETCH0		;ADDRESS OK.
		ADDI	T,1		;FIRST ADDRESS ABOVE LOWER MAY BE IN UPPER
		CAIGE	T,400000	;COMPUTE FIRST ADDRESS IN UPPER.
		MOVEI	T,400000	;
		CAILE	T,(R)		;IS DESIRED ADDRESS ABOVE START OF UPPER?
		POPJ	P,		;ILLEGAL ADDRESS ABOVE LOWER, NOT IN UPPER
		HRRZ	T,JOBHRL	;GET LAST ADDRESS IN UPPER
		CAIGE	T,(R)		;DEPOSIT IN BOUNDS?
		POPJ	P,
FETCH0:		TRNN	R,777760	;AC REF?
		SKIPA	T,AC0(R)
		MOVE	T,0(R)		;GET IT.
		JRST	CPOPJ1>		;RETURN.   ;IFE EDDT&1

	IFN EDDT&1,<
	IFN FTDSWP,<	PUSHJ P,SWPEXM
			JRST CPOPJ1		;EXAMINE DONE, OR LOST
			JRST CPOPJ1		;DISK REF FAILED! >;IFN FTDSWP
		HRRZ	T,JOBREL
		CAIGE	T,(R)
		POPJ	P,			;OUT OF BOUNDS
		TRNN	R,777760
		SKIPA	T,AC0(R)		;MAKE AC REFERENCE
		MOVE	T,(R)			;REFERENCE REAL CORE
		JRST	CPOPJ1			>;IFN EDDT&1
>;IFE UEDDTS

IFN UEDDTS,<
	SKIPE	EXJOBN			;EXAMINING JOB?
	JRST	JEXM			;YES, DO IT!
	SKIPE	EXMMAP			;EXAMINE USING EXPGT?
	JRST	EXPEXM			;YES.
NOEXPE:	MOVEI	T,@PROFF
	CAMLE	T,PRMAX
	JRST	[HRRZ T,R
		CAMLE T,MEMSIZ
		POPJ P,
		PUSHJ P,PRSET
		JRST XFETCH]
	MOVE T,400000(T)
	JRST CPOPJ1

EXPEXM:	LDB	T,[POINT 9,R,26]	;GET THE PAGE NUMBER OF REQUEST
	SKIPL	EXMMAP			;SKIP IF EXAMINE VIA EXPGT.
	JRST	EXMHIC			;NO - EXAMINE HIGH PHYSICAL CORE.
	SKIPN	T,EXPGT(T)		;IS THERE AN EXPGT ENTRY FOR IT?
	JRST	NOEXPE			;NO.  EXAMINE PHYSICAL CORE INSTEAD.
EXMHIX:	PUSH	P,T
	GETPR2	T,
	EXCH	T,(P)			;OLD PR ON STACK. 
	HRRZ	T,T
	LSH	T,5			;MOVE PAGE NUMBER OVER FOR GETHI
	HRLI	T,1			;NUMBER OF PAGES
	GETHI	T,			;ATTACH ONE PAGE AS HIGH-SEG
	JRST	EXPEXL			;LOSE?
	ANDI	R,777			;LEAVE LOW BITS
	MOVE	T,400000(R)		;FETCH DATA
EXPXIT:	EXCH	T,(P)
	SETPR2	T,
	HALT	.
	POP	P,T
	JRST	CPOPJ1

EXMHIC:	ADD	T,EXMMAP		;HERE FOR EXAMINE HIGH PHYSICAL CORE.
	JRST	EXMHIX

EXPEXL:	OUTSTR	[ASCIZ/GETHI failed?
/]
	MOVEI	T,0
	JRST	EXPXIT


JEXM:	TRNE R,777760		;AC?
	JRST JEXM1
	MOVE T,[-1,,JOBPC^]	;GET PC WORD
	MOVEM T,EXJOBN+1
	MOVEI T,EXJOBN
	JOBRD T,
	POPJ P,			;LOSE
	MOVE T,EXJWRD		;GET LOSERS PC
	TLNE T,10000		;USRMOD?
	ADDI R,20		;YES, AC'S ARE REALLY HERE
JEXM1:	HRROM R,EXJOBN+1	;SET ADDRESS AND WORDCOUNT OF 1
	MOVEI T,EXJOBN
	JOBRD T,		;EXAMINE LOSER CORE
	POPJ P,			;LOSE
	MOVE T,EXJWRD
	JRST CPOPJ1
>;IFN UEDDTS

FIRARG:	MOVEM T,DEFV
	TLO F,FAF
	JRST ULIM1
ULIM:	TLO F,SAF
	HRRZM T,ULIMIT
ULIM1:	TLNN F,QF
	JRST ERR
	JRST LIS0

	SUBTTL	DDT - PRINT INSTRUCTION.  PIN,LFPIN,RFPIN,CONSYM
CONSYM:	MOVEM T,LWT
	TRNN F,LF1
	JRST (SCH)		;PIN OR FTOC
	TRNE F,CF1
	JRST  FTOC

LFPIN:	JFCL
RFPIN:	JFCL			;FOR L AND V MODES (JUST SO THEY ARE NOT PIN)
PIN:	TLC	T,700000	;PRINT INSTRUCTION
	TLCN	T,700000
	JRST	INOUT		;IN-OUT INSTRUCTION OR NEG NUM
	AND	T,[XWD 777000,0]
	JUMPE	T,HLFW
	PUSHJ	P,OPTYPE
PIN1:	MOVSI	T,777000
	AND 	T,LWT
	TRNN	F,ITF		;HAS INSTRUCTION BEEN TYPED?
	PUSHJ	P,LOOK		;NO, LOOK IN SYMBOL TABLE
	JRST	PIN1A		;WIN.
	JRST	HLFW		;INEXACT MATCH, OUTPUT AS HALFWORDS
	JRST	HLFW		;NO MATCH AT ALL

PIN1A:	TRO	F,NAF		;INSTRUCTION TYPED, ALLOW NEG ADDRESSES
	PUSHJ	P,TSPC
	LDB	T,[XWD 270400,LWT]	;GET AC FIELD
	JUMPE	T,PI4
	PUSHJ	P,PAD
PI3A:	MOVEI	W1,","
	PUSHJ	P,TEXT
IFE EDDT&1!UEDDTS,<INOU1:>
PI4:	MOVE W1,LWT
	MOVEI T,"@"
	TLNE W1,20		;CHECK FOR INDIRECT BIT
	PUSHJ P,TOUT
	HRRZ T,LWT
	LDB W,[XWD 331100,LWT]	;INSTRUCTION BITS
	CAIL W,240
	CAILE W,247
	JRST PI8
	TLNN W1,20	;INDIRECT
	CAIN W,<JFFO>-33
	JRST PI8	;AND JFFO GET SYMBOLIC
	PUSHJ P,PADS3A
PI7:	TRZ F,NAF	
	LDB R,[XWD 220400,LWT]	;INDEX REGISTER CHECK
	JUMPE R,CPOPJ		;EXIT
	MOVEI T,"("
	PUSHJ P,TOUT
	MOVE T,R
	PUSHJ P,PAD
	MOVEI T,")"
	JRST TOUT		;EXIT

PI8:	CAIE	SCH,LFPIN	;IN ONE OF THE FLAG MODES?
	CAIN	SCH,RFPIN	;?
	JRST	RLFFLG		;YES.
PI8A:	PUSHJ	P,PAD
	JRST	PI7


;	PRINT HALFWORDS, PRINT ADDRESS

HLFW:	HLRZ	T,LWT		;PRINT AS HALF WORDS
	JUMPE	T,HLFW1
	TRO	F,NAF		;ALLOW NEGATIVE
	PUSHJ	P,PAD
	MOVSI	W1,(<ASCII /,,/>)
	PUSHJ	P,TEXT2
HLFW1:	HRRZ	T,LWT

;PRINT ADDRESS
PAD:	JRST	(AR)		;PADSO OR PAD1
PADSO:	JUMPE	T,TOC2+1
	PUSHJ	P,LOOK
	POPJ	P,		;WIN.
	SKIPA	W2,1(W1)	;INEXACT MATCH
	JRST	PADS3		;NO MATCH AT ALL
	CAMGE	T,MXINC
	CAIGE	W2,60
	JRST	PADS3
	MOVEM	T,TEMDDT
	JUMPGE	F,TOC		;EXIT
	PUSHJ	P,SPT0
	MOVEI	T,"+"
PADS1A:	PUSHJ	P,TOUT
	HRRZ	T,TEMDDT
	JRST	TOC		;EXIT

PADS3:	MOVE	T,TEMDDT
PADS3A:	TRNE	F,NAF
	CAIGE	T,776000
	JRST	TOC
PADS3B:	CAMN	T,[-1,,0]
	JRST	PADS3C		;SPECIAL CASE THAT PRINTS WRONG
	MOVNM	T,TEMDDT
	MOVEI	T,"-"
	JRST	PADS1A

PADS3C:	MOVEI	T,"-"
	PUSHJ	P,TOUT
	MOVSI	T,1
	JRST	TOC

INOUT:	TLC	T,-1		;IS IT PERHAPS NEGATIVE
	TLCN	T,-1
	JRST	PADS3B		;LEFT HALF IS -1
	TLC	T,777000
	TLCN	T,777000	;THIS IS ALMOST AS GOOD
	JRST	HLFW		;PRINT AS A HALF WORD

IFE IOTLG,<	JRST	PIN1>	;PRINT AS INSTRUCTION

IFG IOTLG,<			;COMPILE ONLY IF THERE ARE DEVICES KNOWN
	MOVSI	R,-IOTLG	;GET LENGTH OF IOT DEVICE TABLE
	LDB	W2,[POINT 7,T,9]	;GET DEVICE NUMBER
	LSH	W2,2		;TIMES 4
CKIOT:	CAME	W2,IOTBL(R)	;THERE?
	AOBJN	R,CKIOT
	JUMPGE	R,PIN1		;PRINT AS AN INSTRUCTION
	PUSH	P,R		;SAVE INDEX TO IOTBL
	LDB	R,[POINT 3,T,12]
	DPB	R,[POINT 6,T,8]	;MOVE IO BITS OVER FOR OP DECODER
	PUSHJ	P,OPTYPE	;TYPE OPCODE
	PUSHJ	P,TSPC		;TYPE SPACE
	POP	P,R		;GET INDEX TO IOTB2
	MOVEI	W1,IOTB2(R)	;GET POINTER TO RADIX50 OF THE DEVICE NAME
	PUSHJ	P,SPT1W		;PRINT RADIX50 OF 0(W1) WITHOUT TYPE BITS
	JRST	PI3A

>;IFG IOTLG

	SUBTTL	DDT - $M, $N, $W, $E COMMANDS

MASK:	TLNE F,QF
	JRST MASK1
	MOVEI T,MSK
MASK2:	MOVEI W,1
	MOVEM W,FRASE1
	JRST QUAN1

MASK1:	MOVEM T,MSK
	JRST RET

EFFEC:	TLO F,LTF
	HRRZ T,T
WORD:	MOVEI R,322000-326000	;JUMPE-JUMPN
NWORD:	ADDI R,326000+40*T	;JUMPN T,
	HRLM R,SEAR2
	TLZN F,QF
	JRST ERR
	SETCAM T,WRD
	MOVSI T,FRASE-DENDDT-1		;PREVENT TYPE OUT OF DDT PARTS
	SETCMM FRASE(T)
	AOBJN T,.-1
	MOVE T,ULIMIT
	TLNE F,SAF
	TLO F,QF
	PUSHJ	P,SETUP1		;RETURNS R=-WC,,MA FOR SEARCH
	PUSHJ	P,CRF
SEAR1A:	MOVEI	T,1000			;LOOP COUNT
	MOVEM	T,SERLPC
SEAR1:	PUSHJ	P,FETCH	
	JRST	SEAR2A
	TLNE F,LTF	;CHECK FOR EFFECTIVE ADDRESS SEARCH
	JRST EFFEC0
	EQV T,WRD
	AND T,MSK
SEAR2:	JUMPE T,SEAR3		;OR JUMPN T, (INSTR IS CLOBBERED ABOVE)
SEAR2A:	SOSLE	SERLPC		;ONLY LISTEN TO TTY EVERY 1000 TIMES
	JRST	SEAR2C
	PUSHJ	P,LISTEN	;QUIT ON TELETYPE
	CAIA
	JRST	SEAR2B		;A KEY WAS STRUCK.  QUIT NOW.
	MOVEI	T,2000
	MOVEM	T,SERLPC	;RESET LOOP COUNT.
SEAR2C:	CAMN R,[-1]	;LOSING AOBJN WILL SCREW THIS UP!!!!
	JRST SEAR2B	;END
	AOBJN R,SEAR1
	TLNE R,777777	;DID IT JUST GET TO 0 OR IS IT LARGER THAN 128K?
	JRST SEAR1	;BIG SEARCH
SEAR2B:	SETCMM LWT
	JRST DD1

SERLPC:	0

SEAR3:	PUSHJ P,FETCH
	JRST ERR
	TLZ F,STF	;TURN OFF SUPRESS OUTPUT
	MOVEM R,TEM2
	MOVEM R,T
	PUSHJ P,LI1
	PUSHJ P,CRF
	SETCMM LWT
	SETCMM TEMDDT
	SETZM	SERLPC	;CLEAR LOOP COUNT.  LISTEN TO TTY AGAIN.
SEAR4:	MOVE R,TEM2
	JRST  SEAR2A

EFFEC0:	TLNE F,CCF	;DOUBLE ALTMODE?
	JRST EFFECR	;YES, NO @() CHECK -- RPH 5-12-73
	MOVEM R,TEM2
	PUSHJ P,EFFECA
	JRST SEAR4	;LOST ON EFF ADR CALC
	MOVE R,TEM2
EFFECR:	EQV T,WRD
	ANDI T,777777
	JRST SEAR2

EFFECA:	MOVEI W,100
	MOVEM W,TEMDDT
EFFEC1:	MOVE W,T
	LDB R,[POINT 4,T,17]	;GET IR FIELD
	JUMPE R,EFFEC2
	HRRZ T,AC0(R)
	ADD T,W
EFFEC2:	HRR R,T
	TLNN W,20		;INDIRECT BIT CHECK
	JRST EFFEC3
	SOSE TEMDDT
	PUSHJ P,FETCH
	POPJ P,		;ERROR RETURN
	JRST EFFEC1

EFFEC3:	HRRZS T		;HALFWORD ONLY
	JRST CPOPJ1	;SKIP RETURN

	SUBTTL	DDT - $$Z

SETUP:	TROA	F,R20F			;HERE FOR $Z ONLY
SETUP1:	TRZ	F,R20F
	TLNN	F,SAF
IFE UEDDTS,<	MOVE	T,JOBREL>
IFN UEDDTS,<	MOVE	 T,MEMSIZ>	;SYSTEM JOBREL PTR.
	HRRZ	T,T
	MOVEM	T,ULIMIT		;UPPER LIMIT
IFE UEDDTS,<	CAMLE	T,JOBREL>
IFN UEDDTS,<	CAMLE	T,MEMSIZ>
	JRST	ERR
	HRRZ	R,DEFV			;R_LOWER LIMIT IF ONE WAS SUPPLIED
	TLNN	F,FAF
	MOVEI	R,0			;NO EXPLICIT LOWER LIMIT. USE ZERO
	CAML	R,ULIMIT
	JRST	ERR
	MOVEM	R,DEFV
	MOVEI	W,-1(R)			;RPH 3-17-72
	SUB	W,ULIMIT
	HRLM	W,R			;R_-WC,,FIRST ADDRESS.
	POPJ	P,

ZERO:	TLNN	F,CCF			;$$Z ?
	JRST	ERR			;NO ONE ALTMODE ISN'T ENOUGH.
	MOVE	W2,T			;VALUE TO SPREAD.
	TLNN	F,QF
	MOVEI	W2,0			;IF NONE, SPREAD ZERO
	HRRZ	T,ULIMIT
	PUSHJ	P,SETUP			;RETURNS R=-WC,,MA
ZERO1:	TRNE	R,777760		;STORE IN AC?
	JRST	ZERO2			;NO.
	MOVEM	W2,AC0(R)		;STORE IN OUR VERSION OF USER'S ACS.
	AOBJN	R,ZERO1			;LOOP WHILE IN AC
	JRST	DD1

ZERO2:	HRRZ	R,R			;ADDRESS OF NEXT WORD TO STORE INTO
	CAIGE	R,ZLOW
	MOVEI	R,ZLOW			;DON'T ZERO 20-ZLOW
	HRRZ	S,T			;UPPER LIMIT
	CAILE	S,DDTBEG-1
	MOVEI	S,DDTBEG-1
	CAML	S,R			;DON'T DO ANYTHING IF UPPER LESS THAN LOWER
	JSP	W,ZEROR			;S=HIGH, R=LOW.
	HRRZ	R,R
	CAIGE	R,DDTEND  		;DON'T ZERO OUT
	MOVEI	R,DDTEND  		;DDT
	HRRZ	S,T
	CAML	S,R
	JSP	W,ZEROR
	JRST	DD1

ZEROR:	HRL	R,R
	MOVEM	W2,(R)
	ADDI	R,1
	BLT	R,(S)
	JRST	(W)

	SUBTTL	DDT - OUTPUT ROUTINES  TOCC, FTOC, TOC, TOCA

TOCC:	TRO	F,EQF		;SET TO REAL NUMERIC MODE
FTOC:
TOC:	HRRZ	W1,ODF
	CAIN	W1,12
	JRST	TOC4
	TRZE	F,EQF		;REAL NUMERIC MODE?
	JRST	TOCA		;YES.
	CAIN	W1,10
	TLNN	T,-1		;IF RADIX NOT 10, OR LEFT HALF EMPTY
	JRST	TOCA		;PRINT
	HRRM	T,TOCS		;SAVE RIGHT HALF
	HLRZS	T
	PUSHJ	P,TOCA		;PRINT LEFT HALF
	MOVSI	W1,(<ASCII /,,/>)
	PUSHJ	P,TEXT2
TOCS:	MOVEI	T,0		;** RIGHT HALF MODIFIED
TOCA:	LSHC	T,-43
	LSH	W1,-1		;W1=T+1
TOC1:	DIVI	T,(ODF)
	HRLM	W1,0(P)
TOC3:	JUMPE	T,TOC2
	PUSHJ	P,TOCA
TOC2:	HLRZ	T,0(P)
	ADDI	T,"0"
	JRST	TOUT		;DOES POPJ TO TOC2 OR EXIT

TOC4:	MOVM W1,T
	JUMPGE T,TOC5
	MOVEI T,"-"
	PUSHJ P,TOUT
TOC5:	MOVEI T,0
	PUSHJ P,TOC1
TOC6:	MOVEI T,"."
	JRST TOUT

;FLOATING POINT OUTPUT

TFLOT:	MOVE A,T
	JUMPG A, TFLOT1
	JUMPE A,FP1A
	MOVNS A
	MOVEI T,"-"
	PUSHJ P,TOUT
	TLZE A,400000
	JRST FP1A
TFLOT1:	
	TLNN A, 400
	JRST FP7A	;UNNORMALIZED FLOATING PRINT AS DECIMAL

FP1:	MOVEI B,0
	CAMGE A,FT01
	JRST FP4
	CAML A,FT8
	AOJA B,FP4
FP1A:	MOVEI C,0

FP3:	MULI A,400
	ASHC B,-243(A)
	MOVE A,B
	SETZM TEM1
	PUSHJ P,FP7
	PUSHJ P,TOC6		;PRINT DECIMAL POINT
	MOVNI A,10
	ADD A,TEM1
	MOVE W1,C
FP3A:	MOVE T,W1
	MULI T,12
	PUSHJ P,FP7B
	SKIPE W1
	AOJL A,FP3A
	POPJ P,

FP4:	MOVNI C,6
	MOVEI W2,0
FP4A:	ASH W2,1
	XCT FCP(B)
	JRST FP4B
	FMPR A,@FCP+1(B)
	IORI W2,1
FP4B:	AOJN C,FP4A
	PUSH P,FSGN(B)
	PUSHJ P,FP3
	POP P,W1
	MOVE A,W2
	PUSHJ P,TEXT

FP7:	JUMPE A,FP7A2
	IDIVI A,12
	AOS TEM1
	HRLM B,(P)
	JUMPE A,FP7A1
	PUSHJ P,FP7
FP7A1:	HLRZ T,(P)
FP7B:	ADDI T,260
	JRST TOUT
FP7A:	PUSHJ P,FP7
	MOVEI T,"."
	JRST TOUT	;PRINT WITH A .
FP7A2:	MOVEI T,"0"
	JRST TOUT

	353473426555	;1.0E32
	266434157116	;1.0E16
FT8:	233575360400	;1.0E8
	216470400000	;1.0E4
	207620000000	;1.0E2
	204500000000	;1.0E1
FT:	201400000000	;1.0E0
	026637304365	;1.0E-32
	113715126246	;1.0E-16
	146527461671	;1.0E-8
	163643334273	;1.0E-4
	172507534122	;1.0E-2
FT01:	175631463146	;1.0E-1
FT0__FT01+1

FCP:	CAMLE A, FT0(C)
	CAMGE A, FT(C)
	XWD C,FT0

FSGN:	ASCII .E-.
	ASCII .E+.

TEXTT:	MOVE W1,T
TEXT:	TLNN W1,774000		;LEFT JUSTIFIED UNLESS LEFT CHAR IS NULL
	LSH W1,35		;OUTPUT ONE RIGHT JUST. CHR.
TEXT2:	MOVEI T,0
	LSHC T,7
	CAILE T,04		;EOT
	PUSHJ P,TOUT
	JUMPN W1,TEXT2
	POPJ P,

;RPH 7-29-72  TYPE OUT TTY INPUT BUFFERS
TEXTT9:	MOVE W1,T
TEXTT0:	MOVEI T,0
	LSHC T,11
	PUSH P,T
	LSH T,-7
	PUSH P,T
	SKIPA T,["^"]
	PUSHJ P,TOUT
	SOSL (P)
	JRST .-2
	POP P,(P)
	POP P,T
	ANDI T,177
	SKIPE T
	PUSHJ P,TOUT
	JUMPN W1,TEXTT0
	POPJ P,

	SUBTTL	EXEC DDT - PAPER TAPE MANIPULATIONS

IFE EDDT&3-3,<

;PUNCH SINGLE REGISTER  - CALLED BY $<CONTROL T>
PSR:	TLNN	F,ROF		;(NO REFS TO PSR???)
	JRST	ERR
	MOVEM	T,LWT
	PUSHJ	P,DEPRS
	HRRZM	R,DEFV		;R CONTAINS LLOCO
	MOVE	T,R
	JRST	PUN2

;PUNCH TAPE.  CALLED BY FIRST<LAST><CONTROL R>
PUNCH:	TLC	F,FAF+QF	;PUNCH CORE TO TAPE IN RANGE GIVEN
	TLCE	F,FAF+QF
	JRST	ERR		;ONE ARGUMENT MISSING
PUN2:	ADDI	T,1
	HRRZM	T,TEM1
	SUB	T,DEFV
	JUMPLE	T,ERR		;RANGE IS EMPTY

PUN1:	MOVEI	T,10
	PUSHJ	P,FEED
	HRRZ	R,DEFV
	IORI	R,37
	ADDI	R,1
	CAMLE	R,TEM1
	MOVE	R,TEM1
	EXCH	R,DEFV
	MOVE	T,R
	SUB	T,DEFV
	HRL	R,T
	JUMPGE	R,RET		;EXIT OF PUNCH

PBLK:	MOVE	T,R		;PUNCH ONE BLOCK
	SOS	W,T		;ADDRESS?
	PUSHJ	P,PWRD
PBLK1:	PUSHJ	P,FETCH
	JRST	ERR
	ADD	W,T
	PUSHJ	P,PWRD
	AOBJN	R,PBLK1
	MOVE	T,W
	PUSHJ	P,PWRD		;CHECKSUM
	JRST	PUN1

;PUNCH A LOADER - CALLED BY $<CONTROL Q>
LOADER:	TLNE	F,QF		;THIS PUNCHES A LOADER ONTO THE TAPE
	JRST	ERR
	MOVEI	T,400
	PUSHJ	P,FEED
	MOVE	R,LOADE		;AOBJN POINTER TO LOADER
LOAD1:	MOVE	T,0(R)
	PUSHJ	P,PWRD
	AOBJN	R,LOAD1
	MOVEI	T,100
LOAD2:	PUSHJ	P,FEED
	JRST	RET

;PUNCH END BLOCK - CALLED BY ADDR$<CONTROL S>
BLKEND:	TLNN	F,QF		;PUNCH A BLOCK END ONTO TAPE
	MOVE	T,[JRST 4,DDT]	;NO ARGUMENT GIVEN
	TLO	T,254000	;SET JRST IN LEFT HALF OF ARGUMENT
	PUSH	P,T
	MOVEI	T,100
	PUSHJ	P,FEED
	POP	P,T
	PUSHJ	P,PWRD
	PUSHJ	P,PWRD		;EXTRA WORD FOR READER TO STOP ON
	MOVEI	T,500		;FEED SOME MORE
	JRST	LOAD2

PWRD:	MOVEI	W1,6		;PUNCH A WORD FROM T.  CHARACTER COUNT
PWRD2:	ROT	T,6
	CONSZ	PTPP,20
	JRST	.-1		;WAIT FOR NOT BUSY
	CONO	PTPP,50		;SET DONE AND BINARY MODE
	DATAO	PTPP,T		;SHIP A CHARACTER
	SOJG	W1,PWRD2	;LOOP THRU WORD
	POPJ	P,

FEED:	CONSZ	PTPP,20
	JRST	.-1		;WAIT FOR NOT BUSY
	CONO	PTPP,10		;SET DONE
	DATAO	PTPP,FEED1	;SEND A ZERO (ONLY 8 BITS COUNT)
	SOJN	T,FEED
FEED1:	POPJ	P,0



;	PAPER TAPE LOADERS

LOADB:	

IFE EDDT&10,<				;PDP-6/20-LOADER VERSION
DATAI PTRR,1
	XWD -1,-22
DATAI PTRR,2
	CONSO PTRR,10
DATAI PTRR,3
	JRST 2
MOVE 4,37
HRLI 4,710441                          ;DATAI PTRR,0(1)
DATAI PTRR,5
	AOJN 1,2
DATAI PTRR,6
	JRST -6(4)
JRST 2


MOVE 0,1
CONSO PTRR,10
JRST -21(4)
DATAI PTRR,0(1)
ROT 0,1
ADD 0,(1)
AOBJN 1,-21(4)
CONSO PTRR,10
JRST -13(4)
DATAI PTRR,1
CAME 1,0
JRST 4,-6(4)
CONSO PTRR,10
JRST -6(4)
DATAI PTRR,1
JUMPL 1,-22(4)
CONO PTRR,0
JRST 1

>


IFN EDDT&10,<
PHASE 0				;RIM10B CHECKSUM LOADER
	XWD -16,0
BEG:	CONO PTRR,60
	HRRI AA,10
RD:	CONSO PTRR,10
	JRST .-1
	DATAI PTRR,@TBL1-RD+1(AA)
	XCT TBL1-RD+1(AA)
	XCT TBL2-RD+1(AA)
AA:	SOJA AA,
TBL1:	CAME CKSM,ADR
	ADD CKSM,1(ADR)
	SKIPL CKSM,ADR
TBL2:	JRST 4,BEG
	AOBJN ADR,RD
ADR:	JRST BEG+1
CKSM__ADR+1

DEPHASE
>
LOADE:	XWD LOADB-.,LOADB

;VERIFY AND CORE (LOAD TAPE INTO CORE)

;VERIFY TAPE - CALLED BY $<CONTROL V>
;LOAD TAPE INTO CORE - CALLED BY $Y

VERIFY:	TLO F,LTF
CORE:	PUSHJ P,SETUP1		;LOAD TAPES INTO CORE
	CONO PTRR,60
CORE1:	CONSO PTRR,10
	JRST .-1
	DATAI PTRR,T
	CAME T,LOADE-1		;WAIT TO SEE JRST 1
	JRST CORE1
	PUSHJ P,CRF
	PUSHJ P,BLOCKQ

CORE2:	PUSHJ P,GETW
	CAML R,DEFV
	CAML R,ULIMIT
	JRST VER3		;OUTSIDE OF LIMITS
	TLNE F,LTF		;VERIFY OR YANK?
	JRST VER2		;VERIFY
	PUSHJ P,DEP		;STUFF IN CORE
	JRST VER3

VER2:	MOVEM T,TEM2		;STORE TAPE WORD IN TEMP CELL
	PUSHJ P,FETCH		;GET WORD FROM CORE
	JRST ERR
	MOVEM T,TEM3
	XOR T,TEM2
	AND T,MSK
	JUMPE T,VER3		;VERIFY OK.
	PUSH P,S
	PUSH P,R
	HRRZ T,R
	PUSHJ P,PAD		;PRINT ADDRESS
	MOVEI T,257		;SLASH
	PUSHJ P,TOUT
	PUSHJ P,LCT
	MOVE T,TEM3		;CORE CONTENTS
	PUSHJ P,CONSYM
	PUSHJ P,LCT
	MOVE T,TEM2		;TAPE CONTENTS
	PUSHJ P,CONSYM
	PUSHJ P,CRF
	POP P,R
	POP P,S
VER3:	PUSHJ P,LISTEN		;SEE IF HE WANTS TO STOP YET
	AOJA R,CORE2
RUNEND:	PUSHJ P,BLOCKQ		;STOP.
	JRST .-1

GETW:	JUMPL S,GETW1
	PUSHJ P,BLOCKQ
GETW1:	MOVE T,1(S)
	AOBJP S,.+1
	POPJ P,0

BLOCKS:	CONO PTRR,60		;READ DATA BLOCKS
BLOCKQ:	CONSO PTRR,10
	JRST .-1
	DATAI PTRR,W
	JUMPL W,BLK1
	MOVEM W,STARTA
	CONO PTRR,0		;TURN OFF READER
	JRST DD1
BLK1:	MOVEM W,W1
	TLC W,777740
	TLCE W,777740
	JRST ERR		;BLOCK TOO BIG
	ADDI W,1
	HRRZM W,R
	HRRI W,BUFF-1
	MOVEM W,S
BLK2:	CONSO PTRR,10
	JRST .-1
	BLKI PTRR,W
	JRST BLK3
	ADD W1,0(W)
	JRST BLK2
BLK3:	ADD W1,0(W)
	CONSO PTRR,10
	JRST .-1
	DATAI PTRR,W
	CAMN W,W1
	POPJ P,0
	CONO PTRR,0		;CHECKSUM ERROR
	JRST 4,BLOCKS

;R CONTAINS RIGHT HALF OF FIRST LINE
;S CONTAINS (-WC,BUFF-1)

>;END OF PAPER TAPE DDT STUFF

	SUBTTL	DDT - TTY I/O EXEC MODE  - TOUT

IFN EDDT&1,<
IFN EDDT&100,<
; CONO/CONI BITS FOR 10/6 INTERFACE

; TRANSMITTER SIDE, CONO BITS

TPIASH__0	; SHIFT PIA ZERO POSITIONS (BITS 33-35)
TENA__20	; ENABLE TRANSMITTER INTERRUPTS
TCHNG__40	; TRANSMITTER ANY CHANGE (MUST BE ON IN CONO WORD)
TBIT37__10000	; 37TH OUTPUT BIT (MUST BE ON FOR FIRST WD OF HEADER)

; TRANSMITTER SIDE, CONI BITS

		; PIA IS IN LOW ORDER BITS (BITS 33-35)
TREQ__10	; INTERRUPT IS BEING REQUESTED
;TENA__20	; ENABLE TRANSMITTER INTERRUPTS

; RECEIVER SIDE, CONO BITS

RPIASH__6	; SHIFT PIA 6 POSITIONS (BITS 27-29)
RCLEAR__1000	; CLEARS "DATA MISSED" FLAG
RENA__2000	; ENABLE RECEIVER INTERRUPTS
RCHNG__4000	; ENABLE ANY CHANGE (MUST BE ON TO DO ANYTHING BUT RCLEAR)

; RECEIVER SIDE, CONI BITS

		; PIA COMES IN ON BITS 27-29
RREQ__1000	; INTERRUPT IS BEING REQUESTED
;RENA__2000	; ENABLE RECEIVER INTERRUPTS
RMISSED__4000	; DATA MISSED FLAG (CLEARED BY RCLEAR)
RBIT37__10000	; 37TH INPUT BIT (SHOULD BE ON IN FIRST WD OF HEADER)
>;IFN EDDT&100

TINSTR:	ILDB	T,STRING
	JUMPE	T,TIN3		;THERE IS NO CHR
IFE EDDT&100,<
	CONSZ	TTYY,40		;IS THERE TTY INPUT?
>; IFE EDDT&100
IFN EDDT&100,<
	CONSZ	SIX,RREQ	; ANY RECEIVER REQUEST?
>; IFN EDDT&100
	JRST	TIN3		;YES.  THAT MEANS FLUSH STRING PROCESSING.
	CAIE	T,15		;CR?
	JRST	TIN2		;NO.
	ILDB	T,STRING	;GET NEXT BYTE
	CAIN	T,12
	JRST	TIN4		;LF FOLLOWS CR.  THROW LF AWAY
	MOVSI	T,70000		;OOPS. NO LF THERE.  BACK UP THAT BYTE POINTER.
	ADDM	T,STRING
TIN4:	MOVEI	T,15		;REINVENT CR
	JRST	TIN2		;WE HAVE A CHARACTER.

TIN3:	SETZM	STRING		;SET STRING BYTE POINTER TO ZERO AND READ TTY
TIN:	SKIPE	STRING
	JRST	TINSTR		;USE STRING BYTE POINTER IF SET.
	PUSHJ	P,LISTEN	;WAIT FOR SOMETHING.
	JRST	.-1
TIN2:	CAIE	T,175
	CAIN	T,176
	MOVEI	T,33		;CHANGE ALL ALT MODES TO NEW
	CAIN	T,177
	JRST	WRONG
	TRNE	T,140		;SKIP IF THIS IS A NON-PRINTING CHR.
TOUT:	CAIG	T,4		;DON'T TYPE CHARACTERS NULL, CTRL A,B,C OR D.
	POPJ	P,
	SKIPE	OUTRTN
	JRST	@OUTRTN		;IF OUTRTN IS SET, USE IT.  (RETURN VIA POPJ P,)
	SKIPE	OUTLPT
	JRST	LPOUT		;DO LPT OUTPUT THING INSTEAD
	ANDI	T,177		;CHARACTER ONLY
	SKIPE	KLFLG		;KL10?
	JRST	XTKL		;YES.  OUTPUT VIA DTE20/PDP-11
	HRLM	T,(P)
	IMULI	T,200401
	AND	T,[11111111]
	IMUL	T,[11111111]
	HLR	T,(P)
	TLNE	T,10
	TRC	T,200
IFE EDDT&100,<
	CONSZ	TTYY,20
	JRST	.-1
	DATAO	TTYY,T
>; IFE EDDT&100
IFN EDDT&100,<
	CONO SIX,TCHNG!TBIT37	; TURN ON CONTROL BIT
	HRLI T,600015		; PUT IN DDT CHR CODE
	DATAO SIX,T
	CONSO SIX,TREQ		; WAIT FOR IT TO GO OUT
	JRST .-1
>; IFN EDDT&100
	ANDI	T,177		;FLUSH PARITY BIT AND RETURN.
	POPJ	P,


LPOUT:	IDPB	T,LPPTR			;EXEC MODE LPT OUTPUT FEATURE
	SOSLE	LPCNT
	POPJ	P,
	PUSH	P,T
	MOVEI	T,5
	MOVEM	T,LPCNT
	DATAO	LPT,LPWRD
	MOVE	T,[POINT 7,LPWRD]
	MOVEM	T,LPPTR
	CONSO	LPT,100
	JRST	.-1
	POP	P,T
	POPJ	P,

LPPTR:	POINT 7,LPWRD
LPWRD:	0
LPCNT:	5

LISTEN:	SKIPE	KLFLG		;KL10?
	JRST	XTKL2
IFE EDDT&100,<
	CONSO	TTYY,40		;LISTEN FOR TTY
>; IFE EDDT&100
IFN EDDT&100,<
	CONSO	SIX,RREQ
>; IFN EDDT&100
	POPJ	P,
IFE EDDT&100,<
	DATAI	TTYY,T
>; IFE EDDT&100
IFN EDDT&100,<
	DATAI	SIX,T
>; IFN EDDT&100
	ANDI	T,177
	JRST	CPOPJ1

XTKL2:	PUSH	P,0
	MOVEI	0,3400		;DDT MODE INPUT REQUEST TO DTE20/PDP-11
	PUSHJ	P,DTEXX
	MOVE	T,0
	POP	P,0
	ANDI	T,177
	JUMPE	T,CPOPJ
	JRST	CPOPJ1

TTYRET:	SKIPE	KLFLG		;KL10?
	JRST	KLSRT		;SETUP DTE20
IFE EDDT&100,<
	MOVEI	T,3410
TTY1:	MOVEI	W2,40000
	CONSZ	TTYY,120
	SOJG	W2,.-1
	CONI	TTYY,SAVTTY
	DATAI	TTYY,W2
	HRLM	W2,SAVTTY
	CONO	TTYY,(T)
>; IFE EDDT&100
IFN EDDT&100,<
	CONI	SIX,SAVTTY
	CONO	SIX,TCHNG!RCHNG!RCLEAR
>; IFN EDDT&100
	POPJ	P,

TTYLEV:	SKIPE	KLFLG
	JRST	KLLEV
	MOVE	T,SAVTTY
IFE EDDT&100,<
	TRZ	T,160
	TRO	T,3600
	TRNE	T,10
	TRZ	T,200
	JRST	TTY1
>; IFE EDDT&100
IFN EDDT&100,<
	ANDI	T,TENA!<7TPIASH>!RENA!<7RPIASH>
	CONO	SIX,TCHNG!RCHNG(T)
	POPJ	P,
>; IFN EDDT&100


TEXIN:	PUSHJ	P,TIN		;GET CHARACTER
	TRNN	T,140		;SKIP IF CHARACTER HAS ALREADY BEEN ECHOED
	JRST	TOUT		;GO ECHO CHARACTER.
	POPJ	P,


;KL10/DTE20 ROUTINES

KLLEV:	PUSH	P,0
	MOVEI	0,4400		;PREPARE TO SET TTY MONITOR MODE.
	SKIPE	KLTMON		;SKIP IF WE WEREN'T IN MONITOR MODE BEFORE.
	PUSHJ	P,DTEXX		;RESTORE STATE OF MONITOR MODE.
	MOVEI	0,3000		;PRINT NORMAL.
	PUSHJ	P,DTEXX
	POP	P,0
	POPJ	P,

KLSRT:	PUSH	P,T
	PUSH	P,0
	MOVE	T,KEPTAD
	SETZM	DTCMD(T)	;NO COMMAND TO THE 11
	SETZM	DTF11(T)
	MOVEI	0,5400
	PUSHJ	P,DTEXX		;GET STATE OF MONITOR TTY MODE
	MOVEM	0,KLTMON	;KL10 TTY MONITOR STATE
	MOVEI	0,5000
	PUSHJ	P,DTEXX		;CLEAR MONITOR STATE
	MOVEI	0,3001		;FORCE TTY OUTPUT
	PUSHJ	P,DTEXX
	POP	P,0
	POP	P,T
	POPJ	P,

>

	SUBTTL	DDT - TTY I/O USER MODE

IFE EDDT&1,<

TIN:	MOVE	T,POUTBF	;GET NEXT CHARACTER ROUTINE
	CAME	T,[POINT 7,INBFF]
	PUSHJ	P,FINOUT
	SKIPE	STRING
	JRST	TINSTR		;INPUT FROM STRING BYTE POINTER
;	ILDB	T,PINBFF
	INCHRW	T		;RPH 5-22-71
	ANDI T,177		;FLUSH CONTROL AND META BITS
	CAIN	T,15
	INCHRW	1(P)		;THROW AWAY THE LF THAT FOLLOWS
TIN3:	CAIE	T,176
	CAIN	T,175
	MOVEI	T,33		;CHANGE TO NEW ALT MODE
	CAIN	T,177
	JRST	WRONG
	JUMPN	T,CPOPJ		;RETURN NON-NULL CHARACTER
;	MOVE	T,[POINT 7,INBFF]
;	MOVEM	T,PINBFF
;	CALL	T,[SIXBIT /DDTIN/]
TIN2:	SETZM	STRING
	JRST	TIN

TINSTR:	ILDB	T,STRING	;READ FROM STRING
	JUMPE	T,TIN2		;ALL DONE
	CAIN	T,33		;NOT THIS ONE STUPID
	MOVEI	T,"$"		;DO IS AS $
	SKIPN	OUTRTN		;ARE WE ECHOING SPECIAL?
	JRST	TIN4		;NO.  ECHO NORMALLY
	PUSHJ	P,@OUTRTN
	JRST	TIN3

TIN4:	IDPB	T,POUTBF	;DUPLEX
	JRST	TIN3		;AND EAT

TOUT:	JUMPE	T,CPOPJ		;TEXT OUTPUT
	SKIPE	OUTRTN
	JRST	@OUTRTN		;USE OUTRTN IF SET
	CAIE	T,177		;IS IT THIS GODDAMN CHAR?
	JRST	NOTDEL		;NO
	SETO	T,
	TTYUUO	6,T
	TLNE	T,526000	;WILL HE IGNORE A 177?
	POPJ	P,		;NO, SKIP IT
	MOVEI	T,177		;CHANGE BACK TO 177
NOTDEL:	IDPB	T,POUTBF
	CAIE	T,12
	POPJ	P,
TTYLEV:
FINOUT:	MOVEI	T,0
	IDPB	T,POUTBF
	MOVE	T,[POINT 7,INBFF]
;	MOVEM	T,PINBFF
	MOVEM	T,POUTBF
;	CALL	T,[SIXBIT /DDTOUT/]
	OUTSTR	INBFF
	SETZM	INBFF
	POPJ	P,

;PINBFF:	POINT 7,INBFF
POUTBF:	POINT 7,INBFF

IFE UEDDTS,<
LISTEN:	INCHRS T
	POPJ P,
	CLRBFI
	JRST CPOPJ1
>;UEDDTS

IFN UEDDTS,<
LISTEN:	POPJ P,		;DON'T WASTE TIME CHECKING TTY
>;UEDDTS	RPH 7-30-72


INBFF:	BLOCK 31

TTYRET:	MOVE T,[POINT 7,INBFF]
	MOVEM T,POUTBF
;	MOVEM T,PINBFF
	SETZM  INBFF
	POPJ P,


TEXIN__TIN
>

	SUBTTL	DDT - FLAG MODE OUTPUT

;PRINT IN FLAG MODE
PRFLAG:	HRLI	R,-=18		;SET FOR HALF WORD
	SETZM	FLGNUM#
	SETZM	EXFLAG#		;NO ! AND NO NUMERIC PART YET
PRFLG1:	TDNN	T,W1		;IS THE BIT SET?
	JRST	PRFLG3		;NO.
	SKIPN	(R)		;DOES IT HAVE A NAME?
	JRST	PRFLG2		;NOPE. SET BIT IN FLGNUM TO PRINT AS NUMBER
	PUSH	P,T
	PUSH	P,W1
	MOVEI	T,"!"
	SKIPE	EXFLAG		;SKIP IF NOTHING'S BEEN TYPED YET
	PUSHJ	P,TOUT
	MOVE	T,(R)
	PUSHJ	P,SPT1		;TYPE RADIX50
	SETOM	EXFLAG		;WE'LL NEED AN ! BEFORE NEXT PART
	POP	P,W1
	POP	P,T
	JRST	PRFLG3

PRFLG2:	IORM	W1,FLGNUM	;SAVE BIT AS PART OF THE NUMBER
PRFLG3:	LSH	W1,-1
	AOBJN	R,PRFLG1
	SKIPN	FLGNUM		;ANY NUMERIC PART LEFT OVER?
	POPJ	P,
	PUSH	P,T
	PUSH	P,W1
	MOVEI	T,"!"
	SKIPE	EXFLAG
	PUSHJ	P,TOUT
	MOVE	T,FLGNUM
	TRNN	T,-1		;CHECK TO SEE IF LEFT HALF
	MOVSS	T
	PUSHJ	P,TOCC
	POP	P,W1
	POP	P,T
	SETOM	EXFLAG		;FLAG THAT SOMETHING'S BEEN TYPED
	POPJ	P,

;SETUP SCH AND FLGPNT FOR $J, $L AND $V COMMANDS

GETPTR:	SKIPN	R,FLGPTR
	POPJ	P,
FLGSLP:	HRRZM	R,FLGPNT#	;STORE ADDRESS OF RADIX50 TABLE OF 36 WORDS
	TRNE	F,Q2F		;NUMBER TYPED?
	SOSGE	WRD2		;YES. DECREMENT COUNT (ZERO INDEXING)
	JRST	CPOPJ1
	HLRZS	R		;GET POINTER TO NEXT
	JUMPE	R,CPOPJ		;RETURN UNHAPPY IF NO NEXT
	SKIPE	R,(R)		;ADVANCE TO NEXT
	JRST	FLGSLP		;LOOP
	POPJ	P,		;THERE WAS NO NEXT.

LFTT:	SKIPA	SCH,[LFPIN]
RFTT:	MOVEI	SCH,RFPIN
	JRST	.+2
FLGMOD:	MOVEI	SCH,FLGOUT
	PUSHJ	P,GETPTR
	SETZM	FLGPNT
	JRST	BASE1

;OUTPUT ROUTINE FOR $J MODE
FLGOUT:	SKIPN	R,FLGPNT
	JRST	HLFW		;IF NO POINTER USE HALFWORD
	MOVSI	W1,400000	;SET FOR HIGH ORDER BIT
FLGOU1:	PUSHJ	P,PRFLAG
	JUMPE	W1,FLGOU2	;JUMP IF WE'VE DONE BOTH HALVES
	SKIPN	EXFLAG		;ANYTHING DONE IN LH?
	JRST	FLGOU1		;NOPE. DO RH.
	PUSH	P,T
	MOVEI	T,","
	PUSHJ	P,TOUT
	PUSHJ	P,TOUT		;TYPE ,,
	POP	P,T
	JRST	FLGOU1

FLGOU2:	SKIPE	EXFLAG		;WAS THERE SOMETHING PRINTED
	POPJ	P,		;YES, EXIT
	MOVEI	T,"0"		;NO, PRINT A 0
	JRST	TOUT

;OUTPUT ROUTINE FOR $L AND $V MODES
RLFFLG:	SKIPN	R,FLGPNT	;SCH HAS LFPIN OR RFPIN.  CALLED FROM PI8
	JRST	PI8A		;NONE THERE
	CAIN	SCH,RFPIN
	ADDI	R,=18		;START WITH RIGHT SIDE FLAGS
	MOVEI	W1,400000
	PUSHJ	P,PRFLAG
	PUSHJ	P,FLGOU2	;PRINT ZERO IF NOTHING WAS OUTPUT
	JRST	PI7

	SUBTTL	DDT - BYTE OUTPUT $nO
BITO:	MOVEI	R,BITT		;PATCH FOR BYTE OUTPUT WW 12-9-66
	HRRZI	AR,TOC
	TRZN	F,Q2F
	JRST	ERR		;NEEDED TO ALT-NUMBER-O
	MOVE	T,WRD2
	MOVEM	T,SVBTS		;SAVE BYTE SIZE
	MOVEI	T,=36
	IDIV	T,WRD2
	SKIPE	T+1
	ADDI	T,1
	MOVEM	T,SVBTS2	;NUMBER OF BYTES IN WORD
	HRRZ	SCH,R
	JRST	BASE1

BITT:	MOVE	T+1,T
	SKIPN	SVBTS		;0 IS MASK CONDITION
	JRST	BITTM
	MOVE	T,SVBTS2
	MOVEM	T,SVBT2
	MOVEM	T+1,SVBT3
BITT2:	MOVEI T,0
	MOVE T+2,SVBTS
	LSHC T,(T+2)
	MOVEM T+1,SVBT3
	CAIE AR,PADSO
	PUSHJ P,FTOC
	CAIE AR,TOC
	PUSHJ P,PIN
	SOSG SVBT2
	POPJ P,
	MOVEI T,","
	PUSHJ P,TOUT
	MOVE T+1,SVBT3
	JRST BITT2


BITTM:	MOVEI T,=36	;SET OUTPUT COUNT
	MOVEM T,SVBT3
	MOVE T+2,BMASK	;GET MASK BITS
BITTM1:	MOVEI T,0	;SET TO SHIFT WORD
	SKIPL T+2	;START WITH 1 BITS
	SETCA T+2,
BITTM2:	LSHC T,1	;NEXT BIT
	LSH T+2,1	;SHIFT MASK
	SOSLE SVBT3	;ALL BITS GONE?
	JUMPL T+2,BITTM2	;PART OF SAME FIELD
	MOVEM T+2,SVBT2	;SAVE MASK
	MOVEM T+1,SVBT4	;AND PARTIAL MASK
	CAIE AR,PADSO	;DO PROPER OUTPUT
	PUSHJ P,FTOC
	CAIE AR,TOC
	PUSHJ P,PIN
	SKIPG SVBT3	;ANY MORE?
	POPJ P,		;NO, RETURN
	MOVEI T,","	;COMMA
	PUSHJ P,TOUT
	MOVE T+1,SVBT4	;GET WORD BACK
	MOVE T+2,SVBT2	;AND MASK
	JRST BITTM1	;PRINT NEXT FIELD

SVBT4:	0
SVBTS:	0
SVBTS2:	0
SVBT3:	0
SVBT2:	0	;END OF PATCH  WW 12-9-66


	SUBTTL	DDT - CHARACTER DISPATCH TABLE

BDISP:	POINT 12,DISP(R),11
	POINT 12,DISP(R),23
	POINT 12,DISP(R),35

DEFINE D(Z1,Z2,Z3)<((Z1-DDT)=24)!((Z2-DDT)=12)!(Z3-DDT)>

IFN EDDT&3-3,<			;ASSEMBLE IF NOT PAPER TAPE EXEC DDT
	PUNCH__ERR
	PSR__ERR
	BLKEND__ERR
	LOADER__ERR
	VERIFY__ERR
	CORE__ERR>

IFE UEDDTS,<
	JOBSET__ERR
	DARRW__ERR>


DISP:	
D ERR,DARRW,ERR			;NL    
D ERR,ERR,JOBSET		;     
D ERR,ERR,VARRW			;     
D TAB,LINEF,ERR			;HT LF VT
D ERR,CARR,ERR			;FF CR  
D ERR,ERR,LOADER		;        CONTROL O,P,Q
D PUNCH,BLKEND,PSR		;        CONTROL R,S,T
D ERR,VERIFY,ERR		;        CONTROL U,V,W
D ERR,ERR,ERR			;     
D CONTROL,ERR,LTAB		;     
D ERR,ERR,SPACE			;    SP
D SUPTYO,TEXI,ASSEM		; !  "  #
D DOLLAR,BYTI,SETBLK		; $  %  &
D DIVD,LPRN,RPRN		; '  (  )
D MULT,PLUS,ACCF		; *  +  ,
D MINUS,PERIOD,SLASH		; -  .  /
D NUM,NUM,NUM			; 0  1  2
D NUM,NUM,NUM			; 3  4  5
D NUM,NUM,NUM			; 6  7  8
D NUM,TAG,SEMIC			; 9  :  ;
D FIRARG,EQUAL,ULIM		; <  =  >
D QUESTN,INDIRECT,ABSA		; ?  @  A
D BPS,CON,SYMD			; B  C  D
D EFFEC,SFLOT,STR		; E  F  G
D HWRDS,PILOC,FLGMOD		; H  I  J
D KILL,LFTT,MASK		; K  L  M
D NWORD,BITO,PROCEDE		; N  O  P
D QUAN,RELA,SYMBOL		; Q  R  S
D TEXO,UCON,RFTT		; T  U  V
D WORD,XEC,CORE			; W  X  Y
D ZERO,OCON,ICON		; Z  [  \
D OSYM,VARRW,PSYM		; ]  ^  _

;LOWERCASE LETTERS ARE NEVER USED BY THE TIME WE GET HERE.

	SUBTTL DDT - OP DECODER

;REG 1/14/75  It seems like 10 bit bytes are actually used below.
;		Added FxxRI and TTYUUO.

;DESCRIPTION OF OP DECODER FOR DDT:
;
;         THE ENTIRE INSTRUCTION SET FOR THE PDP-6 CAN BE COMPACTED INTO
;A SPACE MUCH SMALLER THAN ONE REGISTER FOR EVERY SYMBOL.  THIS OCCURS
;BECAUSE OF THE MACHINE ORGANIZATION AND INSTRUCTION MNEMONICS CHOSEN
;FOR THE PDP-6.  FOR EXAMPLE, IF BITS (0-2) OF AN INSTRUCTION EQUAL
;101(2) THE INSTRUCTION IS A HALF WORD INSTRUCTION AND AN "H" MAY
;BE ASSUMED. "T" MAY BE ASSUMED FOR ALL TEST INSTRUCTIONS (WHICH
;BEGIN WITH 110(2).
;
;     	THE TABLE TBL IN DDT CONSISTS OF 9 BIT BYTES, 4 TO A WORD.
;THE NUMBERS IN THE BYTES HAVE THE FOLLOWING SIGNIFICANCE:
;0-37(8):	THIS IS A DISPATCH COMMAND FOR THE OP-DECODER INTERPRETER.
;	LET THE RIGHT MOST TWO BITS EQUAL N; LET THE NEXT 3 BITS
;	EQUAL P.
;
;	THE CONTENTS OF INST (INSTRUCTION) CONTAIN IN THE RIGHT
;	MOST NINE BITS THE BINARY FOR THE MACHINE INSTRUCTION.
;	P AND N REFER TO THE CONTENTS OF INST, AND THE OP DECODER
;	WILL PRODUCE AN ANSWER D GIVEN P, N, AND THE CONTENTS
;	OF INSTX N+1 GIVES THE NUMBER OF BITS IN INST; P GIVES THE
;	POSITION (FROM THE RIGHT EDGE) OF THE N+1 BITS.
;
;	EXAMPLE: P = 6
;	         N = 2
;
;;	C(INST) = .010 101 100(2)
;
;	THE RESULT- D = 010(2) = 2(8)
;
;	D IS USED AS A DISPATCH ON THE NEXT BYTES IN THE TABLE.
;	IF D = 5, 5 BYTES IN THE TABLE (DON'T COUNT THE BYTES WHICH
;	PRINT TEXT, 41-72(8)) ARE SKIPPED OVER AND THE 6TH BYTE RESUMES
;	THE INTERPRETATION.
;
;40(8)	THIS IS A STOP CODE; WHEN THIS IS REACHED INTERPRETATION
;	IS FINISHED.
;41(8)-72(8)      THE ALPHABET IS ENCODED INTO THIS RANGE.
;	        41- A
;	        42- B
;	        72- Z
;	        WHEN A BYTE IN THIS RANGE IS REACHED, ITS CORRESPONDING
;	        LETTER IS TYPED.
;
;73(8)-777(8)     THIS IS A TRANSFER BYTE.  IF THE BYTE IN THIS RANGE IS
;	        CONSIDERED TO BE A, TRANSFER INTERPRETATION TO THE A-73(8)RD
;	        BYTE IN THE TABLE.
;
;Macros used to assemble the table TBL:
; 1.   "P" followed by a number assembles a dispatch byte.  The first 
;      digit is the position; the second digit is the size.
; 2.   "S" assembles a stop code.
; 3.   "G" followed by a symbolic name assembles a transfer to that
;      symbolically named byte.
; 4.   "T" followed by a string of letters (terminated by a comma)
;      assembles a string of bytes, each byte being one letter.
; 5.   "L" followed by a symbolic name labels the next byte with that
;      symbolic name.
;
;EXAMPLE OF BINARY TO SYMBOLIC DECODING:
;      THE MACHINE CODE FOR JRST IS 254
;          INST    0  1  0  1  0  1  1  0  0
;      THE INTERPRETER STARTS WITH THE FIRST BYTE IN THE TABLE (63^).
;      THE RESULT OF APPLYING THIS TO C(INST) GIVES 2.  SKIPPING OVER
;      2 BYTES IN THE TABLE AND INTERPRETING THE THIRD RESULTS IN
;      HAK/ BEING INTERPRETED.  AT HAK:, THERE IS A 33^.  APPLYING
;      THIS TO C(INST) RESULTS IN 5 NON PRINTING BYTES BEING SKIPPED
;      OVER:
;          1.  MV/
;               MOV      PRINTING TEXT
;          2.  MO/
;          3.  ML/
;          4.  DV/
;          5.  SH/
;
;      H1/ IS THE NEXT BYTE INTERPRETER.  AT H1: 03^ IS FOUND SO
;      4 BYTES ARE SKIPPED OVER:
;              EXC      PRINTING TEXT
;          1.  S3/
;              BL       PRINTING TEXT
;              T        PRINTING TEXT
;          2.  .
;          3.  AO/
;          4.  AOB/
;          NEXT, THE LETTERS JRS ARE TYPED OUT.  THEN T/ IS FOUND.  AT
;	   T: A T IS TYPED OUT; THEN A "." IS FOUND AND EVERYTHING STOPS.
;
;      THE TABLE IS ALSO USED GOING FROM SYMBOLIC TO BINARY BUT A
;      TREE SEARCH METHOD IS USED.

BEGIN OPDEFS

DEFINE P (A)
<OUTP A&70/2+A&7-1
>
DEFINE G (A)
<OUTP A+73
>
DEFINE T (A)
<FOR B<A> <OUTP "B"-40
>>
DEFINE S (Q)
<OUTP 40
>
DEFINE L (A)
<IFGE CLOC+73-2000,<PRINTX OPTABLE TOO LONG>
A__CLOC
>

;TO GET THE EFFECT OF TWO PASSES, "TABLE" IS EXPANDED ONCE TO GET THE LABEL
;DEFINITIONS WITHOUT DATA GENERATION, THEN "OUTP" IS REDEFINED AND "TABLE"
;EXPANDED ONCE MORE.

DEFINE OUTP (A)
<CLOC__CLOC+1
>
DEFINE BYT9 (A)
<FOR B(A) <B
>>

DEFINE TABLE <
BYT9 <P 63,G %UUO,G %FLO,G %HAK,G %ACCP,G %BOOLE,T H,G %HWT,T T,G %ACBM>
BYT9 <P 21,G %BD,T CON,P 11,G %OI,T S,P 01,G %Z,G %O>
BYT9 <L %BD,P 01,T BLK,G %IO,T DATA,L %IO,P 11,G %I,G %O,L %OI,P 1,G %O,G %I>
BYT9 <L %UUO,P 51,S,P 32,G %U40,G %U50,G %U60,P 21,G %U703,P 11,G %USET>
BYT9 <P 1,T LOOKU,G %P,T ENTE,G %R,L %USET,T USET,P 1,G %I,G %O>
BYT9 <L %U40,P 3,G %U47,T INI,G %T,S,T SPCWA,G %R,S,S,S,L %U47,T CALL>
BYT9 <P 1,S,G %I,L %U60,P 21,G %U603,P 1,T IN,G %BPUT,T OUT,L %BPUT>
BYT9 <P 11,T BU,L %F,T F,S,T PU,G %T,L %U50,P 3,T OPE,G %N,T TTYUU,G %O,S,S,S>
BYT9 <T RENAM,G %E,T I,G %N,T OU,G %T,L %U603,P 1,G %U6062,T STAT>
BYT9 <P 11,L %O,T O,S,L %Z,T Z,S,L %U6062,P 11,T S,G %U62,T G,L %U62>
BYT9 <T ETST,G %S,L %U703,P 2,T CLOS,G %E,T RELEA,G %S,T MTAP,G %E>
BYT9 <T UGET,G %F>

BYT9 <L %FLO,P 51,G %BYTE,T F,P 32,T AD,G %A,T SB,G %A,T MP,G %A,T DV>
BYT9 <L %A,P 21,G %LMB,T R,G %IMB,L %LMB,P 2,S,L %L,T L,S,L %M,T M,S,L %B>
BYT9 <L %B,T B,S,L %BYTE,P 32,G %100,G %110,G %120>
BYT9 <P 3,T UF,G %PA,T DF,G %N,T FS,G %C,T IB,L %P,T P,S>
BYT9 <T I,G %LD,L %LD,T LD,G %B,T I,G %DP,L %DP,T DP,G %B>
BYT9 <L %110,T D,P 3,T FA,L %D,T D,S,T FS,G %B,T FM,G %P,T FDV,S>
BYT9 <T AD,G %D,T SU,G %B,T MUL,S,T DIV,S>
BYT9 <L %100,P 21,S,P 2,T JSY,G %S,T ADJS,G %P,S,S>
BYT9 <L %120,P 3,T DMOV,G %E,T DMOV,G %N,T FIX,S,T EXTEND,S>
BYT9 <T DMOVE,G %M,T DMOVN,G %M,T FIXR,S,T FLTR,S>

BYT9 <L %HAK,P 33,G %MV,L %MV,T MOV,G %MO,G %ML,G %DV,G %SH,G %H1>
BYT9 <G %JP,P 21,T ADD,G %IMB,T SU,L %BIMB,T B,L %IMB,P 2>
BYT9 <S,L %I,T I,S,G %M,G %B,L %MO,P 22,L %EIMS,T E,G %IMS,T S>
BYT9 <G %IMS,T N,G %IMS,T M,L %IMS,P 2,S,G %I,G %M,L %S,T S,S>
BYT9 <L %ML,P 21,T I,G %ML1,L %ML1,T MUL,G %IMB,L %DV,P 21,T I,G %DV1>
BYT9 <L %DV1,T DI,L %DV2,T V,G %IMB,L %H1,P 3,T EXC,G %S3,T BL,L %T>
BYT9 <T T,S,G %AO,L %AO,T AOBJ,G %AOB,T JRS,G %T,T JFC,G %L,T XC,G %T>
BYT9 <T MA,G %P,L %AOB,P 1,G %P,G %N,L %JP,P 3,G %PU,L %PU,T PUSH>
BYT9 <G %PUS,G %PO,L %PO,T POP,G %POP,T JS,L %R,T R,S,T JS,G %P>
BYT9 <T JS,L %PA,T A,S,T JR,G %PA,L %PUS,P 1,L %J,T J,S,S,L %POP>
BYT9 <P 1,S,G %J,L %SH,P 2,T A,G %S2,T ROT,G %S1,T L,L %S2,T S,L %S3>
BYT9 <T H,G %S1,P 21,T JFF,G %O,T KAFIX,S,L %S1,P 21,S,L %C,T C,S>

BYT9 <L %ACCP,P 42,T CA,G %CA1,G %SJ,T A,G %JS,T S,L %JS,T O,P 31>
BYT9 <T J,G %COMP,T S,G %COMP,L %CA1,P 31,T I,G %COMP,T M,G %COMP>
BYT9 <L %SJ,P 31,T JUM,G %PSJ,T SKI,L %PSJ,T P,L %COMP>
BYT9 <P 3,S,G %L,L %E,T E,S,T L,G %E,G %PA,T G,G %E,L %N,T N,S,T G,S>

BYT9 <L %HWT,P 51,G %HW1,P 21,T R,G %HW2,T L,L %HW2,T R,G %HW3,L %HW1>
BYT9 <P 21,T L,G %HW4,T R,L %HW4,T L,L %HW3,P 32,G %IMS,T Z,G %IMS,T O>
BYT9 <G %IMS,G %EIMS>

BYT9 <L %ACBM,P 31,G %AC1,P 1,T D,G %AC2,T S,G %AC2,L %AC1,P 1,T R>
BYT9 <G %AC2,T L,L %AC2,P 42,T N,G %EAN,T Z,G %EAN,T C,G %EAN,T O>
BYT9 <L %EAN,P 12,S,G %E,G %PA,G %N>

BYT9 <L %CB,T C,G %BIMB,L %BOOLE,P 24,G %ST,L %AN,T AND,G %B2,G %AN>
BYT9 <G %ST,G %AN,G %ST,T X,L %OR,T OR,G %B2,T I,G %OR,G %AN,T EQ>
BYT9 <G %DV2,G %ST,G %OR,G %ST,G %OR,G %OR,L %ST,T SET,L %B2>
BYT9 <P 24,T Z,G %IMB,G %IMB,L %CA,T C,G %TA,L %TM,T M,G %IMB,L %CM>
BYT9 <T C,G %TM,L %TA,T A,G %IMB,G %IMB,G %IMB,T C,G %BIMB,G %IMB,G %CA>
BYT9 <G %CA,G %CM,G %CM,G %CB,T O,G %IMB>>
;END OF THE DEFINITION OF "TABLE"

;EXPAND "TABLE" ONCE TO GET THE LABELS DEFINED.

CLOC__0		;INITIALIZE LOCATION COUNTER.
XLIST
TABLE
LIST

;NOW REDEFINE "OUTP" TO CAUSE NEXT EXPANSION OF "TABLE" TO GENERATE DATA

DEFINE OUTP (A)
<BINRY__BINRY=10+A
BINC__BINC-1
IFE BINC,<
BINRY6
BINRY__0
BINC__3
>
CLOC__CLOC+1
>

BINRY__0
BINC__3
CLOC__0
^TBL:		;CAUSE ACTUAL EXPANSION OF THE TABLE TO OCCUR HERE.
XLIST
TABLE
REPEAT BINC,<BINRY__BINRY=10>
IFN BINRY,<BINRY6>
LIST

BEND OPDEFS

PNTR:	INST		;POINTER TO BITS IN INST
INST:	0		;BINARY FOR INSTRUCTION
CHP:	0		;CHAR POINTER INTO TXT, TXT+1
TXT:	BLOCK 2		;STORE INPUT TEXT FOR OPEVAL
SAVPDL:	0		;SAVE PUSH DOWN LIST POINTER

;TABLE USED TO GET NEXT BYTE POINTER FOR TRANSFER BYTE
BTAB:	POINT 10,TBL
	POINT 10,TBL,9
	POINT 10,TBL,19

OPEVAL:	MOVEI T,0		;EVALUATE FOR AN OP CODE
	IDPB T,CHP
	MOVEM P,SAVPDL
	TRZA F,OUTF
OPTYPE:	TRO F,OUTF		;TYPE AN OPCODE SYMBOLICALLY
	LSH T,-33
	MOVEM T,INST		;GET OPCODE INTO RIGHT 9 BITS
	MOVE T,[XWD 440700,TXT]
	MOVEM T,CHP		;FOR OPEVAL,SETUP POINTER TO INPUT TEXT
	TRZ F,ITF		;CLEAR INSTRUCTION TYPED FLAG
	SETZB  R,W1
	MOVE W2,BTAB
DC1:	ILDB T,W2		;GET NEXT BYTE IN TBL
	CAILE T,40
	CAIL T,73
	SOJGE R,DC1		;SKIP OVER # BYTES = C(R)
	JUMPG R,DC1		;SKIP OVER ALPHA TEXT WITHOUT COUNTING
	SUBI T,40
	JUMPE T,DECX		;TRANSFER ON ASTOP CODE
	JUMPG T,DC2
	DPB T,[XWD 340500,PNTR]	;SETUP R ON A DISPATCH BYTE
	TRZ T,-4
	AOS T
	DPB T,[XWD 300600,PNTR]
	TRNN F,OUTF
	JRST DC6		;FOR OPEVAL ONLY
	LDB R,PNTR		;GET # BYTES TO SKIP OVER
	JRST DC1

DC2:	HRREI T,-33(T)
	JUMPL T,DECT		;TYPE OUT A LETTER
	MOVE W1,T		;BYTE IS A TRANSFER
	IDIVI W1,3		;NUMBER OF BYTES/WORD IN TABLE.
	MOVE W2,BTAB(W2)	;CALCULATE POINTER TO NEXT BYTE
	ADDI W2,(W1)
	JRST DC1

DECT:	TRNE F,OUTF
	JRST DC8	;TYPE OUT A LETTER
	ILDB W1,CHP	;GET NEXT INPUT LETTER
	CAIE W1,133(T)	;COMPARE WITH ASSUMED NEXT LETTER
	JRST NOMAT	;DOESNT MATCH
	JRST DC1	;MATCHES, TRY NEXT

DECX:	TRNE F,OUTF	;STOP (CODE 40) HAS BEEN SEEN
	POPJ P,		;IF FOR OUTPUT, RETURN
	ILDB W1,CHP	;GET NEXT INPUT CHAR IF ANY
	JUMPE W1,DC7	;DOES # OF CHARS MATCH
NOMAT:	POP P,R		;NO, BACK UP AND TRY SOME MORE
	POP P,W2
	POP P,PNTR
	POP P,CHP
NOMAT1:	AOS R		;ASSUME NEXT NUMBER FOR BIN VALUE
	DPB R,PNTR	;STUFF INTO ANSWER
	LDB R,PNTR
	JUMPN R,DC6AA	;IF =0, BYTE WAS TOO BIG
	CAME P,SAVPDL
	JRST NOMAT	;NOT AT TOP LEVEL
	POPJ P,		;UNDEFINED, FINALLY

DC6:	MOVEI R,0	;ASSUME 0 FOR INITIAL BINARY VALUE
	DPB R,PNTR
DC6AA:	CAMN P,SAVPDL
	JRST DC6BB
	LDB T,-2(P)	;OLD VALUE OF PNTR
	CAME T,(P)
	JRST NOMAT1
DC6BB:	PUSH P,CHP
	PUSH P,PNTR
	PUSH P,W2
	PUSH P,R
	JRST DC1

DC7:	MOVE P,SAVPDL		;RESTORE PUSH DOWN POINTER
	MOVE T,INST
	LSH T,33		;PUSH BINARY INTO POSITION FOR OPEVAL
	TLC T,700000
	TLCE T,700000
	JRST CPOPJ1
	SETOM IOTFLG	;IT IS AN IOT
	LDB R,[POINT 3,T,8]
	DPB R,[POINT 10,T,12]	;ONLY DONE FOR IO INSTRUCTIONS
	JRST CPOPJ1

DC8:	TRO F,ITF		;SET INSTRUCTION TYPED FLAG
	MOVEI T,133(T)
	PUSHJ P,TOUT		;OUTPUT A LETTER
	SETZM  SPSAV		;SO $D WONT TRY TO DELETE OP CODES
	JRST DC1

PATCH:	BLOCK 10

IFE EDDT&3-3,<
BUFF:	BLOCK 40>

	SUBTTL	UEDDT ROUTINES - COPSYM

IFN UEDDTS,<

UESTRT:	SETZM EXJOBN		;JOB WE ARE EXAMINING!
	SETZM EXSYMS
	SETOM EXMMAP
	MOVEI S,37
	PEEK S,
	MOVEM S,MEMSIZ#
	MOVE T,S
	ANDI S,MAXPR-1
	HRLZM S,PRSIZ#
	ANDI T,<MAXPR-1>
	MOVEM T,PRTOP#
	SETZM SYMSYS#
	SETZM SYMLUZ#
	MOVEI S,265
	PEEK S,			;PEEK ADDRESS OF SYSTOP
	PEEK S,			;PEEK SYSTOP ITSELF
	MOVEM S,SYSTOP#
	MOVEI S,254
	PEEK S,			;ADDRESS OF MAINTMODE
	PEEK S,			;MAINTMODE
	MOVEM S,MAINTM#
	MOVEI T,0
	MOVEI P,PS
	PUSHJ P,PRSET
	MOVEI S,DDTEND
	HRRZ T,74
	CAIN T,DDT		;ARE WE "THE" DEBUGGER?
	MOVEM S,JOBFF		;FLUSH SYMS IF NOT BEING DEBUGGED
	PUSHJ P,COPSYM		;GET SOME SYMBOLS
	SETZM SPCFLG#
	JRST DDT

COPSYM:	SKIPE EXSYMS		;WHOSE SYMBOLS ARE WE LOOKING AT?
	JRST USYMS		;COPY USER'S SYMBOLS
ESYMS:	SETZM EXSYMS		;IN CASE WE JUMPED HERE
	SKIPE R,400036		;EXEC SYMBOL POINTER
	JRST CSYMS		;COPY THEM IN
	SETZM EXCSYM		;NO SYMBOLS YET!
	SKIPN 400163		;DDTXCOR - SKIP IF DDT IS IN XTRA CORE
	HALT .
	MOVE R,400164		;COPY SYMBOLS FROM XTRA CORE
	MOVEM R,EXPGT		;STORE ADDRESS OF KL'S EXPGT
	MOVE R,400162		;POINTER TO SYMLOC
	MOVE R,400000(R)	;FETCH SYMLOC  - AOBJN POINTER TO SYMBOLS.
	SUB R,400165		;-DDTA = OFFSET ABOVE 1,,000000
	ADDI R,400000		;+400000 = OUR UPPER SEGMENT ADDRESS FOR FIRST SYM.
	HLRO T,R		;-WC OF SYMBOLS
	MOVN T,T		;+WC
	ADD T,JOBFF		;NEW JOBFF.
	IORI T,1777
	CORE T,
	JRST NOCORE
	HLRO W1,R		;-WC AGAIN.
	ADD W1,JOBREL		;STARTING ADDRESS FOR SYMBOLS - 1
	ADDI W1,1
	HLL W1,R		;AOBJN POINTER IN OUR CORE FOR NEW SYMS.
	MOVEM W1,EXCSYM
	MOVE 0,[400,,1000*40]	;400 PAGES STARTING AT PHYSICAL 1000000
	GETHI 0,			;ATTACH HIGH CORE.
	HALT .			;LOSE SOMEHOW.
	SUB W1,[1,,1]		;FORM STACK.
XSCOP1:	PUSH W1,(R)		;FETCH HIGH CORE, STORE LOW CORE. INCREMENT LOWCOR
	AOBJN R,XSCOP1		;   POINTER, INCREMENT HIGH CORE POINTER.

;THE FOLLOWING COPIES THE EXPGT INTO OUR CORE-IMAGE.
	LDB R,[POINT 14,EXPGT,31]	;GET EXPGT PAGE NUMBER LSH 5
	HRLI R,1		;1 PAGE
	GETHI R,		;GET EXPGT AS PAGE 400
	HALT .
	MOVSI R,-1000
XSCOP2:	MOVE W1,400000(R)
	MOVEM W1,EXPGT(R)	;COPY SYSTEM'S EXPGT
	AOBJN R,XSCOP2
	JRST PRSET		;RESET SETPR2.  RETURN VIA POPJ

USYMS:	MOVEI R,JOBSYM		;FROM $$
	PUSHJ P,FETCH		;FETCH LOSER JOBSYM
	 SETZ T,		;COULDN'T GET IT
	JUMPE T,ESYMS		;IF NO SYMBOLS, TRY SYSTEM SYMS
	MOVE R,T
CSYMS:	HLRO T,R		;HERE WITH AOBJN POINTER TO SYMS IN R (FROM ESYMS)
	MOVNS T
	ADD T,JOBFF
	IORI T,1777
	CORE T,
	JRST NOCORE
	HLRO W1,R
	ADD W1,JOBREL
	HLL W1,R
	ADDI W1,1
	HRRM W1,EXCSYM
	HLLM R,EXCSYM
UELP1:	PUSHJ P,FETCH
	 SETZ T,		;STORE A 0
	MOVEM T,(W1)
	ADDI R,1
	AOBJN W1,UELP1
	POPJ P,

NOCORE:	OUTSTR [ASCIZ /CAN'T GET CORE/]
	POPJ P,

NOSYM1:	OUTSTR [ASCIZ /NO SYMBOLS ANYWHERE???/]
	POPJ P,

EXCSYM:	0
EXMMAP:	-1
EXSYMS:	0
EXJOBN:	0			;THIS IS A TABLE FOR JOBRD UUO.
	-1,,0			;CLOBBER RH TO USER'S ADDR. BEING EXAMINED
	EXJWRD			;POINTER TO WHERE TO STORE THE DATA THAT'S READ.
EXJWRD:	0

EXPGT:	BLOCK	1000		;HERE'S OUR COPY OF THE EXPGT.

;	MORE UEDDT

ACWPRV__40

DDTREN:	MOVEI T,0		;REENTER COMMAND
	GETPRV T,
	TLO T,ACWPRV
	SETPRV T,
	TLNN T,ACWPRV		;DOES HE HAVE ACW PRV?
	JRST NOREN
	SETOM SPCFLG
	SETZM SPCADR
	JRST DDT

NOREN:	OUTSTR[ASCIZ/SORRY, YOU CAN'T DO THAT!
/]
	JRST DDT

SYMPR:	HRRZ T,EXCSYM
	TRZ T,400000
PRSET:	ANDI T,<MAXPR-1>
	CAME T,PRTOP
	TLOA T,<MAXPR-1>&376001
	HLL T,PRSIZ
	SETPR2 T,
	JRST PRLUZ
	TLO T,1777
	HLRZM T,PRMAX#
	MOVNS T
	HRRM T,PROFF
	SKIPN SYMSYS
	POPJ P,
	ADD T,EXCSYM
	SETZM SYMLUZ
	MOVEI T,-400000(T)
	CAMLE T,PRMAX
	SETOM SYMLUZ
	POPJ P,

PRLUZ:	OUTSTR [ASCIZ /SETPR2 FAILED!
/]
	JRST 4,.

PROFF:	(R)

;LOG CHANGES MADE TO THE SYSTEM BY UEDDT
LOGIT:	INIT 17
	'DSK   '
	0
	POPJ	P,			;BARF
	MOVE	T,[' SSSYS']
	MOVEM	T,LOGPPN
	LOOKUP	LOGNAM
	JRST	LOGIT0
	EXCH	T,LOGPPN
	MOVS	T,T
	MOVN	T,T
	SOJL	T,LOGZ0			;JUMP IF FILE EMPTY
	LSH	T,-7
	ADDI	T,1			;CALCULATE RECORD NUMBER
	MOVEM	T,LOGPTR
	USETI	@LOGPTR
	IN	[IOWD 200,LOGBUF0]
	JRST	LOGOUT
	STATO	20000			;EOF IS OK.
	JRST	LOGLOS
	JRST	LOGOUT

LOGIT0:	HRRZ	T,LOGEXT
	JUMPN	T,LOGLOS		;BARF (WASN'T FILE NOT FOUND)
LOGZ0:	SETZM	LOGBUF
	SETZM	LOGPTR
	AOS	LOGPTR			;SET POINTER TO RECORD 1
LOGOUT:	HLLZS	LOGEXT
	SETZM	LOGDAT
	ENTER	LOGNAM
	JRST	LOGLOS			;CAN'T READ/ALTER THE FILE
	MOVE	R,[POINT 7,LOGBUF]	;LOOK FOR NULL BYTE AT END
LOGZ:	ILDB	T,R
	JUMPN	T,LOGZ
	ADD	R,[70000,,0]		;BACKUP WHEN WE SEE ONE
	PUSH	P,W1
	PUSH	P,W2
	GETPPN	W2,
	PUSHJ	P,LOGSIX		;PPN
	PUSHJ	P,INLMES
	ASCIZ	/	(/
	PJOB	W1,
	PUSHJ	P,LOGDEC		;JOB NUMBER
	PUSHJ	P,INLMES
	ASCIZ	/.)	TTY/
	SETO	W1,
	GETLIN	W1
	HRRZ	W1,W1
	PUSHJ	P,LOGOCT		;TTY LINE NUMBER
	MOVEI	W1,11
	PUSHJ	P,LOGCHR
	DATE	W1,
	IDIVI	W1,=31
	PUSH	P,W2
	IDIVI	W1,=12
	EXCH	W1,(P)
	PUSH	P,W1
	MOVEI	W1,1(W2)
	PUSHJ	P,LOGDC2		;DAY OF MONTH
	MOVEI	W1,"-"
	PUSHJ	P,LOGCHR
	POP	P,W1
	ADDI	W1,1
	PUSHJ	P,LOGDC2		;MONTH
	MOVEI	W1,"-"
	PUSHJ	P,LOGCHR
	POP	P,W1
	ADDI	W1,=64
	PUSHJ	P,LOGDEC		;YEAR
	MOVEI	W1," "
	PUSHJ	P,LOGCHR
	MSTIME	W1,
	IDIVI	W1,=1000*=60
	IDIVI	W1,=60
	PUSH	P,W2
	PUSHJ	P,LOGDC2		;HOURS
	POP	P,W1
	PUSHJ	P,LOGDC2		;MINUTES
	MOVEI	W1,11
	PUSHJ	P,LOGCHR
	HRRZ	W1,SPCADR
	PUSHJ	P,LOGOCT		;ADDRESS
	PUSHJ	P,INLMES
	ASCIZ	?/	?
	MOVE	W1,SPCADR
	PEEK	W1,			;GET OLD CONTENTS
	SETZM	LOGCNT
	PUSHJ	P,LOGWRD		;
	MOVEI	W1,11
	MOVE	W2,LOGCNT
	CAIGE	W2,8
	PUSHJ	P,LOGCHR
	PUSHJ	P,LOGCHR
	MOVE	W1,SPCWRD		;GET NEW CONTENTS
	PUSHJ	P,LOGWRD
	PUSHJ	P,INLMES
	ASCIZ/
/
	SETZ	W1,			;NULL BYTES TO FINISH WORD
LOGZ1:	PUSHJ	P,LOGCHR
	TLNE	R,760000		;FILL OUT WORD
	JRST	LOGZ1
	HRRZ	R,R
	SUBI	R,LOGBUF-1		;GET # OF WORDS
	MOVN	R,R
	MOVS	R,R
	HRRI	R,LOGBUF-1
	MOVEM	R,LOGADR
	USETO	@LOGPTR
	OUTPUT	LOGADR
	POP	P,W2
	POP	P,W1
	MOVE	T,SPCWRD
	MOVE	R,SPCADR
LOGLOS:	RELEASE
	POPJ	P,

LOGDC2:	CAIL	W1,=10
	JRST	LOGDEC
	PUSH	P,W1
	MOVEI	W1,"0"
	PUSHJ	P,LOGCHR
	POP	P,W1
	JRST	LOGDEC

LOGWRD:	HRLM	W1,(P)
	HLRZ	W1,W1
	PUSHJ	P,LOGOCT
	PUSHJ	P,INLMES
	ASCIZ	/,,/
	HLRZ	W1,(P)
LOGOCT:	SKIPA	T,[10]
LOGDEC:	MOVEI	T,=10
LOGNUM:	IDIV	W1,T
	HRLM	W2,(P)
	JUMPE	W1,.+2
	PUSHJ	P,LOGNUM
	HLRZ	W1,(P)
	ADDI	W1,60
LOGCHR:	CAME	R,[POINT 7,LOGBUF+177,34]	;END OF BUFFER?
	JRST	LOGOK			;NO
	USETO	@LOGPTR
	OUTPUT	[IOWD 200,LOGBUF0]
	MOVE	R,[POINT 7,LOGBUF]
	AOS	LOGPTR
LOGOK:	IDPB	W1,R
	AOS	LOGCNT
	POPJ	P,

LOGSIX:	JUMPE	W2,CPOPJ
	SETZ	W1,
	LSHC	W1,6
	ADDI	W1,40
	PUSHJ	P,LOGCHR
	JRST	LOGSIX

INLMES:	POP	P,W2
	HRLI	W2,(<POINT 7,0>)
INLMS1:	ILDB	W1,W2
	JUMPE	W1,1(W2)
	PUSHJ	P,LOGCHR
	JRST	INLMS1

LOGCNT:	0
LOGPTR:	0
LOGADR:	0
	0

LOGBUF:	BLOCK 201

LOGNAM:	'UEDDT '
LOGEXT:	'LOG   '
LOGDAT:	0
LOGPPN:	' SSSYS'
>

;KEEP IT ALL TOGETHER FOR SWAPPING DDT.
;LIT AND VAR XLISTED FOR YOUR READING PLEASURE
XLIST
LIT
VAR
LIST

XP DDTEND,.
^^DDTEND_DDTEND


	SUBTTL	DDT User's Guide

COMMENT 	DDT User's Information

DDT is a program debugging aid that is loaded into the same core image as
the program being debugged.  DDT can be entered via the monitor DDT command
or by a program transfer to the external label DDT or by a program transfer
to the address contained in the right half of JOBDDT.

DDT can also be entered as a result of executing an instruction on which
a breakpoint has been set.

Once DDT has been entered the user may examine and modify the contents of
his accumulators and other memory locations.  To return to the execution
of the program an $P command (proced from a breakpoint) or adr$G (start
execution at adr) may be used.  When DDT is entered via the DDT command,
the PC of the interrupted program is stored in JOBOPC.


The following is a quick summary of DDT for people who already know how
to work DDT in general.  For further information, consult DEC documentation

General -
	$ = Altmode
	n = a number
	$n = a decimal number always!


Input modes

$n%	Input a list of n-bit octal bytes, separated by commas, terminated by $.
	If n=0 use the byte mask ($M+2) to define arbitrary byte boundaries

"<delimiter>text<delimiter>
	Left justified ascii text (up to five characters)  Note: to get CRLF
	entered you must type both CR and LF.  If more than five characters
	are typed, only the last five are used.

"<character>$
	Right justified ascii character.

$"<delimiter>text<delimiter>
	Left justified sixbit text (lower case typin converted to upper case).
	The last six (or fewer) characters are used.

$"<character>$
	right justified ascii character

$$7"<delimiter>text<delimiter>
	Left adjuseted ASCIZ string, five characters per word.

$$"<delimiter>text<delimiter> or $$n"<delimiter>text<delimiter>  (n not 7)
	Left adjuseted sixbit string, six characters per word.  Ends with
	a zero byte or zero word.


Output modes
$A	Absolute

$C	Full word constant in current radix

$F	Floating point

$H	Halfword format

$nJ	Output in flag mode using the n-th flag table.
	Each flag table contains =36 radix50 flag names (flag name for
	bit 0 is first).  The first word in the list of flag tables is
	found by looking in $M+3 (FLGPTR).  Each word in the list of flag
	tables is a right-half pointer to a flag table and a left-half
	pointer to the next word in the list (a zero left half terminates).

$nL	Output right half of cell as left half flags using n-th flag table.
	This is suitable for looking at MOVSI or TLxx instructions.

$nO	Output cell in n-bit bytes
	If n=0 use the byte mask ($M+2) to define arbitrary byte boundaries

$R	Relocatable

$nR	Set typeout radix to n.

$S	Symbolic

$nT	n-bit text bytes.  If n is omitted output 7-bit ascii, left adjusted,
	except if the first byte is null, output one right adjusted character.
	If n is present it should be one of 5, 6, or 9: 6=sixbit, 5=radix50,
	9=Stanford ascii with bucky bits.  Other values of n presently print
	in 7-bit ascii.

$U	each halfword as numeric in the current radix, unless $10R in which
	case output full word in radix 10

$nV	Output right half of cell as right half flags using n-th flag table.
	This is suitable for looking at MOVEI or TRxx instructions.



Special Characters
addr/	open cell in current mode
addr[	open cell as a number in the current radix
addr]	open cell as symbolic
addr!	open cell and suppress typeout
addr\	open cell in current mode and don't change "."
CR	Closes and changes (if user typed a new value) the current cell.
LF	Like CR and opens .+1.
^	Like CR and opens .-1.
TAB	Like CR then opens the cell pointed to by right side of current cell.
 (control ] on ttys)
	Closes and does NOT change the current cell then opens the cell
	pointed to by left side of current cell.
;	retype in current mode (usually following a temporary mode change)
=	retype like $U format (half word numeric in current radix)
$=	retype like $C format (full word numeric in current radix)
_	retype in symbolic mode.
?	typeout all undefined symbols


Searches

$M	Contains the search mask.  Put 1 bits in it where you want to look.

first<last>arg$E
	Effective address search for intructions pointing to arg in the 
	range first to last

first<last>arg$N
	Search for words NOT containing arg in the range first to last.

first<last>arg$W
	Search for words containing arg in the range first to last.

first<last>arg$$Z
	Write the value arg into all words in the range first to last.



Special values

.	(period) has the value of the current address

$I	(exec ddt) has the state of the PI system (CONI PI,)

$Q	Has the last value typed by ddt.

$nB	Address of the four words associated with breakpoint n.

	The first word contains the address of the breakpoint in the
	right half, and the address of the cell to open in the left
	half.

	The second word is the conditional instruction.  If this is zero, or
	if when exected it causes one skip, then the procede counter
	is decremented and if it becomes non-positive, the breakpoint occurs.
	If the conditional instruction does not skip, no break is taken.
	If the conditional instructions skips twice, the break is taken
	regardless of the procede counter.

	The third word is the procede counter.

	If the fourth word is non-zero it is assumed to be the address of
	an ASCIZ string which will be used to set $M-1 (see below) to
	cause this string to be used for input instead of TTY input.

$M-4	(EXEC DDT) If non-zero, DDT output goes to the LPT
$M-3	(EXEC DDT) Stores APR CONI bits here when DDT is entered
$M-2	If non zero, this points to a routine to be called to output
	each character.  The character to be output is in T (ac 5) and
	the routine should return via POPJ 3, without having clobbered
	any acs.
$M-1	If non zero is taken as a byte pointer to an ASCIZ string which
	is used instead of the TTY for input.
$M	Search mask
$M+1	Parameter for symbolic disassembly. If the value disassembed
	minus the best symbol is less than this number (MXINC) then
	the dissambler will print the symbol name plus the difference,
	if the difference is larger than this value, then the value
	being disassembled will be printed as a number.
$M+2	Byte input/output mask for $0% and $0O commands.
$M+3	First word in the list of flag tables. (See $F.)

Symbol manipulations

$D	Suppress the last symbol typed.  Retype the same value.

sym$K	Suppress output of the named symbol

sym$$K	Suppress input and output of this symbol

sym$:	Open the symbol table of the program named sym.

$:	Type a list of all program names.

sym:	Define sym to be the currently open location.

val<sym:
	Define sym to have value val.

sym$&	Open the symbol table of the block named sym in the currently
	open program.  Also accessible will be all symbols in blocks
	that contain the opened block.

$&	Type a list of all block names in the currently open program.

Program control

adr1(adr2)$nB
	Set breakpoint n at adr1.  When breakpoint is hit it will type the
	contents of adr2.  The n and (adr2) are optional.

adr1(adr2)$$nB
	Same as above except DDT will procede from the breakpoint automatically.
	Auto procede continues until typin is present when the breakpoint is
	hit (see $$P).

$B	remove all breakpoints

0$nB	remove breakpoint n.

adr$G	Start execution at adr.  If adr is omitted, execution starts at
	the location pointed to by the right half of JOBSA (in exec DDT
	the right half of STARTA is used instead of JOBSA).   If  JOBSA
	(STARTA) contains a zero starting address, $G with no  argument
	is illegal.  Incidently STARTA is located at DDTBEG+0.

adr$$G	Same as adr$G except  the argument is stored in the right  half
	of JOBSA (or STARTA) for subsequent $G commands.

$P	Procede from breakpoint.

n$P	Procede n times from this breakpoint

$$P	Procede automatically until the typein is present at the breakpoint.

instr$X	Executes the instruction that was typed.  If no argument is given
	then the one instruction at the current breakpoint location is
	single-stepped.  Repetitions of $X cause subsequent instructions to
	be single stepped.  After single stepping, a $P command will return
	to the normal execution of the program.

Assembly operations

+-*'	are arithmetic operators

,	is a separator denoting ac or device field

,,	separates half-words

	numeric typin is octal except digits followed by a decimal point
	are radix 10, except if further digits following the point are
	typed, input is floating point.  Floating point number may be
	followed by E, an optional plus or minus, and an exponent.

()	swap the argument and add it into the assembled word.

@	Set bit 13 in the word being assembled.

blank	is a separator and adding operator in the word assembler.

sym&	sets block name to sym for the next symbol that's input.


Commands for UEDDT

	Like CR except it deposits changes on the Librascope

$n	Examine core image of Timesharing job n.
$$n	Examine core image of Timesharing job n using its symbols.
        If n is zero or omitted in either of the above, UEDDT will
	examine the timesharing system, using the EXPGT (where set,
	or physical pages where the EXPGT has no entry) to accomplish
	mapping.
n$	Examine physical core, with page n being page 0 in the space
	being examined.  If n is negative, examination will be via
	the EXPGT.

Paper tape control (Special EXEC DDT version only)

$^Q	(That's control-Q) Punch loader.
first<last$^R
	Punch data from core range to tape.
addr$^S	Punch addr as the starting address.
^T	Punch currently open location as one tape data block
first<last$Y
	Read tape into core
first<last^V
	Read tape and verify by comparing it with core.






IFE EDDT&1,<IFE UEDDTS!SAVESW,<END>
	IFN UEDDTS,<END UESTRT>
	IFN SAVESW,<END DDT>>
IFE EDDT&41-1,<BEND DDT>
IFN EDDT&40,<END>
>