diff options
author | couriersud <couriersud@gmx.org> | 2020-01-16 22:41:39 +0100 |
---|---|---|
committer | couriersud <couriersud@gmx.org> | 2020-01-16 22:41:39 +0100 |
commit | 804e0e062728d2eb182b5ec6930c32a1362eb26c (patch) | |
tree | 3590166d39b6e15aa5d4331afef60bbdae153d5e | |
parent | 7898be84088c5d1a493ce7e494904801b00cc159 (diff) |
netlist: fix overclocking. (nw)
-rw-r--r-- | src/devices/machine/netlist.cpp | 140 | ||||
-rw-r--r-- | src/devices/machine/netlist.h | 8 |
2 files changed, 78 insertions, 70 deletions
diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 9edc5d1ba5f..9c7cdc03f72 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -180,12 +180,12 @@ public: m_cpu_device = downcast<netlist_mame_cpu_device *>(&nl->parent()); } - ATTR_COLD void reset() override + void reset() override { m_last = 0.0; } - ATTR_COLD void register_callback(netlist_mame_analog_output_device::output_delegate &&callback) + void register_callback(netlist_mame_analog_output_device::output_delegate &&callback) { m_callback.reset(new netlist_mame_analog_output_device::output_delegate(std::move(callback))); } @@ -238,12 +238,12 @@ public: m_cpu_device = downcast<netlist_mame_cpu_device *>(&nl->parent()); } - ATTR_COLD void reset() override + void reset() override { m_last = 0; } - ATTR_COLD void register_callback(netlist_mame_logic_output_device::output_delegate &&callback) + void register_callback(netlist_mame_logic_output_device::output_delegate &&callback) { m_callback.reset(new netlist_mame_logic_output_device::output_delegate(std::move(callback))); } @@ -416,7 +416,7 @@ public: , m_offset(*this, "OFFSET", 0.0) , m_buffer(nullptr) , m_bufsize(0) - , m_sample_time(netlist::netlist_time::from_hz(1)) //sufficiently big enough + , m_sample_time(netlist::netlist_time::from_hz(1)) , m_in(*this, "IN") , m_cur(0.0) , m_last_pos(0) @@ -424,36 +424,15 @@ public: { } - //static const int BUFSIZE = 2048; +protected: - ATTR_COLD void reset() override + void reset() override { m_cur = 0.0; m_last_pos = 0; m_last_buffer_time = netlist::netlist_time_ext::zero(); } - ATTR_HOT void sound_update(const netlist::netlist_time_ext &upto) - { - int pos = (upto - m_last_buffer_time()) / m_sample_time; - if (pos > m_bufsize) - throw emu_fatalerror("sound %s: pos %d exceeded bufsize %d\n", name().c_str(), pos, m_bufsize); - while (m_last_pos < pos ) - { - m_buffer[m_last_pos++] = (stream_sample_t) m_cur; - } - } - - ATTR_HOT void sound_update_fill(int samples) - { - if (samples > m_bufsize) - throw emu_fatalerror("sound %s: pos %d exceeded bufsize %d\n", name().c_str(), samples, m_bufsize); - while (m_last_pos < samples ) - { - m_buffer[m_last_pos++] = (stream_sample_t) m_cur; - } - } - NETLIB_UPDATEI() { nl_fptype val = m_in() * m_mult() + m_offset(); @@ -469,12 +448,34 @@ public: } public: - ATTR_HOT void buffer_reset(const netlist::netlist_time_ext &upto) + void buffer_reset(const netlist::netlist_time_ext &upto) { m_last_pos = 0; m_last_buffer_time = upto; } + void sound_update(const netlist::netlist_time_ext &upto) + { + int pos = (upto - m_last_buffer_time()) / m_sample_time; + if (pos > m_bufsize) + throw emu_fatalerror("sound %s: pos %d exceeded bufsize %d\n", name().c_str(), pos, m_bufsize); + while (m_last_pos < pos ) + { + m_buffer[m_last_pos++] = (stream_sample_t) m_cur; + } + } + + void sound_update_fill(int samples) + { + if (samples > m_bufsize) + throw emu_fatalerror("sound %s: pos %d exceeded bufsize %d\n", name().c_str(), samples, m_bufsize); + while (m_last_pos < samples ) + { + m_buffer[m_last_pos++] = (stream_sample_t) m_cur; + } + } + + netlist::param_int_t m_channel; netlist::param_fp_t m_mult; netlist::param_fp_t m_offset; @@ -502,7 +503,7 @@ public: NETLIB_NAME(sound_in)(netlist::netlist_state_t &anetlist, const pstring &name) : netlist::device_t(anetlist, name) - , m_inc(netlist::netlist_time::from_nsec(1)) + , m_sample_time(netlist::netlist_time::from_nsec(1)) , m_feedback(*this, "FB") // clock part , m_Q(*this, "Q") , m_pos(0) @@ -519,30 +520,14 @@ public: } } - ATTR_COLD void reset() override +protected: + void reset() override { m_pos = 0; for (auto & elem : m_channels) elem.m_buffer = nullptr; } - ATTR_COLD void resolve(std::uint32_t clock) - { - m_pos = 0; - m_inc = netlist::netlist_time::from_hz(clock); - - for (int i = 0; i < MAX_INPUT_CHANNELS; i++) - { - if ((*m_channels[i].m_param_name)() != pstring("")) - { - if (i != m_num_channels) - state().log().fatal("sound input numbering has to be sequential!"); - m_num_channels++; - m_channels[i].m_param = dynamic_cast<netlist::param_fp_t *>(state().setup().find_param((*m_channels[i].m_param_name)(), true)); - } - } - } - NETLIB_UPDATEI() { if (m_pos < m_samples) @@ -564,14 +549,33 @@ public: } m_pos++; - m_Q.net().toggle_and_push_to_queue(m_inc); + m_Q.net().toggle_and_push_to_queue(m_sample_time); } public: + void resolve(netlist::netlist_time sample_time) + { + m_pos = 0; + m_sample_time = sample_time; + + for (int i = 0; i < MAX_INPUT_CHANNELS; i++) + { + if ((*m_channels[i].m_param_name)() != pstring("")) + { + if (i != m_num_channels) + state().log().fatal("sound input numbering has to be sequential!"); + m_num_channels++; + m_channels[i].m_param = dynamic_cast<netlist::param_fp_t *>(state().setup().find_param((*m_channels[i].m_param_name)(), true)); + } + } + } + template <typename S> - ATTR_HOT void buffer_reset(int num_samples, S **inputs) + void buffer_reset(netlist::netlist_time sample_time, int num_samples, S **inputs) { m_samples = num_samples; + m_sample_time = sample_time; + m_pos = 0; for (int i=0; i < m_num_channels; i++) { @@ -592,7 +596,7 @@ public: private: channel m_channels[MAX_INPUT_CHANNELS]; - netlist::netlist_time m_inc; + netlist::netlist_time m_sample_time; netlist::logic_input_t m_feedback; netlist::logic_output_t m_Q; @@ -1176,16 +1180,16 @@ void netlist_mame_device::device_start() save_state(); m_old = netlist::netlist_time_ext::zero(); - m_rem = netlist::netlist_time::zero(); + m_rem = netlist::netlist_time_ext::zero(); LOGDEVCALLS("device_start exit\n"); } void netlist_mame_device::device_clock_changed() { - m_div = static_cast<netlist::netlist_time>( - (netlist::netlist_time::resolution() << MDIV_SHIFT) / clock()); - printf("m_div %d\n", (int) m_div.as_raw()); + m_div = static_cast<netlist::netlist_time_ext>( + (netlist::netlist_time_ext::resolution() << MDIV_SHIFT) / clock()); + //printf("m_div %d\n", (int) m_div.as_raw()); netlist().log().debug("Setting clock {1} and divisor {2}\n", clock(), m_div.as_double()); } @@ -1194,7 +1198,7 @@ void netlist_mame_device::device_reset() { LOGDEVCALLS("device_reset\n"); m_old = netlist::netlist_time_ext::zero(); - m_rem = netlist::netlist_time::zero(); + m_rem = netlist::netlist_time_ext::zero(); netlist().exec().reset(); } @@ -1204,7 +1208,7 @@ void netlist_mame_device::device_stop() netlist().exec().stop(); } -ATTR_COLD void netlist_mame_device::device_post_load() +void netlist_mame_device::device_post_load() { LOGDEVCALLS("device_post_load\n"); @@ -1212,7 +1216,7 @@ ATTR_COLD void netlist_mame_device::device_post_load() netlist().rebuild_lists(); } -ATTR_COLD void netlist_mame_device::device_pre_save() +void netlist_mame_device::device_pre_save() { LOGDEVCALLS("device_pre_save\n"); @@ -1235,7 +1239,7 @@ void netlist_mame_device::check_mame_abort_slice() noexcept netlist().exec().abort_current_queue_slice(); } -ATTR_COLD void netlist_mame_device::save_state() +void netlist_mame_device::save_state() { for (auto const & s : netlist().run_state_manager().save_list()) { @@ -1323,17 +1327,17 @@ void netlist_mame_cpu_device::nl_register_devices(netlist::setup_t &lsetup) cons lsetup.factory().register_device<nld_analog_callback>( "NETDEV_CALLBACK", "nld_analog_callback", "-"); } -ATTR_COLD uint64_t netlist_mame_cpu_device::execute_clocks_to_cycles(uint64_t clocks) const noexcept +uint64_t netlist_mame_cpu_device::execute_clocks_to_cycles(uint64_t clocks) const noexcept { return clocks; } -ATTR_COLD uint64_t netlist_mame_cpu_device::execute_cycles_to_clocks(uint64_t cycles) const noexcept +uint64_t netlist_mame_cpu_device::execute_cycles_to_clocks(uint64_t cycles) const noexcept { return cycles; } -ATTR_HOT void netlist_mame_cpu_device::execute_run() +void netlist_mame_cpu_device::execute_run() { //m_ppc = m_pc; // copy PC to previous PC if (debugger_enabled()) @@ -1343,13 +1347,13 @@ ATTR_HOT void netlist_mame_cpu_device::execute_run() m_genPC++; m_genPC &= 255; debugger_instruction_hook(m_genPC); - netlist().exec().process_queue(nltime_from_clocks(1)); + netlist().exec().process_queue(nltime_ext_from_clocks(1)); update_icount(netlist().exec().time()); } } else { - netlist().exec().process_queue(nltime_from_clocks(m_icount)); + netlist().exec().process_queue(nltime_ext_from_clocks(m_icount)); update_icount(netlist().exec().time()); } } @@ -1463,7 +1467,7 @@ void netlist_mame_sound_device::device_start() if (indevs.size() == 1) { m_in = indevs[0]; - m_in->resolve(clock()); + m_in->resolve(nltime_from_clocks(1)); } /* initialize the stream(s) */ @@ -1484,16 +1488,16 @@ void netlist_mame_sound_device::sound_stream_update(sound_stream &stream, stream { e.second->m_buffer = outputs[e.first]; e.second->m_bufsize = samples; + e.second->m_sample_time = nltime_from_clocks(1); } - if (m_in) { - m_in->buffer_reset(samples, inputs); + m_in->buffer_reset(nltime_from_clocks(1), samples, inputs); } auto cur(netlist().exec().time()); - const auto delta(nltime_from_clocks(samples)); + const auto delta(nltime_ext_from_clocks(samples)); netlist().exec().process_queue(delta); cur += delta; diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index 90ccc84493f..bef8a524645 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -84,12 +84,16 @@ public: static constexpr const unsigned MDIV_SHIFT = 16; - netlist::netlist_time nltime_from_clocks(unsigned c) const noexcept + netlist::netlist_time_ext nltime_ext_from_clocks(unsigned c) const noexcept { - //return (m_div * c + netlist::netlist_time::from_raw((1 << MDIV_SHIFT) - 1)).shr(MDIV_SHIFT); return (m_div * c).shr(MDIV_SHIFT); } + netlist::netlist_time nltime_from_clocks(unsigned c) const noexcept + { + return static_cast<netlist::netlist_time>((m_div * c).shr(MDIV_SHIFT)); + } + protected: netlist_mame_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); |