From 3fcf6e6a3c4ae5fdbe36509e87adcc4748ae8d6d Mon Sep 17 00:00:00 2001 From: "therealmogminer@gmail.com" Date: Tue, 13 Dec 2016 18:41:25 +0100 Subject: -netlist: Add simple ROM hookup capability. [Ryan Holtz] --- src/lib/netlist/prg/nltool.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/lib/netlist/prg/nltool.cpp') diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index b095a081f81..1245f03a391 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -201,6 +201,9 @@ struct input_t case netlist::param_t::LOGIC: static_cast(m_param)->setTo(static_cast(m_value)); break; + case netlist::param_t::ROM: + static_cast(m_param)->setTo(nullptr); + break; } } -- cgit v1.2.3-70-g09d2 From 66abfa8e6d0ebe032ee374a11078510bc4254929 Mon Sep 17 00:00:00 2001 From: "therealmogminer@gmail.com" Date: Wed, 21 Dec 2016 20:14:48 +0100 Subject: -netlist: Added shared RAM pointer, for use by netlist RAM devices which need updating by non-netlist driver code. [Ryan Holtz] -netlist: Added new devices: [Ryan Holtz] * Intel 2102A 1Kbit (1024 x 1) Static RAM * 74365 Hex Bus Driver with 3-State Outputs * Generic 2- and 3-terminal Tristate device * Note: Tristate device and 74365 do not actually tristate, they are simply a way of combining multiple outputs + chip enables. --- scripts/src/netlist.lua | 6 ++ src/devices/machine/netlist.cpp | 54 +++++++++++++--- src/devices/machine/netlist.h | 57 +++++++++++++---- src/lib/netlist/build/makefile | 3 + src/lib/netlist/devices/net_lib.cpp | 6 ++ src/lib/netlist/devices/net_lib.h | 4 ++ src/lib/netlist/devices/nld_2102A.cpp | 103 +++++++++++++++++++++++++++++++ src/lib/netlist/devices/nld_2102A.h | 48 ++++++++++++++ src/lib/netlist/devices/nld_2716.cpp | 31 +++++----- src/lib/netlist/devices/nld_2716.h | 32 +++++++--- src/lib/netlist/devices/nld_74365.cpp | 74 ++++++++++++++++++++++ src/lib/netlist/devices/nld_74365.h | 44 +++++++++++++ src/lib/netlist/devices/nld_82S126.cpp | 22 +++++-- src/lib/netlist/devices/nld_tristate.cpp | 76 +++++++++++++++++++++++ src/lib/netlist/devices/nld_tristate.h | 31 ++++++++++ src/lib/netlist/nl_base.cpp | 2 +- src/lib/netlist/nl_base.h | 4 +- src/lib/netlist/nl_setup.cpp | 4 +- src/lib/netlist/prg/nltool.cpp | 4 +- 19 files changed, 551 insertions(+), 54 deletions(-) create mode 100644 src/lib/netlist/devices/nld_2102A.cpp create mode 100644 src/lib/netlist/devices/nld_2102A.h create mode 100644 src/lib/netlist/devices/nld_74365.cpp create mode 100644 src/lib/netlist/devices/nld_74365.h create mode 100644 src/lib/netlist/devices/nld_tristate.cpp create mode 100644 src/lib/netlist/devices/nld_tristate.h (limited to 'src/lib/netlist/prg/nltool.cpp') diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index b5fe059d074..a0ac5045565 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -91,6 +91,8 @@ project "netlist" MAME_DIR .. "src/lib/netlist/solver/nld_ms_w.h", MAME_DIR .. "src/lib/netlist/solver/nld_ms_direct_lu.h", MAME_DIR .. "src/lib/netlist/solver/vector_base.h", + MAME_DIR .. "src/lib/netlist/devices/nld_2102A.cpp", + MAME_DIR .. "src/lib/netlist/devices/nld_2102A.h", MAME_DIR .. "src/lib/netlist/devices/nld_2716.cpp", MAME_DIR .. "src/lib/netlist/devices/nld_2716.h", MAME_DIR .. "src/lib/netlist/devices/nld_4020.cpp", @@ -131,6 +133,8 @@ project "netlist" MAME_DIR .. "src/lib/netlist/devices/nld_74193.h", MAME_DIR .. "src/lib/netlist/devices/nld_74279.cpp", MAME_DIR .. "src/lib/netlist/devices/nld_74279.h", + MAME_DIR .. "src/lib/netlist/devices/nld_74365.cpp", + MAME_DIR .. "src/lib/netlist/devices/nld_74365.h", MAME_DIR .. "src/lib/netlist/devices/nld_74ls629.cpp", MAME_DIR .. "src/lib/netlist/devices/nld_74ls629.h", MAME_DIR .. "src/lib/netlist/devices/nld_82S16.cpp", @@ -153,6 +157,8 @@ project "netlist" MAME_DIR .. "src/lib/netlist/devices/nld_mm5837.h", MAME_DIR .. "src/lib/netlist/devices/nld_r2r_dac.cpp", MAME_DIR .. "src/lib/netlist/devices/nld_r2r_dac.h", + MAME_DIR .. "src/lib/netlist/devices/nld_tristate.cpp", + MAME_DIR .. "src/lib/netlist/devices/nld_tristate.h", MAME_DIR .. "src/lib/netlist/devices/nld_legacy.cpp", MAME_DIR .. "src/lib/netlist/devices/nld_legacy.h", MAME_DIR .. "src/lib/netlist/devices/net_lib.cpp", diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index b7891d75286..2301ec49a4f 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -29,6 +29,7 @@ const device_type NETLIST_SOUND = &device_creator; const device_type NETLIST_ANALOG_INPUT = &device_creator; const device_type NETLIST_INT_INPUT = &device_creator; const device_type NETLIST_ROM_REGION = &device_creator; +const device_type NETLIST_RAM_POINTER = &device_creator; const device_type NETLIST_LOGIC_INPUT = &device_creator; const device_type NETLIST_STREAM_INPUT = &device_creator; @@ -181,37 +182,74 @@ void netlist_mame_logic_input_t::device_start() } // ---------------------------------------------------------------------------------------- -// netlist_mame_rom_region_t +// netlist_mame_rom_t // ---------------------------------------------------------------------------------------- + netlist_mame_rom_t::netlist_mame_rom_t(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, NETLIST_ROM_REGION, "Netlist ROM Region", tag, owner, clock, "netlist_rom_region", __FILE__) , netlist_mame_sub_interface(*owner) , m_param(nullptr) , m_param_name("") - , m_rom_tag(nullptr) - , m_rom(nullptr) + , m_data_tag(nullptr) + , m_data(nullptr) { } -void netlist_mame_rom_t::static_set_params(device_t &device, const char *param_name, const char* region_tag) +void netlist_mame_rom_t::static_set_params(device_t &device, const char *param_name, const char* data_tag) { - netlist_mame_rom_t &netlist = downcast(device); + netlist_mame_rom_t &netlist = downcast(device); LOG_DEV_CALLS(("static_set_params %s\n", device.tag())); netlist.m_param_name = param_name; - netlist.m_rom_tag = region_tag; + netlist.m_data_tag = data_tag; } void netlist_mame_rom_t::device_start() { LOG_DEV_CALLS(("start %s\n", tag())); netlist::param_t *p = downcast(this->owner())->setup().find_param(m_param_name); - m_param = dynamic_cast(p); + m_param = dynamic_cast(p); + if (m_param == nullptr) + { + fatalerror("device %s wrong parameter type for %s\n", basetag(), m_param_name.cstr()); + } + + if (memregion(m_data_tag) != nullptr) + m_data = memregion(m_data_tag)->base(); + + m_param->setTo(m_data); +} + +// ---------------------------------------------------------------------------------------- +// netlist_ram_pointer_t +// ---------------------------------------------------------------------------------------- + +netlist_ram_pointer_t::netlist_ram_pointer_t(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : device_t(mconfig, NETLIST_RAM_POINTER, "Netlist RAM Pointer", tag, owner, clock, "netlist_ram_pointer", __FILE__) + , netlist_mame_sub_interface(*owner) + , m_param(nullptr) + , m_param_name("") + , m_data(nullptr) +{ +} + +void netlist_ram_pointer_t::static_set_params(device_t &device, const char *param_name) +{ + netlist_ram_pointer_t &netlist = downcast(device); + LOG_DEV_CALLS(("static_set_params %s\n", device.tag())); + netlist.m_param_name = param_name; +} + +void netlist_ram_pointer_t::device_start() +{ + LOG_DEV_CALLS(("start %s\n", tag())); + netlist::param_t *p = downcast(this->owner())->setup().find_param(m_param_name); + m_param = dynamic_cast(p); if (m_param == nullptr) { fatalerror("device %s wrong parameter type for %s\n", basetag(), m_param_name.cstr()); } - m_rom = memregion(m_rom_tag)->base(); + m_data = (*m_param)(); } // ---------------------------------------------------------------------------------------- diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index 28444e2d7e7..3a223541091 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -43,9 +43,13 @@ MCFG_DEVICE_ADD(_basetag ":" _tag, NETLIST_INT_INPUT, 0) \ netlist_mame_int_input_t::static_set_params(*device, _name, _mask, _shift); -#define MCFG_NETLIST_ROM(_basetag, _tag, _name, _region) \ - MCFG_DEVICE_ADD(_basetag ":" _tag, NETLIST_ROM_REGION, 0, _region) \ - netlist_mame_rom_t::static_set_params(*device, _name); +#define MCFG_NETLIST_ROM_REGION(_basetag, _tag, _name, _region) \ + MCFG_DEVICE_ADD(_basetag ":" _tag, NETLIST_ROM_REGION, 0) \ + netlist_mame_rom_t::static_set_params(*device, _name ".m_ROM", ":" _region); + +#define MCFG_NETLIST_RAM_POINTER(_basetag, _tag, _name) \ + MCFG_DEVICE_ADD(_basetag ":" _tag, NETLIST_RAM_POINTER, 0) \ + netlist_ram_pointer_t::static_set_params(*device, _name ".m_RAM"); #define MCFG_NETLIST_STREAM_INPUT(_basetag, _chan, _name) \ MCFG_DEVICE_ADD(_basetag ":cin" # _chan, NETLIST_STREAM_INPUT, 0) \ @@ -413,7 +417,6 @@ private: netlist_analog_output_delegate m_delegate; }; - // ---------------------------------------------------------------------------------------- // netlist_mame_int_input_t // ---------------------------------------------------------------------------------------- @@ -510,8 +513,8 @@ private: // netlist_mame_rom_t // ---------------------------------------------------------------------------------------- -class netlist_mame_rom_t : public device_t, - public netlist_mame_sub_interface +class netlist_mame_rom_t : public device_t, + public netlist_mame_sub_interface { public: @@ -526,14 +529,45 @@ protected: virtual void device_start() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override { - m_param->setTo(m_rom); + m_param->setTo(m_data); + } + +private: + netlist::param_ptr_t *m_param; + pstring m_param_name; + const char* m_data_tag; + uint8_t* m_data; +}; + +// ---------------------------------------------------------------------------------------- +// netlist_ram_pointer_t +// ---------------------------------------------------------------------------------------- + +class netlist_ram_pointer_t: public device_t, + public netlist_mame_sub_interface +{ +public: + + // construction/destruction + netlist_ram_pointer_t(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + virtual ~netlist_ram_pointer_t() { } + + uint8_t* ptr() const { return m_data; } + + static void static_set_params(device_t &device, const char *param_name); + +protected: + // device-level overrides + virtual void device_start() override; + virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override + { + m_data = (*m_param)(); } private: - netlist::param_rom_t *m_param; + netlist::param_ptr_t *m_param; pstring m_param_name; - const char* m_rom_tag; - uint8_t* m_rom; + uint8_t* m_data; }; // ---------------------------------------------------------------------------------------- @@ -796,10 +830,9 @@ extern const device_type NETLIST_ANALOG_INPUT; extern const device_type NETLIST_LOGIC_INPUT; extern const device_type NETLIST_INT_INPUT; extern const device_type NETLIST_ROM_REGION; +extern const device_type NETLIST_RAM_POINTER; extern const device_type NETLIST_ANALOG_OUTPUT; -//extern const device_type NETLIST_LOGIC_OUTPUT; -extern const device_type NETLIST_INT_OUTPUT; extern const device_type NETLIST_STREAM_INPUT; extern const device_type NETLIST_STREAM_OUTPUT; diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index 046ae395d93..70aacc15244 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -66,6 +66,7 @@ NLOBJS := \ $(NLOBJ)/analog/nld_switches.o \ $(NLOBJ)/analog/nld_twoterm.o \ $(NLOBJ)/analog/nld_opamps.o \ + $(NLOBJ)/devices/nld_2102A.o \ $(NLOBJ)/devices/nld_2716.o \ $(NLOBJ)/devices/nld_4020.o \ $(NLOBJ)/devices/nld_4066.o \ @@ -86,6 +87,7 @@ NLOBJS := \ $(NLOBJ)/devices/nld_74192.o \ $(NLOBJ)/devices/nld_74193.o \ $(NLOBJ)/devices/nld_74279.o \ + $(NLOBJ)/devices/nld_74365.o \ $(NLOBJ)/devices/nld_74ls629.o \ $(NLOBJ)/devices/nld_82S16.o \ $(NLOBJ)/devices/nld_82S126.o \ @@ -97,6 +99,7 @@ NLOBJS := \ $(NLOBJ)/devices/nld_mm5837.o \ $(NLOBJ)/devices/nld_ne555.o \ $(NLOBJ)/devices/nld_r2r_dac.o \ + $(NLOBJ)/devices/nld_tristate.o \ $(NLOBJ)/devices/nld_legacy.o \ $(NLOBJ)/devices/net_lib.o \ $(NLOBJ)/devices/nld_log.o \ diff --git a/src/lib/netlist/devices/net_lib.cpp b/src/lib/netlist/devices/net_lib.cpp index c647e986ac2..f235766ebcc 100644 --- a/src/lib/netlist/devices/net_lib.cpp +++ b/src/lib/netlist/devices/net_lib.cpp @@ -107,6 +107,7 @@ static void initialize_factory(factory_list_t &factory) ENTRYX(nicRSFF, NETDEV_RSFF, "+S,R") ENTRYX(nicDelay, NETDEV_DELAY, "-") ENTRYX(2716, EPROM_2716, "-") + ENTRYX(2102A, RAM_2102A, "-") ENTRYX(7450, TTL_7450_ANDORINVERT, "+A,B,C,D") ENTRYX(7448, TTL_7448, "+A,B,C,D,LTQ,BIQ,RBIQ") ENTRYX(7473, TTL_7473, "+CLK1,J1,K1,CLRQ1,CLK2,J2,K2,CLRQ2") @@ -125,6 +126,7 @@ static void initialize_factory(factory_list_t &factory) ENTRYX(74175, TTL_74175, "-") ENTRYX(74192, TTL_74192, "-") ENTRYX(74193, TTL_74193, "-") + ENTRYX(74365, TTL_74365, "-") ENTRYX(DM9334, TTL_DM9334, "-") //ENTRY(74279, TTL_74279, "-") // only dip available ENTRYX(SN74LS629, SN74LS629, "CAP") @@ -141,6 +143,9 @@ static void initialize_factory(factory_list_t &factory) //ENTRY(4066, CD_4066, "+A,B") ENTRYX(NE555, NE555, "-") ENTRYX(r2r_dac, R2R_DAC, "+VIN,R,N") + ENTRYX(tristate, TTL_TRISTATE, "-") + ENTRYX(tristate3, TTL_TRISTATE3, "-") + ENTRYX(2102A_dip, RAM_2102A_DIP, "-") ENTRYX(2716_dip, EPROM_2716_DIP, "-") ENTRYX(4538_dip, CD4538_DIP, "-") ENTRYX(7448_dip, TTL_7448_DIP, "-") @@ -161,6 +166,7 @@ static void initialize_factory(factory_list_t &factory) ENTRYX(74192_dip, TTL_74192_DIP, "-") ENTRYX(74193_dip, TTL_74193_DIP, "-") ENTRYX(74279_dip, TTL_74279_DIP, "-") + ENTRYX(74365_dip, TTL_74365_DIP, "-") ENTRYX(82S16_dip, TTL_82S16_DIP, "-") ENTRYX(82S126_dip, TTL_82S126_DIP, "-") ENTRYX(9602_dip, TTL_9602_DIP, "-") diff --git a/src/lib/netlist/devices/net_lib.h b/src/lib/netlist/devices/net_lib.h index 66c7f57d842..6e9ba446231 100644 --- a/src/lib/netlist/devices/net_lib.h +++ b/src/lib/netlist/devices/net_lib.h @@ -14,6 +14,7 @@ #include "nl_base.h" #include "nld_system.h" +#include "nld_2102A.h" #include "nld_2716.h" #include "nld_4020.h" #include "nld_4066.h" @@ -34,6 +35,7 @@ #include "nld_74192.h" #include "nld_74193.h" #include "nld_74279.h" +#include "nld_74365.h" #include "nld_74ls629.h" #include "nld_82S16.h" #include "nld_82S126.h" @@ -49,6 +51,8 @@ #include "nld_r2r_dac.h" +#include "nld_tristate.h" + #include "nld_log.h" #include "macro/nlm_cd4xxx.h" diff --git a/src/lib/netlist/devices/nld_2102A.cpp b/src/lib/netlist/devices/nld_2102A.cpp new file mode 100644 index 00000000000..45a7ee53c34 --- /dev/null +++ b/src/lib/netlist/devices/nld_2102A.cpp @@ -0,0 +1,103 @@ +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz +/* + * nld_2102A.cpp + * + */ + +#include "nld_2102A.h" + +#define ADDR2BYTE(a) ((a) >> 3) +#define ADDR2BIT(a) ((a) & 0x7) + +namespace netlist +{ + namespace devices + { + NETLIB_OBJECT(2102A) + { + NETLIB_CONSTRUCTOR(2102A) + , m_A(*this, {{"A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9" }}) + , m_CEQ(*this, "CEQ") + , m_RWQ(*this, "RWQ") + , m_DI(*this, "DI") + , m_DO(*this, "DO") + , m_ram(*this, "m_ram", 0) + , m_RAM(*this, "m_RAM", &m_ram[0]) + { + } + + NETLIB_RESETI(); + NETLIB_UPDATEI(); + + protected: + object_array_t m_A; + logic_input_t m_CEQ; + logic_input_t m_RWQ; + logic_input_t m_DI; + + logic_output_t m_DO; + + state_var m_ram; // 1024x1 bits + param_ptr_t m_RAM; + }; + + NETLIB_OBJECT_DERIVED(2102A_dip, 2102A) + { + NETLIB_CONSTRUCTOR_DERIVED(2102A_dip, 2102A) + { + register_subalias("8", m_A[0]); + register_subalias("4", m_A[1]); + register_subalias("5", m_A[2]); + register_subalias("6", m_A[3]); + register_subalias("7", m_A[4]); + register_subalias("2", m_A[5]); + register_subalias("1", m_A[6]); + register_subalias("16", m_A[7]); + register_subalias("15", m_A[8]); + register_subalias("14", m_A[9]); + + register_subalias("13", m_CEQ); + register_subalias("3", m_RWQ); + + register_subalias("11", m_DI); + register_subalias("12", m_DO); + } + }; + + NETLIB_UPDATE(2102A) + { + netlist_time max_delay = NLTIME_FROM_NS(350); + + if (!m_CEQ()) + { + unsigned a = 0; + for (std::size_t i=0; i<10; i++) + { + a |= m_A[i]() << i; + } + const unsigned byte = ADDR2BYTE(a); + const unsigned bit = ADDR2BIT(a); + + if (!m_RWQ()) + { + m_ram[byte] &= ~(static_cast(1) << bit); + m_ram[byte] |= (static_cast(m_DI()) << bit); + } + + m_DO.push((m_ram[byte] >> bit) & 1, max_delay); + } + } + + NETLIB_RESET(2102A) + { + m_RAM.setTo(&m_ram[0]); + for (std::size_t i=0; i<128; i++) + m_ram[i] = 0; + } + + NETLIB_DEVICE_IMPL(2102A) + NETLIB_DEVICE_IMPL(2102A_dip) + + } //namespace devices +} // namespace netlist diff --git a/src/lib/netlist/devices/nld_2102A.h b/src/lib/netlist/devices/nld_2102A.h new file mode 100644 index 00000000000..fe2feebf38e --- /dev/null +++ b/src/lib/netlist/devices/nld_2102A.h @@ -0,0 +1,48 @@ +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz +/* + * nld_2102A.h + * + * 2102: 1024 x 1-bit Static RAM + * + * +--------------+ + * A6 |1 ++ 16| A7 + * A5 |2 15| A8 + * RWQ |3 14| A9 + * A1 |4 82S16 13| CEQ + * A2 |5 12| DO + * A3 |6 11| DI + * A4 |7 10| VCC + * A0 |8 9| GND + * +--------------+ + * + * + * Naming conventions follow Intel datasheet + * + */ + +#ifndef NLD_2102A_H_ +#define NLD_2102A_H_ + +#include "nl_setup.h" + +#define RAM_2102A(name, cCEQ, cA0, cA1, cA2, cA3, cA4, cA5, cA6, cA7, cA8, cA9, cRWQ, cDI) \ + NET_REGISTER_DEV(RAM_2102A, name) \ + NET_CONNECT(name, CEQ, cCEQ) \ + NET_CONNECT(name, A0, cA0) \ + NET_CONNECT(name, A1, cA1) \ + NET_CONNECT(name, A2, cA2) \ + NET_CONNECT(name, A3, cA3) \ + NET_CONNECT(name, A4, cA4) \ + NET_CONNECT(name, A5, cA5) \ + NET_CONNECT(name, A6, cA6) \ + NET_CONNECT(name, A7, cA7) \ + NET_CONNECT(name, A8, cA8) \ + NET_CONNECT(name, A9, cA9) \ + NET_CONNECT(name, RWQ, cRWQ) \ + NET_CONNECT(name, DI, cDI) + +#define RAM_2102A_DIP(name) \ + NET_REGISTER_DEV(RAM_2102A_DIP, name) + +#endif /* NLD_2102A_H_ */ diff --git a/src/lib/netlist/devices/nld_2716.cpp b/src/lib/netlist/devices/nld_2716.cpp index 75176119ae7..45cedba592b 100644 --- a/src/lib/netlist/devices/nld_2716.cpp +++ b/src/lib/netlist/devices/nld_2716.cpp @@ -17,7 +17,7 @@ namespace netlist , m_A(*this, {{ "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10" }}) , m_GQ(*this, "GQ") , m_EPQ(*this, "EPQ") - , m_Q(*this, {{ "Q0", "Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7" }}) + , m_D(*this, {{ "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7" }}) , m_last_EPQ(*this, "m_last_EPQ", 1) , m_ROM(*this, "m_ROM", nullptr) { @@ -29,11 +29,11 @@ namespace netlist object_array_t m_A; logic_input_t m_GQ; logic_input_t m_EPQ; - object_array_t m_Q; + object_array_t m_D; state_var m_last_EPQ; - param_rom_t m_ROM; // 16 Kbits, used as 2 Kbit x 8 + param_ptr_t m_ROM; // 16 Kbits, used as 2 Kbit x 8 }; NETLIB_OBJECT_DERIVED(2716_dip, 2716) @@ -55,21 +55,21 @@ namespace netlist register_subalias("20", m_GQ); register_subalias("18", m_EPQ); - register_subalias("9", m_Q[0]); - register_subalias("10", m_Q[1]); - register_subalias("11", m_Q[2]); - register_subalias("13", m_Q[3]); - register_subalias("14", m_Q[4]); - register_subalias("15", m_Q[5]); - register_subalias("16", m_Q[6]); - register_subalias("17", m_Q[7]); + register_subalias("9", m_D[0]); + register_subalias("10", m_D[1]); + register_subalias("11", m_D[2]); + register_subalias("13", m_D[3]); + register_subalias("14", m_D[4]); + register_subalias("15", m_D[5]); + register_subalias("16", m_D[6]); + register_subalias("17", m_D[7]); } }; // FIXME: timing! NETLIB_UPDATE(2716) { - unsigned q = 0xff; + unsigned d = 0xff; netlist_time delay = NLTIME_FROM_NS(450); if (!m_GQ() && !m_EPQ()) @@ -78,7 +78,10 @@ namespace netlist for (std::size_t i=0; i<11; i++) a |= (m_A[i]() << i); - q = m_ROM()[a]; + if (m_ROM() != nullptr) + { + d = ((std::uint_fast8_t*)(m_ROM()))[a]; + } if (m_last_EPQ) delay = NLTIME_FROM_NS(120); @@ -88,7 +91,7 @@ namespace netlist // FIXME: Outputs are tristate. This needs to be properly implemented for (std::size_t i=0; i<8; i++) - m_Q[i].push((q >> i) & 1, delay); + m_D[i].push((d >> i) & 1, delay); } NETLIB_DEVICE_IMPL(2716) diff --git a/src/lib/netlist/devices/nld_2716.h b/src/lib/netlist/devices/nld_2716.h index 144bbf04658..72a02a2166e 100644 --- a/src/lib/netlist/devices/nld_2716.h +++ b/src/lib/netlist/devices/nld_2716.h @@ -13,11 +13,11 @@ * A3 |5 20| GQ * A2 |6 19| A10 * A1 |7 18| EPQ - * A0 |8 17| Q7 - * Q0 |9 16| Q6 - * Q1 |10 15| Q5 - * Q2 |11 14| Q4 - * VSS |12 13| Q3 + * A0 |8 17| D7 + * D0 |9 16| D6 + * D1 |10 15| D5 + * D2 |11 14| D4 + * VSS |12 13| D3 * +----------------+ * * @@ -30,9 +30,23 @@ #include "nl_setup.h" -#define TTL_2716(name) \ - NET_REGISTER_DEV(TTL_2716, name) -#define TTL_2716_DIP(name) \ - NET_REGISTER_DEV(TTL_2716_DIP, name) +#define EPROM_2716(name, cGQ, cEPQ, cA0, cA1, cA2, cA3, cA4, cA5, cA6, cA7, cA8, cA9, cA10) \ + NET_REGISTER_DEV(EPROM_2716, name) \ + NET_CONNECT(name, GQ, cGQ) \ + NET_CONNECT(name, EPQ, cEPQ) \ + NET_CONNECT(name, A0, cA0) \ + NET_CONNECT(name, A1, cA1) \ + NET_CONNECT(name, A2, cA2) \ + NET_CONNECT(name, A3, cA3) \ + NET_CONNECT(name, A4, cA4) \ + NET_CONNECT(name, A5, cA5) \ + NET_CONNECT(name, A6, cA6) \ + NET_CONNECT(name, A7, cA7) \ + NET_CONNECT(name, A8, cA8) \ + NET_CONNECT(name, A9, cA9) \ + NET_CONNECT(name, A10, cA10) + +#define EPROM_2716_DIP(name) \ + NET_REGISTER_DEV(EPROM_2716_DIP, name) #endif /* NLD_2716_H_ */ diff --git a/src/lib/netlist/devices/nld_74365.cpp b/src/lib/netlist/devices/nld_74365.cpp new file mode 100644 index 00000000000..34eafb0856e --- /dev/null +++ b/src/lib/netlist/devices/nld_74365.cpp @@ -0,0 +1,74 @@ +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz +/* + * nld_74365.cpp + * + */ + +#include "nld_74365.h" + +namespace netlist +{ + namespace devices + { + NETLIB_OBJECT(74365) + { + NETLIB_CONSTRUCTOR(74365) + , m_G1Q(*this, "G1Q") + , m_G2Q(*this, "G2Q") + , m_A(*this, {{ "A1", "A2", "A3", "A4", "A5", "A6" }}) + , m_Y(*this, {{ "Y1", "Y2", "Y3", "Y4", "Y5", "Y6" }}) + { + } + + NETLIB_UPDATEI(); + + protected: + logic_input_t m_G1Q; + logic_input_t m_G2Q; + object_array_t m_A; + object_array_t m_Y; + }; + + NETLIB_OBJECT_DERIVED(74365_dip, 74365) + { + NETLIB_CONSTRUCTOR_DERIVED(74365_dip, 74365) + { + register_subalias("1", m_G1Q); + register_subalias("2", m_A[0]); + register_subalias("3", m_Y[0]); + register_subalias("4", m_A[1]); + register_subalias("5", m_Y[1]); + register_subalias("6", m_A[2]); + register_subalias("7", m_Y[2]); + + register_subalias("9", m_A[3]); + register_subalias("10", m_Y[3]); + register_subalias("11", m_A[4]); + register_subalias("12", m_Y[4]); + register_subalias("13", m_A[5]); + register_subalias("14", m_Y[5]); + register_subalias("15", m_G2Q); + + } + }; + + NETLIB_UPDATE(74365) + { + if (!m_G1Q() && !m_G2Q()) + { + for (std::size_t i=0; i<6; i++) + m_Y[i].push(m_A[i](), NLTIME_FROM_NS(20)); // FIXME: Correct timing + } + else + { + for (std::size_t i=0; i<6; i++) + m_Y[i].push(0, NLTIME_FROM_NS(20)); // FIXME: Correct timing + } + } + + NETLIB_DEVICE_IMPL(74365) + NETLIB_DEVICE_IMPL(74365_dip) + + } //namespace devices +} // namespace netlist diff --git a/src/lib/netlist/devices/nld_74365.h b/src/lib/netlist/devices/nld_74365.h new file mode 100644 index 00000000000..65bfd1a2a57 --- /dev/null +++ b/src/lib/netlist/devices/nld_74365.h @@ -0,0 +1,44 @@ +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz +/* + * nld_74365.h + * + * SN74365: Hex Bus Driver with 3-State Outputs + * + * +--------------+ + * G1Q |1 ++ 16| VCC + * A1 |2 15| G2Q + * Y1 |3 14| A6 + * A2 |4 74365 13| Y6 + * Y2 |5 12| A5 + * A3 |6 11| Y5 + * Y3 |7 10| A4 + * GND |8 9| Y4 + * +--------------+ + * + * Naming conventions follow Texas Instruments datasheet + * + * Note: Currently the netlist system does not support proper tristate output, so this + * is not a "real" bus driver, it simply outputs 0 if the chip is not enabled. + */ + +#ifndef NLD_74365_H_ +#define NLD_74365_H_ + +#include "nl_setup.h" + +#define TTL_74365(name, cG1Q, cG2Q, cA1, cA2, cA3, cA4, cA5, cA6) \ + NET_REGISTER_DEV(TTL_74365, name) \ + NET_CONNECT(name, G1Q, cG1Q) \ + NET_CONNECT(name, G2Q, cG2Q) \ + NET_CONNECT(name, A1, cA1) \ + NET_CONNECT(name, A2, cA2) \ + NET_CONNECT(name, A3, cA3) \ + NET_CONNECT(name, A4, cA4) \ + NET_CONNECT(name, A5, cA5) \ + NET_CONNECT(name, A6, cA6) + +#define TTL_74365_DIP(name) \ + NET_REGISTER_DEV(TTL_74365_DIP, name) + +#endif /* NLD_74365_H_ */ diff --git a/src/lib/netlist/devices/nld_82S126.cpp b/src/lib/netlist/devices/nld_82S126.cpp index 29c2813c751..20fc1371c90 100644 --- a/src/lib/netlist/devices/nld_82S126.cpp +++ b/src/lib/netlist/devices/nld_82S126.cpp @@ -30,7 +30,7 @@ namespace netlist logic_input_t m_CE2Q; object_array_t m_O; - param_rom_t m_ROM; // 1024 bits, 32x32, used as 256x4 + param_ptr_t m_ROM; // 1024 bits, 32x32, used as 256x4 }; NETLIB_OBJECT_DERIVED(82S126_dip, 82S126) @@ -68,12 +68,26 @@ namespace netlist for (std::size_t i=0; i<8; i++) a |= (m_A[i]() << i); - o = m_ROM()[a]; + if (m_ROM() != nullptr) + o = ((std::uint_fast8_t*)(m_ROM()))[a]; delay = NLTIME_FROM_NS(50); } - - // FIXME: Outputs are tristate. This needs to be properly implemented +#if 0 + printf("CE1Q%d CE2Q%d %d%d%d%d%d%d%d%d %x\n", + m_CE1Q() ? 1 : 0, + m_CE2Q() ? 1 : 0, + m_A[0]() ? 1 : 0, + m_A[1]() ? 1 : 0, + m_A[2]() ? 1 : 0, + m_A[3]() ? 1 : 0, + m_A[4]() ? 1 : 0, + m_A[5]() ? 1 : 0, + m_A[6]() ? 1 : 0, + m_A[7]() ? 1 : 0, + o); +#endif + // FIXME: Outputs are tristate. This needs to be properly implemented for (std::size_t i=0; i<4; i++) m_O[i].push((o >> i) & 1, delay); } diff --git a/src/lib/netlist/devices/nld_tristate.cpp b/src/lib/netlist/devices/nld_tristate.cpp new file mode 100644 index 00000000000..571f5f8c334 --- /dev/null +++ b/src/lib/netlist/devices/nld_tristate.cpp @@ -0,0 +1,76 @@ +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz +/* + * nld_tristate.cpp + * + */ + +#include "nld_tristate.h" + +namespace netlist +{ + namespace devices + { + NETLIB_OBJECT(tristate) + { + NETLIB_CONSTRUCTOR(tristate) + , m_CEQ(*this, {{ "CEQ1", "CEQ2" }}) + , m_D(*this, {{ "D1", "D2" }}) + , m_Q(*this, "Q") + { + } + + NETLIB_UPDATEI(); + + protected: + object_array_t m_CEQ; + object_array_t m_D; + logic_output_t m_Q; + }; + + NETLIB_OBJECT(tristate3) + { + NETLIB_CONSTRUCTOR(tristate3) + , m_CEQ(*this, {{ "CEQ1", "CEQ2", "CEQ3" }} ) + , m_D(*this, {{ "D1", "D2", "D3" }} ) + , m_Q(*this, "Q") + { + } + + NETLIB_UPDATEI(); + + protected: + object_array_t m_CEQ; + object_array_t m_D; + logic_output_t m_Q; + }; + + NETLIB_UPDATE(tristate) + { + unsigned q = 0; + if (!m_CEQ[0]()) + q |= m_D[0](); + if (!m_CEQ[1]()) + q |= m_D[1](); + + m_Q.push(q, NLTIME_FROM_NS(1)); + } + + NETLIB_UPDATE(tristate3) + { + unsigned q = 0; + if (!m_CEQ[0]()) + q |= m_D[0](); + if (!m_CEQ[1]()) + q |= m_D[1](); + if (!m_CEQ[2]()) + q |= m_D[2](); + + m_Q.push(q, NLTIME_FROM_NS(1)); + } + + NETLIB_DEVICE_IMPL(tristate) + NETLIB_DEVICE_IMPL(tristate3) + + } //namespace devices +} // namespace netlist diff --git a/src/lib/netlist/devices/nld_tristate.h b/src/lib/netlist/devices/nld_tristate.h new file mode 100644 index 00000000000..e0e40491d8f --- /dev/null +++ b/src/lib/netlist/devices/nld_tristate.h @@ -0,0 +1,31 @@ +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz +/* + * nld_tristate.h + * + * tristate: Hack to merge two tri-stated outputs together + * + */ + +#ifndef NLD_TRISTATE_H_ +#define NLD_TRISTATE_H_ + +#include "nl_setup.h" + +#define TTL_TRISTATE(name, cCEQ1, cD1, cCEQ2, cD2) \ + NET_REGISTER_DEV(TTL_TRISTATE, name) \ + NET_CONNECT(name, CEQ1, cCEQ1) \ + NET_CONNECT(name, D1, cD1) \ + NET_CONNECT(name, CEQ2, cCEQ2) \ + NET_CONNECT(name, D2, cD2) + +#define TTL_TRISTATE3(name, cCEQ1, cD1, cCEQ2, cD2, cCEQ3, cD3) \ + NET_REGISTER_DEV(TTL_TRISTATE3, name) \ + NET_CONNECT(name, CEQ1, cCEQ1) \ + NET_CONNECT(name, D1, cD1) \ + NET_CONNECT(name, CEQ2, cCEQ2) \ + NET_CONNECT(name, D2, cD2) \ + NET_CONNECT(name, CEQ3, cCEQ3) \ + NET_CONNECT(name, D3, cD3) + +#endif /* NLD_TRISTATE_H_ */ diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 187dea1dcb5..165ba1c6b48 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -482,7 +482,7 @@ param_template_t::param_template_t(device_t &device, const pstring name, c template class param_template_t; template class param_template_t; template class param_template_t; -template class param_template_t; +template class param_template_t; template class param_template_t; template class param_template_t; diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index e817a32ab83..6d4a001f7fd 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -833,7 +833,7 @@ namespace netlist DOUBLE, INTEGER, LOGIC, - ROM // Special-case which is always initialized at netlist startup time + POINTER // Special-case which is always initialized at MAME startup time }; param_t(const param_type_t atype, device_t &device, const pstring &name); @@ -869,7 +869,7 @@ namespace netlist using param_str_t = param_template_t; using param_logic_t = param_template_t; - using param_rom_t = param_template_t; + using param_ptr_t = param_template_t; class param_model_t : public param_str_t { diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index cd025603be0..b55f662cd79 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -217,8 +217,8 @@ void setup_t::register_and_set_param(pstring name, param_t ¶m) static_cast(param).initial(static_cast(vald)); } break; - case param_t::ROM: - static_cast(param).initial(nullptr); + case param_t::POINTER: + static_cast(param).initial(nullptr); break; case param_t::STRING: case param_t::MODEL: diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 1245f03a391..8241daaa332 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -201,8 +201,8 @@ struct input_t case netlist::param_t::LOGIC: static_cast(m_param)->setTo(static_cast(m_value)); break; - case netlist::param_t::ROM: - static_cast(m_param)->setTo(nullptr); + case netlist::param_t::POINTER: + static_cast(m_param)->setTo(nullptr); break; } } -- cgit v1.2.3-70-g09d2 From f43e45a5cf2833da31bd981ee63ceabd0aa2d1cd Mon Sep 17 00:00:00 2001 From: couriersud Date: Tue, 27 Dec 2016 02:43:14 +0100 Subject: Netlist: Roms now specify an identifier in the netlist. The identifier is used to load data from a source_t implementation. This allos a consistent approach in netlists independent of netlist implementation. Both sources code and parameter code needed quite some rewrite to support this. [Couriersud] --- src/devices/machine/netlist.cpp | 66 +++++++++++++------- src/devices/machine/netlist.h | 47 +++++++++----- src/lib/netlist/devices/nld_2716.cpp | 9 +-- src/lib/netlist/devices/nld_82S126.cpp | 7 +-- src/lib/netlist/nl_base.cpp | 60 +++++++++++------- src/lib/netlist/nl_base.h | 111 +++++++++++++++++++++++++-------- src/lib/netlist/nl_setup.cpp | 46 ++++++++++---- src/lib/netlist/nl_setup.h | 51 ++++++++++----- src/lib/netlist/prg/nltool.cpp | 4 +- src/mame/drivers/atarittl.cpp | 4 +- src/mame/drivers/hazeltin.cpp | 4 +- src/mame/machine/nl_hazelvid.cpp | 2 + src/mame/machine/nl_stuntcyc.cpp | 3 + 13 files changed, 283 insertions(+), 131 deletions(-) (limited to 'src/lib/netlist/prg/nltool.cpp') diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 8b0897d7eea..7ba29e26fb7 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -15,6 +15,7 @@ #include "netlist/nl_factory.h" #include "netlist/nl_parser.h" #include "netlist/devices/net_lib.h" +#include "plib/palloc.h" #include "debugger.h" //#define LOG_DEV_CALLS(x) printf x @@ -225,35 +226,33 @@ void netlist_mame_logic_input_t::device_start() netlist_mame_rom_t::netlist_mame_rom_t(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, NETLIST_ROM_REGION, "Netlist ROM Region", tag, owner, clock, "netlist_rom_region", __FILE__) , netlist_mame_sub_interface(*owner) - , m_param(nullptr) - , m_param_name("") - , m_data_tag(nullptr) - , m_data(nullptr) + , m_name("") + , m_region_tag(nullptr) + , m_offset(0) + , m_size(0) { } -void netlist_mame_rom_t::static_set_params(device_t &device, const char *param_name, const char* data_tag) +void netlist_mame_rom_t::static_set_params(device_t &device, const char *name, const char* region_tag, std::size_t offset, std::size_t size) { - netlist_mame_rom_t &netlist = downcast(device); + netlist_mame_rom_t &r = downcast(device); LOG_DEV_CALLS(("static_set_params %s\n", device.tag())); - netlist.m_param_name = param_name; - netlist.m_data_tag = data_tag; + r.m_name = name; + r.m_region_tag = region_tag; + r.m_offset = offset; + r.m_size = size; } -void netlist_mame_rom_t::device_start() +void netlist_mame_rom_t::custom_netlist_additions(netlist::setup_t &setup) { - LOG_DEV_CALLS(("start %s\n", tag())); - netlist::param_t *p = downcast(this->owner())->setup().find_param(m_param_name); - m_param = dynamic_cast(p); - if (m_param == nullptr) - { - fatalerror("device %s wrong parameter type for %s\n", basetag(), m_param_name.cstr()); - } - - if (memregion(m_data_tag) != nullptr) - m_data = memregion(m_data_tag)->base(); + if (memregion(m_region_tag) == nullptr) + fatalerror("device %s region %s not found\n", basetag(), m_region_tag); + setup.register_source(plib::make_unique_base(setup, + m_name, memregion(m_region_tag)->base() + m_offset, m_size)); +} - m_param->setTo(m_data); +void netlist_mame_rom_t::device_start() +{ } // ---------------------------------------------------------------------------------------- @@ -449,6 +448,17 @@ void netlist_mame_device_t::device_start() nl_register_devices(); + /* let sub-devices add sources and do stuff prior to parsing */ + for (device_t &d : subdevices()) + { + netlist_mame_sub_interface *sdev = dynamic_cast(&d); + if( sdev != nullptr ) + { + LOG_DEV_CALLS(("Preparse subdevice %s/%s\n", d.name(), d.shortname())); + sdev->pre_parse_action(*m_setup); + } + } + m_setup_func(*m_setup); /* let sub-devices tweak the netlist */ @@ -783,9 +793,17 @@ void netlist_mame_sound_device_t::sound_stream_update(sound_stream &stream, stre // memregion source support // ---------------------------------------------------------------------------------------- -bool netlist_source_memregion_t::parse(netlist::setup_t &setup, const pstring &name) +std::unique_ptr netlist_source_memregion_t::stream(const pstring &name) { - memory_region *mem = downcast(setup.netlist()).machine().root_device().memregion(m_name.cstr()); - plib::pimemstream istrm(mem->base(),mem->bytes() ); - return setup.parse_stream(istrm, name); + memory_region *mem = downcast(setup().netlist()).machine().root_device().memregion(m_name.cstr()); + return plib::make_unique_base(mem->base(), mem->bytes()); } + +std::unique_ptr netlist_data_memregion_t::stream(const pstring &name) +{ + if (name == m_name) + return plib::make_unique_base(m_ptr, m_size); + else + return std::unique_ptr(nullptr); +} + diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index 97132dc793a..9428da5d348 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -49,9 +49,9 @@ MCFG_DEVICE_ADD(_basetag ":" _tag, NETLIST_INT_INPUT, 0) \ netlist_mame_int_input_t::static_set_params(*device, _name, _mask, _shift); -#define MCFG_NETLIST_ROM_REGION(_basetag, _tag, _name, _region) \ +#define MCFG_NETLIST_ROM_REGION(_basetag, _tag, _region, _name, _offset, _size) \ MCFG_DEVICE_ADD(_basetag ":" _tag, NETLIST_ROM_REGION, 0) \ - netlist_mame_rom_t::static_set_params(*device, _name ".m_ROM", ":" _region); + netlist_mame_rom_t::static_set_params(*device, _name, ":" _region, _offset, _size); #define MCFG_NETLIST_RAM_POINTER(_basetag, _tag, _name) \ MCFG_DEVICE_ADD(_basetag ":" _tag, NETLIST_RAM_POINTER, 0) \ @@ -76,7 +76,7 @@ #define MEMREGION_SOURCE(_name) \ - setup.register_source(plib::make_unique_base(_name)); + setup.register_source(plib::make_unique_base(setup, _name)); #define NETDEV_ANALOG_CALLBACK_MEMBER(_name) \ void _name(const double data, const attotime &time) @@ -92,16 +92,35 @@ class netlist_source_memregion_t : public netlist::source_t { public: - netlist_source_memregion_t(pstring name) - : netlist::source_t(), m_name(name) + netlist_source_memregion_t(netlist::setup_t &setup, pstring name) + : netlist::source_t(setup), m_name(name) { } - bool parse(netlist::setup_t &setup, const pstring &name) override; + virtual std::unique_ptr stream(const pstring &name) override; private: pstring m_name; }; +class netlist_data_memregion_t : public netlist::source_t +{ +public: + netlist_data_memregion_t(netlist::setup_t &setup, + pstring name, uint8_t *ptr, std::size_t size) + : netlist::source_t(setup, netlist::source_t::DATA) + , m_name(name) + , m_ptr(ptr) + , m_size(size) + { + } + + virtual std::unique_ptr stream(const pstring &name) override; +private: + pstring m_name; + uint8_t *m_ptr; + std::size_t m_size; +}; + class netlist_mame_device_t; class netlist_mame_t : public netlist::netlist_t @@ -325,6 +344,7 @@ public: virtual ~netlist_mame_sub_interface() { } virtual void custom_netlist_additions(netlist::setup_t &setup) { } + virtual void pre_parse_action(netlist::setup_t &setup) { } inline netlist_mame_device_t &nl_owner() const { return *m_owner; } @@ -557,21 +577,18 @@ public: netlist_mame_rom_t(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); virtual ~netlist_mame_rom_t() { } - static void static_set_params(device_t &device, const char *param_name, const char* region_tag); + static void static_set_params(device_t &device, const char *name, const char* region_tag, std::size_t offset, std::size_t size); protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override - { - m_param->setTo(m_data); - } + virtual void custom_netlist_additions(netlist::setup_t &setup) override; private: - netlist::param_ptr_t *m_param; - pstring m_param_name; - const char* m_data_tag; - uint8_t* m_data; + pstring m_name; + const char* m_region_tag; + std::size_t m_offset; + std::size_t m_size; }; // ---------------------------------------------------------------------------------------- diff --git a/src/lib/netlist/devices/nld_2716.cpp b/src/lib/netlist/devices/nld_2716.cpp index 68cf4dcc134..7ba974b92da 100644 --- a/src/lib/netlist/devices/nld_2716.cpp +++ b/src/lib/netlist/devices/nld_2716.cpp @@ -19,7 +19,7 @@ namespace netlist , m_EPQ(*this, "EPQ") , m_D(*this, {{ "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7" }}) , m_last_EPQ(*this, "m_last_EPQ", 1) - , m_ROM(*this, "m_ROM", nullptr) + , m_ROM(*this, "ROM") { } @@ -33,7 +33,7 @@ namespace netlist state_var m_last_EPQ; - param_ptr_t m_ROM; // 16 Kbits, used as 2 Kbit x 8 + param_rom_t m_ROM; // 16 Kbits, used as 2 Kbit x 8 }; NETLIB_OBJECT_DERIVED(2716_dip, 2716) @@ -78,10 +78,7 @@ namespace netlist for (std::size_t i=0; i<11; i++) a |= (m_A[i]() << i); - if (m_ROM() != nullptr) - { - d = ((std::uint_fast8_t*)(m_ROM()))[a]; - } + d = m_ROM[a]; if (m_last_EPQ) delay = NLTIME_FROM_NS(120); diff --git a/src/lib/netlist/devices/nld_82S126.cpp b/src/lib/netlist/devices/nld_82S126.cpp index dd1d6ad0dc8..d3a86ce84ee 100644 --- a/src/lib/netlist/devices/nld_82S126.cpp +++ b/src/lib/netlist/devices/nld_82S126.cpp @@ -18,7 +18,7 @@ namespace netlist , m_CE1Q(*this, "CE1Q") , m_CE2Q(*this, "CE2Q") , m_O(*this, {{"O1", "O2", "O3", "O4" }}) - , m_ROM(*this, "m_ROM", nullptr) + , m_ROM(*this, "ROM") { } @@ -30,7 +30,7 @@ namespace netlist logic_input_t m_CE2Q; object_array_t m_O; - param_ptr_t m_ROM; // 1024 bits, 32x32, used as 256x4 + param_rom_t m_ROM; // 1024 bits, 32x32, used as 256x4 }; NETLIB_OBJECT_DERIVED(82S126_dip, 82S126) @@ -68,8 +68,7 @@ namespace netlist for (std::size_t i=0; i<8; i++) a |= (m_A[i]() << i); - if (m_ROM() != nullptr) - o = ((std::uint_fast8_t*)(m_ROM()))[a]; + o = m_ROM[a]; delay = NLTIME_FROM_NS(50); } diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 165ba1c6b48..a786c879286 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -464,27 +464,7 @@ void netlist_t::print_stats() const } } -// ---------------------------------------------------------------------------------------- -// Parameters ... -// ---------------------------------------------------------------------------------------- - -template -param_template_t::param_template_t(device_t &device, const pstring name, const C val) -: param_t(T, device, device.name() + "." + name) -, m_param(val) -{ - /* pstrings not yet supported, these need special logic */ - if (T != param_t::STRING && T != param_t::MODEL) - netlist().save(*this, m_param, "m_param"); - device.setup().register_and_set_param(device.name() + "." + name, *this); -} -template class param_template_t; -template class param_template_t; -template class param_template_t; -template class param_template_t; -template class param_template_t; -template class param_template_t; // ---------------------------------------------------------------------------------------- // core_device_t @@ -905,15 +885,45 @@ logic_input_t::logic_input_t(core_device_t &dev, const pstring &aname) } // ---------------------------------------------------------------------------------------- -// param_t & friends +// Parameters ... // ---------------------------------------------------------------------------------------- param_t::param_t(const param_type_t atype, device_t &device, const pstring &name) - : device_object_t(device, name, PARAM) + : device_object_t(device, device.name() + "." + name, PARAM) , m_param_type(atype) { } +void param_t::register_and_set() +{ + dynamic_cast(device()).setup().register_and_set_param(this->name(), *this); +} + +void param_t::changed_and_update() +{ + changed(); + device().update_param(); + if (device().needs_update_after_param_change()) + device().update_dev(); +} + +template +param_template_t::param_template_t(device_t &device, const pstring name, const C val) +: param_t(T, device, name) +, m_param(val) +{ + /* pstrings not yet supported, these need special logic */ + if (T != param_t::STRING && T != param_t::MODEL) + netlist().save(*this, m_param, "m_param"); +} + +template class param_template_t; +template class param_template_t; +template class param_template_t; +template class param_template_t; +template class param_template_t; +//template class param_template_t; + const pstring param_model_t::model_type() { if (m_map.size() == 0) @@ -936,6 +946,12 @@ nl_double param_model_t::model_value(const pstring &entity) return netlist().setup().model_value(m_map, entity); } +std::unique_ptr param_data_t::stream() +{ + return device().netlist().setup().get_data_stream(Value()); +} + + namespace devices { diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index fe799af4c2c..88b09658f2d 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -21,6 +21,7 @@ #include "plib/pdynlib.h" #include "plib/pstate.h" #include "plib/pfmtlog.h" +#include "plib/pstream.h" // ---------------------------------------------------------------------------------------- // Type definitions @@ -842,6 +843,11 @@ namespace netlist param_type_t param_type() const { return m_param_type; } + protected: + virtual void changed() { } + void changed_and_update(); + void register_and_set(); + private: const param_type_t m_param_type; }; @@ -849,41 +855,70 @@ namespace netlist template class param_template_t : public param_t { - P_PREVENT_COPYING(param_template_t) public: param_template_t(device_t &device, const pstring name, const C val); const C operator()() const { return Value(); } - void setTo(const C ¶m); - void initial(const C &val) { m_param = val; } + void setTo(const C ¶m) + { + if (m_param != param) + { + m_param = param; + changed_and_update(); + } + } + void initial(const C &val) { m_param = val; changed(); } protected: C Value() const { return m_param; } - virtual void changed() { } C m_param; private: }; - using param_double_t = param_template_t; - using param_int_t = param_template_t; - using param_str_t = param_template_t; + template + class param_template_final_t final : public param_template_t + { + public: + param_template_final_t(device_t &device, const pstring name, const C val) + : param_template_t(device, name, val) + { + this->register_and_set(); + } + }; + + using param_double_t = param_template_final_t; + using param_int_t = param_template_final_t; - using param_logic_t = param_template_t; - using param_ptr_t = param_template_t; + using param_logic_t = param_template_final_t; + using param_ptr_t = param_template_final_t; + using param_str_base_t = param_template_t; - class param_model_t : public param_str_t + class param_str_t final : public param_str_base_t + { + public: + param_str_t(device_t &device, const pstring name, const pstring val) + : param_str_base_t(device, name, val) + { + register_and_set(); + } + }; + + class param_model_t final : public param_str_base_t { public: param_model_t(device_t &device, const pstring name, const pstring val) - : param_str_t(device, name, val) { } + : param_str_base_t(device, name, val) + { + register_and_set(); + } /* these should be cached! */ nl_double model_value(const pstring &entity); const pstring model_value_str(const pstring &entity); const pstring model_type(); protected: - void changed() override + virtual void changed() override { m_map.clear(); } @@ -891,6 +926,45 @@ namespace netlist model_map_t m_map; }; + class param_data_t : public param_str_base_t + { + public: + + typedef uint8_t type; + + param_data_t(device_t &device, const pstring name) + : param_str_base_t(device, name, "") { } + + std::unique_ptr stream(); + + protected: + virtual void changed() override { } + private: + }; + + + template + class param_rom_t final: public param_data_t + { + public: + + param_rom_t(device_t &device, const pstring name) + : param_data_t(device, name) + { + register_and_set(); + } + + const ST & operator[] (std::size_t n) { return m_data[n]; } + + protected: + virtual void changed() override + { + stream()->read(&m_data[0],1< - inline void param_template_t::setTo(const C ¶m) - { - if (m_param != param) - { - m_param = param; - changed(); - device().update_param(); - if (device().needs_update_after_param_change()) - device().update_dev(); - } - } - inline bool detail::core_terminal_t::is_logic() const noexcept { return dynamic_cast(this) != nullptr; diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index f6a34729c22..e3a878a5f16 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -221,13 +221,12 @@ void setup_t::register_and_set_param(pstring name, param_t ¶m) static_cast(param).initial(nullptr); break; case param_t::STRING: - case param_t::MODEL: { static_cast(param).initial(val); } break; - //default: - // log().fatal("Parameter is not supported {1} : {2}\n", name, val); + default: + log().fatal("Parameter is not supported {1} : {2}\n", name, val); } } if (!m_params.insert({param.name(), param_ref_t(param.name(), param.device(), param)}).second) @@ -975,12 +974,28 @@ void setup_t::include(const pstring &netlist_name) { for (auto &source : m_sources) { - if (source->parse(*this, netlist_name)) + if (source->parse(netlist_name)) return; } log().fatal("unable to find {1} in source collection", netlist_name); } +std::unique_ptr setup_t::get_data_stream(const pstring name) +{ + for (auto &source : m_sources) + { + if (source->type() == source_t::DATA) + { + auto strm = source->stream(name); + if (strm) + return strm; + } + } + log().fatal("unable to find data named {1} in source collection", name); + return std::unique_ptr(nullptr); +} + + bool setup_t::parse_stream(plib::pistream &istrm, const pstring &name) { plib::pomemstream ostrm; @@ -1002,22 +1017,27 @@ void setup_t::register_define(pstring defstr) // base sources // ---------------------------------------------------------------------------------------- -bool source_string_t::parse(setup_t &setup, const pstring &name) +bool source_t::parse(const pstring &name) +{ + if (m_type != SOURCE) + return false; + else + return m_setup.parse_stream(*stream(name), name); +} + +std::unique_ptr source_string_t::stream(const pstring &name) { - plib::pimemstream istrm(m_str.cstr(), m_str.len()); - return setup.parse_stream(istrm, name); + return plib::make_unique_base(m_str.cstr(), m_str.len()); } -bool source_mem_t::parse(setup_t &setup, const pstring &name) +std::unique_ptr source_mem_t::stream(const pstring &name) { - plib::pimemstream istrm(m_str.cstr(), m_str.len()); - return setup.parse_stream(istrm, name); + return plib::make_unique_base(m_str.cstr(), m_str.len()); } -bool source_file_t::parse(setup_t &setup, const pstring &name) +std::unique_ptr source_file_t::stream(const pstring &name) { - plib::pifilestream istrm(m_filename); - return setup.parse_stream(istrm, name); + return plib::make_unique_base(m_filename); } } diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index aec2da2dcd8..9625b192305 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -67,7 +67,7 @@ void NETLIST_NAME(name)(netlist::setup_t &setup) \ #define NETLIST_END() } #define LOCAL_SOURCE(name) \ - setup.register_source(plib::make_unique_base(# name, &NETLIST_NAME(name))); + setup.register_source(plib::make_unique_base(setup, # name, &NETLIST_NAME(name))); #define LOCAL_LIB_ENTRY(name) \ LOCAL_SOURCE(name) \ @@ -149,16 +149,28 @@ namespace netlist class source_t { public: + enum type_t + { + SOURCE, + DATA + }; + using list_t = std::vector>; - source_t() + source_t(setup_t &setup, const type_t type = SOURCE) + : m_setup(setup), m_type(type) {} virtual ~source_t() { } - virtual bool parse(setup_t &setup, const pstring &name) = 0; + virtual bool parse(const pstring &name); + virtual std::unique_ptr stream(const pstring &name) = 0; + setup_t &setup() { return m_setup; } + type_t type() const { return m_type; } private: + setup_t &m_setup; + const type_t m_type; }; // ---------------------------------------------------------------------------------------- @@ -223,6 +235,7 @@ namespace netlist /* parse a source */ void include(const pstring &netlist_name); + std::unique_ptr get_data_stream(const pstring name); bool parse_stream(plib::pistream &istrm, const pstring &name); @@ -307,12 +320,12 @@ namespace netlist { public: - source_string_t(const pstring &source) - : source_t(), m_str(source) + source_string_t(setup_t &setup, const pstring &source) + : source_t(setup), m_str(source) { } - bool parse(setup_t &setup, const pstring &name) override; + virtual std::unique_ptr stream(const pstring &name) override; private: pstring m_str; @@ -322,12 +335,12 @@ namespace netlist { public: - source_file_t(const pstring &filename) - : source_t(), m_filename(filename) + source_file_t(setup_t &setup, const pstring &filename) + : source_t(setup), m_filename(filename) { } - bool parse(setup_t &setup, const pstring &name) override; + virtual std::unique_ptr stream(const pstring &name) override; private: pstring m_filename; @@ -336,12 +349,12 @@ namespace netlist class source_mem_t : public source_t { public: - source_mem_t(const char *mem) - : source_t(), m_str(mem) + source_mem_t(setup_t &setup, const char *mem) + : source_t(setup), m_str(mem) { } - bool parse(setup_t &setup, const pstring &name) override; + virtual std::unique_ptr stream(const pstring &name) override; private: pstring m_str; @@ -350,23 +363,29 @@ namespace netlist class source_proc_t : public source_t { public: - source_proc_t(pstring name, void (*setup_func)(setup_t &)) - : source_t(), + source_proc_t(setup_t &setup, pstring name, void (*setup_func)(setup_t &)) + : source_t(setup), m_setup_func(setup_func), m_setup_func_name(name) { } - bool parse(setup_t &setup, const pstring &name) override + virtual bool parse(const pstring &name) override { if (name == m_setup_func_name) { - m_setup_func(setup); + m_setup_func(setup()); return true; } else return false; } + + virtual std::unique_ptr stream(const pstring &name) override + { + std::unique_ptr p(nullptr); + return p; + } private: void (*m_setup_func)(setup_t &); pstring m_setup_func_name; diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 8241daaa332..c58a5d61c1c 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -117,7 +117,7 @@ public: m_setup->register_define(d); m_setup->register_source(plib::make_unique_base(filename)); + netlist::source_file_t>(*m_setup, filename)); m_setup->include(name); log_setup(logs); @@ -316,7 +316,7 @@ static void listdevices(tool_options_t &opts) netlist::factory_list_t &list = nt.setup().factory(); nt.setup().register_source(plib::make_unique_base("dummy", &netlist_dummy)); + netlist::source_proc_t>(nt.setup(), "dummy", &netlist_dummy)); nt.setup().include("dummy"); diff --git a/src/mame/drivers/atarittl.cpp b/src/mame/drivers/atarittl.cpp index ddd3d54061a..c414f7471b3 100644 --- a/src/mame/drivers/atarittl.cpp +++ b/src/mame/drivers/atarittl.cpp @@ -331,8 +331,8 @@ static MACHINE_CONFIG_START( stuntcyc, stuntcyc_state ) MCFG_DEVICE_ADD("maincpu", NETLIST_CPU, STUNTCYC_NL_CLOCK) MCFG_NETLIST_SETUP(stuntcyc) - MCFG_NETLIST_ROM_REGION("maincpu", "hf1", "hf1", "hf1") - MCFG_NETLIST_ROM_REGION("maincpu", "d7", "d7", "d7") + MCFG_NETLIST_ROM_REGION("maincpu", "hf1", "hf1", "004275.f1", 0x0000, 0x0200) + MCFG_NETLIST_ROM_REGION("maincpu", "d7", "d7", "004811.d7", 0x0000, 0x0020) //MCFG_NETLIST_ANALOG_OUTPUT("maincpu", "vid0", "VIDEO_OUT", fixedfreq_device, update_vid, "fixfreq") MCFG_NETLIST_LOGIC_OUTPUT("maincpu", "probe_bit0", "probe_bit0", stuntcyc_state, probe_bit0_cb, "") diff --git a/src/mame/drivers/hazeltin.cpp b/src/mame/drivers/hazeltin.cpp index 6c4a20110d1..c39d5f5a104 100644 --- a/src/mame/drivers/hazeltin.cpp +++ b/src/mame/drivers/hazeltin.cpp @@ -712,8 +712,8 @@ static MACHINE_CONFIG_START( hazl1500, hazl1500_state ) MCFG_DEVICE_ADD(NETLIST_TAG, NETLIST_CPU, VIDEOBRD_CLOCK) MCFG_NETLIST_SETUP(hazelvid) - MCFG_NETLIST_ROM_REGION(NETLIST_TAG, VIDEO_PROM_TAG, VIDEO_PROM_TAG, VIDEO_PROM_TAG) - MCFG_NETLIST_ROM_REGION(NETLIST_TAG, CHAR_EPROM_TAG, CHAR_EPROM_TAG, CHAR_EPROM_TAG) + MCFG_NETLIST_ROM_REGION(NETLIST_TAG, VIDEO_PROM_TAG, VIDEO_PROM_TAG, "u90_702128_82s129.bin", 0x0000, 0x0100) + MCFG_NETLIST_ROM_REGION(NETLIST_TAG, CHAR_EPROM_TAG, CHAR_EPROM_TAG, "u83_chr.bin", 0x0000, 0x0800) // First 1K MCFG_NETLIST_RAM_POINTER(NETLIST_TAG, "u22", "u22") diff --git a/src/mame/machine/nl_hazelvid.cpp b/src/mame/machine/nl_hazelvid.cpp index e6c3a1180dd..acfb9a5e625 100644 --- a/src/mame/machine/nl_hazelvid.cpp +++ b/src/mame/machine/nl_hazelvid.cpp @@ -49,6 +49,7 @@ NETLIST_START(hazelvid) /* signal lookup PROM */ PROM_82S126(u71, low, low, u70.QA, u70.QB, u70.QC, u70.QD, u69.QA, u69.QB, u69.QC, low) + PARAM(u71.ROM, "u90_702128_82s129.bin") /* signal decoding */ TTL_9334(u72, high, u81.Q1Q, u71.O4, u71.O1, u71.O2, u71.O3) @@ -215,6 +216,7 @@ NETLIST_START(hazelvid) ALIAS(fgbit_q, u56.Q3Q) EPROM_2716(u78, low, low, lc20, lc21, lc22, lc23, u66.Q1, u66.Q2, u66.Q3, u66.Q4, u66.Q5, u66.Q6, u56.Q1) + PARAM(u78.ROM, "u83_chr.bin") TTL_74166(u77, video_clk, low, ndot, low, u78.D0, u78.D1, u78.D2, u78.D3, u78.D4, u78.D5, u78.D6, low, clr_vid_sr) ALIAS(raw_dot, u77.QH) diff --git a/src/mame/machine/nl_stuntcyc.cpp b/src/mame/machine/nl_stuntcyc.cpp index f4a48347650..ee4227932c8 100644 --- a/src/mame/machine/nl_stuntcyc.cpp +++ b/src/mame/machine/nl_stuntcyc.cpp @@ -119,6 +119,7 @@ NETLIST_START(stuntcyc) TTL_9322(J1, HSYNC, V4, P, V3, 4V, V1, 1V, V2, 2V, GROUND) PROM_82S115(hf1, GROUND, P, J1.Y3, J1.Y4, J1.Y2, J1.Y1, H2_2.Q, H2_1.Q, R2, R3, R4, P) + PARAM(hf1.ROM, "004275.f1") CLOCK(PROBECLK, 7129200) ALIAS(probe_bit0, WHITE_VIDEO) @@ -447,6 +448,8 @@ NETLIST_START(stuntcyc) ALIAS(SCORE_2, K6_1.Q) PROM_82S123(d7, GROUND, S1, S2, S3, S4, S5) + PARAM(d7.ROM, "004811.d7") + ALIAS(MAX_SCORE_Q, d7.O6) TTL_7410_NAND(D6_1, 256H_Q, 128H, 128H) -- cgit v1.2.3-70-g09d2 From 28a734436e76d590649bf1862e4f69826bdb0df4 Mon Sep 17 00:00:00 2001 From: couriersud Date: Tue, 27 Dec 2016 11:24:50 +0100 Subject: Added "-r" option to nltool to pass path to a folder containing rom files. Multiple "-r" options may be given. Zip files are not supported, just individual files. [Couriersud] --- src/lib/netlist/prg/nltool.cpp | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'src/lib/netlist/prg/nltool.cpp') diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index c58a5d61c1c..86e01b90ca8 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -30,6 +30,7 @@ public: opt_cmd (*this, "c", "cmd", "run", "run:convert:listdevices:static", "run|convert|listdevices|static"), opt_file(*this, "f", "file", "-", "file to process (default is stdin)"), opt_defines(*this, "D", "define", "predefine value as macro, e.g. -Dname=value. If '=value' is omitted predefine it as 1. This option may be specified repeatedly."), + opt_rfolders(*this, "r", "rom", "where to look for files"), opt_verb(*this, "v", "verbose", "be verbose - this produces lots of output"), opt_quiet(*this, "q", "quiet", "be quiet - no warnings"), opt_version(*this, "", "version", "display version and exit"), @@ -53,6 +54,7 @@ public: plib::option_str_limit opt_cmd; plib::option_str opt_file; plib::option_vec opt_defines; + plib::option_vec opt_rfolders; plib::option_bool opt_verb; plib::option_bool opt_quiet; plib::option_bool opt_version; @@ -87,6 +89,36 @@ NETLIST_END() CORE IMPLEMENTATION ***************************************************************************/ +class netlist_data_folder_t : public netlist::source_t +{ +public: + netlist_data_folder_t(netlist::setup_t &setup, + pstring folder) + : netlist::source_t(setup, netlist::source_t::DATA) + , m_folder(folder) + { + } + + virtual std::unique_ptr stream(const pstring &file) override + { + pstring name = m_folder + "/" + file; + try + { + auto strm = plib::make_unique_base(name); + return strm; + } + catch (plib::pexception e) + { + + } + return std::unique_ptr(nullptr); + } + +private: + pstring m_folder; +}; + + class netlist_tool_t : public netlist::netlist_t { public: @@ -109,13 +141,17 @@ public: void read_netlist(const pstring &filename, const pstring &name, const std::vector &logs, - const std::vector &defines) + const std::vector &defines, + const std::vector &roms) { // read the netlist ... for (auto & d : defines) m_setup->register_define(d); + for (auto & r : roms) + m_setup->register_source(plib::make_unique_base(*m_setup, r)); + m_setup->register_source(plib::make_unique_base(*m_setup, filename)); m_setup->include(name); @@ -249,7 +285,7 @@ static void run(tool_options_t &opts) nt.read_netlist(opts.opt_file(), opts.opt_name(), opts.opt_logs(), - opts.opt_defines()); + opts.opt_defines(), opts.opt_rfolders()); std::vector inps = read_input(nt.setup(), opts.opt_inp()); @@ -292,7 +328,7 @@ static void static_compile(tool_options_t &opts) nt.read_netlist(opts.opt_file(), opts.opt_name(), opts.opt_logs(), - opts.opt_defines()); + opts.opt_defines(), opts.opt_rfolders()); nt.solver()->create_solver_code(pout_strm); -- cgit v1.2.3-70-g09d2 From 016535b3d0b2a3e4d363a2a7b96fe171b8136916 Mon Sep 17 00:00:00 2001 From: couriersud Date: Tue, 27 Dec 2016 15:19:18 +0100 Subject: Simplify. (nw) --- src/lib/netlist/nl_base.cpp | 59 +++++++++++--------- src/lib/netlist/nl_base.h | 119 +++++++++++++++++++++-------------------- src/lib/netlist/nl_setup.cpp | 67 +++++++++++------------ src/lib/netlist/nl_setup.h | 5 +- src/lib/netlist/prg/nltool.cpp | 5 +- 5 files changed, 135 insertions(+), 120 deletions(-) (limited to 'src/lib/netlist/prg/nltool.cpp') diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index a786c879286..709e41f96f9 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -892,38 +892,16 @@ param_t::param_t(const param_type_t atype, device_t &device, const pstring &name : device_object_t(device, device.name() + "." + name, PARAM) , m_param_type(atype) { + device.setup().register_param(this->name(), *this); } -void param_t::register_and_set() +void param_t::update_param() { - dynamic_cast(device()).setup().register_and_set_param(this->name(), *this); -} - -void param_t::changed_and_update() -{ - changed(); device().update_param(); if (device().needs_update_after_param_change()) device().update_dev(); } -template -param_template_t::param_template_t(device_t &device, const pstring name, const C val) -: param_t(T, device, name) -, m_param(val) -{ - /* pstrings not yet supported, these need special logic */ - if (T != param_t::STRING && T != param_t::MODEL) - netlist().save(*this, m_param, "m_param"); -} - -template class param_template_t; -template class param_template_t; -template class param_template_t; -template class param_template_t; -template class param_template_t; -//template class param_template_t; - const pstring param_model_t::model_type() { if (m_map.size() == 0) @@ -931,6 +909,39 @@ const pstring param_model_t::model_type() return m_map["COREMODEL"]; } +param_str_t::param_str_t(device_t &device, const pstring name, const pstring val) +: param_t(param_t::STRING, device, name) +{ + m_param = device.setup().get_initial_param_val(this->name(),val); +} + +param_double_t::param_double_t(device_t &device, const pstring name, const double val) +: param_t(param_t::DOUBLE, device, name) +{ + m_param = device.setup().get_initial_param_val(this->name(),val); + netlist().save(*this, m_param, "m_param"); +} + +param_int_t::param_int_t(device_t &device, const pstring name, const int val) +: param_t(param_t::INTEGER, device, name) +{ + m_param = device.setup().get_initial_param_val(this->name(),val); + netlist().save(*this, m_param, "m_param"); +} + +param_logic_t::param_logic_t(device_t &device, const pstring name, const bool val) +: param_t(param_t::LOGIC, device, name) +{ + m_param = device.setup().get_initial_param_val(this->name(),val); + netlist().save(*this, m_param, "m_param"); +} + +param_ptr_t::param_ptr_t(device_t &device, const pstring name, uint8_t * val) +: param_t(param_t::POINTER, device, name) +{ + m_param = val; //device.setup().get_initial_param_val(this->name(),val); + //netlist().save(*this, m_param, "m_param"); +} const pstring param_model_t::model_value_str(const pstring &entity) { diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 88b09658f2d..3f315fe603b 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -830,7 +830,6 @@ namespace netlist public: enum param_type_t { - MODEL, STRING, DOUBLE, INTEGER, @@ -844,105 +843,109 @@ namespace netlist param_type_t param_type() const { return m_param_type; } protected: - virtual void changed() { } - void changed_and_update(); - void register_and_set(); + void update_param(); + + template + void set(C &p, const C v) + { + if (p != v) + { + p = v; + update_param(); + } + } private: const param_type_t m_param_type; }; - template - class param_template_t : public param_t + class param_ptr_t final: public param_t { public: - param_template_t(device_t &device, const pstring name, const C val); - - const C operator()() const { return Value(); } - - void setTo(const C ¶m) - { - if (m_param != param) - { - m_param = param; - changed_and_update(); - } - } - void initial(const C &val) { m_param = val; changed(); } - - protected: - C Value() const { return m_param; } - C m_param; + param_ptr_t(device_t &device, const pstring name, std::uint8_t* val); + std::uint8_t * operator()() const { return m_param; } + void setTo(std::uint8_t *param) { set(m_param, param); } private: + std::uint8_t* m_param; }; - template - class param_template_final_t final : public param_template_t + class param_logic_t final: public param_t { public: - param_template_final_t(device_t &device, const pstring name, const C val) - : param_template_t(device, name, val) - { - this->register_and_set(); - } + param_logic_t(device_t &device, const pstring name, const bool val); + const bool operator()() const { return m_param; } + void setTo(const bool ¶m) { set(m_param, param); } + private: + bool m_param; }; - using param_double_t = param_template_final_t; - using param_int_t = param_template_final_t; + class param_int_t final: public param_t + { + public: + param_int_t(device_t &device, const pstring name, const int val); + const int operator()() const { return m_param; } + void setTo(const int ¶m) { set(m_param, param); } + private: + int m_param; + }; - using param_logic_t = param_template_final_t; - using param_ptr_t = param_template_final_t; - using param_str_base_t = param_template_t; + class param_double_t final: public param_t + { + public: + param_double_t(device_t &device, const pstring name, const double val); + const double operator()() const { return m_param; } + void setTo(const double ¶m) { set(m_param, param); } + private: + double m_param; + }; - class param_str_t final : public param_str_base_t + class param_str_t : public param_t { public: - param_str_t(device_t &device, const pstring name, const pstring val) - : param_str_base_t(device, name, val) + param_str_t(device_t &device, const pstring name, const pstring val); + const pstring operator()() const { return Value(); } + void setTo(const pstring ¶m) { - register_and_set(); + if (m_param != param) + { + m_param = param; + changed(); + update_param(); + } } + protected: + virtual void changed() { } + pstring Value() const { return m_param; } + private: + pstring m_param; }; - class param_model_t final : public param_str_base_t + class param_model_t final : public param_str_t { public: param_model_t(device_t &device, const pstring name, const pstring val) - : param_str_base_t(device, name, val) - { - register_and_set(); - } + : param_str_t(device, name, val) { } /* these should be cached! */ nl_double model_value(const pstring &entity); const pstring model_value_str(const pstring &entity); const pstring model_type(); protected: - virtual void changed() override - { - m_map.clear(); - } + virtual void changed() override { m_map.clear(); } private: model_map_t m_map; }; - class param_data_t : public param_str_base_t + class param_data_t : public param_str_t { public: - - typedef uint8_t type; - param_data_t(device_t &device, const pstring name) - : param_str_base_t(device, name, "") { } - + : param_str_t(device, name, "") { } std::unique_ptr stream(); - protected: virtual void changed() override { } - private: }; - template class param_rom_t final: public param_data_t { @@ -951,7 +954,7 @@ namespace netlist param_rom_t(device_t &device, const pstring name) : param_data_t(device, name) { - register_and_set(); + stream()->read(&m_data[0],1<second; + else + return def; +} + +double setup_t::get_initial_param_val(const pstring name, const double def) { auto i = m_param_values.find(name); if (i != m_param_values.end()) { - const pstring val = i->second; - log().debug("Found parameter ... {1} : {1}\n", name, val); - switch (param.param_type()) - { - case param_t::DOUBLE: - { - double vald = 0; - if (sscanf(val.cstr(), "%lf", &vald) != 1) - log().fatal("Invalid number conversion {1} : {2}\n", name, val); - static_cast(param).initial(vald); - } - break; - case param_t::INTEGER: - case param_t::LOGIC: - { - double vald = 0; - if (sscanf(val.cstr(), "%lf", &vald) != 1) - log().fatal("Invalid number conversion {1} : {2}\n", name, val); - static_cast(param).initial(static_cast(vald)); - } - break; - case param_t::POINTER: - static_cast(param).initial(nullptr); - break; - case param_t::STRING: - { - static_cast(param).initial(val); - } - break; - default: - log().fatal("Parameter is not supported {1} : {2}\n", name, val); - } + double vald = 0; + if (sscanf(i->second.cstr(), "%lf", &vald) != 1) + log().fatal("Invalid number conversion {1} : {2}\n", name, i->second); + return vald; } + else + return def; +} + +int setup_t::get_initial_param_val(const pstring name, const int def) +{ + auto i = m_param_values.find(name); + if (i != m_param_values.end()) + { + double vald = 0; + if (sscanf(i->second.cstr(), "%lf", &vald) != 1) + log().fatal("Invalid number conversion {1} : {2}\n", name, i->second); + return static_cast(vald); + } + else + return def; +} + +void setup_t::register_param(pstring name, param_t ¶m) +{ if (!m_params.insert({param.name(), param_ref_t(param.name(), param.device(), param)}).second) log().fatal("Error adding parameter {1} to parameter list\n", name); } diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 9625b192305..8c690b36b6d 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -193,7 +193,10 @@ namespace netlist pstring build_fqn(const pstring &obj_name) const; - void register_and_set_param(pstring name, param_t ¶m); + void register_param(pstring name, param_t ¶m); + pstring get_initial_param_val(const pstring name, const pstring def); + double get_initial_param_val(const pstring name, const double def); + int get_initial_param_val(const pstring name, const int def); void register_term(detail::core_terminal_t &obj); diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 86e01b90ca8..fbfa3a50c5c 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -225,8 +225,8 @@ struct input_t { switch (m_param->param_type()) { - case netlist::param_t::MODEL: case netlist::param_t::STRING: + case netlist::param_t::POINTER: throw netlist::nl_exception(plib::pfmt("param {1} is not numeric\n")(m_param->name())); case netlist::param_t::DOUBLE: static_cast(m_param)->setTo(m_value); @@ -237,9 +237,6 @@ struct input_t case netlist::param_t::LOGIC: static_cast(m_param)->setTo(static_cast(m_value)); break; - case netlist::param_t::POINTER: - static_cast(m_param)->setTo(nullptr); - break; } } -- cgit v1.2.3-70-g09d2