openMSX
YM2413OriginalNukeYKT.cc
Go to the documentation of this file.
2 #include "serialize.hh"
3 #include <cassert>
4 
5 namespace openmsx {
6 namespace YM2413OriginalNukeYKT {
7 
9 {
10  reset();
11 }
12 
14 {
16  for (int i = 0; i < 64; ++i) {
17  regs[i] = 0;
18  }
19 }
20 
21 void YM2413::generateChannels(float* out_[9 + 5], uint32_t n)
22 {
23  float* out[9 + 5];
24  for (int i = 0; i < 9 + 5; ++i) out[i] = out_[i];
25 
26  auto f = [&] {
27  int32_t buf[2];
28  OPLL_Clock(&opll, buf);
29  switch (opll.cycles) {
30  case 0: *out[ 9]++ += buf[1] * 2; break;
31  case 1: *out[10]++ += buf[1] * 2; break;
32  case 2: *out[ 6]++ += buf[0];
33  *out[11]++ += buf[1] * 2; break;
34  case 3: *out[ 7]++ += buf[0];
35  *out[12]++ += buf[1] * 2; break;
36  case 4: *out[ 8]++ += buf[0];
37  *out[13]++ += buf[1] * 2; break;
38  case 8: *out[ 0]++ += buf[0]; break;
39  case 9: *out[ 1]++ += buf[0]; break;
40  case 10: *out[ 2]++ += buf[0]; break;
41  case 14: *out[ 3]++ += buf[0]; break;
42  case 15: *out[ 4]++ += buf[0]; break;
43  case 16: *out[ 5]++ += buf[0]; break;
44  }
45  };
46 
47  assert(n != 0);
48  for (uint32_t i = 0; i < 18; ++i) {
49  auto& write = writes[i];
50  if (write.port != uint8_t(-1)) {
51  OPLL_Write(&opll, write.port, write.value);
52  write.port = uint8_t(-1);
53  }
54  f();
55  }
56  n = (n - 1) * 18;
57  for (uint32_t i = 0; i < n; ++i) {
58  f();
59  }
60 
61  allowed_offset = std::max<int>(0, allowed_offset - 18); // see writePort()
62 }
63 
64 void YM2413::writePort(bool port, uint8_t value, int cycle_offset)
65 {
66  // see comments in YM2413NukeYKT.cc
67  while (unlikely(cycle_offset < allowed_offset)) {
68  float d = 0.0f;
69  float* dummy[9 + 5] = {
70  &d, &d, &d, &d, &d, &d, &d, &d, &d,
71  &d, &d, &d, &d, &d,
72  };
73  generateChannels(dummy, 1);
74  }
75  allowed_offset = ((port ? 84 : 12) / 4) + cycle_offset;
76 
77  writes[cycle_offset] = {port, value};
78 
79  // only needed for peekReg()
80  if (port == 0) {
81  latch = value & 63;
82  } else {
83  regs[latch] = value;
84  }
85 }
86 
87 void YM2413::pokeReg(uint8_t /*reg*/, uint8_t /*value*/)
88 {
89  // not supported
90 }
91 
92 uint8_t YM2413::peekReg(uint8_t reg) const
93 {
94  return regs[reg & 63];
95 }
96 
98 {
99  return 1.0f / 256.0f;
100 }
101 
102 template<typename Archive>
103 void YM2413::serialize(Archive& /*ar*/, unsigned /*version*/)
104 {
105  // Not implemented
106 }
107 
108 } // namespace OriginalNuke
109 
113 
114 } // namespace openmsx
openmsx::YM2413OriginalNukeYKT::YM2413::serialize
void serialize(Archive &ar, unsigned version)
Definition: YM2413OriginalNukeYKT.cc:103
openmsx::YM2413OriginalNukeYKT::YM2413::writePort
void writePort(bool port, uint8_t value, int cycle_offset) override
Write to the YM2413 register/data port.
Definition: YM2413OriginalNukeYKT.cc:64
unlikely
#define unlikely(x)
Definition: likely.hh:15
serialize.hh
opll_type_ym2413b
@ opll_type_ym2413b
Definition: opll.hh:31
OPLL_Clock
void OPLL_Clock(opll_t *chip, int32_t *buffer)
Definition: opll.cc:1070
openmsx::YM2413OriginalNukeYKT::YM2413::pokeReg
void pokeReg(uint8_t reg, uint8_t value) override
Write to a YM2413 register (for debug).
Definition: YM2413OriginalNukeYKT.cc:87
openmsx::YM2413OriginalNukeYKT::YM2413::YM2413
YM2413()
Definition: YM2413OriginalNukeYKT.cc:8
opll_t::cycles
uint32_t cycles
Definition: opll.hh:82
openmsx::YM2413OriginalNukeYKT::YM2413::getAmplificationFactor
float getAmplificationFactor() const override
Returns normalization factor.
Definition: YM2413OriginalNukeYKT.cc:97
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
OPLL_Reset
void OPLL_Reset(opll_t *chip, uint32_t chip_type)
Definition: opll.cc:294
openmsx::YM2413
Definition: YM2413.hh:16
openmsx::YM2413OriginalNukeYKT::YM2413::peekReg
uint8_t peekReg(uint8_t reg) const override
Read from a YM2413 register (for debug).
Definition: YM2413OriginalNukeYKT.cc:92
OPLL_Write
void OPLL_Write(opll_t *chip, uint32_t port, uint8_t data)
Definition: opll.cc:1109
openmsx::YM2413OriginalNukeYKT::YM2413::generateChannels
void generateChannels(float *out[9+5], uint32_t n) override
Definition: YM2413OriginalNukeYKT.cc:21
openmsx::YM2413Core
Abstract interface for the YM2413 core.
Definition: YM2413Core.hh:27
openmsx::YM2413
YM2413
Definition: YM2413.cc:119
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
YM2413OriginalNukeYKT.hh
openmsx::REGISTER_POLYMORPHIC_INITIALIZER
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, CassettePlayer, "CassettePlayer")
openmsx::YM2413OriginalNukeYKT::YM2413::reset
void reset() override
Reset this YM2413 core.
Definition: YM2413OriginalNukeYKT.cc:13