📄 fat.h
字号:
/*
gba_nds_fat.h
By chishm (Michael Chisholm)
Routines for reading a compact flash card
using the GBA Movie Player or M3.
Some FAT routines are based on those in fat.c, which
is part of avrlib by Pascal Stang.
This software is completely free. No warranty is provided.
If you use it, please give me credit and email me about your
project at chishm@hotmail.com
See gba_nds_fat.txt for help and license details.
*/
//---------------------------------------------------------------
#ifndef _GBA_NDS_FAT_INCLUDED
#define _GBA_NDS_FAT_INCLUDED
#define true 1
#define false 0
//---------------------------------------------------------------
// Customisable features
// Maximum number of files open at once
// Increase this to open more files, decrease to save memory
#define MAX_FILES_OPEN 4
// Allow file writing
// Disable this to remove file writing support
#define CAN_WRITE_TO_DISC
// Allow file time functions
// This adds ~ 14KB to the compiled size
// Uncomment to enable
// #define FILE_TIME_SUPPORT
//---------------------------------------------------------------
// Platform specific includes
// When compiling for NDS, make sure NDS is defined
#ifndef NDS
#if defined ARM9 || defined ARM7
#define NDS
#endif
#endif
#ifdef FILE_TIME_SUPPORT
#include <time.h>
#endif
//---------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
//---------------------------------------------------------------
//---------------------------------------------------------------
// Important constants
#define MAX_FILENAME_LENGTH 256 // Maximum LFN length. Don't change this one
// File Constants
#ifndef EOF
#define EOF -1
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#endif
// File attributes
#define ATTRIB_ARCH 0x20 // Archive
#define ATTRIB_DIR 0x10 // Directory
#define ATTRIB_LFN 0x0F // Long file name
#define ATTRIB_VOL 0x08 // Volume
#define ATTRIB_SYS 0x04 // System
#define ATTRIB_HID 0x02 // Hidden
#define ATTRIB_RO 0x01 // Read only
// Directory Constants
typedef enum {FT_NONE, FT_FILE, FT_DIR} FILE_TYPE;
// Filesystem type
typedef enum {FS_UNKNOWN, FS_FAT12, FS_FAT16, FS_FAT32} FS_TYPE;
// Open file information structure
typedef struct
{
unsigned int firstCluster;
unsigned int length;
unsigned int curPos;
unsigned int curClus; // Current cluster to read from
int curSect; // Current sector within cluster
int curByte; // Current byte within sector
char readBuffer[512]; // Buffer used for unaligned reads
unsigned int appClus; // Cluster to append to
int appSect; // Sector within cluster for appending
int appByte; // Byte within sector for appending
unsigned char read; // Can read from file
unsigned char write; // Can write to file
unsigned char append; // Can append to file
unsigned char inUse; // This file is open
unsigned int dirEntSector; // The sector where the directory entry is stored
int dirEntOffset; // The offset within the directory sector
} FAT_FILE;
//-----------------------------------------------------------------
// CF Card functions
/*-----------------------------------------------------------------
FAT_InitFiles
Reads the FAT information from the CF card.
You need to call this before reading any files.
unsigned char return OUT: true if successful.
-----------------------------------------------------------------*/
char FAT_InitFiles (void);
/*-----------------------------------------------------------------
FAT_FreeFiles
Closes all open files then resets the CF card.
Call this before exiting back to the GBAMP
unsigned char return OUT: true if successful.
-----------------------------------------------------------------*/
char FAT_FreeFiles (void);
/*-----------------------------------------------------------------
FAT_GetAlias
Get the alias (short name) of the last file or directory entry read
using GetDirEntry. Works for FindFirstFile and FindNextFile
char* alias OUT: will be filled with the alias (short filename),
should be at least 13 bytes long
unsigned char return OUT: return true if successful
-----------------------------------------------------------------*/
char FAT_GetAlias (char* alias);
/*-----------------------------------------------------------------
FAT_GetLongFilename
Get the long name of the last file or directory retrived with
GetDirEntry. Also works for FindFirstFile and FindNextFile
char* filename: OUT will be filled with the filename, should be at
least 256 bytes long
unsigned char return OUT: return true if successful
-----------------------------------------------------------------*/
char FAT_GetLongFilename (char* filename);
/*-----------------------------------------------------------------
FAT_GetFileSize
Get the file size of the last file found or openned.
This idea is based on a modification by MoonShine
unsigned int return OUT: the file size
-----------------------------------------------------------------*/
unsigned int FAT_GetFileSize (void);
/*-----------------------------------------------------------------
FAT_GetFileCluster
Get the first cluster of the last file found or openned.
unsigned int return OUT: the file start cluster
-----------------------------------------------------------------*/
unsigned int FAT_GetFileCluster (void);
/*-----------------------------------------------------------------
FAT_GetFileAttributes
Get the attributes of the last file found or openned.
unsigned char return OUT: the file's attributes
-----------------------------------------------------------------*/
unsigned char FAT_GetFileAttributes (void);
#ifdef CAN_WRITE_TO_DISC
/*-----------------------------------------------------------------
FAT_FAT_SetFileAttributes
Set the attributes of a file.
const char* filename IN: The name and path of the file to modify
unsigned char attributes IN: The attribute values to assign
unsigned char mask IN: Detemines which attributes are changed
unsigned char return OUT: the file's new attributes
-----------------------------------------------------------------*/
unsigned char FAT_SetFileAttributes (const char* filename, unsigned char attributes, unsigned char mask);
#endif
#ifdef FILE_TIME_SUPPORT
/*-----------------------------------------------------------------
FAT_GetFileCreationTime
Get the creation time of the last file found or openned.
time_t return OUT: the file's creation time
-----------------------------------------------------------------*/
time_t FAT_GetFileCreationTime (void);
/*-----------------------------------------------------------------
FAT_GetFileLastWriteTime
Get the creation time of the last file found or openned.
time_t return OUT: the file's creation time
-----------------------------------------------------------------*/
time_t FAT_GetFileLastWriteTime (void);
#endif
/*-----------------------------------------------------------------
FAT_FindNextFile
Gets the name of the next directory entry
(can be a file or subdirectory)
char* filename: OUT filename, must be at least 13 chars long
FILE_TYPE return: OUT returns FT_NONE if failed,
FT_FILE if it found a file and FT_DIR if it found a directory
-----------------------------------------------------------------*/
FILE_TYPE FAT_FindNextFile (char* filename);
/*-----------------------------------------------------------------
FAT_FindFirstFile
Gets the name of the first directory entry and resets the count
(can be a file or subdirectory)
char* filename: OUT filename, must be at least 13 chars long
FILE_TYPE return: OUT returns FT_NONE if failed,
FT_FILE if it found a file and FT_DIR if it found a directory
-----------------------------------------------------------------*/
FILE_TYPE FAT_FindFirstFile (char* filename);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -