1 \ @(#) misc2.fth 98/01/26 1.2
2 \ Utilities for PForth extracted from HMSL
5 \ Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
7 \ Permission to use, copy, modify, and/or distribute this
8 \ software for any purpose with or without fee is hereby granted.
10 \ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 \ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 \ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
13 \ THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
14 \ CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15 \ FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
16 \ CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 \ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 \ 00001 9/14/92 Added call, 'c w->s
20 \ 00002 11/23/92 Moved redef of : to loadcom.fth
24 : 'N ( <name> -- , make 'n state smart )
28 IF namebase - ( make nfa relocatable )
29 [compile] literal ( store nfa of word to be compiled )
35 : ?LITERAL ( n -- , do literal if compiling )
41 : 'c ( <name> -- xt , state sensitive ' )
47 : ? ( address -- , fatch from address and print value )
52 create msec-delay 10000 , ( default for SUN )
53 : (MSEC) ( #msecs -- )
63 : SHIFT ( val n -- val<<n )
71 variable rand-seed here rand-seed !
72 : random ( -- random_number )
75 65535 and dup rand-seed !
77 : choose ( range -- random_number , in range )
81 : wchoose ( hi lo -- random_number )
86 \ sort top two items on stack.
87 : 2sort ( a b -- a<b | b<a , largest on top of stack)
93 \ sort top two items on stack.
94 : -2sort ( a b -- a>b | b>a , smallest on top of stack)
100 : barray ( #bytes -- ) ( index -- addr )
105 : warray ( #words -- ) ( index -- addr )
110 : array ( #cells -- ) ( index -- addr )
115 : .bin ( n -- , print in binary )
116 base @ binary swap . base !
119 base @ decimal swap . base !
122 base @ hex swap . base !
125 : B->S ( c -- c' , sign extend byte )
128 [ $ 0FF invert ] literal or
133 : W->S ( 16bit-signed -- cell-signed )
136 [ $ 0FFFF invert ] literal or
142 : WITHIN { n1 n2 n3 -- flag }
153 : MOVE ( src dst num -- )
162 : ERASE ( caddr num -- )
171 : BLANK ( addr u -- , set memory to blank )
180 \ Obsolete but included for CORE EXT word set.
181 : QUERY REFILL DROP ;
183 : EXPECT accept span ! ;
187 : UNUSED ( -- unused , dictionary space )
191 : MAP ( -- , dump interesting dictionary info )
193 ." CODEBASE = " codebase .hex cr
194 ." HERE = " here .hex cr
195 ." CODELIMIT = " codelimit .hex cr
196 ." Compiled Code Size = " here codebase - . cr
197 ." CODE-SIZE = " code-size @ . cr
198 ." Code Room UNUSED = " UNUSED . cr
200 ." NAMEBASE = " namebase .hex cr
201 ." HEADERS-PTR @ = " headers-ptr @ .hex cr
202 ." NAMELIMIT = " namelimit .hex cr
203 ." CONTEXT @ = " context @ .hex cr
204 ." LATEST = " latest .hex ." = " latest id. cr
205 ." Compiled Name size = " headers-ptr @ namebase - . cr
206 ." HEADERS-SIZE = " headers-size @ . cr
207 ." Name Room Left = " namelimit headers-ptr @ - . cr
211 \ Search for substring S2 in S1
212 : SEARCH { addr1 cnt1 addr2 cnt2 | addr3 cnt3 flag -- addr3 cnt3 flag }
213 \ ." Search for " addr2 cnt2 type ." in " addr1 cnt1 type cr
214 \ if true, s1 contains s2 at addr3 with cnt3 chars remaining
226 addr1 i j + chars + c@ <> \ mismatch?
234 addr1 i chars + -> addr3
245 : env= ( c-addr u c-addr1 u1 x -- x true true | c-addr u false )
246 { x } 2over compare 0= if 2drop x true true else false then
249 : 2env= ( c-addr u c-addr1 u1 x y -- x y true true | c-addr u false )
250 { x y } 2over compare 0= if 2drop x y true true else false then
253 0 invert constant max-u
254 0 invert 1 rshift constant max-n
258 : ENVIRONMENT? ( c-addr u -- false | i*x true )
259 s" /COUNTED-STRING" 255 env= if exit then
260 s" /HOLD" 128 env= if exit then \ same as PAD
261 s" /PAD" 128 env= if exit then
262 s" ADDRESS-UNITS-BITS" 8 env= if exit then
263 s" FLOORED" false env= if exit then
264 s" MAX-CHAR" 255 env= if exit then
265 s" MAX-D" max-n max-u 2env= if exit then
266 s" MAX-N" max-n env= if exit then
267 s" MAX-U" max-u env= if exit then
268 s" MAX-UD" max-u max-u 2env= if exit then
269 s" RETURN-STACK-CELLS" 512 env= if exit then \ DEFAULT_RETURN_DEPTH
270 s" STACK-CELLS" 512 env= if exit then \ DEFAULT_USER_DEPTH
271 \ FIXME: maybe define those: