1 \ -*- coding: utf-8 -*-
7 \ to see kernel options, download FastForthSpecs.f
8 \ FastForth kernel options: nothing
10 \ TARGET SELECTION : copy your target in (shift+F8) parameter 1:
11 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
12 \ MSP_EXP430FR4133 MSP_EXP430FR2433 MSP_EXP430FR2355 CHIPSTICK_FR2433
19 \ https://forth-standard.org/standard/core/SWAP
20 \ SWAP x1 x2 -- x2 x1 swap top two items
30 \ https://forth-standard.org/standard/core/Equal
31 \ = x1 x2 -- flag test x1=x2
37 XOR #-1,TOS \ 1 flag Z = 1
44 \ https://forth-standard.org/standard/core/ZeroEqual
45 \ 0= n/u -- flag return true if TOS=0
47 SUB #1,TOS \ borrow (clear cy) if TOS was 0
48 SUBC TOS,TOS \ TOS=-1 if borrow was set
54 \ https://forth-standard.org/standard/core/IF
55 \ IF -- IFadr initialize conditional forward branch
60 ADD #4,&DP \ compile one word, reserve one word
61 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
62 ADD #2,TOS \ -- HERE+2=IFadr
68 \ https://forth-standard.org/standard/core/THEN
69 \ THEN IFadr -- resolve forward branch
71 MOV &DP,0(TOS) \ -- IFadr
78 \ https://forth-standard.org/standard/core/ELSE
79 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
81 ADD #4,&DP \ make room to compile two words
84 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
86 MOV W,TOS \ -- ELSEadr
91 [UNDEFINED] BEGIN [IF]
92 \ https://forth-standard.org/standard/core/BEGIN
93 \ BEGIN -- BEGINadr initialize backward branch
94 CODE BEGIN \ immediate
95 MOV #HERE,PC \ BR HERE
99 [UNDEFINED] AGAIN [IF]
100 \ https://forth-standard.org/standard/core/AGAIN
101 \ AGAIN BEGINadr -- resolve uncondionnal backward branch
102 CODE AGAIN \ immediate
108 [UNDEFINED] WHILE [IF]
109 \ https://forth-standard.org/standard/core/WHILE
110 \ WHILE BEGINadr -- WHILEadr BEGINadr
116 [UNDEFINED] REPEAT [IF]
117 \ https://forth-standard.org/standard/core/REPEAT
118 \ REPEAT WHILEadr BEGINadr -- resolve WHILE loop
120 POSTPONE AGAIN POSTPONE THEN
125 \ https://forth-standard.org/standard/core/DO
126 \ DO -- DOadr L: -- 0
130 ADD #2,&DP \ make room to compile xdo
131 MOV &DP,TOS \ -- HERE+2
132 MOV #XDO,-2(TOS) \ compile xdo
133 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
135 MOV #0,0(W) \ -- HERE+2 L-- 0
140 [UNDEFINED] LOOP [IF]
141 \ https://forth-standard.org/standard/core/LOOP
142 \ LOOP DOadr -- L-- an an-1 .. a1 0
143 CODE LOOP \ immediate
145 BW1 ADD #4,&DP \ make room to compile two words
147 MOV X,-4(W) \ xloop --> HERE
148 MOV TOS,-2(W) \ DOadr --> HERE+2
149 BEGIN \ resolve all "leave" adr
150 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
151 SUB #2,&LEAVEPTR \ --
152 MOV @TOS,TOS \ -- first LeaveStack value
153 CMP #0,TOS \ -- = value left by DO ?
155 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
163 \ https://forth-standard.org/standard/core/toR
164 \ >R x -- R: -- x push to return stack
173 \ https://forth-standard.org/standard/core/Rfrom
174 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
181 \ https://forth-standard.org/standard/core/RFetch
182 \ R@ -- x R: x -- x fetch from return stack
191 [UNDEFINED] DROP [IF]
192 \ https://forth-standard.org/standard/core/DROP
193 \ DROP x -- drop top of stack
200 [UNDEFINED] ?DUP [IF]
201 \ https://forth-standard.org/standard/core/qDUP
202 \ ?DUP x -- 0 | x x DUP if nonzero
204 CMP #0,TOS \ 2 test for TOS nonzero
206 SUB #2,PSP \ 2 push old TOS..
207 MOV TOS,0(PSP) \ 3 ..onto stack
214 \ https://forth-standard.org/standard/core/Fetch
215 \ @ c-addr -- char fetch char from memory
223 \ https://forth-standard.org/standard/core/Store
224 \ ! x a-addr -- store cell in memory
233 \ https://forth-standard.org/standard/core/less
234 \ < n1 n2 -- flag test n1<n2, signed
236 SUB @PSP+,TOS \ 1 TOS=n2-n1
237 S< ?GOTO FW1 \ 2 signed
239 BW1 MOV #-1,TOS \ 1 flag Z = 0
244 \ https://forth-standard.org/standard/core/more
245 \ > n1 n2 -- flag test n1>n2, signed
247 SUB @PSP+,TOS \ 2 TOS=n2-n1
248 S< ?GOTO BW1 \ 2 --> +5
249 FW1 AND #0,TOS \ 1 flag Z = 1
255 \ https://forth-standard.org/standard/core/Minus
256 \ - n1/u1 n2/u2 -- n3/u3 n3 = n1-n2
258 SUB @PSP+,TOS \ 2 -- n2-n1
260 ADD #1,TOS \ 1 -- n3 = -(n2-n1) = n1-n2
265 [UNDEFINED] UM/MOD [IF]
266 \ https://forth-standard.org/standard/core/UMDivMOD
267 \ UM/MOD udlo|udhi u1 -- r q unsigned 32/16->r16 q16
270 MOV #MUSMOD,PC \ execute MUSMOD then return to DROP
274 [UNDEFINED] ESC" [IF]
275 \ ESC" <escape sequence>" -- type an escape sequence
276 : ESC" $1B POSTPONE LITERAL POSTPONE EMIT POSTPONE S" POSTPONE TYPE ; IMMEDIATE \ "
280 $20 EMIT 1 ABORT" only for 1,4,8,16,24 MHz MCLK!"
284 $20 EMIT ESC" [7m" \ set reverse video
285 ." with MCLK = " FREQ_KHZ @ 0 1000 UM/MOD . DROP
286 1 ABORT" MHz? don't dream!"
291 : CHNGBAUD \ only for 8, 16, 24 MHz
292 PWR_STATE \ to remove this created word (garbage collector)
294 42 \ number of terminal lines
295 0 DO CR LOOP \ don't erase any line of source
297 ESC" [1J" \ erase up (42 empty lines)
298 ESC" [H" \ cursor home
300 FREQ_KHZ @ >R \ r-- target MCLCK frequency in MHz
301 ." target MCLK = " R@ 0 1000 UM/MOD . ." MHz" DROP CR
302 ." choose your baudrate:" CR
305 ." 2 --> 4 MBds" CR \ linux driver max speed
306 ." 3 --> 2457600 Bds" CR
307 ." 4 --> 921600 Bds" CR
308 ." 5 --> 460800 Bds" CR
309 ." 6 --> 230400 Bds" CR
310 ." 7 --> 115200 Bds" CR
311 ." 8 --> 38400 Bds" CR
312 ." 9 --> 19200 Bds" CR
313 ." A --> 9600 Bds" CR
314 ." other --> abort" CR
318 #48 - ?DUP 0= \ select 6MBds ?
319 IF ." 6 MBds" \ add this to the current line
320 R@ #24000 < \ < 24MHz ?
322 R@ #24000 <> \ > 24 MHz ?
323 IF BAD_MHz THEN \ yes --> abort
326 ELSE 1 - ?DUP 0= \ select 5MBds ?
328 R@ #16000 < \ < 16MHz ?
330 R@ #16000 = \ 16 MHz ?
338 ELSE 1 - ?DUP 0= \ 4MBds ?
348 ELSE 1 - ?DUP 0= \ 2457600 ?
350 R@ #8000 < \ < 8MHz ?
361 ELSE 1 - ?DUP 0= \ 921600 ?
363 R@ #4000 < \ < 4MHz ?
377 ELSE 1 - ?DUP 0= \ 460800 ?
393 ELSE 1 - ?DUP 0= \ 230400 ?
412 ELSE 1 - ?DUP 0= \ 115200 ?
429 ELSE 1 - ?DUP 0= \ 38400 ?
446 ELSE 1 - ?DUP 0= \ 19200 ?
463 ELSE 8 - ?DUP 0= \ 9600 ?
480 ELSE \ other selected
493 TERMMCTLW_RST ! \ set UCAxMCTLW value in FRAM
494 TERMBRW_RST ! \ set UCAxBRW value in FRAM
495 R> DROP \ clear stacks
496 CR ESC" [7m" \ escape sequence to set reverse video
497 ." Change baudrate in Teraterm, save its setup, then reset target."