openMSX
EEPROM_93C46.hh
Go to the documentation of this file.
1 #ifndef EEPROM_93C46_HH
2 #define EEPROM_93C46_HH
3 
4 #include "EmuTime.hh"
5 #include "SRAM.hh"
6 #include <climits>
7 #include <string>
8 
9 namespace openmsx {
10 
11 class DeviceConfig;
12 class XMLElement;
13 
15 {
16 public:
17  static constexpr uint8_t ADDRESS_BITS = 7;
18  static constexpr uint32_t NUM_ADDRESSES = 1 << ADDRESS_BITS;
19  static constexpr uint32_t ADDRESS_MASK = NUM_ADDRESSES - 1;
20  static constexpr uint8_t DATA_BITS = 8; // only 8-bit mode implemented
21 
22 public:
23  EEPROM_93C46(const XMLElement& xml); // unittest
24  EEPROM_93C46(const std::string& name, const DeviceConfig& config);
25 
26  void reset();
27 
28  bool read_DO(EmuTime::param time) const;
29  void write_CS (bool value, EmuTime::param time);
30  void write_CLK(bool value, EmuTime::param time);
31  void write_DI (bool value, EmuTime::param time);
32 
33  template<typename Archive>
34  void serialize(Archive& ar, unsigned version);
35 
36  // for unittest
37  const uint8_t* backdoor() const {
38  return &sram[0];
39  }
40 
41 private:
42  uint8_t read(unsigned addr);
43  void write(unsigned addr, uint8_t value, EmuTime::param time);
44  void writeAll(uint8_t value, EmuTime::param time);
45  void erase(unsigned addr, EmuTime::param time);
46  void eraseAll(EmuTime::param time);
47 
48  bool ready(EmuTime::param time) const;
49  void clockEvent(EmuTime::param time);
50  void execute_command(EmuTime::param time);
51 
52 public: // for serialize
53  enum State {
60  };
61 
62 private:
63  SRAM sram;
64  EmuTime completionTime = EmuTime::zero();
65  EmuTime csTime = EmuTime::zero();
66  State state = IN_RESET;
67  uint16_t shiftRegister = 0;
68  uint8_t bits = 0;
69  uint8_t address = 0;
70  bool pinCS = false;
71  bool pinCLK = false;
72  bool pinDI = false;
73  bool writeProtected = true;
74 
75  //static constexpr int SHIFT_REG_BITS = sizeof(shiftRegister) * CHAR_BIT;
76  static constexpr int SHIFT_REG_BITS = sizeof(uint16_t) * CHAR_BIT; // vs workaround ??
77 };
78 
79 } // namespace openmsx
80 
81 #endif
bool read_DO(EmuTime::param time) const
Definition: EEPROM_93C46.cc:65
static constexpr uint32_t NUM_ADDRESSES
Definition: EEPROM_93C46.hh:18
void serialize(Archive &ar, unsigned version)
EEPROM_93C46(const XMLElement &xml)
Definition: EEPROM_93C46.cc:6
static constexpr uint32_t ADDRESS_MASK
Definition: EEPROM_93C46.hh:19
static constexpr uint8_t ADDRESS_BITS
Definition: EEPROM_93C46.hh:17
static constexpr uint8_t DATA_BITS
Definition: EEPROM_93C46.hh:20
const uint8_t * backdoor() const
Definition: EEPROM_93C46.hh:37
void write_CLK(bool value, EmuTime::param time)
Definition: EEPROM_93C46.cc:91
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void write_DI(bool value, EmuTime::param time)
void write_CS(bool value, EmuTime::param time)
Definition: EEPROM_93C46.cc:76