mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-16 07:50:28 +02:00
Replace zlib, zstd, libchdr, libzip and libpng with libretro-common
Deflate, zlib and gzip streams go through rinflate and rdeflate, zstd through rzstd, CHD images through rchd, zip archives through rzip_archive and PNG through rpng. The bundled libraries, their build glue and the system-library options are gone; adler32 and uncompress keep zlib's ABI for the prebuilt FFmpeg archives that still call them. libretro-common is one CMake library that the core, the headless tool and the unit tests all link. The reads take shorter paths on the way. CHD decodes straight from the loader's reads and a range of blocks at a time, and a file read at any alignment decodes into place; CSO keeps one inflate stream instead of one per block; a plain ISO serves a file read with one read of its exact bytes; a stored zip member is read in place and a deflated one through restart points rather than a copy of the whole image in memory; zip members decode into the caller's buffer; sequential reads through the frontend's VFS skip the seek, which also keeps its buffering. libretro/test reads one image as ISO, CSO, CHD and zip through the block devices, boots each, and checks the codecs against Python-made vectors; a CI job runs it.
This commit is contained in:
1 parent
6b22f99818
commit
d56b453891
252 files changed
+1751
-91370
No files matched your search
@@ -520,22 +520,7 @@ int ISOFileSystem::Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outd
|
||||
int block = (u16)desc.firstLETableSector;
|
||||
u32 size = Memory::ClampValidSizeAt(outdataPtr, (u32)desc.pathTableLength);
|
||||
u8 *out = Memory::GetPointerWriteRangeOrException(outdataPtr, size);
|
||||
|
||||
int blocks = size / blockDevice->GetBlockSize();
|
||||
blockDevice->ReadBlocks(block, blocks, out);
|
||||
size -= blocks * blockDevice->GetBlockSize();
|
||||
out += blocks * blockDevice->GetBlockSize();
|
||||
|
||||
// The remaining (or, usually, only) partial sector.
|
||||
if (size > 0) {
|
||||
u8 temp[2048];
|
||||
// `blocks` whole sectors starting at `block` were already consumed by
|
||||
// ReadBlocks() above, so the trailing partial sector is the next one.
|
||||
if (!blockDevice->ReadBlock(block + blocks, temp)) {
|
||||
memset(temp, 0, sizeof(temp));
|
||||
}
|
||||
memcpy(out, temp, size);
|
||||
}
|
||||
blockDevice->ReadBytes((u64)block * blockDevice->GetBlockSize(), size, out);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -617,44 +602,10 @@ size_t ISOFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) {
|
||||
}
|
||||
|
||||
// Okay, we have size and position, let's rock.
|
||||
const int firstBlockOffset = positionOnIso & 2047;
|
||||
const int firstBlockSize = firstBlockOffset == 0 ? 0 : (int)std::min(size, 2048LL - firstBlockOffset);
|
||||
const int lastBlockSize = (size - firstBlockSize) & 2047;
|
||||
const s64 middleSize = size - firstBlockSize - lastBlockSize;
|
||||
_dbg_assert_((middleSize & 2047) == 0);
|
||||
|
||||
u32 secNum = (u32)(positionOnIso / 2048);
|
||||
u8 theSector[2048];
|
||||
|
||||
if ((middleSize & 2047) != 0) {
|
||||
ERROR_LOG(Log::FileSystem, "Remaining size should be aligned");
|
||||
}
|
||||
|
||||
const u8 *const start = pointer;
|
||||
if (firstBlockSize > 0) {
|
||||
// theSector is uninitialized stack memory, so on a failed read we must not copy it out -
|
||||
// that would hand host stack contents to the game.
|
||||
if (!blockDevice->ReadBlock(secNum++, theSector)) {
|
||||
memset(theSector, 0, sizeof(theSector));
|
||||
}
|
||||
memcpy(pointer, theSector + firstBlockOffset, firstBlockSize);
|
||||
pointer += firstBlockSize;
|
||||
}
|
||||
if (middleSize > 0) {
|
||||
const u32 middleSectors = (u32)(middleSize / 2048);
|
||||
blockDevice->ReadBlocks(secNum, middleSectors, pointer);
|
||||
secNum += middleSectors;
|
||||
pointer += middleSize;
|
||||
}
|
||||
if (lastBlockSize > 0) {
|
||||
if (!blockDevice->ReadBlock(secNum++, theSector)) {
|
||||
memset(theSector, 0, sizeof(theSector));
|
||||
}
|
||||
memcpy(pointer, theSector, lastBlockSize);
|
||||
pointer += lastBlockSize;
|
||||
}
|
||||
|
||||
size_t totalBytes = pointer - start;
|
||||
blockDevice->ReadBytes(positionOnIso, (size_t)size, pointer);
|
||||
// The sector after the last one touched, for the seek-time estimate.
|
||||
const u32 secNum = (u32)(size > 0 ? (positionOnIso + size + 2047) / 2048 : positionOnIso / 2048);
|
||||
const size_t totalBytes = (size_t)size;
|
||||
if (abs((int)lastReadBlock_ - (int)secNum) > 100) {
|
||||
// This is an estimate, sometimes it takes 1+ seconds, but it definitely takes time.
|
||||
usec = 100000;
|
||||
|
||||
Reference in new issue
Block a user