diff options
author | couriersud <couriersud@arcor.de> | 2016-12-27 21:40:03 +0100 |
---|---|---|
committer | couriersud <couriersud@arcor.de> | 2016-12-28 13:48:48 +0100 |
commit | 63f4e52dae7933b6acc4d5c7473a2b90ed1d2155 (patch) | |
tree | 5037618283dcef3924e287afc61be0e279efd83e | |
parent | 9ade6db46e5bffe5830f5a1349e2a3bfeda10c80 (diff) |
Moved proxy code into separate file. (nw)
-rw-r--r-- | scripts/src/netlist.lua | 2 | ||||
-rw-r--r-- | src/lib/netlist/build/makefile | 1 | ||||
-rw-r--r-- | src/lib/netlist/devices/nld_system.cpp | 32 | ||||
-rw-r--r-- | src/lib/netlist/devices/nlid_proxy.cpp | 74 | ||||
-rw-r--r-- | src/lib/netlist/devices/nlid_proxy.h | 180 | ||||
-rw-r--r-- | src/lib/netlist/devices/nlid_system.h | 167 | ||||
-rw-r--r-- | src/lib/netlist/nl_base.cpp | 1 | ||||
-rw-r--r-- | src/lib/netlist/nl_base.h | 6 | ||||
-rw-r--r-- | src/lib/netlist/nl_setup.cpp | 1 | ||||
-rw-r--r-- | src/lib/netlist/nl_setup.h | 4 |
10 files changed, 265 insertions, 203 deletions
diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index 95b6a652d28..b1344e9d924 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -187,6 +187,8 @@ project "netlist" MAME_DIR .. "src/lib/netlist/devices/nld_truthtable.h", MAME_DIR .. "src/lib/netlist/devices/nlid_cmos.h", MAME_DIR .. "src/lib/netlist/devices/nlid_system.h", + MAME_DIR .. "src/lib/netlist/devices/nlid_proxy.cpp", + MAME_DIR .. "src/lib/netlist/devices/nlid_proxy.h", MAME_DIR .. "src/lib/netlist/macro/nlm_ttl74xx.cpp", MAME_DIR .. "src/lib/netlist/macro/nlm_ttl74xx.h", MAME_DIR .. "src/lib/netlist/macro/nlm_cd4xxx.cpp", diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index f9710655d26..171ba4cf5bb 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -111,6 +111,7 @@ NLOBJS := \ $(NLOBJ)/devices/nld_legacy.o \ $(NLOBJ)/devices/net_lib.o \ $(NLOBJ)/devices/nld_log.o \ + $(NLOBJ)/devices/nlid_proxy.o \ $(NLOBJ)/devices/nld_system.o \ $(NLOBJ)/devices/nld_truthtable.o \ $(NLOBJ)/macro/nlm_cd4xxx.o \ diff --git a/src/lib/netlist/devices/nld_system.cpp b/src/lib/netlist/devices/nld_system.cpp index e3369e514e5..836e744fc6a 100644 --- a/src/lib/netlist/devices/nld_system.cpp +++ b/src/lib/netlist/devices/nld_system.cpp @@ -86,38 +86,6 @@ namespace netlist { } - // ---------------------------------------------------------------------------------------- - // nld_d_to_a_proxy - // ---------------------------------------------------------------------------------------- - - void nld_d_to_a_proxy::reset() - { - //m_Q.initial(0.0); - m_last_state = -1; - m_RV.do_reset(); - m_is_timestep = m_RV.m_P.net().solver()->has_timestep_devices(); - m_RV.set(NL_FCONST(1.0) / logic_family().m_R_low, logic_family().m_low_V, 0.0); - } - - NETLIB_UPDATE(d_to_a_proxy) - { - const int state = static_cast<int>(m_I()); - if (state != m_last_state) - { - m_last_state = state; - const nl_double R = state ? logic_family().m_R_high : logic_family().m_R_low; - const nl_double V = state ? logic_family().m_high_V : logic_family().m_low_V; - - // We only need to update the net first if this is a time stepping net - if (m_is_timestep) - { - m_RV.update_dev(); - } - m_RV.set(NL_FCONST(1.0) / R, V, 0.0); - m_RV.m_P.schedule_after(NLTIME_FROM_NS(1)); - } - } - // ----------------------------------------------------------------------------- // nld_res_sw diff --git a/src/lib/netlist/devices/nlid_proxy.cpp b/src/lib/netlist/devices/nlid_proxy.cpp new file mode 100644 index 00000000000..d32ba00afe1 --- /dev/null +++ b/src/lib/netlist/devices/nlid_proxy.cpp @@ -0,0 +1,74 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * nlid_proxy.cpp + * + */ + +//#include <memory> +#include "nlid_proxy.h" +#include "solver/nld_solver.h" +//#include "plib/pstream.h" +//#include "plib/pfmtlog.h" +//#include "nld_log.h" + +namespace netlist +{ + namespace devices + { + + // ---------------------------------------------------------------------------------------- + // nld_d_to_a_proxy + // ---------------------------------------------------------------------------------------- + + nld_d_to_a_proxy::nld_d_to_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *out_proxied) + : nld_base_d_to_a_proxy(anetlist, name, out_proxied, m_RV.m_P) + , m_GNDHack(*this, "_Q") + , m_RV(*this, "RV") + , m_last_state(*this, "m_last_var", -1) + , m_is_timestep(false) + { + //register_sub(m_RV); + //register_term("1", m_RV.m_P); + //register_term("2", m_RV.m_N); + + register_subalias("Q", m_RV.m_P); + + connect_late(m_RV.m_N, m_GNDHack); + printf("%s %s\n", out_proxied->name().cstr(), out_proxied->device().name().cstr()); + auto x = netlist().setup().find_terminal(out_proxied->name(), detail::device_object_t::type_t::OUTPUT, false); + if (x) printf("==> %s\n", x->name().cstr()); + } + + + void nld_d_to_a_proxy::reset() + { + //m_Q.initial(0.0); + m_last_state = -1; + m_RV.do_reset(); + m_is_timestep = m_RV.m_P.net().solver()->has_timestep_devices(); + m_RV.set(NL_FCONST(1.0) / logic_family().m_R_low, logic_family().m_low_V, 0.0); + } + + NETLIB_UPDATE(d_to_a_proxy) + { + const int state = static_cast<int>(m_I()); + if (state != m_last_state) + { + m_last_state = state; + const nl_double R = state ? logic_family().m_R_high : logic_family().m_R_low; + const nl_double V = state ? logic_family().m_high_V : logic_family().m_low_V; + + // We only need to update the net first if this is a time stepping net + if (m_is_timestep) + { + m_RV.update_dev(); + } + m_RV.set(NL_FCONST(1.0) / R, V, 0.0); + m_RV.m_P.schedule_after(NLTIME_FROM_NS(1)); + } + } + + + } //namespace devices +} // namespace netlist diff --git a/src/lib/netlist/devices/nlid_proxy.h b/src/lib/netlist/devices/nlid_proxy.h new file mode 100644 index 00000000000..0138d0f759d --- /dev/null +++ b/src/lib/netlist/devices/nlid_proxy.h @@ -0,0 +1,180 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * nlid_proxy.h + * + * netlist proxy devices + * + * This file contains internal headers + */ + +#ifndef NLID_PROXY_H_ +#define NLID_PROXY_H_ + +#include <vector> + +#include "nl_setup.h" +#include "nl_base.h" +#include "nl_factory.h" +#include "analog/nld_twoterm.h" + +namespace netlist +{ + namespace devices + { + + // ----------------------------------------------------------------------------- + // nld_base_proxy + // ----------------------------------------------------------------------------- + + NETLIB_OBJECT(base_proxy) + { + public: + nld_base_proxy(netlist_t &anetlist, const pstring &name, + logic_t *inout_proxied, detail::core_terminal_t *proxy_inout) + : device_t(anetlist, name) + { + m_logic_family = inout_proxied->logic_family(); + m_term_proxied = inout_proxied; + m_proxy_term = proxy_inout; + } + + virtual ~nld_base_proxy() {} + + logic_t &term_proxied() const { return *m_term_proxied; } + detail::core_terminal_t &proxy_term() const { return *m_proxy_term; } + + protected: + const logic_family_desc_t *m_logic_family; + + virtual const logic_family_desc_t &logic_family() const + { + return *m_logic_family; + } + + private: + logic_t *m_term_proxied; + detail::core_terminal_t *m_proxy_term; + }; + + // ----------------------------------------------------------------------------- + // nld_a_to_d_proxy + // ----------------------------------------------------------------------------- + + NETLIB_OBJECT_DERIVED(a_to_d_proxy, base_proxy) + { + public: + nld_a_to_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *in_proxied) + : nld_base_proxy(anetlist, name, in_proxied, &m_I) + , m_I(*this, "I") + , m_Q(*this, "Q") + { + } + + virtual ~nld_a_to_d_proxy() {} + + analog_input_t m_I; + logic_output_t m_Q; + + protected: + + NETLIB_RESETI() { } + + NETLIB_UPDATEI() + { + nl_assert(m_logic_family != nullptr); + if (m_I.Q_Analog() > logic_family().m_high_thresh_V) + m_Q.push(1, NLTIME_FROM_NS(1)); + else if (m_I.Q_Analog() < logic_family().m_low_thresh_V) + m_Q.push(0, NLTIME_FROM_NS(1)); + else + { + // do nothing + } + } + private: + }; + + // ----------------------------------------------------------------------------- + // nld_base_d_to_a_proxy + // ----------------------------------------------------------------------------- + + NETLIB_OBJECT_DERIVED(base_d_to_a_proxy, base_proxy) + { + public: + virtual ~nld_base_d_to_a_proxy() {} + + virtual logic_input_t &in() { return m_I; } + + protected: + nld_base_d_to_a_proxy(netlist_t &anetlist, const pstring &name, + logic_output_t *out_proxied, detail::core_terminal_t &proxy_out) + : nld_base_proxy(anetlist, name, out_proxied, &proxy_out) + , m_I(*this, "I") + { + } + + logic_input_t m_I; + + private: + }; + + NETLIB_OBJECT_DERIVED(d_to_a_proxy, base_d_to_a_proxy) + { + public: + nld_d_to_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *out_proxied); + virtual ~nld_d_to_a_proxy() {} + + protected: + + NETLIB_RESETI(); + NETLIB_UPDATEI(); + + private: + analog_output_t m_GNDHack; // FIXME: Long term, we need to connect proxy gnd to device gnd + NETLIB_SUB(twoterm) m_RV; + state_var<int> m_last_state; + bool m_is_timestep; + }; + + + class factory_lib_entry_t : public base_factory_t + { + P_PREVENT_COPYING(factory_lib_entry_t) + public: + + factory_lib_entry_t(setup_t &setup, const pstring &name, const pstring &classname, + const pstring &def_param) + : base_factory_t(name, classname, def_param), m_setup(setup) { } + + class wrapper : public device_t + { + public: + wrapper(const pstring &devname, netlist_t &anetlist, const pstring &name) + : device_t(anetlist, name), m_devname(devname) + { + anetlist.setup().namespace_push(name); + anetlist.setup().include(m_devname); + anetlist.setup().namespace_pop(); + } + protected: + NETLIB_RESETI() { } + NETLIB_UPDATEI() { } + + pstring m_devname; + }; + + plib::owned_ptr<device_t> Create(netlist_t &anetlist, const pstring &name) override + { + return plib::owned_ptr<device_t>::Create<wrapper>(this->name(), anetlist, name); + } + + private: + setup_t &m_setup; + }; + + + } //namespace devices +} // namespace netlist + +#endif /* NLD_PROXY_H_ */ diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index 2a827f6b20e..89251264fa7 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -413,173 +413,6 @@ namespace netlist state_var<netlist_sig_t> m_last_state; }; - // ----------------------------------------------------------------------------- - // nld_base_proxy - // ----------------------------------------------------------------------------- - - NETLIB_OBJECT(base_proxy) - { - public: - nld_base_proxy(netlist_t &anetlist, const pstring &name, - logic_t *inout_proxied, detail::core_terminal_t *proxy_inout) - : device_t(anetlist, name) - { - m_logic_family = inout_proxied->logic_family(); - m_term_proxied = inout_proxied; - m_proxy_term = proxy_inout; - } - - virtual ~nld_base_proxy() {} - - logic_t &term_proxied() const { return *m_term_proxied; } - detail::core_terminal_t &proxy_term() const { return *m_proxy_term; } - - protected: - const logic_family_desc_t *m_logic_family; - - virtual const logic_family_desc_t &logic_family() const - { - return *m_logic_family; - } - - private: - logic_t *m_term_proxied; - detail::core_terminal_t *m_proxy_term; - }; - - // ----------------------------------------------------------------------------- - // nld_a_to_d_proxy - // ----------------------------------------------------------------------------- - - NETLIB_OBJECT_DERIVED(a_to_d_proxy, base_proxy) - { - public: - nld_a_to_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *in_proxied) - : nld_base_proxy(anetlist, name, in_proxied, &m_I) - , m_I(*this, "I") - , m_Q(*this, "Q") - { - } - - virtual ~nld_a_to_d_proxy() {} - - analog_input_t m_I; - logic_output_t m_Q; - - protected: - - NETLIB_RESETI() { } - - NETLIB_UPDATEI() - { - nl_assert(m_logic_family != nullptr); - if (m_I.Q_Analog() > logic_family().m_high_thresh_V) - m_Q.push(1, NLTIME_FROM_NS(1)); - else if (m_I.Q_Analog() < logic_family().m_low_thresh_V) - m_Q.push(0, NLTIME_FROM_NS(1)); - else - { - // do nothing - } - } - private: - }; - - // ----------------------------------------------------------------------------- - // nld_base_d_to_a_proxy - // ----------------------------------------------------------------------------- - - NETLIB_OBJECT_DERIVED(base_d_to_a_proxy, base_proxy) - { - public: - virtual ~nld_base_d_to_a_proxy() {} - - virtual logic_input_t &in() { return m_I; } - - protected: - nld_base_d_to_a_proxy(netlist_t &anetlist, const pstring &name, - logic_output_t *out_proxied, detail::core_terminal_t &proxy_out) - : nld_base_proxy(anetlist, name, out_proxied, &proxy_out) - , m_I(*this, "I") - { - } - - logic_input_t m_I; - - private: - }; - - NETLIB_OBJECT_DERIVED(d_to_a_proxy, base_d_to_a_proxy) - { - public: - nld_d_to_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *out_proxied) - : nld_base_d_to_a_proxy(anetlist, name, out_proxied, m_RV.m_P) - , m_GNDHack(*this, "_Q") - , m_RV(*this, "RV") - , m_last_state(*this, "m_last_var", -1) - , m_is_timestep(false) - { - //register_sub(m_RV); - //register_term("1", m_RV.m_P); - //register_term("2", m_RV.m_N); - - register_subalias("Q", m_RV.m_P); - - connect_late(m_RV.m_N, m_GNDHack); - //printf("%s %s\n", out_proxied->name().cstr(), out_proxied->device().name().cstr()); - } - - virtual ~nld_d_to_a_proxy() {} - - protected: - - NETLIB_RESETI(); - NETLIB_UPDATEI(); - - private: - analog_output_t m_GNDHack; // FIXME: Long term, we need to connect proxy gnd to device gnd - NETLIB_SUB(twoterm) m_RV; - state_var<int> m_last_state; - bool m_is_timestep; - }; - - - class factory_lib_entry_t : public base_factory_t - { - P_PREVENT_COPYING(factory_lib_entry_t) - public: - - factory_lib_entry_t(setup_t &setup, const pstring &name, const pstring &classname, - const pstring &def_param) - : base_factory_t(name, classname, def_param), m_setup(setup) { } - - class wrapper : public device_t - { - public: - wrapper(const pstring &devname, netlist_t &anetlist, const pstring &name) - : device_t(anetlist, name), m_devname(devname) - { - anetlist.setup().namespace_push(name); - anetlist.setup().include(m_devname); - anetlist.setup().namespace_pop(); - } - protected: - NETLIB_RESETI() { } - NETLIB_UPDATEI() { } - - pstring m_devname; - }; - - plib::owned_ptr<device_t> Create(netlist_t &anetlist, const pstring &name) override - { - return plib::owned_ptr<device_t>::Create<wrapper>(this->name(), anetlist, name); - } - - private: - setup_t &m_setup; - }; - - } //namespace devices } // namespace netlist diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 709e41f96f9..c129c21b72b 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -15,6 +15,7 @@ #include "nl_base.h" #include "devices/nlid_system.h" +#include "devices/nlid_proxy.h" namespace netlist { diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 3f315fe603b..01b3875d7a6 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -873,7 +873,7 @@ namespace netlist { public: param_logic_t(device_t &device, const pstring name, const bool val); - const bool operator()() const { return m_param; } + bool operator()() const { return m_param; } void setTo(const bool ¶m) { set(m_param, param); } private: bool m_param; @@ -883,7 +883,7 @@ namespace netlist { public: param_int_t(device_t &device, const pstring name, const int val); - const int operator()() const { return m_param; } + int operator()() const { return m_param; } void setTo(const int ¶m) { set(m_param, param); } private: int m_param; @@ -893,7 +893,7 @@ namespace netlist { public: param_double_t(device_t &device, const pstring name, const double val); - const double operator()() const { return m_param; } + double operator()() const { return m_param; } void setTo(const double ¶m) { set(m_param, param); } private: double m_param; diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index b7c9646c26f..1023f1a0b28 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -18,6 +18,7 @@ #include "devices/net_lib.h" #include "devices/nld_truthtable.h" #include "devices/nlid_system.h" +#include "devices/nlid_proxy.h" #include "analog/nld_twoterm.h" #include "solver/nld_solver.h" diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 8c690b36b6d..e560a3b9f79 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -281,10 +281,12 @@ namespace netlist std::unordered_map<pstring, pstring> m_param_values; std::unordered_map<pstring, detail::core_terminal_t *> m_terminals; + /* needed by proxy */ + detail::core_terminal_t *find_terminal(const pstring &outname_in, detail::device_object_t::type_t atype, bool required = true); + private: detail::core_terminal_t *find_terminal(const pstring &outname_in, bool required = true); - detail::core_terminal_t *find_terminal(const pstring &outname_in, detail::device_object_t::type_t atype, bool required = true); void merge_nets(detail::net_t &thisnet, detail::net_t &othernet); |