commit f7428b37836cb89392527bf1d28303e33a3be72b
parent 2409dc0ad0c0419f4560427bbe8c65c86a5fc6b7
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Wed, 7 Dec 2022 19:27:00 -0500
asm/uxntal: working!
Diffstat:
9 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/fs/asm/uxntal.c b/fs/asm/uxntal.c
@@ -74,7 +74,7 @@ error(char *name, char *msg)
static char *
sublabel(char *src, char *scope, char *name)
{
- return scat(scat(scpy(scope, src, $40), "/"), name);
+ return scat(scat(scpy(scope, src, $40), "/"0), name);
}
static Macro *
@@ -154,6 +154,7 @@ makemacro(char *name, int hdl)
return error("Macros limit exceeded", name);
m = &p.macros[p.mlen++];
scpy(name, m->name, $40);
+ m->len = 0;
while(freadword(word, hdl) == 1) {
if(word[0] == '{') continue;
if(word[0] == '}') break;
@@ -161,7 +162,7 @@ makemacro(char *name, int hdl)
return error("Macro error", name);
if(m->len >= $40)
return error("Macro size exceeded", name);
- scpy(word, m->items[m->len++], $40);
+ scpy(word, &m->items[(m->len++)*$40], $40);
}
return 1;
}
@@ -236,14 +237,14 @@ static int
writeshort(Uint16 s, int lit)
{
if(lit)
- if(!writebyte(findopcode("LIT2"))) return 0;
+ if(!writebyte(findopcode("LIT2"0))) return 0;
return writebyte(s >> 8) && writebyte(s & $ff);
}
static int
writelitbyte(Uint8 b)
{
- if(!writebyte(findopcode("LIT"))) return 0;
+ if(!writebyte(findopcode("LIT"0))) return 0;
if(!writebyte(b)) return 0;
return 1;
}
@@ -368,7 +369,7 @@ parse(char *w, int hdl)
/* macro */
else if((m = findmacro(w))) {
for(i = 0; i < m->len; i++)
- if(!parse(m->items[i], hdl))
+ if(!parse(&m->items[i*$40], hdl))
return 0;
return 1;
} else
@@ -378,7 +379,7 @@ parse(char *w, int hdl)
}
static int
-resolve(void)
+resolve()
{
Label *l;
int i;
@@ -440,7 +441,7 @@ static int
assemble(int hdl)
{
char w[$40];
- scpy("on-reset", p.scope, $40);
+ scpy("on-reset"0, p.scope, $40);
while(freadword(w, hdl) == 1)
if(!parse(w, hdl))
return error("Unknown token", w);
@@ -455,7 +456,7 @@ review()
if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z')
continue; /* Ignore capitalized labels(devices) */
else if(!p.labels[i].refs)
- fprintf(p.labels[i].name, "-- Unused label: %s\n", ConsoleOut());
+ fprintf(p.labels[i].name, "-- Unused label: %z\n", ConsoleOut());
fprintf(
p.mlen, p.llen, p.length-TRIM,
"Assembled %d bytes, %d labels, %d macros.\n", ConsoleOut());
@@ -466,9 +467,10 @@ uxntal(int srchdl)
{
p.llen = (p.mlen = (p.rlen = (p.length = (p.ptr = 0))));
if(!assemble(srchdl))
- return !error("Assembly", "Failed to assemble rom.");
- if(p.length <= TRIM)
- return !error("Assembly", "Output rom is empty.");
+ return !error("Assembly", "Failed to assemble rom."0);
+ if(p.length <= TRIM)
+ return !error("Assembly", "Output rom is empty."0);
fwrite(p.data + TRIM, p.length - TRIM, StdOut());
+ review();
return 0;
}
diff --git a/fs/comp/c/lib.fs b/fs/comp/c/lib.fs
@@ -7,8 +7,12 @@
\ A few system word proxies
:c void abort();
:c void quit();
+:c int rcnt();
+:c int scnt();
:c unsigned int min(unsigned int a, unsigned int b);
:c unsigned int max(unsigned int a, unsigned int b);
+:c void dump(int addr);
+:c void emit(char c);
:c void stype(char *str);
:c int StdIn();
:c int StdOut();
diff --git a/fs/tests/emul/uxn/deideo.bin b/fs/tests/emul/uxn/deideo.bin
Binary files differ.
diff --git a/fs/tests/emul/uxn/fib.bin b/fs/tests/emul/uxn/fib.bin
Binary files differ.
diff --git a/fs/tests/emul/uxn/file.bin b/fs/tests/emul/uxn/file.bin
Binary files differ.
diff --git a/fs/tests/emul/uxn/hello.bin b/fs/tests/emul/uxn/hello.bin
Binary files differ.
diff --git a/fs/tests/emul/uxn/hexfmt.bin b/fs/tests/emul/uxn/hexfmt.bin
Binary files differ.
diff --git a/fs/tests/emul/uxn/tests.bin b/fs/tests/emul/uxn/tests.bin
Binary files differ.
diff --git a/fs/tests/emul/uxn/vm.fs b/fs/tests/emul/uxn/vm.fs
@@ -5,19 +5,17 @@
?f<< /asm/uxntal.fs
testbegin
\ Testing uxn VM
-\ StdOut DumpIO :new to StdOut
-\ TODO: doesn't match with hello.bin, but at least it doesn't crash!
-\ S" /tests/emul/uxn/hello.tal" curpath :find# Path :open dup uxntal 0 #eq
-\ stdio$
-\ Compiled from dummy.tal with uxn's official assembler
+uxn_ram MemIO :new structbind MemIO _memio
: _load ( path -- )
- uxn_ram $100 + swap curpath :find# Path :open tuck File :readall File :close ;
-S" /tests/emul/uxn/hello.bin" _load
+ uxn_ram $100 + to _memio ptr
+ _memio :self to StdOut
+ curpath :find# Path :open dup uxntal stdio$ 0 #eq File :close ;
+S" /tests/emul/uxn/hello.tal" _load
varvara_init
capture uxn_exec
S" Hello World!" #s=
-S" /tests/emul/uxn/fib.bin" _load
+S" /tests/emul/uxn/fib.tal" _load
varvara_init
create expected 47 nc,
46 $00 $01 $00 $02 $00 $03 $00 $05 $00 $08 $00 $0d $00 $15 $00 $22 $00 $37
@@ -25,15 +23,15 @@ create expected 47 nc,
$1a $6d $2a $c2 $45 $2f $6f $f1 $b5 $20
capture uxn_exec expected 47 []= #
-S" /tests/emul/uxn/hexfmt.bin" _load
+S" /tests/emul/uxn/hexfmt.tal" _load
varvara_init
capture uxn_exec S" 1234abcd" #s=
-S" /tests/emul/uxn/tests.bin" _load
+S" /tests/emul/uxn/tests.tal" _load
varvara_init
capture uxn_exec S" X" #s=
-S" /tests/emul/uxn/deideo.bin" _load
+S" /tests/emul/uxn/deideo.tal" _load
varvara_init
capture uxn_exec Z S" Z" #s=
@@ -43,7 +41,7 @@ capture uxn_exec Z S" Z" #s=
512 TOTSEC RAMDrive :new value mydrv
mydrv BlobFS :mount value myfs
myfs filesystems CELLSZ + ! \ register it as "B:"
-S" /tests/emul/uxn/file.bin" _load
+S" /tests/emul/uxn/file.tal" _load
varvara_init
capture uxn_exec
S" 0011 HELLO.TXT\n" #s=