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);
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;
69  byte value;
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 constexpr 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
openmsx.hh
openmsx::AmdFlash::ST_IDENT
@ ST_IDENT
Definition: AmdFlash.hh:75
openmsx::AmdFlash
Definition: AmdFlash.hh:18
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
serialize_meta.hh
openmsx::AmdFlash::AmdCmd::value
byte value
Definition: AmdFlash.hh:69
openmsx::YM2413NukeYKT::rom
constexpr Rom rom
Definition: YM2413NukeYKT.cc:71
openmsx::AmdFlash::AmdFlash
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:26
openmsx::AmdFlash::getReadCacheLine
const byte * getReadCacheLine(unsigned address) const
Definition: AmdFlash.cc:259
openmsx::AmdFlash::~AmdFlash
~AmdFlash()
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::SRAM
SRAM
Definition: SRAM.cc:150
openmsx::AmdFlash::setVppWpPinLow
void setVppWpPinLow(bool value)
Setting the Vpp/WP# pin LOW enables a certain kind of write protection of some sectors.
Definition: AmdFlash.hh:55
openmsx::AmdFlash::write
void write(unsigned address, byte value)
Definition: AmdFlash.cc:271
openmsx::AmdFlash::ST_IDLE
@ ST_IDLE
Definition: AmdFlash.hh:75
openmsx::AmdFlash::AmdCmd::addr
unsigned addr
Definition: AmdFlash.hh:68
openmsx::AmdFlash::peek
byte peek(unsigned address) const
Definition: AmdFlash.cc:216
openmsx::MemBuffer< int >
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:60
openmsx::AmdFlash::SectorInfo::size
unsigned size
Definition: AmdFlash.hh:21
openmsx::AmdFlash::serialize
void serialize(Archive &ar, unsigned version)
Definition: AmdFlash.cc:413
MemBuffer.hh
openmsx::Rom
Definition: Rom.hh:21
openmsx::AmdFlash::reset
void reset()
Definition: AmdFlash.cc:203
openmsx::XMLLoader::load
XMLElement load(string_view filename, string_view systemID)
Definition: XMLLoader.cc:34
openmsx::AmdFlash::SectorInfo
Definition: AmdFlash.hh:20
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::AmdFlash::read
byte read(unsigned address)
Definition: AmdFlash.cc:253
openmsx::AmdFlash::AmdCmd::serialize
void serialize(Archive &ar, unsigned version)
Definition: AmdFlash.cc:406
openmsx::AmdFlash::AmdCmd
Definition: AmdFlash.hh:67
openmsx::AmdFlash::getSize
unsigned getSize() const
Definition: AmdFlash.hh:57
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::AmdFlash::State
State
Definition: AmdFlash.hh:75
openmsx::AmdFlash::SectorInfo::writeProtected
bool writeProtected
Definition: AmdFlash.hh:22