openMSX
MSXYamahaSFG.cc
Go to the documentation of this file.
1 #include "MSXYamahaSFG.hh"
2 #include "CacheLine.hh"
3 #include "serialize.hh"
4 
5 namespace openmsx {
6 
8  : MSXDevice(config)
9  , rom(getName() + " ROM", "rom", config)
10  , ym2151(getName(), "Yamaha SFG-01/05", config, getCurrentTime())
11  , ym2148(getName(), getMotherBoard())
12 {
14 }
15 
16 void MSXYamahaSFG::reset(EmuTime::param time)
17 {
18  ym2151.reset(time);
19  ym2148.reset();
20  registerLatch = 0; // TODO check
21  irqVector = 255; // TODO check
22  irqVector2148 = 255; // TODO check
23 }
24 
25 void MSXYamahaSFG::writeMem(word address, byte value, EmuTime::param time)
26 {
27  word maskedAddress = address & 0x3FFF;
28  switch (maskedAddress) {
29  case 0x3FF0: // OPM ADDRESS REGISTER
30  writeRegisterPort(value, time);
31  break;
32  case 0x3FF1: // OPM DATA REGISTER
33  writeDataPort(value, time);
34  break;
35  case 0x3FF2: // Register for data latched to ST0 to ST7 output ports
36  // TODO: keyboardLatch = value;
37  //std::cerr << "TODO: keyboardLatch = " << (int)value << '\n';
38  break;
39  case 0x3FF3: // MIDI IRQ VECTOR ADDRESS REGISTER
40  irqVector2148 = value;
41  break;
42  case 0x3FF4: // EXTERNAL IRQ VECTOR ADDRESS REGISTER
43  // IRQ vector for YM2151 (+ default vector ???)
44  irqVector = value;
45  break;
46  case 0x3FF5: // MIDI standard UART DATA WRITE BUFFER
47  ym2148.writeData(value, time);
48  break;
49  case 0x3FF6: // MIDI standard UART COMMAND REGISTER
50  ym2148.writeCommand(value);
51  break;
52  }
53 }
54 
56 {
57  if ((start & 0x3FFF & CacheLine::HIGH) == (0x3FF0 & CacheLine::HIGH)) {
58  return nullptr;
59  }
60  return unmappedWrite;
61 }
62 
64 {
65  return ym2148.pendingIRQ() ? irqVector2148 : irqVector;
66 }
67 
68 void MSXYamahaSFG::writeRegisterPort(byte value, EmuTime::param /*time*/)
69 {
70  registerLatch = value;
71 }
72 
73 void MSXYamahaSFG::writeDataPort(byte value, EmuTime::param time)
74 {
75  ym2151.writeReg(registerLatch, value, time);
76 }
77 
78 byte MSXYamahaSFG::readMem(word address, EmuTime::param time)
79 {
80  word maskedAddress = address & 0x3FFF;
81  if (maskedAddress < 0x3FF0 || maskedAddress >= 0x3FF8) {
82  return peekMem(address, time);
83  }
84  switch (maskedAddress) {
85  case 0x3FF0: // (not used, it seems)
86  case 0x3FF1: // OPM STATUS REGISTER
87  case 0x3FF2: // Data buffer for SD0 to SD7 input ports
88  return peekMem(address, time);
89  case 0x3FF5: // MIDI standard UART DATA READ BUFFER
90  return ym2148.readData(time);
91  case 0x3FF6: // MIDI standard UART STATUS REGISTER
92  return ym2148.readStatus(time);
93  }
94  return 0xFF;
95 }
96 
97 byte MSXYamahaSFG::peekMem(word address, EmuTime::param time) const
98 {
99  word maskedAddress = address & 0x3FFF;
100  if (maskedAddress < 0x3FF0 || maskedAddress >= 0x3FF8) {
101  // size can also be 16kB for SFG-01 or 32kB for SFG-05
102  return rom[address & (rom.getSize() - 1)];
103  }
104  switch (maskedAddress) {
105  case 0x3FF0: // (not used, it seems)
106  return 0xFF;
107  case 0x3FF1: // OPM STATUS REGISTER
108  return ym2151.readStatus();
109  case 0x3FF2: // Data buffer for SD0 to SD7 input ports
110  // TODO: return getKbdStatus();
111  break;
112  case 0x3FF5: // MIDI standard UART DATA READ BUFFER
113  return ym2148.peekData(time);
114  case 0x3FF6: // MIDI standard UART STATUS REGISTER
115  return ym2148.peekStatus(time);
116  }
117  return 0xFF;
118 }
119 
120 const byte* MSXYamahaSFG::getReadCacheLine(word start) const
121 {
122  if ((start & 0x3FFF & CacheLine::HIGH) == (0x3FF0 & CacheLine::HIGH)) {
123  return nullptr;
124  }
125  return &rom[start & (rom.getSize() - 1)];
126 }
127 
128 // version 1: initial version
129 // version 2: moved irqVector2148 from ym2148 to here
130 template<typename Archive>
131 void MSXYamahaSFG::serialize(Archive& ar, unsigned version)
132 {
133  ar.serialize("YM2151", ym2151,
134  "YM2148", ym2148,
135  "registerLatch", registerLatch,
136  "irqVector", irqVector);
137  if (ar.versionAtLeast(version, 2)) {
138  ar.serialize("irqVector2148", irqVector2148);
139  } else {
140  irqVector2148 = 255; // could be retrieved from the old ym2148
141  // savestate data, but I didn't bother
142  }
143 }
146 
147 } // namespace openmsx
MSXYamahaSFG.hh
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
openmsx::YM2148::writeCommand
void writeCommand(byte value)
Definition: YM2148.cc:136
openmsx::YM2148::pendingIRQ
bool pendingIRQ() const
Definition: YM2148.cc:222
serialize.hh
openmsx::MSXYamahaSFG
Definition: MSXYamahaSFG.hh:13
openmsx::YM2148::reset
void reset()
Definition: YM2148.cc:43
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MSXDevice::unmappedWrite
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
openmsx::YM2148::peekStatus
byte peekStatus(EmuTime::param time) const
Definition: YM2148.cc:118
openmsx::MSXYamahaSFG::readIRQVector
byte readIRQVector() override
Gets IRQ vector used in IM2.
Definition: MSXYamahaSFG.cc:63
openmsx::CacheLine::HIGH
constexpr unsigned HIGH
Definition: CacheLine.hh:10
openmsx::MSXYamahaSFG::getWriteCacheLine
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: MSXYamahaSFG.cc:55
openmsx::YM2148::readData
byte readData(EmuTime::param time)
Definition: YM2148.cc:124
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MSXYamahaSFG::getReadCacheLine
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: MSXYamahaSFG.cc:120
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:740
openmsx::YM2151::writeReg
void writeReg(byte r, byte v, EmuTime::param time)
Definition: YM2151.cc:643
openmsx::MSXDevice::getCurrentTime
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:131
openmsx::YM2151::readStatus
byte readStatus() const
Definition: YM2151.cc:1549
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
CacheLine.hh
openmsx::MSXYamahaSFG::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: MSXYamahaSFG.cc:78
openmsx::MSXYamahaSFG::writeMem
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: MSXYamahaSFG.cc:25
openmsx::MSXYamahaSFG::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXYamahaSFG.cc:16
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::YM2148::peekData
byte peekData(EmuTime::param time) const
Definition: YM2148.cc:130
openmsx::YM2151::reset
void reset(EmuTime::param time)
Definition: YM2151.cc:916
openmsx::MSXYamahaSFG::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXYamahaSFG.cc:131
openmsx::YM2148::writeData
void writeData(byte value, EmuTime::param time)
Definition: YM2148.cc:179
openmsx::MSXYamahaSFG::MSXYamahaSFG
MSXYamahaSFG(const DeviceConfig &config)
Definition: MSXYamahaSFG.cc:7
openmsx::MSXYamahaSFG::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: MSXYamahaSFG.cc:97
openmsx::Rom::getSize
unsigned getSize() const
Definition: Rom.hh:32
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::YM2148::readStatus
byte readStatus(EmuTime::param time)
Definition: YM2148.cc:114