1 \ @(#) misc2.fth 98/01/26 1.2
2 \ Utilities for PForth extracted from HMSL
5 \ Copyright 1994 3DO, Phil Burk, Larry Polansky, Devid Rosenboom
7 \ The pForth software code is dedicated to the public domain,
8 \ and any third party may reproduce, distribute and modify
9 \ the pForth software code or any derivative works thereof
10 \ without any compensation or license. The pForth software
11 \ code is provided on an "as is" basis without any warranty
12 \ of any kind, including, without limitation, the implied
13 \ warranties of merchantability and fitness for a particular
14 \ purpose and their equivalents under the laws of any jurisdiction.
16 \ 00001 9/14/92 Added call, 'c w->s
17 \ 00002 11/23/92 Moved redef of : to loadcom.fth
21 : 'N ( <name> -- , make 'n state smart )
25 IF namebase - ( make nfa relocatable )
26 [compile] literal ( store nfa of word to be compiled )
32 : ?LITERAL ( n -- , do literal if compiling )
38 : 'c ( <name> -- xt , state sensitive ' )
45 create msec-delay 1000 , ( default for SUN )
53 : SHIFT ( val n -- val<<n )
61 variable rand-seed here rand-seed !
62 : random ( -- random_number )
65 65535 and dup rand-seed !
67 : choose ( range -- random_number , in range )
71 : wchoose ( hi lo -- random_number )
76 \ sort top two items on stack.
77 : 2sort ( a b -- a<b | b<a , largest on top of stack)
83 \ sort top two items on stack.
84 : -2sort ( a b -- a>b | b>a , smallest on top of stack)
90 : barray ( #bytes -- ) ( index -- addr )
95 : warray ( #words -- ) ( index -- addr )
100 : array ( #cells -- ) ( index -- addr )
105 : .bin ( n -- , print in binary )
106 base @ binary swap . base !
109 base @ decimal swap . base !
112 base @ hex swap . base !
115 : B->S ( c -- c' , sign extend byte )
123 : W->S ( 16bit-signed -- 32bit-signed )
132 : WITHIN { n1 n2 n3 -- flag }
143 : MOVE ( src dst num -- )
152 : ERASE ( caddr num -- )
161 : BLANK ( addr u -- , set memory to blank )
170 \ Obsolete but included for CORE EXT word set.
171 : QUERY REFILL DROP ;
173 : EXPECT accept span ! ;
177 : UNUSED ( -- unused , dictionary space )
181 : MAP ( -- , dump interesting dictionary info )
183 ." CODEBASE = " codebase .hex cr
184 ." HERE = " here .hex cr
185 ." CODELIMIT = " codelimit .hex cr
186 ." Compiled Code Size = " here codebase - . cr
187 ." CODE-SIZE = " code-size @ . cr
188 ." Code Room UNUSED = " UNUSED . cr
190 ." NAMEBASE = " namebase .hex cr
191 ." HEADERS-PTR @ = " headers-ptr @ .hex cr
192 ." NAMELIMIT = " namelimit .hex cr
193 ." CONTEXT @ = " context @ .hex cr
194 ." LATEST = " latest .hex ." = " latest id. cr
195 ." Compiled Name size = " headers-ptr @ namebase - . cr
196 ." HEADERS-SIZE = " headers-size @ . cr
197 ." Name Room Left = " namelimit headers-ptr @ - . cr
201 \ Search for substring S2 in S1
202 : SEARCH { addr1 cnt1 addr2 cnt2 | addr3 cnt3 flag -- addr3 cnt3 flag }
203 \ ." Search for " addr2 cnt2 type ." in " addr1 cnt1 type cr
204 \ if true, s1 contains s2 at addr3 with cnt3 chars remaining
216 addr1 i j + chars + c@ <> \ mismatch?
224 addr1 i chars + -> addr3