\ VP-lib
\ General definitions
\
\ $Id: VP-lib.txt,v 1.5 2000/11/12 03:22:46 kris_johnson Exp $

\ Copyright 2000
\ Kristopher D. Johnson
\ 
\ See LICENSE-JacksOrBetter for the
\ conditions under which you may
\ use, redistribute, or modify this 
\ code, or create derived works.

.( Quartus libraries... )
needs core-ext
needs double
needs toolkit
needs random
needs struct

.( VP-lib... )

: 0.   0 dup ; inline

1 cells constant cell

\ Store to given address; leave
\ address on stack
: !-leave-addr ( x adr -- adr )
  swap over ! ;

\ Print N cells of an array
: .array ( u adr -- )
  swap cells over + swap
  ?do i @ . cell +loop
;

\ This variable is set true when
\ the standalone app is built
variable StandaloneFlag
false StandaloneFlag !

\ Return true if running as
\ standalone program (not inside
\ the Forth environment)
: standalone? ( -- f )
  StandaloneFlag @ ;

: binary ( -- )   2 base ! ;

: d1+ ( d. -- d.+1 )   1 m+ ;

\ Add given value to double-cell
\ value at given address
: m+! ( n &d -- )
  dup >r
  2@ rot m+
  r> 2!
;

\ Like MOVE, but with 32-bit addrs
: movea ( &src. &dst. u -- )
  s>d 2rot 2rot ( ud &src. &dst. )
  MemMove drop
;

\ Set random number generator
\ seed value to the system time
: init-rand-seed ( -- )
  TimGetTicks seed ;

\ Increment value at given address
: incr ( adr -- )   1 swap +! ;

\ Increment double-cell value at
\ given address
: 2incr ( adr -- )
  dup >r 2@ d1+ r> 2! ;

\ Exchange values at given addresses
: swap-cells ( a1 a2 -- )
  2dup @ swap @ ( a1 a2 n2 n1 )
  rot ! swap !
;

\ Logical inverse
: not ( f -- !f )   0= ; inline

\ Greater than or equal
: >= ( n1 n2 -- f )   < not ; inline

