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 return 0xFF;
50}
51
52byte 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
64void 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"
78template<typename Archive>
79void 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}
92
93// For backwards compatiblity, 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".
97
98} // namespace openmsx
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:33
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:126
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.
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:727
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:1009
#define UNREACHABLE
Definition: unreachable.hh:38