diff options
author | Jordi Vilalta Prat | 2008-01-27 19:47:41 +0000 |
---|---|---|
committer | Jordi Vilalta Prat | 2008-01-27 19:47:41 +0000 |
commit | 66e9d4f5e8f35b28f8abd9ce53a0da4da3ce8985 (patch) | |
tree | e27aadabecd8dd910884280e6559ff9c94c3d73c /backends/platform/ds/arm9/source/fat | |
parent | 278857698dc7b1623096fe1ad12511dc4c886c7e (diff) | |
download | scummvm-rg350-66e9d4f5e8f35b28f8abd9ce53a0da4da3ce8985.tar.gz scummvm-rg350-66e9d4f5e8f35b28f8abd9ce53a0da4da3ce8985.tar.bz2 scummvm-rg350-66e9d4f5e8f35b28f8abd9ce53a0da4da3ce8985.zip |
Removed trailing spaces.
svn-id: r30664
Diffstat (limited to 'backends/platform/ds/arm9/source/fat')
30 files changed, 593 insertions, 593 deletions
diff --git a/backends/platform/ds/arm9/source/fat/disc_io.c b/backends/platform/ds/arm9/source/fat/disc_io.c index 4128c769e1..f456343a2c 100644 --- a/backends/platform/ds/arm9/source/fat/disc_io.c +++ b/backends/platform/ds/arm9/source/fat/disc_io.c @@ -5,7 +5,7 @@ uniformed io-interface to work with Chishm's FAT library Written by MightyMax - + Modified by Chishm: 2005-11-06 * Added WAIT_CR modifications for NDS @@ -87,7 +87,7 @@ LPIO_INTERFACE active_interface = 0; Disc Cache functions 2006-02-03: - Added by www.neoflash.com + Added by www.neoflash.com */ int discDetect = 0; @@ -99,7 +99,7 @@ int dldiFound = FALSE; #include <string.h> #define CACHE_FREE 0xFFFFFFFF - + static u8 cacheBuffer[ DISC_CACHE_COUNT * 512 ]; static struct { @@ -112,20 +112,20 @@ FATDevice currentDevice; static u32 disc_CacheFind(u32 sector) { u32 i; - + for( i = 0; i < DISC_CACHE_COUNT; i++ ) { if( cache[ i ].sector == sector ) return i; } - + return CACHE_FREE; } static u32 disc_CacheFindFree(void) { - + u32 i = 0, j; u32 count = -1; - + for( j = 0; j < DISC_CACHE_COUNT; j++ ) { if( cache[ j ].sector == CACHE_FREE ) { @@ -142,7 +142,7 @@ static u32 disc_CacheFindFree(void) { if( cache[ i ].sector != CACHE_FREE && cache[i].dirty != 0 ) { active_interface->fn_WriteSectors( cache[ i ].sector, 1, &cacheBuffer[ i * 512 ] ); - /* todo: handle write error here + /* todo: handle write error here cache[ i ].sector = CACHE_FREE; cache[ i ].dirty = 0; @@ -431,7 +431,7 @@ bool disc_setDsSlotInterface (void) #endif -bool disc_Init(void) +bool disc_Init(void) { #ifdef DISC_CACHE disc_CacheInit(); @@ -455,15 +455,15 @@ bool disc_Init(void) // could not find a working IO Interface active_interface = 0 ; return false ; -} +} -bool disc_IsInserted(void) +bool disc_IsInserted(void) { if (active_interface) return active_interface->fn_IsInserted() ; return false ; -} +} -bool disc_ReadSectors(u32 sector, u8 numSecs, void* buffer) +bool disc_ReadSectors(u32 sector, u8 numSecs, void* buffer) { #ifdef DISC_CACHE u8 *p=(u8*)buffer; @@ -480,9 +480,9 @@ bool disc_ReadSectors(u32 sector, u8 numSecs, void* buffer) if (active_interface) return active_interface->fn_ReadSectors(sector,numSecs,buffer) ; return false ; #endif -} +} -bool disc_WriteSectors(u32 sector, u8 numSecs, void* buffer) +bool disc_WriteSectors(u32 sector, u8 numSecs, void* buffer) { /*#ifdef DISC_CACHE u8 *p=(u8*)buffer; @@ -502,15 +502,15 @@ bool disc_WriteSectors(u32 sector, u8 numSecs, void* buffer) if (active_interface) return active_interface->fn_WriteSectors(sector,numSecs,buffer) ; return false ; //#endif -} +} -bool disc_ClearStatus(void) +bool disc_ClearStatus(void) { if (active_interface) return active_interface->fn_ClearStatus() ; return false ; -} +} -bool disc_Shutdown(void) +bool disc_Shutdown(void) { #ifdef DISC_CACHE disc_CacheFlush(); @@ -518,7 +518,7 @@ bool disc_Shutdown(void) if (active_interface) active_interface->fn_Shutdown() ; active_interface = 0 ; return true ; -} +} u32 disc_HostType (void) { diff --git a/backends/platform/ds/arm9/source/fat/disc_io.h b/backends/platform/ds/arm9/source/fat/disc_io.h index 05d4c020bd..b2317ca110 100644 --- a/backends/platform/ds/arm9/source/fat/disc_io.h +++ b/backends/platform/ds/arm9/source/fat/disc_io.h @@ -7,7 +7,7 @@ // Use DMA to read the card, remove this line to use normal reads/writes // #define _CF_USE_DMA -// Allow buffers not aligned to 16 bits when reading files. +// Allow buffers not aligned to 16 bits when reading files. // Note that this will slow down access speed, so only use if you have to. // It is also incompatible with DMA #define _CF_ALLOW_UNALIGNED @@ -43,7 +43,7 @@ // This allows the code to build on an earlier version of libnds, before the register was renamed #ifndef REG_EXMEMCNT -#define REG_EXMEMCNT REG_EXEMEMCNT +#define REG_EXMEMCNT REG_EXEMEMCNT #endif #ifndef REG_EXEMEMCNT @@ -70,7 +70,7 @@ #endif // Disable NDS specific hardware and features if running on a GBA -#ifndef NDS +#ifndef NDS #undef SUPPORT_NMMC #undef DISC_CACHE #endif diff --git a/backends/platform/ds/arm9/source/fat/gba_nds_fat.c b/backends/platform/ds/arm9/source/fat/gba_nds_fat.c index b5fdd665df..9594066f03 100644 --- a/backends/platform/ds/arm9/source/fat/gba_nds_fat.c +++ b/backends/platform/ds/arm9/source/fat/gba_nds_fat.c @@ -42,7 +42,7 @@ //--------------------------------------------------------------- // Appropriate placement of CF functions and data #ifdef NDS - #define _VARS_IN_RAM + #define _VARS_IN_RAM #else #define _VARS_IN_RAM __attribute__ ((section (".sbss"))) #endif @@ -74,7 +74,7 @@ #ifdef __GNUC__ #define __PACKED __attribute__ ((__packed__)) #else - #define __PACKED + #define __PACKED #pragma pack(1) #endif @@ -98,7 +98,7 @@ typedef struct u32 numSectors; union // Different types of extended BIOS Parameter Block for FAT16 and FAT32 { - struct + struct { // Ext BIOS Parameter Block for FAT16 u8 driveNumber; @@ -110,7 +110,7 @@ typedef struct // Bootcode u8 bootCode[448]; } __PACKED fat16; - struct + struct { // FAT32 extended block u32 sectorsPerFAT32; @@ -158,7 +158,7 @@ typedef struct typedef struct { u8 ordinal; // Position within LFN - u16 char0; + u16 char0; u16 char1; u16 char2; u16 char3; @@ -177,7 +177,7 @@ typedef struct u16 char12; } __PACKED DIR_ENT_LFN; -const char lfn_offset_table[13]={0x01,0x03,0x05,0x07,0x09,0x0E,0x10,0x12,0x14,0x16,0x18,0x1C,0x1E}; +const char lfn_offset_table[13]={0x01,0x03,0x05,0x07,0x09,0x0E,0x10,0x12,0x14,0x16,0x18,0x1C,0x1E}; // End of packed structs #ifdef __PACKED @@ -190,7 +190,7 @@ const char lfn_offset_table[13]={0x01,0x03,0x05,0x07,0x09,0x0E,0x10,0x12,0x14,0x //----------------------------------------------------------------- // Global Variables -// _VARS_IN_RAM variables are stored in the largest section of WRAM +// _VARS_IN_RAM variables are stored in the largest section of WRAM // available: IWRAM on NDS ARM7, EWRAM on NDS ARM9 and GBA // Files @@ -305,7 +305,7 @@ u16 getRTCtoFileTime (void) u16 getRTCtoFileDate (void) { #ifdef NDS - return ( + return ( ( ((IPC->rtc_year + 20) & 0x7F) <<9) | ( (IPC->rtc_month & 0xF) << 5) | (IPC->rtc_day & 0x1F) ); @@ -330,13 +330,13 @@ u32 FAT_NextCluster(u32 cluster) u32 nextCluster = CLUSTER_FREE; u32 sector; int offset; - - switch (filesysType) + + switch (filesysType) { case FS_UNKNOWN: nextCluster = CLUSTER_FREE; break; - + case FS_FAT12: sector = filesysFAT + (((cluster * 3) / 2) / BYTE_PER_READ); offset = ((cluster * 3) / 2) % BYTE_PER_READ; @@ -351,32 +351,32 @@ u32 FAT_NextCluster(u32 cluster) nextCluster = ((u8*)fatBuffer)[offset]; offset++; - + if (offset >= BYTE_PER_READ) { offset = 0; fatBufferCurSector++; disc_ReadSector(fatBufferCurSector, fatBuffer); } - + nextCluster |= (((u8*)fatBuffer)[offset]) << 8; - + if (cluster & 0x01) { nextCluster = nextCluster >> 4; } else { nextCluster &= 0x0FFF; } - + if (nextCluster >= 0x0FF7) { nextCluster = CLUSTER_EOF; } break; - + case FS_FAT16: sector = filesysFAT + ((cluster << 1) / BYTE_PER_READ); offset = cluster % (BYTE_PER_READ >> 1); - + // If FAT buffer contains wrong sector if (sector != fatBufferCurSector) { @@ -387,17 +387,17 @@ u32 FAT_NextCluster(u32 cluster) // read the nextCluster value nextCluster = ((u16*)fatBuffer)[offset]; - + if (nextCluster >= 0xFFF7) { nextCluster = CLUSTER_EOF; } break; - + case FS_FAT32: sector = filesysFAT + ((cluster << 2) / BYTE_PER_READ); offset = cluster % (BYTE_PER_READ >> 2); - + // If FAT buffer contains wrong sector if (sector != fatBufferCurSector) { @@ -408,18 +408,18 @@ u32 FAT_NextCluster(u32 cluster) // read the nextCluster value nextCluster = (((u32*)fatBuffer)[offset]) & 0x0FFFFFFF; - + if (nextCluster >= 0x0FFFFFF7) { nextCluster = CLUSTER_EOF; } break; - + default: nextCluster = CLUSTER_FREE; break; } - + return nextCluster; } @@ -437,13 +437,13 @@ bool FAT_WriteFatEntry (u32 cluster, u32 value) { return false; } - - switch (filesysType) + + switch (filesysType) { case FS_UNKNOWN: return false; break; - + case FS_FAT12: sector = filesysFAT + (((cluster * 3) / 2) / BYTE_PER_READ); offset = ((cluster * 3) / 2) % BYTE_PER_READ; @@ -465,32 +465,32 @@ bool FAT_WriteFatEntry (u32 cluster, u32 value) offset = 0; // write the buffer back to disc disc_WriteSector(fatBufferCurSector, fatBuffer); - // read the next sector + // read the next sector fatBufferCurSector++; disc_ReadSector(fatBufferCurSector, fatBuffer); } - + ((u8*)fatBuffer)[offset] = (value & 0x0FF0) >> 4; } else { - + ((u8*)fatBuffer)[offset] = value & 0xFF; - + offset++; if (offset >= BYTE_PER_READ) { offset = 0; // write the buffer back to disc disc_WriteSector(fatBufferCurSector, fatBuffer); - // read the next sector + // read the next sector fatBufferCurSector++; disc_ReadSector(fatBufferCurSector, fatBuffer); } - + ((u8*)fatBuffer)[offset] = (((u8*)fatBuffer)[offset] & 0xF0) | ((value >> 8) & 0x0F); } break; - + case FS_FAT16: sector = filesysFAT + ((cluster << 1) / BYTE_PER_READ); offset = cluster % (BYTE_PER_READ >> 1); @@ -507,11 +507,11 @@ bool FAT_WriteFatEntry (u32 cluster, u32 value) ((u16*)fatBuffer)[offset] = (value & 0xFFFF); break; - + case FS_FAT32: sector = filesysFAT + ((cluster << 2) / BYTE_PER_READ); offset = cluster % (BYTE_PER_READ >> 2); - + // If FAT buffer contains wrong sector if (sector != fatBufferCurSector) { @@ -524,15 +524,15 @@ bool FAT_WriteFatEntry (u32 cluster, u32 value) (((u32*)fatBuffer)[offset]) = value; break; - + default: return false; break; } - + // write the buffer back to disc disc_WriteSector(fatBufferCurSector, fatBuffer); - + return true; } #endif @@ -540,8 +540,8 @@ bool FAT_WriteFatEntry (u32 cluster, u32 value) #ifdef CAN_WRITE_TO_DISC /*----------------------------------------------------------------- FAT_ReadWriteFatEntryBuffered -Internal function - writes FAT information about a cluster to a - buffer that should then be flushed to disc using +Internal function - writes FAT information about a cluster to a + buffer that should then be flushed to disc using FAT_WriteFatEntryFlushBuffer() Call FAT_WriteFatEntry first so as not to ruin the disc. Also returns the entry being replaced @@ -555,13 +555,13 @@ u32 FAT_ReadWriteFatEntryBuffered (u32 cluster, u32 value) if ((cluster < 0x0002) || (cluster > fatLastCluster)) return CLUSTER_FREE; - - switch (filesysType) + + switch (filesysType) { case FS_UNKNOWN: oldValue = CLUSTER_FREE; break; - + case FS_FAT12: sector = filesysFAT + (((cluster * 3) / 2) / BYTE_PER_READ); offset = ((cluster * 3) / 2) % BYTE_PER_READ; @@ -587,40 +587,40 @@ u32 FAT_ReadWriteFatEntryBuffered (u32 cluster, u32 value) offset = 0; // write the buffer back to disc disc_WriteSector(fatBufferCurSector, fatBuffer); - // read the next sector + // read the next sector fatBufferCurSector++; disc_ReadSector(fatBufferCurSector, fatBuffer); } - + oldValue |= ((((u8*)fatBuffer)[offset]) << 4) & 0x0FF0; ((u8*)fatBuffer)[offset] = (value & 0x0FF0) >> 4; } else { - + oldValue = ((u8*)fatBuffer)[offset] & 0xFF; ((u8*)fatBuffer)[offset] = value & 0xFF; - + offset++; if (offset >= BYTE_PER_READ) { offset = 0; // write the buffer back to disc disc_WriteSector(fatBufferCurSector, fatBuffer); - // read the next sector + // read the next sector fatBufferCurSector++; disc_ReadSector(fatBufferCurSector, fatBuffer); } - + oldValue |= (((u8*)fatBuffer)[offset] & 0x0F) << 8; ((u8*)fatBuffer)[offset] = (((u8*)fatBuffer)[offset] & 0xF0) | ((value >> 8) & 0x0F); } - if (oldValue >= 0x0FF7) + if (oldValue >= 0x0FF7) { oldValue = CLUSTER_EOF; } break; - + case FS_FAT16: sector = filesysFAT + ((cluster << 1) / BYTE_PER_READ); offset = cluster % (BYTE_PER_READ >> 1); @@ -634,23 +634,23 @@ u32 FAT_ReadWriteFatEntryBuffered (u32 cluster, u32 value) // Load correct sector to buffer fatBufferCurSector = sector; disc_ReadSector(fatBufferCurSector, fatBuffer); - } + } // write the value to the FAT buffer oldValue = ((u16*)fatBuffer)[offset]; ((u16*)fatBuffer)[offset] = value; - if (oldValue >= 0xFFF7) + if (oldValue >= 0xFFF7) { oldValue = CLUSTER_EOF; } break; - + case FS_FAT32: sector = filesysFAT + ((cluster << 2) / BYTE_PER_READ); offset = cluster % (BYTE_PER_READ >> 2); - + // If FAT buffer contains wrong sector if (sector != fatBufferCurSector) { @@ -666,18 +666,18 @@ u32 FAT_ReadWriteFatEntryBuffered (u32 cluster, u32 value) oldValue = ((u32*)fatBuffer)[offset]; ((u32*)fatBuffer)[offset] = value; - if (oldValue >= 0x0FFFFFF7) + if (oldValue >= 0x0FFFFFF7) { oldValue = CLUSTER_EOF; } break; - + default: oldValue = CLUSTER_FREE; break; } - + return oldValue; } #endif @@ -727,7 +727,7 @@ u32 FAT_FirstFreeCluster(void) /*----------------------------------------------------------------- FAT_LinkFreeCluster Internal function - gets the first available free cluster, sets it -to end of file, links the input cluster to it then returns the +to end of file, links the input cluster to it then returns the cluster number -----------------------------------------------------------------*/ u32 FAT_LinkFreeCluster(u32 cluster) @@ -746,7 +746,7 @@ u32 FAT_LinkFreeCluster(u32 cluster) { return curLink; // Return the current link - don't allocate a new one } - + // Get a free cluster firstFree = FAT_FirstFreeCluster(); @@ -777,7 +777,7 @@ Internal function - frees any cluster used by a file bool FAT_ClearLinks (u32 cluster) { u32 nextCluster; - + if ((cluster < 0x0002) || (cluster > fatLastCluster)) return false; @@ -793,7 +793,7 @@ bool FAT_ClearLinks (u32 cluster) while ((cluster != CLUSTER_EOF) && (cluster != CLUSTER_FREE)) { cluster = FAT_ReadWriteFatEntryBuffered (cluster, CLUSTER_FREE); - } + } // Flush fat write buffer FAT_WriteFatEntryFlushBuffer (); @@ -814,7 +814,7 @@ bool FAT_InitFiles (void) int i; int bootSector; BOOT_SEC* bootSec; - + if (!disc_Init()) { return (false); @@ -830,7 +830,7 @@ bool FAT_InitFiles (void) return false; }*/ - + // Check if there is a FAT string, which indicates this is a boot sector if ((globalBuffer[0x36] == 'F') && (globalBuffer[0x37] == 'A') && (globalBuffer[0x38] == 'T')) @@ -848,9 +848,9 @@ bool FAT_InitFiles (void) // First check for an active partition for (i=0x1BE; (i < 0x1FE) && (globalBuffer[i] != 0x80); i+= 0x10); // If it didn't find an active partition, search for any valid partition - if (i == 0x1FE) + if (i == 0x1FE) for (i=0x1BE; (i < 0x1FE) && (globalBuffer[i+0x04] == 0x00); i+= 0x10); - + // Go to first valid partition if ( i != 0x1FE) // Make sure it found a partition { @@ -865,7 +865,7 @@ bool FAT_InitFiles (void) if (!disc_ReadSector (bootSector, bootSec)) { return false; } - + // Store required information about the file system if (bootSec->sectorsPerFAT != 0) { @@ -875,7 +875,7 @@ bool FAT_InitFiles (void) { filesysSecPerFAT = bootSec->extBlock.fat32.sectorsPerFAT32; } - + if (bootSec->numSectorsSmall != 0) { filesysNumSec = bootSec->numSectorsSmall; @@ -987,7 +987,7 @@ Return the file info structure of the next valid file entry u32 dirCluster: IN cluster of subdirectory table int entry: IN the desired file entry int origin IN: relative position of the entry -DIR_ENT return OUT: desired dirEntry. First char will be FILE_FREE if +DIR_ENT return OUT: desired dirEntry. First char will be FILE_FREE if the entry does not exist. -----------------------------------------------------------------*/ DIR_ENT FAT_GetDirEntry ( u32 dirCluster, int entry, int origin) @@ -1011,8 +1011,8 @@ DIR_ENT FAT_GetDirEntry ( u32 dirCluster, int entry, int origin) { return (dir); } - - switch (origin) + + switch (origin) { case SEEK_SET: wrkDirCluster = dirCluster; @@ -1022,7 +1022,7 @@ DIR_ENT FAT_GetDirEntry ( u32 dirCluster, int entry, int origin) case SEEK_CUR: // Don't change anything break; case SEEK_END: // Find entry signifying end of directory - // Subtraction will never reach 0, so it keeps going + // Subtraction will never reach 0, so it keeps going // until reaches end of directory wrkDirCluster = dirCluster; wrkDirSector = 0; @@ -1055,7 +1055,7 @@ DIR_ENT FAT_GetDirEntry ( u32 dirCluster, int entry, int origin) { notFound = true; } - firstSector = FAT_ClustToSect(wrkDirCluster); + firstSector = FAT_ClustToSect(wrkDirCluster); } else if ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER) && (wrkDirSector == (filesysData - filesysRootDir))) { @@ -1082,7 +1082,7 @@ DIR_ENT FAT_GetDirEntry ( u32 dirCluster, int entry, int origin) lfnName[0] = '\0'; } } - if (entry == 0) + if (entry == 0) { if (!lfnExists) { @@ -1128,7 +1128,7 @@ DIR_ENT FAT_GetDirEntry ( u32 dirCluster, int entry, int origin) } } } while (!found && !notFound); - + // If no file is found, return FILE_FREE if (notFound) { @@ -1141,7 +1141,7 @@ DIR_ENT FAT_GetDirEntry ( u32 dirCluster, int entry, int origin) /*----------------------------------------------------------------- FAT_GetLongFilename -Get the long name of the last file or directory retrived with +Get the long name of the last file or directory retrived with GetDirEntry. Also works for FindFirstFile and FindNextFile. If a long name doesn't exist, it returns the short name instead. @@ -1156,14 +1156,14 @@ bool FAT_GetLongFilename (char* filename) strncpy (filename, lfnName, MAX_FILENAME_LENGTH - 1); filename[MAX_FILENAME_LENGTH - 1] = '\0'; - + return true; } /*----------------------------------------------------------------- FAT_GetFilename -Get the alias (short name) of the file or directory stored in +Get the alias (short name) of the file or directory stored in dirEntry DIR_ENT dirEntry: IN a valid directory table entry char* alias OUT: will be filled with the alias (short filename), @@ -1192,7 +1192,7 @@ bool FAT_GetFilename (DIR_ENT dirEntry, char* alias) } } else - { + { // Copy the filename from the dirEntry to the string for (i = 0; (i < 8) && (dirEntry.name[i] != ' '); i++) { @@ -1230,7 +1230,7 @@ bool FAT_GetAlias (char* alias) } // Read in the last accessed directory entry disc_ReadSector ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector, globalBuffer); - + return FAT_GetFilename (((DIR_ENT*)globalBuffer)[wrkDirOffset], alias); } @@ -1244,7 +1244,7 @@ u32 FAT_GetFileSize (void) { // Read in the last accessed directory entry disc_ReadSector ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector, globalBuffer); - + return ((DIR_ENT*)globalBuffer)[wrkDirOffset].fileSize; } @@ -1257,7 +1257,7 @@ u32 FAT_GetFileCluster (void) { // Read in the last accessed directory entry disc_ReadSector ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector, globalBuffer); - + return (((DIR_ENT*)globalBuffer)[wrkDirOffset].startCluster) | (((DIR_ENT*)globalBuffer)[wrkDirOffset].startClusterHigh << 16); } @@ -1270,7 +1270,7 @@ u8 FAT_GetFileAttributes (void) { // Read in the last accessed directory entry disc_ReadSector ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector, globalBuffer); - + return ((DIR_ENT*)globalBuffer)[wrkDirOffset].attrib; } @@ -1294,7 +1294,7 @@ u8 FAT_SetFileAttributes (const char* filename, u8 attributes, u8 mask) disc_ReadSector ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector, globalBuffer); ((DIR_ENT*)globalBuffer)[wrkDirOffset].attrib = (((DIR_ENT*)globalBuffer)[wrkDirOffset].attrib & ~(mask & 0x27)) | (attributes & 0x27); // 0x27 is he settable attributes - + disc_WriteSector ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector, globalBuffer); return ((DIR_ENT*)globalBuffer)[wrkDirOffset].attrib; @@ -1305,7 +1305,7 @@ u8 FAT_SetFileAttributes (const char* filename, u8 attributes, u8 mask) time_t FAT_FileTimeToCTime (u16 fileTime, u16 fileDate) { struct tm timeInfo; - + timeInfo.tm_year = (fileDate >> 9) + 80; // years since midnight January 1970 timeInfo.tm_mon = ((fileDate >> 5) & 0xf) - 1; // Months since january timeInfo.tm_mday = fileDate & 0x1f; // Day of the month @@ -1326,7 +1326,7 @@ time_t FAT_GetFileCreationTime (void) { // Read in the last accessed directory entry disc_ReadSector ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector, globalBuffer); - + return FAT_FileTimeToCTime(((DIR_ENT*)globalBuffer)[wrkDirOffset].cTime, ((DIR_ENT*)globalBuffer)[wrkDirOffset].cDate); } @@ -1339,7 +1339,7 @@ time_t FAT_GetFileLastWriteTime (void) { // Read in the last accessed directory entry disc_ReadSector ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector, globalBuffer); - + return FAT_FileTimeToCTime(((DIR_ENT*)globalBuffer)[wrkDirOffset].mTime, ((DIR_ENT*)globalBuffer)[wrkDirOffset].mDate); } #endif @@ -1374,8 +1374,8 @@ DIR_ENT FAT_DirEntFromPath (const char* path) return; } #endif - - if (path[pathPos] == '/') + + if (path[pathPos] == '/') { dirCluster = filesysRootDirClus; // Start at root directory } @@ -1383,13 +1383,13 @@ DIR_ENT FAT_DirEntFromPath (const char* path) { dirCluster = curWorkDirCluster; // Start at current working dir } - + // Eat any slash / while ((path[pathPos] == '/') && (path[pathPos] != '\0')) { pathPos++; } - + // Search until can't continue found = false; notFound = false; @@ -1437,7 +1437,7 @@ DIR_ENT FAT_DirEntFromPath (const char* path) flagLFN = true; } } - + // Add end of string char name[namePos] = '\0'; @@ -1497,7 +1497,7 @@ DIR_ENT FAT_DirEntFromPath (const char* path) dirEntry = FAT_GetDirEntry (dirCluster, 1, SEEK_CUR); } } - + if (found && ((dirEntry.attrib & ATTRIB_DIR) == ATTRIB_DIR) && (path[pathPos] != '\0')) // It has found a directory from within the path that needs to be followed { @@ -1505,7 +1505,7 @@ DIR_ENT FAT_DirEntFromPath (const char* path) dirCluster = dirEntry.startCluster | (dirEntry.startClusterHigh << 16); } } - + if (notFound) { dirEntry.name[0] = FILE_FREE; @@ -1534,11 +1534,11 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) bool flagLFN, dotSeen; char fileAlias[13] = {0}; int tailNum; - + unsigned char chkSum = 0; - + u32 oldWorkDirCluster; - + DIR_ENT* dirEntries = (DIR_ENT*)globalBuffer; u32 dirCluster; int secOffset; @@ -1566,7 +1566,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) { curWorkDirCluster = filesysRootDirClus; } - + pathPos = 0; filePos = 0; flagLFN = false; @@ -1576,7 +1576,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) if (path[pathPos + filePos] == '/') { filename[filePos] = '\0'; - if (FAT_chdir(filename) == false) + if (FAT_chdir(filename) == false) { curWorkDirCluster = oldWorkDirCluster; return false; // Couldn't change directory @@ -1587,17 +1587,17 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) filename[filePos] = path[pathPos + filePos]; filePos++; } - + // Skip over last slashes while (path[pathPos] == '/') pathPos++; - + // Check if the filename has a leading "." // If so, it is an LFN if (path[pathPos] == '.') { flagLFN = true; } - + // Copy name from path filePos = 0; dotSeen = false; @@ -1622,12 +1622,12 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) flagLFN = true; } } - + if (filePos == 0) // No filename { return false; } - + // Check if a long filename was specified if (filePos > 12) { @@ -1638,7 +1638,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) if (!flagLFN && (strrchr (filename, '.') != NULL) && (strlen(strrchr(filename, '.')) > 4)) { flagLFN = true; } - + lfnPos = (filePos - 1) / 13; // Add end of string char @@ -1646,8 +1646,8 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) // Clear remaining chars while (filePos < MAX_FILENAME_LENGTH) filename[filePos++] = 0x01; // Set for LFN compatibility - - + + if (flagLFN) { // Generate short filename - always a 2 digit number for tail @@ -1666,7 +1666,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) // Pad Alias with underscores while (aliasPos < 5) fileAlias[aliasPos++] = '_'; - + fileAlias[5] = '~'; fileAlias[8] = '.'; fileAlias[9] = ' '; @@ -1692,14 +1692,14 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) } else { aliasPos = 9; } - + // Pad Alias extension with spaces while (aliasPos < 12) fileAlias[aliasPos++] = ' '; - + fileAlias[12] = '\0'; - - + + // Get a valid tail number tailNum = 0; do { @@ -1707,7 +1707,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) fileAlias[6] = 0x30 + ((tailNum / 10) % 10); // 10's digit fileAlias[7] = 0x30 + (tailNum % 10); // 1's digit } while ((FAT_DirEntFromPath(fileAlias).name[0] != FILE_FREE) && (tailNum < 100)); - + if (tailNum < 100) // Found an alias not being used { // Calculate file checksum @@ -1725,7 +1725,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) { return false; } - + dirEntryLength = lfnPos + 2; } else // Its not a long file name @@ -1743,7 +1743,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) dirEntryLength = 1; } - + // Change dirEntry name to match alias for (aliasPos = 0; ((fileAlias[aliasPos] != '.') && (fileAlias[aliasPos] != '\0') && (aliasPos < 8)); aliasPos++) { @@ -1775,12 +1775,12 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) maxSectors = (dirCluster == FAT16_ROOT_DIR_CLUSTER ? (filesysData - filesysRootDir) : filesysSecPerClus); firstSector = (dirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(dirCluster)); disc_ReadSector (firstSector + secOffset, dirEntries); - + dirEntryRemain = dirEntryLength; tempDirCluster = dirCluster; tempSecOffset = secOffset; tempEntryOffset = entryOffset; - + // Search for a large enough space to fit in new directory entry while ((dirEntries[entryOffset].name[0] != FILE_LAST) && (dirEntryRemain > 0)) { @@ -1803,7 +1803,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) { dirCluster = FAT_NextCluster(dirCluster); } - firstSector = FAT_ClustToSect(dirCluster); + firstSector = FAT_ClustToSect(dirCluster); } else if ((dirCluster == FAT16_ROOT_DIR_CLUSTER) && (secOffset == (filesysData - filesysRootDir))) { @@ -1824,7 +1824,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) } // Modifying the last directory is a special case - have to erase following entries - if (dirEntries[entryOffset].name[0] == FILE_LAST) + if (dirEntries[entryOffset].name[0] == FILE_LAST) { dirEndFlag = true; } @@ -1843,7 +1843,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) } // Add new directory entry - while (dirEntryRemain > 0) + while (dirEntryRemain > 0) { // Move to next entry, first pass advances from last used entry entryOffset++; @@ -1868,7 +1868,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) { dirCluster = FAT_NextCluster(dirCluster); } - firstSector = FAT_ClustToSect(dirCluster); + firstSector = FAT_ClustToSect(dirCluster); } else if ((dirCluster == FAT16_ROOT_DIR_CLUSTER) && (secOffset == (filesysData - filesysRootDir))) { @@ -1900,7 +1900,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) lfnEntry.flag = ATTRIB_LFN; lfnEntry.reserved1 = 0; lfnEntry.reserved2 = 0; - + *((DIR_ENT_LFN*)&dirEntries[entryOffset]) = lfnEntry; lfnPos --; lfnEntry.ordinal = 0; @@ -1914,7 +1914,7 @@ bool FAT_AddDirEntry (const char* path, DIR_ENT newDirEntry) dirEntryRemain--; } - + // Write directory back to disk disc_WriteSector (firstSector + secOffset, dirEntries); @@ -1930,7 +1930,7 @@ 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, +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) @@ -1963,7 +1963,7 @@ 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, +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) @@ -1971,7 +1971,7 @@ FILE_TYPE FAT_FindFirstFile(char* filename) // Get the first directory entry DIR_ENT file; file = FAT_GetDirEntry (curWorkDirCluster, 1, SEEK_SET); - + if (file.name[0] == FILE_FREE) { return FT_NONE; // Did not find a file @@ -1996,7 +1996,7 @@ FAT_FindFirstFileLFN Gets the long file name of the first directory entry and resets the count (can be a file or subdirectory) char* lfn: OUT long file name, must be at least 256 chars long -FILE_TYPE return: OUT returns FT_NONE if failed, +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_FindFirstFileLFN(char* lfn) @@ -2012,7 +2012,7 @@ FAT_FindNextFileLFN Gets the long file name of the next directory entry (can be a file or subdirectory) char* lfn: OUT long file name, must be at least 256 chars long -FILE_TYPE return: OUT returns FT_NONE if failed, +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_FindNextFileLFN(char* lfn) @@ -2026,29 +2026,29 @@ FILE_TYPE FAT_FindNextFileLFN(char* lfn) /*----------------------------------------------------------------- FAT_FileExists -Returns the type of file +Returns the type of file char* filename: IN filename of the file to look for -FILE_TYPE return: OUT returns FT_NONE if there is now file with +FILE_TYPE return: OUT returns FT_NONE if there is now file with that name, FT_FILE if it is a file and FT_DIR if it is a directory -----------------------------------------------------------------*/ FILE_TYPE FAT_FileExists(const char* filename) { - DIR_ENT dirEntry; - // Get the dirEntry for the path specified - dirEntry = FAT_DirEntFromPath (filename); - - if (dirEntry.name[0] == FILE_FREE) - { - return FT_NONE; - } - else if (dirEntry.attrib & ATTRIB_DIR) - { - return FT_DIR; - } - else - { - return FT_FILE; - } + DIR_ENT dirEntry; + // Get the dirEntry for the path specified + dirEntry = FAT_DirEntFromPath (filename); + + if (dirEntry.name[0] == FILE_FREE) + { + return FT_NONE; + } + else if (dirEntry.attrib & ATTRIB_DIR) + { + return FT_DIR; + } + else + { + return FT_FILE; + } } /*----------------------------------------------------------------- @@ -2074,7 +2074,7 @@ u32 FAT_GetFileSystemTotalSize (void) /*----------------------------------------------------------------- FAT_chdir Changes the current working directory -const char* path: IN null terminated string of directory separated by +const char* path: IN null terminated string of directory separated by forward slashes, / is root bool return: OUT returns true if successful -----------------------------------------------------------------*/ @@ -2090,7 +2090,7 @@ bool FAT_chdir (const char* path) { return true; } - + dir = FAT_DirEntFromPath (path); if (((dir.attrib & ATTRIB_DIR) == ATTRIB_DIR) && (dir.name[0] != FILE_FREE)) @@ -2111,7 +2111,7 @@ bool FAT_chdir (const char* path) return true; } else - { + { // Couldn't change directory - wrong path specified return false; } @@ -2120,12 +2120,12 @@ bool FAT_chdir (const char* path) /*----------------------------------------------------------------- FAT_fopen(filename, mode) Opens a file -const char* path: IN null terminated string of filename and path +const char* path: IN null terminated string of filename and path separated by forward slashes, / is root const char* mode: IN mode to open file in Supported modes: "r", "r+", "w", "w+", "a", "a+", don't use "b" or "t" in any mode, as all files are openned in binary mode -FAT_FILE* return: OUT handle to open file, returns NULL if the file +FAT_FILE* return: OUT handle to open file, returns NULL if the file couldn't be openned -----------------------------------------------------------------*/ FAT_FILE* FAT_fopen(const char* path, const char* mode) @@ -2149,10 +2149,10 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) { return NULL; } - + // Get the dirEntry for the path specified dirEntry = FAT_DirEntFromPath (path); - + // Check that it is not a directory if (dirEntry.attrib & ATTRIB_DIR) { @@ -2174,7 +2174,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) // Find a free file buffer for (fileNum = 0; (fileNum < MAX_FILES_OPEN) && (openFiles[fileNum].inUse == true); fileNum++); - + if (fileNum == MAX_FILES_OPEN) // No free files { return NULL; @@ -2191,7 +2191,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) { return NULL; } - + file->read = true; #ifdef CAN_WRITE_TO_DISC file->write = ( strchr(mode, '+') != NULL ); //(mode[1] == '+'); @@ -2199,13 +2199,13 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) file->write = false; #endif file->append = false; - + // Store information about position within the file, for use // by FAT_fread, FAT_fseek, etc. file->firstCluster = dirEntry.startCluster | (dirEntry.startClusterHigh << 16); - + #ifdef CAN_WRITE_TO_DISC - // Check if file is openned for random. If it is, and currently has no cluster, one must be + // Check if file is openned for random. If it is, and currently has no cluster, one must be // assigned to it. if (file->write && file->firstCluster == CLUSTER_FREE) { @@ -2223,7 +2223,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) disc_WriteSector (file->dirEntSector, globalBuffer); } #endif - + file->length = dirEntry.fileSize; file->curPos = 0; file->curClus = dirEntry.startCluster | (dirEntry.startClusterHigh << 16); @@ -2234,7 +2234,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) file->appByte = 0; file->appClus = 0; file->appSect = 0; - + disc_ReadSector( FAT_ClustToSect( file->curClus), file->readBuffer); file->inUse = true; // We're using this file now @@ -2248,7 +2248,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) { dirEntry.attrib = ATTRIB_ARCH; dirEntry.reserved = 0; - + // Time and date set to system time and date dirEntry.cTime_ms = 0; dirEntry.cTime = getRTCtoFileTime(); @@ -2257,12 +2257,12 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) dirEntry.mTime = getRTCtoFileTime(); dirEntry.mDate = getRTCtoFileDate(); } - else // Already a file entry + else // Already a file entry { // Free any clusters used FAT_ClearLinks (dirEntry.startCluster | (dirEntry.startClusterHigh << 16)); } - + // Get a cluster to use startCluster = FAT_LinkFreeCluster (CLUSTER_FREE); if (startCluster == CLUSTER_FREE) // Couldn't get a free cluster @@ -2298,13 +2298,13 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) ((DIR_ENT*) globalBuffer)[file->dirEntOffset] = dirEntry; disc_WriteSector (file->dirEntSector, globalBuffer); } - + // Now that file is created, open it file->read = ( strchr(mode, '+') != NULL ); //(mode[1] == '+'); file->write = true; file->append = false; - + // Store information about position within the file, for use // by FAT_fread, FAT_fseek, etc. file->firstCluster = startCluster; @@ -2318,7 +2318,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) file->appByte = 0; file->appClus = 0; file->appSect = 0; - + // Empty file, so empty read buffer memset (file->readBuffer, 0, BYTE_PER_READ); file->inUse = true; // We're using this file now @@ -2332,7 +2332,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) { dirEntry.attrib = ATTRIB_ARCH; dirEntry.reserved = 0; - + // Time and date set to system time and date dirEntry.cTime_ms = 0; dirEntry.cTime = getRTCtoFileTime(); @@ -2352,13 +2352,13 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) } dirEntry.startCluster = (startCluster & 0xFFFF); dirEntry.startClusterHigh = ((startCluster >> 16) & 0xFFFF); - + if(!FAT_AddDirEntry (path, dirEntry)) return NULL; - + // Get the newly created dirEntry dirEntry = FAT_DirEntFromPath (path); - + // Store append cluster file->appClus = startCluster; @@ -2377,7 +2377,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) { return NULL; } - + // Store cluster position into the directory entry dirEntry.startCluster = (file->firstCluster & 0xFFFF); dirEntry.startClusterHigh = ((file->firstCluster >> 16) & 0xFFFF); @@ -2387,7 +2387,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) // Store append cluster file->appClus = startCluster; - + } else { // Follow cluster list until last one is found @@ -2410,7 +2410,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) file->read = ( strchr(mode, '+') != NULL ); file->write = false; file->append = true; - + // Calculate the sector and byte of the current position, // and store them file->appSect = (dirEntry.fileSize % filesysBytePerClus) / BYTE_PER_READ; @@ -2424,7 +2424,7 @@ FAT_FILE* FAT_fopen(const char* path, const char* mode) file->curClus = file->appClus; file->curSect = file->appSect; file->curByte = file->appByte; - + // Read into buffer disc_ReadSector( FAT_ClustToSect(file->curClus) + file->curSect, file->readBuffer); file->inUse = true; // We're using this file now @@ -2464,7 +2464,7 @@ bool FAT_fclose (FAT_FILE* file) disc_CacheFlush(); } #endif - file->inUse = false; + file->inUse = false; return true; } else @@ -2515,14 +2515,14 @@ int FAT_fseek(FAT_FILE* file, s32 offset, int origin) } // Can't seek in append only mode - if (!file->read && !file->write) + if (!file->read && !file->write) { return -1; } curPos = file->curPos; - switch (origin) + switch (origin) { case SEEK_SET: if (offset >= 0) @@ -2537,13 +2537,13 @@ int FAT_fseek(FAT_FILE* file, s32 offset, int origin) if (offset >= 0) { position = curPos + offset; - } + } else if ( (u32)(offset * -1) >= curPos ) { // Tried to seek before start of file position = 0; } - else + else { // Using u32 to maintain 32 bits of accuracy position = curPos - (u32)(offset * -1); @@ -2560,7 +2560,7 @@ int FAT_fseek(FAT_FILE* file, s32 offset, int origin) // Tried to seek before start of file position = 0; } - else + else { // Using u32 to maintain 32 bits of accuracy position = file->length - (u32)(offset * -1); @@ -2575,7 +2575,7 @@ int FAT_fseek(FAT_FILE* file, s32 offset, int origin) // Tried to go past end of file position = file->length; } - + // Save position file->curPos = position; @@ -2608,14 +2608,14 @@ int FAT_fseek(FAT_FILE* file, s32 offset, int origin) nextCluster = FAT_NextCluster (cluster); } // Check if ran out of clusters, and the file is being written to - if ((clusCount >= 0) && (file->write || file->append)) + if ((clusCount >= 0) && (file->write || file->append)) { // Set flag to allocate a new cluster file->curSect = filesysSecPerClus; file->curByte = 0; } file->curClus = cluster; - + // Reload sector buffer for new position in file, if it is a different sector if ((curPos ^ position) >= BYTE_PER_READ) { @@ -2645,7 +2645,7 @@ u32 FAT_fread (void* buffer, u32 size, u32 count, FAT_FILE* file) int curSect; u32 curClus; u32 tempNextCluster; - + int tempVar; char* data = (char*)buffer; @@ -2678,14 +2678,14 @@ u32 FAT_fread (void* buffer, u32 size, u32 count, FAT_FILE* file) if (tempVar > remain) tempVar = remain; - if ((tempVar < BYTE_PER_READ) && flagNoError) + if ((tempVar < BYTE_PER_READ) && flagNoError) { memcpy(data, &(file->readBuffer[curByte]), tempVar); remain -= tempVar; data += tempVar; curByte += tempVar; - if (curByte >= BYTE_PER_READ) + if (curByte >= BYTE_PER_READ) { curByte = 0; curSect++; @@ -2694,7 +2694,7 @@ u32 FAT_fread (void* buffer, u32 size, u32 count, FAT_FILE* file) // align to cluster // tempVar is number of sectors to read - if (remain > (filesysSecPerClus - curSect) * BYTE_PER_READ) + if (remain > (filesysSecPerClus - curSect) * BYTE_PER_READ) { tempVar = filesysSecPerClus - curSect; } else { @@ -2789,7 +2789,7 @@ u32 FAT_fread (void* buffer, u32 size, u32 count, FAT_FILE* file) FAT_fwrite(buffer, size, count, file) Writes size * count bytes into file from buffer, starting from current position. It then sets the current position to the - byte after the last byte written. If the file was openned in + byte after the last byte written. If the file was openned in append mode it always writes to the end of the file. const void* buffer IN: Pointer to buffer containing data. Should be at least as big as the number of bytes to be written. @@ -2870,7 +2870,7 @@ u32 FAT_fwrite (const void* buffer, u32 size, u32 count, FAT_FILE* file) disc_ReadSector( FAT_ClustToSect( curClus), writeBuffer); } } - + // Align to sector tempVar = BYTE_PER_READ - curByte; if (tempVar > remain) @@ -2885,9 +2885,9 @@ u32 FAT_fwrite (const void* buffer, u32 size, u32 count, FAT_FILE* file) // Write buffer back to disk disc_WriteSector (curSect + FAT_ClustToSect(curClus), writeBuffer); - + // Move onto next sector - if (curByte >= BYTE_PER_READ) + if (curByte >= BYTE_PER_READ) { curByte = 0; curSect++; @@ -2896,7 +2896,7 @@ u32 FAT_fwrite (const void* buffer, u32 size, u32 count, FAT_FILE* file) // Align to cluster // tempVar is number of sectors to write - if (remain > (filesysSecPerClus - curSect) * BYTE_PER_READ) + if (remain > (filesysSecPerClus - curSect) * BYTE_PER_READ) { tempVar = filesysSecPerClus - curSect; } else { @@ -2964,7 +2964,7 @@ u32 FAT_fwrite (const void* buffer, u32 size, u32 count, FAT_FILE* file) remain -= tempVar * BYTE_PER_READ; curSect += tempVar; } - + // Last remaining sector // Check if sector wanted is different to the one started with if ( (( (file->append ? file->appByte : file->curByte) + length) >= BYTE_PER_READ) && flagNoError) @@ -2984,7 +2984,7 @@ u32 FAT_fwrite (const void* buffer, u32 size, u32 count, FAT_FILE* file) disc_WriteSector( curSect + FAT_ClustToSect( curClus), writeBuffer); } } - + // Amount read is the originally requested amount minus stuff remaining length = length - remain; @@ -3041,14 +3041,14 @@ int FAT_remove (const char* path) u32 oldWorkDirCluster; char checkFilename[13]; FILE_TYPE checkFiletype; - + dirEntry = FAT_DirEntFromPath (path); if (dirEntry.name[0] == FILE_FREE) { return -1; } - + // Only delete directories if the directory is entry if (dirEntry.attrib & ATTRIB_DIR) { @@ -3062,10 +3062,10 @@ int FAT_remove (const char* path) { checkFiletype = FAT_FindNextFile (checkFilename); } - + // Change back to working directory curWorkDirCluster = oldWorkDirCluster; - + // Check that the directory is empty if (checkFiletype != FT_NONE) { @@ -3084,7 +3084,7 @@ int FAT_remove (const char* path) disc_ReadSector ( (wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector , globalBuffer); ((DIR_ENT*)globalBuffer)[wrkDirOffset].name[0] = FILE_FREE; disc_WriteSector ( (wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? filesysRootDir : FAT_ClustToSect(wrkDirCluster)) + wrkDirSector , globalBuffer); - + // Flush any sectors in disc cache disc_CacheFlush(); @@ -3095,7 +3095,7 @@ int FAT_remove (const char* path) #ifdef CAN_WRITE_TO_DISC /*----------------------------------------------------------------- FAT_mkdir (path) -Makes a new directory, so long as no other directory or file has +Makes a new directory, so long as no other directory or file has the same name. const char* path IN: Path and filename of directory to make int return OUT: zero if successful, non-zero if not @@ -3123,7 +3123,7 @@ int FAT_mkdir (const char* path) { curWorkDirCluster = filesysRootDirClus; } - + pathPos = 0; filePos = 0; @@ -3132,7 +3132,7 @@ int FAT_mkdir (const char* path) if (path[pathPos + filePos] == '/') { pathname[filePos] = '\0'; - if (FAT_chdir(pathname) == false) + if (FAT_chdir(pathname) == false) { curWorkDirCluster = oldDirCluster; return -1; // Couldn't change directory @@ -3236,9 +3236,9 @@ FAT_fgets (char *tgtBuffer, int num, FAT_FILE* file) Gets a up to num bytes from file, stopping at the first newline. -CAUTION: does not do strictly streaming. I.e. it's +CAUTION: does not do strictly streaming. I.e. it's reading more then needed bytes and seeking back. - shouldn't matter for random access + shouldn't matter for random access char *tgtBuffer OUT: buffer to write to int num IN: size of target buffer @@ -3250,62 +3250,62 @@ bool return OUT: character if successful, EOF if not * Added check for unix style text files * Removed seek when no newline is found, since it isn't necessary -------------------------------------------------------------------*/ -char *FAT_fgets(char *tgtBuffer, int num, FAT_FILE* file) -{ +char *FAT_fgets(char *tgtBuffer, int num, FAT_FILE* file) +{ u32 curPos; u32 readLength; char *returnChar; - - // invalid filehandle + + // invalid filehandle if (file == NULL) { - return NULL ; + return NULL ; } - - // end of file + + // end of file if (FAT_feof(file)==true) { - return NULL ; - } - - // save current position - curPos = FAT_ftell(file); - - // read the full buffer (max string chars is num-1 and one end of string \0 - readLength = FAT_fread(tgtBuffer,1,num-1,file) ; - - // mark least possible end of string - tgtBuffer[readLength] = '\0' ; - - if (readLength==0) { - // return error - return NULL ; - } - - // get position of first return '\r' - returnChar = strchr(tgtBuffer,'\r'); - + return NULL ; + } + + // save current position + curPos = FAT_ftell(file); + + // read the full buffer (max string chars is num-1 and one end of string \0 + readLength = FAT_fread(tgtBuffer,1,num-1,file) ; + + // mark least possible end of string + tgtBuffer[readLength] = '\0' ; + + if (readLength==0) { + // return error + return NULL ; + } + + // get position of first return '\r' + returnChar = strchr(tgtBuffer,'\r'); + // if no return is found, search for a newline if (returnChar == NULL) { returnChar = strchr(tgtBuffer,'\n'); } - - // Mark the return, if existant, as end of line/string - if (returnChar!=NULL) { - *returnChar++ = 0 ; - if (*returnChar=='\n') { // catch newline too when jumping over the end - // return to location after \r\n (strlen+2) - FAT_fseek(file,curPos+strlen(tgtBuffer)+2,SEEK_SET) ; - return tgtBuffer ; - } else { - // return to location after \r (strlen+1) - FAT_fseek(file,curPos+strlen(tgtBuffer)+1,SEEK_SET) ; - return tgtBuffer ; + + // Mark the return, if existant, as end of line/string + if (returnChar!=NULL) { + *returnChar++ = 0 ; + if (*returnChar=='\n') { // catch newline too when jumping over the end + // return to location after \r\n (strlen+2) + FAT_fseek(file,curPos+strlen(tgtBuffer)+2,SEEK_SET) ; + return tgtBuffer ; + } else { + // return to location after \r (strlen+1) + FAT_fseek(file,curPos+strlen(tgtBuffer)+1,SEEK_SET) ; + return tgtBuffer ; } } - - return tgtBuffer ; + + return tgtBuffer ; } #ifdef CAN_WRITE_TO_DISC @@ -3322,20 +3322,20 @@ bool return OUT: number of characters written if successful, * Uses FAT_FILE instead of int * writtenBytes is now u32 instead of int -------------------------------------------------------------------*/ -int FAT_fputs (const char *string, FAT_FILE* file) -{ +int FAT_fputs (const char *string, FAT_FILE* file) +{ u32 writtenBytes; - // save string except end of string '\0' - writtenBytes = FAT_fwrite((void *)string, 1, strlen(string), file); + // save string except end of string '\0' + writtenBytes = FAT_fwrite((void *)string, 1, strlen(string), file); - // check if we had an error - if (writtenBytes != strlen(string)) - { - // return EOF error + // check if we had an error + if (writtenBytes != strlen(string)) + { + // return EOF error return EOF; } - // return the charcount written - return writtenBytes ; + // return the charcount written + return writtenBytes ; } #endif diff --git a/backends/platform/ds/arm9/source/fat/gba_nds_fat.h b/backends/platform/ds/arm9/source/fat/gba_nds_fat.h index b238182e14..c554cc80f6 100644 --- a/backends/platform/ds/arm9/source/fat/gba_nds_fat.h +++ b/backends/platform/ds/arm9/source/fat/gba_nds_fat.h @@ -147,7 +147,7 @@ bool FAT_GetAlias (char* alias); /*----------------------------------------------------------------- FAT_GetLongFilename -Get the long name of the last file or directory retrived with +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 @@ -210,7 +210,7 @@ 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, +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); @@ -220,7 +220,7 @@ 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, +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); @@ -230,7 +230,7 @@ FAT_FindFirstFileLFN Gets the long file name of the first directory entry and resets the count (can be a file or subdirectory) char* lfn: OUT long file name, must be at least 256 chars long -FILE_TYPE return: OUT returns FT_NONE if failed, +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_FindFirstFileLFN(char* lfn); @@ -240,16 +240,16 @@ FAT_FindNextFileLFN Gets the long file name of the next directory entry (can be a file or subdirectory) char* lfn: OUT long file name, must be at least 256 chars long -FILE_TYPE return: OUT returns FT_NONE if failed, +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_FindNextFileLFN(char* lfn); /*----------------------------------------------------------------- FAT_FileExists -Returns the type of file +Returns the type of file char* filename: IN filename of the file to look for -FILE_TYPE return: OUT returns FT_NONE if there is now file with +FILE_TYPE return: OUT returns FT_NONE if there is now file with that name, FT_FILE if it is a file and FT_DIR if it is a directory -----------------------------------------------------------------*/ FILE_TYPE FAT_FileExists (const char* filename); @@ -269,7 +269,7 @@ u32 FAT_GetFileSystemTotalSize (void); /*----------------------------------------------------------------- FAT_chdir Changes the current working directory -const char* path: IN null terminated string of directory separated by +const char* path: IN null terminated string of directory separated by forward slashes, / is root bool return: OUT returns true if successful -----------------------------------------------------------------*/ @@ -282,12 +282,12 @@ bool FAT_chdir (const char* path); /*----------------------------------------------------------------- FAT_fopen(filename, mode) Opens a file -const char* path: IN null terminated string of filename and path +const char* path: IN null terminated string of filename and path separated by forward slashes, / is root const char* mode: IN mode to open file in Supported modes: "r", "r+", "w", "w+", "a", "a+", don't use "b" or "t" in any mode, as all files are openned in binary mode -FAT_FILE* return: OUT handle to open file, returns -1 if the file +FAT_FILE* return: OUT handle to open file, returns -1 if the file couldn't be openned -----------------------------------------------------------------*/ FAT_FILE* FAT_fopen(const char* path, const char* mode); @@ -338,7 +338,7 @@ u32 FAT_fread (void* buffer, u32 size, u32 count, FAT_FILE* file); FAT_fwrite(buffer, size, count, file) Writes size * count bytes into file from buffer, starting from current position. It then sets the current position to the - byte after the last byte written. If the file was openned in + byte after the last byte written. If the file was openned in append mode it always writes to the end of the file. const void* buffer IN: Pointer to buffer containing data. Should be at least as big as the number of bytes to be written. @@ -371,7 +371,7 @@ int FAT_remove (const char* path); #ifdef CAN_WRITE_TO_DISC /*----------------------------------------------------------------- FAT_mkdir (path) -Makes a new directory, so long as no other directory or file has +Makes a new directory, so long as no other directory or file has the same name. const char* path IN: Path and filename of directory to make int return OUT: zero if successful, non-zero if not @@ -403,9 +403,9 @@ FAT_fgets (char *tgtBuffer, int num, FAT_FILE* file) Gets a up to num bytes from file, stopping at the first newline. -CAUTION: does not do strictly streaming. I.e. it's +CAUTION: does not do strictly streaming. I.e. it's reading more then needed bytes and seeking back. - shouldn't matter for random access + shouldn't matter for random access char *tgtBuffer OUT: buffer to write to int num IN: size of target buffer diff --git a/backends/platform/ds/arm9/source/fat/io_dldi.h b/backends/platform/ds/arm9/source/fat/io_dldi.h index 053de3a94c..034c6aace3 100644 --- a/backends/platform/ds/arm9/source/fat/io_dldi.h +++ b/backends/platform/ds/arm9/source/fat/io_dldi.h @@ -1,8 +1,8 @@ /* - io_dldi.h + io_dldi.h Reserved space for new drivers - + 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 diff --git a/backends/platform/ds/arm9/source/fat/io_dldi.s b/backends/platform/ds/arm9/source/fat/io_dldi.s index c2314e772d..311d43f3ff 100644 --- a/backends/platform/ds/arm9/source/fat/io_dldi.s +++ b/backends/platform/ds/arm9/source/fat/io_dldi.s @@ -18,7 +18,7 @@ .byte 0x0F @32KiB @ Log [base-2] of the size of this driver in bytes. .byte 0x00 @ Sections to fix .byte 0x0F @32KiB @ Log [base-2] of the allocated space in bytes. - + @--------------------------------------------------------------------------------- @ Text identifier - can be anything up to 47 chars + terminating null -- 16 bytes .align 4 @@ -42,13 +42,13 @@ _dldi_driver_name: _io_dldi: .ascii "DLDI" @ ioType .word 0x00000000 @ Features - .word _DLDI_startup @ - .word _DLDI_isInserted @ + .word _DLDI_startup @ + .word _DLDI_isInserted @ .word _DLDI_readSectors @ Function pointers to standard device driver functions - .word _DLDI_writeSectors @ - .word _DLDI_clearStatus @ - .word _DLDI_shutdown @ - + .word _DLDI_writeSectors @ + .word _DLDI_clearStatus @ + .word _DLDI_shutdown @ + @--------------------------------------------------------------------------------- _DLDI_startup: diff --git a/backends/platform/ds/arm9/source/fat/io_efa2.c b/backends/platform/ds/arm9/source/fat/io_efa2.c index f3aa65cfcb..468361969e 100644 --- a/backends/platform/ds/arm9/source/fat/io_efa2.c +++ b/backends/platform/ds/arm9/source/fat/io_efa2.c @@ -47,7 +47,7 @@ See gba_nds_fat.txt for help and license details. // ID of Samsung K9K1G NAND flash chip #define EFA2_NAND_ID 0xEC79A5C0 -// first sector of udisk +// first sector of udisk #define EFA2_UDSK_START 0x40 // @@ -101,7 +101,7 @@ void efa2_nand_lock(void) { // // Set NAND Flash chip enable and write protection bits ? -// +// // val | ~CE | ~WP | // -----+-----+-----+ // 0 | 0 | 0 | @@ -125,7 +125,7 @@ inline void efa2_nand_reset(void) { // // Read out NAND ID information, could be used for card detection -// +// // | EFA2 1GBit | // ------------------+------------+ // maker code | 0xEC | @@ -166,7 +166,7 @@ EFA2_ClearStatus Reads and checks NAND status information bool return OUT: true if NAND is idle -----------------------------------------------------------------*/ -bool EFA2_ClearStatus (void) +bool EFA2_ClearStatus (void) { // tbd: currently there is no write support, so always return // true, there is no possibility for pending operations @@ -178,7 +178,7 @@ EFA2_IsInserted Checks to see if the NAND chip used by the EFA2 is present bool return OUT: true if the correct NAND chip is found -----------------------------------------------------------------*/ -bool EFA2_IsInserted (void) +bool EFA2_IsInserted (void) { EFA2_ClearStatus(); return (efa2_nand_id() == EFA2_NAND_ID); @@ -223,7 +223,7 @@ bool EFA2_ReadSectors (u32 sector, u8 numSecs, void* buffer) efa2_nand_reset(); // set NAND to READ1 operation mode and transfer page address - REG_EFA2_NAND_CMD = 0x00; // write READ1 command + REG_EFA2_NAND_CMD = 0x00; // write READ1 command REG_EFA2_NAND_WR = 0x00; // write address [7:0] REG_EFA2_NAND_WR = (page ) & 0xff; // write address [15:8] REG_EFA2_NAND_WR = (page >> 8 ) & 0xff; // write address[23:16] @@ -280,7 +280,7 @@ bool EFA2_WriteSectors (u32 sector, u8 numSecs, void* buffer) EFA2_Shutdown unload the EFA2 interface -----------------------------------------------------------------*/ -bool EFA2_Shutdown(void) +bool EFA2_Shutdown(void) { return EFA2_ClearStatus(); } @@ -368,7 +368,7 @@ See gba_nds_fat.txt for help and license details. // ID of Samsung K9K1G NAND flash chip #define EFA2_NAND_ID 0xEC79A5C0 -// first sector of udisk +// first sector of udisk #define EFA2_UDSK_START 0x40 // @@ -422,7 +422,7 @@ void efa2_nand_lock(void) { // // Set NAND Flash chip enable and write protection bits ? -// +// // val | ~CE | ~WP | // -----+-----+-----+ // 0 | 0 | 0 | @@ -446,7 +446,7 @@ inline void efa2_nand_reset(void) { // // Read out NAND ID information, could be used for card detection -// +// // | EFA2 1GBit | // ------------------+------------+ // maker code | 0xEC | @@ -487,7 +487,7 @@ EFA2_ClearStatus Reads and checks NAND status information bool return OUT: true if NAND is idle -----------------------------------------------------------------*/ -bool EFA2_ClearStatus (void) +bool EFA2_ClearStatus (void) { // tbd: currently there is no write support, so always return // true, there is no possibility for pending operations @@ -499,7 +499,7 @@ EFA2_IsInserted Checks to see if the NAND chip used by the EFA2 is present bool return OUT: true if the correct NAND chip is found -----------------------------------------------------------------*/ -bool EFA2_IsInserted (void) +bool EFA2_IsInserted (void) { EFA2_ClearStatus(); return (efa2_nand_id() == EFA2_NAND_ID); @@ -544,7 +544,7 @@ bool EFA2_ReadSectors (u32 sector, u8 numSecs, void* buffer) efa2_nand_reset(); // set NAND to READ1 operation mode and transfer page address - REG_EFA2_NAND_CMD = 0x00; // write READ1 command + REG_EFA2_NAND_CMD = 0x00; // write READ1 command REG_EFA2_NAND_WR = 0x00; // write address [7:0] REG_EFA2_NAND_WR = (page ) & 0xff; // write address [15:8] REG_EFA2_NAND_WR = (page >> 8 ) & 0xff; // write address[23:16] @@ -601,7 +601,7 @@ bool EFA2_WriteSectors (u32 sector, u8 numSecs, void* buffer) EFA2_Shutdown unload the EFA2 interface -----------------------------------------------------------------*/ -bool EFA2_Shutdown(void) +bool EFA2_Shutdown(void) { return EFA2_ClearStatus(); } diff --git a/backends/platform/ds/arm9/source/fat/io_fcsr.c b/backends/platform/ds/arm9/source/fat/io_fcsr.c index d576dfbb0f..7a67a6b1b0 100644 --- a/backends/platform/ds/arm9/source/fat/io_fcsr.c +++ b/backends/platform/ds/arm9/source/fat/io_fcsr.c @@ -4,7 +4,7 @@ compact_flash.c By chishm (Michael Chisholm) - Hardware Routines for using a GBA Flash Cart and SRAM as a + Hardware Routines for using a GBA Flash Cart and SRAM as a block device. This software is completely free. No warranty is provided. @@ -57,7 +57,7 @@ FCSR_IsInserted Is a GBA Flash Cart with a valid file system inserted? bool return OUT: true if a GBA FC card is inserted -----------------------------------------------------------------*/ -bool FCSR_IsInserted (void) +bool FCSR_IsInserted (void) { bool flagFoundFileSys = false; @@ -85,7 +85,7 @@ FCSR_ClearStatus Finish any pending operations bool return OUT: always true for GBA FC -----------------------------------------------------------------*/ -bool FCSR_ClearStatus (void) +bool FCSR_ClearStatus (void) { return true; } @@ -101,7 +101,7 @@ void* buffer OUT: pointer to 512 byte buffer to store data in bool return OUT: true if successful -----------------------------------------------------------------*/ bool FCSR_ReadSectors (u32 sector, u8 numSecs, void* buffer) -{ +{ int i; bool flagSramSector = false; int numSectors = (numSecs > 0 ? numSecs : 256); @@ -208,14 +208,14 @@ bool FCSR_WriteSectors (u32 sector, u8 numSecs, void* buffer) FCSR_Shutdown unload the Flash Cart interface -----------------------------------------------------------------*/ -bool FCSR_Shutdown(void) +bool FCSR_Shutdown(void) { int i; if (FCSR_ClearStatus() == false) return false; FCSR_FileSysPointer = 0; - + for (i=0; i < 4; i++) { FCSR_SramSectorPointer[i] = 0; @@ -262,11 +262,11 @@ bool FCSR_StartUp(void) // Get SRAM sector regions from header block for (i = 0; i < 4; i++) { - FCSR_SramSectorStart[i] = fileSysPointer[i+4]; + FCSR_SramSectorStart[i] = fileSysPointer[i+4]; SramRegionSize[i] = fileSysPointer[i+8]; FCSR_SramSectorEnd[i] = FCSR_SramSectorStart[i] + SramRegionSize[i]; } - + // Calculate SRAM region pointers FCSR_SramSectorPointer[0] = (u8*)(SRAM_START + 4); for (i = 1; i < 4; i++) diff --git a/backends/platform/ds/arm9/source/fat/io_fcsr.h b/backends/platform/ds/arm9/source/fat/io_fcsr.h index 2f87c1c8aa..ef390a8ad6 100644 --- a/backends/platform/ds/arm9/source/fat/io_fcsr.h +++ b/backends/platform/ds/arm9/source/fat/io_fcsr.h @@ -1,5 +1,5 @@ /* - io_fcsr.h + io_fcsr.h Hardware Routines for using a GBA Flash Cart with SRAM @@ -23,7 +23,7 @@ extern LPIO_INTERFACE FCSR_GetInterface(void) ; #endif // define IO_FCSR_H /* - io_fcsr.h + io_fcsr.h Hardware Routines for using a GBA Flash Cart with SRAM diff --git a/backends/platform/ds/arm9/source/fat/io_m3_common.c b/backends/platform/ds/arm9/source/fat/io_m3_common.c index ab2c143327..9c8280c808 100644 --- a/backends/platform/ds/arm9/source/fat/io_m3_common.c +++ b/backends/platform/ds/arm9/source/fat/io_m3_common.c @@ -1,13 +1,13 @@ /* - io_m3_common.c + io_m3_common.c Routines common to all version of the M3 - + Some code based on M3 SD drivers supplied by M3Adapter. Some code written by SaTa may have been unknowingly used. Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -47,7 +47,7 @@ void _M3_changeMode (u32 mode) { _M3_readHalfword (0x08000000 + (mode << 1)); _M3_readHalfword (0x0800080e); _M3_readHalfword (0x08000000); - + if ((mode & 0x0f) != 4) { _M3_readHalfword (0x09000000); } else { @@ -56,5 +56,5 @@ void _M3_changeMode (u32 mode) { _M3_readHalfword (0x08000188); _M3_readHalfword (0x08000188); } -} +} diff --git a/backends/platform/ds/arm9/source/fat/io_m3_common.h b/backends/platform/ds/arm9/source/fat/io_m3_common.h index 92e6bed980..6d0c669783 100644 --- a/backends/platform/ds/arm9/source/fat/io_m3_common.h +++ b/backends/platform/ds/arm9/source/fat/io_m3_common.h @@ -1,5 +1,5 @@ /* - io_m3_common.h + io_m3_common.h Routines common to all version of the M3 @@ -7,7 +7,7 @@ Some code written by SaTa may have been unknowingly used. Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -40,7 +40,7 @@ // Values for changing mode #define M3_MODE_ROM 0x00400004 -#define M3_MODE_MEDIA 0x00400003 +#define M3_MODE_MEDIA 0x00400003 extern void _M3_changeMode (u32 mode); diff --git a/backends/platform/ds/arm9/source/fat/io_m3cf.c b/backends/platform/ds/arm9/source/fat/io_m3cf.c index 910f01097e..968d83ae33 100644 --- a/backends/platform/ds/arm9/source/fat/io_m3cf.c +++ b/backends/platform/ds/arm9/source/fat/io_m3cf.c @@ -73,7 +73,7 @@ M3CF_IsInserted Is a compact flash card inserted? bool return OUT: true if a CF card is inserted -----------------------------------------------------------------*/ -bool M3CF_IsInserted (void) +bool M3CF_IsInserted (void) { // Change register, then check if value did change M3_REG_STS = CF_STS_INSERTED; @@ -86,17 +86,17 @@ M3CF_ClearStatus Tries to make the CF card go back to idle mode bool return OUT: true if a CF card is idle -----------------------------------------------------------------*/ -bool M3CF_ClearStatus (void) +bool M3CF_ClearStatus (void) { int i; - + // Wait until CF card is finished previous commands i=0; while ((M3_REG_CMD & CF_STS_BUSY) && (i < CARD_TIMEOUT)) { i++; } - + // Wait until card is ready for commands i = 0; while ((!(M3_REG_STS & CF_STS_INSERTED)) && (i < CARD_TIMEOUT)) @@ -128,7 +128,7 @@ bool M3CF_ReadSectors (u32 sector, u8 numSecs, void* buffer) u8 *buff_u8 = (u8*)buffer; int temp; #endif - + #if defined _CF_USE_DMA && defined NDS && defined ARM9 DC_FlushRange( buffer, j * BYTE_PER_READ); #endif @@ -139,7 +139,7 @@ bool M3CF_ReadSectors (u32 sector, u8 numSecs, void* buffer) { i++; } - + // Wait until card is ready for commands i = 0; while ((!(M3_REG_STS & CF_STS_INSERTED)) && (i < CARD_TIMEOUT)) @@ -148,20 +148,20 @@ bool M3CF_ReadSectors (u32 sector, u8 numSecs, void* buffer) } if (i >= CARD_TIMEOUT) return false; - + // Set number of sectors to read - M3_REG_SEC = numSecs; - + M3_REG_SEC = numSecs; + // Set read sector M3_REG_LBA1 = sector & 0xFF; // 1st byte of sector number M3_REG_LBA2 = (sector >> 8) & 0xFF; // 2nd byte of sector number M3_REG_LBA3 = (sector >> 16) & 0xFF; // 3rd byte of sector number M3_REG_LBA4 = ((sector >> 24) & 0x0F )| CF_CMD_LBA; // last nibble of sector number - + // Set command to read M3_REG_CMD = CF_CMD_READ; - - + + while (j--) { // Wait until card is ready for reading @@ -172,7 +172,7 @@ bool M3CF_ReadSectors (u32 sector, u8 numSecs, void* buffer) } if (i >= CARD_TIMEOUT) return false; - + // Read data #ifdef _CF_USE_DMA #ifdef NDS @@ -194,12 +194,12 @@ bool M3CF_ReadSectors (u32 sector, u8 numSecs, void* buffer) } } else { while(i--) - *buff++ = *M3_DATA; + *buff++ = *M3_DATA; } #else i=256; while(i--) - *buff++ = *M3_DATA; + *buff++ = *M3_DATA; #endif } #if defined _CF_USE_DMA && defined NDS @@ -230,7 +230,7 @@ bool M3CF_WriteSectors (u32 sector, u8 numSecs, void* buffer) u8 *buff_u8 = (u8*)buffer; int temp; #endif - + #if defined _CF_USE_DMA && defined NDS && defined ARM9 DC_FlushRange( buffer, j * BYTE_PER_READ); #endif @@ -241,7 +241,7 @@ bool M3CF_WriteSectors (u32 sector, u8 numSecs, void* buffer) { i++; } - + // Wait until card is ready for commands i = 0; while ((!(M3_REG_STS & CF_STS_INSERTED)) && (i < CARD_TIMEOUT)) @@ -250,19 +250,19 @@ bool M3CF_WriteSectors (u32 sector, u8 numSecs, void* buffer) } if (i >= CARD_TIMEOUT) return false; - + // Set number of sectors to write - M3_REG_SEC = numSecs; - + M3_REG_SEC = numSecs; + // Set write sector M3_REG_LBA1 = sector & 0xFF; // 1st byte of sector number M3_REG_LBA2 = (sector >> 8) & 0xFF; // 2nd byte of sector number M3_REG_LBA3 = (sector >> 16) & 0xFF; // 3rd byte of sector number M3_REG_LBA4 = ((sector >> 24) & 0x0F )| CF_CMD_LBA; // last nibble of sector number - + // Set command to write M3_REG_CMD = CF_CMD_WRITE; - + while (j--) { // Wait until card is ready for writing @@ -273,7 +273,7 @@ bool M3CF_WriteSectors (u32 sector, u8 numSecs, void* buffer) } if (i >= CARD_TIMEOUT) return false; - + // Write data #ifdef _CF_USE_DMA #ifdef NDS @@ -295,19 +295,19 @@ bool M3CF_WriteSectors (u32 sector, u8 numSecs, void* buffer) } } else { while(i--) - *M3_DATA = *buff++; + *M3_DATA = *buff++; } #else i=256; while(i--) - *M3_DATA = *buff++; + *M3_DATA = *buff++; #endif } #if defined _CF_USE_DMA && defined NDS // Wait for end of transfer before returning while(DMA3_CR & DMA_BUSY); #endif - + return true; } @@ -317,7 +317,7 @@ M3_Unlock Returns true if M3 was unlocked, false if failed Added by MightyMax -----------------------------------------------------------------*/ -bool M3_Unlock(void) +bool M3_Unlock(void) { // run unlock sequence volatile unsigned short tmp ; diff --git a/backends/platform/ds/arm9/source/fat/io_m3cf.h b/backends/platform/ds/arm9/source/fat/io_m3cf.h index bade53f511..006c283adc 100644 --- a/backends/platform/ds/arm9/source/fat/io_m3cf.h +++ b/backends/platform/ds/arm9/source/fat/io_m3cf.h @@ -1,5 +1,5 @@ /* - io_m3cf.h + io_m3cf.h Hardware Routines for reading a compact flash card using the M3 CF @@ -24,7 +24,7 @@ extern LPIO_INTERFACE M3CF_GetInterface(void) ; #endif // define IO_M3CF_H /* - io_m3cf.h + io_m3cf.h Hardware Routines for reading a compact flash card using the M3 CF diff --git a/backends/platform/ds/arm9/source/fat/io_m3sd.c b/backends/platform/ds/arm9/source/fat/io_m3sd.c index 914b83e06e..2bbda37a5a 100644 --- a/backends/platform/ds/arm9/source/fat/io_m3sd.c +++ b/backends/platform/ds/arm9/source/fat/io_m3sd.c @@ -218,7 +218,7 @@ void M3SD_writesector(u16 * p,u32 sectorn) } } while ((verify > 0) && (tries < 16)); - + free(data); free(check); } // */ @@ -356,7 +356,7 @@ bool M3SD_Shutdown(void) bool M3SD_StartUp(void) { vu16* waitCr = (vu16*)0x4000204; - + *waitCr |= 0x6000; // *(vu16*)0x4000204=0x6000; // Try unlocking 3 times, because occationally it fails to detect the reader. diff --git a/backends/platform/ds/arm9/source/fat/io_m3sd_asm.s b/backends/platform/ds/arm9/source/fat/io_m3sd_asm.s index ffaa971aca..a6bb8dc187 100644 --- a/backends/platform/ds/arm9/source/fat/io_m3sd_asm.s +++ b/backends/platform/ds/arm9/source/fat/io_m3sd_asm.s @@ -54,7 +54,7 @@ sd_write_loop2: sd_write_busy: bl clkin - ldrh r0,[r1] + ldrh r0,[r1] tst r0,#0x100 beq sd_write_busy ldmfd r13!,{r0-r1} @@ -68,10 +68,10 @@ SD_crc16: stmfd r13!,{r4-r9} mov r9,r2 - mov r3,#0 - mov r4,#0 - mov r5,#0 - mov r6,#0 + mov r3,#0 + mov r4,#0 + mov r5,#0 + mov r6,#0 ldr r7,=0x80808080 ldr r8,=0x1021 @@ -86,19 +86,19 @@ sd_crc16_loop: eorne r3,r3,r8 tst r2,r7,lsr #24 eorne r3,r3,r8 - + mov r4,r4,lsl #1 tst r4,#0x10000 eorne r4,r4,r8 tst r2,r7,lsr #25 eorne r4,r4,r8 - + mov r5,r5,lsl #1 tst r5,#0x10000 eorne r5,r5,r8 tst r2,r7,lsr #26 eorne r5,r5,r8 - + mov r6,r6,lsl #1 tst r6,#0x10000 eorne r6,r6,r8 @@ -107,7 +107,7 @@ sd_crc16_loop: mov r7,r7,ror #4 subs r1,r1,#4 - bne sd_crc16_loop + bne sd_crc16_loop mov r2,r9 mov r8,#16 @@ -145,7 +145,7 @@ SD_data_write: mov r2,#SDODA sd_data_write_busy: bl clkin - ldrh r3,[r2] + ldrh r3,[r2] tst r3,#0x100 beq sd_data_write_busy @@ -169,7 +169,7 @@ sd_data_write_loop: bl clkout subs r5, r5, #2 - bne sd_data_write_loop + bne sd_data_write_loop cmp r1,#0 movne r0,r1 @@ -184,10 +184,10 @@ sd_data_write_loop2: bl clkout subs r5, r5, #1 bne sd_data_write_loop2 - + sd_data_write_busy2: bl clkin - ldrh r3,[r2] + ldrh r3,[r2] tst r3,#0x100 beq sd_data_write_busy2 diff --git a/backends/platform/ds/arm9/source/fat/io_mmcf.c b/backends/platform/ds/arm9/source/fat/io_mmcf.c index 3034afe311..5ccb3122e4 100644 --- a/backends/platform/ds/arm9/source/fat/io_mmcf.c +++ b/backends/platform/ds/arm9/source/fat/io_mmcf.c @@ -74,14 +74,14 @@ static bool cf_block_ready(void) do { while (!(CF_RD_STATUS & 0x40)); - } while (CF_RD_STATUS & 0x80); + } while (CF_RD_STATUS & 0x80); */ do { i++; - while ( (!(CF_RD_STATUS & 0x40)) && (i < CARD_TIMEOUT) ) i++; - } while ( (CF_RD_STATUS & 0x80) && (i < CARD_TIMEOUT) ); + while ( (!(CF_RD_STATUS & 0x40)) && (i < CARD_TIMEOUT) ) i++; + } while ( (CF_RD_STATUS & 0x80) && (i < CARD_TIMEOUT) ); if (i >= CARD_TIMEOUT) { return false; @@ -110,7 +110,7 @@ MMCF_IsInserted Is a compact flash card inserted? bool return OUT: true if a CF card is inserted -----------------------------------------------------------------*/ -bool MMCF_IsInserted (void) +bool MMCF_IsInserted (void) { if ( !cf_set_features(0xAA) ) return false; @@ -123,7 +123,7 @@ MMCF_ClearStatus Tries to make the CF card go back to idle mode bool return OUT: true if a CF card is idle -----------------------------------------------------------------*/ -bool MMCF_ClearStatus (void) +bool MMCF_ClearStatus (void) { return true; } @@ -185,7 +185,7 @@ bool MMCF_ReadSectors (u32 sector, u8 numSecs, void* buffer) } } else { while(i--) - *buff++ = *MP_DATA; + *buff++ = *MP_DATA; } #else i=256; @@ -222,15 +222,15 @@ bool MMCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) u8 *buff_u8 = (u8*)buffer; int temp; #endif - + #if defined _CF_USE_DMA && defined NDS && defined ARM9 DC_FlushRange( buffer, j * BYTE_PER_READ); #endif - if (numSecs > 1) + if (numSecs > 1) { int r = 0; - + for (r = 0; r < numSecs; r++) { MMCF_WriteSectors(sector + r, 1, ((unsigned char *) (buffer)) + 512); @@ -270,12 +270,12 @@ bool MMCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) } } else { while(i--) - *MP_DATA = *buff++; + *MP_DATA = *buff++; } #else i=256; while(i--) - *MP_DATA = *buff++; + *MP_DATA = *buff++; #endif } @@ -283,7 +283,7 @@ bool MMCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) #if defined _CF_USE_DMA && defined NDS // Wait for end of transfer before returning while(DMA3_CR & DMA_BUSY); -#endif +#endif //#define _CF_VERIFY @@ -312,7 +312,7 @@ bool MMCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) MMCF_Shutdown unload the GBAMP CF interface -----------------------------------------------------------------*/ -bool MMCF_Shutdown(void) +bool MMCF_Shutdown(void) { return MMCF_ClearStatus() ; } diff --git a/backends/platform/ds/arm9/source/fat/io_mmcf.h b/backends/platform/ds/arm9/source/fat/io_mmcf.h index baa43ac59f..fa9e6536ee 100644 --- a/backends/platform/ds/arm9/source/fat/io_mmcf.h +++ b/backends/platform/ds/arm9/source/fat/io_mmcf.h @@ -1,5 +1,5 @@ /* - io_mmcf.h + io_mmcf.h Hardware Routines for reading a compact flash card using the GBA Movie Player diff --git a/backends/platform/ds/arm9/source/fat/io_mpcf.c b/backends/platform/ds/arm9/source/fat/io_mpcf.c index a12b6e8e1e..6b56e29291 100644 --- a/backends/platform/ds/arm9/source/fat/io_mpcf.c +++ b/backends/platform/ds/arm9/source/fat/io_mpcf.c @@ -73,7 +73,7 @@ MPCF_IsInserted Is a compact flash card inserted? bool return OUT: true if a CF card is inserted -----------------------------------------------------------------*/ -bool MPCF_IsInserted (void) +bool MPCF_IsInserted (void) { // Change register, then check if value did change MP_REG_STS = CF_STS_INSERTED; @@ -86,17 +86,17 @@ MPCF_ClearStatus Tries to make the CF card go back to idle mode bool return OUT: true if a CF card is idle -----------------------------------------------------------------*/ -bool MPCF_ClearStatus (void) +bool MPCF_ClearStatus (void) { int i; - + // Wait until CF card is finished previous commands i=0; while ((MP_REG_CMD & CF_STS_BUSY) && (i < CARD_TIMEOUT)) { i++; } - + // Wait until card is ready for commands i = 0; while ((!(MP_REG_STS & CF_STS_INSERTED)) && (i < CARD_TIMEOUT)) @@ -139,7 +139,7 @@ bool MPCF_ReadSectors (u32 sector, u8 numSecs, void* buffer) { i++; } - + // Wait until card is ready for commands i = 0; while ((!(MP_REG_STS & CF_STS_INSERTED)) && (i < CARD_TIMEOUT)) @@ -148,20 +148,20 @@ bool MPCF_ReadSectors (u32 sector, u8 numSecs, void* buffer) } if (i >= CARD_TIMEOUT) return false; - + // Set number of sectors to read - MP_REG_SEC = numSecs; - + MP_REG_SEC = numSecs; + // Set read sector MP_REG_LBA1 = sector & 0xFF; // 1st byte of sector number MP_REG_LBA2 = (sector >> 8) & 0xFF; // 2nd byte of sector number MP_REG_LBA3 = (sector >> 16) & 0xFF; // 3rd byte of sector number MP_REG_LBA4 = ((sector >> 24) & 0x0F )| CF_CMD_LBA; // last nibble of sector number - + // Set command to read MP_REG_CMD = CF_CMD_READ; - - + + while (j--) { // Wait until card is ready for reading @@ -172,7 +172,7 @@ bool MPCF_ReadSectors (u32 sector, u8 numSecs, void* buffer) } if (i >= CARD_TIMEOUT) return false; - + // Read data #ifdef _CF_USE_DMA #ifdef NDS @@ -194,12 +194,12 @@ bool MPCF_ReadSectors (u32 sector, u8 numSecs, void* buffer) } } else { while(i--) - *buff++ = *MP_DATA; + *buff++ = *MP_DATA; } #else i=256; while(i--) - *buff++ = *MP_DATA; + *buff++ = *MP_DATA; #endif } #if (defined _CF_USE_DMA) && (defined NDS) @@ -229,7 +229,7 @@ bool MPCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) u8 *buff_u8 = (u8*)buffer; int temp; #endif - + #if defined _CF_USE_DMA && defined NDS && defined ARM9 DC_FlushRange( buffer, j * BYTE_PER_READ); #endif @@ -240,7 +240,7 @@ bool MPCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) { i++; } - + // Wait until card is ready for commands i = 0; while ((!(MP_REG_STS & CF_STS_INSERTED)) && (i < CARD_TIMEOUT)) @@ -249,19 +249,19 @@ bool MPCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) } if (i >= CARD_TIMEOUT) return false; - + // Set number of sectors to write - MP_REG_SEC = numSecs; - + MP_REG_SEC = numSecs; + // Set write sector MP_REG_LBA1 = sector & 0xFF; // 1st byte of sector number MP_REG_LBA2 = (sector >> 8) & 0xFF; // 2nd byte of sector number MP_REG_LBA3 = (sector >> 16) & 0xFF; // 3rd byte of sector number MP_REG_LBA4 = ((sector >> 24) & 0x0F )| CF_CMD_LBA; // last nibble of sector number - + // Set command to write MP_REG_CMD = CF_CMD_WRITE; - + while (j--) { // Wait until card is ready for writing @@ -272,7 +272,7 @@ bool MPCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) } if (i >= CARD_TIMEOUT) return false; - + // Write data #ifdef _CF_USE_DMA #ifdef NDS @@ -294,19 +294,19 @@ bool MPCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) } } else { while(i--) - *MP_DATA = *buff++; + *MP_DATA = *buff++; } #else i=256; while(i--) - *MP_DATA = *buff++; + *MP_DATA = *buff++; #endif } #if defined _CF_USE_DMA && defined NDS // Wait for end of transfer before returning while(DMA3_CR & DMA_BUSY); #endif - + return true; } @@ -314,7 +314,7 @@ bool MPCF_WriteSectors (u32 sector, u8 numSecs, void* buffer) MPCF_Shutdown unload the GBAMP CF interface -----------------------------------------------------------------*/ -bool MPCF_Shutdown(void) +bool MPCF_Shutdown(void) { return MPCF_ClearStatus() ; } diff --git a/backends/platform/ds/arm9/source/fat/io_mpcf.h b/backends/platform/ds/arm9/source/fat/io_mpcf.h index 58cab41b4c..8ec8859097 100644 --- a/backends/platform/ds/arm9/source/fat/io_mpcf.h +++ b/backends/platform/ds/arm9/source/fat/io_mpcf.h @@ -1,5 +1,5 @@ /* - io_mpcf.h + io_mpcf.h Hardware Routines for reading a compact flash card using the GBA Movie Player @@ -24,7 +24,7 @@ extern LPIO_INTERFACE MPCF_GetInterface(void) ; #endif // define IO_MPCF_H /* - io_mpcf.h + io_mpcf.h Hardware Routines for reading a compact flash card using the GBA Movie Player diff --git a/backends/platform/ds/arm9/source/fat/io_njsd.c b/backends/platform/ds/arm9/source/fat/io_njsd.c index fbb223d560..12388da8e9 100644 --- a/backends/platform/ds/arm9/source/fat/io_njsd.c +++ b/backends/platform/ds/arm9/source/fat/io_njsd.c @@ -3,11 +3,11 @@ Hardware Routines for reading an SD card using a NinjaDS SD adapter. - + Original code supplied by NinjaMod - + Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -28,7 +28,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + 2006-08-05 - Chishm * First release */ @@ -84,7 +84,7 @@ static u32 _NJSD_relativeCardAddress = 0; static inline bool _NJSD_waitIRQ(void) { /*#ifdef _NJSD_SYNC int i = IRQ_TIMEOUT; - while (!(REG_IF & 0x100000) && --i); + while (!(REG_IF & 0x100000) && --i); REG_IF = 0x100000; if (i <= 0) { return false; @@ -96,7 +96,7 @@ static inline bool _NJSD_waitIRQ(void) { //if (!(REG_IME & 1)) //{ // irq's disabled... - while (!(REG_IF & 0x100000) && (!(_NJSD_irqFlag)) && --i); + while (!(REG_IF & 0x100000) && (!(_NJSD_irqFlag)) && --i); _NJSD_irqFlag = 0; REG_IF = 0x100000; if (i <= 0) { @@ -106,7 +106,7 @@ static inline bool _NJSD_waitIRQ(void) { } //} else { // irq's enabled - // while (!(_NJSD_irqFlag) && --i); + // while (!(_NJSD_irqFlag) && --i); // _NJSD_irqFlag = 0; // REG_IF = 0x100000; // if (i <= 0) { @@ -118,8 +118,8 @@ static inline bool _NJSD_waitIRQ(void) { //#endif } -static inline void _NJSD_writeCardCommand - (u8 cmd0, u8 cmd1, u8 cmd2, u8 cmd3, u8 cmd4, u8 cmd5, u8 cmd6, u8 cmd7) +static inline void _NJSD_writeCardCommand + (u8 cmd0, u8 cmd1, u8 cmd2, u8 cmd3, u8 cmd4, u8 cmd5, u8 cmd6, u8 cmd7) { CARD_COMMAND[0] = cmd0; CARD_COMMAND[1] = cmd1; @@ -142,7 +142,7 @@ static bool _NJSD_reset (void) { if (i <= 0) { return false; } - + return true; } @@ -179,7 +179,7 @@ static bool _NJSD_sendCMDR (int speed, u8 *rsp_buf, int type, u8 cmd, u32 param) REG_IME = 0; #endif - REG_IE &= ~0x100000; + REG_IE &= ~0x100000; REG_IF = 0x100000; CARD_CR1H = CARD_CR1_ENABLE; @@ -191,7 +191,7 @@ static bool _NJSD_sendCMDR (int speed, u8 *rsp_buf, int type, u8 cmd, u32 param) } else { CARD_COMMAND[0] = 0xF0 | (speed << 2) | 0 | (1 << 1); } - + CARD_COMMAND[1] = (type & 0x40) | ((( type >> 2) & 7) << 3); CARD_COMMAND[2] = 0x40 | cmd; CARD_COMMAND[3] = (param>>24) & 0xFF; @@ -301,7 +301,7 @@ static bool _NJSD_writeSector (u8 *buffer, u8 *crc_buf, u32 offset) { } - REG_IE &= ~0x100000; + REG_IE &= ~0x100000; REG_IF = 0x100000; CARD_CR1H = CARD_CR1_ENABLE; @@ -334,7 +334,7 @@ static bool _NJSD_writeSector (u8 *buffer, u8 *crc_buf, u32 offset) { i++; } } while (CARD_CR2 & CARD_BUSY); - + i = WRITE_TIMEOUT; responseBuffer[3] = 0; do { @@ -352,7 +352,7 @@ static bool _NJSD_writeSector (u8 *buffer, u8 *crc_buf, u32 offset) { #ifdef _NJSD_SYNC REG_IME = old_REG_IME; #endif - + return true; } @@ -365,12 +365,12 @@ static bool _NJSD_sendCLK (int speed, int count) { REG_IME = 0; #endif - REG_IE &= ~0x100000; + REG_IE &= ~0x100000; REG_IF = 0x100000; //CARD_CR1H = CARD_CR1_ENABLE; // | CARD_CR1_IRQ; _NJSD_writeCardCommand (0xE0 | ((speed & 3) << 2), 0, (count - 1), 0, 0, 0, 0, 0); - + CARD_CR2 = _NJSD_cardFlags; i = COMMAND_TIMEOUT; while ((CARD_CR2 & CARD_BUSY) && --i); @@ -404,7 +404,7 @@ static bool _NJSD_sendCMDN (int speed, u8 cmd, u32 param) { REG_IME = 0; #endif - REG_IE &= ~0x100000; + REG_IE &= ~0x100000; REG_IF = 0x100000; CARD_CR1H = CARD_CR1_ENABLE; // | CARD_CR1_IRQ; @@ -438,22 +438,22 @@ static bool _NJSD_sendCMDN (int speed, u8 cmd, u32 param) { static bool _NJSD_cardInit (void) { u8 responseBuffer[17]; int i; - + // If the commands succeed the first time, assume they'll always succeed if (! _NJSD_sendCLK (SD_CLK_200KHz, 256) ) return false; if (! _NJSD_sendCMDN (SD_CLK_200KHz, GO_IDLE_STATE, 0) ) return false; _NJSD_sendCLK (SD_CLK_200KHz, 8); - + _NJSD_sendCLK (SD_CLK_200KHz, 256); _NJSD_sendCMDN (SD_CLK_200KHz, GO_IDLE_STATE, 0); _NJSD_sendCLK (SD_CLK_200KHz, 8); - + for (i = 0; i < MAX_STARTUP_TRIES ; i++) { _NJSD_sendCMDR (SD_CLK_200KHz, responseBuffer, SD_RSP_48, APP_CMD, 0); - if ( + if ( _NJSD_sendCMDR (SD_CLK_200KHz, responseBuffer, SD_RSP_48, SD_APP_OP_COND, SD_OCR_VALUE) && ((responseBuffer[1] & 0x80) != 0)) - { + { // Card is ready to receive commands now break; } @@ -461,10 +461,10 @@ static bool _NJSD_cardInit (void) { if (i >= MAX_STARTUP_TRIES) { return false; } - + // The card's name, as assigned by the manufacturer _NJSD_sendCMDR (SD_CLK_200KHz, responseBuffer, SD_RSP_136, ALL_SEND_CID, 0); - + // Get a new address for (i = 0; i < MAX_STARTUP_TRIES ; i++) { _NJSD_sendCMDR (SD_CLK_200KHz, responseBuffer, SD_RSP_48, SEND_RELATIVE_ADDR, 0); @@ -479,17 +479,17 @@ static bool _NJSD_cardInit (void) { // Some cards won't go to higher speeds unless they think you checked their capabilities _NJSD_sendCMDR (SD_CLK_200KHz, responseBuffer, SD_RSP_136, SEND_CSD, _NJSD_relativeCardAddress); - + // Only this card should respond to all future commands _NJSD_sendCMDR (SD_CLK_200KHz, responseBuffer, SD_RSP_48, SELECT_CARD, _NJSD_relativeCardAddress); - + // Set a 4 bit data bus _NJSD_sendCMDR (SD_CLK_200KHz, responseBuffer, SD_RSP_48, APP_CMD, _NJSD_relativeCardAddress); _NJSD_sendCMDR (SD_CLK_200KHz, responseBuffer, SD_RSP_48, SET_BUS_WIDTH, 2); // 4-bit mode. // Use 512 byte blocks _NJSD_sendCMDR (SD_CLK_200KHz, responseBuffer, SD_RSP_48, SET_BLOCKLEN, 512); // 512 byte blocks - + return true; } @@ -521,7 +521,7 @@ bool _NJSD_startup(void) { return false; } return true; -} +} bool _NJSD_writeSectors (u32 sector, u32 numSectors, const void* buffer) { @@ -531,7 +531,7 @@ bool _NJSD_writeSectors (u32 sector, u32 numSectors, const void* buffer) { while (numSectors--) { _SD_CRC16 ( data, BYTES_PER_READ, crc); - + if (! _NJSD_writeSector (data, crc, offset)) { return false; } @@ -549,7 +549,7 @@ bool _NJSD_readSectors (u32 sector, u32 numSectors, void* buffer) { #ifdef _NJSD_SYNC u32 old_REG_IME; #endif - + u8* tbuf = (u8*)buffer; if (numSectors == 0) { @@ -573,7 +573,7 @@ bool _NJSD_readSectors (u32 sector, u32 numSectors, void* buffer) { if (!_NJSD_waitIRQ ()) { #ifdef _NJSD_SYNC REG_IME = old_REG_IME; -#endif +#endif return false; } } @@ -586,10 +586,10 @@ bool _NJSD_readSectors (u32 sector, u32 numSectors, void* buffer) { if (!_NJSD_waitIRQ ()) { #ifdef _NJSD_SYNC REG_IME = old_REG_IME; -#endif +#endif return false; } - + if (((int)buffer & 0x03) != 0){ cardPolledTransfer (0xA1406000, tmp, BYTES_PER_READ, (u8*)_NJSD_read_cmd); memcpy (tbuf + (numSectors - 1) * BYTES_PER_READ, tmp, BYTES_PER_READ); @@ -618,7 +618,7 @@ bool _NJSD_readSectors (u32 sector, u32 numSectors, void* buffer) { #ifdef _NJSD_SYNC u32 old_REG_IME; #endif - + u8* tbuf = (u8*)buffer; if (numSectors == 0) { @@ -637,7 +637,7 @@ bool _NJSD_readSectors (u32 sector, u32 numSectors, void* buffer) { if (!_NJSD_waitIRQ ()) { #ifdef _NJSD_SYNC REG_IME = old_REG_IME; -#endif +#endif return false; } } @@ -645,10 +645,10 @@ bool _NJSD_readSectors (u32 sector, u32 numSectors, void* buffer) { if (!_NJSD_waitIRQ ()) { #ifdef _NJSD_SYNC REG_IME = old_REG_IME; -#endif +#endif return false; } - + cardPolledTransfer (0xA1406000, (u32*)(tbuf + (numSectors - 1) * BYTES_PER_READ), BYTES_PER_READ, (u8*)_NJSD_read_cmd); } else { _NJSD_sendCMDR (_NJSD_speed, NULL, SD_RSP_STREAM, READ_SINGLE_BLOCK, sector * BYTES_PER_READ); @@ -678,4 +678,4 @@ LPIO_INTERFACE NJSD_GetInterface(void) { } ; #endif // defined NDS -#endif
\ No newline at end of file +#endif diff --git a/backends/platform/ds/arm9/source/fat/io_njsd.h b/backends/platform/ds/arm9/source/fat/io_njsd.h index a297cda112..dce469cad6 100644 --- a/backends/platform/ds/arm9/source/fat/io_njsd.h +++ b/backends/platform/ds/arm9/source/fat/io_njsd.h @@ -1,11 +1,11 @@ /* - io_njsd.h + io_njsd.h Hardware Routines for reading an SD card using a NinjaDS SD adapter. Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/backends/platform/ds/arm9/source/fat/io_nmmc.c b/backends/platform/ds/arm9/source/fat/io_nmmc.c index a29c26e43a..261096a27b 100644 --- a/backends/platform/ds/arm9/source/fat/io_nmmc.c +++ b/backends/platform/ds/arm9/source/fat/io_nmmc.c @@ -13,10 +13,10 @@ project at chishm@hotmail.com See gba_nds_fat.txt for help and license details. - + 2006-02-09 - www.neoflash.com: * First stable release - + 2006-02-13 - Chishm * Added ReadMK2Config function * Added read config test to init function so no unnecessary card commands are sent @@ -87,7 +87,7 @@ void Neo_WriteMK2Config(u8 config) { Neo_EnableEEPROM(false); } -u8 Neo_ReadMK2Config(void) +u8 Neo_ReadMK2Config(void) { u8 config; Neo_EnableEEPROM(true); @@ -104,7 +104,7 @@ u8 Neo_ReadMK2Config(void) u8 selectMMC_command [8] = {0xFF, 0x00, 0x6A, 0xDF, 0x37, 0x59, 0x33, 0xA3}; -void Neo_SelectMMC (u8 dataByte) +void Neo_SelectMMC (u8 dataByte) { selectMMC_command[1] = dataByte; // Set enable / disable byte cardWriteCommand (selectMMC_command); // Send "5. Use the EEPROM CS to access the MK2 MMC/SD card" @@ -154,12 +154,12 @@ bool Neo_CheckMMCResponse( u8 response, u8 mask ) { bool Neo_InitMMC() { Neo_MK2GameMode(); Neo_WriteMK2Config( MK2_CONFIG_ZIP_RAM_CLOSE | MK2_CONFIG_GAME_FLASH_CLOSE); - + // Make sure the configuration was accepted if (Neo_ReadMK2Config() != (MK2_CONFIG_ZIP_RAM_CLOSE | MK2_CONFIG_GAME_FLASH_CLOSE)) { return false; // If not, then it wasn't initialised properly } - + return true; } @@ -167,7 +167,7 @@ bool Neo_InitMMC() { bool NMMC_IsInserted(void) { int i; - + Neo_EnableMMC( true ); // Open SPI port to MMC card Neo_SendMMCCommand(MMC_SEND_CSD, 0); if( Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured @@ -183,13 +183,13 @@ bool NMMC_IsInserted(void) { for (i = 0; i < 28; i++) { Neo_SPI(0xff); } - + return true; } bool NMMC_ClearStatus (void) { u32 i; - + Neo_EnableMMC( true ); // Open SPI port to MMC card for (i = 0; i < 10; i++) { Neo_SPI(0xFF); // Send 10 0xFF bytes to MMC card @@ -224,14 +224,14 @@ bool NMMC_StartUp(void) { return false; } Neo_EnableMMC( true ); // Open SPI port to MMC card - + // Set block length Neo_SendMMCCommand(MMC_SET_BLOCKLEN, BYTE_PER_READ ); if( Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured Neo_EnableMMC( false ); return false; } - + // Check if we can use a higher SPI frequency Neo_SendMMCCommand(MMC_SEND_CSD, 0); if( Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured @@ -252,77 +252,77 @@ bool NMMC_StartUp(void) { if ((transSpeed & 0xf0) >= 0x30) { spi_freq = 0; } - + Neo_EnableMMC( false ); return true; -} +} -bool NMMC_WriteSectors (u32 sector, u8 numSecs, void* buffer) +bool NMMC_WriteSectors (u32 sector, u8 numSecs, void* buffer) { u32 i; u8 *p=buffer; - + int totalSecs = (numSecs == 0) ? 256 : numSecs; sector *= BYTE_PER_READ; - + Neo_EnableMMC( true ); // Open SPI port to MMC card Neo_SendMMCCommand( 25, sector ); if( Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured Neo_EnableMMC( false ); return false; } - + while (totalSecs--) { Neo_SPI( 0xFC ); // Send Start Block token for( i = 0; i < BYTE_PER_READ; i++ ) // Send a block of data Neo_SPI( *p++ ); Neo_SPI( 0xFF ); // Send fake CRC16 Neo_SPI( 0xFF ); // Send fake CRC16 - + if( ( Neo_SPI( 0xFF ) & 0x0F ) != 0x05 ) { // Make sure the block was accepted Neo_EnableMMC( false ); return false; } while( Neo_SPI( 0xFF ) == 0x00 ); // Wait for the block to be written } - + // Stop transmission block Neo_SPI( 0xFD ); // Send Stop Transmission Block token for( i = 0; i < BYTE_PER_READ; i++ ) // Send a block of fake data Neo_SPI( 0xFF ); Neo_SPI( 0xFF ); // Send fake CRC16 Neo_SPI( 0xFF ); // Send fake CRC16 - + Neo_SPI (0xFF); // Send 8 clocks while( Neo_SPI( 0xFF ) == 0x00 ); // Wait for the busy signal to clear - - for ( i = 0; i < 0x10; i++) { + + for ( i = 0; i < 0x10; i++) { Neo_SPI (0xFF); // Send clocks for the MMC card to finish what it's doing } - + Neo_EnableMMC( false ); // Close SPI port to MMC card return true; } -bool NMMC_ReadSectors (u32 sector, u8 numSecs, void* buffer) +bool NMMC_ReadSectors (u32 sector, u8 numSecs, void* buffer) { u32 i; u8 *p=buffer; - + int totalSecs = (numSecs == 0) ? 256 : numSecs; sector *= BYTE_PER_READ; - + Neo_EnableMMC( true ); // Open SPI port to MMC card - + while (totalSecs--) { Neo_SendMMCCommand(MMC_READ_BLOCK, sector ); if( Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured Neo_EnableMMC( false ); return false; } - + if( Neo_CheckMMCResponse( 0xFE, 0xFF ) == false ) { // Check for Start Block token Neo_EnableMMC( false ); return false; @@ -333,7 +333,7 @@ bool NMMC_ReadSectors (u32 sector, u8 numSecs, void* buffer) Neo_SPI( 0xFF ); // Ignore CRC16 sector += BYTE_PER_READ; } - + Neo_EnableMMC( false ); // Close SPI port to MMC card return true; } diff --git a/backends/platform/ds/arm9/source/fat/io_nmmc.h b/backends/platform/ds/arm9/source/fat/io_nmmc.h index 5244d21868..0249e3a864 100644 --- a/backends/platform/ds/arm9/source/fat/io_nmmc.h +++ b/backends/platform/ds/arm9/source/fat/io_nmmc.h @@ -1,5 +1,5 @@ /* - io_NMMC.h + io_NMMC.h Hardware Routines for reading an SD or MMC card using a Neoflash MK2 or MK3. @@ -26,7 +26,7 @@ extern LPIO_INTERFACE NMMC_GetInterface(void) ; #endif // define IO_NMMC_H /* - io_NMMC.h + io_NMMC.h Hardware Routines for reading an SD or MMC card using a Neoflash MK2 or MK3. diff --git a/backends/platform/ds/arm9/source/fat/io_sccf.c b/backends/platform/ds/arm9/source/fat/io_sccf.c index 0c77f4673c..bda628fdaa 100644 --- a/backends/platform/ds/arm9/source/fat/io_sccf.c +++ b/backends/platform/ds/arm9/source/fat/io_sccf.c @@ -57,7 +57,7 @@ bool SCCF_Unlock(void) temp = (~temp & 0xFF); return (CF_REG_LBA1 == temp); #undef CF_REG_LBA1 -} +} bool SCCF_Shutdown(void) { return MPCF_ClearStatus() ; diff --git a/backends/platform/ds/arm9/source/fat/io_sccf.h b/backends/platform/ds/arm9/source/fat/io_sccf.h index 961909fbce..2270c4eab1 100644 --- a/backends/platform/ds/arm9/source/fat/io_sccf.h +++ b/backends/platform/ds/arm9/source/fat/io_sccf.h @@ -1,5 +1,5 @@ /* - io_sccf.h + io_sccf.h Hardware Routines for reading a compact flash card using the Supercard CF @@ -24,7 +24,7 @@ extern LPIO_INTERFACE SCCF_GetInterface(void) ; #endif // define IO_SCCF_H /* - io_sccf.h + io_sccf.h Hardware Routines for reading a compact flash card using the Supercard CF diff --git a/backends/platform/ds/arm9/source/fat/io_scsd.c b/backends/platform/ds/arm9/source/fat/io_scsd.c index 9359fefb6d..270691436d 100644 --- a/backends/platform/ds/arm9/source/fat/io_scsd.c +++ b/backends/platform/ds/arm9/source/fat/io_scsd.c @@ -1,8 +1,8 @@ /* io_scsd.c by SaTa. based on io_sccf.c - - + + */ /* @@ -43,7 +43,7 @@ extern void InitSCMode(void); // CFと同じ extern void ReadSector(u16 *buff,u32 sector,u8 ReadNumber); extern void WriteSector(u16 *buff,u32 sector,u8 writeNumber); extern bool MemoryCard_IsInserted(void); // CFと違う -// +// /*----------------------------------------------------------------- SCSD_Unlock @@ -55,7 +55,7 @@ bool SCSD_Unlock(void) { InitSCMode(); return MemoryCard_IsInserted(); -} +} bool SCSD_Shutdown(void) { return MPCF_ClearStatus() ; @@ -103,4 +103,4 @@ LPIO_INTERFACE SCSD_GetInterface(void) { return &io_scsd ; } ; -#endif
\ No newline at end of file +#endif diff --git a/backends/platform/ds/arm9/source/fat/io_scsd.h b/backends/platform/ds/arm9/source/fat/io_scsd.h index 75115b8d62..492492f619 100644 --- a/backends/platform/ds/arm9/source/fat/io_scsd.h +++ b/backends/platform/ds/arm9/source/fat/io_scsd.h @@ -1,12 +1,12 @@ /* io_scsd.h by SaTa. based on io_sccf.h - - + + */ /* - io_sccf.h + io_sccf.h Hardware Routines for reading a compact flash card using the GBA Movie Player @@ -26,4 +26,4 @@ // export interface extern LPIO_INTERFACE SCSD_GetInterface(void) ; -#endif // define IO_SCSD_H
\ No newline at end of file +#endif // define IO_SCSD_H diff --git a/backends/platform/ds/arm9/source/fat/io_scsd_asm.s b/backends/platform/ds/arm9/source/fat/io_scsd_asm.s index 498cbb96c2..390d36afeb 100644 --- a/backends/platform/ds/arm9/source/fat/io_scsd_asm.s +++ b/backends/platform/ds/arm9/source/fat/io_scsd_asm.s @@ -1,22 +1,22 @@ .TEXT @--------------------------------sd data-------------------------------- .equ sd_comadd,0x9800000 -.equ sd_dataadd,0x9000000 +.equ sd_dataadd,0x9000000 .equ sd_dataradd,0x9100000 @-----------------viod sd_data_write_s(u16 *buff,u16* crc16buff)------------------- .ALIGN - .GLOBAL sd_data_write_s + .GLOBAL sd_data_write_s .CODE 32 sd_data_write_s: stmfd r13!,{r4-r5} mov r5,#512 mov r2,#sd_dataadd sd_data_write_busy: - ldrh r3,[r2] + ldrh r3,[r2] tst r3,#0x100 beq sd_data_write_busy - ldrh r3,[r2] + ldrh r3,[r2] mov r3,#0 @star bit strh r3,[r2] @@ -24,10 +24,10 @@ sd_data_write_loop: ldrh r3,[r0],#2 add r3,r3,r3,lsl #20 mov r4,r3,lsl #8 - stmia r2,{r3-r4} - - subs r5, r5, #2 - bne sd_data_write_loop + stmia r2,{r3-r4} + + subs r5, r5, #2 + bne sd_data_write_loop cmp r1,#0 movne r0,r1 @@ -38,11 +38,11 @@ sd_data_write_loop: mov r3,#0xff @end bit strh r3,[r2] sd_data_write_loop2: - ldrh r3,[r2] + ldrh r3,[r2] tst r3,#0x100 bne sd_data_write_loop2 - ldmia r2,{r3-r4} + ldmia r2,{r3-r4} ldmfd r13!,{r4-r5} bx r14 @@ -50,7 +50,7 @@ sd_data_write_loop2: @----------void sd_data_read_s(u16 *buff)------------- .ALIGN - .GLOBAL sd_data_read_s + .GLOBAL sd_data_read_s .CODE 32 sd_data_read_s: stmfd r13!,{r4} @@ -61,62 +61,62 @@ sd_data_read_loop1: bne sd_data_read_loop1 mov r2,#512 sd_data_read_loop: - ldmia r1,{r3-r4} + ldmia r1,{r3-r4} mov r3,r4,lsr #16 strh r3 ,[r0],#2 - ldmia r1,{r3-r4} + ldmia r1,{r3-r4} mov r3,r4,lsr #16 strh r3 ,[r0],#2 - ldmia r1,{r3-r4} + ldmia r1,{r3-r4} mov r3,r4,lsr #16 strh r3 ,[r0],#2 - ldmia r1,{r3-r4} + ldmia r1,{r3-r4} mov r3,r4,lsr #16 strh r3 ,[r0],#2 - ldmia r1,{r3-r4} + ldmia r1,{r3-r4} mov r3,r4,lsr #16 strh r3 ,[r0],#2 - ldmia r1,{r3-r4} + ldmia r1,{r3-r4} mov r3,r4,lsr #16 strh r3 ,[r0],#2 - ldmia r1,{r3-r4} + ldmia r1,{r3-r4} mov r3,r4,lsr #16 strh r3 ,[r0],#2 - ldmia r1,{r3-r4} + ldmia r1,{r3-r4} mov r3,r4,lsr #16 strh r3 ,[r0],#2 - subs r2, r2, #16 - bne sd_data_read_loop + subs r2, r2, #16 + bne sd_data_read_loop ldmia r1,{r3-r4} @crc 16 - ldmia r1,{r3-r4} - ldmia r1,{r3-r4} - ldmia r1,{r3-r4} + ldmia r1,{r3-r4} + ldmia r1,{r3-r4} + ldmia r1,{r3-r4} ldrh r3,[r1] @end bit - ldmfd r13!,{r4} + ldmfd r13!,{r4} bx r14 @----------end sd_data_read_s------------- @------void sd_com_crc16_s(u16* buff,u16 num,u16* crc16buff) .ALIGN - .GLOBAL sd_crc16_s + .GLOBAL sd_crc16_s .CODE 32 sd_crc16_s: stmfd r13!,{r4-r9} mov r9,r2 - mov r3,#0 - mov r4,#0 - mov r5,#0 - mov r6,#0 + mov r3,#0 + mov r4,#0 + mov r5,#0 + mov r6,#0 ldr r7,=0x80808080 ldr r8,=0x1021 @@ -131,19 +131,19 @@ sd_crc16_loop: eorne r3,r3,r8 tst r2,r7,lsr #24 eorne r3,r3,r8 - + mov r4,r4,lsl #1 tst r4,#0x10000 eorne r4,r4,r8 tst r2,r7,lsr #25 eorne r4,r4,r8 - + mov r5,r5,lsl #1 tst r5,#0x10000 eorne r5,r5,r8 tst r2,r7,lsr #26 eorne r5,r5,r8 - + mov r6,r6,lsl #1 tst r6,#0x10000 eorne r6,r6,r8 @@ -152,7 +152,7 @@ sd_crc16_loop: mov r7,r7,ror #4 subs r1,r1,#4 - bne sd_crc16_loop + bne sd_crc16_loop mov r2,r9 mov r8,#16 @@ -184,7 +184,7 @@ sd_crc16_write_data: @--------------u8 sd_crc7_s(u16* buff,u16 num)---------------------------- .ALIGN - .GLOBAL sd_crc7_s + .GLOBAL sd_crc7_s .CODE 32 sd_crc7_s: stmfd r13!,{r4} @@ -206,7 +206,7 @@ sd_crc7_loop: mov r4,r4,ror #1 subs r1,r1,#1 - bne sd_crc7_loop + bne sd_crc7_loop mov r3,r3,lsl #1 add r0,r3,#1 @@ -216,7 +216,7 @@ sd_crc7_loop: @--------------sd_com_read_s(u16* buff,u32 num)------------------ .ALIGN - .GLOBAL sd_com_read_s + .GLOBAL sd_com_read_s .CODE 32 sd_com_read_s: @@ -229,8 +229,8 @@ sd_com_read_loop1: sd_com_read_loop: ldmia r2,{r3-r6} - subs r1, r1, #1 - bne sd_com_read_loop + subs r1, r1, #1 + bne sd_com_read_loop ldmfd r13!,{r4-r6} bx r14 @--------------end sd_com_read_s------------------ @@ -242,14 +242,14 @@ sd_com_read_loop: .CODE 32 sd_com_write_s: stmfd r13!,{r4-r6} - + mov r2,#sd_comadd sd_com_write_busy: - ldrh r3,[r2] + ldrh r3,[r2] tst r3,#0x1 beq sd_com_write_busy - ldrh r3,[r2] + ldrh r3,[r2] sd_com_write_loop: ldrb r3,[r0],#1 @@ -257,9 +257,9 @@ sd_com_write_loop: mov r4,r3,lsl #2 mov r5,r4,lsl #2 mov r6,r5,lsl #2 - stmia r2,{r3-r6} - subs r1, r1, #1 - bne sd_com_write_loop + stmia r2,{r3-r6} + subs r1, r1, #1 + bne sd_com_write_loop ldmfd r13!,{r4-r6} bx r14 @@ -267,7 +267,7 @@ sd_com_write_loop: @-----------------void send_clk(u32 num)--------- .ALIGN - .GLOBAL send_clk + .GLOBAL send_clk .CODE 32 send_clk: @@ -281,7 +281,7 @@ send_clk_loop1: @---------------------------void SDCommand(u8 command,u8 num,u32 sector)-------------------- .ALIGN - .GLOBAL SDCommand + .GLOBAL SDCommand .CODE 32 @void SDCommand(u8 command,u8 num,u32 sector ) @{ @@ -338,12 +338,12 @@ SDCommand: @ register u16 i,j; @ i=readnum; @ sectno<<=9; -@ SDCommand(18,0,sector); +@ SDCommand(18,0,sector); @ for (j=0;j<i ; j++) @ { @ sd_data_read_s((u32)buff+j*512); @ } -@ SDCommand(12,0,0); +@ SDCommand(12,0,0); @ get_resp(); @ send_clk(0x10); @ @@ -363,7 +363,7 @@ beginforj_ReadSector: cmp r6,r5 bge endforj_ReadSector mov r0,r4 - add r0,r0,r6,lsl #9 + add r0,r0,r6,lsl #9 bl sd_data_read_s add r6,r6,#1 b beginforj_ReadSector @@ -408,17 +408,17 @@ get_resp: @ @ sectno<<=9; @ -@ SDCommand(25,0,sector); +@ SDCommand(25,0,sector); @ get_resp(); -@ send_clk(0x10); +@ send_clk(0x10); @ @ for (j=0;j<i ; j++) @ { @ sd_crc16_s((u32)(u32)buff+j*512,512,(u32)crc16); @ sd_data_write_s((u32)buff+j*512,(u32)crc16); -@ send_clk(0x10); +@ send_clk(0x10); @ } -@ SDCommand(12,0,0); +@ SDCommand(12,0,0); @ get_resp(); @ send_clk(0x10); @ while((*(u16*)sd_dataadd &0x0100)==0); @@ -451,7 +451,7 @@ beginforj_WriteSector: add r2,r13,#4 bl sd_crc16_s mov r0,r4 - add r0,r0,r6,lsl #9 + add r0,r0,r6,lsl #9 add r1,r13,#4 bl sd_data_write_s mov r0,#0x10 @@ -481,7 +481,7 @@ beginwhile_WriteSector: .GLOBAL InitSCMode .CODE 32 InitSCMode: - mvn r0,#0x0F6000000 + mvn r0,#0x0F6000000 sub r0,r0,#0x01 mov r1,#0x0A500 add r1,r1,#0x5A diff --git a/backends/platform/ds/arm9/source/fat/io_sd_common.c b/backends/platform/ds/arm9/source/fat/io_sd_common.c index 0a38e6277c..ade9df0d80 100644 --- a/backends/platform/ds/arm9/source/fat/io_sd_common.c +++ b/backends/platform/ds/arm9/source/fat/io_sd_common.c @@ -5,10 +5,10 @@ Common SD card routines - SD routines partially based on sd.s by Romman + SD routines partially based on sd.s by Romman Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -29,7 +29,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + 2006-08-07 - Chishm * Moved the SD initialization to a common function * Increased timeouts for slower cards @@ -61,10 +61,10 @@ u8 _SD_CRC7(u8* data, int cnt) { } crc = (crc << 1) | 1; return(crc); -} +} /* -Calculates the CRC16 for a sector of data. Calculates it +Calculates the CRC16 for a sector of data. Calculates it as 4 separate lots, merged into one buffer. This is used for 4 SD data lines, not for 1 data line alone. */ @@ -79,53 +79,53 @@ void _SD_CRC16 (u8* buff, int buffLength, u8* crc16buff) { b = 0; // r4 c = 0; // r5 d = 0; // r6 - + buffLength = buffLength * 8; - - + + do { if (bitPattern & 0x80) dataByte = *buff++; - + a = a << 1; if ( a & 0x10000) a ^= crcConst; if (dataByte & (bitPattern >> 24)) a ^= crcConst; - + b = b << 1; if (b & 0x10000) b ^= crcConst; if (dataByte & (bitPattern >> 25)) b ^= crcConst; - + c = c << 1; if (c & 0x10000) c ^= crcConst; if (dataByte & (bitPattern >> 26)) c ^= crcConst; - + d = d << 1; if (d & 0x10000) d ^= crcConst; if (dataByte & (bitPattern >> 27)) d ^= crcConst; - + bitPattern = (bitPattern >> 4) | (bitPattern << 28); } while (buffLength-=4); - + count = 16; // r8 - + do { bitPattern = bitPattern << 4; if (a & 0x8000) bitPattern |= 8; if (b & 0x8000) bitPattern |= 4; if (c & 0x8000) bitPattern |= 2; if (d & 0x8000) bitPattern |= 1; - + a = a << 1; b = b << 1; c = c << 1; d = d << 1; - + count--; - + if (!(count & 0x01)) { *crc16buff++ = (u8)(bitPattern & 0xff); } } while (count != 0); - + return; } @@ -136,20 +136,20 @@ cmd_17byte_response: a pointer to a function that sends the SD card a command an use4bitBus: initialise card to use a 4 bit data bus when communicating with the card RCA: a pointer to the location to store the card's Relative Card Address, preshifted up by 16 bits. */ -bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, +bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, _SD_FN_CMD_17BYTE_RESPONSE cmd_17byte_response, bool use4bitBus, u32 *RCA) { u8 responseBuffer[17] = {0}; int i; - + for (i = 0; i < MAX_STARTUP_TRIES ; i++) { cmd_6byte_response (responseBuffer, APP_CMD, 0); - if ( + if ( cmd_6byte_response (responseBuffer, SD_APP_OP_COND, SD_OCR_VALUE) && ((responseBuffer[1] & 0x80) != 0)) - { + { // Card is ready to receive commands now break; } @@ -157,10 +157,10 @@ bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, if (i >= MAX_STARTUP_TRIES) { return false; } - + // The card's name, as assigned by the manufacturer cmd_17byte_response (responseBuffer, ALL_SEND_CID, 0); - + // Get a new address for (i = 0; i < MAX_STARTUP_TRIES ; i++) { cmd_6byte_response (responseBuffer, SEND_RELATIVE_ADDR, 0); @@ -175,10 +175,10 @@ bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, // Some cards won't go to higher speeds unless they think you checked their capabilities cmd_17byte_response (responseBuffer, SEND_CSD, *RCA); - + // Only this card should respond to all future commands cmd_6byte_response (responseBuffer, SELECT_CARD, *RCA); - + if (use4bitBus) { // Set a 4 bit data bus cmd_6byte_response (responseBuffer, APP_CMD, *RCA); @@ -187,7 +187,7 @@ bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, // Use 512 byte blocks cmd_6byte_response (responseBuffer, SET_BLOCKLEN, 512); // 512 byte blocks - + // Wait until card is ready for data i = 0; do { @@ -196,7 +196,7 @@ bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, } i++; } while (!cmd_6byte_response (responseBuffer, SEND_STATUS, *RCA) && ((responseBuffer[3] & 0x1f) != ((SD_STATE_TRAN << 1) | READY_FOR_DATA))); - + return true; } diff --git a/backends/platform/ds/arm9/source/fat/io_sd_common.h b/backends/platform/ds/arm9/source/fat/io_sd_common.h index 09abffab39..8962d88890 100644 --- a/backends/platform/ds/arm9/source/fat/io_sd_common.h +++ b/backends/platform/ds/arm9/source/fat/io_sd_common.h @@ -8,7 +8,7 @@ SD routines partially based on sd.s by Romman Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -32,7 +32,7 @@ 2006-07-11 - Chishm * Original release - + 2006-07-28 - Chishm * Changed voltage range that the SD card can use */ @@ -76,7 +76,7 @@ #define SD_STATE_IDENT 2 // Identification state, after ALL_SEND_CID #define SD_STATE_STBY 3 // Standby state, when card is deselected #define SD_STATE_TRAN 4 // Transfer state, after card is selected and ready for data transfer -#define SD_STATE_DATA 5 // +#define SD_STATE_DATA 5 // #define SD_STATE_RCV 6 // Receive data state #define SD_STATE_PRG 7 // Programming state #define SD_STATE_DIS 8 // Disconnect state @@ -85,7 +85,7 @@ #define READY_FOR_DATA 1 // bit 8 in card status /* -Calculate the CRC7 of a command and return it preshifted with +Calculate the CRC7 of a command and return it preshifted with an end bit added */ extern u8 _SD_CRC7(u8* data, int size); @@ -106,7 +106,7 @@ cmd_17byte_response: a pointer to a function that sends the SD card a command an use4bitBus: initialise card to use a 4 bit data bus when communicating with the card RCA: a pointer to the location to store the card's Relative Card Address, preshifted up by 16 bits. */ -extern bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, +extern bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, _SD_FN_CMD_17BYTE_RESPONSE cmd_17byte_response, bool use4bitBus, u32 *RCA); |