OXYGENHUB
◆ main openmsx / src / sound / MSXOPL3Cartridge.cc
1.6 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#include "MSXOPL3Cartridge.hh"
2
3
#include "serialize.hh"
4
5
#include "unreachable.hh"
6
7
namespace openmsx {
8
9
MSXOPL3Cartridge::MSXOPL3Cartridge(const DeviceConfig& config)
10
	: MSXDevice(config)
11
	, ymf262(getName(), config, false)
12
{
13
	reset(getCurrentTime());
14
}
15
16
void MSXOPL3Cartridge::reset(EmuTime time)
17
{
18
	ymf262.reset(time);
19
20
	// TODO check
21
	opl3latch = 0;
22
}
23
24
byte MSXOPL3Cartridge::readIO(uint16_t port, EmuTime /*time*/)
25
{
26
	// FM part  0xC4-0xC7 (in MoonSound)
27
	switch (port & 0x03) {
28
		case 0: // read status
29
		case 2:
30
			return ymf262.readStatus();
31
		case 1:
32
		case 3: // read fm register
33
			return ymf262.readReg(opl3latch);
34
		default:
35
			UNREACHABLE;
36
	}
37
}
38
39
byte MSXOPL3Cartridge::peekIO(uint16_t port, EmuTime /*time*/) const
40
{
41
	switch (port & 0x03) {
42
		case 0: // read status
43
		case 2:
44
			return ymf262.peekStatus();
45
		case 1:
46
		case 3: // read fm register
47
			return ymf262.peekReg(opl3latch);
48
		default:
49
			UNREACHABLE;
50
	}
51
}
52
53
void MSXOPL3Cartridge::writeIO(uint16_t port, byte value, EmuTime time)
54
{
55
	switch (port & 0x03) {
56
		case 0: // select register bank 0
57
			opl3latch = value;
58
			break;
59
		case 2: // select register bank 1
60
			opl3latch = value | 0x100;
61
			break;
62
		case 1:
63
		case 3: // write fm register
64
			ymf262.writeReg(opl3latch, value, time);
65
			break;
66
		default:
67
			UNREACHABLE;
68
	}
69
}
70
71
template<typename Archive>
72
void MSXOPL3Cartridge::serialize(Archive& ar, unsigned /*version*/)
73
{
74
	ar.template serializeBase<MSXDevice>(*this);
75
	ar.serialize("ymf262",    ymf262,
76
	             "opl3latch", opl3latch);
77
}
78
INSTANTIATE_SERIALIZE_METHODS(MSXOPL3Cartridge);
79
REGISTER_MSXDEVICE(MSXOPL3Cartridge, "OPL3Cartridge");
80
81
} // namespace openmsx