1 \ -*- coding: utf-8 -*-
3 \ first, we test for downloading driver only if UART TERMINAL target
8 SUB #307,TOS \ FastForth V3.7
10 'CR' EMIT \ return to column 1 without 'LF'
11 ABORT" FastForth version = 3.7 please!"
12 PWR_STATE \ remove ABORT_SD_TEST definition before resuming
21 \ to see kernel options, download FastForthSpecs.f
22 \ FastForth kernel options: MSP430ASSEMBLER, CONDCOMP, SD_CARD_READ_WRITE
24 \ TARGET SELECTION ( = the name of \INC\target.pat file without the extension)
25 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
26 \ MSP_EXP430FR4133 MSP_EXP430FR2433 MSP_EXP430FR2355 CHIPSTICK_FR2433
29 \ from scite editor : copy your target selection in (shift+F8) parameter 1:
33 \ drag and drop this file onto SendSourceFileToTarget.bat
34 \ then select your TARGET when asked.
39 \ how to test SD_CARD driver on your launchpad:
42 \ remove the jumpers RX, TX of programming port (don't remove GND, TST, RST and VCC)
43 \ wire PL2303TA/HXD: GND <-> GND, RX <-- TX, TX --> RX
44 \ connect it to your PC on a free USB port
45 \ connect the PL2303TA/HXD cable to your PC on another free USB port
46 \ configure TERATERM as indicated in forthMSP430FR.asm
49 \ if you have a MSP-EXP430FR5994 launchpad, program it with MSP_EXP430FR5994_xbauds_SD_CARD.txt
50 \ to do, drag and drop this file onto prog.bat
54 \ else edit forthMSP430FR.asm with scite editor
55 \ uncomment your target, copy it
56 \ paste it into (SHIFT+F8) param1
60 \ TERMINALBAUDRATE .equ what_you_want
67 \ compile for your target (CTRL+0)
69 \ program your target via TI interface (CTRL+1)
71 \ then wire your SD_Card module as described in your MSP430-FORTH\target.pat file
75 \ format FAT16 or FAT32 a SD_CARD memory (max 64GB) with "FRxxxx" in the disk name
76 \ drag and drop \MSP430_COND\MISC folder on the root of this SD_CARD memory (FastForth doesn't do yet)
77 \ put it in your target SD slot
78 \ if no reset, type COLD from the console input (teraterm) to reset FAST FORTH
80 \ with MSP430FR5xxx or MSP430FR6xxx targets, you can first set RTC:
81 \ by downloading RTC.f with SendSourceFileToTarget.bat
82 \ then terminal input asks you to type (with spaces) (DMY), then (HMS),
83 \ So, subsequent copied files will be dated:
85 \ with CopySourceFileToTarget_SD_Card.bat (or better, from scite editor, menu tools):
87 \ copy TESTASM.4TH to \MISC\TESTASM.4TH (add path \MISC in the window opened by TERATERM)
88 \ copy TSTWORDS.4TH to \TSTWORDS.4TH
89 \ copy CORETEST.4TH to \CORETEST.4TH
90 \ copy SD_TOOLS.f to \SD_TOOLS.4TH
91 \ copy SD_TEST.f to \SD_TEST.4TH
92 \ copy PROG100k.f to \PROG100k.4TH
93 \ copy RTC.f to \RTC.4TH ( doesn't work with if FR2xxx or FR4xxx)
97 [DEFINED] {SD_TEST} [IF] {SD_TEST} [THEN] \ remove it if defined out of kernel
101 [UNDEFINED] EXIT [IF]
102 \ https://forth-standard.org/standard/core/EXIT
103 \ EXIT -- exit a colon definition; CALL #EXIT performs ASMtoFORTH (10 cycles)
104 \ JMP #EXIT performs EXIT
106 MOV @RSP+,IP \ 2 pop previous IP (or next PC) from return stack
107 MOV @IP+,PC \ 4 = NEXT
112 [UNDEFINED] SWAP [IF]
113 \ https://forth-standard.org/standard/core/SWAP
114 \ SWAP x1 x2 -- x2 x1 swap top two items
123 [UNDEFINED] >BODY [IF]
124 \ https://forth-standard.org/standard/core/toBODY
125 \ >BODY -- addr leave BODY of a CREATEd word\ also leave default ACTION-OF primary DEFERred word
133 \ https://forth-standard.org/standard/core/ZeroEqual
134 \ 0= n/u -- flag return true if TOS=0
136 SUB #1,TOS \ borrow (clear cy) if TOS was 0
137 SUBC TOS,TOS \ TOS=-1 if borrow was set
142 [UNDEFINED] IF [IF] \ define IF and THEN
143 \ https://forth-standard.org/standard/core/IF
144 \ IF -- IFadr initialize conditional forward branch
148 MOV &DP,TOS \ -- HERE
149 ADD #4,&DP \ compile one word, reserve one word
150 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
151 ADD #2,TOS \ -- HERE+2=IFadr
155 \ https://forth-standard.org/standard/core/THEN
156 \ THEN IFadr -- resolve forward branch
157 CODE THEN \ immediate
158 MOV &DP,0(TOS) \ -- IFadr
164 [UNDEFINED] ELSE [IF]
165 \ https://forth-standard.org/standard/core/ELSE
166 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
167 CODE ELSE \ immediate
168 ADD #4,&DP \ make room to compile two words
171 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
173 MOV W,TOS \ -- ELSEadr
178 [UNDEFINED] BEGIN [IF] \ define BEGIN UNTIL AGAIN WHILE REPEAT
179 \ https://forth-standard.org/standard/core/BEGIN
180 \ BEGIN -- BEGINadr initialize backward branch
185 \ https://forth-standard.org/standard/core/UNTIL
186 \ UNTIL BEGINadr -- resolve conditional backward branch
187 CODE UNTIL \ immediate
189 BW1 ADD #4,&DP \ compile two words
191 MOV X,-4(W) \ compile Bran or QFBRAN at HERE
192 MOV TOS,-2(W) \ compile bakcward adr at HERE+2
197 \ https://forth-standard.org/standard/core/AGAIN
198 \ AGAIN BEGINadr -- resolve uncondionnal backward branch
199 CODE AGAIN \ immediate
204 \ https://forth-standard.org/standard/core/WHILE
205 \ WHILE BEGINadr -- WHILEadr BEGINadr
210 \ https://forth-standard.org/standard/core/REPEAT
211 \ REPEAT WHILEadr BEGINadr -- resolve WHILE loop
213 POSTPONE AGAIN POSTPONE THEN
217 [UNDEFINED] DO [IF] \ define DO LOOP +LOOP
218 \ https://forth-standard.org/standard/core/DO
219 \ DO -- DOadr L: -- 0
223 ADD #2,&DP \ make room to compile xdo
224 MOV &DP,TOS \ -- HERE+2
225 MOV #XDO,-2(TOS) \ compile xdo
226 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
228 MOV #0,0(W) \ -- HERE+2 L-- 0
232 \ https://forth-standard.org/standard/core/LOOP
233 \ LOOP DOadr -- L-- an an-1 .. a1 0
234 CODE LOOP \ immediate
236 BW1 ADD #4,&DP \ make room to compile two words
238 MOV X,-4(W) \ xloop --> HERE
239 MOV TOS,-2(W) \ DOadr --> HERE+2
240 BEGIN \ resolve all "leave" adr
241 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
242 SUB #2,&LEAVEPTR \ --
243 MOV @TOS,TOS \ -- first LeaveStack value
244 CMP #0,TOS \ -- = value left by DO ?
246 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
252 \ https://forth-standard.org/standard/core/PlusLOOP
253 \ +LOOP adrs -- L-- an an-1 .. a1 0
254 CODE +LOOP \ immediate
261 \ https://forth-standard.org/standard/core/I
262 \ I -- n R: sys1 sys2 -- sys1 sys2
263 \ get the innermost loop index
265 SUB #2,PSP \ 1 make room in TOS
267 MOV @RSP,TOS \ 2 index = loopctr - fudge
274 \ https://forth-standard.org/standard/core/Plus
275 \ + n1/u1 n2/u2 -- n3/u3 add n1+n2
283 \ https://forth-standard.org/standard/core/Minus
284 \ - n1/u1 n2/u2 -- n3/u3 n3 = n1-n2
286 SUB @PSP+,TOS \ 2 -- n2-n1 ( = -n3)
288 ADD #1,TOS \ 1 -- n3 = -(n2-n1) = n1-n2
293 [UNDEFINED] MAX [IF] \ define MAX and MIN
294 CODE MAX \ n1 n2 -- n3 signed maximum
301 CODE MIN \ n1 n2 -- n3 signed minimum
310 \ https://forth-standard.org/standard/core/CFetch
311 \ C@ c-addr -- char fetch char from memory
318 [UNDEFINED] SPACE [IF]
319 \ https://forth-standard.org/standard/core/SPACE
320 \ SPACE -- output a space
325 [UNDEFINED] SPACES [IF]
326 \ https://forth-standard.org/standard/core/SPACES
327 \ SPACES n -- output n spaces
341 MOV @PSP+,TOS \ -- drop n
346 [UNDEFINED] DUP [IF] \ define DUP and DUP?
347 \ https://forth-standard.org/standard/core/DUP
348 \ DUP x -- x x duplicate top of stack
350 BW1 SUB #2,PSP \ 2 push old TOS..
351 MOV TOS,0(PSP) \ 3 ..onto stack
355 \ https://forth-standard.org/standard/core/qDUP
356 \ ?DUP x -- 0 | x x DUP if nonzero
358 CMP #0,TOS \ 2 test for TOS nonzero
364 [UNDEFINED] OVER [IF]
365 \ https://forth-standard.org/standard/core/OVER
366 \ OVER x1 x2 -- x1 x2 x1
368 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
369 MOV @PSP,TOS \ 2 -- x1 (x2) x1
370 SUB #2,PSP \ 1 -- x1 x2 x1
376 \ https://forth-standard.org/standard/core/toR
377 \ >R x -- R: -- x push to return stack
386 \ https://forth-standard.org/standard/core/Rfrom
387 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
396 [UNDEFINED] CONSTANT [IF]
397 \ https://forth-standard.org/standard/core/CONSTANT
398 \ CONSTANT <name> n -- define a Forth CONSTANT
402 MOV TOS,-2(W) \ PFA = n
409 [UNDEFINED] STATE [IF]
410 \ https://forth-standard.org/standard/core/STATE
411 \ STATE -- a-addr holds compiler state
412 STATEADR CONSTANT STATE
415 [UNDEFINED] IS [IF] \ define DEFER! and IS
416 \ https://forth-standard.org/standard/core/DEFERStore
417 \ Set the word xt1 to execute xt2. An ambiguous condition exists if xt1 is not for a word defined by DEFER.
418 CODE DEFER! \ xt2 xt1 --
419 MOV @PSP+,2(TOS) \ -- xt1=CFA_DEFER xt2 --> [CFA_DEFER+2]
424 \ https://forth-standard.org/standard/core/IS
427 \ DEFER DISPLAY create a "do nothing" definition (2 CELLS)
428 \ inline command : ' U. IS DISPLAY U. becomes the runtime of the word DISPLAY
429 \ or in a definition : ... ['] U. IS DISPLAY ...
430 \ KEY, EMIT, CR, ACCEPT and WARM are examples of DEFERred words
433 IF POSTPONE ['] POSTPONE DEFER!
439 [UNDEFINED] U.R [IF] \ defined in {UTILITY}
440 : U.R \ u n -- display u unsigned in n width (n >= 2)
442 R> OVER - 0 MAX SPACES TYPE
446 [UNDEFINED] DUMP [IF] \ defined in {UTILITY}
447 \ https://forth-standard.org/standard/tools/DUMP
448 CODE DUMP \ adr n -- dump memory
450 PUSH &BASEADR \ save current base
451 MOV #$10,&BASEADR \ HEX base
452 ADD @PSP,TOS \ -- ORG END
455 DO CR \ generate line
456 I 4 U.R SPACE \ generate address
463 I $10 + I \ display 16 chars
464 DO I C@ $7E MIN $20 MAX EMIT LOOP
466 R> BASEADR ! \ restore current base
470 [UNDEFINED] HERE [IF]
477 \ SD_EMIT c -- output char c to a SD_CARD file opened as write
479 CMP #512,&BufferPtr \ 512 bytes by sector
480 U>= IF \ if file buffer is full
481 MOV #WRITE,X \ CALL #Write_File
482 CALL 2(X) \ BufferPtr = 0
485 MOV.B TOS,SD_BUF(Y) \ 3
486 ADD #1,&BufferPtr \ 4
492 PWR_HERE \ remove all volatile programs from MAIN memory
494 ." 0 Set date and time" CR
495 ." 1 Load {TOOLS} words" CR
496 ." 2 Load {SD_TOOLS} words" CR
497 ." 3 Load {CORE_COMP} words" CR
498 ." 4 Load ANS core tests" CR
499 ." 5 Load a 100k program " CR
500 ." 6 Read only this source file" CR
501 ." 7 append a dump of FORTH to YOURFILE.TXT" CR
502 ." 8 delete YOURFILE.TXT" CR
503 ." 9 Load TST_WORDS" CR
512 ." LOAD UTILITY.4TH" CR
516 ." LOAD SD_TOOLS.4TH" CR
520 ." LOAD CORE_ANS.4TH" CR
524 ." LOAD CORETEST.4TH" CR
529 ." LOAD PROG100K.4TH" CR
534 ." READ PROG100K.4TH" CR
537 READ \ sequentially read 512 bytes
538 UNTIL \ prog10k.4TH is closed
541 ." WRITE YOURFILE.TXT" CR
544 \ ." va te faire voir"
545 MAIN_ORG HERE OVER - DUMP
546 ['] EMIT >BODY IS EMIT
550 ." DEL YOURFILE.TXT" CR
554 ." LOAD TSTWORDS.4TH" CR