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