openMSX
SectorAccessibleDisk.hh
Go to the documentation of this file.
1#ifndef SECTORACCESSIBLEDISK_HH
2#define SECTORACCESSIBLEDISK_HH
3
4#include "DiskImageUtils.hh"
5#include "Filename.hh"
6#include "sha1.hh"
7#include <memory>
8#include <span>
9#include <vector>
10
11namespace openmsx {
12
13class FilePool;
14class PatchInterface;
15
17{
18public:
19 static constexpr size_t SECTOR_SIZE = sizeof(SectorBuffer);
20
21 // sector stuff
22 void readSector (size_t sector, SectorBuffer& buf);
23 void writeSector(size_t sector, const SectorBuffer& buf);
24 void readSectors (std::span< SectorBuffer> buffers, size_t startSector);
25 void writeSectors(std::span<const SectorBuffer> buffers, size_t startSector);
26 [[nodiscard]] size_t getNbSectors() const;
27
28 // write protected stuff
29 [[nodiscard]] bool isWriteProtected() const;
30 void forceWriteProtect();
31
32 [[nodiscard]] virtual bool isDummyDisk() const;
33
34 // patch stuff
35 void applyPatch(Filename patchFile);
36 [[nodiscard]] std::vector<Filename> getPatches() const;
37 [[nodiscard]] bool hasPatches() const;
38
42 [[nodiscard]] Sha1Sum getSha1Sum(FilePool& filePool);
43
44 // should only be called by EmptyDiskPatch
45 virtual void readSectorsImpl(
46 std::span<SectorBuffer> buffers, size_t startSector);
47 // Default readSectorsImpl() implementation delegates to readSectorImpl.
48 // Subclasses should override exactly one of these two.
49 virtual void readSectorImpl(size_t sector, SectorBuffer& buf);
50
51protected:
54
55 // Peek-mode changes the behaviour of readSector(). ATM it only has
56 // an effect on DirAsDSK. See comment in DirAsDSK::readSectorImpl()
57 // for more details.
58 void setPeekMode(bool peek) { peekMode = peek; }
59 [[nodiscard]] bool isPeekMode() const { return peekMode; }
60
61 virtual void checkCaches();
62 virtual void flushCaches();
63 virtual Sha1Sum getSha1SumImpl(FilePool& filePool);
64
65private:
66 virtual void writeSectorImpl(size_t sector, const SectorBuffer& buf) = 0;
67 [[nodiscard]] virtual size_t getNbSectorsImpl() const = 0;
68 [[nodiscard]] virtual bool isWriteProtectedImpl() const = 0;
69
70private:
71 std::unique_ptr<const PatchInterface> patch;
72 Sha1Sum sha1cache;
73 bool forcedWriteProtect = false;
74 bool peekMode = false;
75};
76
77} // namespace openmsx
78
79#endif
This class represents a filename.
Definition Filename.hh:18
void writeSectors(std::span< const SectorBuffer > buffers, size_t startSector)
virtual Sha1Sum getSha1SumImpl(FilePool &filePool)
Sha1Sum getSha1Sum(FilePool &filePool)
Calculate SHA1 of the content of this disk.
void readSector(size_t sector, SectorBuffer &buf)
void readSectors(std::span< SectorBuffer > buffers, size_t startSector)
static constexpr size_t SECTOR_SIZE
virtual void readSectorsImpl(std::span< SectorBuffer > buffers, size_t startSector)
std::vector< Filename > getPatches() const
void applyPatch(Filename patchFile)
void writeSector(size_t sector, const SectorBuffer &buf)
virtual void readSectorImpl(size_t sector, SectorBuffer &buf)
This class represents the result of a sha1 calculation (a 160-bit value).
Definition sha1.hh:23
This file implemented 3 utility functions:
Definition Autofire.cc:9