Skip to content

Commit a20a5b9

Browse files
authored
Merge branch 'mamedev:master' into 260125
2 parents dd05d12 + ba5af9a commit a20a5b9

File tree

175 files changed

+5182
-3188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+5182
-3188
lines changed

3rdparty/ymfm/src/ymfm.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <cstdio>
4343
#include <cstring>
4444
#include <algorithm>
45+
#include <array>
4546
#include <memory>
4647
#include <string>
4748
#include <vector>
@@ -109,17 +110,6 @@ inline int32_t clamp(int32_t value, int32_t minval, int32_t maxval)
109110
}
110111

111112

112-
//-------------------------------------------------
113-
// array_size - return the size of an array
114-
//-------------------------------------------------
115-
116-
template<typename ArrayType, int ArraySize>
117-
constexpr uint32_t array_size(ArrayType (&array)[ArraySize])
118-
{
119-
return ArraySize;
120-
}
121-
122-
123113
//-------------------------------------------------
124114
// count_leading_zeros - return the number of
125115
// leading zeros in a 32-bit value; CPU-optimized
@@ -254,7 +244,8 @@ inline int16_t roundtrip_fp(int32_t value)
254244

255245
// apply the shift back and forth to zero out bits that are lost
256246
exponent -= 1;
257-
return (value >> exponent) << exponent;
247+
int32_t mask = (1 << exponent) - 1;
248+
return value & ~mask;
258249
}
259250

260251

@@ -350,7 +341,7 @@ class ymfm_wavfile
350341
{
351342
// create file
352343
char name[20];
353-
sprintf(name, "wavlog-%02d.wav", m_index);
344+
snprintf(&name[0], sizeof(name), "wavlog-%02d.wav", m_index);
354345
FILE *out = fopen(name, "wb");
355346

356347
// make the wav file header
@@ -483,6 +474,8 @@ class ymfm_saved_state
483474
class ymfm_engine_callbacks
484475
{
485476
public:
477+
virtual ~ymfm_engine_callbacks() = default;
478+
486479
// timer callback; called by the interface when a timer fires
487480
virtual void engine_timer_expired(uint32_t tnum) = 0;
488481

@@ -504,6 +497,8 @@ class ymfm_interface
504497
template<typename RegisterType> friend class fm_engine_base;
505498

506499
public:
500+
virtual ~ymfm_interface() = default;
501+
507502
// the following functions must be implemented by any derived classes; the
508503
// default implementations are sufficient for some minimal operation, but will
509504
// likely need to be overridden to integrate with the outside world; they are

3rdparty/ymfm/src/ymfm_fm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class fm_channel
267267
// assign operators
268268
void assign(uint32_t index, fm_operator<RegisterType> *op)
269269
{
270-
assert(index < array_size(m_op));
270+
assert(index < m_op.size());
271271
m_op[index] = op;
272272
if (op != nullptr)
273273
op->set_choffs(m_choffs);
@@ -330,7 +330,7 @@ class fm_channel
330330
uint32_t m_choffs; // channel offset in registers
331331
int16_t m_feedback[2]; // feedback memory for operator 1
332332
mutable int16_t m_feedback_in; // next input value for op 1 feedback (set in output)
333-
fm_operator<RegisterType> *m_op[4]; // up to 4 operators
333+
std::array<fm_operator<RegisterType> *, 4> m_op; // up to 4 operators
334334
RegisterType &m_regs; // direct reference to registers
335335
fm_engine_base<RegisterType> &m_owner; // reference to the owning engine
336336
};

3rdparty/ymfm/src/ymfm_fm.ipp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,12 @@ void fm_channel<RegisterType>::save_restore(ymfm_saved_state &state)
839839
template<class RegisterType>
840840
void fm_channel<RegisterType>::keyonoff(uint32_t states, keyon_type type, uint32_t chnum)
841841
{
842-
for (uint32_t opnum = 0; opnum < array_size(m_op); opnum++)
842+
for (uint32_t opnum = 0; opnum < m_op.size(); opnum++)
843843
if (m_op[opnum] != nullptr)
844844
m_op[opnum]->keyonoff(bitfield(states, opnum), type);
845845

846846
if (debug::LOG_KEYON_EVENTS && ((debug::GLOBAL_FM_CHANNEL_MASK >> chnum) & 1) != 0)
847-
for (uint32_t opnum = 0; opnum < array_size(m_op); opnum++)
847+
for (uint32_t opnum = 0; opnum < m_op.size(); opnum++)
848848
if (m_op[opnum] != nullptr)
849849
debug::log_keyon("%c%s\n", bitfield(states, opnum) ? '+' : '-', m_regs.log_keyon(m_choffs, m_op[opnum]->opoffs()).c_str());
850850
}
@@ -860,7 +860,7 @@ bool fm_channel<RegisterType>::prepare()
860860
uint32_t active_mask = 0;
861861

862862
// prepare all operators and determine if they are active
863-
for (uint32_t opnum = 0; opnum < array_size(m_op); opnum++)
863+
for (uint32_t opnum = 0; opnum < m_op.size(); opnum++)
864864
if (m_op[opnum] != nullptr)
865865
if (m_op[opnum]->prepare())
866866
active_mask |= 1 << opnum;
@@ -880,15 +880,15 @@ void fm_channel<RegisterType>::clock(uint32_t env_counter, int32_t lfo_raw_pm)
880880
m_feedback[0] = m_feedback[1];
881881
m_feedback[1] = m_feedback_in;
882882

883-
for (uint32_t opnum = 0; opnum < array_size(m_op); opnum++)
883+
for (uint32_t opnum = 0; opnum < m_op.size(); opnum++)
884884
if (m_op[opnum] != nullptr)
885885
m_op[opnum]->clock(env_counter, lfo_raw_pm);
886886

887887
/*
888888
useful temporary code for envelope debugging
889889
if (m_choffs == 0x101)
890890
{
891-
for (uint32_t opnum = 0; opnum < array_size(m_op); opnum++)
891+
for (uint32_t opnum = 0; opnum < m_op.size(); opnum++)
892892
{
893893
auto &op = *m_op[((opnum & 1) << 1) | ((opnum >> 1) & 1)];
894894
printf(" %c%03X%c%c ",
@@ -1504,6 +1504,8 @@ void fm_engine_base<RegisterType>::update_timer(uint32_t tnum, uint32_t enable,
15041504
template<class RegisterType>
15051505
void fm_engine_base<RegisterType>::engine_timer_expired(uint32_t tnum)
15061506
{
1507+
assert(tnum == 0 || tnum == 1);
1508+
15071509
// update status
15081510
if (tnum == 0 && m_regs.enable_timer_a())
15091511
set_reset_status(STATUS_TIMERA, 0);
@@ -1515,7 +1517,7 @@ void fm_engine_base<RegisterType>::engine_timer_expired(uint32_t tnum)
15151517
for (uint32_t chnum = 0; chnum < CHANNELS; chnum++)
15161518
if (bitfield(RegisterType::CSM_TRIGGER_MASK, chnum))
15171519
{
1518-
m_channel[chnum]->keyonoff(1, KEYON_CSM, chnum);
1520+
m_channel[chnum]->keyonoff(0xf, KEYON_CSM, chnum);
15191521
m_modified_channels |= 1 << chnum;
15201522
}
15211523

3rdparty/ymfm/src/ymfm_misc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,4 @@ class ym2149
9090

9191
}
9292

93-
9493
#endif // YMFM_MISC_H

3rdparty/ymfm/src/ymfm_opl.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ std::string opl_registers_base<Revision>::log_keyon(uint32_t choffs, uint32_t op
386386
uint32_t opnum = (opoffs & 31) - 2 * ((opoffs & 31) / 8) + 18 * bitfield(opoffs, 8);
387387

388388
char buffer[256];
389-
char *end = &buffer[0];
389+
int end = 0;
390390

391-
end += sprintf(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",
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",
392392
chnum, opnum,
393393
ch_block_freq(choffs),
394394
ch_feedback(choffs),
@@ -405,25 +405,25 @@ std::string opl_registers_base<Revision>::log_keyon(uint32_t choffs, uint32_t op
405405
op_eg_sustain(opoffs));
406406

407407
if (OUTPUTS > 1)
408-
end += sprintf(end, " out=%c%c%c%c",
408+
end += snprintf(&buffer[end], sizeof(buffer) - end, " out=%c%c%c%c",
409409
ch_output_0(choffs) ? 'L' : '-',
410410
ch_output_1(choffs) ? 'R' : '-',
411411
ch_output_2(choffs) ? '0' : '-',
412412
ch_output_3(choffs) ? '1' : '-');
413413
if (op_lfo_am_enable(opoffs) != 0)
414-
end += sprintf(end, " am=%u", lfo_am_depth());
414+
end += snprintf(&buffer[end], sizeof(buffer) - end, " am=%u", lfo_am_depth());
415415
if (op_lfo_pm_enable(opoffs) != 0)
416-
end += sprintf(end, " pm=%u", lfo_pm_depth());
416+
end += snprintf(&buffer[end], sizeof(buffer) - end, " pm=%u", lfo_pm_depth());
417417
if (waveform_enable() && op_waveform(opoffs) != 0)
418-
end += sprintf(end, " wf=%u", op_waveform(opoffs));
418+
end += snprintf(&buffer[end], sizeof(buffer) - end, " wf=%u", op_waveform(opoffs));
419419
if (is_rhythm(choffs))
420-
end += sprintf(end, " rhy=1");
420+
end += snprintf(&buffer[end], sizeof(buffer) - end, " rhy=1");
421421
if (DYNAMIC_OPS)
422422
{
423423
operator_mapping map;
424424
operator_map(map);
425425
if (bitfield(map.chan[chnum], 16, 8) != 0xff)
426-
end += sprintf(end, " 4op");
426+
end += snprintf(&buffer[end], sizeof(buffer) - end, " 4op");
427427
}
428428

429429
return buffer;
@@ -685,21 +685,21 @@ std::string opll_registers::log_keyon(uint32_t choffs, uint32_t opoffs)
685685
uint32_t opnum = opoffs;
686686

687687
char buffer[256];
688-
char *end = &buffer[0];
688+
int end = 0;
689689

690-
end += sprintf(end, "%u.%02u freq=%04X inst=%X fb=%u mul=%X",
690+
end += snprintf(&buffer[end], sizeof(buffer) - end, "%u.%02u freq=%04X inst=%X fb=%u mul=%X",
691691
chnum, opnum,
692692
ch_block_freq(choffs),
693693
ch_instrument(choffs),
694694
ch_feedback(choffs),
695695
op_multiple(opoffs));
696696

697697
if (bitfield(opoffs, 0) == 1 || (is_rhythm(choffs) && choffs >= 6))
698-
end += sprintf(end, " vol=%X", op_volume(opoffs));
698+
end += snprintf(&buffer[end], sizeof(buffer) - end, " vol=%X", op_volume(opoffs));
699699
else
700-
end += sprintf(end, " tl=%02X", ch_total_level(choffs));
700+
end += snprintf(&buffer[end], sizeof(buffer) - end, " tl=%02X", ch_total_level(choffs));
701701

702-
end += sprintf(end, " ksr=%u ksl=%u adr=%X/%X/%X sl=%X sus=%u/%u",
702+
end += snprintf(&buffer[end], sizeof(buffer) - end, " ksr=%u ksl=%u adr=%X/%X/%X sl=%X sus=%u/%u",
703703
op_ksr(opoffs),
704704
op_ksl(opoffs),
705705
op_attack_rate(opoffs),
@@ -710,13 +710,13 @@ std::string opll_registers::log_keyon(uint32_t choffs, uint32_t opoffs)
710710
ch_sustain(choffs));
711711

712712
if (op_lfo_am_enable(opoffs))
713-
end += sprintf(end, " am=1");
713+
end += snprintf(&buffer[end], sizeof(buffer) - end, " am=1");
714714
if (op_lfo_pm_enable(opoffs))
715-
end += sprintf(end, " pm=1");
715+
end += snprintf(&buffer[end], sizeof(buffer) - end, " pm=1");
716716
if (op_waveform(opoffs) != 0)
717-
end += sprintf(end, " wf=1");
717+
end += snprintf(&buffer[end], sizeof(buffer) - end, " wf=1");
718718
if (is_rhythm(choffs))
719-
end += sprintf(end, " rhy=1");
719+
end += snprintf(&buffer[end], sizeof(buffer) - end, " rhy=1");
720720

721721
return buffer;
722722
}
@@ -1715,9 +1715,15 @@ uint8_t ymf278b::read_status()
17151715

17161716
uint8_t ymf278b::read_data_pcm()
17171717
{
1718-
// write to FM
1718+
// read from PCM
17191719
if (bitfield(m_address, 9) != 0)
1720-
return m_pcm.read(m_address & 0xff);
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+
}
17211727
return 0;
17221728
}
17231729

3rdparty/ymfm/src/ymfm_opl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace ymfm
5252
//
5353
// System-wide registers:
5454
// 01 xxxxxxxx Test register
55-
// --x----- Enable OPL compatibility mode [OPL2 only] (1 = enable)
55+
// --x----- Enable OPL compatibility mode [OPL2 only] (0 = enable)
5656
// 02 xxxxxxxx Timer A value (4 * OPN)
5757
// 03 xxxxxxxx Timer B value
5858
// 04 x------- RST
@@ -243,7 +243,7 @@ class opl_registers_base : public fm_registers_base
243243
uint32_t op_decay_rate(uint32_t opoffs) const { return byte(0x60, 0, 4, opoffs); }
244244
uint32_t op_sustain_level(uint32_t opoffs) const { return byte(0x80, 4, 4, opoffs); }
245245
uint32_t op_release_rate(uint32_t opoffs) const { return byte(0x80, 0, 4, opoffs); }
246-
uint32_t op_waveform(uint32_t opoffs) const { return IsOpl2Plus ? byte(0xe0, 0, newflag() ? 3 : 2, opoffs) : 0; }
246+
uint32_t op_waveform(uint32_t opoffs) const { return waveform_enable() ? byte(0xe0, 0, newflag() ? 3 : 2, opoffs) : 0; }
247247

248248
protected:
249249
// return a bitfield extracted from a byte

3rdparty/ymfm/src/ymfm_opm.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ opm_registers::opm_registers() :
6060
{
6161
// waveform 0 is a sawtooth
6262
uint8_t am = index ^ 0xff;
63-
int8_t pm = int8_t(index);
63+
uint8_t pm = index;
6464
m_lfo_waveform[0][index] = am | (pm << 8);
6565

6666
// waveform 1 is a square wave
6767
am = bitfield(index, 7) ? 0 : 0xff;
68-
pm = int8_t(am ^ 0x80);
68+
pm = am ^ 0x80;
6969
m_lfo_waveform[1][index] = am | (pm << 8);
7070

7171
// waveform 2 is a triangle wave
7272
am = bitfield(index, 7) ? (index << 1) : ((index ^ 0xff) << 1);
73-
pm = int8_t(bitfield(index, 6) ? am : ~am);
73+
pm = bitfield(index, 6) ? am : ~am;
7474
m_lfo_waveform[2][index] = am | (pm << 8);
7575

7676
// waveform 3 is noise; it is filled in dynamically
@@ -330,7 +330,7 @@ uint32_t opm_registers::compute_phase_step(uint32_t choffs, uint32_t opoffs, opd
330330
if (pm_sensitivity < 6)
331331
delta += lfo_raw_pm >> (6 - pm_sensitivity);
332332
else
333-
delta += lfo_raw_pm << (pm_sensitivity - 5);
333+
delta += uint32_t(lfo_raw_pm) << (pm_sensitivity - 5);
334334
}
335335

336336
// apply delta and convert to a frequency number
@@ -354,9 +354,9 @@ std::string opm_registers::log_keyon(uint32_t choffs, uint32_t opoffs)
354354
uint32_t opnum = opoffs;
355355

356356
char buffer[256];
357-
char *end = &buffer[0];
357+
int end = 0;
358358

359-
end += sprintf(end, "%u.%02u freq=%04X dt2=%u dt=%u fb=%u alg=%X mul=%X tl=%02X ksr=%u adsr=%02X/%02X/%02X/%X sl=%X out=%c%c",
359+
end += snprintf(&buffer[end], sizeof(buffer) - end, "%u.%02u freq=%04X dt2=%u dt=%u fb=%u alg=%X mul=%X tl=%02X ksr=%u adsr=%02X/%02X/%02X/%X sl=%X out=%c%c",
360360
chnum, opnum,
361361
ch_block_freq(choffs),
362362
op_detune2(opoffs),
@@ -376,14 +376,14 @@ std::string opm_registers::log_keyon(uint32_t choffs, uint32_t opoffs)
376376

377377
bool am = (lfo_am_depth() != 0 && ch_lfo_am_sens(choffs) != 0 && op_lfo_am_enable(opoffs) != 0);
378378
if (am)
379-
end += sprintf(end, " am=%u/%02X", ch_lfo_am_sens(choffs), lfo_am_depth());
379+
end += snprintf(&buffer[end], sizeof(buffer) - end, " am=%u/%02X", ch_lfo_am_sens(choffs), lfo_am_depth());
380380
bool pm = (lfo_pm_depth() != 0 && ch_lfo_pm_sens(choffs) != 0);
381381
if (pm)
382-
end += sprintf(end, " pm=%u/%02X", ch_lfo_pm_sens(choffs), lfo_pm_depth());
382+
end += snprintf(&buffer[end], sizeof(buffer) - end, " pm=%u/%02X", ch_lfo_pm_sens(choffs), lfo_pm_depth());
383383
if (am || pm)
384-
end += sprintf(end, " lfo=%02X/%c", lfo_rate(), "WQTN"[lfo_waveform()]);
384+
end += snprintf(&buffer[end], sizeof(buffer) - end, " lfo=%02X/%c", lfo_rate(), "WQTN"[lfo_waveform()]);
385385
if (noise_enable() && opoffs == 31)
386-
end += sprintf(end, " noise=1");
386+
end += snprintf(&buffer[end], sizeof(buffer) - end, " noise=1");
387387

388388
return buffer;
389389
}

0 commit comments

Comments
 (0)