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