1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-08-08 09:25:19 +00:00
This commit is contained in:
David Schmenk
2025-01-06 10:29:14 -08:00
5 changed files with 79 additions and 87 deletions

View File

@@ -57,41 +57,41 @@ $(IIGSCONV): dhgr.tk/utils/gsfonconv.c
cc dhgr.tk/utils/gsfonconv.c -o dhgr.tk/utils/gsfonconv cc dhgr.tk/utils/gsfonconv.c -o dhgr.tk/utils/gsfonconv
$(DHGRLIB): dhgr.tk/libs/dhgrlib.pla dhgr.tk/inc/dhgrlib.plh $(DHGRLIB): dhgr.tk/libs/dhgrlib.pla dhgr.tk/inc/dhgrlib.plh
./plasm -AMOW dhgr.tk/libs/dhgrlib.pla ./xplasm -AMOW dhgr.tk/libs/dhgrlib.pla
acme --setpc 4094 -o $(DHGRLIB) dhgr.tk/libs/dhgrlib.a acme --setpc 4094 -o $(DHGRLIB) dhgr.tk/libs/dhgrlib.a
$(DHGRUTILS): dhgr.tk/libs/dhgrutils.pla $(DHGRLIB) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh $(DHGRUTILS): dhgr.tk/libs/dhgrutils.pla $(DHGRLIB) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh
./plasm -AMOW dhgr.tk/libs/dhgrutils.pla ./xplasm -AMOW dhgr.tk/libs/dhgrutils.pla
acme --setpc 4094 -o $(DHGRUTILS) dhgr.tk/libs/dhgrutils.a acme --setpc 4094 -o $(DHGRUTILS) dhgr.tk/libs/dhgrutils.a
$(DHGRTEST): dhgr.tk/test/dhgrtest.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh $(DHGRTEST): dhgr.tk/test/dhgrtest.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh
./plasm -AMOW dhgr.tk/test/dhgrtest.pla ./xplasm -AMOW dhgr.tk/test/dhgrtest.pla
acme --setpc 4094 -o $(DHGRTEST) dhgr.tk/test/dhgrtest.a acme --setpc 4094 -o $(DHGRTEST) dhgr.tk/test/dhgrtest.a
$(FONTTEST): dhgr.tk/test/fonttest.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh $(FONTTEST): dhgr.tk/test/fonttest.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh
./plasm -AMOW dhgr.tk/test/fonttest.pla ./xplasm -AMOW dhgr.tk/test/fonttest.pla
acme --setpc 4094 -o $(FONTTEST) dhgr.tk/test/fonttest.a acme --setpc 4094 -o $(FONTTEST) dhgr.tk/test/fonttest.a
$(DHGRSPRED): dhgr.tk/utils/dhgrspred.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh $(DHGRSPRED): dhgr.tk/utils/dhgrspred.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh
./plasm -AMOW dhgr.tk/utils/dhgrspred.pla ./xplasm -AMOW dhgr.tk/utils/dhgrspred.pla
acme --setpc 4094 -o $(DHGRSPRED) dhgr.tk/utils/dhgrspred.a acme --setpc 4094 -o $(DHGRSPRED) dhgr.tk/utils/dhgrspred.a
$(DHGREASY): dhgr.tk/utils/dhgreasy.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh $(DHGREASY): dhgr.tk/utils/dhgreasy.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh
./plasm -AMOW dhgr.tk/utils/dhgreasy.pla ./xplasm -AMOW dhgr.tk/utils/dhgreasy.pla
acme --setpc 4094 -o $(DHGREASY) dhgr.tk/utils/dhgreasy.a acme --setpc 4094 -o $(DHGREASY) dhgr.tk/utils/dhgreasy.a
$(DHGRSHOW): dhgr.tk/utils/dhgrshow.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh $(DHGRSHOW): dhgr.tk/utils/dhgrshow.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh
./plasm -AMOW dhgr.tk/utils/dhgrshow.pla ./xplasm -AMOW dhgr.tk/utils/dhgrshow.pla
acme --setpc 4094 -o $(DHGRSHOW) dhgr.tk/utils/dhgrshow.a acme --setpc 4094 -o $(DHGRSHOW) dhgr.tk/utils/dhgrshow.a
$(DLGRCONV): dhgr.tk/utils/dlgrconv.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh $(DLGRCONV): dhgr.tk/utils/dlgrconv.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh
./plasm -AMOW dhgr.tk/utils/dlgrconv.pla ./xplasm -AMOW dhgr.tk/utils/dlgrconv.pla
acme --setpc 4094 -o $(DLGRCONV) dhgr.tk/utils/dlgrconv.a acme --setpc 4094 -o $(DLGRCONV) dhgr.tk/utils/dlgrconv.a
$(DHGRRGB): dhgr.tk/utils/dhgrrgb.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh $(DHGRRGB): dhgr.tk/utils/dhgrrgb.pla $(DHGRLIB) $(DHGRUTILS) dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh
./plasm -AMOW dhgr.tk/utils/dhgrrgb.pla ./xplasm -AMOW dhgr.tk/utils/dhgrrgb.pla
acme --setpc 4094 -o $(DHGRRGB) dhgr.tk/utils/dhgrrgb.a acme --setpc 4094 -o $(DHGRRGB) dhgr.tk/utils/dhgrrgb.a
$(PENGUINS): dhgr.tk/demos/penguins/penguins.pla dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh $(PENGUINS): dhgr.tk/demos/penguins/penguins.pla dhgr.tk/inc/dhgrlib.plh dhgr.tk/inc/dhgrutils.plh
./plasm -AMOW dhgr.tk/demos/penguins/penguins.pla ./xplasm -AMOW dhgr.tk/demos/penguins/penguins.pla
acme --setpc 4094 -o $(PENGUINS) dhgr.tk/demos/penguins/penguins.a acme --setpc 4094 -o $(PENGUINS) dhgr.tk/demos/penguins/penguins.a

View File

@@ -57,25 +57,6 @@ word brkentry = 0
word brkcfa = 0 word brkcfa = 0
byte brk = 0 byte brk = 0
// //
// Machine code helper routines
//
byte _get_estack = $8A // TXA
byte = $49, $FF // EOR #$FF
byte = $38 // SEC
byte = $69, $20 // ADC #$20
byte = $C9, $21 // CMP #$21
byte = $90, $02 // BCC +2
byte = $A2, $20 // LDX #ESTKSZ/2
byte = $CA // DEX
byte = $95 // STA
byte _estkl = $C0 // ESTKL,X
byte = $A9, $00 // LDA #$00
byte = $95 // STA
byte _estkh = $A0 // ESTKH,X
byte = $60 // RTS
byte _reset_estack = $A2, $20 // LDX #ESTKSZ/2
byte = $60 // RTS
//
// FORTH dictionary layout // FORTH dictionary layout
// //
// bytes usage // bytes usage
@@ -126,6 +107,7 @@ predef _space_#0, _spaces_(a)#0, _see_#0, _prstack_#0, _prrstack_#0
predef _cont_#0, _restart_#0, _bye_#0, _quit_#0 predef _cont_#0, _restart_#0, _bye_#0, _quit_#0
predef _abort_(a)#0, _doabortstr_(a,b)#0, _abortstr_#0 predef _abort_(a)#0, _doabortstr_(a,b)#0, _abortstr_#0
predef _compword_(dentry)#0, _compliteral_(a)#0, _execword_(dentry)#0, _isnum_(a,b)#2 predef _compword_(dentry)#0, _compliteral_(a)#0, _execword_(dentry)#0, _isnum_(a,b)#2
predef _interpret_#0
// //
// Forth Vocabulary // Forth Vocabulary
// //
@@ -764,12 +746,43 @@ char d_words = "WORDS"
byte = showcr_flag byte = showcr_flag
word = @d_pbc, 0, @_words_ word = @d_pbc, 0, @_words_
// //
// Machine code helper routines
//
asm _get_estackdepth#1
!SOURCE "vmsrc/plvmzp.inc"
TXA
EOR #$FF
SEC
ADC #ESTKSZ/2
CMP #ESTKSZ/2+1
BCC +
LDX #ESTKSZ/2
+ DEX
STA ESTKL,X
LDA #$00
STA ESTKH,X
RTS
end
asm _get_estack(index)#1
LDA #ESTKSZ/2
CLC
SBC ESTKL,X
TAY
LDA ESTKL,Y
STA ESTKL,X
LDA ESTKH,Y
STA ESTKH,X
RTS
end
asm _reset_estack#0
LDX #ESTKSZ/2
end
asm _push(a)#0 // Stack hack - call as _push(a)to leave a on eval stack
RTS
end
//
// Helper routines // Helper routines
// //
predef _interpret_#0
def push(a)#1 // Stack hack - call as (@push)(a)#0 to leave a on eval stack
return a
end
def _dictaddw_(a)#0 def _dictaddw_(a)#0
*(heapalloc(2)) = a *(heapalloc(2)) = a
end end
@@ -875,7 +888,7 @@ end
// Warm start // Warm start
// //
def warmstart#0 def warmstart#0
(@_reset_estack)()#0 _reset_estack()
brk = 0 brk = 0
brkcfa = 0 brkcfa = 0
RSP = RSTK_SIZE RSP = RSTK_SIZE
@@ -909,7 +922,6 @@ def find(matchchars, matchlen)#1
matchchars-- matchchars--
while dentry while dentry
if ^dentry == matchlen if ^dentry == matchlen
for i = matchlen downto 1 for i = matchlen downto 1
if ^(matchchars + i) <> ^(dentry + i) if ^(matchchars + i) <> ^(dentry + i)
break break
@@ -1022,7 +1034,7 @@ def _execword_(dentry)#0
fin fin
W = _cfa_(dentry) W = _cfa_(dentry)
(*W)()#0 (*W)()#0
if (@_get_estack)()#1 > 32 if _get_estackdepth() > 32
puts("Stack over/underflow\n") puts("Stack over/underflow\n")
_quit_ _quit_
fin fin
@@ -1120,7 +1132,7 @@ def _interpret_#0
if state & comp_flag if state & comp_flag
_compliteral_(value) _compliteral_(value)
else else
(@push)(value)#0 _push(value)
fin fin
else else
inchars-- inchars--
@@ -1140,7 +1152,7 @@ def _swap_(a,b)#2
return b,a return b,a
end end
def _ifdup_(a)#1 def _ifdup_(a)#1
if a; (@push)(a)#0; fin if a; _push(a); fin
return a return a
end end
def _dup2_(a,b)#4 def _dup2_(a,b)#4
@@ -1312,7 +1324,7 @@ def _state_#1
return state & comp_flag return state & comp_flag
end end
def _dodoes_#0 def _dodoes_#0
(@push)(W + 11)#0 // Pointer to PFA storage _push(W + 11) // Pointer to PFA storage
execwords(*(W + 2)) // Exec PFA ptr execwords(*(W + 2)) // Exec PFA ptr
end end
def _itcdoes_(a)#0 def _itcdoes_(a)#0
@@ -1433,7 +1445,7 @@ def _semi_#0
if ^latest if ^latest
addhash(latest) // COLON definition addhash(latest) // COLON definition
else else
(@push)(latest)#0 // NONAME definition _push(latest) // NONAME definition
fin fin
state = state & ~comp_flag state = state & ~comp_flag
end end
@@ -1653,7 +1665,7 @@ def _tick_#0
if state & comp_flag if state & comp_flag
_compliteral_(dentry) _compliteral_(dentry)
else else
(@push)(dentry)#0 _push(dentry)
fin fin
end end
def _forget_#0 def _forget_#0
@@ -1731,7 +1743,7 @@ def _blank_#0
if state & comp_flag if state & comp_flag
_compliteral_(32) _compliteral_(32)
else else
(@push)(32)#0 _push(32)
fin fin
end end
def _char_#0 def _char_#0
@@ -1742,7 +1754,7 @@ def _char_#0
if state & comp_flag if state & comp_flag
_compliteral_(^str) _compliteral_(^str)
else else
(@push)(^str)#0 _push(^str)
fin fin
end end
def _str_#0 def _str_#0
@@ -1757,7 +1769,7 @@ def _str_#0
_compword_(@d_slit) _compword_(@d_slit)
memcpy(heapalloc(len), str, len) // Add to dictionary memcpy(heapalloc(len), str, len) // Add to dictionary
else else
(@push)(strbuf)#0 _push(strbuf)
memcpy(strbuf, str, len) // Copy to HERE memcpy(strbuf, str, len) // Copy to HERE
fin fin
end end
@@ -1942,13 +1954,13 @@ def _see_#0
fin fin
end end
def _prstack_#0 def _prstack_#0
word val byte index, depth
byte depth depth = _get_estackdepth()
index = 0
for depth = 1 to (@_get_estack)()#1 while index < depth
val = ^(_estkl + 32 - depth) | (^(_estkh + 32 - depth) << 8) puti(_get_estack(index)); putc(' ')
puti(val); putc(' ') index++
next loop
end end
def _prrstack_#0 def _prrstack_#0
byte depth byte depth
@@ -2126,8 +2138,6 @@ while latest
fin fin
latest = *_lfa_(latest) latest = *_lfa_(latest)
loop loop
_estkl = ^(@syscall + 1) // Hack to fill in parameter stack locations
_estkh = ^(@syscall + 3)
fileio:iobufalloc(4) // Allocate a bunch of file buffers fileio:iobufalloc(4) // Allocate a bunch of file buffers
strbuf = heapalloc(256) strbuf = heapalloc(256)
inbuf = heapalloc(SRCREFS * INBUF_SIZE) inbuf = heapalloc(SRCREFS * INBUF_SIZE)

View File

@@ -55,14 +55,14 @@ byte keypressed(M6502 *mpu)
{ {
if (!(keyqueue & 0x80)) if (!(keyqueue & 0x80))
{ {
read(STDIN_FILENO, &keyqueue, 1); if (read(STDIN_FILENO, &keyqueue, 1) > 0)
keyqueue |= 0x80; keyqueue |= 0x80;
} }
return keyqueue; return keyqueue;
} }
byte keyin(M6502 *mpu) byte keyin(M6502 *mpu)
{ {
byte cin = keyqueue & 0x7F; byte cin = keyqueue;
keyqueue = 0; keyqueue = 0;
while (!cin) while (!cin)
{ {
@@ -77,7 +77,7 @@ byte keyin(M6502 *mpu)
else else
usleep(10000); usleep(10000);
} }
return cin; return cin & 0x7F;
} }
void M6502_exec(M6502 *mpu) void M6502_exec(M6502 *mpu)
{ {
@@ -117,7 +117,7 @@ void setRawInput(void)
tcgetattr(STDIN_FILENO, &termio); // save current port settings tcgetattr(STDIN_FILENO, &termio); // save current port settings
memcpy(&org_tio, &termio, sizeof(struct termios)); memcpy(&org_tio, &termio, sizeof(struct termios));
termio.c_cflag = /*BAUDRATE | CRTSCTS |*/ CS8 | CLOCAL | CREAD; termio.c_cflag = /*BAUDRATE | CRTSCTS |*/ CS8 | CLOCAL | CREAD;
termio.c_iflag = IGNPAR; termio.c_iflag = BRKINT | IGNPAR;
termio.c_oflag = 0; termio.c_oflag = 0;
termio.c_lflag = 0; // set input mode (non-canonical, no echo,...) termio.c_lflag = 0; // set input mode (non-canonical, no echo,...)
termio.c_cc[VTIME] = 0; // inter-character timer unused termio.c_cc[VTIME] = 0; // inter-character timer unused
@@ -826,7 +826,7 @@ void export_cmdsys(void)
cmdsys = alloc_heap(23); cmdsys = alloc_heap(23);
stodci("CMDSYS", dci); add_sym(dci, cmdsys); stodci("CMDSYS", dci); add_sym(dci, cmdsys);
mem_6502[SYSPATH_STR] = strlen(strcat(getcwd((char *)mem_6502 + SYSPATH_BUF, 128), "/sys/")); mem_6502[SYSPATH_STR] = strlen(strcat(getcwd((char *)mem_6502 + SYSPATH_BUF, 128), "/sys/"));
mem_6502[cmdsys + 0] = 0x11; // Version 2.11 mem_6502[cmdsys + 0] = 0x20; // Version 2.20
mem_6502[cmdsys + 1] = 0x02; mem_6502[cmdsys + 1] = 0x02;
mem_6502[cmdsys + 2] = (byte)SYSPATH_STR; // syspath mem_6502[cmdsys + 2] = (byte)SYSPATH_STR; // syspath
mem_6502[cmdsys + 3] = (byte)(SYSPATH_STR >> 8); mem_6502[cmdsys + 3] = (byte)(SYSPATH_STR >> 8);

View File

@@ -62,7 +62,7 @@ typedef uint16_t address;
* 6502 memory map * 6502 memory map
*/ */
#define MEM6502_SIZE 0x00010000 #define MEM6502_SIZE 0x00010000
#define ESTK_SIZE 64 #define ESTK_SIZE 32
#define CMDLINE_STR 0x01FF #define CMDLINE_STR 0x01FF
#define CMDLINE_BUF 0x0200 #define CMDLINE_BUF 0x0200
#define SYSPATH_STR 0x0280 #define SYSPATH_STR 0x0280

View File

@@ -94,30 +94,18 @@ void sysputh(M6502 *mpu)
} }
void syskeypressed(M6502 *mpu) void syskeypressed(M6502 *mpu)
{ {
if (!(keyqueue & 0x80)) PUSH_ESTK(keypressed(mpu));
keypressed(mpu);
PUSH_ESTK(keyqueue);
} }
void sysgetc(M6502 *mpu) void sysgetc(M6502 *mpu)
{ {
char c; PUSH_ESTK(keyin(mpu));
//
// Push getchar()
//
if (keyqueue & 0x80)
{
c = keyqueue & 0x7F;
keyqueue = 0;
}
else
c = keyin(mpu);
PUSH_ESTK(c);
} }
void sysgets(M6502 *mpu) void sysgets(M6502 *mpu)
{ {
uword strptr; uword strptr;
int len; int len;
char cext[2], instr[256]; char cext[2], instr[256];
byte cin;
// //
// Push gets(), limiting it to 128 chars // Push gets(), limiting it to 128 chars
@@ -125,21 +113,15 @@ void sysgets(M6502 *mpu)
PULL_ESTK(cext[0]); PULL_ESTK(cext[0]);
putchar(cext[0] & 0x7F); putchar(cext[0] & 0x7F);
len = 0; len = 0;
if (keyqueue)
{
putchar(keyqueue & 0x7F);
instr[len++] = keyqueue & 0x7F;
keyqueue = 0;
}
fflush(stdout); fflush(stdout);
do do
{ {
switch (keyqueue = keyin(mpu)) switch (cin = keyin(mpu))
{ {
case 0x1B: case 0x1B:
if (read(STDIN_FILENO, cext, 2) == 2) if (read(STDIN_FILENO, cext, 2) == 2)
if (cext[0] == '[' && cext[1] == 'D') // Left arrow if (cext[0] == '[' && cext[1] == 'D') // Left arrow
keyqueue = 0x08; cin = 0x08;
else else
break; break;
else else
@@ -155,13 +137,13 @@ void sysgets(M6502 *mpu)
} }
break; break;
default: default:
if (keyqueue >= ' ') if (cin >= ' ')
putchar(instr[len++] = keyqueue); //if (cin >= ' ' || cin == 0x0D)
putchar(instr[len++] = cin);
} }
fflush(stdout); fflush(stdout);
} while (keyqueue != 0x0D && len < 128); } while (cin != 0x0D && len < 128);
sysputln(mpu); sysputln(mpu);
keyqueue = 0;
mem_6502[CMDLINE_STR] = len; mem_6502[CMDLINE_STR] = len;
memcpy(mem_6502 + CMDLINE_BUF, instr, len); memcpy(mem_6502 + CMDLINE_BUF, instr, len);
PUSH_ESTK(CMDLINE_STR); PUSH_ESTK(CMDLINE_STR);