\ fourtap-util 2001/12/22 KDJ
\ 
\ Copyright 2001
\ Kristopher D. Johnson
\ 
\ THIS CODE IS PROVIDED "AS IS"
\ WITHOUT WARRANTY OF ANY KIND.
\ THE AUTHOR SHALL NOT BE LIABLE
\ FOR ANY CLAIM IN CONNECTION
\ WITH THIS CODE.
\ 
\ This code may be used, copied,
\ modified, or distributed for any
\ purpose, provided that the above
\ copyright notice and disclaimer of
\ warranty is retained on all copies.

needs Ver
needs random

.( fourtap-util... )

decimal

1 cells constant cell

create zbyte  0 c,

: 3.0-features? ( -- f )
  OSVersion 2 > ;

: 0variable
  0 align here variable ! ;

: u>ud ( u -- u. )
  0 ; inline

: ud>u ( u. -- u )
  drop ; inline

\ Init random number generator
: rand-seed ( -- )
  TimGetSeconds SysRandom drop ;

: drop-pending-events ( -- )
  begin ekey? while
    ekey drop
  repeat ;

: cmd-id ( -- itemid )
  event >abs itemid ;

: swap! ( adr x -- )
  swap ! ;

: off ( adr -- )
  false swap! ;

: on ( adr -- )
  true swap! ;
  
: off? ( adr -- f )
  @ 0= ;

: on? ( adr -- f )
  off? 0= ;

\ a <= n <= b
: inrange? ( n a b -- f )
  >r over > swap r> > or invert ;

\ Store value to address if it is
\ greater than current value
: max! ( n adr -- )
  dup @ rot max swap! ;

: -if ( f -- )
  postpone 0=
  postpone if
; immediate

: orif ( f -- | 1 )
  postpone dup
  postpone -if
  postpone drop
; immediate

: 3rd ( x y z -- x y z x )
  2 pick ;

: 3dup ( x y z -- x y z x y z )
  3rd 3rd 3rd ;

: choose ( u -- 0..u-1 )
  rand 2* um* nip ;


