mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-15 15:30:29 +02:00
The core and the headless tools no longer use mutexes, condition variables, spinlocks, std::atomic, std::thread or volatile flags. Threads hand off through libretro-common's retro_atomic and rthreads plus a few small pieces on top of them in Common/Thread: Thread, MpscQueue, EventCounter, ParkingLot waits and ReaderGate. Every wait blocks until it's woken; nothing polls on a timer. State that only one thread touches just loses its lock. The PSP filesystem, sceIo and the savedata dialog now belong to the emulation thread: async reads and writes run when they're queued and complete later in emulated time, and the IO and savedata threads are gone. The friend finder only talks to the adhoc server and hands what it gets to the emulation thread. GPU init always runs on the thread that starts the game. The Vulkan render and compile queues, pipeline and render pass caches, delete list and SPIR-V cache, the GL render queue, the software renderer's jit caches, the file loader caches, the web debugger, UPnP, input, savestates, logging and the GE debugger all hand off through queues and atomics. The IR jit's spinning profiler thread goes. A CPU thread with nothing to run now sleeps until work is queued instead of spinning. Headless with --debugger waits for a client while stopped, and ends the run once every client that connected has left. Web server shutdown keeps servicing the CPU queue until the server has finished.
220 lines
6.4 KiB
C++
220 lines
6.4 KiB
C++
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
// Official git repository and contact information can be found at
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
#pragma once
|
|
|
|
// Abstractions around read-only blockdevices, such as PSP UMD discs.
|
|
// CISOFileBlockDevice implements compressed iso images, CISO format.
|
|
//
|
|
// The ISOFileSystemReader reads from a BlockDevice, so it automatically works
|
|
// with CISO images.
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "ext/libkirk/kirk_engine.h"
|
|
|
|
class FileLoader;
|
|
|
|
class BlockDevice {
|
|
public:
|
|
BlockDevice(FileLoader *fileLoader) : fileLoader_(fileLoader) {}
|
|
virtual ~BlockDevice() {}
|
|
virtual bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) = 0;
|
|
virtual bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) {
|
|
for (int b = 0; b < count; ++b) {
|
|
if (!ReadBlock(minBlock + b, outPtr)) {
|
|
return false;
|
|
}
|
|
outPtr += GetBlockSize();
|
|
}
|
|
return true;
|
|
}
|
|
// Bytes [offset, offset + len) of the image, at any alignment. The default reads the
|
|
// partial blocks at either end through a sector buffer; devices that can address bytes
|
|
// read straight into out instead.
|
|
virtual bool ReadBytes(u64 offset, size_t len, u8 *out);
|
|
int constexpr GetBlockSize() const { return 2048;} // forced, it cannot be changed by subclasses. If a subclass uses bigger blocks internally, it must cache and virtualize.
|
|
virtual u32 GetNumBlocks() const = 0;
|
|
virtual u64 GetUncompressedSize() const {
|
|
return (u64)GetNumBlocks() * (u64)GetBlockSize();
|
|
}
|
|
virtual bool IsDisc() const = 0;
|
|
|
|
void NotifyReadError();
|
|
|
|
bool IsOK() const { return errorString_.empty(); }
|
|
const std::string &ErrorString() { return errorString_; }
|
|
|
|
protected:
|
|
FileLoader *fileLoader_;
|
|
bool reportedError_ = false;
|
|
|
|
std::string errorString_;
|
|
};
|
|
|
|
class CISOFileBlockDevice : public BlockDevice {
|
|
public:
|
|
CISOFileBlockDevice(FileLoader *fileLoader);
|
|
~CISOFileBlockDevice();
|
|
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
|
|
bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override;
|
|
u32 GetNumBlocks() const override { return numBlocks; }
|
|
bool IsDisc() const override { return true; }
|
|
|
|
private:
|
|
u32 *index = nullptr;
|
|
u8 *readBuffer = nullptr;
|
|
size_t readBufferSize = 0;
|
|
u8 *zlibBuffer = nullptr;
|
|
u32 zlibBufferFrame = 0;
|
|
void *inflate_ = nullptr; // one rinflate stream, reset per frame
|
|
u8 indexShift = 0;
|
|
u8 blockShift = 0;
|
|
u32 frameSize = 0;
|
|
u32 numBlocks = 0;
|
|
u32 numFrames = 0;
|
|
int ver_ = 0;
|
|
};
|
|
|
|
class FileBlockDevice : public BlockDevice {
|
|
public:
|
|
FileBlockDevice(FileLoader *fileLoader);
|
|
~FileBlockDevice();
|
|
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
|
|
bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override;
|
|
bool ReadBytes(u64 offset, size_t len, u8 *out) override;
|
|
u32 GetNumBlocks() const override {return (u32)(filesize_ / GetBlockSize());}
|
|
bool IsDisc() const override { return true; }
|
|
u64 GetUncompressedSize() const override {
|
|
return filesize_;
|
|
}
|
|
private:
|
|
u64 filesize_;
|
|
};
|
|
|
|
class UDFFileBlockDevice : public BlockDevice {
|
|
public:
|
|
UDFFileBlockDevice(FileLoader *fileLoader);
|
|
~UDFFileBlockDevice();
|
|
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
|
|
bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override;
|
|
u32 GetNumBlocks() const override { return numBlocks_; }
|
|
bool IsDisc() const override { return true; }
|
|
u64 GetUncompressedSize() const override {
|
|
return (u64)numBlocks_ * (u64)GetBlockSize();
|
|
}
|
|
|
|
private:
|
|
struct Extent {
|
|
u32 startBlock = 0;
|
|
u32 numBlocks = 0;
|
|
};
|
|
|
|
Extent layer0_{};
|
|
Extent layer1_{};
|
|
u32 numBlocks_ = 0;
|
|
};
|
|
|
|
class ISOContainerFileBlockDevice : public BlockDevice {
|
|
public:
|
|
ISOContainerFileBlockDevice(FileLoader *fileLoader);
|
|
~ISOContainerFileBlockDevice();
|
|
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
|
|
bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override;
|
|
u32 GetNumBlocks() const override { return numBlocks_; }
|
|
bool IsDisc() const override { return true; }
|
|
u64 GetUncompressedSize() const override {
|
|
return (u64)numBlocks_ * (u64)GetBlockSize();
|
|
}
|
|
|
|
private:
|
|
struct Extent {
|
|
u32 startBlock = 0;
|
|
u32 numBlocks = 0;
|
|
};
|
|
|
|
std::shared_ptr<BlockDevice> outerBlockDevice_;
|
|
Extent layer0_{};
|
|
Extent layer1_{};
|
|
u32 numBlocks_ = 0;
|
|
};
|
|
|
|
|
|
// For encrypted ISOs in PBP files.
|
|
|
|
struct table_info {
|
|
u8 mac[16];
|
|
u32 offset;
|
|
int size;
|
|
int flag;
|
|
int unk_1c;
|
|
};
|
|
|
|
class NPDRMDemoBlockDevice : public BlockDevice {
|
|
public:
|
|
NPDRMDemoBlockDevice(FileLoader *fileLoader);
|
|
~NPDRMDemoBlockDevice();
|
|
|
|
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
|
|
u32 GetNumBlocks() const override {return (u32)lbaSize_;}
|
|
bool IsDisc() const override { return false; }
|
|
|
|
private:
|
|
// Used from one thread at a time (the emulation thread, or the loader thread before it).
|
|
u32 lbaSize_ = 0;
|
|
|
|
u32 psarOffset = 0;
|
|
int blockSize_ = 0;
|
|
int blockLBAs_ = 0;
|
|
u32 numBlocks_ = 0;
|
|
|
|
u8 vkey[16]{};
|
|
u8 hkey[16]{};
|
|
struct table_info *table_ = nullptr;
|
|
|
|
int currentBlock_ = 0;
|
|
u8 *blockBuf_ = nullptr;
|
|
u8 *tempBuf_ = nullptr;
|
|
|
|
// Each block device gets its own private kirk. Multiple ones can be in flight
|
|
// to load metadata.
|
|
KirkState kirk_{};
|
|
};
|
|
|
|
struct rchd;
|
|
|
|
class CHDFileBlockDevice : public BlockDevice {
|
|
public:
|
|
CHDFileBlockDevice(FileLoader *fileLoader);
|
|
~CHDFileBlockDevice();
|
|
bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override;
|
|
bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override;
|
|
bool ReadBytes(u64 offset, size_t len, u8 *out) override;
|
|
u32 GetNumBlocks() const override { return numBlocks; }
|
|
bool IsDisc() const override { return true; }
|
|
private:
|
|
bool ReadRange(u64 offset, size_t len, u8 *out);
|
|
struct rchd *chd_ = nullptr;
|
|
std::vector<u8> scratch_; // compressed bytes, borrowed by the decoder
|
|
u32 numBlocks = 0;
|
|
};
|
|
|
|
BlockDevice *ConstructBlockDevice(FileLoader *fileLoader, std::string *errorString);
|