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 test for downloading driver only if good FastForth version
33 SUB #308,TOS \ FastForth V3.8
35 'CR' EMIT \ return to column 1 without 'LF'
36 ABORT" FastForth V3.8 please!"
37 PWR_STATE \ remove ABORT_FF_SPECS definition before resuming
43 \ https://forth-standard.org/standard/core/AND
44 \ C AND x1 x2 -- x3 logical AND
51 [UNDEFINED] DUP [IF] \ define DUP and DUP?
52 \ https://forth-standard.org/standard/core/DUP
53 \ DUP x -- x x duplicate top of stack
55 BW1 SUB #2,PSP \ 2 push old TOS..
56 MOV TOS,0(PSP) \ 3 ..onto stack
60 \ https://forth-standard.org/standard/core/qDUP
61 \ ?DUP x -- 0 | x x DUP if nonzero
63 CMP #0,TOS \ 2 test for TOS nonzero
70 \ https://forth-standard.org/standard/core/OVER
71 \ OVER x1 x2 -- x1 x2 x1
73 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
74 MOV @PSP,TOS \ 2 -- x1 (x2) x1
75 SUB #2,PSP \ 1 -- x1 x2 x1
81 \ https://forth-standard.org/standard/core/DROP
82 \ DROP x -- drop top of stack
90 \ https://forth-standard.org/standard/core/SWAP
91 \ SWAP x1 x2 -- x2 x1 swap top two items
101 \ https://forth-standard.org/standard/core/ROT
102 \ ROT x1 x2 x3 -- x2 x3 x1
104 MOV @PSP,W \ 2 fetch x2
105 MOV TOS,0(PSP) \ 3 store x3
106 MOV 2(PSP),TOS \ 3 fetch x1
107 MOV W,2(PSP) \ 3 store x2
113 \ https://forth-standard.org/standard/core/toR
114 \ >R x -- R: -- x push to return stack
123 \ https://forth-standard.org/standard/core/Rfrom
124 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
134 \ https://forth-standard.org/standard/core/ZeroEqual
135 \ 0= n/u -- flag return true if TOS=0
137 SUB #1,TOS \ borrow (clear cy) if TOS was 0
138 SUBC TOS,TOS \ TOS=-1 if borrow was set
144 \ https://forth-standard.org/standard/core/Zeroless
145 \ 0< n -- flag true if TOS negative
147 ADD TOS,TOS \ 1 set carry if TOS negative
148 SUBC TOS,TOS \ 1 TOS=-1 if carry was clear
149 XOR #-1,TOS \ 1 TOS=-1 if carry was set
155 \ https://forth-standard.org/standard/core/Equal
156 \ = x1 x2 -- flag test x1=x2
160 AND #0,TOS \ 1 flag Z = 1
168 \ https://forth-standard.org/standard/core/Uless
169 \ U< u1 u2 -- flag test u1<u2, unsigned
172 SUB @PSP+,TOS \ 2 u2-u1
176 AND #0,TOS \ 1 flag Z = 1
183 [UNDEFINED] IF [IF] \ define IF and THEN
184 \ https://forth-standard.org/standard/core/IF
185 \ IF -- IFadr initialize conditional forward branch
189 MOV &DP,TOS \ -- HERE
190 ADD #4,&DP \ compile one word, reserve one word
191 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
192 ADD #2,TOS \ -- HERE+2=IFadr
196 \ https://forth-standard.org/standard/core/THEN
197 \ THEN IFadr -- resolve forward branch
199 MOV &DP,0(TOS) \ -- IFadr
205 [UNDEFINED] ELSE [IF]
206 \ https://forth-standard.org/standard/core/ELSE
207 \ 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 [UNDEFINED] BEGIN [IF] \ define BEGIN UNTIL AGAIN WHILE REPEAT
220 \ https://forth-standard.org/standard/core/BEGIN
221 \ BEGIN -- BEGINadr initialize backward branch
227 [UNDEFINED] UNTIL [IF] \ define BEGIN UNTIL AGAIN WHILE REPEAT
228 \ https://forth-standard.org/standard/core/UNTIL
229 \ UNTIL BEGINadr -- resolve conditional backward branch
232 BW1 ADD #4,&DP \ compile two words
234 MOV X,-4(W) \ compile Bran or QFBRAN at HERE
235 MOV TOS,-2(W) \ compile bakcward adr at HERE+2
240 \ https://forth-standard.org/standard/core/AGAIN
241 \ AGAIN BEGINadr -- resolve uncondionnal backward branch
248 [UNDEFINED] WHILE [IF] \ define DO LOOP +LOOP
249 \ https://forth-standard.org/standard/core/WHILE
250 \ WHILE BEGINadr -- WHILEadr BEGINadr
256 [UNDEFINED] REPEAT [IF] \ define DO LOOP +LOOP
257 \ https://forth-standard.org/standard/core/REPEAT
258 \ REPEAT WHILEadr BEGINadr -- resolve WHILE loop
260 POSTPONE AGAIN POSTPONE THEN
264 [UNDEFINED] DO [IF] \ define DO LOOP +LOOP
265 \ https://forth-standard.org/standard/core/DO
266 \ DO -- DOadr L: -- 0
270 ADD #2,&DP \ make room to compile xdo
271 MOV &DP,TOS \ -- HERE+2
272 MOV #XDO,-2(TOS) \ compile xdo
273 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
275 MOV #0,0(W) \ -- HERE+2 L-- 0
279 \ https://forth-standard.org/standard/core/LOOP
280 \ LOOP DOadr -- L-- an an-1 .. a1 0
283 BW1 ADD #4,&DP \ make room to compile two words
285 MOV X,-4(W) \ xloop --> HERE
286 MOV TOS,-2(W) \ DOadr --> HERE+2
287 BEGIN \ resolve all "leave" adr
288 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
289 SUB #2,&LEAVEPTR \ --
290 MOV @TOS,TOS \ -- first LeaveStack value
291 CMP #0,TOS \ -- = value left by DO ?
293 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
299 \ https://forth-standard.org/standard/core/PlusLOOP
300 \ +LOOP adrs -- L-- an an-1 .. a1 0
303 GOTO BW1 \ goto BW1 LOOP
308 \ https://forth-standard.org/standard/core/I
309 \ I -- n R: sys1 sys2 -- sys1 sys2
310 \ get the innermost loop index
312 SUB #2,PSP \ 1 make room in TOS
314 MOV @RSP,TOS \ 2 index = loopctr - fudge
320 [UNDEFINED] HERE [IF]
327 \ https://forth-standard.org/standard/core/CFetch
328 \ C@ c-addr -- char fetch char from memory
335 [UNDEFINED] SPACES [IF]
336 \ https://forth-standard.org/standard/core/SPACES
337 \ SPACES n -- output n spaces
351 MOV @PSP+,TOS \ -- drop n
357 \ https://forth-standard.org/standard/core/OnePlus
358 \ 1+ n1/u1 -- n2/u2 add 1 to TOS
366 \ https://forth-standard.org/standard/core/Plus
367 \ + n1/u1 n2/u2 -- n3/u3 add n1+n2
375 \ https://forth-standard.org/standard/core/Minus
376 \ - n1/u1 n2/u2 -- n3/u3 n3 = n1-n2
378 SUB @PSP+,TOS \ 2 -- n2-n1 ( = -n3)
380 ADD #1,TOS \ 1 -- n3 = -(n2-n1) = n1-n2
386 \ https://forth-standard.org/standard/core/TwoTimes
387 \ 2* x1 -- x2 arithmetic left shift
394 [UNDEFINED] UM/MOD [IF]
395 \ https://forth-standard.org/standard/core/UMDivMOD
396 \ UM/MOD udlo|udhi u1 -- r q unsigned 32/16->r16 q16
399 MOV #MUSMOD,PC \ execute MUSMOD then return to DROP
403 [UNDEFINED] MOVE [IF]
404 \ https://forth-standard.org/standard/core/MOVE
405 \ MOVE addr1 addr2 u -- smart move
406 \ VERSION FOR 1 ADDRESS UNIT = 1 CHAR
409 MOV @PSP+,Y \ Y = addr2 = dst
410 MOV @PSP+,X \ X = addr1 = src
411 MOV @PSP+,TOS \ pop new TOS
412 CMP #0,W \ count = 0 ?
413 0<> IF \ if 0, already done !
414 CMP X,Y \ Y-X \ dst - src
415 0<> IF \ if dst = src, already done !
416 U< IF \ U< if src > dst
423 THEN \ U>= if dst > src
424 ADD W,Y \ copy W bytes beginning with the end
438 [UNDEFINED] WORDS [IF]
439 \ https://forth-standard.org/standard/tools/WORDS
440 \ list all words of vocabulary first in CONTEXT.
443 CONTEXT @ PAD_ORG \ -- VOC_BODY PAD MOVE all threads of VOC_BODY in PAD_ORG
444 THREADS @ 2* \ -- VOC_BODY PAD THREADS*2
445 MOVE \ -- vocabulary entries are copied in PAD_ORG
447 0 DUP \ -- ptr=0 MAX=0
448 THREADS @ 2* 0 \ -- ptr=0 MAX=0 THREADS*2 0
449 DO \ -- ptr MAX I = PAD_ptr = thread*2
450 DUP I PAD_ORG + @ \ -- ptr MAX MAX NFAx
451 U< IF \ -- ptr MAX if MAX U< NFAx
452 DROP DROP \ -- drop ptr and MAX
453 I DUP PAD_ORG + @ \ -- new_ptr new_MAX
456 ?DUP \ -- ptr MAX MAX | -- ptr 0 (all threads in PAD = 0)
457 WHILE \ -- ptr MAX replace it by its LFA
459 2 - @ \ -- ptr MAX [LFA]
460 ROT \ -- MAX [LFA] ptr
461 PAD_ORG + \ -- MAX [LFA] thread
462 ! \ -- MAX [LFA]=new_NFA updates PAD+ptr
464 COUNT $7F AND \ -- MAX addr count (with suppr. of immediate bit)
466 C@ $0F AND \ -- count_of_chars
467 $10 SWAP - SPACES \ -- complete with spaces modulo 16 chars
470 ; \ all threads in PAD are filled with 0
473 [UNDEFINED] CASE [IF]
474 \ https://forth-standard.org/standard/core/CASE
475 : CASE 0 ; IMMEDIATE \ -- #of-1
477 \ https://forth-standard.org/standard/core/OF
478 : OF \ #of-1 -- orgOF #of
480 >R \ move off the stack in case the control-flow stack is the data stack.
481 POSTPONE OVER POSTPONE = \ copy and test case value
482 POSTPONE IF \ add orig to control flow stack
483 POSTPONE DROP \ discards case value if =
484 R> \ we can bring count back now
487 \ https://forth-standard.org/standard/core/ENDOF
488 : ENDOF \ orgOF #of -- orgENDOF #of
489 >R \ move off the stack in case the control-flow stack is the data stack.
491 R> \ we can bring count back now
494 \ https://forth-standard.org/standard/core/ENDCASE
495 : ENDCASE \ orgENDOF1..orgENDOFn #of --
504 CODE S_ \ Squote alias with blank instead quote separator
505 MOV #0,&CAPS \ turn CAPS OFF
507 XSQUOTE , \ compile run-time code
508 'SP' WORD \ -- c-addr (= HERE)
510 MOV.B @TOS,TOS \ -- len compile string
511 ADD #1,TOS \ -- len+1
513 ADDC TOS,&DP \ store aligned DP
515 MOV @RSP+,IP \ pop paired with push COLON
516 MOV #$20,&CAPS \ turn CAPS ON (default state)
524 0= IF MOV @IP+,PC \ interpret time usage disallowed
527 'ESC' \ -- char escape
528 POSTPONE LITERAL \ compile-time code : lit 'ESC'
529 POSTPONE EMIT \ compile-time code : EMIT
530 POSTPONE S_ \ compile-time code : S_ <escape_sequence>
531 POSTPONE TYPE \ compile-time code : TYPE
535 \ -------------------------------------------------------
536 : SPECS \ to see all FastForth specifications
537 \ -------------------------------------------------------
538 PWR_STATE \ before computing free bytes, remove all created words
540 ESC [8;40;80t \ set 40L * 80C terminal display
541 39 0 DO CR LOOP \ to avoid erasing any line of source, create 42-1 empty lines
542 ESC [H \ then cursor home
543 ESC [7m \ Turn reverse video on
544 $0D EMIT ." FastForth V" \ title line in reverse video
546 0 <# # 'BS' HOLD # '.' HOLD #S #> TYPE
548 HERE \ HERE - MAIN_ORG = bytes code
549 DEVICEID @ \ value kept in TLV area
551 \ device_ID OF ." xxxx," $MAIN_ORG ENDOF \ <-- add here your device
552 $8102 OF ." 5738," $C200 ENDOF
553 $8103 OF ." 5739," $C200 ENDOF
554 $8160 OF ." 5948," $4400 ENDOF
555 $8169 OF ." 5969," $4400 ENDOF
556 $825D OF ." 5972," $4400 ENDOF
557 $81A8 OF ." 6989," $4400 ENDOF
558 $810D OF ." 5986," $4400 ENDOF
559 $81F0 OF ." 4133," $C400 ENDOF
560 $8240 OF ." 2433," $C400 ENDOF
561 $82A1 OF ." 5994," $4000 ENDOF
562 $82A6 OF ." 5962," $4000 ENDOF
563 $830C OF ." 2355," $8000 ENDOF
564 $830D OF ." 2353," $C000 ENDOF
565 $831E OF ." 2155," $8000 ENDOF
566 $831D OF ." 2153," $C000 ENDOF
567 $832A OF ." 2476," $8000 ENDOF
568 $832B OF ." 2475," $8000 ENDOF
569 $833C OF ." 2633," $C400 ENDOF
570 $833D OF ." 2533," $C400 ENDOF
571 ABORT" xxxx <-- unrecognized device!"
572 ENDCASE \ -- HERE MAIN_ORG
573 ['] ['] DUP @ $1284 = \ DOCOL = CALL rDOCOL opcode
574 IF ." DTC=1," DROP \ [CFA] = CALL rDOCOL
576 IF ." DTC=2," \ [CFA] = PUSH IP, [CFA+2] = CALL rDOCOL
577 ELSE ." DTC=3," \ [CFA] = PUSH IP, [CFA+2] = MOV PC,IP
581 THREADS @ U. 'BS' EMIT ." -Entry word set, " \ number of Entry word set,
582 FREQ_KHZ @ 0 1000 UM/MOD U. \ frequency,
583 ?DUP IF 'BS' EMIT ',' EMIT U. \ if remainder
584 THEN ." MHz, " \ MCLK
585 - U. ." bytes" \ HERE - MAIN_ORG = number of bytes code,
586 ESC [0m \ Turn off character attributes
588 ." /COUNTED-STRING = 255" CR
591 ." ADDRESS-UNIT-BITS = 16" CR
592 ." FLOORED = true" CR
593 ." MAX-CHAR = 255" CR
596 ." MAX-D = 2147483647" CR
597 ." MAX-UD = 4294967295" CR
598 ." STACK-CELLS = 48" CR
599 ." RETURN-STACK-CELLS= 48" CR
600 ." DeFiNiTiOnS aRe CaSe-InSeNsItIvE" CR
602 ESC [7m ." KERNEL SPECS" ESC [0m \ subtitle in reverse video
605 DUP 0< IF ." 32.768kHz XTAL" CR THEN \ BIT15
606 2* DUP 0< IF ." (RTS/CTS) UART TERMINAL" CR 2* \ BIT14 BIT13
608 0< IF ." (RTS) UART TERMINAL" CR
611 2* DUP 0< IF ." (XON/XOFF) UART TERMINAL" CR \ BIT12
613 2* DUP 0< IF ." Half-Duplex TERMINAL" CR THEN \ BIT11
614 2* DUP 0< IF ." I2C_Master TERMINAL" CR THEN \ BIT10
615 2* DUP 0< IF ." Q15.16 input" CR THEN \ BIT9
616 2* DUP 0< IF ." DOUBLE input" CR THEN \ BIT8
617 2* DUP 0< IF ." MSP430_X assembler" CR 2* 2* \ BIT7 BIT6 BIT5
619 0< IF ." MSP430 Assembler"
620 2* DUP 0< IF ." with 20bits address" \ BIT5
629 2* 0< IF \ BIT0 true if COND. COMPILATION
630 [DEFINED] DEFER [IF] ." DEFER word set" CR [THEN]
631 [DEFINED] ALSO [IF] ." VOCABULARY word set" CR [THEN]
632 [DEFINED] LOAD" [IF] ." SD_CARD Loader" CR [THEN]
633 [DEFINED] BOOT [IF] ." bootloader" CR [THEN]
634 [DEFINED] READ" [IF] ." SD_CARD Read/Write" CR [THEN]
636 ESC [7m ." OPTIONS" ESC [0m \ subtitle in reverse video
638 [DEFINED] {CORE_ANS} [IF] ." ANS94 core" CR [THEN]
639 [DEFINED] {DOUBLE} [IF] ." DOUBLE word set" CR [THEN]
640 [DEFINED] {TOOLS} [IF] ." UTILITY" CR [THEN]
641 [DEFINED] {FIXPOINT} [IF] ." Q15.16 ADD SUB MUL DIV" CR [THEN]
642 [DEFINED] {CORDIC} [IF] ." CORDIC engine" CR [THEN]
643 [DEFINED] {SD_TOOLS} [IF] ." SD_TOOLS" CR [THEN]
644 [DEFINED] {RTC} [IF] ." RTC utility" CR [THEN]
645 [DEFINED] {UARTI2CS} [IF] ." UART to I2C_FastForth bridge" CR [THEN]
649 ESC [7m ." ASSEMBLER word set" ESC [0m \ subtitle in reverse video
650 ALSO ASSEMBLER WORDS PREVIOUS \ type ASSEMBLER word set
655 ESC [7m ." FORTH word set" ESC [0m \ subtitle in reverse video
656 WORDS \ type FORTH word set
659 MOV #WARM_DISPLAY,PC \ type count of bytes free without re-executing INI_APP, no return
662 SPECS \ here FastForth displays a message with some informations