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