duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit e42d6aa87edc32e58b67607c5e9dc077424b3b55
parent 62f26854035210cac81dd38ec84de8786c10b8d3
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Tue, 15 Nov 2022 13:49:39 -0500

app/uxn: add some stuff until a CC bug is hit

Diffstat:
Mfs/app/uxn/vm.c | 39+++++++++++++++++++++++++++++++++------
Mfs/tests/app/uxn/vm.fs | 10+++++++---
2 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/fs/app/uxn/vm.c b/fs/app/uxn/vm.c @@ -18,16 +18,43 @@ struct Device { void (*deo)(Device*, unsigned char); }; -// TODO: for debugging purposes during development, we omit "static" below. -unsigned char ram[$10000]; +// TODO: for debugging purposes during development, we sometimes omit "static". +static unsigned char ram[$10000]; // TODO: allow single line decl Stack wst; -Stack rst; -Device dev[$10]; -unsigned int errorcode; +static Stack rst; +static Device dev[$10]; + +static void error(int code) { + printf(code, "Error %d encountered\n"); + abort(); +} void push8(Stack *s, unsigned char val) { - if (s->ptr == $ff) { errorcode = 2; } else { s->dat[s->ptr++] = val; } + if (s->ptr == $ff) { error(2); } else { s->dat[s->ptr++] = val; } +} + +void push16(Stack *s, unsigned short val) { + if (s->ptr >= $fe) { error(2); } else { + s->dat[s->ptr] = val >> 8; + s->dat[s->ptr+1] = val; + s->ptr += 2 ; + } +} + +unsigned char pop8(Stack *s) { + if (!s->ptr) { error(0); } else { return s->dat[--s->ptr]; } +} + +unsigned short pop16(Stack *s) { + unsigned short val; + if (s->ptr <= 1) { error(0); } else { + s->ptr -= 2; + val = s->dat[s->ptr] << 8; + // TODO: this line below is broken in all arches + val |= s->dat[s->ptr+1]; + return val; + } } void uxn_init() { diff --git a/fs/tests/app/uxn/vm.fs b/fs/tests/app/uxn/vm.fs @@ -4,8 +4,12 @@ testbegin \ Testing uxn VM uxn_init wst 42 push8 -S" Stack" findTypedef CType :export -wst Stack ptr 1 #eq -wst Stack dat c@ 42 #eq +wst $1234 push16 +create expected 4 nc, 3 42 $12 $34 +wst expected 4 []= # +\ TODO: this line below is broken on i386 +\ wst pop8 $34 #eq +\ TODO: this line below is broken in all arches +\ wst pop16 $2a12 #eq testend