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 PatchInterface;
13 
15 {
16 public:
17  static const size_t SECTOR_SIZE = sizeof(SectorBuffer);
18 
19  virtual ~SectorAccessibleDisk();
20 
21  // sector stuff
22  void readSector (size_t sector, SectorBuffer& buf);
23  void writeSector(size_t sector, const SectorBuffer& buf);
24  size_t getNbSectors() const;
25 
26  // write protected stuff
27  bool isWriteProtected() const;
28  void forceWriteProtect();
29 
30  virtual bool isDummyDisk() const;
31 
32  // patch stuff
33  void applyPatch(const Filename& patchFile);
34  std::vector<Filename> getPatches() const;
35  bool hasPatches() const;
36 
40  virtual Sha1Sum getSha1Sum();
41 
42  // For compatibility with nowind
43  // - read/write multiple sectors instead of one-per-one
44  // - use error codes instead of exceptions
45  // - different order of parameters
46  int readSectors ( SectorBuffer* buffers, size_t startSector,
47  size_t nbSectors);
48  int writeSectors(const SectorBuffer* buffers, size_t startSector,
49  size_t nbSectors);
50 
51 protected:
53 
54  // Peek-mode changes the behaviour of readSector(). ATM it only has
55  // an effect on DirAsDSK. See comment in DirAsDSK::readSectorImpl()
56  // for more details.
57  void setPeekMode(bool peek) { peekMode = peek; }
58  bool isPeekMode() const { return peekMode; }
59 
60  virtual void checkCaches();
61  virtual void flushCaches();
62 
63 private:
64  virtual void readSectorImpl (size_t sector, SectorBuffer& buf) = 0;
65  virtual void writeSectorImpl(size_t sector, const SectorBuffer& buf) = 0;
66  virtual size_t getNbSectorsImpl() const = 0;
67  virtual bool isWriteProtectedImpl() const = 0;
68 
69  std::unique_ptr<const PatchInterface> patch;
70  Sha1Sum sha1cache;
71  bool forcedWriteProtect;
72  bool peekMode;
73 
74  friend class EmptyDiskPatch;
75 };
76 
77 } // namespace openmsx
78 
79 #endif
void readSector(size_t sector, SectorBuffer &buf)
int readSectors(SectorBuffer *buffers, size_t startSector, size_t nbSectors)
virtual Sha1Sum getSha1Sum()
Calculate SHA1 of the content of this disk.
This class represents the result of a sha1 calculation (a 160-bit value).
Definition: sha1.hh:18
void applyPatch(const Filename &patchFile)
This class represents a filename.
Definition: Filename.hh:17
int writeSectors(const SectorBuffer *buffers, size_t startSector, size_t nbSectors)
std::vector< Filename > getPatches() const
void writeSector(size_t sector, const SectorBuffer &buf)