From e7652e14d6e52e651359e6d2bf827701aa164ba4 Mon Sep 17 00:00:00 2001 From: couriersud Date: Tue, 16 Apr 2019 01:49:33 +0200 Subject: [PATCH] netlist: Improve validation code. Adjust warning levels and fix a number of topics identified. --- src/devices/machine/netlist.cpp | 61 +++++++++++++++++++------- src/lib/netlist/devices/nld_ne555.cpp | 1 - src/lib/netlist/devices/nlid_proxy.cpp | 4 +- src/lib/netlist/nl_base.cpp | 21 +++++++++ src/lib/netlist/nl_base.h | 4 ++ src/lib/netlist/nl_errstr.h | 15 ++++--- src/lib/netlist/nl_setup.cpp | 17 +++++-- src/lib/netlist/plib/pfmtlog.h | 2 +- src/lib/netlist/solver/nld_solver.cpp | 2 +- src/mame/drivers/electra.cpp | 2 +- src/mame/machine/nl_pong.cpp | 2 +- src/mame/machine/nl_rebound.cpp | 2 +- 12 files changed, 98 insertions(+), 35 deletions(-) diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index b9c3ff00f7d..cf019d8582c 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -20,6 +20,7 @@ #include "netlist/plib/palloc.h" #include "debugger.h" +#include "romload.h" #include #include @@ -67,12 +68,12 @@ protected: case plib::plog_level::DEBUG: m_parent.logerror("netlist DEBUG: %s\n", ls.c_str()); break; - case plib::plog_level::INFO: - m_parent.logerror("netlist INFO: %s\n", ls.c_str()); - break; case plib::plog_level::VERBOSE: m_parent.logerror("netlist VERBOSE: %s\n", ls.c_str()); break; + case plib::plog_level::INFO: + m_parent.logerror("netlist INFO: %s\n", ls.c_str()); + break; case plib::plog_level::WARNING: m_parent.logerror("netlist WARNING: %s\n", ls.c_str()); break; @@ -104,19 +105,19 @@ protected: { case plib::plog_level::DEBUG: break; - case plib::plog_level::INFO: - break; case plib::plog_level::VERBOSE: break; + case plib::plog_level::INFO: + osd_printf_verbose("netlist INFO: %s\n", ls.c_str()); + break; case plib::plog_level::WARNING: - osd_printf_verbose("netlist WARNING: %s\n", ls.c_str()); + osd_printf_warning("netlist WARNING: %s\n", ls.c_str()); break; case plib::plog_level::ERROR: osd_printf_error("netlist ERROR: %s\n", ls.c_str()); break; case plib::plog_level::FATAL: - //throw emu_fatalerror(1, "netlist ERROR: %s\n", ls.c_str()); - throw emu_fatalerror("netlist ERROR: %s\n", ls.c_str()); + throw emu_fatalerror(1, "netlist ERROR: %s\n", ls.c_str()); } } @@ -307,10 +308,9 @@ private: plib::unique_ptr netlist_source_memregion_t::stream(const pstring &name) { - //memory_region *mem = static_cast(setup().setup().exec()).machine().root_device().memregion(m_name.c_str()); if (m_dev.has_running_machine()) { - memory_region *mem = m_dev.machine().root_device().memregion(m_name.c_str()); + memory_region *mem = m_dev.memregion(m_name.c_str()); return plib::make_unique(mem->base(), mem->bytes()); } else @@ -323,19 +323,43 @@ netlist_data_memregions_t::netlist_data_memregions_t(const device_t &dev) { } +static bool rom_exists(device_t &root, pstring name) +{ + // iterate, starting with the driver's ROMs and continuing with device ROMs + for (device_t &device : device_iterator(root)) + { + // scan the ROM entries for this device + for (tiny_rom_entry const *romp = device.rom_region(); romp && !ROMENTRY_ISEND(romp); ++romp) + { + if (ROMENTRY_ISREGION(romp)) // if this is a region, check for rom + { + char const *const basetag = romp->name; + if (name == pstring(":") + basetag) + return true; + } + } + } + return false; +} + plib::unique_ptr netlist_data_memregions_t::stream(const pstring &name) { //memory_region *mem = static_cast(setup().setup().exec()).parent().memregion(name.c_str()); - memory_region *mem = m_dev.memregion(name.c_str()); - if (mem != nullptr) + if (m_dev.has_running_machine()) { - return plib::make_unique(mem->base(), mem->bytes()); + memory_region *mem = m_dev.memregion(name.c_str()); + if (mem != nullptr) + return plib::make_unique(mem->base(), mem->bytes()); + else + return plib::unique_ptr(nullptr); } 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 plib::unique_ptr(nullptr); + /* validation */ + if (rom_exists(m_dev.mconfig().root_device(), pstring(m_dev.tag()) + ":" + name)) + return plib::make_unique(); + else + return plib::unique_ptr(nullptr); } } @@ -957,7 +981,7 @@ void netlist_mame_device::common_dev_start(netlist::netlist_t *lnetlist) const } /* add default data provider for roms - if not in validity check*/ - if (has_running_machine()) + //if (has_running_machine()) lsetup.register_source(plib::make_unique(*this)); m_setup_func(lsetup); @@ -978,9 +1002,12 @@ void netlist_mame_device::common_dev_start(netlist::netlist_t *lnetlist) const } + void netlist_mame_device::device_validity_check(validity_checker &valid) const { #if 1 + + //rom_exists(mconfig().root_device()); LOGDEVCALLS("device_validity_check %s\n", this->mconfig().gamedrv().name); try diff --git a/src/lib/netlist/devices/nld_ne555.cpp b/src/lib/netlist/devices/nld_ne555.cpp index 5e990d2e974..dc6e3e5696a 100644 --- a/src/lib/netlist/devices/nld_ne555.cpp +++ b/src/lib/netlist/devices/nld_ne555.cpp @@ -78,7 +78,6 @@ namespace netlist register_subalias("VCC", m_R1.m_P); // Pin 8 register_subalias("OUT", m_ROUT.m_P); // Pin 3 - connect(m_R1.m_N, m_R2.m_P); connect(m_R1.m_N, m_R2.m_P); connect(m_R2.m_N, m_R3.m_P); connect(m_RDIS.m_N, m_R3.m_N); diff --git a/src/lib/netlist/devices/nlid_proxy.cpp b/src/lib/netlist/devices/nlid_proxy.cpp index e40d3506cff..c2eba21f648 100644 --- a/src/lib/netlist/devices/nlid_proxy.cpp +++ b/src/lib/netlist/devices/nlid_proxy.cpp @@ -104,9 +104,9 @@ namespace netlist f = true; } } - //FIXME: Use power terminals! + //FIXME: Use power terminals and change info to warning or error if (!f) - log().warning(MW_1_NO_POWER_TERMINALS_ON_DEVICE_1, out_proxied->device().name()); + log().info(MI_1_NO_POWER_TERMINALS_ON_DEVICE_1, out_proxied->device().name()); else log().verbose("D/A Proxy: Found power terminals on device {1}", out_proxied->device().name()); } diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 43c2f6db499..5e5399c9d3a 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -1036,11 +1036,32 @@ plib::unique_ptr param_data_t::stream() return dynamic_cast(this) != nullptr; } + bool detail::core_terminal_t::is_logic_input() const NL_NOEXCEPT + { + return dynamic_cast(this) != nullptr; + } + + bool detail::core_terminal_t::is_logic_output() const NL_NOEXCEPT + { + return dynamic_cast(this) != nullptr; + } + bool detail::core_terminal_t::is_analog() const NL_NOEXCEPT { return dynamic_cast(this) != nullptr; } + bool detail::core_terminal_t::is_analog_input() const NL_NOEXCEPT + { + return dynamic_cast(this) != nullptr; + } + + bool detail::core_terminal_t::is_analog_output() const NL_NOEXCEPT + { + return dynamic_cast(this) != nullptr; + } + + bool detail::net_t::is_logic() const NL_NOEXCEPT { return dynamic_cast(this) != nullptr; diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index f52b720ab37..b9545f8e5af 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -565,7 +565,11 @@ namespace netlist net_t & net() noexcept { return *m_net;} bool is_logic() const NL_NOEXCEPT; + bool is_logic_input() const NL_NOEXCEPT; + bool is_logic_output() const NL_NOEXCEPT; bool is_analog() const NL_NOEXCEPT; + bool is_analog_input() const NL_NOEXCEPT; + bool is_analog_output() const NL_NOEXCEPT; bool is_state(state_e astate) const noexcept { return (m_state == astate); } state_e terminal_state() const noexcept { return m_state; } diff --git a/src/lib/netlist/nl_errstr.h b/src/lib/netlist/nl_errstr.h index ee3c47f3339..175bbb4962e 100644 --- a/src/lib/netlist/nl_errstr.h +++ b/src/lib/netlist/nl_errstr.h @@ -41,7 +41,7 @@ #define MF_1_UNKNOWN_SOLVER_TYPE "Unknown solver type: {1}" #define MF_1_NETGROUP_SIZE_EXCEEDED_1 "Encountered netgroup with > {1} nets" -#define MW_1_NO_SPECIFIC_SOLVER "No specific solver found for netlist of size {1}" +#define MI_1_NO_SPECIFIC_SOLVER "No specific solver found for netlist of size {1}" // nl_base.cpp @@ -82,14 +82,17 @@ #define MF_2_MODEL_PARAMETERS_NOT_UPPERCASE_1_2 "model parameters should be uppercase:{1} {2}" #define MF_2_ENTITY_1_NOT_FOUND_IN_MODEL_2 "Entity {1} not found in model {2}" #define MF_1_UNKNOWN_NUMBER_FACTOR_IN_1 "Unknown number factor in: {1}" -#define MF_1_NOT_FOUND_IN_SOURCE_COLLECTION "unable to find {1} in source collection" +#define MF_1_NOT_FOUND_IN_SOURCE_COLLECTION "unable to find {1} in sources collection" #define MW_3_OVERWRITING_PARAM_1_OLD_2_NEW_3 "Overwriting {1} old <{2}> new <{3}>" #define MW_1_CONNECTING_1_TO_ITSELF "Connecting {1} to itself. This may be right, though" -#define MW_1_DUMMY_1_WITHOUT_CONNECTIONS "Found dummy terminal {1} without connections" +#define MI_1_DUMMY_1_WITHOUT_CONNECTIONS "Found dummy terminal {1} without connections" +#define MI_1_ANALOG_OUTPUT_1_WITHOUT_CONNECTIONS "Found analog output {1} without connections" +#define MI_1_LOGIC_OUTPUT_1_WITHOUT_CONNECTIONS "Found logic output {1} without connections" +#define MW_1_LOGIC_INPUT_1_WITHOUT_CONNECTIONS "Found logic input {1} without connections" #define MW_1_TERMINAL_1_WITHOUT_CONNECTIONS "Found terminal {1} without connections" -#define MW_3_REMOVE_DEVICE_1_CONNECTED_ONLY_TO_RAILS_2_3 "Found device {1} connected only to railterminals {2}/{3}. Will be removed" -#define MW_1_DATA_1_NOT_FOUND "unable to find data named {1} in source collection" +#define MI_3_REMOVE_DEVICE_1_CONNECTED_ONLY_TO_RAILS_2_3 "Found device {1} connected only to railterminals {2}/{3}. Will be removed" +#define MW_1_DATA_1_NOT_FOUND "unable to find data {1} in sources collection" // nld_mm5837.cpp @@ -97,7 +100,7 @@ // nlid_proxy.cpp -#define MW_1_NO_POWER_TERMINALS_ON_DEVICE_1 "D/A Proxy: Found no valid combination of power terminals on device {1}" +#define MI_1_NO_POWER_TERMINALS_ON_DEVICE_1 "D/A Proxy: Found no valid combination of power terminals on device {1}" #endif /* NL_ERRSTR_H_ */ diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 6caafa27a66..d651ae1b9f8 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -768,11 +768,20 @@ void setup_t::resolve_inputs() { detail::core_terminal_t *term = i.second; if (!term->has_net() && dynamic_cast< devices::NETLIB_NAME(dummy_input) *>(&term->device()) != nullptr) - log().warning(MW_1_DUMMY_1_WITHOUT_CONNECTIONS, term->name()); + log().info(MI_1_DUMMY_1_WITHOUT_CONNECTIONS, term->name()); else if (!term->has_net()) errstr += plib::pfmt("Found terminal {1} without a net\n")(term->name()); else if (term->net().num_cons() == 0) - log().warning(MW_1_TERMINAL_1_WITHOUT_CONNECTIONS, term->name()); + { + if (term->is_logic_input()) + log().warning(MW_1_LOGIC_INPUT_1_WITHOUT_CONNECTIONS, term->name()); + else if (term->is_logic_output()) + log().info(MI_1_LOGIC_OUTPUT_1_WITHOUT_CONNECTIONS, term->name()); + else if (term->is_analog_output()) + log().info(MI_1_ANALOG_OUTPUT_1_WITHOUT_CONNECTIONS, term->name()); + else + log().warning(MW_1_TERMINAL_1_WITHOUT_CONNECTIONS, term->name()); + } } //FIXME: error string handling if (errstr != "") @@ -1075,7 +1084,7 @@ void setup_t::prepare_to_run() // FIXME: get device name, check for device } else - log().info("Unknown parameter: {}", p.first); + log().warning("Unknown parameter: {}", p.first); } } @@ -1107,7 +1116,7 @@ void setup_t::prepare_to_run() { if (t->m_N.net().isRailNet() && t->m_P.net().isRailNet()) { - log().warning(MW_3_REMOVE_DEVICE_1_CONNECTED_ONLY_TO_RAILS_2_3, + log().info(MI_3_REMOVE_DEVICE_1_CONNECTED_ONLY_TO_RAILS_2_3, t->name(), t->m_N.net().name(), t->m_P.net().name()); t->m_N.net().remove_terminal(t->m_N); t->m_P.net().remove_terminal(t->m_P); diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index cb9b59c01ce..ce94407d018 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -17,8 +17,8 @@ namespace plib { P_ENUM(plog_level, DEBUG, - INFO, VERBOSE, + INFO, WARNING, ERROR, FATAL) diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index 4734cc3624d..63642b65e10 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -358,7 +358,7 @@ namespace devices #endif #endif default: - log().warning(MW_1_NO_SPECIFIC_SOLVER, net_count); + log().info(MI_1_NO_SPECIFIC_SOLVER, net_count); if (net_count <= 8) { ms = create_solver(net_count, sname); diff --git a/src/mame/drivers/electra.cpp b/src/mame/drivers/electra.cpp index 861c439f96c..13f33b893f5 100644 --- a/src/mame/drivers/electra.cpp +++ b/src/mame/drivers/electra.cpp @@ -66,7 +66,7 @@ private: static NETLIST_START(electra) - SOLVER(Solve, 48000) + SOLVER(Solver, 48000) // PARAM(Solver.FREQ, 48000) PARAM(Solver.ACCURACY, 1e-4) // works and is sufficient diff --git a/src/mame/machine/nl_pong.cpp b/src/mame/machine/nl_pong.cpp index 558171cdcc2..ce374873d9d 100644 --- a/src/mame/machine/nl_pong.cpp +++ b/src/mame/machine/nl_pong.cpp @@ -19,7 +19,7 @@ NETLIST_START(pong_fast) SOLVER(Solver, 48000) PARAM(Solver.PARALLEL, 0) // Don't do parallel solvers PARAM(Solver.ACCURACY, 1e-4) // works and is sufficient - PARAM(Solver.LTE, 1e-4) // Default is not enough for paddle control if using LTE + PARAM(Solver.DYNAMIC_LTE, 1e-4) // Default is not enough for paddle control if using LTE PARAM(NETLIST.USE_DEACTIVATE, 1) ANALOG_INPUT(V5, 5) diff --git a/src/mame/machine/nl_rebound.cpp b/src/mame/machine/nl_rebound.cpp index 66da37a9a26..81e60f284d8 100644 --- a/src/mame/machine/nl_rebound.cpp +++ b/src/mame/machine/nl_rebound.cpp @@ -72,7 +72,7 @@ NETLIST_START(rebound_schematics) SOLVER(Solver, 48000) PARAM(Solver.DYNAMIC_TS, 1) - PARAM(Solver.LTE, 1e-2) + PARAM(Solver.DYNAMIC_LTE, 1e-3) PARAM(Solver.DYNAMIC_MIN_TIMESTEP, 5e-7) PARAM(Solver.PARALLEL, 0) // Don't do parallel solvers