Previous 199869 Revisions Next

r34471 Sunday 18th January, 2015 at 19:13:11 UTC by Luca Bruno
core: link state entries to parent state interface

In device state, link a single device_state_entry to its parent
device_state_interface and expose a parent_state() getter.

Signed-off-by: Luca Bruno <lucab@debian.org>
[src/emu]distate.c distate.h
[src/emu/machine]netlist.c
[src/emu/netlist]nl_base.c nl_base.h nl_config.h nl_dice_compat.h nl_factory.c nl_factory.h nl_parser.c nl_parser.h nl_setup.c nl_setup.h pstate.c pstate.h pstring.c pstring.h
[src/emu/netlist/analog]nld_bjt.c nld_bjt.h nld_fourterm.c nld_fourterm.h nld_ms_direct.h nld_ms_direct1.h nld_ms_direct2.h nld_ms_gauss_seidel.h nld_solver.c nld_solver.h nld_twoterm.c nld_twoterm.h
[src/emu/netlist/devices]nld_4020.c nld_4066.c nld_74123.c nld_74ls629.c nld_cmos.h nld_ne555.c nld_ne555.h nld_r2r_dac.c nld_system.c
[src/mame/drivers]nl_pongd.c
[src/tools]nltool.c

trunk/src/emu/distate.c
r242982r242983
4949//  device_state_entry - constructor
5050//-------------------------------------------------
5151
52device_state_entry::device_state_entry(int index, const char *symbol, void *dataptr, UINT8 size)
53   : m_next(NULL),
52device_state_entry::device_state_entry(int index, const char *symbol, void *dataptr, UINT8 size, device_state_interface *dev)
53   : m_device_state(dev),
54      m_next(NULL),
5455      m_index(index),
5556      m_dataptr(dataptr),
5657      m_datamask(0),
r242982r242983
8687      m_symbol.cpy("CURFLAGS");
8788}
8889
89device_state_entry::device_state_entry(int index)
90   : m_next(NULL),
90device_state_entry::device_state_entry(int index, device_state_interface *dev)
91   : m_device_state(dev),
92       m_next(NULL),
9193      m_index(index),
9294      m_dataptr(NULL),
9395      m_datamask(0),
r242982r242983
523525   assert(symbol != NULL);
524526
525527   // allocate new entry
526   device_state_entry *entry = global_alloc(device_state_entry(index, symbol, data, size));
528   device_state_entry *entry = global_alloc(device_state_entry(index, symbol, data, size, this));
527529
528530   // append to the end of the list
529531   m_state_list.append(*entry);
r242982r242983
543545device_state_entry &device_state_interface::state_add_divider(int index)
544546{
545547   // allocate new entry
546   device_state_entry *entry = global_alloc(device_state_entry(index));
548   device_state_entry *entry = global_alloc(device_state_entry(index, this));
547549
548550   // append to the end of the list
549551   m_state_list.append(*entry);
trunk/src/emu/distate.h
r242982r242983
4949
5050private:
5151   // construction/destruction
52   device_state_entry(int index, const char *symbol, void *dataptr, UINT8 size);
53   device_state_entry(int index);
52   device_state_entry(int index, const char *symbol, void *dataptr, UINT8 size, device_state_interface *dev);
53   device_state_entry(int index, device_state_interface *dev);
5454
5555public:
5656   // post-construction modifiers
r242982r242983
7070   const char *symbol() const { return m_symbol; }
7171   bool visible() const { return ((m_flags & DSF_NOSHOW) == 0); }
7272   bool divider() const { return m_flags & DSF_DIVIDER; }
73   device_state_interface *parent_state() const {return m_device_state;}
7374
7475protected:
7576   // device state flags
r242982r242983
9899   static const UINT64 k_decimal_divisor[20];      // divisors for outputting decimal values
99100
100101   // public state description
102   device_state_interface *m_device_state;         // link to parent device state
101103   device_state_entry *    m_next;                 // link to next item
102104   UINT32                  m_index;                // index by which this item is referred
103105   generic_ptr             m_dataptr;              // pointer to where the data lives
trunk/src/emu/machine/netlist.c
r242982r242983
4848#include "netlist.h"
4949#include "netlist/nl_base.h"
5050#include "netlist/nl_setup.h"
51#include "netlist/nl_factory.h"
5251#include "netlist/devices/net_lib.h"
5352#include "debugger.h"
5453
r242982r242983
135134   pstring dname = "OUT_" + m_in;
136135   m_delegate.bind_relative_to(owner()->machine().root_device());
137136   NETLIB_NAME(analog_callback) *dev = downcast<NETLIB_NAME(analog_callback) *>(
138         setup.register_dev("nld_analog_callback", dname));
137         setup.factory().new_device_by_classname("nld_analog_callback", setup));
139138
139   setup.register_dev(dev, dname);
140140   dev->register_callback(m_delegate);
141141   setup.register_link(dname + ".IN", m_in);
142142}
r242982r242983
208208{
209209   NETLIB_NAME(sound_in) *snd_in = setup.netlist().get_first_device<NETLIB_NAME(sound_in)>();
210210   if (snd_in == NULL)
211      snd_in = dynamic_cast<NETLIB_NAME(sound_in) *>(setup.register_dev("nld_sound_in", "STREAM_INPUT"));
211   {
212      snd_in = dynamic_cast<NETLIB_NAME(sound_in) *>(setup.factory().new_device_by_classname("nld_sound_in", setup));
213      setup.register_dev(snd_in, "STREAM_INPUT");
214   }
212215
213216   pstring sparam = pstring::sprintf("STREAM_INPUT.CHAN%d", m_channel);
214217   setup.register_param(sparam, m_param_name);
r242982r242983
244247
245248void netlist_mame_stream_output_t::custom_netlist_additions(netlist_setup_t &setup)
246249{
247   //NETLIB_NAME(sound_out) *snd_out;
250   NETLIB_NAME(sound_out) *snd_out;
248251   pstring sname = pstring::sprintf("STREAM_OUT_%d", m_channel);
249252
250   //snd_out = dynamic_cast<NETLIB_NAME(sound_out) *>(setup.register_dev("nld_sound_out", sname));
251   setup.register_dev("nld_sound_out", sname);
253   snd_out = dynamic_cast<NETLIB_NAME(sound_out) *>(setup.factory().new_device_by_classname("nld_sound_out", setup));
254   setup.register_dev(snd_out, sname);
252255
253256   setup.register_param(sname + ".CHAN" , m_channel);
254257   setup.register_param(sname + ".MULT",  m_mult);
r242982r242983
440443               if (td != NULL) save_pointer(td, s->m_name, s->m_count);
441444            }
442445            break;
443            case DT_FLOAT:
444                {
445                    float *td = s->resolved<float>();
446                    if (td != NULL) save_pointer(td, s->m_name, s->m_count);
447                }
448                break;
449446         case DT_INT64:
450447            save_pointer((INT64 *) s->m_ptr, s->m_name, s->m_count);
451448            break;
trunk/src/emu/netlist/analog/nld_bjt.c
r242982r242983
1111{
1212public:
1313   diode() : m_Is(1e-15), m_VT(0.0258), m_VT_inv(1.0 / m_VT) {}
14   diode(const nl_double Is, const nl_double n)
14   diode(const double Is, const double n)
1515   {
1616      m_Is = Is;
1717      m_VT = 0.0258 * n;
1818      m_VT_inv = 1.0 / m_VT;
1919   }
20   void set(const nl_double Is, const nl_double n)
20   void set(const double Is, const double n)
2121   {
2222      m_Is = Is;
2323      m_VT = 0.0258 * n;
2424      m_VT_inv = 1.0 / m_VT;
2525   }
26   nl_double I(const nl_double V) const { return m_Is * exp(V * m_VT_inv) - m_Is; }
27   nl_double g(const nl_double V) const { return m_Is * m_VT_inv * exp(V * m_VT_inv); }
28   nl_double V(const nl_double I) const { return log(1.0 + I / m_Is) * m_VT; }
29   nl_double gI(const nl_double I) const { return m_VT_inv * (I + m_Is); }
26   double I(const double V) const { return m_Is * exp(V * m_VT_inv) - m_Is; }
27   double g(const double V) const { return m_Is * m_VT_inv * exp(V * m_VT_inv); }
28   double V(const double I) const { return log(1.0 + I / m_Is) * m_VT; }
29   double gI(const double I) const { return m_VT_inv * (I + m_Is); }
3030
3131private:
32   nl_double m_Is;
33   nl_double m_VT;
34   nl_double m_VT_inv;
32   double m_Is;
33   double m_VT;
34   double m_VT_inv;
3535};
3636
3737
r242982r242983
8585   m_state_on = 0;
8686
8787   {
88      nl_double IS = m_model.model_value("IS", 1e-15);
89      nl_double BF = m_model.model_value("BF", 100);
90      nl_double NF = m_model.model_value("NF", 1);
91      //nl_double VJE = m_model.dValue("VJE", 0.75);
88      double IS = m_model.model_value("IS", 1e-15);
89      double BF = m_model.model_value("BF", 100);
90      double NF = m_model.model_value("NF", 1);
91      //double VJE = m_model.dValue("VJE", 0.75);
9292
9393      set_qtype((m_model.model_type() == "NPN") ? BJT_NPN : BJT_PNP);
9494
95      nl_double alpha = BF / (1.0 + BF);
95      double alpha = BF / (1.0 + BF);
9696
9797      diode d(IS, NF);
9898
r242982r242983
155155   m_gD_BC.save("m_D_BC", *this);
156156
157157   {
158      nl_double IS = m_model.model_value("IS", 1e-15);
159      nl_double BF = m_model.model_value("BF", 100);
160      nl_double NF = m_model.model_value("NF", 1);
161      nl_double BR = m_model.model_value("BR", 1);
162      nl_double NR = m_model.model_value("NR", 1);
163      //nl_double VJE = m_model.dValue("VJE", 0.75);
158      double IS = m_model.model_value("IS", 1e-15);
159      double BF = m_model.model_value("BF", 100);
160      double NF = m_model.model_value("NF", 1);
161      double BR = m_model.model_value("BR", 1);
162      double NR = m_model.model_value("NR", 1);
163      //double VJE = m_model.dValue("VJE", 0.75);
164164
165165      set_qtype((m_model.model_type() == "NPN") ? BJT_NPN : BJT_PNP);
166166      //printf("type %s\n", m_model.model_type().cstr());
trunk/src/emu/netlist/analog/nld_bjt.h
r242982r242983
9898
9999   NETLIB_UPDATE_TERMINALS()
100100   {
101      const nl_double m = (is_qtype( BJT_NPN) ? 1 : -1);
101      const double m = (is_qtype( BJT_NPN) ? 1 : -1);
102102
103103      const int new_state = (m_RB.deltaV() * m > m_V ) ? 1 : 0;
104104      if (m_state_on ^ new_state)
105105      {
106106#if 0
107         nl_double gb = m_gB;
108         nl_double gc = m_gC;
109         nl_double v  = m_V * m;
107         double gb = m_gB;
108         double gc = m_gC;
109         double v  = m_V * m;
110110         if (!new_state )
111111         {
112112            // not conducting
r242982r242983
115115            gc = netlist().gmin();
116116         }
117117#else
118         const nl_double gb = new_state ? m_gB : netlist().gmin();
119         const nl_double gc = new_state ? m_gC : netlist().gmin();
120         const nl_double v  = new_state ? m_V * m : 0;
118         const double gb = new_state ? m_gB : netlist().gmin();
119         const double gc = new_state ? m_gC : netlist().gmin();
120         const double v  = new_state ? m_V * m : 0;
121121#endif
122122         m_RB.set(gb, v,   0.0);
123123         m_RC.set(gc, 0.0, 0.0);
r242982r242983
142142   ATTR_COLD virtual void start();
143143   ATTR_HOT void update_param();
144144
145   nl_double m_gB; // base conductance / switch on
146   nl_double m_gC; // collector conductance / switch on
147   nl_double m_V; // internal voltage source
145   double m_gB; // base conductance / switch on
146   double m_gC; // collector conductance / switch on
147   double m_V; // internal voltage source
148148   UINT8 m_state_on;
149149
150150private:
r242982r242983
169169
170170   NETLIB_UPDATE_TERMINALS()
171171   {
172      const nl_double polarity = (qtype() == BJT_NPN ? 1.0 : -1.0);
172      const double polarity = (qtype() == BJT_NPN ? 1.0 : -1.0);
173173
174174      m_gD_BE.update_diode(-m_D_EB.deltaV() * polarity);
175175      m_gD_BC.update_diode(-m_D_CB.deltaV() * polarity);
176176
177      const nl_double gee = m_gD_BE.G();
178      const nl_double gcc = m_gD_BC.G();
179      const nl_double gec =  m_alpha_r * gcc;
180      const nl_double gce =  m_alpha_f * gee;
181      const nl_double sIe = -m_gD_BE.I() + m_alpha_r * m_gD_BC.I();
182      const nl_double sIc = m_alpha_f * m_gD_BE.I() - m_gD_BC.I();
183      const nl_double Ie = (sIe + gee * m_gD_BE.Vd() - gec * m_gD_BC.Vd()) * polarity;
184      const nl_double Ic = (sIc - gce * m_gD_BE.Vd() + gcc * m_gD_BC.Vd()) * polarity;
177      const double gee = m_gD_BE.G();
178      const double gcc = m_gD_BC.G();
179      const double gec =  m_alpha_r * gcc;
180      const double gce =  m_alpha_f * gee;
181      const double sIe = -m_gD_BE.I() + m_alpha_r * m_gD_BC.I();
182      const double sIc = m_alpha_f * m_gD_BE.I() - m_gD_BC.I();
183      const double Ie = (sIe + gee * m_gD_BE.Vd() - gec * m_gD_BC.Vd()) * polarity;
184      const double Ic = (sIc - gce * m_gD_BE.Vd() + gcc * m_gD_BC.Vd()) * polarity;
185185
186186      m_D_EB.set_mat(gee, gec - gee, gce - gee, gee - gec, Ie, -Ie);
187187      m_D_CB.set_mat(gcc, gce - gcc, gec - gcc, gcc - gce, Ic, -Ic);
r242982r242983
202202   nld_twoterm m_D_EB;  // gee, gec - gee, gce - gee, gee - gec | Ie
203203   nld_twoterm m_D_EC;  // 0, -gec, -gcc, 0 | 0
204204
205   nl_double m_alpha_f;
206   nl_double m_alpha_r;
205   double m_alpha_f;
206   double m_alpha_r;
207207
208208private:
209209};
trunk/src/emu/netlist/analog/nld_fourterm.c
r242982r242983
1717   m_gfac = 1.0;
1818}
1919
20void NETLIB_NAME(VCCS)::start_internal(const nl_double def_RI)
20void NETLIB_NAME(VCCS)::start_internal(const double def_RI)
2121{
2222   register_param("G", m_G, 1.0);
2323   register_param("RI", m_RI, def_RI);
r242982r242983
4545
4646NETLIB_RESET(VCCS)
4747{
48   const nl_double m_mult = m_G.Value() * m_gfac; // 1.0 ==> 1V ==> 1A
49   const nl_double GI = 1.0 / m_RI.Value();
48   const double m_mult = m_G.Value() * m_gfac; // 1.0 ==> 1V ==> 1A
49   const double GI = 1.0 / m_RI.Value();
5050
5151   m_IP.set(GI);
5252   m_IN.set(GI);
trunk/src/emu/netlist/analog/nld_fourterm.h
r242982r242983
5959   ATTR_COLD virtual void update_param();
6060   ATTR_HOT ATTR_ALIGN void update();
6161
62   ATTR_COLD void start_internal(const nl_double def_RI);
62   ATTR_COLD void start_internal(const double def_RI);
6363
6464   netlist_terminal_t m_OP;
6565   netlist_terminal_t m_ON;
r242982r242983
7373   netlist_param_double_t m_G;
7474   netlist_param_double_t m_RI;
7575
76   nl_double m_gfac;
76   double m_gfac;
7777};
7878
7979// ----------------------------------------------------------------------------------------
r242982r242983
115115   ATTR_COLD virtual void update_param();
116116   ATTR_HOT ATTR_ALIGN void update();
117117
118   nl_double m_gfac;
118   double m_gfac;
119119};
120120
121121
trunk/src/emu/netlist/analog/nld_ms_direct.h
r242982r242983
2828protected:
2929   ATTR_COLD virtual void add_term(int net_idx, netlist_terminal_t *term);
3030
31   ATTR_HOT virtual nl_double vsolve();
31   ATTR_HOT virtual double vsolve();
3232
3333   ATTR_HOT int solve_non_dynamic();
3434   ATTR_HOT void build_LE();
35   ATTR_HOT void gauss_LE(nl_double (* RESTRICT x));
36   ATTR_HOT nl_double delta(const nl_double (* RESTRICT V));
37   ATTR_HOT void store(const nl_double (* RESTRICT V), const bool store_RHS);
35   ATTR_HOT void gauss_LE(double (* RESTRICT x));
36   ATTR_HOT double delta(const double (* RESTRICT V));
37   ATTR_HOT void store(const double (* RESTRICT V), const bool store_RHS);
3838
3939   /* bring the whole system to the current time
4040    * Don't schedule a new calculation time. The recalculation has to be
4141    * triggered by the caller after the netlist element was changed.
4242    */
43   ATTR_HOT nl_double compute_next_timestep();
43   ATTR_HOT double compute_next_timestep();
4444
45   nl_double m_A[_storage_N][((_storage_N + 7) / 8) * 8];
46   nl_double m_RHS[_storage_N];
47   nl_double m_last_RHS[_storage_N]; // right hand side - contains currents
48   nl_double m_Vdelta[_storage_N];
49   nl_double m_last_V[_storage_N];
45   double m_A[_storage_N][((_storage_N + 7) / 8) * 8];
46   double m_RHS[_storage_N];
47   double m_last_RHS[_storage_N]; // right hand side - contains currents
48   double m_Vdelta[_storage_N];
49   double m_last_V[_storage_N];
5050
5151   terms_t **m_terms;
5252   terms_t *m_rails_temp;
r242982r242983
5555   vector_ops_t *m_row_ops[_storage_N + 1];
5656
5757   int m_dim;
58   nl_double m_lp_fact;
58   double m_lp_fact;
5959};
6060
6161// ----------------------------------------------------------------------------------------
r242982r242983
8484}
8585
8686template <int m_N, int _storage_N>
87ATTR_HOT nl_double netlist_matrix_solver_direct_t<m_N, _storage_N>::compute_next_timestep()
87ATTR_HOT double netlist_matrix_solver_direct_t<m_N, _storage_N>::compute_next_timestep()
8888{
89   nl_double new_solver_timestep = m_params.m_max_timestep;
89   double new_solver_timestep = m_params.m_max_timestep;
9090
9191   if (m_params.m_dynamic)
9292   {
r242982r242983
103103      {
104104         netlist_analog_net_t *n = m_nets[k];
105105#endif
106         const nl_double DD_n = (n->m_cur_Analog - m_last_V[k]);
107         const nl_double hn = current_timestep();
106         const double DD_n = (n->m_cur_Analog - m_last_V[k]);
107         const double hn = current_timestep();
108108
109         nl_double DD2 = (DD_n / hn - n->m_DD_n_m_1 / n->m_h_n_m_1) / (hn + n->m_h_n_m_1);
110         nl_double new_net_timestep;
109         double DD2 = (DD_n / hn - n->m_DD_n_m_1 / n->m_h_n_m_1) / (hn + n->m_h_n_m_1);
110         double new_net_timestep;
111111
112112         n->m_h_n_m_1 = hn;
113113         n->m_DD_n_m_1 = DD_n;
r242982r242983
236236      for (int i=0; i < N(); i++)
237237         m_A[k][i] = 0.0;
238238
239      nl_double rhsk = 0.0;
240      nl_double akk  = 0.0;
239      double rhsk = 0.0;
240      double akk  = 0.0;
241241      {
242242         const int terms_count = m_terms[k]->count();
243         const nl_double * RESTRICT gt = m_terms[k]->gt();
244         const nl_double * RESTRICT go = m_terms[k]->go();
245         const nl_double * RESTRICT Idr = m_terms[k]->Idr();
243         const double * RESTRICT gt = m_terms[k]->gt();
244         const double * RESTRICT go = m_terms[k]->go();
245         const double * RESTRICT Idr = m_terms[k]->Idr();
246246#if VECTALT
247247
248248         for (int i = 0; i < terms_count; i++)
r242982r242983
253253#else
254254         m_terms[k]->ops()->sum2(Idr, gt, rhsk, akk);
255255#endif
256         nl_double * const * RESTRICT other_cur_analog = m_terms[k]->other_curanalog();
256         double * const * RESTRICT other_cur_analog = m_terms[k]->other_curanalog();
257257         for (int i = m_terms[k]->m_railstart; i < terms_count; i++)
258258         {
259259            //rhsk = rhsk + go[i] * terms[i]->m_otherterm->net().as_analog().Q_Analog();
r242982r242983
272272      m_A[k][k] += 1.0;
273273      {
274274         const int *net_other = m_terms[k]->net_other();
275         const nl_double *go = m_terms[k]->go();
275         const double *go = m_terms[k]->go();
276276         const int railstart =  m_terms[k]->m_railstart;
277277
278278         for (int i = 0; i < railstart; i++)
r242982r242983
285285      m_A[k][k] += akk;
286286      {
287287         const int * RESTRICT net_other = m_terms[k]->net_other();
288         const nl_double * RESTRICT go = m_terms[k]->go();
288         const double * RESTRICT go = m_terms[k]->go();
289289         const int railstart =  m_terms[k]->m_railstart;
290290
291291         for (int i = 0; i < railstart; i++)
r242982r242983
299299
300300template <int m_N, int _storage_N>
301301ATTR_HOT void netlist_matrix_solver_direct_t<m_N, _storage_N>::gauss_LE(
302      nl_double (* RESTRICT x))
302      double (* RESTRICT x))
303303{
304304#if 0
305305   for (int i = 0; i < N(); i++)
r242982r242983
336336      }
337337
338338      /* FIXME: Singular matrix? */
339      const nl_double f = 1.0 / m_A[i][i];
339      const double f = 1.0 / m_A[i][i];
340340
341341      /* Eliminate column i from row j */
342342
343343      for (int j = i + 1; j < kN; j++)
344344      {
345         const nl_double f1 = - m_A[j][i] * f;
345         const double f1 = - m_A[j][i] * f;
346346         if (f1 != 0.0)
347347         {
348348#if 0 && VECTALT
r242982r242983
359359   /* back substitution */
360360   for (int j = kN - 1; j >= 0; j--)
361361   {
362      nl_double tmp = 0;
362      double tmp = 0;
363363
364364      for (int k = j + 1; k < kN; k++)
365365         tmp += m_A[j][k] * x[k];
r242982r242983
380380}
381381
382382template <int m_N, int _storage_N>
383ATTR_HOT nl_double netlist_matrix_solver_direct_t<m_N, _storage_N>::delta(
384      const nl_double (* RESTRICT V))
383ATTR_HOT double netlist_matrix_solver_direct_t<m_N, _storage_N>::delta(
384      const double (* RESTRICT V))
385385{
386   nl_double cerr = 0;
387   nl_double cerr2 = 0;
386   double cerr = 0;
387   double cerr2 = 0;
388388   for (int i = 0; i < this->N(); i++)
389389   {
390      const nl_double e = (V[i] - this->m_nets[i]->m_cur_Analog);
391      const nl_double e2 = (m_RHS[i] - this->m_last_RHS[i]);
390      const double e = (V[i] - this->m_nets[i]->m_cur_Analog);
391      const double e2 = (m_RHS[i] - this->m_last_RHS[i]);
392392      cerr = (fabs(e) > cerr ? fabs(e) : cerr);
393393      cerr2 = (fabs(e2) > cerr2 ? fabs(e2) : cerr2);
394394   }
r242982r242983
398398
399399template <int m_N, int _storage_N>
400400ATTR_HOT void netlist_matrix_solver_direct_t<m_N, _storage_N>::store(
401      const nl_double (* RESTRICT V), const bool store_RHS)
401      const double (* RESTRICT V), const bool store_RHS)
402402{
403403   for (int i = 0; i < this->N(); i++)
404404   {
r242982r242983
414414}
415415
416416template <int m_N, int _storage_N>
417ATTR_HOT nl_double netlist_matrix_solver_direct_t<m_N, _storage_N>::vsolve()
417ATTR_HOT double netlist_matrix_solver_direct_t<m_N, _storage_N>::vsolve()
418418{
419419   solve_base<netlist_matrix_solver_direct_t>(this);
420420   return this->compute_next_timestep();
r242982r242983
424424template <int m_N, int _storage_N>
425425ATTR_HOT int netlist_matrix_solver_direct_t<m_N, _storage_N>::solve_non_dynamic()
426426{
427   nl_double new_v[_storage_N] = { 0.0 };
427   double new_v[_storage_N] = { 0.0 };
428428
429429   this->gauss_LE(new_v);
430430
431431   if (this->is_dynamic())
432432   {
433      nl_double err = delta(new_v);
433      double err = delta(new_v);
434434
435435      store(new_v, true);
436436
trunk/src/emu/netlist/analog/nld_ms_direct1.h
r242982r242983
1818      {}
1919   ATTR_HOT inline int vsolve_non_dynamic();
2020protected:
21   ATTR_HOT virtual nl_double vsolve();
21   ATTR_HOT virtual double vsolve();
2222private:
2323};
2424
r242982r242983
2626// netlist_matrix_solver - Direct1
2727// ----------------------------------------------------------------------------------------
2828
29ATTR_HOT nl_double netlist_matrix_solver_direct1_t::vsolve()
29ATTR_HOT double netlist_matrix_solver_direct1_t::vsolve()
3030{
3131   solve_base<netlist_matrix_solver_direct1_t>(this);
3232   return this->compute_next_timestep();
r242982r242983
3838   this->build_LE();
3939   //NL_VERBOSE_OUT(("%f %f\n", new_val, m_RHS[0] / m_A[0][0]);
4040
41   nl_double new_val =  m_RHS[0] / m_A[0][0];
41   double new_val =  m_RHS[0] / m_A[0][0];
4242
43   nl_double e = (new_val - net->m_cur_Analog);
44   nl_double cerr = fabs(e);
43   double e = (new_val - net->m_cur_Analog);
44   double cerr = fabs(e);
4545
4646   net->m_cur_Analog = new_val;
4747
trunk/src/emu/netlist/analog/nld_ms_direct2.h
r242982r242983
2020      {}
2121   ATTR_HOT inline int vsolve_non_dynamic();
2222protected:
23   ATTR_HOT virtual nl_double vsolve();
23   ATTR_HOT virtual double vsolve();
2424private:
2525};
2626
r242982r242983
2828// netlist_matrix_solver - Direct2
2929// ----------------------------------------------------------------------------------------
3030
31ATTR_HOT nl_double netlist_matrix_solver_direct2_t::vsolve()
31ATTR_HOT double netlist_matrix_solver_direct2_t::vsolve()
3232{
3333   solve_base<netlist_matrix_solver_direct2_t>(this);
3434   return this->compute_next_timestep();
r242982r242983
3838{
3939   build_LE();
4040
41   const nl_double a = m_A[0][0];
42   const nl_double b = m_A[0][1];
43   const nl_double c = m_A[1][0];
44   const nl_double d = m_A[1][1];
41   const double a = m_A[0][0];
42   const double b = m_A[0][1];
43   const double c = m_A[1][0];
44   const double d = m_A[1][1];
4545
46   nl_double new_val[2];
46   double new_val[2];
4747   new_val[1] = (a * m_RHS[1] - c * m_RHS[0]) / (a * d - b * c);
4848   new_val[0] = (m_RHS[0] - b * new_val[1]) / a;
4949
5050   if (is_dynamic())
5151   {
52      nl_double err = this->delta(new_val);
52      double err = this->delta(new_val);
5353      store(new_val, true);
5454      if (err > m_params.m_accuracy )
5555         return 2;
trunk/src/emu/netlist/analog/nld_ms_gauss_seidel.h
r242982r242983
2929
3030   ATTR_HOT inline int vsolve_non_dynamic();
3131protected:
32   ATTR_HOT virtual nl_double vsolve();
32   ATTR_HOT virtual double vsolve();
3333
3434private:
35   nl_double m_lp_fact;
35   double m_lp_fact;
3636   int m_gs_fail;
3737   int m_gs_total;
3838
r242982r242983
6464}
6565
6666template <int m_N, int _storage_N>
67ATTR_HOT nl_double netlist_matrix_solver_gauss_seidel_t<m_N, _storage_N>::vsolve()
67ATTR_HOT double netlist_matrix_solver_gauss_seidel_t<m_N, _storage_N>::vsolve()
6868{
6969   /*
7070    * enable linear prediction on first newton pass
r242982r242983
8686
8787   if (USE_LINEAR_PREDICTION)
8888   {
89      nl_double sq = 0;
90      nl_double sqo = 0;
91      const nl_double rez_cts = 1.0 / this->current_timestep();
89      double sq = 0;
90      double sqo = 0;
91      const double rez_cts = 1.0 / this->current_timestep();
9292      for (int k = 0; k < this->N(); k++)
9393      {
9494         const netlist_analog_net_t *n = this->m_nets[k];
95         const nl_double nv = (n->m_cur_Analog - this->m_last_V[k]) * rez_cts ;
95         const double nv = (n->m_cur_Analog - this->m_last_V[k]) * rez_cts ;
9696         sq += nv * nv;
9797         sqo += this->m_Vdelta[k] * this->m_Vdelta[k];
9898         this->m_Vdelta[k] = nv;
r242982r242983
116116    */
117117
118118#if 0 || USE_MATRIX_GS
119   static nl_double ws = 1.0;
120   ATTR_ALIGN nl_double new_v[_storage_N] = { 0.0 };
119   static double ws = 1.0;
120   ATTR_ALIGN double new_v[_storage_N] = { 0.0 };
121121   const int iN = this->N();
122122
123123   bool resched = false;
r242982r242983
127127   this->build_LE();
128128
129129   {
130      nl_double frob;
130      double frob;
131131      frob = 0;
132      nl_double rmin = 1e99, rmax = -1e99;
132      double rmin = 1e99, rmax = -1e99;
133133      for (int k = 0; k < iN; k++)
134134      {
135135         new_v[k] = this->m_nets[k]->m_cur_Analog;
136         nl_double s=0.0;
136         double s=0.0;
137137         for (int i = 0; i < iN; i++)
138138         {
139139            frob += this->m_A[k][i] * this->m_A[k][i];
r242982r242983
146146            rmax = s;
147147      }
148148#if 0
149      nl_double frobA = sqrt(frob /(iN));
149      double frobA = sqrt(frob /(iN));
150150      if (1 &&frobA < 1.0)
151151         //ws = 2.0 / (1.0 + sqrt(1.0-frobA));
152152         ws = 2.0 / (2.0 - frobA);
r242982r242983
161161      // overhead is bigger than the gain. Consequently the fast GS below
162162      // uses a fixed GS. One can however use this here to determine a
163163      // suitable parameter.
164      nl_double rm = (rmax + rmin) * 0.5;
164      double rm = (rmax + rmin) * 0.5;
165165      if (rm < 1.0)
166166         ws = 2.0 / (1.0 + sqrt(1.0-rm));
167167      else
r242982r242983
172172   }
173173
174174   // Frobenius norm for (D-L)^(-1)U
175   //nl_double frobU;
176   //nl_double frobL;
177   //nl_double norm;
175   //double frobU;
176   //double frobL;
177   //double norm;
178178   do {
179179      resched = false;
180      nl_double cerr = 0.0;
180      double cerr = 0.0;
181181      //frobU = 0;
182182      //frobL = 0;
183183      //norm = 0;
184184
185185      for (int k = 0; k < iN; k++)
186186      {
187         nl_double Idrive = 0;
188         //nl_double norm_t = 0;
187         double Idrive = 0;
188         //double norm_t = 0;
189189         // Reduction loops need -ffast-math
190190         for (int i = 0; i < iN; i++)
191191            Idrive += this->m_A[k][i] * new_v[i];
r242982r242983
198198         }
199199
200200         //if (norm_t > norm) norm = norm_t;
201         const nl_double new_val = (1.0-ws) * new_v[k] + ws * (this->m_RHS[k] - Idrive + this->m_A[k][k] * new_v[k]) / this->m_A[k][k];
201         const double new_val = (1.0-ws) * new_v[k] + ws * (this->m_RHS[k] - Idrive + this->m_A[k][k] * new_v[k]) / this->m_A[k][k];
202202
203         const nl_double e = fabs(new_val - new_v[k]);
203         const double e = fabs(new_val - new_v[k]);
204204         cerr = (e > cerr ? e : cerr);
205205         new_v[k] = new_val;
206206      }
r242982r242983
210210         resched = true;
211211      }
212212      resched_cnt++;
213      //ATTR_UNUSED nl_double frobUL = sqrt((frobU + frobL) / (double) (iN) / (double) (iN));
213      //ATTR_UNUSED double frobUL = sqrt((frobU + frobL) / (double) (iN) / (double) (iN));
214214   } while (resched && (resched_cnt < this->m_params.m_gs_loops));
215215   //printf("Frobenius %f %f %f %f %f\n", sqrt(frobU), sqrt(frobL), frobUL, frobA, norm);
216216   //printf("Omega Estimate1 %f %f\n", 2.0 / (1.0 + sqrt(1-frobUL)), 2.0 / (1.0 + sqrt(1-frobA)) ); //        printf("Frobenius %f\n", sqrt(frob / (double) (iN * iN) ));
r242982r242983
247247    * omega = 2.0 / (1.0 + sqrt(1-rho))
248248    */
249249
250   const nl_double ws = this->m_params.m_sor; //1.045; //2.0 / (1.0 + /*sin*/(3.14159 * 5.5 / (double) (m_nets.count()+1)));
251   //const nl_double ws = 2.0 / (1.0 + sin(3.14159 * 4 / (double) (this->N())));
250   const double ws = this->m_params.m_sor; //1.045; //2.0 / (1.0 + /*sin*/(3.14159 * 5.5 / (double) (m_nets.count()+1)));
251   //const double ws = 2.0 / (1.0 + sin(3.14159 * 4 / (double) (this->N())));
252252
253   ATTR_ALIGN nl_double w[_storage_N];
254   ATTR_ALIGN nl_double one_m_w[_storage_N];
255   ATTR_ALIGN nl_double RHS[_storage_N];
256   ATTR_ALIGN nl_double new_V[_storage_N];
253   ATTR_ALIGN double w[_storage_N];
254   ATTR_ALIGN double one_m_w[_storage_N];
255   ATTR_ALIGN double RHS[_storage_N];
256   ATTR_ALIGN double new_V[_storage_N];
257257
258258   for (int k = 0; k < iN; k++)
259259   {
260      nl_double gtot_t = 0.0;
261      nl_double gabs_t = 0.0;
262      nl_double RHS_t = 0.0;
260      double gtot_t = 0.0;
261      double gabs_t = 0.0;
262      double RHS_t = 0.0;
263263
264264      new_V[k] = this->m_nets[k]->m_cur_Analog;
265265
266266      {
267267         const int term_count = this->m_terms[k]->count();
268         const nl_double * const RESTRICT gt = this->m_terms[k]->gt();
269         const nl_double * const RESTRICT go = this->m_terms[k]->go();
270         const nl_double * const RESTRICT Idr = this->m_terms[k]->Idr();
271         const nl_double * const *other_cur_analog = this->m_terms[k]->other_curanalog();
268         const double * const RESTRICT gt = this->m_terms[k]->gt();
269         const double * const RESTRICT go = this->m_terms[k]->go();
270         const double * const RESTRICT Idr = this->m_terms[k]->Idr();
271         const double * const *other_cur_analog = this->m_terms[k]->other_curanalog();
272272#if VECTALT
273273         for (int i = 0; i < term_count; i++)
274274         {
r242982r242983
308308
309309   }
310310
311   const nl_double accuracy = this->m_params.m_accuracy;
311   const double accuracy = this->m_params.m_accuracy;
312312
313313   do {
314314      resched = false;
r242982r242983
317317      {
318318         const int * RESTRICT net_other = this->m_terms[k]->net_other();
319319         const int railstart = this->m_terms[k]->m_railstart;
320         const nl_double * RESTRICT go = this->m_terms[k]->go();
320         const double * RESTRICT go = this->m_terms[k]->go();
321321
322         nl_double Idrive = 0.0;
322         double Idrive = 0.0;
323323         for (int i = 0; i < railstart; i++)
324324            Idrive = Idrive + go[i] * new_V[net_other[i]];
325325
326         //nl_double new_val = (net->m_cur_Analog * gabs[k] + iIdr) / (gtot[k]);
327         const nl_double new_val = new_V[k] * one_m_w[k] + (Idrive + RHS[k]) * w[k];
326         //double new_val = (net->m_cur_Analog * gabs[k] + iIdr) / (gtot[k]);
327         const double new_val = new_V[k] * one_m_w[k] + (Idrive + RHS[k]) * w[k];
328328
329329         resched = resched || (std::abs(new_val - new_V[k]) > accuracy);
330330         new_V[k] = new_val;
trunk/src/emu/netlist/analog/nld_solver.c
r242982r242983
233233
234234ATTR_COLD void netlist_matrix_solver_t::update()
235235{
236   const nl_double new_timestep = solve();
236   const double new_timestep = solve();
237237
238238   if (m_params.m_dynamic && is_timestep() && new_timestep > 0)
239239      m_Q_sync.net().reschedule_in_queue(netlist_time::from_double(new_timestep));
r242982r242983
241241
242242ATTR_COLD void netlist_matrix_solver_t::update_forced()
243243{
244   ATTR_UNUSED const nl_double new_timestep = solve();
244   ATTR_UNUSED const double new_timestep = solve();
245245
246246   if (m_params.m_dynamic && is_timestep())
247247      m_Q_sync.net().reschedule_in_queue(netlist_time::from_double(m_params.m_min_timestep));
r242982r242983
249249
250250ATTR_HOT void netlist_matrix_solver_t::step(const netlist_time delta)
251251{
252   const nl_double dd = delta.as_double();
252   const double dd = delta.as_double();
253253   for (int k=0; k < m_step_devices.count(); k++)
254254      m_step_devices[k]->step_time(dd);
255255}
r242982r242983
284284   }
285285}
286286
287ATTR_HOT nl_double netlist_matrix_solver_t::solve()
287ATTR_HOT double netlist_matrix_solver_t::solve()
288288{
289289   netlist_time now = netlist().time();
290290   netlist_time delta = now - m_last_step;
r242982r242983
300300
301301   step(delta);
302302
303   const nl_double next_time_step = vsolve();
303   const double next_time_step = vsolve();
304304
305305   update_inputs();
306306   return next_time_step;
r242982r242983
348348   register_param("GMIN", m_gmin, NETLIST_GMIN_DEFAULT);
349349   register_param("DYNAMIC_TS", m_dynamic, 0);
350350   register_param("LTE", m_lte, 5e-5);                     // diff/timestep
351   register_param("MIN_TIMESTEP", m_min_timestep, 1e-6);   // nl_double timestep resolution
351   register_param("MIN_TIMESTEP", m_min_timestep, 1e-6);   // double timestep resolution
352352
353353   // internal staff
354354
r242982r242983
417417      if (m_mat_solvers[i]->is_timestep())
418418         {
419419            // Ignore return value
420            ATTR_UNUSED const nl_double ts = m_mat_solvers[i]->solve();
420            ATTR_UNUSED const double ts = m_mat_solvers[i]->solve();
421421         }
422422   }
423423#endif
trunk/src/emu/netlist/analog/nld_solver.h
r242982r242983
3737
3838struct netlist_solver_parameters_t
3939{
40   nl_double m_accuracy;
41   nl_double m_lte;
42   nl_double m_min_timestep;
43   nl_double m_max_timestep;
44   nl_double m_sor;
40   double m_accuracy;
41   double m_lte;
42   double m_min_timestep;
43   double m_max_timestep;
44   double m_sor;
4545   bool m_dynamic;
4646   int m_gs_loops;
4747   int m_nr_loops;
r242982r242983
5959
6060   virtual ~vector_ops_t() {}
6161
62   virtual const nl_double sum(const nl_double * v) = 0;
63   virtual void sum2(const nl_double * RESTRICT v1, const nl_double * RESTRICT v2, nl_double & RESTRICT  s1, nl_double & RESTRICT s2) = 0;
64   virtual void addmult(nl_double * RESTRICT v1, const nl_double * RESTRICT v2, const nl_double &mult) = 0;
65   virtual void sum2a(const nl_double * RESTRICT v1, const nl_double * RESTRICT v2, const nl_double * RESTRICT v3abs, nl_double & RESTRICT s1, nl_double & RESTRICT s2, nl_double & RESTRICT s3abs) = 0;
62   virtual const double sum(const double * v) = 0;
63   virtual void sum2(const double * RESTRICT v1, const double * RESTRICT v2, double & RESTRICT  s1, double & RESTRICT s2) = 0;
64   virtual void addmult(double * RESTRICT v1, const double * RESTRICT v2, const double &mult) = 0;
65   virtual void sum2a(const double * RESTRICT v1, const double * RESTRICT v2, const double * RESTRICT v3abs, double & RESTRICT s1, double & RESTRICT s2, double & RESTRICT s3abs) = 0;
6666
67   virtual const nl_double sumabs(const nl_double * v) = 0;
67   virtual const double sumabs(const double * v) = 0;
6868
6969   static vector_ops_t *create_ops(const int size);
7070
r242982r242983
9595
9696   ATTR_HOT inline const int N() const { if (m_N == 0) return m_dim; else return m_N; }
9797
98   const nl_double sum(const nl_double * v)
98   const double sum(const double * v)
9999   {
100      const nl_double *  RESTRICT vl = v;
101      nl_double tmp = 0.0;
100      const double *  RESTRICT vl = v;
101      double tmp = 0.0;
102102      for (int i=0; i < N(); i++)
103103         tmp += vl[i];
104104      return tmp;
105105   }
106106
107   void sum2(const nl_double * RESTRICT v1, const nl_double * RESTRICT v2, nl_double & RESTRICT s1, nl_double & RESTRICT s2)
107   void sum2(const double * RESTRICT v1, const double * RESTRICT v2, double & RESTRICT s1, double & RESTRICT s2)
108108   {
109      const nl_double * RESTRICT v1l = v1;
110      const nl_double * RESTRICT v2l = v2;
109      const double * RESTRICT v1l = v1;
110      const double * RESTRICT v2l = v2;
111111      for (int i=0; i < N(); i++)
112112      {
113113         s1 += v1l[i];
r242982r242983
115115      }
116116   }
117117
118   void addmult(nl_double * RESTRICT v1, const nl_double * RESTRICT v2, const nl_double &mult)
118   void addmult(double * RESTRICT v1, const double * RESTRICT v2, const double &mult)
119119   {
120      nl_double * RESTRICT v1l = v1;
121      const nl_double * RESTRICT v2l = v2;
120      double * RESTRICT v1l = v1;
121      const double * RESTRICT v2l = v2;
122122      for (int i=0; i < N(); i++)
123123      {
124124         v1l[i] += v2l[i] * mult;
125125      }
126126   }
127127
128   void sum2a(const nl_double * RESTRICT v1, const nl_double * RESTRICT v2, const nl_double * RESTRICT v3abs, nl_double & RESTRICT s1, nl_double & RESTRICT s2, nl_double & RESTRICT s3abs)
128   void sum2a(const double * RESTRICT v1, const double * RESTRICT v2, const double * RESTRICT v3abs, double & RESTRICT s1, double & RESTRICT s2, double & RESTRICT s3abs)
129129   {
130      const nl_double * RESTRICT v1l = v1;
131      const nl_double * RESTRICT v2l = v2;
132      const nl_double * RESTRICT v3l = v3abs;
130      const double * RESTRICT v1l = v1;
131      const double * RESTRICT v2l = v2;
132      const double * RESTRICT v3l = v3abs;
133133      for (int i=0; i < N(); i++)
134134      {
135135         s1 += v1l[i];
r242982r242983
138138      }
139139   }
140140
141   const nl_double sumabs(const nl_double * v)
141   const double sumabs(const double * v)
142142   {
143      const nl_double * RESTRICT vl = v;
144      nl_double tmp = 0.0;
143      const double * RESTRICT vl = v;
144      double tmp = 0.0;
145145      for (int i=0; i < N(); i++)
146146         tmp += fabs(vl[i]);
147147      return tmp;
r242982r242983
171171
172172   ATTR_HOT inline netlist_terminal_t **terms() { return m_term; }
173173   ATTR_HOT inline int *net_other() { return m_net_other; }
174   ATTR_HOT inline nl_double *gt() { return m_gt; }
175   ATTR_HOT inline nl_double *go() { return m_go; }
176   ATTR_HOT inline nl_double *Idr() { return m_Idr; }
177   ATTR_HOT inline nl_double **other_curanalog() { return m_other_curanalog; }
174   ATTR_HOT inline double *gt() { return m_gt; }
175   ATTR_HOT inline double *go() { return m_go; }
176   ATTR_HOT inline double *Idr() { return m_Idr; }
177   ATTR_HOT inline double **other_curanalog() { return m_other_curanalog; }
178178
179179   ATTR_COLD void set_pointers();
180180
r242982r242983
183183private:
184184   plinearlist_t<netlist_terminal_t *> m_term;
185185   plinearlist_t<int> m_net_other;
186   plinearlist_t<nl_double> m_go;
187   plinearlist_t<nl_double> m_gt;
188   plinearlist_t<nl_double> m_Idr;
189   plinearlist_t<nl_double *> m_other_curanalog;
186   plinearlist_t<double> m_go;
187   plinearlist_t<double> m_gt;
188   plinearlist_t<double> m_Idr;
189   plinearlist_t<double *> m_other_curanalog;
190190};
191191
192192class netlist_matrix_solver_t : public netlist_device_t
r242982r242983
209209   template<class C>
210210   void solve_base(C *p);
211211
212   ATTR_HOT nl_double solve();
212   ATTR_HOT double solve();
213213
214214   ATTR_HOT inline bool is_dynamic() { return m_dynamic_devices.count() > 0; }
215215   ATTR_HOT inline bool is_timestep() { return m_step_devices.count() > 0; }
r242982r242983
236236   ATTR_HOT void update_dynamic();
237237
238238   // should return next time step
239   ATTR_HOT virtual nl_double vsolve() = 0;
239   ATTR_HOT virtual double vsolve() = 0;
240240
241241   ATTR_COLD virtual void  add_term(int net_idx, netlist_terminal_t *term) = 0;
242242
r242982r242983
249249
250250   const netlist_solver_parameters_t &m_params;
251251
252   ATTR_HOT inline const nl_double current_timestep() { return m_cur_ts; }
252   ATTR_HOT inline const double current_timestep() { return m_cur_ts; }
253253private:
254254
255255   netlist_time m_last_step;
256   nl_double m_cur_ts;
256   double m_cur_ts;
257257   dev_list_t m_step_devices;
258258   dev_list_t m_dynamic_devices;
259259
r242982r242983
279279
280280   ATTR_COLD void post_start();
281281
282   ATTR_HOT inline nl_double gmin() { return m_gmin.Value(); }
282   ATTR_HOT inline double gmin() { return m_gmin.Value(); }
283283
284284protected:
285285   ATTR_HOT void update();
trunk/src/emu/netlist/analog/nld_twoterm.c
r242982r242983
1616   set_param(1e-15, 1, 1e-15);
1717}
1818
19ATTR_COLD void netlist_generic_diode::set_param(const nl_double Is, const nl_double n, nl_double gmin)
19ATTR_COLD void netlist_generic_diode::set_param(const double Is, const double n, double gmin)
2020{
2121   m_Is = Is;
2222   m_n = n;
r242982r242983
157157
158158NETLIB_UPDATE_PARAM(POT)
159159{
160   nl_double v = m_Dial.Value();
160   double v = m_Dial.Value();
161161   if (m_DialIsLog.Value())
162162      v = (exp(v) - 1.0) / (exp(1.0) - 1.0);
163163
r242982r242983
221221
222222NETLIB_UPDATE_PARAM(D)
223223{
224   nl_double Is = m_model.model_value("Is", 1e-15);
225   nl_double n = m_model.model_value("N", 1);
224   double Is = m_model.model_value("Is", 1e-15);
225   double n = m_model.model_value("N", 1);
226226
227227   m_D.set_param(Is, n, netlist().gmin());
228228}
trunk/src/emu/netlist/analog/nld_twoterm.h
r242982r242983
9797   {
9898   }
9999
100   ATTR_HOT inline void set(const nl_double G, const nl_double V, const nl_double I)
100   ATTR_HOT inline void set(const double G, const double V, const double I)
101101   {
102102      /*      GO, GT, I                */
103103      m_P.set( G,  G, (  V) * G - I);
104104      m_N.set( G,  G, ( -V) * G + I);
105105   }
106106
107   ATTR_HOT inline nl_double deltaV() const
107   ATTR_HOT inline double deltaV() const
108108   {
109109      return m_P.net().as_analog().Q_Analog() - m_N.net().as_analog().Q_Analog();
110110   }
111111
112   ATTR_HOT void set_mat(nl_double a11, nl_double a12, nl_double a21, nl_double a22, nl_double r1, nl_double r2)
112   ATTR_HOT void set_mat(double a11, double a12, double a21, double a22, double r1, double r2)
113113   {
114114      /*      GO, GT, I                */
115115      m_P.set(-a12, a11, -r1);
r242982r242983
133133public:
134134   ATTR_COLD NETLIB_NAME(R_base)() : NETLIB_NAME(twoterm)(RESISTOR) { }
135135
136   inline void set_R(const nl_double R)
136   inline void set_R(const double R)
137137   {
138138      set(1.0 / R, 0.0, 0.0);
139139   }
r242982r242983
171171public:
172172   ATTR_COLD NETLIB_NAME(C)() : NETLIB_NAME(twoterm)(CAPACITOR) { }
173173
174   ATTR_HOT void step_time(const nl_double st)
174   ATTR_HOT void step_time(const double st)
175175   {
176      const nl_double G = m_C.Value() / st;
177      const nl_double I = -G * deltaV();
176      const double G = m_C.Value() / st;
177      const double I = -G * deltaV();
178178      set(G, 0.0, I);
179179   }
180180
r242982r242983
198198public:
199199   ATTR_COLD netlist_generic_diode();
200200
201   ATTR_HOT inline void update_diode(const nl_double nVd)
201   ATTR_HOT inline void update_diode(const double nVd)
202202   {
203203      //FIXME: Optimize cutoff case
204204
r242982r242983
212212      {
213213         m_Vd = nVd;
214214
215         const nl_double eVDVt = exp(m_Vd * m_VtInv);
215         const double eVDVt = exp(m_Vd * m_VtInv);
216216         m_Id = m_Is * (eVDVt - 1.0);
217217         m_G = m_Is * m_VtInv * eVDVt + m_gmin;
218218      }
r242982r242983
221221#if defined(_MSC_VER) && _MSC_VER < 1800
222222         m_Vd = m_Vd + log((nVd - m_Vd) * m_VtInv + 1.0) * m_Vt;
223223#else
224         nl_double a = (nVd - m_Vd) * m_VtInv;
224         double a = (nVd - m_Vd) * m_VtInv;
225225         if (a<1e-12 - 1.0) a = 1e-12 - 1.0;
226226         m_Vd = m_Vd + log1p(a) * m_Vt;
227227#endif
228         const nl_double eVDVt = exp(m_Vd * m_VtInv);
228         const double eVDVt = exp(m_Vd * m_VtInv);
229229         m_Id = m_Is * (eVDVt - 1.0);
230230
231231         m_G = m_Is * m_VtInv * eVDVt + m_gmin;
r242982r242983
234234      //printf("nVd %f m_Vd %f Vcrit %f\n", nVd, m_Vd, m_Vcrit);
235235   }
236236
237   ATTR_COLD void set_param(const nl_double Is, const nl_double n, nl_double gmin);
237   ATTR_COLD void set_param(const double Is, const double n, double gmin);
238238
239   ATTR_HOT inline nl_double I() const { return m_Id; }
240   ATTR_HOT inline nl_double G() const { return m_G; }
241   ATTR_HOT inline nl_double Ieq() const { return (m_Id - m_Vd * m_G); }
242   ATTR_HOT inline nl_double Vd() const { return m_Vd; }
239   ATTR_HOT inline double I() const { return m_Id; }
240   ATTR_HOT inline double G() const { return m_G; }
241   ATTR_HOT inline double Ieq() const { return (m_Id - m_Vd * m_G); }
242   ATTR_HOT inline double Vd() const { return m_Vd; }
243243
244244   /* owning object must save those ... */
245245
246246   ATTR_COLD void save(pstring name, netlist_object_t &parent);
247247
248248private:
249   nl_double m_Vd;
250   nl_double m_Id;
251   nl_double m_G;
249   double m_Vd;
250   double m_Id;
251   double m_G;
252252
253   nl_double m_Vt;
254   nl_double m_Is;
255   nl_double m_n;
256   nl_double m_gmin;
253   double m_Vt;
254   double m_Is;
255   double m_n;
256   double m_gmin;
257257
258   nl_double m_VtInv;
259   nl_double m_Vcrit;
258   double m_VtInv;
259   double m_Vcrit;
260260};
261261
262262// ----------------------------------------------------------------------------------------
r242982r242983
268268// add c3 and it'll be better than 1%
269269
270270#if 0
271inline nl_double fastexp_h(const nl_double x)
271inline double fastexp_h(const double x)
272272{
273   static const nl_double ln2r = 1.442695040888963387;
274   static const nl_double ln2  = 0.693147180559945286;
275   //static const nl_double c3   = 0.166666666666666667;
273   static const double ln2r = 1.442695040888963387;
274   static const double ln2  = 0.693147180559945286;
275   //static const double c3   = 0.166666666666666667;
276276
277   const nl_double y = x * ln2r;
277   const double y = x * ln2r;
278278   const unsigned int t = y;
279   const nl_double z = (x - ln2 * (double) t);
280   const nl_double zz = z * z;
281   //const nl_double zzz = zz * z;
279   const double z = (x - ln2 * (double) t);
280   const double zz = z * z;
281   //const double zzz = zz * z;
282282
283283   return (double)(1 << t)*(1.0 + z + 0.5 * zz); // + c3*zzz;
284284}
285285
286inline nl_double fastexp(const nl_double x)
286inline double fastexp(const double x)
287287{
288288   if (x<0)
289289      return 1.0 / fastexp_h(-x);
trunk/src/emu/netlist/devices/nld_4020.c
r242982r242983
125125   register_subalias("7", sub.m_Q[3]);
126126   register_subalias("8", m_supply.m_vss);
127127
128   register_subalias("9", sub.m_Q[0]);
128   register_subalias("9", sub.m_Q[1]);
129129   register_subalias("10", sub.m_IP);
130130   register_subalias("11", m_RESET);
131131   register_subalias("12", sub.m_Q[8]);
trunk/src/emu/netlist/devices/nld_4066.c
r242982r242983
1919
2020NETLIB_UPDATE(4066)
2121{
22   nl_double sup = (m_supply.get()->vdd() - m_supply.get()->vss());
23   nl_double low = 0.45 * sup;
24   nl_double high = 0.55 * sup;
25   nl_double in = INPANALOG(m_control) - m_supply.get()->vss();
26   nl_double rON = 270.0 * 5.0 / sup;
22   double sup = (m_supply.get()->vdd() - m_supply.get()->vss());
23   double low = 0.45 * sup;
24   double high = 0.55 * sup;
25   double in = INPANALOG(m_control) - m_supply.get()->vss();
26   double rON = 270.0 * 5.0 / sup;
2727
2828   if (in < low)
2929   {
r242982r242983
5353   register_subalias("4", m_B.m_R.m_N);
5454   register_subalias("5", m_B.m_control);
5555   register_subalias("6", m_C.m_control);
56   register_subalias("7", m_supply.m_vss);
56   register_input("7", m_supply.m_vss);
5757
5858   register_subalias("8", m_C.m_R.m_P);
5959   register_subalias("9", m_C.m_R.m_N);
r242982r242983
6161   register_subalias("11", m_D.m_R.m_N);
6262   register_subalias("12", m_D.m_control);
6363   register_subalias("13", m_A.m_control);
64   register_subalias("14", m_supply.m_vdd);
64   register_input("14", m_supply.m_vdd);
6565
6666}
6767
trunk/src/emu/netlist/devices/nld_74123.c
r242982r242983
6969
7070   if (m_state == 1)
7171   {
72      const nl_double vLow = m_KP * TERMANALOG(m_RP.m_P);
72      const double vLow = m_KP * TERMANALOG(m_RP.m_P);
7373      if (INPANALOG(m_CV) < vLow)
7474      {
7575         m_RN.set_R(R_OFF);
r242982r242983
7878   }
7979   else if (m_state == 2)
8080   {
81      const nl_double vHigh = TERMANALOG(m_RP.m_P) * (1.0 - m_KP);
81      const double vHigh = TERMANALOG(m_RP.m_P) * (1.0 - m_KP);
8282      if (INPANALOG(m_CV) > vHigh)
8383      {
8484         m_RP.set_R(R_OFF);
trunk/src/emu/netlist/devices/nld_74ls629.c
r242982r242983
104104{
105105   {
106106      // recompute
107      nl_double  freq;
108      nl_double  v_freq_2, v_freq_3, v_freq_4;
109      nl_double  v_freq = INPANALOG(m_FC);
110      nl_double  v_rng = INPANALOG(m_RNG);
107      double  freq;
108      double  v_freq_2, v_freq_3, v_freq_4;
109      double  v_freq = INPANALOG(m_FC);
110      double  v_rng = INPANALOG(m_RNG);
111111
112112      /* coefficients */
113      const nl_double k1 = 1.9904769024796283E+03;
114      const nl_double k2 = 1.2070059213983407E+03;
115      const nl_double k3 = 1.3266985579561108E+03;
116      const nl_double k4 = -1.5500979825922698E+02;
117      const nl_double k5 = 2.8184536266938172E+00;
118      const nl_double k6 = -2.3503421582744556E+02;
119      const nl_double k7 = -3.3836786704527788E+02;
120      const nl_double k8 = -1.3569136703258670E+02;
121      const nl_double k9 = 2.9914575453819188E+00;
122      const nl_double k10 = 1.6855569086173170E+00;
113      const double k1 = 1.9904769024796283E+03;
114      const double k2 = 1.2070059213983407E+03;
115      const double k3 = 1.3266985579561108E+03;
116      const double k4 = -1.5500979825922698E+02;
117      const double k5 = 2.8184536266938172E+00;
118      const double k6 = -2.3503421582744556E+02;
119      const double k7 = -3.3836786704527788E+02;
120      const double k8 = -1.3569136703258670E+02;
121      const double k9 = 2.9914575453819188E+00;
122      const double k10 = 1.6855569086173170E+00;
123123
124124      /* scale due to input resistance */
125125
trunk/src/emu/netlist/devices/nld_cmos.h
r242982r242983
2929      ATTR_HOT void reset()  {};
3030
3131public:
32   ATTR_HOT inline nl_double vdd() { return INPANALOG(m_vdd); }
33   ATTR_HOT inline nl_double vss() { return INPANALOG(m_vss); }
32   ATTR_HOT inline double vdd() { return INPANALOG(m_vdd); }
33   ATTR_HOT inline double vss() { return INPANALOG(m_vss); }
3434};
3535
3636#endif /* NLD_CMOS_H_ */
trunk/src/emu/netlist/devices/nld_ne555.c
r242982r242983
1010#define R_OFF (1E20)
1111#define R_ON (25)   // Datasheet states a maximum discharge of 200mA, R = 5V / 0.2
1212
13inline nl_double NETLIB_NAME(NE555)::clamp(const nl_double v, const nl_double a, const nl_double b)
13inline double NETLIB_NAME(NE555)::clamp(const double v, const double a, const double b)
1414{
15   nl_double ret = v;
16   nl_double vcc = TERMANALOG(m_R1.m_P);
15   double ret = v;
16   double vcc = TERMANALOG(m_R1.m_P);
1717
1818   if (ret >  vcc - a)
1919      ret = vcc - a;
r242982r242983
6464{
6565   // FIXME: assumes GND is connected to 0V.
6666
67   nl_double vt = clamp(TERMANALOG(m_R2.m_P), 0.7, 1.4);
67   double vt = clamp(TERMANALOG(m_R2.m_P), 0.7, 1.4);
6868   bool bthresh = (INPANALOG(m_THRES) > vt);
6969   bool btrig = (INPANALOG(m_TRIG) > clamp(TERMANALOG(m_R2.m_N), 0.7, 1.4));
7070   bool out = m_last_out;
trunk/src/emu/netlist/devices/nld_ne555.h
r242982r242983
3939
4040   netlist_state_t<bool> m_last_out;
4141
42   inline nl_double clamp(const nl_double v, const nl_double a, const nl_double b);
42   inline double clamp(const double v, const double a, const double b);
4343
4444);
4545
trunk/src/emu/netlist/devices/nld_r2r_dac.c
r242982r242983
3232
3333   update_dev();
3434
35   nl_double V = m_VIN.Value() / (double) (1 << m_num.Value()) * (double) m_val.Value();
35   double V = m_VIN.Value() / (double) (1 << m_num.Value()) * (double) m_val.Value();
3636
3737   this->set(1.0 / m_R.Value(), V, 0.0);
3838}
trunk/src/emu/netlist/devices/nld_system.c
r242982r242983
118118   if (state != m_last_state)
119119   {
120120      m_last_state = state;
121      const nl_double R = state ? m_logic_family->m_R_high : m_logic_family->m_R_low;
122      const nl_double V = state ? m_logic_family->m_high_V : m_logic_family->m_low_V;
121      const double R = state ? m_logic_family->m_R_high : m_logic_family->m_R_low;
122      const double V = state ? m_logic_family->m_high_V : m_logic_family->m_low_V;
123123
124124      // We only need to update the net first if this is a time stepping net
125125      if (m_RV.m_P.net().as_analog().solver()->is_timestep())
trunk/src/emu/netlist/nl_base.c
r242982r242983
170170   netlist_object_t::save_register();
171171}
172172
173ATTR_HOT const nl_double netlist_base_t::gmin() const
173ATTR_HOT const double netlist_base_t::gmin() const
174174{
175175   return solver()->gmin();
176176}
r242982r242983
452452}
453453
454454template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_double_t &param, const double initialVal);
455template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_double_t &param, const float initialVal);
456455template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_int_t &param, const int initialVal);
457456template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_logic_t &param, const int initialVal);
458457template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_str_t &param, const char * const initialVal);
r242982r242983
875874   net().as_analog().m_cur_Analog = 0.98;
876875}
877876
878ATTR_COLD void netlist_analog_output_t::initial(const nl_double val)
877ATTR_COLD void netlist_analog_output_t::initial(const double val)
879878{
880879   net().as_analog().m_cur_Analog = val * 0.99;
881880}
r242982r242983
932931}
933932
934933
935ATTR_COLD nl_double netlist_param_model_t::model_value(const pstring &entity, const nl_double defval) const
934ATTR_COLD double netlist_param_model_t::model_value(const pstring &entity, const double defval) const
936935{
937936   pstring tmp = this->Value();
938937   // .model 1N914 D(Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon)
r242982r242983
946945      if (pequal < 0)
947946         netlist().error("parameter %s misformat in model %s temp %s\n", entity.cstr(), Value().cstr(), tmp.cstr());
948947      tmp = tmp.substr(pequal+1);
949      nl_double factor = 1.0;
948      double factor = 1.0;
950949      switch (*(tmp.right(1).cstr()))
951950      {
952951         case 'm': factor = 1e-3; break;
r242982r242983
10021001   net.set_time(netlist().time() + m_inc);
10031002}
10041003
1004// ----------------------------------------------------------------------------------------
1005// net_device_t_base_factory
1006// ----------------------------------------------------------------------------------------
1007
1008ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::term_param_list()
1009{
1010   if (m_def_param.startsWith("+"))
1011      return nl_util::split(m_def_param.substr(1), ",");
1012   else
1013      return nl_util::pstring_list();
1014}
1015
1016ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::def_params()
1017{
1018   if (m_def_param.startsWith("+") || m_def_param.equals("-"))
1019      return nl_util::pstring_list();
1020   else
1021      return nl_util::split(m_def_param, ",");
1022}
trunk/src/emu/netlist/nl_base.h
r242982r242983
272272
273273struct netlist_logic_family_desc_t
274274{
275   nl_double m_low_thresh_V;
276   nl_double m_high_thresh_V;
277   nl_double m_low_V;
278   nl_double m_high_V;
279   nl_double m_R_low;
280   nl_double m_R_high;
275   double m_low_thresh_V;
276   double m_high_thresh_V;
277   double m_low_V;
278   double m_high_V;
279   double m_R_low;
280   double m_R_high;
281281};
282282
283283/* Terminals inherit the family description from the netlist_device
r242982r242983
474474
475475   ATTR_COLD netlist_terminal_t();
476476
477   nl_double *m_Idr1; // drive current
478   nl_double *m_go1;  // conductance for Voltage from other term
479   nl_double *m_gt1;  // conductance for total conductance
477   double *m_Idr1; // drive current
478   double *m_go1;  // conductance for Voltage from other term
479   double *m_gt1;  // conductance for total conductance
480480
481   ATTR_HOT inline void set(const nl_double G)
481   ATTR_HOT inline void set(const double G)
482482   {
483483      set_ptr(m_Idr1, 0);
484484      set_ptr(m_go1, G);
485485      set_ptr(m_gt1, G);
486486   }
487487
488   ATTR_HOT inline void set(const nl_double GO, const nl_double GT)
488   ATTR_HOT inline void set(const double GO, const double GT)
489489   {
490490      set_ptr(m_Idr1, 0);
491491      set_ptr(m_go1, GO);
492492      set_ptr(m_gt1, GT);
493493   }
494494
495   ATTR_HOT inline void set(const nl_double GO, const nl_double GT, const nl_double I)
495   ATTR_HOT inline void set(const double GO, const double GT, const double I)
496496   {
497497      set_ptr(m_Idr1, I);
498498      set_ptr(m_go1, GO);
r242982r242983
509509
510510   ATTR_COLD virtual void reset();
511511private:
512   inline void set_ptr(nl_double *ptr, const nl_double val)
512   inline void set_ptr(double *ptr, const double val)
513513   {
514514      if (ptr != NULL)
515515         *ptr = val;
r242982r242983
586586   ATTR_COLD netlist_analog_input_t()
587587      : netlist_input_t(INPUT, ANALOG) { }
588588
589   ATTR_HOT inline const nl_double Q_Analog() const;
589   ATTR_HOT inline const double Q_Analog() const;
590590};
591591
592592//#define INPVAL(_x) (_x).Q()
r242982r242983
661661   // We have to have those on one object. Dividing those does lead
662662   // to a significant performance hit
663663   // FIXME: Have to fix the public at some time
664   nl_double m_cur_Analog;
664   double m_cur_Analog;
665665
666666};
667667
r242982r242983
736736   ATTR_COLD netlist_analog_net_t();
737737   ATTR_COLD virtual ~netlist_analog_net_t() { };
738738
739   ATTR_HOT inline const nl_double Q_Analog() const
739   ATTR_HOT inline const double Q_Analog() const
740740   {
741741      //nl_assert(object_type(SIGNAL_MASK) == SIGNAL_ANALOG);
742742      nl_assert(family() == ANALOG);
743743      return m_cur_Analog;
744744   }
745745
746   ATTR_COLD inline nl_double &Q_Analog_state_ptr()
746   ATTR_COLD inline double &Q_Analog_state_ptr()
747747   {
748748      //nl_assert(object_type(SIGNAL_MASK) == SIGNAL_ANALOG);
749749      nl_assert(family() == ANALOG);
r242982r242983
764764private:
765765
766766public:
767   nl_double m_DD_n_m_1;
768   nl_double m_h_n_m_1;
767   double m_DD_n_m_1;
768   double m_h_n_m_1;
769769
770770   //FIXME: needed by current solver code
771771   netlist_matrix_solver_t *m_solver;
r242982r242983
831831
832832   ATTR_COLD netlist_analog_output_t();
833833
834   ATTR_COLD void initial(const nl_double val);
834   ATTR_COLD void initial(const double val);
835835
836   ATTR_HOT inline void set_Q(const nl_double newQ);
836   ATTR_HOT inline void set_Q(const double newQ);
837837
838838   netlist_analog_net_t *m_proxied_net; // only for proxy nets in analog input logic
839839
r242982r242983
876876public:
877877   ATTR_COLD netlist_param_double_t();
878878
879   ATTR_HOT inline void setTo(const nl_double param);
880   ATTR_COLD inline void initial(const nl_double val) { m_param = val; }
881   ATTR_HOT inline const nl_double Value() const        { return m_param;   }
879   ATTR_HOT inline void setTo(const double param);
880   ATTR_COLD inline void initial(const double val) { m_param = val; }
881   ATTR_HOT inline const double Value() const        { return m_param;   }
882882
883883protected:
884884   ATTR_COLD virtual void save_register()
r242982r242983
888888   }
889889
890890private:
891   nl_double m_param;
891   double m_param;
892892};
893893
894894class netlist_param_int_t : public netlist_param_t
r242982r242983
946946   ATTR_HOT inline const pstring &Value() const     { return m_param;     }
947947
948948   /* these should be cached! */
949   ATTR_COLD nl_double model_value(const pstring &entity, const nl_double defval = 0.0) const;
949   ATTR_COLD double model_value(const pstring &entity, const double defval = 0.0) const;
950950   ATTR_COLD const pstring model_type() const;
951951
952952private:
r242982r242983
997997      out.set_Q(val, delay);
998998   }
999999
1000   ATTR_HOT inline const nl_double INPANALOG(const netlist_analog_input_t &inp) const { return inp.Q_Analog(); }
1000   ATTR_HOT inline const double INPANALOG(const netlist_analog_input_t &inp) const { return inp.Q_Analog(); }
10011001
1002   ATTR_HOT inline const nl_double TERMANALOG(const netlist_terminal_t &term) const { return term.net().as_analog().Q_Analog(); }
1002   ATTR_HOT inline const double TERMANALOG(const netlist_terminal_t &term) const { return term.net().as_analog().Q_Analog(); }
10031003
1004   ATTR_HOT inline void OUTANALOG(netlist_analog_output_t &out, const nl_double val)
1004   ATTR_HOT inline void OUTANALOG(netlist_analog_output_t &out, const double val)
10051005   {
10061006      out.set_Q(val);
10071007   }
r242982r242983
10101010
10111011   ATTR_HOT virtual void dec_active() {  }
10121012
1013   ATTR_HOT virtual void step_time(const nl_double st) { }
1013   ATTR_HOT virtual void step_time(const double st) { }
10141014   ATTR_HOT virtual void update_terminals() { }
10151015
10161016
r242982r242983
11201120   ATTR_HOT inline const netlist_time time() const { return m_time; }
11211121   ATTR_HOT inline NETLIB_NAME(solver) *solver() const { return m_solver; }
11221122   ATTR_HOT inline NETLIB_NAME(gnd) *gnd() const { return m_gnd; }
1123   ATTR_HOT const nl_double gmin() const;
1123   ATTR_HOT const double gmin() const;
11241124
11251125   ATTR_HOT inline void push_to_queue(netlist_net_t *out, const netlist_time attime)
11261126   {
r242982r242983
12511251   }
12521252}
12531253
1254ATTR_HOT inline void netlist_param_double_t::setTo(const nl_double param)
1254ATTR_HOT inline void netlist_param_double_t::setTo(const double param)
12551255{
12561256   if (m_param != param)
12571257   {
r242982r242983
13561356   return net().as_logic().Q();
13571357}
13581358
1359ATTR_HOT inline const nl_double netlist_analog_input_t::Q_Analog() const
1359ATTR_HOT inline const double netlist_analog_input_t::Q_Analog() const
13601360{
13611361   return net().as_analog().Q_Analog();
13621362}
13631363
1364ATTR_HOT inline void netlist_analog_output_t::set_Q(const nl_double newQ)
1364ATTR_HOT inline void netlist_analog_output_t::set_Q(const double newQ)
13651365{
13661366   if (newQ != net().as_analog().m_cur_Analog)
13671367   {
trunk/src/emu/netlist/nl_config.h
r242982r242983
4949
5050#define NETLIST_GMIN_DEFAULT    (1e-9)
5151
52//typedef double   nl_double;
53
54#define nl_double double
55
5652//============================================================
5753//  DEBUGGING
5854//============================================================
r242982r242983
159155#else
160156#define nl_assert(x)               do { } while (0)
161157//#define assert_always(x, msg)   do { if (!(x)) throw emu_fatalerror("Fatal error: %s (%s:%d)", msg, __FILE__, __LINE__); } while (0)
162#define nl_assert_always(x, msg)    do { if (!(x)) throw nl_fatalerror("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0)
158#define nl_assert_always(x, msg)   do { } while (0)
163159#endif
164160
165161//============================================================
trunk/src/emu/netlist/nl_dice_compat.h
r242982r242983
88#ifndef NL_DICE_COMPAT_H_
99#define NL_DICE_COMPAT_H_
1010
11#include "netlist/devices/net_lib.h"
12
1311/* --------------------------------------------------------------------
1412 * Compatibility macros for DICE netlists ...
1513 * -------------------------------------------------------------------- */
1614
17/*
18 * define NETLIST_DEVELOPMENT in IDEs before including this header file
19 * to get compile time errors on unknown devices. This should only be
20 * a temporary support and not be used in commits.
21 */
22
23#ifdef NETLIST_DEVELOPMENT
15//#define CHIP(_n, _t) netlist.register_dev(NET_NEW(_t ## _dip), _n);
2416#define CHIP(_n, _t) setup.register_dev( nl_alloc(nld_ ## _t ## _dip), _n);
25#else
26#define CHIP(_n, _t) setup.register_dev(NETLIB_NAME_STR(_t ## _dip), _n);
27#endif
2817
2918#define CONNECTION( ... ) CONNECTIONY( CONNECTIONX( __VA_ARGS__ ) )
3019#define CONNECTIONY(_a) _a
r242982r242983
4130struct Mono555Desc
4231{
4332public:
44      nl_double r, c;
33      double r, c;
4534
46      Mono555Desc(nl_double res, nl_double cap) : r(res), c(cap) { }
35      Mono555Desc(double res, double cap) : r(res), c(cap) { }
4736};
4837
4938struct SeriesRCDesc
5039{
5140public:
52      nl_double r, c;
41      double r, c;
5342
54      SeriesRCDesc(nl_double res, nl_double cap) : r(res), c(cap) { }
43      SeriesRCDesc(double res, double cap) : r(res), c(cap) { }
5544};
5645
5746#define CHIP_555_Mono(_name,  _pdesc)   \
trunk/src/emu/netlist/nl_factory.c
r242982r242983
5050#include "nl_factory.h"
5151#include "nl_setup.h"
5252
53// ----------------------------------------------------------------------------------------
54// net_device_t_base_factory
55// ----------------------------------------------------------------------------------------
56
57ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::term_param_list()
58{
59    if (m_def_param.startsWith("+"))
60        return nl_util::split(m_def_param.substr(1), ",");
61    else
62        return nl_util::pstring_list();
63}
64
65ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::def_params()
66{
67    if (m_def_param.startsWith("+") || m_def_param.equals("-"))
68        return nl_util::pstring_list();
69    else
70        return nl_util::split(m_def_param, ",");
71}
72
73
7453netlist_factory_t::netlist_factory_t()
7554{
7655}
r242982r242983
8564   m_list.clear();
8665}
8766
88netlist_device_t *netlist_factory_t::new_device_by_classname(const pstring &classname) const
67netlist_device_t *netlist_factory_t::new_device_by_classname(const pstring &classname, netlist_setup_t &setup) const
8968{
9069   for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e))
9170   {
r242982r242983
9776      }
9877      p++;
9978   }
79   setup.netlist().error("Class %s not found!\n", classname.cstr());
10080   return NULL; // appease code analysis
10181}
10282
trunk/src/emu/netlist/nl_factory.h
r242982r242983
8080      m_list.add(nl_alloc(net_device_t_factory< _C >, name, classname, def_param));
8181   }
8282
83   ATTR_COLD netlist_device_t *new_device_by_classname(const pstring &classname) const;
83   ATTR_COLD netlist_device_t *new_device_by_classname(const pstring &classname, netlist_setup_t &setup) const;
8484   ATTR_COLD netlist_device_t *new_device_by_name(const pstring &name, netlist_setup_t &setup) const;
8585   ATTR_COLD net_device_t_base_factory * factory_by_name(const pstring &name, netlist_setup_t &setup) const;
8686
trunk/src/emu/netlist/nl_parser.c
r242982r242983
66 */
77
88#include "nl_parser.h"
9#include "nl_factory.h"
109
1110//#undef NL_VERBOSE_OUT
1211//#define NL_VERBOSE_OUT(x) printf x
r242982r242983
400399void netlist_parser::netdev_param()
401400{
402401   pstring param;
403   nl_double val;
402   double val;
404403   param = get_identifier();
405404   require_token(m_tok_comma);
406405   val = eval_param(get_token());
r242982r242983
440439      }
441440      else
442441      {
443         nl_double val = eval_param(tok);
442         double val = eval_param(tok);
444443         m_setup.register_param(paramfq, val);
445444      }
446445      cnt++;
r242982r242983
468467// ----------------------------------------------------------------------------------------
469468
470469
471nl_double netlist_parser::eval_param(const token_t tok)
470double netlist_parser::eval_param(const token_t tok)
472471{
473472   static const char *macs[6] = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"};
474   static nl_double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
473   static double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
475474   int i;
476475   int f=0;
477476   bool e;
478   nl_double ret;
477   double ret;
479478   pstring val;
480479
481480   //printf("param %s\n", tok.m_token.cstr());
trunk/src/emu/netlist/nl_parser.h
r242982r242983
160160   virtual void verror(pstring msg, int line_num, pstring line);
161161private:
162162
163   nl_double eval_param(const token_t tok);
163   double eval_param(const token_t tok);
164164
165165   token_id_t m_tok_param_left;
166166   token_id_t m_tok_param_right;
trunk/src/emu/netlist/nl_setup.c
r242982r242983
99#include "nl_setup.h"
1010#include "nl_parser.h"
1111#include "nl_util.h"
12#include "nl_factory.h"
1312#include "devices/net_lib.h"
1413#include "devices/nld_system.h"
1514#include "analog/nld_solver.h"
r242982r242983
3837   , m_proxy_cnt(0)
3938{
4039   netlist.set_setup(this);
41   m_factory = nl_alloc(netlist_factory_t);
4240}
4341
4442void netlist_setup_t::init()
r242982r242983
5755   m_params_temp.clear();
5856
5957   netlist().set_setup(NULL);
60   nl_free(m_factory);
6158
6259   pstring::resetmem();
6360}
r242982r242983
9592   return dev;
9693}
9794
98netlist_device_t *netlist_setup_t::register_dev(const pstring &classname, const pstring &name)
99{
100    netlist_device_t *dev = factory().new_device_by_classname(classname);
101    if (dev == NULL)
102        netlist().error("Class %s not found!\n", classname.cstr());
103    return register_dev(dev, name);
104}
105
10695template <class T>
10796static void remove_start_with(T &hm, pstring &sw)
10897{
r242982r242983
706695      {
707696         NL_VERBOSE_OUT(("%d: <%s>\n",i, ll[i].cstr()));
708697         NL_VERBOSE_OUT(("%d: <%s>\n",i, ll[i].cstr()));
709         netlist_device_t *nc = factory().new_device_by_classname("nld_log");
698         netlist_device_t *nc = factory().new_device_by_classname("nld_log", *this);
710699         pstring name = "log_" + ll[i];
711700         register_dev(nc, name);
712701         register_link(name + ".I", ll[i]);
trunk/src/emu/netlist/nl_setup.h
r242982r242983
33/*
44 * nlsetup.h
55 *
6 *  Created on: 3 Nov 2013
7 *      Author: andre
68 */
79
810#ifndef NLSETUP_H_
911#define NLSETUP_H_
1012
1113#include "nl_base.h"
12//#include "nl_factory.h"
14#include "nl_factory.h"
1315
1416//============================================================
1517//  MACROS / inline netlist definitions
r242982r242983
2325#define ALIAS(_alias, _name)                                                        \
2426   setup.register_alias(# _alias, # _name);
2527
26//#define NET_NEW(_type)  setup.factory().new_device_by_classname(NETLIB_NAME_STR(_type), setup)
28#define NET_NEW(_type)  setup.factory().new_device_by_classname(NETLIB_NAME_STR(_type), setup)
2729
2830#define NET_REGISTER_DEV(_type, _name)                                              \
29      setup.register_dev(NETLIB_NAME_STR(_type), # _name);
31      setup.register_dev(NET_NEW(_type), # _name);
3032
3133#define NET_REMOVE_DEV(_name)                                                       \
3234      setup.remove_dev(# _name);
r242982r242983
6567      setup.namespace_pop();
6668
6769// ----------------------------------------------------------------------------------------
70// FIXME: Clean this up
71// ----------------------------------------------------------------------------------------
72
73//class NETLIB_NAME(analog_callback);
74
75// ----------------------------------------------------------------------------------------
6876// netlist_setup_t
6977// ----------------------------------------------------------------------------------------
7078
71// Forward definition so we keep nl_factory.h out of the public
72class netlist_factory_t;
73
7479class netlist_setup_t
7580{
7681   NETLIST_PREVENT_COPYING(netlist_setup_t)
r242982r242983
113118
114119   netlist_base_t &netlist() { return m_netlist; }
115120   const netlist_base_t &netlist() const { return m_netlist; }
121   netlist_factory_t &factory() { return m_factory; }
122   const netlist_factory_t &factory() const { return m_factory; }
116123
117124   pstring build_fqn(const pstring &obj_name) const;
118125
119126   netlist_device_t *register_dev(netlist_device_t *dev, const pstring &name);
120   netlist_device_t *register_dev(const pstring &classname, const pstring &name);
121127   void remove_dev(const pstring &name);
122128
123129   void register_model(const pstring &model);
r242982r242983
146152   void namespace_push(const pstring &aname);
147153   void namespace_pop();
148154
149    netlist_factory_t &factory() { return *m_factory; }
150    const netlist_factory_t &factory() const { return *m_factory; }
155   /* not ideal, but needed for save_state */
156   tagmap_terminal_t  m_terminals;
151157
152    /* not ideal, but needed for save_state */
153    tagmap_terminal_t  m_terminals;
158   void print_stats() const;
154159
155    void print_stats() const;
156
157160protected:
158161
159162private:
r242982r242983
165168   tagmap_link_t   m_links;
166169   tagmap_nstring_t m_params_temp;
167170
168   netlist_factory_t *m_factory;
171   netlist_factory_t m_factory;
169172
170173   plinearlist_t<pstring> m_models;
171174
trunk/src/emu/netlist/pstate.c
r242982r242983
2323         "DT_INT16",
2424         "DT_INT8",
2525         "DT_INT",
26         "DT_BOOLEAN",
27            "DT_FLOAT"
26         "DT_BOOLEAN"
2827   };
2928
3029   NL_VERBOSE_OUT(("SAVE: <%s> %s(%d) %p\n", fullname.cstr(), ts[dt].cstr(), size, ptr));
trunk/src/emu/netlist/pstate.h
r242982r242983
3232   DT_INT16,
3333   DT_INT8,
3434   DT_INT,
35   DT_BOOLEAN,
36   DT_FLOAT
35   DT_BOOLEAN
3736};
3837
3938template<typename _ItemType> struct nl_datatype
r242982r242983
5655
5756NETLIST_SAVE_TYPE(char, DT_INT8);
5857NETLIST_SAVE_TYPE(double, DT_DOUBLE);
59NETLIST_SAVE_TYPE(float, DT_FLOAT);
6058NETLIST_SAVE_TYPE(INT8, DT_INT8);
6159NETLIST_SAVE_TYPE(UINT8, DT_INT8);
6260NETLIST_SAVE_TYPE(INT64, DT_INT64);
trunk/src/emu/netlist/pstring.c
r242982r242983
108108   return 1;
109109}
110110
111nl_double pstring::as_double(bool *error) const
111double pstring::as_double(bool *error) const
112112{
113   nl_double ret;
113   double ret;
114114   char *e = NULL;
115115
116116   if (error != NULL)
r242982r242983
124124
125125long pstring::as_long(bool *error) const
126126{
127   nl_double ret;
127   double ret;
128128   char *e = NULL;
129129
130130   if (error != NULL)
trunk/src/emu/netlist/pstring.h
r242982r242983
159159
160160   // conversions
161161
162   nl_double as_double(bool *error = NULL) const;
162   double as_double(bool *error = NULL) const;
163163
164164   long as_long(bool *error = NULL) const;
165165
trunk/src/mame/drivers/nl_pongd.c
r242982r242983
6565 *
6666 */
6767
68// identify unknown devices in IDE
6968
70//#define NETLIST_DEVELOPMENT 1
71
7269#include "netlist/nl_dice_compat.h"
7370#include "netlist/devices/net_lib.h"
7471#include "netlist/analog/nld_twoterm.h"
trunk/src/tools/nltool.c
r242982r242983
1818#include "netlist/nl_base.h"
1919#include "netlist/nl_setup.h"
2020#include "netlist/nl_parser.h"
21#include "netlist/nl_factory.h"
2221#include "netlist/nl_util.h"
23#include "netlist/devices/net_lib.h"
2422#include "options.h"
2523
2624/***************************************************************************
27 * MAME COMPATIBILITY ...
28 *
29 * These are needed if we link without libutil
30 ***************************************************************************/
25    MAME COMPATIBILITY ...
26***************************************************************************/
3127
3228#if 0
3329void ATTR_PRINTF(1,2) osd_printf_warning(const char *format, ...)
r242982r242983
3935   vprintf(format, argptr);
4036   va_end(argptr);
4137}
38#endif
4239
4340void *malloc_file_line(size_t size, const char *file, int line)
4441{
r242982r242983
7572         src_type.name(), dst_type.name());
7673   throw;
7774}
78#endif
7975
8076struct options_entry oplist[] =
8177{
r242982r242983
8783   { NULL }
8884};
8985
90NETLIST_START(dummy)
91    /* Standard stuff */
92
93    CLOCK(clk, 1000) // 1000 Hz
94    SOLVER(Solver, 48000)
95
96NETLIST_END()
97
9886/***************************************************************************
9987    CORE IMPLEMENTATION
10088***************************************************************************/
r242982r242983
172160      nl_util::pstring_list ll = nl_util::split(m_logs, ":");
173161      for (int i=0; i < ll.count(); i++)
174162      {
175            pstring name = "log_" + ll[i];
176         netlist_device_t *nc = m_setup->register_dev("nld_log", name);
163         netlist_device_t *nc = m_setup->factory().new_device_by_classname("nld_log", *m_setup);
164         pstring name = "log_" + ll[i];
165         m_setup->register_dev(nc, name);
177166         m_setup->register_link(name + ".I", ll[i]);
178167      }
179168   }
r242982r242983
241230   nt.init();
242231   const netlist_factory_t::list_t &list = nt.setup().factory().list();
243232
244    netlist_sources_t sources;
245
246    sources.add(netlist_source_t("dummy", &netlist_dummy));
247    sources.parse(nt.setup(),"dummy");
248
249233   nt.setup().start_devices();
250234   nt.setup().resolve_inputs();
251235


Previous 199869 Revisions Next


© 1997-2024 The MAME Team