Previous 199869 Revisions Next

r26800 Sunday 29th December, 2013 at 01:27:49 UTC by Couriersud
Further untangled nl_base.[hc] and mame-specific netlist.c. No wn
[src/emu/machine]netlist.c netlist.h
[src/emu/netlist]nl_base.c nl_base.h nl_config.h nl_time.h
[src/mame/drivers]pong.c
[src/tools]nltool.c

trunk/src/mame/drivers/pong.c
r26799r26800
901901static MACHINE_CONFIG_START( pong, pong_state )
902902
903903   /* basic machine hardware */
904   MCFG_NETLIST_ADD("maincpu", pong)
904   MCFG_NETLIST_ADD("maincpu", pong, MASTER_CLOCK * 2)
905905    MCFG_NETLIST_ANALOG_INPUT("maincpu", "vr0", "ic_b9_R.R")
906906    MCFG_NETLIST_ANALOG_INPUT_MULT_OFFSET(1.0 / 100.0 * RES_K(50), RES_K(56) )
907907    MCFG_NETLIST_ANALOG_INPUT("maincpu", "vr1", "ic_a9_R.R")
trunk/src/tools/nltool.c
r26799r26800
116116        this->init_object(*this, "netlist");
117117        m_setup->init();
118118
119        this->set_clock_freq(NETLIST_CLOCK);
120
121119      // read the netlist ...
122120      //m_setup_func(*m_setup);
123121
r26799r26800
183181   nt.read_netlist(filetobuf(opts.value("f")));
184182   double ttr = opts.float_value("ttr");
185183
186   INT64 tt = ttr * NETLIST_CLOCK;
187
188184   printf("startup time ==> %5.3f\n", (double) (osd_ticks() - t) / (double) osd_ticks_per_second() );
189185   printf("runnning ...\n");
190186   t = osd_ticks();
191   while (tt>0)
192   {
193      INT32 tr = MIN(tt, NETLIST_CLOCK / 10);
194      tt -= tr;
195      nt.process_queue(tr);
196   }
187
188   nt.process_queue(netlist_time::from_double(ttr));
189
197190   double emutime = (double) (osd_ticks() - t) / (double) osd_ticks_per_second();
198191   printf("%f seconds emulation took %f real time ==> %5.2f%%\n", ttr, emutime, ttr/emutime*100.0);
199192
trunk/src/emu/machine/netlist.c
r26799r26800
140140
141141netlist_mame_device_t::netlist_mame_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
142142   : device_t(mconfig, NETLIST_CORE, "Netlist core device", tag, owner, clock, "netlist_core", __FILE__),
143       m_icount(0),
144        m_div(0),
145        m_rem(0),
146        m_old(netlist_time::zero),
143147        m_netlist(NULL),
144148        m_setup(NULL),
145149        m_setup_func(NULL)
r26799r26800
148152
149153netlist_mame_device_t::netlist_mame_device_t(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *file)
150154    : device_t(mconfig, type, name, tag, owner, clock, shortname, file),
155        m_icount(0),
156        m_div(0),
157        m_rem(0),
158        m_old(netlist_time::zero),
151159        m_netlist(NULL),
152160        m_setup(NULL),
153161        m_setup_func(NULL)
r26799r26800
170178{
171179   LOG_DEV_CALLS(("device_start %s\n", tag()));
172180
181   printf("clock is %d\n", clock());
182
173183   m_netlist = global_alloc_clear(netlist_mame_t(*this));
174184   m_setup = global_alloc_clear(netlist_setup_t(*m_netlist));
175185   netlist().init_object(*m_netlist, "netlist");
176186   m_setup->init();
177187
178   netlist().set_clock_freq(this->clock());
179
180188   // register additional devices
181189
182190   m_setup->factory().register_device<nld_analog_callback>( "NETDEV_CALLBACK", "nld_analog_callback");
r26799r26800
197205   m_setup->start_devices();
198206   m_setup->resolve_inputs();
199207
208    netlist().save(NAME(m_rem));
209    netlist().save(NAME(m_div));
210    netlist().save(NAME(m_old));
211
200212   save_state();
201213
214    m_old = netlist_time::zero;
215    m_rem = 0;
216
202217}
203218
219void netlist_mame_device_t::device_clock_changed()
220{
221    //printf("device_clock_changed\n");
222    m_div = netlist_time::from_hz(clock()).as_raw();
223    //m_rem = 0;
224    NL_VERBOSE_OUT(("Setting clock %" I64FMT "d and divisor %d\n", clockfreq, m_div));
225    //printf("Setting clock %d and divisor %d\n", clock(), m_div);
226}
227
228
204229void netlist_mame_device_t::device_reset()
205230{
206231   LOG_DEV_CALLS(("device_reset\n"));
232    m_old = netlist_time::zero;
233    m_rem = 0;
207234   netlist().reset();
208235}
209236
r26799r26800
236263{
237264}
238265
266ATTR_HOT ATTR_ALIGN void netlist_mame_device_t::update_time_x()
267{
268    const netlist_time delta = netlist().time() - m_old + netlist_time::from_raw(m_rem);
269    m_old = netlist().time();
270    m_icount -= divu_64x32_rem(delta.as_raw(), m_div, &m_rem);
271}
272
273ATTR_HOT ATTR_ALIGN void netlist_mame_device_t::check_mame_abort_slice()
274{
275    if (m_icount <= 0)
276        netlist().abort_current_queue_slice();
277}
278
239279ATTR_COLD void netlist_mame_device_t::save_state()
240280{
241281   for (pstate_entry_t::list_t::entry_t *p = netlist().save_list().first(); p != NULL; p = netlist().save_list().next(p))
r26799r26800
279319        device_state_interface(mconfig, *this),
280320        device_disasm_interface(mconfig, *this),
281321        device_memory_interface(mconfig, *this),
282        m_program_config("program", ENDIANNESS_LITTLE, 8, 12, 0, ADDRESS_MAP_NAME(program_dummy)),
283        m_icount(0)
322        m_program_config("program", ENDIANNESS_LITTLE, 8, 12, 0, ADDRESS_MAP_NAME(program_dummy))
284323{
285324}
286325
r26799r26800
352391   {
353392      while (m_icount > 0)
354393      {
355         int m_temp = 1;
356394         m_genPC++;
357395         m_genPC &= 255;
358396         debugger_instruction_hook(this, m_genPC);
359         netlist().process_queue(m_temp);
360         m_icount -= (1 - m_temp);
397         netlist().process_queue(netlist_time::from_raw(m_div));
398           update_time_x();
361399      }
362400   }
363401   else
364      netlist().process_queue(m_icount);
402   {
403        netlist().process_queue(netlist_time::from_raw(m_div) * m_icount);
404        update_time_x();
405   }
365406}
trunk/src/emu/machine/netlist.h
r26799r26800
5656
5757// MAME specific configuration
5858
59#define MCFG_NETLIST_ADD(_tag, _setup )                                             \
60   MCFG_DEVICE_ADD(_tag, NETLIST_CPU, NETLIST_CLOCK)                               \
59#define MCFG_NETLIST_ADD(_tag, _setup, _clock )                                     \
60   MCFG_DEVICE_ADD(_tag, NETLIST_CPU, _clock)                                      \
6161   MCFG_NETLIST_SETUP(_setup)
6262
6363#define MCFG_NETLIST_REPLACE(_tag, _setup)                                          \
r26799r26800
148148   ATTR_HOT inline netlist_setup_t &setup() { return *m_setup; }
149149   ATTR_HOT inline netlist_mame_t &netlist() { return *m_netlist; }
150150
151    ATTR_HOT inline netlist_time last_time_update() { return m_old; }
152   ATTR_HOT void update_time_x();
153   ATTR_HOT void check_mame_abort_slice();
154
155    int m_icount;
156
151157protected:
152158   // device_t overrides
153159   virtual void device_config_complete();
r26799r26800
157163   virtual void device_post_load();
158164   virtual void device_pre_save();
159165   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
166    //virtual void device_debug_setup();
167    virtual void device_clock_changed();
160168
169    UINT32              m_div;
170
161171private:
162172    void save_state();
163173
164   netlist_mame_t *m_netlist;
165    netlist_setup_t *m_setup;
174    /* timing support here - so sound can hijack it ... */
175    UINT32              m_rem;
176    netlist_time        m_old;
166177
178   netlist_mame_t *    m_netlist;
179    netlist_setup_t *   m_setup;
180
167181   void (*m_setup_func)(netlist_setup_t &);
168182};
169183
r26799r26800
241255
242256private:
243257
244    int m_icount;
245258    int m_genPC;
246259
247260};
r26799r26800
368381
369382   ATTR_HOT void update()
370383   {
384       m_cpu_device->update_time_x();
371385        m_callback(INPANALOG(m_in), m_cpu_device->local_time());
386        m_cpu_device->check_mame_abort_slice();
372387   }
373388
374389private:
trunk/src/emu/netlist/nl_base.h
r26799r26800
10181018
10191019   ATTR_HOT NETLIB_NAME(solver) *solver() const { return m_solver; }
10201020
1021   ATTR_HOT void process_queue(INT32 &atime);
1021   ATTR_HOT void process_queue(const netlist_time delta);
1022   ATTR_HOT inline void abort_current_queue_slice() { m_stop = netlist_time::zero; }
10221023
10231024   ATTR_HOT inline const netlist_time &time() const { return m_time_ps; }
10241025
r26799r26800
10281029
10291030   ATTR_COLD netlist_net_t *find_net(const pstring &name);
10301031
1031   ATTR_COLD void set_clock_freq(UINT64 clockfreq);
1032
10331032   ATTR_COLD netlist_setup_t &setup() { return *m_setup; }
10341033   ATTR_COLD void reset();
10351034
r26799r26800
10481047   {
10491048      save(NAME(m_queue.callback()));
10501049      save(NAME(m_time_ps));
1051      save(NAME(m_rem));
1052      save(NAME(m_div));
10531050      netlist_object_t::save_register();
10541051   }
10551052
r26799r26800
10611058#endif
10621059
10631060private:
1064   ATTR_HOT void update_time(const netlist_time t, INT32 &atime);
1061   netlist_time                m_stop;     // target time for current queue processing
10651062
10661063   netlist_time                m_time_ps;
10671064   netlist_queue_t             m_queue;
1068   UINT32                      m_rem;
1069   UINT32                      m_div;
10701065
10711066   NETLIB_NAME(mainclock) *    m_mainclock;
10721067   NETLIB_NAME(solver) *       m_solver;
trunk/src/emu/netlist/nl_time.h
r26799r26800
4343
4444   ATTR_HOT inline const netlist_time &operator=(const netlist_time &right) { m_time = right.m_time; return *this; }
4545   ATTR_HOT inline const netlist_time &operator=(const double &right) { m_time = (INTERNALTYPE) ( right * (double) RESOLUTION); return *this; }
46   ATTR_HOT inline operator double() const { return as_double(); }
4746
47   // issues with ISO C++ standard
48   //ATTR_HOT inline operator double() const { return as_double(); }
49
4850   ATTR_HOT inline const netlist_time &operator+=(const netlist_time &right) { m_time += right.m_time; return *this; }
4951
5052   ATTR_HOT inline const INTERNALTYPE as_raw() const { return m_time; }
trunk/src/emu/netlist/nl_config.h
r26799r26800
2929
3030// Use nano-second resolution - Sufficient for now
3131#define NETLIST_INTERNAL_RES        (U64(1000000000))
32#define NETLIST_DIV_BITS            (0)
3332//#define NETLIST_INTERNAL_RES      (U64(1000000000000))
34//#define NETLIST_DIV_BITS          (10)
35#define NETLIST_DIV                 (U64(1) << NETLIST_DIV_BITS)
36#define NETLIST_MASK                (NETLIST_DIV-1)
37#define NETLIST_CLOCK               (NETLIST_INTERNAL_RES / NETLIST_DIV)
3833
39//FIXME: LEGACY
40//#define NETLIST_HIGHIMP_V   (1.23456e20)        /* some voltage we should never see */
34#define NETLIST_CLOCK               (NETLIST_INTERNAL_RES)
4135
4236#define NETLIST_GMIN    (1e-9)
4337
trunk/src/emu/netlist/nl_base.c
r26799r26800
2727   manager.save_item(m_times, module + "." + "times");
2828   manager.save_item(&(m_name[0][0]), module + "." + "names", sizeof(m_name));
2929}
30
3031void netlist_queue_t::on_pre_save()
3132{
3233   NL_VERBOSE_OUT(("on_pre_save\n"));
r26799r26800
111112   :   netlist_object_t(NETLIST, GENERIC),
112113      m_time_ps(netlist_time::zero),
113114      m_queue(*this),
114      m_rem(0),
115      m_div(NETLIST_DIV),
116115      m_mainclock(NULL),
117116      m_solver(NULL)
118117{
r26799r26800
168167ATTR_COLD void netlist_base_t::reset()
169168{
170169   m_time_ps = netlist_time::zero;
171   m_rem = 0;
172170   m_queue.clear();
173171   if (m_mainclock != NULL)
174172      m_mainclock->m_Q.net().set_time(netlist_time::zero);
r26799r26800
188186   }
189187}
190188
191void netlist_base_t::set_clock_freq(UINT64 clockfreq)
192{
193   m_div = netlist_time::from_hz(clockfreq).as_raw();
194   m_rem = 0;
195   assert_always(m_div == NETLIST_DIV, "netlist: illegal clock!");
196   NL_VERBOSE_OUT(("Setting clock %" I64FMT "d and divisor %d\n", clockfreq, m_div));
197}
198189
199ATTR_HOT ATTR_ALIGN inline void netlist_base_t::update_time(const netlist_time t, INT32 &atime)
190ATTR_HOT ATTR_ALIGN void netlist_base_t::process_queue(const netlist_time delta)
200191{
201   if (NETLIST_DIV_BITS == 0)
202   {
203      const netlist_time delta = t - m_time_ps;
204      m_time_ps = t;
205      atime -= delta.as_raw();
206   } else {
207      const netlist_time delta = t - m_time_ps + netlist_time::from_raw(m_rem);
208      m_time_ps = t;
209      m_rem = delta.as_raw() & NETLIST_MASK;
210      atime -= (delta.as_raw() >> NETLIST_DIV_BITS);
192    m_stop = m_time_ps + delta;
211193
212      // The folling is suitable for non-power of 2 m_divs ...
213      // atime -= divu_64x32_rem(delta.as_raw(), m_div, &m_rem);
214   }
215}
194    if (m_mainclock == NULL)
195    {
196        while ( (m_time_ps < m_stop) && (m_queue.is_not_empty()))
197        {
198            const netlist_queue_t::entry_t &e = m_queue.pop();
199            m_time_ps = e.time();
200            e.object().update_devs();
216201
217ATTR_HOT ATTR_ALIGN void netlist_base_t::process_queue(INT32 &atime)
218{
219   if (m_mainclock == NULL)
220   {
221      while ( (atime > 0) && (m_queue.is_not_empty()))
222      {
223         const netlist_queue_t::entry_t &e = m_queue.pop();
224         update_time(e.time(), atime);
202            add_to_stat(m_perf_out_processed, 1);
203            if (FATAL_ERROR_AFTER_NS)
204                if (time() > NLTIME_FROM_NS(FATAL_ERROR_AFTER_NS))
205                    xfatalerror("Stopped");
206        }
207        if (m_queue.is_empty())
208            m_time_ps = m_stop;
225209
226         //if (FATAL_ERROR_AFTER_NS)
227         //  NL_VERBOSE_OUT(("%s\n", e.object().netdev()->name().cstr());
210    } else {
211        netlist_net_t &mcQ = m_mainclock->m_Q.net();
212        const netlist_time inc = m_mainclock->m_inc;
228213
229         e.object().update_devs();
214        while (m_time_ps < m_stop)
215        {
216            if (m_queue.is_not_empty())
217            {
218                while (m_queue.peek().time() > mcQ.time())
219                {
220                    m_time_ps = mcQ.time();
221                    NETLIB_NAME(mainclock)::mc_update(mcQ, m_time_ps + inc);
222                }
230223
231         add_to_stat(m_perf_out_processed, 1);
224                const netlist_queue_t::entry_t &e = m_queue.pop();
225                m_time_ps = e.time();
226                e.object().update_devs();
232227
233         if (FATAL_ERROR_AFTER_NS)
234            if (time() > NLTIME_FROM_NS(FATAL_ERROR_AFTER_NS))
235               xfatalerror("Stopped");
236      }
228            } else {
229                m_time_ps = mcQ.time();
230                NETLIB_NAME(mainclock)::mc_update(mcQ, m_time_ps + inc);
231            }
232            if (FATAL_ERROR_AFTER_NS)
233                if (time() > NLTIME_FROM_NS(FATAL_ERROR_AFTER_NS))
234                    xfatalerror("Stopped");
237235
238      if (atime > 0)
239      {
240         m_time_ps += netlist_time::from_raw(atime * m_div);
241         atime = 0;
242      }
243   } else {
244      netlist_net_t &mcQ = m_mainclock->m_Q.net();
245      const netlist_time inc = m_mainclock->m_inc;
246
247      while (atime > 0)
248      {
249         if (m_queue.is_not_empty())
250         {
251            while (m_queue.peek().time() > mcQ.time())
252            {
253               update_time(mcQ.time(), atime);
254
255               NETLIB_NAME(mainclock)::mc_update(mcQ, time() + inc);
256
257            }
258            const netlist_queue_t::entry_t &e = m_queue.pop();
259
260            update_time(e.time(), atime);
261
262            e.object().update_devs();
263
264         } else {
265            update_time(mcQ.time(), atime);
266
267            NETLIB_NAME(mainclock)::mc_update(mcQ, time() + inc);
268         }
269         if (FATAL_ERROR_AFTER_NS)
270            if (time() > NLTIME_FROM_NS(FATAL_ERROR_AFTER_NS))
271               xfatalerror("Stopped");
272
273         add_to_stat(m_perf_out_processed, 1);
274      }
275
276      if (atime > 0)
277      {
278         m_time_ps += netlist_time::from_raw(atime * m_div);
279         atime = 0;
280      }
281   }
236            add_to_stat(m_perf_out_processed, 1);
237        }
238    }
282239}
283240
284241ATTR_COLD void netlist_base_t::xfatalerror(const char *format, ...) const

Previous 199869 Revisions Next


© 1997-2024 The MAME Team