Split netlist_mame_device_t into a core device and a "cpu" device. Based on this setup, work can start on "pure" sound devices.

This commit is contained in:
Couriersud 2013-12-28 21:20:40 +00:00
parent 1eac5f4e9e
commit f03fe6e80a
2 changed files with 171 additions and 109 deletions

View File

@ -54,13 +54,19 @@
//#define LOG_DEV_CALLS(x) printf x
#define LOG_DEV_CALLS(x) do { } while (0)
const device_type NETLIST = &device_creator<netlist_mame_device_t>;
const device_type NETLIST_CORE = &device_creator<netlist_mame_device_t>;
const device_type NETLIST_CPU = &device_creator<netlist_mame_cpu_device_t>;
const device_type NETLIST_ANALOG_INPUT = &device_creator<netlist_mame_analog_input_t>;
const device_type NETLIST_LOGIC_INPUT = &device_creator<netlist_mame_logic_input_t>;
// ----------------------------------------------------------------------------------------
// netlist_mame_analog_input_t
// ----------------------------------------------------------------------------------------
netlist_mame_analog_input_t::netlist_mame_analog_input_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, NETLIST_ANALOG_INPUT, "netlist analog input", tag, owner, clock, "netlist_analog_input", __FILE__),
netlist_mame_sub_interface(*this),
m_param(0),
m_offset(0.0),
m_mult(1.0),
m_auto_port(true),
@ -97,6 +103,7 @@ void netlist_mame_analog_input_t::device_start()
netlist_mame_logic_input_t::netlist_mame_logic_input_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, NETLIST_ANALOG_INPUT, "netlist analog input", tag, owner, clock, "netlist_analog_input", __FILE__),
netlist_mame_sub_interface(*this),
m_param(0),
m_mask(0xffffffff),
m_shift(0),
m_param_name("")
@ -124,7 +131,7 @@ void netlist_mame_logic_input_t::device_start()
// ----------------------------------------------------------------------------------------
// netlist_mame_device
// netlist_mame_device_t
// ----------------------------------------------------------------------------------------
static ADDRESS_MAP_START(program_dummy, AS_PROGRAM, 8, netlist_mame_device_t)
@ -132,17 +139,18 @@ static ADDRESS_MAP_START(program_dummy, AS_PROGRAM, 8, netlist_mame_device_t)
ADDRESS_MAP_END
netlist_mame_device_t::netlist_mame_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, NETLIST, "netlist", tag, owner, clock, "netlist_mame", __FILE__),
device_execute_interface(mconfig, *this),
device_state_interface(mconfig, *this),
device_disasm_interface(mconfig, *this),
device_memory_interface(mconfig, *this),
m_program_config("program", ENDIANNESS_LITTLE, 8, 12, 0, ADDRESS_MAP_NAME(program_dummy)),
m_netlist(NULL),
m_setup(NULL),
m_setup_func(NULL),
m_icount(0),
m_genPC(0)
: device_t(mconfig, NETLIST_CORE, "Netlist core device", tag, owner, clock, "netlist_core", __FILE__),
m_netlist(NULL),
m_setup(NULL),
m_setup_func(NULL)
{
}
netlist_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)
: device_t(mconfig, type, name, tag, owner, clock, shortname, file),
m_netlist(NULL),
m_setup(NULL),
m_setup_func(NULL)
{
}
@ -164,10 +172,10 @@ void netlist_mame_device_t::device_start()
m_netlist = global_alloc_clear(netlist_mame_t(*this));
m_setup = global_alloc_clear(netlist_setup_t(*m_netlist));
m_netlist->init_object(*m_netlist, "netlist");
netlist().init_object(*m_netlist, "netlist");
m_setup->init();
m_netlist->set_clock_freq(this->clock());
netlist().set_clock_freq(this->clock());
// register additional devices
@ -191,31 +199,12 @@ void netlist_mame_device_t::device_start()
save_state();
// State support
state_add(STATE_GENPC, "curpc", m_genPC).noshow();
for (int i=0; i < m_netlist->m_nets.count(); i++)
{
netlist_net_t *n = m_netlist->m_nets[i];
if (n->isRailNet())
{
state_add(i*2, n->name(), n->Q_state_ptr());
}
else
{
state_add(i*2+1, n->name(), n->Q_Analog_state_ptr()).formatstr("%20s");
}
}
// set our instruction counter
m_icountptr = &m_icount;
}
void netlist_mame_device_t::device_reset()
{
LOG_DEV_CALLS(("device_reset\n"));
m_netlist->reset();
netlist().reset();
}
void netlist_mame_device_t::device_stop()
@ -233,25 +222,23 @@ ATTR_COLD void netlist_mame_device_t::device_post_load()
{
LOG_DEV_CALLS(("device_post_load\n"));
m_netlist->post_load();
netlist().post_load();
}
ATTR_COLD void netlist_mame_device_t::device_pre_save()
{
LOG_DEV_CALLS(("device_pre_save\n"));
m_netlist->pre_save();
netlist().pre_save();
}
void netlist_mame_device_t::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
}
ATTR_COLD void netlist_mame_device_t::save_state()
{
for (pstate_entry_t::list_t::entry_t *p = m_netlist->save_list().first(); p != NULL; p = m_netlist->save_list().next(p))
for (pstate_entry_t::list_t::entry_t *p = netlist().save_list().first(); p != NULL; p = netlist().save_list().next(p))
{
pstate_entry_t *s = p->object();
NL_VERBOSE_OUT(("saving state for %s\n", s->m_name.cstr()));
@ -275,24 +262,67 @@ ATTR_COLD void netlist_mame_device_t::save_state()
case DT_CUSTOM:
case NOT_SUPPORTED:
default:
m_netlist->xfatalerror("found unsupported save element %s\n", s->m_name.cstr());
netlist().xfatalerror("found unsupported save element %s\n", s->m_name.cstr());
break;
}
}
}
ATTR_COLD UINT64 netlist_mame_device_t::execute_clocks_to_cycles(UINT64 clocks) const
// ----------------------------------------------------------------------------------------
// netlist_mame_cpu_device_t
// ----------------------------------------------------------------------------------------
netlist_mame_cpu_device_t::netlist_mame_cpu_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: netlist_mame_device_t(mconfig, NETLIST_CPU, "Netlist cpu device", tag, owner, clock, "netlist_cpu", __FILE__),
device_execute_interface(mconfig, *this),
device_state_interface(mconfig, *this),
device_disasm_interface(mconfig, *this),
device_memory_interface(mconfig, *this),
m_program_config("program", ENDIANNESS_LITTLE, 8, 12, 0, ADDRESS_MAP_NAME(program_dummy)),
m_icount(0)
{
}
void netlist_mame_cpu_device_t::device_start()
{
netlist_mame_device_t::device_start();
LOG_DEV_CALLS(("device_start %s\n", tag()));
// State support
state_add(STATE_GENPC, "curpc", m_genPC).noshow();
for (int i=0; i < netlist().m_nets.count(); i++)
{
netlist_net_t *n = netlist().m_nets[i];
if (n->isRailNet())
{
state_add(i*2, n->name(), n->Q_state_ptr());
}
else
{
state_add(i*2+1, n->name(), n->Q_Analog_state_ptr()).formatstr("%20s");
}
}
// set our instruction counter
m_icountptr = &m_icount;
}
ATTR_COLD UINT64 netlist_mame_cpu_device_t::execute_clocks_to_cycles(UINT64 clocks) const
{
return clocks;
}
ATTR_COLD UINT64 netlist_mame_device_t::execute_cycles_to_clocks(UINT64 cycles) const
ATTR_COLD UINT64 netlist_mame_cpu_device_t::execute_cycles_to_clocks(UINT64 cycles) const
{
return cycles;
}
ATTR_COLD offs_t netlist_mame_device_t::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
ATTR_COLD offs_t netlist_mame_cpu_device_t::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
{
//char tmp[16];
unsigned startpc = pc;
@ -300,12 +330,12 @@ ATTR_COLD offs_t netlist_mame_device_t::disasm_disassemble(char *buffer, offs_t
//UINT16 opcode = (oprom[pc - startpc] << 8) | oprom[pc+1 - startpc];
//UINT8 inst = opcode >> 13;
if (relpc >= 0 && relpc < m_netlist->queue().count())
if (relpc >= 0 && relpc < netlist().queue().count())
{
// sprintf(buffer, "%04x %02d %s", pc, relpc, m_netlist->queue()[m_netlist->queue().count() - relpc - 1].object().name().cstr());
int dpc = m_netlist->queue().count() - relpc - 1;
sprintf(buffer, "%c %s @%10.7f", (relpc == 0) ? '*' : ' ', m_netlist->queue()[dpc].object().name().cstr(),
m_netlist->queue()[dpc].time().as_double());
// sprintf(buffer, "%04x %02d %s", pc, relpc, netlist().queue()[netlist().queue().count() - relpc - 1].object().name().cstr());
int dpc = netlist().queue().count() - relpc - 1;
sprintf(buffer, "%c %s @%10.7f", (relpc == 0) ? '*' : ' ', netlist().queue()[dpc].object().name().cstr(),
netlist().queue()[dpc].time().as_double());
}
else
sprintf(buffer, "%s", "");
@ -313,7 +343,7 @@ ATTR_COLD offs_t netlist_mame_device_t::disasm_disassemble(char *buffer, offs_t
return (pc - startpc);
}
ATTR_HOT void netlist_mame_device_t::execute_run()
ATTR_HOT void netlist_mame_cpu_device_t::execute_run()
{
bool check_debugger = ((device_t::machine().debug_flags & DEBUG_FLAG_ENABLED) != 0);
// debugging
@ -326,10 +356,10 @@ ATTR_HOT void netlist_mame_device_t::execute_run()
m_genPC++;
m_genPC &= 255;
debugger_instruction_hook(this, m_genPC);
m_netlist->process_queue(m_temp);
netlist().process_queue(m_temp);
m_icount -= (1 - m_temp);
}
}
else
m_netlist->process_queue(m_icount);
netlist().process_queue(m_icount);
}

View File

@ -57,11 +57,11 @@
// MAME specific configuration
#define MCFG_NETLIST_ADD(_tag, _setup ) \
MCFG_DEVICE_ADD(_tag, NETLIST, NETLIST_CLOCK) \
MCFG_DEVICE_ADD(_tag, NETLIST_CPU, NETLIST_CLOCK) \
MCFG_NETLIST_SETUP(_setup)
#define MCFG_NETLIST_REPLACE(_tag, _setup) \
MCFG_DEVICE_REPLACE(_tag, NETLIST, NETLIST_CLOCK) \
MCFG_DEVICE_REPLACE(_tag, NETLIST_CPU, NETLIST_CLOCK) \
MCFG_NETLIST_SETUP(_setup)
#define MCFG_NETLIST_SETUP(_setup) \
@ -134,25 +134,22 @@ private:
// netlist_mame_device_t
// ----------------------------------------------------------------------------------------
class netlist_mame_device_t : public device_t,
public device_execute_interface,
public device_state_interface,
public device_disasm_interface,
public device_memory_interface
class netlist_mame_device_t : public device_t
{
public:
// construction/destruction
netlist_mame_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
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);
virtual ~netlist_mame_device_t() {}
static void static_set_constructor(device_t &device, void (*setup_func)(netlist_setup_t &));
netlist_setup_t &setup() { return *m_setup; }
netlist_mame_t &netlist() { return *m_netlist; }
ATTR_HOT inline netlist_setup_t &setup() { return *m_setup; }
ATTR_HOT inline netlist_mame_t &netlist() { return *m_netlist; }
protected:
// device-level overrides
// device_t overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_stop();
@ -160,54 +157,14 @@ protected:
virtual void device_post_load();
virtual void device_pre_save();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
virtual UINT64 execute_clocks_to_cycles(UINT64 clocks) const;
virtual UINT64 execute_cycles_to_clocks(UINT64 cycles) const;
ATTR_HOT virtual void execute_run();
// device_disasm_interface overrides
ATTR_COLD virtual UINT32 disasm_min_opcode_bytes() const { return 1; }
ATTR_COLD virtual UINT32 disasm_max_opcode_bytes() const { return 1; }
ATTR_COLD virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);
// device_memory_interface overrides
address_space_config m_program_config;
virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const
{
switch (spacenum)
{
case AS_PROGRAM: return &m_program_config;
case AS_IO: return NULL;
default: return NULL;
}
}
virtual void state_string_export(const device_state_entry &entry, astring &string)
{
if (entry.index() >= 0)
{
if (entry.index() & 1)
string.format("%10.6f", *((double *) entry.dataptr()));
else
string.format("%d", *((netlist_sig_t *) entry.dataptr()));
}
}
netlist_mame_t *m_netlist;
netlist_setup_t *m_setup;
private:
void save_state();
void save_state();
netlist_mame_t *m_netlist;
netlist_setup_t *m_setup;
void (*m_setup_func)(netlist_setup_t &);
int m_icount;
int m_genPC;
};
inline running_machine &netlist_mame_t::machine()
@ -215,6 +172,80 @@ inline running_machine &netlist_mame_t::machine()
return m_parent.machine();
}
// ----------------------------------------------------------------------------------------
// netlist_mame_cpu_device_t
// ----------------------------------------------------------------------------------------
class netlist_mame_cpu_device_t : public netlist_mame_device_t,
public device_execute_interface,
public device_state_interface,
public device_disasm_interface,
public device_memory_interface
{
public:
// construction/destruction
netlist_mame_cpu_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
virtual ~netlist_mame_cpu_device_t() {}
static void static_set_constructor(device_t &device, void (*setup_func)(netlist_setup_t &));
protected:
// device_t overrides
//virtual void device_config_complete();
virtual void device_start();
//virtual void device_stop();
//virtual void device_reset();
//virtual void device_post_load();
//virtual void device_pre_save();
//virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
// device_execute_interface overrides
virtual UINT64 execute_clocks_to_cycles(UINT64 clocks) const;
virtual UINT64 execute_cycles_to_clocks(UINT64 cycles) const;
ATTR_HOT virtual void execute_run();
// device_disasm_interface overrides
ATTR_COLD virtual UINT32 disasm_min_opcode_bytes() const { return 1; }
ATTR_COLD virtual UINT32 disasm_max_opcode_bytes() const { return 1; }
ATTR_COLD virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);
// device_memory_interface overrides
address_space_config m_program_config;
virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const
{
switch (spacenum)
{
case AS_PROGRAM: return &m_program_config;
case AS_IO: return NULL;
default: return NULL;
}
}
// device_state_interface overrides
virtual void state_string_export(const device_state_entry &entry, astring &string)
{
if (entry.index() >= 0)
{
if (entry.index() & 1)
string.format("%10.6f", *((double *) entry.dataptr()));
else
string.format("%d", *((netlist_sig_t *) entry.dataptr()));
}
}
private:
int m_icount;
int m_genPC;
};
// ----------------------------------------------------------------------------------------
// netlist_mame_sub_interface
// ----------------------------------------------------------------------------------------
@ -327,6 +358,7 @@ public:
{
register_input("IN", m_in);
m_callback.bind_relative_to(downcast<netlist_mame_t &>(netlist()).machine().root_device());
m_cpu_device = downcast<netlist_mame_cpu_device_t *>(&downcast<netlist_mame_t &>(netlist()).parent());
}
ATTR_COLD void register_callback(netlist_analog_output_delegate callback)
@ -336,14 +368,13 @@ public:
ATTR_HOT void update()
{
// FIXME: Remove after device cleanup
if (!m_callback.isnull())
m_callback(INPANALOG(m_in), downcast<netlist_mame_t &>(netlist()).parent().local_time());
m_callback(INPANALOG(m_in), m_cpu_device->local_time());
}
private:
netlist_analog_input_t m_in;
netlist_analog_output_delegate m_callback;
netlist_mame_cpu_device_t *m_cpu_device;
};
class NETLIB_NAME(sound) : public netlist_device_t
@ -393,7 +424,8 @@ private:
// device type definition
extern const device_type NETLIST;
extern const device_type NETLIST_CORE;
extern const device_type NETLIST_CPU;
extern const device_type NETLIST_ANALOG_INPUT;
extern const device_type NETLIST_LOGIC_INPUT;