1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-08 22:30:48 +00:00

Add FALSE/TRUE constants and prep editor memory manager

This commit is contained in:
David Schmenk 2017-12-18 11:50:04 -08:00
parent 85bc86ab4c
commit e6fbdd5e68
7 changed files with 100 additions and 56 deletions

View File

@ -1,4 +1,12 @@
import cmdsys import cmdsys
//
// Useful values for everyone
//
const FALSE = 0
const TRUE = not FALSE
//
// Machine ID values
//
const MACHID_CLOCK = $01 const MACHID_CLOCK = $01
const MACHID_80COL = $02 const MACHID_80COL = $02
const MACHID_MEM = $03 const MACHID_MEM = $03

View File

@ -2,8 +2,6 @@ include "inc/cmdsys.plh"
// //
// Handy constants. // Handy constants.
// //
const FALSE = 0
const TRUE = !FALSE
const FULLMODE = 0 const FULLMODE = 0
const MIXMODE = 1 const MIXMODE = 1
// //

View File

@ -2,8 +2,6 @@ include "inc/cmdsys.plh"
// //
// Handy constants. // Handy constants.
// //
const FALSE=0
const TRUE=!FALSE
const FULLMODE=0 const FULLMODE=0
const MIXMODE=1 const MIXMODE=1
// //

View File

@ -11,9 +11,6 @@ import rogueio
word rnd, getkb, home, gotoxy, tone, open, read, close, newline word rnd, getkb, home, gotoxy, tone, open, read, close, newline
end end
const FALSE = 0
const TRUE = 1
// //
// Octant beam parameters // Octant beam parameters
// //

View File

@ -44,9 +44,6 @@ import rogueio
word rnd, getkb, home, gotoxy, tone word rnd, getkb, home, gotoxy, tone
end end
const FALSE = 0
const TRUE = not FALSE
const maxlight = 10 const maxlight = 10
const maxview = 19 const maxview = 19

View File

@ -1,7 +1,5 @@
include "inc/cmdsys.plh" include "inc/cmdsys.plh"
const FALSE = 0
const TRUE = !FALSE
const size = 8190 const size = 8190
const sizepl = size+1 const sizepl = size+1

View File

@ -7,8 +7,6 @@
include "inc/cmdsys.plh" include "inc/cmdsys.plh"
include "inc/args.plh" include "inc/args.plh"
include "inc/fileio.plh" include "inc/fileio.plh"
const FALSE = 0
const TRUE = not FALSE
// //
// Hardware constants // Hardware constants
// //
@ -58,9 +56,11 @@ const getbuff = $01FF
// //
// Data and text buffer constants // Data and text buffer constants
// //
const maxlines = 1500 const MAXLINES = 1500
const maxfill = 1524 const MAXLINESSIZE = MAXLINES+24
const maxlnlen = 79 const MAXLNLEN = 79
const MAXSTRPLSIZE = $8000 // $7000
//const STRPLMAPSIZE = 224 // $E0 = 28K is memory@16 bytes per bit map, 128 bytes per 8 bit map, 1K bytes per 8 byte map
const pgjmp = 16 const pgjmp = 16
const changed = 1 const changed = 1
const insmode = 2 const insmode = 2
@ -78,16 +78,14 @@ word = $0450,$04D0,$0550,$05D0,$0650,$06D0,$0750,$07D0
// //
byte nullstr = "" byte nullstr = ""
byte[64] txtfile = "UNTITLED" byte[64] txtfile = "UNTITLED"
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
byte exit = FALSE byte exit = FALSE
byte flags = 0 byte flags = 0
byte flash = 0 byte flash = 0
word numlines = 0 word numlines = 0
word cutbuf = 0 word cutbuf = 0
word strplsize = MAXSTRPLSIZE
word strplmapsize
word strlinbuf, strpoolmap, strpool
byte cursx, cursy, scrnleft, curscol, underchr, curschr byte cursx, cursy, scrnleft, curscol, underchr, curschr
word keyin, cursrow, scrntop, cursptr word keyin, cursrow, scrntop, cursptr
// //
@ -102,11 +100,12 @@ predef cmdmode#0
asm equates asm equates
!SOURCE "vmsrc/plvmzp.inc" !SOURCE "vmsrc/plvmzp.inc"
end end
asm clrhibit(strptr) asm clrhibit(strptr)#0
LDA ESTKL,X LDA ESTKL,X
STA SRCL STA SRCL
LDA ESTKH,X LDA ESTKH,X
STA SRCH STA SRCH
INX
LDY #$00 LDY #$00
LDA (SRC),Y LDA (SRC),Y
BEQ + BEQ +
@ -118,11 +117,12 @@ CLHILP LDA (SRC),Y
BNE CLHILP BNE CLHILP
+ RTS + RTS
end end
asm sethibit(strptr) asm sethibit(strptr)#0
LDA ESTKL,X LDA ESTKL,X
STA SRCL STA SRCL
LDA ESTKH,X LDA ESTKH,X
STA SRCH STA SRCH
INX
LDY #$00 LDY #$00
LDA (SRC),Y LDA (SRC),Y
BEQ + BEQ +
@ -134,7 +134,7 @@ STHILP LDA (SRC),Y
BNE STHILP BNE STHILP
+ RTS + RTS
end end
asm cpyln(srcstr, dststr) asm cpyln(srcstr, dststr)#0
LDA ESTKL,X LDA ESTKL,X
STA DSTL STA DSTL
LDA ESTKH,X LDA ESTKH,X
@ -144,6 +144,7 @@ asm cpyln(srcstr, dststr)
STA SRCL STA SRCL
LDA ESTKH,X LDA ESTKH,X
STA SRCH STA SRCH
INX
LDY #$00 LDY #$00
LDA (SRC),Y LDA (SRC),Y
TAY TAY
@ -165,31 +166,73 @@ CPLNLP LDA (SRC),Y
RTS RTS
end end
def bell def bell#0
putc($07) putc($07)
end end
// //
// Memory management routines // Memory management routines
// //
def strcpy(dststr, srcstr) def sizemask(size)
if size <= 16
return $01
elsif size <= 32
return $03
elsif size <= 48
return $07
elsif size <= 64
return $0F
elsif size <= 80
return $1F
fin
return 0
end
def strpoolalloc(size)
byte szmask, i
word mapmask, addr
szmask = sizemask(size)
for i = strplmapsize - 1 downto 0
if ^(strpoolmap + i) <> $FF
mapmask = szmask
repeat
if ^(strpoolmap + i) & mapmask
mapmask = mapmask << 1
else
^(strpoolmap + i) = ^(strpoolmap + i) | mapmask
addr = (i << 7) + strpool
while !(mapmask & 1)
addr = addr + 16
mapmask = mapmask >> 1
loop
return addr
fin
until mapmask & $100
fin
next
bell()
puts("OUT OF MEMORY!")
return 0
end
def strcpy(dststr, srcstr)#0
byte strlen byte strlen
strlen = ^srcstr strlen = ^srcstr
while (srcstr).[strlen] == $8D or (srcstr).[strlen] == $A0 while ^(srcstr + strlen) == $8D or ^(srcstr + strlen) == $A0
strlen-- strlen--
loop loop
^dststr = strlen ^dststr = strlen
memcpy(dststr + 1, srcstr + 1, strlen) memcpy(dststr + 1, srcstr + 1, strlen)
end end
def delstr(strptr) def delstr(strptr)#0
byte mask, ofst byte mask, ofst
if strptr and strptr <> @nullstr if strptr and strptr <> @nullstr
// mask = sizemask(^strptr + 1) mask = sizemask(^strptr + 1)
// ofst = (strptr - strheap) >> 4 ofst = (strptr - strpool) >> 4
// mask = mask << (ofst & $07) mask = mask << (ofst & $07)
// ofst = ofst >> 3 ofst = ofst >> 3
// strpoolmap->[ofst] = strpoolmap->[ofst] & ~mask ^(strpoolmap + ofst) = ^(strpoolmap + ofst) & ~mask
fin fin
end end
def newstr(strptr) def newstr(strptr)
@ -197,30 +240,35 @@ def newstr(strptr)
word newptr word newptr
strlen = ^strptr strlen = ^strptr
while (strptr).[strlen] == $8D or (strptr).[strlen] == $A0 while ^(strptr + strlen) == $8D or ^(strptr + strlen) == $A0
strlen-- strlen--
loop loop
if strlen == 0 if strlen == 0
return @nullstr return @nullstr
fin fin
// newptr = strpoolalloc(strlen + 1) newptr = strpoolalloc(strlen + 1)
// if newptr if newptr
// memcpy(newptr, strptr, strlen + 1) memcpy(newptr, strptr, strlen + 1)
// ^newptr = strlen ^newptr = strlen
// return newptr return newptr
// fin fin
return @nullstr return @nullstr
end end
def inittxtbuf#0 def inittxtbuf#0
word i word i
// strlinbuf = $1000 strlinbuf = heapalloc(MAXLINESSIZE*2)
// strpoolmap = $1F00 memset(strlinbuf, MAXLINESSIZE*2, @nullstr)
// strpoolmsz = 224 // $E0 = 28K is memory@16 bytes per bit map, 128 bytes per 8 bit map, 1K bytes per 8 byte map while isult(heapavail, strplsize)
// strpool = $4800 strplsize = strplsize - 4096
// strpoolsz = $7000 loop
// memset(strpoolmap, strheapmsz, 0) if isult(heapavail - strplsize, 4096) // Keep at least 4096 free
// memset(strlinbuf, maxfill * 2, @nullstr) strplsize = strplsize - 4096
fin
strplmapsize = strplsize / 128
strpoolmap = heapalloc(strplmapsize)
strpool = heapalloc(strplsize)
memset(strpoolmap, strplmapsize, 0)
numlines = 1 numlines = 1
cursrow = 0 cursrow = 0
curscol = 0 curscol = 0
@ -316,7 +364,7 @@ def readtxt(filename)#0
if refnum if refnum
newline(refnum, $7F, $0D) newline(refnum, $7F, $0D)
repeat repeat
txtbuf = fileio:read(refnum, @txtbuf + 1, maxlnlen) txtbuf = fileio:read(refnum, @txtbuf + 1, MAXLNLEN)
if txtbuf if txtbuf
sethibit(@txtbuf) sethibit(@txtbuf)
if flags & uppercase; strupper(@txtbuf); fin if flags & uppercase; strupper(@txtbuf); fin
@ -324,12 +372,12 @@ def readtxt(filename)#0
numlines++ numlines++
fin fin
if !(numlines & $0F); putc('.'); fin if !(numlines & $0F); putc('.'); fin
until txtbuf == 0 or numlines == maxlines until txtbuf == 0 or numlines == MAXLINES
fileio:close(refnum) fileio:close(refnum)
// //
// Make sure there is a blank line at the end of the buffer // Make sure there is a blank line at the end of the buffer
// //
if numlines < maxlines and strlinbuf:[numlines - 1] <> @nullstr if numlines < MAXLINES and strlinbuf:[numlines - 1] <> @nullstr
strlinbuf:[numlines] = @nullstr strlinbuf:[numlines] = @nullstr
numlines++ numlines++
fin fin
@ -620,7 +668,7 @@ def printtxt(slot)#0
*csw = scrncsw *csw = scrncsw
end end
def openline(row) def openline(row)
if numlines < maxlines if numlines < MAXLINES
memcpy(@strlinbuf:[row + 1], @strlinbuf:[row], (numlines - row) * 2) memcpy(@strlinbuf:[row + 1], @strlinbuf:[row], (numlines - row) * 2)
strlinbuf:[row] = @nullstr strlinbuf:[row] = @nullstr
numlines++ numlines++
@ -644,7 +692,7 @@ def cutline#0
redraw redraw
end end
def pasteline#0 def pasteline#0
if cutbuf and numlines < maxlines if cutbuf and numlines < MAXLINES
memcpy(@strlinbuf:[cursrow + 1], @strlinbuf:[cursrow], (numlines - cursrow) * 2) memcpy(@strlinbuf:[cursrow + 1], @strlinbuf:[cursrow], (numlines - cursrow) * 2)
strlinbuf:[cursrow] = newstr(cutbuf) strlinbuf:[cursrow] = newstr(cutbuf)
numlines++ numlines++
@ -742,11 +790,11 @@ def editline(key)
fin fin
curson curson
fin fin
elsif curscol < maxlnlen elsif curscol < MAXLNLEN
curscol++ curscol++
cursx++ cursx++
if flags & insmode if flags & insmode
if editstr < maxlnlen or editstr.maxlnlen == $A0 if editstr < MAXLNLEN or editstr.MAXLNLEN == $A0
editstr++ editstr++
if curscol >= editstr if curscol >= editstr
editstr = curscol editstr = curscol
@ -831,7 +879,7 @@ def editmode#0
is keyctrlv is keyctrlv
pasteline; break pasteline; break
is keyctrlf is keyctrlf
if numlines < maxlines and cursrow == numlines - 1 if numlines < MAXLINES and cursrow == numlines - 1
strlinbuf:[numlines] = @nullstr strlinbuf:[numlines] = @nullstr
numlines++ numlines++
fin fin