summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/Src/DriveBlob.cpp
diff options
context:
space:
mode:
authorhrydgard <hrydgard@gmail.com>2009-02-22 16:48:54 +0000
committerhrydgard <hrydgard@gmail.com>2009-02-22 16:48:54 +0000
commite3d1704979beb3fc4dc0db775d00aec420e926c7 (patch)
treeee7860a4a24d103f4bfb07d4eb142326b261424f /Source/Core/DiscIO/Src/DriveBlob.cpp
parent42a7d2fc85baa49c5b47907d3ce8ddf440d2af99 (diff)
Attempt to speed up drive reading by doing larger block reads - didn't help very much. we need to support async reads, I think.
Also delete some copypasta in DriveBlob - it already inherits those functions so it doesn't need them itself. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2368 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/DiscIO/Src/DriveBlob.cpp')
-rw-r--r--Source/Core/DiscIO/Src/DriveBlob.cpp64
1 files changed, 16 insertions, 48 deletions
diff --git a/Source/Core/DiscIO/Src/DriveBlob.cpp b/Source/Core/DiscIO/Src/DriveBlob.cpp
index 61a253548c..1ebef3af55 100644
--- a/Source/Core/DiscIO/Src/DriveBlob.cpp
+++ b/Source/Core/DiscIO/Src/DriveBlob.cpp
@@ -49,7 +49,7 @@ namespace DiscIO
#else
file_ = fopen(drive, "rb");
if (!file_)
- PanicAlert("Load from DVD backup failed");
+ PanicAlert("Load from DVD backup failed");
else
SetSectorSize(2048);
#endif
@@ -69,46 +69,13 @@ namespace DiscIO
#else
fclose(file_);
#endif
- } // DriveReader::~DriveReader
-
+ }
DriveReader * DriveReader::Create(const char *drive)
{
return new DriveReader(drive);
}
- bool DriveReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
- {
- u64 startingBlock = offset / m_blocksize;
- u64 remain = nbytes;
- int positionInBlock = (int)(offset % m_blocksize);
- u64 block = startingBlock;
-
- while (remain > 0)
- {
- const u8* data = GetBlockData(block);
- if (!data)
- return false;
-
- u32 toCopy = m_blocksize - positionInBlock;
- if (toCopy >= remain)
- {
- // yay, we are done!
- memcpy(out_ptr, data + positionInBlock, (size_t)remain);
- return true;
- }
- else
- {
- memcpy(out_ptr, data + positionInBlock, toCopy);
- out_ptr += toCopy;
- remain -= toCopy;
- positionInBlock = 0;
- block++;
- }
- }
- return true;
- } // DriveReader::Read
-
void DriveReader::GetBlock(u64 block_num, u8 *out_ptr)
{
u32 NotUsed;
@@ -124,23 +91,24 @@ namespace DiscIO
fseek(file_, m_blocksize*block_num, SEEK_SET);
fread(lpSector, 1, m_blocksize, file_);
#endif
-
memcpy(out_ptr, lpSector, m_blocksize);
delete lpSector;
}
- const u8 *DriveReader::GetBlockData(u64 block_num)
+ bool DriveReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 *out_ptr)
{
- if (SectorReader::cache_tags[0] == block_num)
- {
- return SectorReader::cache[0];
- }
- else
- {
- GetBlock(block_num, cache[0]);
- SectorReader::cache_tags[0] = block_num;
- return SectorReader::cache[0];
- }
+ u32 NotUsed;
+#ifdef _WIN32
+ u64 offset = m_blocksize * block_num;
+ LONG off_low = (LONG)offset & 0xFFFFFFFF;
+ LONG off_high = (LONG)(offset >> 32);
+ SetFilePointer(hDisc, off_low, &off_high, FILE_BEGIN);
+ if (!ReadFile(hDisc, out_ptr, (DWORD)(m_blocksize * num_blocks), (LPDWORD)&NotUsed, NULL))
+ PanicAlert("DRE");
+#else
+ fseek(file_, m_blocksize*block_num, SEEK_SET);
+ fread(out_ptr, 1, m_blocksize * num_blocks, file_);
+#endif
+ return true;
}
-
} // namespace