Minor code clean-up in netlist devices

This commit is contained in:
Couriersud 2013-10-21 20:37:06 +00:00
parent be84948d71
commit e1aa7f10bd
5 changed files with 135 additions and 113 deletions

View File

@ -433,8 +433,40 @@ NETLIB_UPDATE(nic7450)
{
UINT8 t1 = INPVAL(m_I0) & INPVAL(m_I1);
UINT8 t2 = INPVAL(m_I2) & INPVAL(m_I3);
#if 0
UINT8 t = (t1 | t2) ^ 1;
m_Q.setTo(t, t ? NLTIME_FROM_NS(22) : NLTIME_FROM_NS(15));
#else
const netlist_time times[2] = { NLTIME_FROM_NS(22), NLTIME_FROM_NS(15) };
UINT8 res = 0;
m_I0.activate();
m_I1.activate();
if (t1 ^ 1)
{
m_I2.activate();
m_I3.activate();
if (t2 ^ 1)
{
res = 1;
}
else
{
m_I0.inactivate();
m_I1.inactivate();
}
} else {
m_I2.activate();
m_I3.activate();
if (t2 ^ 1)
{
m_I2.inactivate();
m_I3.inactivate();
}
}
m_Q.setTo(res, times[1 - res]);// ? 22000 : 15000);
#endif
}
INLINE void nic7474_newstate(const UINT8 state, ttl_output_t &Q, ttl_output_t &QQ)
@ -456,19 +488,24 @@ NETLIB_UPDATE(nic7474sub)
NETLIB_UPDATE(nic7474)
{
sub.m_nextD = INPVAL(m_D);
if (!INPVAL(m_preQ))
{
nic7474_newstate(1, sub.m_Q, sub.m_QQ);
sub.m_clk.inactivate();
m_D.inactivate();
}
else if (!INPVAL(m_clrQ))
{
nic7474_newstate(0, sub.m_Q, sub.m_QQ);
sub.m_clk.inactivate();
m_D.inactivate();
}
else
{
m_D.activate();
sub.m_nextD = INPVAL(m_D);
sub.m_clk.activate_lh();
}
}
NETLIB_CONSTRUCTOR(nic7474)
@ -609,7 +646,7 @@ NETLIB_CONSTRUCTOR(nic7493)
NETLIB_UPDATE(nic7493ff)
{
//if INP_LAST(m_I) && !INP(m_I))
m_Q.setToNoCheck(!m_Q.new_Q(), NLTIME_FROM_NS(18));
m_Q.setTo(!m_Q.new_Q(), NLTIME_FROM_NS(18));
}
NETLIB_UPDATE(nic7493)
@ -751,7 +788,8 @@ INLINE void nic74107A_newstate(UINT8 state, ttl_output_t &Q, ttl_output_t &QQ)
NETLIB_UPDATE(nic74107Asub)
{
{
nic74107A_newstate((!m_Q.new_Q() & m_Q1) | (m_Q.new_Q() & m_Q2) | m_F, m_Q, m_QQ);
net_sig_t t = m_Q.new_Q();
nic74107A_newstate((!t & m_Q1) | (t & m_Q2) | m_F, m_Q, m_QQ);
if (!m_Q1)
m_clk.inactivate();
}
@ -867,15 +905,16 @@ NETLIB_UPDATE(nic9316)
{
sub.m_loadq = INPVAL(m_LOADQ);
sub.m_ent = INPVAL(m_ENT);
const net_sig_t clrq = INPVAL(m_CLRQ);
if ((!sub.m_loadq || (sub.m_ent & INPVAL(m_ENP))) & INPVAL(m_CLRQ))
if ((!sub.m_loadq || (sub.m_ent & INPVAL(m_ENP))) & clrq)
{
sub.m_clk.activate_lh();
}
else
{
sub.m_clk.inactivate();
if (!INPVAL(m_CLRQ) & (sub.m_cnt>0))
if (!clrq & (sub.m_cnt>0))
{
sub.m_cnt = 0;
sub.update_outputs();

View File

@ -51,8 +51,7 @@
#include "netlist.h"
// this is a bad hack
#define USE_OLD7493 (1)
#define USE_OLD7493 (0)
// ----------------------------------------------------------------------------------------
// Special chips

View File

@ -83,27 +83,23 @@
// netlist_timed_queue
// ----------------------------------------------------------------------------------------
ATTR_HOT ATTR_ALIGN void netlist_timed_queue::push(const netlist_timed_queue::entry_t &e)
ATTR_HOT ATTR_ALIGN void netlist_timed_queue::push(const entry_t &e)
{
const netlist_time &t = e.time();
/* no real speedup */
#if 0
if (is_empty() || (t <= item(m_end - 1).time()))
{
set_item(m_end, e);
m_end++;
inc_stat(m_prof_end);
}
else if (t >= item(m_start).time())
{
m_start--;
set_item(m_start, e);
inc_stat(m_prof_start);
}
else
#endif
{
register UINT32 i = m_end;
int i = m_end;
m_end++;
while ((t > item(i-1).time()))
while ((i>0) && (t > item(i-1).time()) )
{
set_item(i, item(i-1));
inc_stat(m_prof_sortmove);
@ -117,6 +113,22 @@ ATTR_HOT ATTR_ALIGN void netlist_timed_queue::push(const netlist_timed_queue::en
const netlist_time netlist_time::zero = netlist_time::from_raw(0);
ATTR_HOT ATTR_ALIGN const net_sig_t net_core_device_t::INPVAL_PASSIVE(logic_input_t &inp)
{
net_sig_t ret;
const net_input_t::net_input_state st = inp.state();
if (st == net_input_t::INP_STATE_PASSIVE)
{
inp.activate();
ret = inp.Q();
inp.inactivate();
}
else
ret = inp.Q();
return ret;
}
// ----------------------------------------------------------------------------------------
// A netlist parser
// ----------------------------------------------------------------------------------------
@ -343,9 +355,13 @@ public:
assert(in_proxied.object_type(SIGNAL_MASK) == SIGNAL_DIGITAL);
m_I.m_high_thresh_V = in_proxied.m_high_thresh_V;
m_I.m_low_thresh_V = in_proxied.m_low_thresh_V;
m_I.init(this);
m_Q.set_netdev(this);
m_Q.initial(1);
}
ATTR_HOT void update()
ATTR_HOT ATTR_ALIGN void update()
{
if (m_I.Q_Analog() > m_I.m_high_thresh_V)
m_Q.setTo(1, NLTIME_FROM_NS(1));
@ -353,14 +369,6 @@ public:
m_Q.setTo(0, NLTIME_FROM_NS(1));
}
ATTR_COLD void start()
{
m_I.init(this);
m_Q.set_netdev(this);
m_Q.initial(1);
}
analog_input_t m_I;
ttl_output_t m_Q;
};
@ -449,13 +457,13 @@ ATTR_HOT ATTR_ALIGN void netlist_base_t::process_list(INT32 &atime)
{
while ( (atime > 0) && (m_queue.is_not_empty()))
{
queue_t::entry_t &e = m_queue.pop();
const queue_t::entry_t &e = m_queue.pop();
update_time(e.time(), atime);
if (FATAL_ERROR_AFTER_NS)
printf("%s\n", e.object()->netdev()->name());
printf("%s\n", e.object().netdev()->name());
e.object()->update_devs();
e.object().update_devs();
add_to_stat(m_perf_out_processed, 1);
@ -482,11 +490,13 @@ ATTR_HOT ATTR_ALIGN void netlist_base_t::process_list(INT32 &atime)
m_mainclock->update();
mainclock_Q.update_devs();
}
queue_t::entry_t &e = m_queue.pop();
const queue_t::entry_t &e = m_queue.pop();
update_time(e.time(), atime);
e.object()->update_devs();
e.object().
update_devs();
} else {
update_time(mainclock_Q.time(), atime);
@ -700,7 +710,6 @@ void netlist_setup_t::resolve_inputs(void)
// fatalerror("connecting analog output %s with %s\n", out.netdev()->name(), in->netdev()->name());
// fatalerror("connecting analog output %s with %s\n", out.netdev()->name(), in->netdev()->name());
netdev_a_to_d_proxy *proxy = new netdev_a_to_d_proxy(*this, "abc", *in);
proxy->start();
in->set_output(proxy->GETINPPTR(proxy->m_Q));
//Next check would not work with dynamic activation
//if (in->state() != net_input_t::INP_STATE_PASSIVE)
@ -905,28 +914,30 @@ ATTR_COLD void net_output_t::set_netdev(net_core_device_t *dev)
m_netlist = &dev->netlist();
}
ATTR_HOT inline void net_output_t::update_dev(const net_input_t &inp, const UINT8 mask)
ATTR_HOT ATTR_ALIGN inline void net_output_t::update_dev(const net_input_t &inp, const UINT8 mask)
{
if (((inp.state() & mask) != 0))
{
begin_timing(inp.netdev()->total_time);
inc_stat(inp.netdev()->stat_count);
ATTR_UNUSED net_core_device_t *netdev = inp.netdev();
begin_timing(netdev->total_time);
inc_stat(netdev->stat_count);
#if USE_DELEGATES
inp.h();
#else
inp.netdev()->update();
netdev->update();
#endif
end_timing(inp.netdev()->total_time);
end_timing(netdev()->total_time);
}
}
ATTR_HOT inline void net_output_t::update_devs()
ATTR_HOT ATTR_ALIGN inline void net_output_t::update_devs()
{
assert(m_num_cons != 0);
const UINT8 masks[4] = { 1, 5, 3, 1 };
m_Q = m_new_Q;
m_Q_analog = m_new_Q_analog;
m_in_queue = 2; /* mark as taken ... */
//if (m_last_Q == m_Q)
//printf("%s\n", m_netdev->name());
@ -948,7 +959,6 @@ ATTR_HOT inline void net_output_t::update_devs()
break;
}
m_in_queue = 2; /* mark as taken ... */
m_last_Q = m_Q;
}
@ -960,15 +970,12 @@ ATTR_COLD void net_output_t::register_con(net_input_t &input)
/* keep similar devices together */
for (i = 0; i < m_num_cons; i++)
#if USE_DELEGATES
if (m_cons[i]->h == input.h)
if (m_cons[i]->netdev() == input.netdev())
break;
#else
if (m_cons[i]->netdev() == input.netdev())
break;
#endif
for (int j = m_num_cons; j > i; j--)
m_cons[j] = m_cons[j - 1];
m_cons[i] = &input;
m_num_cons++;
if (input.state() != net_input_t::INP_STATE_PASSIVE)

View File

@ -210,16 +210,16 @@ public:
inline netlist_time() : m_time(0) {}
friend inline netlist_time operator-(const netlist_time &left, const netlist_time &right);
friend inline netlist_time operator+(const netlist_time &left, const netlist_time &right);
friend inline netlist_time operator*(const netlist_time &left, const UINT64 factor);
friend inline const netlist_time operator-(const netlist_time &left, const netlist_time &right);
friend inline const netlist_time operator+(const netlist_time &left, const netlist_time &right);
friend inline const netlist_time operator*(const netlist_time &left, const UINT64 factor);
friend inline bool operator>(const netlist_time &left, const netlist_time &right);
friend inline bool operator<(const netlist_time &left, const netlist_time &right);
friend inline bool operator>=(const netlist_time &left, const netlist_time &right);
friend inline bool operator<=(const netlist_time &left, const netlist_time &right);
ATTR_HOT inline netlist_time &operator=(const netlist_time &right) { m_time = right.m_time; return *this; }
ATTR_HOT inline netlist_time &operator+=(const netlist_time &right) { m_time += right.m_time; return *this; }
ATTR_HOT inline const netlist_time &operator=(const netlist_time &right) { m_time = right.m_time; return *this; }
ATTR_HOT inline const netlist_time &operator+=(const netlist_time &right) { m_time += right.m_time; return *this; }
ATTR_HOT inline const INTERNALTYPE as_raw() const { return m_time; }
@ -238,17 +238,17 @@ protected:
INTERNALTYPE m_time;
};
ATTR_HOT inline netlist_time operator-(const netlist_time &left, const netlist_time &right)
ATTR_HOT inline const netlist_time operator-(const netlist_time &left, const netlist_time &right)
{
return netlist_time::from_raw(left.m_time - right.m_time);
}
ATTR_HOT inline netlist_time operator*(const netlist_time &left, const UINT64 factor)
ATTR_HOT inline const netlist_time operator*(const netlist_time &left, const UINT64 factor)
{
return netlist_time::from_raw(left.m_time * factor);
}
ATTR_HOT inline netlist_time operator+(const netlist_time &left, const netlist_time &right)
ATTR_HOT inline const netlist_time operator+(const netlist_time &left, const netlist_time &right)
{
return netlist_time::from_raw(left.m_time + right.m_time);
}
@ -331,9 +331,9 @@ public:
{
public:
inline entry_t() {}
inline entry_t(netlist_time atime, net_output_t *elem) : m_time(atime), m_object(elem) {}
inline entry_t(const netlist_time atime, net_output_t &elem) : m_time(atime), m_object(&elem) {}
ATTR_HOT inline const netlist_time &time() const { return m_time; }
ATTR_HOT inline net_output_t * object() const { return m_object; }
ATTR_HOT inline net_output_t & object() const { return *m_object; }
private:
netlist_time m_time;
net_output_t *m_object;
@ -344,30 +344,25 @@ public:
clear();
}
#if 1
ATTR_HOT bool is_empty() { return ((m_start ^ m_end) & SIZE) == 0; }
ATTR_HOT bool is_not_empty() { return ((m_start ^ m_end) & SIZE) != 0; }
#else
ATTR_HOT bool is_empty() { return ((m_start & SIZE) == (m_end & SIZE)); }
ATTR_HOT bool is_not_empty() { return ((m_start & SIZE) != (m_end & SIZE)); }
#endif
ATTR_HOT inline bool is_empty() { return (m_end == 0); }
ATTR_HOT inline bool is_not_empty() { return (m_end != 0); }
ATTR_HOT ATTR_ALIGN void push(const entry_t &e);
ATTR_HOT entry_t &pop()
ATTR_HOT inline const entry_t &pop()
{
m_end--;
return item(m_end);
}
ATTR_HOT entry_t &peek()
ATTR_HOT inline const entry_t &peek() const
{
return item(m_end-1);
}
ATTR_COLD void clear()
{
m_end = m_start = (SIZE + 1) >> 1;
m_end = 0;
}
// profiling
@ -376,10 +371,9 @@ public:
INT32 m_prof_sortmove;
INT32 m_prof_sort;
private:
ATTR_HOT inline entry_t &item(const UINT32 x) { return m_list[x & SIZE]; }
ATTR_HOT inline void set_item(const UINT32 x, const entry_t &aitem) { m_list[x & SIZE] = aitem; }
ATTR_HOT inline const entry_t &item(const UINT32 x) const { return m_list[x]; }
ATTR_HOT inline void set_item(const UINT32 x, const entry_t &aitem) { m_list[x] = aitem; }
UINT32 m_start;
UINT32 m_end;
entry_t m_list[SIZE + 1];
@ -407,7 +401,7 @@ public:
: m_objtype(atype) {}
ATTR_HOT inline int object_type() const { return m_objtype; }
ATTR_HOT inline int object_type(int mask) const { return m_objtype & mask; }
ATTR_HOT inline int object_type(const UINT32 mask) const { return m_objtype & mask; }
private:
int m_objtype;
@ -434,8 +428,8 @@ public:
ATTR_COLD void init(net_core_device_t *dev, net_input_state astate = INP_STATE_ACTIVE);
ATTR_HOT inline net_output_t * RESTRICT output() const { return m_output; }
ATTR_HOT inline bool is_state(const net_input_state astate) { return (m_state == astate); }
ATTR_HOT inline net_input_state state() const { return m_state; }
ATTR_HOT inline const bool is_state(const net_input_state astate) { return (m_state == astate); }
ATTR_HOT inline const net_input_state state() const { return m_state; }
ATTR_COLD void set_output(net_output_t *aout) { m_output = aout; }
ATTR_HOT inline void inactivate();
@ -469,10 +463,10 @@ public:
m_high_thresh_V = 2.0;
}
ATTR_HOT inline net_sig_t Q() const;
ATTR_HOT inline net_sig_t last_Q() const;
ATTR_HOT inline const net_sig_t Q() const;
ATTR_HOT inline const net_sig_t last_Q() const;
ATTR_COLD inline void set_thresholds(double low, double high)
ATTR_COLD inline void set_thresholds(const double low, const double high)
{
m_low_thresh_V = low;
m_high_thresh_V = high;
@ -492,8 +486,8 @@ public:
analog_input_t()
: net_input_t(INPUT | SIGNAL_ANALOG) { }
ATTR_HOT inline bool is_highz() const;
ATTR_HOT inline double Q_Analog() const;
ATTR_HOT inline const bool is_highz() const;
ATTR_HOT inline const double Q_Analog() const;
};
//#define INPVAL(_x) (_x).Q()
@ -511,7 +505,7 @@ public:
net_output_t(int atype);
friend net_sig_t logic_input_t::Q() const;
friend const net_sig_t logic_input_t::Q() const;
ATTR_HOT inline const net_sig_t last_Q() const { return m_last_Q; }
ATTR_HOT inline const net_sig_t new_Q() const { return m_new_Q; }
@ -541,9 +535,9 @@ public:
ATTR_HOT inline void inc_active();
ATTR_HOT inline void dec_active();
ATTR_HOT inline int active_count() { return m_active; }
ATTR_HOT inline netlist_time time() { return m_time; }
ATTR_HOT inline void set_time(netlist_time ntime) { m_time = ntime; }
ATTR_HOT inline const int active_count() const { return m_active; }
ATTR_HOT inline const netlist_time time() const { return m_time; }
ATTR_HOT inline void set_time(const netlist_time ntime) { m_time = ntime; }
ATTR_COLD void set_netdev(net_core_device_t *dev);
@ -588,15 +582,16 @@ protected:
UINT8 m_in_queue;
int m_active;
net_sig_t m_last_Q;
net_sig_t m_Q;
net_sig_t m_new_Q;
net_sig_t m_last_Q;
double m_Q_analog;
double m_new_Q_analog;
netlist_base_t *m_netlist;
int m_num_cons;
net_input_t *m_cons[48];
net_core_device_t *m_netdev;
@ -671,39 +666,25 @@ public:
ATTR_HOT virtual void update() { }
ATTR_HOT inline net_sig_t INPVAL_PASSIVE(logic_input_t &inp)
{
net_sig_t ret;
net_input_t::net_input_state st = inp.state();
if (st == net_input_t::INP_STATE_PASSIVE)
{
inp.activate();
ret = inp.Q();
inp.inactivate();
}
else
ret = inp.Q();
ATTR_HOT const net_sig_t INPVAL_PASSIVE(logic_input_t &inp);
return ret;
}
ATTR_HOT inline net_sig_t INPVAL(const logic_input_t &inp)
ATTR_HOT inline const net_sig_t INPVAL(const logic_input_t &inp)
{
assert(inp.state() != net_input_t::INP_STATE_PASSIVE);
return inp.Q();
}
ATTR_HOT inline net_sig_t INPVAL_LAST(const logic_input_t &inp) { return inp.last_Q(); }
ATTR_HOT inline const net_sig_t INPVAL_LAST(const logic_input_t &inp) { return inp.last_Q(); }
ATTR_HOT inline double INPANALOG(const analog_input_t &inp) { return inp.Q_Analog(); }
ATTR_HOT inline const double INPANALOG(const analog_input_t &inp) { return inp.Q_Analog(); }
ATTR_HOT inline netlist_base_t &netlist() const { return m_netlist; }
ATTR_COLD inline net_output_t * GETINPPTR(net_output_t &out) const { return &out; }
ATTR_HOT virtual void inc_active() { }
ATTR_HOT virtual void inc_active() { }
ATTR_HOT virtual void dec_active() { }
ATTR_HOT virtual void dec_active() { /*printf("DeActivate %s\n", m_name);*/ }
/* stats */
osd_ticks_t total_time;
@ -940,9 +921,6 @@ public:
ATTR_HOT ATTR_ALIGN void update()
{
const netlist_time times[2] = { NLTIME_FROM_NS(22), NLTIME_FROM_NS(15) };
//const UINT8 res_tab[4] = {1, 1, 1, 0 };
//const UINT8 ai1[4] = {0, 1, 0, 0 };
//const UINT8 ai2[4] = {1, 0, 1, 0 };
UINT8 res = _invert ^ 1 ^_check;
m_i[0].activate();
@ -1104,14 +1082,14 @@ public:
void set_clock_freq(UINT64 clockfreq);
ATTR_HOT inline void push_to_queue(net_output_t *out, const netlist_time &attime)
ATTR_HOT inline void push_to_queue(net_output_t &out, const netlist_time &attime)
{
m_queue.push(queue_t::entry_t(attime, out));
}
ATTR_HOT void process_list(INT32 &atime);
ATTR_HOT inline netlist_time &time() { return m_time_ps; }
ATTR_HOT inline const netlist_time &time() { return m_time_ps; }
ATTR_COLD void set_mainclock_dev(netdev_mainclock *dev) { m_mainclock = dev; }
@ -1251,7 +1229,7 @@ ATTR_HOT inline void net_output_t::push_to_queue(const netlist_time &delay)
if (m_active > 0)
{
m_in_queue = 1; /* pending */
m_netlist->push_to_queue(this, m_time);
m_netlist->push_to_queue(*this, m_time);
}
}
@ -1273,7 +1251,7 @@ ATTR_HOT inline void net_output_t::inc_active()
if (m_time > m_netlist->time())
{
m_in_queue = 1; /* pending */
m_netlist->push_to_queue(this, m_time);
m_netlist->push_to_queue(*this, m_time);
}
else
{
@ -1296,10 +1274,10 @@ ATTR_HOT inline void net_output_t::dec_active()
ATTR_HOT inline net_sig_t logic_input_t::Q() const { return output()->Q(); }
ATTR_HOT inline net_sig_t logic_input_t::last_Q() const { return output()->last_Q(); }
ATTR_HOT inline double analog_input_t::Q_Analog() const { return output()->Q_Analog(); }
ATTR_HOT inline bool analog_input_t::is_highz() const { return output()->Q_Analog() == NETLIST_HIGHIMP_V; }
ATTR_HOT inline const net_sig_t logic_input_t::Q() const { return output()->Q(); }
ATTR_HOT inline const net_sig_t logic_input_t::last_Q() const { return output()->last_Q(); }
ATTR_HOT inline const double analog_input_t::Q_Analog() const { return output()->Q_Analog(); }
ATTR_HOT inline const bool analog_input_t::is_highz() const { return output()->Q_Analog() == NETLIST_HIGHIMP_V; }
// ----------------------------------------------------------------------------------------
// net_dev class factory

View File

@ -620,7 +620,6 @@ INPUT_CHANGED_MEMBER(pong_state::input_changed)
}
static INPUT_PORTS_START( pong )
PORT_START( "PADDLE0" ) /* fake input port for player 1 paddle */
PORT_BIT( 0xff, 0x00, IPT_PADDLE ) PORT_SENSITIVITY(2) PORT_KEYDELTA(100) PORT_CENTERDELTA(0) PORT_CHANGED_MEMBER(DEVICE_SELF, pong_state, input_changed,IC_PADDLE1)