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  [[nodiscard]] size_t getNbSectors() const;
24 
25  // write protected stuff
26  [[nodiscard]] bool isWriteProtected() const;
27  void forceWriteProtect();
28 
29  [[nodiscard]] virtual bool isDummyDisk() const;
30 
31  // patch stuff
32  void applyPatch(Filename patchFile);
33  [[nodiscard]] std::vector<Filename> getPatches() const;
34  [[nodiscard]] bool hasPatches() const;
35 
39  [[nodiscard]] Sha1Sum getSha1Sum(FilePool& filepool);
40 
41  // For compatibility with nowind
42  // - read/write multiple sectors instead of one-per-one
43  // - use error codes instead of exceptions
44  // - different order of parameters
45  int readSectors ( SectorBuffer* buffers, size_t startSector,
46  size_t nbSectors);
47  int writeSectors(const SectorBuffer* buffers, size_t startSector,
48  size_t nbSectors);
49 
50  // should only be called by EmptyDiskPatch
51  virtual void readSectorImpl (size_t sector, SectorBuffer& buf) = 0;
52 
53 protected:
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() const = 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
openmsx::SectorAccessibleDisk::getSha1SumImpl
virtual Sha1Sum getSha1SumImpl(FilePool &filepool)
Definition: SectorAccessibleDisk.cc:81
openmsx::SectorAccessibleDisk
Definition: SectorAccessibleDisk.hh:16
openmsx::SectorBuffer
Definition: DiskImageUtils.hh:90
openmsx::SectorAccessibleDisk::forceWriteProtect
void forceWriteProtect()
Definition: SectorAccessibleDisk.cc:130
sha1.hh
openmsx::SectorAccessibleDisk::isPeekMode
bool isPeekMode() const
Definition: SectorAccessibleDisk.hh:61
openmsx::SectorAccessibleDisk::writeSector
void writeSector(size_t sector, const SectorBuffer &buf)
Definition: SectorAccessibleDisk.cc:36
openmsx::SectorAccessibleDisk::SECTOR_SIZE
static constexpr size_t SECTOR_SIZE
Definition: SectorAccessibleDisk.hh:18
openmsx::SectorAccessibleDisk::isWriteProtected
bool isWriteProtected() const
Definition: SectorAccessibleDisk.cc:125
openmsx::SectorAccessibleDisk::readSector
void readSector(size_t sector, SectorBuffer &buf)
Definition: SectorAccessibleDisk.cc:18
openmsx::SectorAccessibleDisk::getNbSectors
size_t getNbSectors() const
Definition: SectorAccessibleDisk.cc:52
openmsx::SectorAccessibleDisk::readSectorImpl
virtual void readSectorImpl(size_t sector, SectorBuffer &buf)=0
Filename.hh
openmsx::SectorAccessibleDisk::hasPatches
bool hasPatches() const
Definition: SectorAccessibleDisk.cc:67
DiskImageUtils.hh
openmsx::SectorAccessibleDisk::isDummyDisk
virtual bool isDummyDisk() const
Definition: SectorAccessibleDisk.cc:136
openmsx::SectorAccessibleDisk::flushCaches
virtual void flushCaches()
Definition: SectorAccessibleDisk.cc:146
openmsx::Sha1Sum
This class represents the result of a sha1 calculation (a 160-bit value).
Definition: sha1.hh:20
openmsx::SectorAccessibleDisk::setPeekMode
void setPeekMode(bool peek)
Definition: SectorAccessibleDisk.hh:60
openmsx::SectorAccessibleDisk::checkCaches
virtual void checkCaches()
Definition: SectorAccessibleDisk.cc:141
openmsx::SectorAccessibleDisk::SectorAccessibleDisk
SectorAccessibleDisk()
Definition: SectorAccessibleDisk.cc:11
openmsx::FilePool
Definition: FilePool.hh:16
openmsx::SectorAccessibleDisk::applyPatch
void applyPatch(Filename patchFile)
Definition: SectorAccessibleDisk.cc:57
openmsx::SectorAccessibleDisk::~SectorAccessibleDisk
~SectorAccessibleDisk()
openmsx::SectorAccessibleDisk::getSha1Sum
Sha1Sum getSha1Sum(FilePool &filepool)
Calculate SHA1 of the content of this disk.
Definition: SectorAccessibleDisk.cc:72
openmsx::SectorAccessibleDisk::readSectors
int readSectors(SectorBuffer *buffers, size_t startSector, size_t nbSectors)
Definition: SectorAccessibleDisk.cc:99
openmsx::Filename
This class represents a filename.
Definition: Filename.hh:18
openmsx::SectorAccessibleDisk::writeSectors
int writeSectors(const SectorBuffer *buffers, size_t startSector, size_t nbSectors)
Definition: SectorAccessibleDisk.cc:112
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::SectorAccessibleDisk::getPatches
std::vector< Filename > getPatches() const
Definition: SectorAccessibleDisk.cc:62