OSDN Git Service

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