Previous 199869 Revisions Next

r26235 Sunday 17th November, 2013 at 19:07:14 UTC by Couriersud
netlist: Added capacitor. At 50kHz, calculating a resistor net and a cap doesn't hit performance. Promising.
[src/emu/netlist]nl_base.c nl_base.h nl_lists.h nl_parser.c nl_setup.c nl_setup.h nl_time.h
[src/emu/netlist/devices]net_lib.c net_lib.h nld_system.c nld_system.h
[src/mame/drivers]pong.c

trunk/src/emu/netlist/devices/nld_system.h
r26234r26235
1111
1212#include "../nl_setup.h"
1313#include "../nl_base.h"
14#include "../nl_lists.h"
1514
1615// ----------------------------------------------------------------------------------------
1716// Macros
r26234r26235
8382        netlist_ttl_output_t m_Q;
8483
8584        netlist_time m_inc;
85        netlist_time m_last_step;
86        netlist_list_t<netlist_terminal_t *> m_terms;
87        netlist_list_t<netlist_terminal_t *> m_inps;
88
8689public:
8790        netlist_list_t<netlist_net_t *> m_nets;
8891
8992        ATTR_HOT inline void schedule();
93
94        ATTR_COLD void post_start();
9095);
9196
9297inline void NETLIB_NAME(solver)::schedule()
9398{
9499    // FIXME: time should be parameter;
95    if (!m_Q.net().is_queued())
100    if (!m_Q.net().is_queued()) {
96101        m_Q.net().push_to_queue(NLTIME_FROM_NS(10));
102    }
97103}
98104
99105// ----------------------------------------------------------------------------------------
r26234r26235
154160
155161    ATTR_HOT ATTR_ALIGN virtual void update()
156162    {
157        netlist().solver().schedule();
158#if 0
159        if (!m_N.net().is_queued() && !m_N.net().isRailNet())
160            m_N.net().push_to_queue(NLTIME_FROM_NS(10));
161        if (!m_P.net().is_queued() && !m_P.net().isRailNet() )
162            m_P.net().push_to_queue(NLTIME_FROM_NS(10));
163#endif
163        /* only called if connected to a rail net ==> notify the solver to recalculate */
164        netlist().solver()->schedule();
164165    }
165166
166167    double m_g; // conductance
r26234r26235
198199private:
199200};
200201
202class nld_C : public nld_twoterm
203{
204public:
205    nld_C()
206    : nld_twoterm()
207    {
208    }
209
210    netlist_param_t m_C;
211
212protected:
213    void start()
214    {
215        register_terminal("1", m_P);
216        register_terminal("2", m_N);
217
218        register_param("C", m_C, NETLIST_GMIN);
219    }
220
221    virtual void update_param()
222    {
223        // set to some very big step time for now
224        // ==> large resistance
225        step_time(1e-9);
226    }
227
228    ATTR_HOT virtual void step_time(const double st)
229    {
230        m_g = m_P.m_g = m_N.m_g = m_C.Value() / st;
231        m_I = -m_g * (m_P.net().Q_Analog()- m_N.net().Q_Analog());
232    }
233private:
234};
235
201236#endif /* NLD_SYSTEM_H_ */
trunk/src/emu/netlist/devices/net_lib.c
r26234r26235
7575
7676NETLIB_UPDATE(log)
7777{
78   printf("%s: %d %d\n", name().cstr(), (UINT32) (netlist().time().as_raw() / 1000000), INPLOGIC(m_I));
78   printf("%s: %f %f\n", name().cstr(), netlist().time().as_double(), INPANALOG(m_I));
7979}
8080
8181
r26234r26235
950950static const net_device_t_base_factory *netregistry[] =
951951{
952952    ENTRY(R,                    NETDEV_R)
953    ENTRY(C,                    NETDEV_C)
953954   ENTRY(ttl_const,            NETDEV_TTL_CONST)
954955   ENTRY(analog_const,         NETDEV_ANALOG_CONST)
955956   ENTRY(logic_input,          NETDEV_LOGIC_INPUT)
trunk/src/emu/netlist/devices/net_lib.h
r26234r26235
7171
7272#define NETDEV_R(_name, _R)                                                         \
7373        NET_REGISTER_DEV(R, _name)                                                  \
74        NETDEV_PARAMI(_name, R, _R)                                           \
74        NETDEV_PARAMI(_name, R, _R)
7575
76#define NETDEV_C(_name, _C)                                                         \
77        NET_REGISTER_DEV(C, _name)                                                  \
78        NETDEV_PARAMI(_name, C, _C)
7679
80
7781// ----------------------------------------------------------------------------------------
7882// Special chips
7983// ----------------------------------------------------------------------------------------
r26234r26235
238242);
239243
240244NETLIB_DEVICE(log,
241   netlist_ttl_input_t m_I;
245   netlist_analog_input_t m_I;
242246);
243247
244248
trunk/src/emu/netlist/devices/nld_system.c
r26234r26235
8585    register_output("Q", m_Q);
8686    //register_input("FB", m_feedback);
8787
88    m_inc = netlist_time::from_hz(48000);
88    m_inc = netlist_time::from_hz(50000);
8989
9090    register_link_internal(m_feedback, m_Q, netlist_input_t::STATE_INP_ACTIVE);
91    m_last_step = netlist_time::zero;
9192
9293}
9394
r26234r26235
9697    //m_inc = netlist_time::from_hz(m_freq.Value()*2);
9798}
9899
100NETLIB_FUNC_VOID(solver, post_start, ())
101{
102    for (netlist_net_t **pn = m_nets.first(); pn != NULL; pn = m_nets.next(pn))
103    {
104        for (netlist_terminal_t *p = (*pn)->m_head; p != NULL; p = p->m_update_list_next)
105        {
106            switch (p->type())
107            {
108                case netlist_terminal_t::TERMINAL:
109                    m_terms.add(p);
110                    break;
111                case netlist_terminal_t::INPUT:
112                    m_inps.add(p);
113                    break;
114                default:
115                    fatalerror("unhandled element found\n");
116                    break;
117            }
118        }
119    }
120}
121
99122NETLIB_UPDATE(solver)
100123{
101124    //m_Q.setToNoCheck(!m_Q.new_Q(), m_inc  );
102125    //OUTLOGIC(m_Q, !m_Q.net().new_Q(), m_inc  );
103126
104    netlist_net_t **pn = m_nets.first();
105127    bool resched = false;
128    netlist_time now = netlist().time();
129    netlist_time delta = now - m_last_step;
106130
107    while (pn <= m_nets.last())
131    if (delta >= m_inc)
108132    {
133        /* update all terminals for new time step */
134        m_last_step = now;
135        for (netlist_terminal_t **p = m_terms.first(); p != NULL; p = m_terms.next(p))
136            (*p)->netdev().step_time(delta.as_double());
137    }
138    for (netlist_net_t **pn = m_nets.first(); pn != NULL; pn = m_nets.next(pn))
139    {
109140        double gtot = 0;
110141        double iIdr = 0;
111142
112        netlist_terminal_t *p = (*pn)->m_head;
113        do
143        for (netlist_terminal_t *p = (*pn)->m_head; p != NULL; p = p->m_update_list_next)
114144        {
115145            p->netdev().update_terminals();
116146            gtot += p->m_g;
117147            iIdr += p->m_Idr;
148        }
118149
119            p = p->m_update_list_next;
120        } while (p != NULL);
121        (*pn)->m_new.Analog = iIdr / gtot;
122        if (fabs((*pn)->m_new.Analog - (*pn)->m_cur.Analog) > 1e-4)
150        double new_val = iIdr / gtot;
151        if (fabs(new_val - (*pn)->m_cur.Analog) > 1e-4)
123152            resched = true;
124        (*pn)->m_cur.Analog = (*pn)->m_new.Analog;
153        (*pn)->m_cur.Analog = (*pn)->m_new.Analog = new_val;
125154
126        //printf("New: %f\n", (*pn)->m_new.Analog);
127        pn++;
155        //printf("New: %d %lld %f %f\n", ts_cnt, netlist().time().as_raw(), netlist().time().as_double(), new_val);
128156    }
129157    if (resched)
158    {
130159        schedule();
160    }
131161    else
132      m_Q.net().push_to_queue(m_inc); // step circuit
162    {
163        /* update all inputs connected to this drive */
164        for (netlist_terminal_t **p = m_inps.first(); p != NULL; p = m_inps.next(p))
165            (*p)->netdev().update_dev();
166        /* step circuit */
167        if (!m_Q.net().is_queued())
168        {
169            m_Q.net().push_to_queue(m_inc);
170        }
171    }
133172
134173        /* only inputs and terminals connected
135174         * approach:
trunk/src/emu/netlist/nl_base.c
r26234r26235
233233
234234ATTR_COLD void netlist_device_t::register_input(netlist_core_device_t &dev, const astring &name, netlist_input_t &inp, netlist_input_t::state_e type)
235235{
236    m_terminals.add(name);
236237   m_setup->register_object(*this, dev, name, inp, type);
237238}
238239
trunk/src/emu/netlist/nl_parser.c
r26234r26235
9696      skipws();
9797      astring output_name = getname2(',', ')');
9898      NL_VERBOSE_OUT(("Parser: ID: %s %s\n", output_name.cstr(), dev->m_terminals.item(cnt)->cstr()));
99      m_setup.register_link(*dev->m_terminals.item(cnt), output_name);
99      m_setup.register_link(devname + "." + *dev->m_terminals.item(cnt), output_name);
100100      skipws();
101101      cnt++;
102102   }
trunk/src/emu/netlist/nl_base.h
r26234r26235
168168//          : net_device_t(setup, name)
169169
170170#define NETLIB_UPDATE_PARAM(_chip) ATTR_HOT ATTR_ALIGN void NETLIB_NAME(_chip) :: update_param(void)
171#define NETLIB_FUNC_VOID(_chip, _name, _params) ATTR_HOT ATTR_ALIGN inline void NETLIB_NAME(_chip) :: _name _params
171#define NETLIB_FUNC_VOID(_chip, _name, _params) ATTR_HOT ATTR_ALIGN void NETLIB_NAME(_chip) :: _name _params
172172
173173#define NETLIB_DEVICE_BASE(_name, _pclass, _extra, _priv)                           \
174174    class _name : public _pclass                                                    \
r26234r26235
661661
662662   ATTR_HOT virtual void dec_active() { /*printf("DeActivate %s\n", m_name);*/ }
663663
664   ATTR_HOT virtual void step_time(const double st) { }
664665    ATTR_HOT virtual void update_terminals() { }
665666
666667   /* stats */
r26234r26235
774775      m_queue.push(queue_t::entry_t(attime, out));
775776   }
776777
777   ATTR_HOT NETLIB_NAME(solver) &solver() { return *m_solver; }
778   ATTR_HOT NETLIB_NAME(solver) *solver() { return m_solver; }
778779
779780   ATTR_HOT void process_queue(INT32 &atime);
780781
trunk/src/emu/netlist/nl_setup.c
r26234r26235
4141netlist_setup_t::~netlist_setup_t()
4242{
4343   tagmap_free_entries<tagmap_devices_t>(m_devices);
44   tagmap_free_entries<tagmap_astring_t>(m_links);
44   tagmap_free_entries<tagmap_link_t>(m_links);
4545   tagmap_free_entries<tagmap_astring_t>(m_alias);
4646   m_params.reset();
4747   m_terminals.reset();
r26234r26235
8282   //remove_start_with<tagmap_input_t>(m_inputs, temp);
8383   remove_start_with<tagmap_terminal_t>(m_terminals, temp);
8484   remove_start_with<tagmap_param_t>(m_params, temp);
85   remove_start_with<tagmap_astring_t>(m_links, temp);
85
86   tagmap_link_t::entry_t *p = m_links.first();
87   while (p != NULL)
88   {
89       tagmap_link_t::entry_t *n = m_links.next(p);
90       if (temp.cmpsubstr(p->object()->e1,0,temp.len()) == 0 || temp.cmpsubstr(p->object()->e2,0,temp.len()) == 0)
91           m_links.remove(p->object());
92       p = n;
93   }
8694   m_devices.remove(name);
8795}
8896
r26234r26235
141149                term.init_terminal(upd_dev);
142150                term.set_state(state);
143151                if (!(m_terminals.add(temp, &term, false)==TMERR_NONE))
144                    fatalerror("Error adding %s %s to terminal list\n", objtype_as_astr(term).cstr(), name.cstr());
152                    fatalerror("Error adding %s %s to terminal list\n", objtype_as_astr(term).cstr(), temp.cstr());
145153                NL_VERBOSE_OUT(("%s %s\n", objtype_as_astr(term).cstr(), name.cstr()));
146154            }
147155            break;
r26234r26235
164172
165173void netlist_setup_t::register_link(const astring &sin, const astring &sout)
166174{
167   const astring *temp = new astring(sout);
175   link_t *temp = new link_t(sin, sout);
168176   NL_VERBOSE_OUT(("link %s <== %s\n", sin.cstr(), sout.cstr()));
169   if (!(m_links.add(sin, temp, false)==TMERR_NONE))
177   if (!(m_links.add(sin + "." + sout, temp, false)==TMERR_NONE))
170178      fatalerror("Error adding link %s<==%s to link list\n", sin.cstr(), sout.cstr());
171179}
172180
r26234r26235
266274    }
267275}
268276
277void netlist_setup_t::connect_terminal_input(netlist_terminal_t &term, netlist_input_t &inp)
278{
279    if (inp.isFamily(netlist_terminal_t::ANALOG))
280    {
281        connect_terminals(term, inp);
282    }
283    else if (inp.isFamily(netlist_terminal_t::LOGIC))
284    {
285        //printf("here 1\n");
286        nld_a_to_d_proxy *proxy = new nld_a_to_d_proxy(inp);
287        astring x = "";
288        x.printf("proxy_da_%d", m_proxy_cnt++);
289        proxy->init(*this, x.cstr());
290        register_dev(proxy);
291
292        connect_terminals(term, proxy->m_I);
293
294        if (inp.has_net())
295            proxy->m_Q.net().merge_net(&inp.net());
296        else
297            proxy->m_Q.net().register_con(inp);
298    }
299    else
300    {
301        fatalerror("Netlist: Severe Error");
302    }
303}
304
269305// FIXME: optimize code  ...
270306void netlist_setup_t::connect_terminal_output(netlist_terminal_t &in, netlist_output_t &out)
271307{
r26234r26235
322358        NL_VERBOSE_OUT(("adding net ...\n"));
323359        netlist_net_t *anet =  new netlist_net_t(netlist_object_t::NET, netlist_object_t::ANALOG);
324360        in.set_net(*anet);
325        m_netlist.solver().m_nets.add(anet);
361        m_netlist.solver()->m_nets.add(anet);
326362        in.net().init_object(netlist());
327363        in.net().register_con(out);
328364        in.net().register_con(in);
r26234r26235
347383    }
348384
349385    NL_VERBOSE_OUT(("Resolving ...\n"));
350    for (tagmap_astring_t::entry_t *entry = m_links.first(); entry != NULL; entry = m_links.next(entry))
386    for (tagmap_link_t::entry_t *entry = m_links.first(); entry != NULL; entry = m_links.next(entry))
351387    {
352        const astring t1s = *entry->object();
353        const astring t2s = entry->tag();
388        const astring t1s = entry->object()->e1;
389        const astring t2s = entry->object()->e2;
354390        netlist_terminal_t &t1 = find_terminal(t1s);
355391        netlist_terminal_t &t2 = find_terminal(t2s);
356392
r26234r26235
376412        {
377413            connect_terminal_output(dynamic_cast<netlist_terminal_t &>(t1), dynamic_cast<netlist_output_t &>(t2));
378414        }
415        else if (t1.isType(netlist_terminal_t::INPUT) && t2.isType(netlist_terminal_t::TERMINAL))
416        {
417            connect_terminal_input(dynamic_cast<netlist_terminal_t &>(t2), dynamic_cast<netlist_input_t &>(t1));
418        }
419        else if (t1.isType(netlist_terminal_t::TERMINAL) && t2.isType(netlist_terminal_t::INPUT))
420        {
421            connect_terminal_input(dynamic_cast<netlist_terminal_t &>(t1), dynamic_cast<netlist_input_t &>(t2));
422        }
379423        else if (t1.isType(netlist_terminal_t::TERMINAL) && t2.isType(netlist_terminal_t::TERMINAL))
380424        {
381425            connect_terminals(dynamic_cast<netlist_terminal_t &>(t1), dynamic_cast<netlist_terminal_t &>(t2));
r26234r26235
392436            //VERBOSE_OUT(("%s %d\n", out->netdev()->name(), *out->Q_ptr()));
393437    }
394438
439    if (m_netlist.solver() != NULL)
440        m_netlist.solver()->post_start();
395441
442
396443}
397444
398445void netlist_setup_t::step_devices_once(void)
trunk/src/emu/netlist/nl_time.h
r26234r26235
4545   ATTR_HOT inline const netlist_time &operator+=(const netlist_time &right) { m_time += right.m_time; return *this; }
4646
4747   ATTR_HOT inline const INTERNALTYPE as_raw() const { return m_time; }
48    ATTR_HOT inline const double as_double() const { return (double) m_time / (double) RESOLUTION; }
4849
4950   ATTR_HOT static inline const netlist_time from_nsec(const int ns) { return netlist_time((UINT64) ns * (RESOLUTION / U64(1000000000))); }
5051   ATTR_HOT static inline const netlist_time from_usec(const int us) { return netlist_time((UINT64) us * (RESOLUTION / U64(1000000))); }
trunk/src/emu/netlist/nl_lists.h
r26234r26235
3636
3737      *(++m_ptr) = elem;
3838   }
39   ATTR_HOT inline void resize(const int new_size)
40   {
41       int cnt = count();
42       _ListClass *m_new = new _ListClass[new_size];
43       memcpy(m_new, m_list, new_size * sizeof(_ListClass));
44       delete[] m_list;
45       m_list = m_new;
46       m_ptr = m_list + cnt - 1;
47   }
3948    ATTR_HOT inline void del(const _ListClass elem)
4049    {
4150        for (_ListClass * i=m_list; i<=m_ptr; i++)
r26234r26235
5261            }
5362        }
5463    }
55   ATTR_HOT inline _ListClass *first() { return &m_list[0]; }
64   ATTR_HOT inline _ListClass *first() { return (m_ptr >= m_list ? &m_list[0] : NULL ); }
65    ATTR_HOT inline _ListClass *next(_ListClass *lc) { return (lc < last() ? lc + 1 : NULL ); }
5666   ATTR_HOT inline _ListClass *last()  { return m_ptr; }
5767   ATTR_HOT inline _ListClass *item(int i) { return &m_list[i]; }
5868   ATTR_HOT inline int count() const { return m_ptr - m_list + 1; }
trunk/src/emu/netlist/nl_setup.h
r26234r26235
6363{
6464public:
6565
66    struct link_t
67    {
68        link_t(const astring &ae1, const astring &ae2)
69        {
70            e1 = ae1;
71            e2 = ae2;
72        }
73        astring e1;
74        astring e2;
75    };
76
6677   typedef tagmap_t<netlist_device_t *, 393> tagmap_devices_t;
78    typedef tagmap_t<link_t *, 393> tagmap_link_t;
6779   typedef tagmap_t<const astring *, 393> tagmap_astring_t;
6880   typedef tagmap_t<netlist_param_t *, 393> tagmap_param_t;
6981   typedef tagmap_t<netlist_terminal_t *, 393> tagmap_terminal_t;
r26234r26235
108120   tagmap_devices_t m_devices;
109121   tagmap_astring_t m_alias;
110122   tagmap_param_t  m_params;
111   tagmap_astring_t  m_links;
123   tagmap_link_t  m_links;
112124
113125   int m_proxy_cnt;
114126
115127   void connect_terminals(netlist_terminal_t &in, netlist_terminal_t &out);
116128   void connect_input_output(netlist_input_t &in, netlist_output_t &out);
117129    void connect_terminal_output(netlist_terminal_t &in, netlist_output_t &out);
130    void connect_terminal_input(netlist_terminal_t &term, netlist_input_t &inp);
118131
119132    // helpers
120133    astring objtype_as_astr(netlist_object_t &in);
trunk/src/mame/drivers/pong.c
r26234r26235
465465   NETDEV_PARAM(videomix.R2, RES_K(1.2))
466466   NETDEV_PARAM(videomix.R3, RES_K(22))
467467
468#if 0
469   NETDEV_SOLVER(Solver)
470   NETDEV_ANALOG_CONST(V5, 5)
468    NETDEV_SOLVER(Solver)
469    NETDEV_ANALOG_CONST(V5, 5)
471470    NETDEV_ANALOG_CONST(V0, 0)
471#if 1
472472    NETDEV_R(R1, 10)
473473    NETDEV_R(R2, 10)
474474    NETDEV_R(R3, 10)
r26234r26235
477477    NET_C(R2.2, R3.1)
478478    NET_C(R3.2, V0)
479479#endif
480#if 1
481    NETDEV_R(R4, 1000)
482    NETDEV_C(C1, 1e-6)
483    NET_C(V5,R4.1)
484    NET_C(R4.2, C1.1)
485    NET_C(C1.2, V0)
486    //NETDEV_LOG(log1, C1.1)
487#endif
480488NETLIST_END
481489
482490static NETLIST_START(pong)

Previous 199869 Revisions Next


© 1997-2024 The MAME Team