OSDN Git Service

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