Previous 199869 Revisions Next

r26796 Saturday 28th December, 2013 at 21:20:40 UTC by Couriersud
Split netlist_mame_device_t into a core device and a "cpu" device. Based on this setup, work can start on "pure" sound devices.
[src/emu/machine]netlist.c netlist.h

trunk/src/emu/machine/netlist.c
r26795r26796
5454//#define LOG_DEV_CALLS(x)   printf x
5555#define LOG_DEV_CALLS(x)   do { } while (0)
5656
57const device_type NETLIST = &device_creator<netlist_mame_device_t>;
57const device_type NETLIST_CORE = &device_creator<netlist_mame_device_t>;
58const device_type NETLIST_CPU = &device_creator<netlist_mame_cpu_device_t>;
5859const device_type NETLIST_ANALOG_INPUT = &device_creator<netlist_mame_analog_input_t>;
5960const device_type NETLIST_LOGIC_INPUT = &device_creator<netlist_mame_logic_input_t>;
6061
62// ----------------------------------------------------------------------------------------
63// netlist_mame_analog_input_t
64// ----------------------------------------------------------------------------------------
65
6166netlist_mame_analog_input_t::netlist_mame_analog_input_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
6267      : device_t(mconfig, NETLIST_ANALOG_INPUT, "netlist analog input", tag, owner, clock, "netlist_analog_input", __FILE__),
6368         netlist_mame_sub_interface(*this),
69         m_param(0),
6470         m_offset(0.0),
6571         m_mult(1.0),
6672         m_auto_port(true),
r26795r26796
97103netlist_mame_logic_input_t::netlist_mame_logic_input_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
98104      : device_t(mconfig, NETLIST_ANALOG_INPUT, "netlist analog input", tag, owner, clock, "netlist_analog_input", __FILE__),
99105         netlist_mame_sub_interface(*this),
106         m_param(0),
100107         m_mask(0xffffffff),
101108         m_shift(0),
102109         m_param_name("")
r26795r26796
124131
125132
126133// ----------------------------------------------------------------------------------------
127// netlist_mame_device
134// netlist_mame_device_t
128135// ----------------------------------------------------------------------------------------
129136
130137static ADDRESS_MAP_START(program_dummy, AS_PROGRAM, 8, netlist_mame_device_t)
r26795r26796
132139ADDRESS_MAP_END
133140
134141netlist_mame_device_t::netlist_mame_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
135   : device_t(mconfig, NETLIST, "netlist", tag, owner, clock, "netlist_mame", __FILE__),
136      device_execute_interface(mconfig, *this),
137      device_state_interface(mconfig, *this),
138      device_disasm_interface(mconfig, *this),
139      device_memory_interface(mconfig, *this),
140      m_program_config("program", ENDIANNESS_LITTLE, 8, 12, 0, ADDRESS_MAP_NAME(program_dummy)),
141      m_netlist(NULL),
142      m_setup(NULL),
143      m_setup_func(NULL),
144      m_icount(0),
145      m_genPC(0)
142   : device_t(mconfig, NETLIST_CORE, "Netlist core device", tag, owner, clock, "netlist_core", __FILE__),
143        m_netlist(NULL),
144        m_setup(NULL),
145        m_setup_func(NULL)
146146{
147147}
148148
149netlist_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)
150    : device_t(mconfig, type, name, tag, owner, clock, shortname, file),
151        m_netlist(NULL),
152        m_setup(NULL),
153        m_setup_func(NULL)
154{
155}
156
149157void netlist_mame_device_t::static_set_constructor(device_t &device, void (*setup_func)(netlist_setup_t &))
150158{
151159   LOG_DEV_CALLS(("static_set_constructor\n"));
r26795r26796
164172
165173   m_netlist = global_alloc_clear(netlist_mame_t(*this));
166174   m_setup = global_alloc_clear(netlist_setup_t(*m_netlist));
167   m_netlist->init_object(*m_netlist, "netlist");
175   netlist().init_object(*m_netlist, "netlist");
168176   m_setup->init();
169177
170   m_netlist->set_clock_freq(this->clock());
178   netlist().set_clock_freq(this->clock());
171179
172180   // register additional devices
173181
r26795r26796
191199
192200   save_state();
193201
194   // State support
195
196   state_add(STATE_GENPC, "curpc", m_genPC).noshow();
197
198   for (int i=0; i < m_netlist->m_nets.count(); i++)
199   {
200      netlist_net_t *n = m_netlist->m_nets[i];
201      if (n->isRailNet())
202      {
203         state_add(i*2, n->name(), n->Q_state_ptr());
204      }
205      else
206      {
207         state_add(i*2+1, n->name(), n->Q_Analog_state_ptr()).formatstr("%20s");
208      }
209   }
210
211   // set our instruction counter
212   m_icountptr = &m_icount;
213202}
214203
215204void netlist_mame_device_t::device_reset()
216205{
217206   LOG_DEV_CALLS(("device_reset\n"));
218   m_netlist->reset();
207   netlist().reset();
219208}
220209
221210void netlist_mame_device_t::device_stop()
r26795r26796
233222{
234223   LOG_DEV_CALLS(("device_post_load\n"));
235224
236   m_netlist->post_load();
225   netlist().post_load();
237226}
238227
239228ATTR_COLD void netlist_mame_device_t::device_pre_save()
240229{
241230   LOG_DEV_CALLS(("device_pre_save\n"));
242231
243   m_netlist->pre_save();
232   netlist().pre_save();
244233}
245234
246235void netlist_mame_device_t::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
247236{
248237}
249238
250
251
252239ATTR_COLD void netlist_mame_device_t::save_state()
253240{
254   for (pstate_entry_t::list_t::entry_t *p = m_netlist->save_list().first(); p != NULL; p = m_netlist->save_list().next(p))
241   for (pstate_entry_t::list_t::entry_t *p = netlist().save_list().first(); p != NULL; p = netlist().save_list().next(p))
255242   {
256243      pstate_entry_t *s = p->object();
257244      NL_VERBOSE_OUT(("saving state for %s\n", s->m_name.cstr()));
r26795r26796
275262         case DT_CUSTOM:
276263         case NOT_SUPPORTED:
277264         default:
278            m_netlist->xfatalerror("found unsupported save element %s\n", s->m_name.cstr());
265            netlist().xfatalerror("found unsupported save element %s\n", s->m_name.cstr());
279266            break;
280267      }
281268   }
282269
283270}
284271
285ATTR_COLD UINT64 netlist_mame_device_t::execute_clocks_to_cycles(UINT64 clocks) const
272// ----------------------------------------------------------------------------------------
273// netlist_mame_cpu_device_t
274// ----------------------------------------------------------------------------------------
275
276netlist_mame_cpu_device_t::netlist_mame_cpu_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
277    : netlist_mame_device_t(mconfig, NETLIST_CPU, "Netlist cpu device", tag, owner, clock, "netlist_cpu", __FILE__),
278        device_execute_interface(mconfig, *this),
279        device_state_interface(mconfig, *this),
280        device_disasm_interface(mconfig, *this),
281        device_memory_interface(mconfig, *this),
282        m_program_config("program", ENDIANNESS_LITTLE, 8, 12, 0, ADDRESS_MAP_NAME(program_dummy)),
283        m_icount(0)
286284{
285}
286
287
288void netlist_mame_cpu_device_t::device_start()
289{
290    netlist_mame_device_t::device_start();
291
292    LOG_DEV_CALLS(("device_start %s\n", tag()));
293
294    // State support
295
296    state_add(STATE_GENPC, "curpc", m_genPC).noshow();
297
298    for (int i=0; i < netlist().m_nets.count(); i++)
299    {
300        netlist_net_t *n = netlist().m_nets[i];
301        if (n->isRailNet())
302        {
303            state_add(i*2, n->name(), n->Q_state_ptr());
304        }
305        else
306        {
307            state_add(i*2+1, n->name(), n->Q_Analog_state_ptr()).formatstr("%20s");
308        }
309    }
310
311    // set our instruction counter
312    m_icountptr = &m_icount;
313}
314
315ATTR_COLD UINT64 netlist_mame_cpu_device_t::execute_clocks_to_cycles(UINT64 clocks) const
316{
287317   return clocks;
288318}
289319
290ATTR_COLD UINT64 netlist_mame_device_t::execute_cycles_to_clocks(UINT64 cycles) const
320ATTR_COLD UINT64 netlist_mame_cpu_device_t::execute_cycles_to_clocks(UINT64 cycles) const
291321{
292322   return cycles;
293323}
294324
295ATTR_COLD offs_t netlist_mame_device_t::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
325ATTR_COLD offs_t netlist_mame_cpu_device_t::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
296326{
297327   //char tmp[16];
298328   unsigned startpc = pc;
r26795r26796
300330   //UINT16 opcode = (oprom[pc - startpc] << 8) | oprom[pc+1 - startpc];
301331   //UINT8 inst = opcode >> 13;
302332
303   if (relpc >= 0 && relpc < m_netlist->queue().count())
333   if (relpc >= 0 && relpc < netlist().queue().count())
304334   {
305      //            sprintf(buffer, "%04x %02d %s", pc, relpc, m_netlist->queue()[m_netlist->queue().count() - relpc - 1].object().name().cstr());
306      int dpc = m_netlist->queue().count() - relpc - 1;
307      sprintf(buffer, "%c %s @%10.7f", (relpc == 0) ? '*' : ' ', m_netlist->queue()[dpc].object().name().cstr(),
308            m_netlist->queue()[dpc].time().as_double());
335      //            sprintf(buffer, "%04x %02d %s", pc, relpc, netlist().queue()[netlist().queue().count() - relpc - 1].object().name().cstr());
336      int dpc = netlist().queue().count() - relpc - 1;
337      sprintf(buffer, "%c %s @%10.7f", (relpc == 0) ? '*' : ' ', netlist().queue()[dpc].object().name().cstr(),
338            netlist().queue()[dpc].time().as_double());
309339   }
310340   else
311341      sprintf(buffer, "%s", "");
r26795r26796
313343   return (pc - startpc);
314344}
315345
316ATTR_HOT void netlist_mame_device_t::execute_run()
346ATTR_HOT void netlist_mame_cpu_device_t::execute_run()
317347{
318348   bool check_debugger = ((device_t::machine().debug_flags & DEBUG_FLAG_ENABLED) != 0);
319349   // debugging
r26795r26796
326356         m_genPC++;
327357         m_genPC &= 255;
328358         debugger_instruction_hook(this, m_genPC);
329         m_netlist->process_queue(m_temp);
359         netlist().process_queue(m_temp);
330360         m_icount -= (1 - m_temp);
331361      }
332362   }
333363   else
334      m_netlist->process_queue(m_icount);
364      netlist().process_queue(m_icount);
335365}
trunk/src/emu/machine/netlist.h
r26795r26796
5757// MAME specific configuration
5858
5959#define MCFG_NETLIST_ADD(_tag, _setup )                                             \
60   MCFG_DEVICE_ADD(_tag, NETLIST, NETLIST_CLOCK)                                   \
60   MCFG_DEVICE_ADD(_tag, NETLIST_CPU, NETLIST_CLOCK)                               \
6161   MCFG_NETLIST_SETUP(_setup)
6262
6363#define MCFG_NETLIST_REPLACE(_tag, _setup)                                          \
64   MCFG_DEVICE_REPLACE(_tag, NETLIST, NETLIST_CLOCK)                               \
64   MCFG_DEVICE_REPLACE(_tag, NETLIST_CPU, NETLIST_CLOCK)                           \
6565   MCFG_NETLIST_SETUP(_setup)
6666
6767#define MCFG_NETLIST_SETUP(_setup)                                                  \
r26795r26796
134134// netlist_mame_device_t
135135// ----------------------------------------------------------------------------------------
136136
137class netlist_mame_device_t : public device_t,
138                        public device_execute_interface,
139                        public device_state_interface,
140                        public device_disasm_interface,
141                        public device_memory_interface
137class netlist_mame_device_t : public device_t
142138{
143139public:
144140
145141   // construction/destruction
146142   netlist_mame_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
143   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);
147144   virtual ~netlist_mame_device_t() {}
148145
149146   static void static_set_constructor(device_t &device, void (*setup_func)(netlist_setup_t &));
150147
151   netlist_setup_t &setup() { return *m_setup; }
152   netlist_mame_t &netlist() { return *m_netlist; }
148   ATTR_HOT inline netlist_setup_t &setup() { return *m_setup; }
149   ATTR_HOT inline netlist_mame_t &netlist() { return *m_netlist; }
153150
154151protected:
155   // device-level overrides
152   // device_t overrides
156153   virtual void device_config_complete();
157154   virtual void device_start();
158155   virtual void device_stop();
r26795r26796
160157   virtual void device_post_load();
161158   virtual void device_pre_save();
162159   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
163   virtual UINT64 execute_clocks_to_cycles(UINT64 clocks) const;
164   virtual UINT64 execute_cycles_to_clocks(UINT64 cycles) const;
165160
166   ATTR_HOT virtual void execute_run();
161private:
162    void save_state();
167163
168   // device_disasm_interface overrides
169   ATTR_COLD virtual UINT32 disasm_min_opcode_bytes() const { return 1; }
170   ATTR_COLD virtual UINT32 disasm_max_opcode_bytes() const { return 1; }
171   ATTR_COLD virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);
164   netlist_mame_t *m_netlist;
165    netlist_setup_t *m_setup;
172166
173   // device_memory_interface overrides
167   void (*m_setup_func)(netlist_setup_t &);
168};
174169
175   address_space_config m_program_config;
170inline running_machine &netlist_mame_t::machine()
171{
172   return m_parent.machine();
173}
176174
177   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const
178   {
179      switch (spacenum)
180      {
181         case AS_PROGRAM: return &m_program_config;
182         case AS_IO:      return NULL;
183         default:         return NULL;
184      }
185   }
175// ----------------------------------------------------------------------------------------
176// netlist_mame_cpu_device_t
177// ----------------------------------------------------------------------------------------
186178
187   virtual void state_string_export(const device_state_entry &entry, astring &string)
188   {
189      if (entry.index() >= 0)
190      {
191         if (entry.index() & 1)
192            string.format("%10.6f", *((double *) entry.dataptr()));
193         else
194            string.format("%d", *((netlist_sig_t *) entry.dataptr()));
195      }
196   }
179class netlist_mame_cpu_device_t : public netlist_mame_device_t,
180                                  public device_execute_interface,
181                                  public device_state_interface,
182                                  public device_disasm_interface,
183                                  public device_memory_interface
184{
185public:
197186
187    // construction/destruction
188    netlist_mame_cpu_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
189    virtual ~netlist_mame_cpu_device_t() {}
198190
199   netlist_mame_t *m_netlist;
200   netlist_setup_t *m_setup;
191    static void static_set_constructor(device_t &device, void (*setup_func)(netlist_setup_t &));
201192
202private:
193protected:
194    // device_t overrides
195    //virtual void device_config_complete();
196    virtual void device_start();
197    //virtual void device_stop();
198    //virtual void device_reset();
199    //virtual void device_post_load();
200    //virtual void device_pre_save();
201    //virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
203202
204   void save_state();
203    // device_execute_interface overrides
205204
206   void (*m_setup_func)(netlist_setup_t &);
205    virtual UINT64 execute_clocks_to_cycles(UINT64 clocks) const;
206    virtual UINT64 execute_cycles_to_clocks(UINT64 cycles) const;
207207
208   int m_icount;
209   int m_genPC;
208    ATTR_HOT virtual void execute_run();
210209
210    // device_disasm_interface overrides
211    ATTR_COLD virtual UINT32 disasm_min_opcode_bytes() const { return 1; }
212    ATTR_COLD virtual UINT32 disasm_max_opcode_bytes() const { return 1; }
213    ATTR_COLD virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);
214
215    // device_memory_interface overrides
216
217    address_space_config m_program_config;
218
219    virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const
220    {
221        switch (spacenum)
222        {
223            case AS_PROGRAM: return &m_program_config;
224            case AS_IO:      return NULL;
225            default:         return NULL;
226        }
227    }
228
229    //  device_state_interface overrides
230
231    virtual void state_string_export(const device_state_entry &entry, astring &string)
232    {
233        if (entry.index() >= 0)
234        {
235            if (entry.index() & 1)
236                string.format("%10.6f", *((double *) entry.dataptr()));
237            else
238                string.format("%d", *((netlist_sig_t *) entry.dataptr()));
239        }
240    }
241
242private:
243
244    int m_icount;
245    int m_genPC;
246
211247};
212248
213inline running_machine &netlist_mame_t::machine()
214{
215   return m_parent.machine();
216}
217
218249// ----------------------------------------------------------------------------------------
219250// netlist_mame_sub_interface
220251// ----------------------------------------------------------------------------------------
r26795r26796
327358   {
328359      register_input("IN", m_in);
329360      m_callback.bind_relative_to(downcast<netlist_mame_t &>(netlist()).machine().root_device());
361      m_cpu_device = downcast<netlist_mame_cpu_device_t *>(&downcast<netlist_mame_t &>(netlist()).parent());
330362   }
331363
332364   ATTR_COLD void register_callback(netlist_analog_output_delegate callback)
r26795r26796
336368
337369   ATTR_HOT void update()
338370   {
339      // FIXME: Remove after device cleanup
340      if (!m_callback.isnull())
341         m_callback(INPANALOG(m_in), downcast<netlist_mame_t &>(netlist()).parent().local_time());
371        m_callback(INPANALOG(m_in), m_cpu_device->local_time());
342372   }
343373
344374private:
345375   netlist_analog_input_t m_in;
346376   netlist_analog_output_delegate m_callback;
377   netlist_mame_cpu_device_t *m_cpu_device;
347378};
348379
349380class NETLIB_NAME(sound) : public netlist_device_t
r26795r26796
393424
394425
395426// device type definition
396extern const device_type NETLIST;
427extern const device_type NETLIST_CORE;
428extern const device_type NETLIST_CPU;
397429extern const device_type NETLIST_ANALOG_INPUT;
398430extern const device_type NETLIST_LOGIC_INPUT;
399431

Previous 199869 Revisions Next


© 1997-2024 The MAME Team