aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/ds/arm9/source/fat/disc_io.c
diff options
context:
space:
mode:
authorNeil Millstone2008-05-15 22:12:51 +0000
committerNeil Millstone2008-05-15 22:12:51 +0000
commit2c5e8cc93861cded0b9a8ca7c605c61c7c2acc31 (patch)
treef5c0b1d4914d85d5f09eab5b739fbf9a4c3b59a8 /backends/platform/ds/arm9/source/fat/disc_io.c
parentdefc030143487550057cac1fb617d31ce9ab1ab2 (diff)
downloadscummvm-rg350-2c5e8cc93861cded0b9a8ca7c605c61c7c2acc31.tar.gz
scummvm-rg350-2c5e8cc93861cded0b9a8ca7c605c61c7c2acc31.tar.bz2
scummvm-rg350-2c5e8cc93861cded0b9a8ca7c605c61c7c2acc31.zip
Porting changes from 0.11.0 branch
svn-id: r32140
Diffstat (limited to 'backends/platform/ds/arm9/source/fat/disc_io.c')
-rw-r--r--backends/platform/ds/arm9/source/fat/disc_io.c68
1 files changed, 48 insertions, 20 deletions
diff --git a/backends/platform/ds/arm9/source/fat/disc_io.c b/backends/platform/ds/arm9/source/fat/disc_io.c
index f456343a2c..6d48674d62 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;
@@ -499,18 +499,46 @@ bool disc_WriteSectors(u32 sector, u8 numSecs, void* buffer)
#ifdef DISC_CACHE
disc_CacheInit();
#endif
+
+#define MISALIGNMENT_BODGE
+
+#ifdef MISALIGNMENT_BODGE
+ // This bodge works around problems with some card reader drivers which require data to be
+ // aligned to 2- or 4-byte boundaries it varies which one they require. This bodge sorts
+ // it but also reduces write speed as it doesn't use the multi-sector write capability any
+ // more. A better fix will be written for a future version.
+
+ if (active_interface) {
+ u8 sectorBuffer[512];
+ int r;
+
+ for (r = 0; r < numSecs; r++) {
+ memcpy(sectorBuffer, &buffer[r * 512], 512);
+
+ if (!active_interface->fn_WriteSectors(sector + r, 1, sectorBuffer))
+ {
+ return false;
+ }
+ }
+
+
+ return true;
+ }
+
+#else
if (active_interface) return active_interface->fn_WriteSectors(sector,numSecs,buffer) ;
return false ;
+#endif
//#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 +546,7 @@ bool disc_Shutdown(void)
if (active_interface) active_interface->fn_Shutdown() ;
active_interface = 0 ;
return true ;
-}
+}
u32 disc_HostType (void)
{