3 ; https://forth-standard.org/standard/tools/BracketTHEN
5 FORTHWORDIMM "[THEN]" ; do nothing
8 ; ; https://forth-standard.org/standard/string/COMPARE
9 ; ; COMPARE ( c-addr1 u1 c-addr2 u2 -- n )
10 ; ;Compare the string specified by c-addr1 u1 to the string specified by c-addr2 u2.
11 ; ;The strings are compared, beginning at the given addresses, character by character,
12 ; ;up to the length of the shorter string or until a difference is found.
13 ; ;If the two strings are identical, n is zero.
14 ; ;If the two strings are identical up to the length of the shorter string,
15 ; ; n is minus-one (-1) if u1 is less than u2 and one (1) otherwise.
16 ; ;If the two strings are not identical up to the length of the shorter string,
17 ; ; n is minus-one (-1) if the first non-matching character in the string specified by c-addr1 u1
18 ; ; has a lesser numeric value than the corresponding character in the string specified by c-addr2 u2 and one (1) otherwise.
22 ; MOV @PSP+,Y ;2 Y = addr2
23 ; MOV @PSP+,T ;2 T = u1
24 ; MOV @PSP+,X ;2 X = addr1
25 ; COMPAR1 MOV T,TOS ;1
26 ; ADD S,TOS ;1 TOS = u1+u2
27 ; JZ COMPEQUAL ;2 u1=u2=0, Z=1, end of all successfull comparisons
29 ; JN COMPLESS ;2 u1<u2 if u1 < 0
31 ; JN COMPGREATER ;2 u1>u2 if u2 < 0
33 ; CMP.B @Y+,-1(X) ;4 char1-char2
34 ; JZ COMPAR1 ;2 char1=char2 17~ loop
35 ; JC COMPGREATER ;2 char1>char2
36 ; COMPLESS ; char1<char2
42 ; MOV @IP+,PC ;4 20 + 5 words def'n
44 ; ; https://forth-standard.org/standard/tools/BracketELSE
45 ; ; [ELSE] a few (smaller and faster) definition
47 ; ;Perform the execution semantics given below.
49 ; ;( "<spaces>name ..." -- )
50 ; ;Skipping leading spaces, parse and discard space-delimited words from the parse area,
51 ; ;including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
52 ; ;until the word [THEN] has been parsed and discarded.
53 ; ;If the parse area becomes exhausted, it is refilled as with REFILL.
54 ; FORTHWORDIMM "[ELSE]" ; or [IF] if isnogood...
61 ; .word FBLANK,WORDD,COUNT ; -- addr u
62 ; .word DUP,QFBRAN,BRACKETELSE5 ; u = 0 if end of line --> refill buffer then loop back
67 ; .word QTBRAN,BRACKETELSE2 ; if bad comparaison, jump for next comparaison
68 ; .word TWODROP,ONEMINUS ; 2DROP, decrement count
69 ; .word QDUP,QTBRAN,BRACKETELSE1; loop back if count <> 0
70 ; .word EXIT ; else exit
76 ; .word QTBRAN,BRACKETELSE3 ; if bad comparaison, jump for next comparaison
77 ; .word TWODROP,ONEMINUS ; 2DROP, decrement count
78 ; .word QDUP,QTBRAN,BRACKETELSE0; if count <> 0 restore old count with loop back increment
79 ; .word EXIT ; else exit
84 ; .word QTBRAN,BRACKETELSE1 ; if bad comparaison, loop back
85 ; .word BRAN,BRACKETELSE0 ; else increment loop back
88 ; ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
89 ; ; OPTION ; plus 5 words option
90 ; ;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
92 ; .byte 5,13,10,"ko " ;
93 ; .word TYPE ; CR+LF ." ko " to show false branch of conditionnal compilation
94 ; ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
95 ; .word REFILL ; REFILL Input Buffer with next line
96 ; .word SETIB ; SET Input Buffer pointers SOURCE_LEN, SOURCE_ORG and clear >IN
97 ; .word BRAN,BRACKETELSE1 ; then loop back 54 words without options
99 BADCOMPBR ; branch if string compare is false; [COMPARE,QTBRAN] replacement
101 MOV @PSP+,Y ;2 Y = addr2
102 MOV @PSP+,T ;2 T = u1
103 MOV @PSP+,X ;2 X = addr1
105 ADD S,TOS ;1 TOS = u1+u2
106 JZ COMPEQU ;2 u1=u2=0, Z=1, end of all successfull comparisons
108 JN COMPDIF ;2 u1<u2 if u1 < 0
110 JN COMPDIF ;2 u1>u2 if u2 < 0
112 CMP.B @Y+,-1(X) ;4 char1-char2
113 JZ COMPAR1 ;2 char1=char2 17~ loop
114 COMPDIF MOV @IP,IP ; take branch
118 TOQTB ; [TWODROP,ONEMINUS,?DUP,QTBRAN] replacement
119 ADD #2,PSP ;1 -- savedTOS TOS
120 SUB #1,0(PSP) ;3 -- savedTOS-1 TOS
121 JNZ COMPDIF ;2 -- cnt take branch
123 COMPEQU ADD #2,IP ; skip branch
124 JMP CMPEND ; 25 words
126 ; https://forth-standard.org/standard/tools/BracketELSE
127 ; [ELSE] a few (smaller and faster) definition
129 ;Perform the execution semantics given below.
131 ;( "<spaces>name ..." -- )
132 ;Skipping leading spaces, parse and discard space-delimited words from the parse area,
133 ;including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
134 ;until the word [THEN] has been parsed and discarded.
135 ;If the parse area becomes exhausted, it is refilled as with REFILL.
136 FORTHWORDIMM "[ELSE]" ; or [IF] if isnogood...
143 .word FBLANK,WORDD,COUNT ; -- addr u
144 .word DUP,QFBRAN,BRACKETELSE5 ; u = 0 if end of line --> refill buffer then loop back
148 .word BADCOMPBR,BRACKETELSE2 ; if bad string comparaison, jump for next comparaison
149 .word TOQTB,BRACKETELSE1 ; 2DROP, count-1, loop back if count <> 0, else DROP
150 .word EXIT ; then exit
155 .word BADCOMPBR,BRACKETELSE3 ; if bad string comparaison, jump for next comparaison
156 .word TOQTB,BRACKETELSE0 ; 2DROP, count-1, loop back with count+1 if count <> 0, else DROP
157 .word EXIT ; then exit
161 .word BADCOMPBR,BRACKETELSE1 ; if bad string comparaison, loop back
162 .word BRAN,BRACKETELSE0 ; else loop back with count+1
165 ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
166 ; OPTION ; plus 5 words option
167 ;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
169 .byte 5,13,10,"ko " ;
170 .word TYPE ; CR+LF ." ko " to show false branch of conditionnal compilation
171 ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
172 .word REFILL ; REFILL Input Buffer with next line
173 .word SETIB ; SET Input Buffer pointers SOURCE_LEN, SOURCE_ORG and clear >IN
174 .word BRAN,BRACKETELSE1 ; then loop back 44 words without options
176 ; https://forth-standard.org/standard/tools/BracketIF
179 ;Perform the execution semantics given below.
180 ;Execution: ;( flag | flag "<spaces>name ..." -- )
181 ;If flag is true, do nothing. Otherwise, skipping leading spaces,
182 ; parse and discard space-delimited words from the parse area,
183 ; including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
184 ; until either the word [ELSE] or the word [THEN] has been parsed and discarded.
185 ;If the parse area becomes exhausted, it is refilled as with REFILL. [IF] is an immediate word.
186 ;An ambiguous condition exists if [IF] is POSTPONEd,
187 ; or if the end of the input buffer is reached and cannot be refilled before the terminating [ELSE] or [THEN] is parsed.
188 FORTHWORDIMM "[IF]" ; flag --
195 ; https://forth-standard.org/standard/core/NIP
196 ; NIP x1 x2 -- x2 Drop the first item below the top of stack
202 ; https://forth-standard.org/standard/tools/BracketDEFINED
205 ;Perform the execution semantics given below.
207 ;( "<spaces>name ..." -- flag )
208 ;Skip leading space delimiters. Parse name delimited by a space.
209 ;Return a true flag if name is the name of a word that can be found,
210 ;otherwise return a false flag. [DEFINED] is an immediate word.
212 FORTHWORDIMM "[DEFINED]"
214 .word FBLANK,WORDD,FIND,NIP,EXIT
216 ; https://forth-standard.org/standard/tools/BracketUNDEFINED
219 ;Perform the execution semantics given below.
220 ;Execution: ( "<spaces>name ..." -- flag )
221 ;Skip leading space delimiters. Parse name delimited by a space.
222 ;Return a false flag if name is the name of a word that can be found,
223 ;otherwise return a true flag.
224 FORTHWORDIMM "[UNDEFINED]"