diff --git a/etc/link.tal b/etc/link.tal new file mode 100644 index 0000000..dbd303d --- /dev/null +++ b/etc/link.tal @@ -0,0 +1,32 @@ +|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 + +|0100 + + ;task1 #f0 DEO2 + ;task2 #f2 DEO2 + + #0000 #f0 DEO2k INC INC DEO2 + #010e DEO + #800f DEO + +BRK + +@task1 ( -> ) + ;t1 print-text +BRK + +@task2 ( -> ) + ;t2 print-text +BRK + +@print-text ( str* -- ) + + &while + ( send ) LDAk .Console/write DEO + ( loop ) INC2 LDAk ?&while + POP2 + +JMP2r + +@t1 "Text1 00 +@t2 "Text2 00 diff --git a/makefile b/makefile index 29434aa..69b43ff 100644 --- a/makefile +++ b/makefile @@ -15,6 +15,9 @@ rom: @ ./bin/uxnasm etc/polycat.tal bin/polycat.rom run: bin/uxnasm bin/uxncli bin/uxn11 rom @ ./bin/uxn11 bin/polycat.rom +cli: bin/uxnasm bin/uxncli + @ ./bin/uxnasm etc/link.tal bin/link.rom + @ ./bin/uxncli bin/link.rom test: bin/uxnasm bin/uxncli bin/uxn11 @ ./bin/uxnasm && ./bin/uxncli && ./bin/uxn11 && ./bin/uxnasm -v && ./bin/uxncli -v && ./bin/uxn11 -v install: bin/uxnasm bin/uxncli bin/uxn11 diff --git a/src/devices/link.c b/src/devices/link.c index c80501c..67999c8 100644 --- a/src/devices/link.c +++ b/src/devices/link.c @@ -15,6 +15,41 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +pthread_t threads[8]; +static int args[8]; +static Uint16 link_vectors[8]; +static Uint8 *link_ram; + +static void + * + link_eval(void *x) +{ + int tid = *((int *)x); + Uxn u; + u.ram = link_ram; + printf("eval %d #%04x\n", tid, link_vectors[tid]); + uxn_eval(&u, link_vectors[tid]); + return NULL; +} + +static void +link_init(Uint8 *ram, int id, Uint16 vector) +{ + printf("init %d #%04x\n", id, vector); + args[id] = id; + link_vectors[id] = vector; + link_ram = ram; + pthread_create(&threads[id], NULL, link_eval, (void *)&args[id]); +} + +static void +link_wait(int id) +{ + printf("wait %d\n", id); + pthread_join(threads[id], NULL); + threads[id] = 0; +} + Uint8 link_dei(Uxn *u, Uint8 addr) { @@ -24,4 +59,12 @@ link_dei(Uxn *u, Uint8 addr) 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); + } }