equi

A self-descriptive stack-based PC platform
git clone git://git.luxferre.top/equi.git
Log | Files | Refs | README | LICENSE

commit 71eb5bafa8817b5ecad5e0661f27c0bea1068baa
parent 7e7544a15a930fcf8b1b55a1636b591702178573
Author: Luxferre <lux@ferre>
Date:   Sun, 14 Aug 2022 18:08:07 +0300

Added multitask example

Diffstat:
Mequi.c | 9++++++---
Aexamples/multitask.equi | 28++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/equi.c b/equi.c @@ -452,9 +452,12 @@ ushort equi_find_free_task_slot() { /* Find the next active task in the table, round-robin fashion */ struct EquiCtx* equi_find_next_task() { ushort oldtaskid = ram.taskid; /* save the current one to avoid deadlocks */ - while(!ram.tasks[ram.taskid].active) { + while(1) { ++ram.taskid; - if(ram.taskid == EQUI_TASKS_MAX) ram.taskid = 0; + if(ram.taskid == EQUI_TASKS_MAX) + ram.taskid = 0; + if(ram.tasks[ram.taskid].active) + break; if(ram.taskid == oldtaskid) /* found no active tasks, bailing out */ return NULL; } @@ -488,7 +491,7 @@ void equi_main_loop() { while(1) { /* iterate over the instructions in the command buffer */ curtask = equi_find_next_task(); /* attempt to switch the context on every iteration */ if(curtask == NULL) break; /* exit the main loop when no tasks are left */ - instr = flatram[++curtask->pc]; + instr = flatram[++(curtask->pc)]; /* silently exit on zero or FF */ if(instr == 0 || instr == 0xFFu) curtask->active = 0; diff --git a/examples/multitask.equi b/examples/multitask.equi @@ -0,0 +1,28 @@ +(A very simple example to showcase multitasking capabilities of Equi) +(by Luxferre, 2022, public domain) + +(save cmd buffer start to ease calculations) +X1-GS + +(define a task multiplexer to run the second task) +0026#GL+6#0Y! + +(and the third task) +002D#GL+6#0Y! + +(while we define the third task, the second is already running, +so some B's will be output even before A's, +and when the third task will be defined, one C will be output) + +(define task 0 - output A in endless loop) +A"$.5NJ + +(define task 1 - output B in endless loop) +B"$.5NJ + +(define task 2- output C in endless loop) +C"$.5NJ + +(and now, ABC pattern should print continuously) + +Q