| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#include "ymfm_opl.h" |
| 32 |
#include "ymfm_fm.ipp" |
| 33 |
|
| 34 |
namespace ymfm |
| 35 |
{ |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
inline uint32_t opl_key_scale_atten(uint32_t block, uint32_t fnum_4msb) |
| 46 |
{ |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
static uint8_t const fnum_to_atten[16] = { 0,24,32,37,40,43,45,47,48,50,51,52,53,54,55,56 }; |
| 51 |
int32_t result = fnum_to_atten[fnum_4msb] - 8 * (block ^ 7); |
| 52 |
return std::max<int32_t>(0, result); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
template<int Revision> |
| 65 |
opl_registers_base<Revision>::opl_registers_base() : |
| 66 |
m_lfo_am_counter(0), |
| 67 |
m_lfo_pm_counter(0), |
| 68 |
m_noise_lfsr(1), |
| 69 |
m_lfo_am(0) |
| 70 |
{ |
| 71 |
|
| 72 |
|
| 73 |
uint16_t *wf0 = &m_waveform[0][0]; |
| 74 |
uint16_t *wf1 = &m_waveform[1 % WAVEFORMS][0]; |
| 75 |
uint16_t *wf2 = &m_waveform[2 % WAVEFORMS][0]; |
| 76 |
uint16_t *wf3 = &m_waveform[3 % WAVEFORMS][0]; |
| 77 |
uint16_t *wf4 = &m_waveform[4 % WAVEFORMS][0]; |
| 78 |
uint16_t *wf5 = &m_waveform[5 % WAVEFORMS][0]; |
| 79 |
uint16_t *wf6 = &m_waveform[6 % WAVEFORMS][0]; |
| 80 |
uint16_t *wf7 = &m_waveform[7 % WAVEFORMS][0]; |
| 81 |
|
| 82 |
|
| 83 |
for (uint32_t index = 0; index < WAVEFORM_LENGTH; index++) |
| 84 |
wf0[index] = abs_sin_attenuation(index) | (bitfield(index, 9) << 15); |
| 85 |
|
| 86 |
if (WAVEFORMS >= 4) |
| 87 |
{ |
| 88 |
uint16_t zeroval = wf0[0]; |
| 89 |
for (uint32_t index = 0; index < WAVEFORM_LENGTH; index++) |
| 90 |
{ |
| 91 |
wf1[index] = bitfield(index, 9) ? zeroval : wf0[index]; |
| 92 |
wf2[index] = wf0[index] & 0x7fff; |
| 93 |
wf3[index] = bitfield(index, 8) ? zeroval : (wf0[index] & 0x7fff); |
| 94 |
if (WAVEFORMS >= 8) |
| 95 |
{ |
| 96 |
wf4[index] = bitfield(index, 9) ? zeroval : wf0[index * 2]; |
| 97 |
wf5[index] = bitfield(index, 9) ? zeroval : wf0[(index * 2) & 0x1ff]; |
| 98 |
wf6[index] = bitfield(index, 9) << 15; |
| 99 |
wf7[index] = (bitfield(index, 9) ? (index ^ 0x13ff) : index) << 3; |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
if (Revision > 2) |
| 107 |
m_regdata[0x104 % REGISTERS] = 0; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
template<int Revision> |
| 116 |
void opl_registers_base<Revision>::reset() |
| 117 |
{ |
| 118 |
std::fill_n(&m_regdata[0], REGISTERS, 0); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
template<int Revision> |
| 127 |
void opl_registers_base<Revision>::save_restore(ymfm_saved_state &state) |
| 128 |
{ |
| 129 |
state.save_restore(m_lfo_am_counter); |
| 130 |
state.save_restore(m_lfo_pm_counter); |
| 131 |
state.save_restore(m_lfo_am); |
| 132 |
state.save_restore(m_noise_lfsr); |
| 133 |
state.save_restore(m_regdata); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
template<int Revision> |
| 143 |
void opl_registers_base<Revision>::operator_map(operator_mapping &dest) const |
| 144 |
{ |
| 145 |
if (Revision <= 2) |
| 146 |
{ |
| 147 |
|
| 148 |
static const operator_mapping s_fixed_map = |
| 149 |
{ { |
| 150 |
operator_list( 0, 3 ), |
| 151 |
operator_list( 1, 4 ), |
| 152 |
operator_list( 2, 5 ), |
| 153 |
operator_list( 6, 9 ), |
| 154 |
operator_list( 7, 10 ), |
| 155 |
operator_list( 8, 11 ), |
| 156 |
operator_list( 12, 15 ), |
| 157 |
operator_list( 13, 16 ), |
| 158 |
operator_list( 14, 17 ), |
| 159 |
} }; |
| 160 |
dest = s_fixed_map; |
| 161 |
} |
| 162 |
else |
| 163 |
{ |
| 164 |
|
| 165 |
uint32_t fourop = fourop_enable(); |
| 166 |
|
| 167 |
dest.chan[ 0] = bitfield(fourop, 0) ? operator_list( 0, 3, 6, 9 ) : operator_list( 0, 3 ); |
| 168 |
dest.chan[ 1] = bitfield(fourop, 1) ? operator_list( 1, 4, 7, 10 ) : operator_list( 1, 4 ); |
| 169 |
dest.chan[ 2] = bitfield(fourop, 2) ? operator_list( 2, 5, 8, 11 ) : operator_list( 2, 5 ); |
| 170 |
dest.chan[ 3] = bitfield(fourop, 0) ? operator_list() : operator_list( 6, 9 ); |
| 171 |
dest.chan[ 4] = bitfield(fourop, 1) ? operator_list() : operator_list( 7, 10 ); |
| 172 |
dest.chan[ 5] = bitfield(fourop, 2) ? operator_list() : operator_list( 8, 11 ); |
| 173 |
dest.chan[ 6] = operator_list( 12, 15 ); |
| 174 |
dest.chan[ 7] = operator_list( 13, 16 ); |
| 175 |
dest.chan[ 8] = operator_list( 14, 17 ); |
| 176 |
|
| 177 |
dest.chan[ 9] = bitfield(fourop, 3) ? operator_list( 18, 21, 24, 27 ) : operator_list( 18, 21 ); |
| 178 |
dest.chan[10] = bitfield(fourop, 4) ? operator_list( 19, 22, 25, 28 ) : operator_list( 19, 22 ); |
| 179 |
dest.chan[11] = bitfield(fourop, 5) ? operator_list( 20, 23, 26, 29 ) : operator_list( 20, 23 ); |
| 180 |
dest.chan[12] = bitfield(fourop, 3) ? operator_list() : operator_list( 24, 27 ); |
| 181 |
dest.chan[13] = bitfield(fourop, 4) ? operator_list() : operator_list( 25, 28 ); |
| 182 |
dest.chan[14] = bitfield(fourop, 5) ? operator_list() : operator_list( 26, 29 ); |
| 183 |
dest.chan[15] = operator_list( 30, 33 ); |
| 184 |
dest.chan[16] = operator_list( 31, 34 ); |
| 185 |
dest.chan[17] = operator_list( 32, 35 ); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
template<int Revision> |
| 195 |
bool opl_registers_base<Revision>::write(uint16_t index, uint8_t data, uint32_t &channel, uint32_t &opmask) |
| 196 |
{ |
| 197 |
assert(index < REGISTERS); |
| 198 |
|
| 199 |
|
| 200 |
if (index == REG_MODE && bitfield(data, 7) != 0) |
| 201 |
m_regdata[index] |= 0x80; |
| 202 |
else |
| 203 |
m_regdata[index] = data; |
| 204 |
|
| 205 |
|
| 206 |
if (index == 0xbd) |
| 207 |
{ |
| 208 |
channel = RHYTHM_CHANNEL; |
| 209 |
opmask = bitfield(data, 5) ? bitfield(data, 0, 5) : 0; |
| 210 |
return true; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
if ((index & 0xf0) == 0xb0) |
| 215 |
{ |
| 216 |
channel = index & 0x0f; |
| 217 |
if (channel < 9) |
| 218 |
{ |
| 219 |
if (IsOpl3Plus) |
| 220 |
channel += 9 * bitfield(index, 8); |
| 221 |
opmask = bitfield(data, 5) ? 15 : 0; |
| 222 |
return true; |
| 223 |
} |
| 224 |
} |
| 225 |
return false; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
static int32_t opl_clock_noise_and_lfo(uint32_t &noise_lfsr, uint16_t &lfo_am_counter, uint16_t &lfo_pm_counter, uint8_t &lfo_am, uint32_t am_depth, uint32_t pm_depth) |
| 236 |
{ |
| 237 |
|
| 238 |
|
| 239 |
noise_lfsr <<= 1; |
| 240 |
noise_lfsr |= bitfield(noise_lfsr, 23) ^ bitfield(noise_lfsr, 9) ^ bitfield(noise_lfsr, 8) ^ bitfield(noise_lfsr, 1); |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
uint32_t am_counter = lfo_am_counter++; |
| 247 |
if (am_counter >= 210*64 - 1) |
| 248 |
lfo_am_counter = 0; |
| 249 |
|
| 250 |
|
| 251 |
int shift = 9 - 2 * am_depth; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
lfo_am = ((am_counter < 105*64) ? am_counter : (210*64+63 - am_counter)) >> shift; |
| 256 |
|
| 257 |
|
| 258 |
uint32_t pm_counter = lfo_pm_counter++; |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
static int8_t const pm_scale[8] = { 8, 4, 0, -4, -8, -4, 0, 4 }; |
| 264 |
return pm_scale[bitfield(pm_counter, 10, 3)] >> (pm_depth ^ 1); |
| 265 |
} |
| 266 |
|
| 267 |
template<int Revision> |
| 268 |
int32_t opl_registers_base<Revision>::clock_noise_and_lfo() |
| 269 |
{ |
| 270 |
return opl_clock_noise_and_lfo(m_noise_lfsr, m_lfo_am_counter, m_lfo_pm_counter, m_lfo_am, lfo_am_depth(), lfo_pm_depth()); |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
template<int Revision> |
| 282 |
void opl_registers_base<Revision>::cache_operator_data(uint32_t choffs, uint32_t opoffs, opdata_cache &cache) |
| 283 |
{ |
| 284 |
|
| 285 |
cache.waveform = &m_waveform[op_waveform(opoffs) % WAVEFORMS][0]; |
| 286 |
|
| 287 |
|
| 288 |
uint32_t block_freq = cache.block_freq = ch_block_freq(choffs); |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
uint32_t keycode = bitfield(block_freq, 10, 3) << 1; |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
keycode |= bitfield(block_freq, 9 - note_select(), 1); |
| 303 |
|
| 304 |
|
| 305 |
cache.detune = 0; |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
uint32_t multiple = op_multiple(opoffs); |
| 310 |
cache.multiple = ((multiple & 0xe) | bitfield(0xc2aa, multiple)) * 2; |
| 311 |
if (cache.multiple == 0) |
| 312 |
cache.multiple = 1; |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
if (op_lfo_pm_enable(opoffs) == 0) |
| 317 |
cache.phase_step = compute_phase_step(choffs, opoffs, cache, 0); |
| 318 |
else |
| 319 |
cache.phase_step = opdata_cache::PHASE_STEP_DYNAMIC; |
| 320 |
|
| 321 |
|
| 322 |
cache.total_level = op_total_level(opoffs) << 3; |
| 323 |
|
| 324 |
|
| 325 |
uint32_t ksl = op_ksl(opoffs); |
| 326 |
if (ksl != 0) |
| 327 |
cache.total_level += opl_key_scale_atten(bitfield(block_freq, 10, 3), bitfield(block_freq, 6, 4)) << ksl; |
| 328 |
|
| 329 |
|
| 330 |
cache.eg_sustain = op_sustain_level(opoffs); |
| 331 |
cache.eg_sustain |= (cache.eg_sustain + 1) & 0x10; |
| 332 |
cache.eg_sustain <<= 5; |
| 333 |
|
| 334 |
|
| 335 |
uint32_t ksrval = keycode >> (2 * (op_ksr(opoffs) ^ 1)); |
| 336 |
cache.eg_rate[EG_ATTACK] = effective_rate(op_attack_rate(opoffs) * 4, ksrval); |
| 337 |
cache.eg_rate[EG_DECAY] = effective_rate(op_decay_rate(opoffs) * 4, ksrval); |
| 338 |
cache.eg_rate[EG_SUSTAIN] = op_eg_sustain(opoffs) ? 0 : effective_rate(op_release_rate(opoffs) * 4, ksrval); |
| 339 |
cache.eg_rate[EG_RELEASE] = effective_rate(op_release_rate(opoffs) * 4, ksrval); |
| 340 |
cache.eg_rate[EG_DEPRESS] = 0x3f; |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
static uint32_t opl_compute_phase_step(uint32_t block_freq, uint32_t multiple, int32_t lfo_raw_pm) |
| 349 |
{ |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
uint32_t fnum = bitfield(block_freq, 0, 10) << 2; |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
fnum += (lfo_raw_pm * bitfield(block_freq, 7, 3)) >> 1; |
| 359 |
|
| 360 |
|
| 361 |
fnum &= 0xfff; |
| 362 |
|
| 363 |
|
| 364 |
uint32_t block = bitfield(block_freq, 10, 3); |
| 365 |
uint32_t phase_step = (fnum << block) >> 2; |
| 366 |
|
| 367 |
|
| 368 |
return (phase_step * multiple) >> 1; |
| 369 |
} |
| 370 |
|
| 371 |
template<int Revision> |
| 372 |
uint32_t opl_registers_base<Revision>::compute_phase_step(uint32_t choffs, uint32_t opoffs, opdata_cache const &cache, int32_t lfo_raw_pm) |
| 373 |
{ |
| 374 |
return opl_compute_phase_step(cache.block_freq, cache.multiple, op_lfo_pm_enable(opoffs) ? lfo_raw_pm : 0); |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
template<int Revision> |
| 383 |
std::string opl_registers_base<Revision>::log_keyon(uint32_t choffs, uint32_t opoffs) |
| 384 |
{ |
| 385 |
uint32_t chnum = (choffs & 15) + 9 * bitfield(choffs, 8); |
| 386 |
uint32_t opnum = (opoffs & 31) - 2 * ((opoffs & 31) / 8) + 18 * bitfield(opoffs, 8); |
| 387 |
|
| 388 |
char buffer[256]; |
| 389 |
int end = 0; |
| 390 |
|
| 391 |
end += snprintf(&buffer[end], sizeof(buffer) - end, "%2u.%02u freq=%04X fb=%u alg=%X mul=%X tl=%02X ksr=%u ns=%u ksl=%u adr=%X/%X/%X sl=%X sus=%u", |
| 392 |
chnum, opnum, |
| 393 |
ch_block_freq(choffs), |
| 394 |
ch_feedback(choffs), |
| 395 |
ch_algorithm(choffs), |
| 396 |
op_multiple(opoffs), |
| 397 |
op_total_level(opoffs), |
| 398 |
op_ksr(opoffs), |
| 399 |
note_select(), |
| 400 |
op_ksl(opoffs), |
| 401 |
op_attack_rate(opoffs), |
| 402 |
op_decay_rate(opoffs), |
| 403 |
op_release_rate(opoffs), |
| 404 |
op_sustain_level(opoffs), |
| 405 |
op_eg_sustain(opoffs)); |
| 406 |
|
| 407 |
if (OUTPUTS > 1) |
| 408 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " out=%c%c%c%c", |
| 409 |
ch_output_0(choffs) ? 'L' : '-', |
| 410 |
ch_output_1(choffs) ? 'R' : '-', |
| 411 |
ch_output_2(choffs) ? '0' : '-', |
| 412 |
ch_output_3(choffs) ? '1' : '-'); |
| 413 |
if (op_lfo_am_enable(opoffs) != 0) |
| 414 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " am=%u", lfo_am_depth()); |
| 415 |
if (op_lfo_pm_enable(opoffs) != 0) |
| 416 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " pm=%u", lfo_pm_depth()); |
| 417 |
if (waveform_enable() && op_waveform(opoffs) != 0) |
| 418 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " wf=%u", op_waveform(opoffs)); |
| 419 |
if (is_rhythm(choffs)) |
| 420 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " rhy=1"); |
| 421 |
if (DYNAMIC_OPS) |
| 422 |
{ |
| 423 |
operator_mapping map; |
| 424 |
operator_map(map); |
| 425 |
if (bitfield(map.chan[chnum], 16, 8) != 0xff) |
| 426 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " 4op"); |
| 427 |
} |
| 428 |
|
| 429 |
return buffer; |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
opll_registers::opll_registers() : |
| 442 |
m_lfo_am_counter(0), |
| 443 |
m_lfo_pm_counter(0), |
| 444 |
m_noise_lfsr(1), |
| 445 |
m_lfo_am(0) |
| 446 |
{ |
| 447 |
|
| 448 |
for (uint32_t index = 0; index < WAVEFORM_LENGTH; index++) |
| 449 |
m_waveform[0][index] = abs_sin_attenuation(index) | (bitfield(index, 9) << 15); |
| 450 |
|
| 451 |
uint16_t zeroval = m_waveform[0][0]; |
| 452 |
for (uint32_t index = 0; index < WAVEFORM_LENGTH; index++) |
| 453 |
m_waveform[1][index] = bitfield(index, 9) ? zeroval : m_waveform[0][index]; |
| 454 |
|
| 455 |
|
| 456 |
for (uint32_t choffs = 0; choffs < CHANNELS; choffs++) |
| 457 |
m_chinst[choffs] = &m_regdata[0]; |
| 458 |
for (uint32_t opoffs = 0; opoffs < OPERATORS; opoffs++) |
| 459 |
m_opinst[opoffs] = &m_regdata[bitfield(opoffs, 0)]; |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
void opll_registers::reset() |
| 468 |
{ |
| 469 |
std::fill_n(&m_regdata[0], REGISTERS, 0); |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
void opll_registers::save_restore(ymfm_saved_state &state) |
| 478 |
{ |
| 479 |
state.save_restore(m_lfo_am_counter); |
| 480 |
state.save_restore(m_lfo_pm_counter); |
| 481 |
state.save_restore(m_lfo_am); |
| 482 |
state.save_restore(m_noise_lfsr); |
| 483 |
state.save_restore(m_regdata); |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
void opll_registers::operator_map(operator_mapping &dest) const |
| 493 |
{ |
| 494 |
static const operator_mapping s_fixed_map = |
| 495 |
{ { |
| 496 |
operator_list( 0, 1 ), |
| 497 |
operator_list( 2, 3 ), |
| 498 |
operator_list( 4, 5 ), |
| 499 |
operator_list( 6, 7 ), |
| 500 |
operator_list( 8, 9 ), |
| 501 |
operator_list( 10, 11 ), |
| 502 |
operator_list( 12, 13 ), |
| 503 |
operator_list( 14, 15 ), |
| 504 |
operator_list( 16, 17 ), |
| 505 |
} }; |
| 506 |
dest = s_fixed_map; |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
bool opll_registers::write(uint16_t index, uint8_t data, uint32_t &channel, uint32_t &opmask) |
| 518 |
{ |
| 519 |
|
| 520 |
|
| 521 |
if (index >= REGISTERS) |
| 522 |
return false; |
| 523 |
|
| 524 |
|
| 525 |
m_regdata[index] = data; |
| 526 |
|
| 527 |
|
| 528 |
if (index == 0x0e) |
| 529 |
{ |
| 530 |
channel = RHYTHM_CHANNEL; |
| 531 |
opmask = bitfield(data, 5) ? bitfield(data, 0, 5) : 0; |
| 532 |
return true; |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
if ((index & 0xf0) == 0x20) |
| 537 |
{ |
| 538 |
channel = index & 0x0f; |
| 539 |
if (channel < CHANNELS) |
| 540 |
{ |
| 541 |
opmask = bitfield(data, 4) ? 3 : 0; |
| 542 |
return true; |
| 543 |
} |
| 544 |
} |
| 545 |
return false; |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
int32_t opll_registers::clock_noise_and_lfo() |
| 556 |
{ |
| 557 |
|
| 558 |
return opl_clock_noise_and_lfo(m_noise_lfsr, m_lfo_am_counter, m_lfo_pm_counter, m_lfo_am, 1, 1); |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
void opll_registers::cache_operator_data(uint32_t choffs, uint32_t opoffs, opdata_cache &cache) |
| 570 |
{ |
| 571 |
|
| 572 |
uint32_t instrument = ch_instrument(choffs); |
| 573 |
if (rhythm_enable() && choffs >= 6) |
| 574 |
m_chinst[choffs] = &m_instdata[8 * (15 + (choffs - 6))]; |
| 575 |
else |
| 576 |
m_chinst[choffs] = (instrument == 0) ? &m_regdata[0] : &m_instdata[8 * (instrument - 1)]; |
| 577 |
m_opinst[opoffs] = m_chinst[choffs] + bitfield(opoffs, 0); |
| 578 |
|
| 579 |
|
| 580 |
cache.waveform = &m_waveform[op_waveform(opoffs) % WAVEFORMS][0]; |
| 581 |
|
| 582 |
|
| 583 |
uint32_t block_freq = cache.block_freq = ch_block_freq(choffs); |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
uint32_t keycode = bitfield(block_freq, 8, 4); |
| 594 |
|
| 595 |
|
| 596 |
cache.detune = 0; |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
uint32_t multiple = op_multiple(opoffs); |
| 601 |
cache.multiple = ((multiple & 0xe) | bitfield(0xc2aa, multiple)) * 2; |
| 602 |
if (cache.multiple == 0) |
| 603 |
cache.multiple = 1; |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
if (op_lfo_pm_enable(opoffs) == 0) |
| 608 |
cache.phase_step = compute_phase_step(choffs, opoffs, cache, 0); |
| 609 |
else |
| 610 |
cache.phase_step = opdata_cache::PHASE_STEP_DYNAMIC; |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
if (bitfield(opoffs, 0) == 1 || (rhythm_enable() && choffs >= 7)) |
| 615 |
cache.total_level = op_volume(opoffs) * 4; |
| 616 |
else |
| 617 |
cache.total_level = ch_total_level(choffs); |
| 618 |
cache.total_level <<= 3; |
| 619 |
|
| 620 |
|
| 621 |
uint32_t ksl = op_ksl(opoffs); |
| 622 |
if (ksl != 0) |
| 623 |
cache.total_level += opl_key_scale_atten(bitfield(block_freq, 9, 3), bitfield(block_freq, 5, 4)) << ksl; |
| 624 |
|
| 625 |
|
| 626 |
cache.eg_sustain = op_sustain_level(opoffs); |
| 627 |
cache.eg_sustain |= (cache.eg_sustain + 1) & 0x10; |
| 628 |
cache.eg_sustain <<= 5; |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
constexpr uint8_t DP = 12 * 4; |
| 645 |
constexpr uint8_t RR = 7 * 4; |
| 646 |
constexpr uint8_t RS = 5 * 4; |
| 647 |
|
| 648 |
|
| 649 |
uint32_t ksrval = keycode >> (2 * (op_ksr(opoffs) ^ 1)); |
| 650 |
cache.eg_rate[EG_DEPRESS] = DP; |
| 651 |
cache.eg_rate[EG_ATTACK] = effective_rate(op_attack_rate(opoffs) * 4, ksrval); |
| 652 |
cache.eg_rate[EG_DECAY] = effective_rate(op_decay_rate(opoffs) * 4, ksrval); |
| 653 |
if (op_eg_sustain(opoffs)) |
| 654 |
{ |
| 655 |
cache.eg_rate[EG_SUSTAIN] = 0; |
| 656 |
cache.eg_rate[EG_RELEASE] = ch_sustain(choffs) ? RS : effective_rate(op_release_rate(opoffs) * 4, ksrval); |
| 657 |
} |
| 658 |
else |
| 659 |
{ |
| 660 |
cache.eg_rate[EG_SUSTAIN] = effective_rate(op_release_rate(opoffs) * 4, ksrval); |
| 661 |
cache.eg_rate[EG_RELEASE] = ch_sustain(choffs) ? RS : RR; |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
uint32_t opll_registers::compute_phase_step(uint32_t choffs, uint32_t opoffs, opdata_cache const &cache, int32_t lfo_raw_pm) |
| 671 |
{ |
| 672 |
|
| 673 |
|
| 674 |
return opl_compute_phase_step(cache.block_freq << 1, cache.multiple, op_lfo_pm_enable(opoffs) ? lfo_raw_pm : 0); |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
std::string opll_registers::log_keyon(uint32_t choffs, uint32_t opoffs) |
| 683 |
{ |
| 684 |
uint32_t chnum = choffs; |
| 685 |
uint32_t opnum = opoffs; |
| 686 |
|
| 687 |
char buffer[256]; |
| 688 |
int end = 0; |
| 689 |
|
| 690 |
end += snprintf(&buffer[end], sizeof(buffer) - end, "%u.%02u freq=%04X inst=%X fb=%u mul=%X", |
| 691 |
chnum, opnum, |
| 692 |
ch_block_freq(choffs), |
| 693 |
ch_instrument(choffs), |
| 694 |
ch_feedback(choffs), |
| 695 |
op_multiple(opoffs)); |
| 696 |
|
| 697 |
if (bitfield(opoffs, 0) == 1 || (is_rhythm(choffs) && choffs >= 6)) |
| 698 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " vol=%X", op_volume(opoffs)); |
| 699 |
else |
| 700 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " tl=%02X", ch_total_level(choffs)); |
| 701 |
|
| 702 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " ksr=%u ksl=%u adr=%X/%X/%X sl=%X sus=%u/%u", |
| 703 |
op_ksr(opoffs), |
| 704 |
op_ksl(opoffs), |
| 705 |
op_attack_rate(opoffs), |
| 706 |
op_decay_rate(opoffs), |
| 707 |
op_release_rate(opoffs), |
| 708 |
op_sustain_level(opoffs), |
| 709 |
op_eg_sustain(opoffs), |
| 710 |
ch_sustain(choffs)); |
| 711 |
|
| 712 |
if (op_lfo_am_enable(opoffs)) |
| 713 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " am=1"); |
| 714 |
if (op_lfo_pm_enable(opoffs)) |
| 715 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " pm=1"); |
| 716 |
if (op_waveform(opoffs) != 0) |
| 717 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " wf=1"); |
| 718 |
if (is_rhythm(choffs)) |
| 719 |
end += snprintf(&buffer[end], sizeof(buffer) - end, " rhy=1"); |
| 720 |
|
| 721 |
return buffer; |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
ym3526::ym3526(ymfm_interface &intf) : |
| 735 |
m_address(0), |
| 736 |
m_fm(intf) |
| 737 |
{ |
| 738 |
} |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
void ym3526::reset() |
| 746 |
{ |
| 747 |
|
| 748 |
m_fm.reset(); |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
void ym3526::save_restore(ymfm_saved_state &state) |
| 757 |
{ |
| 758 |
state.save_restore(m_address); |
| 759 |
m_fm.save_restore(state); |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
uint8_t ym3526::read_status() |
| 768 |
{ |
| 769 |
return m_fm.status() | 0x06; |
| 770 |
} |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
uint8_t ym3526::read(uint32_t offset) |
| 778 |
{ |
| 779 |
uint8_t result = 0xff; |
| 780 |
switch (offset & 1) |
| 781 |
{ |
| 782 |
case 0: |
| 783 |
result = read_status(); |
| 784 |
break; |
| 785 |
|
| 786 |
case 1: |
| 787 |
break; |
| 788 |
} |
| 789 |
return result; |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
void ym3526::write_address(uint8_t data) |
| 799 |
{ |
| 800 |
|
| 801 |
|
| 802 |
m_fm.intf().ymfm_set_busy_end(12 * m_fm.clock_prescale()); |
| 803 |
|
| 804 |
|
| 805 |
m_address = data; |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
void ym3526::write_data(uint8_t data) |
| 815 |
{ |
| 816 |
|
| 817 |
|
| 818 |
m_fm.intf().ymfm_set_busy_end(84 * m_fm.clock_prescale()); |
| 819 |
|
| 820 |
|
| 821 |
m_fm.write(m_address, data); |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
void ym3526::write(uint32_t offset, uint8_t data) |
| 831 |
{ |
| 832 |
switch (offset & 1) |
| 833 |
{ |
| 834 |
case 0: |
| 835 |
write_address(data); |
| 836 |
break; |
| 837 |
|
| 838 |
case 1: |
| 839 |
write_data(data); |
| 840 |
break; |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
void ym3526::generate(output_data *output, uint32_t numsamples) |
| 850 |
{ |
| 851 |
for (uint32_t samp = 0; samp < numsamples; samp++, output++) |
| 852 |
{ |
| 853 |
|
| 854 |
m_fm.clock(fm_engine::ALL_CHANNELS); |
| 855 |
|
| 856 |
|
| 857 |
m_fm.output(output->clear(), 1, 32767, fm_engine::ALL_CHANNELS); |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
output->roundtrip_fp(); |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
y8950::y8950(ymfm_interface &intf) : |
| 876 |
m_address(0), |
| 877 |
m_io_ddr(0), |
| 878 |
m_fm(intf), |
| 879 |
m_adpcm_b(intf) |
| 880 |
{ |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
void y8950::reset() |
| 889 |
{ |
| 890 |
|
| 891 |
m_fm.reset(); |
| 892 |
m_adpcm_b.reset(); |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
void y8950::save_restore(ymfm_saved_state &state) |
| 901 |
{ |
| 902 |
state.save_restore(m_address); |
| 903 |
state.save_restore(m_io_ddr); |
| 904 |
m_fm.save_restore(state); |
| 905 |
} |
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
uint8_t y8950::read_status() |
| 913 |
{ |
| 914 |
|
| 915 |
uint8_t status = m_fm.status() & ~(STATUS_ADPCM_B_EOS | STATUS_ADPCM_B_BRDY | STATUS_ADPCM_B_PLAYING); |
| 916 |
|
| 917 |
|
| 918 |
uint8_t adpcm_status = m_adpcm_b.status(); |
| 919 |
if ((adpcm_status & adpcm_b_channel::STATUS_EOS) != 0) |
| 920 |
status |= STATUS_ADPCM_B_EOS; |
| 921 |
if ((adpcm_status & adpcm_b_channel::STATUS_BRDY) != 0) |
| 922 |
status |= STATUS_ADPCM_B_BRDY; |
| 923 |
if ((adpcm_status & adpcm_b_channel::STATUS_PLAYING) != 0) |
| 924 |
status |= STATUS_ADPCM_B_PLAYING; |
| 925 |
|
| 926 |
|
| 927 |
return m_fm.set_reset_status(status, ~status); |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
uint8_t y8950::read_data() |
| 936 |
{ |
| 937 |
uint8_t result = 0xff; |
| 938 |
switch (m_address) |
| 939 |
{ |
| 940 |
case 0x05: |
| 941 |
result = m_fm.intf().ymfm_external_read(ACCESS_IO, 1); |
| 942 |
break; |
| 943 |
|
| 944 |
case 0x09: |
| 945 |
case 0x1a: |
| 946 |
result = m_adpcm_b.read(m_address - 0x07); |
| 947 |
break; |
| 948 |
|
| 949 |
case 0x19: |
| 950 |
result = m_fm.intf().ymfm_external_read(ACCESS_IO, 0); |
| 951 |
break; |
| 952 |
|
| 953 |
default: |
| 954 |
debug::log_unexpected_read_write("Unexpected read from Y8950 data port %02X\n", m_address); |
| 955 |
break; |
| 956 |
} |
| 957 |
return result; |
| 958 |
} |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
uint8_t y8950::read(uint32_t offset) |
| 966 |
{ |
| 967 |
uint8_t result = 0xff; |
| 968 |
switch (offset & 1) |
| 969 |
{ |
| 970 |
case 0: |
| 971 |
result = read_status(); |
| 972 |
break; |
| 973 |
|
| 974 |
case 1: |
| 975 |
result = read_data(); |
| 976 |
break; |
| 977 |
} |
| 978 |
return result; |
| 979 |
} |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
void y8950::write_address(uint8_t data) |
| 988 |
{ |
| 989 |
|
| 990 |
|
| 991 |
m_fm.intf().ymfm_set_busy_end(12 * m_fm.clock_prescale()); |
| 992 |
|
| 993 |
|
| 994 |
m_address = data; |
| 995 |
} |
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
void y8950::write_data(uint8_t data) |
| 1004 |
{ |
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
m_fm.intf().ymfm_set_busy_end(((m_address <= 0x1a) ? 12 : 84) * m_fm.clock_prescale()); |
| 1009 |
|
| 1010 |
|
| 1011 |
switch (m_address) |
| 1012 |
{ |
| 1013 |
case 0x04: |
| 1014 |
m_fm.write(m_address, data); |
| 1015 |
read_status(); |
| 1016 |
break; |
| 1017 |
|
| 1018 |
case 0x06: |
| 1019 |
m_fm.intf().ymfm_external_write(ACCESS_IO, 1, data); |
| 1020 |
break; |
| 1021 |
|
| 1022 |
case 0x08: |
| 1023 |
m_adpcm_b.write(m_address - 0x07, (data & 0x0f) | 0x80); |
| 1024 |
m_fm.write(m_address, data & 0xc0); |
| 1025 |
break; |
| 1026 |
|
| 1027 |
case 0x07: |
| 1028 |
case 0x09: |
| 1029 |
case 0x0a: |
| 1030 |
case 0x0b: |
| 1031 |
case 0x0c: |
| 1032 |
case 0x0d: |
| 1033 |
case 0x0e: |
| 1034 |
case 0x0f: |
| 1035 |
case 0x10: |
| 1036 |
case 0x11: |
| 1037 |
case 0x12: |
| 1038 |
case 0x15: |
| 1039 |
case 0x16: |
| 1040 |
case 0x17: |
| 1041 |
m_adpcm_b.write(m_address - 0x07, data); |
| 1042 |
break; |
| 1043 |
|
| 1044 |
case 0x18: |
| 1045 |
m_io_ddr = data & 0x0f; |
| 1046 |
break; |
| 1047 |
|
| 1048 |
case 0x19: |
| 1049 |
m_fm.intf().ymfm_external_write(ACCESS_IO, 0, data & m_io_ddr); |
| 1050 |
break; |
| 1051 |
|
| 1052 |
default: |
| 1053 |
m_fm.write(m_address, data); |
| 1054 |
break; |
| 1055 |
} |
| 1056 |
} |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
void y8950::write(uint32_t offset, uint8_t data) |
| 1065 |
{ |
| 1066 |
switch (offset & 1) |
| 1067 |
{ |
| 1068 |
case 0: |
| 1069 |
write_address(data); |
| 1070 |
break; |
| 1071 |
|
| 1072 |
case 1: |
| 1073 |
write_data(data); |
| 1074 |
break; |
| 1075 |
} |
| 1076 |
} |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
void y8950::generate(output_data *output, uint32_t numsamples) |
| 1084 |
{ |
| 1085 |
for (uint32_t samp = 0; samp < numsamples; samp++, output++) |
| 1086 |
{ |
| 1087 |
|
| 1088 |
m_fm.clock(fm_engine::ALL_CHANNELS); |
| 1089 |
m_adpcm_b.clock(); |
| 1090 |
|
| 1091 |
|
| 1092 |
m_fm.output(output->clear(), 1, 32767, fm_engine::ALL_CHANNELS); |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
m_adpcm_b.output(*output, 3); |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
output->roundtrip_fp(); |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
ym3812::ym3812(ymfm_interface &intf) : |
| 1115 |
m_address(0), |
| 1116 |
m_fm(intf) |
| 1117 |
{ |
| 1118 |
} |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
void ym3812::reset() |
| 1126 |
{ |
| 1127 |
|
| 1128 |
m_fm.reset(); |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
void ym3812::save_restore(ymfm_saved_state &state) |
| 1137 |
{ |
| 1138 |
state.save_restore(m_address); |
| 1139 |
m_fm.save_restore(state); |
| 1140 |
} |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
uint8_t ym3812::read_status() |
| 1148 |
{ |
| 1149 |
return m_fm.status() | 0x06; |
| 1150 |
} |
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
uint8_t ym3812::read(uint32_t offset) |
| 1158 |
{ |
| 1159 |
uint8_t result = 0xff; |
| 1160 |
switch (offset & 1) |
| 1161 |
{ |
| 1162 |
case 0: |
| 1163 |
result = read_status(); |
| 1164 |
break; |
| 1165 |
|
| 1166 |
case 1: |
| 1167 |
break; |
| 1168 |
} |
| 1169 |
return result; |
| 1170 |
} |
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
void ym3812::write_address(uint8_t data) |
| 1179 |
{ |
| 1180 |
|
| 1181 |
|
| 1182 |
m_fm.intf().ymfm_set_busy_end(12 * m_fm.clock_prescale()); |
| 1183 |
|
| 1184 |
|
| 1185 |
m_address = data; |
| 1186 |
} |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
void ym3812::write_data(uint8_t data) |
| 1195 |
{ |
| 1196 |
|
| 1197 |
|
| 1198 |
m_fm.intf().ymfm_set_busy_end(84 * m_fm.clock_prescale()); |
| 1199 |
|
| 1200 |
|
| 1201 |
m_fm.write(m_address, data); |
| 1202 |
} |
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
void ym3812::write(uint32_t offset, uint8_t data) |
| 1211 |
{ |
| 1212 |
switch (offset & 1) |
| 1213 |
{ |
| 1214 |
case 0: |
| 1215 |
write_address(data); |
| 1216 |
break; |
| 1217 |
|
| 1218 |
case 1: |
| 1219 |
write_data(data); |
| 1220 |
break; |
| 1221 |
} |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
void ym3812::generate(output_data *output, uint32_t numsamples) |
| 1230 |
{ |
| 1231 |
for (uint32_t samp = 0; samp < numsamples; samp++, output++) |
| 1232 |
{ |
| 1233 |
|
| 1234 |
m_fm.clock(fm_engine::ALL_CHANNELS); |
| 1235 |
|
| 1236 |
|
| 1237 |
m_fm.output(output->clear(), 1, 32767, fm_engine::ALL_CHANNELS); |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
output->roundtrip_fp(); |
| 1242 |
} |
| 1243 |
} |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
ymf262::ymf262(ymfm_interface &intf) : |
| 1256 |
m_address(0), |
| 1257 |
m_fm(intf) |
| 1258 |
{ |
| 1259 |
} |
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
void ymf262::reset() |
| 1267 |
{ |
| 1268 |
|
| 1269 |
m_fm.reset(); |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
void ymf262::save_restore(ymfm_saved_state &state) |
| 1278 |
{ |
| 1279 |
state.save_restore(m_address); |
| 1280 |
m_fm.save_restore(state); |
| 1281 |
} |
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
uint8_t ymf262::read_status() |
| 1289 |
{ |
| 1290 |
return m_fm.status(); |
| 1291 |
} |
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
uint8_t ymf262::read(uint32_t offset) |
| 1299 |
{ |
| 1300 |
uint8_t result = 0xff; |
| 1301 |
switch (offset & 3) |
| 1302 |
{ |
| 1303 |
case 0: |
| 1304 |
result = read_status(); |
| 1305 |
break; |
| 1306 |
|
| 1307 |
case 1: |
| 1308 |
case 2: |
| 1309 |
case 3: |
| 1310 |
debug::log_unexpected_read_write("Unexpected read from YMF262 offset %d\n", offset & 3); |
| 1311 |
break; |
| 1312 |
} |
| 1313 |
return result; |
| 1314 |
} |
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
void ymf262::write_address(uint8_t data) |
| 1323 |
{ |
| 1324 |
|
| 1325 |
|
| 1326 |
m_fm.intf().ymfm_set_busy_end(32 * m_fm.clock_prescale()); |
| 1327 |
|
| 1328 |
|
| 1329 |
m_address = data; |
| 1330 |
} |
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
void ymf262::write_data(uint8_t data) |
| 1339 |
{ |
| 1340 |
|
| 1341 |
|
| 1342 |
m_fm.intf().ymfm_set_busy_end(32 * m_fm.clock_prescale()); |
| 1343 |
|
| 1344 |
|
| 1345 |
m_fm.write(m_address, data); |
| 1346 |
} |
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
void ymf262::write_address_hi(uint8_t data) |
| 1355 |
{ |
| 1356 |
|
| 1357 |
|
| 1358 |
m_fm.intf().ymfm_set_busy_end(32 * m_fm.clock_prescale()); |
| 1359 |
|
| 1360 |
|
| 1361 |
m_address = data | 0x100; |
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
if (m_fm.regs().newflag() == 0 && m_address != 0x105) |
| 1366 |
m_address &= 0xff; |
| 1367 |
} |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
void ymf262::write(uint32_t offset, uint8_t data) |
| 1376 |
{ |
| 1377 |
switch (offset & 3) |
| 1378 |
{ |
| 1379 |
case 0: |
| 1380 |
write_address(data); |
| 1381 |
break; |
| 1382 |
|
| 1383 |
case 1: |
| 1384 |
write_data(data); |
| 1385 |
break; |
| 1386 |
|
| 1387 |
case 2: |
| 1388 |
write_address_hi(data); |
| 1389 |
break; |
| 1390 |
|
| 1391 |
case 3: |
| 1392 |
write_data(data); |
| 1393 |
break; |
| 1394 |
} |
| 1395 |
} |
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
void ymf262::generate(output_data *output, uint32_t numsamples) |
| 1403 |
{ |
| 1404 |
for (uint32_t samp = 0; samp < numsamples; samp++, output++) |
| 1405 |
{ |
| 1406 |
|
| 1407 |
m_fm.clock(fm_engine::ALL_CHANNELS); |
| 1408 |
|
| 1409 |
|
| 1410 |
m_fm.output(output->clear(), 0, 32767, fm_engine::ALL_CHANNELS); |
| 1411 |
|
| 1412 |
|
| 1413 |
output->clamp16(); |
| 1414 |
} |
| 1415 |
} |
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
ymf289b::ymf289b(ymfm_interface &intf) : |
| 1436 |
m_address(0), |
| 1437 |
m_fm(intf) |
| 1438 |
{ |
| 1439 |
} |
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
void ymf289b::reset() |
| 1447 |
{ |
| 1448 |
|
| 1449 |
m_fm.reset(); |
| 1450 |
} |
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
void ymf289b::save_restore(ymfm_saved_state &state) |
| 1458 |
{ |
| 1459 |
state.save_restore(m_address); |
| 1460 |
m_fm.save_restore(state); |
| 1461 |
} |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
uint8_t ymf289b::read_status() |
| 1469 |
{ |
| 1470 |
uint8_t result = m_fm.status(); |
| 1471 |
|
| 1472 |
|
| 1473 |
if (ymf289b_mode() && m_fm.intf().ymfm_is_busy()) |
| 1474 |
result |= STATUS_BUSY_FLAGS; |
| 1475 |
return result; |
| 1476 |
} |
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
uint8_t ymf289b::read_data() |
| 1484 |
{ |
| 1485 |
uint8_t result = 0xff; |
| 1486 |
|
| 1487 |
|
| 1488 |
if (ymf289b_mode()) |
| 1489 |
result = m_fm.regs().read(m_address); |
| 1490 |
return result; |
| 1491 |
} |
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
uint8_t ymf289b::read(uint32_t offset) |
| 1499 |
{ |
| 1500 |
uint8_t result = 0xff; |
| 1501 |
switch (offset & 3) |
| 1502 |
{ |
| 1503 |
case 0: |
| 1504 |
result = read_status(); |
| 1505 |
break; |
| 1506 |
|
| 1507 |
case 1: |
| 1508 |
result = read_data(); |
| 1509 |
break; |
| 1510 |
|
| 1511 |
case 2: |
| 1512 |
case 3: |
| 1513 |
debug::log_unexpected_read_write("Unexpected read from YMF289B offset %d\n", offset & 3); |
| 1514 |
break; |
| 1515 |
} |
| 1516 |
return result; |
| 1517 |
} |
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
void ymf289b::write_address(uint8_t data) |
| 1526 |
{ |
| 1527 |
m_address = data; |
| 1528 |
|
| 1529 |
|
| 1530 |
m_fm.intf().ymfm_set_busy_end(56); |
| 1531 |
} |
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
void ymf289b::write_data(uint8_t data) |
| 1540 |
{ |
| 1541 |
|
| 1542 |
m_fm.write(m_address, data); |
| 1543 |
|
| 1544 |
|
| 1545 |
if (m_address == 0x108 && bitfield(data, 2) != 0) |
| 1546 |
m_fm.regs().reset(); |
| 1547 |
|
| 1548 |
|
| 1549 |
m_fm.intf().ymfm_set_busy_end(56); |
| 1550 |
} |
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
void ymf289b::write_address_hi(uint8_t data) |
| 1559 |
{ |
| 1560 |
|
| 1561 |
m_address = data | 0x100; |
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
if (m_fm.regs().newflag() == 0 && m_address != 0x105) |
| 1566 |
m_address &= 0xff; |
| 1567 |
|
| 1568 |
|
| 1569 |
m_fm.intf().ymfm_set_busy_end(56); |
| 1570 |
} |
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
void ymf289b::write(uint32_t offset, uint8_t data) |
| 1579 |
{ |
| 1580 |
switch (offset & 3) |
| 1581 |
{ |
| 1582 |
case 0: |
| 1583 |
write_address(data); |
| 1584 |
break; |
| 1585 |
|
| 1586 |
case 1: |
| 1587 |
write_data(data); |
| 1588 |
break; |
| 1589 |
|
| 1590 |
case 2: |
| 1591 |
write_address_hi(data); |
| 1592 |
break; |
| 1593 |
|
| 1594 |
case 3: |
| 1595 |
write_data(data); |
| 1596 |
break; |
| 1597 |
} |
| 1598 |
} |
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
void ymf289b::generate(output_data *output, uint32_t numsamples) |
| 1606 |
{ |
| 1607 |
for (uint32_t samp = 0; samp < numsamples; samp++, output++) |
| 1608 |
{ |
| 1609 |
|
| 1610 |
m_fm.clock(fm_engine::ALL_CHANNELS); |
| 1611 |
|
| 1612 |
|
| 1613 |
fm_engine::output_data full; |
| 1614 |
m_fm.output(full.clear(), 0, 32767, fm_engine::ALL_CHANNELS); |
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
output->data[0] = full.data[0]; |
| 1619 |
output->data[1] = full.data[1]; |
| 1620 |
output->clamp16(); |
| 1621 |
} |
| 1622 |
} |
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
ymf278b::ymf278b(ymfm_interface &intf) : |
| 1635 |
m_address(0), |
| 1636 |
m_fm_pos(0), |
| 1637 |
m_load_remaining(0), |
| 1638 |
m_next_status_id(false), |
| 1639 |
m_fm(intf), |
| 1640 |
m_pcm(intf) |
| 1641 |
{ |
| 1642 |
} |
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
void ymf278b::reset() |
| 1650 |
{ |
| 1651 |
|
| 1652 |
m_fm.reset(); |
| 1653 |
m_pcm.reset(); |
| 1654 |
|
| 1655 |
|
| 1656 |
m_next_status_id = true; |
| 1657 |
} |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
void ymf278b::save_restore(ymfm_saved_state &state) |
| 1665 |
{ |
| 1666 |
state.save_restore(m_address); |
| 1667 |
state.save_restore(m_fm_pos); |
| 1668 |
state.save_restore(m_load_remaining); |
| 1669 |
state.save_restore(m_next_status_id); |
| 1670 |
m_fm.save_restore(state); |
| 1671 |
m_pcm.save_restore(state); |
| 1672 |
} |
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
uint8_t ymf278b::read_status() |
| 1680 |
{ |
| 1681 |
uint8_t result; |
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
if (m_next_status_id) |
| 1686 |
{ |
| 1687 |
if (m_fm.regs().new2flag()) |
| 1688 |
result = 0x02; |
| 1689 |
else if (m_fm.regs().newflag()) |
| 1690 |
result = 0x00; |
| 1691 |
else |
| 1692 |
result = 0x06; |
| 1693 |
m_next_status_id = false; |
| 1694 |
} |
| 1695 |
else |
| 1696 |
{ |
| 1697 |
result = m_fm.status(); |
| 1698 |
if (m_fm.intf().ymfm_is_busy()) |
| 1699 |
result |= STATUS_BUSY; |
| 1700 |
if (m_load_remaining != 0) |
| 1701 |
result |= STATUS_LD; |
| 1702 |
|
| 1703 |
|
| 1704 |
if (!m_fm.regs().new2flag()) |
| 1705 |
result &= ~(STATUS_BUSY | STATUS_LD); |
| 1706 |
} |
| 1707 |
return result; |
| 1708 |
} |
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
uint8_t ymf278b::read_data_pcm() |
| 1717 |
{ |
| 1718 |
|
| 1719 |
if (bitfield(m_address, 9) != 0) |
| 1720 |
{ |
| 1721 |
uint8_t result = m_pcm.read(m_address & 0xff); |
| 1722 |
if ((m_address & 0xff) == 0x02) |
| 1723 |
result |= 0x20; |
| 1724 |
|
| 1725 |
return result; |
| 1726 |
} |
| 1727 |
return 0; |
| 1728 |
} |
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
uint8_t ymf278b::read(uint32_t offset) |
| 1736 |
{ |
| 1737 |
uint8_t result = 0xff; |
| 1738 |
switch (offset & 7) |
| 1739 |
{ |
| 1740 |
case 0: |
| 1741 |
result = read_status(); |
| 1742 |
break; |
| 1743 |
|
| 1744 |
case 5: |
| 1745 |
result = read_data_pcm(); |
| 1746 |
break; |
| 1747 |
|
| 1748 |
default: |
| 1749 |
debug::log_unexpected_read_write("Unexpected read from ymf278b offset %d\n", offset & 3); |
| 1750 |
break; |
| 1751 |
} |
| 1752 |
return result; |
| 1753 |
} |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
void ymf278b::write_address(uint8_t data) |
| 1762 |
{ |
| 1763 |
|
| 1764 |
m_address = data; |
| 1765 |
} |
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
void ymf278b::write_data(uint8_t data) |
| 1774 |
{ |
| 1775 |
|
| 1776 |
if (bitfield(m_address, 9) == 0) |
| 1777 |
{ |
| 1778 |
uint8_t old = m_fm.regs().new2flag(); |
| 1779 |
m_fm.write(m_address, data); |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
if (old == 0 && m_fm.regs().new2flag() != 0) |
| 1784 |
m_next_status_id = true; |
| 1785 |
} |
| 1786 |
|
| 1787 |
|
| 1788 |
m_fm.intf().ymfm_set_busy_end(56); |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
void ymf278b::write_address_hi(uint8_t data) |
| 1798 |
{ |
| 1799 |
|
| 1800 |
m_address = data | 0x100; |
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
if (m_fm.regs().newflag() == 0 && m_address != 0x105) |
| 1805 |
m_address &= 0xff; |
| 1806 |
} |
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
void ymf278b::write_address_pcm(uint8_t data) |
| 1815 |
{ |
| 1816 |
|
| 1817 |
m_address = data | 0x200; |
| 1818 |
} |
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
void ymf278b::write_data_pcm(uint8_t data) |
| 1827 |
{ |
| 1828 |
|
| 1829 |
if (m_fm.regs().new2flag() == 0) |
| 1830 |
return; |
| 1831 |
|
| 1832 |
|
| 1833 |
if (bitfield(m_address, 9) != 0) |
| 1834 |
{ |
| 1835 |
uint8_t addr = m_address & 0xff; |
| 1836 |
m_pcm.write(addr, data); |
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
if (addr >= 0x08 && addr <= 0x1f) |
| 1841 |
m_load_remaining = 13; |
| 1842 |
} |
| 1843 |
|
| 1844 |
|
| 1845 |
m_fm.intf().ymfm_set_busy_end(88); |
| 1846 |
} |
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
void ymf278b::write(uint32_t offset, uint8_t data) |
| 1855 |
{ |
| 1856 |
switch (offset & 7) |
| 1857 |
{ |
| 1858 |
case 0: |
| 1859 |
write_address(data); |
| 1860 |
break; |
| 1861 |
|
| 1862 |
case 1: |
| 1863 |
write_data(data); |
| 1864 |
break; |
| 1865 |
|
| 1866 |
case 2: |
| 1867 |
write_address_hi(data); |
| 1868 |
break; |
| 1869 |
|
| 1870 |
case 3: |
| 1871 |
write_data(data); |
| 1872 |
break; |
| 1873 |
|
| 1874 |
case 4: |
| 1875 |
write_address_pcm(data); |
| 1876 |
break; |
| 1877 |
|
| 1878 |
case 5: |
| 1879 |
write_data_pcm(data); |
| 1880 |
break; |
| 1881 |
|
| 1882 |
default: |
| 1883 |
debug::log_unexpected_read_write("Unexpected write to ymf278b offset %d\n", offset & 7); |
| 1884 |
break; |
| 1885 |
} |
| 1886 |
} |
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
void ymf278b::generate(output_data *output, uint32_t numsamples) |
| 1894 |
{ |
| 1895 |
static const int16_t s_mix_scale[8] = { 0x7fa, 0x5a4, 0x3fd, 0x2d2, 0x1fe, 0x169, 0xff, 0 }; |
| 1896 |
int32_t const pcm_l = s_mix_scale[m_pcm.regs().mix_pcm_l()]; |
| 1897 |
int32_t const pcm_r = s_mix_scale[m_pcm.regs().mix_pcm_r()]; |
| 1898 |
int32_t const fm_l = s_mix_scale[m_pcm.regs().mix_fm_l()]; |
| 1899 |
int32_t const fm_r = s_mix_scale[m_pcm.regs().mix_fm_r()]; |
| 1900 |
for (uint32_t samp = 0; samp < numsamples; samp++, output++) |
| 1901 |
{ |
| 1902 |
|
| 1903 |
m_fm_pos += FM_EXTRA_SAMPLE_STEP; |
| 1904 |
if (m_fm_pos >= FM_EXTRA_SAMPLE_THRESH) |
| 1905 |
{ |
| 1906 |
m_fm.clock(fm_engine::ALL_CHANNELS); |
| 1907 |
m_fm_pos -= FM_EXTRA_SAMPLE_THRESH; |
| 1908 |
} |
| 1909 |
m_fm.clock(fm_engine::ALL_CHANNELS); |
| 1910 |
m_pcm.clock(pcm_engine::ALL_CHANNELS); |
| 1911 |
|
| 1912 |
|
| 1913 |
fm_engine::output_data fmout; |
| 1914 |
m_fm.output(fmout.clear(), 0, 32767, fm_engine::ALL_CHANNELS); |
| 1915 |
|
| 1916 |
|
| 1917 |
pcm_engine::output_data pcmout; |
| 1918 |
m_pcm.output(pcmout.clear(), pcm_engine::ALL_CHANNELS); |
| 1919 |
|
| 1920 |
|
| 1921 |
output->data[0] = fmout.data[2]; |
| 1922 |
output->data[1] = fmout.data[3]; |
| 1923 |
|
| 1924 |
|
| 1925 |
output->data[2] = pcmout.data[2]; |
| 1926 |
output->data[3] = pcmout.data[3]; |
| 1927 |
|
| 1928 |
|
| 1929 |
output->data[4] = (fmout.data[0] * fm_l + pcmout.data[0] * pcm_l) >> 11; |
| 1930 |
output->data[5] = (fmout.data[1] * fm_r + pcmout.data[1] * pcm_r) >> 11; |
| 1931 |
|
| 1932 |
|
| 1933 |
output->clamp16(); |
| 1934 |
} |
| 1935 |
|
| 1936 |
|
| 1937 |
if (m_load_remaining > 0) |
| 1938 |
m_load_remaining -= std::min(m_load_remaining, numsamples); |
| 1939 |
} |
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
opll_base::opll_base(ymfm_interface &intf, uint8_t const *instrument_data) : |
| 1952 |
m_address(0), |
| 1953 |
m_fm(intf) |
| 1954 |
{ |
| 1955 |
m_fm.regs().set_instrument_data(instrument_data); |
| 1956 |
} |
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
void opll_base::reset() |
| 1964 |
{ |
| 1965 |
|
| 1966 |
m_fm.reset(); |
| 1967 |
} |
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
void opll_base::save_restore(ymfm_saved_state &state) |
| 1975 |
{ |
| 1976 |
state.save_restore(m_address); |
| 1977 |
m_fm.save_restore(state); |
| 1978 |
} |
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
void opll_base::write_address(uint8_t data) |
| 1987 |
{ |
| 1988 |
|
| 1989 |
|
| 1990 |
m_fm.intf().ymfm_set_busy_end(12); |
| 1991 |
|
| 1992 |
|
| 1993 |
m_address = data; |
| 1994 |
} |
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
void opll_base::write_data(uint8_t data) |
| 2003 |
{ |
| 2004 |
|
| 2005 |
|
| 2006 |
m_fm.intf().ymfm_set_busy_end(84); |
| 2007 |
|
| 2008 |
|
| 2009 |
m_fm.write(m_address, data); |
| 2010 |
} |
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
void opll_base::write(uint32_t offset, uint8_t data) |
| 2019 |
{ |
| 2020 |
switch (offset & 1) |
| 2021 |
{ |
| 2022 |
case 0: |
| 2023 |
write_address(data); |
| 2024 |
break; |
| 2025 |
|
| 2026 |
case 1: |
| 2027 |
write_data(data); |
| 2028 |
break; |
| 2029 |
} |
| 2030 |
} |
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
void opll_base::generate(output_data *output, uint32_t numsamples) |
| 2038 |
{ |
| 2039 |
for (uint32_t samp = 0; samp < numsamples; samp++, output++) |
| 2040 |
{ |
| 2041 |
|
| 2042 |
m_fm.clock(fm_engine::ALL_CHANNELS); |
| 2043 |
|
| 2044 |
|
| 2045 |
m_fm.output(output->clear(), 5, 256, fm_engine::ALL_CHANNELS); |
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
output->data[0] = (output->data[0] * 128) / 9; |
| 2050 |
output->data[1] = (output->data[1] * 128) / 9; |
| 2051 |
} |
| 2052 |
} |
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
ym2413::ym2413(ymfm_interface &intf, uint8_t const *instrument_data) : |
| 2065 |
opll_base(intf, (instrument_data != nullptr) ? instrument_data : s_default_instruments) |
| 2066 |
{ |
| 2067 |
}; |
| 2068 |
|
| 2069 |
|
| 2070 |
uint8_t const ym2413::s_default_instruments[] = |
| 2071 |
{ |
| 2072 |
|
| 2073 |
0x71, 0x61, 0x1E, 0x17, 0xEF, 0x7F, 0x00, 0x17, |
| 2074 |
0x13, 0x41, 0x1A, 0x0D, 0xF8, 0xF7, 0x23, 0x13, |
| 2075 |
0x13, 0x01, 0x99, 0x00, 0xF2, 0xC4, 0x11, 0x23, |
| 2076 |
0x31, 0x61, 0x0E, 0x07, 0x98, 0x64, 0x70, 0x27, |
| 2077 |
0x22, 0x21, 0x1E, 0x06, 0xBF, 0x76, 0x00, 0x28, |
| 2078 |
0x31, 0x22, 0x16, 0x05, 0xE0, 0x71, 0x0F, 0x18, |
| 2079 |
0x21, 0x61, 0x1D, 0x07, 0x82, 0x8F, 0x10, 0x07, |
| 2080 |
0x23, 0x21, 0x2D, 0x14, 0xFF, 0x7F, 0x00, 0x07, |
| 2081 |
0x41, 0x61, 0x1B, 0x06, 0x64, 0x65, 0x10, 0x17, |
| 2082 |
0x61, 0x61, 0x0B, 0x18, 0x85, 0xFF, 0x81, 0x07, |
| 2083 |
0x13, 0x01, 0x83, 0x11, 0xFA, 0xE4, 0x10, 0x04, |
| 2084 |
0x17, 0x81, 0x23, 0x07, 0xF8, 0xF8, 0x22, 0x12, |
| 2085 |
0x61, 0x50, 0x0C, 0x05, 0xF2, 0xF5, 0x29, 0x42, |
| 2086 |
0x01, 0x01, 0x54, 0x03, 0xC3, 0x92, 0x03, 0x02, |
| 2087 |
0x41, 0x41, 0x89, 0x03, 0xF1, 0xE5, 0x11, 0x13, |
| 2088 |
0x01, 0x01, 0x18, 0x0F, 0xDF, 0xF8, 0x6A, 0x6D, |
| 2089 |
0x01, 0x01, 0x00, 0x00, 0xC8, 0xD8, 0xA7, 0x48, |
| 2090 |
0x05, 0x01, 0x00, 0x00, 0xF8, 0xAA, 0x59, 0x55 |
| 2091 |
}; |
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
ym2423::ym2423(ymfm_interface &intf, uint8_t const *instrument_data) : |
| 2104 |
opll_base(intf, (instrument_data != nullptr) ? instrument_data : s_default_instruments) |
| 2105 |
{ |
| 2106 |
}; |
| 2107 |
|
| 2108 |
|
| 2109 |
uint8_t const ym2423::s_default_instruments[] = |
| 2110 |
{ |
| 2111 |
|
| 2112 |
|
| 2113 |
|
| 2114 |
0x61, 0x61, 0x1B, 0x07, 0x94, 0x5F, 0x10, 0x06, |
| 2115 |
0x93, 0xB1, 0x51, 0x04, 0xF3, 0xF2, 0x70, 0xFB, |
| 2116 |
0x41, 0x21, 0x11, 0x85, 0xF2, 0xF2, 0x70, 0x75, |
| 2117 |
0x93, 0xB2, 0x28, 0x07, 0xF3, 0xF2, 0x70, 0xB4, |
| 2118 |
0x72, 0x31, 0x97, 0x05, 0x51, 0x6F, 0x60, 0x09, |
| 2119 |
0x13, 0x30, 0x18, 0x06, 0xF7, 0xF4, 0x50, 0x85, |
| 2120 |
0x51, 0x31, 0x1C, 0x07, 0x51, 0x71, 0x20, 0x26, |
| 2121 |
0x41, 0xF4, 0x1B, 0x07, 0x74, 0x34, 0x00, 0x06, |
| 2122 |
0x50, 0x30, 0x4D, 0x03, 0x42, 0x65, 0x20, 0x06, |
| 2123 |
0x40, 0x20, 0x10, 0x85, 0xF3, 0xF5, 0x20, 0x04, |
| 2124 |
0x61, 0x61, 0x1B, 0x07, 0xC5, 0x96, 0xF3, 0xF6, |
| 2125 |
0xF9, 0xF1, 0xDC, 0x00, 0xF5, 0xF3, 0x77, 0xF2, |
| 2126 |
0x60, 0xA2, 0x91, 0x03, 0x94, 0xC1, 0xF7, 0xF7, |
| 2127 |
0x30, 0x30, 0x17, 0x06, 0xF3, 0xF1, 0xB7, 0xFC, |
| 2128 |
0x31, 0x36, 0x0D, 0x05, 0xF2, 0xF4, 0x27, 0x9C, |
| 2129 |
0x01, 0x01, 0x18, 0x0F, 0xDF, 0xF8, 0x6A, 0x6D, |
| 2130 |
0x01, 0x01, 0x00, 0x00, 0xC8, 0xD8, 0xA7, 0x48, |
| 2131 |
0x05, 0x01, 0x00, 0x00, 0xF8, 0xAA, 0x59, 0x55 |
| 2132 |
}; |
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
ymf281::ymf281(ymfm_interface &intf, uint8_t const *instrument_data) : |
| 2145 |
opll_base(intf, (instrument_data != nullptr) ? instrument_data : s_default_instruments) |
| 2146 |
{ |
| 2147 |
}; |
| 2148 |
|
| 2149 |
|
| 2150 |
uint8_t const ymf281::s_default_instruments[] = |
| 2151 |
{ |
| 2152 |
|
| 2153 |
0x72, 0x21, 0x1A, 0x07, 0xF6, 0x64, 0x01, 0x16, |
| 2154 |
0x00, 0x10, 0x45, 0x00, 0xF6, 0x83, 0x73, 0x63, |
| 2155 |
0x13, 0x01, 0x96, 0x00, 0xF1, 0xF4, 0x31, 0x23, |
| 2156 |
0x71, 0x21, 0x0B, 0x0F, 0xF9, 0x64, 0x70, 0x17, |
| 2157 |
0x02, 0x21, 0x1E, 0x06, 0xF9, 0x76, 0x00, 0x28, |
| 2158 |
0x00, 0x61, 0x82, 0x0E, 0xF9, 0x61, 0x20, 0x27, |
| 2159 |
0x21, 0x61, 0x1B, 0x07, 0x84, 0x8F, 0x10, 0x07, |
| 2160 |
0x37, 0x32, 0xCA, 0x02, 0x66, 0x64, 0x47, 0x29, |
| 2161 |
0x41, 0x41, 0x07, 0x03, 0xF5, 0x70, 0x51, 0xF5, |
| 2162 |
0x36, 0x01, 0x5E, 0x07, 0xF2, 0xF3, 0xF7, 0xF7, |
| 2163 |
0x00, 0x00, 0x18, 0x06, 0xC5, 0xF3, 0x20, 0xF2, |
| 2164 |
0x17, 0x81, 0x25, 0x07, 0xF7, 0xF3, 0x21, 0xF7, |
| 2165 |
0x35, 0x64, 0x00, 0x00, 0xFF, 0xF3, 0x77, 0xF5, |
| 2166 |
0x11, 0x31, 0x00, 0x07, 0xDD, 0xF3, 0xFF, 0xFB, |
| 2167 |
0x3A, 0x21, 0x00, 0x07, 0x95, 0x84, 0x0F, 0xF5, |
| 2168 |
0x01, 0x01, 0x18, 0x0F, 0xDF, 0xF8, 0x6A, 0x6D, |
| 2169 |
0x01, 0x01, 0x00, 0x00, 0xC8, 0xD8, 0xA7, 0x48, |
| 2170 |
0x05, 0x01, 0x00, 0x00, 0xF8, 0xAA, 0x59, 0x55 |
| 2171 |
}; |
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
ds1001::ds1001(ymfm_interface &intf, uint8_t const *instrument_data) : |
| 2184 |
opll_base(intf, (instrument_data != nullptr) ? instrument_data : s_default_instruments) |
| 2185 |
{ |
| 2186 |
}; |
| 2187 |
|
| 2188 |
|
| 2189 |
uint8_t const ds1001::s_default_instruments[] = |
| 2190 |
{ |
| 2191 |
|
| 2192 |
0x03, 0x21, 0x05, 0x06, 0xC8, 0x81, 0x42, 0x27, |
| 2193 |
0x13, 0x41, 0x14, 0x0D, 0xF8, 0xF7, 0x23, 0x12, |
| 2194 |
0x31, 0x11, 0x08, 0x08, 0xFA, 0xC2, 0x28, 0x22, |
| 2195 |
0x31, 0x61, 0x0C, 0x07, 0xF8, 0x64, 0x60, 0x27, |
| 2196 |
0x22, 0x21, 0x1E, 0x06, 0xFF, 0x76, 0x00, 0x28, |
| 2197 |
0x02, 0x01, 0x05, 0x00, 0xAC, 0xF2, 0x03, 0x02, |
| 2198 |
0x21, 0x61, 0x1D, 0x07, 0x82, 0x8F, 0x10, 0x07, |
| 2199 |
0x23, 0x21, 0x22, 0x17, 0xFF, 0x73, 0x00, 0x17, |
| 2200 |
0x15, 0x11, 0x25, 0x00, 0x41, 0x71, 0x00, 0xF1, |
| 2201 |
0x95, 0x01, 0x10, 0x0F, 0xB8, 0xAA, 0x50, 0x02, |
| 2202 |
0x17, 0xC1, 0x5E, 0x07, 0xFA, 0xF8, 0x22, 0x12, |
| 2203 |
0x71, 0x23, 0x11, 0x06, 0x65, 0x74, 0x10, 0x16, |
| 2204 |
0x01, 0x02, 0xD3, 0x05, 0xF3, 0x92, 0x83, 0xF2, |
| 2205 |
0x61, 0x63, 0x0C, 0x00, 0xA4, 0xFF, 0x30, 0x06, |
| 2206 |
0x21, 0x62, 0x0D, 0x00, 0xA1, 0xFF, 0x50, 0x08, |
| 2207 |
0x01, 0x01, 0x18, 0x0F, 0xDF, 0xF8, 0x6A, 0x6D, |
| 2208 |
0x01, 0x01, 0x00, 0x00, 0xC8, 0xD8, 0xA7, 0x48, |
| 2209 |
0x05, 0x01, 0x00, 0x00, 0xF8, 0xAA, 0x59, 0x55 |
| 2210 |
}; |
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
template class opl_registers_base<4>; |
| 2218 |
template class fm_engine_base<opl_registers_base<4>>; |
| 2219 |
|
| 2220 |
} |