openMSX
Carnivore2.hh
Go to the documentation of this file.
1 #ifndef CARNIVORE2_HH
2 #define CARNIVORE2_HH
3 
4 #include "MSXDevice.hh"
5 #include "MSXMapperIO.hh"
6 #include "MSXCPUInterface.hh"
7 #include "AmdFlash.hh"
8 #include "EEPROM_93C46.hh"
9 #include "Math.hh"
10 #include "Ram.hh"
11 #include "SCC.hh"
12 #include "YM2413.hh"
13 #include "serialize_meta.hh"
14 #include <utility>
15 
16 namespace openmsx {
17 
18 class IDEDevice;
19 
20 class Carnivore2 final
21  : public MSXDevice
22  , public MSXMapperIOClient
23  , public GlobalReadClient<Carnivore2, CT_Interval<0x0000>, CT_Interval<0x4000, 0x4010>>
24 {
25 public:
26  Carnivore2(const DeviceConfig& config);
27  ~Carnivore2() override;
28 
29  void powerUp(EmuTime::param time) override;
30  void reset(EmuTime::param time) override;
31 
32  [[nodiscard]] byte readMem(word address, EmuTime::param time) override;
33  [[nodiscard]] byte peekMem(word address, EmuTime::param time) const override;
34  void writeMem(word address, byte value, EmuTime::param time) override;
35  void globalRead(word address, EmuTime::param time) override;
36 
37  [[nodiscard]] byte readIO(word port, EmuTime::param time) override;
38  [[nodiscard]] byte peekIO(word port, EmuTime::param time) const override;
39  void writeIO(word port, byte value, EmuTime::param time) override;
40  [[nodiscard]] byte getSelectedSegment(byte page) const override;
41 
42  template<typename Archive>
43  void serialize(Archive& ar, unsigned version);
44 
45 private:
46  // config regs
47  [[nodiscard]] unsigned getDirectFlashAddr() const;
48  [[nodiscard]] byte peekConfigRegister(word address, EmuTime::param time) const;
49  [[nodiscard]] byte readConfigRegister(word address, EmuTime::param time);
50  void writeSndLVL(byte value, EmuTime::param time);
51  void writeCfgEEPR(byte value, EmuTime::param time);
52  void writeConfigRegister(word address, byte value, EmuTime::param time);
53 
54  [[nodiscard]] bool sccEnabled() const { return configRegs[0x00] & 0x10; }
55  [[nodiscard]] bool delayedConfig() const { return configRegs[0x00] & 0x08; }
56  [[nodiscard]] bool delayedConfig4000() const { return configRegs[0x00] & 0x04; }
57  [[nodiscard]] bool readBIOSfromRAM() const { return configRegs[0x00] & 0x02; }
58 
59  [[nodiscard]] bool slotExpanded() const { return configRegs[0x1e] & 0x80; }
60  [[nodiscard]] bool memMapReadEnabled() const {
61  return (configRegs[0x1e] & 0x40) && !(port3C & 0x20);
62  }
63  [[nodiscard]] bool fmPacPortEnabled2() const { return configRegs[0x1e] & 0x20; }
64  [[nodiscard]] bool subSlotEnabled(unsigned slot) const {
65  assert(slot < 4);
66  return configRegs[0x1e] & (1 << slot);
67  }
68  [[nodiscard]] bool writePort3cEnabled() const {
69  return (configRegs[0x1e] & 0x10) && !(port3C & 0x20);
70  }
71 
72  enum class SubDevice { MultiMapper, IDE, MemoryMapper, FmPac, Nothing };
73 
74  [[nodiscard]] SubDevice getSubDevice(word address) const;
75 
76  // multi-mapper
77  [[nodiscard]] bool isConfigReg(word address) const;
78  [[nodiscard]] std::pair<unsigned, byte> decodeMultiMapper(word address) const;
79  [[nodiscard]] bool sccAccess(word address) const;
80  [[nodiscard]] byte readMultiMapperSlot(word address, EmuTime::param time);
81  [[nodiscard]] byte peekMultiMapperSlot(word address, EmuTime::param time) const;
82  void writeMultiMapperSlot(word address, byte value, EmuTime::param time);
83 
84  // IDE
85  [[nodiscard]] byte readIDESlot(word address, EmuTime::param time);
86  [[nodiscard]] byte peekIDESlot(word address, EmuTime::param time) const;
87  void writeIDESlot(word address, byte value, EmuTime::param time);
88  [[nodiscard]] word ideReadData(EmuTime::param time);
89  void ideWriteData(word value, EmuTime::param time);
90  [[nodiscard]] byte ideReadReg(byte reg, EmuTime::param time);
91  void ideWriteReg(byte reg, byte value, EmuTime::param time);
92  [[nodiscard]] bool ideRegsEnabled() const { return ideControlReg & 0x01; }
93  [[nodiscard]] byte ideBank() const { return Math::reverseByte(ideControlReg & 0xe0); }
94 
95  // memory mapper
96  [[nodiscard]] bool isMemmapControl(word address) const;
97  [[nodiscard]] unsigned getMemoryMapperAddress(word address) const;
98  [[nodiscard]] bool isMemoryMapperWriteProtected(word address) const;
99  [[nodiscard]] byte peekMemoryMapperSlot(word address) const;
100  [[nodiscard]] byte readMemoryMapperSlot(word address);
101  void writeMemoryMapperSlot(word address, byte value);
102 
103  // fm-pac
104  [[nodiscard]] byte readFmPacSlot(word address);
105  [[nodiscard]] byte peekFmPacSlot(word address) const;
106  void writeFmPacSlot(word address, byte value, EmuTime::param time);
107  [[nodiscard]] bool fmPacPortEnabled1() const { return fmPacEnable & 0x01; }
108  [[nodiscard]] bool fmPacSramEnabled() const {
109  return (fmPac5ffe == 0x4d) && (fmPac5fff == 0x69);
110  }
111 
112 private:
113  AmdFlash flash; // 8MB
114  Ram ram; // 2MB
115  EEPROM_93C46 eeprom;
116  byte configRegs[64]; // in reality there are less than 64
117  byte shadowConfigRegs[64]; // only regs[0x05..0x1e] have a shadow counterpart
118  byte subSlotReg;
119  byte port3C;
120 
121  // multi-mapper
122  SCC scc;
123  byte sccMode;
124  byte sccBank[4]; // mostly write-only, except to test for scc-bank
125 
126  // ide
127  std::unique_ptr<IDEDevice> ideDevices[2];
128  byte ideSoftReset;
129  byte ideSelectedDevice;
130  byte ideControlReg;
131  byte ideRead;
132  byte ideWrite;
133 
134  // memory-mapper
135  byte memMapRegs[4]; // only stores 6 lower bits
136 
137  // fm-pac
138  YM2413 ym2413;
139  byte fmPacEnable; // enable
140  byte fmPacBank; // bank
141  byte fmPac5ffe;
142  byte fmPac5fff;
143 };
145 
146 } // namespace openmsx
147 
148 #endif
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: Carnivore2.cc:688
void reset(EmuTime::param time) override
This method is called on reset.
Definition: Carnivore2.cc:48
void writeMem(word address, byte value, EmuTime::param time) override
Write a given byte to a given location at a certain time to this device.
Definition: Carnivore2.cc:171
void serialize(Archive &ar, unsigned version)
Definition: Carnivore2.cc:723
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: Carnivore2.cc:683
void globalRead(word address, EmuTime::param time) override
Global reads.
Definition: Carnivore2.cc:98
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
Definition: Carnivore2.cc:41
~Carnivore2() override
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: Carnivore2.cc:143
Carnivore2(const DeviceConfig &config)
Definition: Carnivore2.cc:22
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
Definition: Carnivore2.cc:698
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: Carnivore2.cc:157
byte getSelectedSegment(byte page) const override
Definition: Carnivore2.cc:715
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
constexpr uint8_t reverseByte(uint8_t a)
Reverse the bits in a byte.
Definition: Math.hh:169
This file implemented 3 utility functions:
Definition: Autofire.cc:5
Ram
Definition: Ram.cc:125
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
SCC
Definition: SCC.cc:599