Previous 199869 Revisions Next

r26399 Sunday 24th November, 2013 at 20:08:04 UTC by Couriersud
Netlist: Added pascal like strings (pstring) class. These use only size(void *) in objects. Uses reference counter to share identical string between various pstrings.

In addition, fixed some bugs and added auto-sizing to netlist_list_t.

There shouldn't be memory holes left now, apart from memory allocated in a static class factory.
[src/emu/machine]netlist.c netlist.h
[src/emu/netlist]netlist.mak nl_base.c nl_base.h nl_config.h nl_lists.h nl_parser.c nl_parser.h nl_setup.c nl_setup.h nl_time.h pstring.c* pstring.h*
[src/emu/netlist/devices]net_lib.c nld_system.c nld_system.h

trunk/src/emu/machine/netlist.c
r26398r26399
4949#include "netlist/nl_setup.h"
5050#include "netlist/devices/net_lib.h"
5151
52const netlist_time netlist_time::zero = netlist_time::from_raw(0);
53
5452// ----------------------------------------------------------------------------------------
5553// netlist_mame_device
5654// ----------------------------------------------------------------------------------------
r26398r26399
9189   m_setup->start_devices();
9290
9391   bool allok = true;
94   for (on_device_start **ods = m_device_start_list.first(); ods <= m_device_start_list.last(); ods++)
95      allok &= (*ods)->OnDeviceStart();
92   for (device_start_list_t::entry_t *ods = m_device_start_list.first(); ods != NULL; ods = m_device_start_list.next(ods))
93      allok &= ods->object()->OnDeviceStart();
9694
9795   if (!allok)
9896      fatalerror("required elements not found\n");
trunk/src/emu/machine/netlist.h
r26398r26399
118118   netlist_setup_t &setup() { return *m_setup; }
119119   netlist_t &netlist() { return *m_netlist; }
120120
121   netlist_list_t<on_device_start *> m_device_start_list;
121   typedef netlist_list_t<on_device_start *> device_start_list_t;
122122
123   device_start_list_t m_device_start_list;
124
123125protected:
124126   // device-level overrides
125127   virtual void device_config_complete();
trunk/src/emu/netlist/nl_base.h
r26398r26399
138138#include "nl_config.h"
139139#include "nl_lists.h"
140140#include "nl_time.h"
141#include "pstring.h"
141142
142143// ----------------------------------------------------------------------------------------
143144// Type definitions
r26398r26399
248249
249250   virtual ~netlist_object_t();
250251
251   ATTR_COLD void init_object(netlist_base_t &nl, const astring &aname);
252   ATTR_COLD void init_object(netlist_base_t &nl, const pstring &aname);
252253
253    ATTR_COLD const astring &name() const;
254    ATTR_COLD const pstring &name() const;
254255
255256   ATTR_HOT inline const type_t type() const { return m_objtype; }
256257    ATTR_HOT inline const family_t family() const { return m_family; }
r26398r26399
262263    ATTR_HOT inline const netlist_base_t & RESTRICT netlist() const { return *m_netlist; }
263264
264265private:
266    pstring m_name;
265267   const type_t m_objtype;
266268    const family_t m_family;
267269    netlist_base_t * RESTRICT m_netlist;
268    astring *m_name;
269270};
270271
271272// ----------------------------------------------------------------------------------------
r26398r26399
277278public:
278279    ATTR_COLD netlist_owned_object_t(const type_t atype, const family_t afamily);
279280
280    ATTR_COLD void init_object(netlist_core_device_t &dev, const astring &aname);
281    ATTR_COLD void init_object(netlist_core_device_t &dev, const pstring &aname);
281282
282283    ATTR_HOT inline netlist_core_device_t & RESTRICT netdev() const { return *m_netdev; }
283284private:
r26398r26399
306307   ATTR_COLD netlist_terminal_t(const type_t atype, const family_t afamily);
307308    ATTR_COLD netlist_terminal_t();
308309
309   ATTR_COLD void init_object(netlist_core_device_t &dev, const astring &aname, const state_e astate);
310   ATTR_COLD void init_object(netlist_core_device_t &dev, const pstring &aname, const state_e astate);
310311
311312    ATTR_COLD void set_net(netlist_net_t &anet);
312313    ATTR_COLD inline bool has_net() { return (m_net != NULL); }
r26398r26399
515516
516517   ATTR_COLD netlist_output_t(const type_t atype, const family_t afamily);
517518
518    ATTR_COLD void init_object(netlist_core_device_t &dev, const astring &aname);
519    ATTR_COLD void init_object(netlist_core_device_t &dev, const pstring &aname);
519520
520521   double m_low_V;
521522   double m_high_V;
r26398r26399
601602
602603    ATTR_COLD virtual ~netlist_core_device_t();
603604
604   ATTR_COLD virtual void init(netlist_setup_t &setup, const astring &name);
605   ATTR_COLD virtual void init(netlist_setup_t &setup, const pstring &name);
605606
606607
607608   ATTR_HOT virtual void update_param() {}
r26398r26399
656657   ATTR_HOT virtual void step_time(const double st) { }
657658    ATTR_HOT virtual void update_terminals() { }
658659
659   /* stats */
660#if (NL_KEEP_STATISTICS)
661    /* stats */
660662   osd_ticks_t total_time;
661663   INT32 stat_count;
664#endif
662665
663666#if USE_DELEGATES
664667   net_update_delegate static_update;
r26398r26399
681684
682685   ATTR_COLD virtual ~netlist_device_t();
683686
684   ATTR_COLD virtual void init(netlist_setup_t &setup, const astring &name);
687   ATTR_COLD virtual void init(netlist_setup_t &setup, const pstring &name);
685688
686689   ATTR_COLD const netlist_setup_t *setup() const { return m_setup; }
687690
688691   ATTR_COLD bool variable_input_count() { return m_variable_input_count; }
689692
690   ATTR_COLD void register_sub(netlist_core_device_t &dev, const astring &name);
693   ATTR_COLD void register_sub(netlist_core_device_t &dev, const pstring &name);
691694
692    ATTR_COLD void register_terminal(const astring &name, netlist_terminal_t &port);
695    ATTR_COLD void register_terminal(const pstring &name, netlist_terminal_t &port);
693696
694   ATTR_COLD void register_output(const astring &name, netlist_output_t &out);
695   ATTR_COLD void register_output(netlist_core_device_t &dev, const astring &name, netlist_output_t &out);
697   ATTR_COLD void register_output(const pstring &name, netlist_output_t &out);
698   ATTR_COLD void register_output(netlist_core_device_t &dev, const pstring &name, netlist_output_t &out);
696699
697   ATTR_COLD void register_input(const astring &name, netlist_input_t &in, netlist_input_t::state_e state = netlist_input_t::STATE_INP_ACTIVE);
698   ATTR_COLD void register_input(netlist_core_device_t &dev, const astring &name, netlist_input_t &in, netlist_input_t::state_e state = netlist_input_t::STATE_INP_ACTIVE);
700   ATTR_COLD void register_input(const pstring &name, netlist_input_t &in, netlist_input_t::state_e state = netlist_input_t::STATE_INP_ACTIVE);
701   ATTR_COLD void register_input(netlist_core_device_t &dev, const pstring &name, netlist_input_t &in, netlist_input_t::state_e state = netlist_input_t::STATE_INP_ACTIVE);
699702
700703   ATTR_COLD void register_link_internal(netlist_input_t &in, netlist_output_t &out, netlist_input_t::state_e aState);
701704   ATTR_COLD void register_link_internal(netlist_core_device_t &dev, netlist_input_t &in, netlist_output_t &out, netlist_input_t::state_e aState);
r26398r26399
703706    ATTR_HOT virtual void update_terminals() { }
704707
705708    /* driving logic outputs don't count in here */
706   netlist_list_t<astring> m_terminals;
709   netlist_list_t<pstring, 20> m_terminals;
707710
708711protected:
709712
710713   virtual void update() { }
711714   virtual void start() { }
712715
713   ATTR_COLD void register_param(const astring &sname, netlist_param_t &param, const double initialVal = 0.0);
714   ATTR_COLD void register_param(netlist_core_device_t &dev, const astring &sname, netlist_param_t &param, const double initialVal = 0.0);
716   ATTR_COLD void register_param(const pstring &sname, netlist_param_t &param, const double initialVal = 0.0);
717   ATTR_COLD void register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_t &param, const double initialVal = 0.0);
715718
716719   netlist_setup_t *m_setup;
717720   bool m_variable_input_count;
r26398r26399
780783   ATTR_COLD void reset();
781784
782785protected:
786#if (NL_KEEP_STATISTICS)
783787   // performance
784788   int m_perf_out_processed;
785789   int m_perf_inp_processed;
786790   int m_perf_inp_active;
791#endif
787792
788793private:
794    netlist_time                m_time_ps;
789795    queue_t                     m_queue;
790   NETLIB_NAME(mainclock) *    m_mainclock;
791    NETLIB_NAME(solver) *       m_solver;
792   netlist_time                m_time_ps;
793796   UINT32                      m_rem;
794797   UINT32                      m_div;
795798
799   NETLIB_NAME(mainclock) *    m_mainclock;
800    NETLIB_NAME(solver) *       m_solver;
801
796802   ATTR_HOT void update_time(const netlist_time t, INT32 &atime);
797803
798804};
r26398r26399
9941000class net_device_t_base_factory
9951001{
9961002public:
997   net_device_t_base_factory(const astring &name, const astring &classname)
1003   net_device_t_base_factory(const pstring &name, const pstring &classname)
9981004   : m_name(name), m_classname(classname)
9991005   {}
10001006
r26398r26399
10021008
10031009   virtual netlist_device_t *Create() const = 0;
10041010
1005   const astring &name() const { return m_name; }
1006   const astring &classname() const { return m_classname; }
1011   const pstring &name() const { return m_name; }
1012   const pstring &classname() const { return m_classname; }
10071013protected:
1008   astring m_name;                             /* device name */
1009   astring m_classname;                        /* device class name */
1014   pstring m_name;                             /* device name */
1015   pstring m_classname;                        /* device class name */
10101016};
10111017
10121018template <class C>
10131019class net_device_t_factory : public net_device_t_base_factory
10141020{
10151021public:
1016   net_device_t_factory(const astring &name, const astring &classname)
1022   net_device_t_factory(const pstring &name, const pstring &classname)
10171023   : net_device_t_base_factory(name, classname) { }
10181024
10191025   netlist_device_t *Create() const
r26398r26399
10241030   }
10251031};
10261032
1027netlist_device_t *net_create_device_by_classname(const astring &classname, netlist_setup_t &setup);
1028netlist_device_t *net_create_device_by_name(const astring &name, netlist_setup_t &setup);
1033netlist_device_t *net_create_device_by_classname(const pstring &classname, netlist_setup_t &setup);
1034netlist_device_t *net_create_device_by_name(const pstring &name, netlist_setup_t &setup);
10291035
10301036
10311037#endif /* NLBASE_H_ */
trunk/src/emu/netlist/netlist.mak
r26398r26399
1818#-------------------------------------------------
1919
2020NETLISTOBJS+= \
21   $(NETLISTOBJ)/nl_base.o \
22   $(NETLISTOBJ)/pstring.o \
2123   $(NETLISTOBJ)/nl_setup.o \
22   $(NETLISTOBJ)/nl_base.o \
2324   $(NETLISTOBJ)/nl_parser.o \
2425   $(NETLISTOBJ)/devices/nld_system.o \
2526   $(NETLISTOBJ)/devices/net_lib.o \
trunk/src/emu/netlist/nl_setup.c
r26398r26399
4141netlist_setup_t::~netlist_setup_t()
4242{
4343   tagmap_free_entries<tagmap_devices_t>(m_devices);
44   tagmap_free_entries<tagmap_link_t>(m_links);
45   tagmap_free_entries<tagmap_astring_t>(m_alias);
44   //tagmap_free_entries<tagmap_link_t>(m_links);
45   //tagmap_free_entries<tagmap_nstring_t>(m_alias);
46   m_links.reset();
47   m_alias.reset();
4648   m_params.reset();
4749   m_terminals.reset();
50   m_params_temp.reset();
51   pstring::resetmem();
4852}
4953
50netlist_device_t *netlist_setup_t::register_dev(netlist_device_t *dev, const astring &name)
54netlist_device_t *netlist_setup_t::register_dev(netlist_device_t *dev, const pstring &name)
5155{
5256   if (!(m_devices.add(name, dev, false)==TMERR_NONE))
5357      fatalerror("Error adding %s to device list\n", name.cstr());
r26398r26399
5559}
5660
5761template <class T>
58static void remove_start_with(T &hm, astring &sw)
62static void remove_start_with(T &hm, pstring &sw)
5963{
6064   typename T::entry_t *entry = hm.first();
6165   while (entry != NULL)
6266   {
6367      typename T::entry_t *next = hm.next(entry);
64      if (sw.cmpsubstr(entry->tag(), 0, sw.len()) == 0)
68      pstring x = entry->tag().cstr();
69      if (sw.equals(x.substr(0, sw.len())))
6570      {
6671         NL_VERBOSE_OUT(("removing %s\n", entry->tag().cstr()));
6772         hm.remove(entry->object());
r26398r26399
7075   }
7176}
7277
73void netlist_setup_t::remove_dev(const astring &name)
78void netlist_setup_t::remove_dev(const pstring &name)
7479{
7580   netlist_device_t *dev = m_devices.find(name);
76   astring temp = name;
81   pstring temp = name + ".";
7782   if (dev == NULL)
7883      fatalerror("Device %s does not exist\n", name.cstr());
7984
80   temp.cat(".");
81
8285   //remove_start_with<tagmap_input_t>(m_inputs, temp);
8386   remove_start_with<tagmap_terminal_t>(m_terminals, temp);
8487   remove_start_with<tagmap_param_t>(m_params, temp);
r26398r26399
8790   while (p != NULL)
8891   {
8992       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)
93       if (temp.equals(p->object().e1.substr(0,temp.len())) || temp.equals(p->object().e2.substr(0,temp.len())))
9194           m_links.remove(p->object());
9295       p = n;
9396   }
9497   m_devices.remove(name);
9598}
9699
97void netlist_setup_t::register_callback(const astring &devname, netlist_output_delegate delegate)
100void netlist_setup_t::register_callback(const pstring &devname, netlist_output_delegate delegate)
98101{
99102   NETLIB_NAME(analog_callback) *dev = (NETLIB_NAME(analog_callback) *) m_devices.find(devname);
100103   if (dev == NULL)
r26398r26399
102105   dev->register_callback(delegate);
103106}
104107
105void netlist_setup_t::register_alias(const astring &alias, const astring &out)
108void netlist_setup_t::register_alias(const pstring &alias, const pstring &out)
106109{
107   if (!(m_alias.add(alias, new astring(out), false)==TMERR_NONE))
110    //if (!(m_alias.add(alias, new nstring(out), false)==TMERR_NONE))
111   if (!(m_alias.add(alias, out, false)==TMERR_NONE))
108112      fatalerror("Error adding alias %s to alias list\n", alias.cstr());
109113}
110114
111astring netlist_setup_t::objtype_as_astr(netlist_object_t &in)
115pstring netlist_setup_t::objtype_as_astr(netlist_object_t &in)
112116{
113117    switch (in.type())
114118    {
r26398r26399
134138    fatalerror("Unknown object type %d\n", in.type());
135139}
136140
137void netlist_setup_t::register_object(netlist_device_t &dev, netlist_core_device_t &upd_dev, const astring &name, netlist_object_t &obj, netlist_input_t::state_e state)
141void netlist_setup_t::register_object(netlist_device_t &dev, netlist_core_device_t &upd_dev, const pstring &name, netlist_object_t &obj, netlist_input_t::state_e state)
138142{
139143    switch (obj.type())
140144    {
r26398r26399
157161            break;
158162        case netlist_terminal_t::PARAM:
159163            {
164
160165                netlist_param_t &param = dynamic_cast<netlist_param_t &>(obj);
161                astring temp = param.netdev().name();
162                temp.cat(".");
163                temp.cat(name);
164                const astring *val = m_params_temp.find(temp);
165                if (val != NULL)
166                pstring temp = param.netdev().name() + "." + name;
167                const pstring val = m_params_temp.find(temp);
168                if (val != "")
166169                {
167170                    //printf("Found parameter ... %s : %s\n", temp.cstr(), val->cstr());
168171                    double vald = 0;
169                    if (sscanf(val->cstr(), "%lf", &vald) != 1)
170                        fatalerror("Invalid number conversion %s : %s\n", temp.cstr(), val->cstr());
172                    if (sscanf(val.cstr(), "%lf", &vald) != 1)
173                        fatalerror("Invalid number conversion %s : %s\n", temp.cstr(), val.cstr());
171174                    param.initial(vald);
172175                }
173176                if (!(m_params.add(temp, &param, false)==TMERR_NONE))
r26398r26399
179182    }
180183}
181184
182void netlist_setup_t::register_link(const astring &sin, const astring &sout)
185void netlist_setup_t::register_link(const pstring &sin, const pstring &sout)
183186{
184   link_t *temp = new link_t(sin, sout);
187   link_t temp = link_t(sin, sout);
185188   NL_VERBOSE_OUT(("link %s <== %s\n", sin.cstr(), sout.cstr()));
186   if (!(m_links.add(sin + "." + sout, temp, false)==TMERR_NONE))
187      fatalerror("Error adding link %s<==%s to link list\n", sin.cstr(), sout.cstr());
189    m_links.add(temp);
190   //if (!(m_links.add(sin + "." + sout, temp, false)==TMERR_NONE))
191   //   fatalerror("Error adding link %s<==%s to link list\n", sin.cstr(), sout.cstr());
188192}
189193
190void netlist_setup_t::register_param(const astring &param, const double value)
194void netlist_setup_t::register_param(const pstring &param, const double value)
191195{
192196    // FIXME: there should be a better way
193    astring temp;
194    temp.printf("%.9e", value);
195    register_param(param, temp);
197    register_param(param, pstring::sprintf("%.9e", value));
196198}
197199
198void netlist_setup_t::register_param(const astring &param, const astring &value)
200void netlist_setup_t::register_param(const pstring &param, const pstring &value)
199201{
200    if (!(m_params_temp.add(param, new astring(value), false)==TMERR_NONE))
202    //if (!(m_params_temp.add(param, new nstring(value), false)==TMERR_NONE))
203    if (!(m_params_temp.add(param, value, false)==TMERR_NONE))
201204        fatalerror("Error adding parameter %s to parameter list\n", param.cstr());
202205}
203206
204const astring netlist_setup_t::resolve_alias(const astring &name) const
207const pstring netlist_setup_t::resolve_alias(const pstring &name) const
205208{
206   const astring *temp = m_alias.find(name);
207   astring ret = name;
208   if (temp != NULL)
209      ret = *temp;
209   const pstring temp = m_alias.find(name);
210   pstring ret = name;
211   if (temp != "")
212      ret = temp;
210213   int p = ret.find(".[");
211214   if (p > 0)
212215   {
213       astring dname = ret;
216       pstring dname = ret;
214217       netlist_device_t *dev = m_devices.find(dname.substr(0,p));
215218       if (dev == NULL)
216219           fatalerror("Device for %s not found\n", name.cstr());
217       ret.substr(p+2,ret.len()-p-3);
218       int c = atoi(ret);
219       ret = dev->name() + "." + *(dev->m_terminals.item(c));
220       int c = atoi(ret.substr(p+2,ret.len()-p-3));
221       ret = dev->name() + "." + dev->m_terminals.item(c)->object();
220222   }
221223
224    //printf("%s==>%s\n", name.cstr(), ret.cstr());
222225   return ret;
223226}
224227
225netlist_terminal_t &netlist_setup_t::find_terminal(const astring &terminal_in)
228netlist_terminal_t &netlist_setup_t::find_terminal(const pstring &terminal_in)
226229{
227    const astring &tname = resolve_alias(terminal_in);
230    const pstring &tname = resolve_alias(terminal_in);
228231    netlist_terminal_t *ret;
229232
230233    ret = dynamic_cast<netlist_terminal_t *>(m_terminals.find(tname));
r26398r26399
232235    if (ret == NULL)
233236    {
234237        /* look for ".Q" std output */
235        astring s = tname;
236        s.cat(".Q");
238        pstring s = tname + ".Q";
237239        ret = dynamic_cast<netlist_terminal_t *>(m_terminals.find(s));
238240    }
239241    if (ret == NULL)
r26398r26399
242244    return *ret;
243245}
244246
245netlist_terminal_t &netlist_setup_t::find_terminal(const astring &terminal_in, netlist_object_t::type_t atype)
247netlist_terminal_t &netlist_setup_t::find_terminal(const pstring &terminal_in, netlist_object_t::type_t atype)
246248{
247   const astring &tname = resolve_alias(terminal_in);
249   const pstring &tname = resolve_alias(terminal_in);
248250   netlist_terminal_t *ret;
249251
250252   ret = dynamic_cast<netlist_terminal_t *>(m_terminals.find(tname));
r26398r26399
252254   if (ret == NULL && atype == netlist_object_t::OUTPUT)
253255   {
254256      /* look for ".Q" std output */
255      astring s = tname;
256      s.cat(".Q");
257      pstring s = tname + ".Q";
257258      ret = dynamic_cast<netlist_terminal_t *>(m_terminals.find(s));
258259   }
259260   if (ret == NULL)
r26398r26399
264265   return *ret;
265266}
266267
267netlist_param_t &netlist_setup_t::find_param(const astring &param_in)
268netlist_param_t &netlist_setup_t::find_param(const pstring &param_in)
268269{
269   const astring &outname = resolve_alias(param_in);
270   const pstring &outname = resolve_alias(param_in);
270271   netlist_param_t *ret;
271272
272273   ret = m_params.find(outname);
r26398r26399
282283    if (out.isFamily(netlist_terminal_t::ANALOG) && in.isFamily(netlist_terminal_t::LOGIC))
283284    {
284285        nld_a_to_d_proxy *proxy = new nld_a_to_d_proxy(in);
285        astring x = "";
286        x.printf("proxy_ad_%d", m_proxy_cnt++);
286        pstring x = pstring::sprintf("proxy_ad_%d", m_proxy_cnt);
287        m_proxy_cnt++;
287288
288        proxy->init(*this, x.cstr());
289        proxy->init(*this, x);
289290        register_dev(proxy, x);
290291
291292        proxy->m_Q.net().register_con(in);
r26398r26399
296297    {
297298        //printf("here 1\n");
298299        nld_d_to_a_proxy *proxy = new nld_d_to_a_proxy(out);
299        astring x = "";
300        x.printf("proxy_da_%d", m_proxy_cnt++);
301        proxy->init(*this, x.cstr());
300        pstring x = pstring::sprintf("proxy_da_%d", m_proxy_cnt);
301        m_proxy_cnt++;
302
303        proxy->init(*this, x);
302304        register_dev(proxy, x);
303305
304306        proxy->m_Q.net().register_con(in);
r26398r26399
320322    {
321323        NL_VERBOSE_OUT(("connect_terminal_input: connecting proxy\n"));
322324        nld_a_to_d_proxy *proxy = new nld_a_to_d_proxy(inp);
323        astring x = "";
324        x.printf("proxy_da_%d", m_proxy_cnt++);
325        proxy->init(*this, x.cstr());
325        pstring x = pstring::sprintf("proxy_da_%d", m_proxy_cnt);
326        m_proxy_cnt++;
327
328        proxy->init(*this, x);
326329        register_dev(proxy, x);
327330
328331        connect_terminals(term, proxy->m_I);
r26398r26399
355358    {
356359        NL_VERBOSE_OUT(("connect_terminal_output: connecting proxy\n"));
357360        nld_d_to_a_proxy *proxy = new nld_d_to_a_proxy(out);
358        astring x = "";
359        x.printf("proxy_da_%d", m_proxy_cnt++);
360        proxy->init(*this, x.cstr());
361        pstring x = pstring::sprintf("proxy_da_%d", m_proxy_cnt);
362        m_proxy_cnt++;
363
364        proxy->init(*this, x);
361365        register_dev(proxy, x);
362366
363367        out.net().register_con(proxy->m_I);
r26398r26399
426430    NL_VERBOSE_OUT(("Resolving ...\n"));
427431    for (tagmap_link_t::entry_t *entry = m_links.first(); entry != NULL; entry = m_links.next(entry))
428432    {
429        const astring t1s = entry->object()->e1;
430        const astring t2s = entry->object()->e2;
433        const pstring t1s = entry->object().e1;
434        const pstring t2s = entry->object().e2;
431435        netlist_terminal_t &t1 = find_terminal(t1s);
432436        netlist_terminal_t &t2 = find_terminal(t2s);
433437
r26398r26399
490494    for (tagmap_devices_t::entry_t *entry = m_devices.first(); entry != NULL; entry = m_devices.next(entry))
491495    {
492496        netlist_device_t *dev = entry->object();
493        dev->init(*this, entry->tag());
497        dev->init(*this, entry->tag().cstr());
494498    }
495499}
496500
r26398r26399
518522
519523void netlist_setup_t::print_stats()
520524{
521   if (NL_KEEP_STATISTICS)
525#if (NL_KEEP_STATISTICS)
522526   {
523527      for (netlist_setup_t::tagmap_devices_t::entry_t *entry = m_devices.first(); entry != NULL; entry = m_devices.next(entry))
524528      {
r26398r26399
530534      printf("Queue Sort  %15d\n", m_netlist.queue().m_prof_sort);
531535      printf("Queue Move  %15d\n", m_netlist.queue().m_prof_sortmove);
532536   }
537#endif
533538}
trunk/src/emu/netlist/nl_parser.h
r26398r26399
1919   void parse(char *buf);
2020   void net_alias();
2121   void netdev_param();
22   void netdev_const(const astring &dev_name);
23   void netdev_device(const astring &dev_type);
22   void netdev_const(const pstring &dev_name);
23   void netdev_device(const pstring &dev_type);
2424
2525private:
2626
2727   void skipeol();
2828   void skipws();
29   astring getname(char sep);
30   astring getname2(char sep1, char sep2);
29   pstring getname(char sep);
30   pstring getname2(char sep1, char sep2);
3131   void check_char(char ctocheck);
3232   double eval_param();
3333
trunk/src/emu/netlist/pstring.h
r0r26399
1// license:GPL-2.0+
2// copyright-holders:Couriersud
3/*
4 * pstring.h
5 */
6
7#ifndef _PSTRING_H_
8#define _PSTRING_H_
9
10#include "nl_config.h"
11
12// ----------------------------------------------------------------------------------------
13// nstring: immutable strings ...
14//
15// nstrings are just a pointer to a "pascal-style" string representation.
16// It uses reference counts and only uses new memory when a string changes.
17// ----------------------------------------------------------------------------------------
18
19struct pstring
20{
21public:
22    // simple construction/destruction
23    pstring()
24    {
25        init();
26    }
27    ~pstring();
28
29    // construction with copy
30    pstring(const char *string) {init(); if (string != NULL) pcopy(string); }
31    pstring(const pstring &string) {init(); pcopy(string); }
32
33    // assignment operators
34    pstring &operator=(const char *string) { pcopy(string); return *this; }
35    pstring &operator=(const pstring &string) { pcopy(string); return *this; }
36
37    // C string conversion operators and helpers
38    operator const char *() const { return m_ptr->str(); }
39    inline const char *cstr() const { return m_ptr->str(); }
40
41    // concatenation operators
42    pstring& operator+=(const pstring &string) { pcat(string.cstr()); return *this; }
43    friend pstring operator+(const pstring &lhs, const pstring &rhs) { return pstring(lhs) += rhs; }
44    friend pstring operator+(const pstring &lhs, const char *rhs) { return pstring(lhs) += rhs; }
45    friend pstring operator+(const char *lhs, const pstring &rhs) { return pstring(lhs) += rhs; }
46
47    // comparison operators
48    bool operator==(const char *string) const { return (pcmp(string) == 0); }
49    bool operator==(const pstring &string) const { return (pcmp(string.cstr()) == 0); }
50    bool operator!=(const char *string) const { return (pcmp(string) != 0); }
51    bool operator!=(const pstring &string) const { return (pcmp(string.cstr()) != 0); }
52    bool operator<(const char *string) const { return (pcmp(string) < 0); }
53    bool operator<(const pstring &string) const { return (pcmp(string.cstr()) < 0); }
54    bool operator<=(const char *string) const { return (pcmp(string) <= 0); }
55    bool operator<=(const pstring &string) const { return (pcmp(string.cstr()) <= 0); }
56    bool operator>(const char *string) const { return (pcmp(string) > 0); }
57    bool operator>(const pstring &string) const { return (pcmp(string.cstr()) > 0); }
58    bool operator>=(const char *string) const { return (pcmp(string) >= 0); }
59    bool operator>=(const pstring &string) const { return (pcmp(string.cstr()) >= 0); }
60
61    //
62    inline const int len() const { return m_ptr->len(); }
63
64    inline bool equals(const pstring &string) { return (pcmp(string.cstr(), m_ptr->str()) == 0); }
65    int cmp(pstring &string) { return pcmp(string.cstr()); }
66
67    int find(const char *search, int start = 0) const
68    {
69        int alen = len();
70        const char *result = strstr(cstr() + MIN(start, alen), search);
71        return (result != NULL) ? (result - cstr()) : -1;
72    }
73
74    // various
75
76    bool startsWith(pstring &arg) { return (pcmp(cstr(), arg.cstr(), arg.len()) == 0); }
77    bool startsWith(const char *arg) { return (pcmp(cstr(), arg, strlen(arg)) == 0); }
78
79    // these return nstring ...
80    pstring cat(const pstring &s) const { return *this + s; }
81    pstring cat(const char *s) const { return *this + s; }
82
83    pstring substr(unsigned int start, int count = -1) const ;
84
85    pstring left(unsigned int count) const { return substr(0, count); }
86    pstring right(unsigned int count) const  { return substr(len() - count, count); }
87
88    // printf using string as format ...
89
90    pstring vprintf(va_list args) const;
91
92    // static
93    static pstring sprintf(const char *format, ...);
94    static void resetmem();
95
96protected:
97
98    struct str_t
99    {
100        int reference_count;
101        char *str() { return &m_str[0]; }
102        int len() { return m_len; }
103    //private:
104        int m_len;
105        char m_str[];
106    };
107
108    str_t *m_ptr;
109
110private:
111    void init();
112
113    inline int pcmp(const char *right) const
114    {
115        return pcmp(m_ptr->str(), right);
116    }
117
118    inline int pcmp(const char *left, const char *right, int count = -1) const
119    {
120        if (count < 0)
121            return strcmp(left, right);
122        else
123            return strncmp(left, right, count);
124    }
125
126    void pcopy(const char *from, int size);
127
128    inline void pcopy(const char *from)
129    {
130        pcopy(from, strlen(from));
131    }
132
133    inline void pcopy(const pstring &from)
134    {
135        sfree(m_ptr);
136        m_ptr = from.m_ptr;
137        m_ptr->reference_count++;
138    }
139
140    void pcat(const char *s);
141
142    static str_t *m_zero;
143
144    static str_t *salloc(int n);
145    static void sfree(str_t *s);
146
147    struct memblock
148    {
149        memblock *next;
150        int size;
151        int allocated;
152        int remaining;
153        char *cur;
154        char data[];
155    };
156
157    static memblock *m_first;
158    static char *alloc_str(int n);
159    static void dealloc_str(void *ptr);
160};
161
162
163#endif /* _PSTRING_H_ */
164
Property changes on: trunk/src/emu/netlist/pstring.h
Added: svn:eol-style
   + native
Added: svn:mime-type
   + text/plain
trunk/src/emu/netlist/nl_lists.h
r26398r26399
1515// ----------------------------------------------------------------------------------------
1616
1717
18template <class _ListClass>
18template <class _ListClass, int _NumElem = 128>
1919struct netlist_list_t
2020{
2121public:
22   ATTR_COLD netlist_list_t(int numElements = 100)
22
23    struct entry_t {
24
25        // keep compatibility with tagmap
26        _ListClass object() { return m_obj; }
27
28        _ListClass m_obj;
29    };
30
31   ATTR_COLD netlist_list_t(int numElements = _NumElem)
2332   {
2433      m_num_elements = numElements;
25      m_list = new _ListClass[m_num_elements];
34      m_list = new entry_t[m_num_elements];
2635      m_ptr = m_list;
2736      m_ptr--;
2837   }
r26398r26399
3241   }
3342   ATTR_HOT inline void add(const _ListClass elem)
3443   {
35      assert(m_ptr-m_list <= m_num_elements - 1);
44      if (m_ptr-m_list >= m_num_elements - 1)
45          resize(m_num_elements * 2);
3646
37      *(++m_ptr) = elem;
47      (++m_ptr)->m_obj = elem;
3848   }
3949   ATTR_HOT inline void resize(const int new_size)
4050   {
4151       int cnt = count();
42       _ListClass *m_new = new _ListClass[new_size];
43       memcpy(m_new, m_list, new_size * sizeof(_ListClass));
52       entry_t *m_new = new entry_t[new_size];
53       entry_t *pd = m_new;
54
55       for (entry_t *ps = m_list; ps <= m_ptr; ps++, pd++)
56           *pd = *ps;
4457       delete[] m_list;
4558       m_list = m_new;
4659       m_ptr = m_list + cnt - 1;
60       m_num_elements = new_size;
4761   }
48    ATTR_HOT inline void del(const _ListClass elem)
62    ATTR_HOT inline void remove(const _ListClass elem)
4963    {
50        for (_ListClass * i=m_list; i<=m_ptr; i++)
64        for (entry_t *i = m_list; i <= m_ptr; i++)
5165        {
52            if (*i == elem)
66            if (i->object() == elem)
5367            {
5468                while (i <= m_ptr)
5569                {
r26398r26399
6175            }
6276        }
6377    }
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 ); }
66   ATTR_HOT inline _ListClass *last()  { return m_ptr; }
67   ATTR_HOT inline _ListClass *item(int i) { return &m_list[i]; }
78   ATTR_HOT inline entry_t *first() { return (m_ptr >= m_list ? &m_list[0] : NULL ); }
79    ATTR_HOT inline entry_t *next(entry_t *lc) { return (lc < last() ? lc + 1 : NULL ); }
80   ATTR_HOT inline entry_t *last()  { return m_ptr; }
81   ATTR_HOT inline entry_t *item(int i) { return &m_list[i]; }
6882   ATTR_HOT inline int count() const { return m_ptr - m_list + 1; }
6983   ATTR_HOT inline bool empty() { return (m_ptr < m_list); }
70   ATTR_HOT inline void clear() { m_ptr = m_list - 1; }
84   ATTR_HOT inline void reset() { m_ptr = m_list - 1; }
7185private:
72   _ListClass * m_ptr;
73   _ListClass * m_list;
86   entry_t * m_ptr;
87   entry_t * m_list;
7488   int m_num_elements;
7589   //_ListClass m_list[_NumElements];
7690};
r26398r26399
111125      if (is_empty() || (e.time() <= (m_end - 1)->time()))
112126      {
113127         *m_end++ = e;
114         //inc_stat(m_prof_end);
128         inc_stat(m_prof_end);
115129      }
116130      else
117131      {
r26398r26399
120134         {
121135            i--;
122136            *(i+1) = *i;
123            //inc_stat(m_prof_sortmove);
137            inc_stat(m_prof_sortmove);
124138         }
125139         *i = e;
126         //inc_stat(m_prof_sort);
140         inc_stat(m_prof_sort);
127141      }
128142      assert(m_end - m_list < _Size);
129143   }
130144
131   ATTR_HOT inline const entry_t pop()
145   ATTR_HOT inline const entry_t &pop()
132146   {
133147      return *--m_end;
134148   }
135149
136   ATTR_HOT inline const entry_t peek() const
150   ATTR_HOT inline const entry_t &peek() const
137151   {
138152      return *(m_end-1);
139153   }
r26398r26399
142156   {
143157      m_end = &m_list[0];
144158   }
159
160#if (NL_KEEP_STATISTICS)
145161   // profiling
146
147162   INT32   m_prof_start;
148163   INT32   m_prof_end;
149164   INT32   m_prof_sortmove;
150165   INT32   m_prof_sort;
166#endif
167
151168private:
152169
153170   entry_t * RESTRICT m_end;
trunk/src/emu/netlist/nl_time.h
r26398r26399
2626{
2727public:
2828
29   typedef UINT64 INTERNALTYPE;
29    typedef UINT64 INTERNALTYPE;
3030
31   static const INTERNALTYPE RESOLUTION = NETLIST_INTERNAL_RES;
31    static const INTERNALTYPE RESOLUTION = NETLIST_INTERNAL_RES;
3232
33   ATTR_HOT inline netlist_time() : m_time(0) {}
33    ATTR_HOT inline netlist_time() : m_time(0) {}
3434
35   ATTR_HOT friend inline const netlist_time operator-(const netlist_time &left, const netlist_time &right);
36   ATTR_HOT friend inline const netlist_time operator+(const netlist_time &left, const netlist_time &right);
37   ATTR_HOT friend inline const netlist_time operator*(const netlist_time &left, const UINT32 factor);
35    ATTR_HOT friend inline const netlist_time operator-(const netlist_time &left, const netlist_time &right);
36    ATTR_HOT friend inline const netlist_time operator+(const netlist_time &left, const netlist_time &right);
37    ATTR_HOT friend inline const netlist_time operator*(const netlist_time &left, const UINT32 factor);
3838    ATTR_HOT friend inline const UINT32 operator/(const netlist_time &left, const netlist_time &right);
39   ATTR_HOT friend inline bool operator>(const netlist_time &left, const netlist_time &right);
40   ATTR_HOT friend inline bool operator<(const netlist_time &left, const netlist_time &right);
41   ATTR_HOT friend inline bool operator>=(const netlist_time &left, const netlist_time &right);
42   ATTR_HOT friend inline bool operator<=(const netlist_time &left, const netlist_time &right);
39    ATTR_HOT friend inline bool operator>(const netlist_time &left, const netlist_time &right);
40    ATTR_HOT friend inline bool operator<(const netlist_time &left, const netlist_time &right);
41    ATTR_HOT friend inline bool operator>=(const netlist_time &left, const netlist_time &right);
42    ATTR_HOT friend inline bool operator<=(const netlist_time &left, const netlist_time &right);
4343
44   ATTR_HOT inline const netlist_time &operator=(const netlist_time &right) { m_time = right.m_time; return *this; }
45   ATTR_HOT inline const netlist_time &operator+=(const netlist_time &right) { m_time += right.m_time; return *this; }
44    ATTR_HOT inline const netlist_time &operator=(const netlist_time &right) { m_time = right.m_time; return *this; }
45    ATTR_HOT inline const netlist_time &operator+=(const netlist_time &right) { m_time += right.m_time; return *this; }
4646
47   ATTR_HOT inline const INTERNALTYPE as_raw() const { return m_time; }
47    ATTR_HOT inline const INTERNALTYPE as_raw() const { return m_time; }
4848    ATTR_HOT inline const double as_double() const { return (double) m_time / (double) RESOLUTION; }
4949
50   ATTR_HOT static inline const netlist_time from_nsec(const int ns) { return netlist_time((UINT64) ns * (RESOLUTION / U64(1000000000))); }
51   ATTR_HOT static inline const netlist_time from_usec(const int us) { return netlist_time((UINT64) us * (RESOLUTION / U64(1000000))); }
52   ATTR_HOT static inline const netlist_time from_msec(const int ms) { return netlist_time((UINT64) ms * (RESOLUTION / U64(1000))); }
53   ATTR_HOT static inline const netlist_time from_hz(const UINT64 hz) { return netlist_time(RESOLUTION / hz); }
54   ATTR_HOT static inline const netlist_time from_raw(const INTERNALTYPE raw) { return netlist_time(raw); }
50    ATTR_HOT static inline const netlist_time from_nsec(const int ns) { return netlist_time((UINT64) ns * (RESOLUTION / U64(1000000000))); }
51    ATTR_HOT static inline const netlist_time from_usec(const int us) { return netlist_time((UINT64) us * (RESOLUTION / U64(1000000))); }
52    ATTR_HOT static inline const netlist_time from_msec(const int ms) { return netlist_time((UINT64) ms * (RESOLUTION / U64(1000))); }
53    ATTR_HOT static inline const netlist_time from_hz(const UINT64 hz) { return netlist_time(RESOLUTION / hz); }
54    ATTR_HOT static inline const netlist_time from_raw(const INTERNALTYPE raw) { return netlist_time(raw); }
5555
56   static const netlist_time zero;
56    static const netlist_time zero;
5757
5858protected:
5959
60   ATTR_HOT inline netlist_time(const INTERNALTYPE val) : m_time(val) {}
60    ATTR_HOT inline netlist_time(const INTERNALTYPE val) : m_time(val) {}
6161
62   INTERNALTYPE m_time;
62    INTERNALTYPE m_time;
6363};
6464
6565ATTR_HOT inline const netlist_time operator-(const netlist_time &left, const netlist_time &right)
6666{
67   return netlist_time::from_raw(left.m_time - right.m_time);
67    return netlist_time::from_raw(left.m_time - right.m_time);
6868}
6969
7070ATTR_HOT inline const netlist_time operator*(const netlist_time &left, const UINT32 factor)
7171{
72   return netlist_time::from_raw(left.m_time * factor);
72    return netlist_time::from_raw(left.m_time * factor);
7373}
7474
7575ATTR_HOT inline const UINT32 operator/(const netlist_time &left, const netlist_time &right)
r26398r26399
7979
8080ATTR_HOT inline const netlist_time operator+(const netlist_time &left, const netlist_time &right)
8181{
82   return netlist_time::from_raw(left.m_time + right.m_time);
82    return netlist_time::from_raw(left.m_time + right.m_time);
8383}
8484
8585ATTR_HOT inline bool operator<(const netlist_time &left, const netlist_time &right)
8686{
87   return (left.m_time < right.m_time);
87    return (left.m_time < right.m_time);
8888}
8989
9090ATTR_HOT inline bool operator>(const netlist_time &left, const netlist_time &right)
9191{
92   return (left.m_time > right.m_time);
92    return (left.m_time > right.m_time);
9393}
9494
9595ATTR_HOT inline bool operator<=(const netlist_time &left, const netlist_time &right)
9696{
97   return (left.m_time <= right.m_time);
97    return (left.m_time <= right.m_time);
9898}
9999
100100ATTR_HOT inline bool operator>=(const netlist_time &left, const netlist_time &right)
101101{
102   return (left.m_time >= right.m_time);
102    return (left.m_time >= right.m_time);
103103}
104104
105105
trunk/src/emu/netlist/nl_setup.h
r26398r26399
6868
6969    struct link_t
7070    {
71        link_t(const astring &ae1, const astring &ae2)
71        link_t() { }
72        // Copy constructor
73        link_t(const link_t &from)
7274        {
75            e1 = from.e1;
76            e2 = from.e2;
77        }
78
79        link_t(const pstring &ae1, const pstring &ae2)
80        {
7381            e1 = ae1;
7482            e2 = ae2;
7583        }
76        astring e1;
77        astring e2;
84        pstring e1;
85        pstring e2;
86
87        bool operator==(const link_t &rhs) const { return (e1 == rhs.e1) && (e2 == rhs.e2); }
88        link_t &operator=(const link_t &rhs) { e1 = rhs.e1; e2 = rhs.e2; return *this; }
7889    };
7990
8091   typedef tagmap_t<netlist_device_t *, 393> tagmap_devices_t;
81    typedef tagmap_t<link_t *, 393> tagmap_link_t;
82   typedef tagmap_t<const astring *, 393> tagmap_astring_t;
92   typedef tagmap_t<pstring, 393> tagmap_nstring_t;
8393   typedef tagmap_t<netlist_param_t *, 393> tagmap_param_t;
8494   typedef tagmap_t<netlist_terminal_t *, 393> tagmap_terminal_t;
95   typedef netlist_list_t<link_t> tagmap_link_t;
8596
8697   netlist_setup_t(netlist_base_t &netlist);
8798   ~netlist_setup_t();
8899
89100   netlist_base_t &netlist() { return m_netlist; }
90101
91   netlist_device_t *register_dev(netlist_device_t *dev, const astring &name);
92   void remove_dev(const astring &name);
102   netlist_device_t *register_dev(netlist_device_t *dev, const pstring &name);
103   void remove_dev(const pstring &name);
93104
94    void register_alias(const astring &alias, const astring &out);
95    void register_link(const astring &sin, const astring &sout);
96    void register_param(const astring &param, const astring &value);
97    void register_param(const astring &param, const double value);
105    void register_alias(const pstring &alias, const pstring &out);
106    void register_link(const pstring &sin, const pstring &sout);
107    void register_param(const pstring &param, const pstring &value);
108    void register_param(const pstring &param, const double value);
98109
99    void register_object(netlist_device_t &dev, netlist_core_device_t &upd_dev, const astring &name, netlist_object_t &obj, netlist_input_t::state_e state);
110    void register_object(netlist_device_t &dev, netlist_core_device_t &upd_dev, const pstring &name, netlist_object_t &obj, netlist_input_t::state_e state);
100111
101    netlist_terminal_t &find_terminal(const astring &outname_in);
102    netlist_terminal_t &find_terminal(const astring &outname_in, netlist_object_t::type_t atype);
112    netlist_terminal_t &find_terminal(const pstring &outname_in);
113    netlist_terminal_t &find_terminal(const pstring &outname_in, netlist_object_t::type_t atype);
103114
104    netlist_param_t &find_param(const astring &param_in);
115    netlist_param_t &find_param(const pstring &param_in);
105116
106   void register_callback(const astring &devname, netlist_output_delegate delegate);
117   void register_callback(const pstring &devname, netlist_output_delegate delegate);
107118
108119   void parse(char *buf);
109120
r26398r26399
123134   netlist_base_t &m_netlist;
124135
125136   tagmap_devices_t m_devices;
126   tagmap_astring_t m_alias;
137   tagmap_nstring_t m_alias;
127138   tagmap_param_t  m_params;
128   tagmap_link_t  m_links;
129    tagmap_astring_t m_params_temp;
139   tagmap_link_t   m_links;
140    tagmap_nstring_t m_params_temp;
130141
131142   int m_proxy_cnt;
132143
r26398r26399
136147    void connect_terminal_input(netlist_terminal_t &term, netlist_input_t &inp);
137148
138149    // helpers
139    astring objtype_as_astr(netlist_object_t &in);
150    pstring objtype_as_astr(netlist_object_t &in);
140151
141   const astring resolve_alias(const astring &name) const;
152   const pstring resolve_alias(const pstring &name) const;
142153};
143154
144155#endif /* NLSETUP_H_ */
trunk/src/emu/netlist/devices/nld_system.h
r26398r26399
9696// ----------------------------------------------------------------------------------------
9797
9898NETLIB_DEVICE_WITH_PARAMS(solver,
99        typedef netlist_list_t<netlist_terminal_t *> terminal_list_t;
100        typedef netlist_list_t<netlist_net_t *>      net_list_t;
101
99102        netlist_ttl_input_t m_feedback;
100103        netlist_ttl_output_t m_Q;
101104
r26398r26399
104107        netlist_time m_inc;
105108        netlist_time m_last_step;
106109
107        netlist_list_t<netlist_terminal_t *> m_terms;
108        netlist_list_t<netlist_terminal_t *> m_inps;
110        terminal_list_t m_terms;
111        terminal_list_t m_inps;
109112
110113public:
111        netlist_list_t<netlist_net_t *> m_nets;
112114
115        ~NETLIB_NAME(solver)();
116
117        net_list_t m_nets;
118
113119        ATTR_HOT inline void schedule();
114120
115121        ATTR_COLD void post_start();
trunk/src/emu/netlist/devices/net_lib.c
r26398r26399
987987   NULL
988988};
989989
990netlist_device_t *net_create_device_by_classname(const astring &classname, netlist_setup_t &setup)
990netlist_device_t *net_create_device_by_classname(const pstring &classname, netlist_setup_t &setup)
991991{
992992   const net_device_t_base_factory **p = &netregistry[0];
993993   while (*p != NULL)
r26398r26399
10031003   return NULL; // appease code analysis
10041004}
10051005
1006netlist_device_t *net_create_device_by_name(const astring &name, netlist_setup_t &setup)
1006netlist_device_t *net_create_device_by_name(const pstring &name, netlist_setup_t &setup)
10071007{
10081008   const net_device_t_base_factory **p = &netregistry[0];
10091009   while (*p != NULL)
trunk/src/emu/netlist/devices/nld_system.c
r26398r26399
9898    m_inc = netlist_time::from_hz(m_freq.Value());
9999}
100100
101NETLIB_NAME(solver)::~NETLIB_NAME(solver)()
102{
103    net_list_t::entry_t *p = m_nets.first();
104    while (p != NULL)
105    {
106        net_list_t::entry_t *pn = m_nets.next(pn);
107        delete pn->object();
108        p = pn;
109    }
110}
111
101112NETLIB_FUNC_VOID(solver, post_start, ())
102113{
103114    NL_VERBOSE_OUT(("post start solver ...\n"));
104    for (netlist_net_t **pn = m_nets.first(); pn != NULL; pn = m_nets.next(pn))
115    for (net_list_t::entry_t *pn = m_nets.first(); pn != NULL; pn = m_nets.next(pn))
105116    {
106117        NL_VERBOSE_OUT(("setting up net\n"));
107        for (netlist_terminal_t *p = (*pn)->m_head; p != NULL; p = p->m_update_list_next)
118        for (netlist_terminal_t *p = pn->object()->m_head; p != NULL; p = p->m_update_list_next)
108119        {
109120            switch (p->type())
110121            {
r26398r26399
121132                    break;
122133            }
123134        }
124        if ((*pn)->m_head == NULL)
135        if (pn->object()->m_head == NULL)
125136        {
126137            NL_VERBOSE_OUT(("Deleting net ...\n"));
127            netlist_net_t *to_delete = *pn;
128            m_nets.del(to_delete);
138            netlist_net_t *to_delete = pn->object();
139            m_nets.remove(to_delete);
129140            delete to_delete;
130141            pn--;
131142        }
r26398r26399
146157        NL_VERBOSE_OUT(("Step!\n"));
147158        /* update all terminals for new time step */
148159        m_last_step = now;
149        for (netlist_terminal_t **p = m_terms.first(); p != NULL; p = m_terms.next(p))
150            (*p)->netdev().step_time(delta.as_double());
160        for (terminal_list_t::entry_t *p = m_terms.first(); p != NULL; p = m_terms.next(p))
161            p->object()->netdev().step_time(delta.as_double());
151162    }
152    for (netlist_net_t **pn = m_nets.first(); pn != NULL; pn = m_nets.next(pn))
163    for (net_list_t::entry_t *pn = m_nets.first(); pn != NULL; pn = m_nets.next(pn))
153164    {
154165        double gtot = 0;
155166        double iIdr = 0;
156167
157        for (netlist_terminal_t *p = (*pn)->m_head; p != NULL; p = p->m_update_list_next)
168        for (netlist_terminal_t *p = pn->object()->m_head; p != NULL; p = p->m_update_list_next)
158169        {
159170            if (p->isType(netlist_terminal_t::TERMINAL))
160171            {
r26398r26399
165176        }
166177
167178        double new_val = iIdr / gtot;
168        if (fabs(new_val - (*pn)->m_cur.Analog) > 1e-4)
179        if (fabs(new_val - pn->object()->m_cur.Analog) > 1e-4)
169180            resched = true;
170        (*pn)->m_cur.Analog = (*pn)->m_new.Analog = new_val;
181        pn->object()->m_cur.Analog = pn->object()->m_new.Analog = new_val;
171182
172183        NL_VERBOSE_OUT(("Info: %d\n", (*pn)->m_num_cons));
173184        NL_VERBOSE_OUT(("New: %lld %f %f\n", netlist().time().as_raw(), netlist().time().as_double(), new_val));
r26398r26399
179190    else
180191    {
181192        /* update all inputs connected */
182        for (netlist_terminal_t **p = m_inps.first(); p != NULL; p = m_inps.next(p))
183            (*p)->netdev().update_dev();
193        for (terminal_list_t::entry_t *p = m_inps.first(); p != NULL; p = m_inps.next(p))
194            p->object()->netdev().update_dev();
184195        /* step circuit */
185196        if (!m_Q.net().is_queued())
186197        {
trunk/src/emu/netlist/nl_base.c
r26398r26399
55
66#include "nl_base.h"
77#include "devices/nld_system.h"
8#include "pstring.h"
89
10const netlist_time netlist_time::zero = netlist_time::from_raw(0);
11
912// ----------------------------------------------------------------------------------------
1013// netlist_object_t
1114// ----------------------------------------------------------------------------------------
r26398r26399
1417: m_objtype(atype)
1518, m_family(afamily)
1619, m_netlist(NULL)
17, m_name(NULL)
1820{}
1921
2022ATTR_COLD netlist_object_t::~netlist_object_t()
2123{
22    delete m_name;
24    //delete m_name;
2325}
2426
25ATTR_COLD void netlist_object_t::init_object(netlist_base_t &nl, const astring &aname)
27ATTR_COLD void netlist_object_t::init_object(netlist_base_t &nl, const pstring &aname)
2628{
2729    m_netlist = &nl;
28    m_name = new astring(aname);
30    m_name = aname;
2931}
3032
31ATTR_COLD const astring &netlist_object_t::name() const
33ATTR_COLD const pstring &netlist_object_t::name() const
3234{
33    if (m_name == NULL)
35    if (m_name == "")
3436        fatalerror("object not initialized");
35    return *m_name;
37    return m_name;
3638}
3739
3840// ----------------------------------------------------------------------------------------
r26398r26399
4749}
4850
4951ATTR_COLD void netlist_owned_object_t::init_object(netlist_core_device_t &dev,
50        const astring &aname)
52        const pstring &aname)
5153{
5254    netlist_object_t::init_object(dev.netlist(), aname);
5355    m_netdev = &dev;
r26398r26399
5860// ----------------------------------------------------------------------------------------
5961
6062netlist_base_t::netlist_base_t()
61   : m_mainclock(NULL),
62      m_time_ps(netlist_time::zero),
63   :    m_time_ps(netlist_time::zero),
6364      m_rem(0),
64      m_div(NETLIST_DIV)
65      m_div(NETLIST_DIV),
66      m_mainclock(NULL),
67      m_solver(NULL)
6568{
6669}
6770
6871netlist_base_t::~netlist_base_t()
6972{
73    pstring::resetmem();
7074}
7175
7276ATTR_COLD void netlist_base_t::set_mainclock_dev(NETLIB_NAME(mainclock) *dev)
r26398r26399
8185
8286ATTR_COLD void netlist_base_t::reset()
8387{
84      m_time_ps = netlist_time::zero;
85      m_rem = 0;
86      m_queue.clear();
87      if (m_mainclock != NULL)
88         m_mainclock->m_Q.net().set_time(netlist_time::zero);
88    m_time_ps = netlist_time::zero;
89    m_rem = 0;
90    m_queue.clear();
91    if (m_mainclock != NULL)
92        m_mainclock->m_Q.net().set_time(netlist_time::zero);
93
8994}
9095
9196
r26398r26399
121126   {
122127      while ( (atime > 0) && (m_queue.is_not_empty()))
123128      {
124         const queue_t::entry_t e = m_queue.pop();
129         const queue_t::entry_t &e = m_queue.pop();
125130         update_time(e.time(), atime);
126131
127132         //if (FATAL_ERROR_AFTER_NS)
r26398r26399
156161               NETLIB_NAME(mainclock)::mc_update(mcQ, time() + inc);
157162
158163            }
159            const queue_t::entry_t e = m_queue.pop();
164            const queue_t::entry_t &e = m_queue.pop();
160165
161166            update_time(e.time(), atime);
162167
r26398r26399
197202{
198203}
199204
200ATTR_COLD void netlist_core_device_t::init(netlist_setup_t &setup, const astring &name)
205ATTR_COLD void netlist_core_device_t::init(netlist_setup_t &setup, const pstring &name)
201206{
202207    init_object(setup.netlist(), name);
203208
r26398r26399
248253   //NL_VERBOSE_OUT(("~net_device_t\n");
249254}
250255
251ATTR_COLD void netlist_device_t::init(netlist_setup_t &setup, const astring &name)
256ATTR_COLD void netlist_device_t::init(netlist_setup_t &setup, const pstring &name)
252257{
253258   netlist_core_device_t::init(setup, name);
254259   m_setup = &setup;
r26398r26399
256261}
257262
258263
259ATTR_COLD void netlist_device_t::register_sub(netlist_core_device_t &dev, const astring &name)
264ATTR_COLD void netlist_device_t::register_sub(netlist_core_device_t &dev, const pstring &name)
260265{
261266   dev.init(*m_setup, this->name() + "." + name);
262267}
263268
264ATTR_COLD void netlist_device_t::register_output(netlist_core_device_t &dev, const astring &name, netlist_output_t &port)
269ATTR_COLD void netlist_device_t::register_output(netlist_core_device_t &dev, const pstring &name, netlist_output_t &port)
265270{
266271   m_setup->register_object(*this, dev, name, port, netlist_terminal_t::STATE_OUT);
267272}
268273
269ATTR_COLD void netlist_device_t::register_terminal(const astring &name, netlist_terminal_t &port)
274ATTR_COLD void netlist_device_t::register_terminal(const pstring &name, netlist_terminal_t &port)
270275{
271276    m_setup->register_object(*this,*this,name, port, netlist_terminal_t::STATE_INP_ACTIVE);
272277}
273278
274ATTR_COLD void netlist_device_t::register_output(const astring &name, netlist_output_t &port)
279ATTR_COLD void netlist_device_t::register_output(const pstring &name, netlist_output_t &port)
275280{
276281   m_setup->register_object(*this,*this,name, port, netlist_terminal_t::STATE_OUT);
277282}
278283
279ATTR_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)
284ATTR_COLD void netlist_device_t::register_input(netlist_core_device_t &dev, const pstring &name, netlist_input_t &inp, netlist_input_t::state_e type)
280285{
281286    m_terminals.add(name);
282287   m_setup->register_object(*this, dev, name, inp, type);
283288}
284289
285ATTR_COLD void netlist_device_t::register_input(const astring &name, netlist_input_t &inp, netlist_input_t::state_e type)
290ATTR_COLD void netlist_device_t::register_input(const pstring &name, netlist_input_t &inp, netlist_input_t::state_e type)
286291{
287292   register_input(*this, name, inp, type);
288293}
r26398r26399
303308   register_link_internal(*this, in, out, aState);
304309}
305310
306ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const astring &name, netlist_param_t &param, double initialVal)
311ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &name, netlist_param_t &param, double initialVal)
307312{
308313   param.set_netdev(dev);
309314   param.initial(initialVal);
310315   m_setup->register_object(*this, *this, name, param, netlist_terminal_t::STATE_NONEX);
311316}
312317
313ATTR_COLD void netlist_device_t::register_param(const astring &name, netlist_param_t &param, double initialVal)
318ATTR_COLD void netlist_device_t::register_param(const pstring &name, netlist_param_t &param, double initialVal)
314319{
315320   register_param(*this,name, param, initialVal);
316321}
r26398r26399
451456
452457}
453458
454ATTR_COLD void netlist_terminal_t::init_object(netlist_core_device_t &dev, const astring &aname, const state_e astate)
459ATTR_COLD void netlist_terminal_t::init_object(netlist_core_device_t &dev, const pstring &aname, const state_e astate)
455460{
456461   set_state(astate);
457462   netlist_owned_object_t::init_object(dev, aname);
r26398r26399
480485    this->set_net(m_my_net);
481486}
482487
483ATTR_COLD void netlist_output_t::init_object(netlist_core_device_t &dev, const astring &aname)
488ATTR_COLD void netlist_output_t::init_object(netlist_core_device_t &dev, const pstring &aname)
484489{
485490    netlist_terminal_t::init_object(dev, aname, STATE_OUT);
486491    net().init_object(dev.netlist(), aname);
trunk/src/emu/netlist/nl_config.h
r26398r26399
1616//  SETUP
1717//============================================================
1818
19//#define astring breakme()
20
1921#define USE_DELEGATES           (0)
2022/*
2123 * The next options needs -Wno-pmf-conversions to compile and gcc
trunk/src/emu/netlist/nl_parser.c
r26398r26399
1616   m_p = buf;
1717   while (*m_p)
1818   {
19      astring n;
19      pstring n;
2020      skipws();
2121      if (!*m_p) break;
2222      n = getname('(');
r26398r26399
3434
3535void netlist_parser::net_alias()
3636{
37   astring alias;
38   astring out;
37   pstring alias;
38   pstring out;
3939   skipws();
4040   alias = getname(',');
4141   skipws();
r26398r26399
4646
4747void netlist_parser::netdev_param()
4848{
49   astring param;
49   pstring param;
5050   double val;
5151   skipws();
5252   param = getname(',');
r26398r26399
5858   check_char(')');
5959}
6060
61void netlist_parser::netdev_const(const astring &dev_name)
61void netlist_parser::netdev_const(const pstring &dev_name)
6262{
63   astring name;
63   pstring name;
6464   netlist_device_t *dev;
65   astring paramfq;
65   pstring paramfq;
6666   double val;
6767
6868   skipws();
r26398r26399
7272   skipws();
7373   val = eval_param();
7474   check_char(')');
75   paramfq = name;
76   paramfq.cat(".CONST");
75   paramfq = name + ".CONST";
7776   NL_VERBOSE_OUT(("Parser: Const: %s %f\n", name.cstr(), val));
7877   //m_setup.find_param(paramfq).initial(val);
7978   m_setup.register_param(paramfq, val);
8079}
8180
82void netlist_parser::netdev_device(const astring &dev_type)
81void netlist_parser::netdev_device(const pstring &dev_type)
8382{
84   astring devname;
83   pstring devname;
8584   netlist_device_t *dev;
8685   int cnt;
8786
r26398r26399
9695   {
9796      m_p++;
9897      skipws();
99      astring output_name = getname2(',', ')');
98      pstring output_name = getname2(',', ')');
10099      NL_VERBOSE_OUT(("Parser: ID: %s %s\n", output_name.cstr(), dev->m_terminals.item(cnt)->cstr()));
101      astring temp;
102      temp.printf("%s.[%d]", devname.cstr(), cnt);
103      m_setup.register_link(temp, output_name);
100      m_setup.register_link(pstring::sprintf("%s.[%d]", devname.cstr(), cnt), output_name);
104101      skipws();
105102      cnt++;
106103   }
r26398r26399
156153   }
157154}
158155
159astring netlist_parser::getname(char sep)
156pstring netlist_parser::getname(char sep)
160157{
161158   char buf[300];
162159   char *p1 = buf;
r26398r26399
165162      *p1++ = *m_p++;
166163   *p1 = 0;
167164   m_p++;
168   return astring(buf);
165   return pstring(buf);
169166}
170167
171astring netlist_parser::getname2(char sep1, char sep2)
168pstring netlist_parser::getname2(char sep1, char sep2)
172169{
173170   char buf[300];
174171   char *p1 = buf;
r26398r26399
176173   while ((*m_p != sep1) && (*m_p != sep2))
177174      *p1++ = *m_p++;
178175   *p1 = 0;
179   return astring(buf);
176   return pstring(buf);
180177}
181178
182179void netlist_parser::check_char(char ctocheck)
trunk/src/emu/netlist/pstring.c
r0r26399
1/*
2 * nl_string.c
3 *
4 */
5
6#include "pstring.h"
7#include <cstdio>
8
9//nstring::str_t *nstring::m_zero = NULL;
10pstring::str_t *pstring::m_zero = pstring::salloc(0);
11pstring::memblock *pstring::m_first = NULL;
12
13#define IMMEDIATE_MODE  (1)
14#define DEBUG_MODE      (0)
15
16pstring::~pstring()
17{
18   sfree(m_ptr);
19}
20
21void pstring::init()
22{
23    if (m_zero == NULL)
24    {
25        m_zero = (str_t *) alloc_str(sizeof(str_t) + 1);
26        m_zero->reference_count = 1;
27        m_zero->m_len = 0;
28        m_zero->m_str[0] = 0;
29    }
30    m_ptr = m_zero;
31    m_ptr->reference_count++;
32}
33
34void pstring::pcat(const char *s)
35{
36    int slen = strlen(s);
37    str_t *n = salloc(m_ptr->len() + slen);
38    if (m_ptr->len() > 0)
39        memcpy(n->str(), m_ptr->str(), m_ptr->len());
40    if (slen > 0)
41        memcpy(n->str() + m_ptr->len(), s, slen);
42    *(n->str() + n->len()) = 0;
43    sfree(m_ptr);
44    m_ptr = n;
45}
46
47void pstring::pcopy(const char *from, int size)
48{
49    str_t *n = salloc(size);
50    if (size > 0)
51        memcpy(n->str(), from, size);
52    *(n->str() + size) = 0;
53    sfree(m_ptr);
54    m_ptr = n;
55}
56
57pstring pstring::substr(unsigned int start, int count) const
58{
59    int alen = len();
60    if (start >= alen)
61        return pstring();
62    if (count <0 || start + count > alen)
63        count = alen - start;
64    pstring ret;
65    ret.pcopy(cstr() + start, count);
66    return ret;
67}
68
69pstring pstring::vprintf(va_list args) const
70{
71    // sprintf into the temporary buffer
72    char tempbuf[4096];
73    vsprintf(tempbuf, cstr(), args);
74
75    return pstring(tempbuf);
76}
77
78// ----------------------------------------------------------------------------------------
79// static stuff ...
80// ----------------------------------------------------------------------------------------
81
82void pstring::sfree(str_t *s)
83{
84    s->reference_count--;
85    if (s->reference_count == 0)
86        dealloc_str(s);
87}
88
89pstring::str_t *pstring::salloc(int n)
90{
91    str_t *ret = (str_t *) alloc_str(sizeof(str_t) + n + 1);
92    ret->reference_count = 1;
93    ret->m_len = n;
94    ret->m_str[0] = 0;
95    return ret;
96    //std::printf("old string %d <%s> %p %p\n", n, old, old, m_ptr);
97}
98
99pstring pstring::sprintf(const char *format, ...)
100{
101    va_list ap;
102    va_start(ap, format);
103    pstring ret = pstring(format).vprintf(ap);
104    va_end(ap);
105    return ret;
106}
107
108char *pstring::alloc_str(int n)
109{
110#if (IMMEDIATE_MODE)
111    return (char *) malloc(n);
112#else
113#if (DEBUG_MODE)
114    int min_alloc = MAX(0, n+sizeof(memblock));
115#else
116    int min_alloc = MAX(8192, n+sizeof(memblock));
117#endif
118    char *ret = NULL;
119
120    //std::printf("m_first %p\n", m_first);
121    for (memblock *p = m_first; p != NULL && ret == NULL; p = p->next)
122    {
123        if (p->remaining > n)
124        {
125            ret = p->cur;
126            p->cur += n;
127            p->allocated += 1;
128            p->remaining -= n;
129        }
130    }
131
132    if (ret == NULL)
133    {
134        // need to allocate a new block
135        memblock *p = (memblock *) malloc(min_alloc); //new char[min_alloc];
136        p->allocated = 0;
137        p->cur = &p->data[0];
138        p->size = p->remaining = min_alloc - sizeof(memblock);
139        p->next = m_first;
140        //std::printf("allocated block size %d\n", p->size);
141
142        ret = p->cur;
143        p->cur += n;
144        p->allocated += 1;
145        p->remaining -= n;
146
147        m_first = p;
148    }
149
150    return ret;
151#endif
152}
153
154void pstring::dealloc_str(void *ptr)
155{
156#if (IMMEDIATE_MODE)
157    free(ptr);
158#else
159    for (memblock *p = m_first; p != NULL; p = p->next)
160    {
161        if (ptr >= &p->data[0] && ptr < &p->data[p->size])
162        {
163            p->allocated -= 1;
164            if (p->allocated < 0)
165                fatalerror("nstring: memory corruption\n");
166            if (p->allocated == 0)
167            {
168                //std::printf("Block entirely freed\n");
169                p->remaining = p->size;
170                p->cur = &p->data[0];
171            }
172            // shutting down ?
173            if (m_zero == NULL)
174                resetmem(); // try to free blocks
175            return;
176        }
177    }
178    fatalerror("nstring: string <%p> not found\n", ptr);
179#endif
180}
181
182void pstring::resetmem()
183{
184#if (IMMEDIATE_MODE)
185#else
186    memblock **p = &m_first;
187    int totalblocks = 0;
188    int freedblocks = 0;
189
190    // Release the 0 string
191    if (m_zero != NULL) sfree(m_zero);
192    m_zero = NULL;
193
194    while (*p != NULL)
195    {
196        totalblocks++;
197        memblock **next = &((*p)->next);
198        if ((*p)->allocated == 0)
199        {
200            //std::printf("freeing block %p\n", *p);
201            memblock *freeme = *p;
202            *p = *next;
203            free(freeme); //delete[] *p;
204            freedblocks++;
205        }
206        else
207        {
208#if (DEBUG_MODE)
209            std::printf("Allocated: <%s>\n", ((str_t *)(&(*p)->data[0]))->str());
210#endif
211            p = next;
212        }
213    }
214#if (DEBUG_MODE)
215    std::printf("Freed %d out of total %d blocks\n", freedblocks, totalblocks);
216#endif
217#endif
218}
Property changes on: trunk/src/emu/netlist/pstring.c
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Previous 199869 Revisions Next


© 1997-2024 The MAME Team