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