commit bd976ce
neauoire
·
2023-08-25 16:18:37 +0000 UTC
parent 0ed2617
Boilerplate threads
3 files changed,
+78,
-0
+32,
-0
1@@ -0,0 +1,32 @@
2+|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
3+
4+|0100
5+
6+ ;task1 #f0 DEO2
7+ ;task2 #f2 DEO2
8+
9+ #0000 #f0 DEO2k INC INC DEO2
10+ #010e DEO
11+ #800f DEO
12+
13+BRK
14+
15+@task1 ( -> )
16+ ;t1 print-text
17+BRK
18+
19+@task2 ( -> )
20+ ;t2 print-text
21+BRK
22+
23+@print-text ( str* -- )
24+
25+ &while
26+ ( send ) LDAk .Console/write DEO
27+ ( loop ) INC2 LDAk ?&while
28+ POP2
29+
30+JMP2r
31+
32+@t1 "Text1 00
33+@t2 "Text2 00
M
makefile
+3,
-0
1@@ -15,6 +15,9 @@ rom:
2 @ ./bin/uxnasm etc/polycat.tal bin/polycat.rom
3 run: bin/uxnasm bin/uxncli bin/uxn11 rom
4 @ ./bin/uxn11 bin/polycat.rom
5+cli: bin/uxnasm bin/uxncli
6+ @ ./bin/uxnasm etc/link.tal bin/link.rom
7+ @ ./bin/uxncli bin/link.rom
8 test: bin/uxnasm bin/uxncli bin/uxn11
9 @ ./bin/uxnasm && ./bin/uxncli && ./bin/uxn11 && ./bin/uxnasm -v && ./bin/uxncli -v && ./bin/uxn11 -v
10 install: bin/uxnasm bin/uxncli bin/uxn11
+43,
-0
1@@ -15,6 +15,41 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
2 WITH REGARD TO THIS SOFTWARE.
3 */
4
5+pthread_t threads[8];
6+static int args[8];
7+static Uint16 link_vectors[8];
8+static Uint8 *link_ram;
9+
10+static void
11+ *
12+ link_eval(void *x)
13+{
14+ int tid = *((int *)x);
15+ Uxn u;
16+ u.ram = link_ram;
17+ printf("eval %d #%04x\n", tid, link_vectors[tid]);
18+ uxn_eval(&u, link_vectors[tid]);
19+ return NULL;
20+}
21+
22+static void
23+link_init(Uint8 *ram, int id, Uint16 vector)
24+{
25+ printf("init %d #%04x\n", id, vector);
26+ args[id] = id;
27+ link_vectors[id] = vector;
28+ link_ram = ram;
29+ pthread_create(&threads[id], NULL, link_eval, (void *)&args[id]);
30+}
31+
32+static void
33+link_wait(int id)
34+{
35+ printf("wait %d\n", id);
36+ pthread_join(threads[id], NULL);
37+ threads[id] = 0;
38+}
39+
40 Uint8
41 link_dei(Uxn *u, Uint8 addr)
42 {
43@@ -24,4 +59,12 @@ link_dei(Uxn *u, Uint8 addr)
44 void
45 link_deo(Uint8 *ram, Uint8 *d, Uint8 port)
46 {
47+ if(port & 0x1) {
48+ Uint8 id = port >> 0x1;
49+ Uint16 vector = PEEK2(d + port - 1);
50+ if(threads[id])
51+ link_wait(id);
52+ if(vector)
53+ link_init(ram, id, vector);
54+ }
55 }