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
IGCR:	MOVEI	B,15
	ILDB	C,P
	CAIN	C,^L
	 JRST	FF
	CAIN	C,3
	JSP	L,CC1
	CAME	C,B	;CR
	JRST	IGCR+1
	JRST	MAIN

CC1:	SOS	L
CC:	MOVEI	P,(P)
	CAIE	P,BUFE
	JRST	SORT
	MOVE	E,[-BUFL,,BUF]
	.IOT	I,E
	MOVE	P,[350700,,BUF]
	LDB	C,P
	JRSTF	-1(L)
;READ IN A COMMAND, PROCESSING RUBOUTS, PROMPTING WITH "*".
TTILIN:	.IOT	TYO,[^M]

;COME HERE AFTER NULL LINE.
TTILI2:	.IOT	TYO,["*]
	SETZM	TTICNT		;NO CHARS READ YET.
	MOVE	B,[440700,,TTIBUF]
	MOVEM	B,TTIPNT
TTILUP:	.IOT	TYI,B		;READ A CHAR.
	CAIN	B,^M
	JRST	TTICR		;^M MEANS ALL READ.
	CAIN	B,177
	JRST	TTIRUB
	CAIN	B,^U
	JRST	TTILIN		;^U - CANCEL COMMAND.
	IDPB	B,TTIPNT	;NORMAL CHAR.
	AOS	TTICNT
	JRST	TTILUP

TTICR:	SKIPN	TTICNT		;IF READING CMD, ON NULL LINE, RETRY.
	JRST	TTILI2
	IDPB	B,TTIPNT
	MOVE	B,[440700,,TTIBUF]
	MOVEM	B,TTIPNT	;SET UP FOR REMOVAL OF CHARS.
	JRST	CLUP3		;RETURN.

TTIRUB:	SOSGE	TTICNT		;IF NO CHAR TO RUB, RETRY.
	JRST	TTILIN
	LDB	B,TTIPNT
	.IOT	TYO,B		;PRINT RUBBED CHAR.
	MOVSI	B,070000
	ADD	B,TTIPNT
	JUMPGE	B,TTIRU1	;IF STILL IN SAME WD.
	MOVEI	B,-1(B)		;ELSE, MOVE TO END OF PREV. WD.
	HRLI	B,010700
TTIRU1:	MOVEM	B,TTIPNT
	JRST	TTILUP

TTICNT:	0		;NUM CHARS READ.
TTIPNT:	0		;PTR INTO BUFFER.
TTIBUF:	BLOCK	40
BEG:	.OPEN	TYI,[0,,(SIXBIT /T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
	REPEAT 10,U MAIN
	JRST	FF
	REPEAT 27,U MAIN
	ADD	A,SQ.$(B)
	ADD	A,SQ.%(B)
	REPEAT 10,U MAIN
	ADD	A,SQ..(B)
	U	MAIN
	IRPC Z,,0123456789
	ADD	A,SQ.!Z(B)
	TERMIN
	U	MAIN
	U	IGCR
	REPEAT 5,U MAIN
	IRPC Z,,ABCDEFGHIJKLMNOPQRSTUVWXYZ
	ADD	A,SQ.!Z(B)
	TERMIN
	REPEAT 45,U MAIN
IFN .-200-DTAB,PRINTX /LOSE LOSE/

DEFINE	SQT	A,B
	SQUOZE 0,B+A_40
	SQUOZE 0,B/50+A_40
	SQUOZE 0,B/50/50+A_40
	SQUOZE 0,B/50/50/50+A_40
	SQUOZE 0,B/50/50/50/50+A_40
	SQUOZE 0,B/50/50/50/50/50+A_40
SQ.!B:	A_40
TERMIN

IRPC Z,,ABCDEFGHIJKLMNOPQRSTUVWXYZ$%
	SQT	10,Z
TERMIN
	SQT	4,.
IRPC Z,,0123456789
	SQT	0,Z
TERMIN

RTAB:	0
	IRPC Z,,0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.$%
	"Z
TERMIN
CONSTANTS
VARIABLES

INFIL:	BLOCK 4
OUTFIL:	BLOCK 4

PDL:	BLOCK 10

DEFINE	S	A
	SQUOZE	0,A
TERMIN
DEFINE	T	A
	SQUOZE	4,A
TERMIN
DEFINE	II	A
	SQUOZE	10,A
TERMIN
DEFINE	MS	FOO/
DEFINE	M	X
IRP	Z,,[,FOO]
	S	X!!Z
TERMIN
TERMIN
TERMIN

ISYMT:	S UFA
	S DFN
	S FSC
	S IBP
	S ILDB
	S LDB
	S IDPB
	S DPB
MS	L,M,B,R,RL,RM,RB
	M FAD
	M FSB
	M FMP
	M FDV
MS	I,M,S
	M MOVE
	M MOVS
	M MOVN
	M MOVM
MS	I,M,B
	M IMUL
	M MUL
	M IDIV
	M DIV
	S ASH
	S ROT
	S LSH
	S JFFO
	S ASHC
	S ROTC
	S LSHC
	S EXCH
	S BLT
	S AOBJP
	S AOBJN
	S JRST
	S JFCL
	S XCT
	S PUSHJ
	S PUSH
	S POP
	S POPJ
	S JSR
	S JSP
	S JSA
	M ADD
	M SUB
MS	L,E,LE,A,GE,N,G
	M CAI
	M CAM
	M JUMP
	M SKIP
	M AOJ
	M AOS
	M SOJ
	M SOS
MS	I,M,B
	M SETZ
	M AND
	M ANDCA
	M SETM
	M ANDCM
	M SETA
	M XOR
	M IOR
	M ANDCB
	M EQV
	M SETCA
	M ORCA
	M SETCM
	M ORCM
	M ORCB
	M SETO
MS	I,M,S,Z,ZI,ZM,ZS,O,OI,OM,OS,E,EI,EM,ES
	M HLL
	M HRL
	M HLR
	M HRR
MS	N,NE,NA,NN,Z,ZE,ZA,ZN,C,CE,CA,CN,O,OE,OA,ON
	M TR
	M TL
	M TD
	M TS
	S BLKI
	S DATAI
	S BLKO
	S DATAO
	S CONO
	S CONI
	S CONSZ
	S CONSO
	S APR
	S PI
	S PTP
	S PTR
	S TTY
	S LPT
	S DIS
	S DC
	S UTC
	S UTS
	S IBM
MS	I,M,B
	M CLEAR
	S END
	S LOC
	S XWORD
	S RIM1
	S RIM10
	S SBLK
	S RIM
	II TITLE
	S SQUOZE
	S EXP
	S XWD
	S .BEGIN
	S REPEAT
	S .END
	S OCT
	S CONSTA
	T SIXBIT
	T ASCII
	S RADIX
	S BLOCK
	S NOSYMS
	S EXPUNGE
	S NULL
	S EQUALS
	S DEFINE	;UGH
	II IRP	;UGH
	II IRPC	;UGH
	II IRPS	;UGH
	S TERMIN
	S .QUOTE
	S WORD
	S RELOCA
	S 1PASS
	S OFFSET
	S IFG
	S IFGE
	S IFE
	S IFLE
	S IFN
	S IFSE	;UGH
	S IFSN	;UGH
	S IF1
	S IF2
	S IFL
	T PRINTX
	T PRINTC
	S VARIAB
	S .LIBRA
	T .LENGTH
	S .LIFS
	S .ELDC
	S .LIFE
	S .LIFN
	S .LIFG
	S .LIFLE
	S .LIFGE
	S .LIFL
	S .SLDR
	S .OP
	S .FORMAT
	S .STOP
	S .ISTOP
	S .RPCNT
	S .LOP
	S $.
	S $R.
	S .LVAL1
	S .LVAL2
	S .LNKOT
	S .NSTGW
	S .YSTGW
	S .GSSET
	S .TYPE
	S .LIBRQ
	S .GLOBAL
	S .GO
	S .TAG
	T .ASCII
	T ASCIZ
	S .BYTC
	S .BYTE
	S .WALGN
	S .IRPCNT
	S .FNAM1
	S .FNAM2
	II .INSRT
	II .I
	II .F
TSS:

BUF:	BLOCK BUFL
BUFE:	3_35

ST:	BLOCK SYML
ST2:	BLOCK SYML

FS:
LOC .\1777+4000
LEN==.-FS+1
END BEG
