From 37d61c8fb0c28b384fc68ca59e2055a136eccf77 Mon Sep 17 00:00:00 2001 From: neauoire Date: Fri, 24 Nov 2023 11:02:36 -0800 Subject: [PATCH] Printing program content --- build.sh | 2 +- etc/listen.tal | 13 ++++++++ src/porporo.c | 80 ++++++++++++++++++++++++++++++++++---------------- src/uxn.c | 2 ++ src/uxn.h | 1 + 5 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 etc/listen.tal diff --git a/build.sh b/build.sh index 98a8a18..354c7c2 100755 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr # roms cc src/uxnasm.c -o bin/uxnasm bin/uxnasm etc/hello.tal bin/hello.rom - +bin/uxnasm etc/listen.tal bin/listen.rom # run ./bin/porporo \ No newline at end of file diff --git a/etc/listen.tal b/etc/listen.tal new file mode 100644 index 0000000..c7b019a --- /dev/null +++ b/etc/listen.tal @@ -0,0 +1,13 @@ +|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 + +|0100 ( -> ) + + ;on-console .Console/vector DEO2 + +BRK + +@on-console ( -> ) + + .Console/read DEI #18 DEO + +BRK diff --git a/src/porporo.c b/src/porporo.c index c19d2db..e60c43e 100644 --- a/src/porporo.c +++ b/src/porporo.c @@ -20,8 +20,6 @@ WITH REGARD TO THIS SOFTWARE. #define PAD 2 #define SZ (HOR * VER * 16) -typedef unsigned char Uint8; - typedef struct Connection { Uint8 ap, bp; struct Program *a, *b; @@ -139,13 +137,13 @@ static Uint32 *pixels; #pragma mark - Helpers -static int +int distance(Point2d a, Point2d b) { return (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y); } -static Point2d * +Point2d * setpt2d(Point2d *p, int x, int y) { p->x = x; @@ -153,13 +151,13 @@ setpt2d(Point2d *p, int x, int y) return p; } -static Point2d * +Point2d * clamp2d(Point2d *p, int step) { return setpt2d(p, p->x / step * step, p->y / step * step); } -static Point2d +Point2d Pt2d(int x, int y) { Point2d p; @@ -278,13 +276,25 @@ drawtext(Uint32 *dst, int x, int y, char *t, int color) drawicn(dst, x += 8, y, &font[(c - 0x20) << 3], color); } +static char +nibble(Uint8 v) +{ + return v > 0x9 ? 'a' + v - 10 : '0' + v; +} + static void drawbyte(Uint32 *dst, int x, int y, Uint8 byte, int color) { - int hb = '0' - 0x20 + (byte >> 0x4); - int lb = '0' - 0x20 + (byte & 0xf); - drawicn(dst, x += 8, y, &font[hb << 3], color); - drawicn(dst, x += 8, y, &font[lb << 3], color); + drawicn(dst, x += 8, y, &font[(nibble(byte >> 4) - 0x20) << 3], color); + drawicn(dst, x += 8, y, &font[(nibble(byte & 0xf) - 0x20) << 3], color); +} + +static void +drawpage(Uint32 *dst, int x, int y, Uint8 *r) +{ + int i; + for(i = 0; i < 0x8; i++) + drawbyte(dst, x + (i * 0x18), y, r[i], 3); } static void @@ -298,6 +308,7 @@ drawprogram(Uint32 *dst, Program *p) drawicn(dst, p->x + p->w, p->y, icons[0], 2); drawbyte(dst, p->x - 8, p->y - 9, 0x12, 3); drawbyte(dst, p->x + p->w - 8, p->y - 9, 0x18, 3); + drawpage(dst, p->x, p->y + 0x10, &p->u.ram[0x100]); } static void @@ -467,7 +478,9 @@ addprogram(int x, int y, int w, int h, char *rom) Program *p = &programs[plen++]; p->x = x, p->y = y, p->w = w, p->h = h, p->rom = rom; p->u.ram = ram + (plen - 1) * 0x10000; + p->u.id = plen - 1; system_init(&p->u, ram, rom); + uxn_eval(&p->u, 0x100); return p; } @@ -479,13 +492,13 @@ connectports(Program *a, Program *b, Uint8 ap, Uint8 bp) c->a = a, c->b = b; } -Program *currentprogram; - Uint8 emu_dei(Uxn *u, Uint8 addr) { + Program *prg = &programs[u->id]; + printf("?????\n"); switch(addr & 0xf0) { - case 0x10: printf("!! input from %s\n", currentprogram->rom); break; + case 0x10: printf("<< %s\n", prg->rom); break; } return u->dev[addr]; } @@ -494,9 +507,25 @@ void emu_deo(Uxn *u, Uint8 addr, Uint8 value) { Uint8 p = addr & 0x0f, d = addr & 0xf0; + Program *prg = &programs[u->id]; u->dev[addr] = value; + + if(!u->id) { + printf("PORPORO\n"); + } + switch(d) { - case 0x10: printf("!! output from %s\n", currentprogram->rom); break; + case 0x10: { + Program *tprg = prg->out[0].b; + if(tprg) { + Uint16 vector = (tprg->u.dev[0x10] << 8) | tprg->u.dev[0x11]; + tprg->u.dev[0x12] = value; + if(vector) { + printf(">> %s to %s [%04x]\n", prg->rom, tprg->rom, vector); + uxn_eval(&tprg->u, vector); + } + } + } break; } } @@ -506,7 +535,7 @@ main(int argc, char **argv) Uint32 begintime = 0; Uint32 endtime = 0; Uint32 delta = 0; - Program *a, *b, *c, *d, *e; + Program *a, *listen, *c, *d, *hello, *f, *porporo; (void)argc; (void)argv; @@ -518,21 +547,22 @@ main(int argc, char **argv) if(!init()) return error("Init", "Failure"); + porporo = addprogram(550, 350, 140, 20, "bin/porporo.rom"); + a = addprogram(150, 30, 120, 120, "console.rom"); - b = addprogram(320, 120, 120, 120, "print.rom"); + listen = addprogram(520, 120, 140, 140, "bin/listen.rom"); c = addprogram(10, 130, 100, 70, "keyb.rom"); d = addprogram(190, 170, 100, 80, "debug.rom"); + hello = addprogram(300, 300, 140, 140, "bin/hello.rom"); - e = addprogram(300, 300, 160, 160, "bin/hello.rom"); - - connectports(a, b, 0x12, 0x18); + connectports(hello, listen, 0x12, 0x18); connectports(c, a, 0x12, 0x18); - connectports(d, b, 0x12, 0x18); - - /* eval program */ - currentprogram = e; - uxn_eval(&e->u, 0x100); - + + connectports(listen, porporo, 0x12, 0x18); + + uxn_eval(&hello->u, 0x100); + + printf("%c\n", nibble(0xe)); while(1) { SDL_Event event; diff --git a/src/uxn.c b/src/uxn.c index 9efac2a..873b9a5 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -39,10 +39,12 @@ uxn_eval(Uxn *u, Uint16 pc) { Uint16 t, n, l, r; Uint8 *ram = u->ram, *rr; + printf("eval: %04x\n", pc); if(!pc || u->dev[0x0f]) return 0; for(;;) { Uint8 ins = ram[pc++]; Stack *s = ins & 0x40 ? &u->rst : &u->wst; + printf("- %02x\n", ins); switch(ins & 0x3f) { /* IMM */ case 0x00: case 0x20: diff --git a/src/uxn.h b/src/uxn.h index 04f4aa5..a311140 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -31,6 +31,7 @@ typedef struct { typedef struct Uxn { Uint8 *ram, dev[0x100]; Stack wst, rst; + Uint16 id; } Uxn; /* required functions */