1 \ -*- coding: utf-8 -*-
3 \ displays all FastForth specifications
6 \ FastForth kernel compilation minimal options:
7 \ TERMINAL3WIRES, TERMINAL4WIRES
8 \ MSP430ASSEMBLER, CONDCOMP
10 \ TARGET ( = the name of \INC\target.pat file without extension):
11 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
12 \ MSP_EXP430FR4133 CHIPSTICK_FR2433 MSP_EXP430FR2433 MSP_EXP430FR2355
16 \ from scite editor : copy your TARGET selection in (shift+F8) parameter 1:
17 \ copy COMPLEMENT if used in (shift+F8) parameter 2:
21 \ from file explorer : drag and drop this file onto SendSourceFileToTarget.bat
22 \ then select your TARGET + COMPLEMENT when asked.
24 ; ---------------------------------
26 ; ---------------------------------
28 \ first, we do some tests allowing the download
32 MOV &VERSION,TOS \ ARG
33 SUB #309,TOS \ FastForth V3.9
35 'CR' EMIT \ return to column 1 without 'LF'
36 ABORT" FastForth V3.9 please!"
37 RST_RET \ remove ABORT_FF_SPECS definition before resuming
42 \ https://forth-standard.org/standard/core/DUP
43 \ DUP x -- x x duplicate top of stack
45 [IF] \ define DUP and DUP?
47 BW1 SUB #2,PSP \ 2 push old TOS..
48 MOV TOS,0(PSP) \ 3 ..onto stack
52 \ https://forth-standard.org/standard/core/qDUP
53 \ ?DUP x -- 0 | x x DUP if nonzero
55 CMP #0,TOS \ 2 test for TOS nonzero
61 \ https://forth-standard.org/standard/core/OVER
62 \ OVER x1 x2 -- x1 x2 x1
66 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
67 MOV @PSP,TOS \ 2 -- x1 (x2) x1
68 SUB #2,PSP \ 1 -- x1 x2 x1
73 \ https://forth-standard.org/standard/core/DROP
74 \ DROP x -- drop top of stack
83 \ https://forth-standard.org/standard/core/SWAP
84 \ SWAP x1 x2 -- x2 x1 swap top two items
95 \ https://forth-standard.org/standard/core/ROT
96 \ ROT x1 x2 x3 -- x2 x3 x1
100 MOV @PSP,W \ 2 fetch x2
101 MOV TOS,0(PSP) \ 3 store x3
102 MOV 2(PSP),TOS \ 3 fetch x1
103 MOV W,2(PSP) \ 3 store x2
108 \ https://forth-standard.org/standard/core/toR
109 \ >R x -- R: -- x push to return stack
119 \ https://forth-standard.org/standard/core/Rfrom
120 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
131 \ https://forth-standard.org/standard/core/Zeroless
132 \ 0< n -- flag true if TOS negative
136 ADD TOS,TOS \ 1 set carry if TOS negative
137 SUBC TOS,TOS \ 1 TOS=-1 if carry was clear
138 XOR #-1,TOS \ 1 TOS=-1 if carry was set
143 \ https://forth-standard.org/standard/core/Equal
144 \ = x1 x2 -- flag test x1=x2
150 AND #0,TOS \ 1 flag Z = 1
158 \ https://forth-standard.org/standard/core/Uless
159 \ U< u1 u2 -- flag test u1<u2, unsigned
163 SUB @PSP+,TOS \ 2 u2-u1
171 \ https://forth-standard.org/standard/core/Umore
175 U< ?GOTO BW1 \ 2 flag = true, Z = 0
176 FW1 AND #0,TOS \ 1 Z = 1
181 \ https://forth-standard.org/standard/core/IF
182 \ IF -- IFadr initialize conditional forward branch
184 [IF] \ define IF and THEN
188 MOV &DP,TOS \ -- HERE
189 ADD #4,&DP \ compile one word, reserve one word
190 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
191 ADD #2,TOS \ -- HERE+2=IFadr
195 \ https://forth-standard.org/standard/core/THEN
196 \ THEN IFadr -- resolve forward branch
198 MOV &DP,0(TOS) \ -- IFadr
204 \ https://forth-standard.org/standard/core/ELSE
205 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
209 ADD #4,&DP \ make room to compile two words
212 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
214 MOV W,TOS \ -- ELSEadr
219 \ https://forth-standard.org/standard/core/BEGIN
220 \ BEGIN -- BEGINadr initialize backward branch
222 [IF] \ define BEGIN UNTIL AGAIN WHILE REPEAT
227 \ https://forth-standard.org/standard/core/UNTIL
228 \ UNTIL BEGINadr -- resolve conditional backward branch
229 CODE UNTIL \ immediate
231 BW1 ADD #4,&DP \ compile two words
233 MOV X,-4(W) \ compile Bran or QFBRAN at HERE
234 MOV TOS,-2(W) \ compile bakcward adr at HERE+2
239 \ https://forth-standard.org/standard/core/AGAIN
240 \ AGAIN BEGINadr -- resolve uncondionnal backward branch
249 \ https://forth-standard.org/standard/core/WHILE
250 \ WHILE BEGINadr -- WHILEadr BEGINadr
258 \ https://forth-standard.org/standard/core/REPEAT
259 \ REPEAT WHILEadr BEGINadr -- resolve WHILE loop
261 POSTPONE AGAIN POSTPONE THEN
265 \ https://forth-standard.org/standard/core/DO
266 \ DO -- DOadr L: -- 0
268 [IF] \ define DO LOOP +LOOP
269 HDNCODE XDO \ DO run time
270 MOV #$8000,X \ 2 compute 8000h-limit = "fudge factor"
272 MOV TOS,Y \ 1 loop ctr = index+fudge
273 ADD X,Y \ 1 Y = INDEX
274 PUSHM #2,X \ 4 PUSHM X,Y, i.e. PUSHM LIMIT, INDEX
282 ADD #2,&DP \ make room to compile xdo
283 MOV &DP,TOS \ -- HERE+2
284 MOV #XDO,-2(TOS) \ compile xdo
285 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
287 MOV #0,0(W) \ -- HERE+2 L-- 0
291 \ https://forth-standard.org/standard/core/LOOP
292 \ LOOP DOadr -- L-- an an-1 .. a1 0
293 HDNCODE XLOOP \ LOOP run time
294 ADD #1,0(RSP) \ 4 increment INDEX
295 BW1 BIT #$100,SR \ 2 is overflow bit set?
296 0= IF \ branch if no overflow
300 ADD #4,RSP \ 1 empties RSP
301 ADD #2,IP \ 1 overflow = loop done, skip branch ofs
302 MOV @IP+,PC \ 4 14~ taken or not taken xloop/loop
307 BW2 ADD #4,&DP \ make room to compile two words
309 MOV X,-4(W) \ xloop --> HERE
310 MOV TOS,-2(W) \ DOadr --> HERE+2
311 BEGIN \ resolve all "leave" adr
312 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
313 SUB #2,&LEAVEPTR \ --
314 MOV @TOS,TOS \ -- first LeaveStack value
315 CMP #0,TOS \ -- = value left by DO ?
317 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
323 \ https://forth-standard.org/standard/core/PlusLOOP
324 \ +LOOP adrs -- L-- an an-1 .. a1 0
325 HDNCODE XPLOO \ +LOOP run time
326 ADD TOS,0(RSP) \ 4 increment INDEX by TOS value
327 MOV @PSP+,TOS \ 2 get new TOS, doesn't change flags
337 \ https://forth-standard.org/standard/core/I
338 \ I -- n R: sys1 sys2 -- sys1 sys2
339 \ get the innermost loop index
343 SUB #2,PSP \ 1 make room in TOS
345 MOV @RSP,TOS \ 2 index = loopctr - fudge
358 \ https://forth-standard.org/standard/core/CFetch
359 \ C@ c-addr -- char fetch char from memory
368 \ https://forth-standard.org/standard/core/SPACES
369 \ SPACES n -- output n spaces
384 MOV @PSP+,TOS \ -- drop n
389 \ https://forth-standard.org/standard/core/OnePlus
390 \ 1+ n1/u1 -- n2/u2 add 1 to TOS
399 \ https://forth-standard.org/standard/core/Plus
400 \ + n1/u1 n2/u2 -- n3/u3 add n1+n2
409 \ https://forth-standard.org/standard/core/Minus
410 \ - n1/u1 n2/u2 -- n3/u3 n3 = n1-n2
414 SUB @PSP+,TOS \ 2 -- n2-n1 ( = -n3)
416 ADD #1,TOS \ 1 -- n3 = -(n2-n1) = n1-n2
421 \ https://forth-standard.org/standard/core/TwoTimes
422 \ 2* x1 -- x2 arithmetic left shift
431 \ https://forth-standard.org/standard/core/TwoDiv
432 \ 2/ x1 -- x2 arithmetic right shift
441 \ https://forth-standard.org/standard/core/UMDivMOD
442 \ UM/MOD udlo|udhi u1 -- r q unsigned 32/16->r16 q16
447 MOV #MUSMOD,PC \ execute MUSMOD then return to DROP
451 \ https://forth-standard.org/standard/core/MOVE
452 \ MOVE addr1 addr2 u -- smart move
453 \ VERSION FOR 1 ADDRESS UNIT = 1 CHAR
458 MOV @PSP+,Y \ Y = addr2 = dst
459 MOV @PSP+,X \ X = addr1 = src
460 MOV @PSP+,TOS \ pop new TOS
461 CMP #0,W \ count = 0 ?
462 0<> IF \ if 0, already done !
463 CMP X,Y \ Y-X \ dst - src
464 0<> IF \ if dst = src, already done !
465 U< IF \ U< if src > dst
472 THEN \ U>= if dst > src
473 ADD W,Y \ copy W bytes beginning with the end
487 \ https://forth-standard.org/standard/core/CR
488 \ CR -- send CR+LF to the output device
492 \ create a primary defered word, i.e. with its default runtime beginning at the >BODY of the definition
493 CODE CR \ part I : DEFERed definition of CR
494 MOV #NEXT_ADR,PC \ [PFA] = NEXT_ADR
497 :NONAME \ part II : :NONAME part as default runtime of CR
499 ; IS CR \ set [PFA] of CR = >BODY addr of CR = CFA of :NONAME part
504 : WORDS \ VOC_BODY --
505 PAD_ORG \ -- VOC_BODY PAD MOVE all threads of VOC_BODY in PAD_ORG
506 THREADS @ 2* \ -- VOC_BODY PAD THREADS*2
507 MOVE \ -- vocabulary entries are copied in PAD_ORG
509 0 DUP \ -- ptr=0 MAX=0
510 THREADS @ 2* 0 \ -- ptr=0 MAX=0 THREADS*2 0
511 DO \ -- ptr MAX I = PAD_ptr = thread*2
512 DUP I PAD_ORG + @ \ -- ptr MAX MAX NFAx
513 U< IF \ -- ptr MAX if MAX U< NFAx
514 DROP DROP \ -- drop ptr and MAX
515 I DUP PAD_ORG + @ \ -- new_ptr new_MAX
518 ?DUP \ -- ptr MAX MAX | -- ptr 0 (all threads in PAD = 0)
519 WHILE \ -- ptr MAX replace it by its LFA
521 2 - @ \ -- ptr MAX [LFA]
522 ROT \ -- MAX [LFA] ptr
523 PAD_ORG + \ -- MAX [LFA] thread
524 ! \ -- MAX MAX=highest_NFA [LFA]=new_NFA updates PAD_ORG+ptr
525 COUNT 2/ \ -- addr name_count 2/ to hide Immediate flag
526 DUP >R TYPE \ -- R-- count
527 $10 R> - SPACES \ -- R-- complete with spaces modulo 16 chars
530 ; \ all threads in PAD are filled with 0
532 \ https://forth-standard.org/standard/core/CASE
537 ; IMMEDIATE \ -- #of-1
539 \ https://forth-standard.org/standard/core/OF
540 : OF \ #of-1 -- orgOF #of
542 >R \ move off the stack in case the control-flow stack is the data stack.
544 POSTPONE = \ copy and test case value
545 POSTPONE IF \ add orig to control flow stack
546 POSTPONE DROP \ discards case value if =
547 R> \ we can bring count back now
550 \ https://forth-standard.org/standard/core/ENDOF
551 : ENDOF \ orgOF #of -- orgENDOF #of
552 >R \ move off the stack in case the control-flow stack is the data stack.
554 R> \ we can bring count back now
557 \ https://forth-standard.org/standard/core/ENDCASE
558 : ENDCASE \ orgENDOF1..orgENDOFn #of --
568 CODE S_ \ Squote alias with blank instead quote separator
569 MOV #0,&CAPS \ turn CAPS OFF
571 XSQUOTE , \ compile run-time code
572 'SP' WORD \ -- c-addr (= HERE)
574 MOV.B @TOS,TOS \ -- len compile string
575 ADD #1,TOS \ -- len+1
577 ADDC TOS,&DP \ store aligned DP
579 MOV @RSP+,IP \ pop paired with push COLON
580 MOV #$20,&CAPS \ turn CAPS ON (default state)
589 0= IF MOV @IP+,PC \ interpret time usage disallowed
592 'ESC' \ -- char escape
593 POSTPONE LITERAL \ compile-time code : lit 'ESC'
594 POSTPONE EMIT \ compile-time code : EMIT
595 POSTPONE S_ \ compile-time code : S_ <escape_sequence>
596 POSTPONE TYPE \ compile-time code : TYPE
600 [DEFINED] FORTH \ word-set addon ?
602 CODE BODY>SQNFA \ BODY -- ADR cnt BODY > SQuoteNFA
609 MOV X,0(PSP) \ -- string_test_address CFA
610 MOV.B @X+,TOS \ -- string_test_address cnt_test
611 RRA TOS \ -- string_test_address cnt_test/2
613 BIT #1,W \ cnt_test even ?
615 ADD #1,W \ if yes add #1,TOS
617 ADD X,W \ string_test_address + cnt_test
618 CMP W,Y \ string_test_address + cnt_test = CFA ?
619 0<> WHILE \ out of loop if yes
620 MOV @PSP,X \ loop back to test with X - one_word
622 MOV X,0(PSP) \ -- string_addr string_cnt
627 \ -------------------------------------------------------
628 : SPECS \ to see all FastForth specifications
629 \ -------------------------------------------------------
630 RST_RET \ before computing free bytes, remove all FF_SPECS definitions
632 ESC [8;42;80t \ set 42L * 80C terminal display
634 \ title in reverse video
635 ESC [7m \ Turn reverse video on
638 0 <# # 'BS' HOLD # '.' HOLD #S #> TYPE
640 HERE \ HERE - MAIN_ORG = bytes code
641 DEVICEID @ \ value kept in TLV area
644 \ device_ID OF ." xxxx," $MAIN_ORG ENDOF \ <-- add here your device
645 $8102 OF ." 5738," $C200 ENDOF
646 $8103 OF ." 5739," $C200 ENDOF
647 $810D OF ." 5986," $4400 ENDOF
648 $8160 OF ." 5948," $4400 ENDOF
649 $8169 OF ." 5969," $4400 ENDOF
650 $81A8 OF ." 6989," $4400 ENDOF
651 $81F0 OF ." 4133," $C400 ENDOF
652 $8240 OF ." 2433," $C400 ENDOF
653 $825D OF ." 5972," $4400 ENDOF
654 $82A1 OF ." 5994," $4000 ENDOF
655 $82A6 OF ." 5962," $4000 ENDOF
656 $830C OF ." 2355," $8000 ENDOF
657 $830D OF ." 2353," $C000 ENDOF
658 $831E OF ." 2155," $8000 ENDOF
659 $831D OF ." 2153," $C000 ENDOF
660 $832A OF ." 2476," $8000 ENDOF
661 $832B OF ." 2475," $8000 ENDOF
662 $833C OF ." 2633," $C400 ENDOF
663 $833D OF ." 2533," $C400 ENDOF
664 ABORT" xxxx <-- unrecognized device!"
665 ENDCASE \ -- HERE MAIN_ORG
666 ['] ['] DUP @ $1284 = \ DOCOL = CALL rDOCOL opcode
667 IF ." DTC=1," DROP \ [CFA] = CALL rDOCOL
669 IF ." DTC=2," \ [CFA] = PUSH IP, [CFA+2] = CALL rDOCOL
670 ELSE ." DTC=3," \ [CFA] = PUSH IP, [CFA+2] = MOV PC,IP
674 THREADS @ U. 'BS' EMIT
675 ." -Entry word set, " \ number of Entry word set,
676 FREQ_KHZ @ 0 1000 UM/MOD U. \ frequency
677 ?DUP IF 'BS' EMIT ',' EMIT U. \ if remainder
678 THEN ." MHz, " \ MCLK
679 - U. ." bytes" \ HERE - MAIN_ORG = number of bytes code,
680 ESC [0m \ Turn off character attributes
684 ." /COUNTED-STRING = 255" CR
687 ." ADDRESS-UNIT-BITS = 16" CR
688 ." FLOORED DIVISION = "
689 KERNEL_ADDON @ \ negative value if FLOORED DIVISION
693 ." MAX-CHAR = 255" CR
696 ." MAX-D = 2147483647" CR
697 ." MAX-UD = 4294967295" CR
698 ." STACK-CELLS = 48" CR
699 ." RETURN-STACK-CELLS= 48" CR
700 ." Definitions are forced to UPPERCASE." CR
703 CR ESC [7m ." Kernel add-ons" ESC [0m CR \ subtitle in reverse video
705 2* DUP 0< IF ." 32.768kHz LF XTAL" CR THEN \ BIT14
706 2* DUP 0< IF ." /RTS /CTS " 2* \ BIT13
708 0< IF ." /RTS " THEN \ /BIT13 & BIT12
710 2* DUP 0< IF ." XON/XOFF " THEN \ BIT11
711 2* DUP 0< IF ." Half-Duplex " THEN \ BIT10
712 2* DUP 0< IF ." I2C_Master TERMINAL" \ BIT9
713 ELSE ." UART TERMINAL" THEN CR \ /BIT9
714 2* DUP 0< IF 2* DUP 0< IF ." DOUBLE and " \ BIT8 + BIT7
715 THEN ." Q15.16 numbers handling" CR
716 ELSE 2* DUP 0< IF ." DOUBLE numbers handling" CR \ /BIT8 + BIT7
719 2* DUP 0< IF ." MSP430_X assembler with TI's syntax"
720 CR 2* 2* \ BIT6 BIT5 BIT4
723 0< IF ." MSP430 Assembler" \ BIT5
725 0< IF ." , 20bits extended addresses," \ BIT4
729 ." with TI's syntax" CR
730 THEN DROP \ BIT2 to BIT0 are free
731 [DEFINED] FORTH [IF] ." word-set management" CR
733 [DEFINED] LOAD" [IF] ." SD_CARD Load" CR
735 [DEFINED] BOOT [IF] ." SD_CARD Bootloader" CR
737 [DEFINED] READ" [IF] ." SD_CARD Read/Write" CR
741 LASTVOC \ -- VOCLINK addr.
743 @ ?DUP \ -- VOCLINK word-set here ?
745 DUP THREADS @ 2* - \ -- VLK WORDSET_BODY
747 [DEFINED] FORTH \ word-set addon ?
748 [IF] DUP BODY>SQNFA \ -- VLK WRDST_BODY addr cnt
749 [ELSE] OVER @ \ -- VLK WRDST_BODY NEXT_VLINK
750 IF S" hidden" \ if next_vlink <>0
751 ELSE S" FORTH" \ if next_vlink = 0
752 THEN \ -- VLK WRDST_BODY addr cnt
754 TYPE ." word-set" \ -- VLK WRDST_BODY subtitle in reverse video
756 WORDS CR \ -- VLINK definitions display
760 CR ESC [7m ." EXTENSIONS" ESC [0m \ subtitle in reverse video
761 [DEFINED] {CORE_ANS} [IF] CR ." core ANS94"
763 [DEFINED] {DOUBLE} [IF] CR ." DOUBLE word set"
765 [DEFINED] {UTILITY} [IF] CR ." UTILITY"
767 [DEFINED] {FIXPOINT} [IF] CR ." Q15.16 ADD SUB MUL DIV"
769 [DEFINED] {CORDIC} [IF] CR ." CORDIC engine"
771 [DEFINED] {SD_TOOLS} [IF] CR ." SD_TOOLS"
773 [DEFINED] {RTC} [IF] CR ." RTC utility"
775 [DEFINED] {UARTI2CS} [IF] CR ." UART to I2C_FastForth bridge"
781 SPECS \ performs RST_RET and displays FastForth specs