Made multitasker keep sp only, and implicitly loop.

This commit is contained in:
Brad Nelson
2021-03-05 22:17:55 -08:00
parent d90dd1ceac
commit d1055fd038
2 changed files with 18 additions and 17 deletions

View File

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

View File

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