dsforth: added "NIP" and "TUCK"
[urasm.git] / dsforth / main_wfind_linear.zas
blobff0f9f519fc74c774a2beb67d7a7e511b4069f6b
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; word finder (linear list)
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 $FORTH_CONST (VLIST-HASHED)  0
8 ; (XFIND) ( caddr voclwptr -- cfa b tf  ok)
9 ;         ( caddr voclwptr -- ff        bad)
10 ; Searches the dictionary starting at the name field address @voclwptr,
11 ; matching to the text at addr,l. Returns parameter field address, length
12 ; byte of name field and true for a good match. If no match is found, only
13 ; a boolean false is left.
14 ; note that `voclwptr` should point to a vocabulary for hashtable version.
16 ; non-hashed version
17 $FORTH_CODE_WORD (XFIND)
18 ;; AberSoft
19 ;; ( addr l voclwptr -- cfa b tf  ok)
20 ;; ( addr l voclwptr -- ff        bad)
21   ; load latest vocabulary word
22   pop   hl
23   ld    e,(hl)
24   inc   hl
25   ld    d,(hl)
26   ;pop   de
27 xfind0:
28   pop   hl
29   push  hl
30   ld    a,(de)
31   xor   (hl)
32   and   #3F
33   jr    nz,xfind4
34 xfind1:
35   inc   hl
36   inc   de
37   ld    a,(de)
38   xor   (hl)
39   add   a,a
40   jr    nz,xfind3
41   jr    nc,xfind1
42   ld    hl,5
43   add   hl,de
44   ex    (sp),hl
45 xfind2:
46   dec   de
47   ld    a,(de)
48   or    a
49   jp    p,xfind2
50   ;k8: move to cfa
51   pop   hl
52   dec   hl
53   dec   hl
54   push  hl
55   ld    e,a
56   ld    d,0
57   ld    hl,1
58   jp    i_pushde
59 xfind3:
60   jr    c,xfind5
61 xfind4:
62   inc   de
63   ld    a,(de)
64   or    a
65   jp    p,xfind4
66 xfind5:
67   inc   de
68   ex    de,hl
69   ld    e,(hl)
70   inc   hl
71   ld    d,(hl)
72   ld    a,d
73   or    e
74   jr    nz,xfind0
75   pop   hl
76   jp    i_push_zero
77 $FORTH_END_CODE_WORD (XFIND)