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

module load memory improvements and some nice optimizaions from

peterferrie
This commit is contained in:
David Schmenk 2014-06-11 19:43:43 -07:00
parent bd258a8b14
commit 5118b70b30
3 changed files with 130 additions and 107 deletions

View File

@ -19,25 +19,25 @@ predef syscall, call
predef markheap, allocheap, allocalignheap, releaseheap, availheap predef markheap, allocheap, allocalignheap, releaseheap, availheap
predef memset, memcpy predef memset, memcpy
predef uword_isgt, uword_isge, uword_islt, uword_isle predef uword_isgt, uword_isge, uword_islt, uword_isle
predef loadmod, execmod predef loadmod, execmod, lookupmod
; ;
; Exported Machine ID. ; System variables.
;
byte machid = $08 ; Apple 1 (NA in ProDOS Tech Ref)
;
; System variable.
; ;
word version = $0010 ; 00.10
word systemflags = 0 word systemflags = 0
word heap word heap
word symtbl, lastsym word symtbl, lastsym
byte perr byte perr
word cmdptr word cmdptr
; ;
; Exported Machine ID.
;
byte machid = $08 ; Apple 1 (NA in ProDOS Tech Ref)
;
; Standard Library exported functions. ; Standard Library exported functions.
; ;
byte stdlibstr[] = "STDLIB" byte stdlibstr[] = "STDLIB"
byte machidstr[] = "MACHID" byte machidstr[] = "MACHID"
byte sysvarstr[] = "SYSVARS"
byte putcstr[] = "PUTC" byte putcstr[] = "PUTC"
byte putlnstr[] = "PUTLN" byte putlnstr[] = "PUTLN"
byte putsstr[] = "PUTS" byte putsstr[] = "PUTS"
@ -56,8 +56,9 @@ byte uisgtstr[] = "ISUGT"
byte uisgestr[] = "ISUGE" byte uisgestr[] = "ISUGE"
byte uisltstr[] = "ISULT" byte uisltstr[] = "ISULT"
byte uislestr[] = "ISULE" byte uislestr[] = "ISULE"
byte loadstr[] = "LOAD" byte loadstr[] = "MODLOAD"
byte execstr[] = "EXEC" byte execstr[] = "MODEXEC"
byte modadrstr[] = "MODADDR"
word exports[] = @sysstr, @syscall word exports[] = @sysstr, @syscall
word = @callstr, @call word = @callstr, @call
word = @putcstr, @cout word = @putcstr, @cout
@ -77,15 +78,15 @@ word = @uisltstr, @uword_islt
word = @uislestr, @uword_isle word = @uislestr, @uword_isle
word = @loadstr, @loadmod word = @loadstr, @loadmod
word = @execstr, @execmod word = @execstr, @execmod
word = @modadrstr, @lookupmod
word = @machidstr, @machid word = @machidstr, @machid
word = @sysvarstr, @systemflags
word = 0 word = 0
word stdlibsym = @exports word stdlibsym = @exports
; ;
; String pool. ; String pool.
; ;
byte autorun[] = "AUTORUN" byte autorun[] = "AUTORUN"
byte version[] = "\nPLASMA 0.9\n" byte verstr[] = "\nPLASMA "
byte freestr[] = "MEM FREE:$" byte freestr[] = "MEM FREE:$"
byte errorstr[] = "ERR:$" byte errorstr[] = "ERR:$"
byte prompt[] = "PLASMA" byte prompt[] = "PLASMA"
@ -292,28 +293,26 @@ asm uword_isle
RTS RTS
end end
asm uword_isgt asm uword_isgt
LDY #$FF
LDA ESTKL,X LDA ESTKL,X
CMP ESTKL+1,X CMP ESTKL+1,X
LDA ESTKH,X LDA ESTKH,X
SBC ESTKH+1,X SBC ESTKH+1,X
BCC + LDA #$FF
INY ADC #$00
+ STY ESTKL+1,X STA ESTKL+1,X
STY ESTKH+1,X STA ESTKH+1,X
INX INX
RTS RTS
end end
asm uword_islt asm uword_islt
LDY #$FF
LDA ESTKL+1,X LDA ESTKL+1,X
CMP ESTKL,X CMP ESTKL,X
LDA ESTKH+1,X LDA ESTKH+1,X
SBC ESTKH,X SBC ESTKH,X
BCC + LDA #$FF
INY ADC #$00
+ STY ESTKL+1,X STA ESTKL+1,X
STY ESTKH+1,X STA ESTKH+1,X
INX INX
RTS RTS
end end
@ -419,8 +418,7 @@ TOUPR AND #$7F
BCC + BCC +
CMP #'z'+1 CMP #'z'+1
BCS + BCS +
SEC SBC #$1F
SBC #$20
+ STA ESTKL,X + STA ESTKL,X
RTS RTS
end end
@ -812,6 +810,10 @@ def loadmod(mod)
modaddr = allocheap(modsize) modaddr = allocheap(modsize)
memcpy(modaddr, moddep, rdlen) memcpy(modaddr, moddep, rdlen)
; ;
; Add module to symbol table.
;
addmod(mod, modaddr)
;
; Apply all fixups and symbol import/export. ; Apply all fixups and symbol import/export.
; ;
modfix = modaddr - modfix modfix = modaddr - modfix
@ -889,8 +891,15 @@ def loadmod(mod)
; Call init routine if it exists. ; Call init routine if it exists.
; ;
if init if init
return adddef(init - defofst + bytecode, @deflast)() fixup = adddef(init - defofst + bytecode, @deflast)()
modend = init - defofst + bytecode
else
fixup = 0
fin fin
;
; Free up the end-of-module in main memory.
;
releaseheap(modend)
return 0 return 0
end end
; ;
@ -982,7 +991,6 @@ def execmod(modfile)
heap = saveheap heap = saveheap
fin fin
end end
; ;
; Get heap start. ; Get heap start.
; ;
@ -994,7 +1002,7 @@ symtbl = allocheap($200)
lastsym = symtbl lastsym = symtbl
^lastsym = 0 ^lastsym = 0
stodci(@stdlibstr, heap) stodci(@stdlibstr, heap)
addmod(heap, 1) addmod(heap, @systemflags)
while *stdlibsym while *stdlibsym
stodci((stdlibsym):0, heap) stodci((stdlibsym):0, heap)
addsym(heap, (stdlibsym):2) addsym(heap, (stdlibsym):2)
@ -1008,7 +1016,11 @@ perr = 0
; ;
; Print some startup info. ; Print some startup info.
; ;
prstr(@version) prstr(@verstr)
prbyte(version.1)
cout('.')
prbyte(version.0)
crout
prstr(@freestr) prstr(@freestr)
prword(availheap) prword(availheap)
crout crout

View File

@ -21,10 +21,11 @@ predef crout, cout, prstr, cin, rdstr
predef markheap, allocheap, allocalignheap, releaseheap, availheap predef markheap, allocheap, allocalignheap, releaseheap, availheap
predef memset, memcpy predef memset, memcpy
predef uword_isgt, uword_isge, uword_islt, uword_isle predef uword_isgt, uword_isge, uword_islt, uword_isle
predef loadmod, execmod predef loadmod, execmod, lookupmod
; ;
; System variable. ; System variable.
; ;
word version = $0010 ; 00.10
word systemflags = 0 word systemflags = 0
word heap word heap
word xheap = $0800 word xheap = $0800
@ -36,7 +37,6 @@ word cmdptr
; ;
byte stdlibstr[] = "STDLIB" byte stdlibstr[] = "STDLIB"
byte machidstr[] = "MACHID" byte machidstr[] = "MACHID"
byte sysvarstr[] = "SYSVARS"
byte sysstr[] = "SYSCALL" byte sysstr[] = "SYSCALL"
byte callstr[] = "CALL" byte callstr[] = "CALL"
byte putcstr[] = "PUTC" byte putcstr[] = "PUTC"
@ -55,8 +55,9 @@ byte uisgtstr[] = "ISUGT"
byte uisgestr[] = "ISUGE" byte uisgestr[] = "ISUGE"
byte uisltstr[] = "ISULT" byte uisltstr[] = "ISULT"
byte uislestr[] = "ISULE" byte uislestr[] = "ISULE"
byte loadstr[] = "LOAD" byte loadstr[] = "MODLOAD"
byte execstr[] = "EXEC" byte execstr[] = "MODEXEC"
byte modadrstr[] = "MODADDR"
word exports[] = @sysstr, @syscall word exports[] = @sysstr, @syscall
word = @callstr, @call word = @callstr, @call
word = @putcstr, @cout word = @putcstr, @cout
@ -76,15 +77,15 @@ word = @uisltstr, @uword_islt
word = @uislestr, @uword_isle word = @uislestr, @uword_isle
word = @loadstr, @loadmod word = @loadstr, @loadmod
word = @execstr, @execmod word = @execstr, @execmod
word = @modadrstr, @lookupmod
word = @machidstr, MACHID word = @machidstr, MACHID
word = @sysvarstr, @systemflags
word = 0 word = 0
word stdlibsym = @exports word stdlibsym = @exports
; ;
; String pool. ; String pool.
; ;
byte autorun[] = "AUTORUN" byte autorun[] = "AUTORUN"
byte version[] = "PLASMA 0.9\n" byte verstr[] = "PLASMA "
byte freestr[] = "MEM FREE:$" byte freestr[] = "MEM FREE:$"
byte errorstr[] = "ERR:$" byte errorstr[] = "ERR:$"
byte okstr[] = "OK" byte okstr[] = "OK"
@ -173,11 +174,11 @@ end
; CALL LOADED SYSTEM PROGRAM ; CALL LOADED SYSTEM PROGRAM
; ;
asm exec asm exec
LDA #$00 LDX #$00
STA IFPL STX IFPL
LDA #$BF LDA #$BF
STA IFPH STA IFPH
LDX #$FF DEX
TXS TXS
LDX #ESTKSZ/2 LDX #ESTKSZ/2
BIT ROMEN BIT ROMEN
@ -372,7 +373,6 @@ asm prstr
STA SRCL STA SRCL
LDA ESTKH,X LDA ESTKH,X
STA SRCH STA SRCH
STY ESTKH,X
LDA (SRC),Y LDA (SRC),Y
STA TMP STA TMP
BEQ ++ BEQ ++
@ -384,8 +384,7 @@ asm prstr
JSR TOUPR JSR TOUPR
+ ORA #$80 + ORA #$80
JSR $FDED JSR $FDED
TYA CPY TMP
CMP TMP
BNE - BNE -
BIT LCRDEN+LCBNK2 BIT LCRDEN+LCBNK2
++ RTS ++ RTS
@ -406,12 +405,11 @@ end
; PRINT WORD ; PRINT WORD
; ;
asm prword asm prword
LDA ESTKH,X STX ESP
TXA
TAY TAY
LDA ESTKL,X LDA ESTKH,Y
STX ESP LDX ESTKL,Y
TAX
TYA
BIT ROMEN BIT ROMEN
JSR $F941 JSR $F941
LDX ESP LDX ESP
@ -434,8 +432,8 @@ asm rdstr
STA $01FF,X STA $01FF,X
DEX DEX
BPL - BPL -
TXA
LDX ESP LDX ESP
LDA #$FF
STA ESTKL,X STA ESTKL,X
LDA #$01 LDA #$01
STA ESTKH,X STA ESTKH,X
@ -461,7 +459,7 @@ asm uword_isle
CMP ESTKL+1,X CMP ESTKL+1,X
LDA ESTKH,X LDA ESTKH,X
SBC ESTKH+1,X SBC ESTKH+1,X
BCC + BCC +
DEY DEY
+ STY ESTKL+1,X + STY ESTKL+1,X
STY ESTKH+1,X STY ESTKH+1,X
@ -469,28 +467,26 @@ asm uword_isle
RTS RTS
end end
asm uword_isgt asm uword_isgt
LDY #$FF
LDA ESTKL,X LDA ESTKL,X
CMP ESTKL+1,X CMP ESTKL+1,X
LDA ESTKH,X LDA ESTKH,X
SBC ESTKH+1,X SBC ESTKH+1,X
BCC + LDA #$FF
INY ADC #$00
+ STY ESTKL+1,X STA ESTKL+1,X
STY ESTKH+1,X STA ESTKH+1,X
INX INX
RTS RTS
end end
asm uword_islt asm uword_islt
LDY #$FF
LDA ESTKL+1,X LDA ESTKL+1,X
CMP ESTKL,X CMP ESTKL,X
LDA ESTKH+1,X LDA ESTKH+1,X
SBC ESTKH,X SBC ESTKH,X
BCC + LDA #$FF
INY ADC #$00
+ STY ESTKL+1,X STA ESTKL+1,X
STY ESTKH+1,X STA ESTKH+1,X
INX INX
RTS RTS
end end
@ -587,8 +583,7 @@ TOUPR AND #$7F
BCC + BCC +
CMP #'z'+1 CMP #'z'+1
BCS + BCS +
SEC SBC #$1F
SBC #$20
+ STA ESTKL,X + STA ESTKL,X
RTS RTS
end end
@ -823,16 +818,6 @@ def allocxheap(size)
fin fin
return xaddr return xaddr
end end
;def availxheap(void)
; return $BF00 - xheap;
;end
;def markxheap
; return xheap
;end
;def releasexheap(newxheap)
; xheap = newxheap;
; return $BF00 - xheap
;end
; ;
; DCI table routines, ; DCI table routines,
; ;
@ -1008,6 +993,10 @@ def loadmod(mod)
until rdlen <= 0 until rdlen <= 0
close(refnum) close(refnum)
; ;
; Add module to symbol table.
;
addmod(mod, modaddr)
;
; Apply all fixups and symbol import/export. ; Apply all fixups and symbol import/export.
; ;
modfix = modaddr - modfix modfix = modaddr - modfix
@ -1094,10 +1083,6 @@ def loadmod(mod)
; ;
memxcpy(defaddr, bytecode, modsize - (bytecode - modaddr)) memxcpy(defaddr, bytecode, modsize - (bytecode - modaddr))
fin fin
;
; Free up the end-of-module in main memory.
;
releaseheap(modend)
fin fin
if perr if perr
return -perr return -perr
@ -1106,9 +1091,20 @@ def loadmod(mod)
; Call init routine if it exists. ; Call init routine if it exists.
; ;
if init if init
return adddef(defbank, init - defofst + defaddr, @deflast)() fixup = adddef(defbank, init - defofst + defaddr, @deflast)()
if defbank
xheap = init - defofst + defaddr
else
modend = init - defofst + defaddr
fin
else
fixup = 0
fin fin
return 0 ;
; Free up the end-of-module in main memory.
;
releaseheap(modend)
return fixup
end end
; ;
; Command mode ; Command mode
@ -1288,7 +1284,6 @@ def execmod(modfile)
heap = saveheap heap = saveheap
fin fin
end end
; ;
; Get heap start. ; Get heap start.
; ;
@ -1297,7 +1292,7 @@ heap = *freemem
; Init symbol table. ; Init symbol table.
; ;
stodci(@stdlibstr, heap) stodci(@stdlibstr, heap)
addmod(heap, 1) addmod(heap, @systemflags)
while *stdlibsym while *stdlibsym
stodci((stdlibsym):0, heap) stodci((stdlibsym):0, heap)
addsym(heap, (stdlibsym):2) addsym(heap, (stdlibsym):2)
@ -1312,7 +1307,11 @@ perr = 0
; ;
; Print some startup info. ; Print some startup info.
; ;
prstr(@version) prstr(@verstr)
prbyte(version.1)
cout('.')
prbyte(version.0)
crout
prstr(@freestr) prstr(@freestr)
prword(availheap) prword(availheap)
crout crout

View File

@ -14,28 +14,29 @@ predef syscall, call
predef markheap, allocheap, allocalignheap, releaseheap, availheap predef markheap, allocheap, allocalignheap, releaseheap, availheap
predef memset, memcpy predef memset, memcpy
predef uword_isgt, uword_isge, uword_islt, uword_isle predef uword_isgt, uword_isge, uword_islt, uword_isle
predef loadmod, execmod predef loadmod, execmod, lookupmod
; ;
; Exported Machine ID. ; System variables.
;
byte machid = $F2 ; Apple ///, 80 columns
;
; System variable.
; ;
word version = $0010 ; 00.10
word systemflags = 0 word systemflags = 0
word heap = $2000 word heap = $2000
word refcons, devcons word refcons = 0
word devcons
byte modid = 0 byte modid = 0
byte modseg[15] byte modseg[15]
word symtbl, lastsym word symtbl, lastsym
byte perr, terr, lerr byte perr, terr, lerr
word cmdptr word cmdptr
; ;
; Exported Machine ID.
;
byte machid = $F2 ; Apple ///, 80 columns
;
; Standard Library exported functions. ; Standard Library exported functions.
; ;
byte stdlibstr[] = "STDLIB" byte stdlibstr[] = "STDLIB"
byte machidstr[] = "MACHID" byte machidstr[] = "MACHID"
byte sysvarstr[] = "SYSVARS"
byte sysstr[] = "SYSCALL" byte sysstr[] = "SYSCALL"
byte callstr[] = "CALL" byte callstr[] = "CALL"
byte putcstr[] = "PUTC" byte putcstr[] = "PUTC"
@ -54,8 +55,9 @@ byte uisgtstr[] = "ISUGT"
byte uisgestr[] = "ISUGE" byte uisgestr[] = "ISUGE"
byte uisltstr[] = "ISULT" byte uisltstr[] = "ISULT"
byte uislestr[] = "ISULE" byte uislestr[] = "ISULE"
byte loadstr[] = "LOAD" byte loadstr[] = "MODLOAD"
byte execstr[] = "EXEC" byte execstr[] = "MODEXEC"
byte modadrstr[] = "MODADDR"
word exports[] = @sysstr, @syscall word exports[] = @sysstr, @syscall
word = @callstr, @call word = @callstr, @call
word = @putcstr, @cout word = @putcstr, @cout
@ -75,8 +77,8 @@ word = @uisltstr, @uword_islt
word = @uislestr, @uword_isle word = @uislestr, @uword_isle
word = @loadstr, @loadmod word = @loadstr, @loadmod
word = @execstr, @execmod word = @execstr, @execmod
word = @modadrstr, @lookupmod
word = @machidstr, @machid word = @machidstr, @machid
word = @sysvarstr, @systemflags
word = 0 word = 0
word stdlibsym = @exports word stdlibsym = @exports
; ;
@ -84,13 +86,14 @@ word stdlibsym = @exports
; ;
byte console[] = ".CONSOLE" byte console[] = ".CONSOLE"
byte autorun[] = "AUTORUN" byte autorun[] = "AUTORUN"
byte version[] = "PLASMA 0.9\n" byte verstr[] = "PLASMA "
byte freestr[] = "MEM FREE:$" byte freestr[] = "MEM FREE:$"
byte errorstr[] = "ERR:$" byte errorstr[] = "ERR:$"
byte okstr[] = "OK" byte okstr[] = "OK"
byte huhstr[] = "?\n" byte huhstr[] = "?\n"
byte devtovol[] = " => /" byte devtovol[] = " => /"
byte prefix[128] = "" byte prefix[128] = ""
byte textmode[] = 16, 0, 15
byte hexchar[] = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' byte hexchar[] = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
; ;
; CALL SOS ; CALL SOS
@ -331,28 +334,26 @@ asm uword_isle
RTS RTS
end end
asm uword_isgt asm uword_isgt
LDY #$FF
LDA ESTKL,X LDA ESTKL,X
CMP ESTKL+1,X CMP ESTKL+1,X
LDA ESTKH,X LDA ESTKH,X
SBC ESTKH+1,X SBC ESTKH+1,X
BCC + LDA #$FF
INY ADC #$00
+ STY ESTKL+1,X STA ESTKL+1,X
STY ESTKH+1,X STA ESTKH+1,X
INX INX
RTS RTS
end end
asm uword_islt asm uword_islt
LDY #$FF
LDA ESTKL+1,X LDA ESTKL+1,X
CMP ESTKL,X CMP ESTKL,X
LDA ESTKH+1,X LDA ESTKH+1,X
SBC ESTKH,X SBC ESTKH,X
BCC + LDA #$FF
INY ADC #$00
+ STY ESTKL+1,X STA ESTKL+1,X
STY ESTKH+1,X STA ESTKH+1,X
INX INX
RTS RTS
end end
@ -458,8 +459,7 @@ TOUPR AND #$7F
BCC + BCC +
CMP #'z'+1 CMP #'z'+1
BCS + BCS +
SEC SBC #$1F
SBC #$20
+ STA ESTKL,X + STA ESTKL,X
RTS RTS
end end
@ -768,7 +768,10 @@ end
; ;
def init_cons def init_cons
byte nlmode[2] byte nlmode[2]
refcons = open(@console, O_READ_WRITE) if !refcons
refcons = open(@console, O_READ_WRITE)
fin
write(refcons, @textmode, 3)
devcons = dev_getnum(@console) devcons = dev_getnum(@console)
nlmode.0 = $80 nlmode.0 = $80
nlmode.1 = $0D nlmode.1 = $0D
@ -1021,6 +1024,10 @@ def loadmod(mod)
until rdlen <= 0 until rdlen <= 0
close(refnum) close(refnum)
; ;
; Add module to symbol table.
;
addmod(mod, modaddr)
;
; Apply all fixups and symbol import/export. ; Apply all fixups and symbol import/export.
; ;
modfix = modaddr - modfix modfix = modaddr - modfix
@ -1123,9 +1130,11 @@ def loadmod(mod)
; Call init routine if it exists. ; Call init routine if it exists.
; ;
if init if init
return adddef(defext, init - defofst + defaddr, @deflast)() fixup = adddef(defext, init - defofst + defaddr, @deflast)()
else
fixup = 0
fin fin
return 0 return fixup
end end
; ;
; Command mode ; Command mode
@ -1269,7 +1278,6 @@ def execmod(modfile)
loop loop
fin fin
end end
; ;
; Init console. ; Init console.
; ;
@ -1281,7 +1289,7 @@ symtbl = allocheap($400)
lastsym = symtbl lastsym = symtbl
^lastsym = 0 ^lastsym = 0
stodci(@stdlibstr, heap) stodci(@stdlibstr, heap)
addmod(heap, 1) addmod(heap, @systemflags)
while *stdlibsym while *stdlibsym
stodci((stdlibsym):0, heap) stodci((stdlibsym):0, heap)
addsym(heap, (stdlibsym):2) addsym(heap, (stdlibsym):2)
@ -1295,7 +1303,11 @@ perr = 0
; ;
; Print some startup info. ; Print some startup info.
; ;
prstr(@version) prstr(@verstr)
prbyte(version.1)
cout('.')
prbyte(version.0)
crout
prstr(@freestr) prstr(@freestr)
prword(availheap) prword(availheap)
crout crout