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  byte result;
25  // FM part 0xC4-0xC7 (in MoonSound)
26  switch (port & 0x03) {
27  case 0: // read status
28  case 2:
29  result = ymf262.readStatus();
30  break;
31  case 1:
32  case 3: // read fm register
33  result = ymf262.readReg(opl3latch);
34  break;
35  default: // unreachable, avoid warning
36  UNREACHABLE; result = 255;
37  }
38  return result;
39 }
40 
41 byte MSXOPL3Cartridge::peekIO(word port, EmuTime::param /*time*/) const
42 {
43  byte result;
44  switch (port & 0x03) {
45  case 0: // read status
46  case 2:
47  result = ymf262.peekStatus();
48  break;
49  case 1:
50  case 3: // read fm register
51  result = ymf262.peekReg(opl3latch);
52  break;
53  default: // unreachable, avoid warning
54  UNREACHABLE; result = 255;
55  }
56  return result;
57 }
58 
59 void MSXOPL3Cartridge::writeIO(word port, byte value, EmuTime::param time)
60 {
61  switch (port & 0x03) {
62  case 0: // select register bank 0
63  opl3latch = value;
64  break;
65  case 2: // select register bank 1
66  opl3latch = value | 0x100;
67  break;
68  case 1:
69  case 3: // write fm register
70  ymf262.writeReg(opl3latch, value, time);
71  break;
72  default:
74  }
75 }
76 
77 template<typename Archive>
78 void MSXOPL3Cartridge::serialize(Archive& ar, unsigned /*version*/)
79 {
80  ar.template serializeBase<MSXDevice>(*this);
81  ar.serialize("ymf262", ymf262,
82  "opl3latch", opl3latch);
83 }
85 REGISTER_MSXDEVICE(MSXOPL3Cartridge, "OPL3Cartridge");
86 
87 } // namespace openmsx
byte peekStatus() const
Definition: YMF262.cc:1506
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
void writeReg(unsigned r, byte v, EmuTime::param time)
Definition: YMF262.cc:1056
byte peekReg(unsigned reg) const
Definition: YMF262.cc:1051
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
byte readStatus()
Definition: YMF262.cc:1498
MSXOPL3Cartridge(const DeviceConfig &config)
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)
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:129
void reset(EmuTime::param time)
Definition: YMF262.cc:1415
void reset(EmuTime::param time) override
This method is called on reset.
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.
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 peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:589
byte readReg(unsigned reg)
Definition: YMF262.cc:1045
#define UNREACHABLE
Definition: unreachable.hh:38