$auto$=-2
.enabl lc
; Mp version as of: 16-aug-80
         mutask=1
         
        .enabl lc
        .enabl ama
        .nlist sym
         
         
        .if df mutask
        .MACRO pure
        .psect pur,ro
        .ENDM 
         
        .MACRO impure
        .psect ipur,rw
        .ENDM 
         
        .iff 
         
        .MACRO pure
        .ENDM 
         
        .MACRO impure
        .ENDM 
         
        .endc 
         
         
        .globl ncom     ;Handle the New commands (2 letter commands)
	.globl autostart ;automatic y command on entry
        .mcall dir$,callr
         
        impure 
         
        nl=12 
        cr=15 
         
key:    .blkb   40.             ;40 char key max
         
        pure 
str1:   .ascii/00/ 
execy:  .ascii/1y/
        .byte 12
auto:   .ascii /autoexecute~/
autoe=.-1
	.even
         
ncom:    
	JSR PC,getc
	CMPB R0,#'a		;IS R0 HIS #'a
	BLO Ec1	;Not if LO
	CMPB R0,#'z		;IS R0 LOS #'z
	BHI Ec4	;Not if HI
	BR Ec7	;Here IFB R0 LOS #'z    
Ec4=.
	BR Ec1		;Here if not
Ec7=.
            bic #40,r0                              ;make it lower case
Ec1=.			; 
Ec3=.
         
Ec8=.
	CMP R0,#'C		;Case #'C
	BNE Ec10
	JSR PC,crypt
	JMP Ec9         ;break
Ec10=.
	CMP R0,#'S		;Case #'S
	BNE Ec12
	JSR PC,defall
            mov #str1,r0
            mov #1,r1
	JSR PC,putbak
	JSR PC,scom
	TST smode		;IS smode NE #0
	BEQ Ec14	;Not if EQ
	JSR PC,bcom1
Ec14=.			; 
Ec16=.
	JMP Ec9         ;break
Ec12=.
	CMP R0,#'F		;Case #'F
	BNE Ec17
	JSR PC,nfill
	JMP Ec9         ;break
Ec17=.
            mov #2,r1
            jmp error
Ec9=.
Ec19=.
        rts pc
         
crypt:   
	JSR PC,defall
        mov #key,r1
        clr r3
Ec20=.
	JSR PC,getc
	CMP r0,#nl		;IS r0 = #nl
	BNE Ec25	;Not if NE
	BR Ec23		;condition met
Ec25=.
	CMP r1,#key+39.		;IS r1 HI #key+39.
	BLOS Ec22	;Not if LOS
Ec23=.
	JMP Ec21         ;break
Ec22=.			; 
Ec24=.
            bic #177600,r0          ;this had better be 7 bit ascii
            movb r0,(r1)+
            inc r3                  ;note count of chars in key
	JMP Ec20		;Repeat loop
Ec21=.
         
	TST r3		;IS r3 LE #0
	BGT Ec28	;Not if GT
            mov #2,r1
            jmp error
Ec28=.			; 
Ec30=.
         
        clrb (r1)                  ;asciz it
        mov #key,r2                ;start key at beginning
	MOV adr1,dot	;Init loop index
Ec31=.
	CMP dot,adr2	;done loop?
	BHI Ec32	;yes if HI
            mov @dot,r0
	JSR PC,getlin
            mov #lbuf1,r1
             
Ec33=.
	TSTB (r1)		;IS (r1) = #0
	BNE Ec38	;Not if NE
	BR Ec36		;condition met
Ec38=.
	CMPB (r1),#12		;IS (r1) = #12
	BNE Ec35	;Not if NE
Ec36=.
	JMP Ec34         ;break
Ec35=.			; 
Ec37=.
	JSR PC,encode
                inc r1                  ;next char in lbuf
                inc r2
	TSTB (r2)		;IS (r2) = #0
	BNE Ec41	;Not if NE
                    mov #key,r2          ;recycle pointer
Ec41=.			; 
Ec43=.
	JMP Ec33		;Repeat loop
Ec34=.
	JSR PC,putlin
            mov r0,@dot
	ADD #2,dot
	JMP Ec31		;back to top
Ec32=.
        mov adr2,dot                  ;end at last line
        rts pc
encode:  
        mov r0,-(sp)
        mov r3,-(sp)
        movb (r1),r0            ;get char
        bit #200,r0
        bic #177600,r0          ;just want 7 bits
        movb (r2),r3            ;r0 is the char, r3 is key char
        xor r3,r0               ;r0 is encoded now
        bic #177600,r0          ;just low byte
         
	CMP r0,#cr		;IS r0 = #cr
	BNE Ec50	;Not if NE
	BR Ec48		;condition met
Ec50=.
	CMP r0,#nl		;IS r0 = #nl
	BNE Ec47	;Not if NE
Ec48=.
	BR Ec45		;condition met
Ec47=.
	TST r0		;IS r0 = #0
	BNE Ec44	;Not if NE
Ec45=.
            bis #200,r0          ;yes, set 8'th bit
Ec44=.			; 
Ec46=.
         
        movb r0,(r1)            ;replace it now
         
        mov (sp)+,r3
        mov (sp)+,r0
        rts pc
         
autostart:
	CMP zero,dol		;IS zero LO dol
	BHIS Ec53	;Not if HIS
	BR Ec56
Ec53:	JMP Ec57
Ec56:
;
; 
;
	MOV zero,r0
	ADD #2,r0
           mov (r0),r0
	JSR PC,getlin
           mov #lbuf1,r0
Ec58=.
	CMPB (r0),#'a		;IS (r0) = #'a
	BNE Ec60	;Not if NE
	JMP Ec59         ;break
Ec60=.			; 
Ec62=.
	TSTB (r0)		;IS (r0) = #0
	BNE Ec63	;Not if NE
                 rts pc
Ec63=.			; 
Ec65=.
              inc r0
	JMP Ec58		;Repeat loop
Ec59=.
	MOV #auto,r1	;Init loop index
Ec66=.
	CMP r1,#autoe	;done loop?
	BHI Ec67	;yes if HI
	TSTB (r0)		;IS (r0) = #0
	BNE Ec71	;Not if NE
	BR Ec69		;condition met
Ec71=.
	CMPB (r1),(r0)		;IS (r1) NE (r0)
	BEQ Ec68	;Not if EQ
Ec69=.
                 rts pc
Ec68=.			; 
Ec70=.
              inc r0
	INC r1
	JMP Ec66		;back to top
Ec67=.
           mov #execy,r0
           mov #3,r1
	JSR PC,putbak
Ec57=.			; 
Ec55=.
        rts pc
        .end 
