This commit is contained in:
Martin Haye 2014-06-13 13:10:45 -07:00
commit 44fdabab49
9 changed files with 259 additions and 502 deletions

View File

@ -16,26 +16,34 @@ const resxhgr2 = $0020
; ;
; Pedefined functions. ; Pedefined functions.
; ;
predef home, gotoxy, viewport, crout, cout, prstr, cin, rdstr
predef syscall, call predef syscall, call
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.
;
word version = $0010 ; 00.10
word systemflags = 0
word heap
word xheap = $0800
word lastsym = symtbl
byte perr
word cmdptr
; ;
; Standard Library exported functions. ; Standard Library exported functions.
; ;
byte stdlibstr[] = "STDLIB" byte stdlibstr[] = "STDLIB"
byte machidstr[] = "MACHID" byte machidstr[] = "MACHID"
byte clsstr[] = "CLS" byte sysstr[] = "SYSCALL"
byte gotoxystr[] = "GOTOXY" byte callstr[] = "CALL"
byte viewstr[] = "VIEWPORT"
byte putcstr[] = "PUTC" byte putcstr[] = "PUTC"
byte putlnstr[] = "PUTLN"
byte putsstr[] = "PUTS" byte putsstr[] = "PUTS"
byte getcstr[] = "GETC" byte getcstr[] = "GETC"
byte getsstr[] = "GETS" byte getsstr[] = "GETS"
byte sysstr[] = "SYSCALL"
byte callstr[] = "CALL"
byte hpmarkstr[] = "HEAPMARK" byte hpmarkstr[] = "HEAPMARK"
byte hpalignstr[] = "HEAPALLOCALIGN" byte hpalignstr[] = "HEAPALLOCALIGN"
byte hpallocstr[] = "HEAPALLOC" byte hpallocstr[] = "HEAPALLOC"
@ -47,17 +55,16 @@ 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"
word exports[] = @clsstr, @home byte modadrstr[] = "MODADDR"
word = @gotoxystr, @gotoxy word exports[] = @sysstr, @syscall
word = @viewstr, @viewport word = @callstr, @call
word = @putcstr, @cout word = @putcstr, @cout
word = @putlnstr, @crout
word = @putsstr, @prstr word = @putsstr, @prstr
word = @getcstr, @cin word = @getcstr, @cin
word = @getsstr, @rdstr word = @getsstr, @rdstr
word = @sysstr, @syscall
word = @callstr, @call
word = @hpmarkstr, @markheap word = @hpmarkstr, @markheap
word = @hpallocstr,@allocheap word = @hpallocstr,@allocheap
word = @hpalignstr,@allocalignheap word = @hpalignstr,@allocalignheap
@ -70,42 +77,24 @@ 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 = 0 word = 0
word stdlibsym = @exports word stdlibsym = @exports
; ;
; String pool. ; String pool.
; ;
byte version[] = "PLASMA 0.9\n" byte autorun[] = "AUTORUN"
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 prefix[32] = "" byte prefix[32] = ""
; ;
; System variable.
;
word heap
word lastsym = symtbl
word xheap = $0800
word systemflags = 0
byte perr
word cmdptr
;
; Utility functions ; Utility functions
; ;
asm equates ;asm equates included from cmdstub.s
;*
;* BANK SWITCHED MEM
;*
LCRDEN = $C080
LCWTEN = $C081
ROMEN = $C082
LCRWEN = $C083
LCBNK2 = $00
LCBNK1 = $08
!SOURCE "plvm02zp.inc"
end
; ;
; CALL PRODOS ; CALL PRODOS
; SYSCALL(CMD, PARAMS) ; SYSCALL(CMD, PARAMS)
@ -128,25 +117,25 @@ PARAMS: !WORD 0000
end end
; ;
; CALL 6502 ROUTINE ; CALL 6502 ROUTINE
; CALL(AREG, XREG, YREG, STATUS, ADDR) ; CALL(ADDR, AREG, XREG, YREG, STATUS)
; ;
asm call asm call
REGVALS = SRC REGVALS = SRC
PHP PHP
LDA ESTKL,X LDA ESTKL+4,X
STA TMPL STA TMPL
LDA ESTKH,X LDA ESTKH+4,X
STA TMPH STA TMPH
INX
LDA ESTKL,X LDA ESTKL,X
PHA PHA
INX
LDA ESTKL,X
TAY
INX
LDA ESTKL+1,X LDA ESTKL+1,X
TAY
LDA ESTKL+3,X
PHA PHA
LDA ESTKL,X LDA ESTKL+2,X
INX
INX
INX
INX INX
STX ESP STX ESP
TAX TAX
@ -174,11 +163,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
@ -189,7 +178,7 @@ end
; ;
asm reboot asm reboot
BIT ROMEN BIT ROMEN
DEC $3F4 ; INVALIDATE POWER-UP BYTE DEC $03F4 ; INVALIDATE POWER-UP BYTE
JMP ($FFFC) ; RESET JMP ($FFFC) ; RESET
end end
; ;
@ -328,67 +317,6 @@ asm memxcpy
INX INX
RTS RTS
end end
;
; HOME
;
asm home
STX ESP
BIT ROMEN
JSR $FC58
BIT LCRDEN+LCBNK2
LDX ESP
DEX
RTS
end
;
; SET VIEWPORT
; VIEWPORT(LEFT, TOP, WIDTH, HEIGHT)
;
asm viewport
LDA ESTKL+1,X
BNE +
LDA ESTKL,X
BNE +
STA ESTKL+3,X
STA ESTKL+2,X
LDA #40
STA ESTKL+1,X
LDA #24
STA ESTKL,X
+ LDA ESTKL+3,X
STA $20
LDA ESTKL+1,X
STA $21
LDA ESTKL+2,X
STA $22
CLC
ADC ESTKL,X
STA $23
LDY #$00
STY $24
LDA $22
INX
INX
BNE VTAB
end
;
; SET VIEWPORT RELATIVE CURSOR POSITION
; GOTOXY(X,Y)
;
asm gotoxy
LDA ESTKL+1,X
STA $24
LDA ESTKL,X
CLC
ADC $22
VTAB STX ESP
BIT ROMEN
JSR $FB5B
BIT LCRDEN+LCBNK2
LDX ESP
INX
RTS
end
asm crout asm crout
DEX DEX
LDA #$8D LDA #$8D
@ -434,7 +362,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 ++
@ -446,8 +373,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
@ -468,12 +394,11 @@ end
; PRINT WORD ; PRINT WORD
; ;
asm prword asm prword
LDA ESTKH,X
TAY
LDA ESTKL,X
STX ESP STX ESP
TAX TXA
TYA TAY
LDA ESTKH,Y
LDX ESTKL,Y
BIT ROMEN BIT ROMEN
JSR $F941 JSR $F941
LDX ESP LDX ESP
@ -496,8 +421,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
@ -531,28 +456,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
@ -649,8 +572,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
@ -885,16 +807,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,
; ;
@ -1032,7 +944,7 @@ def loadmod(mod)
close(refnum) close(refnum)
refnum = 0 refnum = 0
if loadmod(moddep) < 0 if loadmod(moddep) < 0
return perr return -perr
fin fin
fin fin
moddep = moddep + dcitos(moddep, @str) moddep = moddep + dcitos(moddep, @str)
@ -1070,6 +982,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
@ -1156,10 +1072,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
@ -1168,9 +1080,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 fin
return 0 else
fixup = 0
fin
;
; Free up the end-of-module in main memory.
;
releaseheap(modend)
return fixup
end end
; ;
; Command mode ; Command mode
@ -1350,17 +1273,34 @@ def execmod(modfile)
heap = saveheap heap = saveheap
fin fin
end end
;
; Get heap start.
;
heap = *freemem heap = *freemem
;
; 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)
stdlibsym = stdlibsym + 4 stdlibsym = stdlibsym + 4
loop loop
;
; Try to run autorun module.
;
resetmemfiles() resetmemfiles()
prstr(@version) execmod(@autorun)
perr = 0
;
; Print some startup info.
;
prstr(@verstr)
prbyte(version.1)
cout('.')
prbyte(version.0)
crout
prstr(@freestr) prstr(@freestr)
prword(availheap) prword(availheap)
crout crout

View File

@ -1,179 +0,0 @@
const iobuffer = $0800
const databuff = $0C00
const memmap = $BF58
const sysfile = $0280
byte syshalt[] = "SYSTEM HALTED..."
byte perr
;
; Utility functions
;
; CALL PRODOS
; SYSCALL(CMD, PARAMS)
;
asm prodos
LDA ESTKL,X
LDY ESTKH,X
STA PARAMS
STY PARAMS+1
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
RTS
end
;
; CALL LOADED SYSTEM PROGRAM
;
asm exec
LDA #$00
STA IFPL
LDA #$BF
STA IFPH
LDX #$FE
TXS
LDX #ESTKSZ/2
BIT ROMEN
JMP $2000
end
;
; EXIT
;
asm reboot
BIT ROMEN
LDA #$00
STA $3F4 ; INVALIDATE POWER-UP BYTE
JMP ($FFFC) ; RESET
end
;
; SET MEMORY TO 0
; MEMCLR(ADDR, SIZE)
;
asm memclr
LDY #$00
LDA ESTKL+1,X
STA DSTL
LDA ESTKH+1,X
STA DSTH
INC ESTKL,X
INC ESTKH,X
TYA
SETMLP DEC ESTKL,X
BNE +
DEC ESTKH,X
BEQ ++
+ STA (DST),Y
INY
BNE SETMLP
INC DSTH
BNE SETMLP
++ INX
RTS
end
asm cin
BIT ROMEN
STX ESP
JSR $FD0C
LDX ESP
DEX
STA ESTKL,X
LDY #$00
STY ESTKH,X
BIT LCRDEN+LCBNK2
RTS
end
;
; PRINT STRING
; PRSTR(STR)
;
asm prstr
LDY #$00
LDA ESTKL,X
STA SRCL
LDA ESTKH,X
STA SRCH
BIT ROMEN
LDA (SRC),Y
STA ESTKL,X
BEQ +
- INY
LDA (SRC),Y
ORA #$80
JSR $FDED
TYA
CMP ESTKL,X
BNE -
+ BIT LCRDEN+LCBNK2
RTS
end
;
; ProDOS routines
;
def open(path, buff)
byte params[6]
params.0 = 3
params:1 = path
params:3 = buff
params.5 = 0
perr = prodos($C8, @params)
return params.5
end
def close(refnum)
byte params[2]
params.0 = 1
params.1 = refnum
perr = prodos($CC, @params)
return perr
end
def read(refnum, buff, len)
byte params[8]
params.0 = 4
params.1 = refnum
params:2 = buff
params:4 = len
params:6 = 0
perr = prodos($CA, @params)
return params:6
end
def resetmemfiles
;
; Close all files
;
^$BFD8 = 0
close(0)
;
; Set memory bitmap
;
memclr(memmap, 24)
^memmap.0 = $CF
^memmap.23 = $01
end
def execsys
byte refnum
if ^sysfile
refnum = open(sysfile, iobuffer)
if refnum
if read(refnum, $2000, $FFFF)
resetmemfiles()
exec()
fin
fin
fin
end
resetmemfiles()
execsys
prstr(@syshalt)
cin()
reboot()
done

View File

@ -1,29 +1,45 @@
INTERP = $03D0 INTERP = $03D0
LCRDEN = $C080
LCWTEN = $C081
ROMEN = $C082
LCRWEN = $C083
LCBNK2 = $00
LCBNK1 = $08
!SOURCE "plvm02zp.inc"
;* ;*
;* MOVE CMD DOWN TO $1000-$2000 ;* MOVE CMD DOWN TO $1000-$2000
;* ;*
LDA #<_CMDBEGIN LDA #<_CMDBEGIN
STA $06 STA SRCL
LDA #>_CMDBEGIN LDA #>_CMDBEGIN
STA $07 STA SRCH
LDA #$00
STA $08
LDA #$10
STA $09
LDY #$00 LDY #$00
- LDA ($06),Y STY DSTL
STA ($08),Y LDA #$10
STA DSTH
- LDA (SRC),Y
STA (DST),Y
INY INY
BNE - BNE -
INC $07 INC SRCH
INC $09 INC DSTH
LDA $09 LDA DSTH
CMP #$20 CMP #$20 ; STOP WHEN DST=$2000 REACHED
BNE - BNE -
LDA #<_CMDEND LDA #<_CMDEND
STA $06 STA SRCL
LDA #>_CMDEND LDA #>_CMDEND
STA $07 STA SRCH
;
; INIT VM ENVIRONMENT STACK POINTERS
;
LDA #$00 ; INIT FRAME POINTER
STA IFPL
LDA #$BF
STA IFPH
LDX #$FE ; INIT STACK POINTER (YES, $FE. SEE GETS)
TXS
LDX #ESTKSZ/2 ; INIT EVAL STACK INDEX
JMP $1000 JMP $1000
_CMDBEGIN = * _CMDBEGIN = *
!PSEUDOPC $1000 { !PSEUDOPC $1000 {

View File

@ -2,8 +2,8 @@
AFLAGS = -o $@ AFLAGS = -o $@
LFLAGS = -C default.cfg LFLAGS = -C default.cfg
PLVM = plvm PLVM = plvm
PLVM02 = PLVM02.SYS PLVM02 = PLASMA.SYSTEM\#FF2000
CMD = CMD.SYS CMD = CMD\#FF2000
PLASM = plasm PLASM = plasm
INCS = tokens.h symbols.h lex.h parse.h codegen.h INCS = tokens.h symbols.h lex.h parse.h codegen.h
OBJS = plasm.c parse.o lex.o codegen.o OBJS = plasm.c parse.o lex.o codegen.o
@ -22,10 +22,10 @@ TXTTYPE = .TXT
#SYSTYPE = \#ff0000 #SYSTYPE = \#ff0000
#TXTTYPE = \#040000 #TXTTYPE = \#040000
all: $(PLASM) $(PLVM) $(PLVM02) $(CMD) TESTLIB all: $(PLASM) $(PLVM) $(PLVM02) $(CMD)
clean: clean:
-rm *.o *~ *.a *.SYM *.SYS *.REL TESTLIB $(PLASM) $(PLVM) -rm *.o *~ *.a *FE1000 $(PLVM02) $(CMD) $(PLASM) $(PLVM)
$(PLASM): $(OBJS) $(INCS) $(PLASM): $(OBJS) $(INCS)
cc $(OBJS) -o $(PLASM) cc $(OBJS) -o $(PLASM)
@ -33,31 +33,28 @@ $(PLASM): $(OBJS) $(INCS)
$(PLVM): plvm.c $(PLVM): plvm.c
cc plvm.c -o $(PLVM) cc plvm.c -o $(PLVM)
cmdexec.a: cmdexec.pla $(PLASM) $(PLVM02): plvm02.s
./$(PLASM) -A < cmdexec.pla > cmdexec.a acme -o $(PLVM02) plvm02.s
$(PLVM02): plvm02.s cmdexec.a
acme -o $(PLVM02) -l PLVM02.SYM plvm02.s
$(CMD): cmd.pla cmdstub.s $(PLVM) $(PLASM) $(CMD): cmd.pla cmdstub.s $(PLVM) $(PLASM)
./$(PLASM) -A < cmd.pla > cmd.a ./$(PLASM) -A < cmd.pla > cmd.a
acme --setpc 8192 -o $(CMD) cmdstub.s acme --setpc 8192 -o $(CMD) cmdstub.s
TESTLIB: testlib.pla $(PLVM) $(PLASM) TESTLIB\#FE1000: testlib.pla $(PLVM) $(PLASM)
m4 < testlib.pla |./$(PLASM) -AM > testlib.a m4 < testlib.pla |./$(PLASM) -AM > testlib.a
acme --setpc 4094 -o TESTLIB testlib.a acme --setpc 4094 -o TESTLIB\#FE1000 testlib.a
test: test.pla TESTLIB $(PLVM) $(PLASM) test: test.pla TESTLIB\#FE1000 $(PLVM) $(PLASM)
m4 < test.pla | ./$(PLASM) -AM > test.a m4 < test.pla | ./$(PLASM) -AM > test.a
acme --setpc 4094 -o TEST.REL test.a acme --setpc 4094 -o TEST\#FE1000 test.a
./$(PLVM) TEST.REL ./$(PLVM) TEST
debug: test.pla TESTLIB $(PLVM) $(PLASM) debug: test.pla TESTLIB $(PLVM) $(PLASM)
m4 < test.pla | ./$(PLASM) -AM > test.a m4 < test.pla | ./$(PLASM) -AM > test.a
acme --setpc 4094 -o TEST.REL test.a acme --setpc 4094 -o TEST\#FE1000 test.a
./$(PLVM) -s TEST.REL MAIN ./$(PLVM) -s TEST MAIN
hello: hello.pla $(PLVM) $(PLASM) hello: hello.pla $(PLVM) $(PLASM)
m4 < hello.pla | ./$(PLASM) -AM > hello.a m4 < hello.pla | ./$(PLASM) -AM > hello.a
acme --setpc 4094 -o HELLO.REL hello.a acme --setpc 4094 -o HELLO\#FE1000 hello.a
./$(PLVM) HELLO.REL ./$(PLVM) HELLO

View File

@ -146,6 +146,8 @@ uword lookup_tbl(byte *dci, byte *tbl)
while (*entry++ & 0x80); while (*entry++ & 0x80);
entry += 2; entry += 2;
} }
dcitos(dci, str);
printf("\nError: symbols %s not found in symbol table.\n", str);
return 0; return 0;
} }
uword add_tbl(byte *dci, int val, byte **last) uword add_tbl(byte *dci, int val, byte **last)
@ -233,10 +235,12 @@ int load_mod(byte *mod)
byte *moddep, *rld, *esd, *cdd, *sym; byte *moddep, *rld, *esd, *cdd, *sym;
byte header[128]; byte header[128];
int fd; int fd;
char filename[32], string[17]; char filename[48], string[17];
dcitos(mod, filename); dcitos(mod, filename);
printf("Load module %s\n", filename); printf("Load module %s\n", filename);
if (strlen(filename) < 8 || (filename[strlen(filename) - 7] != '#'))
strcat(filename, "#FE1000");
fd = open(filename, O_RDONLY, 0); fd = open(filename, O_RDONLY, 0);
if ((fd > 0) && (len = read(fd, header, 128)) > 0) if ((fd > 0) && (len = read(fd, header, 128)) > 0)
{ {
@ -316,6 +320,10 @@ int load_mod(byte *mod)
printf("Module def count: $%04X\n", defcnt); printf("Module def count: $%04X\n", defcnt);
printf("Module init: $%04X\n", init ? init + modfix - MOD_ADDR : 0); printf("Module init: $%04X\n", init ? init + modfix - MOD_ADDR : 0);
} }
/*
* Add module to symbol table.
*/
add_mod(mod, modaddr);
/* /*
* Print out the Re-Location Dictionary. * Print out the Re-Location Dictionary.
*/ */
@ -418,6 +426,7 @@ int load_mod(byte *mod)
if (init) if (init)
{ {
interp(mem_data + init + modfix - MOD_ADDR); interp(mem_data + init + modfix - MOD_ADDR);
// release_heap(init + modfix - MOD_ADDR); // Free up init code
return POP; return POP;
} }
return 0; return 0;
@ -429,6 +438,8 @@ void call(uword pc)
unsigned int i, s; unsigned int i, s;
char c, sz[64]; char c, sz[64];
if (show_state)
printf("\nCall code:$%02X\n", mem_data[pc]);
switch (mem_data[pc++]) switch (mem_data[pc++])
{ {
case 0: // NULL call case 0: // NULL call
@ -440,19 +451,14 @@ void call(uword pc)
case 2: // BYTECODE in mem_data case 2: // BYTECODE in mem_data
interp(mem_data + (mem_data[pc] + (mem_data[pc + 1] << 8))); interp(mem_data + (mem_data[pc] + (mem_data[pc + 1] << 8)));
break; break;
case 3: // LIBRARY STDLIB::VIEWPORT case 3: // LIBRARY STDLIB::PUTC
printf("Set Viewport %d, %d, %d, %d\n", esp[3], esp[2], esp[1], esp[0]);
esp += 4;
PUSH(0);
break;
case 4: // LIBRARY STDLIB::PUTC
c = POP; c = POP;
if (c == 0x0D) if (c == 0x0D)
c = '\n'; c = '\n';
putchar(c); putchar(c);
PUSH(0); PUSH(0);
break; break;
case 5: // LIBRARY STDLIB::PUTS case 4: // LIBRARY STDLIB::PUTS
s = POP; s = POP;
i = mem_data[s++]; i = mem_data[s++];
PUSH(i); PUSH(i);
@ -464,7 +470,7 @@ void call(uword pc)
putchar(c); putchar(c);
} }
break; break;
case 6: // LIBRARY STDLIB::PUTSZ case 5: // LIBRARY STDLIB::PUTSZ
s = POP; s = POP;
while ((c = mem_data[s++])) while ((c = mem_data[s++]))
{ {
@ -474,10 +480,10 @@ void call(uword pc)
} }
PUSH(0); PUSH(0);
break; break;
case 7: // LIBRARY STDLIB::GETC case 6: // LIBRARY STDLIB::GETC
PUSH(getchar()); PUSH(getchar());
break; break;
case 8: // LIBRARY STDLIB::GETS case 7: // LIBRARY STDLIB::GETS
gets(sz); gets(sz);
for (i = 0; sz[i]; i++) for (i = 0; sz[i]; i++)
mem_data[0x200 + i] = sz[i]; mem_data[0x200 + i] = sz[i];
@ -485,25 +491,14 @@ void call(uword pc)
mem_data[0x1FF] = i; mem_data[0x1FF] = i;
PUSH(i); PUSH(i);
break; break;
case 9: // LIBRARY STDLIB::CLS case 8: // LIBRARY STDLIB::PUTNL
puts("\033[2J");
fflush(stdout);
PUSH(0);
PUSH(0);
case 10: // LIBRARY STDLIB::GOTOXY
s = POP + 1;
i = POP + 1;
printf("\033[%d;%df", s, i);
fflush(stdout);
PUSH(0);
break;
case 11: // LIBRARY STDLIB::PUTNL
putchar('\n'); putchar('\n');
fflush(stdout); fflush(stdout);
PUSH(0); PUSH(0);
break; break;
default: default:
printf("Bad call code\n"); printf("\nBad call code:$%02X\n", mem_data[pc - 1]);
exit(1);
} }
} }
@ -880,22 +875,16 @@ void interp(code *ip)
} }
char *stdlib_exp[] = { char *stdlib_exp[] = {
"VIEWPORT",
"PUTC", "PUTC",
"PUTS", "PUTS",
"PUTSZ", "PUTSZ",
"GETC", "GETC",
"GETS", "GETS",
"CLS", "PUTLN",
"GOTOXY", "MACHID",
"PUTNL",
0 0
}; };
byte stdlib[] = {
0x00
};
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
byte dci[32]; byte dci[32];

View File

@ -40,21 +40,19 @@ ALTWROFF= $C004
ALTWRON = $C005 ALTWRON = $C005
!SOURCE "plvm02zp.inc" !SOURCE "plvm02zp.inc"
STRBUF = $0280 STRBUF = $0280
;**********************************************************
;* ;*
;* INTERPRETER INSTRUCTION POINTER INCREMENT MACRO ;* INTERPRETER INSTRUCTION POINTER INCREMENT MACRO
;* ;*
;**********************************************************
!MACRO INC_IP { !MACRO INC_IP {
INY INY
BNE * + 4 BNE * + 4
INC IPH INC IPH
} }
;*********************************************** ;******************************
;* ;* *
;* INTERPRETER INITIALIZATION ;* INTERPRETER INITIALIZATION *
;* ;* *
;*********************************************** ;******************************
* = $2000 * = $2000
LDX #$FF LDX #$FF
TXS TXS
@ -161,51 +159,9 @@ RAMDONE CLI
STA $D103,Y ; YEAH, I HARDCODED THE ADDRESS STA $D103,Y ; YEAH, I HARDCODED THE ADDRESS
DEY DEY
BPL - BPL -
JMP CMDEXEC
;*
;* LOOK FOR STARTUP FILE
;*
JSR PRODOS ; OPEN AUTORUN
!BYTE $C8
!WORD OPENPARMS
BNE NOAUTO
LDA REFNUM
STA NLPARMS+1
JSR PRODOS
!BYTE $C9
!WORD NLPARMS
BNE NOAUTO
LDA REFNUM
STA READPARMS+1
JSR PRODOS
!BYTE $CA
!WORD READPARMS
BNE NOAUTO
LDX READPARMS+6
STX STRBUF ; STRING LENGTH
JSR PRODOS
!BYTE $CC
!WORD CLOSEPARMS
NOAUTO JMP CMDEXEC
GETPFXPARMS !BYTE 1 GETPFXPARMS !BYTE 1
!WORD STRBUF ; PATH STRING GOES HERE !WORD STRBUF ; PATH STRING GOES HERE
AUTORUN !BYTE 7
!TEXT "AUTORUN"
OPENPARMS !BYTE 3
!WORD AUTORUN
!WORD $0800
REFNUM !BYTE 0
NLPARMS !BYTE 3
!BYTE 0
!BYTE $7F
!BYTE $0D
READPARMS !BYTE 4
!BYTE 0
!WORD STRBUF+1
!WORD $0080
!WORD 0
CLOSEPARMS !BYTE 1
!BYTE 0
PAGE3 = * PAGE3 = *
!PSEUDOPC $03D0 { !PSEUDOPC $03D0 {
;* ;*
@ -220,6 +176,11 @@ INTERP BIT LCRDEN+LCBNK2 ; $03D0 - DIRECT INTERP ENTRY
TMRVEC !WORD TMRRTS TMRVEC !WORD TMRRTS
TMRRTS RTS TMRRTS RTS
} }
;************************************************
;* *
;* LANGUAGE CARD RESIDENT PLASMA VM STARTS HERE *
;* *
;************************************************
VMCORE = * VMCORE = *
!PSEUDOPC $D000 { !PSEUDOPC $D000 {
;* ;*
@ -245,12 +206,9 @@ OPTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
!WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E !WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
!WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E !WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
;* ;*
;* 'BYE' COMMAND PROCESSING ;* 'BYE' PROCESSING - COPIED TO $1000 ON PRODOS BYE COMMAND
;* ;*
!PSEUDOPC $1000 { !PSEUDOPC $1000 {
;*
;* CLEAR COMMAND LINE LENGTH BYTE IF CALLED FROM 'BYE'
;*
BYE JMP CPYCMD BYE JMP CPYCMD
DEFCMD !FILL 63 ; AT $D103 IN LC MEMORY DEFCMD !FILL 63 ; AT $D103 IN LC MEMORY
CPYCMD LDY DEFCMD CPYCMD LDY DEFCMD
@ -258,31 +216,10 @@ CPYCMD LDY DEFCMD
STA STRBUF,Y STA STRBUF,Y
DEY DEY
BPL - BPL -
;* CMDEXEC = *
;* MOVE REST OF CMD FROM LANGUAGE CARD ;
;* ; DEACTIVATE 80 COL CARDS
CMDEXEC LDY #$00 ;
STY SRCL
STY DSTL
LDA #$D2
STA SRCH
LDA #$11
STA DSTH
BIT LCRDEN+LCBNK2
- LDA (SRC),Y
STA (DST),Y
INY
BNE -
INC SRCH
INC DSTH
LDA SRCH
CMP #$D4 ; #$E0
BNE -
;*
;* DEACTIVATE 80 COL CARDS
;*
LDX #$FE
TXS
BIT ROMEN BIT ROMEN
LDY #4 LDY #4
- LDA DISABLE80,Y - LDA DISABLE80,Y
@ -294,16 +231,56 @@ CMDEXEC LDY #$00
BIT $C051 BIT $C051
BIT $C058 BIT $C058
JSR $FC58 ; HOME JSR $FC58 ; HOME
;* ;
;* JUMP TO INTERPRETER ; READ CMD INTO MEMORY
;* ;
START LDA #$00 JSR PRODOS ; CLOSE EVERYTHING
STA IFPL !BYTE $CC
LDA #$BF !WORD CLOSEPARMS
STA IFPH BNE FAIL
LDX #ESTKSZ/2 JSR PRODOS ; OPEN CMD
!SOURCE "cmdexec.a" !BYTE $C8
!WORD OPENPARMS
BNE FAIL
LDA REFNUM
STA READPARMS+1
JSR PRODOS
!BYTE $CA
!WORD READPARMS
BNE FAIL
JSR PRODOS
!BYTE $CC
!WORD CLOSEPARMS
BNE FAIL
JMP $2000 ; JUMP TO LOADED SYSTEM COMMAND
;
; PRINT FAIL MESSAGE, WAIT FOR KEYPRESS, AND REBOOT
;
FAIL INC $3F4 ; INVALIDATE POWER-UP BYTE
LDY #$01
- LDA FAILMSG,Y
ORA #$80
JSR $FDED
INY
CPY FAILMSG
BNE -
JSR $FD0C ; WAIT FOR KEYPRESS
JMP ($FFFC) ; RESET
OPENPARMS !BYTE 3
!WORD STRBUF
!WORD $0800
REFNUM !BYTE 0
READPARMS !BYTE 4
!BYTE 0
!WORD $2000
!WORD $1100
!WORD 0
CLOSEPARMS !BYTE 1
!BYTE 0
DISABLE80 !BYTE 21, 13, '1', 26, 13 DISABLE80 !BYTE 21, 13, '1', 26, 13
FAILMSG !BYTE 39
!TEXT "MISSING CMD. PRESS ANY KEY TO RESET..."
ENDBYE = *
} }
;* ;*
;* ENTER INTO BYTECODE INTERPRETER ;* ENTER INTO BYTECODE INTERPRETER
@ -359,12 +336,12 @@ NEXTOPX INY
FETCHOPX LDA (IP),Y FETCHOPX LDA (IP),Y
STA *+4 STA *+4
JMP (OPXTBL) ; USE AUX OPCODES JMP (OPXTBL) ; USE AUX OPCODES
TIMERX STA ALTRDOFF ;TIMERX STA ALTRDOFF
CLI ; CLI
JSR JMPTMR ; JSR JMPTMR
SEI ; SEI
STA ALTRDON ; STA ALTRDON
JMP FETCHOPX ; JMP FETCHOPX
;* ;*
;* INTERP BYTECODE IN MAIN MEM ;* INTERP BYTECODE IN MAIN MEM
;* ;*
@ -379,8 +356,8 @@ FETCHOP LDA (IP),Y
ORA #$80 ; USE MAIN OPCODES ORA #$80 ; USE MAIN OPCODES
STA *+4 STA *+4
JMP (OPTBL) JMP (OPTBL)
TIMER JSR JMPTMR ;TIMER JSR JMPTMR
JMP FETCHOP ; JMP FETCHOP
;* ;*
;* INDIRECT JUMP TO (TMRVEC) ;* INDIRECT JUMP TO (TMRVEC)
;* ;*

View File

@ -1,10 +1,11 @@
import stdlib import stdlib
predef cls, gotoxy, viewport, putc, puts, getc, gets predef putc, putln, puts, getc, gets
predef call, syscall predef call, syscall
predef heapmark, heapallocallign, heapalloc, heaprelease, heapavail predef heapmark, heapallocallign, heapalloc, heaprelease, heapavail
predef memset, memcpy predef memset, memcpy
predef isugt, isuge, isult, isule predef isugt, isuge, isult, isule
predef load, exec predef load, exec
word MACHID, sysvars
; ;
; System flags: memory allocator screen holes. ; System flags: memory allocator screen holes.
; ;

View File

@ -9,7 +9,13 @@ include(testlib.plh)
; Declare all global variables for this module. ; Declare all global variables for this module.
; ;
byte hello[] = "Hello, world.\n" byte hello[] = "Hello, Apple "
byte a1[] = "1"
byte a2[] = "]["
byte a2p[] = "][+"
byte a2e[] = "//e"
byte a2c[] = "//c"
byte a3[] = "///"
word struct[] = 1, 10, 100, 1000, 10000 word struct[] = 1, 10, 100, 1000, 10000
byte spaces[] = " " byte spaces[] = " "
@ -47,14 +53,28 @@ def nums(range)
end end
export def main(range) export def main(range)
cls
nums(*range) nums(*range)
tens(*range*10) tens(*range*10)
viewport(12, 12, 16, 8)
ascii ascii
viewport(0, 0, 40, 24) putln
gotoxy(15,5)
puts(@hello) puts(@hello)
when MACHID & $C8
is $08
puts(@a1)
is $00
puts(@a2)
is $40
puts(@a2p)
is $80
puts(@a2e)
is $88
puts(@a2c)
is $C0
puts(@a3)
otherwise
putc('?')
wend
putln
end end
main(@struct:6) main(@struct:6)

View File

@ -38,10 +38,6 @@ export def puti(i)
fin fin
end end
export def putln
putc($0D)
end
puts(@loadstr) puts(@loadstr)
putln putln
done done