; *********************************************************************
; EDIT01 - Stand alone pascal editor required routines.
; Pascal editor file 01
; B.Bridgwater 19.1.84
; *********************************************************************
;
;------------------------------------------------------------------------
XYscratch ;Load XY with address of scratch.
;
       ldxIM :LSB: scratch
       ldyIM :MSB: scratch
       rts
;------------------------------------------------------------------------
filename ;
;
;Entry - IY temp points to input name.
;
;Exit  - scratch --> filename.
;
       clc
       tya
       adc temp
       sta scratch
       ldaIM 0
       adc temp+1
       sta scratch+1
       rts
;------------------------------------------------------------------------
pasload ;Entry -IY temp --> filename
;
;         addr = load address
;         AX = max free address
;Exit  -  File checked for size (not on slow FS's)
;         File loaded to addr, with XY = top of file
;
       sec
       sbc addr
       sta maxsize
       txa
       sbc addr+1
       sta maxsize+1
       ;
       jsr filename
       ;
       jsr slowFStest
       bcc nosizecheck
       ;
       ;Using a random access filing system, so can quickly check size of file.
       ;
       ldaIM 5
       jsr XYscratch
       jsr OSFILE
       cmpIM 1
       bne nosizecheck ;Let FS generate 'Directory/not found' error.
       ;
       lda scratch+&0C
       ora scratch+&0D
       bne paslhuge
       lda maxsize
       cmp scratch+&0A
       lda maxsize+1
       sbc scratch+&0B
       bcc paslhuge
       ;
nosizecheck ;Load file to addr, & set XY --> top of loaded file.
       ;
       lda addr
       sta scratch+2
       lda addr+1
       sta scratch+3
       ldaIM 0
       sta scratch+4
       sta scratch+5
       sta scratch+6
       ;
       ldaIM &FF
       jsr XYscratch
       jsr OSFILE
       ;
       clc
       lda addr
       adc scratch+&0A
       tax
       lda addr+1
       adc scratch+&0B
       tay
       rts
       ;
paslhuge jmp brkX3 ;'File too big'
;-----------------------------------------------------------------------
tload ;
;
       lda TSTART
       sta addr
       lda TSTART+1
       sta addr+1
       ;
       lda TMAX
       ldx TMAX+1
       ;
       jsr pasload
       stx TEND
       sty TEND+1
       ;
       rts
;-----------------------------------------------------------------------
tsave ;Save (defaulting) marked block of text.
;
;Entry - (temp),Y points to input name.
;        GE   = Start of block
;        ENDP = End of block
;
;Exit  - specified memory saved as filename.
;
       jsr filename
       ;
       ldaIM 0
       ldxIM 15
pasacl staAX scratch+2
       dex
       bpl pasacl
       ;
       lda GE
       sta scratch+&0A
       lda GE+1
       sta scratch+&0B
       lda ENDP
       sta scratch+&0E
       lda ENDP+1
       sta scratch+&0F
       ;
       ldaIM 0
       jsr XYscratch
       jmp OSFILE
;------------------------------------------------------------------------
readnstrip ;Reads line to commandline (linbuf), & strips leading &
;trailing spaces.
;
;Exit - temp --> 1st non-space char on line
;       A = 1st non-space char on line
;       Y = 0
;       EQ if line was 'empty', else NE
;
       jsr readline
;
rensco ;Entry point for prompt_line.
;
       tya
       beq rensCR
rensst ldaAY commandline-1
       cmpIM space
       bne rensCR
       dey
       bne rensst
rensCR ldaIM CR
       staAY commandline
       ;
       ldyIM &FF
rensig iny
       ldaAY commandline
       cmpIM space
       beq rensig
       ;
       clc
       tya
       adcIM :LSB: commandline
       sta temp
       ldaIM 0
       adcIM :MSB: commandline
       sta temp+1
       ;
       ldaAY commandline
       ldyIM 0
       cmpIM CR
       rts
;------------------------------------------------------------------------
readline ;Read line into linbuf/commandline, testing for escape.
         ;Exit - Y = No. of chars read (excluding CR).
;
       jsr rdlnRE
       ;
;........................................................................
ESCtst ;Test &FF and escape if set.
;
       lda &FF
       bmi escset
       rts
;
escset ;Acknowledge escape & raise error.
;
       ldaIM &7E
       jsr OSBYTE
       jmp brkX1
;------------------------------------------------------------------------
rdlnRE ;Read line into linbuf/commandline, testing for escape.
;
;Exit  -  CC - Y = No. of chars read (excluding CR).
;         CS - Escape pressed.
;
       ldxIM 4
rdlncp ldaAX rdlndata
       staAX scratch
       dex
       bpl rdlncp
       ;
       ldaIM 0
       jsr XYscratch
       jmp OSWORD
;------------------------------------------------------------------------
rdlndata ;OSWORD A=0 control block.
       & linbuf
       = 255
       = space
       = &FF
;------------------------------------------------------------------------
slowFStest ;Returns CC if a slow filing system is in use, else CS.
       ldyIM 0
       tya
       jsr OSARGS
       cmpIM 4
       rts
;------------------------------------------------------------------------
copybk ;Copy block backwards (i.e. to lower address).
;
;Entry - ARGP --> block of size XY
;        VARP --> destination address 
;
       stx size
       sty size+1
blkcpy ;
       ;
       lda size
       ora size+1
       beq bkexit
       ;
       ldx size+1
       sec
       ldaIM 0
       sbc size
       tay
       beq bkloop
       sta temp
       ;
       sec
       lda ARGP
       sbc temp
       sta ARGP
       bcs cpnhi1
       dec ARGP+1
       sec
cpnhi1 lda VARP
       sbc temp
       sta VARP
       bcs cpnhi2
       dec VARP+1
       ;
cpnhi2 inx
       ;
bkloop ldaIY ARGP
       staIY VARP
       iny
       bne bkloop
       inc ARGP+1
       inc VARP+1
       dex
       bne bkloop
bkexit rts
;--------------------------------------------------------------------
strout ;Output stringA1 pointed to by (string)
;Terminator is top bit set char, or 0.
       ldyIM 0
strtlp iny
       ldaIY string
       beq strtex
       andIM &7F
       jsr OSASCI
       ldaIY string
       bpl strtlp
strtex rts
;------------------------------------------------------------------------

       lnk edit02
