⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat.h

📁 这项工程将让您把自己的MP3播放器平台
💻 H
字号:
//++
//fat.h - declarations for fat.c module
//
// Copyright (C) 2005 by Spare Time Gizmos.  All rights reserved.
//
// This file is part of the Spare Time Gizmos' MP3 Player firmware.
//
// This firmware is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple
// Place, Suite 330, Boston, MA  02111-1307  USA
//
//REVISION HISTORY:
// dd-mmm-yy    who     description
// 20-May-05	RLA	New file.
// 12-Oct-05	RLA	Fix WSWAP/LSWAP macros for SDCC.
// 19-Oct-05	RLA	Add STACKSLOCS hack for SDCC (see slocs.h for more info)...
// 20-Oct-05	RLA	Reduce MAX_LFN_LENGTH to 32 - we need the extra space
//			 on the 89C664 for another disk buffer
//--
#ifndef _fat_h_
#define _fat_h_
#include "slocs.h"	// STACKSLOCS hack for SDCC

//   The is the one time (and I'm pretty sure it's the only time) that SDCC
// wins hands down - SDCC is little endian, and with SDCC all these macros
// can be no-ops...
#define WSWAP(x) (x)
#define LSWAP(x) (x)

//   This type is used everywhere (I hope!) in the software where a cluster
// number is implied.  This should hopefully allow easy future conversions to
// support FAT32 structures...
typedef WORD CLUSTER;

// Structure of a partition table entry (stored in the MBR)...
struct _PARTITION_TABLE_ENTRY {
  BYTE bFlags;			// 0x80 if bootable
  BYTE abStartCHS[3];		// start of the partition in CHS-addressing
  BYTE bType;	 		// type of the partition
  BYTE abEndCHS[3];		// end of the partition in CHS-addressing
  LONG lOffset;			// relative offset to the partition in sectors (LBA)
  LONG lSize;			// size of the partition in sectors
};                                    
typedef struct _PARTITION_TABLE_ENTRY PARTITION_TABLE_ENTRY;

// Structure of the master boot record...
#define MAX_PARTITIONS	4
struct _MASTER_BOOT_RECORD {
  BYTE abBootCode[139];
  char acMessages[307];
  PARTITION_TABLE_ENTRY aPartitions[MAX_PARTITIONS];
  WORD wSignature;  
};
typedef struct _MASTER_BOOT_RECORD MASTER_BOOT_RECORD;

// Structure of the BIOS Parameter Block (hereafter, BPB) ...
struct _BIOS_PARAMETER_BLOCK {
  WORD wBytesPerSector;		// Sector size in bytes
  BYTE bSectorsPerCluster;	// Number of sectors per cluster
  WORD wReservedSectors;	// Reserved sectors
  BYTE bNumberFATs;		// Number of FATs
  WORD wRootEntries;		// Number of directory entries in the root directory
  WORD wSmallSectors;		// (unused for drives .GT. 32Mb - see lTotalSectors)
  BYTE bMediaDescriptor;	// Media descriptor (bit #2 holds whether the disk is removable)
  WORD wSectorsPerFAT;		// Number of sectors used for one FAT table (N.A. for FAT32)
  WORD wSectorsPerTrack;	// Number of sectors per track (cylinder), CHS addressing
  WORD wTotalHeads;		// Number of heads, CHS addressing
  LONG lHiddenSectors;		// Number of hidden sectors (rarely used)
  LONG lLargeSectors;		// Total number of sectors on the disk/partition
				//  (valid only if wSmallSectors == 0)
  BYTE bPhysicalDrive;		// Drive number
  BYTE bCurrentHead;		// Current head
  BYTE bBootSignature;		// 0x28 or 0x29
				// (the value 0x29 indicates the three next fields are valid)
  LONG lVolumeID;		// Volume serial number
  char szVolumeLabel[11];	// Volume label
  char szSystemID[8];		// "FAT16" or "FAT12"
};
typedef struct _BIOS_PARAMETER_BLOCK BPB;

// Structure of the boot sector...
struct _BOOT_SECTOR {
  BYTE abJump[3];      		// Intel 80x86 jump instruction
  char szOEMName[8];   		// OEM name (not the volume name)
  BPB  bpb;			// BIOS Parameter Block
  BYTE abBootCode[448];		// bootstrap code
  WORD wBootSignature;		// must be ox55AA
};
typedef struct _BOOT_SECTOR BOOT_SECTOR;

// Structure of a directory entry...
struct _DIRECTORY_ENTRY {
  char szFileName[8];		// file name, padded with spaces 
  char szFileType[3];		// file extension  "   "     "
  BYTE bAttributes;		// file attributes 
  BYTE abReserved[10];		// reserved (extended date/time info)
  WORD wTime;			// time of last change 
  WORD wDate;			// date of last change
  WORD wFirstCluster;		// starting cluster in this file
  LONG lFileSize;		// file size (in bytes)
};
typedef struct _DIRECTORY_ENTRY DIRECTORY_ENTRY;
typedef struct _DIRECTORY_ENTRY XDATA *PXDIRENT;

// Directory entry related constants...
#define DELETED_FILE    0xE5	// szFileName[0] - this entry is deleted
#define EMPTY_FILE	0x00	// szFileName[0] - this entry is (never) used
#define READ_ONLY_FILE	0x01	// bAttributes - read only file
#define HIDDEN_FILE	0x02	// bAttributes - hidden file
#define SYSTEM_FILE	0x04	// bAttributes - system file
#define VOLUME_NAME	0x08	// bAttributes - volume name (not a file at all!)
#define DIRECTORY_FILE	0x10	// bAttributes - (sub)directory file
#define ARCHIVE_FILE	0x20	// bAttributes - archived file
#define LFN_ATTRIBUTES	0x0F	// bAttributes - this a LFN entry

//   This is the structure of a LFN (Long File Name) directory entry.  It must
// be the same length (32 bytes) as a regular directory entry, but the structure
// is different...
struct _LFN_DIRECTORY_ENTRY {
  BYTE bSequence;		// LFN entry sequence number (1, 2, 3, ...)
  WORD awChars1[5];		// first five characters, in Unicode!
  BYTE bAttributes;		// file attributes, always 0x0F for LFNs
  BYTE bMBZ1;			// always zero for LFN entries
  BYTE bChecksum;		// checksum of this LFN entry
  WORD awChars2[6];		// next six characters, in Unicode.
  WORD wMBZ2;			// always zero for LFN entries
  WORD awChars3[2];		// last two characters, in Unicode.
};
typedef struct _LFN_DIRECTORY_ENTRY LFN_DIRECTORY_ENTRY;

// Magic constants for FAT file systems...
#define EOF_CLUSTER	0xFFFF	// end of file cluster
#define CLUSTER_OFFSET	     2	// offset of first cluster in FAT
#define VOLUME_LABEL_LENGTH 12	// volume label length +1 (for EOS byte)
#define SYSTEM_TYPE_LENGTH   9	// system type (e.g. FAT16) length +1
#define CLUSTERS_PER_SECTOR 		(IDE_SECTOR_SIZE / sizeof(CLUSTER))
#define DIRECTORY_ENTRIES_PER_SECTOR	(IDE_SECTOR_SIZE / sizeof(DIRECTORY_ENTRY))
//   Note that a proper LFN can actually be as long as 256 characters, but
// there's no point is saving all those when we can only show 20 characters
// on our little display.  All things being equal we'd keep them anyway, but
// the 89C664 is really short on XDATA RAM and the extra 200 bytes add enough
// free space to make the difference between one disk buffer and two!
#define MAX_LFN_LENGTH	   32	// longest possible long file name

// Methods...
extern BOOL InitializeFAT (void);
extern void GetVolumeData (void);
extern PXDIRENT FirstMP3File (void);
extern PXDIRENT NextMP3File (void);
extern PXDIRENT PrevMP3File (void);
extern void OpenFile (PXDIRENT pxDirEnt);
extern WORD ReadFile (PXBYTE pxBuffer);
extern BOOL ReadFileEnd (PXBYTE pxBuffer, WORD cbBuffer)  STACKSLOCS;
extern void CloseFile (void);

// Members...
extern XDATA char g_szVolumeLabel[VOLUME_LABEL_LENGTH];
extern XDATA char g_szSystemType[SYSTEM_TYPE_LENGTH];
extern XDATA char g_szLongFileName[MAX_LFN_LENGTH];
extern XDATA WORD g_wTotalMP3Files;

#endif	// _fat_h_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -