(*

create buff 20 allot
create copy 11 allot

code B!     ( byte addr -- )    \ Variant of C! with bit-7 always set
    sp )+ w mov
    80 # w bis
    w tos ) .b mov
    sp )+ tos mov
    next
end-code

code B@     ( addr -- byte )    \ Variant of C@ with bit-7 always clear
    tos ) tos .b mov
    80 # tos bic
    next
end-code

code UP     ( b1 -- b2 )        \ Variant of 2* with bit-7 always set
    7F # tos and>               \ Leave only low 7 bits
    tos tos add                 \ Shift left
    80 # tos bit  cs? if,       \ Bit-7 set?
        #1 tos bis              \ Yes, set bit-0
    then,
    80 # tos bis                \ Bit-7 always high
    next
end-code

code DWN    ( b1 -- b2 )        \ Variant of 2/ with bit-7 always set
    7F # tos and>               \ Leave only low 7 bits
    tos rrc  cs? if,            \ Shift right, biit-0 set?
        40 # tos bis            \ Yes, set bit-6
    then,
    80 # tos bis                \ Bit-7 always high
    next
end-code

: t1  buff 20 -1 fill  0 buff c! ;
: t2  buff 20 -1 fill  s" 123" buff swap move ;

: <<    ( +n -- )
    >r  buff copy r@ move
    buff r@ +  buff  20 r@ - move
    copy buff 20 + r@ - r> move ;

: >>    ( +n -- )
    >r  buff 20 + r@ - copy r@ move
    buff buff r@ +  20 r@ - move
    copy buff r> move ;

: /\    ( -- )
    buff 20 bounds do
        i b@  2*
        dup  80 and 0 > 1 and  or b!
    loop ;

: \/    ( -- )
    buff 20 bounds do
        i b@  dup 1 and >r
        2/  r> 0 > 40 and  or b!
    loop ;

code SET-PAUSE1     ( -- )      \ Compact and fast code version of SET-PAUSE
    bright # sun mov            \ Point to brightness array
    #0 day mov                  \ Start total at zero
    dm 10 # moon mov
    begin,
        sun )+ day add          \ Add whole array
        #1 moon sub
     0=? until,
     dm 40000 # w mov           \ Subtract from period total
     day w sub
     dm 250 # day mov           \ Lowest content = 250,
     day w cmp u>? if,
        day w mov
     then,
     w sun ) mov                \ Store pause length
     next
end-code

code SET-PAUSE2     ( -- )      \ Compact and fast code version of SET-PAUSE
    bright # sun mov            \ Point to brightness array
    dm 40000 # day mov          \ Start total at period length
    dm 10 # moon mov
    begin,
        sun )+ day sub          \ Subtract whole array from period
        #1 moon sub
     0=? until,
     dm 250 # w mov             \ Lowest content = 250
     w day cmp u>? if,
        w day mov
     then,
     day sun ) mov              \ Store pause length
     next
end-code

code SET-PAUSE3     ( -- )      \ Compact and fast code version of SET-PAUSE
    bright # sun mov            \ Point to brightness array
    dm 40000 # day mov          \ Start total at period length
    dm 10 # moon mov
    begin,
        sun )+ day sub          \ Subtract whole array from period
        #1 moon sub
     0=? until,
     dm 250 # day add           \ Add minimal pause = 500 cycles
     day sun ) mov              \ Store new pause length
     next
end-code

*)
