                
$auto$=-2
.enabl lc
;15-aug-80 for Conroy C runtime
        .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$ see below
                
                
                
read:
        .BYTE 3,12.
.WORD io.rtt
.WORD 1
.BYTE 1,0
.WORD iosred
.WORD 0
.WORD ib
.WORD ibsize
.WORD 0
.WORD tbl
.WORD 0
.WORD 0
helpq:
        .BYTE 3,12.
.WORD io.wvb
.WORD 1
.BYTE 1,0
.WORD 0
.WORD 0
.WORD help
.WORD ehelp-help
.WORD 0
.WORD 0
.WORD 0
.WORD 0
helpq2:
        .BYTE 3,12.
.WORD io.wvb
.WORD 1
.BYTE 1,0
.WORD 0
.WORD 0
.WORD help2
.WORD ehelp2-help2
.WORD 0
.WORD 0
.WORD 0
.WORD 0
tofq:
        .BYTE 3,12.
.WORD io.wvb
.WORD 1
.BYTE 1,0
.WORD 0
.WORD 0
.WORD tof
.WORD etof-tof
.WORD 0
.WORD 0
.WORD 0
.WORD 0
setmul:
        .BYTE 3,12.
.WORD sf.smc
.WORD 1
.BYTE 1,0
.WORD setios
.WORD 0
.WORD setm
.WORD esetm-setm
.WORD 0
.WORD 0
.WORD 0
.WORD 0
getmul:
        .BYTE 3,12.
.WORD sf.gmc
.WORD 1
.BYTE 1,0
.WORD setios
.WORD 0
.WORD retm
.WORD eretm-retm
.WORD 0
.WORD 0
.WORD 0
.WORD 0
retmul:
        .BYTE 3,12.
.WORD sf.smc
.WORD 1
.BYTE 1,0
.WORD setios
.WORD 0
.WORD retm
.WORD eretm-retm
.WORD 0
.WORD 0
.WORD 0
.WORD 0
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,  132.,   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
        colon   =   72
        semicolon   =   73
        lbr     =   133
                
        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
        line         =  0
        col80        =  81.
        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
        .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 
pcmd:   .ascii /.p/<nl>         ;this restores the underline on exit
        pcmdl=.-pcmd 
lbcmd:  .ascii /b/<nl>/l/       ;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
cprflg: .word 0 ;flag used by compress
                
                
        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=.
        mov fpage,r1
        bic #10,r1
        mov fdot,sdot
        mov r1,fdot
                
                
	JSR PC,getc
	CMP r0,#nl		;IS r0 = #nl
	BNE Eb14	;Not if NE
            mov pat,spat
            clr pat
	JMP Eb17
Eb14=.			; 
	CMP r0,#'#		;IS r0 = #'#
	BNE Eb18	;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 Eb21	;Not if EQ
                    mov #2,r1          ; bad command error
                    jmp error          ;
Eb21=.			; 
Eb23=.
                mov pat,spat
                clr pat
                                
	JMP Eb24
Eb18=.			; 
                mov #1,pat              ;its definitively a pattern
	CMPB r0,#'/		;IS r0 = #'/
	BNE Eb25	;Not if NE
	JSR PC,compil
	JMP Eb28
Eb25=.			; 
                    mov r0,peek                     ;put back (1st char in pattern)
                    mov #1,r0                       ;use control a as del
	JSR PC,compil
Eb28=.			; 
Eb27=.
Eb24=.			; 
Eb20=.
Eb17=.			; 
Eb16=.
        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
	TST firsttime		;IS firsttime NE #0
	BEQ Eb29	;Not if EQ
	MOV r0,-(SP)
        MOV cursl,-(SP)
        MOV #1,-(SP)
        CALL CURSR2
jsr pc,ttflsh
            mov #lbuf1,r0
	JSR PC,ttystr
	MOV (SP)+,r0
Eb29=.			; 
Eb31=.
	JSR PC,expand
        clr chglin
        clr firsttime
	TST arrows		;IS arrows = #0
	BNE Eb32	;Not if NE
	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
	BLOS .+6	;Stay in loop
	JMP Eb64	;else end  while loop
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 Eb65
	JSR PC,tabback
            jmp lcom1
Eb65=.
	CMPB iosred+1,#con.v		;Case #con.v
	BNE Eb67
                        
            mov curser,r1
	JSR PC,compress
                        
	JSR PC,cut
            inc chglin
            jmp lcom1
Eb67=.
	CMPB iosred+1,#con.d		;Case #con.d
	BNE Eb69
	JSR PC,delete
MOVB #esc,R0
        CALL TTYCC
MOVB #'K,R0
        CALL TTYCC
jsr pc,ttflsh
            inc chglin
            jmp lcom1
Eb69=.
	CMPB iosred+1,#con.o		;Case #con.o
	BNE Eb71
	TST omode		;IS omode = #0
	BNE Eb73	;Not if NE
                inc omode               ;set flag indicating mode
	JSR PC,saveln
	JSR PC,movright
	JSR PC,delete
                inc chglin
                jmp lcom1
	JMP Eb76
Eb73=.			; 
omode2:                                      
	JSR PC,edone
                clr omode
                jmp lcom1
Eb76=.			; 
Eb75=.
Eb71=.
	CMPB iosred+1,#con.i		;Case #con.i
	BNE Eb77
            inc tabseen
	JSR PC,tabforward
            jmp lcom1
                           
Eb77=.
	CMPB iosred+1,#con.j		;Case #con.j
	BNE Eb79
	CMP curser,#text		;IS curser HI #text
	BLOS Eb81	;Not if LOS
                dec curser
	JSR PC,tocurs
jsr pc,ttflsh
Eb81=.			; 
Eb83=.
            jmp lcom1
Eb79=.
	CMPB iosred+1,#con.k		;Case #con.k
	BNE Eb84
	CMP curser,#text+col80-2		;IS curser LO #text+col80-2
	BHIS Eb86	;Not if HIS
                inc curser
	JSR PC,tocurs
jsr pc,ttflsh
Eb86=.			; 
Eb88=.
            jmp lcom1
Eb84=.
	CMPB iosred+1,#con.l		;Case #con.l
	BNE Eb89
	JSR PC,delchar
                        
	JSR PC,redraw
	JSR PC,last2
            inc chglin
            jmp lcom1
                        
last2:      				;this is simulated on vt100
        MOV cursl,-(SP)
        MOV #col80-2,-(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
            rts pc
redraw:     				;redraw screen from current cursor position
	JSR PC,saval
MOVB #esc,R0
        CALL TTYCC
MOVB #'K,R0
        CALL TTYCC
            mov curser,r1
            push ob
            mov #1,ob
	JSR PC,icompress
            pop ob
            mov #lbuf1,r0
	MOV #lbuf1,r2
	ADD #text+col80,r2
	SUB curser,r2
	SUB #2,r2
	CMP r2,#lbuf1		;IS r2 HIS #lbuf1
	BLO Eb91	;Not if LO
	CMP r2,#lbuf1+lbs-2		;IS r2 LOS #lbuf1+lbs-2
	BHI Eb94	;Not if HI
	BR Eb97	;Here IF r2 LOS #lbuf1+lbs-2
Eb94=.
	BR Eb91		;Here if not
Eb97=.
                movb (r2),r3
                clrb (r2)
	JSR PC,out
                movb r3,(r2)
	JMP Eb98
Eb91=.			; 
	JSR PC,out
Eb98=.			; 
Eb93=.
	JSR PC,tocurs
jsr pc,ttflsh
            rts pc
out:                
	JSR PC,saval
	JSR PC,ttystr
            rts pc
                        
Eb89=.
	CMPB iosred+1,#con.e		;Case #con.e
	BNE Eb99
            com emode
	JSR PC,tocurs
jsr pc,ttflsh
            jmp lcom1
                        
inline:          
                        
	JSR PC,ansi
MOVB #esc,R0
        CALL TTYCC
MOVB #lbr,R0
        CALL TTYCC
MOVB #'1,R0
        CALL TTYCC
MOVB #semicolon,R0
        CALL TTYCC
MOVB #'1,R0
        CALL TTYCC
MOVB #'3,R0
        CALL TTYCC
MOVB #'r,R0
        CALL TTYCC
MOVB #esc,R0
        CALL TTYCC
MOVB #lbr,R0
        CALL TTYCC
MOVB #'1,R0
        CALL TTYCC
MOVB #'3,R0
        CALL TTYCC
MOVB #semicolon,R0
        CALL TTYCC
MOVB #'1,R0
        CALL TTYCC
MOVB #'f,R0
        CALL TTYCC
MOVB #esc,R0
        CALL TTYCC
MOVB #'D,R0
        CALL TTYCC
MOVB #esc,R0
        CALL TTYCC
MOVB #lbr,R0
        CALL TTYCC
MOVB #'1,R0
        CALL TTYCC
MOVB #semicolon,R0
        CALL TTYCC
MOVB #'2,R0
        CALL TTYCC
MOVB #'4,R0
        CALL TTYCC
MOVB #'r,R0
        CALL TTYCC
	JSR PC,vt52
	JSR PC,tocurs
jsr pc,ttflsh
            rts pc
                        
                        
Eb99=.
	CMPB iosred+1,#con.p		;Case #con.p
	BNE Eb101
	TST spat		;IS spat NE #0
	BEQ Eb103	;Not if EQ
                mov spat,pat
Eb103=.			; 
Eb105=.
                        
	TST pat		;IS pat NE #0
	BEQ Eb106	;Not if EQ
                mov curser,r2	;start at curser +1
                inc r2
	JSR PC,matcher
	TST r2		;IS r2 = #0
	BNE Eb109	;Not if NE
                    mov #text,r2
	JSR PC,matcher
	TST r2		;IS r2 NE #0
	BEQ Eb112	;Not if EQ
                        br 3000$
Eb112=.			; 
Eb114=.
	JMP Eb115
Eb109=.			; 
3000$:                            
	CMP r2,#text+col80-2		;IS r2 HIS #text+col80-2
	BLO Eb116	;Not if LO
                        mov #text,curser
	JMP Eb119
Eb116=.			; 
                        mov r2,curser
Eb119=.			; 
Eb118=.
Eb115=.			; 
Eb111=.
	JMP Eb120
Eb106=.			; 
                mov coln,curser
                add #text-1,curser
Eb120=.			; 
Eb108=.
	JSR PC,tocurs
jsr pc,ttflsh
            jmp lcom1
Eb101=.
	CMPB iosred+1,#con.r		;Case #con.r
	BNE Eb121
	JSR PC,inschar
	JSR PC,redraw
	JSR PC,last2
            inc chglin
            jmp lcom1
Eb121=.
	CMPB iosred+1,#con.t		;Case #con.t
	BNE Eb123
            mov curser,coln
            sub #text,coln
            inc coln
            inc tabseen
            inc tagset
            mov pat,spat
            clr pat
            jmp lcom1
Eb123=.
	CMPB iosred+1,#con.u		;Case #con.u
	BNE Eb125
            mov #restor,r0
            mov #restl,r1
            clr chglin
            callr putbak                        ;.pl cmd renter   setup curser
Eb125=.
	CMPB iosred+1,#con.w		;Case #con.w
	BNE Eb127
	JSR PC,mov2wd
	JSR PC,tocurs
jsr pc,ttflsh
            jmp lcom1
Eb48=.
Eb127=.
                   
	TST omode		;IS omode GT #0
	BLE Eb129	;Not if LE
            jmp omode2				;all exits go here
Eb129=.			; 
Eb131=.
                   
                   
	TST chglin		;IS chglin GT #0
	BLE Eb132	;Not if LE
            mov #text,r1    ;move all text in `text'
	JSR PC,compress
	JSR PC,putlin
            mov r0,@dot     ;replace line dot
Eb132=.			; 
Eb134=.
                   
                   
Eb135=.
	CMPB iosred+1,#uparrow		;Case #uparrow
	BNE Eb137
            mov #1,arrows
            br 1000$
Eb137=.
	CMPB iosred+1,#esc		;Case #esc
	BNE Eb139
1000$:            
	MOV ZERO,R0
	ADD #2,R0
	CMP dot,r0		;IS dot HI r0
	BLOS Eb141	;Not if LOS
                mov #up,r0
                mov #upl,r1
                callr putbak
	JMP Eb144
Eb141=.			; 
                dir$ #tofq
	JSR PC,tocurs
jsr pc,ttflsh
                jmp lcom1
Eb144=.			; 
Eb143=.
Eb139=.
	CMPB iosred+1,#downarrow		;Case #downarrow
	BNE Eb145
            mov #1,arrows
            br 20$
Eb145=.
	CMPB iosred+1,#cr		;Case #cr
	BNE Eb147
20$:                
	TST emode		;IS emode NE #0
	BEQ Eb149	;Not if EQ
	CMP arrows,#1		;IS arrows NE #1
	BEQ Eb152	;Not if EQ
	BR Eb155	;Here IF arrows NE #1
Eb152=.
	BR Eb149		;Here if not
Eb155=.
	JSR PC,addline
	JSR PC,inline
                add #2,dot
                mov #restor,r0
                mov #restl,r1
                callr putbak
	JMP Eb151
Eb149=.
	CMP dot,dol		;IS dot HIS dol
	BLO Eb156	;Not if LO
	JSR PC,addline
Eb156=.			; 
Eb151=.
            mov #dwn,r0
            mov #dwnl,r1
            callr putbak
                           
Eb147=.
	CMPB iosred+1,#con.z		;Case #con.z
	BNE Eb159
            callr post
Eb136=.
Eb159=.
                   
                   
post:                      
        mov sdot,fdot
        MOV #bottom-2,-(SP)
        MOV #1,-(SP)
        CALL CURSR2
jsr pc,ttflsh
        clr lmode
        clr emode
        clr setmar
        dir$ #retmul
        mov #pcmd,r0
        mov #pcmdl,r1
        callr putbak
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
                   
Eb161=.
	JSR PC,eget
	BNE Eb163	;Not if NE
	JMP Eb162         ;break
Eb163=.			; 
Eb165=.
                           
            inc cnt                 ;limit check
	CMP cnt,#lbs		;IS cnt GT #lbs
	BLE Eb166	;Not if LE
	JMP Eb162         ;break
Eb166=.			; 
Eb168=.
                        
                        
                        
	CMP r0,#tab		;IS r0 = #tab
	BNE Eb169	;Not if NE
                mov #1,tabseen
                mov #space,r0
	JSR PC,eput
Eb172=.
	JSR PC,tabstop
	BNE Eb174	;Not if NE
	JMP Eb173         ;break
Eb174=.			; 
Eb176=.
                    mov #space,r0
	JSR PC,eput
	JMP Eb172		;Repeat loop
Eb173=.
	JMP Eb171
Eb169=.
	CMP r0,#nl		;IS r0 NE #nl
	BEQ Eb177	;Not if EQ
	JSR PC,eput
Eb177=.			; 
Eb171=.
	JMP Eb161		;Repeat loop
Eb162=.
        rts pc
                   
eget:                    
        movb (r1)+,r0
        bic #177400,r0
        rts pc
                   
eput:                    
	CMP r2,#etext		;IS r2 LO #etext
	BHIS Eb180	;Not if HIS
            movb r0,(r2)+
Eb180=.			; 
Eb182=.
        rts pc
                   
tabstop:  
	CMP r2,#text+col80-1		;IS r2 HIS #text+col80-1
	BLO Eb183	;Not if LO
            clr r3                       ;after col 80 or we'll loop
            rts pc                       ;endlessly
Eb183=.			; 
Eb185=.
                
	CMP r2,#text		;IS r2 = #text
	BNE Eb186	;Not if NE
            mov #1,r3                    ;force cond codes to non zero
	JMP Eb189
Eb186=.			; 
            mov r2,r3
            sub #text,r3
            bic tabmsk,r3
Eb189=.			; 
Eb188=.
        rts pc
icompress:  
        clr cprflg
        br com1
compress:      
        mov #1,cprflg
com1:      
	JSR PC,saval
        mov #etext,r0				;delete trailing blanks
Eb190=.
	CMPB (r0),#space		;IS (r0) NE #space
	BEQ Eb192	;Not if EQ
	CMPB (r0),#nl		;IS (r0) NE #nl
	BEQ Eb195	;Not if EQ
	BR Eb198	;Here IFB (r0) NE #nl    
Eb195=.
	BR Eb192		;Here if not
Eb198=.
	JMP Eb191         ;break
Eb192=.			; 
Eb194=.
                               
	CMP r0,r1		;IS r0 LO r1
	BHIS Eb199	;Not if HIS
	JMP Eb191         ;break
Eb199=.			; 
Eb201=.
                               
            dec r0				;next place
	JMP Eb190		;Repeat loop
Eb191=.
	TST cprflg		;IS cprflg NE #0
	BEQ Eb202	;Not if EQ
            clrb 2(r0)
            movb #nl,1(r0)				;put the newline back at end
Eb202=.			; 
Eb204=.
        mov #lbuf1,r2
	TST tabseen		;IS tabseen NE #0
	BEQ Eb205	;Not if EQ
	CMP r1,#text		;IS r1 = #text
	BNE Eb208	;Not if NE
	TST ob		;IS ob = #0
	BNE Eb211	;Not if NE
	BR Eb214	;Here IF ob = #0
Eb211=.
	BR Eb208		;Here if not
Eb214=.
	BR Eb215	;Here IF r1 = #text AND ob = #0
Eb208=.
	BR Eb205		;Here if not
Eb215=.
	JSR PC,retab
Eb205=.			; 
Eb207=.
Eb216=.
            movb (r1)+,(r2)+
	BNE Eb218	;Not if NE
	JMP Eb217         ;break
Eb218=.			; 
Eb220=.
	JMP Eb216		;Repeat loop
Eb217=.
        rts pc
                   
update:      
	TST iosred+2		;IS iosred+2 LE #0
	BGT Eb221	;Not if GT
            rts pc
Eb221=.			; 
Eb223=.
                   
        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
Eb224=.
	JSR PC,eget
	BNE Eb226	;Not if NE
	JMP Eb225         ;break
Eb226=.			; 
Eb228=.
	JSR PC,eput
	JMP Eb224		;Repeat loop
Eb225=.
        mov r2,curser			;update curser
        rts pc
                   
tabforward:      
        push r2
        mov curser,r2
Eb229=.
            inc r2
	CMP r2,#text+col80-2		;IS r2 HIS #text+col80-2
	BLO Eb231	;Not if LO
                mov #text+col80-2,curser
	JSR PC,tocurs
jsr pc,ttflsh
	JMP Eb230         ;break
Eb231=.			; 
Eb233=.
                               
	JSR PC,tabstop
	BNE Eb234	;Not if NE
                mov r2,curser
	JSR PC,tocurs
jsr pc,ttflsh
	JMP Eb230         ;break
Eb234=.			; 
Eb236=.
                               
	JMP Eb229		;Repeat loop
Eb230=.
        pop r2
        rts pc
tabback:  
        push r2
        mov curser,r2
Eb237=.
            dec r2
	CMP r2,#text		;IS r2 LOS #text
	BHI Eb239	;Not if HI
                mov #text,curser
	JSR PC,tocurs
jsr pc,ttflsh
	JMP Eb238         ;break
Eb239=.			; 
Eb241=.
                               
	JSR PC,tabstop
	BNE Eb242	;Not if NE
                mov r2,curser
	JSR PC,tocurs
jsr pc,ttflsh
	JMP Eb238         ;break
Eb242=.			; 
Eb244=.
                               
	JMP Eb237		;Repeat loop
Eb238=.
        pop r2
        rts pc
                   
inschar:  
        push r0
        mov #etext,r0
Eb245=.
            movb -1(r0),(r0)
            dec r0
	CMP R0,curser		;IS R0 LOS curser
	BHI Eb247	;Not if HI
                movb #space,@curser
	JMP Eb246         ;break
Eb247=.			; 
Eb249=.
	JMP Eb245		;Repeat loop
Eb246=.
        pop r0
        rts pc
delete:      
        push r2
        mov curser,r2
Eb250=.
	CMP r2,#etext		;Is r2 LOS #etext
	BLOS .+6	;Stay in loop
	JMP Eb251	;else end  while loop
            movb #space,(r2)+
	JMP Eb250		;Repeat loop
Eb251=.
        pop r2
        rts pc
delchar:  
        push r0
        mov curser,r0
Eb252=.
            movb 1(r0),(r0)
            inc r0
	CMP r0,#etext		;IS r0 HI #etext
	BLOS Eb254	;Not if LOS
                movb #space,etext
	JMP Eb253         ;break
Eb254=.			; 
Eb256=.
	JMP Eb252		;Repeat loop
Eb253=.
        pop r0
        rts pc
adjust:      
	JSR PC,saval
        mov curser,r2
        mov r2,r1
Eb257=.
	CMPB (r2),#space		;IS (r2) NE #space
	BEQ Eb259	;Not if EQ
	JMP Eb258         ;break
Eb259=.			; 
Eb261=.
            inc r2
	JMP Eb257		;Repeat loop
Eb258=.
                   
Eb262=.
            movb (r2)+,(r1)+
	CMP r2,#etext		;IS r2 HI #etext
	BLOS Eb264	;Not if LOS
Eb267=.
	CMP r1,#etext		;Is r1 LOS #etext
	BLOS .+6	;Stay in loop
	JMP Eb268	;else end  while loop
                    movb #space,(r1)+
	JMP Eb267		;Repeat loop
Eb268=.
	JMP Eb263         ;break
Eb264=.			; 
Eb266=.
	JMP Eb262		;Repeat loop
Eb263=.
        rts pc
        vt100=1 
tocurs:      
        push r1
        mov curser,r1
        sub #text-2+vt100,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 Eb269	;Not if NE
Eb272=.
	JSR PC,nextcol
	CMP curser,#text		;IS curser = #text
	BNE Eb274	;Not if NE
	JMP Eb273         ;break
Eb274=.			; 
Eb276=.
                movb @curser,r0
	JSR PC,typch
	BEQ Eb277	;Not if EQ
	JMP Eb273         ;break
Eb277=.			; 
Eb279=.
	JMP Eb272		;Repeat loop
Eb273=.
Eb269=.			; 
Eb271=.
                   
Eb280=.
            movb @curser,r0
	JSR PC,typch
	BNE Eb282	;Not if NE
	JMP Eb281         ;break
Eb282=.			; 
Eb284=.
	JSR PC,nextcol
                               
	CMP cycle,#1		;IS cycle GT #1
	BLE Eb285	;Not if LE
                mov scurser,curser
	JMP Eb281         ;break
Eb285=.			; 
Eb287=.
                               
	JMP Eb280		;Repeat loop
Eb281=.
        rts pc
                   
nextcol:  
        inc curser
	CMP curser,#text+col80-1		;IS curser HIS #text+col80-1
	BLO Eb288	;Not if LO
            mov #text,curser
            inc cycle
Eb288=.			; 
Eb290=.
        rts pc
typch:           
	CMPB r0,#'A		;IS r0 HIS #'A
	BLO Eb291	;Not if LO
	CMPB r0,#'Z		;IS r0 LOS #'Z
	BHI Eb294	;Not if HI
	BR Eb297	;Here IFB r0 LOS #'Z    
Eb294=.
	BR Eb291		;Here if not
Eb297=.
            br 5000$
Eb291=.			; 
Eb293=.
	CMPB r0,#'a		;IS r0 HIS #'a
	BLO Eb298	;Not if LO
	CMPB r0,#'z		;IS r0 LOS #'z
	BHI Eb301	;Not if HI
	BR Eb304	;Here IFB r0 LOS #'z    
Eb301=.
	BR Eb298		;Here if not
Eb304=.
            br 5000$
Eb298=.			; 
Eb300=.
	CMPB r0,#'0		;IS r0 HIS #'0
	BLO Eb305	;Not if LO
	CMPB r0,#'9		;IS r0 LOS #'9
	BHI Eb308	;Not if HI
	BR Eb311	;Here IFB r0 LOS #'9    
Eb308=.
	BR Eb305		;Here if not
Eb311=.
            br 5000$
Eb305=.			; 
Eb307=.
        tst #1
        rts pc
5000$:  tst #0
        rts pc
                   
movright:      
        push r0
        push r2
        push r3
        clr r3
        mov #text+col80,r2
	CMPB (r2),#space		;IS (r2) = #space
	BNE Eb312	;Not if NE
            dec r2
Eb315=.
                                           
	CMPB -(r2),#space		;IS -(r2) NE #space
	BEQ Eb317	;Not if EQ
	JMP Eb316         ;break
Eb317=.			; 
Eb319=.
                                           
	CMP curser,r2		;IS curser HIS r2
	BLO Eb320	;Not if LO
	JMP Eb316         ;break
Eb320=.			; 
Eb322=.
                                           
                inc r3
                nop 
	JMP Eb315		;Repeat loop
Eb316=.
Eb312=.			; 
Eb314=.
MOVB #esc,R0
        CALL TTYCC
MOVB #'K,R0
        CALL TTYCC
jsr pc,ttflsh
        push curser
        ADD r3,curser
	JSR PC,tocurs
        pop curser
	JSR PC,redraw
        pop r3
        pop r2
        pop r0
        rts pc
                   
saveln:      
        push r1
        push r0
        mov curser,r0
        mov #lbuf3,r1
Eb323=.
	CMP r0,#etext		;IS r0 HI #etext
	BLOS Eb325	;Not if LOS
                clrb (r1)
	JMP Eb324         ;break
Eb325=.			; 
Eb327=.
            movb (r0)+,(r1)+
	JMP Eb323		;Repeat loop
Eb324=.
        pop r0
        pop r1
        rts pc
                   
edone:          
                   
        mov #etext,r2
Eb328=.
	CMPB (r2),#space		;IS (r2) NE #space
	BEQ Eb330	;Not if EQ
                inc r2
	JMP Eb329         ;break
Eb330=.			; 
Eb332=.
                           
	CMP r2,curser		;IS r2 LOS curser
	BHI Eb333	;Not if HI
	JMP Eb329         ;break
Eb333=.			; 
Eb335=.
            dec r2
	JMP Eb328		;Repeat loop
Eb329=.
                   
        mov #lbuf3,r1
Eb336=.
	JSR PC,eget
	BNE Eb338	;Not if NE
	JMP Eb337         ;break
Eb338=.			; 
Eb340=.
	JSR PC,eput
	JMP Eb336		;Repeat loop
Eb337=.
                   
        MOV cursl,-(SP)
        MOV #1,-(SP)
        CALL CURSR2
        mov #text,r1
	MOV #1,R2	;Init loop index
Eb341=.
	CMP R2,#col80-1	;done loop?
	BGT Eb342	;yes if GT
MOVB @R1,R0
        CALL TTYCC
            inc r1
	INC R2
	JMP Eb341		;back to top
Eb342=.
	JSR PC,tocurs
jsr pc,ttflsh
        rts pc
                
findend: 
        mov #etext,r0
Eb343=.
	CMP r0,#text		;IS r0 LOS #text
	BHI Eb345	;Not if HI
                mov #text,r0
	JMP Eb344         ;break
Eb345=.			; 
Eb347=.
                        
	CMPB -(r0),#space		;IS -(r0) NE #space
	BEQ Eb348	;Not if EQ
                inc r0
	JMP Eb344         ;break
Eb348=.			; 
Eb350=.
	JMP Eb343		;Repeat loop
Eb344=.
        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
Eb351=.
	JSR PC,match
	BCS Eb353	;Not if CS
	JMP Eb352         ;break
	JMP Eb356
Eb353=.			; 
                inc r2
                mov r2,r0                       ;next col to try
	TSTB (r0)		;IS (r0) = #0
	BNE Eb357	;Not if NE
                    clr r2
	JMP Eb352         ;break
Eb357=.			; 
Eb359=.
Eb356=.			; 
Eb355=.
	JMP Eb351		;Repeat loop
Eb352=.
        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
Eb360=.
	CMPB (r3)+,#space		;IS (r3)+ NE #space
	BEQ Eb362	;Not if EQ
	JMP Eb361         ;break
Eb362=.			; 
Eb364=.
            inc r4
	JMP Eb360		;Repeat loop
Eb361=.
        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
Eb365=.
	CMP r0,r4	;done loop?
	BGT Eb366	;yes if GT
            dec r1                        ;backup and
            movb #tab,(r1)                ;precede buffer with a tab here
	INC r0
	JMP Eb365		;back to top
Eb366=.
                
        pop r0
        pop r3
        pop r4
        rts pc
cut:        
                
                
                
	JSR PC,saval
	JSR PC,delete
MOVB #esc,R0
        CALL TTYCC
MOVB #'K,R0
        CALL TTYCC
jsr pc,ttflsh
	JSR PC,addlbuf
	JSR PC,ansi
MOVB #esc,R0
        CALL TTYCC
MOVB #lbr,R0
        CALL TTYCC
MOVB #'1,R0
        CALL TTYCC
MOVB #'4,R0
        CALL TTYCC
MOVB #semicolon,R0
        CALL TTYCC
MOVB #'2,R0
        CALL TTYCC
MOVB #'2,R0
        CALL TTYCC
MOVB #'r,R0
        CALL TTYCC
MOVB #esc,R0
        CALL TTYCC
MOVB #lbr,R0
        CALL TTYCC
MOVB #'1,R0
        CALL TTYCC
MOVB #'4,R0
        CALL TTYCC
MOVB #semicolon,R0
        CALL TTYCC
MOVB #'1,R0
        CALL TTYCC
MOVB #'f,R0
        CALL TTYCC
MOVB #esc,R0
        CALL TTYCC
MOVB #'M,R0
        CALL TTYCC
MOVB #esc,R0
        CALL TTYCC
MOVB #lbr,R0
        CALL TTYCC
MOVB #'1,R0
        CALL TTYCC
MOVB #semicolon,R0
        CALL TTYCC
MOVB #'2,R0
        CALL TTYCC
MOVB #'4,R0
        CALL TTYCC
MOVB #'r,R0
        CALL TTYCC
	JSR PC,vt52
jsr pc,ttflsh
	MOV cursl,r1
	INC r1
        MOV r1,-(SP)
        MOV #1,-(SP)
        CALL CURSR2
                
        mov #lbuf1,r0                           ;and
	JSR PC,ttystr
	JSR PC,tocurs
                
jsr pc,ttflsh
        rts pc
                
ansi:      
MOVB #esc,R0
        CALL TTYCC
MOVB #74,R0
        CALL TTYCC
        rts pc
vt52:      
MOVB #esc,R0
        CALL TTYCC
MOVB #133,R0
        CALL TTYCC
MOVB #'?,R0
        CALL TTYCC
MOVB #'2,R0
        CALL TTYCC
MOVB #'l,R0
        CALL TTYCC
        rts pc
buf:    .blkb 100.
        .end 
