OSDN Git Service

V4.0
[fast-forth/master.git] / README.md
1 ## FastForth for MSP430FRxxxx TI's CPUs, light, fast, reliable.
2
3
4 Tested on TI MSP-EXP430FR
5 [5739](https://duckduckgo.com/?q=MSP-EXP430FR5739&iax=images&ia=images),
6 [**5969**](https://duckduckgo.com/?q=MSP-EXP430FR5969&iax=images&ia=images),
7 [**5994**](https://duckduckgo.com/?q=MSP-EXP430FR5994&iax=images&ia=images),
8 [6989](https://duckduckgo.com/?q=MSP-EXP430FR6989&iax=images&ia=images),
9 [4133](https://duckduckgo.com/?q=MSP-EXP430FR4133&iax=images&ia=images),
10 [2476](https://duckduckgo.com/?q=LP-MSP430FR2476&iax=images&ia=images),
11 [**2355**](https://duckduckgo.com/?q=MSP-EXP430FR2355&iax=images&ia=images),
12 [2433](https://duckduckgo.com/?q=MSP-EXP430FR2433&iax=images&ia=images) launchpads, at 1, 2, 4, 8, 12, 16 MHz plus 20 & 24 MHz with MSP430FR(23xx,57xx) devices.
13
14
15 note: if you want to write a program to make a LED flash, i suggest you to go [here](https://www.raspberrypi.com),
16       but if you want to deepen your programming basics, you've come to the right place.
17
18 FastForth is a "Just In First" Load-Interpret-Compile Operating System for all the 16/20 bits CPU MSP430FRxxxx (MSP430 with FRAM) :
19
20 * LOAD: choice of the TERMINAL interface:
21
22     * UART TERMINAL up to 6MBds @ MCLK=24MHz, with software (XON/XOFF) or hardware (RTS) control flow, **transmit delay: 0 ms/char, 0 ms/line**
23
24     * a very well designed **I2C TERMINAL**, with a full duplex behaviour, ready to communicate with all the targets **I2C_FastForth** wired on its I2C bus,
25     
26 * INTERPRET: with a 16-entry word-set that speeds up the FORTH interpreter by 4,
27
28 * COMPILE: in addition to the FORTH engine, the **MSP430 assembler, label free, with the TI's syntax** (not the FORTH one!),
29
30 and as result "Load Interpret Compile" a source file is faster and easier than **just** loading its equivalent TI.txt binary file via the TI's eZFET interface. 
31 For example, with a target running at 24MHz, UART=6MBds 8n1, an USBtoUART bridge [PL2303GC](https://duckduckgo.com/?q=DSD+TECH+SH-U06A) 
32 and [Teraterm.exe](https://osdn.net/projects/ttssh2/releases/) as TERMINAL, 
33 the "JIF" process of the /MSP430-FORTH/CORETEST.4TH file is done at an **effective rate** up to 800 kBds, up to 500 kBds with an I2C_Slave target running at 24MHz, and beyond 1Mbit/s from a SD_CARD.  
34 This is, by far, unparalleled on the planet FORTH, and on others too.   
35
36 Despite its **size of 4.75 kb** FastForth includes:
37
38 * FORTH kernel with interpreting decimal, hex, binary (#,$,% prefixed) numbers, digits separator '_', 'char', double numbers and Q15.16 numbers,
39
40 * the assembler for MSP430 (with TI's syntax),
41
42 * a good error handling which discards the "JIF" process of source files and thus avoids system crash,
43
44 * a memory management which can be modulated according to these 3 levels (software|hardware): `-1 SYS`|`<SW1+RST>`, `MARKER`|, `6 SYS`|`<RST>`.
45
46 * everything you need to write a real time application:
47
48     * the complete set of the FORTH building definitions,
49
50     * conditional compilation,
51
52     * thanks to [GEMA preprocessor](http://gema.sourceforge.net/new/index.shtml), the compilation of all symbolic addresses without having to declare them in FORTH, 
53
54     * easy roundtrip between FORTH and ASSEMBLER levels with only two 'one word' switches: `HI2LO`, `LO2HI`,
55
56     * automatic releasing memory with `MARKER` and `RST_SET`/`RST_RET` tags,
57
58     * Fully configurable sequences reset, init and background,
59
60     * CPU in sleep mode LPM0|LPM4 in awaiting a command from UART|I2C TERMINAL, and ready to process any interrupts.
61
62 If you want to quickly get an idea of what Fast Forth can do, see the /MSP430-FORTH/UARTI2CS.f application file. 
63 You will see that the FORTH language is used here as packaging of the program written in assembler.
64 See /MSP430-FORTH/FF_SPECS.f for another point of view.
65
66 For only 3 kbytes in addition, we have the primitives to access the SD_CARD FAT32: read, write, del, download source files and also to copy them from PC to the SD_Card.
67 It works with all SD\_CARD memories from 4GB to 64GB with FAT32 format.
68
69 With all the kernel addons, including the 20 bits MSP430\_X assembler and the SD\_Card driver, FastForth size is **10 kB**.
70
71 Once downloading /MSP430-FORTH/CORE_ANS.f file (2.25 kb), FastForth passes the tests: /MSP430-FORTH/CORETEST.4TH ( CORE ANS94 + COREPLUSTEST ), thus proving its compliance with the ANS94 standard.
72
73 However, if all works well with Windows 10, it works less well with Linux due to the lack of a good alternative to TERATERM...
74
75 Note: please, for each update download all subdirectories to correctly update the project.
76
77 ## how to connect TERMINAL
78
79     The files \binaries\launchpad_xMHz.txt are the executables ready to use with a serial terminal 
80     (TERATERM.exe), with XON/XOFF or RTS_hardware flow controls and a PL2303TA/CP2102 cable.
81     ------------------------------------------------------------------------------------------
82     WARNING! doesn't use it to supply your launchpad: red wire is 5V ==> MSP430FRxxxx destroyed!
83     ------------------------------------------------------------------------------------------
84     (modify this first: open the box and weld red wire on 3.3V pad).
85
86 ### programming with MSP430Flasher/UniFlash and FET interface:
87
88             J101 connector
89                     |
90                     v
91      TI Launchpad <--> FET interface  <-------------> USB <-------->COMx<----> MSP430Flasher.exe/UniFlash
92               Vcc <--- 3V3
93        TST/SBWTCK <--> SBWTCK        ) 
94               GND <--> GND           > used to program MAIN
95       RST/SBWTDIO <--> SBWTDIO       ) 
96
97      TI Launchpad <--> CP2102/PL2303 cable <--------> USB <-------->COMy<----> TERATERM.exe 
98                RX <--- TX            )
99               GND <--> GND           > FastForth TERMINAL
100                TX ---> RX            )
101      Pin Px.y RTS ---> CTS (optionnal) RTS pin Px.y is described in your \inc\launchpad.asm)
102     
103 ## Out of the box
104
105 Once FastForth is loaded in the target FRAM memory, you add assembly code or FORTH code, or both,
106 by downloading your source files which embedded FastForth interprets and compiles.
107     
108 Beforehand, the preprocessor GEMA, by means of a \config\gema\target.pat file, will have translated
109 your generic MSP430FR.f source file in a targeted MSP430FRxxxx.4th source file, allowing you to use
110 symbolic addressing for all peripheral registers (SFR), without having to do FORTH declarations.
111 A set of .bat files in \MSP430-FORTH folder is furnished to do all this automatically.
112     
113 To see all specifications of FastForth, download \MSP430-FORTH\FF_SPECS.f.
114
115 To change the UART TERMINAL baudrate on the fly, 9600 Bauds up to 6 MBds, download \MSP430-FORTH\CHNGBAUD.f.
116 Beyond 1 MBds, shorten the PL2303HXD cable, down to 50 cm for 6MBds.
117
118 XON/XOFF flow control allows 3.75kV galvanic isolation of terminal input with SOIC8 Si8622EC|ISO7021.
119
120 If you choose I2C_FastForth for your project, you will need of one more launchpad to make the UARTtoI2C bridge.
121 See driver for it :  \MSP430-FORTH\UARTI2CS.f.
122
123 Notice that FAST FORTH interprets lines up to 84 chars, only SPACE as delimiter, only CR+LF as
124 End Of Line, and BACKSPACE; all other control chars are discarded. 
125 And that the high limit of a FORTH program memory is $FF40. 
126
127 Finally, using the SCITE editor as IDE, all is ready to do everything from its "tools" menu.
128
129 What is new ?
130 -------------
131
132 ### V4.0, the last.   
133
134 * = V3.9 - 26 bytes.
135
136 * `HNDCODE` and `TICK` fixed
137
138 * `KEY` and `EMIT` rewritten, also `ECHO` and `NOECHO`
139
140 * the assembler handles correctly argument+/-offset
141
142 * the SD_Card driver is re-rewritten
143
144     * it only supports FAT32 format and SD Cards from 4 GB to 64 GB
145
146     * FAT32 Directories can be enlarged
147
148     * fixed errors handling
149
150 * the driver UART to I2C is enhanced and more reliable
151
152 * added DOUBLE.asm in /ADDONS (DOUBLE word set)
153
154
155 ### V3.9   
156
157 * = V3.8 - 350 bytes.
158
159 * removed `INTERPRET`, `CR` and the useless error line displaying.
160
161 * Removed `PWR_HERE` and `PWR_STATE`, replaced `RST_HERE` by `RST_SET` and `RST_STATE` by `RST_RET`.
162
163 * Replaced `WIPE` by `-1 SYS`, `COLD` by `4 SYS` and `WARM` by `0 SYS` or simply `SYS`.
164
165 * replaced `VOCABULARY` with `WORDSET`. `ALSO` is removed because the executing of a definition created by `WORDSET` adds it into the CONTEXT stack. For example, typing `FORTH` adds it into CONTEXT. Note that as result the use of ONLY is modified: `FORTH ONLY` instead of ~~`ONLY FORTH`~~.
166
167 * modified QNUMBER QABORT `ABORT` `QUIT` `HI2LO` `PREVIOUS` `WORD` `FIND` `>NUMBER` `TYPE` `#>` `COUNT` `SWAP` `TICK` `POSTPONE` `COLON` `[ELSE]` plus the assembler.
168
169 * The bootstrap ON/OFF is modified: `BOOT` / `NOBOOT` to enable / disable it.
170
171 * the word-set `ASSEMBLER` is renamed `hidden` because it stores not only the ASM instructions definitions but also HDNCODE definitions.
172
173 * when you execute a `MARKER` definition, it starts by removing from its previous definition if exists.
174
175 * Some bugs corrected:  
176     * QNUMBER FORWDOES `TYPE` `WORD`, 
177     * `M*/` in \MSP430-FORTH\DOUBLE.f file, 
178     * ~~the assembler handles correctly argument+/-offset.~~
179
180 * User can choose floored or symmetric division. See \MSP430-FORTH\ANS_CORE.f
181
182 * the words `:NONAME` `IS` `DOES>` `CODENNM` are added to the core and there is still enough room in its 5kb for the VOCABULARY_SET add-on.  
183   DEFER is not included because too easy to replace by a CODE definition, see CR in file CORE_ANS.f. 
184
185 * When used with VOCABULARY_SET activated, `RST_SET`/`RST_RET` and definition/use of `MARKER` tags save/restore the full word-set environment: DP, CURRENT, CONTEXT stack, VOCLINK.
186
187 * FF_SPECS.f displays all word-sets, including the `hidden` one.
188
189 * the SD_Card driver is rewritten. Only FAT32 format is supported. I suggest 4kb sized clusters.   
190   The old `WRITE"` command is duplicated :  
191     * `WRITE"` to create a new file (to overwrite if found),  
192     * `APPEND"` to append to a file (to create it if not found)
193
194
195 ### V3.8
196
197 * = V3.7 - 16 bytes.
198     
199 * Source file copy from TERMINAL to the SD\_Card of any I2C\_FastForth target works fine.
200     
201 * ~~The bootstrap call is modified: `' BOOT IS WARM` to enable it, `' BOOT [PFA] IS WARM` to remove it~~.
202
203 * `ASM` definitions are renamed `HDNCODE` (HiDdeN CODE), `ENDASM` is replaced by `ENDCODE`.
204
205     `HDNCODE` definitions are identical to low level `CODE` ones, but are hidden because defined in the ~~`ASSEMBLER`~~ `hidden` word set, and must be used only
206     in the scope of another low level CODE definition. See use in \MSP430-FORTH\UARTI2CS.f.
207     
208 * FastForth passes CORETEST + COREPLUSTEST tests. See modified \MSP430-FORTH\CORETEST.4TH
209
210 * Double number word `D<` corrected in \MSP430-FORTH\DOUBLE.f
211
212
213 ### V3.7
214
215 * 54 bytes added to (Kernel + Conditional_Compilation + Assembler).
216
217 * ~~Source file copy from I2C_TERMINAL to the SD_Card of any I2C_target works now.~~
218     
219 * In addition of target's ID test made by Teraterm macro, a preamble has been added to all
220     \MSP430-FORTH\source.f files to prohibit their downloading with another version of FastForth.
221
222 * Words @ ! ALLOT come back from "ANS_COMP" add-on to core.
223
224 * Recognized prefixes are $ # % and ' respectively for hex decimal binary and ASCII 'char' numbers.  
225     Examples: 'U' - $55 = 0, '3' - #33 = 0, '@' - %0100_0000 = 0.  
226     When use in source.f files, all ASCII special chars are available. See \inc\FastForthREGtoTI.pat.
227
228 * Assembler allows "argument+offset" into FORTH area (0 to $FFFF). Examples:  
229  `MOV #RXON,&BACKGRND+2` to store RXON addr at BACKGRND+2 addr.  
230  `MOV.B BUFFER-1(X),TOS` to load the byte at BUFFER-1(X) addr in the register TOS.
231     
232 * `6 SYS` does same than hardware RST.  
233   `-1 SYS` does same than hardware SW1+RST (DEEP_RESET).  
234
235
236 * More complicated:
237
238   In the FastForth init process, COLD WARM BACKGRND are modified and INIT_FORTH is added.  
239   They start each with a call to a paired assembly subroutine:
240       
241           RST_SYS failures ------------>+       +<- ABORT_TERM <--- ABORT" <--- (error) <---+<-- COMPILE/EXECUTE<-INTERPRET <--+
242                                         |       |                                           |                                  ^
243           RST ----------->+             |       v                                           v                                  |
244                           v             |       +-> INIT_FORTH ----------->+-> ABORT->QUIT->+->ACCEPT->+            +->ACCEPT->+
245           SW1+RST ------->+             |           ==========             ^                           |            ^
246                           v             v                                  |                           v            |  
247           -n SYS -------->+---> COLD -->+->PUC->+-> INIT_FORTH --> WARM -->+                           +->BACKGRND->o  
248                           ^     ====            ^   ==========     ====                                   ========  ^
249                           |                     |                                                                   \
250           +n SYS (even) ->+                     |                                                                   /
251                                                 |                                                                   \
252           +n SYS (odd) -->+--> (NOPUC) -------->+                                                        UART_RX_INT/I2C_START_INT
253                           ^     ==== 
254           [0] SYS ------->+
255    
256                       CALL...   &STOP_APP          &SOFT_APP      &HARD_APP                              &BACKGRND_APP
257                                 =========          =========      =========                              =============
258
259            Default subroutine   INIT_STOP          INIT_SOFT      INIT_TERM                              INIT_BACKGRND
260                Default action   UART: wait idle    do nothing     init TERM UC..                         UART: send RXON
261                                 I2C: do nothing                   ..unlock I/O                           I2C: send Ctrl_Char $00 
262           
263           note: -n SYS|SW1+RST reset the default subroutine of these four calls. 
264                 don't use TOS in these subroutines.
265
266     On the other hand, MARKER is modified in such a way that MARKER\_DOES executes a CALL to
267     the content of USER_BODY-2,   by default RET_ADR:
268     
269         MARKER [CFA]         = DODOES
270                [PFA]         = MARKER_DOES
271                [BODY]        = previous DP (Dictionnary Pointer)
272                ...
273                [USER_PARAM-2] = RET_ADR  as REMOVE_APP by default
274
275
276 By replacing [USER_PARAM-2] with the address of a new defined subroutine (named for example: REMOVE_XXX), 
277 MARKER_DOES will execute it to restore n critical pointers (room made by 2n ALLOT) at USER_PARAM, USER_PARAM+2, ...
278
279 Thus, with MARKER and the definition of subroutines STOP_XXX, SOFT_XXX, HARD_XXX, BACKGRND_XXX, 
280 the programmer has full control of his "XXX" real time application using interrupts, 
281 with everything he needs to start, stop and remove it properly, thanks to this 'soft' MARKER definition, 
282 avoiding the hardware (SW1+RST) of the last chance. 
283
284 See example in  /MSP430-FORTH/UARTI2CS.f.
285
286
287 ### V3.6
288
289 * 8 bytes added to (Kernel + Conditional_Compilation + Assembler).
290     
291 * Fixed the crash caused by forgetting the prefix '&' in the last term of an assembly instruction.
292     (the TI's symbolic mode is not implemented).
293     
294 * Added in the macro \config\SendFile.ttl the word ?ID to prevent any crash during download
295     due to a device confusion:
296
297    when downloading a source_file.f asked from the scite editor or by the use
298    of SendSourceFileToTarget.bat, Teraterm macro first sends ?ID definition then 
299    the string:  %deviceID% ?ID.  
300    By executing ?ID, FastForth substracts %deviceID% value from the target's one then 
301    executes ABORT" DeviceID mismatch!" : the downloading is aborted if DeviceID mismatch.  
302    %deviceID% is provided by the file \config\select.bat.
303
304    When downloading a source_file.4TH, it's up to you to be careful because 
305    Teraterm sends the string 0 ?ID, so that ?ID bypasses the substraction.   
306     
307 * Added the word set DOUBLE in the \MSP430-FORTH\DOUBLE.f file.
308
309 ### V3.5
310
311 * 48 bytes removed.
312     
313 * from Scite menu, we can program MSP430FRxxxx also with BSL_Scripter.
314     
315     To do, save file \prog\BSL_Scripter.exe from: 
316     https://github.com/drcrane/bslscripter-vs2017/releases/download/v3.4.2/BSL-Scripter-v3.4.2.zip,
317     but erasing a MSP430FR2355 or MSP430FR2476 doesn't work, thanks to BSL V. 00.09.36.B4 & B5.
318     See SLAU550Z tables 16 & 17.
319     
320     and buy a USB2UART module CP2102 6 pin. On the web, search: "CP2102 3.3V DTR RTS" 
321     For wiring, see \config\BSL_Prog.bat.
322     
323     So, we download both binaries and source files with only one CP2102|PL2303TA module,
324     the XON/XOFF TERMINAL and BSL_Scripter. Bye bye T.I. FET!
325     
326 * ABORT messages display first the I2C address, if applicable.
327
328 * QNUMBER some issues solved.
329 * UART version of ACCEPT and KEY are shortened.
330 * EVALUATE is moved to CORE_ANS.
331
332 ### V3.4
333
334 * 36 bytes removed.
335     
336 * Fixed: word F. issue in FIXPOINT.asm
337     
338 * the new kernel DEFERRED option adds :NONAME CODENNM DEFER IS.
339     
340 * pin RESET is software replaced by pin NMI and so, RESET executes COLD, allowing code insert before BOR.
341   however SYSRSTIV numbering remains unchanged: = 4 for RESET, = 6 for COLD.
342     
343 * Hardware Deep RESET (S1+RST) reinitializes vectors interrupts and SIGNATURES area, as WIPE.
344     
345     
346 * A newcomer: FastForth for I2C TERMINAL. With the driver UART2I2CS running on another FastForth target, 
347 we have the USB to I2C_Slave bridge we need: one TERMINAL for up to 112 I2C_FastForth targets.
348
349                                                                                       +-------------------------+ 
350         notebook                     USB to I2C_Slave bridge                    +-I2C-| others I2C_slave target | 
351       +-----------+      +-------------------------------------------------+   /    +-------------------------+ | 
352       |           |      Â¦ PL2303HXD         target running UARTI2CS @24MHz¦  +-I2C-|  MSP430FR4133 @ 1 MHz   | |
353       |           |      Â¦------------+       +----------------------------¦ /   +--------------------------+ |-+
354       |           |      Â¦            | 3wires|   MSP430FR2355 @ 24MHz     Â¦/    |   MSP430FR5738 @ 24 MHz  | |
355       | TERATERM -o->USB-o->USB2UART->o->UART-o-> FAST FORTH -> UARTI2CS  -o-I2C-o-> FAST FORTH with option |-+
356       | terminal  |      Â¦            | 6MBds |               (I2C MASTER) Â¦     |  TERMINAL_I2C (I2C SLAVE)| 
357       |           |      Â¦------------+       +----------------------------¦     +--------------------------+
358       |           |      Â¦            |< 20cm>|                            Â¦       up to 112 I2C_Slave targets  
359       +-----------+      +-------------------------------------------------+
360
361 With the indicated MCLK and UART speed, Coretest.4th (45896 bytes) is downloaded to (and executed by) I2C_Slave in 1220ms.   
362 The driver UARTI2CS works without error from 1MHz to 24MHz MCLK and from 115200Bds up to 6MBds UART.  
363 With I2C_Master running at 24 MHz, the I2C bus frequency is about 1MHz, and it works fine
364 even if I2C_slave is running at 1 MHz.
365 Don't forget to add two 3k3 pullup resistors on SCL and SDA...
366
367 the Multi Master Mode works but is not tested in multi master environment.
368     
369 "Cerise sur le gâteau": when they wait for a TERMINAL input (idle state), 
370 both I2C_Master and I2C_Slave(s) are sleeping in LPMx mode and the bus I2C is freed. 
371 The I2C_slave driver handles LPM4 mode.
372     
373 The UART2I2CS does not use TI's horrible UCBx_I2C_Master driver, but a much faster software driver,
374 with one more UCBx still available for an I2C_Slave or SPI driver.
375
376 ##### HOW TO DO ?
377
378     first you make the I2C cable (GND,SDA,SCL,3V3) between your 2 LaunchPad, with 3,3k pullup resistors
379     on SDA and SCL lines. See in forthMSP430FR_TERM_I2C.asm to select SDA and SCL pins.
380     
381     to compile FastForth for I2C TERMINAL from forthMSP430FR.asm file:
382     -  uncomment the line "TERMINAL_I2C".
383     -  search "I2CSLAVEADR" line and set your <slave address you want>, i.e. 10h.
384     -  compile file then prog your I2C_Slave LaunchPad.
385     
386     with the another LaunchPad running FastForth:
387     At the end of UART2I2CS.f file set the <slave address you want>, i.e. $10.
388     then download it, it's done: TERMINAL is linked to I2C_Slave.
389     
390     Type `Alt+B` on teraterm (send a BREAK) or press S2 on UARTtoI2C module to unlink I2C_Slave.
391
392 ### PREVIOUS versions
393     
394 Unlocking I/O's is transfered from RESET to WARM.
395 Thus, by redefining HARD_APP, you can add I/O's configuration for your application before a global unlocking.
396
397
398 The structure of primary DEFERred words as KEY,EMIT,CR,ACCEPT... is modified,
399 the address of their default execute part, without name, can be found with: `' <name> >BODY`
400
401 example, after this entry: `' DROP IS KEY` KEY runs DROP i.e. runs the redirection made by IS,  
402
403 but `' KEY >BODY EXECUTE` runs KEY, the default action at the BODY address.
404
405 and `' KEY >BODY IS KEY` restores the default action of this **primary** DEFERred word.
406
407
408 to build a **primary** DEFERred definition, you must create a CODE definition followed by a :NONAME definition:
409
410     CODE SPACES         \ create a CODE definition named 'SPACES' which does a jump to the NEXT_ADR instruction to do nothing
411     MOV #NEXT_ADR,PC    \ CFA = code of the instruction, PFA = parameter I of the instruction = NEXT_ADR
412     ENDCODE             \ this definition 'SPACES' does nothing, for the moment...
413
414     :NONAME             \ starts a FORTH definition without name
415     BEGIN
416         ?DUP
417     WHILE
418         'SP' EMIT
419         1-
420     REPEAT
421     ;
422     IS SPACES           \ this :NONAME execution_address is stored at PFA of SPACES, replacing NEXT_ADR
423     
424 The advantage of creating primary DEFERred definitionss is to set their
425 default execution subroutine at their BODY address, enabling to reinitialize them easily:
426 ' truc >BODY IS truc
427
428 Same with CODENNM definition, as low level equivalent of :NONAME
429
430     CODE TSTBIT         \ create a CODE definition named 'TSTBIT' which does a jump to the NEXT_ADR instruction to do nothing
431     MOV #NEXT_ADR,PC    \ CFA = instruction, PFA = NEXT_ADR
432     ENDCODE             \ this definition 'TSTBIT' does nothing, for the moment...
433
434     CODENNM             \ starts an assembly definition without name
435     MOV @PSP+,X
436     AND @X,TOS
437     MOV @IP+,PC
438     ENDCODE             \ -- execution_address_of_CODENNM
439     IS TSTBIT           \ this CODENNM execution_address is stored at PFA of TSTBIT, replacing NEXT_ADR
440
441 you can obviously mix LOW/HIGH levels in CODENNM and :NONAME
442
443 All interpretation/compilation errors now execute ~~`PWR_RET`~~ `RST_RET`, so any incorrect definition
444 and all its source file will be automatically erased.
445     
446
447 Accept SD_Card from 4 to 64 GB (FAT32).  
448 Note that Windows 10 no longer offers the FAT32 format for the highest sizes of SD_CARD memory.
449 So you must use an alternative to do, for example: https://www.partitionwizard.com.
450
451
452 Added direct file transfer from PC to the target SD_CARD.  
453 Measured throughput with "HCI" SD CARD: 90 kbytes/s at 3Mbauds TERMINAL and 16MHz MCLK.
454 You can do it from scite editor (menu Tools) or by using specific bat file.
455 Double click on it to see how to do.
456
457 JTAG and BSL signatures (FF80h-FF88h) are protected against overwrite during source file download. 
458
459
460 ## Many thanks to Brad Rodriguez
461
462 for his CamelForth which served me as a kind of canvas.
463 And also to Matthias Koch for its ideas about Q15.16 implementation.
464
465 Unlike CamelForth FASTFORTH is a "Direct Threaded Code", with an embedded assembler following the standard syntax,
466 not the one used in the world Forth.
467
468 It is optimized for the speed, especially in the interpreter mode, so that you can load an application program written in FORTH/Assembler faster than its binary via MSP430 Flasher.exe.
469 Everything can be done from your text editor, the preprocessor and a serial terminal.
470
471 ## What's this and why?
472
473 I have first programmed atmel tiny devices.
474 Particularly I2C master driver to have both I2C slave and I2C master on a ATtiny461.
475 which means a lot of back and forth between the editor, assembler, the programmer and the test in situ.
476
477 Previously I had programmed a FORTH on a Motorola 6809 and had been seduced by the possibility of sending a source file directly to the target using a serial terminal. Target which compiled and executed the program. At the time FORTH program lay in a battery backed RAM.
478
479 The advent of chip MSP430 TEXAS INSTRUMENT with embedded FRAM gave me the idea to do it again : FAST FORTH was born.
480
481 Today I dropped the ATMEL chips and proprietary interfaces, I program my applications in a mix 80%/20% of assembler/FORTH I then sent on MSP430FR5738 chips with embedded FAST FORTH.
482
483 And that's the magic: After I finished editing (or modify) the source file, I press the "send" button in my text editor and I can test result on target in the second following. This is the whole point of an IDE reduced to its simplest form: a text editor, a cable, a target.
484
485
486 ## build your FastForth local copy
487
488 download https://framagit.org/Jean-Mi/FAST-FORTH/tree/master
489 Once you have unzipped it into your folder, share it - with you - and notice its network path.
490 Then right clic on the root of your notepad to create a network drive by recopying this network path (change backslashes \ to / ); then set drive letter as you want.
491
492 In explorer you should obtain this back your driver letter:
493
494
495     \ForthMSP430FR.asm                main FASTFORTH program
496     \ForthMSP430FR_ASM.asm            assembler
497     \ForthMSP430FR_EXTD_ASM.asm       extended assembler 
498     \ForthMSP430FR_CONDCOMP.asm       conditionnal compilation
499     \ForthMSP430FR_SD_ACCEPT.asm      ACCEPT for SD_Card
500     \ForthMSP430FR_SD_INIT.asm        init SD_CARD (FAT16/32)
501     \ForthMSP430FR_SD_LOAD.asm        load source files from SD_CARD
502     \ForthMSP430FR_SD_LowLevel.asm    SPI routines + Read / write sector 
503     \ForthMSP430FR_SD_RW.asm          read create write del SD_CARD files + file copy to SD_CARD
504     \ForthMSP430FR_TERM_I2C.asm       I2C terminal
505     \ForthMSP430FR_TERM_UART.asm      full duplex UART terminal
506     \ForthMSP430FR_TERM_UART_HALF.asm half duplex UART terminal
507     \SciTEDirectories.properties      copy of \config\scite\AS_MSP430\SciTEDirectories.properties
508
509     \ADD-ON\                          FASTFORTH OPTIONAL KERNEL ADD-ON (not erasable version)
510            \CORE_ANS.asm              set of complementary words to pass CORETEST.4TH
511            \FIXPOINT.asm              adds HOLDS F+ F- F* F/ F#S F. S>F
512            \SD_TOOLS.asm              adds some trivial words to display sectors content
513            \UTILITY.asm               adds WORDS, DUMP, ? .S .RS
514     
515     \binaries\files.txt              ready for drag'n drop to prog.bat
516              \prog(.bat)             to do what ?...
517    
518     \config\
519            \asm.properties                      configuration for *.inc,*.asm files
520            \forth.properties                    configuration for *.f,*.4th files
521            \fortran.properties                  configuration for *.pat files
522            \SciTEDirectory.properties           copy it to your project root folder
523            \SciTEUser.properties                copy it in your home directory
524            \SendFile.ttl                        TERATERM macro file to send source file to FASTFORTH
525            \SendToSD.ttl                        TERATERM macro file to send source file to embedded SD_CARD 
526            \build(.bat)                         called by scite to build target.txt program 
527            \BSL_prog(.bat)                      to flash target with target.txt file with BSL_Scripter
528            \FET_prog(.bat)                      to flash target with target.txt file with MSP430Flasher
529            \CopyTo_SD_Card(.bat)                to copy in your MSP430-FORTH
530            \SendSource(.bat)                    to send file to FASTFORTH
531            \Preprocess(.bat)                    to convert generic .f file to specific .4th file
532            \CopySourceFileToTarget_SD_Card.bat  copy it in any user folder for drag'n drop use
533            \SendSourceFileToTarget.bat          copy it in any user folder for drag'n drop use
534            \PreprocessSourceFile.bat            copy it in any user folder for drag'n drop use
535            \SelectTarget.bat                    called to select target, device and deviceID
536     
537     \inc\                         MACRO ASsembler files.inc, files.asm, GEMA preprocessor files.pat
538         \TargetInit.asm           select target configuration file for AS assembler
539         \MSP_EXP430FRxxxx.asm     target minimalist hardware config to compile FastForth
540         \ThingsInFirst.inc        general configuration for AS assembler
541         \MSP430FRxxxx.inc         device declarations
542         \ThingsInLast.inc         general post configuration for AS assembler
543         \FastForthREGtoTI.pat     converts FORTH symbolic registers names to TI Rx registers
544         \tiREGtoFastForth.pat     converts TI Rx registers to FORTH symbolic registers names 
545         \MSP430FRxxxx.pat         device configuration for gema preprocessor
546         \MSP_EXP430FRxxxx.pat     target configuration for gema preprocessor
547
548     \prog\        SciTEGlobal.properties, TERATERM.INI + programs.url
549         
550 ### FORTH generic_source_files.f and targeted_source_files.4th
551
552     \MSP430-FORTH\
553                  \PreprocessSourceFile.bat            (link)
554                  \SendSourceFileToTarget.bat          (link)
555                  \CopySourceFileToTarget_SD_Card.bat  (link)
556                  \*.f            source files which must be preprocessed before downloading  
557                  \*.4th          source files ready to download to any target
558                  \LAST.4TH       last source target file issued by preprocessor
559                  \BOOT.f         performs bootstrap
560                  \CHNGBAUD.f     allows you to change terminal baudrate
561                  \CORE_ANS.f     same as CORE_ANS.asm, (but erasable) 
562                  \CORETEST.4TH   ANS core tests 
563                  \CORDIC.f       for afficionados 
564                  \DOUBLE.f       adds DOUBLE word set
565                  \FIXPOINT.f     same as FIXPOINT.asm, (but erasable)
566                  \FF_SPECS.f     shows all specificities of FAST-FORTH compiled on your target 
567                  \RTC.f          set date and time, one example of MARKER use.
568                  \RC5toLCD.f     multitasking example 
569                  \SD_TEST.f      tests for SD_CARD driver
570                  \SD_TOOLS.f     same as SD_TOOLS.asm, (but erasable)
571                  \TESTASM.f      some tests for embedded assembler
572                  \TESTXASM.f     some tests for embedded extended assembler
573                  \UARTI2CS.f     I2C_Master driver to link TERMINAL UART with any I2CSlave target
574                  \UTILITY.f      same as UTILITY.asm, (but erasable)
575     
576
577 Note: all actions (flashing target, download files) can be made by using bat files directly.
578 The next is to download IDE (WINDOWS):
579
580 ## First get TI's programs
581
582 [MSP430-FLASHER](https://www.ti.com/tool/MSP430-FLASHER), [MSP430_FET_Drivers](http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430_FET_Drivers/latest/index_FDS.html)
583
584 install in the suggested directory, then copy MSP430Flasher.exe and MSP430.dll to \prog\
585
586 ## download IDE
587
588 * [modified BSL-Scripter.zip](https://github.com/drcrane/bslscripter-vs2017/releases) and unzip as \prog\BSL-Scriper.exe
589
590 * [teraterm](https://osdn.net/projects/ttssh2/releases/)
591
592 * [GEMA general purpose preprocessor](https://sourceforge.net/projects/gema/files/latest/download), unzip in drive:\prog\
593
594 * [sCiTE single file executable](https://www.scintilla.org/SciTEDownload.html) to drive:\prog\, then rename Scxxx.exe to scite.exe
595
596 * [Macro AS](http://john.ccac.rwth-aachen.de:8000/ftp/as/precompiled/i386-unknown-win32/aswcurr-142-bld158.zip), unzip in drive:\prog\  
597
598 * [srecord](https://sourceforge.net/projects/srecord/files/srecord-win32/1.64/), unzip in drive:\prog\  
599
600
601 In explorer you should obtain that (minimum requested programs):
602
603
604     \prog\as.msg
605          \asw.exe
606          \BSL-Scripter.exe
607          \cmdarg.msg
608          \gema.exe
609          \ioerrs.msg
610          \MSP430.dll
611          \MSP430Flasher.exe
612          \P2hex.exe     
613          \P2hex.msg
614          \srec_cat.exe
615          \sCiTE.exe
616          \SciTEGlobal.properties
617          \tools.msg
618     
619
620 Next we need to change the drive letter in hard links below:
621
622     \binaries\prog.bat
623     \MSP430-FORTH\SendSourceFileToTarget.bat
624                  \CopySourceFileToTarget_SD_Card.bat
625                  \PreprocessSourceFile.bat
626
627 to do, right clic on them
628      select "properties"
629             set your drive letter in "target"
630
631 The last step is ask Windows to associate scite editor with file types:
632
633 right clic on a .asm file, 
634     select "open with", 
635             select "other application" then select: drive:\prog\scite.exe
636
637 repeat for .inc, .lst, .f, .4th, .pat, .properties, .TTL files.
638
639
640 IT's done ! See  forthMSP430FRxxxx.asm to configure TeraTerm
641
642
643 ## Build the program file
644
645 \forthMSP430FR.asm is the main file to compile FastForth:    
646
647 * Open forthMSP430FR.asm with scite editor
648
649 * uncomment the target as you want, i.e. MSP_EXP430FR5969
650
651 * choose frequency, baudrate, flow control.
652
653 * comment / uncomment options switches as your convenience.
654
655 * save file.
656
657 * assemble (CTRL+0). A window asks you for 4 parameters:
658
659 * set your target as first param, i.e. MSP_EXP430FR5969
660
661 * then execute. the output will be \binaries\MSP_EXP430FR5969.txt
662
663 ## Load Txt file (TI format) to target
664
665     in \binaries folder, drag your target.txt file and drop it on prog.bat
666     
667     or use scite internal command TOOLS: FET prog (CTRL+1).
668
669 nota : programming the device use SBW2 interface, so UARTn is free for serial terminal connexion.
670
671 If you want to program your own MSP430FRxxxx board, wire its pins TST, RST, 3V3 and GND 
672 to same pins of the launchpad, on eZ-FET side of the programming connector.
673
674 ## Connect the FAST FORTH target to a serial terminal
675
676 you will need an USBtoUART cable with a PL2303TA|PL2303HXD|PL1303GC device that allows both XON/XOFF 
677 and hardware control flow :
678
679 [PL2303GC](https://duckduckgo.com/?q=DSD+TECH+SH-U06A+PL2303GC)
680 [PL2303 driver](http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=225&pcid=41)
681
682 WARNING! always verify VCC PIN = 3.3V before use to supply your target with.
683
684 or with a CP2102 device and 3.3V/5V that allows XON/XOFF control flow up to 921600 Bds:
685
686 [CP2102 3.3V](https://duckduckgo.com/q=cp2102+3.3V+6PIN)
687 [CP2102 driver](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers)
688
689 WARNING! always verify VCC PIN = 3.3V before use to supply your target with.
690
691
692 ## Send a source file.f or file.4th to the FAST FORH target
693
694 Three bat files are done in \MSP430-FORTH that enable you to do all you want.
695 drag and drop your source file on to.
696 you can also open any source file with scite editor, and do all you want via its Tools menu.
697
698 If you have any downloading error, first verify in "LAST.4th" that all lines are 
699 correctly ended with CR+LF.
700
701 ## SD_Card driver
702
703 #### First, hardware
704
705 If you have MSP-EXP430FR5994, nothing to do.
706
707 For the choice of a SD card socket be carefull, pin CD (Card Detect) must be present! 
708 web search: "micro SD card 9 pin"
709 Look for the good wiring in /Launchpad.asm file
710
711 #### Compile with SD_Card addon
712
713 in forthMSP430FR.asm, uncomment lines SD_CARD_LOADER,  SD_CARD_READ_WRITE, SD_TOOLS 
714 then compile for your target
715
716 ### the commands
717
718 With the `LOAD"` pathame" command FastForth loads source files from a SD_CARD memory.
719
720     * LOAD" path\filename.4th" relative path,
721
722     * LOAD" \path\filename.4th" absolute path.
723
724 The file is interpreted by FORTH in same manner than from the serial terminal.  
725 When EOF is reached, the file is automatically closed.  
726 A source file can `LOAD"` another source file, and so on in the limit of 8 handles. 
727
728 `LOAD"` may be used as Change Directory command: 
729
730     * LOAD" \misc".       \misc becomes the current folder.
731
732     * LOAD" ..\"          parent folder becomes the current folder.
733
734     * LOAD" \"            Root becomes the current folder.
735
736
737 To read a file: `READ"` pathname"
738
739 * open it, the first sector is loaded in SD_BUF
740
741 The command `READ` sequentially loads the next sector in the buffer and leaves on the stack a true flag when the EOF is reached.    
742 The variable BufferLen keep the count of bytes to be read (1 to 512).
743
744 The file is automatically closed.  
745   
746 If you want to anticipate the end, remove the false flag left by the previous `READ` then use the `CLOSE` command.
747
748 To overwrite a file: `WRITE"` path\filename.ext".
749
750 * If the file does not exist, create it
751
752 * set the write pointer at the **beginning** of the file, ready to append chars.
753
754 To write a file: `APPEND"` path\filename.ext".
755
756 * If the file does not exist, create it
757
758 * set the write pointer at the **end** of the file, ready to append chars.
759
760 The command `WRITE` sequentially writes the SD_BUF in SD_CARD and increments the current sector.
761
762 Use `CLOSE` to close a WRITE file.
763
764 See examples of use in \MSP430-FORTH\SD_TEST.f.
765
766
767 #### Copy source file to SD_Card
768
769 to copy a source file (.f or.4th) to SD_CARD target, use CopySourceFileToTarget\_SD\_Card.bat.
770 Double click on one of this bat files to see how to do.
771
772 or use scite.
773
774 If you have any copy error, first verify in "LAST.4th" that all lines are 
775 correctly ended with CR+LF.
776
777 ## The system is not responding ?
778
779 First, remove the USBtoUART bridge then reconnect it. Perhaps it was in suspend state...
780
781 If the system is always freezed, press `RST` button on the MSP-EXP430FR5xxx ; FORTH restarts 
782 as it was after the last `RST_SET` command.
783
784 If the system does not restart again, press `SW1+RESET`. 
785 FORTH restarts in the state of its object file.
786
787 Here is the FastForth memory management, one of its major assets, with both hardware events and software equivalent:
788
789 *  RST_RET 
790     
791     *  when you type `RST_RET` the program beyond the last RST_SET is lost.
792
793     *  Running a `MARKER` definition will remove it and the program beyond. In addition the user can link it a routine to remove the modified configuration in system: vectors, hardware, I/Os... 
794
795
796 *  WARM level : `SYS` -->(no PUC)--> INIT_FORTH --> INIT_HARD --> WARM display --> ABORT --> ACCEPT --> BACKGRND --> SLEEP.
797
798     *  when you type `SYS`, FORTH restarts, the WARM display starts by #0. 
799     
800     *  when you type `+n SYS` (n>0, odd), the WARM display starts by #+n. 
801
802         * same effect as RST_RET
803
804         * words ACCEPT, EMIT, KEY are initialised with their default value,
805     
806         * TIB is initialised with its default value.
807
808
809 *  COLD level : `+n SYS` --> PUC --> INIT_FORTH --> INIT_HARD --> WARM display --> ABORT --> ACCEPT --> BACKGRND --> SLEEP.
810
811     *  Power ON : the WARM display starts with the SYSRSTIV value #2.
812     
813     *  hardware `RST` : the WARM display starts with the SYSRSTIV value #6, because RST pin acts as NMI pin.
814     
815     *  SVSHIFG SVSH event (supply dropout) : the WARM display starts with the SYSRSTIV value: #14.
816
817     *  PUC on failure : the WARM display starts with the SYSRSTIV value: #n.
818
819     *  other `+n SYS` (n>0 and even) are software RESET : the WARM display starts with the SYSRSTIV value "#+n" (even).
820
821         * same effects as WARM level, plus:
822
823         * performs a PUC.
824
825     
826
827 *  DEEP RESET level:
828
829     *  `-n SYS` (n<0) performs the software Deep Reset, WARM display = #-n.
830  
831     *  hardware `SW1+RESET`, WARM display = #-1.
832     
833     *  recompiling FastForth, WARM display = #-3.
834
835         * same effects as COLD level, plus:
836
837         *  all programs donwloaded from the TERMINAL or from the SD_CARD are lost,
838
839         *  COLD_APP, SOFT_APP, HARD_APP and BACKGND_APP default values are restored,
840
841         *  all interrupts vectors are initialised with their default value, 
842
843         *  SIGNATURES area is FFh full filled.
844
845
846 * ERROR : ABORT" your_text" --> INIT_FORTH --> display = "your_text" --> ABORT --> ACCEPT --> BACKGRND --> SLEEP. 
847     
848     *  when an error occurs, FASTFORTH discards the end of current downloading if any. In this way, any error is followed by the complete erasure of the bad defined word causing this error, and also by discarding the end of downloading of the source file including it. 
849
850
851 Once validate, it is strongly recommended to end any source file with `RST_SET` to protect the resulting program from a subsequent download error.
852
853 As all other FORTH words, `RST_SET` `RST_RET` and` MARKER` definitions may be freely used in compiling mode.    
854
855 If you have previously set `NOECHO`, there is no WARM display.
856
857 If you don't want to display an ABORT" message, type: `ABORT" "`
858
859 With I2C_FastForth version, WARM and `ABORT"` displays are preceded by the decimal I2C slave address, example: `@18`. 
860
861
862 ## VOCABULARY ADD-ON
863
864 These words are not ANS94 compliant.
865
866 The CONTEXT stack is 8 word_set sized.
867
868 after typing: `WORDSET TRUC`   a new word-set called TRUC is created, then:
869
870 * `TRUC`            adds the word-set TRUC first in the CONTEXT stack, the interpreter search existing definitions first in TRUC
871
872 * `DEFINITIONS`     adds news definitions in the first word-set in the CONTEXT stack, i.e. TRUC,
873 * `PREVIOUS`        removes TRUC from CONTEXT but new definitions are still added in TRUC
874 * `DEFINITIONS`     new definitions are added into the previous first word-set in the CONTEXT stack,
875 *  after `-1 SYS`, FORTH is the CONTEXT and the CURRENT word-set.
876
877
878 ## EMBEDDED ASSEMBLER
879
880 The preprocessor GEMA allows the embedded assembler to access all system variables. 
881 See files \\inc\\Target.pat. 
882
883 ### HOW TO MIX assembly and FORTH ?
884
885 FAST FORTH knows two modes of definitions :
886
887 * high level FORTH definitions `: <name> ... ;`
888
889 * assembly low level definitions `CODE <name> ... ENDCODE`
890
891 there is also some variations of these two modes :
892
893 * high level definitions `NONAME: ... ;`
894
895 * low level definitions `CODENNM ... ENDCODE`, low-level equivalent of `NONAME:`
896     
897 * low level definitions `HDNCODE <name> ... ENDCODE`, these definitions are 'hidden' and can be accessed only from assembly level.
898     
899 Examples:
900     
901     : NOOP              \ FORTH definition "NOOP", does nothing
902         DUP
903         DROP
904     ;
905
906
907     CODE ADD            \ low level definition "ADD", alias of word +
908         ADD @PSP+,TOS
909         MOV @IP+,PC
910     ENDCODE
911
912
913     HDNCODE WDT_INT         \ low level hidden definition "WDT_INT" (Watchdog interrupt)
914     BIT #8,&TERM_STATW      \ break (ALT+b) sent by TERMINAL ?
915     0<> IF                  \ if yes
916         MOV #ABORT,PC       \   continue with ABORT (no return)
917     THEN
918                             \ else return to background task SLEEP
919     BIC #%0111_1000,0(RSP)  \ force CPU Active Mode, disable all interrupts
920     RETI                    \
921     ENDCODE
922     
923     
924 At the end of low level CODE definition, the instruction MOV @IP+,PC jumps to the next definition. 
925 This faster (4 cycles) and shorter (one word) instruction replaces the famous pair of assembly 
926 instructions : CALL #LABEL ... RET (4+4 cycles, 2+1 words).  
927 The register IP is the Interpretative Pointer. 
928
929 High level FORTH definitions starts with a boot code "DOCOL" which saves the IP pointer and loads it with the first address
930 of a list of execution addresses, then performs a postincrement branch to the first one. 
931 The list ends with the address of another piece of code: EXIT (6 cycles) which restores IP before the instruction MOV @IP+,PC.
932
933 here, the compilation of low level ADD definition :
934
935                     header          \ compiled by the word CODE
936     execution addr  ADD @PSP+,TOS
937                     MOV @IP+,PC     \ instruction called NEXT
938
939 and the one of the high level word NOOP :
940
941                     header          \ compiled by the word :
942     execution addr  PUSH IP         \ boot code "DOCOL"...
943                     CALL rDOCOL     \ ...compiled by the word :
944                     addr of DUP     \ execution addr of DUP
945                     addr of DROP    \ execution addr of DROP
946                     addr of EXIT    \ execution addr of EXIT compiled by the word ;
947
948 _A high level FORTH word is a list of execution addresses preceded by a boot code and ending with EXIT address._
949
950 ### WRITING RULES
951
952 any low level FORTH words must be ended with the instruction MOV @IP+,PC (NEXT).
953
954         CODE TEST               \ CODE starts a low level word
955             asm1                \ assembly instruction 1
956             asm2                \ assembly instruction 2
957             MOV @IP+,PC         \ NEXT
958         ENDCODE                 \ end of low level word
959
960 If you want to use the IP register, save it before and restore it before NEXT
961
962         CODE TEST1              \ CODE starts a low level word
963             asm1                \ assembly instruction
964             ...
965             PUSH IP             \ save IP before use
966             MOV #1,IP           \ assembly instruction that uses IP
967             ...                 \ assembly instructions
968             MOV @RSP+,IP        \ restore IP
969             MOV @IP+,PC         \ NEXT
970         ENDCODE                 \ end of low level word
971
972 A little more complex, the case of mixing FORTH and assembly with use of the words HI2LO, LO2HI and COLON
973
974         : MIX_FORTH_ASM         \ definition of a FORTH word starts with :
975             SWAP
976             DUP
977         HI2LO                   \ FORTH to assembler switch
978             asm1                \ you can freely use IP
979             asm2
980             ... 
981             ...
982             MOV @RSP+,IP        \ restore IP stacked by :
983             MOV @IP+,PC         \ goto NEXT
984         ENDCODE                 \ end of low level word, compile nothing
985
986 If we see the code "MIX\_FORTH\_ASM" after compilation :
987
988             header              \ compiled by :
989     exec@   PUSH IP             \ 
990             CALL rDOCOL
991             addr of SWAP
992             addr of DUP
993             next addr           \ addr of asm1, compiled by HI2LO
994             asm1
995             asm2
996             ...
997             ... 
998             MOV @RSP+,IP        \ restore IP saved by boot code
999             MOV @IP+,PC         \ NEXT
1000
1001 going a step further :
1002
1003         CODE MIX_ASM_FORTH      \ CODE starts a low level word
1004             asm1
1005             asm2
1006         COLON                   \ starts high level
1007             word1
1008             word2
1009         ;                       \ end of high level word, compile EXIT
1010
1011 If we see this code "MIX\_ASM\_FORTH" after compilation :
1012
1013             header              \ compiled by CODE
1014     exec@   asm1
1015             asm2
1016     DOCOL   PUSH IP
1017             CALL rDOCOL         \ "DOCOL" compiled by COLON
1018             addr of word1
1019             addr of word2
1020             addr of EXIT        \ EXIT restores IP from stack then executes MOV @IP+,PC
1021
1022 A new step:
1023
1024         : MIX_FORTH_ASM_FORTH   \ definition of a FORTH word starts with :
1025             word1
1026             word2
1027             ...
1028         HI2LO                   \ FORTH to assembler switch
1029             MOV #0,IP           \ IP is free for use
1030             asm1
1031             ...
1032         LO2HI                   \ assembler to FORTH switch
1033             word3
1034             word4
1035         ;                       \ end of high level word
1036
1037 the compiled result    
1038
1039             header              \ )
1040     exec@   PUSH IP             \ > compiled by :
1041             CALL rDOCOL         \ )
1042             addr of word1
1043             addr of word2
1044             ...
1045             next addr           \ compiled by HI2LO
1046             MOV #0,IP           \ IP is free for use
1047             asm1                \ assembly instruction
1048             ...
1049             CALL rDOCOL         \ compiled by LO2HI
1050             addr of word3
1051             addr of word4
1052             addr of EXIT        \ compiled by ;
1053
1054 Still another step : 
1055
1056         CODE MIX_ASM_FORTH_ASM  \ CODE starts a low level word
1057             asm1
1058             asm2
1059         COLON                   \ start high level definition
1060             word
1061             ... 
1062         HI2LO                   \ switch high to low level
1063             asm3
1064             asm4
1065             MOV @RSP+,IP        \ restore IP
1066             MOV @IP+,PC         \ goto NEXT
1067         ENDCODE                 \ end of low level word
1068
1069 In fact, an exclusive of FAST FORTH, the start of a word FORTH can be placed anywhere :
1070
1071         CODE MIX_ASM_FORTH_ASM_FORTH
1072             asm1
1073             asm2
1074             ...
1075         COLON                   \ starts high level definition
1076             word1
1077             word2
1078             ...
1079         HI2LO                   \ FORTH to assembler switch
1080             asm3
1081             asm4
1082            ...
1083         LO2HI                   \ assembler to FORTH switch
1084             word
1085             word
1086             ...
1087         ;                       \ end of high level word
1088
1089 with the compiled result :
1090
1091             header              \ compiled by CODE
1092     exec@   asm
1093             asm
1094     DOCOL   PUSH IP             \ compiled... 
1095             CALL rDOCOL         \ ...by COLON
1096             addr
1097             addr
1098             next address        \ compiled by HI2LO
1099             asm
1100             asm
1101             CALL rDOCOL         \ compiled by LO2HI
1102             addr
1103             addr
1104             EXIT addr           \ that restores IP from return stack and then executes MOV @IP+,PC
1105
1106
1107 ### ASSEMBLER WITHOUT LABELS ? YES !
1108
1109 To compare AS macro assembler and FastForth embedded assembler,
1110 compare files \ADDON\FIXPOINT.asm and \MSP430-FORTH\FIXPOINT.f
1111
1112 The conditionnal instructions doesn't use labels.
1113 Instead, they borrow FORTH's conditional environment:
1114
1115     CODE TEST_IF_THEN
1116         CMP #1,R8           \ set Z,N,V, flags
1117         0= IF               \ irritating, the "IF 0=" upside down, isn't it?
1118             ADD R8,R9       \ true part of comparaison
1119         THEN                    
1120         ...                 \ the next
1121         ...
1122         MOV @IP+,PC         \ don't forget...
1123     ENDCODE                 \ don't forget...
1124
1125 and the complete version :
1126
1127     CODE TEST_IF_ELSE_THEN
1128         CMP #1,R8           \ set Z,N,V, flags
1129         0= IF               \
1130             ADD R8,R9       \ true part of comparaison
1131         ELSE
1132             SUB R8,R9       \ false part of comparaison
1133         THEN                    
1134         ...                 \ the next for the two branches
1135         MOV @IP+,PC
1136     ENDCODE
1137
1138 test for loop back version BEGIN ... UNTIL
1139
1140     CODE TEST_BEGIN_UNTIL
1141         MOV #8,R10
1142         BEGIN           
1143             SUB #1,R10      \ set Z,N,V flags
1144         0= UNTIL            \ loop back to BEGIN if flag Z is not set
1145         ... 
1146         MOV @IP+,PC
1147     ENDCODE
1148
1149 test for out of loop version BEGIN ... WHILE ... REPEAT
1150
1151     CODE TEST_BEGIN_WHILE_REPEAT
1152         MOV #8,R10
1153         BEGIN
1154             SUB #1,R10      \ set Z,N,V flags
1155         0<> WHILE           \ go to out of loop if X=0 (Z flag =1)
1156             XOR #1,R9   
1157         REPEAT              \ unconditionnal loop back to BEGIN 
1158         ...                 \ out of loop here
1159         MOV @IP+,PC
1160     ENDCODE
1161
1162 infinite loop :
1163
1164     CODE TEST_BEGIN_AGAIN
1165         BEGIN
1166             ADD #1,R9
1167         AGAIN               \ unconditionnal loop back to BEGIN 
1168     ENDCODE
1169
1170 to quit this infinite loop, press reset. 
1171
1172 We can nest several conditional branches :
1173
1174     CODE TEST_NESTED_IF_ELSE
1175         CMP #0,R10
1176         0= IF
1177             CMP #0,R10
1178             0= IF
1179                 MOV #0,R11
1180             ELSE
1181                 SUB #1,R11
1182             THEN
1183         ELSE
1184             MOV #1,R11
1185         THEN
1186         MOV @IP+,PC
1187     ENDCODE
1188
1189 another nest :
1190
1191     CODE TEST_NESTED_BEGIN_AGAIN_IF
1192         MOV #8,R9
1193         BEGIN
1194             CMP #-1,R9
1195             0= IF   
1196                 MOV @IP+,PC \ out of test_NESTED_BEGIN_AGAIN_IF
1197             THEN
1198             SUB #1,R9
1199         AGAIN
1200     ENDCODE
1201
1202 you can MIX conditional branches with a mix of FORTH/assembly: see TEST5 in the demo file \MSP430-FORTH\TESTASM.4TH
1203
1204
1205 FAST FORTH have one pass assembler, not able to resolve forward jumps.
1206
1207 I have added possibility of several "non canonical" jumps, up to 3 backward and up to 3 forward jumps to label :
1208
1209     \ C UM/MOD   udlo|udhi u1 -- ur uq
1210     CODE UM/MOD
1211         MOV @PSP+,W     \ 2 W = DIVIDENDhi
1212         MOV @PSP,S      \ 2 S = DIVIDENDlo
1213     \ T.I. ROUTINE  Section 5.1.5 of MSP430 Family Application Reports
1214         MOV #0,Y        \ 1 CLEAR RESULT
1215         MOV #16,X       \ 2 INITIALIZE LOOP COUNTER
1216     BW1 CMP TOS,W       \ 1
1217         U>= IF          \ 2
1218             SUB TOS,W   \ 1 if carry DIVIDENDhi-divisor
1219         THEN
1220     BEGIN
1221         ADDC Y,Y        \ 1 RLC quotient
1222         U>= ?GOTO FW1   \ 2 if carry Error: result > 16 bits
1223         SUB #1,X        \ 1 Decrement loop counter
1224         <0 ?GOTO FW2    \ 2 if 0< terminate w/o error
1225         ADD S,S         \ 1 RLA DIVIDENDlo
1226         ADDC W,W        \ 1 RLC DIVIDENDhi
1227         U< ?GOTO BW1    \ 2 if not carry    14~ loop
1228         SUB TOS,W       \ 1 if carry DIVIDENDhi-divisor
1229         BIS #1,SR       \ 1 SETC
1230     AGAIN               \ 2                 14~ loop
1231     FW2 BIC #1,SR       \ 1 CLRC  No error, C = 0
1232     FW1                 \  Error indication in C
1233     \ END of T.I. ROUTINE  Section 5.1.5 of MSP430 Family Application Reports
1234         MOV W,0(PSP)    \ 3 remainder on stack
1235         MOV Y,TOS       \ 1 quotient in TOS
1236         MOV @IP+,PC     \ 4
1237     ENDCODE
1238
1239 Forward labels FWx are for single use, backward labels BWx can solve several jumps,
1240 until their new definition.
1241
1242 ### SYMBOLIC ASSEMBLER ? YES !
1243
1244 I have discovered a little semantic preprocessor "GEMA", just like that FAST FORTH have its symbolic assembler !
1245
1246 * \inc\DEVICE.pat contains memory map and vectors for a specified DEVICE
1247 * \inc\LAUNCHPAD.pat is the I/O config file for specific LAUNCHPAD (or application)
1248
1249 Gema translates FORTH registers in ASM registers (R0 to R15) via \inc\ThingsInFirst.pat
1250
1251 With the three bat files in \MSP430_FORTH folder all is done automatically.
1252
1253 ### WHAT ABOUT VARIABLES, CONSTANTS...
1254
1255 In addition to the FORTH VARIABLE and CONSTANT definitions, the macroassembler allows to use symbolic variables and constants
1256 which are compiled / executed as number by the FORTH interpreter, also by the assembler, but only in the scope of a source use.f file with their declaration done in a use.pat file.
1257
1258 On the other hand, the CONSTANT, VARIABLE and MARKER definitions are correctly handled by the assembler which provides for each case the expected argument: the constant, the address of the variable and the address of the first user variable with MARKER.
1259
1260 Example:
1261
1262     VARIABLE BASE 
1263     $10 BASE !
1264     2 CONSTANT TWO
1265     MARKER {MYAPP}
1266     'ESC' , 'XON' C, 'XOFF' C,
1267     
1268     HDNCODE EXAMPLE         \ hidden definition because linked in the hidden word-set
1269     CMP #RET_ADR,&{MYAPP}-2 \ compare content of {MYAPP}-2 address with RET_ADR
1270     MOV &BASE,X             \ X = 16
1271     MOV #BASE,X             \ X = address of base
1272     MOV @X,X                \ X = 16
1273     MOV #TWO,Y              \ Y = 2
1274     MOV &{MYAPP},W          \ W = $1B
1275     MOV.B &{MYAPP}+2,W      \ W = 17
1276     MOV.B &{MYAPP}+3,W      \ W = 19
1277     MOV @IP+PC
1278     ENDCODE
1279
1280     CODE RUN_EXAMPLE
1281     MOV #EXAMPLE,PC         \ = BR EXAMPLE      runs EXAMPLE, without return
1282     ENDCODE
1283
1284
1285 # COMPILE FAST FORTH FOR YOUR TARGET
1286
1287 1- in forthMSP430FR.asm "TARGET configuration"  create a line for your target, example:
1288
1289     ;MY_MSP430FR5738_1 ; compile for my own MSP430FR5738 miniboard V1
1290
1291 2- create your \inc\MSP430FR5738_1.asm and \inc\MSP430FR5738.inc from another target.asm and device.inc as pattern, 
1292 Notice that you must define here only the necessary for FAST-FORTH compilation.
1293
1294 3- in \inc\ThingsInFirst.inc add one "device.inc" item:
1295
1296         .IFDEF MY_MSP430FR5738_1
1297     UCA0_UART   ; defines uart used for TERMINAL 
1298     LF_XTAL     ; defines if your module have a 32768 Hz xtal, to enable it.
1299     UCB0_SD     ; defines UC used for SD Card driver if any
1300         .include "MSP430FR5738.inc"  ; include device declarations
1301         .ENDIF
1302
1303 4- in \inc\TargetInit.asm add one "target.asm" item: 
1304
1305         .IFDEF MY_MSP430FR5738_1
1306             .include MY_MSP430FR5738_1.asm
1307         .ENDIF
1308
1309 Then, for the preprocessor which you will use when downloading FORTH source files:
1310
1311 1- create your \inc\device.pat file if not exist, from your \inc\device.inc and/or another \inc\device.pat as pattern.
1312
1313 2- create your \inc\target.pat file from your \inc\target.asm and/or another \inc\target.pat as pattern.
1314
1315 Best practice, I suggest you that all digital pins you define (input or output) in your projects have their idle state high, with external pull up resistor
1316 that is the reset state of FastForth...
1317
1318
1319 # ANNEXES
1320
1321 Here you have a good overview of MSP430 assembly:
1322 [MSP430 ISA](http://www.ece.utep.edu/courses/web3376/Notes_files/ee3376-isa.pdf)
1323
1324 FastForth embedded assembler doesn't recognize the (useless) TI's symbolic addressing mode: ADD.B EDE,TONI.
1325
1326 REGISTERS correspondence (you can freely use ASM or TI or FASTFORTH registers's names).
1327
1328         REG         TI      FASTFORTH   comment 
1329     
1330         R0          PC      PC          Program Counter
1331         R1          SP      RSP         Return Stack Pointer
1332         R2          SR/CG1              Status Register/Constant Generator 1
1333         R3          CG2                 Constant Generator 2
1334         R4          R4      R (rDOCOL)  contents address of xDOCOL (DTC=1|2)            
1335         R5          R5      Q (rDODOES) contents address of xdodoes   
1336         R6          R6      P (rDOCON)  contents address of xdocon    
1337         R7          R7      M (rDOVAR)  contents address of RFROM           
1338         R8          R8      Y           scratch register
1339         R9          R9      X           scratch register
1340         R10         R10     W           scratch register
1341         R11         R11     T           scratch register
1342         R12         R12     S           scratch register      
1343         R13         R13     IP          Interpretation Pointer
1344         R14         R14     TOS         Top Of parameters Stack
1345         R15         R15     PSP         Parameters Stack Pointer
1346
1347 **REGISTERS use**
1348
1349 The FASTFORTH registers rDOCOL, rDOVAR, rDOCON and rDODOES must be preserved. 
1350 If you use them you may either `PUSHM #4,M` before and `POPM #4,M after`,
1351 or use them directly then restore FastForth default values:
1352
1353 `MOV #INIT_DOXXX,X`  
1354 `MOV @X+,rDOCOL`  
1355 `MOV @X+,rDODOES`  
1356 `MOV @X+,rDOCON`  
1357 `MOV @X,rDOVAR`
1358
1359 (Search `INIT_DOXXX` in \inc\MSP430xxxx.pat)
1360
1361 If you want to restore only rDODOES, rDOCON and rDOVAR:
1362
1363 `MOV #INIT_DOXXX+4,X`  
1364 `MOV @X+,rDODOES`  
1365 `MOV @X+,rDOCON`  
1366 `MOV @X,rDOVAR`
1367
1368 If you want to restore only rDODOES and rDOCON:
1369
1370 `MOV #XDODOES,rDODOES`  
1371 `MOV #XDOCON,rDOCON`  
1372
1373 When you use these registers you can't call any FORTH words using them at the same time! 
1374
1375 don't use R3 and use R2 (SR) only with BIC, BIT, BIS instructions in register mode.
1376
1377 The bits 0-11 of SR register are saved by interrupts and restored by the instruction RETI.
1378 you can use freely UF9 UF10 and UF11 as SR bits 9-11. 
1379 FastForth uses UF9 for double numbers interpreting and also by TO ... VALUE.
1380     
1381
1382 **PARAMETERS STACK**
1383
1384 The register TOS (Top Of Stack) is the first cell of the Parameters stack. 
1385 The register PSP (Parameters Stack Pointer) points the second cell.
1386
1387 to push one cell on the PSP stack :
1388
1389     SUB #2,PSP                  \ insert a empty 2th cell
1390     MOV TOS,0(PSP)              \ fill this 2th cell with first cell
1391     MOV(.B) <what you want>,TOS \ i.e. update first cell
1392
1393 to pop one cell from the PSP stack :
1394
1395     MOV @PSP+,TOS               \ first cell TOS is lost and replaced by the 2th.
1396
1397 don't never pop a byte with instruction MOV.B @PSP+, because it generates a stack misalignement...
1398
1399 **RETURN STACK**
1400
1401 register RSP is the Return Stack Pointer (SP).
1402
1403 to push one cell on the RSP stack: `PUSH <what you want>`
1404
1405 to pop one cell from the RSP stack: `MOV @RSP+,<where you want>`
1406
1407 don't never push or pop a byte on RSP stack !
1408
1409
1410 to push multiple registers on the RSP stack :
1411
1412 `PUSHM #n,Rx`,  with 0 <= x-(n-1) < 16
1413
1414 to pop multiple registers from the RSP stack :
1415
1416 `POPM #n,Rx`,  with 0 <= x-(n-1) < 16
1417
1418     PUSHM order : PSP,TOS, IP, S , T , W , X , Y ,rDOVAR,rDOCON,rDODOES,rDOCOL, R3, SR,RSP, PC
1419     PUSHM order : R15,R14,R13,R12,R11,R10, R9, R8,  R7  ,  R6  ,  R5   ,  R4  , R3, R2, R1, R0
1420
1421 example : `PUSHM #6,IP` pushes IP,S,T,W,X,Y registers to return stack
1422
1423     POPM  order :  PC,RSP, SR, R3,rDOCOL,rDODOES,rDOCON,rDOVAR, Y , X , W , T , S , IP,TOS,PSP
1424     POPM  order :  R0, R1, R2, R3,  R4  ,  R5   ,  R6  ,   R7 , R8, R9,R10,R11,R12,R13,R14,R15
1425
1426 example : `POPM #6,IP` pulls Y,X,W,T,S,IP registers from return stack
1427
1428 Error occurs if #n is out of bounds.
1429
1430 **conditionnal jumps use**
1431
1432     0=    with IF UNTIL WHILE ?GOTO
1433     0<>   with IF UNTIL WHILE ?GOTO   
1434     U>=   with IF UNTIL WHILE ?GOTO   
1435     U<    with IF UNTIL WHILE ?GOTO    
1436     S<    with IF UNTIL WHILE ?GOTO    
1437     S>=   with IF UNTIL WHILE ?GOTO   
1438     0>=   with IF UNTIL WHILE
1439     0<    with ?GOTO 
1440
1441 # FAST FORTH resumed
1442
1443     RETURN-STACK-CELLS  = 48            max size of the return stack, in cells  
1444     STACK-CELLS         = 48            max size of the data stack, in cells  
1445     /COUNTED-STRING      = 255              max size of a counted string, in characters  
1446     /HOLD                  = 34            size of the pictured numeric output string buffer, in characters  
1447     /PAD                    = 84            size of the scratch area pointed to by PAD, in characters  
1448     ADDRESS-UNIT-BITS   = 16            size of one address unit, in bits
1449     FLOORED              = true             true if floored division is the default
1450     MAX-CHAR            = 255           max value of any character in the implementation-defined character set
1451     MAX-N               = 32767         largest usable signed integer  
1452     MAX-U               = 65535         largest usable unsigned integer  
1453     MAX-D                  = 2147483647     largest usable signed double number  
1454     MAX-UD              = 4294967295    largest usable unsigned double number  
1455     DeFiNiTiOnS aRe CaSe-InSeNsItIvE    they are compiled in their CAPS_ON form.
1456
1457 ## FORTH word-set
1458
1459 Reduced to 53 definitions, but with everything necessary to be expandable up to $FF80.
1460
1461 RST_SET,
1462 RST_RET,
1463 [MARKER     ](https://forth-standard.org/standard/core/MARKER),
1464 HI2LO,
1465 CODENNM,
1466 HDNCODE,
1467 CODE,
1468 [IS         ](https://forth-standard.org/standard/core/IS),
1469 [\:NONAME   ](https://forth-standard.org/standard/core/ColonNONAME),
1470 [DOES>      ](https://forth-standard.org/standard/core/DOES),
1471 [CREATE     ](https://forth-standard.org/standard/core/CREATE),
1472 [IMMEDIATE  ](https://forth-standard.org/standard/core/IMMEDIATE),
1473 [;          ](https://forth-standard.org/standard/core/Semi),
1474 [:          ](https://forth-standard.org/standard/core/Colon),
1475 [POSTPONE   ](https://forth-standard.org/standard/core/POSTPONE),
1476 [\\         ](https://forth-standard.org/standard/core/bs),
1477 [\]         ](https://forth-standard.org/standard/core/right-bracket),
1478 [\[         ](https://forth-standard.org/standard/core/Bracket),
1479 [\[\'\]     ](https://forth-standard.org/standard/core/BracketTick),
1480 [\'         ](https://forth-standard.org/standard/core/Tick),
1481 [ABORT"     ](https://forth-standard.org/standard/core/ABORTq),
1482 [ALLOT      ](https://forth-standard.org/standard/core/ALLOT),
1483 [COUNT      ](https://forth-standard.org/standard/core/COUNT),
1484 [LITERAL    ](https://forth-standard.org/standard/core/LITERAL),
1485 [,          ](https://forth-standard.org/standard/core/Comma),
1486 [>NUMBER    ](https://forth-standard.org/standard/core/toNUMBER),
1487 [FIND       ](https://forth-standard.org/standard/core/FIND),
1488 [WORD       ](https://forth-standard.org/standard/core/WORD),
1489 [."         ](https://forth-standard.org/standard/core/Dotq),
1490 [S"         ](https://forth-standard.org/standard/core/Sq),
1491 [.          ](https://forth-standard.org/standard/core/d),
1492 [U.         ](https://forth-standard.org/standard/core/Ud),
1493 [SIGN       ](https://forth-standard.org/standard/core/SIGN),
1494 [HOLD       ](https://forth-standard.org/standard/core/HOLD),
1495 [#>         ](https://forth-standard.org/standard/core/num-end),
1496 [#S         ](https://forth-standard.org/standard/core/numS),
1497 [#          ](https://forth-standard.org/standard/core/num),
1498 [<#         ](https://forth-standard.org/standard/core/num-start),
1499 [\[UNDEFINED\]  ](https://forth-standard.org/standard/tools/BracketUNDEFINED),
1500 [\[DEFINED\]    ](https://forth-standard.org/standard/tools/BracketDEFINED),
1501 [\[IF\]         ](https://forth-standard.org/standard/tools/BracketIF),
1502 [\[THEN\]       ](https://forth-standard.org/standard/tools/BracketTHEN)
1503 [\[ELSE\]       ](https://forth-standard.org/standard/tools/BracketELSE),
1504 [!          ](https://forth-standard.org/standard/core/Store),
1505 [@          ](https://forth-standard.org/standard/core/Fetch),
1506 [TYPE       ](https://forth-standard.org/standard/core/TYPE),
1507 NOECHO,
1508 ECHO,
1509 [EMIT       ](https://forth-standard.org/standard/core/EMIT),
1510 [KEY        ](https://forth-standard.org/standard/core/KEY),
1511 [ACCEPT     ](https://forth-standard.org/standard/core/ACCEPT),
1512 SYS.
1513
1514 Words ACCEPT KEY EMIT are DEFERred definitions. ACCEPT doesn't use KEY.
1515
1516     RST_SET         defines the bound of the program memory protected against any PUC.  
1517     RST_RET         removes all words defined after RST_SET.  
1518     HI2LO           used to switch compilation from high level (FORTH) to low level (assembler).
1519     CODENNM         the assembler counterpart of :NONAME.
1520     CODE <name>     creates a definition written in assembler.
1521                     this defined <name> must be ended with ENDCODE unless COLON or LO2HI use. 
1522     HDNCODE <name>  same as CODE but the definition is in the hidden word-set to be visible only in the assembly mode.
1523     NOECHO          disables display on the TERMINAL  
1524     ECHO            enables display on the TERMINAL
1525     SYS             0 SYS | SYS   executes WARM
1526                     +n (odd) SYS  same,
1527                     +n (even) SYS does software RESET then executes WARM 
1528                     -n SYS        same as +n (even) SYS, plus resets the program memory to its original state.
1529
1530 ### Other constants/addresses which are usable in any generic source_files.f
1531
1532 **All constants, variables and definitions included in \inc\any.pat files are usable by
1533 the assembler and also by the FORTH interpreter.**
1534
1535
1536 ## MSP430ASSEMBLER word-set (in the hidden word-set)
1537
1538 [ADD, ADD.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=135),
1539 [ADDC, ADDC.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=136),
1540 [AND, AND.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=137),
1541 [BIC, BIC.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=138),
1542 [BIS, BIS.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=139),
1543 [BIT, BIT.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=140),
1544 [CALL           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=142),
1545 [CMP, CMP.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=147),
1546 [DADD, DADD.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=149),
1547 [MOV, MOV.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=165),
1548 [PUSH, PUSH.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=168),
1549 [RETI           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=170),
1550 [RRA, RRA.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=173),
1551 [RRC, RRC.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=174),
1552 [SUB, SUB.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=179),
1553 [SUBC, SUBC.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=180),
1554 [SWPB           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=181),
1555 [SXT            ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=182),
1556 [XOR, XOR.B     ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=184),
1557 [RRUM           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=218),
1558 [RLAM           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=208),
1559 [RRAM           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=211),
1560 [RRCM           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=214),
1561 [POPM           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=204),
1562 [PUSHM          ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=205),
1563 ?GOTO,
1564 GOTO, 
1565 BW3, 
1566 BW2,
1567 BW1,
1568 FW3,
1569 FW2,
1570 FW1,
1571 REPEAT,
1572 WHILE,
1573 AGAIN,
1574 UNTIL,
1575 ELSE,
1576 THEN,
1577 IF,
1578 0=,
1579 0<>,
1580 U>=,
1581 U<,
1582 0<,
1583 0>=,
1584 S<,
1585 S>=,
1586 LO2HI,
1587 COLON,
1588 ENDCODE.
1589
1590     ?GOTO           used after a conditionnal (0=,0<>,U>=,U<,0<,S<,S>=) to branch to a label FWx or BWx  
1591     GOTO            used as unconditionnal branch to a label FWx or BWx  
1592     BW3             BACKWARD branch destination n°3  
1593     BW2                                         n°2  
1594     BW1                                         n°1  
1595     FW3             FORWARD branch destination  n°3  
1596     FW2                                         n°2  
1597     FW1                                         n°1  
1598     REPEAT          assembler version of the FORTH word REPEAT  
1599     WHILE           idem  
1600     AGAIN           idem  
1601     UNTIL           idem  
1602     ELSE            idem  
1603     THEN            idem  
1604     IF              idem  
1605     0=              conditionnal       
1606     0<>             conditionnal  
1607     U>=             conditionnal  
1608     U<              conditionnal  
1609     0<              conditionnal, to use only with ?GOTO  
1610     0>=             conditionnal, to use only with IF UNTIL WHILE  
1611     S<              conditionnal  
1612     S>=             conditionnal  
1613     LO2HI           switches compilation from low level to high level modes without saving IP register.  
1614     COLON           pushes IP then performs LO2HI.
1615     ENDCODE         to end a CODE or HDNCODE definition.  
1616
1617 #### EXTENDED_MEM WORDS set:
1618
1619 Gives access to addresses beyond $FFFF
1620
1621 [POPM.A         ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=204),
1622 [PUSHM.A        ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=205),
1623 [ADDA           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=229),
1624 [CALLA          ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=232),
1625 [CMPA           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=235),
1626 [MOVA           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=238),
1627 [SUBA           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=241)
1628
1629 #### EXTENDED_ASM WORDS set:
1630
1631 Full 20 bits address/data assembler
1632
1633 [ADDX, ADDX.A, ADDX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=187),
1634 [ADDCX, ADDCX.A, ADDCX.B](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=188),
1635 [ANDX ANDX.A, ANDX.B    ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=189),
1636 [BICX, BICX.A, BICX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=190),
1637 [BISX, BISX.A, BISX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=191),
1638 [BITX, BITX.A, BITX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=192),
1639 [CMPX, CMPX.A, CMPX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=194),
1640 [DADDX, DADDX.A, DADDX.B](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=196),
1641 [MOVX, MOVX.A, MOVX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=202),
1642 [PUSHX, PUSHX.A, PUSHX.B](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=207),
1643 [RRAX, RRAX.A, RRAX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=212),
1644 [RRCX, RRCX.A, RRCX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=216),
1645 [RRUX, RRUX.A, RRUX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=219),
1646 [SUBX, SUBX.A, SUBX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=221),
1647 [SUBCX, SUBCX.A, SUBCX.B](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=222),
1648 [SWPBX, SWPBX.A         ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=223),
1649 [SXTX, SXTX.A           ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=225),
1650 [XORX, XORX.A, XORX.B   ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=227),
1651 [RPT                    ](http://www.ti.com/lit/ug/slau272d/slau272d.pdf#page=119)
1652
1653 ### VOCABULARY ADD-ON
1654
1655 [DEFINITIONS     ](https://forth-standard.org/standard/search/DEFINITIONS),
1656 [PREVIOUS        ](https://forth-standard.org/standard/search/PREVIOUS),
1657 ONLY,
1658 FORTH,
1659 WORDSET.
1660
1661     FORTH               adds FORTH as first CONTEXT word-set  
1662     FORTH ONLY          clears the CONTEXT stack, same as `-1 SYS`
1663     WORDSET <name>      creates a new word-set named <name>
1664     <name>              adds this named word-set in the CONTEXT stack
1665
1666
1667 ### SD_CARD_LOADER ADD-ON
1668
1669     LOAD" SD_TEST.4TH"  loads source file SD_TEST.4TH from SD_Card and compile it.
1670     BOOT                enable bootstrap
1671     NOBOOT              disable bootstrap
1672
1673 Once bootloader is enabled, any PUC event loads (and executes) the file \BOOT.4TH from the SD_Card.
1674
1675 ### SD_CARD_READ_WRITE ADD-ON
1676
1677     TERM2SD"        TERM2SD" SD_TEST.4TH" copy SD_TEST.4TH file to SD_CARD (use CopySourceFileToTarget_SD_Card.bat to do)
1678     WRITE           write sequentially the content of SD_buf to a file
1679     READ            read sequentially a file in SD_buf, leave a flag, false when the file is automatically closed.
1680     CLOSE           close last opened file.
1681     DEL" TRUC"      remove the file TRUC from SD_CARD.
1682     WRITE" TRUC"    create or overwrite a file TRUC ready to write to its beginning.
1683     APPEND" TRUC"   open or create a file TRUC ready to write to the end of this file
1684     READ" TRUC"     open TRUC and load its first sector in SD_buf
1685     WR_SECT         Write SD_BUF in Sector loaded in  W=lo:X=hi
1686     RD_SECT         load Sector W=lo:X=hi into SD_BUF, set BufferPtr=0
1687
1688
1689 ## OPTIONNAL ADD-ON
1690
1691 * Their respective MARKER word identified with braces {} removes all ADD-ONs words.  
1692   Sources are in the folder \MSP430-FORTH\, as source.f file.
1693
1694 ### ANS_COMP
1695
1696 Adds complement to pass FORTH ANS94 core test.
1697
1698 [VALUE      ](https://forth-standard.org/standard/core/VALUE),
1699 [TO         ](https://forth-standard.org/standard/core/TO),
1700 [DEFER      ](https://forth-standard.org/standard/core/DEFER),
1701 [BEGIN      ](https://forth-standard.org/standard/core/BEGIN),
1702 [SPACES     ](https://forth-standard.org/standard/core/SPACES),
1703 [SPACE      ](https://forth-standard.org/standard/core/SPACE),
1704 [BL         ](https://forth-standard.org/standard/core/BL),
1705 [PAD        ](https://forth-standard.org/standard/core/PAD),
1706 [>IN        ](https://forth-standard.org/standard/core/toIN),
1707 [BASE       ](https://forth-standard.org/standard/core/BASE),
1708 [STATE      ](https://forth-standard.org/standard/core/STATE),
1709 [CONSTANT   ](https://forth-standard.org/standard/core/CONSTANT),
1710 [VARIABLE   ](https://forth-standard.org/standard/core/VARIABLE),
1711 [SOURCE     ](https://forth-standard.org/standard/core/SOURCE),
1712 [RECURSE    ](https://forth-standard.org/standard/core/RECURSE),
1713 [EVALUATE   ](https://forth-standard.org/standard/core/EVALUATE),
1714 [EXECUTE    ](https://forth-standard.org/standard/core/EXECUTE),
1715 [>BODY      ](https://forth-standard.org/standard/core/toBODY),
1716 [.(         ](https://forth-standard.org/standard/core/Dotp),
1717 [(          ](https://forth-standard.org/standard/core/p),
1718 [DECIMAL    ](https://forth-standard.org/standard/core/DECIMAL),
1719 [HEX        ](https://forth-standard.org/standard/core/HEX),
1720 [HERE       ](https://forth-standard.org/standard/core/HERE),
1721 [FILL       ](https://forth-standard.org/standard/core/FILL),
1722 [MOVE       ](https://forth-standard.org/standard/core/MOVE),
1723 [+!         ](https://forth-standard.org/standard/core/PlusStore),
1724 [[CHAR]     ](https://forth-standard.org/standard/core/BracketCHAR),
1725 [CHAR       ](https://forth-standard.org/standard/core/CHAR),
1726 [CELL+      ](https://forth-standard.org/standard/core/CELLPlus),
1727 [CELLS      ](https://forth-standard.org/standard/core/CELLS),
1728 [CHAR+      ](https://forth-standard.org/standard/core/CHARPlus),
1729 [CHARS      ](https://forth-standard.org/standard/core/CHARS),
1730 [ALIGN      ](https://forth-standard.org/standard/core/ALIGN),
1731 [ALIGNED    ](https://forth-standard.org/standard/core/ALIGNED),
1732 [2OVER      ](https://forth-standard.org/standard/core/TwoOVER),
1733 [2SWAP      ](https://forth-standard.org/standard/core/TwoSWAP),
1734 [2DROP      ](https://forth-standard.org/standard/core/TwoDROP),
1735 [2DUP       ](https://forth-standard.org/standard/core/TwoDUP),
1736 [2!         ](https://forth-standard.org/standard/core/TwoStore),
1737 [2@         ](https://forth-standard.org/standard/core/TwoFetch),
1738 [R@         ](https://forth-standard.org/standard/core/RFetch),
1739 [ROT        ](https://forth-standard.org/standard/core/ROT),
1740 [OVER       ](https://forth-standard.org/standard/core/OVER),
1741 [*/         ](https://forth-standard.org/standard/core/TimesDiv),
1742 [*/MOD      ](https://forth-standard.org/standard/core/TimesDivMOD),
1743 [MOD        ](https://forth-standard.org/standard/core/MOD),
1744 [/          ](https://forth-standard.org/standard/core/Div),
1745 [/MOD       ](https://forth-standard.org/standard/core/DivMOD),
1746 [*          ](https://forth-standard.org/standard/core/Times),
1747 [FM/MOD     ](https://forth-standard.org/standard/core/FMDivMOD),
1748 [ABS        ](https://forth-standard.org/standard/core/ABS),
1749 [NEGATE     ](https://forth-standard.org/standard/core/NEGATE),
1750 [SM/REM     ](https://forth-standard.org/standard/core/SMDivREM),
1751 [UM/MOD     ](https://forth-standard.org/standard/core/UMDivMOD),
1752 [M*         ](https://forth-standard.org/standard/core/MTimes),
1753 [UM*        ](https://forth-standard.org/standard/core/UMTimes),
1754 [2/         ](https://forth-standard.org/standard/core/TwoDiv),
1755 [2*         ](https://forth-standard.org/standard/core/TwoTimes),
1756 [MIN        ](https://forth-standard.org/standard/core/MIN),
1757 [MAX        ](https://forth-standard.org/standard/core/MAX),
1758 [RSHIFT     ](https://forth-standard.org/standard/core/RSHIFT),
1759 [LSHIFT     ](https://forth-standard.org/standard/core/LSHIFT),
1760 [INVERT     ](https://forth-standard.org/standard/core/INVERT),
1761 [1-         ](https://forth-standard.org/standard/core/OneMinus),
1762 [1+         ](https://forth-standard.org/standard/core/OnePlus),
1763 [S>D        ](https://forth-standard.org/standard/core/StoD),
1764 [XOR        ](https://forth-standard.org/standard/core/XOR),
1765 [OR         ](https://forth-standard.org/standard/core/OR),
1766 [AND        ](https://forth-standard.org/standard/core/AND),
1767 [LEAVE      ](https://forth-standard.org/standard/core/LEAVE),
1768 [UNLOOP     ](https://forth-standard.org/standard/core/UNLOOP),
1769 [J          ](https://forth-standard.org/standard/core/J),
1770 [I          ](https://forth-standard.org/standard/core/I),
1771 [+LOOP      ](https://forth-standard.org/standard/core/PlusLOOP),
1772 [LOOP       ](https://forth-standard.org/standard/core/LOOP),
1773 [DO         ](https://forth-standard.org/standard/core/DO),
1774 [REPEAT     ](https://forth-standard.org/standard/core/REPEAT),
1775 [WHILE      ](https://forth-standard.org/standard/core/WHILE),
1776 [AGAIN      ](https://forth-standard.org/standard/core/AGAIN),
1777 [UNTIL      ](https://forth-standard.org/standard/core/UNTIL),
1778 [THEN       ](https://forth-standard.org/standard/core/THEN),
1779 [ELSE       ](https://forth-standard.org/standard/core/ELSE),
1780 [IF         ](https://forth-standard.org/standard/core/IF),
1781 [>          ](https://forth-standard.org/standard/core/more),
1782 [<          ](https://forth-standard.org/standard/core/less),
1783 [U<         ](https://forth-standard.org/standard/core/Uless),
1784 [=          ](https://forth-standard.org/standard/core/Equal),
1785 [0<         ](https://forth-standard.org/standard/core/Zeroless),
1786 [0=         ](https://forth-standard.org/standard/core/ZeroEqual),
1787 [C,         ](https://forth-standard.org/standard/core/CComma),
1788 [C!         ](https://forth-standard.org/standard/core/CStore),
1789 [C@         ](https://forth-standard.org/standard/core/CFetch),
1790 [R>         ](https://forth-standard.org/standard/core/Rfrom),
1791 [>R         ](https://forth-standard.org/standard/core/toR),
1792 [NIP        ](https://forth-standard.org/standard/core/NIP),
1793 [DROP       ](https://forth-standard.org/standard/core/DROP),
1794 [SWAP       ](https://forth-standard.org/standard/core/SWAP),
1795 [DEPTH      ](https://forth-standard.org/standard/core/DEPTH),
1796 [EXIT       ](https://forth-standard.org/standard/core/EXIT),
1797 [?DUP       ](https://forth-standard.org/standard/core/qDUP),
1798 [DUP        ](https://forth-standard.org/standard/core/DUP),
1799 [-          ](https://forth-standard.org/standard/core/Minus),
1800 [+          ](https://forth-standard.org/standard/core/Plus),
1801 [CR         ](https://forth-standard.org/standard/core/CR).
1802
1803
1804 ### FIXPOINT
1805
1806 S>F,
1807 F.,
1808 F*,
1809 F#S,
1810 F/,
1811 F-,
1812 F+,
1813 [HOLDS          ](https://forth-standard.org/standard/core/HOLDS).
1814
1815     S>F             u/n -- Qlo Qhi       convert u/n in a Q15.16 value
1816     F.              display a Q15.16 value
1817     F*              Q15.16 multiplication  
1818     F#S             Qlo Qhi u -- Qhi 0    
1819                     convert fractionnal part of a Q15.16 value displaying u digits
1820     F/              Q15.16 division        
1821     F-              Q15.16 soustraction
1822     F+              Q15.16 addition
1823
1824
1825 ### UTILITY
1826
1827 [DUMP           ](https://forth-standard.org/standard/tools/DUMP), 
1828 [U.R            ](https://forth-standard.org/standard/core/UDotR),
1829 [WORDS          ](https://forth-standard.org/standard/tools/WORDS),
1830 [?              ](https://forth-standard.org/standard/tools/q), 
1831 [.S             ](https://forth-standard.org/standard/tools/DotS),
1832 .RS.
1833
1834     .RS             displays Return Stack content  
1835
1836 ### SD_TOOLS
1837
1838     DIR             dump first sector of current directory  
1839     FAT             dump first sector of FAT1  
1840     CLUSTER.        .123 CLUSTER. displays first sector of cluster 123  
1841     SECTOR.         .123456789 SECTOR. displays sector 123456789  
1842
1843 ### DOUBLE word set
1844
1845 [D.R             ](https://forth-standard.org/standard/double/DDotR),
1846 [2LITERAL        ](https://forth-standard.org/standard/double/TwoLITERAL),
1847 [2VALUE          ](https://forth-standard.org/standard/double/TwoVALUE),
1848 [2CONSTANT       ](https://forth-standard.org/standard/double/TwoCONSTANT),
1849 [2VARIABLE       ](https://forth-standard.org/standard/double/TwoVARIABLE),
1850 [M*/             ](https://forth-standard.org/standard/double/MTimesDiv),
1851 [DMIN            ](https://forth-standard.org/standard/double/DMIN),
1852 [DMAX            ](https://forth-standard.org/standard/double/DMAX),
1853 [D2*             ](https://forth-standard.org/standard/double/DTwoTimes),
1854 [D2/             ](https://forth-standard.org/standard/double/DTwoDiv),
1855 [DABS            ](https://forth-standard.org/standard/double/DABS),
1856 [DNEGATE         ](https://forth-standard.org/standard/double/DNEGATE),
1857 [D-              ](https://forth-standard.org/standard/double/DMinus),
1858 [M+              ](https://forth-standard.org/standard/double/MPlus),
1859 [D+              ](https://forth-standard.org/standard/double/DPlus),
1860 [DU<             ](https://forth-standard.org/standard/double/DUless),
1861 [D<              ](https://forth-standard.org/standard/double/Dless),
1862 [D=              ](https://forth-standard.org/standard/double/DEqual),
1863 [D0<             ](https://forth-standard.org/standard/double/DZeroless),
1864 [D0=             ](https://forth-standard.org/standard/double/DZeroEqual),
1865 [D>S             ](https://forth-standard.org/standard/double/DtoS),
1866 [2ROT            ](https://forth-standard.org/standard/double/TwoROT),
1867 [D.              ](https://forth-standard.org/standard/double/Dd),
1868 [2R>             ](https://forth-standard.org/standard/core/TwoRfrom),
1869 [2R@             ](https://forth-standard.org/standard/core/TwoRFetch),
1870 [2>R             ](https://forth-standard.org/standard/core/TwotoR)
1871
1872
1873 ## IDE for linux UBUNTU 
1874
1875 First search from ti.com: [MSP430Flasher](http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430Flasher/latest/index_FDS.html)
1876
1877 untar in a home folder then:
1878 * set executable flag in permission of this file
1879 * open MSPFlasher-1.3.16-linux-x64-installer.run
1880 * install in MSP430Flasher (under home)
1881
1882 open a terminal in MSP430Flasher/Drivers: 
1883     sudo ./msp430uif_install.sh
1884     
1885 copy MSP430Flasher/MSP430Flasher to /usr/local/bin/MSP430Flasher 
1886 copy MSP430Flasher/libmsp430.so  to /usr/local/lib/MSP430Flasher/libmsp430.so
1887
1888 open an editor as superuser in /etc/ld.so.conf.d/
1889      write on first line (of new file): /usr/local/lib/msp430flasher/
1890      save this new file as libmsp430.conf
1891 then in a terminal: sudo /sbin/ldconfig
1892
1893
1894 #### install the package srecord
1895
1896 install the package scite
1897 as super user, edit /etc/scite/SciTEGlobal.properties
1898 uncomment (line 18): position.maximize=1
1899 uncomment (line 257): properties.directory.enable=1
1900 add line 7: PLAT_WIN=0
1901 add line 8: PLAT_GTK=1
1902 save file
1903
1904 at the end of your ~.profile file, add these two lines:
1905 FF="/the_root_of_your_FastForth_local_copy"
1906 export FF
1907
1908 https://sourceforge.net/projects/gema/files/gema/gema-1.4-RC/gema-1.4RC-src.tgz/download
1909 untar in a home folder then:
1910 make (ignore warnings)
1911 sudo make install (ignore warnings)
1912 make clean
1913 result in: /usr/local/bin/gema
1914
1915 http://john.ccac.rwth-aachen.de:8000/ftp/as/source/c_version/asl-current.tar.gz
1916 untar in a home folder then:
1917 copy /Makefile.def-samples/Makefile.def-i386-unknown-linux2.x,x to ../Makefile.def
1918 edit this Makefile.def to remove "-march=i586" option from line 7 (if any)
1919 make
1920 make test
1921 sudo make install
1922 make clean
1923 result: asl files are in /usr/local
1924
1925
1926 #### install minicom package
1927
1928
1929 sudo gpasswd --add ${USER} dialout
1930
1931 copy /config/msp430/.minirc.dfl in your home directory.
1932
1933 In /inc/RemoveComments.pat, deselect windows part, select linux part. 
1934
1935
1936 With scite editor you can 
1937    - assemble FastForth then download it to eZFET target, 
1938    - edit your source files
1939    - preprocess file.f to file.4th 
1940
1941 With minicom you can send a file.4th to your target via dev/ttyUSB0, up to 4Mbauds:
1942 CTRL_A + Y to send a file
1943
1944
1945