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 10000 , ( default for SUN )
46 : (MSEC) ( #msecs -- )
56 : SHIFT ( val n -- val<<n )
64 variable rand-seed here rand-seed !
65 : random ( -- random_number )
68 65535 and dup rand-seed !
70 : choose ( range -- random_number , in range )
74 : wchoose ( hi lo -- random_number )
79 \ sort top two items on stack.
80 : 2sort ( a b -- a<b | b<a , largest on top of stack)
86 \ sort top two items on stack.
87 : -2sort ( a b -- a>b | b>a , smallest on top of stack)
93 : barray ( #bytes -- ) ( index -- addr )
98 : warray ( #words -- ) ( index -- addr )
103 : array ( #cells -- ) ( index -- addr )
108 : .bin ( n -- , print in binary )
109 base @ binary swap . base !
112 base @ decimal swap . base !
115 base @ hex swap . base !
118 : B->S ( c -- c' , sign extend byte )
126 : W->S ( 16bit-signed -- 32bit-signed )
135 : WITHIN { n1 n2 n3 -- flag }
146 : MOVE ( src dst num -- )
155 : ERASE ( caddr num -- )
164 : BLANK ( addr u -- , set memory to blank )
173 \ Obsolete but included for CORE EXT word set.
174 : QUERY REFILL DROP ;
176 : EXPECT accept span ! ;
180 : UNUSED ( -- unused , dictionary space )
184 : MAP ( -- , dump interesting dictionary info )
186 ." CODEBASE = " codebase .hex cr
187 ." HERE = " here .hex cr
188 ." CODELIMIT = " codelimit .hex cr
189 ." Compiled Code Size = " here codebase - . cr
190 ." CODE-SIZE = " code-size @ . cr
191 ." Code Room UNUSED = " UNUSED . cr
193 ." NAMEBASE = " namebase .hex cr
194 ." HEADERS-PTR @ = " headers-ptr @ .hex cr
195 ." NAMELIMIT = " namelimit .hex cr
196 ." CONTEXT @ = " context @ .hex cr
197 ." LATEST = " latest .hex ." = " latest id. cr
198 ." Compiled Name size = " headers-ptr @ namebase - . cr
199 ." HEADERS-SIZE = " headers-size @ . cr
200 ." Name Room Left = " namelimit headers-ptr @ - . cr
204 \ Search for substring S2 in S1
205 : SEARCH { addr1 cnt1 addr2 cnt2 | addr3 cnt3 flag -- addr3 cnt3 flag }
206 \ ." Search for " addr2 cnt2 type ." in " addr1 cnt1 type cr
207 \ if true, s1 contains s2 at addr3 with cnt3 chars remaining
219 addr1 i j + chars + c@ <> \ mismatch?
227 addr1 i chars + -> addr3