openMSX
MusicModuleMIDI.cc
Go to the documentation of this file.
1 #include "MusicModuleMIDI.hh"
2 #include "serialize.hh"
3 
4 namespace openmsx {
5 
6 // MSX interface:
7 // port R/W
8 // 0 W Control Register
9 // 1 W Transmit Data Register
10 // 4 R Status Register
11 // 5 R Receive Data Register
12 
13 // Some existing Music-Module detection routines:
14 // - fac demo 5: does OUT 0,3 : OUT 0,21 : INP(4) and expects to read 2
15 // - tetris 2 special edition: does INP(4) and expects to read 0
16 // - Synthesix: does INP(4), expects 0; OUT 0,3 : OUT 0,21: INP(4) and expects
17 // bit 1 to be 1 and bit 2, 3 and 7 to be 0. Then does OUT 5,0xFE : INP(4)
18 // and expects bit 1 to be 0.
19 // I did some _very_basic_ investigation and found the following:
20 // - after a reset reading from port 4 returns 0
21 // - after initializing the control register, reading port 4 returns 0 (of
22 // course this will change when you start to actually receive/transmit data)
23 // - writing any value with the lower 2 bits set to 1 returns to the initial
24 // state, and reading port 4 again returns 0.
25 // - ?INP(4) : OUT0,3 : ?INP(4) : OUT0,21 : ? INP(4) : OUT0,3 : ?INP(4)
26 // outputs: 0, 0, 2, 0
27 
29  : MSXDevice(config)
30  , mc6850(MSXDevice::getName(), getMotherBoard(), 500000) // 500 kHz
31 {
33 }
34 
35 void MusicModuleMIDI::reset(EmuTime::param time)
36 {
37  mc6850.reset(time);
38 }
39 
40 byte MusicModuleMIDI::readIO(word port, EmuTime::param /*time*/)
41 {
42  switch (port & 0x1) {
43  case 0:
44  return mc6850.readStatusReg();
45  case 1:
46  return mc6850.readDataReg();
47  }
49  return 0xFF;
50 }
51 
52 byte MusicModuleMIDI::peekIO(word port, EmuTime::param /*time*/) const
53 {
54  switch (port & 0x1) {
55  case 0:
56  return mc6850.peekStatusReg();
57  case 1:
58  return mc6850.peekDataReg();
59  }
61  return 0xFF;
62 }
63 
64 void MusicModuleMIDI::writeIO(word port, byte value, EmuTime::param time)
65 {
66  switch (port & 0x01) {
67  case 0:
68  mc6850.writeControlReg(value, time);
69  break;
70  case 1:
71  mc6850.writeDataReg(value, time);
72  break;
73  }
74 }
75 
76 // versions 1-3: were for type "MC6850", see that class for details
77 // version 4: first version for "MusicModuleMIDI"
78 template<typename Archive>
79 void MusicModuleMIDI::serialize(Archive& ar, unsigned version)
80 {
81  ar.template serializeBase<MSXDevice>(*this);
82  if (ar.versionAtLeast(version, 4)) {
83  ar.serialize("MC6850", mc6850);
84  } else {
85  // MC6850 members were serialized as direct children of the
86  // <device> tag, without an intermediate <MC6850> tag.
87  mc6850.serialize(ar, version);
88  }
89 }
91 REGISTER_MSXDEVICE(MusicModuleMIDI, "MusicModuleMIDI");
92 
93 // For backwards compatility, also register this class with the old name (only
94 // needed for loading from disk). Versions 1-3 use the old name "MC6850",
95 // version 4 (and above) use the name "MusicModuleMIDI".
96 static RegisterInitializerHelper<XmlInputArchive, MusicModuleMIDI> registerbwCompat("MC6850");
97 
98 } // namespace openmsx
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
openmsx::MC6850::reset
void reset(EmuTime::param time)
Definition: MC6850.cc:75
serialize.hh
openmsx::MusicModuleMIDI::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MusicModuleMIDI.cc:52
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MC6850::writeDataReg
void writeDataReg(byte value, EmuTime::param time)
Definition: MC6850.cc:178
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MC6850::peekStatusReg
byte peekStatusReg() const
Definition: MC6850.cc:97
openmsx::MusicModuleMIDI::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MusicModuleMIDI.cc:35
UNREACHABLE
#define UNREACHABLE
Definition: unreachable.hh:38
openmsx::MC6850::readStatusReg
byte readStatusReg() const
Definition: MC6850.cc:92
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:742
openmsx::MusicModuleMIDI::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: MusicModuleMIDI.cc:40
openmsx::MSXDevice::getCurrentTime
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:131
MusicModuleMIDI.hh
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::MC6850::writeControlReg
void writeControlReg(byte value, EmuTime::param time)
Definition: MC6850.cc:121
openmsx::RegisterInitializerHelper
Definition: serialize_meta.hh:315
openmsx::MusicModuleMIDI::MusicModuleMIDI
MusicModuleMIDI(const DeviceConfig &config)
Definition: MusicModuleMIDI.cc:28
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::MusicModuleMIDI
Definition: MusicModuleMIDI.hh:11
openmsx::MusicModuleMIDI::serialize
void serialize(Archive &ar, unsigned version)
Definition: MusicModuleMIDI.cc:79
openmsx::MusicModuleMIDI::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: MusicModuleMIDI.cc:64
openmsx::MC6850::serialize
void serialize(Archive &ar, unsigned version)
Definition: MC6850.cc:296
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::MC6850::peekDataReg
byte peekDataReg() const
Definition: MC6850.cc:116
openmsx::MC6850::readDataReg
byte readDataReg()
Definition: MC6850.cc:104