openMSX
SectorAccessibleDisk.hh
Go to the documentation of this file.
1 #ifndef SECTORACCESSIBLEDISK_HH
2 #define SECTORACCESSIBLEDISK_HH
3 
4 #include "Filename.hh"
5 #include "sha1.hh"
6 #include "openmsx.hh"
7 #include <vector>
8 #include <string>
9 #include <memory>
10 
11 namespace openmsx {
12 
13 class PatchInterface;
14 
16 {
17 public:
18  static const size_t SECTOR_SIZE = 512;
19 
20  virtual ~SectorAccessibleDisk();
21 
22  // sector stuff
23  void readSector(size_t sector, byte* buf);
24  void writeSector(size_t sector, const byte* buf);
25  size_t getNbSectors() const;
26 
27  // write protected stuff
28  bool isWriteProtected() const;
29  void forceWriteProtect();
30 
31  virtual bool isDummyDisk() const;
32 
33  // patch stuff
34  void applyPatch(const Filename& patchFile);
35  std::vector<Filename> getPatches() const;
36  bool hasPatches() const;
37 
41  virtual Sha1Sum getSha1Sum();
42 
43  // For compatibility with nowind
44  // - read/write multiple sectors instead of one-per-one
45  // - use error codes instead of exceptions
46  // - different order of parameters
47  int readSectors ( byte* buffer, size_t startSector,
48  size_t nbSectors);
49  int writeSectors(const byte* buffer, size_t startSector,
50  size_t nbSectors);
51 
52 protected:
54 
55  // Peek-mode changes the behaviour of readSector(). ATM it only has
56  // an effect on DirAsDSK. See comment in DirAsDSK::readSectorImpl()
57  // for more details.
58  void setPeekMode(bool peek) { peekMode = peek; }
59  bool isPeekMode() const { return peekMode; }
60 
61  virtual void checkCaches();
62  virtual void flushCaches();
63 
64 private:
65  virtual void readSectorImpl(size_t sector, byte* buf) = 0;
66  virtual void writeSectorImpl(size_t sector, const byte* 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