1 \ -*- coding: utf-8 -*-
3 \ to see kernel options, download FastForthSpecs.f
4 \ FastForth kernel options: MSP430ASSEMBLER, CONDCOMP, SD_CARD_READ_WRITE
6 \ TARGET SELECTION ( = the name of \INC\target.pat file without the extension)
7 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
8 \ MSP_EXP430FR4133 MSP_EXP430FR2433 MSP_EXP430FR2355 CHIPSTICK_FR2433
11 \ from scite editor : copy your target selection in (shift+F8) parameter 1:
15 \ drag and drop this file onto SendSourceFileToTarget.bat
16 \ then select your TARGET when asked.
21 \ how to test SD_CARD driver on your launchpad:
24 \ remove the jumpers RX, TX of programming port (don't remove GND, TST, RST and VCC)
25 \ wire PL2303TA/HXD: GND <-> GND, RX <-- TX, TX --> RX
26 \ connect it to your PC on a free USB port
27 \ connect the PL2303TA/HXD cable to your PC on another free USB port
28 \ configure TERATERM as indicated in forthMSP430FR.asm
31 \ if you have a MSP-EXP430FR5994 launchpad, program it with MSP_EXP430FR5994_xbauds_SD_CARD.txt
32 \ to do, drag and drop this file onto prog.bat
36 \ else edit forthMSP430FR.asm with scite editor
37 \ uncomment your target, copy it
38 \ paste it into (SHIFT+F8) param1
42 \ TERMINALBAUDRATE .equ what_you_want
49 \ compile for your target (CTRL+0)
51 \ program your target via TI interface (CTRL+1)
53 \ then wire your SD_Card module as described in your MSP430-FORTH\target.pat file
57 \ format FAT16 or FAT32 a SD_CARD memory (max 64GB) with "FRxxxx" in the disk name
58 \ drag and drop \MSP430_COND\MISC folder on the root of this SD_CARD memory (FastForth doesn't do yet)
59 \ put it in your target SD slot
60 \ if no reset, type COLD from the console input (teraterm) to reset FAST FORTH
62 \ with MSP430FR5xxx or MSP430FR6xxx targets, you can first set RTC:
63 \ by downloading RTC.f with SendSourceFileToTarget.bat
64 \ then terminal input asks you to type (with spaces) (DMY), then (HMS),
65 \ So, subsequent copied files will be dated:
67 \ with CopySourceFileToTarget_SD_Card.bat (or better, from scite editor, menu tools):
69 \ copy TESTASM.4TH to \MISC\TESTASM.4TH (add path \MISC in the window opened by TERATERM)
70 \ copy TSTWORDS.4TH to \TSTWORDS.4TH
71 \ copy CORETEST.4TH to \CORETEST.4TH
72 \ copy SD_TOOLS.f to \SD_TOOLS.4TH
73 \ copy SD_TEST.f to \SD_TEST.4TH
74 \ copy PROG100k.f to \PROG100k.4TH
75 \ copy RTC.f to \RTC.4TH ( doesn't work with if FR2xxx or FR4xxx)
77 ; --------------------------------
79 ; --------------------------------
81 \ first, we do some tests allowing the download
92 SUB #401,TOS \ FastForth V4.1
94 'CR' EMIT \ return to column 1 without 'LF'
95 ABORT" FastForth V4.1 please!"
96 ABORT" build FastForth with SD_CARD_READ_WRITE addon!"
97 RST_RET \ remove ABORT_SD_TEST definition before resuming
102 ; ------------------------------------------------------------------
103 ; first we download the set of definitions we need (from CORE_ANS.f)
104 ; ------------------------------------------------------------------
106 \ https://forth-standard.org/standard/core/EXIT
107 \ EXIT -- exit a colon definition; CALL #EXIT performs ASMtoFORTH (10 cycles)
108 \ JMP #EXIT performs EXIT
112 MOV @RSP+,IP \ 2 pop previous IP (or next PC) from return stack
113 MOV @IP+,PC \ 4 = NEXT
117 \ https://forth-standard.org/standard/core/SWAP
118 \ SWAP x1 x2 -- x2 x1 swap top two items
129 \ https://forth-standard.org/standard/core/toBODY
130 \ >BODY -- addr leave BODY of a CREATEd word\ also leave default ACTION-OF primary DEFERred word
139 \ https://forth-standard.org/standard/core/ZeroEqual
140 \ 0= n/u -- flag return true if TOS=0
144 SUB #1,TOS \ borrow (clear cy) if TOS was 0
145 SUBC TOS,TOS \ TOS=-1 if borrow was set
150 \ https://forth-standard.org/standard/core/IF
151 \ IF -- IFadr initialize conditional forward branch
153 [IF] \ define IF and THEN
157 MOV &DP,TOS \ -- HERE
158 ADD #4,&DP \ compile one word, reserve one word
159 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
160 ADD #2,TOS \ -- HERE+2=IFadr
164 \ https://forth-standard.org/standard/core/THEN
165 \ THEN IFadr -- resolve forward branch
166 CODE THEN \ immediate
167 MOV &DP,0(TOS) \ -- IFadr
173 \ https://forth-standard.org/standard/core/ELSE
174 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
177 CODE ELSE \ immediate
178 ADD #4,&DP \ make room to compile two words
181 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
183 MOV W,TOS \ -- ELSEadr
188 \ https://forth-standard.org/standard/core/BEGIN
189 \ BEGIN -- BEGINadr initialize backward branch
191 [IF] \ define BEGIN UNTIL AGAIN WHILE REPEAT
196 \ https://forth-standard.org/standard/core/UNTIL
197 \ UNTIL BEGINadr -- resolve conditional backward branch
198 CODE UNTIL \ immediate
200 BW1 ADD #4,&DP \ compile two words
202 MOV X,-4(W) \ compile Bran or QFBRAN at HERE
203 MOV TOS,-2(W) \ compile bakcward adr at HERE+2
208 \ https://forth-standard.org/standard/core/AGAIN
209 \ AGAIN BEGINadr -- resolve uncondionnal backward branch
210 CODE AGAIN \ immediate
215 \ https://forth-standard.org/standard/core/WHILE
216 \ WHILE BEGINadr -- WHILEadr BEGINadr
221 \ https://forth-standard.org/standard/core/REPEAT
222 \ REPEAT WHILEadr BEGINadr -- resolve WHILE loop
224 POSTPONE AGAIN POSTPONE THEN
228 \ https://forth-standard.org/standard/core/DO
229 \ DO -- DOadr L: -- 0
231 [IF] \ define DO LOOP +LOOP
232 HDNCODE XDO \ DO run time
233 MOV #$8000,X \ 2 compute 8000h-limit = "fudge factor"
235 MOV TOS,Y \ 1 loop ctr = index+fudge
236 ADD X,Y \ 1 Y = INDEX
237 PUSHM #2,X \ 4 PUSHM X,Y, i.e. PUSHM LIMIT, INDEX
245 ADD #2,&DP \ make room to compile xdo
246 MOV &DP,TOS \ -- HERE+2
247 MOV #XDO,-2(TOS) \ compile xdo
248 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
250 MOV #0,0(W) \ -- HERE+2 L-- 0
254 \ https://forth-standard.org/standard/core/LOOP
255 \ LOOP DOadr -- L-- an an-1 .. a1 0
256 HDNCODE XLOOP \ LOOP run time
257 ADD #1,0(RSP) \ 4 increment INDEX
258 BW1 BIT #$100,SR \ 2 is overflow bit set?
259 0= IF \ branch if no overflow
263 ADD #4,RSP \ 1 empties RSP
264 ADD #2,IP \ 1 overflow = loop done, skip branch ofs
265 MOV @IP+,PC \ 4 14~ taken or not taken xloop/loop
270 BW2 ADD #4,&DP \ make room to compile two words
272 MOV X,-4(W) \ xloop --> HERE
273 MOV TOS,-2(W) \ DOadr --> HERE+2
274 BEGIN \ resolve all "leave" adr
275 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
276 SUB #2,&LEAVEPTR \ --
277 MOV @TOS,TOS \ -- first LeaveStack value
278 CMP #0,TOS \ -- = value left by DO ?
280 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
286 \ https://forth-standard.org/standard/core/PlusLOOP
287 \ +LOOP adrs -- L-- an an-1 .. a1 0
288 HDNCODE XPLOO \ +LOOP run time
289 ADD TOS,0(RSP) \ 4 increment INDEX by TOS value
290 MOV @PSP+,TOS \ 2 get new TOS, doesn't change flags
296 GOTO BW2 \ goto BW1 LOOP
300 \ https://forth-standard.org/standard/core/I
301 \ I -- n R: sys1 sys2 -- sys1 sys2
302 \ get the innermost loop index
306 SUB #2,PSP \ 1 make room in TOS
308 MOV @RSP,TOS \ 2 index = loopctr - fudge
314 \ https://forth-standard.org/standard/core/Plus
315 \ + n1/u1 n2/u2 -- n3/u3 add n1+n2
324 \ https://forth-standard.org/standard/core/Minus
325 \ - n1/u1 n2/u2 -- n3/u3 n3 = n1-n2
329 SUB @PSP+,TOS \ 2 -- n2-n1 ( = -n3)
331 ADD #1,TOS \ 1 -- n3 = -(n2-n1) = n1-n2
337 [IF] \ define MAX and MIN
338 CODE MAX \ n1 n2 -- n3 signed maximum
345 CODE MIN \ n1 n2 -- n3 signed minimum
353 \ https://forth-standard.org/standard/core/CFetch
354 \ C@ c-addr -- char fetch char from memory
363 \ https://forth-standard.org/standard/core/SPACE
364 \ SPACE -- output a space
371 \ https://forth-standard.org/standard/core/SPACES
372 \ SPACES n -- output n spaces
388 MOV @PSP+,TOS \ -- drop n
393 \ https://forth-standard.org/standard/core/DUP
394 \ DUP x -- x x duplicate top of stack
396 [IF] \ define DUP and DUP?
398 BW1 SUB #2,PSP \ 2 push old TOS..
399 MOV TOS,0(PSP) \ 3 ..onto stack
403 \ https://forth-standard.org/standard/core/qDUP
404 \ ?DUP x -- 0 | x x DUP if nonzero
406 CMP #0,TOS \ 2 test for TOS nonzero
412 \ https://forth-standard.org/standard/core/OVER
413 \ OVER x1 x2 -- x1 x2 x1
417 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
418 MOV @PSP,TOS \ 2 -- x1 (x2) x1
419 SUB #2,PSP \ 1 -- x1 x2 x1
424 \ https://forth-standard.org/standard/core/toR
425 \ >R x -- R: -- x push to return stack
435 \ https://forth-standard.org/standard/core/Rfrom
436 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
447 \ https://forth-standard.org/standard/core/CONSTANT
448 \ CONSTANT <name> n -- define a Forth CONSTANT
454 MOV TOS,-2(W) \ PFA = n
461 \ https://forth-standard.org/standard/core/STATE
462 \ STATE -- a-addr holds compiler state
465 STATEADR CONSTANT STATE
468 \ https://forth-standard.org/standard/core/CR
469 \ CR -- send CR+LF to the output device
473 \ DEFER CR \ DEFERed definition, by default executes that of :NONAME
474 \ create a primary defered word, i.e. with its default runtime beginning at the >BODY of the definition
475 CODE CR \ part I : DEFERed definition of CR
476 MOV #NEXT_ADR,PC \ [PFA] = NEXT_ADR
484 \ https://forth-standard.org/standard/core/BASE
485 \ BASE -- a-addr holds conversion radix
488 BASEADR CONSTANT BASE
498 \ https://forth-standard.org/standard/core/DROP
499 \ DROP x -- drop top of stack
508 \ https://forth-standard.org/standard/core/OnePlus
509 \ 1+ n1/u1 -- n2/u2 add 1 to TOS
518 \ https://forth-standard.org/standard/core/Equal
519 \ = x1 x2 -- flag test x1=x2
528 XOR #-1,TOS \ 1 flag Z = 1
533 \ https://forth-standard.org/standard/core/CASE
538 ; IMMEDIATE \ -- #of-1
540 \ https://forth-standard.org/standard/core/OF
541 : OF \ #of-1 -- orgOF #of
543 >R \ move off the stack in case the control-flow stack is the data stack.
545 POSTPONE = \ copy and test case value
546 POSTPONE IF \ add orig to control flow stack
547 POSTPONE DROP \ discards case value if =
548 R> \ we can bring count back now
551 \ https://forth-standard.org/standard/core/ENDOF
552 : ENDOF \ orgOF #of -- orgENDOF #of
553 >R \ move off the stack in case the control-flow stack is the data stack.
555 R> \ we can bring count back now
558 \ https://forth-standard.org/standard/core/ENDCASE
559 : ENDCASE \ orgENDOF1..orgENDOFn #of --
567 ; ------------------------------------------------------------------
568 ; then we download the set of definitions we need (from UTILITY.f)
569 ; ------------------------------------------------------------------
572 [IF] \ defined in {UTILITY}
573 : U.R \ u n -- display u unsigned in n width (n >= 2)
575 R> OVER - 0 MAX SPACES TYPE
579 ; --------------------------
580 ; end of definitions we need
581 ; --------------------------
583 \ https://forth-standard.org/standard/tools/DUMP
584 CODE DUMP \ adr n -- dump memory
586 PUSH &BASE \ save current base
587 MOV #$10,&BASE \ HEX base
588 ADD @PSP,TOS \ -- ORG END
592 I 4 U.R SPACE \ generate address
599 I $10 + I \ display 16 chars
600 DO I C@ $7E MIN $20 MAX EMIT LOOP
603 R> BASE ! \ restore current base
606 \ SD_EMIT c -- output char c to a SD_CARD file opened as write
609 MOV.B TOS,SD_BUF(Y) \ 3
613 CMP #$200,Y \ 2 512 bytes by sector
614 U>= IF \ 2 if buffer is full
615 CALL #Write_File \ write it; BufferPtr = 0
621 ['] SD_EMIT IS EMIT \ redirect output to SD_EMIT
622 MAIN_ORG HERE OVER - DUMP \ dump MAIN memory up to HERE address
623 ['] EMIT >BODY IS EMIT \ redirect output to default EMIT
624 CLOSE \ close YOURFILE.TXT
628 MOV #%01_0010_0100,&TB0CTL \ start TB0, ACLK (32768 Hz), continuous mode
634 MOV TOS,4(PSP) \ save TOS
635 MOV &TB0R,2(PSP) \ DVDlo=TB0R
636 MOV #0,&TB0CTL \ stop timer
637 MOV #0,0(PSP) \ DVDhi=0
638 MOV #33,TOS \ DVR=33 --> 0.7% error, 1985ms max
639 CALL #MUSMOD \ DVDlo DVDhi DVR -- REM QUOTlo QUOThi
640 MOV @PSP+,TOS \ -- REM QUOTlo
641 ADD #2,PSP \ -- QUOlo
643 ECHO ." , done in " U. ." ms"
653 ." ? Fast Forth Specs" CR
654 ." 0 Set date and time (MSP430FR5xxx)" CR
655 ." 1 Load {UTILITY} words" CR
656 ." 2 Load {SD_TOOLS} words" CR
657 ." 3 Load {CORE_ANS} words" CR
658 ." 4 Execute ANS core tests" CR
659 ." 5 Load a source file to compile 10k program" CR
660 ." 6 Read it only (51k)" CR
661 ." 7 write FORTH dump in YOURFILE.TXT" CR
662 ." 8 append FORTH dump to YOURFILE.TXT" CR
663 ." 9 delete YOURFILE.TXT" CR
666 IF KEY DROP ." 'CR'" \ skip LF...
669 RST_RET \ remove all definitions
672 '?' OF CR LOAD" FF_SPECS.4TH" ENDOF \ LOAD" command is always executed after the SD_TEST exit,
673 '0' OF CR LOAD" RTC.4TH" ENDOF \ so, no risk of crashing this program, regardless of RST_RET use...
674 '1' OF CR LOAD" UTILITY.4TH" ENDOF
675 '2' OF CR LOAD" SD_TOOLS.4TH" ENDOF
676 '3' OF CR LOAD" CORE_ANS.4TH" ENDOF
677 '4' OF CR LOAD" CORETEST.4TH" ENDOF
678 '5' OF CR LOAD" PROG10K.4TH" ENDOF
679 \ ...instead of READ" WRITE" APPEND" DEL" which are executed immediately
681 READ" PROG10K.4TH" \ open file as read
682 BEGIN READ UNTIL \ sequentially read 512 bytes, then the file is closed
685 WRITE" YOURFILE.TXT" \ create new file or overwrite existing file
686 WRITEDUMP DISPLAY_TIME ENDOF
688 APPEND" YOURFILE.TXT" \ append to existing file or create new file
689 WRITEDUMP DISPLAY_TIME ENDOF
691 DEL" YOURFILE.TXT" \ no message