Previous 199869 Revisions Next

r26690 Sunday 22nd December, 2013 at 21:32:13 UTC by Couriersud
Netlist: introduced more consistent and general state saving. Useful for regression tests going forward.
[src/emu/machine]netlist.c
[src/emu/netlist]netlist.mak nl_base.c nl_base.h nl_setup.c nl_setup.h pstate.c* pstate.h*

trunk/src/emu/machine/netlist.c
r26689r26690
4949#include "netlist/nl_base.h"
5050#include "netlist/nl_setup.h"
5151#include "netlist/devices/net_lib.h"
52#include "debugger.h"
5253
5354//#define LOG_DEV_CALLS(x)   printf x
5455#define LOG_DEV_CALLS(x)   do { } while (0)
r26689r26690
178179
179180ATTR_COLD void netlist_mame_device::save_state()
180181{
181    for (netlist_setup_t::save_entry_list_t::entry_t *p = setup().m_save.first(); p != NULL; p = setup().m_save.next(p))
182    for (pstate_entry_t::list_t::entry_t *p = m_netlist->save_list().first(); p != NULL; p = m_netlist->save_list().next(p))
182183    {
183        netlist_setup_t::save_entry_t *s = p->object();
184        pstate_entry_t *s = p->object();
184185        NL_VERBOSE_OUT(("saving state for %s\n", s->m_name.cstr()));
185186        switch (s->m_dt)
186187        {
187188            case DT_DOUBLE:
188                save_pointer((double *) s->m_ptr, s->m_name, 1);
189                save_pointer((double *) s->m_ptr, s->m_name, s->m_count);
189190                break;
190191            case DT_INT64:
191                save_pointer((INT64 *) s->m_ptr, s->m_name, 1);
192                save_pointer((INT64 *) s->m_ptr, s->m_name, s->m_count);
192193                break;
193194            case DT_INT8:
194                save_pointer((INT8 *) s->m_ptr, s->m_name, 1);
195                save_pointer((INT8 *) s->m_ptr, s->m_name, s->m_count);
195196                break;
196197            case DT_INT:
197                save_pointer((int *) s->m_ptr, s->m_name, 1);
198                save_pointer((int *) s->m_ptr, s->m_name, s->m_count);
198199                break;
199200            case DT_BOOLEAN:
200                save_pointer((bool *) s->m_ptr, s->m_name, 1);
201                save_pointer((bool *) s->m_ptr, s->m_name, s->m_count);
201202                break;
202#if 0
203            case DT_NLTIME:
204                {
205                    netlist_time *nlt = (netlist_time *) s->m_ptr;
206                    //save_pointer((netlist_time::INTERNALTYPE *) s->m_ptr, s->m_name, 1);
207                    //save_pointer(nlt->get_internaltype_ptr(), s->m_name, 1);
208                    save_item(*nlt->get_internaltype_ptr(), s->m_name.cstr());
209                }
210                break;
211#endif
212203            case NOT_SUPPORTED:
213204            default:
214205                m_netlist->xfatalerror("found unsupported save element %s\n", s->m_name.cstr());
r26689r26690
225216        save_pointer(qtemp[i].m_name, "queue_name", sizeof(qtemp[i].m_name), i);
226217
227218    }
228#if 0
229
230    netlist_time *nlt = (netlist_time *) ;
231    netlist_base_t::queue_t::entry_t *p = m_netlist->queue().listptr()[i];
232    netlist_time *nlt = (netlist_time *) p->time_ptr();
233    save_pointer(nlt->get_internaltype_ptr(), "queue", 1, i);
234#endif
235219}
236220
237221ATTR_COLD UINT64 netlist_mame_device::execute_clocks_to_cycles(UINT64 clocks) const
r26689r26690
246230
247231ATTR_HOT void netlist_mame_device::execute_run()
248232{
249   //bool check_debugger = ((device_t::machine().debug_flags & DEBUG_FLAG_ENABLED) != 0);
233   bool check_debugger = ((device_t::machine().debug_flags & DEBUG_FLAG_ENABLED) != 0);
250234
251235   // debugging
252236   //m_ppc = m_pc; // copy PC to previous PC
253   //if (check_debugger)
254   //  debugger_instruction_hook(this, 0); //m_pc);
237   if (check_debugger)
238       debugger_instruction_hook(this, 0); //m_pc);
255239
256240   m_netlist->process_queue(m_icount);
257241}
trunk/src/emu/netlist/nl_base.c
r26689r26690
3939    return m_name;
4040}
4141
42ATTR_COLD void netlist_object_t::save_state_ptr(const pstring &stname, const netlist_data_type_e dt, const int size, void *ptr)
43{
44    pstring fullname = name() + "." + stname;
45    // do nothing for now;
46    ATTR_UNUSED  pstring ts[] = {
47            "NOT_SUPPORTED",
48            "DT_DOUBLE",
49            "DT_INT64",
50            "DT_INT8",
51            "DT_INT",
52            "DT_BOOLEAN"
53    };
54
55    NL_VERBOSE_OUT(("SAVE: <%s> %s(%d) %p\n", fullname.cstr(), ts[dt].cstr(), size, ptr));
56    netlist().setup().save_state_ptr(fullname, dt, size, ptr);
57}
58
5942// ----------------------------------------------------------------------------------------
6043// netlist_owned_object_t
6144// ----------------------------------------------------------------------------------------
trunk/src/emu/netlist/pstate.h
r0r26690
1/*
2 * pstate.h
3 *
4 */
5
6#ifndef PSTATE_H_
7#define PSTATE_H_
8
9#include "nl_config.h"
10#include "nl_time.h"
11#include "nl_lists.h"
12#include "pstring.h"
13
14// ----------------------------------------------------------------------------------------
15// state saving ...
16// ----------------------------------------------------------------------------------------
17
18#define PSTATE_INTERFACE(manager, module)               \
19    template<class C> ATTR_COLD void save(C &state, const pstring &stname) \
20    {                                                                       \
21        dynamic_cast<pstate_manager_t &>(manager).save_manager(state, module + "." + stname);  \
22    }
23
24enum netlist_data_type_e {
25    NOT_SUPPORTED,
26    DT_DOUBLE,
27    DT_INT64,
28    DT_INT8,
29    DT_INT,
30    DT_BOOLEAN
31};
32
33template<typename _ItemType> struct nl_datatype { static const netlist_data_type_e type = netlist_data_type_e(NOT_SUPPORTED); };
34//template<typename _ItemType> struct type_checker<_ItemType*> { static const bool is_atom = false; static const bool is_pointer = true; };
35
36#define NETLIST_SAVE_TYPE(TYPE, TYPEDESC) template<> struct nl_datatype<TYPE>{ static const netlist_data_type_e type = netlist_data_type_e(TYPEDESC); }
37
38NETLIST_SAVE_TYPE(double, DT_DOUBLE);
39NETLIST_SAVE_TYPE(INT8, DT_INT8);
40NETLIST_SAVE_TYPE(UINT8, DT_INT8);
41NETLIST_SAVE_TYPE(INT64, DT_INT64);
42NETLIST_SAVE_TYPE(UINT64, DT_INT64);
43NETLIST_SAVE_TYPE(bool, DT_BOOLEAN);
44NETLIST_SAVE_TYPE(UINT32, DT_INT);
45NETLIST_SAVE_TYPE(INT32, DT_INT);
46
47struct pstate_entry_t
48{
49    typedef netlist_list_t<pstate_entry_t *> list_t;
50
51    pstate_entry_t(const pstring &stname, const netlist_data_type_e dt, const int size, const int count, void *ptr) :
52        m_name(stname), m_dt(dt), m_size(size), m_count(count), m_ptr(ptr) { }
53    pstring m_name;
54    netlist_data_type_e m_dt;
55    int m_size;
56    int m_count;
57    void *m_ptr;
58};
59
60class pstate_manager_t
61{
62public:
63
64    ATTR_COLD ~pstate_manager_t();
65
66    template<class C> ATTR_COLD void save_manager(C &state, const pstring &stname)
67    {
68        save_state_ptr(stname, nl_datatype<C>::type, sizeof(C), 1, &state);
69    }
70
71    template<class C> ATTR_COLD void save_manager(C *state, const pstring &stname, const int count)
72    {
73        save_state_ptr(stname, nl_datatype<C>::type, sizeof(C), count, state);
74    }
75
76    template<class C, std::size_t N> ATTR_COLD void save_manager(C (&state)[N], const pstring &stname)
77    {
78        save_state_ptr(stname, nl_datatype<C>::type, sizeof(C), N, &(state[0]));
79    }
80
81    inline const pstate_entry_t::list_t &save_list() const { return m_save; }
82
83protected:
84    ATTR_COLD void save_state_ptr(const pstring &stname, const netlist_data_type_e, const int size, const int count, void *ptr);
85
86private:
87    pstate_entry_t::list_t m_save;
88};
89
90template<> ATTR_COLD inline void pstate_manager_t::save_manager(netlist_time &nlt, const pstring &stname)
91{
92    save_state_ptr(stname, DT_INT64, sizeof(netlist_time::INTERNALTYPE), 1, nlt.get_internaltype_ptr());
93}
94
95
96
97#endif /* PSTATE_H_ */
Property changes on: trunk/src/emu/netlist/pstate.h
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native
trunk/src/emu/netlist/netlist.mak
r26689r26690
2222   $(NETLISTOBJ)/nl_parser.o \
2323   $(NETLISTOBJ)/nl_setup.o \
2424   $(NETLISTOBJ)/pstring.o \
25   $(NETLISTOBJ)/pstate.o \
2526   $(NETLISTOBJ)/devices/nld_7404.o \
2627   $(NETLISTOBJ)/devices/nld_7474.o \
2728   $(NETLISTOBJ)/devices/nld_7483.o \
trunk/src/emu/netlist/nl_base.h
r26689r26690
155155#include "nl_lists.h"
156156#include "nl_time.h"
157157#include "pstring.h"
158#include "pstate.h"
158159
159160// ----------------------------------------------------------------------------------------
160161// Type definitions
r26689r26690
247248class NETLIB_NAME(mainclock);
248249
249250// ----------------------------------------------------------------------------------------
250// state saving ...
251// ----------------------------------------------------------------------------------------
252
253enum netlist_data_type_e {
254    NOT_SUPPORTED,
255    DT_DOUBLE,
256    DT_INT64,
257    DT_INT8,
258    DT_INT,
259    DT_BOOLEAN
260};
261
262template<typename _ItemType> struct nl_datatype { static const netlist_data_type_e type = netlist_data_type_e(NOT_SUPPORTED); };
263//template<typename _ItemType> struct type_checker<_ItemType*> { static const bool is_atom = false; static const bool is_pointer = true; };
264
265#define NETLIST_SAVE_TYPE(TYPE, TYPEDESC) template<> struct nl_datatype<TYPE>{ static const netlist_data_type_e type = netlist_data_type_e(TYPEDESC); }
266
267NETLIST_SAVE_TYPE(double, DT_DOUBLE);
268NETLIST_SAVE_TYPE(INT8, DT_INT8);
269NETLIST_SAVE_TYPE(UINT8, DT_INT8);
270NETLIST_SAVE_TYPE(INT64, DT_INT64);
271NETLIST_SAVE_TYPE(UINT64, DT_INT64);
272NETLIST_SAVE_TYPE(bool, DT_BOOLEAN);
273NETLIST_SAVE_TYPE(UINT32, DT_INT);
274NETLIST_SAVE_TYPE(INT32, DT_INT);
275
276// ----------------------------------------------------------------------------------------
277251// netlist_object_t
278252// ----------------------------------------------------------------------------------------
279253
r26689r26690
313287
314288    ATTR_COLD const pstring &name() const;
315289
316    ATTR_COLD void save_state_ptr(const pstring &stname, const netlist_data_type_e, const int size, void *ptr);
290    PSTATE_INTERFACE(*m_netlist, name())
291
292#if 0
317293    template<class C> ATTR_COLD void save(C &state, const pstring &stname)
318294    {
319295        save_state_ptr(stname, nl_datatype<C>::type, sizeof(C), &state);
320296    }
297#endif
321298
322299   ATTR_HOT inline const type_t type() const { return m_objtype; }
323300    ATTR_HOT inline const family_t family() const { return m_family; }
r26689r26690
330307
331308protected:
332309
310#if 0
311    // pstate_interface virtual
312    ATTR_COLD virtual void save_state_ptr(const pstring &stname, const netlist_data_type_e, const int size, const int count, void *ptr);
313#endif
314
333315    // must call parent save_register !
334316    ATTR_COLD virtual void save_register() { };
335317
r26689r26690
340322    netlist_base_t * RESTRICT m_netlist;
341323};
342324
343template<> ATTR_COLD inline void netlist_object_t::save(netlist_time &state, const pstring &stname)
344{
345    save_state_ptr(stname, DT_INT64, sizeof(netlist_time::INTERNALTYPE), state.get_internaltype_ptr());
346}
347
348325// ----------------------------------------------------------------------------------------
349326// netlist_owned_object_t
350327// ----------------------------------------------------------------------------------------
r26689r26690
983960
984961typedef tagmap_t<netlist_device_t *, 393> tagmap_devices_t;
985962
986class netlist_base_t : public netlist_object_t
963class netlist_base_t : public netlist_object_t, public pstate_manager_t
987964{
988965    NETLIST_PREVENT_COPYING(netlist_base_t)
989966public:
trunk/src/emu/netlist/nl_setup.c
r26689r26690
4949   m_params.reset();
5050   m_terminals.reset();
5151   m_params_temp.reset();
52   m_save.reset_and_free();
5352
5453   netlist().set_setup(NULL);
5554
trunk/src/emu/netlist/nl_setup.h
r26689r26690
135135
136136   void print_stats();
137137
138   /* save state */
139
140   struct save_entry_t
141   {
142       save_entry_t(const pstring &stname, const netlist_data_type_e dt, const int size, void *ptr) :
143           m_name(stname), m_dt(dt), m_size(size), m_ptr(ptr) { }
144       pstring m_name;
145       netlist_data_type_e m_dt;
146       int m_size;
147       void *m_ptr;
148   };
149
150   typedef netlist_list_t<save_entry_t *> save_entry_list_t;
151
152   void save_state_ptr(const pstring &stname, const netlist_data_type_e dt, const int size, void *ptr)
153   {
154       save_entry_t *p = new save_entry_t(stname, dt, size, ptr);
155       m_save.add(p);
156   }
157
158   save_entry_list_t m_save;
159
160138protected:
161139
162140private:
trunk/src/emu/netlist/pstate.c
r0r26690
1/*
2 * pstate.c
3 *
4 */
5
6#include "pstate.h"
7
8ATTR_COLD pstate_manager_t::~pstate_manager_t()
9{
10    m_save.reset_and_free();
11}
12
13
14
15ATTR_COLD void pstate_manager_t::save_state_ptr(const pstring &stname, const netlist_data_type_e dt, const int size, const int count, void *ptr)
16{
17    pstring fullname = stname;
18    ATTR_UNUSED  pstring ts[] = {
19            "NOT_SUPPORTED",
20            "DT_DOUBLE",
21            "DT_INT64",
22            "DT_INT8",
23            "DT_INT",
24            "DT_BOOLEAN"
25    };
26
27    NL_VERBOSE_OUT(("SAVE: <%s> %s(%d) %p\n", fullname.cstr(), ts[dt].cstr(), size, ptr));
28    pstate_entry_t *p = new pstate_entry_t(stname, dt, size, count, ptr);
29    m_save.add(p);
30}
Property changes on: trunk/src/emu/netlist/pstate.c
Added: svn:eol-style
   + native
Added: svn:mime-type
   + text/plain

Previous 199869 Revisions Next


© 1997-2024 The MAME Team