From 27129fe152f6c7110377d41c91bbfe8484e621b8 Mon Sep 17 00:00:00 2001 From: Dave Schmenk Date: Sat, 14 Dec 2019 17:42:39 -0800 Subject: [PATCH] Upgrade editor to programmers editor --- src/tftpsys | 1 + src/toolsrc/ed.pla | 631 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 485 insertions(+), 147 deletions(-) diff --git a/src/tftpsys b/src/tftpsys index d652e52..78b1609 100755 --- a/src/tftpsys +++ b/src/tftpsys @@ -14,6 +14,7 @@ echo "SYS/JITUNE"; atftp $1 --put -l rel/apple/JITUNE#FE1000 -r $2/SYS/JITUNE echo "SYS/ARGS"; atftp $1 --put -l rel/ARGS#FE1000 -r $2/SYS/ARGS#FE1000 echo "SYS/DHCP"; atftp $1 --put -l rel/DHCP#FE1000 -r $2/SYS/DHCP#FE1000 echo "SYS/ED"; atftp $1 --put -l rel/ED#FE1000 -r $2/SYS/ED#FE1000 +echo "SYS/TFTPD"; atftp $1 --put -l rel/TFTPD#FE1000 -r $2/SYS/TFTPD#FE1000 echo "SYS/ETHERIP"; atftp $1 --put -l rel/ETHERIP#FE1000 -r $2/SYS/ETHERIP#FE1000 echo "SYS/MOUSE"; atftp $1 --put -l rel/apple/MOUSE#FE1000 -r $2/SYS/MOUSE#FE1000 echo "SYS/FIBER"; atftp $1 --put -l rel/FIBER#FE1000 -r $2/SYS/FIBER#FE1000 diff --git a/src/toolsrc/ed.pla b/src/toolsrc/ed.pla index 7e895a7..3e6e047 100755 --- a/src/toolsrc/ed.pla +++ b/src/toolsrc/ed.pla @@ -49,13 +49,15 @@ const keyctrlu = $95 const keyctrlv = $96 const keyctrlw = $97 const keyctrlx = $98 +const keyctrly = $99 const keyctrlz = $9A const keydelete = $FF // // Data and text buffer constants // -const MAXLINES = 1500 +const MAXLINES = 999 const MAXLINESSIZE = MAXLINES+24 +const MAXCLIPLINES = 256 const MAXLNLEN = 79 const MAXSTRPLSIZE = $8000 //const STRPLMAPSIZE = 224 // $E0 = 28K is memory@16 bytes per bit map, 128 bytes per 8 bit map, 1K bytes per 8 byte map @@ -64,28 +66,31 @@ const changed = 1 const insmode = 2 const showcurs = 4 const uppercase = 8 +const selection = 16 const shiftlock = 128 // // Text screen row address array // -word txtscrn = $0400,$0480,$0500,$0580,$0600,$0680,$0700,$0780 -word = $0428,$04A8,$0528,$05A8,$0628,$06A8,$0728,$07A8 -word = $0450,$04D0,$0550,$05D0,$0650,$06D0,$0750,$07D0 +const scrnwidth = 35 +word txtscrn = $0404,$0484,$0504,$0584,$0604,$0684,$0704,$0784 +word = $042C,$04AC,$052C,$05AC,$062C,$06AC,$072C,$07AC +word = $0454,$04D4,$0554,$05D4,$0654,$06D4,$0754,$07D4 // // Editor variables // byte nullstr = "" +byte[80] findstr = "" byte[64] filename = "UNTITLED" byte exit = FALSE byte flags = 0 byte flash = 0 word numlines = 0 -word cutbuf = 0 +word numcliplines = 0 word arg word strplsize = MAXSTRPLSIZE -word strpool, strplmapsize, strlinbuf, strpoolmap +word strpool, strplmapsize, txtlinbuf, cliplinbuf, strpoolmap byte cursx, cursy, scrnleft, curscol, underchr, curschr -word keyin, cursrow, scrntop, cursptr +word keyin, cursrow, selrow, scrntop, cursptr byte a3echo = $80 byte a3noecho = $00 // @@ -117,17 +122,17 @@ STHILP LDA (SRC),Y BNE STHILP + RTS end -asm cpyln(srcstr, dststr)#0 - LDA ESTKL,X - STA DSTL - LDA ESTKH,X - STA DSTH - INX +asm lncpy(dststr, srcstr)#0 LDA ESTKL,X STA SRCL LDA ESTKH,X STA SRCH INX + LDA ESTKL,X + STA DSTL + LDA ESTKH,X + STA DSTH + INX LDY #$00 LDA (SRC),Y TAY @@ -148,7 +153,43 @@ CPLNLP LDA (SRC),Y ++ STA (DST),Y RTS end - +asm lnupcpy(dststr, srcstr)#0 + LDA ESTKL,X + STA SRCL + LDA ESTKH,X + STA SRCH + INX + LDA ESTKL,X + STA DSTL + LDA ESTKH,X + STA DSTH + INX + LDY #$00 + LDA (SRC),Y + TAY + LDA #$00 + INY + STA (DST),Y + DEY + BEQ +++ +CPUPLP LDA (SRC),Y + CMP #$20 + BCS + + ADC #$60 ++ AND #$7F + CMP #$7B + BCS ++ + CMP #$61 + BCC ++ + SEC + SBC #$20 +++ STA (DST),Y + DEY + BNE CPUPLP + LDA (SRC),Y ++++ STA (DST),Y + RTS +end def bell#0 putc($07) end @@ -257,7 +298,8 @@ def inittxtbuf#0 word i if not strpool - strlinbuf = heapalloc(MAXLINESSIZE*2) + txtlinbuf = heapalloc(MAXLINESSIZE*2) + cliplinbuf = heapalloc(MAXCLIPLINES*2) while isult(heapavail, strplsize) strplsize = strplsize - 4096 loop @@ -267,9 +309,17 @@ def inittxtbuf#0 strplmapsize = strplsize / 128 strpoolmap = heapalloc(strplmapsize) strpool = heapalloc(strplsize) + memset(txtlinbuf, @nullstr, MAXLINESSIZE*2) + memset(cliplinbuf, @nullstr, MAXCLIPLINES*2) + memset(strpoolmap, 0, strplmapsize) + else + for i = 0 to MAXLINESSIZE-1 + if txtlinbuf=>[i] <> @nullstr + delstr(txtlinbuf=>[i]) + txtlinbuf=>[i] = @nullstr + fin + next fin - memset(strlinbuf, @nullstr, MAXLINESSIZE*2) - memset(strpoolmap, 0, strplmapsize) numlines = 1 cursrow = 0 curscol = 0 @@ -277,7 +327,7 @@ def inittxtbuf#0 cursy = 0 scrnleft = 0 scrntop = 0 - cutbuf = 0 + flags = flags & ~selection end // // Case conversion/printing routines @@ -315,7 +365,7 @@ def txtupper#0 flags = flags | uppercase for i = numlines - 1 downto 0 - strupper(strlinbuf=>[i]) + strupper(txtlinbuf=>[i]) next end def txtlower#0 @@ -323,9 +373,23 @@ def txtlower#0 flags = flags & ~uppercase for i = numlines - 1 downto 0 - strlower(strlinbuf=>[i]) + strlower(txtlinbuf=>[i]) next end +def strtonum(strptr) + word num, i + byte c + + num = 0 + for i = 1 to ^strptr + c = ^(strptr + i) & $7F + if c < '0' and c > '9' + break + fin + num = num * 10 + c - '0' + next + return num +end def nametostr(namestr, len, strptr)#0 ^strptr = len memcpy(strptr + 1, namestr, len) @@ -345,7 +409,7 @@ def readtxt(filename, startline)#0 if txtbuf sethibit(@txtbuf) if flags & uppercase; strupper(@txtbuf); fin - strlinbuf=>[numlines] = newstr(@txtbuf) + txtlinbuf=>[numlines] = newstr(@txtbuf) numlines++ fin if !(numlines & $0F); putc('.'); fin @@ -354,8 +418,8 @@ def readtxt(filename, startline)#0 // // Make sure there is a blank line at the end of the buffer // - if numlines < MAXLINES and strlinbuf=>[numlines - 1] <> @nullstr - strlinbuf=>[numlines] = @nullstr + if numlines < MAXLINES and txtlinbuf=>[numlines - 1] <> @nullstr + txtlinbuf=>[numlines] = @nullstr numlines++ fin fin @@ -374,12 +438,12 @@ def writetxt(filename)#0 // // Remove blank lines at end of text. // - while numlines > 1 and strlinbuf=>[numlines - 1] == @nullstr; numlines--; loop + while numlines > 1 and txtlinbuf=>[numlines - 1] == @nullstr; numlines--; loop // // Write all the text line to the file. // for i = 0 to numlines - 1 - cpyln(strlinbuf=>[i], @txtbuf) + lncpy(@txtbuf, txtlinbuf=>[i]) txtbuf++; txtbuf[txtbuf] = $0D // Add CR to end of line fileio:write(refnum, @txtbuf + 1, txtbuf) if !(i & $0F); putc('.'); fin @@ -406,57 +470,137 @@ def drawrow(row, ofst, strptr)#0 else numchars = ^strptr - ofst fin - if numchars >= 40 - numchars = 40 + if numchars >= 36 + numchars = 36 else - memset(scrnptr + numchars, $A0A0, 40 - numchars) + memset(scrnptr + numchars, $A0A0, 36 - numchars) fin memcpy(scrnptr, strptr + ofst + 1, numchars) end +def drawgutter(scrnrow, ofst)#0 + byte row, hilite, ofstch, huns, tens, ones + word scrnptr, scrnrow + + // + // Draw line numbers and gutter hilites + // + ofstch = ofst ?? $80 | '<' :: $80 | ' ' + huns, tens = divmod(scrnrow + 1, 100) + tens, ones = divmod(tens, 10) + for row = 0 to 23 + scrnptr = txtscrn[row] - 4 + if scrnrow < numlines + if flags & selection and (scrnrow >= selrow and scrnrow <= cursrow) or (scrnrow >= cursrow and scrnrow <= selrow) + hilite = $00 + elsif scrnrow == cursrow + hilite = $00 + else + hilite = $80 + fin + if huns + ^scrnptr = hilite + '0' + huns + ^(scrnptr+1) = hilite + '0' + tens + ^(scrnptr+2) = hilite + '0' + ones + ones++ + if ones > 9 + ones = 0 + tens++ + if tens > 9 + tens = 0 + huns++ + fin + fin + elsif tens + ^scrnptr = hilite + ' ' + ^(scrnptr+1) = hilite + '0' + tens + ^(scrnptr+2) = hilite + '0' + ones + ones++ + if ones > 9 + ones = 0 + tens++ + if tens > 9 + tens = 0 + huns = 1 + fin + fin + elsif ones + ^scrnptr = hilite + ' ' + ^(scrnptr+1) = hilite + ' ' + ^(scrnptr+2) = hilite + '0' + ones + ones++ + if ones > 9 + ones = 0 + tens = 1 + fin + fin + ^(scrnptr+3) = ofstch + else + *scrnptr = $A0A0 + *(scrnptr+2) = $A0A0 + fin + scrnrow++ + next +end def drawscrn(toprow, ofst)#0 byte row, numchars word strptr, scrnptr + + drawgutter(toprow, ofst) + // + // Draw text + // if ofst for row = 0 to 23 - strptr = strlinbuf=>[toprow + row] + strptr = txtlinbuf=>[toprow + row] scrnptr = txtscrn[row] if ofst >= ^strptr numchars = 0 else numchars = ^strptr - ofst fin - if numchars >= 40 - numchars = 40 + if numchars >= 36 + numchars = 36 else - memset(scrnptr + numchars, $A0A0, 40 - numchars) + memset(scrnptr + numchars, $A0A0, 36 - numchars) fin memcpy(scrnptr, strptr + ofst + 1, numchars) next else for row = 0 to 23 - strptr = strlinbuf=>[toprow + row] + strptr = txtlinbuf=>[toprow + row] scrnptr = txtscrn[row] numchars = ^strptr - if numchars >= 40 - numchars = 40 + if numchars >= 36 + numchars = 36 else - memset(scrnptr + numchars, $A0A0, 40 - numchars) + memset(scrnptr + numchars, $A0A0, 36 - numchars) fin memcpy(scrnptr, strptr + 1, numchars) next fin end def cursoff#0 + word scrnptr + if flags & showcurs - ^cursptr = underchr + ^cursptr = underchr + scrnptr = txtscrn[cursy] - 4 + *scrnptr = *scrnptr | $8080 + ^(scrnptr+2) = ^(scrnptr+2) | $80 flags = flags & ~showcurs + fin end def curson#0 + word scrnptr + if !(flags & showcurs) cursptr = txtscrn[cursy] + cursx underchr = ^cursptr ^cursptr = curschr + scrnptr = txtscrn[cursy] - 4 + *scrnptr = *scrnptr & $7F7F + ^(scrnptr+2) = ^(scrnptr+2) & $7F flags = flags | showcurs fin end @@ -509,6 +653,9 @@ def cursup#0 cursrow-- if cursy > 0 cursy-- + if flags & selection + drawgutter(scrntop, scrnleft) + fin else scrntop = cursrow drawscrn(scrntop, scrnleft) @@ -529,6 +676,9 @@ def cursdown#0 cursrow++ if cursy < 23 cursy++ + if flags & selection + drawgutter(scrntop, scrnleft) + fin else scrntop = cursrow - 23 drawscrn(scrntop, scrnleft) @@ -564,13 +714,13 @@ def pgleft#0 next end def cursright#0 - if curscol < 80 + if curscol < MAXLNLEN cursoff curscol++ - if cursx < 39 + if cursx < scrnwidth cursx++ else - scrnleft = curscol - 39 + scrnleft = curscol - scrnwidth drawscrn(scrntop, scrnleft) fin curson @@ -583,6 +733,79 @@ def pgright#0 cursright next end +def curshpos(hpos)#0 + cursoff + curscol = hpos + if curscol > scrnwidth + cursx = curscol - scrnwidth + scrnleft = scrnwidth + else + cursx = curscol + scrnleft = 0 + fin + curson +end +def cursvpos(vpos)#0 + cursrow = vpos + if cursrow > numlines - 1 + cursrow = numlines - 1 + fin + if numlines > 23 and cursrow > 12 + cursy = 12 + scrntop = cursrow - 12 + else + cursy = cursrow + scrntop = 0 + fin + redraw +end +// +// Find string in text +// +def findline(strptr)#1 + byte upstr[80], scan, i + + if ^strptr >= findstr + lnupcpy(@upstr, strptr) + for scan = 1 to upstr - findstr + 1 + if upstr[scan] == findstr[1] + for i = 2 to findstr + if upstr[scan + i - 1] <> findstr[i] + break + fin + next + if i > findstr + curshpos(scan - 1) + return TRUE + fin + fin + next + fin + return FALSE +end +def findtxt#0 + word f + + // + // Search from current pos to end + // + for f = cursrow + 1 to numlines - 1 + if findline(txtlinbuf=>[f]) + cursvpos(f) + return + fin + next + // + // Search from beginning to current pos + // + for f = 0 to cursrow + if findline(txtlinbuf=>[f]) + cursvpos(f) + return + fin + next + bell +end // // Keyboard routines // @@ -661,9 +884,9 @@ def keyin3 is $80 | '5' key = keyctrld; break // Del is $80 | '.' - key = keyctrlb; break // Ins + key = keyctrlc; break // Copy is $80 | '0' - key = keyctrlv; break // Copy + key = keyctrlv; break // Paste is $80 | '-' key = keyctrlx; break // Cut wend @@ -773,7 +996,7 @@ def printtxt(slot)#0 scrncsw = *csw *csw = $C000 | (slot << 8) for i = 0 to numlines - 1 - cpyln(strlinbuf=>[i], @txtbuf) + lncpy(@txtbuf, txtlinbuf=>[i]) puts(@txtbuf) putln next @@ -781,8 +1004,8 @@ def printtxt(slot)#0 end def openline(row) if numlines < MAXLINES - memcpy(@strlinbuf=>[row + 1], @strlinbuf=>[row], (numlines - row) * 2) - strlinbuf=>[row] = @nullstr + memcpy(@txtlinbuf=>[row + 1], @txtlinbuf=>[row], (numlines - row) * 2) + txtlinbuf=>[row] = @nullstr numlines++ flags = flags | changed return TRUE @@ -790,48 +1013,152 @@ def openline(row) bell return FALSE end -def cutline#0 - delstr(cutbuf) - cutbuf = strlinbuf=>[cursrow] - memcpy(@strlinbuf=>[cursrow], @strlinbuf=>[cursrow + 1], (numlines - cursrow) * 2) - if numlines > 1 - numlines-- - fin - flags = flags | changed - if cursrow == numlines - cursup - fin - redraw +def freesel#0 + word i + + for i = 0 to numcliplines - 1 + if cliplinbuf=>[i] <> @nullstr + delstr(cliplinbuf=>[i]) + cliplinbuf=>[i] = @nullstr + fin + next + numcliplines = 0 end -def pasteline#0 - if cutbuf and numlines < MAXLINES - memcpy(@strlinbuf=>[cursrow + 1], @strlinbuf=>[cursrow], (numlines - cursrow) * 2) - strlinbuf=>[cursrow] = newstr(cutbuf) - numlines++ +def selrange#2 + word first, last + + if flags & selection + if cursrow > selrow + first, last = selrow, cursrow + else + first, last = cursrow, selrow + fin + else + first = cursrow + last = first + fin + return first, last +end +def beginsel#0 + flags = flags ^ selection + selrow = cursrow + drawgutter(scrntop, scrnleft) +end +def copysel#0 + word firstsel, lastsel + + freesel + firstsel, lastsel = selrange + for numcliplines = 0 to lastsel - firstsel + cliplinbuf=>[numcliplines] = newstr(txtlinbuf=>[firstsel + numcliplines]) + next + flags = flags & ~selection + drawgutter(scrntop, scrnleft) +end +def cutsel#0 + word firstsel, lastsel + + freesel + firstsel, lastsel = selrange + if lastsel - firstsel < MAXCLIPLINES + for numcliplines = 0 to lastsel - firstsel + cliplinbuf=>[numcliplines] = txtlinbuf=>[firstsel + numcliplines] + next + memcpy(@txtlinbuf=>[firstsel], @txtlinbuf=>[lastsel + 1], (numlines - lastsel + 1) * 2) + numlines = numlines - numcliplines + cursrow = firstsel + if cursrow >= numlines + cursrow = numlines - 1 + fin + if cursrow < scrntop + scrntop = cursrow + fin + cursy = cursrow - scrntop + flags = flags | changed + flags = flags & ~selection + redraw + else + bell + fin +end +def pastesel#0 + word p + + if numcliplines and numcliplines + numlines < MAXLINES + memcpy(@txtlinbuf=>[cursrow + numcliplines], @txtlinbuf=>[cursrow], (numlines - cursrow) * 2) + for p = 0 to numcliplines - 1 + txtlinbuf=>[cursrow + p] = newstr(cliplinbuf=>[p]) + next + numlines = numlines + numcliplines flags = flags | changed redraw else bell fin end +def indentsel#0 + byte indentstr[80], l + word firstsel, lastsel, i + + freesel + firstsel, lastsel = selrange + for i = firstsel to lastsel + l = ^(txtlinbuf=>[i]) + if l < MAXLNLEN - 2 + memcpy(@indentstr + 3, txtlinbuf=>[i] + 1, l) + indentstr[0] = l + 2 + indentstr[1] = $A0 + indentstr[2] = $A0 + delstr(txtlinbuf=>[i]) + txtlinbuf=>[i] = newstr(@indentstr) + flags = flags | changed + fin + next + redraw +end +def undentsel#0 + byte undentstr[80], l + word firstsel, lastsel, i + + freesel + firstsel, lastsel = selrange + for i = firstsel to lastsel + l = ^(txtlinbuf=>[i]) + if l + memcpy(@undentstr + 1, txtlinbuf=>[i] + 1, l) + if undentstr[1] == $A0 + memcpy(@undentstr + 1, @undentstr + 2, l - 1) + l-- + if l and undentstr[1] == $A0 + memcpy(@undentstr + 1, @undentstr + 2, l - 1) + l-- + fin + undentstr[0] = l + delstr(txtlinbuf=>[i]) + txtlinbuf=>[i] = newstr(@undentstr) + flags = flags | changed + fin + fin + next + redraw +end def joinline#0 byte joinstr[80], joinlen, stripjoin[80] if cursrow < numlines - 1 - strstripcpy(@joinstr, strlinbuf=>[cursrow]) - joinstr++ - joinstr[joinstr] = $80 | ' ' // add trailing space - memcpy(@stripjoin, strlinbuf=>[cursrow + 1], ^(strlinbuf=>[cursrow + 1]) + 1) + strstripcpy(@joinstr, txtlinbuf=>[cursrow]) + memcpy(@stripjoin, txtlinbuf=>[cursrow + 1], ^(txtlinbuf=>[cursrow + 1]) + 1) striplead(@stripjoin, $80 | ' '); joinlen = joinstr + stripjoin if joinlen < 80 + curshpos(joinstr) memcpy(@joinstr + joinstr + 1, @stripjoin + 1, stripjoin) joinstr = joinlen - delstr(strlinbuf=>[cursrow]) - strlinbuf=>[cursrow] = newstr(@joinstr) - delstr(strlinbuf=>[cursrow + 1]) + delstr(txtlinbuf=>[cursrow]) + txtlinbuf=>[cursrow] = newstr(@joinstr) + delstr(txtlinbuf=>[cursrow + 1]) numlines-- - memcpy(@strlinbuf=>[cursrow + 1], @strlinbuf=>[cursrow + 2], (numlines - cursrow) * 2) + memcpy(@txtlinbuf=>[cursrow + 1], @txtlinbuf=>[cursrow + 2], (numlines - cursrow) * 2) flags = flags | changed redraw else @@ -844,52 +1171,38 @@ def splitline#0 if openline(cursrow + 1) if curscol - splitlen = ^(strlinbuf=>[cursrow]) + splitlen = ^(txtlinbuf=>[cursrow]) if curscol < splitlen - 1 splitstr = splitlen - curscol - memcpy(@splitstr + 1, strlinbuf=>[cursrow] + curscol + 1, splitstr) + memcpy(@splitstr + 1, txtlinbuf=>[cursrow] + curscol + 1, splitstr) striplead(@splitstr, $80 | ' ') - for i = 1 to curscol - 1 - if ^(strlinbuf=>[cursrow] + i) <> $80 | ' ' + for i = 1 to curscol + if ^(txtlinbuf=>[cursrow] + i) <> $80 | ' ' break fin memcpy(@splitstr + 2, @splitstr + 1, splitstr) splitstr[1] = $80 | ' ' splitstr++ next - strlinbuf=>[cursrow + 1] = newstr(@splitstr) + txtlinbuf=>[cursrow + 1] = newstr(@splitstr) splitstr = curscol - memcpy(@splitstr + 1, strlinbuf=>[cursrow] + 1, splitstr) - delstr(strlinbuf=>[cursrow]) - strlinbuf=>[cursrow] = newstr(@splitstr) - curscol = i - 1 - if curscol > 39 - cursx = curscol - 39 - scrnleft = 39 - else - cursx = curscol - scrnleft = 0 - fin + memcpy(@splitstr + 1, txtlinbuf=>[cursrow] + 1, splitstr) + delstr(txtlinbuf=>[cursrow]) + txtlinbuf=>[cursrow] = newstr(@splitstr) + curshpos(i - 1) else if splitlen > 0 for curscol = 1 to splitlen - 1 - if ^(strlinbuf=>[cursrow] + curscol) <> $80 | ' ' + if ^(txtlinbuf=>[cursrow] + curscol) <> $80 | ' ' break fin - next - curscol-- - if curscol > 39 - cursx = curscol - 39 - scrnleft = 39 - else - cursx = curscol - scrnleft = 0 - fin + next + curshpos(curscol - 1) fin fin else - strlinbuf=>[cursrow + 1] = strlinbuf=>[cursrow] - strlinbuf=>[cursrow] = @nullstr + txtlinbuf=>[cursrow + 1] = txtlinbuf=>[cursrow] + txtlinbuf=>[cursrow] = @nullstr fin redraw cursdown @@ -908,9 +1221,9 @@ def editline(key) if (editkey(key)) flags = flags | changed memset(@editstr, $A0A0, 80) - strstripcpy(@editstr, strlinbuf=>[cursrow]) - undoline = strlinbuf=>[cursrow] - strlinbuf=>[cursrow] = @editstr + strstripcpy(@editstr, txtlinbuf=>[cursrow]) + undoline = txtlinbuf=>[cursrow] + txtlinbuf=>[cursrow] = @editstr repeat if key >= keyspace if key == keydelete @@ -919,20 +1232,11 @@ def editline(key) memcpy(@editstr[curscol], @editstr[curscol + 1], editstr - curscol) editstr-- fin - curscol-- - cursoff - if cursx > 0 - cursx-- - drawrow(cursy, scrnleft, @editstr) - else - scrnleft-- - drawscrn(scrntop, scrnleft) - fin + curshpos(curscol - 1) curson fin elsif curscol < MAXLNLEN - curscol++ - cursx++ + curshpos(curscol + 1) if flags & insmode if editstr < MAXLNLEN or editstr.MAXLNLEN == $A0 editstr++ @@ -942,8 +1246,7 @@ def editline(key) memcpy(@editstr[curscol + 1], @editstr[curscol], editstr - curscol) fin else - curscol-- - cursx-- + curshpos(curscol - 1) key = editstr[curscol] bell fin @@ -954,11 +1257,11 @@ def editline(key) fin editstr[curscol] = caseconv(key) cursoff - if cursx <= 39 + if cursx <= scrnwidth drawrow(cursy, scrnleft, @editstr) else scrnleft++ - cursx = 39 + cursx = scrnwidth drawscrn(scrntop, scrnleft) fin curson @@ -983,9 +1286,9 @@ def editline(key) key = keyin() until not editkey(key) if editstr - strlinbuf=>[cursrow] = newstr(@editstr) + txtlinbuf=>[cursrow] = newstr(@editstr) else - strlinbuf=>[cursrow] = @nullstr + txtlinbuf=>[cursrow] = @nullstr fin delstr(undoline) fin @@ -1017,14 +1320,25 @@ def editmode#0 curshome; break is keyctrle cursend; break + is keyctrlb + beginsel; break + is keyctrlc + copysel; break is keyctrlx - cutline; break + cutsel; break is keyctrlv - pasteline; break + pastesel; break is keyctrlf - if numlines < MAXLINES and cursrow == numlines - 1 - strlinbuf=>[numlines] = @nullstr - numlines++ + if cursrow == (numlines - 1) + if numlines < MAXLINES + numlines++ + cursdown + flags = flags | changed + drawgutter(scrntop, scrnleft) + else + bell + fin + break fin cursdown is keyctrlo @@ -1043,11 +1357,19 @@ def editmode#0 is keyctrlt joinline; break is keyctrli - keyin = @tabkeyin - editline(keyspace) - setkeyin + if flags & selection + if flags & insmode + indentsel + else + undentsel + fin + else + keyin = @tabkeyin + editline(keyspace) + setkeyin + fin break - is keyctrlb + is keyctrly if flags & insmode flags = flags & ~insmode curschr = ' ' @@ -1056,14 +1378,6 @@ def editmode#0 curschr = '+' fin break - is keyctrlc - if flags & uppercase - txtlower - else - txtupper - fin - redraw - break is keyescape if MACHID == $F2 // Apple 3 dev_control(cmdsys.devcons, 11, @a3echo) @@ -1167,7 +1481,7 @@ def chkchng end def cmdmode#0 byte slot - word cmdptr + word cmdptr, line clrscrn puts("PLASMA Editor, Version 2.0 Dev\n") @@ -1175,11 +1489,26 @@ def cmdmode#0 puts(@filename) cmdptr = gets($BA) when toupper(parsecmd(cmdptr)) - is 'A' + is 'F' // Find string + if ^cmdptr + lnupcpy(@findstr, cmdptr) + fin + findtxt + return + is 'G' // Goto line # + line = strtonum(cmdptr) + if line + curshpos(0) + cursvpos(line - 1) + fin + is 'E' // Edit mode + is 0 + return + is 'A' // Append file readtxt(cmdptr, numlines) flags = flags | changed break - is 'R' + is 'R' // Read file if chkchng inittxtbuf strstripcpy(@filename, cmdptr) @@ -1187,7 +1516,7 @@ def cmdmode#0 flags = flags & ~changed fin break - is 'W' + is 'W' // Write file if ^cmdptr strstripcpy(@filename, cmdptr) fin @@ -1195,11 +1524,11 @@ def cmdmode#0 //if flags & changed; fin flags = flags & ~changed break - is 'C' + is 'C' // Catalog prfiles(cmdptr); break - is 'P' + is 'P' // Prefix fileio:setpfx(cmdptr); break - is 'H' + is 'H' // Hardcopy if ^cmdptr slot = cmdptr.1 - '0' else @@ -1207,17 +1536,25 @@ def cmdmode#0 fin printtxt(slot) break - is 'Q' + is 'Q' // Quit exit = chkchng - is 'E' - is 0 - return - is 'N' + if not exit + return + fin + break + is 'N' if chkchng inittxtbuf strstripcpy(@filename, "UNTITLED") fin break + is 'T' // Toggle upper/lower case display + if flags & uppercase + txtlower + else + txtupper + fin + break otherwise bell putc('?')