1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-08-14 02:26:10 +00:00

Fix some editor redraw issues

This commit is contained in:
David Schmenk
2019-12-15 13:24:26 -08:00
parent 72ddf025e3
commit bc45a9263c
4 changed files with 175 additions and 118 deletions

View File

@@ -2,8 +2,8 @@ WELCOME TO THE PLASMA EDITOR!
============================= =============================
FIRST THINGS FIRST: FIRST THINGS FIRST:
TO NAVIGATE, USE THE ARROW KEYS. ON THE TO NAVIGATE, USE THE ARROW KEYS. ON
APPLE ][: THE APPLE ][:
CTRL-K = UP CTRL-K = UP
CTRL-J = DOWN. CTRL-J = DOWN.
@@ -18,22 +18,23 @@ TO JUMP AROUND THE TEXT FILE USE:
CTRL-Q = JUMP BEGINNING CTRL-Q = JUMP BEGINNING
CTRL-E = JUMP END CTRL-E = JUMP END
THE 'ESCAPE' KEY WILL PUT YOU IN COMMAND THE 'ESCAPE' KEY WILL PUT YOU IN
MODE. FROM THERE YOU CAN EXIT BY COMMAND MODE. FROM THERE YOU CAN
ENTERING 'Q' AND 'RETURN'. YOU CAN ALSO EXIT BY ENTERING 'Q' AND 'RETURN'.
RETURN TO THE EDITOR BY JUST PRESSING YOU CAN ALSO RETURN TO THE EDITOR BY
'RETURN'. JUST PRESSING 'RETURN'.
------- -------
THE PLASMA EDITOR IS A SIMPLE TEXT THE PLASMA EDITOR IS A SIMPLE TEXT
EDITOR FOR ENTERING AND MANIPULATING EDITOR FOR ENTERING AND MANIPULATING
TEXT AND SOURCE CODE FILES. THE EDITOR TEXT AND SOURCE CODE FILES. THE
ONLY SUPPORTS 40 COLUMN TEXT ALTHOUGH EDITOR ONLY SUPPORTS 40 COLUMN TEXT
LINES CAN BE UP TO 79 CHARACTERS LONG. ALTHOUGH LINES CAN BE UP TO 79
THE SCREEN WILL SCROLL HORIZONTALLY CHARACTERS LONG. THE SCREEN WILL
AS THE CURSOR MOVES. THERE IS 16K OF SCROLL HORIZONTALLY AS THE CURSOR
MEMORY FOR THE TEXT BUFFER. MOVES. THERE IS 16K OF MEMORY FOR
THE TEXT BUFFER.
IT HAS TWO MODES, COMMAND AND EDIT. IT HAS TWO MODES, COMMAND AND EDIT.
@@ -82,7 +83,7 @@ EDIT COMMANDS:
APPLE ][, UPPER AND LOWER CASE APPLE ][, UPPER AND LOWER CASE
ENTRY WORKS AS EXPECTED. ENTRY WORKS AS EXPECTED.
CTRL-C = FORCE LOWER-CASE CHARS ESC T = FORCE LOWER-CASE CHARS
If you have a lower-case character If you have a lower-case character
generator installed, you can force generator installed, you can force
@@ -128,7 +129,7 @@ EDIT COMMANDS:
OA-7 = JUMP BEGIN OA-7 = JUMP BEGIN
OA-1 = JUMP END OA-1 = JUMP END
OA-5 = DELETE CHAR OA-5 = DELETE CHAR
OA-- = DELETE/CUT LINE OA-- = DELETE/CUT LI
OA-0 = COPY DELETED LINE OA-0 = COPY DELETED LINE
OA-ENTER = OPEN NEW LINE OA-ENTER = OPEN NEW LINE
OA-. = TOGGLE INSERT/OVERWRITE OA-. = TOGGLE INSERT/OVERWRITE

Binary file not shown.

Binary file not shown.

View File

@@ -72,6 +72,7 @@ const shiftlock = 128
// Text screen row address array // Text screen row address array
// //
const scrnwidth = 35 const scrnwidth = 35
const scrnheight = 23
word txtscrn = $0404,$0484,$0504,$0584,$0604,$0684,$0704,$0784 word txtscrn = $0404,$0484,$0504,$0584,$0604,$0684,$0704,$0784
word = $042C,$04AC,$052C,$05AC,$062C,$06AC,$072C,$07AC word = $042C,$04AC,$052C,$05AC,$062C,$06AC,$072C,$07AC
word = $0454,$04D4,$0554,$05D4,$0654,$06D4,$0754,$07D4 word = $0454,$04D4,$0554,$05D4,$0654,$06D4,$0754,$07D4
@@ -89,7 +90,8 @@ word numcliplines = 0
word arg word arg
word strplsize = MAXSTRPLSIZE word strplsize = MAXSTRPLSIZE
word strpool, strplmapsize, txtlinbuf, cliplinbuf, strpoolmap word strpool, strplmapsize, txtlinbuf, cliplinbuf, strpoolmap
byte cursx, cursy, scrnleft, curscol, underchr, curschr word cursx, cursy, scrnleft, curscol
byte underchr, curschr
word keyin, cursrow, selrow, scrntop, cursptr word keyin, cursrow, selrow, scrntop, cursptr
byte a3echo = $80 byte a3echo = $80
byte a3noecho = $00 byte a3noecho = $00
@@ -262,7 +264,7 @@ def striptail(strptr, chr)#0
end end
def strstripcpy(dststr, srcstr)#0 def strstripcpy(dststr, srcstr)#0
memcpy(dststr, srcstr, ^srcstr + 1) memcpy(dststr, srcstr, ^srcstr + 1)
striptail(dststr, $80 | ' ') striptail(dststr, keyspace)
end end
def delstr(strptr)#0 def delstr(strptr)#0
byte mask, ofst byte mask, ofst
@@ -280,7 +282,7 @@ def newstr(strptr)
word newptr word newptr
strlen = ^strptr strlen = ^strptr
while ^(strptr + strlen) == $8D or ^(strptr + strlen) == $A0 while ^(strptr + strlen) == keyenter or ^(strptr + strlen) == keyspace
strlen-- strlen--
loop loop
if strlen == 0 if strlen == 0
@@ -484,7 +486,8 @@ def drawgutter(scrnrow, ofst)#0
// //
// Draw line numbers and gutter hilites // Draw line numbers and gutter hilites
// //
ofstch = ofst ?? $80 | '<' :: $80 | ' ' //ofstch = ofst ?? $80 | '<' :: keyspace
ofstch = ofst ?? '<' :: ' '
huns, tens = divmod(scrnrow + 1, 100) huns, tens = divmod(scrnrow + 1, 100)
tens, ones = divmod(tens, 10) tens, ones = divmod(tens, 10)
for row = 0 to 23 for row = 0 to 23
@@ -619,6 +622,44 @@ def redraw#0
drawscrn(scrntop, scrnleft) drawscrn(scrntop, scrnleft)
curson curson
end end
def curshpos(hpos)#1
byte needredraw
needredraw = TRUE
if hpos < 0; hpos = 0; fin
if hpos > MAXLNLEN; hpos = MAXLNLEN; fin
curscol = hpos
cursx = curscol - scrnleft
if cursx > scrnwidth
cursx = scrnwidth
scrnleft = curscol - scrnwidth
elsif cursx < 0
cursx = 0
scrnleft = curscol
else
needredraw = FALSE
fin
return needredraw
end
def cursvpos(vpos)#1
byte needredraw
needredraw = TRUE
if vpos < 0; vpos = 0; fin
if vpos > numlines - 1; vpos = numlines - 1; fin
cursrow = vpos
cursy = cursrow - scrntop
if cursy > scrnheight
cursy = scrnheight
scrntop = cursrow - scrnheight
elsif cursy < 0
cursy = 0
scrntop = cursrow
else
needredraw = FALSE
fin
return needredraw
end
def curshome#0 def curshome#0
cursoff cursoff
cursrow = 0 cursrow = 0
@@ -664,11 +705,15 @@ def cursup#0
fin fin
end end
def pgup#0 def pgup#0
byte i cursoff
if cursvpos(cursrow - pgjmp)
for i = 0 to pgjmp drawscrn(scrntop, scrnleft)
cursup else
next if flags & selection
drawgutter(scrntop, scrnleft)
fin
fin
curson
end end
def cursdown#0 def cursdown#0
if cursrow < numlines - 1 if cursrow < numlines - 1
@@ -687,11 +732,15 @@ def cursdown#0
fin fin
end end
def pgdown#0 def pgdown#0
byte i cursoff
if cursvpos(cursrow + pgjmp)
for i = 0 to pgjmp drawscrn(scrntop, scrnleft)
cursdown else
next if flags & selection
drawgutter(scrntop, scrnleft)
fin
fin
curson
end end
def cursleft#0 def cursleft#0
if curscol > 0 if curscol > 0
@@ -707,11 +756,15 @@ def cursleft#0
fin fin
end end
def pgleft#0 def pgleft#0
byte i cursoff
if curshpos(curscol - 8)
for i = 0 to 7 drawscrn(scrntop, scrnleft)
cursleft else
next if flags & selection
drawgutter(scrntop, scrnleft)
fin
fin
curson
end end
def cursright#0 def cursright#0
if curscol < MAXLNLEN if curscol < MAXLNLEN
@@ -727,43 +780,21 @@ def cursright#0
fin fin
end end
def pgright#0 def pgright#0
byte i cursoff
if curshpos(curscol + 8)
for i = 0 to 7 drawscrn(scrntop, scrnleft)
cursright else
next if flags & selection
end drawgutter(scrntop, scrnleft)
def curshpos(hpos)#0 fin
cursoff fin
curscol = hpos curson
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 end
// //
// Find string in text // Find string in text
// //
def findline(strptr)#1 def findline(strptr)#1
byte upstr[80], scan, i byte upstr[MAXLNLEN+1], scan, i
if ^strptr >= findstr if ^strptr >= findstr
lnupcpy(@upstr, strptr) lnupcpy(@upstr, strptr)
@@ -990,7 +1021,7 @@ end
// Printer routines // Printer routines
// //
def printtxt(slot)#0 def printtxt(slot)#0
byte txtbuf[80] byte txtbuf[MAXLNLEN+1]
word i, scrncsw word i, scrncsw
scrncsw = *csw scrncsw = *csw
@@ -1002,17 +1033,6 @@ def printtxt(slot)#0
next next
*csw = scrncsw *csw = scrncsw
end end
def openline(row)
if numlines < MAXLINES
memcpy(@txtlinbuf=>[row + 1], @txtlinbuf=>[row], (numlines - row) * 2)
txtlinbuf=>[row] = @nullstr
numlines++
flags = flags | changed
return TRUE
fin
bell
return FALSE
end
def freesel#0 def freesel#0
word i word i
@@ -1097,7 +1117,7 @@ def pastesel#0
fin fin
end end
def indentsel#0 def indentsel#0
byte indentstr[80], l byte indentstr[MAXLNLEN+1], l
word firstsel, lastsel, i word firstsel, lastsel, i
freesel freesel
@@ -1107,8 +1127,8 @@ def indentsel#0
if l < MAXLNLEN - 2 if l < MAXLNLEN - 2
memcpy(@indentstr + 3, txtlinbuf=>[i] + 1, l) memcpy(@indentstr + 3, txtlinbuf=>[i] + 1, l)
indentstr[0] = l + 2 indentstr[0] = l + 2
indentstr[1] = $A0 indentstr[1] = keyspace
indentstr[2] = $A0 indentstr[2] = keyspace
delstr(txtlinbuf=>[i]) delstr(txtlinbuf=>[i])
txtlinbuf=>[i] = newstr(@indentstr) txtlinbuf=>[i] = newstr(@indentstr)
flags = flags | changed flags = flags | changed
@@ -1117,7 +1137,7 @@ def indentsel#0
redraw redraw
end end
def undentsel#0 def undentsel#0
byte undentstr[80], l byte undentstr[MAXLNLEN+1], l
word firstsel, lastsel, i word firstsel, lastsel, i
freesel freesel
@@ -1126,10 +1146,10 @@ def undentsel#0
l = ^(txtlinbuf=>[i]) l = ^(txtlinbuf=>[i])
if l if l
memcpy(@undentstr + 1, txtlinbuf=>[i] + 1, l) memcpy(@undentstr + 1, txtlinbuf=>[i] + 1, l)
if undentstr[1] == $A0 if undentstr[1] == keyspace
memcpy(@undentstr + 1, @undentstr + 2, l - 1) memcpy(@undentstr + 1, @undentstr + 2, l - 1)
l-- l--
if l and undentstr[1] == $A0 if l and undentstr[1] == keyspace
memcpy(@undentstr + 1, @undentstr + 2, l - 1) memcpy(@undentstr + 1, @undentstr + 2, l - 1)
l-- l--
fin fin
@@ -1142,15 +1162,36 @@ def undentsel#0
next next
redraw redraw
end end
def autoindent(strptr)#0
byte i
for i = 1 to ^strptr
if ^(strptr + i) <> keyspace
break
fin
next
curshpos(i - 1)
end
def openline(row)
if numlines < MAXLINES
memcpy(@txtlinbuf=>[row + 1], @txtlinbuf=>[row], (numlines - row) * 2)
txtlinbuf=>[row] = @nullstr
numlines++
flags = flags | changed
return TRUE
fin
bell
return FALSE
end
def joinline#0 def joinline#0
byte joinstr[80], joinlen, stripjoin[80] byte joinstr[MAXLNLEN+1], joinlen, stripjoin[MAXLNLEN+1]
if cursrow < numlines - 1 if cursrow < numlines - 1
strstripcpy(@joinstr, txtlinbuf=>[cursrow]) strstripcpy(@joinstr, txtlinbuf=>[cursrow])
memcpy(@stripjoin, txtlinbuf=>[cursrow + 1], ^(txtlinbuf=>[cursrow + 1]) + 1) memcpy(@stripjoin, txtlinbuf=>[cursrow + 1], ^(txtlinbuf=>[cursrow + 1]) + 1)
striplead(@stripjoin, $80 | ' '); striplead(@stripjoin, keyspace);
joinlen = joinstr + stripjoin joinlen = joinstr + stripjoin
if joinlen < 80 if joinlen <= MAXLNLEN
curshpos(joinstr) curshpos(joinstr)
memcpy(@joinstr + joinstr + 1, @stripjoin + 1, stripjoin) memcpy(@joinstr + joinstr + 1, @stripjoin + 1, stripjoin)
joinstr = joinlen joinstr = joinlen
@@ -1160,14 +1201,13 @@ def joinline#0
numlines-- numlines--
memcpy(@txtlinbuf=>[cursrow + 1], @txtlinbuf=>[cursrow + 2], (numlines - cursrow) * 2) memcpy(@txtlinbuf=>[cursrow + 1], @txtlinbuf=>[cursrow + 2], (numlines - cursrow) * 2)
flags = flags | changed flags = flags | changed
redraw return
else
bell
fin fin
fin fin
bell
end end
def splitline#0 def splitline#0
byte splitstr[80], splitlen, i byte splitstr[MAXLNLEN+1], splitlen, i
if openline(cursrow + 1) if openline(cursrow + 1)
if curscol if curscol
@@ -1175,13 +1215,13 @@ def splitline#0
if curscol < splitlen - 1 if curscol < splitlen - 1
splitstr = splitlen - curscol splitstr = splitlen - curscol
memcpy(@splitstr + 1, txtlinbuf=>[cursrow] + curscol + 1, splitstr) memcpy(@splitstr + 1, txtlinbuf=>[cursrow] + curscol + 1, splitstr)
striplead(@splitstr, $80 | ' ') striplead(@splitstr, keyspace)
for i = 1 to curscol for i = 1 to curscol
if ^(txtlinbuf=>[cursrow] + i) <> $80 | ' ' if ^(txtlinbuf=>[cursrow] + i) <> keyspace
break break
fin fin
memcpy(@splitstr + 2, @splitstr + 1, splitstr) memcpy(@splitstr + 2, @splitstr + 1, splitstr)
splitstr[1] = $80 | ' ' splitstr[1] = keyspace
splitstr++ splitstr++
next next
txtlinbuf=>[cursrow + 1] = newstr(@splitstr) txtlinbuf=>[cursrow + 1] = newstr(@splitstr)
@@ -1193,7 +1233,7 @@ def splitline#0
else else
if splitlen > 0 if splitlen > 0
for curscol = 1 to splitlen - 1 for curscol = 1 to splitlen - 1
if ^(txtlinbuf=>[cursrow] + curscol) <> $80 | ' ' if ^(txtlinbuf=>[cursrow] + curscol) <> keyspace
break break
fin fin
next next
@@ -1204,8 +1244,6 @@ def splitline#0
txtlinbuf=>[cursrow + 1] = txtlinbuf=>[cursrow] txtlinbuf=>[cursrow + 1] = txtlinbuf=>[cursrow]
txtlinbuf=>[cursrow] = @nullstr txtlinbuf=>[cursrow] = @nullstr
fin fin
redraw
cursdown
fin fin
end end
def editkey(key) def editkey(key)
@@ -1215,12 +1253,13 @@ def editkey(key)
return FALSE return FALSE
end end
def editline(key) def editline(key)
byte editstr[80] byte editstr[MAXLNLEN+1], localchange, need
word undoline word undoline
localchange = FALSE
if (editkey(key)) if (editkey(key))
flags = flags | changed localchange = TRUE
memset(@editstr, $A0A0, 80) memset(@editstr + 1, $A0A0, MAXLNLEN)
strstripcpy(@editstr, txtlinbuf=>[cursrow]) strstripcpy(@editstr, txtlinbuf=>[cursrow])
undoline = txtlinbuf=>[cursrow] undoline = txtlinbuf=>[cursrow]
txtlinbuf=>[cursrow] = @editstr txtlinbuf=>[cursrow] = @editstr
@@ -1232,13 +1271,18 @@ def editline(key)
memcpy(@editstr[curscol], @editstr[curscol + 1], editstr - curscol) memcpy(@editstr[curscol], @editstr[curscol + 1], editstr - curscol)
editstr-- editstr--
fin fin
curshpos(curscol - 1) cursoff
if curshpos(curscol - 1)
drawscrn(scrntop, scrnleft)
else
drawrow(cursy, scrnleft, @editstr)
fin
curson curson
fin fin
elsif curscol < MAXLNLEN elsif curscol < MAXLNLEN
curshpos(curscol + 1) curscol++
if flags & insmode if flags & insmode
if editstr < MAXLNLEN or editstr.MAXLNLEN == $A0 if editstr < MAXLNLEN or editstr.MAXLNLEN == keyspace
editstr++ editstr++
if curscol >= editstr if curscol >= editstr
editstr = curscol editstr = curscol
@@ -1246,7 +1290,7 @@ def editline(key)
memcpy(@editstr[curscol + 1], @editstr[curscol], editstr - curscol) memcpy(@editstr[curscol + 1], @editstr[curscol], editstr - curscol)
fin fin
else else
curshpos(curscol - 1) curscol--
key = editstr[curscol] key = editstr[curscol]
bell bell
fin fin
@@ -1257,12 +1301,10 @@ def editline(key)
fin fin
editstr[curscol] = caseconv(key) editstr[curscol] = caseconv(key)
cursoff cursoff
if cursx <= scrnwidth if curshpos(curscol)
drawrow(cursy, scrnleft, @editstr)
else
scrnleft++
cursx = scrnwidth
drawscrn(scrntop, scrnleft) drawscrn(scrntop, scrnleft)
else
drawrow(cursy, scrnleft, @editstr)
fin fin
curson curson
else else
@@ -1282,15 +1324,21 @@ def editline(key)
cursoff cursoff
drawrow(cursy, scrnleft, @editstr) drawrow(cursy, scrnleft, @editstr)
curson curson
localchange = FALSE
fin fin
key = keyin() key = keyin()
until not editkey(key) until not editkey(key)
if editstr if localchange
txtlinbuf=>[cursrow] = newstr(@editstr) flags = flags | changed
else delstr(undoline)
txtlinbuf=>[cursrow] = @nullstr if editstr
fin txtlinbuf=>[cursrow] = newstr(@editstr)
delstr(undoline) else
txtlinbuf=>[cursrow] = @nullstr
fin
else
txtlinbuf=>[cursrow] = undoline
fin
fin fin
return key return key
end end
@@ -1343,6 +1391,11 @@ def editmode#0
cursdown cursdown
is keyctrlo is keyctrlo
openline(cursrow) openline(cursrow)
if cursrow
autoindent(txtlinbuf=>[cursrow - 1])
else
curshpos(0)
fin
redraw redraw
break break
is keyenter is keyenter
@@ -1350,12 +1403,15 @@ def editmode#0
splitline splitline
else else
openline(cursrow + 1) openline(cursrow + 1)
cursdown
redraw
fin fin
autoindent(txtlinbuf=>[cursrow])
cursvpos(cursrow + 1)
redraw
break break
is keyctrlt is keyctrlt
joinline; break joinline
redraw
break
is keyctrli is keyctrli
if flags & selection if flags & selection
if flags & insmode if flags & insmode