1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-18 07:24:16 +00:00

Apple /// PLASMA WIP

This commit is contained in:
David Schmenk 2014-05-30 22:54:41 -07:00
parent 45bd973607
commit c1aa4afa4c
10 changed files with 2384 additions and 143 deletions

View File

@ -1,31 +0,0 @@
;
; Declare all imported modules and their data/functions.
;
import stdlib
predef putc, puts
end
import testcls
word print
const dec = 0
const hex = 2
end
byte spaces[] = " "
def putln
putc($0D)
end
def printnums
word i
i = 10000
repeat
print:dec(i)
puts(@spaces)
print:hex(i)
putln
i = i / 10
until i == 0
end
printnums
done

View File

@ -167,11 +167,9 @@ asm syscall
INX
LDA ESTKL,X
STA CMD
STX ESP
JSR $BF00
CMD: !BYTE 00
PARAMS: !WORD 0000
LDX ESP
STA ESTKL,X
LDY #$00
STY ESTKH,X
@ -1018,7 +1016,7 @@ def adddef(bank, addr, deflast)
end
def loadmod(mod)
word refnum, rdlen, modsize, bytecode, defofst, defcnt, init, fixup
word addr, defaddr, modaddr, modfix
word addr, defaddr, modaddr, modfix, modend
word deftbl, deflast
word moddep, rld, esd, sym
byte defbank, str[16], filename[64]
@ -1048,7 +1046,7 @@ def loadmod(mod)
; Load module dependencies.
;
while ^moddep
if lookupmod(moddep) == 0
if !lookupmod(moddep)
close(refnum)
refnum = 0
if loadmod(moddep) < 0
@ -1063,7 +1061,7 @@ def loadmod(mod)
deftbl = allocheap(defcnt * 5 + 1)
deflast = deftbl
^deflast = 0
if refnum == 0
if !refnum
;
; Reset read pointer.
;
@ -1094,9 +1092,10 @@ def loadmod(mod)
;
modfix = modaddr - modfix
bytecode = defofst + modfix - MODADDR
rld = modaddr + modsize ; Re-Locatable Directory
esd = rld ; Extern+Entry Symbol Directory
while ^esd <> $00 ; Scan to end of ESD
modend = modaddr + modsize
rld = modend ; Re-Locatable Directory
esd = rld ; Extern+Entry Symbol Directory
while !^esd ; Scan to end of ESD
esd = esd + 4
loop
esd = esd + 1
@ -1106,6 +1105,7 @@ def loadmod(mod)
if ^MACHID & $30 == $30
defbank = 1
defaddr = allocxheap(rld - bytecode)
modend = bytecode
else
defbank = 0
defaddr = bytecode
@ -1173,11 +1173,11 @@ def loadmod(mod)
; Move bytecode to AUX bank.
;
memxcpy(0, defaddr, bytecode, modsize - (bytecode - modaddr))
;
; Free up the bytecode in main memory.
;
releaseheap(bytecode)
fin
;
; Free up the end-of-module in main memory.
;
releaseheap(modend)
else
perr = perr | 0x100
return -perr

View File

@ -1,3 +1,4 @@
INTERP = $03D0
;*
;* MOVE CMD DOWN TO $1000-$2000
;*

View File

@ -509,7 +509,7 @@ void emit_def(char *name, int is_bytecode)
{
//printf("%s%c\n", name, LBL);
if (is_bytecode)
printf("\tJSR $03D0\n");
printf("\tJSR\tINTERP\n");
}
}
void emit_codetag(int tag)

View File

@ -1,8 +0,0 @@
import STDLIB
predef puts
end
byte hellostr[] = "Hello, world.\n"
puts(@hellostr)
done

View File

@ -2,8 +2,11 @@
AFLAGS = -o $@
LFLAGS = -C default.cfg
PLVM = plvm
PLVM02 = PLVM02.SYS
CMD = CMD.SYS
PLVM02 = PLASMA.SYSTEM\#FF2000
PLVM03 = SOS.INTERP\#050000
CMD = CMD\#FF2000
ROD = ROD\#FE1000
HGR1 = HGR1\#FE1000
PLASM = plasm
INCS = tokens.h symbols.h lex.h parse.h codegen.h
OBJS = plasm.c parse.o lex.o codegen.o
@ -17,15 +20,15 @@ TXTTYPE = .TXT
#
# Image filetypes for CiderPress
#
#PLATYPE = \#ed0000
#RELTYPE = \#fe1000
#BINTYPE = \#060000
#SYSTYPE = \#ff0000
#SYSTYPE = \#ff2000
#TXTTYPE = \#040000
all: $(PLASM) $(PLVM) $(PLVM02) $(CMD) TESTLIB ROD.REL
all: $(PLASM) $(PLVM) $(PLVM02) $(PLVM03) $(CMD) $(ROD) $(HGR1)
clean:
-rm *.o *~ *.a *.SYM *.SYS *.REL TESTLIB $(PLASM) $(PLVM)
-rm *.o *~ *.a *.SYM $(CMD) *\#FE1000 $(ROD) $(HGR1) $(PLASM) $(PLVM)
$(PLASM): $(OBJS) $(INCS)
cc $(OBJS) -o $(PLASM)
@ -39,44 +42,34 @@ cmdexec.a: cmdexec.pla $(PLASM)
$(PLVM02): plvm02.s cmdexec.a
acme -o $(PLVM02) -l PLVM02.SYM plvm02.s
$(CMD): cmd.pla cmdstub.s $(PLVM) $(PLASM)
soscmd.a: soscmd.pla $(PLASM)
./$(PLASM) -A < soscmd.pla > soscmd.a
$(PLVM03): plvm03.s soscmd.a
acme -o $(PLVM03) -l PLVM03.SYM plvm03.s
$(CMD): cmd.pla cmdstub.s $(PLVM02) $(PLASM)
./$(PLASM) -A < cmd.pla > cmd.a
acme --setpc 8192 -o $(CMD) cmdstub.s
TESTLIB: testlib.pla $(PLVM) $(PLASM)
./$(PLASM) -AM < testlib.pla > testlib.a
acme --setpc 4094 -o TESTLIB testlib.a
test: test.pla TESTLIB $(PLVM) $(PLASM)
test: test.pla testlib.pla $(PLVM) $(PLASM)
./$(PLASM) -AM < test.pla > test.a
acme --setpc 4094 -o TEST.REL test.a
./$(PLVM) TEST.REL
acme --setpc 4094 -o TEST#FE1000 test.a
./$(PLASM) -AM < teslib.pla >testlib.a
acme --setpc 4094 -o TESTLIB#FE1000 testlib.a
./$(PLVM) TEST\#FE1000
TESTCLS: testcls.pla $(PLVM) $(PLASM)
./$(PLASM) -AM < testcls.pla > testcls.a
acme --setpc 4094 -o TESTCLS testcls.a
class: class.pla TESTCLS $(PLVM) $(PLASM)
./$(PLASM) -AM < class.pla > class.a
acme --setpc 4094 -o CLASS.REL class.a
./$(PLVM) CLASS.REL
debug: test.pla TESTLIB $(PLVM) $(PLASM)
./$(PLASM) -AM < test.pla > test.a
acme --setpc 4094 -o TEST.REL test.a
./$(PLVM) -s TEST.REL MAIN
hello: hello.pla $(PLVM) $(PLASM)
./$(PLASM) -AM < hello.pla > hello.a
acme --setpc 4094 -o HELLO.REL hello.a
./$(PLVM) HELLO.REL
ROD.REL: rod.pla $(PLVM) $(PLASM)
$(ROD): rod.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < rod.pla > rod.a
acme --setpc 4094 -o ROD.REL rod.a
acme --setpc 4094 -o $(ROD) rod.a
HGR1: hgr1.pla hgr1test.pla $(PLVM) $(PLASM)
$(HGR1): hgr1.pla hgr1test.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < hgr1test.pla > hgr1test.a
acme --setpc 4094 -o HGR1TEST.REL hgr1test.a
acme --setpc 4094 -o HGR1TEST.REL#FE1000 hgr1test.a
./$(PLASM) -AM < hgr1.pla > hgr1.a
acme --setpc 4094 -o HGR1 hgr1.a
acme --setpc 4094 -o $(HGR1) hgr1.a
hello: hello.pla $(PLVM) $(PLASM)
m4 < hello.pla | ./$(PLASM) -AM > hello.a
acme --setpc 4094 -o HELLO#FE1000 hello.a
./$(PLVM) HELLO#FE1000

View File

@ -209,8 +209,8 @@ PAGE3 = *
;*
;* PAGE 3 VECTORS INTO INTERPRETER
;*
BIT LCRDEN+LCBNK2 ; $03D0 - DIRECT INTERP ENTRY
JMP INTERP
INTERP BIT LCRDEN+LCBNK2 ; $03D0 - DIRECT INTERP ENTRY
JMP DINTERP
BIT LCRDEN+LCBNK2 ; $03D6 - INDIRECT INTERP ENTRY
JMP IINTRP
BIT LCRDEN+LCBNK2 ; $03DC - INDIRECT INTERPX ENTRY
@ -306,7 +306,7 @@ DISABLE80 !BYTE 21, 13, '1', 26, 13
;*
;* ENTER INTO BYTECODE INTERPRETER
;*
INTERP BIT LCRWEN+LCBNK2 ; WRITE ENABLE LANGUAGE CARD
DINTERP BIT LCRWEN+LCBNK2 ; WRITE ENABLE LANGUAGE CARD
BIT LCRWEN+LCBNK2
PLA
STA IPL
@ -384,10 +384,6 @@ TIMER JSR JMPTMR
;*
JMPTMR JMP (TMRVEC)
;*
;* INDIRECT JUMP TO (TMP)
;*
JMPTMP JMP (TMP)
;*
;* ADD TOS TO TOS-1
;*
ADD LDA ESTKL,X
@ -1818,17 +1814,17 @@ IBRNCHX LDA IPL
;*
CALL +INC_IP
LDA (IP),Y
STA TMPL
STA CALLADR+1
+INC_IP
LDA (IP),Y
STA TMPH
STA CALLADR+2
LDA IPH
PHA
LDA IPL
PHA
TYA
PHA
JSR JMPTMP
CALLADR JSR $FFFF
PLA
TAY
PLA
@ -1841,10 +1837,10 @@ CALL +INC_IP
;
CALLX +INC_IP
LDA (IP),Y
STA TMPL
STA CALXADR+1
+INC_IP
LDA (IP),Y
STA TMPH
STA CALXADR+2
LDA IPH
PHA
LDA IPL
@ -1853,7 +1849,7 @@ CALLX +INC_IP
PHA
STA ALTRDOFF
CLI
JSR JMPTMP
CALXADR JSR $FFFF
SEI
STA ALTRDON
PLA
@ -1869,9 +1865,9 @@ CALLX +INC_IP
;* INDIRECT CALL TO ADDRESS (NATIVE CODE)
;*
ICAL LDA ESTKL,X
STA TMPL
STA ICALADR+1
LDA ESTKH,X
STA TMPH
STA ICALADR+2
INX
LDA IPH
PHA
@ -1879,7 +1875,7 @@ ICAL LDA ESTKL,X
PHA
TYA
PHA
JSR JMPTMP
ICALADR JSR $FFFF
PLA
TAY
PLA
@ -1891,9 +1887,9 @@ ICAL LDA ESTKL,X
JMP NEXTOP
;
ICALX LDA ESTKL,X
STA TMPL
STA ICLXADR+1
LDA ESTKH,X
STA TMPH
STA ICLXADR+2
INX
LDA IPH
PHA
@ -1903,7 +1899,7 @@ ICALX LDA ESTKL,X
PHA
STA ALTRDOFF
CLI
JSR JMPTMP
ICLXADR JSR $FFFF
SEI
STA ALTRDON
PLA
@ -1952,7 +1948,7 @@ ENTER4 LDA ESTKH,X
STA (IFP),Y
DEY
INX
DEC TMPL
DEC NPARMS
BNE ENTER4
ENTER5 LDY IPY
JMP NEXTOP
@ -1992,7 +1988,7 @@ ENTERX4 LDA ESTKH,X
STA (IFP),Y
DEY
INX
DEC TMPL
DEC NPARMS
BNE ENTERX4
ENTERX5 STA ALTRDON
LDY IPY

1016
src/plvm03.s Normal file

File diff suppressed because it is too large Load Diff

1306
src/soscmd.pla Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +0,0 @@
;
; Declare all imported modules and their data/functions.
;
import stdlib
predef putc
end
predef puti, puth
export word print[] = @puti, @puth
byte valstr[] = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
;
; Define functions.
;
def puti(i)
if i < 0
putc('-')
i = -i
fin
if i < 10
putc(i + '0')
else
puti(i / 10)
putc(i % 10 + '0')
fin
end
def puth(h)
putc('$')
putc(valstr[(h >> 12) & $0F])
putc(valstr[(h >> 8) & $0F])
putc(valstr[(h >> 4) & $0F])
putc(valstr[ h & $0F])
end
done