openMSX
MSXOPL3Cartridge.cc
Go to the documentation of this file.
1 #include "MSXOPL3Cartridge.hh"
2 #include "serialize.hh"
3 #include "unreachable.hh"
4 
5 namespace openmsx {
6 
8  : MSXDevice(config)
9  , ymf262(getName(), config, false)
10 {
12 }
13 
14 void MSXOPL3Cartridge::reset(EmuTime::param time)
15 {
16  ymf262.reset(time);
17 
18  // TODO check
19  opl3latch = 0;
20 }
21 
22 byte MSXOPL3Cartridge::readIO(word port, EmuTime::param /*time*/)
23 {
24  // FM part 0xC4-0xC7 (in MoonSound)
25  switch (port & 0x03) {
26  case 0: // read status
27  case 2:
28  return ymf262.readStatus();
29  case 1:
30  case 3: // read fm register
31  return ymf262.readReg(opl3latch);
32  default: // unreachable, avoid warning
33  UNREACHABLE; return 255;
34  }
35 }
36 
37 byte MSXOPL3Cartridge::peekIO(word port, EmuTime::param /*time*/) const
38 {
39  switch (port & 0x03) {
40  case 0: // read status
41  case 2:
42  return ymf262.peekStatus();
43  case 1:
44  case 3: // read fm register
45  return ymf262.peekReg(opl3latch);
46  default: // unreachable, avoid warning
47  UNREACHABLE; return 255;
48  }
49 }
50 
51 void MSXOPL3Cartridge::writeIO(word port, byte value, EmuTime::param time)
52 {
53  switch (port & 0x03) {
54  case 0: // select register bank 0
55  opl3latch = value;
56  break;
57  case 2: // select register bank 1
58  opl3latch = value | 0x100;
59  break;
60  case 1:
61  case 3: // write fm register
62  ymf262.writeReg(opl3latch, value, time);
63  break;
64  default:
66  }
67 }
68 
69 template<typename Archive>
70 void MSXOPL3Cartridge::serialize(Archive& ar, unsigned /*version*/)
71 {
72  ar.template serializeBase<MSXDevice>(*this);
73  ar.serialize("ymf262", ymf262,
74  "opl3latch", opl3latch);
75 }
78 
79 } // namespace openmsx
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:33
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:126
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.
MSXOPL3Cartridge(const DeviceConfig &config)
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.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
void serialize(Archive &ar, unsigned version)
void reset(EmuTime::param time)
Definition: YMF262.cc:1410
byte readStatus()
Definition: YMF262.cc:1493
byte readReg(unsigned reg)
Definition: YMF262.cc:1040
void writeReg(unsigned r, byte v, EmuTime::param time)
Definition: YMF262.cc:1051
byte peekReg(unsigned reg) const
Definition: YMF262.cc:1046
byte peekStatus() const
Definition: YMF262.cc:1501
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:741
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:998
#define UNREACHABLE
Definition: unreachable.hh:38