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
7#include "sha1.hh"
8
9#include <memory>
10#include <span>
11#include <vector>
12
13namespace openmsx {
14
15class FilePool;
16class PatchInterface;
17
19{
20public:
21 static constexpr size_t SECTOR_SIZE = sizeof(SectorBuffer);
22
23 // sector stuff
24 void readSector (size_t sector, SectorBuffer& buf) const;
25 void writeSector(size_t sector, const SectorBuffer& buf);
26 void readSectors (std::span< SectorBuffer> buffers, size_t startSector) const;
27 void writeSectors(std::span<const SectorBuffer> buffers, size_t startSector);
28 [[nodiscard]] size_t getNbSectors() const;
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
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
53protected:
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
67private:
68 virtual void writeSectorImpl(size_t sector, const SectorBuffer& buf) = 0;
69 [[nodiscard]] virtual size_t getNbSectorsImpl() const = 0;
70 [[nodiscard]] virtual bool isWriteProtectedImpl() const = 0;
71
72private:
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
This class represents a filename.
Definition Filename.hh:20
void writeSectors(std::span< const SectorBuffer > buffers, size_t startSector)
void readSectors(std::span< SectorBuffer > buffers, size_t startSector) const
virtual Sha1Sum getSha1SumImpl(FilePool &filePool)
Sha1Sum getSha1Sum(FilePool &filePool)
Calculate SHA1 of the content of this disk.
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 readSector(size_t sector, SectorBuffer &buf) const
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:24
This file implemented 3 utility functions:
Definition Autofire.cc:11