commit e522eeb
neauoire
·
2023-08-25 17:15:57 +0000 UTC
parent 618212a
Basic link implementation
4 files changed,
+23,
-26
+7,
-10
1@@ -4,12 +4,11 @@
2
3 ;task1 #f0 DEO2
4 ;task2 #f2 DEO2
5-
6 #0000 #f0 DEO2k INC INC DEO2
7- #010e DEO
8+ ;end-txt print-text
9 #800f DEO
10
11-BRK
12+BRK
13
14 @task1 ( -> )
15 ;t1 print-text
16@@ -20,13 +19,11 @@ BRK
17 BRK
18
19 @print-text ( str* -- )
20-
21- &while
22- ( send ) LDAk .Console/write DEO
23- ( loop ) INC2 LDAk ?&while
24+ ( send ) LDAk .Console/write DEO
25+ ( loop ) INC2 LDAk ?print-text
26 POP2
27-
28 JMP2r
29
30-@t1 "Text1 00
31-@t2 "Text2 00
32+@t1 "AAAAAAAAAAAAAAAA 00
33+@t2 "BBBBBBBBBBBBBBBB 00
34+@end-txt 0a "Done. 0a
+14,
-14
1@@ -16,7 +16,7 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 pthread_t threads[8];
5-static int args[8];
6+static int tids[8];
7 static Uint16 link_vectors[8];
8 static Uint8 *link_ram;
9
10@@ -26,26 +26,27 @@ static void
11 {
12 int tid = *((int *)x);
13 Uxn u;
14+ Uint16 vector = link_vectors[tid];
15 u.ram = link_ram;
16- printf("eval %d #%04x\n", tid, link_vectors[tid]);
17+ u.wst.ptr = u.rst.ptr = 0;
18 uxn_eval(&u, link_vectors[tid]);
19+ threads[tid] = 0;
20+ link_vectors[tid] = 0;
21 return NULL;
22 }
23
24 static void
25 link_init(Uint8 *ram, int id, Uint16 vector)
26 {
27- printf("init %d #%04x\n", id, vector);
28- args[id] = id;
29+ tids[id] = id;
30 link_vectors[id] = vector;
31 link_ram = ram;
32- pthread_create(&threads[id], NULL, link_eval, (void *)&args[id]);
33+ pthread_create(&threads[id], NULL, link_eval, (void *)&tids[id]);
34 }
35
36 static void
37 link_wait(int id)
38 {
39- printf("wait %d\n", id);
40 pthread_join(threads[id], NULL);
41 threads[id] = 0;
42 }
43@@ -53,18 +54,17 @@ link_wait(int id)
44 Uint8
45 link_dei(Uxn *u, Uint8 addr)
46 {
47+ /* TODO: return non-zero if active */
48 return 0;
49 }
50
51 void
52 link_deo(Uint8 *ram, Uint8 *d, Uint8 port)
53 {
54- if(port & 0x1) {
55- Uint8 id = port >> 0x1;
56- Uint16 vector = PEEK2(d + port - 1);
57- if(threads[id])
58- link_wait(id);
59- if(vector)
60- link_init(ram, id, vector);
61- }
62+ Uint8 id = port >> 0x1;
63+ Uint16 vector = PEEK2(d + port - 1);
64+ if(threads[id])
65+ link_wait(id);
66+ if(vector)
67+ link_init(ram, id, vector);
68 }
+1,
-1
1@@ -14,4 +14,4 @@ WITH REGARD TO THIS SOFTWARE.
2 #define LINK_DEOMASK 0xaaaa
3
4 Uint8 link_dei(Uxn *u, Uint8 addr);
5-void link_deo(Uxn *u, Uint8 *d, Uint8 port);
6+void link_deo(Uint8 *ram, Uint8 *d, Uint8 port);
+1,
-1
1@@ -39,7 +39,7 @@ emu_deo(Uxn *u, Uint8 addr)
2 case 0x10: console_deo(&u->dev[d], p); break;
3 case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
4 case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break;
5- case 0xf0: link_deo(u, &u->dev[d], p); break;
6+ case 0xf0: link_deo(u->ram, &u->dev[d], p); break;
7 }
8 }
9