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