openMSX
AmdFlash.hh
Go to the documentation of this file.
1 #ifndef AMDFLASH_HH
2 #define AMDFLASH_HH
3 
4 #include "MemBuffer.hh"
5 #include "openmsx.hh"
6 #include "serialize_meta.hh"
7 #include <memory>
8 #include <vector>
9 
10 namespace openmsx {
11 
12 class MSXMotherBoard;
13 class Rom;
14 class SRAM;
15 class DeviceConfig;
16 
17 class AmdFlash
18 {
19 public:
20  struct SectorInfo {
21  unsigned size;
23  };
40  AmdFlash(const Rom& rom, std::vector<SectorInfo> sectorInfo,
41  word ID, bool use12bitAddressing,
42  const DeviceConfig& config, bool load = true);
43  AmdFlash(const std::string& name, std::vector<SectorInfo> sectorInfo,
44  word ID, bool use12bitAddressing,
45  const DeviceConfig& config);
46  ~AmdFlash();
47 
48  void reset();
55  void setVppWpPinLow(bool value) { vppWpPinLow = value; }
56 
57  unsigned getSize() const { return size; }
58  byte read(unsigned address);
59  byte peek(unsigned address) const;
60  void write(unsigned address, byte value);
61  const byte* getReadCacheLine(unsigned address) const;
62 
63  template<typename Archive>
64  void serialize(Archive& ar, unsigned version);
65 
66 //private:
67  struct AmdCmd {
68  unsigned addr;
70 
71  template<typename Archive>
72  void serialize(Archive& ar, unsigned version);
73  };
74 
75  enum State { ST_IDLE, ST_IDENT };
76 
77 private:
78  void init(const std::string& name, const DeviceConfig& config, bool load, const Rom* rom);
79  void getSectorInfo(unsigned address, unsigned& sector,
80  unsigned& sectorSize, unsigned& offset) const;
81 
82  void setState(State newState);
83  bool checkCommandReset();
84  bool checkCommandEraseSector();
85  bool checkCommandEraseChip();
86  bool checkCommandProgramHelper(unsigned numBytes, const byte* cmdSeq, size_t cmdLen);
87  bool checkCommandProgram();
88  bool checkCommandDoubleByteProgram();
89  bool checkCommandQuadrupleByteProgram();
90  bool checkCommandManufacturer();
91  bool partialMatch(size_t len, const byte* dataSeq) const;
92 
93  bool isSectorWritable(unsigned sector) const;
94 
95  MSXMotherBoard& motherBoard;
96  std::unique_ptr<SRAM> ram;
97  MemBuffer<int> writeAddress;
98  MemBuffer<const byte*> readAddress;
99  const std::vector<SectorInfo> sectorInfo;
100  const unsigned size;
101  const word ID;
102  const bool use12bitAddressing;
103 
104  static const unsigned MAX_CMD_SIZE = 8;
105  AmdCmd cmd[MAX_CMD_SIZE];
106  unsigned cmdIdx;
107  State state = ST_IDLE;
108  bool vppWpPinLow = false; // true = protection on
109 };
111 
112 } // namespace openmsx
113 
114 #endif
byte read(unsigned address)
Definition: AmdFlash.cc:252
const byte * getReadCacheLine(unsigned address) const
Definition: AmdFlash.cc:258
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
void setVppWpPinLow(bool value)
Setting the Vpp/WP# pin LOW enables a certain kind of write protection of some sectors.
Definition: AmdFlash.hh:55
byte peek(unsigned address) const
Definition: AmdFlash.cc:215
SRAM
Definition: SRAM.cc:150
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
unsigned getSize() const
Definition: AmdFlash.hh:57
void serialize(Archive &ar, unsigned version)
Definition: AmdFlash.cc:412
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
XMLElement load(string_view filename, string_view systemID)
Definition: XMLLoader.cc:31
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
void write(unsigned address, byte value)
Definition: AmdFlash.cc:270
AmdFlash(const Rom &rom, std::vector< SectorInfo > sectorInfo, word ID, bool use12bitAddressing, const DeviceConfig &config, bool load=true)
Create AmdFlash with given configuration.
Definition: AmdFlash.cc:25