OSDN Git Service

V309 Modified APPEND" in the long run, clusters can become non-contiguous
[fast-forth/master.git] / MSP430-FORTH / lib / DEFER.f
1 \ -*- coding: utf-8 -*-
2
3 ; --------------------
4 ; DEFER.f
5 ; --------------------
6 \
7 \ TARGET SELECTION
8 \ LP_MSP430FR2476
9 \ MSP_EXP430FR5739  MSP_EXP430FR5969    MSP_EXP430FR5994    MSP_EXP430FR6989
10 \ MSP_EXP430FR4133  MSP_EXP430FR2433    CHIPSTICK_FR2433    MSP_EXP430FR2355
11 \\
12 \ from scite editor : copy your target selection in (shift+F8) parameter 1:
13 \
14 \ OR
15 \
16 \ drag and drop this file onto SendSourceFileToTarget.bat
17 \ then select your TARGET when asked.
18 \
19 \ FastForth kernel compilation minimal options:
20 \ TERMINAL3WIRES, TERMINAL4WIRES
21 \ MSP430ASSEMBLER, CONDCOMP
22 \
23 \ to see kernel options, download FastForthSpecs.f
24 \
25 \ REGISTERS USAGE
26 \ R4 to R7 must be saved before use and restored after
27 \ scratch registers Y to S are free for use
28 \ under interrupt, IP is free for use
29 \
30 \ PUSHM order : PSP,TOS, IP,  S,  T,  W,  X,  Y, rEXIT,rDOVAR,rDOCON, rDODOES, R3, SR,RSP, PC
31 \ PUSHM order : R15,R14,R13,R12,R11,R10, R9, R8,  R7  ,  R6  ,  R5  ,   R4   , R3, R2, R1, R0
32 \
33 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
34 \
35 \ POPM  order :  PC,RSP, SR, R3, rDODOES,rDOCON,rDOVAR,rEXIT,  Y,  X,  W,  T,  S, IP,TOS,PSP
36 \ POPM  order :  R0, R1, R2, R3,   R4   ,  R5  ,  R6  ,  R7 , R8, R9,R10,R11,R12,R13,R14,R15
37 \
38 \ example : POPM #6,IP   pop Y,X,W,T,S,IP registers from return stack
39 \
40 \
41 \ FORTH conditionnals:  unary{ 0= 0< 0> }, binary{ = < > U< }
42 \
43 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE  S<  S>=  U<   U>=  0=  0<>  0>=
44 \ ASSEMBLER conditionnal usage with ?JMP ?GOTO      S<  S>=  U<   U>=  0=  0<>  0<
45 \
46
47 PWR_STATE
48
49 [UNDEFINED] @ [IF]
50 \ https://forth-standard.org/standard/core/Fetch
51 \ @     c-addr -- char   fetch char from memory
52 CODE @
53 MOV @TOS,TOS
54 MOV @IP+,PC
55 ENDCODE
56 [THEN]
57
58 [UNDEFINED] IF [IF]     \ define IF and THEN
59 \ https://forth-standard.org/standard/core/IF
60 \ IF       -- IFadr    initialize conditional forward branch
61 CODE IF       \ immediate
62 SUB #2,PSP              \
63 MOV TOS,0(PSP)          \
64 MOV &DP,TOS             \ -- HERE
65 ADD #4,&DP            \           compile one word, reserve one word
66 MOV #QFBRAN,0(TOS)      \ -- HERE   compile QFBRAN
67 ADD #2,TOS              \ -- HERE+2=IFadr
68 MOV @IP+,PC
69 ENDCODE IMMEDIATE
70
71 \ https://forth-standard.org/standard/core/THEN
72 \ THEN     IFadr --                resolve forward branch
73 CODE THEN               \ immediate
74 MOV &DP,0(TOS)          \ -- IFadr
75 MOV @PSP+,TOS           \ --
76 MOV @IP+,PC
77 ENDCODE IMMEDIATE
78 [THEN]
79
80 [UNDEFINED] ELSE [IF]
81 \ https://forth-standard.org/standard/core/ELSE
82 \ ELSE     IFadr -- ELSEadr        resolve forward IF branch, leave ELSEadr on stack
83 CODE ELSE     \ immediate
84 ADD #4,&DP              \ make room to compile two words
85 MOV &DP,W               \ W=HERE+4
86 MOV #BRAN,-4(W)
87 MOV W,0(TOS)            \ HERE+4 ==> [IFadr]
88 SUB #2,W                \ HERE+2
89 MOV W,TOS               \ -- ELSEadr
90 MOV @IP+,PC
91 ENDCODE IMMEDIATE
92 [THEN]
93
94 [UNDEFINED] DEFER [IF]
95 \ https://forth-standard.org/standard/core/DEFER
96 \ DEFER "<spaces>name"   --
97 \ Skip leading space delimiters. Parse name delimited by a space.
98 \ Create a definition for name with the execution semantics defined below.
99
100 \ name Execution:   --
101 \ Execute the xt that name is set to execute, i.e. NEXT (nothing),
102 \ until the phrase ' word IS name is executed, causing a new value of xt to be assigned to name.
103 : DEFER
104 CREATE
105 HI2LO
106 MOV #$4030,-4(W)        \ CFA = MOV @PC+,PC = BR MOV @IP+,PC
107 MOV #BR@IP+_ADR,-2(W)   \ PFA = address of MOV @IP+,PC to do nothing.
108 MOV @RSP+,IP
109 MOV @IP+,PC
110 ENDCODE
111 [THEN]
112
113 [UNDEFINED] DEFER! [IF] 
114 \ https://forth-standard.org/standard/core/DEFERStore
115 \ Set the word xt1 to execute xt2. An ambiguous condition exists if xt1 is not for a word defined by DEFER.
116 CODE DEFER!             \ xt2 xt1 --
117 MOV @PSP+,2(TOS)        \ -- xt1=CFA_DEFER          xt2 --> [CFA_DEFER+2]
118 MOV @PSP+,TOS           \ --
119 MOV @IP+,PC
120 ENDCODE
121 [THEN]
122
123 [UNDEFINED] IS [IF]
124 \ https://forth-standard.org/standard/core/IS
125 \ IS <name>        xt --
126 \ used as is :
127 \ DEFER DISPLAY                         create a "do nothing" definition (2 CELLS)
128 \ inline command : ' U. IS DISPLAY      U. becomes the runtime of the word DISPLAY
129 \ or in a definition : ... ['] U. IS DISPLAY ...
130 \ KEY, EMIT, CR, ACCEPT and WARM are examples of DEFERred words
131 \
132 \ as IS replaces the PFA value of any word, it's a TO alias for VARIABLE and CONSTANT words...
133 : IS
134 STATEADR @
135 IF  POSTPONE ['] POSTPONE DEFER! 
136 ELSE ' DEFER! 
137 THEN
138 ; IMMEDIATE
139 [THEN]
140
141 PWR_HERE