OXYGENHUB
◆ main openmsx / src / fdc / SectorAccessibleDisk.hh
2.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef SECTORACCESSIBLEDISK_HH
2
#define SECTORACCESSIBLEDISK_HH
3
4
#include "DiskImageUtils.hh"
5
#include "Filename.hh"
6
7
#include "sha1.hh"
8
9
#include <memory>
10
#include <span>
11
#include <vector>
12
13
namespace openmsx {
14
15
class FilePool;
16
class PatchInterface;
17
18
class SectorAccessibleDisk
19
{
20
public:
21
	static constexpr size_t SECTOR_SIZE = sizeof(SectorBuffer);
22
23
	// sector stuff
24
	void readSector (size_t sector,       SectorBuffer& buf);
25
	void writeSector(size_t sector, const SectorBuffer& buf);
26
	void readSectors (std::span<      SectorBuffer> buffers, size_t startSector);
27
	void writeSectors(std::span<const SectorBuffer> buffers, size_t startSector);
28
	[[nodiscard]] size_t getNbSectors();
29
30
	// write protected stuff
31
	[[nodiscard]] bool isWriteProtected() const;
32
	void forceWriteProtect();
33
34
	[[nodiscard]] virtual bool isDummyDisk() const;
35
36
	// patch stuff
37
	void applyPatch(Filename patchFile);
38
	[[nodiscard]] std::vector<Filename> getPatches() const;
39
	[[nodiscard]] bool hasPatches() const;
40
41
	/** Calculate SHA1 of the content of this disk.
42
	 * This value is cached (and flushed on writes).
43
	 */
44
	[[nodiscard]] Sha1Sum getSha1Sum(FilePool& filePool);
45
46
	// should only be called by EmptyDiskPatch
47
	virtual void readSectorsImpl(
48
		std::span<SectorBuffer> buffers, size_t startSector);
49
	// Default readSectorsImpl() implementation delegates to readSectorImpl.
50
	// Subclasses should override exactly one of these two.
51
	virtual void readSectorImpl(size_t sector, SectorBuffer& buf);
52
53
protected:
54
	SectorAccessibleDisk();
55
	~SectorAccessibleDisk();
56
57
	// Peek-mode changes the behaviour of readSector(). ATM it only has
58
	// an effect on DirAsDSK. See comment in DirAsDSK::readSectorImpl()
59
	// for more details.
60
	void setPeekMode(bool peek) { peekMode = peek; }
61
	[[nodiscard]] bool isPeekMode() const { return peekMode; }
62
63
	virtual void checkCaches();
64
	virtual void flushCaches();
65
	virtual Sha1Sum getSha1SumImpl(FilePool& filePool);
66
67
private:
68
	virtual void writeSectorImpl(size_t sector, const SectorBuffer& buf) = 0;
69
	[[nodiscard]] virtual size_t getNbSectorsImpl() = 0;
70
	[[nodiscard]] virtual bool isWriteProtectedImpl() const = 0;
71
72
private:
73
	std::unique_ptr<const PatchInterface> patch;
74
	Sha1Sum sha1cache;
75
	bool forcedWriteProtect = false;
76
	bool peekMode = false;
77
};
78
79
} // namespace openmsx
80
81
#endif