OSDN Git Service

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