Text formatting clean-up

This commit is contained in:
David Schmenk 2017-12-17 13:55:29 -08:00
parent 6c0147819c
commit 5fe534f6b1
3 changed files with 147 additions and 151 deletions

View File

@ -79,7 +79,7 @@ word strlinbuf = $1000
word strpoolmap = $1F00
word strpoolmsz = 224 // $E0 = 28K is memory@16 bytes per bit map, 128 bytes per 8 bit map, 1K bytes per 8 byte map
word strpool = $4800
word strpoolsz = $7000
word strpoolsz = $7000
byte flags = 0
byte flash = 0
word numlines = 0
@ -96,7 +96,7 @@ predef cmdmode
// Defines for ASM routines
//
asm equates
!SOURCE "vmsrc/plvmzp.inc"
!SOURCE "vmsrc/plvmzp.inc"
end
//def toupper(c)
// if c >= 'a'
@ -217,7 +217,7 @@ def newstr(strptr)
strlen = ^strptr
while (strptr).[strlen] == $8D or (strptr).[strlen] == $A0
strlen = strlen - 1
strlen--
loop
if strlen == 0
return @nullstr
@ -238,7 +238,6 @@ def inittxtbuf#0
strpoolmsz = 224 // $E0 = 28K is memory@16 bytes per bit map, 128 bytes per 8 bit map, 1K bytes per 8 byte map
strpool = $4800
strpoolsz = $7000
memset(strpoolmap, strheapmsz, 0)
memset(strlinbuf, maxfill * 2, @nullstr)
numlines = 1
@ -297,14 +296,6 @@ def txtlower#0
strlower(strlinbuf:[i])
next
end
def prbyte(h)#0
cout('$')
call($FDDA, h, 0, 0, 0)
end
def prword(h)#0
cout('$')
call($F941, h >> 8, h, 0, 0)
end
def print(i)#0
byte numstr[7]
byte place, sign
@ -319,13 +310,13 @@ def print(i)#0
while i >= 10
numstr[place] = i % 10 + '0'
i = i / 10
place = place - 1
place--
loop
numstr[place] = i + '0'
place = place - 1
place--
if sign
numstr[place] = '-'
place = place - 1
place--
fin
numstr[place] = 6 - place
puts(@numstr[place])
@ -340,27 +331,27 @@ end
def readtxt(filename)#0
byte txtbuf[81], refnum, i, j
refnum = open(filename, sysbuf)
refnum = fileio:open(filename)
if refnum
newline(refnum, $7F, $0D)
repeat
txtbuf = read(refnum, @txtbuf + 1, maxlnlen)
txtbuf = fileio:read(refnum, @txtbuf + 1, maxlnlen)
if txtbuf
sethibit(@txtbuf)
if flags & uppercase; strupper(@txtbuf); fin
strlinbuf:[numlines] = newstr(@txtbuf)
numlines = numlines + 1
numlines++
fin
if !(numlines & $0F); cout('.'); fin
until txtbuf == 0 or numlines == maxlines
close(refnum)
//
// Make sure there is a blank line at the end of the buffer
//
if numlines < maxlines and strlinbuf:[numlines - 1] <> @nullstr
strlinbuf:[numlines] = @nullstr
numlines = numlines + 1
fin
fileio:close(refnum)
//
// Make sure there is a blank line at the end of the buffer
//
if numlines < maxlines and strlinbuf:[numlines - 1] <> @nullstr
strlinbuf:[numlines] = @nullstr
numlines++
fin
fin
end
def writetxt(filename)#0
@ -368,9 +359,9 @@ def writetxt(filename)#0
byte j, chr
word i, strptr
destroy(filename)
create(filename, $C3, $04, $00) // full access, TXT file
refnum = open(filename, sysbuf)
fileio:destroy(filename)
fileio:create(filename, $04, $00) // full access, TXT file
refnum = fileio:open(filename)
if refnum == 0
return
fin
@ -385,15 +376,15 @@ def writetxt(filename)#0
cpyln(strlinbuf:[i], @txtbuf)
txtbuf = txtbuf + 1
txtbuf[txtbuf] = $0D
write(refnum, @txtbuf + 1, txtbuf)
fileio:write(refnum, @txtbuf + 1, txtbuf)
if !(i & $0F); cout('.'); fin
next
close(refnum)
fileio:close(refnum)
end
//
// Screen routines
//
def clrscrn@0
def clrscrn#0
call($FC58, 0, 0, 0, 0)
end
def drawrow(row, ofst, strptr)#0
@ -420,30 +411,30 @@ def drawscrn(toprow, ofst)#0
if ofst
for row = 0 to 23
strptr = strlinbuf:[toprow + row]
scrnptr = txtscrn[row]
if ofst >= ^strptr
numchars = 0
else
scrnptr = txtscrn[row]
if ofst >= ^strptr
numchars = 0
else
numchars = ^strptr - ofst
fin
if numchars >= 40
fin
if numchars >= 40
numchars = 40
else
memset(scrnptr + numchars, 40 - numchars, $A0A0)
fin
memcpy(scrnptr, strptr + ofst + 1, numchars)
else
memset(scrnptr + numchars, 40 - numchars, $A0A0)
fin
memcpy(scrnptr, strptr + ofst + 1, numchars)
next
else
for row = 0 to 23
strptr = strlinbuf:[toprow + row]
scrnptr = txtscrn[row]
numchars = ^strptr
if numchars >= 40
scrnptr = txtscrn[row]
numchars = ^strptr
if numchars >= 40
numchars = 40
else
memset(scrnptr + numchars, 40 - numchars, $A0A0)
fin
memcpy(scrnptr, strptr + 1, numchars)
else
memset(scrnptr + numchars, 40 - numchars, $A0A0)
fin
memcpy(scrnptr, strptr + 1, numchars)
next
fin
end
@ -507,9 +498,9 @@ end
def cursup#0
if cursrow > 0
cursoff
cursrow = cursrow - 1
cursrow--
if cursy > 0
cursy = cursy - 1
cursy--
else
scrntop = cursrow
drawscrn(scrntop, scrnleft)
@ -527,9 +518,9 @@ end
def cursdown#0
if cursrow < numlines - 1
cursoff
cursrow = cursrow + 1
cursrow++
if cursy < 23
cursy = cursy + 1
cursy++
else
scrntop = cursrow - 23
drawscrn(scrntop, scrnleft)
@ -547,9 +538,9 @@ end
def cursleft#0
if curscol > 0
cursoff
curscol = curscol - 1
curscol--
if cursx > 0
cursx = cursx - 1
cursx--
else
scrnleft = curscol
drawscrn(scrntop, scrnleft)
@ -567,9 +558,9 @@ end
def cursright#0
if curscol < 80
cursoff
curscol = curscol + 1
curscol++
if cursx < 39
cursx = cursx + 1
cursx++
else
scrnleft = curscol - 39
drawscrn(scrntop, scrnleft)
@ -651,7 +642,7 @@ def openline(row)
if numlines < maxlines
memcpy(@strlinbuf:[row + 1], @strlinbuf:[row], (numlines - row) * 2)
strlinbuf:[row] = @nullstr
numlines = numlines + 1
numlines++
flags = flags | changed
return TRUE
fin
@ -663,7 +654,7 @@ def cutline#0
cutbuf = strlinbuf:[cursrow]
memcpy(@strlinbuf:[cursrow], @strlinbuf:[cursrow + 1], (numlines - cursrow) * 2)
if numlines > 1
numlines = numlines - 1
numlines--
fin
flags = flags | changed
if cursrow == numlines
@ -675,7 +666,7 @@ def pasteline#0
if cutbuf and numlines < maxlines
memcpy(@strlinbuf:[cursrow + 1], @strlinbuf:[cursrow], (numlines - cursrow) * 2)
strlinbuf:[cursrow] = newstr(cutbuf)
numlines = numlines + 1
numlines++
flags = flags | changed
redraw
else
@ -694,7 +685,7 @@ def joinline#0
freestr(strlinbuf:[cursrow])
strlinbuf:[cursrow] = newstr(@joinstr)
freestr(strlinbuf:[cursrow + 1])
numlines = numlines - 1
numlines--
memcpy(@strlinbuf:[cursrow + 1], @strlinbuf:[cursrow + 2], (numlines - cursrow) * 2)
flags = flags | changed
redraw
@ -757,34 +748,34 @@ def editline(key)
if curscol > 0
if curscol <= editstr
memcpy(@editstr[curscol], @editstr[curscol + 1], editstr - curscol)
editstr = editstr - 1
editstr--
fin
curscol = curscol - 1
curscol--
cursoff
if cursx > 0
cursx = cursx - 1
cursx--
drawrow(cursy, scrnleft, @editstr)
else
scrnleft = scrnleft - 1
scrnleft--
drawscrn(scrntop, scrnleft)
fin
curson
fin
elsif curscol < maxlnlen
curscol = curscol + 1
cursx = cursx + 1
curscol++
cursx++
if flags & insmode
if editstr < maxlnlen or editstr.maxlnlen == $A0
editstr = editstr + 1
editstr++
if curscol >= editstr
editstr = curscol
else
memcpy(@editstr[curscol + 1], @editstr[curscol], editstr - curscol)
fin
else
curscol = curscol - 1
cursx = cursx - 1
key = editstr[curscol]
curscol--
cursx--
key = editstr[curscol]
bell
fin
else
@ -797,8 +788,8 @@ def editline(key)
if cursx <= 39
drawrow(cursy, scrnleft, @editstr)
else
scrnleft = scrnleft + 1
cursx = 39
scrnleft++
cursx = 39
drawscrn(scrntop, scrnleft)
fin
curson
@ -809,7 +800,7 @@ def editline(key)
if curscol < editstr
strcpy(undoline, @editstr)
memcpy(@editstr[curscol + 1], @editstr[curscol + 2], editstr - curscol)
editstr = editstr - 1
editstr--
cursoff
drawrow(cursy, scrnleft, @editstr)
curson
@ -859,15 +850,15 @@ def editmode#0
is keyctrlv
pasteline; break
is keyctrlf
if numlines < maxlines and cursrow == numlines - 1
if numlines < maxlines and cursrow == numlines - 1
strlinbuf:[numlines] = @nullstr
numlines = numlines + 1
fin
cursdown
numlines++
fin
cursdown
is keyctrlo
openline(cursrow)
redraw
break
break
is keyenter
if flags & insmode
splitline
@ -876,7 +867,7 @@ def editmode#0
cursdown
redraw
fin
break
break
is keyctrlt
joinline; break
is keyctrli
@ -887,7 +878,7 @@ def editmode#0
flags = flags | insmode
curschr = '+'
fin
break
break
is keyctrlc
if flags & uppercase
txtlower
@ -895,12 +886,12 @@ def editmode#0
txtupper
fin
redraw
break
break
is keyescape
cursoff
cmdmode
redraw
break
break
wend
until false
end
@ -944,12 +935,12 @@ def prfiles(optpath)
puts(entry)
if type & $F0 == $D0 // Is it a directory?
cout('/')
len = len + 1
len++
fin
for len = 20 - len downto 1
cout(' ')
next
filecnt = filecnt - 1
filecnt--
fin
entry = entry + entrylen
next
@ -965,7 +956,7 @@ end
def striplead(strptr, chr)#0
while ^strptr and ^(strptr + 1) == chr
memcpy(strptr + 1, strptr + 2, ^strptr)
^strptr = ^strptr - 1
^strptr--
loop
end
def parsecmd(strptr)
@ -976,7 +967,7 @@ def parsecmd(strptr)
if ^strptr
cmd = ^(strptr + 1)
memcpy(strptr + 1, strptr + 2, ^strptr)
^strptr = ^strptr - 1
^strptr--
fin
if ^strptr
striplead(strptr, ' ')
@ -999,7 +990,7 @@ def quit#0
exit
fin
end
def cmdmode
def cmdmode#0
byte slot
word cmdptr
@ -1013,17 +1004,17 @@ def cmdmode
is 'A'
readtxt(cmdptr)
flags = flags | changed
break
break
is 'R'
if chkchng
inittxtbuf
numlines = 0
numlines = 0
strcpy(@txtfile, cmdptr)
readtxt(@txtfile)
if numlines == 0; numlines = 1; fin
if numlines == 0; numlines = 1; fin
flags = flags & ~changed
fin
break
break
is 'W'
if ^cmdptr
strcpy(@txtfile, cmdptr)
@ -1031,7 +1022,7 @@ def cmdmode
writetxt(@txtfile)
//if flags & changed; fin
flags = flags & ~changed
break
break
is 'C'
prfiles(cmdptr); break
is 'P'
@ -1043,7 +1034,7 @@ def cmdmode
slot = 1
fin
printtxt(slot)
break
break
is 'Q'
quit
is 'E'
@ -1054,7 +1045,7 @@ def cmdmode
inittxtbuf
strcpy(@txtfile, "UNTITLED")
fin
break
break
otherwise
bell
cout('?')

View File

@ -2024,7 +2024,7 @@ end
//
def emit_byte(bval)#0
^codeptr = bval
codeptr = codeptr + 1
codeptr++
end
def emit_word(wval)#0
*codeptr = wval
@ -2087,14 +2087,14 @@ def emit_data(vartype, consttype, constval, constsize)
size = constsize
emit_fill(constsize)
elsif consttype == STR_TYPE
size = constsize
chrptr = constval
constsize = constsize - 1
size = constsize
chrptr = constval
constsize--
emit_byte(constsize)
while constsize > 0
emit_byte(^chrptr)
chrptr = chrptr + 1
constsize = constsize - 1
chrptr++
constsize--
loop
else
if vartype & BYTE_TYPE
@ -2105,7 +2105,7 @@ def emit_data(vartype, consttype, constval, constsize)
if consttype == CONSTADDR_TYPE
emit_addr(constval)
else
emit_word(constval)
emit_word(constval)
fin
fin
fin
@ -2375,9 +2375,9 @@ def emit_drop#0
end
def emit_leave#0
if framesize
emit_op($5A)
emit_op($5A)
else
emit_op($5C)
emit_op($5C)
fin
end
def emit_enter(cparams)#0
@ -2408,7 +2408,7 @@ def idmatch(nameptr, len, idptr, idcnt)
fin
fin
idptr = idptr + idptr->idname + idrecsz
idcnt = idcnt - 1
idcnt--
loop
return 0
end
@ -2431,7 +2431,7 @@ def dumpsym(idptr, idcnt)#0
fin
crout
idptr = idptr + idptr->idname + idrecsz
idcnt = idcnt - 1
idcnt--
loop
end
def id_lookup(nameptr, len)
@ -2455,7 +2455,7 @@ def idlocal_add(namestr, len, type, size)
lastlocal=>idval = framesize
lastlocal->idtype = type | LOCAL_TYPE
nametostr(namestr, len, lastlocal + idname)
locals = locals + 1
locals++
lastlocal = lastlocal + idrecsz + len
if lastlocal > idlocal_tbl + idlocal_tblsz
prstr(@local_sym_overflw)
@ -2463,8 +2463,7 @@ def idlocal_add(namestr, len, type, size)
fin
framesize = framesize + size
if framesize > 255
prstr(@local_overflw)
return FALSE
return parse_err(@local_overflw)
fin
return TRUE
end
@ -2474,7 +2473,7 @@ def iddata_add(namestr, len, type, size)
lastglobal->idtype = type
nametostr(namestr, len, lastglobal + idname)
emit_iddata(datasize, size, lastglobal + idname)
globals = globals + 1
globals++
lastglobal = lastglobal + idrecsz + len
if lastglobal > idglobal_tbl + idglobal_tblsz
prstr(@global_sym_overflw)
@ -2496,7 +2495,7 @@ def idglobal_add(namestr, len, type, value)
lastglobal=>idval = value
lastglobal->idtype = type
nametostr(namestr, len, lastglobal + idname)
globals = globals + 1
globals++
lastglobal = lastglobal + idrecsz + len
if lastglobal > idglobal_tbl + idglobal_tblsz
prstr(@global_sym_overflw)
@ -2639,7 +2638,7 @@ def pop_val(valptr, sizeptr, typeptr)
^sizeptr = sizestack[valsp]
^typeptr = typestack[valsp]
valsp--
return valsp + 1
return valsp + 1
end
//
// Lexical anaylzer
@ -2878,16 +2877,12 @@ def nextln
cpyln(strlinbuf:[lineno], instr)
lineno++
if !(lineno & $0F); cout('.'); fin
print(lineno);cout(':');print(numlines)
cout('>')
prstr(instr)
crout
//print(lineno);cout(':');print(numlines);cout('>');prstr(instr);crout
scan
else
cout('<')
crout
^instr = 0
^inbuff = 0
//cout('<');crout
*instr = 0
//^inbuff = 0
token = DONE_TKN
fin
fin
@ -2973,7 +2968,7 @@ def parse_constval
when token
is SUB_TKN
mod = mod | 1; break
is ALT_COMP_TKN
is ALT_COMP_TKN
is COMP_TKN
mod = mod | 2; break
is LOGIC_NOT_TKN
@ -3012,7 +3007,7 @@ def parse_constval
if !idptr; return parse_err(@bad_cnst); fin
type = idptr->idtype
if type & ADDR_TYPE
if mod <> 8; return parse_err(@bad_cnst); fin
if mod <> 8; return parse_err(@bad_cnst); fin
type = CONSTADDR_TYPE
fin
value = idptr=>idval
@ -3139,20 +3134,20 @@ def parse_value(rvalue)
if deref
push_op(token, 0)
else
deref = deref + 1
type = type | BPTR_TYPE
deref++
type = type | BPTR_TYPE
fin
break
is WPTR_TKN
if deref
push_op(token, 0)
else
deref = deref + 1
type = type | WPTR_TYPE
deref++
type = type | WPTR_TYPE
fin
break
is AT_TKN
deref = deref - 1
deref--
break
is SUB_TKN
is ALT_COMP_TKN
@ -3184,14 +3179,14 @@ def parse_value(rvalue)
// type = type | WORD_TYPE
emit_val = TRUE
break
is STR_TKN
//
// Special case
//
emit_constr(constval, tknlen - 1)
scan
return WORD_TYPE
break
is STR_TKN
//
// Special case
//
emit_constr(constval, tknlen - 1)
scan
return WORD_TYPE
break
otherwise
return 0
wend
@ -3205,16 +3200,16 @@ def parse_value(rvalue)
is NEG_TKN
pop_op
value = -value
break
break
is ALT_COMP_TKN
is COMP_TKN
pop_op
value = ~value
break
break
is LOGIC_NOT_TKN
pop_op
value = !value
break
break
otherwise
cparams = FALSE
wend
@ -3238,7 +3233,8 @@ def parse_value(rvalue)
ref_offset = 0
fin
if ref_type & BPTR_TYPE; emit_lb
elsif ref_type & WPTR_TYPE; emit_lw; fin
elsif ref_type & WPTR_TYPE; emit_lw
fin
if lookahead <> CLOSE_PAREN_TKN
emit_push
fin
@ -3847,7 +3843,7 @@ def parse_var(type)
byte consttype, constsize, idlen
word idptr, constval, arraysize, size
cout('T')
//cout('T')
idlen = 0
size = 1
if scan == OPEN_BRACKET_TKN
@ -3903,7 +3899,7 @@ def parse_struc
byte type, idlen, struclen, constsize
word size, offset, idstr
cout('S')
//cout('S')
struclen = 0
if scan == ID_TKN
struclen = tknlen
@ -3959,7 +3955,7 @@ def parse_vars
byte idlen, type, size
word value, idptr
cout('V')
//cout('V')
when token
is CONST_TKN
if scan <> ID_TKN
@ -4012,7 +4008,7 @@ def parse_defs
word func_tag, idptr
if token == DEF_TKN
cout('D')
//cout('D')
if scan <> ID_TKN; return parse_err(@bad_decl); fin
cfnparms = 0
infunc = TRUE
@ -4028,12 +4024,12 @@ def parse_defs
idlocal_init
if scan == OPEN_PAREN_TKN
repeat
if scan == ID_TKN
cfnparms = cfnparms + 1
idlocal_add(tknptr, tknlen, WORD_TYPE, 2)
scan
fin
until token <> COMMA_TKN
if scan == ID_TKN
cfnparms = cfnparms + 1
idlocal_add(tknptr, tknlen, WORD_TYPE, 2)
scan
fin
until token <> COMMA_TKN
if token <> CLOSE_PAREN_TKN
return parse_err(@bad_decl)
fin
@ -4070,7 +4066,7 @@ def parse_module
while parse_defs
nextln
loop
cout('I')
//cout('I')
framesize = 0
entrypoint = codeptr
emit_enter(0)
@ -4080,7 +4076,7 @@ def parse_module
nextln
loop
fin
cout('!')
//cout('!')
if prevstmnt <> RETURN_TKN
emit_const(0)
emit_leave

View File

@ -0,0 +1,9 @@
# Filetype extension configuration file for Geany
# Insert as many items as you want, separate them with a ";".
# See Geany's main documentation for details.
[Extensions]
PLASMA=*.pla;*.plh;
# Note: restarting is required after editing groups
[Groups]
Programming=PLASMA;