.PRINT	 ;         $MACRO PRINTF
.PRINT	 ;         mov r0,-(sp)
.PRINT	 ;         mov r1,-(sp)
.PRINT	 ;         PRINTS #@1 <#@2><#@3><#@4><#@5><#@6><#@7><#@8><#@9><#@A><#@B><#@C><#@D>
.PRINT	 ;         TYPE #@1
.PRINT	 ;         mov (sp)+,r1
.PRINT	 ;         mov (sp)+,r0
.PRINT	 ;         $ENDM 
.PRINT	 ; ; move comments over 1 tab	C/;/	;/
.PRINT	 ; ; move back 1 tab        	C/	;/;/
.PRINT	 ;         $MACRO return	;this MUST be lower case
.PRINT	 ;         rts pc
.PRINT	 ;         $ENDM 
.PRINT	 ; /
.PRINT	 ;         PROGRAM Ea 	;Utility routines module 2
$auto$=-2
.enabl lc
;15-aug-80 for Conroy C runtime
.PRINT	 ; mutask=1
mutask=1
.PRINT	 ;         .psect edi10
        .psect edi10
.PRINT	 ;         .enabl lc
        .enabl lc
.PRINT	 ;         .enabl ama
        .enabl ama
.PRINT	 ;         .nlist sym
        .nlist sym
.PRINT	 ;          
         
.PRINT	 ;         .if df mutask
        .if df mutask
.PRINT	 ;         .MACRO pure
        .MACRO pure
        .psect pur,ro
        .ENDM 
.PRINT	 ;          
         
.PRINT	 ;         .MACRO impure
        .MACRO impure
        .psect ipur,rw
        .ENDM 
.PRINT	 ;          
         
.PRINT	 ;         .iff 
        .iff 
.PRINT	 ;          
         
.PRINT	 ;         .MACRO pure
        .MACRO pure
        .ENDM 
.PRINT	 ;         .MACRO impure
        .MACRO impure
        .ENDM 
.PRINT	 ;          
         
.PRINT	 ;         .endc 
        .endc 
.PRINT	 ;         .globl caseck	;check for &\x options in substitute command
        .globl caseck	;check for &\x options in substitute command
.PRINT	 ;         .globl marktg   ;mark tags
        .globl marktg   ;mark tags
.PRINT	 ;         .globl marktd   ;mark tags delete entry
        .globl marktd   ;mark tags delete entry
.PRINT	 ;         .globl retag    ;restore tags after operation
        .globl retag    ;restore tags after operation
.PRINT	 ;          
         
.PRINT	 ;         .MACRO push this
        .MACRO push this
        mov this,-(sp)
        .ENDM 
.PRINT	 ;          
         
.PRINT	 ;         .MACRO pop that
        .MACRO pop that
        mov (sp)+,that
        .ENDM 
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ; ; - - -	 macro library calls
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ;         .mcall dir$,callr
        .mcall dir$,callr
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ; ; - - -	 system	macros
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ; ; - - -	 local data and	symbols
.PRINT	 ; s1:     .word           ;save padr1
s1:     .word           ;save padr1
.PRINT	 ; s2:     .word           ;save padr2
s2:     .word           ;save padr2
.PRINT	 ; one:    .word           ;compute address of line 1
one:    .word           ;compute address of line 1
.PRINT	 ; ;temp:   .blkb  100.     ;temp
.PRINT	 ;          
         
.PRINT	 ;         pure 
        pure 
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ; ;+
.PRINT	 ; ;
.PRINT	 ; ; This routine checks for various & options in the substitute
.PRINT	 ; ; command.
.PRINT	 ; ;
.PRINT	 ; ; currently, the options are:
.PRINT	 ; ;
.PRINT	 ; ;		&\u	convert to upper case
.PRINT	 ; ;		&\l	convert to lower case
.PRINT	 ; ;		&\t	toggle case
.PRINT	 ; ;		&\r	reverse all characters (not yet, but maybe)
.PRINT	 ; ;
.PRINT	 ; ;   If there is a \ followed by a valid char (one of above) then
.PRINT	 ; ;   we  either  do  it all here (going thru sstore ourselves) in
.PRINT	 ; ;   which case we set the carry bit on return, or  we  don't  do
.PRINT	 ; ;   nothin (indicated, of course, by a clear carry bit). 
.PRINT	 ; ; So...
.PRINT	 ; ;	Input: r0,r2,r3,r4,r5, and all other stuff local to the sub cmd
.PRINT	 ; ;	Output: carry bit with all the regs updated as in sub  or
.PRINT	 ; ;	        carry clear with nothing changed.
.PRINT	 ; ;
.PRINT	 ; ;-
.PRINT	 ; caseck:  
caseck:  
.PRINT	 ;         IFB (r4) = #'\	;is it us
	CMPB (r4),#'\		;IS (r4) = #'\
	BNE Ea1	;Not if NE
.PRINT	 ;             push r1
            push r1
.PRINT	 ;             inc r4
            inc r4
.PRINT	 ;             movb (r4)+,r1		;get next char
            movb (r4)+,r1		;get next char
.PRINT	 ;             bic #177600,r1		;7 bit ascii only
            bic #177600,r1		;7 bit ascii only
.PRINT	 ;             IF r1 = #0			;test for end of buf
	TST r1		;IS r1 = #0
	BNE Ea4	;Not if NE
.PRINT	 ; 10$:            sub #2,r4		;and retrace our steps
10$:            sub #2,r4		;and retrace our steps
.PRINT	 ;                 pop r1
                pop r1
.PRINT	 ;                 clc			;didn't do nuthin
                clc			;didn't do nuthin
.PRINT	 ;                 return 
        rts pc
.PRINT	 ;             ELSE 
	JMP Ea7
Ea4=.			; 
.PRINT	 ;                 bic #40,r1		;make it upper case
                bic #40,r1		;make it upper case
.PRINT	 ;                 SELECT case r1 of
.PRINT	 ;                 CASE #'L
Ea8=.
	CMP r1,#'L		;Case #'L
	BNE Ea10
.PRINT	 ;                     call csL
                    call csL
.PRINT	 ;                 BREAK 
	JMP Ea9         ;break
.PRINT	 ;                 CASE #'U
Ea10=.
	CMP r1,#'U		;Case #'U
	BNE Ea12
.PRINT	 ;                     call csU
                    call csU
.PRINT	 ;                 BREAK 
	JMP Ea9         ;break
.PRINT	 ;                 CASE #'T
Ea12=.
	CMP r1,#'T		;Case #'T
	BNE Ea14
.PRINT	 ;                     call csT
                    call csT
.PRINT	 ;                 BREAK 
	JMP Ea9         ;break
.PRINT	 ;                 CASE #'R
Ea14=.
	CMP r1,#'R		;Case #'R
	BNE Ea16
.PRINT	 ;                     call csR
                    call csR
.PRINT	 ;                 BREAK 
	JMP Ea9         ;break
.PRINT	 ;                 DEFAULT 
Ea16=.
.PRINT	 ;                     br 10$
                    br 10$
.PRINT	 ;                 ESAC 
Ea9=.
Ea18=.
.PRINT	 ;             FI 
Ea7=.			; 
Ea6=.
.PRINT	 ;             pop r1
            pop r1
.PRINT	 ;             sec 
            sec 
.PRINT	 ;             return 
        rts pc
.PRINT	 ;         FI 
Ea1=.			; 
Ea3=.
.PRINT	 ;         clc 
        clc 
.PRINT	 ;         return 
        rts pc
.PRINT	 ;          
         
.PRINT	 ; ; - - -   toggle case
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ;         .if eq 0                ;is implemented again
        .if eq 0                ;is implemented again
.PRINT	 ; csT:    				;toggle case
csT:    				;toggle case
.PRINT	 ;         MOV	R4,-(SP)	;SAVE R.H.S. POINTER
        MOV	R4,-(SP)	;SAVE R.H.S. POINTER
.PRINT	 ;         MOV	R2,R4		;POINTER TO WHAT MATCHES
        MOV	R2,R4		;POINTER TO WHAT MATCHES
.PRINT	 ; 136$:   CMP	R4,R0		;DONE ?
136$:   CMP	R4,R0		;DONE ?
.PRINT	 ;         BHIS	139$		;YES
        BHIS	139$		;YES
.PRINT	 ;         MOVB	(R4)+,R5	;GET CHARACTER
        MOVB	(R4)+,R5	;GET CHARACTER
.PRINT	 ;         CMP	R5,#'A		;UPPER CASE ?
        CMP	R5,#'A		;UPPER CASE ?
.PRINT	 ;         BLO	138$		;NO
        BLO	138$		;NO
.PRINT	 ;         CMP	R5,#'Z		;PERHAPS ?
        CMP	R5,#'Z		;PERHAPS ?
.PRINT	 ;         BHI	137$		;NO
        BHI	137$		;NO
.PRINT	 ;         BIS	#' ,R5		;FORCE LOWER
        BIS	#' ,R5		;FORCE LOWER
.PRINT	 ;         BR	138$		;
        BR	138$		;
.PRINT	 ; 137$:   CMP	R5,#'a		;LOWER CASE ?
137$:   CMP	R5,#'a		;LOWER CASE ?
.PRINT	 ;         BLO	138$		;NO
        BLO	138$		;NO
.PRINT	 ;         CMP	R5,#'z		;PERHAPS ?
        CMP	R5,#'z		;PERHAPS ?
.PRINT	 ;         BHI	138$		;NO
        BHI	138$		;NO
.PRINT	 ;         BIC	#' ,R5		;FORCE UPPER
        BIC	#' ,R5		;FORCE UPPER
.PRINT	 ; 138$:   CALL	SSTORE		;STORE R.H.S. CHARACTER
138$:
	JSR PC,SSTORE
.PRINT	 ;         BR	136$		;
        BR	136$		;
.PRINT	 ; 139$:    
139$:    
.PRINT	 ;         pop r4
        pop r4
.PRINT	 ;         return 
        rts pc
.PRINT	 ;         .endc 
        .endc 
.PRINT	 ;          
         
.PRINT	 ; ; - - -    force all to lower
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ; csL:     
csL:     
.PRINT	 ;         MOV	R4,-(SP)	;SAVE R.H.S. POINTER
        MOV	R4,-(SP)	;SAVE R.H.S. POINTER
.PRINT	 ;         MOV	R2,R4		;POINTER TO WHAT MATCHES
        MOV	R2,R4		;POINTER TO WHAT MATCHES
.PRINT	 ; 136$:   CMP	R4,R0		;DONE ?
136$:   CMP	R4,R0		;DONE ?
.PRINT	 ;         BHIS	139$		;YES
        BHIS	139$		;YES
.PRINT	 ;         MOVB	(R4)+,R5	;GET CHARACTER
        MOVB	(R4)+,R5	;GET CHARACTER
.PRINT	 ;         CMP	R5,#'A		;UPPER CASE ?
        CMP	R5,#'A		;UPPER CASE ?
.PRINT	 ;         BLO	138$		;NO
        BLO	138$		;NO
.PRINT	 ;         CMP	R5,#'Z		;PERHAPS ?
        CMP	R5,#'Z		;PERHAPS ?
.PRINT	 ;         BHI	138$		;NO
        BHI	138$		;NO
.PRINT	 ;         BIS	#' ,R5		;FORCE LOWER
        BIS	#' ,R5		;FORCE LOWER
.PRINT	 ; 138$:   CALL	SSTORE		;STORE R.H.S. CHARACTER
138$:
	JSR PC,SSTORE
.PRINT	 ;         BR	136$		;
        BR	136$		;
.PRINT	 ; 139$:    
139$:    
.PRINT	 ;         pop r4
        pop r4
.PRINT	 ;         return 
        rts pc
.PRINT	 ;          
         
.PRINT	 ; ; - - -    force all to UPPER
.PRINT	 ;          
         
.PRINT	 ; csU:     
csU:     
.PRINT	 ;         MOV	R4,-(SP)	;SAVE R.H.S. POINTER
        MOV	R4,-(SP)	;SAVE R.H.S. POINTER
.PRINT	 ;         MOV	R2,R4		;POINTER TO WHAT MATCHES
        MOV	R2,R4		;POINTER TO WHAT MATCHES
.PRINT	 ; 136$:   CMP	R4,R0		;DONE ?
136$:   CMP	R4,R0		;DONE ?
.PRINT	 ;         BHIS	139$		;YES
        BHIS	139$		;YES
.PRINT	 ;         MOVB	(R4)+,R5	;GET CHARACTER
        MOVB	(R4)+,R5	;GET CHARACTER
.PRINT	 ;         CMP	R5,#'a		;lower CASE ?
        CMP	R5,#'a		;lower CASE ?
.PRINT	 ;         BLO	138$		;NO
        BLO	138$		;NO
.PRINT	 ;         CMP	R5,#'z		;PERHAPS ?
        CMP	R5,#'z		;PERHAPS ?
.PRINT	 ;         BHI	138$		;NO
        BHI	138$		;NO
.PRINT	 ;         bic	#' ,R5		;FORCE UPPER
        bic	#' ,R5		;FORCE UPPER
.PRINT	 ; 138$:   CALL	SSTORE		;STORE R.H.S. CHARACTER
138$:
	JSR PC,SSTORE
.PRINT	 ;         BR	136$		;
        BR	136$		;
.PRINT	 ; 139$:    
139$:    
.PRINT	 ;         pop r4
        pop r4
.PRINT	 ;         return 
        rts pc
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ; ; - - - 	reverse string
.PRINT	 ; csR:     
csR:     
.PRINT	 ;         push r4
        push r4
.PRINT	 ;         mov r0,r4
        mov r0,r4
.PRINT	 ; 136$:   cmp r4,r2	;done?
136$:   cmp r4,r2	;done?
.PRINT	 ;         blos 139$	;yes
        blos 139$	;yes
.PRINT	 ;         movb -(r4),r5
        movb -(r4),r5
.PRINT	 ;         call sstore
        call sstore
.PRINT	 ;         br 136$
        br 136$
.PRINT	 ; 139$:    
139$:    
.PRINT	 ;         pop r4
        pop r4
.PRINT	 ;         return 
        rts pc
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ; ; - - - unimplemented stuff
.PRINT	 ;          
         
.PRINT	 ;         .if eq 1
        .if eq 1
.PRINT	 ; ;;csT:	
.PRINT	 ;         sub #2,r4
        sub #2,r4
.PRINT	 ;         add #2,sp
        add #2,sp
.PRINT	 ;         pop r1
        pop r1
.PRINT	 ;         clc 
        clc 
.PRINT	 ;         return			;this retracts each of these commands
        rts pc
.PRINT	 ;          
         
.PRINT	 ;         .endc 
        .endc 
.PRINT	 ;          
         
.PRINT	 ; marktd:  
marktd:  
.PRINT	 ; 	call saval
	call saval
.PRINT	 ;        LET one = zero + #2
	MOV zero,one
	ADD #2,one
.PRINT	 ;         IF adr1 = adr2
	CMP adr1,adr2		;IS adr1 = adr2
	BNE Ea19	;Not if NE
.PRINT	 ;             IF padr1 = adr1  AND  padr1 LO dol
	CMP padr1,adr1		;IS padr1 = adr1
	BNE Ea22	;Not if NE
	CMP padr1,dol		;IS padr1 LO dol
	BHIS Ea25	;Not if HIS
	BR Ea28	;Here IF padr1 LO dol    
Ea25=.
	BR Ea22		;Here if not
Ea28=.
.PRINT	 ;                 add #2,padr1
                add #2,padr1
.PRINT	 ;             ELSEIF padr2 = adr1 AND padr2 HI one
	JMP Ea24
Ea22=.
	CMP padr2,adr1		;IS padr2 = adr1
	BNE Ea29	;Not if NE
	CMP padr2,one		;IS padr2 HI one
	BLOS Ea32	;Not if LOS
	BR Ea35	;Here IF padr2 HI one    
Ea32=.
	BR Ea29		;Here if not
Ea35=.
.PRINT	 ;                 sub #2,padr2
                sub #2,padr2
.PRINT	 ;             FI 
Ea29=.			; 
Ea24=.
.PRINT	 ;         FI 
Ea19=.			; 
Ea21=.
.PRINT	 ; br mar1
br mar1
.PRINT	 ; marktg:  
marktg:  
.PRINT	 ;         call saval
        call saval
.PRINT	 ; mar1:   mov #1,s1
mar1:   mov #1,s1
.PRINT	 ;         mov #1,s2
        mov #1,s2
.PRINT	 ;         IF padr1 NE #0  AND  padr2 NE #0
	TST padr1		;IS padr1 NE #0
	BEQ Ea36	;Not if EQ
	TST padr2		;IS padr2 NE #0
	BEQ Ea39	;Not if EQ
	BR Ea42	;Here IF padr2 NE #0    
Ea39=.
	BR Ea36		;Here if not
Ea42=.
.PRINT	 ;             LET one = zero + #2
	MOV zero,one
	ADD #2,one
.PRINT	 ;             IF padr1 HIS one  AND  Padr1 LOS dol
	CMP padr1,one		;IS padr1 HIS one
	BLO Ea43	;Not if LO
	CMP Padr1,dol		;IS Padr1 LOS dol
	BHI Ea46	;Not if HI
	BR Ea49	;Here IF Padr1 LOS dol    
Ea46=.
	BR Ea43		;Here if not
Ea49=.
.PRINT	 ;                 mov @padr1,s1
                mov @padr1,s1
.PRINT	 ;                 IF padr2 HIS padr1   AND  padr2  LOS dol
	CMP padr2,padr1		;IS padr2 HIS padr1
	BLO Ea50	;Not if LO
	CMP padr2,dol		;IS padr2 LOS dol
	BHI Ea53	;Not if HI
	BR Ea56	;Here IF padr2 LOS dol    
Ea53=.
	BR Ea50		;Here if not
Ea56=.
.PRINT	 ;                     mov @padr2,s2
                    mov @padr2,s2
.PRINT	 ;                 ELSE 
	JMP Ea57
Ea50=.			; 
.PRINT	 ;                     mov #1,s2
                    mov #1,s2
.PRINT	 ;                     mov #1,s1
                    mov #1,s1
.PRINT	 ;                 FI 
Ea57=.			; 
Ea52=.
.PRINT	 ;             ELSE 
	JMP Ea58
Ea43=.			; 
.PRINT	 ;                 mov #1,s2
                mov #1,s2
.PRINT	 ;                 mov #1,s1
                mov #1,s1
.PRINT	 ;             FI 
Ea58=.			; 
Ea45=.
.PRINT	 ;         FI 
Ea36=.			; 
Ea38=.
.PRINT	 ; ;PRINTF #temp <before retag s1=%o s2=%o padr1=%o padr2=%o> s1 s2 padr1 padr2
.PRINT	 ;         rts pc
        rts pc
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ; retag:   
retag:   
.PRINT	 ;         call saval
        call saval
.PRINT	 ; ;PRINTF #temp <s1=%o s2=%o padr1=%o padr2=%o> s1 s2 padr1 padr2
.PRINT	 ; ;PRINTF #temp <dot=%o zero=%o dol=%o> dot zero dol
.PRINT	 ; ;PRINTF #temp <adr1=%o adr2=%o> adr1 adr2
.PRINT	 ;         IF s1 = #1  OR  s2 = #1
	CMP s2,#1		;IS s2 = #1
	BNE Ea62	;Not if NE
	BR Ea60		;condition met
Ea62=.
	CMP s1,#1		;IS s1 = #1
	BNE Ea59	;Not if NE
Ea60=.
.PRINT	 ;             br clear
            br clear
.PRINT	 ;         FI 
Ea59=.			; 
Ea61=.
.PRINT	 ;         mov s1,r0
        mov s1,r0
.PRINT	 ;         call findpt
        call findpt
.PRINT	 ;         bcs clear
        bcs clear
.PRINT	 ;          
         
.PRINT	 ;         mov r1,padr1
        mov r1,padr1
.PRINT	 ;         mov s2,r0
        mov s2,r0
.PRINT	 ;         call findpt
        call findpt
.PRINT	 ;         bcs clear
        bcs clear
.PRINT	 ;          
         
.PRINT	 ;         mov r1,padr2
        mov r1,padr2
.PRINT	 ;         rts pc
        rts pc
.PRINT	 ;          
         
.PRINT	 ; clear:   
clear:   
.PRINT	 ;         clr padr1
        clr padr1
.PRINT	 ;         clr padr2
        clr padr2
.PRINT	 ;         rts pc
        rts pc
.PRINT	 ;          
         
.PRINT	 ;          
         
.PRINT	 ; findpt:  
findpt:  
.PRINT	 ;         LOOP for r1 = one THRU dol STEP #2
	MOV one,r1	;Init loop index
Ea65=.
	CMP r1,dol	;done loop?
	BHI Ea66	;yes if HI
.PRINT	 ;             IF r0 = (r1)
	CMP r0,(r1)		;IS r0 = (r1)
	BNE Ea67	;Not if NE
.PRINT	 ;                  
                 
.PRINT	 ; ;	      PRINTF #temp <returning sucess from findpt r0=%o r1=%o> r0 r1
.PRINT	 ;                 clc 
                clc 
.PRINT	 ;                 rts pc
                rts pc
.PRINT	 ;             FI 
Ea67=.			; 
Ea69=.
.PRINT	 ;         NEXT r1
	ADD #2,r1
	JMP Ea65		;back to top
Ea66=.
.PRINT	 ; ;        PRINTF #temp <returning failure from findpt r0=%o> r0
.PRINT	 ;         sec 
        sec 
.PRINT	 ;         rts pc
        rts pc
.PRINT	 ;          
         
.PRINT	 ;         .end 
        .end 
