-; ------------------------------------------------------------------------------
-; ANS_COMP.f words complement to pass CORETEST.4th
-; ------------------------------------------------------------------------------
-\ TARGET SELECTION (used by preprocessor GEMA to load \config\gema\TARGET.pat)
+; -----------------------------------------------------
+; ANS_COMP.f words complement to pass CORETEST.4th
+; -----------------------------------------------------
+\
+\ to see kernel options, download FastForthSpecs.f
+\ FastForth kernel options: MSP430ASSEMBLER, CONDCOMP
+\
+\ TARGET Current Selection
+\ (used by preprocessor GEMA to load the pattern: \config\gema\TARGET.pat)
\ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
\ MSP_EXP430FR2433 MSP_EXP430FR4133 MSP_EXP430FR2355 CHIPSTICK_FR2433
-\ MY_MSP430FR5738_1 MY_MSP430FR5738 MY_MSP430FR5948 MY_MSP430FR5948_1
-\ JMJ_BOX
-
+\
\ REGISTERS USAGE
\ rDODOES to rEXIT must be saved before use and restored after
\ scratch registers Y to S are free for use
\ under interrupt, IP is free for use
-
+\
\ PUSHM order : PSP,TOS, IP, S, T, W, X, Y, rEXIT, rDOVAR, rDOCON, rDODOES
\ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
\
\ POPM order : rDODOES, rDOCON, rDOVAR, rEXIT, Y, X, W, T, S, IP,TOS,PSP
\ example : POPM #6,IP pulls Y,X,W,T,S,IP registers from return stack
-
+\
\ FORTH conditionnals: unary{ 0= 0< 0> }, binary{ = < > U< }
-
+\
\ ASSEMBLER conditionnal usage with IF UNTIL WHILE S< S>= U< U>= 0= 0<> 0>=
+\ ASSEMBLER conditionnal usage with ?JMP ?GOTO S< S>= U< U>= 0= 0<> 0<
-\ ASSEMBLER conditionnal usage with ?JMP ?GOTO S< S>= U< U>= 0= 0<> <0
-
- \
PWR_STATE
- \
-[DEFINED] {ANS_COMP} [IF] {ANS_COMP} [THEN] \ remove {ANS_COMP} if outside core
- \
-[UNDEFINED] ASM [IF]
-ECHO
-ASM \ assembler is required!
-[THEN]
- \
-[UNDEFINED] {ANS_COMP} [IF]
+
+: DEFINED! ECHO 1 ABORT" already loaded!" ;
+
+[DEFINED] {ANS_COMP} [IF] DEFINED!
+
+[ELSE]
MARKER {ANS_COMP}
- \
+[UNDEFINED] AND [IF]
\ https://forth-standard.org/standard/core/AND
\ C AND x1 x2 -- x3 logical AND
CODE AND
AND @PSP+,TOS
MOV @IP+,PC
ENDCODE
- \
+[THEN]
+[UNDEFINED] OR [IF]
\ https://forth-standard.org/standard/core/OR
\ C OR x1 x2 -- x3 logical OR
CODE OR
BIS @PSP+,TOS
MOV @IP+,PC
ENDCODE
- \
+[THEN]
+[UNDEFINED] XOR [IF]
\ https://forth-standard.org/standard/core/XOR
\ C XOR x1 x2 -- x3 logical XOR
CODE XOR
XOR @PSP+,TOS
MOV @IP+,PC
ENDCODE
- \
+[THEN]
\ https://forth-standard.org/standard/core/INVERT
\ INVERT x1 -- x2 bitwise inversion
XOR #-1,TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/LSHIFT
\ LSHIFT x1 u -- x2 logical L shift u places
THEN MOV W,TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/RSHIFT
\ RSHIFT x1 u -- x2 logical R7 shift u places
THEN MOV W,TOS
MOV @IP+,PC
ENDCODE
- \
[UNDEFINED] MAX [IF]
\ https://forth-standard.org/standard/core/MAX
BW1 ADD #2,PSP
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/MIN
\ MIN n1 n2 -- n3 signed minimum
MOV @IP+,PC
ENDCODE
[THEN]
- \
\ https://forth-standard.org/standard/core/TwoTimes
\ 2* x1 -- x2 arithmetic left shift
CODE 2*
-ADD TOS,TOS
-MOV @IP+,PC
+ADD TOS,TOS
+MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/TwoDiv
\ 2/ x1 -- x2 arithmetic right shift
RRA TOS
MOV @IP+,PC
ENDCODE
- \
\ --------------------
\ ARITHMETIC OPERATORS
\ --------------------
-
$1A04 C@ $EF > [IF] ; test tag value MSP430FR413x subfamily without hardware_MPY
- \
+
\ https://forth-standard.org/standard/core/MTimes
\ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
-CODE M*
+CODE M*
MOV @PSP,S \ S= n1
CMP #0,S \ n1 > -1 ?
S< IF
XOR #-1,TOS \ n2 --> u2
ADD #1,TOS \
THEN
-\ PUSHM IP,S \ UMSTAR use S,T,W,X,Y
PUSHM #2,IP \ UMSTAR use S,T,W,X,Y
LO2HI \ -- ud1 u2
UM*
THEN
MOV @IP+,PC
ENDCODE
- \
+
[ELSE] ; MSP430FRxxxx with hardware_MPY
- \
+
\ https://forth-standard.org/standard/core/UMTimes
\ UM* u1 u2 -- udlo udhi unsigned 16x16->32 mult.
CODE UM*
MOV &RES1,TOS \ high result in TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/MTimes
\ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
MOV @PSP,&MPYS \ Load 1st operand for signed multiplication
GOTO BW1
ENDCODE
- \
-[THEN]
- \
-HERE
+[THEN]
\ https://forth-standard.org/standard/core/SMDivREM
\ SM/REM d1lo d1hi n2 -- r3 q4 symmetric signed div
ADD #1,2(PSP) \ d1lo+1
ADDC #0,0(PSP) \ d1hi+C
THEN \ -- uDVDlo uDVDhi uDIVlo
-\ PUSHM IP,T \ save IP,S,T
PUSHM #3,IP \ save IP,S,T
LO2HI
UM/MOD \ -- uREMlo uQUOTlo
HI2LO
-\ POPM T,IP \ restore T,S,IP
POPM #3,IP \ restore T,S,IP
CMP #0,T \ T=rem_sign
S< IF
THEN \ -- n3 n4 S=divisor
MOV @IP+,PC
ENDCODE
- \
-
-HERE OVER - DUMP
\ https://forth-standard.org/standard/core/NEGATE
\ C NEGATE x1 -- x2 two's complement
CODE NEGATE
GOTO BW1
ENDCODE
- \
\ https://forth-standard.org/standard/core/ABS
\ C ABS n1 -- +n2 absolute value
0< ?GOTO BW2
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/FMDivMOD
\ FM/MOD d1 n1 -- r q floored signed div'n
MOV @RSP+,IP
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/Times
\ * n1 n2 -- n3 signed multiply
: *
M* DROP
;
- \
\ https://forth-standard.org/standard/core/DivMOD
\ /MOD n1 n2 -- r3 q4 signed division
: /MOD
>R DUP 0< R> FM/MOD
;
- \
\ https://forth-standard.org/standard/core/Div
\ / n1 n2 -- n3 signed quotient
: /
>R DUP 0< R> FM/MOD NIP
;
- \
\ https://forth-standard.org/standard/core/MOD
\ MOD n1 n2 -- n3 signed remainder
: MOD
>R DUP 0< R> FM/MOD DROP
;
- \
\ https://forth-standard.org/standard/core/TimesDivMOD
\ */MOD n1 n2 n3 -- r4 q5 signed mult/div
: */MOD
>R M* R> FM/MOD
;
- \
\ https://forth-standard.org/standard/core/TimesDiv
\ */ n1 n2 n3 -- n4 n1*n2/q3
: */
>R M* R> FM/MOD NIP
;
- \
\ ----------------------------------------------------------------------
\ DOUBLE OPERATORS
: S>D
DUP 0<
;
- \
\ https://forth-standard.org/standard/core/TwoFetch
\ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
CODE 2@
-SUB #2, PSP
+SUB #2,PSP
MOV 2(TOS),0(PSP)
MOV @TOS,TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/TwoStore
\ 2! x1 x2 a-addr -- store 2 cells ; the top of stack is stored at the lower adr
MOV @PSP+,TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/TwoDUP
\ 2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x2
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/TwoDROP
\ 2DROP x1 x2 -- drop 2 cells
MOV @PSP+,TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/TwoSWAP
\ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
MOV W,2(PSP) \ -- x3 x4 x1 x2
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/TwoOVER
\ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
MOV @IP+,PC
ENDCODE
- \
\ ----------------------------------------------------------------------
\ ALIGNMENT OPERATORS
\ ----------------------------------------------------------------------
-
\ https://forth-standard.org/standard/core/ALIGNED
\ ALIGNED addr -- a-addr align given addr
CODE ALIGNED
ADDC #0,TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/ALIGN
\ ALIGN -- align HERE
ADDC #0,&DP \ 4
MOV @IP+,PC
ENDCODE
- \
\ ---------------------
\ PORTABILITY OPERATORS
\ ---------------------
-
\ https://forth-standard.org/standard/core/CHARS
\ CHARS n1 -- n2 chars->adrs units
CODE CHARS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/CHARPlus
\ CHAR+ c-addr1 -- c-addr2 add char size
ADD #1,TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/CELLS
\ CELLS n1 -- n2 cells->adrs units
ADD TOS,TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/CELLPlus
\ CELL+ a-addr1 -- a-addr2 add cell size
ADD #2,TOS
MOV @IP+,PC
ENDCODE
- \
+
\ ---------------------------
\ BLOCK AND STRING COMPLEMENT
\ ---------------------------
-
\ https://forth-standard.org/standard/core/CHAR
\ CHAR -- char parse ASCII character
: CHAR
CHAR lit lit , ,
; IMMEDIATE
- \
-
\ https://forth-standard.org/standard/core/PlusStore
\ +! n/u a-addr -- add n/u to memory
CODE +!
MOV @PSP+,TOS
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/FILL
\ FILL c-addr u char -- fill memory with char
MOV @PSP+,TOS \ empties stack
MOV @IP+,PC
ENDCODE
- \
\ --------------------
\ INTERPRET COMPLEMENT
\ --------------------
-
\ https://forth-standard.org/standard/core/HEX
CODE HEX
MOV #$10,&BASE
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/DECIMAL
CODE DECIMAL
MOV #$0A,&BASE
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/p
\ ( -- skip input until char ) or EOL
: (
$29 WORD DROP
; IMMEDIATE
- \
-[DEFINED] CAPS_ON [IF]
- \
\ https://forth-standard.org/standard/core/Dotp
\ .( -- type comment immediatly.
-: .(
-CAPS_OFF
+CODE .( \ "
+MOV #0,&CAPS \ CAPS OFF
+COLON
$29 WORD
COUNT TYPE
-CAPS_ON
+BL CAPS ! \ CAPS ON
; IMMEDIATE
- \
-[ELSE]
-\ https://forth-standard.org/standard/core/Dotp
-\ .( -- type comment immediatly.
-: .(
-$29 WORD
-COUNT TYPE
-; IMMEDIATE
- \
-[THEN]
- \
\ https://forth-standard.org/standard/core/SOURCE
\ SOURCE -- adr u of current input buffer
SUB #4,PSP
MOV TOS,2(PSP)
MOV &SOURCE_LEN,TOS
-MOV &SOURCE_ADR,0(PSP)
+MOV &SOURCE_ORG,0(PSP)
MOV @IP+,PC
ENDCODE
- \
\ https://forth-standard.org/standard/core/toIN
\ C >IN -- a-addr holds offset in input stream
TOIN CONSTANT >IN
- \
[UNDEFINED] PAD [IF]
[THEN]
- \
RST_HERE
-[THEN]
- \
+[THEN]
+ECHO