openMSX
MSXOPL3Cartridge.cc
Go to the documentation of this file.
1#include "MSXOPL3Cartridge.hh"
2#include "serialize.hh"
3#include "unreachable.hh"
4
5namespace openmsx {
6
8 : MSXDevice(config)
9 , ymf262(getName(), config, false)
10{
12}
13
14void MSXOPL3Cartridge::reset(EmuTime::param time)
15{
16 ymf262.reset(time);
17
18 // TODO check
19 opl3latch = 0;
20}
21
22byte MSXOPL3Cartridge::readIO(word port, EmuTime::param /*time*/)
23{
24 // FM part 0xC4-0xC7 (in MoonSound)
25 switch (port & 0x03) {
26 case 0: // read status
27 case 2:
28 return ymf262.readStatus();
29 case 1:
30 case 3: // read fm register
31 return ymf262.readReg(opl3latch);
32 default:
34 }
35}
36
37byte MSXOPL3Cartridge::peekIO(word port, EmuTime::param /*time*/) const
38{
39 switch (port & 0x03) {
40 case 0: // read status
41 case 2:
42 return ymf262.peekStatus();
43 case 1:
44 case 3: // read fm register
45 return ymf262.peekReg(opl3latch);
46 default:
48 }
49}
50
51void MSXOPL3Cartridge::writeIO(word port, byte value, EmuTime::param time)
52{
53 switch (port & 0x03) {
54 case 0: // select register bank 0
55 opl3latch = value;
56 break;
57 case 2: // select register bank 1
58 opl3latch = value | 0x100;
59 break;
60 case 1:
61 case 3: // write fm register
62 ymf262.writeReg(opl3latch, value, time);
63 break;
64 default:
66 }
67}
68
69template<typename Archive>
70void MSXOPL3Cartridge::serialize(Archive& ar, unsigned /*version*/)
71{
72 ar.template serializeBase<MSXDevice>(*this);
73 ar.serialize("ymf262", ymf262,
74 "opl3latch", opl3latch);
75}
78
79} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:354
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 writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
MSXOPL3Cartridge(const DeviceConfig &config)
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
void reset(EmuTime::param time) override
This method is called on reset.
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)
uint8_t readReg(unsigned reg) const
Definition YMF262.cc:1023
void reset(EmuTime::param time)
Definition YMF262.cc:1396
uint8_t peekStatus() const
Definition YMF262.cc:1480
uint8_t readStatus()
Definition YMF262.cc:1472
void writeReg(unsigned r, uint8_t v, EmuTime::param time)
Definition YMF262.cc:1034
uint8_t peekReg(unsigned reg) const
Definition YMF262.cc:1029
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