	.ident /20APR1/
; 20-APR-81 15:51:53
        yes=1
        no=0
        debug=no
	cntl==140        ;add this to a control char to get ascii
        control==-1      ;type of all control chars
.iif ndf $temp$ $temp$=0
$top$=.
$auto$=$temp$
.enabl lc
; Mp version as of: 28-jan-81
	.title  jpl
        .mcall gprt$,dir$
gprt:
	gprt$ psdev,tbuf
tbuf:   .blkw 3
speed:: .word 9600.      ;speed of terminal if this is small, assume no crt
cret:   .byte 15,0
ech:    .asciz '=x'
fact:   .asciz 'reserved letters=(f,g,i,m,o,q,r,s,u,z)'
prm:    .asciz    <15>'a>'
btab:   .asciz /abcdehjklnptvwxy/
        .even
mcr:    .byte 127.,41.  ;get mcr cmd line dpb
	input=0
term=input
        input=input+2
string=input
   input=input+<82.>
        .mcall exit$s
start:
	jsr pc,main
        exit$s                  ;so don't use std main stuff
	$auto$=$auto$-<84.>
s=	$auto$
	$auto$=$auto$-<2>
t=	$auto$
	$auto$=$auto$-<2>
len=	$auto$
	$auto$=$auto$-<8.>
lh=	$auto$
	$auto$=$auto$-<2>
p=	$auto$
	$auto$=$auto$-<2>
star=	$auto$
	$auto$=$auto$-<2>
ch=	$auto$
	$auto$=$auto$-<2>
t1=	$auto$
	$auto$=$auto$-<2>
pt=	$auto$
	$auto$=$auto$-<2>
t2=	$auto$
main::
	jsr r0,$$csav
	add #$auto$,sp
	$auto.=$auto$
	$auto$=$temp$
        cur=r3
        trm=r4
	dir$ #gprt
	BCC jpl1
	movb #'b,prm+1
jpl1=.			; 
jpl3=.
        .if eq debug-yes
	movb #76,prm+1
        .endc
	mov #s,-(SP)
	ADD R5,(SP)	;and compute address of s
	mov (SP)+,r2
	mov mcr,(r2)
	dir$ r2
	cmp 6(r2),#<"SL>
	BNE jpl4
	mov #300.,speed
jpl4=.			; 
jpl6=.
	mov #3,r1
	asl r1
	add #lh,r1
	add r5,r1
	mov r1,r0
	mov r1,-(sp)
	clr -(sp)
	clr (sp)
	mov (sp)+,@(sp)+
	mov #lh,-(SP)
	ADD R5,(SP)	;and compute address of lh
      jsr pc,ilist
  tst (sp)+
	BR jpl8
jpl7=.
	.ASCIZ __
	.EVEN
jpl8=.
	mov #jpl7,-(SP)
	mov #con.a,-(SP)
	mov lh(r5),-(SP)
      jsr pc,stuff
	add #006,sp
	BR jpl10
jpl9=.
	.ASCIZ __
	.EVEN
jpl10=.
	mov #jpl9,-(SP)
	mov #con.b,-(SP)
	mov lh(r5),-(SP)
      jsr pc,stuff
	add #006,sp
	mov lh(r5),-(SP)
      jsr pc,next
  tst (sp)+
	mov r0,cur
jpl11=.
jpl13=.
	mov #prm,-(SP)
	mov speed,-(SP)
	mov #s,-(SP)
	ADD R5,(SP)	;and compute address of s
      jsr pc,line
	add #006,sp
	mov r0,t(r5)
	cmp t(r5),#-1
	BEQ jpl15
	JMP jpl14         ;break
jpl15=.			; 
jpl17=.
	BR jpl19
jpl18=.
	.ASCIZ _  Time out at:_
	.EVEN
jpl19=.
	mov #jpl18,r0
	JSR PC,outstr
	JSR PC,creturn
	BR jpl21
jpl20=.
	.ASCIZ _tim_
	.EVEN
jpl21=.
	mov #jpl20,-(SP)
      jsr pc,system
  tst (sp)+
	JMP jpl13		;Repeat loop
jpl14=.
	mov #s,-(SP)
	ADD R5,(SP)	;and compute address of s
      jsr pc,strlen
  tst (sp)+
	mov r0,len(r5)
	mov t(r5),-(SP)
      jsr pc,ctype
  tst (sp)+
	mov r0,trm
	tst len(r5)
	BNE jpl22
	BR jpl25
jpl22:	JMP jpl26
jpl25:
jpl27=.
	cmp trm,#cr
	BNE jpl29
	clr -(sp)
	mov #s,-(SP)
	ADD R5,(SP)	;and compute address of s
	mov cur,-(SP)
	mov lh(r5),-(SP)
      jsr pc,editm
	add #006,sp
	mov r0,(sp)
	cmp (sp)+,#0
	BEQ jpl31
	JSR PC,creturn
	mov cur,-2.(r5)
	ADD #string,-2.(r5)
	mov -2.(r5),-(SP)
      jsr pc,system
  tst (sp)+
jpl31=.			; 
jpl33=.
	JMP jpl28         ;break
jpl29=.
	cmp trm,#esc
	BNE jpl34
	mov cur,-(SP)
      jsr pc,next
  tst (sp)+
	mov r0,cur
	cmp cur,lh(r5)
	BNE jpl36
	mov cur,-(SP)
      jsr pc,next
  tst (sp)+
	mov r0,cur
jpl36=.			; 
jpl38=.
	JSR PC,creturn
	mov cur,p(r5)
	JSR PC,prnt
	JMP jpl28         ;break
jpl34=.
	cmp trm,#control
	BNE jpl39
	mov t(r5),-(SP)
	mov lh(r5),-(SP)
      jsr pc,find
  cmp (sp)+,(sp)+
	mov r0,r2
	cmp (r2),t(r5)
	BNE jpl41
	mov r2,r0
	ADD #string,r0
	JSR PC,outstr
	JSR PC,creturn
	mov r2,-2.(r5)
	ADD #string,-2.(r5)
	mov -2.(r5),-(SP)
      jsr pc,system
  tst (sp)+
	JMP jpl44
jpl41=.			; 
	JSR PC,creturn
	BR jpl46
jpl45=.
	.ASCIZ _undefined string `%c'_
	.EVEN
jpl46=.
	mov r0,-(sp)
	mov r1,-(sp)
	mov t(r5),-2.(r5)
	ADD #cntl,-2.(r5)
	mov -2.(r5),-(SP)
	mov #jpl45,-(SP)
	mov #$buf$,-(SP)
      jsr pc,sprint
	add #006,sp
	mov #$buf$,-(sp)
	jsr pc,$type$
	mov (sp)+,r1
	mov (sp)+,r0
jpl44=.			; 
jpl43=.
	JMP jpl28         ;break
jpl39=.
	cmp trm,#con.z
	BNE jpl47
	mov cur,r1
	add #string,r1
	mov r1,r0
	mov r1,-(sp)
	clr -(sp)
	clr (sp)
	mov (sp)+,@(sp)+
	JMP jpl28         ;break
jpl47=.
	cmp trm,#con.f
	BNE jpl49
	cmp speed,#600.
	BLE jpl51
	mov #fact,r0
	JSR PC,outstr
jpl51=.			; 
jpl53=.
	JSR PC,creturn
	mov lh(r5),-(SP)
      jsr pc,next
  tst (sp)+
	mov r0,p(r5)
jpl54=.
	cmp p(r5),lh(r5)
	BEQ jpl56
	JMP jpl59
jpl56=.			; 
	JMP jpl55	;else end  while loop
jpl59=.			; 
jpl58=.
	JSR PC,prnt
	mov p(r5),-(SP)
      jsr pc,next
  tst (sp)+
	mov r0,p(r5)
	JMP jpl54		;Repeat loop
jpl55=.
	JMP jpl28         ;break
jpl49=.
	cmp trm,#con.qq
	BNE jpl60
	JSR PC,creturn
	BR jpl63
jpl62=.
	.ASCIZ _h jplconq_
	.EVEN
jpl63=.
	mov #jpl62,-(SP)
      jsr pc,system
  tst (sp)+
	JMP jpl28         ;break
jpl60=.
	tst trm
	BNE jpl64
	JSR PC,creturn
	mov lh(r5),-(SP)
      jsr pc,ldump
  tst (sp)+
	BR jpl67
jpl66=.
	.ASCIZ _&s=%o t=%o cur=%o_
	.EVEN
jpl67=.
	mov r0,-(sp)
	mov r1,-(sp)
	mov cur,-(SP)
	mov t(r5),-(SP)
	mov #s,-(SP)
	ADD R5,(SP)	;and compute address of s
	mov #jpl66,-(SP)
	mov #$buf$,-(SP)
      jsr pc,sprint
	add #012,sp
	mov #$buf$,-(sp)
	jsr pc,$type$
	mov (sp)+,r1
	mov (sp)+,r0
	BR jpl69
jpl68=.
	.ASCIZ _editm=(%o) change=(%o) find=(%o)_
	.EVEN
jpl69=.
	mov r0,-(sp)
	mov r1,-(sp)
	mov #find,-(SP)
	mov #change,-(SP)
	mov #editm,-(SP)
	mov #jpl68,-(SP)
	mov #$buf$,-(SP)
      jsr pc,sprint
	add #012,sp
	mov #$buf$,-(sp)
	jsr pc,$type$
	mov (sp)+,r1
	mov (sp)+,r0
	JMP jpl28         ;break
jpl64=.
	jmp none
jpl28=.
jpl70=.
	JMP jpl71
jpl26=.			; 
jpl72=.
	cmp trm,#con.qq
	BNE jpl74
	JSR PC,conqq
	JMP jpl73         ;break
jpl74=.
	cmp trm,#control
	BNE jpl76
conques:
	mov #s,-(SP)
	ADD R5,(SP)	;and compute address of s
	mov t(r5),-(SP)
	mov lh(r5),-(SP)
      jsr pc,stuff
	add #006,sp
	mov t(r5),-(SP)
      jsr pc,outterm
  tst (sp)+
	JMP jpl73         ;break
jpl76=.
	cmp trm,#cr
	BNE jpl78
	mov #s,-(SP)
	ADD R5,(SP)	;and compute address of s
	mov cur,-(SP)
      jsr pc,cpy
  cmp (sp)+,(sp)+
	JSR PC,creturn
	mov #s,-(SP)
	ADD R5,(SP)	;and compute address of s
      jsr pc,system
  tst (sp)+
	JMP jpl73         ;break
jpl78=.
none:
	JSR PC,creturn
	BR jpl82
jpl81=.
	.ASCIZ _I can't do that_
	.EVEN
jpl82=.
	mov r0,-(sp)
	mov r1,-(sp)
	mov #jpl81,-(SP)
	mov #$buf$,-(SP)
      jsr pc,sprint
  cmp (sp)+,(sp)+
	mov #$buf$,-(sp)
	jsr pc,$type$
	mov (sp)+,r1
	mov (sp)+,r0
jpl73=.
jpl80=.
jpl71=.			; 
jpl24=.
	JMP jpl11		;Repeat loop
jpl12=.
done:
	jmp $$cret
conqq:
	mov #btab,pt(r5)
	mov lh(r5),-(SP)
      jsr pc,next
  tst (sp)+
	mov r0,p(r5)
jpl83=.
	cmp p(r5),lh(r5)
	BEQ jpl85
	JMP jpl88
jpl85=.			; 
	JMP jpl84	;else end  while loop
jpl88=.			; 
jpl87=.
	cmp p(r5),cur
	BEQ jpl89
	mov p(r5),r1
	mov term(r1),r0
	mov r0,t1(r5)
	mov pt(r5),r1
	movb 0(r1),r0
	mov r0,t2(r5)
	clr -(sp)
	mov p(r5),-2.(r5)
	ADD #string,-2.(r5)
	mov -2.(r5),-(SP)
      jsr pc,strlen
  tst (sp)+
	mov r0,(sp)
	cmp (sp)+,#0
	BNE jpl95
	BR jpl93
jpl95=.
	clr -(sp)
	mov t2(r5),(sp)
	SUB #cntl,(sp)
	cmp t1(r5),(sp)+
	BEQ jpl92
jpl93=.
qq1:
	mov t2(r5),t(r5)
	SUB #cntl,t(r5)
	jmp conques
jpl92=.			; 
jpl94=.
jpl89=.			; 
jpl91=.
	inc pt(r5)
	mov p(r5),-(SP)
      jsr pc,next
  tst (sp)+
	mov r0,p(r5)
	JMP jpl83		;Repeat loop
jpl84=.
	mov pt(r5),r1
	movb 0(r1),r0
	mov r0,t2(r5)
	tst t2(r5)
	BEQ jpl98
	br qq1
	JMP jpl101
jpl98=.			; 
	JSR PC,creturn
	BR jpl103
jpl102=.
	.ASCIZ _No more buffers_
	.EVEN
jpl103=.
	mov r0,-(sp)
	mov r1,-(sp)
	mov #jpl102,-(SP)
	mov #$buf$,-(SP)
      jsr pc,sprint
  cmp (sp)+,(sp)+
	mov #$buf$,-(sp)
	jsr pc,$type$
	mov (sp)+,r1
	mov (sp)+,r0
jpl101=.			; 
jpl100=.
	rts pc
prnt:                                           ;prints buf at p
	cmp p(r5),cur
	BNE jpl104
	mov #'*,star(r5)
	JMP jpl107
jpl104=.			; 
	mov #space,star(r5)
jpl107=.			; 
jpl106=.
	BR jpl109
jpl108=.
	.ASCIZ _%c%c=(%s)_
	.EVEN
jpl109=.
	mov r0,-(sp)
	mov r1,-(sp)
	mov p(r5),-2.(r5)
	ADD #string,-2.(r5)
	mov -2.(r5),-(SP)
	mov @p(r5),-2.(r5)
	ADD #cntl,-2.(r5)
	mov -2.(r5),-(SP)
	mov star(r5),-(SP)
	mov #jpl108,-(SP)
	mov #$buf$,-(SP)
      jsr pc,sprint
	add #012,sp
	mov #$buf$,-(sp)
	jsr pc,$type$
	mov (sp)+,r1
	mov (sp)+,r0
	rts pc
creturn::                                       ;output a cr
	mov r0,-(SP)
	mov #cret,r0
	JSR PC,outstr
	mov (SP)+,r0
	rts pc
	$auto$=$auto$-<2>
ch=	$auto$
t=10.
outterm::
	jsr r0,$$csav
	add #$auto$,sp
	$auto.=$auto$
	$auto$=$temp$
	mov t(r5),ch(r5)
	ADD #cntl,ch(r5)
	movb ch(r5),ech+1
	mov #ech,r0
	JSR PC,outstr
	jmp $$cret
lh=10.
t=12.
s=14.
stuff::
	jsr r0,$$csav
	add #$auto$,sp
	$auto.=$auto$
	$auto$=$temp$
        found=r4
        new.cell=r2
	mov t(r5),-(SP)
	mov lh(r5),-(SP)
      jsr pc,find
  cmp (sp)+,(sp)+
	mov r0,found
	cmp term(found),t(r5)
	BNE jpl110
	mov s(r5),-(SP)
	mov found,-(SP)
      jsr pc,cpy
  cmp (sp)+,(sp)+
	JMP jpl113
jpl110=.			; 
	mov #input,-(SP)
      jsr pc,new
  tst (sp)+
	mov r0,-2.(r5)
	mov -2.(r5),-(SP)
	mov found,-(SP)
      jsr pc,prev
  tst (sp)+
	mov r0,-2.(r5)
	mov -2.(r5),-(SP)
      jsr pc,insert
  cmp (sp)+,(sp)+
	mov r0,new.cell
	mov t(r5),term(new.cell)
	mov s(r5),-(SP)
	mov new.cell,-(SP)
      jsr pc,cpy
  cmp (sp)+,(sp)+
jpl113=.			; 
jpl112=.
	jmp $$cret
into=10.
s=12.
cpy::
	jsr r0,$$csav
	add #$auto$,sp
	$auto.=$auto$
	$auto$=$temp$
	mov into(r5),r2
	ADD #string,r2
	clrb (r2)
	clr -(SP)
	mov s(r5),-(SP)
	mov r2,-(SP)
      jsr pc,cat
	add #006,sp
	jmp $$cret
lh=10.
t=12.
find::
	jsr r0,$$csav
	add #$auto$,sp
	$auto.=$auto$
	$auto$=$temp$
        this=r4
	mov lh(r5),this
jpl114=.
	mov this,-(SP)
      jsr pc,next
  tst (sp)+
	mov r0,this
	cmp this,lh(r5)
	BNE jpl119
	BR jpl117
jpl119=.
	cmp term(this),t(r5)
	BLT jpl116
jpl117=.
	mov this,r0
	jmp $$cret
jpl116=.			; 
jpl118=.
	JMP jpl114		;Repeat loop
jpl115=.
term=10.
ctype::
	jsr r0,$$csav
	add #$auto$,sp
	$auto.=$auto$
	$auto$=$temp$
	mov term(r5),r4
jpl122=.
	cmp r4,#cr
	BNE jpl124
	mov #cr,r0
	jmp $$cret
jpl124=.
	cmp r4,#esc
	BNE jpl126
	mov #esc,r0
	jmp $$cret
jpl126=.
	cmp r4,#con.z
	BNE jpl128
	mov #con.z,r0
	jmp $$cret
jpl128=.
	cmp r4,#con.f
	BNE jpl130
	mov #con.f,r0
	jmp $$cret
jpl130=.
	cmp r4,#con.qq
	BNE jpl132
	mov #con.qq,r0
	jmp $$cret
jpl132=.
	tst r4
	BNE jpl134
	clr r0
	jmp $$cret
jpl134=.
	mov #control,r0
	jmp $$cret
jpl123=.
jpl136=.
$temp$=-4.
.END start
