;	C/	;/;/
;	C/;/	;/
;
; the following	are mpp	macros
;
        $MACRO TTY A B C D E ...
        ** TTY1	#@1 #@2	#@3 #@4	#@5 #@6	#@7 #@8	#@9 #@A	#@B #@C	
        $ENDM 
;
        $MACRO TTY1
        I%IN <#@1> END <<JSR PC,TTflsh>> <TTY2 <#@1>>
        $ENDM 
;
        $MACRO TTY2
        S%SW 21
        I%IN <#@1> <R1 R2 R3 @R0 @R1 @R2 @R3>	<> <S%SW -21>
        I%SW 21	<MOV #@1,R0> <I%DF <#@1> R0 <MOV ##@1,R0>>
        CALL TTYCC
        $ENDM 
;
        $MACRO FUNCTION	set to parm3
        I%IDN	R0 <#@2> <I%ERR	<Cant use	r0 here>>
        TTY ESC	'R
        I%DF R0	<#@3>	<mov #@3,r0>
        call ttycc
        $ENDM 
;
        $MACRO CURSOR TO X,Y
        MOV #@2,-(SP)
        MOV #@3,-(SP)
        CALL CURSR2
        $ENDM 
;
        $MACRO return	;this MUST be lower case
        rts pc
        $ENDM 
/
        PROGRAM	E8. SCREEN EDITOR	2
        mutask=1 
        .psect edi08
         
         
        .enabl lc
         
        .MACRO push this
        mov this,-(sp)
        .ENDM 
         
        .MACRO pop that
        mov (sp)+,that
        .ENDM 
        .if df mutask
        .MACRO pure
        .psect pur,ro
        .ENDM 
         
        .MACRO impure
        .psect ipur,rw
        .ENDM 
         
        .iff 
         
        .MACRO pure
        .ENDM 
        .MACRO impure
        .ENDM 
         
        .endc 
        impure 
         
        .globl sfacts	;entry for facts output
        .globl 	lkill	;line kill
        .globl 	scner2	;error	message	screen mode fixup
        .globl 	scner1	;error	message	screen mode fixup
         
         
         
; - - -	 macro library calls
         
         
        .mcall dir$,callr
         
         
; - - -	 local data and	symbols
         
        esc	=	33
        sdel	=	123
        home	=	110
        bottom	=	24.
        insert	=	114
        delete	=	115
        ceol	=	113
        ceop	=	'J
        rightmost =	80.
        screen	=	1
        line	=	0
        blank	=	40
         
        tab	=	11
         
fst:    .word 0
lst:    .word 0
loc:    .word 0
         
         
         
        pure 
         
         
         
lf:     .asciz /Left= /
rt:     .asciz / Right= /
ind:    .asciz / Indent= /
spc:    .asciz / Spacing= /
jst:    .asciz / Justify= /
         
         
fil:    .asciz /file: /
dt:     .asciz /   .= /
d$:     .asciz /   $= /
tp:     .asciz /    tmp= /
        .even 
         
fword:  .word lf,rt,ind,spc,jst
         
         
         
; - - -	lkill	kill the line (as	in control-u, but no linefeed)
         
lkill:   
        IF smode NE #0			;if =	screen mode
            push R0
            CURSOR to	#30.,#1		;30 means current line column 1
            TTY	esc ceol  END		;clear	it out on	the current line
            pop R0
        FI 
        return 
         
         
; - - -	 error fix up routines
         
scner2:  
        IF smode = #0
            call ttynl
            callr ttyskp
        ELSE 
            CURSOR to	#bottom-1,#1
            TTY	esc ceol END
            callr ttyskp
        FI 
         
         
scner1:  
        IF smode NE #0
            CURSOR to	#bottom,#30.	;leave it here, don't dump	it yet
            FUNCTION set to #'D
        FI 
        return 
         
         
; - - -	screen editor facts
         
sfacts:  
        call fixscn			;clear bottom 2 lines first
        CURSOR to #bottom-1,#20.
        call fillfacts                  ;display fill parmameters
         
        CURSOR to #bottom,#20.
         
        mov #fil,r0			;string "	file: "
        call ttystr
         
        mov #sfn,r0			;the file	name
        call ttystr
         
        mov #dt,r0			;string " .= "
        call ttystr
         
        mov dot,r1
        sub zero,r1			;decimal value of	dot
        asr r1
        call ttynum
         
        mov #d$,r0			;string " $= "
        call ttystr
         
        mov dol,r1			;decimal value of dollar
        sub zero,r1
        asr r1
        call ttynum
         
        mov #tp,r0			;string " tmp= "
        call ttystr
        mov $tptr,r1			;tmp pointer value
        call ttynum			;output it
         
        CURSOR to #bottom-1,#1.
        TTY END
        IF adr2 NE #0
            call shade                    
        FI 
         
        return 
         
         
         
         
shade:   
;        push    r4
;	push	r3
;	push	r0
        call saval
         
        LOOP for r2 = #1 TO #2
            LET fst = dot - #24.
            LET lst = dot + #18.
            mov #-1,loc
             
            LOOP for r3 = fst THRU lst step #2
                inc loc
                IF r3 HI zero   AND   r3 LOS   dol
                    IF r3 HIS padr1  AND r3 LOS padr2
                    ELSE 
                        call 10$
                    FI 
                FI 
                 
            NEXT r3
            CURSOR to #bottom-1,#1
            TTY END
            call getc
            mov r0,peek
        NEXT r2
;;	pop	r0
;;	pop	r3
;;	pop	r4
        return 
         
         
         
10$:     
        IF loc = #0
            CURSOR to #24.,#rightmost
        ELSE 
            CURSOR to loc,#rightmost
        FI 
         
        TTY esc sdel esc 'R
         
        IF r3 = dot
            mov fdot,r0
        ELSE 
            mov fpage,r0
        FI 
         
        IF r2 = #1
            bis #2,r0
        FI 
        TTY R0 END
        rts pc
         
         
fillfacts:  
        call saval
        mov #fparms,r3
        LOOP for r2 = #fword THRU #fword+8. STEP #2
            mov (r2),r0
            call ttystr
            mov (r3)+,r1
            call ttynum
        NEXT r2
        TTY END
        rts pc
         
         
         
        .end 
