This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gba_nds_fat.txt
249 lines (184 loc) · 11.1 KB
/
gba_nds_fat.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
gba_nds_fat
By chishm (Michael Chisholm)
Routines for reading a compact flash card using the GBA Movie Player or M3 devices.
FAT12, FAT16 and FAT32 are supported.
This software is completely free. No warranty is provided. If you use it, please give due credit and/or email me about your project at [email protected]
________________________________________________________________
License:
Copyright (c) 2005 Michael Chisholm ("Chishm")
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
________________________________________________________________
How to use:
This is a library for accessing files in a FAT file system, on flash media, on a GBA or NDS. It is intended to behave similar to standard file functions, like fread, etc. However, due to the way this is written, it does not behave in the exact same way. The functions all have an explanation of how to use them included in the header, so please read it.
Insert #include "gba_nds_fat/gba_nds_fat.h" into your project where you need compact flash access. Make sure you compile the included code by adding the gba_nds_cf directory to your sources.
This driver requires libgba on GBA or libnds on an NDS.
You MUST call FAT_InitFiles() before using any other FAT function. If you do not, bad things will happen. Also, if you are using this on the NDS, you need to allow the IRC to be updated correctly before openning a file, so as to get the correct date. The easiest way is to wait 2 VBlanks, assuming the VBlank interrupt is enabled and set to update the IPC data. The GBA doesn't require this, since it has no RTC.
Paths are separated with forward slashes ( / ). / is the root of the card. Filenames can be in short or long format. Only ASCII is supported for long filenames. Extended characters are case sensitive, eg ä and Ä are treated as two different characters, whereas a and A are both treated as A.
Call FAT_chdir to change directory, specifying either relative or absolute paths. Paths do not have to be terminated with a slash. Any terminating slashes are ignored.
Call FAT_FindFirstFile(char* filename) to get the name of the first file or directory in the current directory. A return value of 1 indicates a file was found, 2 indicates a directory was found and 0 indicates nothing was found.
Call FAT_FindNextFile(char* filename) to get the name of the next file or directory.
Call FAT_GetLongFilename to get the long filename as a C-string.
Call FAT_GetFileSize to get the size of the last file found or openned.
Call FAT_GetFileCluster to get the start cluster of the last file found or openned.
FAT_fopen, FAT_fclose, FAT_fseek, FAT_ftell, FAT_fread and FAT_fwrite work the same as normal fopen, fclose etc. However, files can only be openned in binary mode. Text mode is unsupported.
Files are refered to using FAT_FILE* handle, where handle is the handle of the file. If you have used previous versions, change the int handle to FAT_FILE* handle when refering to files.
When specifying a mode to FAT_fopen, only the strings "r", "r+", "w", "w+", "a" and "a+" will work. Anything else is rejected.
Make sure you call FAT_fclose when you are finished with a file, especially after writing. Otherwise the file length will not be updated.
________________________________________________________________
Acknowledgements:
FAT_NextCluster was based on routines in fat.c, which is part of avrlib by Pascal Stang.
Darkfader helped with low level CF reading and writing.
MightyMax added support for the M3.
MightyMax also gave me a new hardware interface.
Thanks Tepples for answers to my questions.
The author of maverick-os for the documentation about the FAT16 file system (available http://www.maverick-os.dk/FileSystemFormats/FAT16_FileSystem.html)
CF routines were modified with help from Darkfader.
Dwedit was very helpful in discovering bugs.
SaTa was the first to add automatic memory access control settings.
MoonLight came up with the idea of getting the size of files.
MightyMax has helped with fseek.
Joat provided system time and date functions.
wwcube provided example patches for unaligned buffer support.
MightyMax wrote FAT_fgets and FAT_fputs.
www.neoflash.com provided the routines to access the MK2 / MK3. They also added sector caching.
0xtob fixed a bug in AddDirEntry that corrupted short filename extensions.
Dwedit rolled up the LFN loops.
cory1492 improved the SuperCard SD driver.
SaTa and Moonlight provided a read only M3 SD driver.
Loopy fixed SuperCard SD reading.
CyteX added EFA2 support.
________________________________________________________________
History:
2005-06-12
* Successfully reverse engineered the reading of compact flash cards
2005-06-13
* Started work on file system driver
2005-06-15
* First release of file system driver
* File reading implemented
2005-06-24
* Second proper release
* All known bugs fixed
* File writing implemented
* File functions behave as expected
* Long filenames now work
2005-06-27
* Third release
* Bug fix for small cards
* FAT32 implemented
* Structure packing changed to be more compatible with non GCC compilers
2005-07-12
* Some bug fixes:
* Reading & writing files on FAT16 cards in the root directory is now fixed
* Accessing files near the end of FAT32 cards is now fixed
2005-07-13
* Added option not to use DMA
2005-07-14
* Fixed FAT_fseek() buffer bug
2005-07-24
* Modified for use on the NDS
* When using it on the ARM9 you don't need to modify anything. On the ARM7 you will have to manually define NDS.
2005-08-05
* Fixed FAT_fopen bug in append mode
* Fixed FAT_AddDirEntry bug that created orphen clusters if a directory entry was created that filled the end of a cluster
2005-08-07
* Fixed FAT_CWD bug when changing to ".." from a 1st level subdirectory
2005-08-21
* Added FAT_GetFileSize - Returns the size of the last file accessed
* Included automatic memory access control setting for the NDS
* Removed typedef of bool (not needed with libnds)
2005-09-05
* Added FAT_GetFileCluster - Returns the start cluster of the last file accessed
2005-09-10
* Fixed problem with FAT_GetDirEntry not initialising the attrib of the returned DIR_ENT
2005-09-15
* Added ability to read multiple sectors at once
* Improved FAT_fread and FAT_fwrite functions
* Fixed bug when trying to create a file in a non-existant directory
2005-09-18
* Fixed fseek bug with u32 offset instead of s32. Thanks goes to MightyMax for pointing that out
2005-09-21
* Improved FAT_fseek speed
2005-10-12
* Fixed long file name bug in FAT_GetDirEntry. Thanks goes to MoonLight for pointing it out
2005-10-15
* Changed file functions to use FAT_FILE* handles instead of int handles. Please change your code to reflect this change
* Split source into hardware and disk level files and renamed the files. Include gba_nds_cf.h into your project instead of gbamp_cf.h
* Added M3 adapter support
2005-10-16
* Added file time and date modification for writing, thanks to Joat
2005-10-17
* Fixed FAT_fseek when trying to SEEK_END, thanks to MoonLight
2005-10-31
* Changed FAT_CWD to FAT_chdir
* FAT_ftell now returns u32 instead of long int
2005-11-06
* Added FAT12 support and fixed FAT buffer bugs
* Added FAT_FileExists - returns FT_NONE if no file exists, FT_DIR or FT_FILE if it does
* Completely changed the hardware interface, with a big thanks to MightyMax for doing most of the work
* Added SuperCard CF support
2005-11-07
* Switched to memcpy instead of copy loops in fread and fwrite
2005-11-08
* Added ability to use unaligned buffers, thanks to wwcube
* No longer need to define NDS when compiling for the NDS (this is automatically done for you)
2005-11-09
* Long directory entries are now fit amongst old ones, rather than at the end
* Changed FAT_DeleteFile to FAT_remove and added ability to remove empty directories
* Added FAT_mkdir to create a new directory
2005-11-14
* Improved error handling in FAT_fread and FAT_fwrite
* FAT_GetLongFilename uses strncpy instead of custom code
* Added DMA support for use on NDS
2005-11-15
* FAT_fopen uses string functions for checking mode
2005-11-17
* Added FAT_fgets and FAT_fputs, with thanks again to MightyMax
2005-11-21
* Removed EOF marking from FAT_fclose
* FAT_fwrite now takes a const void* buffer. rather than a void* buffer
* FAT_fwrite initialises new sectors before using them
2005-11-24
* Fixed FAT_fseek bug, thanks to AgentQ
* Added cluster allocation in FAT_fseek
* FAT_fopen now checks for read only files
* Added FAT_FindFirstFileLFN and FAT_FindNextFileLFN - Long file name versions of FAT_FindFirstFile and FAT_FindNextFile
2005-11-25
* Clusters are now allocated as they are needed.
* Fixed seeking in append mode
* Fixed adding of new directory entries
* Added support for standard GBA Flash Carts, with SRAM
2005-11-26
* disc_io now has a HostType function, for determining what type of flash cart is inserted.
2005-11-27
* Fixed reading / writing of sector buffer in FAT_fread and FAT_fwrite, thanks to AgentQ
2006-01-04
* Fixed FAT_fwrite when writing in cluster aligned chunks
2006-02-09
* Fixed file and directory names starting with a dot ("."), or containing more than one dot
* Added Neoflash MK2 / MK3 support, thanks to www.neoflash.com
* Modified CF access routines to mask of the high byte of the status register, hopefully improving compatibility
* Added disc caching, thanks to www.neoflash.com . It can only be enabled on the DS (not GBA) since it will consume 128KB of memory on the default setting. It is advisable to call FAT_FreeFiles() before shut down if caching is enabled, to flush any writes to disc
* Added Supercard SD test code. It unfortunately doesn't work, and is disabled by default
* Added FAT total size and type functions
* Added file creation and modification functions. Disabled by default, see gba_nds_fat.h for more info
* Fixed AddDirEntry bugs:
* should no longer corrupt a directory when adding a new file
* no longer puts garbage into a short file name's extension, thanks to 0xtob
* long file names with less than 12 characters now work, thanks to DragonMinded for pointing it out
2006-03-03
* Improved NMMC (MK2 / MK3) driver
* Optimised LFNs into loops, thanks to dwedit
* Optimised SuperCard SD CFC7, thanks to Cory1492
* Added file attribute support
* Added read only M3 SD support, thanks to SaTa and Moonlight. Disabled by default due to incompleteness
* Fixed SuperCard SD reading, thanks to Loopy
* Added EFA2 support, thanks to CyteX
TODO:
* Add Supercard SD write support
* Add M3 SD write support
* Add EFA2 write support