\ debug.fs  \ And some code examples.

0 [if]
Copyright (C) 2004 by Charles Shattuck.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

For LGPL information:   http://www.gnu.org/copyleft/lesser.txt
[then]

] \ Target Forth
: sign -if negate 45 # emit ; then ;
: space 32 # emit ;
: cr 13 # emit 10 # emit ;
: (digit)   -10 # + -if -39 # + then 97 # + ;  
: digit   (digit) emit ;
: u/mod |u/mod ;
\ Avoid leading zeroes in (u.).
: three digit
: two digit digit ;
: (u.) 10 # u/mod 10 # u/mod if three ; then drop if two ; then drop
   digit ;
\ Accept leading zeroes to save code.
\ : (u.) 10 # u/mod 10 # u/mod digit digit digit ;
: u. (u.) space ;
: . sign u. ;
: (h.) 16 # u/mod digit digit ;
: h. (h.) space ;
: dh. (h.) h. ;
: depth S #@ invert ;
\ : .s S #@ a! begin a invert 0=if drop ; then drop @+ u. again
: .s S #@ dup invert (u.) 62 # emit space a! begin @+ a 0=if 2drop ;
   then drop . again
: filter -if drop 46 # ; then 32 # <if drop 46 # then ;
: p |p ;
: @p |@p ;
: @p+ |@p+ ;
: .line ( cr) p dh. p 16 # begin @p+ h. 1- 0=until drop p! 16 # begin @p+
   filter emit 1- 0=until drop ;
: d+  |d+ ;  \ |d+ added to misc8051.fs -- 13Feb08 rjn
\ : d+  push swap push + pop pop +' ;
\ : dump ( da n) push p! pop 16 # u/mod swap if swap 1+ swap then drop begin
\   .line 1- 0=until drop ;
: d ( da) p! .line ;
: n p d ;
: b p -32 ## d+ p! n ;
\ : .show cr a 0 # dh. a 16 # begin @+ h. 1- 0=until drop a! 16 # begin @+
\   filter emit 1- 0=until drop ;
\ : show ( da n) push a! pop 16 # u/mod swap if swap 1+ swap then drop begin
\   .show 1- 0=until drop ;
\ Display double numbers (16 bits).
: 10000s 0 # begin push -10000 ## d+ -if 10000 ## d+ pop ; then pop 1+ again
: 1000s 0 # begin push -1000 ## d+ -if 1000 ## d+ pop ; then pop 1+ again
: 100s 0 # begin push -100 ## d+ -if 100 ## d+ pop ; then pop 1+ again
: ud. 10000s digit 1000s digit 100s digit drop 10 # u/mod digit digit
   space ;
: dnegate swap invert swap invert 1 ## d+ ;
: dsign -if dnegate 45 # emit ; then ;
: d. dsign ud. ;
\ Strings.
: type ( da) p! @p+ begin @p+ emit 1- 0=until drop ;
:m " 34 parse here there place here there [ c@ 1 + ] allot m;
\ : string pop pop swap type ;
\ : greet string " Welcome to MISC8051"
\ For testing some of the primitives.
\ :m (emit) emit m;
\ :m (dup) dup m;
\ :m (drop) drop m;
\ :m (swap) swap m;
\ :m (+) + m;
\ :m (negate) negate m;
\ : dup (dup) ;
\ : drop (drop) ;
\ : swap (swap) ;
\ : + (+) ;
\ : negate (negate) ;
