OSDN Git Service

V300 beautified
[fast-forth/master.git] / MSP430-FORTH / SD_TOOLS.f
1
2 ; ---------------------------------------------------------------
3 ; SD_TOOLS.f : BASIC TOOLS for SD Card : DIR FAT SECTOR CLUSTER
4 ; ---------------------------------------------------------------
5 \
6 \ to see kernel options, download FastForthSpecs.f
7 \ FastForth kernel options: MSP430ASSEMBLER, CONDCOMP, DOUBLE_INPUT, SD_CARD_LOADER
8 \
9 \ TARGET SELECTION
10 \ MSP_EXP430FR5739  MSP_EXP430FR5969    MSP_EXP430FR5994    MSP_EXP430FR6989
11 \ MSP_EXP430FR4133  CHIPSTICK_FR2433    MSP_EXP430FR2433    MSP_EXP430FR2355
12 \
13 \ REGISTERS USAGE
14 \ R4 to R7 must be saved before use and restored after
15 \ scratch registers Y to S are free for use
16 \ under interrupt, IP is free for use
17 \
18 \ PUSHM order : PSP,TOS, IP,  S,  T,  W,  X,  Y, rEXIT,rDOVAR,rDOCON, rDODOES, R3, SR,RSP, PC
19 \ PUSHM order : R15,R14,R13,R12,R11,R10, R9, R8,  R7  ,  R6  ,  R5  ,   R4   , R3, R2, R1, R0
20 \
21 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
22 \
23 \ POPM  order :  PC,RSP, SR, R3, rDODOES,rDOCON,rDOVAR,rEXIT,  Y,  X,  W,  T,  S, IP,TOS,PSP
24 \ POPM  order :  R0, R1, R2, R3,   R4   ,  R5  ,  R6  ,  R7 , R8, R9,R10,R11,R12,R13,R14,R15
25 \
26 \ example : POPM #6,IP   pop Y,X,W,T,S,IP registers from return stack
27 \
28 \
29 \ FORTH conditionnals:  unary{ 0= 0< 0> }, binary{ = < > U< }
30 \
31 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE  S<  S>=  U<   U>=  0=  0<>  0>=
32 \ ASSEMBLER conditionnal usage with ?JMP ?GOTO      S<  S>=  U<   U>=  0=  0<>  0<
33
34 PWR_STATE
35
36 : DEFINED! ECHO 1 ABORT" already loaded!" ;
37
38 [DEFINED] {SD_TOOLS} [IF] DEFINED!
39
40 [ELSE]
41
42 MARKER {SD_TOOLS}
43
44 [UNDEFINED] MAX [IF]    \ MAX and MIN are defined in {UTILITY}
45
46 CODE MAX    \    n1 n2 -- n3       signed maximum
47     CMP @PSP,TOS    \ n2-n1
48     S<  ?GOTO FW1   \ n2<n1
49 BW1 ADD #2,PSP
50     MOV @IP+,PC
51 ENDCODE
52
53 CODE MIN    \    n1 n2 -- n3       signed minimum
54     CMP @PSP,TOS     \ n2-n1
55     S<  ?GOTO BW1    \ n2<n1
56 FW1 MOV @PSP+,TOS
57     MOV @IP+,PC
58 ENDCODE
59
60 [THEN]
61
62 [UNDEFINED] U.R [IF]        \ defined in {UTILITY}
63 : U.R                       \ u n --           display u unsigned in n width (n >= 2)
64   >R  <# 0 # #S #>  
65   R> OVER - 0 MAX SPACES TYPE
66 ;
67 [THEN]
68
69 [UNDEFINED] AND [IF]
70
71 \ https://forth-standard.org/standard/core/AND
72 \ C AND    x1 x2 -- x3           logical AND
73 CODE AND
74 AND @PSP+,TOS
75 MOV @IP+,PC
76 ENDCODE
77
78 [THEN]
79
80 [UNDEFINED] DUMP [IF]       \ defined in {UTILITY}
81 \ https://forth-standard.org/standard/tools/DUMP
82 CODE DUMP                   \ adr n  --   dump memory
83 PUSH IP
84 PUSH &BASE                  \ save current base
85 MOV #$10,&BASE              \ HEX base
86 ADD @PSP,TOS                \ -- ORG END
87 LO2HI
88   SWAP OVER OVER            \ -- END ORG END ORG 
89   U. U.                     \ -- END ORG        display org end 
90   $FFF0 AND                 \ -- END ORG_modulo_16
91   DO  CR                    \ generate line
92     I 7 U.R SPACE           \ generate address
93       I $10 + I             \ display 16 bytes
94       DO I C@ 3 U.R LOOP  
95       SPACE SPACE
96       I $10 + I             \ display 16 chars
97       DO I C@ $7E MIN BL MAX EMIT LOOP
98   $10 +LOOP
99   R> BASE !                 \ restore current base
100 ;
101 [THEN]
102
103 \ display content of a sector
104 \ ----------------------------------\
105 CODE SECTOR                         \ sector. --     don't forget to add decimal point to your sector number
106 \ ----------------------------------\
107     MOV     TOS,X                   \ X = SectorH
108     MOV     @PSP,W                  \ W = sectorL
109     CALL    &ReadSectorWX           \ W = SectorLO  X = SectorHI
110 COLON                               \
111     <# #S #> TYPE SPACE             \ ud --            display the double number
112     SD_BUF $200 DUMP CR ;           \ then dump the sector
113 \ ----------------------------------\
114
115 \ ----------------------------------\
116 CODE FAT                            \ Display CurFATsector
117 \ ----------------------------------\
118     SUB     #4,PSP                  \
119     MOV     TOS,2(PSP)              \
120     MOV     &OrgFAT1,0(PSP)         \
121     MOV     #0,TOS                  \ FATsectorHI = 0
122     JMP     SECTOR                  \ jump to a defined word
123 ENDCODE
124 \ ----------------------------------\
125
126 \ display first sector of a Cluster
127 \ ----------------------------------\
128 CODE CLUSTER                        \ cluster.  --        don't forget to add decimal point to your cluster number
129 \ ----------------------------------\
130     MOV.B &SecPerClus,W             \ SecPerClus(54321) = multiplicator
131     MOV @PSP,X                      \ X = ClusterL
132     RRA W                           \
133     U< IF                           \ case of SecPerClus>1
134         BEGIN
135             ADD X,X                 \ (RLA) shift one left MULTIPLICANDlo16
136             ADDC TOS,TOS            \ (RLC) shift one left MULTIPLICANDhi8
137             RRA W                   \ shift one right multiplicator
138         U>= UNTIL                   \ carry set
139     THEN                            \
140     ADD     &OrgClusters,X          \ add OrgClusters = sector of virtual cluster 0 (word size)
141     MOV     X,0(PSP)      
142     ADDC    #0,TOS                  \ don't forget carry
143     JMP     SECTOR                  \ jump to a defined word
144 ENDCODE
145 \ ----------------------------------\
146
147 \ ----------------------------------\
148 CODE DIR                            \ Display CurrentDir first sector
149 \ ----------------------------------\
150     SUB     #4,PSP                  \
151     MOV     TOS,2(PSP)              \           save TOS
152     MOV     &DIRclusterL,0(PSP)     \
153     MOV     &DIRclusterH,TOS        \
154     JMP     CLUSTER                 \
155 ENDCODE
156 \ ----------------------------------\
157
158
159 RST_HERE
160
161 [THEN]
162 ECHO
163 ; added : FAT to DUMP first sector of FAT1 and DIR for that of current DIRectory.
164 ; added : SECTOR to DUMP a sector and CLUSTER for first sector of a cluster:
165 ;         include a decimal point to force 32 bits number, example : .2 CLUSTER
166