3 .cpu MSP430X ; define CPU
5 ; ----------------------------------------------
6 ; MACROS FOR assembly instructions
7 ; ----------------------------------------------
9 NOP .macro ; 1 word, 1 cycle
10 .word 4303h ; mov #0, r3
13 NOP2 .macro ; 1 Word, 2 cycles
17 NOP3 .macro ; 1 Word, 3 cycles
18 .word 4000h ; MOV PC,PC
21 ; SR bits : only SR(11:0) are PUSHed by calls and interrupts
27 CPUOFF .equ 0010h ; CPU Off. 1=turn_off_CPU
28 OSCOFF .equ 0020h ; Oscillator Off. 1=turn_off_LFXT1CLK
29 SCG0 .equ 0040h ; System Clock Generator 0. 1=turn_off_DCO
30 SCG1 .equ 0080h ; System Clock Generator 1. 1=turn_off_SMCLK
31 UF9 .equ 0200h ; = SR(9) User Flag 1
32 UF10 .equ 0400h ; = SR(10) User Flag 2
33 UF11 .equ 0800h ; = SR(11) User Flag 3
35 ;----------------------------------------------------------------------------
37 LPM1 .equ SCG0 + CPUOFF ; for devices with FLL: LPM1 = LPM0 + FLL disabled
38 LPM2 .equ SCG1 + CPUOFF
39 LPM3 .equ SCG1 + SCG0 + CPUOFF
40 LPM4 .equ SCG1 + SCG0 + OSCOFF + CPUOFF
42 ;-------------------------------------------------------------------------------
43 ; DEFINING FORTH REGISTERS - DTC model
44 ;-------------------------------------------------------------------------------
45 RSP .reg R1 ; RSP = Return Stack Pointer (return stack)
48 ; DOxxx registers ; must be saved before use and restored after use
50 rDODOES .reg r5 ; to restore: MOV #XDODOES,rDODOES
51 rDOCON .reg r6 ; to restore: MOV #XDOCON,rDOCON
52 rDOVAR .reg r7 ; to restore: MOV #R>,rDOVAR
54 R .reg r4 ; rDOCOL alias
55 Q .reg r5 ; rDODOES alias
56 P .reg r6 ; rDOCON alias
57 M .reg R7 ; rDOVAR alias
64 ; Forth virtual machine
65 IP .reg R13 ; interpretative pointer
66 TOS .reg R14 ; first PSP cell
67 PSP .reg R15 ; PSP = Parameters Stack Pointer (stack data)
71 ; ----------------------------------------------
72 ; EXECUTIVE WORDS FOR Direct-Threaded Code (DTC)
73 ; ----------------------------------------------
75 ;-------------------------------------------------------------------------------
76 ; DODOES leave on parameter stack the PFA of a CREATE definition and execute Master word
77 ;-------------------------------------------------------------------------------
78 DODOES .equ 1285h ; CALL rDODOES ; [rDODOES] is defined as xdodoes by COLD
80 ;-------------------------------------------------------------------------------
81 ; DOCON leave on parameter stack the [PFA] of a CONSTANT definition
82 ;-------------------------------------------------------------------------------
83 DOCON .equ 1286h ; 4 CALL rDOCON ; [rDOCON] is defined as xdocon by COLD
85 ;-------------------------------------------------------------------------------
86 ; DOVAR leave on parameter stack the PFA of a VARIABLE definition
87 ;-------------------------------------------------------------------------------
88 DOVAR .equ 1287h ; 4 for CALL rDOVAR S-- VAR PFA R--
89 ; [rDOVAR] is defined as RFROM by COLD
90 ;-------------------------------------------------------------------------------
91 ; DOCOL starts high level words
92 ;-------------------------------------------------------------------------------
93 ; very nice FAST FORTH feature:
94 ; as IP is always computed from the PC value, we can place low to high level
95 ; "ASMtoFORTH" or "mDOCOL" switches anywhere in a word, i.e. not only at its
96 ; beginning as ITC competitors.
97 ;-------------------------------------------------------------------------------
100 .CASE 1 ; DOCOL = CALL rDOCOL, [rDOCOL] = xdocol
102 DOCOL1 .equ 1284h ; 4 CALL rDOCOL
104 ASMtoFORTH .MACRO ; compiled by LO2HI
105 CALL #EXIT ; 10 cycles
106 .ENDM ; 2 words, 10 cycles
107 ; LO2HI + HI2LO = 3 words, 10 cycles.
109 mDOCOL .MACRO ; compiled by : and by colon
110 CALL rDOCOL ; 10 [rDOCOL] = xdocol
111 .ENDM ; 1 word, 14 cycles (CALL included) (ITC+4)
112 ; COLON + SEMI = 2 words, 20 cycles (ITC+2)
114 .CASE 2 ; DOCOL = PUSH IP + CALL rDOCOL, [rDOCOL] = EXIT
116 DOCOL1 .equ 120Dh ; 3 PUSH IP
117 DOCOL2 .equ 1284h ; 4 CALL rDOCOL
119 ASMtoFORTH .MACRO ; compiled by LO2HI
120 CALL rDOCOL ; 10 [rDOCOL] = EXIT
121 .ENDM ; 1 word, 10 cycles.
122 ; LO2HI + HI2LO = 2 words, 10 cycles.
124 mDOCOL .MACRO ; compiled by : and by COLON
126 CALL rDOCOL ; 10 [rDOCOL] = EXIT
127 .ENDM ; 2 words, 13 cycles (ITC+3)
128 ; COLON + SEMI = 3 words, 19 cycles (ITC+1)
130 .CASE 3 ; inlined DOCOL
132 DOCOL1 .equ 120Dh ; 3 PUSH IP
133 DOCOL2 .equ 400Dh ; 1 MOV PC,IP
134 DOCOL3 .equ 522Dh ; 1 ADD #4,IP
136 ASMtoFORTH .MACRO ; compiled by LO2HI
140 .ENDM ; 6 cycles, 3 words
141 ; LO2HI + HI2LO = 4 words, 6 cycles.
143 mDOCOL .MACRO ; compiled by : and by COLON
148 .ENDM ; 4 words, 9 cycles (ITC-1)
149 ; COLON + SEMI = 5 words, 15 cycles (ITC-3)
153 NEXT .equ 4D30h ; 4 MOV @IP+,PC
154 ; jump from Asm word to NEXT Asm word: 1 word, 4 cycles (ITC-2)
156 ; ----------------------------------------------
157 ; INIT VOCABULARY POINTERS and MACROS FOR HEADER
158 ; ----------------------------------------------
159 voclink .set 0 ; init vocabulary links
168 FORTHWORD .MACRO name
171 .byte STRLEN(name),name
175 FORTHWORDIMM .MACRO name
178 .byte STRLEN(name)+128,name
185 .byte STRLEN(name),name
254 ;-------------------------------------------
255 ; (THREADS-1)*2 = AND mask to define CURRENT offset in vocabulary
256 ;-------------------------------------------
257 FORTHWORD .MACRO name
258 CONTEXTofst .set charfromstr(name,0) & ((THREADS-1)*2)
357 .byte STRLEN(name),name
360 ;-------------------------------------------
361 ; (THREADS-1)*2 = AND mask to define CURRENT offset in vocabulary
362 ;-------------------------------------------
363 FORTHWORDIMM .MACRO name
364 CONTEXTofst .set charfromstr(name,0) & ((THREADS-1)*2)
463 .byte 80h+STRLEN(name),name
466 ;-------------------------------------------
467 ; (THREADS-1)*2 = AND mask to define CURRENT offset in vocabulary
468 ;-------------------------------------------
470 CONTEXTofst .set charfromstr(name,0) & ((THREADS-1)*2)
569 .byte STRLEN(name),name
576 ; --------------------------
577 ; COMPUTE BAUDRATE registers = fn(FREQUENCY,BAUDS)
578 ; --------------------------
579 .include "TERMINALBAUDRATE.inc"
582 ; -------------------------------------
583 ; define MAIN max bound
584 ; -------------------------------------
585 FRAM_FULL .equ SIGNATURES-40h ; set to protect JTAG and BSL signatures against overwrite.
586 ; 64 bytes are sufficient considering what can be compiled in one line + WORD use.
587 ; take care with ALLOT : don't ALLOT more than 32 words by line!
589 ;-----------------------------------------------------------------------
590 ; DEVICE I/O, MEMORY, SFR, vectors and minimum FORTH I/O declarations
591 ;-----------------------------------------------------------------------
592 .IFDEF MSP_EXP430FR5739
600 .include "MSP430FR5739.inc"
602 .IFDEF MSP_EXP430FR5969
610 .include "MSP430FR5969.inc"
612 .IFDEF MSP_EXP430FR5994
620 .include "MSP430FR5994.inc"
622 .IFDEF MSP_EXP430FR6989
630 .INCLUDE "MSP430FR6989.inc"
632 .IFDEF MSP_EXP430FR4133
640 .INCLUDE "MSP430FR4133.inc"
642 .IFDEF MSP_EXP430FR2433
650 .include "MSP430FR2433.inc"
652 .IFDEF CHIPSTICK_FR2433
653 ; no LF_XTAL to select ACLK = REFOCLK
661 .include "MSP430FR2433.inc"
663 .IFDEF MSP_EXP430FR2355
671 .include "MSP430FR2355.inc"
673 .IFDEF LP_MSP430FR2476
674 ; LF_XTAL ; connect resistors R2=0k, R3=0k before uncomment this line
681 .include "MSP430FR2476.inc"
685 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
686 ; add here your device.inc item:
687 ; .IFDEF MY_MSP430FR5738_1
688 ; UCA0_UART ; defines uart used by FORTH input terminal
689 ; LF_XTAL ; defines if your module have a 32768 Hz xtal, to enable it.
690 ; UCB0_SD ; defines UC used for SD Card driver if used
691 ; .include "MSP430FR5738.inc" ; include device declarations
693 ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
695 ; --------------------------
697 ; --------------------------
699 .IFDEF CORE_COMPLEMENT
711 .IFDEF FIXPOINT_INPUT
717 ; define if QUIT is DEFERed
718 .IFDEF SD_CARD_LOADER
728 CONDCOMP ; mandatory for Bootstrap
742 .IFNDEF MSP430ASSEMBLER
752 .IFNDEF FIXPOINT_INPUT
753 FIXPOINT_INPUT ; to interpret fixpoint numbers
757 .IFDEF FIXPOINT_INPUT
758 .IFNDEF DOUBLE_NUMBERS
759 DOUBLE_NUMBERS ; to process double numbers
764 .IFNDEF DOUBLE_NUMBERS
765 DOUBLE_NUMBERS ; to process double numbers
770 ; ---------------------------
771 ; compute value of FORTHADDON
772 ; ---------------------------
775 FADDON .SET FADDON | 01h ; Conditionnal Compilation
777 .IFDEF MSP430ASSEMBLER
778 FADDON .SET FADDON | 02h ; MSP430 Assembler (16 bits addresses)
780 .IFDEF EXTENDED_ASM ; MSP430X Assembler (16+20 bits addresses)
781 FADDON .SET FADDON | 04h
784 FADDON .SET FADDON | 08h ; DEFERRED, adds DEFER IS :NONAME CODENNM
786 .IFDEF VOCABULARY_SET
787 FADDON .SET FADDON | 10h ; VOCABULERY SET, adds VOCABULARY FORTH ASSEMBLER ALSO PREVIOUS ONLY DEFINITIONS (FORTH83)
790 FADDON .SET FADDON | 20h ; DOUBLE INPUT
792 .IFDEF FIXPOINT_INPUT
793 FADDON .SET FADDON | 40h ; FIXPOINT INPUT
795 .IFDEF SD_CARD_LOADER
796 FADDON .SET FADDON | 80h ; SD_CARD Loader
798 .IFDEF SD_CARD_READ_WRITE
799 FADDON .SET FADDON | 100h ; SD_CARD Read Write Delete
802 FADDON .SET FADDON | 200h ; BOOTLOADER
806 FADDON .SET FADDON | 400h ; MSP430 Assembler with Address access beyond $FFFF
809 .IFNDEF TERMINAL_I2C ; if TERMINAL UART...
811 FADDON .SET FADDON | 800h ; UART Half Duplex
813 .IFDEF TERMINAL3WIRES
814 FADDON .SET FADDON | 1000h ; UART XON/XOFF
816 .IFDEF TERMINAL4WIRES
817 FADDON .SET FADDON | 2000h ; UART RTS
819 .IFDEF TERMINAL5WIRES
820 FADDON .SET FADDON | 4000h ; UART CTS
822 .ENDIF ; TERMINAL UART
824 FADDON .SET FADDON | 8000h ; LFXTAL = 32768 Hz