openMSX
MSXAudio.cc
Go to the documentation of this file.
1#include "MSXAudio.hh"
2#include "Y8950Periphery.hh"
3#include "DACSound8U.hh"
4#include "StringOp.hh"
5#include "serialize.hh"
6#include <memory>
7
8namespace openmsx {
9
10// MSXAudio
11
13 : MSXDevice(config)
14 , y8950(getName(), config,
15 config.getChildDataAsInt("sampleram", 256) * 1024,
16 getCurrentTime(), *this)
17{
18 auto type = config.getChildData("type", "philips");
19 if (StringOp::casecmp cmp; cmp(type, "philips")) {
20 dac = std::make_unique<DACSound8U>(
21 getName() + " 8-bit DAC", "MSX-AUDIO 8-bit DAC",
22 config);
23 }
25}
26
28{
29 // delete soon, because PanasonicAudioPeriphery still uses
30 // this object in its destructor
31 periphery.reset();
32}
33
34Y8950Periphery& MSXAudio::createPeriphery(const std::string& soundDeviceName)
35{
37 *this, getDeviceConfig2(), soundDeviceName);
38 return *periphery;
39}
40
41void MSXAudio::powerUp(EmuTime::param time)
42{
43 y8950.clearRam();
44 reset(time);
45}
46
47void MSXAudio::reset(EmuTime::param time)
48{
49 y8950.reset(time);
50 periphery->reset();
51 registerLatch = 0; // TODO check
52}
53
54byte MSXAudio::readIO(word port, EmuTime::param time)
55{
56 if ((port & 0xE8) == 0x08) {
57 // read DAC
58 return 0xFF;
59 } else {
60 return (port & 1) ? y8950.readReg(registerLatch, time)
61 : y8950.readStatus(time);
62 }
63}
64
65byte MSXAudio::peekIO(word port, EmuTime::param time) const
66{
67 if ((port & 0xE8) == 0x08) {
68 // read DAC
69 return 0xFF; // read always returns 0xFF
70 } else {
71 return (port & 1) ? y8950.peekReg(registerLatch, time)
72 : y8950.peekStatus(time);
73 }
74}
75
76void MSXAudio::writeIO(word port, byte value, EmuTime::param time)
77{
78 if ((port & 0xE8) == 0x08) {
79 dacValue = value;
80 if (dacEnabled) {
81 assert(dac);
82 dac->writeDAC(dacValue, time);
83 }
84 } else if ((port & 0x01) == 0) {
85 // 0xC0 or 0xC2
86 registerLatch = value;
87 } else {
88 // 0xC1 or 0xC3
89 y8950.writeReg(registerLatch, value, time);
90 }
91}
92
93byte MSXAudio::readMem(word address, EmuTime::param time)
94{
95 return periphery->readMem(address, time);
96}
97byte MSXAudio::peekMem(word address, EmuTime::param time) const
98{
99 return periphery->peekMem(address, time);
100}
101void MSXAudio::writeMem(word address, byte value, EmuTime::param time)
102{
103 periphery->writeMem(address, value, time);
104}
105const byte* MSXAudio::getReadCacheLine(word start) const
106{
107 return periphery->getReadCacheLine(start);
108}
110{
111 return periphery->getWriteCacheLine(start);
112}
113
114void MSXAudio::enableDAC(bool enable, EmuTime::param time)
115{
116 if ((dacEnabled != enable) && dac) {
117 dacEnabled = enable;
118 byte value = dacEnabled ? dacValue : 0x80;
119 dac->writeDAC(value, time);
120 }
121}
122
123template<typename Archive>
124void MSXAudio::serialize(Archive& ar, unsigned /*version*/)
125{
126 ar.serializePolymorphic("periphery", *periphery);
127 ar.serialize("Y8950", y8950,
128 "registerLatch", registerLatch,
129 "dacValue", dacValue,
130 "dacEnabled", dacEnabled);
131
132 if constexpr (Archive::IS_LOADER) {
133 // restore dac status
134 if (dacEnabled) {
135 assert(dac);
136 dac->writeDAC(dacValue, getCurrentTime());
137 }
138 }
139}
142
143} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:354
std::string_view getChildData(std::string_view name) const
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
Definition MSXAudio.cc:41
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition MSXAudio.cc:97
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition MSXAudio.cc:105
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 MSXAudio.cc:76
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition MSXAudio.cc:54
void writeMem(word address, byte value, EmuTime::param time) override
Write a given byte to a given location at a certain time to this device.
Definition MSXAudio.cc:101
MSXAudio(const DeviceConfig &config)
Definition MSXAudio.cc:12
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition MSXAudio.cc:109
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition MSXAudio.cc:93
void serialize(Archive &ar, unsigned version)
Definition MSXAudio.cc:124
void reset(EmuTime::param time) override
This method is called on reset.
Definition MSXAudio.cc:47
~MSXAudio() override
Definition MSXAudio.cc:27
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition MSXAudio.cc:65
Y8950Periphery & createPeriphery(const std::string &soundDeviceName)
Creates a periphery object for this MSXAudio cartridge.
Definition MSXAudio.cc:34
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
const DeviceConfig & getDeviceConfig2() const
Definition MSXDevice.hh:237
virtual const std::string & getName() const
Returns a human-readable name for this device.
Definition MSXDevice.cc:375
EmuTime::param getCurrentTime() const
Definition MSXDevice.cc:125
static std::unique_ptr< Y8950Periphery > create(MSXAudio &audio, const DeviceConfig &config, const std::string &soundDeviceName)
Models the 4 general purpose I/O pins on the Y8950 (controlled by registers r#18 and r#19)
void reset(EmuTime::param time)
Definition Y8950.cc:557
uint8_t peekReg(uint8_t rg, EmuTime::param time) const
Definition Y8950.cc:1157
uint8_t peekStatus(EmuTime::param time) const
Definition Y8950.cc:1187
uint8_t readStatus(EmuTime::param time) const
Definition Y8950.cc:1180
void clearRam()
Definition Y8950.cc:551
void writeReg(uint8_t rg, uint8_t data, EmuTime::param time)
Definition Y8950.cc:903
uint8_t readReg(uint8_t rg, EmuTime::param time)
Definition Y8950.cc:1142
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)