From d1055fd03858a4a1d78ebf3af251461b92931af6 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Fri, 5 Mar 2021 22:17:55 -0800 Subject: [PATCH] Made multitasker keep sp only, and implicitly loop. --- ueforth/common/tasking_tester.fs | 6 +++--- ueforth/common/tasks.fs | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/ueforth/common/tasking_tester.fs b/ueforth/common/tasking_tester.fs index f78ce15..10490d1 100644 --- a/ueforth/common/tasking_tester.fs +++ b/ueforth/common/tasking_tester.fs @@ -1,8 +1,8 @@ ( Trying some things with tasks ) -: printer1 begin 42 emit 1000 ms again ; -: printer2 begin 43 emit 500 ms again ; -: runner begin pause again ; +: printer1 42 emit 1000 ms ; +: printer2 43 emit 500 ms ; +: runner begin pause again ; ' printer1 1000 1000 task print1 ' printer2 1000 1000 task print2 diff --git a/ueforth/common/tasks.fs b/ueforth/common/tasks.fs index 27520e2..8bb0191 100644 --- a/ueforth/common/tasks.fs +++ b/ueforth/common/tasks.fs @@ -4,13 +4,22 @@ vocabulary tasks tasks definitions variable task-list -forth definitions tasks +forth definitions tasks also internals -: task ( xt rsz dsz "name" ) - create here >r 0 , 0 , 0 , - here cell+ r@ cell+ ! cells allot - here r@ 2 cells + ! cells allot - dup 0= if drop else >body r@ 2 cells + @ ! then rdrop ; +: pause + rp@ sp@ task-list @ cell+ ! + task-list @ @ task-list ! + task-list @ cell+ @ sp! rp! +; + +: task ( xt dsz rsz "name" ) + create here >r 0 , 0 , ( link, sp ) + swap here cell+ r@ cell+ ! cells allot + here r@ cell+ @ ! cells allot + dup 0= if drop else + here r@ cell+ @ @ ! ( set rp to point here ) + , postpone pause ['] branch , here 3 cells - , + then rdrop ; : start-task ( t -- ) task-list @ if @@ -22,14 +31,6 @@ forth definitions tasks then ; -: pause - rp@ task-list @ 2 cells + ! - sp@ task-list @ cell+ ! - task-list @ @ task-list ! - task-list @ cell+ @ sp! - task-list @ 2 cells + @ rp! -; - DEFINED? ms-ticks [IF] : ms ( n -- ) ms-ticks >r begin pause ms-ticks r@ - over >= until rdrop drop ; [THEN]