1 ; -*- coding: utf-8 -*-
2 ; http://patorjk.com/software/taag/#p=display&f=Banner&t=Fast Forth
4 ; Fast Forth For Texas Instrument MSP430FRxxxx FRAM devices
5 ; Copyright (C) <2015> <J.M. THOORENS>
7 ; This program is free software: you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation, either version 3 of the License, or
10 ; (at your option) any later version.
12 ; This program is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ; https://forth-standard.org/standard/core/toR
26 ; >R x -- R: -- x push to return stack
34 ;https://forth-standard.org/standard/core/AND
35 ;C AND x1 x2 -- x3 logical AND
42 ;https://forth-standard.org/standard/core/CFetch
43 ;C C@ c-addr -- char fetch char from memory
45 CFETCH MOV.B @TOS,TOS ;2
50 ;https://forth-standard.org/standard/core/SPACE
51 ;C SPACE -- output a space
58 ;https://forth-standard.org/standard/core/SPACES
59 ;C SPACES n -- output n spaces
69 JNZ SPACE ;25~ ==> 27~ by space ==> 2.963 MBds @ 8 MHz
71 SPACESNEXT2 MOV @PSP+,TOS ; -- drop n
77 ; https://forth-standard.org/standard/core/I
78 ; I -- n R: sys1 sys2 -- sys1 sys2
79 ; get the innermost loop index
81 II SUB #2,PSP ;1 make room in TOS
83 MOV @RSP,TOS ;2 index = loopctr - fudge
88 ;https://forth-standard.org/standard/tools/DotS
89 FORTHWORD ".S" ; -- print <depth> of Param Stack and stack contents if not empty
90 DOTS MOV TOS,-2(PSP) ; -- TOS ( tos x x )
92 SUB #2,TOS ; to take count that TOS is first cell
93 MOV TOS,-6(PSP) ; -- TOS ( tos x PSP )
94 MOV #PSTACK,TOS ; -- P0 ( tos x PSP )
95 SUB #2,TOS ; to take count that TOS is first cell
96 DOTS1 MOV TOS,-4(PSP) ; -- S0 ( tos S0 SP )
97 SUB #6,PSP ; -- S0 SP S0
98 SUB @PSP,TOS ; -- S0 SP S0-SP
99 RRA TOS ; -- S0 SP #cells
102 .word DOT ; display #cells
103 .word lit,08h,EMIT ; backspace
104 .word lit,'>',EMIT,SPACE
105 .word TWODUP,ONEPLUS,ULESS
106 .word QFBRAN,STKDISPL1
109 STKDISPL2 .word II,FETCH,UDOT
110 .word lit,2,xploop,STKDISPL2
114 FORTHWORD ".RS" ; -- print <depth> of Return Stack and stack contents if not empty
115 DOTRS MOV TOS,-2(PSP) ; -- TOS ( tos x x )
116 MOV RSP,-6(PSP) ; -- TOS ( tos x RSP )
117 MOV #RSTACK,TOS ; -- R0 ( tos x RSP )
120 ;https://forth-standard.org/standard/tools/q
121 ;Z ? adr -- display the content of adr
123 QUESTION MOV @TOS,TOS
129 ;https://forth-standard.org/standard/tools/WORDS
130 ;X WORDS -- list all words in first vocabulary in CONTEXT. 38 words
134 .word LIT,CONTEXT,FETCH ; -- VOC_BODY
135 WORDS1 .word FETCH ; -- NFA
136 .word QDUP ; -- 0 | -- NFA NFA
137 .word QFBRAN,WORDS2 ; -- NFA
138 .word DUP,DUP,COUNT ; -- NFA NFA addr count
139 .word lit,07Fh,ANDD,TYPE ; -- NFA NFA
140 .word CFETCH,lit,0Fh,ANDD
141 .word lit,10h,SWAP,MINUS
143 .word lit,2,MINUS ; NFA -- LFA
145 WORDS2 .word EXIT ; --
151 ;https://forth-standard.org/standard/core/PAD
159 ;https://forth-standard.org/standard/core/ROT
160 ;C ROT x1 x2 x3 -- x2 x3 x1
162 ROT MOV @PSP,W ; 2 fetch x2
163 MOV TOS,0(PSP) ; 3 store x3
164 MOV 2(PSP),TOS ; 3 fetch x1
165 MOV W,2(PSP) ; 3 store x2
169 ;https://forth-standard.org/standard/tools/WORDS
170 ;X WORDS -- list all words in first vocabulary in CONTEXT. 38 words
174 .word LIT,CONTEXT,FETCH
175 .word PAD,LIT,THREADS,DUP,PLUS
178 WORDS2 .word LIT,0,DUP
179 .word LIT,THREADS,DUP,PLUS ; I = ptr = thread*2
183 .word II,PAD,PLUS,FETCH ; old MAX NFA U< NFA ?
184 .word ULESS,QFBRAN,WORDS4 ; no
185 .word DROP,DROP,II ; yes, replace old MAX of NFA by new MAX of NFA
186 .word DUP,PAD,PLUS,FETCH ;
187 WORDS4 .word LIT,2,xploop,WORDS3 ; 2 +LOOP
188 .word QDUP ; MAX of NFA = 0 ?
189 .word QFBRAN,WORDS5 ; WHILE
190 .word DUP,LIT,2,MINUS,FETCH ; replace NFA MAX by its [LFA]
191 .word ROT,PAD,PLUS,STORE
192 .word DUP,COUNT ; display NFA MAX in 10 chars format
193 .word lit,07Fh,ANDD,TYPE
194 .word CFETCH,lit,0Fh,ANDD
195 .word lit,10h,SWAP,MINUS
197 .word BRAN,WORDS2 ; REPEAT
206 ;https://forth-standard.org/standard/core/MAX
207 ;C MAX n1 n2 -- n3 signed maximum
209 MAX CMP @PSP,TOS ; n2-n1
214 ;https://forth-standard.org/standard/core/MIN
215 ;C MIN n1 n2 -- n3 signed minimum
217 MIN CMP @PSP,TOS ; n2-n1
225 ;https://forth-standard.org/standard/core/Plus
226 ;C + n1/u1 n2/u2 -- n3/u3 add n1+n2
233 ;https://forth-standard.org/standard/core/OVER
234 ;C OVER x1 x2 -- x1 x2 x1
236 OVER MOV TOS,-2(PSP) ; 3 -- x1 (x2) x2
237 MOV @PSP,TOS ; 2 -- x1 (x2) x1
238 SUB #2,PSP ; 1 -- x1 x2 x1
243 ;https://forth-standard.org/standard/core/UDotR
244 ;X U.R u n -- display u unsigned in n width
247 .word TOR,LESSNUM,lit,0,NUM,NUMS,NUMGREATER
248 .word RFROM,OVER,MINUS,lit,0,MAX,SPACES,TYPE
252 ;https://forth-standard.org/standard/tools/DUMP
255 PUSH &BASE ; save current base
256 MOV #10h,&BASE ; HEX base
257 ADD @PSP,TOS ; -- ORG END
259 .word SWAP ; -- END ORG
262 .word II,lit,4,UDOTR,SPACE ; generate address
264 .word II,lit,8,PLUS,II,xdo ; display first 8 bytes
265 DUMP2 .word II,CFETCH,lit,3,UDOTR
266 .word xloop,DUMP2 ; bytes display loop
268 .word II,lit,10h,PLUS,II,lit,8,PLUS,xdo ; display last 8 bytes
269 DUMP3 .word II,CFETCH,lit,3,UDOTR
270 .word xloop,DUMP3 ; bytes display loop
272 .word II,lit,10h,PLUS,II,xdo ; display 16 chars
273 DUMP4 .word II,CFETCH
274 .word lit,7Eh,MIN,FBLANK,MAX,EMIT
275 .word xloop,DUMP4 ; chars display loop
276 .word lit,10h,xploop,DUMP1 ; line loop
277 .word RFROM,lit,BASE,STORE ; restore current base