openMSX
MusicModuleMIDI.cc
Go to the documentation of this file.
1#include "MusicModuleMIDI.hh"
2#include "serialize.hh"
3
4namespace 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
35void MusicModuleMIDI::reset(EmuTime::param time)
36{
37 mc6850.reset(time);
38}
39
40byte 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}
50
51byte MusicModuleMIDI::peekIO(word port, EmuTime::param /*time*/) const
52{
53 switch (port & 0x1) {
54 case 0:
55 return mc6850.peekStatusReg();
56 case 1:
57 return mc6850.peekDataReg();
58 }
60}
61
62void MusicModuleMIDI::writeIO(word port, byte value, EmuTime::param time)
63{
64 switch (port & 0x01) {
65 case 0:
66 mc6850.writeControlReg(value, time);
67 break;
68 case 1:
69 mc6850.writeDataReg(value, time);
70 break;
71 }
72}
73
74// versions 1-3: were for type "MC6850", see that class for details
75// version 4: first version for "MusicModuleMIDI"
76template<typename Archive>
77void MusicModuleMIDI::serialize(Archive& ar, unsigned version)
78{
79 ar.template serializeBase<MSXDevice>(*this);
80 if (ar.versionAtLeast(version, 4)) {
81 ar.serialize("MC6850", mc6850);
82 } else {
83 // MC6850 members were serialized as direct children of the
84 // <device> tag, without an intermediate <MC6850> tag.
85 mc6850.serialize(ar, version);
86 }
87}
90
91// For backwards compatiblity, also register this class with the old name (only
92// needed for loading from disk). Versions 1-3 use the old name "MC6850",
93// version 4 (and above) use the name "MusicModuleMIDI".
94static const RegisterInitializerHelper<XmlInputArchive, MusicModuleMIDI> registerbwCompat("MC6850");
95
96} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:356
byte readDataReg()
Definition MC6850.cc:103
byte peekStatusReg() const
Definition MC6850.cc:96
void reset(EmuTime::param time)
Definition MC6850.cc:74
void writeControlReg(byte value, EmuTime::param time)
Definition MC6850.cc:120
byte readStatusReg() const
Definition MC6850.cc:91
void writeDataReg(byte value, EmuTime::param time)
Definition MC6850.cc:177
byte peekDataReg() const
Definition MC6850.cc:115
void serialize(Archive &ar, unsigned version)
Definition MC6850.cc:295
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
EmuTime::param getCurrentTime() const
Definition MSXDevice.cc:125
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.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
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.
MusicModuleMIDI(const DeviceConfig &config)
void reset(EmuTime::param time) override
This method is called on reset.
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define UNREACHABLE