commit e191a16
Devine Lu Linvega
·
2023-05-01 05:03:35 +0000 UTC
parent 87a72de
Added multithreading port
4 files changed,
+248,
-9
M
build.sh
+10,
-6
1@@ -1,8 +1,8 @@
2 #!/bin/sh -e
3
4 RELEASE_FLAGS="-Os -DNDEBUG -g0 -s"
5-DEBUG_FLAGS="-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined"
6-CORE_DEVICES="src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c"
7+DEBUG_FLAGS="-std=c99 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined"
8+CORE_DEVICES="src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c -lpthread"
9 EMU_INC="${CORE_DEVICES} src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/uxn11.c -o bin/uxn11 -lX11"
10 CLI_INC="${CORE_DEVICES} src/uxncli.c -o bin/uxncli"
11
12@@ -32,16 +32,20 @@ then
13 gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${CLI_INC}
14 else
15 gcc ${C_FLAGS} ${LD_FLAGS} ${DEBUG_FLAGS} ${EMU_INC}
16- gcc ${C_FLAGS} ${LD_FLAGS} ${DEBUG_FLAGS} ${CLI_INC}
17+ gcc ${C_FLAGS} ${LD_FLAGS} ${DEBUG_FLAGS} ${CLI_INC}
18 fi
19
20 if [ "${1}" = '--install' ];
21 then
22 gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${EMU_INC}
23 gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${CLI_INC}
24- cp bin/uxn11 bin/uxnasm bin/uxncli $HOME/bin/
25+ cp bin/uxn11 bin/uxnemu
26+ cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/
27 fi
28
29-bin/uxnasm etc/polycat.tal bin/polycat.rom
30-bin/uxn11 bin/polycat.rom
31+# bin/uxnasm etc/polycat.tal bin/polycat.rom
32+# bin/uxn11 bin/polycat.rom
33+
34+bin/uxnasm etc/friend.tal bin/friend.rom
35+bin/uxn11 bin/friend.rom
36
+188,
-0
1@@ -0,0 +1,188 @@
2+|00 @System &vector $2 &expansion $2 &friend $2 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &halt $1
3+|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
4+
5+|0100
6+
7+ ( theme )
8+ #f0f7 .System/r DEO2
9+ #f00e .System/g DEO2
10+ #f00c .System/b DEO2
11+
12+ ;thread-a .System/friend DEO2
13+ ;thread-b .System/friend DEO2
14+ ;thread-c .System/friend DEO2
15+
16+ ( wait for threads to finish )
17+ #0000 .System/friend DEO2
18+
19+BRK
20+
21+@thread-a ( -> )
22+
23+ #0020 .Screen/x DEO2
24+ #0028 .Screen/y DEO2
25+ #1010 ;dafu10x10 #05 draw-fast
26+
27+BRK
28+
29+@thread-b ( -> )
30+
31+ #0070 .Screen/x DEO2
32+ #0040 .Screen/y DEO2
33+ #1010 ;dafu10x10 #0a draw-fast
34+
35+BRK
36+
37+@thread-c ( -> )
38+
39+ #00d0 .Screen/x DEO2
40+ #0048 .Screen/y DEO2
41+ #1010 ;dafu10x10 #0f draw-fast
42+
43+BRK
44+
45+@draw-fast ( w h addr* color -- )
46+
47+ ,&color STR
48+ .Screen/addr DEO2
49+ SWP #01 SUB #40 SFT #06 ORA .Screen/auto DEO
50+ #00 SWP SUB
51+ &loop
52+ ( self modification )
53+ [ LIT2 &color $1 -Screen/sprite ] DEO
54+ INC DUP ?&loop
55+ POP
56+
57+JMP2r
58+
59+@dafu10x10
60+ 0000 0000 0000 0000 0000 0000 0000 0000
61+ 0000 0000 0000 0000 0000 0000 0000 0000
62+ 0000 0000 0000 0001 0000 0000 010f 7fff
63+ 0000 002f ffff ffff 0000 00fd ffff ffff
64+ 0000 0000 e0fc ffff 0000 0000 0000 00e0
65+ 0000 0000 0000 0000 0000 0000 0000 0000
66+ 0000 0000 0000 0000 0000 0000 0000 0000
67+ 0000 0000 0000 0000 0000 0000 0000 0000
68+ 0000 0000 0000 0000 0000 0000 0000 0000
69+ 0000 0000 0000 0000 0000 0000 0107 071f
70+ 071f 3fff fffc f3cf ffff f8c7 3fff ffff
71+ e82f fbfb fbfb fbfb 02ff ffff ffff ffff
72+ bf41 feff ffff ffff fcff 1fe3 fcff ffff
73+ 00d0 fcff 7fd2 ffff 0000 00c0 f0f8 5efe
74+ 0000 0000 0000 0000 0000 0000 0000 0000
75+ 0000 0000 0000 0000 0000 0000 0000 0000
76+ 0000 0000 0000 0000 0000 0000 0000 0000
77+ 0000 0103 0f1f 3f7e 5f7e f9f3 cf9f 7fff
78+ 3f7f ffff ffff ffff ffff ffff ffff ffff
79+ f9fb fbf9 fdf9 fdfd ffff ffff ffff ffff
80+ ffff ffff ffff ffff ffff ffff ffff ffff
81+ ffff ffff ffff ffff ffff ffff feff fefe
82+ 0000 0000 0000 0000 0000 0000 0000 0000
83+ 0000 0000 0000 0000 0000 0000 0000 0000
84+ 0000 0000 0000 0000 0001 002f 1f1f 1f1f
85+ e907 ffff ffff ffff ffff ffff ffff ffff
86+ ffff ffff ffff ffff ffff ffff ffff ffff
87+ fdfd fdfd fcff fd45 ffff ffff ffff ed37
88+ ffff ffff ffff b76c ffff ffff ffff ff0b
89+ ffff ffff ffff ffff fefc fcfc f8fc f8f8
90+ 0000 0000 0000 0000 0000 0000 0000 0000
91+ 0000 0000 0000 0000 0000 0000 0000 0000
92+ 0000 0000 0000 0000 1f1f 1f0f 0f07 0703
93+ ffff ffff ffff ffff ffff ffff fffe fdf5
94+ ffff fceb 8fbf 7fff f48b 7fff ffff ffff
95+ bffe fefa f8fc fdff ffff 7f3f 3f7f bfff
96+ ffff ffff ffff ffff f8ff ffff ffff ffff
97+ 7fd7 ffff ffff ffff f0f0 f0e0 e0e0 e0e0
98+ 0000 0000 0000 0000 0000 0000 0000 0000
99+ 0000 0000 0000 0000 0000 0000 0000 0000
100+ 0000 0000 0000 0000 0301 0100 0000 0000
101+ ffff fffc 7d33 3f1f ef9f 7fff ffff ffff
102+ ffff ffff ffff f4cb ffff ffff e807 ffff
103+ ffff ffa0 00c0 0197 ffff 5007 1f03 5eff
104+ ffff a5ff ff6d bfff ffff 4de8 ff7f 6fff
105+ ffff ffbf a7fe fefe f0e0 f0e0 f0e0 b0d0
106+ 0000 0000 0000 0000 0000 0000 0000 0000
107+ 0000 0000 0000 0000 0000 0000 0000 0000
108+ 0000 0000 0000 0000 0000 0000 0000 0000
109+ 1f0f 0f0f 0f0e 0e12 fefa f5cf bfff ffff
110+ 3fff ffff ffff ffff ffff ffff ffff ffff
111+ f8e0 e0c0 e040 c040 7f7f 5f2f 7b1b 0f0f
112+ ffff ffff ffff ffff ffff ffff ffff ffff
113+ ffff fcfd fbf5 f9d4 50f0 f0e0 f0f0 e060
114+ 0000 0000 0000 0000 0000 0000 0000 0000
115+ 0000 0000 0000 0000 0000 0000 0000 0000
116+ 0000 0000 0000 0000 0000 0000 0000 0000
117+ 1a1a 150f 0d07 1100 7fff ffff fdff ffe1
118+ ffff ffff baff ff55 ffff ffaa fdff fe00
119+ c040 d708 f0eb a800 0fa6 7f2f 3fd0 021a
120+ d7bf fff7 086a b8b0 feff e914 a000 0000
121+ ab20 e078 0000 0000 e0c0 d6e1 4084 0204
122+ 0000 0000 0000 0000 0000 0000 0000 0000
123+ 0000 0000 0000 0000 0000 0000 0000 0000
124+ 0000 0000 0000 0000 0000 0000 0000 0000
125+ 0402 010a 0200 0000 7876 39b0 5078 9018
126+ 0892 71a9 2112 1210 aa00 ff01 7692 0000
127+ a01e 3628 8488 4484 a5a0 0000 0080 8000
128+ 2003 070d 3815 0260 feff 7b69 9e60 0000
129+ 90e0 8080 0000 0000 c004 8020 8890 8888
130+ 0000 0000 0000 0000 0000 0000 0000 0000
131+ 0000 0000 0000 0000 0000 0000 0000 0000
132+ 0000 0000 0000 0000 0000 0000 0000 0000
133+ 0300 0000 0000 0000 2848 8008 4428 0c04
134+ 1211 1201 1d14 2a29 1200 0016 dd55 22a9
135+ 4084 44ca 8a0d 5800 0000 0800 a02e d105
136+ 1000 0000 0080 6a11 0000 0000 0000 8865
137+ 0100 0100 0101 005e 2080 2040 4000 0000
138+ 0000 0000 0000 0000 0000 0000 0000 0000
139+ 0000 0000 0000 0000 0000 0000 0000 0000
140+ 0000 0000 0000 0000 0000 0000 0000 0000
141+ 0000 0000 0000 0000 0600 0a05 0303 0300
142+ 50a0 8040 8000 8000 0000 0000 0000 0000
143+ 0000 0000 0000 0000 0000 0000 0000 0000
144+ ad00 0000 0000 0000 510a 0000 0000 0000
145+ 2214 0002 0200 0406 0000 0000 0000 0080
146+ 0000 0000 0000 0000 0000 0000 0000 0000
147+ 0000 0000 0000 0000 0000 0000 0000 0000
148+ 0000 0000 0000 0000 0000 0000 0000 0000
149+ 0000 0000 0021 010f 0407 0812 2e5c de3e
150+ 4000 c060 f0f0 f878 0000 0000 0000 0000
151+ 0000 0000 0000 0000 0000 502d 0200 157f
152+ 0040 a000 0000 e0f8 0000 0000 0000 0000
153+ 060f 0f1f 1737 336b a01c e3f0 feff ffff
154+ 0000 407a 05c0 f0fc 0000 0000 807c 0300
155+ 0000 0000 0000 a05a 0000 0000 0000 0004
156+ 0000 0000 0000 030c 0001 0514 53a7 0f3f
157+ 265c 5df9 f3e7 c7cf fbfd fbfb fbfb fbfb
158+ 7c7e 7fbf bfff bfff 0000 0090 c0e0 f0f8
159+ 0101 0101 0001 0020 7fc8 ff1b c6f0 7f78
160+ fc5c ec08 b858 30e0 0108 0001 0103 0707
161+ 6b5b dbdf bbbf bb7f ffff ffff ffff ffff
162+ fefe fcfc f9f3 f3f7 6079 fffe fcfc f9f3
163+ 0540 823f 7fff ffff d02c 03f8 feff ffff
164+ 3040 800e 3f7f ffff 7f7f 7fff 7f7f 7f7f
165+ 9fdf 9f9f df9f 9fdf fbfb fbf3 fbfb fbfb
166+ efff fff7 fffd ffff fefe ffff ffff ff7f
167+ 0000 80e0 f0fc ffff 1f02 0000 0001 01e1
168+ c000 00a8 b050 590b 0f1f 1e7d 7dff ffff
169+ 7f7f ffff ffff ffff ffff ffff ffff ffff
170+ e7ef cfdf 9f3f 7f3f f3e7 efcf dfbf bf3f
171+ ffff ffff ffff ffff fffe fcf8 f0f0 e0c0
172+ ffff ffff ffff ffff bfbf bfbf dfdf dfcf
173+ 9fcf 9fcf dfcf dfcf f7fb fbf7 fbfb fbfb
174+ ffff ffff ffff ffff ffd7 f7fd feff ffff
175+ ffff ffff 7f9e e8e0 ffff fff5 8000 0001
176+ 4f47 66a4 7056 4b43 fffe 8001 015f ffff
177+ ffbf 1f7f ffff ffff fefe fcfe fdf9 fbfb
178+ 7fff feff fefe fcfe 7f7f 7f7f ffff ffff
179+ ffff fffe fefc f8f8 8183 070f 1f3f 3f7f
180+ ffff ffff 7f3f 9f8f efef eff7 f7f7 f7f7
181+ dfcf efdf cfff cfef fbfb fbf9 fdfd fbfc
182+ ffff fffe f4c0 8000 fffc e080 0000 0000
183+ 8000 0000 0000 0000 0506 0802 0300 0000
184+ 4925 2365 a2b2 1191 ffff ffff ff05 0000
185+ ffff ffff ff7f 0307 fbfb ffff ffff ffff
186+ fcfd fcfe fdfd fdfd ffff ffff ffff ffff
187+ f0e0 e1c3 8387 0f1f ffff ffff ffff fffe
188+
189+
+47,
-0
1@@ -1,5 +1,6 @@
2 #include <stdio.h>
3 #include <stdlib.h>
4+#include <pthread.h>
5
6 #include "../uxn.h"
7 #include "system.h"
8@@ -74,15 +75,61 @@ system_inspect(Uxn *u)
9 system_print(&u->rst, "rst");
10 }
11
12+/* Friends */
13+
14+Uint8 *global_ram;
15+Uint16 friends_tasks[0x80];
16+pthread_t friends[0x80];
17+int friends_count = 0;
18+int friends_args[0x80];
19+
20+void *
21+friend_task(void *x)
22+{
23+ Uxn friend;
24+ uxn_boot(&friend, global_ram);
25+ uxn_eval(&friend, friends_tasks[*((int *)x)]);
26+ return NULL;
27+}
28+
29+int
30+spawn_friend(Uint16 task)
31+{
32+ if(friends_count >= 0x80)
33+ return system_error("friends", "Too many threads");
34+ friends_args[friends_count] = friends_count;
35+ friends_tasks[friends_count] = task;
36+ pthread_create(&friends[friends_count], NULL, friend_task, (void *)&friends_args[friends_count]);
37+ return friends_count++;
38+}
39+
40+void
41+wait_friends(void)
42+{
43+ int i;
44+ for(i = 0; i < friends_count; ++i)
45+ pthread_join(friends[i], NULL);
46+ friends_count = 0;
47+}
48+
49 /* IO */
50
51 void
52 system_deo(Uxn *u, Uint8 *d, Uint8 port)
53 {
54+ Uint16 v;
55 switch(port) {
56 case 0x3:
57 system_cmd(u->ram, PEEK2(d + 2));
58 break;
59+ case 0x5:
60+ v = PEEK2(d + 4);
61+ global_ram = u->ram;
62+ if(v)
63+ spawn_friend(v);
64+ else
65+ wait_friends();
66+ break;
67 case 0xe:
68 system_inspect(u);
69 break;
+3,
-3
1@@ -38,7 +38,7 @@ char *rom_path;
2 #define PAD 4
3 #define CONINBUFSIZE 256
4
5-Uint16 deo_mask[] = {0xff08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
6+Uint16 deo_mask[] = {0xff28, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
7 Uint16 dei_mask[] = {0x0000, 0x0000, 0x003c, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
8
9 Uint8
10@@ -93,9 +93,9 @@ hide_cursor(void)
11 Cursor blank;
12 Pixmap bitmap;
13 XColor black;
14- static char empty[] = {0, 0, 0, 0, 0, 0, 0, 0};
15+ static char empty[] = {0};
16 black.red = black.green = black.blue = 0;
17- bitmap = XCreateBitmapFromData(display, window, empty, 8, 8);
18+ bitmap = XCreateBitmapFromData(display, window, empty, 1, 1);
19 blank = XCreatePixmapCursor(display, bitmap, bitmap, &black, &black, 0, 0);
20 XDefineCursor(display, window, blank);
21 XFreeCursor(display, blank);