mirror of
https://github.com/holub/mame
synced 2025-07-06 18:39:28 +03:00
Truthtable refactoring. (nw)
This commit is contained in:
parent
8cbac2531e
commit
a1b97d3064
@ -67,11 +67,11 @@
|
|||||||
// Extensions to interface netlist with MAME code ....
|
// Extensions to interface netlist with MAME code ....
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class netlist_source_memregion_t : public netlist::setup_t::source_t
|
class netlist_source_memregion_t : public netlist::source_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
netlist_source_memregion_t(pstring name)
|
netlist_source_memregion_t(pstring name)
|
||||||
: netlist::setup_t::source_t(), m_name(name)
|
: netlist::source_t(), m_name(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "nld_truthtable.h"
|
#include "nld_truthtable.h"
|
||||||
#include "plib/plists.h"
|
#include "plib/plists.h"
|
||||||
|
#include "nl_setup.h"
|
||||||
|
|
||||||
namespace netlist
|
namespace netlist
|
||||||
{
|
{
|
||||||
@ -261,18 +262,17 @@ void truthtable_desc_t::setup(const plib::pstring_vector_t &truthtable, uint_lea
|
|||||||
|
|
||||||
#define ENTRYX(n, m, h) case (n * 1000 + m * 10 + h): \
|
#define ENTRYX(n, m, h) case (n * 1000 + m * 10 + h): \
|
||||||
{ using xtype = netlist_factory_truthtable_t<n, m, h>; \
|
{ using xtype = netlist_factory_truthtable_t<n, m, h>; \
|
||||||
return plib::owned_ptr<netlist_base_factory_truthtable_t>::Create<xtype>(name,classname,def_param); } break
|
ret = new xtype(desc.name, desc.classname, desc.def_param); } break
|
||||||
|
|
||||||
#define ENTRYY(n, m) ENTRYX(n, m, 0); ENTRYX(n, m, 1)
|
#define ENTRYY(n, m) ENTRYX(n, m, 0); ENTRYX(n, m, 1)
|
||||||
|
|
||||||
#define ENTRY(n) ENTRYY(n, 1); ENTRYY(n, 2); ENTRYY(n, 3); ENTRYY(n, 4); ENTRYY(n, 5); ENTRYY(n, 6)
|
#define ENTRY(n) ENTRYY(n, 1); ENTRYY(n, 2); ENTRYY(n, 3); ENTRYY(n, 4); ENTRYY(n, 5); ENTRYY(n, 6)
|
||||||
|
|
||||||
plib::owned_ptr<netlist_base_factory_truthtable_t> nl_tt_factory_create(const unsigned ni, const unsigned no,
|
void nl_tt_factory_create(setup_t &setup, tt_desc &desc)
|
||||||
const unsigned has_state,
|
|
||||||
const pstring &name, const pstring &classname,
|
|
||||||
const pstring &def_param)
|
|
||||||
{
|
{
|
||||||
switch (ni * 1000 + no * 10 + has_state)
|
netlist_base_factory_truthtable_t *ret;
|
||||||
|
|
||||||
|
switch (desc.ni * 1000 + desc.no * 10 + desc.has_state)
|
||||||
{
|
{
|
||||||
ENTRY(1);
|
ENTRY(1);
|
||||||
ENTRY(2);
|
ENTRY(2);
|
||||||
@ -285,10 +285,13 @@ plib::owned_ptr<netlist_base_factory_truthtable_t> nl_tt_factory_create(const un
|
|||||||
ENTRY(9);
|
ENTRY(9);
|
||||||
ENTRY(10);
|
ENTRY(10);
|
||||||
default:
|
default:
|
||||||
pstring msg = plib::pfmt("unable to create truthtable<{1},{2},{3}>")(ni)(no)(has_state);
|
pstring msg = plib::pfmt("unable to create truthtable<{1},{2},{3}>")(desc.ni)(desc.no)(desc.has_state);
|
||||||
nl_assert_always(false, msg);
|
nl_assert_always(false, msg);
|
||||||
}
|
}
|
||||||
//return nullptr;
|
ret->m_desc = desc.desc;
|
||||||
|
if (desc.family != "")
|
||||||
|
ret->m_family = setup.family_from_model(desc.family);
|
||||||
|
setup.factory().register_device(plib::owned_ptr<netlist_base_factory_truthtable_t>(ret, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace devices
|
} //namespace devices
|
||||||
|
@ -29,22 +29,28 @@
|
|||||||
static const char *m_desc[]; \
|
static const char *m_desc[]; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TRUTHTABLE_START(cname, in, out, has_state, def_params) \
|
#define TRUTHTABLE_START(cname, in, out, has_statep, def_params) \
|
||||||
{ \
|
{ \
|
||||||
auto ttd = netlist::devices::nl_tt_factory_create(in, out, has_state, \
|
netlist::devices::tt_desc desc; \
|
||||||
# cname, # cname, "+" def_params);
|
desc.name = #cname ; \
|
||||||
|
desc.classname = #cname ; \
|
||||||
|
desc.ni = in; \
|
||||||
|
desc.no = out; \
|
||||||
|
desc.has_state = has_statep; \
|
||||||
|
desc.def_param = pstring("+") + def_params; \
|
||||||
|
desc.family = "";
|
||||||
|
|
||||||
#define TT_HEAD(x) \
|
#define TT_HEAD(x) \
|
||||||
ttd->m_desc.push_back(x);
|
desc.desc.push_back(x);
|
||||||
|
|
||||||
#define TT_LINE(x) \
|
#define TT_LINE(x) \
|
||||||
ttd->m_desc.push_back(x);
|
desc.desc.push_back(x);
|
||||||
|
|
||||||
#define TT_FAMILY(x) \
|
#define TT_FAMILY(x) \
|
||||||
ttd->m_family = setup.family_from_model(x);
|
desc.family = x;
|
||||||
|
|
||||||
#define TRUTHTABLE_END() \
|
#define TRUTHTABLE_END() \
|
||||||
setup.factory().register_device(std::move(ttd)); \
|
netlist::devices::nl_tt_factory_create(setup, desc); \
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace netlist
|
namespace netlist
|
||||||
@ -411,10 +417,19 @@ namespace netlist
|
|||||||
const logic_family_desc_t *m_family;
|
const logic_family_desc_t *m_family;
|
||||||
};
|
};
|
||||||
|
|
||||||
plib::owned_ptr<netlist_base_factory_truthtable_t> nl_tt_factory_create(const unsigned ni, const unsigned no,
|
struct tt_desc
|
||||||
const unsigned has_state,
|
{
|
||||||
const pstring &name, const pstring &classname,
|
pstring name;
|
||||||
const pstring &def_param);
|
pstring classname;
|
||||||
|
unsigned ni;
|
||||||
|
unsigned no;
|
||||||
|
unsigned has_state;
|
||||||
|
pstring def_param;
|
||||||
|
plib::pstring_vector_t desc;
|
||||||
|
pstring family;
|
||||||
|
};
|
||||||
|
|
||||||
|
void nl_tt_factory_create(setup_t &setup, tt_desc &desc);
|
||||||
|
|
||||||
} //namespace devices
|
} //namespace devices
|
||||||
} // namespace netlist
|
} // namespace netlist
|
||||||
|
@ -965,22 +965,6 @@ namespace netlist
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// param_ref_t
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
struct param_ref_t
|
|
||||||
{
|
|
||||||
param_ref_t(const pstring name, core_device_t &device, param_t ¶m)
|
|
||||||
: m_name(name)
|
|
||||||
, m_device(device)
|
|
||||||
, m_param(param)
|
|
||||||
{ }
|
|
||||||
pstring m_name;
|
|
||||||
core_device_t &m_device;
|
|
||||||
param_t &m_param;
|
|
||||||
};
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// device_t
|
// device_t
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -158,8 +158,14 @@ void parser_t::net_truthtable_start()
|
|||||||
pstring def_param = get_string();
|
pstring def_param = get_string();
|
||||||
require_token(m_tok_param_right);
|
require_token(m_tok_param_right);
|
||||||
|
|
||||||
plib::owned_ptr<netlist::devices::netlist_base_factory_truthtable_t> ttd = netlist::devices::nl_tt_factory_create(ni, no, hs,
|
netlist::devices::tt_desc desc;
|
||||||
name, name, "+" + def_param);
|
desc.classname = name;
|
||||||
|
desc.name = name;
|
||||||
|
desc.ni = ni;
|
||||||
|
desc.no = no;
|
||||||
|
desc.has_state = hs;
|
||||||
|
desc.def_param = "+" + def_param;
|
||||||
|
desc.family = "";
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -168,19 +174,19 @@ void parser_t::net_truthtable_start()
|
|||||||
if (token.is(m_tok_TT_HEAD))
|
if (token.is(m_tok_TT_HEAD))
|
||||||
{
|
{
|
||||||
require_token(m_tok_param_left);
|
require_token(m_tok_param_left);
|
||||||
ttd->m_desc.push_back(get_string());
|
desc.desc.push_back(get_string());
|
||||||
require_token(m_tok_param_right);
|
require_token(m_tok_param_right);
|
||||||
}
|
}
|
||||||
else if (token.is(m_tok_TT_LINE))
|
else if (token.is(m_tok_TT_LINE))
|
||||||
{
|
{
|
||||||
require_token(m_tok_param_left);
|
require_token(m_tok_param_left);
|
||||||
ttd->m_desc.push_back(get_string());
|
desc.desc.push_back(get_string());
|
||||||
require_token(m_tok_param_right);
|
require_token(m_tok_param_right);
|
||||||
}
|
}
|
||||||
else if (token.is(m_tok_TT_FAMILY))
|
else if (token.is(m_tok_TT_FAMILY))
|
||||||
{
|
{
|
||||||
require_token(m_tok_param_left);
|
require_token(m_tok_param_left);
|
||||||
ttd->m_family = m_setup.family_from_model(get_string());
|
desc.family = get_string();
|
||||||
require_token(m_tok_param_right);
|
require_token(m_tok_param_right);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -188,7 +194,7 @@ void parser_t::net_truthtable_start()
|
|||||||
require_token(token, m_tok_TRUTHTABLE_END);
|
require_token(token, m_tok_TRUTHTABLE_END);
|
||||||
require_token(m_tok_param_left);
|
require_token(m_tok_param_left);
|
||||||
require_token(m_tok_param_right);
|
require_token(m_tok_param_right);
|
||||||
m_setup.factory().register_device(std::move(ttd));
|
netlist::devices::nl_tt_factory_create(m_setup, desc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -431,7 +437,7 @@ nl_double parser_t::eval_param(const token_t tok)
|
|||||||
val = tok.str();
|
val = tok.str();
|
||||||
ret = val.as_double(&e);
|
ret = val.as_double(&e);
|
||||||
if (e)
|
if (e)
|
||||||
error("Error with parameter ...\n");
|
error(plib::pfmt("Error with parameter {1}...\n")(val));
|
||||||
}
|
}
|
||||||
return ret * facs[f];
|
return ret * facs[f];
|
||||||
|
|
||||||
|
@ -788,6 +788,16 @@ void setup_t::start_devices()
|
|||||||
netlist().start();
|
netlist().start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plib::plog_base<NL_DEBUG> &setup_t::log()
|
||||||
|
{
|
||||||
|
return netlist().log();
|
||||||
|
}
|
||||||
|
const plib::plog_base<NL_DEBUG> &setup_t::log() const
|
||||||
|
{
|
||||||
|
return netlist().log();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
// Model / family
|
// Model / family
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
|
@ -11,7 +11,13 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "plib/pstring.h"
|
||||||
|
#include "plib/palloc.h"
|
||||||
|
#include "plib/pfmtlog.h"
|
||||||
|
#include "plib/putil.h"
|
||||||
|
#include "nl_config.h"
|
||||||
#include "nl_base.h"
|
#include "nl_base.h"
|
||||||
#include "nl_factory.h"
|
#include "nl_factory.h"
|
||||||
|
|
||||||
@ -71,20 +77,24 @@ void NETLIST_NAME(name)(netlist::setup_t &setup) \
|
|||||||
NETLIST_NAME(model)(setup); \
|
NETLIST_NAME(model)(setup); \
|
||||||
setup.namespace_pop();
|
setup.namespace_pop();
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------
|
|
||||||
// netlist_setup_t
|
|
||||||
// ----------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace netlist
|
namespace netlist
|
||||||
{
|
{
|
||||||
// Forward definition so we keep nl_factory.h out of the public
|
|
||||||
class factory_list_t;
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// param_ref_t
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class setup_t
|
struct param_ref_t
|
||||||
{
|
{
|
||||||
P_PREVENT_COPYING(setup_t)
|
param_ref_t(const pstring name, core_device_t &device, param_t ¶m)
|
||||||
public:
|
: m_name(name)
|
||||||
|
, m_device(device)
|
||||||
|
, m_param(param)
|
||||||
|
{ }
|
||||||
|
pstring m_name;
|
||||||
|
core_device_t &m_device;
|
||||||
|
param_t &m_param;
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
// A Generic netlist sources implementation
|
// A Generic netlist sources implementation
|
||||||
@ -104,6 +114,16 @@ namespace netlist
|
|||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------------------
|
||||||
|
// setup_t
|
||||||
|
// ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class setup_t
|
||||||
|
{
|
||||||
|
P_PREVENT_COPYING(setup_t)
|
||||||
|
public:
|
||||||
|
|
||||||
using link_t = std::pair<pstring, pstring>;
|
using link_t = std::pair<pstring, pstring>;
|
||||||
|
|
||||||
setup_t(netlist_t &netlist);
|
setup_t(netlist_t &netlist);
|
||||||
@ -179,8 +199,8 @@ namespace netlist
|
|||||||
|
|
||||||
void model_parse(const pstring &model, model_map_t &map);
|
void model_parse(const pstring &model, model_map_t &map);
|
||||||
|
|
||||||
plib::plog_base<NL_DEBUG> &log() { return netlist().log(); }
|
plib::plog_base<NL_DEBUG> &log();
|
||||||
const plib::plog_base<NL_DEBUG> &log() const { return netlist().log(); }
|
const plib::plog_base<NL_DEBUG> &log() const;
|
||||||
|
|
||||||
std::vector<std::pair<pstring, base_factory_t *>> m_device_factory;
|
std::vector<std::pair<pstring, base_factory_t *>> m_device_factory;
|
||||||
|
|
||||||
@ -232,12 +252,12 @@ namespace netlist
|
|||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class source_string_t : public setup_t::source_t
|
class source_string_t : public source_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
source_string_t(const pstring &source)
|
source_string_t(const pstring &source)
|
||||||
: setup_t::source_t(), m_str(source)
|
: source_t(), m_str(source)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,12 +267,12 @@ namespace netlist
|
|||||||
pstring m_str;
|
pstring m_str;
|
||||||
};
|
};
|
||||||
|
|
||||||
class source_file_t : public setup_t::source_t
|
class source_file_t : public source_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
source_file_t(const pstring &filename)
|
source_file_t(const pstring &filename)
|
||||||
: setup_t::source_t(), m_filename(filename)
|
: source_t(), m_filename(filename)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,11 +282,11 @@ namespace netlist
|
|||||||
pstring m_filename;
|
pstring m_filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
class source_mem_t : public setup_t::source_t
|
class source_mem_t : public source_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
source_mem_t(const char *mem)
|
source_mem_t(const char *mem)
|
||||||
: setup_t::source_t(), m_str(mem)
|
: source_t(), m_str(mem)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,11 +296,11 @@ namespace netlist
|
|||||||
pstring m_str;
|
pstring m_str;
|
||||||
};
|
};
|
||||||
|
|
||||||
class source_proc_t : public setup_t::source_t
|
class source_proc_t : public source_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
source_proc_t(pstring name, void (*setup_func)(setup_t &))
|
source_proc_t(pstring name, void (*setup_func)(setup_t &))
|
||||||
: setup_t::source_t(),
|
: source_t(),
|
||||||
m_setup_func(setup_func),
|
m_setup_func(setup_func),
|
||||||
m_setup_func_name(name)
|
m_setup_func_name(name)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user