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 const 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  size_t getNbSectors() const;
24 
25  // write protected stuff
26  bool isWriteProtected() const;
27  void forceWriteProtect();
28 
29  virtual bool isDummyDisk() const;
30 
31  // patch stuff
32  void applyPatch(const Filename& patchFile);
33  std::vector<Filename> getPatches() const;
34  bool hasPatches() const;
35 
39  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 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  virtual Sha1Sum getSha1SumImpl(FilePool& filepool);
63 
64 private:
65  virtual void readSectorImpl (size_t sector, SectorBuffer& buf) = 0;
66  virtual void writeSectorImpl(size_t sector, const SectorBuffer& buf) = 0;
67  virtual size_t getNbSectorsImpl() const = 0;
68  virtual bool isWriteProtectedImpl() const = 0;
69 
70  std::unique_ptr<const PatchInterface> patch;
71  Sha1Sum sha1cache;
72  bool forcedWriteProtect;
73  bool peekMode;
74 
75  friend class EmptyDiskPatch;
76 };
77 
78 } // namespace openmsx
79 
80 #endif
void readSector(size_t sector, SectorBuffer &buf)
int readSectors(SectorBuffer *buffers, size_t startSector, size_t nbSectors)
Sha1Sum getSha1Sum(FilePool &filepool)
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:5
virtual Sha1Sum getSha1SumImpl(FilePool &filepool)
int writeSectors(const SectorBuffer *buffers, size_t startSector, size_t nbSectors)
std::vector< Filename > getPatches() const
void writeSector(size_t sector, const SectorBuffer &buf)