diff options
Diffstat (limited to 'src/emu/machine/netlist.h')
-rw-r--r-- | src/emu/machine/netlist.h | 144 |
1 files changed, 82 insertions, 62 deletions
diff --git a/src/emu/machine/netlist.h b/src/emu/machine/netlist.h index c6e8e2ce396..ed93abbed3d 100644 --- a/src/emu/machine/netlist.h +++ b/src/emu/machine/netlist.h @@ -28,7 +28,7 @@ netlist_mame_analog_input_t::static_set_name(*device, _name); #define MCFG_NETLIST_ANALOG_MULT_OFFSET(_mult, _offset) \ - netlist_mame_analog_input_t::static_set_mult_offset(*device, _mult, _offset); + netlist_mame_sub_interface::static_set_mult_offset(*device, _mult, _offset); #define MCFG_NETLIST_ANALOG_OUTPUT(_basetag, _tag, _IN, _class, _member, _class_tag) \ MCFG_DEVICE_ADD(_basetag ":" _tag, NETLIST_ANALOG_OUTPUT, 0) \ @@ -60,20 +60,33 @@ // Extensions to interface netlist with MAME code .... // ---------------------------------------------------------------------------------------- -#define NETLIST_MEMREGION(_name) \ - setup.parse((char *)downcast<netlist_mame_t &>(setup.netlist()).machine().root_device().memregion(_name)->base()); +class netlist_source_memregion_t : public netlist::setup_t::source_t +{ +public: + netlist_source_memregion_t(pstring name) + : netlist::setup_t::source_t(), m_name(name) + { + } + + bool parse(netlist::setup_t *setup, const pstring name); +private: + pstring m_name; +}; + +#define MEMREGION_SOURCE(_name) \ + setup.register_source(palloc(netlist_source_memregion_t(_name))); #define NETDEV_ANALOG_CALLBACK_MEMBER(_name) \ void _name(const double data, const attotime &time) class netlist_mame_device_t; -class netlist_mame_t : public netlist_base_t +class netlist_mame_t : public netlist::netlist_t { public: netlist_mame_t(netlist_mame_device_t &parent) - : netlist_base_t(), + : netlist::netlist_t(), m_parent(parent) {} virtual ~netlist_mame_t() { }; @@ -103,12 +116,12 @@ public: 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 &)); + static void static_set_constructor(device_t &device, void (*setup_func)(netlist::setup_t &)); - ATTR_HOT inline netlist_setup_t &setup() { return *m_setup; } + ATTR_HOT inline netlist::setup_t &setup() { return *m_setup; } ATTR_HOT inline netlist_mame_t &netlist() { return *m_netlist; } - ATTR_HOT inline netlist_time last_time_update() { return m_old; } + ATTR_HOT inline netlist::netlist_time last_time_update() { return m_old; } ATTR_HOT void update_time_x(); ATTR_HOT void check_mame_abort_slice(); @@ -137,12 +150,12 @@ private: /* timing support here - so sound can hijack it ... */ UINT32 m_rem; - netlist_time m_old; + netlist::netlist_time m_old; netlist_mame_t * m_netlist; - netlist_setup_t * m_setup; + netlist::setup_t * m_setup; - void (*m_setup_func)(netlist_setup_t &); + void (*m_setup_func)(netlist::setup_t &); }; inline running_machine &netlist_mame_t::machine() @@ -166,7 +179,7 @@ public: 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 &)); + static void static_set_constructor(device_t &device, void (*setup_func)(netlist::setup_t &)); protected: // netlist_mame_device_t @@ -243,7 +256,7 @@ public: netlist_mame_sound_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); virtual ~netlist_mame_sound_device_t() {} - static void static_set_constructor(device_t &device, void (*setup_func)(netlist_setup_t &)); + static void static_set_constructor(device_t &device, void (*setup_func)(netlist::setup_t &)); inline sound_stream *get_stream() { return m_stream; } @@ -293,7 +306,7 @@ public: } virtual ~netlist_mame_sub_interface() { } - virtual void custom_netlist_additions(netlist_setup_t &setup) { } + virtual void custom_netlist_additions(netlist::setup_t &setup) { } inline netlist_mame_device_t &nl_owner() const { return *m_owner; } @@ -362,7 +375,7 @@ protected: virtual void device_start(); private: - netlist_param_double_t *m_param; + netlist::param_double_t *m_param; bool m_auto_port; pstring m_param_name; }; @@ -387,7 +400,7 @@ public: protected: // device-level overrides virtual void device_start(); - virtual void custom_netlist_additions(netlist_setup_t &setup); + virtual void custom_netlist_additions(netlist::setup_t &setup); private: pstring m_in; @@ -412,16 +425,9 @@ public: inline void write(const UINT32 val) { - if (is_sound_device()) - { - update_to_current_time(); - m_param->setTo((val >> m_shift) & m_mask); - } - else - { - // FIXME: use device timer .... - m_param->setTo((val >> m_shift) & m_mask); - } + const UINT32 v = (val >> m_shift) & m_mask; + if (v != m_param->Value()) + synchronize(0, v); } inline DECLARE_INPUT_CHANGED_MEMBER(input_changed) { write(newval); } @@ -434,9 +440,15 @@ public: protected: // device-level overrides virtual void device_start(); + virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) + { + if (is_sound_device()) + update_to_current_time(); + m_param->setTo(param); + } private: - netlist_param_int_t *m_param; + netlist::param_int_t *m_param; UINT32 m_mask; UINT32 m_shift; pstring m_param_name; @@ -460,7 +472,7 @@ public: protected: // device-level overrides virtual void device_start(); - virtual void custom_netlist_additions(netlist_setup_t &setup); + virtual void custom_netlist_additions(netlist::setup_t &setup); private: UINT32 m_channel; pstring m_param_name; @@ -484,7 +496,7 @@ public: protected: // device-level overrides virtual void device_start(); - virtual void custom_netlist_additions(netlist_setup_t &setup); + virtual void custom_netlist_additions(netlist::setup_t &setup); private: UINT32 m_channel; pstring m_out_name; @@ -493,11 +505,11 @@ private: // netdev_callback // ---------------------------------------------------------------------------------------- -class NETLIB_NAME(analog_callback) : public netlist_device_t +class NETLIB_NAME(analog_callback) : public netlist::device_t { public: NETLIB_NAME(analog_callback)() - : netlist_device_t(), m_cpu_device(NULL), m_last(0) { } + : device_t(), m_cpu_device(NULL), m_last(0) { } ATTR_COLD void start() { @@ -532,7 +544,7 @@ public: } private: - netlist_analog_input_t m_in; + netlist::analog_input_t m_in; netlist_analog_output_delegate m_callback; netlist_mame_cpu_device_t *m_cpu_device; nl_double m_last; @@ -542,11 +554,11 @@ private: // sound_out // ---------------------------------------------------------------------------------------- -class NETLIB_NAME(sound_out) : public netlist_device_t +class NETLIB_NAME(sound_out) : public netlist::device_t { public: NETLIB_NAME(sound_out)() - : netlist_device_t() { } + : netlist::device_t() { } static const int BUFSIZE = 2048; @@ -556,63 +568,71 @@ public: register_param("CHAN", m_channel, 0); register_param("MULT", m_mult, 1000.0); register_param("OFFSET", m_offset, 0.0); - m_sample = netlist_time::from_hz(1); //sufficiently big enough + m_sample = netlist::netlist_time::from_hz(1); //sufficiently big enough save(NAME(m_last_buffer)); } ATTR_COLD void reset() { - m_cur = 0; + m_cur = 0.0; m_last_pos = 0; - m_last_buffer = netlist_time::zero; + m_last_buffer = netlist::netlist_time::zero; } - ATTR_HOT void sound_update(const netlist_time upto) + ATTR_HOT void sound_update(const netlist::netlist_time upto) { int pos = (upto - m_last_buffer) / m_sample; if (pos >= BUFSIZE) netlist().error("sound %s: exceeded BUFSIZE\n", name().cstr()); while (m_last_pos < pos ) { - m_buffer[m_last_pos++] = m_cur; + m_buffer[m_last_pos++] = (stream_sample_t) m_cur; } } ATTR_HOT void update() { - nl_double val = INPANALOG(m_in); + nl_double val = INPANALOG(m_in) * m_mult.Value() + m_offset.Value(); sound_update(netlist().time()); - m_cur = (stream_sample_t) (val * m_mult.Value() + m_offset.Value()); + /* ignore spikes */ + if (std::abs(val) < 32767.0) + m_cur = val; + else if (val > 0.0) + m_cur = 32767.0; + else + m_cur = -32767.0; + } - ATTR_HOT void buffer_reset(netlist_time upto) + ATTR_HOT void buffer_reset(netlist::netlist_time upto) { m_last_pos = 0; m_last_buffer = upto; + m_cur = 0.0; } - netlist_param_int_t m_channel; - netlist_param_double_t m_mult; - netlist_param_double_t m_offset; + netlist::param_int_t m_channel; + netlist::param_double_t m_mult; + netlist::param_double_t m_offset; stream_sample_t *m_buffer; - netlist_time m_sample; + netlist::netlist_time m_sample; private: - netlist_analog_input_t m_in; - stream_sample_t m_cur; + netlist::analog_input_t m_in; + double m_cur; int m_last_pos; - netlist_time m_last_buffer; + netlist::netlist_time m_last_buffer; }; // ---------------------------------------------------------------------------------------- // sound_in // ---------------------------------------------------------------------------------------- -class NETLIB_NAME(sound_in) : public netlist_device_t +class NETLIB_NAME(sound_in) : public netlist::device_t { public: NETLIB_NAME(sound_in)() - : netlist_device_t() { } + : netlist::device_t() { } static const int MAX_INPUT_CHANNELS = 10; @@ -622,8 +642,8 @@ public: register_output("Q", m_Q); register_input("FB", m_feedback); - connect(m_feedback, m_Q); - m_inc = netlist_time::from_nsec(1); + connect_late(m_feedback, m_Q); + m_inc = netlist::netlist_time::from_nsec(1); for (int i = 0; i < MAX_INPUT_CHANNELS; i++) @@ -652,7 +672,7 @@ public: if (i != m_num_channel) netlist().error("sound input numbering has to be sequential!"); m_num_channel++; - m_param[i] = dynamic_cast<netlist_param_double_t *>(setup().find_param(m_param_name[i].Value(), true)); + m_param[i] = dynamic_cast<netlist::param_double_t *>(setup().find_param(m_param_name[i].Value(), true)); } } return m_num_channel; @@ -664,7 +684,7 @@ public: { if (m_buffer[i] == NULL) break; // stop, called outside of stream_update - nl_double v = m_buffer[i][m_pos]; + const nl_double v = m_buffer[i][m_pos]; m_param[i]->setTo(v * m_param_mult[i].Value() + m_param_offset[i].Value()); } m_pos++; @@ -676,16 +696,16 @@ public: m_pos = 0; } - netlist_param_str_t m_param_name[MAX_INPUT_CHANNELS]; - netlist_param_double_t *m_param[MAX_INPUT_CHANNELS]; + netlist::param_str_t m_param_name[MAX_INPUT_CHANNELS]; + netlist::param_double_t *m_param[MAX_INPUT_CHANNELS]; stream_sample_t *m_buffer[MAX_INPUT_CHANNELS]; - netlist_param_double_t m_param_mult[MAX_INPUT_CHANNELS]; - netlist_param_double_t m_param_offset[MAX_INPUT_CHANNELS]; - netlist_time m_inc; + netlist::param_double_t m_param_mult[MAX_INPUT_CHANNELS]; + netlist::param_double_t m_param_offset[MAX_INPUT_CHANNELS]; + netlist::netlist_time m_inc; private: - netlist_logic_input_t m_feedback; - netlist_logic_output_t m_Q; + netlist::logic_input_t m_feedback; + netlist::logic_output_t m_Q; int m_pos; int m_num_channel; |