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/>.
24 ;https://forth-standard.org/standard/tools/DotS
25 FORTHWORD ".S" ; -- print <depth> of Param Stack and stack contents if not empty
26 DOTS MOV TOS,-2(PSP) ; -- TOS ( tos x x )
28 SUB #2,TOS ; to take count that TOS is first cell
29 MOV TOS,-6(PSP) ; -- TOS ( tos x PSP )
30 MOV #PSTACK,TOS ; -- P0 ( tos x PSP )
31 SUB #2,TOS ; to take count that TOS is first cell
32 DOTS1 MOV TOS,-4(PSP) ; -- S0 ( tos S0 SP )
33 SUB #6,PSP ; -- S0 SP S0
34 SUB @PSP,TOS ; -- S0 SP S0-SP
35 RRA TOS ; -- S0 SP #cells
38 .word DOT ; display #cells
39 .word lit,08h,EMIT ; backspace
40 .word lit,'>',EMIT,SPACE
41 .word OVER,OVER,GREATER
42 .word QZBRAN,STKDISPL1
45 STKDISPL2 .word II,FETCH,UDOT
46 .word lit,2,xploop,STKDISPL2
50 FORTHWORD ".RS" ; -- print <depth> of Return Stack and stack contents if not empty
51 DOTRS MOV TOS,-2(PSP) ; -- TOS ( tos x x )
52 MOV RSP,-6(PSP) ; -- TOS ( tos x RSP )
53 MOV #RSTACK,TOS ; -- R0 ( tos x RSP )
56 ;https://forth-standard.org/standard/tools/q
57 ;Z ? adr -- display the content of adr
62 ;https://forth-standard.org/standard/tools/WORDS
63 ;X WORDS -- list all words in first vocabulary in CONTEXT. 38 words
72 ;; vvvvvvvv may be skipped vvvvvvvv
73 ; .word XSQUOTE ; type # of threads in vocabularies
74 ; .byte 23,"monothread vocabularies"
78 ;; ^^^^^^^^ may be skipped ^^^^^^^^
80 .word LIT,CONTEXT,FETCH ; -- VOC_BODY
81 WORDS1 .word FETCH ; -- NFA
82 .word QDUP ; -- 0 | -- NFA NFA
83 .word QBRAN,WORDS2 ; -- NFA
84 .word DUP,DUP,COUNT ; -- NFA NFA addr count
85 .word lit,07Fh,ANDD,TYPE ; -- NFA NFA
86 .word CFETCH,lit,0Fh,ANDD
87 .word lit,10h,SWAP,MINUS
89 .word lit,2,MINUS ; NFA -- LFA
91 WORDS2 .word EXIT ; --
96 ;; vvvvvvvv may be skipped vvvvvvvv
98 ; .word LIT,0Ah,FBASE,STORE
99 ; .word LIT,THREADS,DOT
100 ; .word XSQUOTE ; type # of threads in vocabularies
101 ; .byte 20,"threads vocabularies"
106 ;; ^^^^^^^^ may be skipped ^^^^^^^^
108 .word LIT,CONTEXT,FETCH
109 .word PAD,LIT,THREADS,DUP,PLUS
112 WORDS2 .word LIT,0,DUP
113 .word LIT,THREADS,DUP,PLUS ; I = ptr = thread*2
117 .word II,PAD,PLUS,FETCH ; old MAX NFA U< NFA ?
118 .word ULESS,QBRAN,WORDS4 ; no
119 .word DROP,DROP,II ; yes, replace old MAX of NFA by new MAX of NFA
120 .word DUP,PAD,PLUS,FETCH ;
121 WORDS4 .word LIT,2,xploop,WORDS3 ; 2 +LOOP
122 .word QDUP ; MAX of NFA = 0 ?
123 .word QBRAN,WORDS5 ; WHILE
124 .word DUP,LIT,2,MINUS,FETCH ; replace NFA MAX by its [LFA]
125 .word ROT,PAD,PLUS,STORE
126 .word DUP,COUNT ; display NFA MAX in 10 chars format
127 .word lit,07Fh,ANDD,TYPE
128 .word CFETCH,lit,0Fh,ANDD
129 .word lit,10h,SWAP,MINUS
131 .word BRAN,WORDS2 ; REPEAT
138 .IFNDEF ANS_CORE_COMPLIANT
140 ;https://forth-standard.org/standard/core/MAX
141 ;C MAX n1 n2 -- n3 signed maximum
143 MAX: CMP @PSP,TOS ; n2-n1
148 ;https://forth-standard.org/standard/core/MIN
149 ;C MIN n1 n2 -- n3 signed minimum
151 MIN: CMP @PSP,TOS ; n2-n1
158 ;https://forth-standard.org/standard/core/UDotR
159 ;X U.R u n -- display u unsigned in n width
162 .word TOR,LESSNUM,lit,0,NUM,NUMS,NUMGREATER
163 .word RFROM,OVER,MINUS,lit,0,MAX,SPACES,TYPE
167 ;https://forth-standard.org/standard/tools/DUMP
170 PUSH &BASE ; save current base
171 MOV #10h,&BASE ; HEX base
172 ADD @PSP,TOS ; -- ORG END
174 .word SWAP,OVER,OVER ; -- END ORG END ORG
175 .word UDOT,LIT,1,MINUS,UDOT ; -- END ORG display org end-1
176 .word LIT,0FFFEh,ANDD,xdo ; -- END ORG_modulo_2
178 .word II,lit,7,UDOTR,SPACE ; generate address
179 .word II,lit,10h,PLUS,II,xdo ; display 16 bytes
180 DUMP2 .word II,CFETCH,lit,3,UDOTR
181 .word xloop,DUMP2 ; bytes display loop
183 .word II,lit,10h,PLUS,II,xdo ; display 16 chars
184 DUMP3 .word II,CFETCH
185 .word lit,7Eh,MIN,FBLANK,MAX,EMIT
186 .word xloop,DUMP3 ; chars display loop
187 .word lit,10h,xploop,DUMP1 ; line loop
188 .word RFROM,FBASE,STORE ; restore current base