$auto$=-2
.enabl lc
; Mp version as of: 16-aug-80
	mutask=1 
	.if df mutask
	.MACRO pure
	.psect pur,ro
	.ENDM 
		
	.MACRO impure
	.psect ipur,rw
	.ENDM 
		
	.iff 
		
	.MACRO pure
	.ENDM 
	.MACRO impure
	.ENDM 
		
	.endc 
	.enabl ama
	.nlist sym
	.psect edi11
		
		
	.globl lcom
	.globl lcom2
	.globl lmode
	.globl text
	.globl etext
	.globl expand
	.globl compress
	.globl findend
		
	.MACRO push this
	mov this,-(sp)
	.ENDM 
		
	.MACRO pop that
	mov (sp)+,that
	.ENDM 
		
	.MACRO callr x
	jmp x
	.ENDM 
		
		
		
	.mcall dir$,callr,qiow$,mrkt$,wtse$
		
		
		
read:   qiow$	io.rtt,1,1,,iosred,,<ib,ibsize,,tbl>
helpq:  qiow$   io.wvb,1,1,,,,<help,ehelp-help,0>
helpq2: qiow$   io.wvb,1,1,,,,<help2,ehelp2-help2,0>
tofq:   qiow$   io.wvb,1,1,,,,<tof,etof-tof,0>
setmul: qiow$   sf.smc,1,1,,setios,,<setm,esetm-setm>  ;set
getmul: qiow$   sf.gmc,1,1,,setios,,<retm,eretm-retm>  ;get into restore loc
retmul: qiow$   sf.smc,1,1,,setios,,<retm,eretm-retm>  ;restore
setios: .word 0,0
		
	d       =       1       ;make this a 1 for debug mode, 0 for production
		
tbl:        
	.word d+2+4+10+20+40+100+200+400+1000+2000+4000+10000+20000+40000+100000
	.word 1+4+20+40+100+200+400+1000+2000+4000+100000
	.word 0,0,0,0
	.word 0,100000,0,0              ;rubout
	.word 0,0,0,0,0,0
		
help:      
	.byte esc,'Y,bottom-2+40,'!
	.ascii /L=text<- B=tab<- D=del-eol N=end-l  W=wordfind E=enter J=<-- Y=up V=split/
	ehelp=. 
		
		
help2:    
	.byte,esc,'Y,bottom-1+40,'! 
	.ascii /R=text-> U=Undo  T=tabstop A=adjust P=position O=open  K=--> H=down/
		
	ehelp2=. 
tof:    .byte,esc,'Y,12.-1+40,'= 
	.ascii / **  Top of File **/
	etof=. 
	.even 
setm:   .byte   tc.hht,1,    tc.wid,  255.,   tc.acr,  0
	esetm=. 
retm:   .byte   tc.hht,0,    tc.wid,  000.,   tc.acr,  0
	eretm=. 
		
		
		
		
	blank   =   40
	bottom  =   24.
	ceol    =   113
	ceop    =   'J
	cr      =   15
		
	con.0   =   0       ;control 0
	con.a   =   1       ;control a
	con.b   =   2       ;control b
	con.c   =   3       ;control c
	con.d   =   4       ;control d
	con.e   =   5       ;control e
	con.f   =   6       ;control f
	con.g   =   7       ;control g
	con.h   =   10      ;control h
	downarrow=con.h 
	con.i   =   11      ;control i
	con.j   =   12      ;controj j
	con.k   =   13      ;controk k
	con.l   =   14      ;control l
	con.o   =   17      ;control o
	con.p   =   20      ;control p
	con.q   =   21      ;control q
	con.r   =   22      ;control r
	con.s   =   23      ;control s
	con.t   =   24      ;control t
	con.u   =   25      ;control u
	con.v   =   26      ;control v
	con.w   =   27      ;control w
	con.x   =   30      ;control x
	con.y   =   31      ;control y
	uparrow = con.y
	con.z   =   32      ;control z
		
	esc          =  33
	tab          =  9.
	space        =  40
	home         =  110
	insert       =  114
	del          =  115
	line         =  0
	col80        =  80.
	rub          =  177
	screen       =  1
	sdel         =  123
	transl       =  'i      ;`i' transmit line
	nl	     =  12
		
	ibsize       =  50.     ;input buffer size
	tsize        =  254.    ;this be larger thanlbs but needs to be local
	tabseen:.word 0                ;0=don't convert tabs on way out, 1=do it
setmar: .word 0                 ;if we have set the special multiple chars <>0
chglin: .word			;change made on line 0=no,>0 =yes
tagset: .word	0		;0=not set, >0 = set
arrows: .word	0		;0=not, 1=yes (command was an up/down arrow)
cycle:  .word   0               ;count times thru word look wraparound
	scurser:.word   0               ;save curser
omode:  .word   0               ;open mode 0=no, >0 =yes
emode:  .word   0               ;Enter mode 0=no, <>0 = yes
iosred: .word        0,0
ios:    .word        0,0
ib:     .blkb        ibsize
ib2:    .blkw        2
lmode:  .word	0
gtemp:  .word   0               ;save whether we were at $
	.even 
	maccmd=177 
up:     .ascii /-1p/<maccmd><2> ;enter through special window to lcom2
	upl=.-up 
dwn:    .ascii /+p/<maccmd><2>  ;enter through special window to lcom2
	dwnl=.-dwn 
restor: .ascii /.p/<maccmd><2>  ;enter through special window to lcom2
	restl=.-restor 
lbcmd:  .ascii /b/<nl>/l/<nl>	;do the b for him
	lbcmdl=.-lbcmd 
	.even 
spat:   .word 0         ;save pattern if control t is set
pat:    .word 0         ;bool, pattern=1,nopat=0
coln:   .word 1         ;column number to l to
text:   .blkb tsize     ;text buffer (current line expanded without tabs)
	etext=.-1       ;pointer to last char in text buffer
	.even 
curser: .word 0         ;curser position on current line
firsttime: .word 0 ;first time into l command (each issuance of l)
sdot:   .word 0 ;save fdot code while here
cnt:    .word 0 ;spare counter
		
		
mark:   mrkt$	30.,4,1
wait:   wtse$	30.
		
	pure 
		
		
		
lcom:              
	TST setmar		;IS setmar = #0
	BNE Eb1	;Not if NE
	    dir$ #getmul    ;get current for latter restoration
	    dir$ #setmul
	    inc setmar
Eb1=.			; 
Eb3=.
		
	CMP dot,zero		;IS dot = zero
	BNE Eb4	;Not if NE
	CMP dot,dol		;IS dot = dol
	BNE Eb7	;Not if NE
	BR Eb10	;Here IF dot = dol
Eb7=.
	BR Eb4		;Here if not
Eb10=.
	JSR PC,addline
	MOV zero,dot
	ADD #2,dot
Eb4=.			; 
Eb6=.
	mov #1,lmode
		
	TST smode		;IS smode = #0
	BNE Eb11	;Not if NE
	    mov #lbcmd,r0
	    mov #lbcmdl,r1
	    callr putbak                    ;put the user in screen & redo command
Eb11=.			; 
Eb13=.
	TST ol		;IS ol NE #0
	BEQ Eb14	;Not if EQ
	MOV cursl,r1
	DEC r1
	MOV r1,-(SP)
	MOV #col80,-(SP)
	CALL CURSR2
MOVB #esc,R0
	CALL TTYCC
MOVB #sdel,R0
	CALL TTYCC
	    mov fpage,r1
	    bic #10,r1
	    mov fdot,sdot
	    mov r1,fdot
MOVB #ESC,R0
	CALL TTYCC
MOVB #'R,R0
	CALL TTYCC
mov r1,r0
	JSR PC,ttycc
Eb14=.			; 
Eb16=.
		
		
	JSR PC,getc
	CMP r0,#nl		;IS r0 = #nl
	BNE Eb17	;Not if NE
	    mov pat,spat
	    clr pat
	JMP Eb20
Eb17=.			; 
	CMP r0,#'#		;IS r0 = #'#
	BNE Eb21	;Not if NE
	JSR PC,getc
	JSR PC,getnum
		mov r1,coln             ;save column
	JSR PC,getc
	CMP r0,#nl		;IS r0 NE #nl
	BEQ Eb24	;Not if EQ
		    mov #2,r1          ; bad command error
		    jmp error          ;
Eb24=.			; 
Eb26=.
		mov pat,spat
		clr pat
			        
	JMP Eb27
Eb21=.			; 
		mov #1,pat              ;its definitively a pattern
	CMPB r0,#'/		;IS r0 = #'/
	BNE Eb28	;Not if NE
	JSR PC,compil
	JMP Eb31
Eb28=.			; 
		    mov r0,peek                     ;put back (1st char in pattern)
		    mov #1,r0                       ;use control a as del
	JSR PC,compil
Eb31=.			; 
Eb30=.
Eb27=.			; 
Eb23=.
Eb20=.			; 
Eb19=.
	clr omode                               ;initially not in o mode
	mov #1,tagset                           ;initially not set - cr=down
	clr arrows
	mov coln,curser
	add #text-1,curser			;first time, allways point here
	mov #1,firsttime
lcom2:          
	mov @dot,r0
	JSR PC,getlin
	JSR PC,expand
	clr chglin
	TST arrows		;IS arrows = #0
	BNE Eb32	;Not if NE
	    clr firsttime
	TST pat		;IS pat NE #0
	BEQ Eb35	;Not if EQ
		mov #text,r2			;start search here
	JSR PC,matcher
			        
	TST r2		;IS r2 NE #0
	BEQ Eb38	;Not if EQ
		    mov r2,curser
	JMP Eb41
Eb38=.			; 
		    mov #text,curser
Eb41=.			; 
Eb40=.
	JMP Eb42
Eb35=.			; 
		mov coln,curser
		add #text-1,curser
Eb42=.			; 
Eb37=.
	JMP Eb43
Eb32=.			; 
	    clr arrows
Eb43=.			; 
Eb34=.
	JSR PC,tocurs
jsr pc,ttflsh
		   
lcom1:  dir$ #read                         ;just read till  terminator
		   
	JSR PC,update
		   
	CMP iosred+2,#ibsize		;IS iosred+2 = #ibsize
	BNE Eb44	;Not if NE
	    br lcom1			;yes, just update and read again
Eb44=.			; 
Eb46=.
		
Eb47=.
	CMPB iosred+1,#37		;Case #37
	BNE Eb49
	    dir$ #helpq
	    dir$ #helpq2
	JSR PC,tocurs
jsr pc,ttflsh
	    jmp lcom1
			
			
Eb49=.
	CMPB iosred+1,#rub		;Case #rub
	BNE Eb51
			
	CMP curser,#text		;IS curser HI #text
	BLOS Eb53	;Not if LOS
MOVB #10,R0
	CALL TTYCC
MOVB #40,R0
	CALL TTYCC
MOVB #10,R0
	CALL TTYCC
jsr pc,ttflsh
		dec curser
		movb #space,@curser
		inc chglin
Eb53=.			; 
Eb55=.
	    jmp lcom1
Eb51=.
	CMPB iosred+1,#con.0		;Case #con.0
	BNE Eb56
	CMP #debuga,#1		;IS #debuga = #1
	BNE Eb58	;Not if NE
		mov coln,r0
		mov curser,r1
		mov #text,r2
		mov setios,r3
		mov setios+2,r4
		mov dot,r5
		iot 
Eb58=.			; 
Eb60=.
	    jmp lcom1
Eb56=.
	CMPB iosred+1,#con.a		;Case #con.a
	BNE Eb61
	JSR PC,adjust
	    mov curser,r2                        ; but update screen here
Eb63=.
	CMP r2,#text+col80-1		;IS r2 LOS #text+col80-1
	BHI Eb65	;Not if HI
	JMP Eb68
Eb65=.			; 
	JMP Eb64	;else end  while loop
Eb68=.			; 
Eb67=.
MOVB @R2,R0
	CALL TTYCC
		inc r2                           ;cursor to end of screen
	JMP Eb63		;Repeat loop
Eb64=.
	JSR PC,tocurs
jsr pc,ttflsh
	    inc chglin
	    jmp lcom1
Eb61=.
	CMPB iosred+1,#con.b		;Case #con.b
	BNE Eb69
	JSR PC,tabback
	JSR PC,drag
	    jmp lcom1
Eb69=.
	CMPB iosred+1,#con.v		;Case #con.v
	BNE Eb71
			
	    mov curser,r1
	JSR PC,compress
			
	JSR PC,cut
	    inc chglin
	    jmp lcom1
Eb71=.
	CMPB iosred+1,#con.d		;Case #con.d
	BNE Eb73
	JSR PC,deleol
MOVB #esc,R0
	CALL TTYCC
MOVB #'K,R0
	CALL TTYCC
jsr pc,ttflsh
	    inc chglin
	    jmp lcom1
Eb73=.
	CMPB iosred+1,#con.o		;Case #con.o
	BNE Eb75
	TST omode		;IS omode = #0
	BNE Eb77	;Not if NE
		inc omode               ;set flag indicating mode
	JSR PC,saveln
	JSR PC,movright
	JSR PC,deleol
		inc chglin
		jmp lcom1
	JMP Eb80
Eb77=.			; 
omode2:                                      
	JSR PC,edone
		clr omode
		jmp lcom1
Eb80=.			; 
Eb79=.
Eb75=.
	CMPB iosred+1,#con.i		;Case #con.i
	BNE Eb81
	    inc tabseen
	JSR PC,tabforward
	JSR PC,drag
	    jmp lcom1
			   
Eb81=.
	CMPB iosred+1,#con.j		;Case #con.j
	BNE Eb83
	CMP curser,#text		;IS curser HI #text
	BLOS Eb85	;Not if LOS
		dec curser
	JSR PC,tocurs
jsr pc,ttflsh
Eb85=.			; 
Eb87=.
	    jmp lcom1
Eb83=.
	CMPB iosred+1,#con.k		;Case #con.k
	BNE Eb88
	CMP curser,#text+col80-2		;IS curser LO #text+col80-2
	BHIS Eb90	;Not if HIS
		inc curser
	JSR PC,tocurs
jsr pc,ttflsh
Eb90=.			; 
Eb92=.
	    jmp lcom1
Eb88=.
	CMPB iosred+1,#con.l		;Case #con.l
	BNE Eb93
	JSR PC,delchar
MOVB #esc,R0
	CALL TTYCC
MOVB #'Q,R0
	CALL TTYCC
	MOV cursl,-(SP)
	MOV #col80-1,-(SP)
	CALL CURSR2
	    movb text+col80-3,r1                    ;get new char into display
MOVB R1,R0
	CALL TTYCC
	    movb text+col80-2,r1			;get new char into display
MOVB R1,R0
	CALL TTYCC
	JSR PC,tocurs
jsr pc,ttflsh
	    inc chglin
	    jmp lcom1
Eb93=.
	CMPB iosred+1,#con.e		;Case #con.e
	BNE Eb95
	    com emode
	JSR PC,tocurs
jsr pc,ttflsh
	    jmp lcom1
			
inline:          
	MOV #bottom-3,-(SP)
	MOV #col80,-(SP)
	CALL CURSR2
MOVB #esc,R0
	CALL TTYCC
MOVB #sdel,R0
	CALL TTYCC
MOVB #esc,R0
	CALL TTYCC
MOVB #'J,R0
	CALL TTYCC
	MOV cursl,r1
	INC r1
	MOV R1,-(SP)
	MOV #1,-(SP)
	CALL CURSR2
MOVB #esc,R0
	CALL TTYCC
MOVB #insert,R0
	CALL TTYCC
MOVB #ESC,R0
	CALL TTYCC
MOVB #'R,R0
	CALL TTYCC
mov FPAGE,r0
	JSR PC,ttycc
jsr pc,ttflsh
                 dir$ #mark          ;display is too slow
                 dir$ #wait          ;must   give it some time
	    rts pc
	     
	     
	     
Eb95=.
	CMPB iosred+1,#con.g		;Case #con.g
	BNE Eb97
	MOV dot,gtemp
	SUB dol,gtemp
	CMP dol,zero		;IS dol NE zero
	BEQ Eb99	;Not if EQ
		mov dot,adr1
		mov dot,adr2
	JSR PC,delete
MOVB #esc,R0
	CALL TTYCC
MOVB #'M,R0
	CALL TTYCC
		  
	MOV dot,R2
	ADD #18.,R2
	JSR PC,get.line
		  
	MOV #BOTTOM-2,-(SP)
	MOV #1,-(SP)
	CALL CURSR2
MOVB #ESC,R0
	CALL TTYCC
MOVB #'R,R0
	CALL TTYCC
mov FDOT,r0
	JSR PC,ttycc
jsr pc,ttflsh
		mov #lbuf1,r0                           ;now
	JSR PC,ttystr
		  
	JSR PC,tocurs
jsr pc,ttflsh
Eb99=.			; 
Eb101=.
	     
	TST gtemp		;IS gtemp = #0
	BNE Eb102	;Not if NE
	CMP zero,dol		;IS zero NE dol
	BEQ Eb105	;Not if EQ
	BR Eb108	;Here IF zero NE dol
Eb105=.
	BR Eb102		;Here if not
Eb108=.
		movb #uparrow,iosred+1
		add #2,dot
	JMP Eb109
Eb102=.			; 
		jmp lcom2
Eb109=.			; 
Eb104=.
	     
Eb97=.
	CMPB iosred+1,#con.p		;Case #con.p
	BNE Eb110
	TST spat		;IS spat NE #0
	BEQ Eb112	;Not if EQ
		mov spat,pat
Eb112=.			; 
Eb114=.
			
	TST pat		;IS pat NE #0
	BEQ Eb115	;Not if EQ
		mov curser,r2	;start at curser +1
		inc r2
	JSR PC,matcher
	TST r2		;IS r2 = #0
	BNE Eb118	;Not if NE
		    mov #text,r2
	JSR PC,matcher
	TST r2		;IS r2 NE #0
	BEQ Eb121	;Not if EQ
			br 3000$
Eb121=.			; 
Eb123=.
	JMP Eb124
Eb118=.			; 
3000$:                            
	CMP r2,#text+col80-2		;IS r2 HIS #text+col80-2
	BLO Eb125	;Not if LO
			mov #text,curser
	JMP Eb128
Eb125=.			; 
			mov r2,curser
Eb128=.			; 
Eb127=.
Eb124=.			; 
Eb120=.
	JMP Eb129
Eb115=.			; 
		mov coln,curser
		add #text-1,curser
Eb129=.			; 
Eb117=.
	JSR PC,tocurs
jsr pc,ttflsh
	    jmp lcom1
Eb110=.
	CMPB iosred+1,#con.r		;Case #con.r
	BNE Eb130
	JSR PC,inschar
MOVB #esc,R0
	CALL TTYCC
MOVB #'P,R0
	CALL TTYCC
jsr pc,ttflsh
	    inc chglin
	    jmp lcom1
Eb130=.
	CMPB iosred+1,#con.t		;Case #con.t
	BNE Eb132
	    mov curser,coln
	    sub #text,coln
	    inc coln
	    inc tabseen
	    inc tagset
	    mov pat,spat
	    clr pat
	    jmp lcom1
Eb132=.
	CMPB iosred+1,#con.u		;Case #con.u
	BNE Eb134
	    mov #restor,r0
	    mov #restl,r1
	    clr chglin
	    callr putbak                        ;.pl cmd renter   setup curser
Eb134=.
	CMPB iosred+1,#con.w		;Case #con.w
	BNE Eb136
	JSR PC,mov2wd
	JSR PC,tocurs
jsr pc,ttflsh
	    jmp lcom1
Eb48=.
Eb136=.
		   
	TST omode		;IS omode GT #0
	BLE Eb138	;Not if LE
	    jmp omode2				;all exits go here
Eb138=.			; 
Eb140=.
		   
		   
	TST chglin		;IS chglin GT #0
	BLE Eb141	;Not if LE
	    mov #text,r1    ;move all text in `text'
	JSR PC,compress
	JSR PC,putlin
	    mov r0,@dot     ;replace line dot
Eb141=.			; 
Eb143=.
		   
		   
Eb144=.
	CMPB iosred+1,#uparrow		;Case #uparrow
	BNE Eb146
	    mov #1,arrows
	    br 1000$
Eb146=.
	CMPB iosred+1,#esc		;Case #esc
	BNE Eb148
1000$:            
	MOV ZERO,R0
	ADD #2,R0
	CMP dot,r0		;IS dot HI r0
	BLOS Eb150	;Not if LOS
		sub #2,dot                  ;go back one line
	MOV dot,r2
	SUB #24.,r2
	JSR PC,get.line
MOVB #esc,R0
	CALL TTYCC
MOVB #home,R0
	CALL TTYCC
MOVB #esc,R0
	CALL TTYCC
MOVB #insert,R0
	CALL TTYCC
MOVB #ESC,R0
	CALL TTYCC
MOVB #'R,R0
	CALL TTYCC
mov fpage,r0
	JSR PC,ttycc
jsr pc,ttflsh
		mov #lbuf1,r0               ;this is the line
	JSR PC,ttystr
	MOV #bottom-2,-(SP)
	MOV #col80,-(SP)
	CALL CURSR2
MOVB #esc,R0
	CALL TTYCC
MOVB #sdel,R0
	CALL TTYCC
MOVB #esc,R0
	CALL TTYCC
MOVB #ceop,R0
	CALL TTYCC
jsr pc,ttflsh
		jmp lcom2
	JMP Eb153
Eb150=.			; 
		dir$ #tofq
	JSR PC,tocurs
jsr pc,ttflsh
		jmp lcom1
Eb153=.			; 
Eb152=.
Eb148=.
	CMPB iosred+1,#downarrow		;Case #downarrow
	BNE Eb154
	    mov #1,arrows
	    br 20$
Eb154=.
	CMPB iosred+1,#cr		;Case #cr
	BNE Eb156
20$:                
	TST emode		;IS emode NE #0
	BEQ Eb158	;Not if EQ
	CMP arrows,#1		;IS arrows NE #1
	BEQ Eb161	;Not if EQ
	BR Eb164	;Here IF arrows NE #1
Eb161=.
	BR Eb158		;Here if not
Eb164=.
	JSR PC,addline
	JSR PC,inline
			        
	JMP Eb160
Eb158=.
	CMP dot,dol		;IS dot HIS dol
	BLO Eb165	;Not if LO
	JSR PC,addline
Eb165=.			; 
Eb160=.
            add #2,dot
	MOV dot,r2
	ADD #18.,r2
	JSR PC,get.line
MOVB #esc,R0
	CALL TTYCC
MOVB #home,R0
	CALL TTYCC
MOVB #esc,R0
	CALL TTYCC
MOVB #del,R0
	CALL TTYCC
	MOV #bottom-2,-(SP)
	MOV #1,-(SP)
	CALL CURSR2
MOVB #ESC,R0
	CALL TTYCC
MOVB #'R,R0
	CALL TTYCC
mov fpage,r0
	JSR PC,ttycc
            mov #lbuf1,r0
	JSR PC,ttystr
            jmp lcom2
			   
Eb156=.
	CMPB iosred+1,#con.z		;Case #con.z
	BNE Eb168
	    callr post
Eb145=.
Eb168=.
		   
		   
post:                      
	mov sdot,fdot
	TST ol		;IS ol NE #0
	BEQ Eb170	;Not if EQ
	MOV cursl,r1
	DEC r1
	MOV r1,-(SP)
	MOV #col80,-(SP)
	CALL CURSR2
MOVB #esc,R0
	CALL TTYCC
MOVB #sdel,R0
	CALL TTYCC
MOVB #ESC,R0
	CALL TTYCC
MOVB #'R,R0
	CALL TTYCC
mov fdot,r0
	JSR PC,ttycc
Eb170=.			; 
Eb172=.
	MOV #bottom-2,-(SP)
	MOV #1,-(SP)
	CALL CURSR2
jsr pc,ttflsh
	clr lmode
	clr emode
	clr setmar
	dir$ #retmul
	rts pc
		   
expand:      
	JSR PC,saval
	clr tabseen
	clr cnt
	mov #text,r0
	mov #etext-text+1,r1
2000$:  movb #space,(r0)+
	sob r1,2000$
		   
	mov #lbuf1,r1
	mov #text,r2
		   
Eb173=.
	JSR PC,eget
	BNE Eb175	;Not if NE
	JMP Eb174         ;break
Eb175=.			; 
Eb177=.
			   
	    inc cnt                 ;limit check
	CMP cnt,#lbs		;IS cnt GT #lbs
	BLE Eb178	;Not if LE
	JMP Eb174         ;break
Eb178=.			; 
Eb180=.
			
			
			
	CMP r0,#tab		;IS r0 = #tab
	BNE Eb181	;Not if NE
		mov #1,tabseen
		mov #space,r0
	JSR PC,eput
		push tabmsk
		mov #177770,tabmsk
Eb184=.
	JSR PC,tabstop
	BNE Eb186	;Not if NE
	JMP Eb185         ;break
Eb186=.			; 
Eb188=.
		    mov #space,r0
	JSR PC,eput
	JMP Eb184		;Repeat loop
Eb185=.
		pop tabmsk
	JMP Eb183
Eb181=.
	CMP r0,#nl		;IS r0 NE #nl
	BEQ Eb189	;Not if EQ
	JSR PC,eput
Eb189=.			; 
Eb183=.
	JMP Eb173		;Repeat loop
Eb174=.
	rts pc
		   
eget:                    
	movb (r1)+,r0
	bic #177400,r0
	rts pc
		   
eput:                    
	CMP r2,#etext		;IS r2 LO #etext
	BHIS Eb192	;Not if HIS
	    movb r0,(r2)+
Eb192=.			; 
Eb194=.
	rts pc
		   
tabstop:  
	CMP r2,#text+col80-1		;IS r2 HIS #text+col80-1
	BLO Eb195	;Not if LO
	    clr r3                       ;after col 80 or we'll loop
	    rts pc                       ;endlessly
Eb195=.			; 
Eb197=.
		
	CMP r2,#text		;IS r2 = #text
	BNE Eb198	;Not if NE
	    mov #1,r3                    ;force cond codes to non zero
	JMP Eb201
Eb198=.			; 
	    mov r2,r3
	    sub #text,r3
	    bic tabmsk,r3               ;use tab mask
Eb201=.			; 
Eb200=.
	rts pc
		   
compress:      
	JSR PC,saval
	mov #etext,r0				;delete trailing blanks
Eb202=.
	CMPB (r0),#space		;IS (r0) NE #space
	BEQ Eb204	;Not if EQ
	CMPB (r0),#nl		;IS (r0) NE #nl
	BEQ Eb207	;Not if EQ
	BR Eb210	;Here IFB (r0) NE #nl    
Eb207=.
	BR Eb204		;Here if not
Eb210=.
	JMP Eb203         ;break
Eb204=.			; 
Eb206=.
			       
	CMP r0,r1		;IS r0 LO r1
	BHIS Eb211	;Not if HIS
	JMP Eb203         ;break
Eb211=.			; 
Eb213=.
			       
	    dec r0				;next place
	JMP Eb202		;Repeat loop
Eb203=.
		   
	clrb 2(r0)
	movb #nl,1(r0)				;put the newline back at end
		   
	mov #lbuf1,r2
	TST tabseen		;IS tabseen NE #0
	BEQ Eb214	;Not if EQ
	CMP r1,#text		;IS r1 = #text
	BNE Eb217	;Not if NE
	TST ob		;IS ob = #0
	BNE Eb220	;Not if NE
	BR Eb223	;Here IF ob = #0
Eb220=.
	BR Eb217		;Here if not
Eb223=.
	BR Eb224	;Here IF r1 = #text AND ob = #0
Eb217=.
	BR Eb214		;Here if not
Eb224=.
	JSR PC,retab
Eb214=.			; 
Eb216=.
Eb225=.
	    movb (r1)+,(r2)+
	BNE Eb227	;Not if NE
	JMP Eb226         ;break
Eb227=.			; 
Eb229=.
	JMP Eb225		;Repeat loop
Eb226=.
	rts pc
		   
update:      
	TST iosred+2		;IS iosred+2 LE #0
	BGT Eb230	;Not if GT
	    rts pc
Eb230=.			; 
Eb232=.
		   
	inc chglin
		
	JSR PC,saval
	mov iosred+2,r0
	add #ib,r0			;address of end of input
	clrb (r0)			;asciz it
		   
	mov #ib,r1
	mov curser,r2
Eb233=.
	JSR PC,eget
	BNE Eb235	;Not if NE
	JMP Eb234         ;break
Eb235=.			; 
Eb237=.
	JSR PC,eput
	JMP Eb233		;Repeat loop
Eb234=.
	mov r2,curser			;update curser
	rts pc
		   
tabforward:      
	push r2
	mov curser,r2
Eb238=.
	    inc r2
	CMP r2,#text+col80-2		;IS r2 HIS #text+col80-2
	BLO Eb240	;Not if LO
		mov #text+col80-2,curser
	JSR PC,tocurs
jsr pc,ttflsh
	JMP Eb239         ;break
Eb240=.			; 
Eb242=.
			       
	JSR PC,tabstop
	BNE Eb243	;Not if NE
		mov r2,curser
	JSR PC,tocurs
jsr pc,ttflsh
	JMP Eb239         ;break
Eb243=.			; 
Eb245=.
			       
	JMP Eb238		;Repeat loop
Eb239=.
	pop r2
	rts pc
tabback:  
	push r2
	mov curser,r2
Eb246=.
	    dec r2
	CMP r2,#text		;IS r2 LOS #text
	BHI Eb248	;Not if HI
		mov #text,curser
	JSR PC,tocurs
jsr pc,ttflsh
	JMP Eb247         ;break
Eb248=.			; 
Eb250=.
			       
	JSR PC,tabstop
	BNE Eb251	;Not if NE
		mov r2,curser
	JSR PC,tocurs
jsr pc,ttflsh
	JMP Eb247         ;break
Eb251=.			; 
Eb253=.
			       
	JMP Eb246		;Repeat loop
Eb247=.
	pop r2
	rts pc
		   
inschar:  
	push r0
	mov #etext,r0
Eb254=.
	    movb -1(r0),(r0)
	    dec r0
	CMP R0,curser		;IS R0 LOS curser
	BHI Eb256	;Not if HI
		movb #space,@curser
	JMP Eb255         ;break
Eb256=.			; 
Eb258=.
	JMP Eb254		;Repeat loop
Eb255=.
	pop r0
	rts pc
deleol:  
	push r2
	mov curser,r2
Eb259=.
	CMP r2,#etext		;IS r2 LOS #etext
	BHI Eb261	;Not if HI
	JMP Eb264
Eb261=.			; 
	JMP Eb260	;else end  while loop
Eb264=.			; 
Eb263=.
	    movb #space,(r2)+
	JMP Eb259		;Repeat loop
Eb260=.
	pop r2
	rts pc
delchar:  
	push r0
	mov curser,r0
Eb265=.
	    movb 1(r0),(r0)
	    inc r0
	CMP r0,#etext		;IS r0 HI #etext
	BLOS Eb267	;Not if LOS
		movb #space,etext
	JMP Eb266         ;break
Eb267=.			; 
Eb269=.
	JMP Eb265		;Repeat loop
Eb266=.
	pop r0
	rts pc
adjust:      
	JSR PC,saval
	mov curser,r2
	mov r2,r1
Eb270=.
	CMPB (r2),#space		;IS (r2) NE #space
	BEQ Eb272	;Not if EQ
	JMP Eb271         ;break
Eb272=.			; 
Eb274=.
	    inc r2
	JMP Eb270		;Repeat loop
Eb271=.
		   
Eb275=.
	    movb (r2)+,(r1)+
	CMP r2,#etext		;IS r2 HI #etext
	BLOS Eb277	;Not if LOS
Eb280=.
	CMP r1,#etext		;IS r1 LOS #etext
	BHI Eb282	;Not if HI
	JMP Eb285
Eb282=.			; 
	JMP Eb281	;else end  while loop
Eb285=.			; 
Eb284=.
		    movb #space,(r1)+
	JMP Eb280		;Repeat loop
Eb281=.
	JMP Eb276         ;break
Eb277=.			; 
Eb279=.
	JMP Eb275		;Repeat loop
Eb276=.
	rts pc
tocurs:      
	push r1
	mov curser,r1
	sub #text-2,r1
	MOV cursl,-(SP)
	MOV r1,-(SP)
	CALL CURSR2
	pop r1
	rts pc
mov2wd:      
	clr cycle
	mov curser,scurser
	movb @curser,r0
	JSR PC,typch
	BNE Eb286	;Not if NE
Eb289=.
	JSR PC,nextcol
	CMP curser,#text		;IS curser = #text
	BNE Eb291	;Not if NE
	JMP Eb290         ;break
Eb291=.			; 
Eb293=.
		movb @curser,r0
	JSR PC,typch
	BEQ Eb294	;Not if EQ
	JMP Eb290         ;break
Eb294=.			; 
Eb296=.
	JMP Eb289		;Repeat loop
Eb290=.
Eb286=.			; 
Eb288=.
		   
Eb297=.
	    movb @curser,r0
	JSR PC,typch
	BNE Eb299	;Not if NE
	JMP Eb298         ;break
Eb299=.			; 
Eb301=.
	JSR PC,nextcol
			       
	CMP cycle,#1		;IS cycle GT #1
	BLE Eb302	;Not if LE
		mov scurser,curser
	JMP Eb298         ;break
Eb302=.			; 
Eb304=.
			       
	JMP Eb297		;Repeat loop
Eb298=.
	rts pc
		   
nextcol:  
	inc curser
	CMP curser,#text+col80-1		;IS curser HIS #text+col80-1
	BLO Eb305	;Not if LO
	    mov #text,curser
	    inc cycle
Eb305=.			; 
Eb307=.
	rts pc
typch:           
	CMPB r0,#'A		;IS r0 HIS #'A
	BLO Eb308	;Not if LO
	CMPB r0,#'Z		;IS r0 LOS #'Z
	BHI Eb311	;Not if HI
	BR Eb314	;Here IFB r0 LOS #'Z    
Eb311=.
	BR Eb308		;Here if not
Eb314=.
	    br 5000$
Eb308=.			; 
Eb310=.
	CMPB r0,#'a		;IS r0 HIS #'a
	BLO Eb315	;Not if LO
	CMPB r0,#'z		;IS r0 LOS #'z
	BHI Eb318	;Not if HI
	BR Eb321	;Here IFB r0 LOS #'z    
Eb318=.
	BR Eb315		;Here if not
Eb321=.
	    br 5000$
Eb315=.			; 
Eb317=.
	CMPB r0,#'0		;IS r0 HIS #'0
	BLO Eb322	;Not if LO
	CMPB r0,#'9		;IS r0 LOS #'9
	BHI Eb325	;Not if HI
	BR Eb328	;Here IFB r0 LOS #'9    
Eb325=.
	BR Eb322		;Here if not
Eb328=.
	    br 5000$
Eb322=.			; 
Eb324=.
	tst #1
	rts pc
5000$:  tst #0
	rts pc
		   
movright:      
	push r0
	push r2
	mov #text+col80,r2
	CMPB (r2),#space		;IS (r2) = #space
	BNE Eb329	;Not if NE
	    dec r2
Eb332=.
			                   
	CMPB -(r2),#space		;IS -(r2) NE #space
	BEQ Eb334	;Not if EQ
	JMP Eb333         ;break
Eb334=.			; 
Eb336=.
			                   
	CMP curser,r2		;IS curser HIS r2
	BLO Eb337	;Not if LO
	JMP Eb333         ;break
Eb337=.			; 
Eb339=.
			                   
MOVB #esc,R0
	CALL TTYCC
MOVB #'P,R0
	CALL TTYCC
jsr pc,ttflsh
		nop 
	JMP Eb332		;Repeat loop
Eb333=.
Eb329=.			; 
Eb331=.
	pop r2
	pop r0
	rts pc
		   
saveln:      
	push r1
	push r0
	mov curser,r0
	mov #lbuf3,r1
Eb340=.
	CMP r0,#etext		;IS r0 HI #etext
	BLOS Eb342	;Not if LOS
		clrb (r1)
	JMP Eb341         ;break
Eb342=.			; 
Eb344=.
	    movb (r0)+,(r1)+
	JMP Eb340		;Repeat loop
Eb341=.
	pop r0
	pop r1
	rts pc
		   
edone:          
		   
	mov #etext,r2
Eb345=.
	CMPB (r2),#space		;IS (r2) NE #space
	BEQ Eb347	;Not if EQ
		inc r2
	JMP Eb346         ;break
Eb347=.			; 
Eb349=.
			   
	CMP r2,curser		;IS r2 LOS curser
	BHI Eb350	;Not if HI
	JMP Eb346         ;break
Eb350=.			; 
Eb352=.
	    dec r2
	JMP Eb345		;Repeat loop
Eb346=.
		   
	mov #lbuf3,r1
Eb353=.
	JSR PC,eget
	BNE Eb355	;Not if NE
	JMP Eb354         ;break
Eb355=.			; 
Eb357=.
	JSR PC,eput
	JMP Eb353		;Repeat loop
Eb354=.
		   
	MOV cursl,-(SP)
	MOV #1,-(SP)
	CALL CURSR2
	mov #text,r1
	MOV #1,R2	;Init loop index
Eb358=.
	CMP R2,#col80-1	;done loop?
	BGT Eb359	;yes if GT
MOVB @R1,R0
	CALL TTYCC
	    inc r1
	INC R2
	JMP Eb358		;back to top
Eb359=.
	JSR PC,tocurs
jsr pc,ttflsh
	rts pc
		
findend: 
	mov #etext,r0
Eb360=.
	CMP r0,#text		;IS r0 LOS #text
	BHI Eb362	;Not if HI
		mov #text,r0
	JMP Eb361         ;break
Eb362=.			; 
Eb364=.
			
	CMPB -(r0),#space		;IS -(r0) NE #space
	BEQ Eb365	;Not if EQ
		inc r0
	JMP Eb361         ;break
Eb365=.			; 
Eb367=.
	JMP Eb360		;Repeat loop
Eb361=.
	rts pc
		
		
matcher: 
	push r0
	push r1
	push r3
	JSR PC,findend
	mov r0,r3                   ;save
	movb #nl,(r0)+
	clrb (r0)                   ;nl and asciiz it for match routine
	mov r2,r0		;get starting location
	mov #pbuf,r1
	mov r0,r2                   ;copy
Eb368=.
	JSR PC,match
	BCS Eb370	;Not if CS
	JMP Eb369         ;break
	JMP Eb373
Eb370=.			; 
		inc r2
		mov r2,r0                       ;next col to try
	TSTB (r0)		;IS (r0) = #0
	BNE Eb374	;Not if NE
		    clr r2
	JMP Eb369         ;break
Eb374=.			; 
Eb376=.
Eb373=.			; 
Eb372=.
	JMP Eb368		;Repeat loop
Eb369=.
	movb #space,(r3)+
	movb #space,(r3)+
		
	pop r3
	pop r1
	pop r0
	rts pc
		
addline: 
	JSR PC,saval
		
	mov #10$,r4                  ; address of routine to get chars
	mov dot,r5                   ; append after here
	JSR PC,append
	sub #2,dot                   ; back up
		
	rts pc               ;done
		
10$:    mov #nl,lbuf1                ; put a null line into lbuf1
15$:    mov #20$,r4                  ; change input routine to end of file ret
	clc                          ; return one line
	rts pc
20$:    sec                          ; return end of input
	rts pc
		
		
		
		
	addlbuf=. 
	JSR PC,saval
	mov #15$,r4                     ;this routine just appends
	mov dot,r5                      ;lbuf1 to the text buffer
	JSR PC,append
	sub #2,dot                      ;it leaves dot in place
	rts pc
		
		
		
retab:    
	push r4
	push r3
	push r0
	mov r1,r3
	clr r4
Eb377=.
	CMPB (r3)+,#space		;IS (r3)+ NE #space
	BEQ Eb379	;Not if EQ
	JMP Eb378         ;break
Eb379=.			; 
Eb381=.
	    inc r4
	JMP Eb377		;Repeat loop
Eb378=.
	bic #7,r4                       ;round down to number of tab columns
	add r4,r1                       ;this where the text starts
	asr r4
	asr r4                          ;
	asr r4                          ;this many tabs can be used instead
		
	MOV #1,r0	;Init loop index
Eb382=.
	CMP r0,r4	;done loop?
	BGT Eb383	;yes if GT
	    dec r1                        ;backup and
	    movb #tab,(r1)                ;precede buffer with a tab here
	INC r0
	JMP Eb382		;back to top
Eb383=.
		
	pop r0
	pop r3
	pop r4
	rts pc
cut:        
	JSR PC,saval
	JSR PC,deleol
MOVB #esc,R0
	CALL TTYCC
MOVB #'K,R0
	CALL TTYCC
jsr pc,ttflsh
	JSR PC,addlbuf
	JSR PC,inline
	mov #lbuf1,r0                   ;and
	JSR PC,ttystr
	JSR PC,tocurs
jsr pc,ttflsh
	rts pc
		
		
		
drag:                                   ;drag tag along with curser
	TST oa		;IS oa NE #0
	BEQ Eb384	;Not if EQ
	MOV curser,coln
	SUB #text,coln
	INC coln
Eb384=.			; 
Eb386=.
	rts pc
		
		
.END 
