mirror of
https://github.com/holub/mame
synced 2025-10-04 16:34:53 +03:00
netlist: remove locked-in context from sources. (nw)
This commit is contained in:
parent
11c3b63c41
commit
17d784d83b
@ -213,22 +213,26 @@ private:
|
||||
class netlist_source_memregion_t : public netlist::source_t
|
||||
{
|
||||
public:
|
||||
netlist_source_memregion_t(netlist::nlparse_t &setup, pstring name)
|
||||
: netlist::source_t(setup), m_name(name)
|
||||
netlist_source_memregion_t(device_t &dev, pstring name)
|
||||
: netlist::source_t(), m_dev(dev), m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<plib::pistream> stream(const pstring &name) override;
|
||||
private:
|
||||
device_t &m_dev;
|
||||
pstring m_name;
|
||||
};
|
||||
|
||||
class netlist_data_memregions_t : public netlist::source_t
|
||||
{
|
||||
public:
|
||||
netlist_data_memregions_t(netlist::setup_t &setup);
|
||||
netlist_data_memregions_t(device_t &dev);
|
||||
|
||||
virtual std::unique_ptr<plib::pistream> stream(const pstring &name) override;
|
||||
|
||||
private:
|
||||
device_t &m_dev;
|
||||
};
|
||||
|
||||
|
||||
@ -238,18 +242,20 @@ public:
|
||||
|
||||
std::unique_ptr<plib::pistream> netlist_source_memregion_t::stream(const pstring &name)
|
||||
{
|
||||
memory_region *mem = static_cast<netlist_mame_device::netlist_mame_t &>(setup().setup().exec()).machine().root_device().memregion(m_name.c_str());
|
||||
//memory_region *mem = static_cast<netlist_mame_device::netlist_mame_t &>(setup().setup().exec()).machine().root_device().memregion(m_name.c_str());
|
||||
memory_region *mem = m_dev.machine().root_device().memregion(m_name.c_str());
|
||||
return plib::make_unique<plib::pimemstream>(mem->base(), mem->bytes());
|
||||
}
|
||||
|
||||
netlist_data_memregions_t::netlist_data_memregions_t(netlist::setup_t &setup)
|
||||
: netlist::source_t(setup, netlist::source_t::DATA)
|
||||
netlist_data_memregions_t::netlist_data_memregions_t(device_t &dev)
|
||||
: netlist::source_t(netlist::source_t::DATA), m_dev(dev)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<plib::pistream> netlist_data_memregions_t::stream(const pstring &name)
|
||||
{
|
||||
memory_region *mem = static_cast<netlist_mame_device::netlist_mame_t &>(setup().setup().exec()).parent().memregion(name.c_str());
|
||||
//memory_region *mem = static_cast<netlist_mame_device::netlist_mame_t &>(setup().setup().exec()).parent().memregion(name.c_str());
|
||||
memory_region *mem = m_dev.memregion(name.c_str());
|
||||
if (mem != nullptr)
|
||||
{
|
||||
return plib::make_unique<plib::pimemstream>(mem->base(), mem->bytes());
|
||||
@ -454,9 +460,9 @@ netlist::setup_t &netlist_mame_device::setup()
|
||||
return m_netlist->nlstate().setup();
|
||||
}
|
||||
|
||||
void netlist_mame_device::register_memregion_source(netlist::nlparse_t &setup, const char *name)
|
||||
void netlist_mame_device::register_memregion_source(netlist::nlparse_t &setup, device_t &dev, const char *name)
|
||||
{
|
||||
setup.register_source(plib::make_unique<netlist_source_memregion_t>(setup, pstring(name)));
|
||||
setup.register_source(plib::make_unique<netlist_source_memregion_t>(dev, pstring(name)));
|
||||
}
|
||||
|
||||
void netlist_mame_analog_input_device::write(const double val)
|
||||
@ -826,12 +832,6 @@ netlist_mame_device::~netlist_mame_device()
|
||||
LOGDEVCALLS("~netlist_mame_device\n");
|
||||
}
|
||||
|
||||
void netlist_mame_device::set_constructor(void (*setup_func)(netlist::nlparse_t &))
|
||||
{
|
||||
if (LOG_DEV_CALLS) logerror("set_constructor\n");
|
||||
m_setup_func = setup_func;
|
||||
}
|
||||
|
||||
void netlist_mame_device::device_config_complete()
|
||||
{
|
||||
LOGDEVCALLS("device_config_complete %s\n", this->mconfig().gamedrv().name);
|
||||
@ -867,7 +867,7 @@ void netlist_mame_device::device_start()
|
||||
}
|
||||
|
||||
/* add default data provider for roms */
|
||||
setup().register_source(plib::make_unique<netlist_data_memregions_t>(setup()));
|
||||
setup().register_source(plib::make_unique<netlist_data_memregions_t>(*this));
|
||||
|
||||
m_setup_func(setup());
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
#ifndef MAME_MACHINE_NETLIST_H
|
||||
#define MAME_MACHINE_NETLIST_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "netlist/nl_time.h"
|
||||
#include "netlist/netlist_types.h"
|
||||
|
||||
@ -32,6 +34,9 @@ namespace netlist {
|
||||
#define MCFG_NETLIST_SETUP(_setup) \
|
||||
downcast<netlist_mame_device &>(*device).set_constructor(NETLIST_NAME(_setup));
|
||||
|
||||
#define MCFG_NETLIST_SETUP_MEMBER(_obj, _setup) \
|
||||
downcast<netlist_mame_device &>(*device).set_constructor(_obj, _setup);
|
||||
|
||||
#define MCFG_NETLIST_ANALOG_INPUT(_basetag, _tag, _name) \
|
||||
MCFG_DEVICE_ADD(_basetag ":" _tag, NETLIST_ANALOG_INPUT, 0) \
|
||||
downcast<netlist_mame_analog_input_device &>(*device).set_name(_name);
|
||||
@ -80,9 +85,10 @@ namespace netlist {
|
||||
#define NETLIST_ANALOG_PORT_CHANGED(_base, _tag) \
|
||||
PORT_CHANGED_MEMBER(_base ":" _tag, netlist_mame_analog_input_device, input_changed, 0)
|
||||
|
||||
/* This macro can only be called from device member */
|
||||
|
||||
#define MEMREGION_SOURCE(_name) \
|
||||
netlist_mame_device::register_memregion_source(setup, _name);
|
||||
netlist_mame_device::register_memregion_source(setup, *this, _name);
|
||||
|
||||
#define NETDEV_ANALOG_CALLBACK_MEMBER(_name) \
|
||||
void _name(const double data, const attotime &time)
|
||||
@ -102,11 +108,22 @@ public:
|
||||
class netlist_mame_t;
|
||||
class netlist_mame_callbacks_t;
|
||||
|
||||
using func_type = std::function<void(netlist::nlparse_t &)>;
|
||||
|
||||
// construction/destruction
|
||||
netlist_mame_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
|
||||
virtual ~netlist_mame_device();
|
||||
|
||||
void set_constructor(void (*setup_func)(netlist::nlparse_t &));
|
||||
void set_constructor(void (*setup_func)(netlist::nlparse_t &))
|
||||
{
|
||||
m_setup_func = func_type(setup_func);
|
||||
}
|
||||
|
||||
template <typename T, typename F>
|
||||
void set_constructor(T *obj, F && f)
|
||||
{
|
||||
m_setup_func = std::move(std::bind(std::forward<F>(f), obj, std::placeholders::_1));
|
||||
}
|
||||
|
||||
ATTR_HOT inline netlist::setup_t &setup();
|
||||
ATTR_HOT inline netlist_mame_t &netlist() { return *m_netlist; }
|
||||
@ -114,7 +131,7 @@ public:
|
||||
ATTR_HOT void update_icount(netlist::netlist_time time);
|
||||
ATTR_HOT void check_mame_abort_slice();
|
||||
|
||||
static void register_memregion_source(netlist::nlparse_t &setup, const char *name);
|
||||
static void register_memregion_source(netlist::nlparse_t &setup, device_t &dev, const char *name);
|
||||
|
||||
int m_icount;
|
||||
|
||||
@ -145,7 +162,7 @@ private:
|
||||
|
||||
netlist::poolptr<netlist_mame_t> m_netlist;
|
||||
|
||||
void (*m_setup_func)(netlist::nlparse_t &);
|
||||
func_type m_setup_func;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
@ -237,13 +237,13 @@ detail::terminal_type detail::core_terminal_t::type() const
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
netlist_t::netlist_t(const pstring &aname, std::unique_ptr<callbacks_t> callbacks)
|
||||
: m_time(netlist_time::zero())
|
||||
, m_mainclock(nullptr)
|
||||
, m_state(plib::make_unique<netlist_state_t>(aname,
|
||||
: m_state(plib::make_unique<netlist_state_t>(aname,
|
||||
std::move(callbacks),
|
||||
plib::make_unique<setup_t>(*this))) // FIXME, ugly but needed to have netlist_state_t constructed first
|
||||
, m_queue(*m_state)
|
||||
, m_solver(nullptr)
|
||||
, m_time(netlist_time::zero())
|
||||
, m_mainclock(nullptr)
|
||||
, m_queue(*m_state)
|
||||
{
|
||||
devices::initialize_factory(nlstate().setup().factory());
|
||||
NETLIST_NAME(base)(nlstate().setup());
|
||||
|
@ -1453,19 +1453,16 @@ namespace netlist
|
||||
void print_stats() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<netlist_state_t> m_state;
|
||||
devices::NETLIB_NAME(solver) * m_solver;
|
||||
|
||||
/* mostly rw */
|
||||
PALIGNAS_CACHELINE()
|
||||
netlist_time m_time;
|
||||
PALIGNAS_CACHELINE()
|
||||
devices::NETLIB_NAME(mainclock) * m_mainclock;
|
||||
|
||||
PALIGNAS_CACHELINE()
|
||||
std::unique_ptr<netlist_state_t> m_state;
|
||||
PALIGNAS_CACHELINE()
|
||||
detail::queue_t m_queue;
|
||||
|
||||
devices::NETLIB_NAME(solver) * m_solver;
|
||||
|
||||
// performance
|
||||
nperftime_t<NL_KEEP_STATISTICS> m_stat_mainloop;
|
||||
nperfcount_t<NL_KEEP_STATISTICS> m_perf_out_processed;
|
||||
|
@ -37,6 +37,7 @@ namespace netlist
|
||||
void lock() noexcept{ while (m_lock.test_and_set(std::memory_order_acquire)) { } }
|
||||
void unlock() noexcept { m_lock.clear(std::memory_order_release); }
|
||||
private:
|
||||
PALIGNAS_CACHELINE()
|
||||
std::atomic_flag m_lock = ATOMIC_FLAG_INIT;
|
||||
};
|
||||
|
||||
@ -96,7 +97,7 @@ namespace netlist
|
||||
|
||||
/* Use TS = true for a threadsafe queue */
|
||||
template <class T, bool TS, bool KEEPSTAT, class QueueOp = typename T::QueueOp>
|
||||
class PALIGNAS_CACHELINE() timed_queue_linear : plib::nocopyassignmove
|
||||
class timed_queue_linear : plib::nocopyassignmove
|
||||
{
|
||||
public:
|
||||
|
||||
@ -192,6 +193,7 @@ namespace netlist
|
||||
using lock_guard_type = std::lock_guard<mutex_type>;
|
||||
|
||||
mutex_type m_lock;
|
||||
PALIGNAS_CACHELINE()
|
||||
T * m_end;
|
||||
std::vector<T> m_list;
|
||||
|
||||
|
@ -101,7 +101,7 @@ namespace netlist
|
||||
{
|
||||
for (auto &source : m_sources)
|
||||
{
|
||||
if (source->parse(netlist_name))
|
||||
if (source->parse(*this, netlist_name))
|
||||
return;
|
||||
}
|
||||
log().fatal(MF_1_NOT_FOUND_IN_SOURCE_COLLECTION, netlist_name);
|
||||
@ -1136,13 +1136,13 @@ void setup_t::prepare_to_run()
|
||||
// base sources
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
bool source_t::parse(const pstring &name)
|
||||
bool source_t::parse(nlparse_t &setup, const pstring &name)
|
||||
{
|
||||
if (m_type != SOURCE)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
return m_setup.parse_stream(stream(name), name);
|
||||
return setup.parse_stream(stream(name), name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1164,11 +1164,11 @@ std::unique_ptr<plib::pistream> source_file_t::stream(const pstring &name)
|
||||
return plib::make_unique<plib::pifilestream>(m_filename);
|
||||
}
|
||||
|
||||
bool source_proc_t::parse(const pstring &name)
|
||||
bool source_proc_t::parse(nlparse_t &setup, const pstring &name)
|
||||
{
|
||||
if (name == m_setup_func_name)
|
||||
{
|
||||
m_setup_func(setup());
|
||||
m_setup_func(setup);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -67,7 +67,7 @@ void NETLIST_NAME(name)(netlist::nlparse_t &setup) \
|
||||
#define NETLIST_END() }
|
||||
|
||||
#define LOCAL_SOURCE(name) \
|
||||
setup.register_source(plib::make_unique<netlist::source_proc_t>(setup, # name, &NETLIST_NAME(name)));
|
||||
setup.register_source(plib::make_unique<netlist::source_proc_t>(# name, &NETLIST_NAME(name)));
|
||||
|
||||
#define LOCAL_LIB_ENTRY(name) \
|
||||
LOCAL_SOURCE(name) \
|
||||
@ -182,24 +182,22 @@ namespace netlist
|
||||
|
||||
using list_t = std::vector<std::unique_ptr<source_t>>;
|
||||
|
||||
source_t(nlparse_t &setup, const type_t type = SOURCE)
|
||||
: m_setup(setup)
|
||||
, m_type(type)
|
||||
source_t(const type_t type = SOURCE)
|
||||
: m_type(type)
|
||||
{}
|
||||
|
||||
COPYASSIGNMOVE(source_t, delete)
|
||||
|
||||
virtual ~source_t() noexcept = default;
|
||||
|
||||
virtual bool parse(const pstring &name);
|
||||
nlparse_t &setup() { return m_setup; }
|
||||
virtual bool parse(nlparse_t &setup, const pstring &name);
|
||||
|
||||
type_t type() const { return m_type; }
|
||||
|
||||
protected:
|
||||
virtual std::unique_ptr<plib::pistream> stream(const pstring &name) = 0;
|
||||
|
||||
private:
|
||||
nlparse_t &m_setup;
|
||||
const type_t m_type;
|
||||
};
|
||||
|
||||
@ -400,8 +398,8 @@ namespace netlist
|
||||
{
|
||||
public:
|
||||
|
||||
source_string_t(setup_t &setup, const pstring &source)
|
||||
: source_t(setup), m_str(source)
|
||||
source_string_t(const pstring &source)
|
||||
: source_t(), m_str(source)
|
||||
{
|
||||
}
|
||||
|
||||
@ -416,8 +414,8 @@ namespace netlist
|
||||
{
|
||||
public:
|
||||
|
||||
source_file_t(setup_t &setup, const pstring &filename)
|
||||
: source_t(setup), m_filename(filename)
|
||||
source_file_t(const pstring &filename)
|
||||
: source_t(), m_filename(filename)
|
||||
{
|
||||
}
|
||||
|
||||
@ -431,8 +429,8 @@ namespace netlist
|
||||
class source_mem_t : public source_t
|
||||
{
|
||||
public:
|
||||
source_mem_t(setup_t &setup, const char *mem)
|
||||
: source_t(setup), m_str(mem)
|
||||
source_mem_t(const char *mem)
|
||||
: source_t(), m_str(mem)
|
||||
{
|
||||
}
|
||||
|
||||
@ -446,14 +444,14 @@ namespace netlist
|
||||
class source_proc_t : public source_t
|
||||
{
|
||||
public:
|
||||
source_proc_t(nlparse_t &setup, pstring name, void (*setup_func)(nlparse_t &))
|
||||
: source_t(setup),
|
||||
source_proc_t(pstring name, void (*setup_func)(nlparse_t &))
|
||||
: source_t(),
|
||||
m_setup_func(setup_func),
|
||||
m_setup_func_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
bool parse(const pstring &name) override;
|
||||
bool parse(nlparse_t &setup, const pstring &name) override;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<plib::pistream> stream(const pstring &name) override;
|
||||
|
@ -120,9 +120,8 @@ NETLIST_END()
|
||||
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)
|
||||
netlist_data_folder_t(pstring folder)
|
||||
: netlist::source_t(netlist::source_t::DATA)
|
||||
, m_folder(folder)
|
||||
{
|
||||
}
|
||||
@ -189,9 +188,9 @@ public:
|
||||
setup().add_define(d);
|
||||
|
||||
for (auto & r : roms)
|
||||
setup().register_source(plib::make_unique<netlist_data_folder_t>(setup(), r));
|
||||
setup().register_source(plib::make_unique<netlist_data_folder_t>(r));
|
||||
|
||||
setup().register_source(plib::make_unique<netlist::source_file_t>(setup(), filename));
|
||||
setup().register_source(plib::make_unique<netlist::source_file_t>(filename));
|
||||
setup().include(name);
|
||||
create_dynamic_logs(logs);
|
||||
|
||||
@ -524,7 +523,7 @@ void tool_app_t::create_header()
|
||||
nt.log().verbose.set_enabled(false);
|
||||
nt.log().warning.set_enabled(false);
|
||||
|
||||
nt.setup().register_source(plib::make_unique<netlist::source_proc_t>(nt.setup(), "dummy", &netlist_dummy));
|
||||
nt.setup().register_source(plib::make_unique<netlist::source_proc_t>("dummy", &netlist_dummy));
|
||||
nt.setup().include("dummy");
|
||||
|
||||
pout("// license:GPL-2.0+\n");
|
||||
@ -568,7 +567,7 @@ void tool_app_t::create_docheader()
|
||||
nt.log().verbose.set_enabled(false);
|
||||
nt.log().warning.set_enabled(false);
|
||||
|
||||
nt.setup().register_source(plib::make_unique<netlist::source_proc_t>(nt.setup(), "dummy", &netlist_dummy));
|
||||
nt.setup().register_source(plib::make_unique<netlist::source_proc_t>("dummy", &netlist_dummy));
|
||||
nt.setup().include("dummy");
|
||||
|
||||
std::vector<pstring> devs;
|
||||
@ -620,7 +619,7 @@ void tool_app_t::listdevices()
|
||||
|
||||
netlist::factory::list_t &list = nt.setup().factory();
|
||||
|
||||
nt.setup().register_source(plib::make_unique<netlist::source_proc_t>(nt.setup(), "dummy", &netlist_dummy));
|
||||
nt.setup().register_source(plib::make_unique<netlist::source_proc_t>("dummy", &netlist_dummy));
|
||||
nt.setup().include("dummy");
|
||||
|
||||
|
||||
|
@ -184,6 +184,15 @@ public:
|
||||
void pongd(machine_config &config);
|
||||
void pong(machine_config &config);
|
||||
void pongf(machine_config &config);
|
||||
|
||||
NETLIST_START(pong)
|
||||
|
||||
MEMREGION_SOURCE("maincpu")
|
||||
PARAM(NETLIST.USE_DEACTIVATE, 1)
|
||||
INCLUDE(pong_schematics)
|
||||
|
||||
NETLIST_END()
|
||||
|
||||
protected:
|
||||
|
||||
// driver_device overrides
|
||||
@ -260,6 +269,7 @@ private:
|
||||
|
||||
};
|
||||
|
||||
#if 0
|
||||
static NETLIST_START(pong)
|
||||
|
||||
MEMREGION_SOURCE("maincpu")
|
||||
@ -267,6 +277,7 @@ static NETLIST_START(pong)
|
||||
INCLUDE(pong_schematics)
|
||||
|
||||
NETLIST_END()
|
||||
#endif
|
||||
|
||||
INPUT_CHANGED_MEMBER(pong_state::input_changed)
|
||||
{
|
||||
@ -379,7 +390,8 @@ MACHINE_CONFIG_START(pong_state::pong)
|
||||
|
||||
/* basic machine hardware */
|
||||
MCFG_DEVICE_ADD("maincpu", NETLIST_CPU, NETLIST_CLOCK)
|
||||
MCFG_NETLIST_SETUP(pong)
|
||||
//MCFG_NETLIST_SETUP(pong)
|
||||
MCFG_NETLIST_SETUP_MEMBER(this, &pong_state::NETLIST_NAME(pong))
|
||||
|
||||
MCFG_NETLIST_ANALOG_INPUT("maincpu", "vr0", "ic_b9_R.R")
|
||||
MCFG_NETLIST_ANALOG_MULT_OFFSET(1.0 / 100.0 * RES_K(50), RES_K(56) )
|
||||
|
Loading…
Reference in New Issue
Block a user