; *********************************************************************
; EDIT05
; Pascal editor file 05
; B.Bridgwater 5.12.83
; *********************************************************************
;
;------------------------------------------------------------------------
scrnud ;
;
;Entry - scrnY = desired screen Y coord of current line
;        (scrnX,scrnY) = final cursor position
;        updatereqd e [none,
;                      csronwards,
;                      hardup,harddown,
;                      fullscreen,
;                      thelot]
;
;Exit  - screen & scrim updated
;        scrnY forced if necessary
;        update possibly aborted by incoming char.
;        currlength valid
;
       jsr curoff
       ;
       jsr lengthcalc
       sta currlength
       ;
       ;Update marks set, if any, to locate them for superimposition.
       ;
       jsr markupdate
       ;
       lda updatereqd
       cmpIM thelot
       bne scudti
       ;
       jsr clearscreen
       jsr status
       ldaIM fullscreen
       sta updatereqd
       ;
scudti ;If screen messier than would be fixed up by intended update,
       ;then do something about it.
       ;
       lda scrnpy
       cmp updatereqd
       bcc scudco
       sta updatereqd
       ;
scudco ;updatereqd should now fix up the screen.
       ;
       ldaIM none
       sta scrnpy
       ;
       ;If fullscreen update is required, then find internal start
       ;of screen, possibly forcing scrnY, and update top half.
       ;
       lda updatereqd
       beq scudex ;'none'
       cmpIM fullscreen
       bne scudBo
       ;
       lda scrnY
       jsr TPGSbk
       sta scrnY
       ;
       tay
       dey
       sty maxscrupY
       bmi scudBo
       ldaIM 0
       ldx TP
       ldy TP+1
       jsr updtln
       bcs scudAb
       ;
scudBo ;Output bottom half of screen, branching for hardscrolls.
       ;
       ldaim 0
       sta EOTflag
       ;
       ldx updatereqd
       cpxIM hardup
       beq scudHU
       cpxIM harddown
       beq scudHD
       ;
       ldy pagelength
       sty maxscrupY
       jsr updtbt
       bcc scudex
       ;
scudAb ;Record the fact that screen isn't totally up-to-date.
       ;
       ldaIM csronwards
       cmp updatereqd
       bcs scudAS
       ldaIM fullscreen
scudAS sta scrnpy
       ;
scudex rts
;------------------------------------------------------------------------
scudHU ;Push against bottom to scroll up.
;              
       jsr csr0statusY
       ldaim down
       jsr OSWRCH
       ;
       ;Scroll scrim up.
       ;       
       ldyim 0
scHUlp ldaay scrim+1
       staay scrim
       iny
       cpy scrnlg
       bne scHUlp
       ldaim 0
       staay scrim
       ;
       jsr status
       ;
       lda pagelength
       bpl scHUDc
;
scudHD ;Rewrite status, then push against top to scroll down.
;
       ldy pagelength
       jsr statsY
       ;
       ldaim home
       jsr OSWRCH
       ldaim up
       jsr OSWRCH
       ;
       ;Scroll scrim down.
       ;
       ldy pagelength
scHDlp ldaay scrim
       staay scrim+1
       dey
       bpl scHDlp
       ldaim 0
       sta scrim
       ;
       ldaim 0
scHUDc sta maxscrupY
       ;
       ldx SCP
       ldy SCP+1
       bne updtln
       ;       
       tay
       jmp wipeline
;------------------------------------------------------------------------
updtbt ;Set upAX A,Y for bottom half update.
;
       lda scrnY
       ldx GE
       ldy GE+1
;
;........................................................................
updtln ;
;
;Entry - A = Y-coord of 1st line to be output.
;        XY --> 1st line to be output.
;        maxscrupY = last line to be updated.
;         
;Exit  - line output, with rest of line wiped if necessary
;        scrim,scrupY assigned (top bit set if no <CR> on line)
;        If was last line (temp = hymem after update), then
;        loop clearing lines until scrupY = pagelength.
;
;        CC - Normal termination
;        CS - Update aborted due to incoming character.
;
       sta scrupY
       stx TP
       sty TP+1
       ;
       ;If required update is a hard scroll, then skip queuetest to ensure
       ;that scroll line is output.
       ;
       lda updatereqd
       cmpim hardup
       beq updlco
       cmpim harddown
       beq updlco
       ;
       ;If updatereqd = csronwards then start screen update from char under
       ;cursor.
       ;
       cmpim csronwards
       bne updlQT
       ;
       jsr queuetest
       ;
       ldx scrnX
       cpx currlength
       bcc updlC1
       ldx currlength
updlC1 ldy scrupY
       jsr csrXY
       ;
       txa
       tay
       ;
       bpl updll2
       ;
updlQT jsr queuetest
       ;
updlco jsr csr0scrupY
       ;
       ldyim &FF
updllp iny
updll2 ldaIY TP
       pha
       jsr paswrch
       pla
       cmpim CR
       beq updlCR
       cpy pagewidth
       bne updllp
       ;
       tya
       oraim &80
       bne udleln
updlCR tya
       ;
udleln sty count ;Max csrX on this line.
       ;
       ;Superimpose marks, if any, onto this line.
       ;
       ldy markX
       ;
moutlp dey
       bmi moutex
       sty index
       ;
       ;If 0 <= (Mark - TP) <= count, then this is csrX within line.
       ;
       sec
       ldaay UMATlo
       sbc TP
       tax
       ldaay UMAThi
       sbc TP+1
       bcc moutlp
       bne moutlp
       ;  
       cpx count
       beq moutmo
       bcs moutlp
       ;
moutmo ldy scrupY
       jsr csrXY
       ;
       ldaim space
       jsr invwrch
       ;
       ldy index
       bne moutlp
       ;
moutex ;Update TP, and see if have hit end of file.
       ;
       lda count
       ldy scrupY
       jsr wipetail
       ;
       jsr TPpAp1 ;A = count
       bcc updlNE
       ;
       inc EOTflag
       ;
       ;Overwrite sentinal EOT CR with EOT character.
       ;
       ldx count
       ldy scrupy
       jsr csrXY
       ;
       ldaim "*"
       jsr invwrch
       ;
updlNE ldy scrupY
       cpy maxscrupY
       bcs updlfi
       ;
       inc scrupY
       ;
       lda EOTflag
       bne udlEOT
       jmp updlQT
       ;
udlEOT jsr queuetest
       ;
       ldy scrupY
       jsr wipeline
       ;
       inc scrupY
       ;
       cpy pagelength
       bcc udlEOT
       ;
updlfi clc
       rts
;-----------------------------------------------------------------------
queuetest ;Test if any characters/commands are being queued in buffer.
;
;Exit  -  Nothing queueing (EQ).
;      -  If anything was queueing, then pla: pla: sec: rts
;
       lda nextreadflag
       bne queuCS
       ;
       ldaim &81
       ldxim 0
       ldyim 0
       jsr OSBYTE
       cpyim &FF
       beq queuex
       ;
       cpyim ESCAPE
       bne queust
       ;
       ldaim &7E
       jsr OSBYTE
       ;
       ldxim ESCAPE
       ;
queust inc nextreadflag
       stx nxtchr
       ;
queuCS pla
       pla
       sec
       ;
queuex rts
;-----------------------------------------------------------------------
wipeline ;Clear a specified line, assigning new scrim value.
;
;Entry - Y is line to clear.
;
       sty atemp
       ;
       jsr csr0Y
       ;
       ldaim space
       jsr OSWRCH
       ;
       ldaim 0
wplico ldy atemp
;
;........................................................................
wipetail ;Assign scrim entry for a line, clearing old tail of line.
;
;Entry - A = New scrim entry (may have top bit set)
;        Y = screen Y-coord
;Exit  - Tail of line wiped.
;        scrim updated
;        A,Y preserved.
;
       sta atemp
       bmi wtscrm
       ;
       sec
       ldaay scrim
       andim &7F
       sbc atemp
       bcc wtscrm
       beq wtscrm
       ;
       tax
       ldaim space
wtwipe jsr OSWRCH
       dex
       bne wtwipe
       ;
wtscrm lda atemp
       staay scrim
       ;
       rts
;-----------------------------------------------------------------------
paswrch ;
;
;Entry - A = char to output.
;
;Exit  - Y preserved
;        CR          --> ' ' or inverted, depending on CRvisflag
;        ctrl ch     --> inverted or chr(255) depending on mode
;        delete      --> chr(255)
;        other chars --> echoed
;
       cmpim space
       bcc paswct
       cmpim delete
       bne paswOS
       ;
       ldaim space
       bne invwrch
       ;
paswct cmpim CR
       bne paswNC
       ldx CRvisflag
       bne paswNC
       ;
       ldaim space
paswOS jmp OSWRCH
       ;
paswNC ;Output control character as inverted keytop.
       ;
       oraim &40
       ;
;........................................................................
invwrch ;Output character in inverse video (blob in mode 7).
;
;Entry - A = character
;        mode IN [0..7]
;
       ldx mode
       cpxim 7
       bne invwN7
       ;
       ldaim 255
       jmp OSWRCH
       ;
invwN7 pha
       ldxim 7
invwlp ldaax invdata
       jsr OSWRCH
       cpxim 4
       bne invwNA
       pla
       jsr OSWRCH
invwNA dex
       bpl invwlp
       rts
       ;
;
invdata ;(Backwards) VDU stream to toggle text BG/FG colours.
;
 = 1
 = 17
 = 128
 = 17
 = 0
 = 17
 = 129
 = 17

;------------------------------------------------------------------------
 lnk edit06
