From e522eeb7a5d2e39d5c58d2d3971c859f723f399d Mon Sep 17 00:00:00 2001 From: neauoire Date: Fri, 25 Aug 2023 10:15:57 -0700 Subject: [PATCH] Basic link implementation --- etc/link.tal | 17 +++++++---------- src/devices/link.c | 28 ++++++++++++++-------------- src/devices/link.h | 2 +- src/uxncli.c | 2 +- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/etc/link.tal b/etc/link.tal index dbd303d..f6c449e 100644 --- a/etc/link.tal +++ b/etc/link.tal @@ -4,12 +4,11 @@ ;task1 #f0 DEO2 ;task2 #f2 DEO2 - #0000 #f0 DEO2k INC INC DEO2 - #010e DEO + ;end-txt print-text #800f DEO -BRK +BRK @task1 ( -> ) ;t1 print-text @@ -20,13 +19,11 @@ BRK BRK @print-text ( str* -- ) - - &while - ( send ) LDAk .Console/write DEO - ( loop ) INC2 LDAk ?&while + ( send ) LDAk .Console/write DEO + ( loop ) INC2 LDAk ?print-text POP2 - JMP2r -@t1 "Text1 00 -@t2 "Text2 00 +@t1 "AAAAAAAAAAAAAAAA 00 +@t2 "BBBBBBBBBBBBBBBB 00 +@end-txt 0a "Done. 0a diff --git a/src/devices/link.c b/src/devices/link.c index 67999c8..8d200e5 100644 --- a/src/devices/link.c +++ b/src/devices/link.c @@ -16,7 +16,7 @@ WITH REGARD TO THIS SOFTWARE. */ pthread_t threads[8]; -static int args[8]; +static int tids[8]; static Uint16 link_vectors[8]; static Uint8 *link_ram; @@ -26,26 +26,27 @@ static void { int tid = *((int *)x); Uxn u; + Uint16 vector = link_vectors[tid]; u.ram = link_ram; - printf("eval %d #%04x\n", tid, link_vectors[tid]); + u.wst.ptr = u.rst.ptr = 0; uxn_eval(&u, link_vectors[tid]); + threads[tid] = 0; + link_vectors[tid] = 0; return NULL; } static void link_init(Uint8 *ram, int id, Uint16 vector) { - printf("init %d #%04x\n", id, vector); - args[id] = id; + tids[id] = id; link_vectors[id] = vector; link_ram = ram; - pthread_create(&threads[id], NULL, link_eval, (void *)&args[id]); + pthread_create(&threads[id], NULL, link_eval, (void *)&tids[id]); } static void link_wait(int id) { - printf("wait %d\n", id); pthread_join(threads[id], NULL); threads[id] = 0; } @@ -53,18 +54,17 @@ link_wait(int id) Uint8 link_dei(Uxn *u, Uint8 addr) { + /* TODO: return non-zero if active */ return 0; } void link_deo(Uint8 *ram, Uint8 *d, Uint8 port) { - if(port & 0x1) { - Uint8 id = port >> 0x1; - Uint16 vector = PEEK2(d + port - 1); - if(threads[id]) - link_wait(id); - if(vector) - link_init(ram, id, vector); - } + Uint8 id = port >> 0x1; + Uint16 vector = PEEK2(d + port - 1); + if(threads[id]) + link_wait(id); + if(vector) + link_init(ram, id, vector); } diff --git a/src/devices/link.h b/src/devices/link.h index 9939f24..0cba46c 100644 --- a/src/devices/link.h +++ b/src/devices/link.h @@ -14,4 +14,4 @@ WITH REGARD TO THIS SOFTWARE. #define LINK_DEOMASK 0xaaaa Uint8 link_dei(Uxn *u, Uint8 addr); -void link_deo(Uxn *u, Uint8 *d, Uint8 port); +void link_deo(Uint8 *ram, Uint8 *d, Uint8 port); diff --git a/src/uxncli.c b/src/uxncli.c index d6536bf..a0487cb 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -39,7 +39,7 @@ emu_deo(Uxn *u, Uint8 addr) case 0x10: console_deo(&u->dev[d], p); break; case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break; case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break; - case 0xf0: link_deo(u, &u->dev[d], p); break; + case 0xf0: link_deo(u->ram, &u->dev[d], p); break; } }