anchor.diff:      save-task @ sp! rp!  \ restore pointers
       unloop ;              \ pop { r4  r5 } to restore the loop registers
   
  -: wake ( task -- ) 1 cells +  true swap ! ; \ Wake a random task (IRQ safe)
  -: idle ( task -- ) 1 cells + false swap ! ;  \ Idle a random task (IRQ safe)
  +: wake ( task -- ) 1 cells +  true swap ! ; \ Wake a task (IRQ safe)
  +: idle ( task -- ) 1 cells + false swap ! ; \ Idle a task (IRQ safe)
   
   \ -------------------------------------------------------
   \  Round-robin list task handling - do not use in IRQ !
   \ -------------------------------------------------------
   
  -: stop ( -- ) false task-state ! pause ; \ Stop current task
  +: stop    ( -- ) false task-state ! pause ; \ Stop current task
  +: running ( -- ) true task-state ! pause ;  \ Mark current task as running
  +: wfi     ( -- ) 1 task-state ! pause ;     \ Mark task as waiting-for-interrupt
   : multitask  ( -- ) ['] (pause) hook-pause ! ;
   : singletask ( -- ) [']  nop    hook-pause ! ;
   
  
positive.code: 
  \ Internal stucture of task memory:
  \  0: Pointer to next task
  \  4: Task currently active ?
  \  8: Saved stack pointer
  \ 12: Handler for Catch/Throw
  \  Parameter stack space
  
negative.code: \  Lowpower mode
  \ --------------------------------------------------
  
  : up-alone? ( -- ? ) \ Checks if all other tasks are currently in idle state (only counts state==1)
    next-task @ \ Current task is in UP. Start with the next one.
    begin
      dup up @ <> \ Scan the whole round-robin list until back to current task.
    while
      dup 1 cells + @ -1 = if drop false exit then
      \ Check state of this task and exit if it is active
      @ \ Next task in list
    repeat
  