1 \ -*- coding: utf-8 -*-
3 \ to see kernel options, download FastForthSpecs.f
4 \ FastForth kernel options: MSP430ASSEMBLER, CONDCOMP, DOUBLE_INPUT, SD_CARD_LOADER
6 \ TARGET SELECTION ( = the name of \INC\target.pat file without the extension)
7 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
8 \ MSP_EXP430FR4133 CHIPSTICK_FR2433 MSP_EXP430FR2433 MSP_EXP430FR2355
11 \ from scite editor : copy your target selection in (shift+F8) parameter 1:
15 \ drag and drop this file onto SendSourceFileToTarget.bat
16 \ then select your TARGET when asked.
20 \ R4 to R7 must be saved before use and restored after
21 \ scratch registers Y to S are free for use
22 \ under interrupt, IP is free for use
24 \ PUSHM order : PSP,TOS, IP, S, T, W, X, Y, rEXIT,rDOVAR,rDOCON, rDODOES, R3, SR,RSP, PC
25 \ PUSHM order : R15,R14,R13,R12,R11,R10, R9, R8, R7 , R6 , R5 , R4 , R3, R2, R1, R0
27 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
29 \ POPM order : PC,RSP, SR, R3, rDODOES,rDOCON,rDOVAR,rEXIT, Y, X, W, T, S, IP,TOS,PSP
30 \ POPM order : R0, R1, R2, R3, R4 , R5 , R6 , R7 , R8, R9,R10,R11,R12,R13,R14,R15
32 \ example : POPM #6,IP pop Y,X,W,T,S,IP registers from return stack
35 \ FORTH conditionnals: unary{ 0= 0< 0> }, binary{ = < > U< }
37 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE S< S>= U< U>= 0= 0<> 0>=
38 \ ASSEMBLER conditionnal usage with ?JMP ?GOTO S< S>= U< U>= 0= 0<> 0<
40 ; ---------------------------------------------------------------
42 ; BASIC TOOLS for SD Card : DIR FAT SECTOR. CLUSTER.
43 ; ---------------------------------------------------------------
45 \ first, we do some tests allowing the download
56 SUB #400,TOS \ FastForth V4.0
58 'CR' EMIT \ return to column 1 without 'LF'
59 ABORT" FastForth V4.0 please!"
60 ABORT" Build FastForth with SD_CARD_LOADER addon!"
61 RST_RET \ remove ABORT_UARTI2CS definition before resuming
69 [UNDEFINED] {SD_TOOLS}
73 ; ------------------------------------------------------------------
74 ; first we download the set of definitions we need (from CORE_ANS.f)
75 ; ------------------------------------------------------------------
83 \ https://forth-standard.org/standard/core/Plus
84 \ + n1/u1 n2/u2 -- n3/u3 add n1+n2
93 [IF] \ define MAX and MIN
94 CODE MAX \ n1 n2 -- n3 signed maximum
101 CODE MIN \ n1 n2 -- n3 signed minimum
109 \ https://forth-standard.org/standard/core/CFetch
110 \ C@ c-addr -- char fetch char from memory
119 \ https://forth-standard.org/standard/core/SPACE
120 \ SPACE -- output a space
127 \ https://forth-standard.org/standard/core/SPACES
128 \ SPACES n -- output n spaces
144 MOV @PSP+,TOS \ -- drop n
149 \ https://forth-standard.org/standard/core/SWAP
150 \ SWAP x1 x2 -- x2 x1 swap top two items
161 \ https://forth-standard.org/standard/core/OVER
162 \ OVER x1 x2 -- x1 x2 x1
166 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
167 MOV @PSP,TOS \ 2 -- x1 (x2) x1
168 SUB #2,PSP \ 1 -- x1 x2 x1
173 \ https://forth-standard.org/standard/core/toR
174 \ >R x -- R: -- x push to return stack
184 \ https://forth-standard.org/standard/core/Rfrom
185 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
196 \ https://forth-standard.org/standard/core/Minus
197 \ - n1/u1 n2/u2 -- n3/u3 n3 = n1-n2
201 SUB @PSP+,TOS \ 2 -- n2-n1 ( = -n3)
203 ADD #1,TOS \ 1 -- n3 = -(n2-n1) = n1-n2
208 \ https://forth-standard.org/standard/core/DO
209 \ DO -- DOadr L: -- 0
211 [IF] \ define DO LOOP +LOOP
212 HDNCODE XDO \ DO run time
213 MOV #$8000,X \ 2 compute 8000h-limit = "fudge factor"
215 MOV TOS,Y \ 1 loop ctr = index+fudge
216 ADD X,Y \ 1 Y = INDEX
217 PUSHM #2,X \ 4 PUSHM X,Y, i.e. PUSHM LIMIT, INDEX
225 ADD #2,&DP \ make room to compile xdo
226 MOV &DP,TOS \ -- HERE+2
227 MOV #XDO,-2(TOS) \ compile xdo
228 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
230 MOV #0,0(W) \ -- HERE+2 L-- 0
234 \ https://forth-standard.org/standard/core/LOOP
235 \ LOOP DOadr -- L-- an an-1 .. a1 0
236 HDNCODE XLOOP \ LOOP run time
237 ADD #1,0(RSP) \ 4 increment INDEX
238 BW1 BIT #$100,SR \ 2 is overflow bit set?
239 0= IF \ branch if no overflow
243 ADD #4,RSP \ 1 empties RSP
244 ADD #2,IP \ 1 overflow = loop done, skip branch ofs
245 MOV @IP+,PC \ 4 14~ taken or not taken xloop/loop
250 BW2 ADD #4,&DP \ make room to compile two words
252 MOV X,-4(W) \ xloop --> HERE
253 MOV TOS,-2(W) \ DOadr --> HERE+2
254 BEGIN \ resolve all "leave" adr
255 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
256 SUB #2,&LEAVEPTR \ --
257 MOV @TOS,TOS \ -- first LeaveStack value
258 CMP #0,TOS \ -- = value left by DO ?
260 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
266 \ https://forth-standard.org/standard/core/PlusLOOP
267 \ +LOOP adrs -- L-- an an-1 .. a1 0
268 HDNCODE XPLOO \ +LOOP run time
269 ADD TOS,0(RSP) \ 4 increment INDEX by TOS value
270 MOV @PSP+,TOS \ 2 get new TOS, doesn't change flags
276 GOTO BW2 \ goto BW1 LOOP
280 \ https://forth-standard.org/standard/core/I
281 \ I -- n R: sys1 sys2 -- sys1 sys2
282 \ get the innermost loop index
286 SUB #2,PSP \ 1 make room in TOS
288 MOV @RSP,TOS \ 2 index = loopctr - fudge
294 \ https://forth-standard.org/standard/core/CR
295 \ CR -- send CR+LF to the output device
298 \ create a primary defered word, i.e. with its default runtime beginning at the >BODY of the definition
299 CODE CR \ part I : DEFERed definition of CR
300 MOV #NEXT_ADR,PC \ [PFA] = NEXT_ADR
308 ; ------------------------------------------------------------------
309 ; then we download the set of definitions we need (from UTILITY.f)
310 ; ------------------------------------------------------------------
313 [IF] \ defined in {UTILITY}
314 : U.R \ u n -- display u unsigned in n width (n >= 2)
316 R> OVER - 0 MAX SPACES TYPE
320 \ https://forth-standard.org/standard/tools/DUMP
322 [IF] \ defined in {UTILITY}
323 CODE DUMP \ adr n -- dump memory
325 PUSH &BASEADR \ save current base
326 MOV #$10,&BASEADR \ HEX base
327 ADD @PSP,TOS \ -- ORG END
332 DO I 3 U.R LOOP \ -- END ORG
333 DO CR \ generate line
334 I 4 U.R \ generate address
338 I $10 + I \ display 16 chars
339 DO I C@ $7E MIN $20 MAX EMIT LOOP
341 R> BASEADR ! \ restore current base
345 ; --------------------------
346 ; end of definitions we need
347 ; --------------------------
349 \ display content of a sector
350 \ to Display MBR_FirstSector, type : 0. SECTOR.
351 \ --------------------------------\
352 CODE SECTOR. \ sector. -- don't forget to add decimal point to your sector number
353 \ --------------------------------\
354 BW1 MOV TOS,X \ X = SectorH
355 MOV @PSP,W \ W = sectorL
356 CALL #RD_SECT \ W = SectorLO X = SectorHI
358 SPACE <# #S #> TYPE \ ud -- display the double number
359 SD_BUF $200 DUMP CR ; \ then dump the sector
360 \ --------------------------------\
362 \ display first sector of a Cluster
363 \ --------------------------------\
364 CODE CLUSTER. \ cluster. -- don't forget to add decimal point to your cluster number
365 \ --------------------------------\
366 BW2 BIT.B #CD_SD,&SD_CDIN \ test Card Detect: memory card present ?
367 0<> IF \ no: force COLD
370 MOV.B &SecPerClus,W \ SecPerClus(54321) = multiplicator
371 MOV @PSP,X \ X = ClusterL
373 RRA W \ shift one right multiplicator
374 U< WHILE \ carry clear
375 ADD X,X \ (RLA) shift one left MULTIPLICANDlo16
376 ADDC TOS,TOS \ (RLC) shift one left MULTIPLICANDhi8
378 ADD &OrgClusters,X \ add OrgClusters = sector of virtual cluster 0 (word size)
380 ADDC #0,TOS \ don't forget carry
381 GOTO BW1 \ jump to SECTOR
383 \ --------------------------------\
385 \ --------------------------------\
386 CODE FAT \ Display FATsector
387 \ --------------------------------\
390 MOV &OrgFAT1,0(PSP) \
391 MOV #0,TOS \ FATsectorHI = 0
392 GOTO BW1 \ jump to SECTOR
394 \ --------------------------------\
396 \ --------------------------------\
397 CODE DIR \ Display CurrentDir first sector
398 \ --------------------------------\
400 MOV TOS,2(PSP) \ save TOS
401 MOV &DIRclusterL,0(PSP) \
402 MOV &DIRclusterH,TOS \
404 0<> ?GOTO BW2 \ jump to CLUSTER
405 CMP #1,0(PSP) \ cluster 1 ?
406 0<> ?GOTO BW2 \ jump to CLUSTER
407 MOV &OrgRootDir,0(PSP) \ if yes, special case of FAT16 OrgRootDir
408 GOTO BW1 \ jump to SECTOR
410 \ --------------------------------\
414 [THEN] \ endof [UNDEFINED] {SD_TOOLS}