Basic link implementation

This commit is contained in:
neauoire 2023-08-25 10:15:57 -07:00
parent 618212a0d7
commit e522eeb7a5
4 changed files with 23 additions and 26 deletions

View File

@ -4,12 +4,11 @@
;task1 #f0 DEO2 ;task1 #f0 DEO2
;task2 #f2 DEO2 ;task2 #f2 DEO2
#0000 #f0 DEO2k INC INC DEO2 #0000 #f0 DEO2k INC INC DEO2
#010e DEO ;end-txt print-text
#800f DEO #800f DEO
BRK BRK
@task1 ( -> ) @task1 ( -> )
;t1 print-text ;t1 print-text
@ -20,13 +19,11 @@ BRK
BRK BRK
@print-text ( str* -- ) @print-text ( str* -- )
( send ) LDAk .Console/write DEO
&while ( loop ) INC2 LDAk ?print-text
( send ) LDAk .Console/write DEO
( loop ) INC2 LDAk ?&while
POP2 POP2
JMP2r JMP2r
@t1 "Text1 00 @t1 "AAAAAAAAAAAAAAAA 00
@t2 "Text2 00 @t2 "BBBBBBBBBBBBBBBB 00
@end-txt 0a "Done. 0a

View File

@ -16,7 +16,7 @@ WITH REGARD TO THIS SOFTWARE.
*/ */
pthread_t threads[8]; pthread_t threads[8];
static int args[8]; static int tids[8];
static Uint16 link_vectors[8]; static Uint16 link_vectors[8];
static Uint8 *link_ram; static Uint8 *link_ram;
@ -26,26 +26,27 @@ static void
{ {
int tid = *((int *)x); int tid = *((int *)x);
Uxn u; Uxn u;
Uint16 vector = link_vectors[tid];
u.ram = link_ram; u.ram = link_ram;
printf("eval %d #%04x\n", tid, link_vectors[tid]); u.wst.ptr = u.rst.ptr = 0;
uxn_eval(&u, link_vectors[tid]); uxn_eval(&u, link_vectors[tid]);
threads[tid] = 0;
link_vectors[tid] = 0;
return NULL; return NULL;
} }
static void static void
link_init(Uint8 *ram, int id, Uint16 vector) link_init(Uint8 *ram, int id, Uint16 vector)
{ {
printf("init %d #%04x\n", id, vector); tids[id] = id;
args[id] = id;
link_vectors[id] = vector; link_vectors[id] = vector;
link_ram = ram; link_ram = ram;
pthread_create(&threads[id], NULL, link_eval, (void *)&args[id]); pthread_create(&threads[id], NULL, link_eval, (void *)&tids[id]);
} }
static void static void
link_wait(int id) link_wait(int id)
{ {
printf("wait %d\n", id);
pthread_join(threads[id], NULL); pthread_join(threads[id], NULL);
threads[id] = 0; threads[id] = 0;
} }
@ -53,18 +54,17 @@ link_wait(int id)
Uint8 Uint8
link_dei(Uxn *u, Uint8 addr) link_dei(Uxn *u, Uint8 addr)
{ {
/* TODO: return non-zero if active */
return 0; return 0;
} }
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;
Uint8 id = port >> 0x1; Uint16 vector = PEEK2(d + port - 1);
Uint16 vector = PEEK2(d + port - 1); if(threads[id])
if(threads[id]) link_wait(id);
link_wait(id); if(vector)
if(vector) link_init(ram, id, vector);
link_init(ram, id, vector);
}
} }

View File

@ -14,4 +14,4 @@ WITH REGARD TO THIS SOFTWARE.
#define LINK_DEOMASK 0xaaaa #define LINK_DEOMASK 0xaaaa
Uint8 link_dei(Uxn *u, Uint8 addr); Uint8 link_dei(Uxn *u, Uint8 addr);
void link_deo(Uxn *u, Uint8 *d, Uint8 port); void link_deo(Uint8 *ram, Uint8 *d, Uint8 port);

View File

@ -39,7 +39,7 @@ emu_deo(Uxn *u, Uint8 addr)
case 0x10: console_deo(&u->dev[d], p); break; case 0x10: console_deo(&u->dev[d], p); break;
case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break; case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break; case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break;
case 0xf0: link_deo(u, &u->dev[d], p); break; case 0xf0: link_deo(u->ram, &u->dev[d], p); break;
} }
} }