1 ; ------------------------------------------------------------------------
2 ; BASIC TOOLS for SD Card : {DIR FAT SECTOR CLUSER} DUMP ; include UTILITY
3 ; ------------------------------------------------------------------------
5 \ Fast Forth For Texas Instrument MSP430FRxxxx FRAM devices
6 \ Copyright (C) <2017> <J.M. THOORENS>
8 \ This program is free software: you can redistribute it and/or modify
9 \ it under the terms of the GNU General Public License as published by
10 \ the Free Software Foundation, either version 3 of the License, or
11 \ (at your option) any later version.
13 \ This program is distributed in the hope that it will be useful,
14 \ but WITHOUT ANY WARRANTY; without even the implied warranty of
15 \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 \ GNU General Public License for more details.
18 \ You should have received a copy of the GNU General Public License
19 \ along with this program. If not, see <http://www.gnu.org/licenses/>.
22 \ R4 to R7 must be saved before use and restored after
23 \ scratch registers Y to S are free for use
24 \ under interrupt, IP is free for use
26 \ PUSHM order : PSP,TOS, IP, S, T, W, X, Y, R7, R6, R5, R4
27 \ example : PUSHM IP,Y
29 \ POPM order : R4, R5, R6, R7, Y, X, W, T, S, IP,TOS,PSP
32 \ ASSEMBLER conditionnal usage after IF UNTIL WHILE : S< S>= U< U>= 0= 0<> 0>=
33 \ ASSEMBLER conditionnal usage before GOTO ?GOTO : S< S>= U< U>= 0= 0<> <0
35 \ FORTH conditionnal usage after IF UNTIL WHILE : 0= 0< = < > U<
40 \ ECHO ; if an error occurs, uncomment this line before new download to find it.
44 CODE ? \ adr -- display the content of adr
57 : .S \ -- print <number> of cells and stack contents if not empty
58 $3C EMIT \ -- char "<"
61 $3E EMIT SPACE \ char ">"
62 SP@ PSTACK OVER OVER U< \
72 : WORDS \ -- list all words in all dicts in CONTEXT.
74 \ vvvvvvvv may be skipped vvvvvvvv
79 1 = IF DROP ." monothread"
83 \ ^^^^^^^^ may be skipped ^^^^^^^^
86 BEGIN \ search dictionnary
88 2 + SWAP \ -- CONTEXT+2 CONTEXT
89 @ ?DUP \ -- CONTEXT+2 (VOC_BODY VOC_BODY or 0)
90 WHILE \ -- CONTEXT+2 VOC_BODY dictionnary found
92 \ MOVE all threads of VOC_BODY in PAD
93 DUP PAD INI_THREAD @ DUP + \ -- CONTEXT+2 VOC_BODY VOC_BODY PAD THREAD*2
96 BEGIN \ -- CONTEXT+2 VOC_BODY
97 0 DUP \ -- CONTEXT+2 VOC_BODY ptr MAX
98 \ select the MAX of NFA in threads
99 INI_THREAD @ DUP + 0 DO \ ptr = threads*2
100 DUP I PAD + @ \ -- CONTEXT+2 VOC_BODY ptr MAX MAX NFAx
102 DROP DROP I DUP PAD + @ \ -- CONTEXT+2 VOC_BODY ptr MAX if MAX U< NFAx replace adr and MAX
104 2 +LOOP \ -- CONTEXT+2 VOC_BODY ptr MAX
105 ?DUP \ -- CONTEXT+2 VOC_BODY ptr MAX max NFA = 0 ? end of vocabulary ?
106 WHILE \ -- CONTEXT+2 VOC_BODY ptr MAX
107 \ replace it by its LFA
108 DUP \ -- CONTEXT+2 VOC_BODY ptr MAX MAX
109 2 - @ \ -- CONTEXT+2 VOC_BODY ptr MAX [LFA]
110 ROT \ -- CONTEXT+2 VOC_BODY MAX [LFA] ptr
111 PAD + \ -- CONTEXT+2 VOC_BODY MAX [LFA] thread
112 ! \ -- CONTEXT+2 VOC_BODY MAX
113 \ type it in 16 chars format
114 DUP \ -- CONTEXT+2 VOC_BODY MAX MAX
115 COUNT $7F AND TYPE \ -- CONTEXT+2 VOC_BODY MAX
117 $10 SWAP - SPACES \ -- CONTEXT+2 VOC_BODY
118 \ search next MAX of NFA
120 \ -- CONTEXT+2 VOC_BODY 0
121 DROP DROP \ -- CONTEXT+2
123 \ repeat for each CONTEXT vocabulary
130 CODE MAX \ n1 n2 -- n3 signed maximum
138 CODE MIN \ n1 n2 -- n3 signed minimum
146 : U.R \ u n -- display u unsigned in n width (n >= 2)
148 R> OVER - 0 MAX SPACES TYPE
152 : DUMP \ adr n -- dump memory
156 DO CR \ generate line
157 I 7 U.R SPACE \ generate address
158 I $10 + I \ display 16 bytes
161 I $10 + I \ display 16 chars
162 DO I C@ $7E MIN BL MAX EMIT LOOP
168 \ display content of a sector
169 \ ----------------------------------\
170 CODE SECT_D \ sector. -- don't forget to add decimal point to your sector number
171 \ ----------------------------------\
172 MOV TOS,X \ X = SectorH
173 MOV @PSP,W \ W = sectorL
174 CALL &ReadSectorWX \ W = SectorLO X = SectorHI
176 UD. \ display the sector number
177 BUFFER $200 DUMP CR ; \ then dump the sector
178 \ ----------------------------------\
181 \ ----------------------------------\
182 CODE FAT_D \ Display CurFATsector
183 \ ----------------------------------\
186 MOV &CurFATsector,0(PSP) \ FATsectorLO
187 ADD &OrgFAT1,0(PSP) \
188 MOV #0,TOS \ FATsectorHI = 0
189 JMP SECT_D \ jump to a defined word
191 \ ----------------------------------\
194 \ display first sector of a Cluster
195 \ ----------------------------------\
196 CODE CLUST_D \ cluster. -- don't forget to add decimal point to your cluster number
197 \ ----------------------------------\
198 MOV.B &SecPerClus,W \ 3 SecPerClus(5-1) = multiplicator
201 U< IF \ case of SecPerClus>1
203 ADD X,X \ 5 (RLA) shift one left MULTIPLICANDlo16
204 ADDC TOS,TOS \ 1 (RLC) shift one left MULTIPLICANDhi8
205 RRA W \ 1 shift one right multiplicator
208 ADD &OrgClusters,X \ add OrgClusters = sector of virtual cluster 0 (word size)
210 ADDC #0,TOS \ don't forget carry
211 JMP SECT_D \ jump to a defined word
213 \ ----------------------------------\
216 \ ----------------------------------\
217 CODE DIR_D \ Display CurrentDir first sector
218 \ ----------------------------------\
220 MOV TOS,2(PSP) \ save TOS
221 MOV &DIRclusterL,0(PSP) \
222 MOV &DIRclusterH,TOS \
225 \ ----------------------------------\
229 ; added : UTILITY : ? SP@ .S WORDS MAX MIN U.R DUMP
230 ; added : FAT_D to DUMP first sector of FAT1 and DIR_D for that of current DIRectory.
231 ; added : SECT_D to DUMP a sector and CLUST_D for first sector of a cluster
232 ; include a decimal point to force 32 bits number, example : 2. CLUST_D
234 PWR_HERE ; to protect this app against a RESET, type: RST_HERE