summaryrefslogtreecommitdiffstats
path: root/src/devices/machine/netlist.cpp
diff options
context:
space:
mode:
authorGravatarGravatar Vas Crabb <vas@vastheman.com>2019-03-26 11:13:37 +1100
committerGravatarGravatar Vas Crabb <vas@vastheman.com>2019-03-26 11:13:37 +1100
commit97b67170277437131adf6ed4d60139c172529e4f (patch) (github)
tree7a5cbf608f191075f1612b1af15832c206a3fe2d /src/devices/machine/netlist.cpp
parentb380514764cf857469bae61c11143a19f79a74c5 (diff)
downloadmame-97b67170277437131adf6ed4d60139c172529e4f.tar.bz2
mame-97b67170277437131adf6ed4d60139c172529e4f.zip
(nw) Clean up the mess on master
This effectively reverts b380514764cf857469bae61c11143a19f79a74c5 and c24473ddff715ecec2e258a6eb38960cf8c8e98e, restoring the state at 598cd5227223c3b04ca31f0dbc1981256d9ea3ff. Before pushing, please check that what you're about to push is sane. Check your local commit log and ensure there isn't anything out-of-place before pushing to mainline. When things like this happen, it wastes everyone's time. I really don't need this in a week when real work™ is busting my balls and I'm behind where I want to be with preparing for MAME release.
Diffstat (limited to 'src/devices/machine/netlist.cpp')
-rw-r--r--src/devices/machine/netlist.cpp375
1 files changed, 201 insertions, 174 deletions
diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp
index 648d435ace8..3e7580be5b9 100644
--- a/src/devices/machine/netlist.cpp
+++ b/src/devices/machine/netlist.cpp
@@ -49,21 +49,16 @@ DEFINE_DEVICE_TYPE(NETLIST_STREAM_OUTPUT, netlist_mame_stream_output_device, "nl
// Special netlist extension devices ....
// ----------------------------------------------------------------------------------------
-class netlist_mame_device::netlist_mame_t : public netlist::netlist_t
+class netlist_mame_device::netlist_mame_callbacks_t : public netlist::callbacks_t
{
public:
- netlist_mame_t(netlist_mame_device &parent, const pstring &aname)
- : netlist::netlist_t(aname)
+ netlist_mame_callbacks_t(netlist_mame_device &parent)
+ : netlist::callbacks_t()
, m_parent(parent)
{
}
- running_machine &machine() { return m_parent.machine(); }
-
-
- netlist_mame_device &parent() { return m_parent; }
-
protected:
void vlog(const plib::plog_level &l, const pstring &ls) const override
{
@@ -95,6 +90,24 @@ private:
};
+class netlist_mame_device::netlist_mame_t : public netlist::netlist_t
+{
+public:
+
+ netlist_mame_t(netlist_mame_device &parent, const pstring &aname)
+ : netlist::netlist_t(aname, plib::make_unique<netlist_mame_device::netlist_mame_callbacks_t>(parent))
+ , m_parent(parent)
+ {
+ }
+
+ running_machine &machine() { return m_parent.machine(); }
+ netlist_mame_device &parent() { return m_parent; }
+
+private:
+ netlist_mame_device &m_parent;
+};
+
+
namespace {
// ----------------------------------------------------------------------------------------
@@ -104,13 +117,13 @@ namespace {
class NETLIB_NAME(analog_callback) : public netlist::device_t
{
public:
- NETLIB_NAME(analog_callback)(netlist::netlist_t &anetlist, const pstring &name)
+ NETLIB_NAME(analog_callback)(netlist::netlist_state_t &anetlist, const pstring &name)
: device_t(anetlist, name)
, m_in(*this, "IN")
, m_cpu_device(nullptr)
, m_last(*this, "m_last", 0)
{
- m_cpu_device = downcast<netlist_mame_cpu_device *>(&downcast<netlist_mame_device::netlist_mame_t &>(netlist()).parent());
+ m_cpu_device = downcast<netlist_mame_cpu_device *>(&static_cast<netlist_mame_device::netlist_mame_t &>(exec()).parent());
}
ATTR_COLD void reset() override
@@ -131,7 +144,7 @@ public:
// avoid calls due to noise
if (std::fabs(cur - m_last) > 1e-6)
{
- m_cpu_device->update_time_x();
+ m_cpu_device->update_icount(exec().time());
m_callback(cur, m_cpu_device->local_time());
m_cpu_device->check_mame_abort_slice();
m_last = cur;
@@ -152,13 +165,13 @@ private:
class NETLIB_NAME(logic_callback) : public netlist::device_t
{
public:
- NETLIB_NAME(logic_callback)(netlist::netlist_t &anetlist, const pstring &name)
+ NETLIB_NAME(logic_callback)(netlist::netlist_state_t &anetlist, const pstring &name)
: device_t(anetlist, name)
, m_in(*this, "IN")
, m_cpu_device(nullptr)
, m_last(*this, "m_last", 0)
{
- m_cpu_device = downcast<netlist_mame_cpu_device *>(&downcast<netlist_mame_device::netlist_mame_t &>(netlist()).parent());
+ m_cpu_device = downcast<netlist_mame_cpu_device *>(&static_cast<netlist_mame_device::netlist_mame_t &>(exec()).parent());
}
ATTR_COLD void reset() override
@@ -173,13 +186,13 @@ public:
NETLIB_UPDATEI()
{
- netlist_sig_t cur = m_in();
+ netlist::netlist_sig_t cur = m_in();
// FIXME: make this a parameter
// avoid calls due to noise
if (cur != m_last)
{
- m_cpu_device->update_time_x();
+ m_cpu_device->update_icount(exec().time());
m_callback(cur, m_cpu_device->local_time());
m_cpu_device->check_mame_abort_slice();
m_last = cur;
@@ -190,9 +203,10 @@ private:
netlist::logic_input_t m_in;
netlist_mame_logic_output_device::output_delegate m_callback;
netlist_mame_cpu_device *m_cpu_device;
- netlist::state_var<netlist_sig_t> m_last;
+ netlist::state_var<netlist::netlist_sig_t> m_last;
};
+
// ----------------------------------------------------------------------------------------
// Extensions to interface netlist with MAME code ....
// ----------------------------------------------------------------------------------------
@@ -200,22 +214,26 @@ private:
class netlist_source_memregion_t : public netlist::source_t
{
public:
- netlist_source_memregion_t(netlist::setup_t &setup, pstring name)
- : netlist::source_t(setup), m_name(name)
+ netlist_source_memregion_t(device_t &dev, pstring name)
+ : netlist::source_t(), m_dev(dev), m_name(name)
{
}
- virtual std::unique_ptr<plib::pistream> stream(const pstring &name) override;
+ virtual plib::unique_ptr<plib::pistream> stream(const pstring &name) override;
private:
+ device_t &m_dev;
pstring m_name;
};
class netlist_data_memregions_t : public netlist::source_t
{
public:
- netlist_data_memregions_t(netlist::setup_t &setup);
+ netlist_data_memregions_t(device_t &dev);
- virtual std::unique_ptr<plib::pistream> stream(const pstring &name) override;
+ virtual plib::unique_ptr<plib::pistream> stream(const pstring &name) override;
+
+private:
+ device_t &m_dev;
};
@@ -223,30 +241,31 @@ public:
// memregion source support
// ----------------------------------------------------------------------------------------
-std::unique_ptr<plib::pistream> netlist_source_memregion_t::stream(const pstring &name)
+plib::unique_ptr<plib::pistream> netlist_source_memregion_t::stream(const pstring &name)
{
- memory_region *mem = downcast<netlist_mame_device::netlist_mame_t &>(setup().netlist()).machine().root_device().memregion(m_name.c_str());
- return plib::make_unique_base<plib::pistream, plib::pimemstream>(mem->base(), mem->bytes());
+ //memory_region *mem = static_cast<netlist_mame_device::netlist_mame_t &>(setup().setup().exec()).machine().root_device().memregion(m_name.c_str());
+ memory_region *mem = m_dev.machine().root_device().memregion(m_name.c_str());
+ return plib::make_unique<plib::pimemstream>(mem->base(), mem->bytes());
}
-netlist_data_memregions_t::netlist_data_memregions_t(netlist::setup_t &setup)
- : netlist::source_t(setup, netlist::source_t::DATA)
+netlist_data_memregions_t::netlist_data_memregions_t(device_t &dev)
+ : netlist::source_t(netlist::source_t::DATA), m_dev(dev)
{
}
-std::unique_ptr<plib::pistream> netlist_data_memregions_t::stream(const pstring &name)
+plib::unique_ptr<plib::pistream> netlist_data_memregions_t::stream(const pstring &name)
{
- memory_region *mem = downcast<netlist_mame_device::netlist_mame_t &>(setup().netlist()).parent().memregion(name.c_str());
- //memory_region *mem = downcast<netlist_mame_t &>(setup().netlist()).machine().root_device().memregion(name.c_str());
+ //memory_region *mem = static_cast<netlist_mame_device::netlist_mame_t &>(setup().setup().exec()).parent().memregion(name.c_str());
+ memory_region *mem = m_dev.memregion(name.c_str());
if (mem != nullptr)
{
- return plib::make_unique_base<plib::pistream, plib::pimemstream>(mem->base(), mem->bytes());
+ return plib::make_unique<plib::pimemstream>(mem->base(), mem->bytes());
}
else
{
// This should be the last data provider being called - last resort
fatalerror("data named %s not found in device rom regions\n", name.c_str());
- return std::unique_ptr<plib::pistream>(nullptr);
+ return plib::unique_ptr<plib::pistream>(nullptr);
}
}
@@ -261,44 +280,55 @@ std::unique_ptr<plib::pistream> netlist_data_memregions_t::stream(const pstring
class NETLIB_NAME(sound_out) : public netlist::device_t
{
public:
- NETLIB_NAME(sound_out)(netlist::netlist_t &anetlist, const pstring &name)
+ NETLIB_NAME(sound_out)(netlist::netlist_state_t &anetlist, const pstring &name)
: netlist::device_t(anetlist, name)
, m_channel(*this, "CHAN", 0)
, m_mult(*this, "MULT", 1000.0)
, m_offset(*this, "OFFSET", 0.0)
, m_buffer(nullptr)
- , m_sample(netlist::netlist_time::from_hz(1)) //sufficiently big enough
+ , m_bufsize(0)
+ , m_sample_time(netlist::netlist_time::from_hz(1)) //sufficiently big enough
, m_in(*this, "IN")
, m_cur(0.0)
, m_last_pos(0)
- , m_last_buffer(*this, "m_last_buffer", netlist::netlist_time::zero())
+ , m_last_buffer_time(*this, "m_last_buffer", netlist::netlist_time::zero())
{
}
- static const int BUFSIZE = 2048;
+ //static const int BUFSIZE = 2048;
ATTR_COLD void reset() override
{
m_cur = 0.0;
m_last_pos = 0;
- m_last_buffer = netlist::netlist_time::zero();
+ m_last_buffer_time = netlist::netlist_time::zero();
}
ATTR_HOT void sound_update(const netlist::netlist_time &upto)
{
- int pos = (upto - m_last_buffer) / m_sample;
- if (pos >= BUFSIZE)
- netlist().log().fatal("sound {1}: exceeded BUFSIZE\n", name().c_str());
+ 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_double val = m_in() * m_mult() + m_offset();
- sound_update(netlist().time());
+ sound_update(exec().time());
/* ignore spikes */
if (std::abs(val) < 32767.0)
m_cur = val;
@@ -313,21 +343,22 @@ public:
ATTR_HOT void buffer_reset(const netlist::netlist_time &upto)
{
m_last_pos = 0;
- m_last_buffer = upto;
- m_cur = 0.0;
+ m_last_buffer_time = upto;
}
netlist::param_int_t m_channel;
netlist::param_double_t m_mult;
netlist::param_double_t m_offset;
stream_sample_t *m_buffer;
- netlist::netlist_time m_sample;
+ int m_bufsize;
+
+ netlist::netlist_time m_sample_time;
private:
netlist::analog_input_t m_in;
double m_cur;
int m_last_pos;
- netlist::state_var<netlist::netlist_time> m_last_buffer;
+ netlist::state_var<netlist::netlist_time> m_last_buffer_time;
};
// ----------------------------------------------------------------------------------------
@@ -337,58 +368,57 @@ private:
class NETLIB_NAME(sound_in) : public netlist::device_t
{
public:
- NETLIB_NAME(sound_in)(netlist::netlist_t &anetlist, const pstring &name)
+
+ static const int MAX_INPUT_CHANNELS = 16;
+
+ 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_feedback(*this, "FB") // clock part
, m_Q(*this, "Q")
, m_pos(0)
- , m_num_channel(0)
+ , m_num_channels(0)
{
connect(m_feedback, m_Q);
- m_inc = netlist::netlist_time::from_nsec(1);
-
for (int i = 0; i < MAX_INPUT_CHANNELS; i++)
{
- m_param_name[i] = std::make_unique<netlist::param_str_t>(*this, plib::pfmt("CHAN{1}")(i), "");
- m_param_mult[i] = std::make_unique<netlist::param_double_t>(*this, plib::pfmt("MULT{1}")(i), 1.0);
- m_param_offset[i] = std::make_unique<netlist::param_double_t>(*this, plib::pfmt("OFFSET{1}")(i), 0.0);
+ m_channels[i].m_param_name = netlist::pool().make_poolptr<netlist::param_str_t>(*this, plib::pfmt("CHAN{1}")(i), "");
+ m_channels[i].m_param_mult = netlist::pool().make_poolptr<netlist::param_double_t>(*this, plib::pfmt("MULT{1}")(i), 1.0);
+ m_channels[i].m_param_offset = netlist::pool().make_poolptr<netlist::param_double_t>(*this, plib::pfmt("OFFSET{1}")(i), 0.0);
}
}
- static const int MAX_INPUT_CHANNELS = 10;
-
ATTR_COLD void reset() override
{
m_pos = 0;
- for (auto & elem : m_buffer)
- elem = nullptr;
+ for (auto & elem : m_channels)
+ elem.m_buffer = nullptr;
}
- ATTR_COLD int resolve()
+ ATTR_COLD void resolve()
{
m_pos = 0;
for (int i = 0; i < MAX_INPUT_CHANNELS; i++)
{
- if ((*m_param_name[i])() != pstring(""))
+ if ((*m_channels[i].m_param_name)() != pstring(""))
{
- if (i != m_num_channel)
- netlist().log().fatal("sound input numbering has to be sequential!");
- m_num_channel++;
- m_param[i] = dynamic_cast<netlist::param_double_t *>(setup().find_param((*m_param_name[i])(), true));
+ 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_double_t *>(setup().find_param((*m_channels[i].m_param_name)(), true));
}
}
- return m_num_channel;
}
NETLIB_UPDATEI()
{
- for (int i=0; i<m_num_channel; i++)
+ for (int i=0; i<m_num_channels; i++)
{
- if (m_buffer[i] == nullptr)
+ if (m_channels[i].m_buffer == nullptr)
break; // stop, called outside of stream_update
- const nl_double v = m_buffer[i][m_pos];
- m_param[i]->setTo(v * (*m_param_mult[i])() + (*m_param_offset[i])());
+ const nl_double v = m_channels[i].m_buffer[m_pos];
+ m_channels[i].m_param->setTo(v * (*m_channels[i].m_param_mult)() + (*m_channels[i].m_param_offset)());
}
m_pos++;
m_Q.net().toggle_and_push_to_queue(m_inc);
@@ -400,19 +430,25 @@ public:
m_pos = 0;
}
- std::unique_ptr<netlist::param_str_t> m_param_name[MAX_INPUT_CHANNELS];
- netlist::param_double_t *m_param[MAX_INPUT_CHANNELS];
- stream_sample_t *m_buffer[MAX_INPUT_CHANNELS];
- std::unique_ptr<netlist::param_double_t> m_param_mult[MAX_INPUT_CHANNELS];
- std::unique_ptr<netlist::param_double_t> m_param_offset[MAX_INPUT_CHANNELS];
+ struct channel
+ {
+ netlist::pool_owned_ptr<netlist::param_str_t> m_param_name;
+ netlist::param_double_t *m_param;
+ stream_sample_t *m_buffer;
+ netlist::pool_owned_ptr<netlist::param_double_t> m_param_mult;
+ netlist::pool_owned_ptr<netlist::param_double_t> m_param_offset;
+ };
+ channel m_channels[MAX_INPUT_CHANNELS];
netlist::netlist_time m_inc;
+ int num_channels() { return m_num_channels; }
+
private:
netlist::logic_input_t m_feedback;
netlist::logic_output_t m_Q;
int m_pos;
- int m_num_channel;
+ int m_num_channels;
};
@@ -431,26 +467,25 @@ private:
netlist::setup_t &netlist_mame_device::setup()
{
- return m_netlist->setup();
+ return m_netlist->nlstate().setup();
}
-void netlist_mame_device::register_memregion_source(netlist::setup_t &setup, const char *name)
+void netlist_mame_device::register_memregion_source(netlist::nlparse_t &setup, device_t &dev, const char *name)
{
- setup.register_source(plib::make_unique_base<netlist::source_t, netlist_source_memregion_t>(setup, pstring(name, pstring::UTF8)));
+ setup.register_source(plib::make_unique<netlist_source_memregion_t>(dev, pstring(name)));
}
void netlist_mame_analog_input_device::write(const double val)
{
- if (is_sound_device())
- {
- update_to_current_time();
- m_param->setTo(val * m_mult + m_offset);
- }
- else
- {
- // FIXME: use device timer ....
- m_param->setTo(val * m_mult + m_offset);
- }
+ m_value_for_device_timer = val * m_mult + m_offset;
+ if (m_value_for_device_timer != (*m_param)())
+ synchronize(0, 0, &m_value_for_device_timer);
+}
+
+void netlist_mame_analog_input_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
+{
+ update_to_current_time();
+ m_param->setTo(*((double *) ptr));
}
void netlist_mame_int_input_device::write(const uint32_t val)
@@ -469,15 +504,13 @@ void netlist_mame_logic_input_device::write(const uint32_t val)
void netlist_mame_int_input_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
- if (is_sound_device())
- update_to_current_time();
+ update_to_current_time();
m_param->setTo(param);
}
void netlist_mame_logic_input_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
- if (is_sound_device())
- update_to_current_time();
+ update_to_current_time();
m_param->setTo(param);
}
@@ -500,7 +533,7 @@ void netlist_mame_cpu_device::state_string_export(const device_state_entry &entr
if (entry.index() & 1)
str = string_format("%10.6f", *((double *)entry.dataptr()));
else
- str = string_format("%d", *((netlist_sig_t *)entry.dataptr()));
+ str = string_format("%d", *((netlist::netlist_sig_t *)entry.dataptr()));
}
}
@@ -528,7 +561,7 @@ netlist_mame_analog_input_device::netlist_mame_analog_input_device(const machine
void netlist_mame_analog_input_device::device_start()
{
LOGDEVCALLS("start\n");
- netlist::param_t *p = this->nl_owner().setup().find_param(pstring(m_param_name, pstring::UTF8));
+ netlist::param_t *p = this->nl_owner().setup().find_param(pstring(m_param_name));
m_param = dynamic_cast<netlist::param_double_t *>(p);
if (m_param == nullptr)
{
@@ -560,16 +593,17 @@ void netlist_mame_analog_output_device::set_params(const char *in_name, output_d
m_delegate = std::move(adelegate);
}
-void netlist_mame_analog_output_device::custom_netlist_additions(netlist::setup_t &setup)
+void netlist_mame_analog_output_device::custom_netlist_additions(netlist::netlist_state_t &nlstate)
{
- const pstring pin(m_in, pstring::UTF8);
+ const pstring pin(m_in);
pstring dname = pstring("OUT_") + pin;
+ pstring dfqn = nlstate.setup().build_fqn(dname);
m_delegate.bind_relative_to(owner()->machine().root_device());
- plib::owned_ptr<netlist::device_t> dev = plib::owned_ptr<netlist::device_t>::Create<NETLIB_NAME(analog_callback)>(setup.netlist(), setup.build_fqn(dname));
+ auto dev = netlist::pool().make_poolptr<NETLIB_NAME(analog_callback)>(nlstate, dfqn);
static_cast<NETLIB_NAME(analog_callback) *>(dev.get())->register_callback(std::move(m_delegate));
- setup.netlist().register_dev(std::move(dev));
- setup.register_link(dname + ".IN", pin);
+ nlstate.add_dev(dfqn, std::move(dev));
+ nlstate.setup().register_link(dname + ".IN", pin);
}
void netlist_mame_analog_output_device::device_start()
@@ -595,16 +629,18 @@ void netlist_mame_logic_output_device::set_params(const char *in_name, output_de
m_delegate = std::move(adelegate);
}
-void netlist_mame_logic_output_device::custom_netlist_additions(netlist::setup_t &setup)
+void netlist_mame_logic_output_device::custom_netlist_additions(netlist::netlist_state_t &nlstate)
{
- pstring pin(m_in, pstring::UTF8);
+ pstring pin(m_in);
pstring dname = "OUT_" + pin;
+ pstring dfqn = nlstate.setup().build_fqn(dname);
+
m_delegate.bind_relative_to(owner()->machine().root_device());
- plib::owned_ptr<netlist::device_t> dev = plib::owned_ptr<netlist::device_t>::Create<NETLIB_NAME(logic_callback)>(setup.netlist(), setup.build_fqn(dname));
+ auto dev = netlist::pool().make_poolptr<NETLIB_NAME(logic_callback)>(nlstate, dfqn);
static_cast<NETLIB_NAME(logic_callback) *>(dev.get())->register_callback(std::move(m_delegate));
- setup.netlist().register_dev(std::move(dev));
- setup.register_link(dname + ".IN", pin);
+ nlstate.add_dev(dfqn, std::move(dev));
+ nlstate.setup().register_link(dname + ".IN", pin);
}
void netlist_mame_logic_output_device::device_start()
@@ -638,7 +674,7 @@ void netlist_mame_int_input_device::set_params(const char *param_name, const uin
void netlist_mame_int_input_device::device_start()
{
LOGDEVCALLS("start\n");
- netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name, pstring::UTF8));
+ netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name));
m_param = dynamic_cast<netlist::param_int_t *>(p);
if (m_param == nullptr)
{
@@ -669,7 +705,7 @@ void netlist_mame_logic_input_device::set_params(const char *param_name, const u
void netlist_mame_logic_input_device::device_start()
{
LOGDEVCALLS("start\n");
- netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name, pstring::UTF8));
+ netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name));
m_param = dynamic_cast<netlist::param_logic_t *>(p);
if (m_param == nullptr)
{
@@ -700,7 +736,7 @@ void netlist_mame_ram_pointer_device::set_params(const char *param_name)
void netlist_mame_ram_pointer_device::device_start()
{
LOGDEVCALLS("start\n");
- netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name, pstring::UTF8));
+ netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name));
m_param = dynamic_cast<netlist::param_ptr_t *>(p);
if (m_param == nullptr)
{
@@ -733,17 +769,17 @@ void netlist_mame_stream_input_device::device_start()
LOGDEVCALLS("start\n");
}
-void netlist_mame_stream_input_device::custom_netlist_additions(netlist::setup_t &setup)
+void netlist_mame_stream_input_device::custom_netlist_additions(netlist::netlist_state_t &nlstate)
{
- if (!setup.device_exists("STREAM_INPUT"))
- setup.register_dev("NETDEV_SOUND_IN", "STREAM_INPUT");
+ if (!nlstate.setup().device_exists("STREAM_INPUT"))
+ nlstate.setup().register_dev("NETDEV_SOUND_IN", "STREAM_INPUT");
pstring sparam = plib::pfmt("STREAM_INPUT.CHAN{1}")(m_channel);
- setup.register_param(sparam, pstring(m_param_name, pstring::UTF8));
+ nlstate.setup().register_param(sparam, pstring(m_param_name));
sparam = plib::pfmt("STREAM_INPUT.MULT{1}")(m_channel);
- setup.register_param(sparam, m_mult);
+ nlstate.setup().register_param(sparam, m_mult);
sparam = plib::pfmt("STREAM_INPUT.OFFSET{1}")(m_channel);
- setup.register_param(sparam, m_offset);
+ nlstate.setup().register_param(sparam, m_offset);
}
// ----------------------------------------------------------------------------------------
@@ -769,18 +805,18 @@ void netlist_mame_stream_output_device::device_start()
LOGDEVCALLS("start\n");
}
-void netlist_mame_stream_output_device::custom_netlist_additions(netlist::setup_t &setup)
+void netlist_mame_stream_output_device::custom_netlist_additions(netlist::netlist_state_t &nlstate)
{
//NETLIB_NAME(sound_out) *snd_out;
pstring sname = plib::pfmt("STREAM_OUT_{1}")(m_channel);
//snd_out = dynamic_cast<NETLIB_NAME(sound_out) *>(setup.register_dev("nld_sound_out", sname));
- setup.register_dev("NETDEV_SOUND_OUT", sname);
+ nlstate.setup().register_dev("NETDEV_SOUND_OUT", sname);
- setup.register_param(sname + ".CHAN" , m_channel);
- setup.register_param(sname + ".MULT", m_mult);
- setup.register_param(sname + ".OFFSET", m_offset);
- setup.register_link(sname + ".IN", pstring(m_out_name, pstring::UTF8));
+ nlstate.setup().register_param(sname + ".CHAN" , m_channel);
+ nlstate.setup().register_param(sname + ".MULT", m_mult);
+ nlstate.setup().register_param(sname + ".OFFSET", m_offset);
+ nlstate.setup().register_link(sname + ".IN", pstring(m_out_name));
}
@@ -797,7 +833,6 @@ netlist_mame_device::netlist_mame_device(const machine_config &mconfig, device_t
: device_t(mconfig, type, tag, owner, clock)
, m_icount(0)
, m_old(netlist::netlist_time::zero())
- , m_netlist(nullptr)
, m_setup_func(nullptr)
{
}
@@ -807,12 +842,6 @@ netlist_mame_device::~netlist_mame_device()
LOGDEVCALLS("~netlist_mame_device\n");
}
-void netlist_mame_device::set_constructor(void (*setup_func)(netlist::setup_t &))
-{
- if (LOG_DEV_CALLS) logerror("set_constructor\n");
- m_setup_func = setup_func;
-}
-
void netlist_mame_device::device_config_complete()
{
LOGDEVCALLS("device_config_complete %s\n", this->mconfig().gamedrv().name);
@@ -830,7 +859,7 @@ void netlist_mame_device::device_start()
//printf("clock is %d\n", clock());
- m_netlist = global_alloc(netlist_mame_t(*this, "netlist"));
+ m_netlist = netlist::pool().make_poolptr<netlist_mame_t>(*this, "netlist");
// register additional devices
@@ -843,12 +872,12 @@ void netlist_mame_device::device_start()
if( sdev != nullptr )
{
LOGDEVCALLS("Preparse subdevice %s/%s\n", d.name(), d.shortname());
- sdev->pre_parse_action(setup());
+ sdev->pre_parse_action(m_netlist->nlstate());
}
}
/* add default data provider for roms */
- setup().register_source(plib::make_unique_base<netlist::source_t, netlist_data_memregions_t>(setup()));
+ setup().register_source(plib::make_unique<netlist_data_memregions_t>(*this));
m_setup_func(setup());
@@ -859,15 +888,15 @@ void netlist_mame_device::device_start()
if( sdev != nullptr )
{
LOGDEVCALLS("Found subdevice %s/%s\n", d.name(), d.shortname());
- sdev->custom_netlist_additions(setup());
+ sdev->custom_netlist_additions(m_netlist->nlstate());
}
}
- netlist().start();
+ setup().prepare_to_run();
- netlist().save(*this, m_rem, "m_rem");
- netlist().save(*this, m_div, "m_div");
- netlist().save(*this, m_old, "m_old");
+ netlist().nlstate().save(*this, m_rem, this->name(), "m_rem");
+ netlist().nlstate().save(*this, m_div, this->name(), "m_div");
+ netlist().nlstate().save(*this, m_old, this->name(), "m_old");
save_state();
@@ -896,29 +925,26 @@ void netlist_mame_device::device_stop()
{
LOGDEVCALLS("device_stop\n");
netlist().stop();
-
- global_free(m_netlist);
- m_netlist = nullptr;
}
ATTR_COLD void netlist_mame_device::device_post_load()
{
LOGDEVCALLS("device_post_load\n");
- netlist().state().post_load();
- netlist().rebuild_lists();
+ netlist().run_state_manager().post_load();
+ netlist().nlstate().rebuild_lists();
}
ATTR_COLD void netlist_mame_device::device_pre_save()
{
LOGDEVCALLS("device_pre_save\n");
- netlist().state().pre_save();
+ netlist().run_state_manager().pre_save();
}
-void netlist_mame_device::update_time_x()
+void netlist_mame_device::update_icount(netlist::netlist_time time)
{
- const netlist::netlist_time newt(netlist().time());
+ const netlist::netlist_time newt(time);
const netlist::netlist_time delta(newt - m_old + m_rem);
const uint64_t d = delta / m_div;
m_old = newt;
@@ -934,7 +960,7 @@ void netlist_mame_device::check_mame_abort_slice()
ATTR_COLD void netlist_mame_device::save_state()
{
- for (auto const & s : netlist().state().save_list())
+ for (auto const & s : netlist().run_state_manager().save_list())
{
netlist().log().debug("saving state for {1}\n", s->m_name.c_str());
if (s->m_dt.is_float)
@@ -997,17 +1023,18 @@ void netlist_mame_cpu_device::device_start()
state_add(STATE_GENPC, "GENPC", m_genPC).noshow();
state_add(STATE_GENPCBASE, "CURPC", m_genPC).noshow();
- for (int i=0; i < netlist().m_nets.size(); i++)
+ int index = 0;
+ for (auto &n : netlist().nlstate().nets())
{
- netlist::detail::net_t *n = netlist().m_nets[i].get();
if (n->is_logic())
{
- state_add(i*2, n->name().c_str(), *downcast<netlist::logic_net_t *>(n)->Q_state_ptr());
+ state_add(index, n->name().c_str(), *(downcast<netlist::logic_net_t &>(*n).Q_state_ptr()));
}
else
{
- state_add(i*2+1, n->name().c_str(), *downcast<netlist::analog_net_t *>(n)->Q_Analog_state_ptr());
+ state_add(index, n->name().c_str(), *(downcast<netlist::analog_net_t &>(*n).Q_Analog_state_ptr()));
}
+ index++;
}
// set our instruction counter
@@ -1032,10 +1059,8 @@ ATTR_COLD uint64_t netlist_mame_cpu_device::execute_cycles_to_clocks(uint64_t cy
ATTR_HOT void netlist_mame_cpu_device::execute_run()
{
- bool check_debugger = ((device_t::machine().debug_flags & DEBUG_FLAG_ENABLED) != 0);
- // debugging
//m_ppc = m_pc; // copy PC to previous PC
- if (check_debugger)
+ if (debugger_enabled())
{
while (m_icount > 0)
{
@@ -1043,13 +1068,13 @@ ATTR_HOT void netlist_mame_cpu_device::execute_run()
m_genPC &= 255;
debugger_instruction_hook(m_genPC);
netlist().process_queue(m_div);
- update_time_x();
+ update_icount(netlist().time());
}
}
else
{
netlist().process_queue(m_div * m_icount);
- update_time_x();
+ update_icount(netlist().time());
}
}
@@ -1089,11 +1114,8 @@ offs_t netlist_disassembler::disassemble(std::ostream &stream, offs_t pc, const
netlist_mame_sound_device::netlist_mame_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: netlist_mame_device(mconfig, NETLIST_SOUND, tag, owner, clock)
, device_sound_interface(mconfig, *this)
- , m_out{nullptr}
, m_in(nullptr)
, m_stream(nullptr)
- , m_num_inputs(0)
- , m_num_outputs(0)
{
}
@@ -1105,44 +1127,45 @@ void netlist_mame_sound_device::device_start()
// Configure outputs
- std::vector<nld_sound_out *> outdevs = netlist().get_device_list<nld_sound_out>();
+ std::vector<nld_sound_out *> outdevs = netlist().nlstate().get_device_list<nld_sound_out>();
if (outdevs.size() == 0)
fatalerror("No output devices");
- m_num_outputs = outdevs.size();
+ //m_num_outputs = outdevs.size();
/* resort channels */
- for (int i=0; i < MAX_OUT; i++) m_out[i] = nullptr;
- for (int i=0; i < m_num_outputs; i++)
+ for (auto &outdev : outdevs)
{
- int chan = outdevs[i]->m_channel();
+ int chan = outdev->m_channel();
- netlist().log().verbose("Output %d on channel %d", i, chan);
+ netlist().log().verbose("Output %s on channel %d", outdev->name(), chan);
- if (chan < 0 || chan >= MAX_OUT || chan >= outdevs.size())
+ if (chan < 0 || chan >= outdevs.size())
fatalerror("illegal channel number");
- m_out[chan] = outdevs[i];
- m_out[chan]->m_sample = netlist::netlist_time::from_hz(clock());
+ m_out[chan] = outdev;
+ m_out[chan]->m_sample_time = netlist::netlist_time::from_hz(clock());
m_out[chan]->m_buffer = nullptr;
+ m_out[chan]->m_bufsize = 0;
}
// Configure inputs
+ // FIXME: The limitation to one input device seems artificial.
+ // We should allow multiple devices with one channel each.
- m_num_inputs = 0;
m_in = nullptr;
- std::vector<nld_sound_in *> indevs = netlist().get_device_list<nld_sound_in>();
+ std::vector<nld_sound_in *> indevs = netlist().nlstate().get_device_list<nld_sound_in>();
if (indevs.size() > 1)
fatalerror("A maximum of one input device is allowed!");
if (indevs.size() == 1)
{
m_in = indevs[0];
- m_num_inputs = m_in->resolve();
+ m_in->resolve();
m_in->m_inc = netlist::netlist_time::from_hz(clock());
}
/* initialize the stream(s) */
- m_stream = machine().sound().stream_alloc(*this, m_num_inputs, m_num_outputs, clock());
+ m_stream = machine().sound().stream_alloc(*this, m_in ? m_in->num_channels() : 0, m_out.size(), clock());
}
@@ -1155,17 +1178,21 @@ void netlist_mame_sound_device::nl_register_devices()
void netlist_mame_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
- for (int i=0; i < m_num_outputs; i++)
+
+ for (auto &e : m_out)
{
- m_out[i]->m_buffer = outputs[i];
+ e.second->m_buffer = outputs[e.first];
+ e.second->m_bufsize = samples;
}
- if (m_num_inputs)
- m_in->buffer_reset();
- for (int i=0; i < m_num_inputs; i++)
+ if (m_in)
{
- m_in->m_buffer[i] = inputs[i];
+ m_in->buffer_reset();
+ for (int i=0; i < m_in->num_channels(); i++)
+ {
+ m_in->m_channels[i].m_buffer = inputs[i];
+ }
}
netlist::netlist_time cur(netlist().time());
@@ -1174,9 +1201,9 @@ void netlist_mame_sound_device::sound_stream_update(sound_stream &stream, stream
cur += (m_div * samples);
- for (int i=0; i < m_num_outputs; i++)
+ for (auto &e : m_out)
{
- m_out[i]->sound_update(cur);
- m_out[i]->buffer_reset(cur);
+ e.second->sound_update_fill(samples);
+ e.second->buffer_reset(cur);
}
}