mirror of
https://github.com/holub/mame
synced 2025-04-23 00:39:36 +03:00
Simplify. (nw)
This commit is contained in:
parent
28a734436e
commit
016535b3d0
@ -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_t &>(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 <typename C, param_t::param_type_t T>
|
||||
param_template_t<C, 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<double, param_t::DOUBLE>;
|
||||
template class param_template_t<int, param_t::INTEGER>;
|
||||
template class param_template_t<bool, param_t::LOGIC>;
|
||||
template class param_template_t<std::uint_fast8_t*, param_t::POINTER>;
|
||||
template class param_template_t<pstring, param_t::STRING>;
|
||||
//template class param_template_t<pstring, param_t::MODEL>;
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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<typename C>
|
||||
void set(C &p, const C v)
|
||||
{
|
||||
if (p != v)
|
||||
{
|
||||
p = v;
|
||||
update_param();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const param_type_t m_param_type;
|
||||
};
|
||||
|
||||
template <typename C, param_t::param_type_t T>
|
||||
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);
|
||||
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;
|
||||
};
|
||||
|
||||
const C operator()() const { return Value(); }
|
||||
class param_logic_t final: public param_t
|
||||
{
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
void setTo(const C ¶m)
|
||||
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;
|
||||
};
|
||||
|
||||
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 : public param_t
|
||||
{
|
||||
public:
|
||||
param_str_t(device_t &device, const pstring name, const pstring val);
|
||||
const pstring operator()() const { return Value(); }
|
||||
void setTo(const pstring ¶m)
|
||||
{
|
||||
if (m_param != param)
|
||||
{
|
||||
m_param = param;
|
||||
changed_and_update();
|
||||
changed();
|
||||
update_param();
|
||||
}
|
||||
}
|
||||
void initial(const C &val) { m_param = val; changed(); }
|
||||
|
||||
protected:
|
||||
C Value() const { return m_param; }
|
||||
C m_param;
|
||||
virtual void changed() { }
|
||||
pstring Value() const { return m_param; }
|
||||
private:
|
||||
pstring m_param;
|
||||
};
|
||||
|
||||
template <typename C, param_t::param_type_t T>
|
||||
class param_template_final_t final : public param_template_t<C, T>
|
||||
{
|
||||
public:
|
||||
param_template_final_t(device_t &device, const pstring name, const C val)
|
||||
: param_template_t<C,T>(device, name, val)
|
||||
{
|
||||
this->register_and_set();
|
||||
}
|
||||
};
|
||||
|
||||
using param_double_t = param_template_final_t<nl_double, param_t::DOUBLE>;
|
||||
using param_int_t = param_template_final_t<int, param_t::INTEGER>;
|
||||
|
||||
using param_logic_t = param_template_final_t<bool, param_t::LOGIC>;
|
||||
using param_ptr_t = param_template_final_t<std::uint_fast8_t*, param_t::POINTER>;
|
||||
using param_str_base_t = param_template_t<pstring, param_t::STRING>;
|
||||
|
||||
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
|
||||
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<plib::pistream> stream();
|
||||
|
||||
protected:
|
||||
virtual void changed() override { }
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
template <typename ST, std::size_t AW, std::size_t DW>
|
||||
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<<AW);
|
||||
}
|
||||
|
||||
const ST & operator[] (std::size_t n) { return m_data[n]; }
|
||||
|
@ -191,44 +191,45 @@ pstring setup_t::objtype_as_str(detail::device_object_t &in) const
|
||||
return "Error";
|
||||
}
|
||||
|
||||
void setup_t::register_and_set_param(pstring name, param_t ¶m)
|
||||
pstring setup_t::get_initial_param_val(const pstring name, const pstring def)
|
||||
{
|
||||
auto i = m_param_values.find(name);
|
||||
if (i != m_param_values.end())
|
||||
return i->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_double_t &>(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_int_t &>(param).initial(static_cast<int>(vald));
|
||||
}
|
||||
break;
|
||||
case param_t::POINTER:
|
||||
static_cast<param_ptr_t &>(param).initial(nullptr);
|
||||
break;
|
||||
case param_t::STRING:
|
||||
{
|
||||
static_cast<param_str_base_t &>(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<int>(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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<netlist::param_double_t*>(m_param)->setTo(m_value);
|
||||
@ -237,9 +237,6 @@ struct input_t
|
||||
case netlist::param_t::LOGIC:
|
||||
static_cast<netlist::param_logic_t*>(m_param)->setTo(static_cast<bool>(m_value));
|
||||
break;
|
||||
case netlist::param_t::POINTER:
|
||||
static_cast<netlist::param_ptr_t*>(m_param)->setTo(nullptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user