Boilerplate threads

This commit is contained in:
neauoire 2023-08-25 09:18:37 -07:00
parent 0ed2617506
commit bd976ce842
3 changed files with 78 additions and 0 deletions

32
etc/link.tal Normal file
View File

@ -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

View File

@ -15,6 +15,9 @@ rom:
@ ./bin/uxnasm etc/polycat.tal bin/polycat.rom @ ./bin/uxnasm etc/polycat.tal bin/polycat.rom
run: bin/uxnasm bin/uxncli bin/uxn11 rom run: bin/uxnasm bin/uxncli bin/uxn11 rom
@ ./bin/uxn11 bin/polycat.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 test: bin/uxnasm bin/uxncli bin/uxn11
@ ./bin/uxnasm && ./bin/uxncli && ./bin/uxn11 && ./bin/uxnasm -v && ./bin/uxncli -v && ./bin/uxn11 -v @ ./bin/uxnasm && ./bin/uxncli && ./bin/uxn11 && ./bin/uxnasm -v && ./bin/uxncli -v && ./bin/uxn11 -v
install: bin/uxnasm bin/uxncli bin/uxn11 install: bin/uxnasm bin/uxncli bin/uxn11

View File

@ -15,6 +15,41 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE. 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 Uint8
link_dei(Uxn *u, Uint8 addr) link_dei(Uxn *u, Uint8 addr)
{ {
@ -24,4 +59,12 @@ link_dei(Uxn *u, Uint8 addr)
void void
link_deo(Uint8 *ram, Uint8 *d, Uint8 port) 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);
}
} }