OSDN Git Service

62783f24e3c06909170c87938770eb7634587629
[fast-forth/master.git] / ADDON / SD_TOOLS.asm
1 ; -*- coding: utf-8 -*-
2 ; http://patorjk.com/software/taag/#p=display&f=Banner&t=Fast Forth
3
4 ; Fast Forth For Texas Instrument MSP430FRxxxx FRAM devices
5 ; Copyright (C) <2015>  <J.M. THOORENS>
6 ;
7 ; This program is free software: you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation, either version 3 of the License, or
10 ; (at your option) any later version.
11 ;
12 ; This program is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ; GNU General Public License for more details.
16 ;
17 ; You should have received a copy of the GNU General Public License
18 ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21     .IFNDEF UTILITY
22
23     .IFNDEF ANS_CORE_COMPLIANT
24
25 ;https://forth-standard.org/standard/core/MAX
26 ;C MAX    n1 n2 -- n3       signed maximum
27             FORTHWORD "MAX"
28 MAX:        CMP     @PSP,TOS    ; n2-n1
29             JL      SELn1       ; n2<n1
30 SELn2:      ADD     #2,PSP
31             mNEXT
32
33 ;https://forth-standard.org/standard/core/MIN
34 ;C MIN    n1 n2 -- n3       signed minimum
35             FORTHWORD "MIN"
36 MIN:        CMP     @PSP,TOS    ; n2-n1
37             JL      SELn2       ; n2<n1
38 SELn1:      MOV     @PSP+,TOS
39             mNEXT
40
41     .ENDIF ;  ANS_CORE_COMPLIANT
42
43 ;https://forth-standard.org/standard/core/UDotR
44 ;X U.R      u n --      display u unsigned in n width
45             FORTHWORD "U.R"
46 UDOTR       mDOCOL
47             .word   TOR,LESSNUM,lit,0,NUM,NUMS,NUMGREATER
48             .word   RFROM,OVER,MINUS,lit,0,MAX,SPACES,TYPE
49             .word   EXIT
50
51 ;https://forth-standard.org/standard/tools/DUMP
52             FORTHWORD "DUMP"
53 DUMP        PUSH    IP
54             PUSH    &BASE
55             MOV     #10h,&BASE
56             ADD     @PSP,TOS                ; compute end address
57             AND     #0FFF0h,0(PSP)          ; compute start address
58             ASMtoFORTH
59             .word   SWAP,xdo                ; generate line
60 DUMP1       .word   CR
61             .word   II,lit,7,UDOTR,SPACE    ; generate address
62             .word   II,lit,10h,PLUS,II,xdo  ; display 16 bytes
63 DUMP2       .word   II,CFETCH,lit,3,UDOTR
64             .word   xloop,DUMP2
65             .word   SPACE,SPACE
66             .word   II,lit,10h,PLUS,II,xdo  ; display 16 chars
67 DUMP3       .word   II,CFETCH
68             .word   lit,7Eh,MIN,FBLANK,MAX,EMIT
69             .word   xloop,DUMP3
70             .word   lit,10h,xploop,DUMP1
71             .word   RFROM,FBASE,STORE
72             .word   EXIT
73
74     .ENDIF ; UTILITY
75
76     FORTHWORD "{SD_TOOLS}"
77     mNEXT
78
79 ; read logical sector and dump it 
80 ; ----------------------------------;
81     FORTHWORD "SECTOR"              ; sector. --            don't forget to add decimal point to your sector number (if < 65536)
82 ; ----------------------------------;
83 SECTOR
84     MOV     TOS,X                   ; X = SectorH
85     MOV     @PSP,W                  ; W = sectorL
86     CALL    #readSectorWX           ; W = SectorLO  X = SectorHI
87 DisplaySector
88     mDOCOL                          ;
89     .word   LESSNUM,NUMS,NUMGREATER ; ud --            display the double number
90     .word   TYPE,SPACE              ;
91     .word   lit,SD_BUF,lit,200h,DUMP;    
92     .word   EXIT                    ;
93 ; ----------------------------------;
94
95 ; TIP : How to identify FAT16 or FAT32 SD_Card ?
96 ; 1 CLUSTER <==> FAT16 RootDIR
97 ; 2 CLUSTER <==> FAT32 RootDIR
98 ; ----------------------------------;
99 ; read first sector of Cluster and dump it
100 ; ----------------------------------;
101             FORTHWORD "CLUSTER"     ; cluster.  --         don't forget to add decimal point to your sector number (if < 65536)
102 ; ----------------------------------;
103     MOV     TOS,&ClusterH           ;
104     MOV     @PSP,&ClusterL          ;
105 Clust_ClustProcess
106     CALL    #ComputeClusFrstSect    ;
107     MOV     &SectorL,0(PSP)         ;
108     MOV     &SectorH,TOS            ;
109     JMP     SECTOR                  ;
110 ; ----------------------------------;
111
112 ; dump FAT1 sector of last entry
113 ; ----------------------------------;
114             FORTHWORD "FAT"         ;VWXY Display first FATsector
115 ; ----------------------------------;
116     SUB     #4,PSP                  ;
117     MOV     TOS,2(PSP)              ;
118     MOV     &OrgFAT1,0(PSP)         ;
119     MOV     #0,TOS                  ; FATsectorHI = 0
120     JMP     SECTOR                  ;
121 ; ----------------------------------;
122
123 ;; dump FAT1 sector of last entry
124 ;; ----------------------------------;
125 ;            FORTHWORD "FAT"      ; Display FATsector
126 ;; ----------------------------------;
127 ;    MOV     &OrgFAT1,Y              ;
128 ;FAT1_Next                           ;
129 ;    SUB     #4,PSP                  ;
130 ;    MOV     TOS,2(PSP)              ; save TOS
131 ;    MOV     Y,0(PSP)                ;
132 ;    MOV     #0,TOS                  ; FATsectorHI = 0
133 ;    JMP     SECTOR                  ;
134 ;; ----------------------------------;
135 ;
136 ;; dump FAT1 sector of last entry
137 ;; ----------------------------------;
138 ;            FORTHWORD "FAT2"        ; Display FATsector
139 ;; ----------------------------------;
140 ;    MOV     &OrgFAT2,Y              ;
141 ;    JMP     FAT1_Next               ;
142 ;; ----------------------------------;
143
144
145
146 ; dump DIR sector of opened file or first sector of current DIR by default
147 ; ----------------------------------;
148             FORTHWORD "DIR"         ; Display DIR sector of CurrentHdl or CurrentDir sector by default 
149 ; ----------------------------------;
150     SUB     #4,PSP                  ;
151     MOV     TOS,2(PSP)              ;           save TOS
152     MOV     &DIRClusterL,&ClusterL  ;
153     MOV     &DIRClusterH,&ClusterH  ;
154     JMP     Clust_ClustProcess      ;
155 ; ----------------------------------;
156