diff options
Diffstat (limited to 'src/devices/machine/netlist.cpp')
-rw-r--r-- | src/devices/machine/netlist.cpp | 145 |
1 files changed, 67 insertions, 78 deletions
diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index ad7bb45fbc2..e0023ebb8d4 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -77,13 +77,70 @@ static netlist::netlist_time_ext nltime_from_attotime(attotime t) return nlmtime; } -#if 0 -static attotime attotime_from_nltime(netlist::netlist_time_ext t) +void netlist_log_csv<1>::open(running_machine &machine, const std::string &name) { - return attotime(t.as_raw() / netlist::netlist_time_ext::resolution(), - (t.as_raw() % netlist::netlist_time_ext::resolution()) * (ATTOSECONDS_PER_SECOND / netlist::netlist_time_ext::resolution())); + m_csv_file = fopen(name.c_str(), "wb"); + m_machine = &machine; +} + +void netlist_log_csv<1>::close() +{ + if (m_csv_file != nullptr) + { + log_flush(); + fclose(m_csv_file); + } +} + +void netlist_log_csv<1>::log_add(char const* param, double value, bool isfloat) +{ + // skip if no file + if (m_csv_file == nullptr) + return; + + // make a new entry + buffer_entry entry = { (*m_machine).scheduler().time(), isfloat, value, param }; + + // flush out half of the old entries if we hit the buffer limit + if (m_buffer.size() >= MAX_BUFFER_ENTRIES) + log_flush(MAX_BUFFER_ENTRIES / 2); + + // fast common case: if we go at the end, just push_back + if (m_buffer.size() == 0 || entry.time >= m_buffer.back().time) + { + m_buffer.push_back(entry); + return; + } + + // find our place in the queue + for (auto cur = m_buffer.rbegin(); cur != m_buffer.rend(); cur++) + if (entry.time >= cur->time) + { + m_buffer.insert(cur.base(), entry); + return; + } + + // if we're too early, drop this entry rather than risk putting an out-of-order + // entry after the last one we flushed +} + +void netlist_log_csv<1>::log_flush(int count) +{ + if (m_csv_file == nullptr) + return; + if (count > m_buffer.size()) + count = m_buffer.size(); + while (count--) + { + auto &entry = m_buffer.front(); + if (entry.isfloat) + fprintf(m_csv_file, "%s,%s,%f\n", entry.time.as_string(), entry.string, entry.value); + else + fprintf(m_csv_file, "%s,%s,%d\n", entry.time.as_string(), entry.string, int(entry.value)); + m_buffer.pop_front(); + } } -#endif + class netlist_mame_device::netlist_mame_t : public netlist::netlist_state_t { @@ -296,9 +353,7 @@ void netlist_mame_analog_input_device::write(const double val) void netlist_mame_analog_input_device::device_timer(emu_timer &timer, device_timer_id id, int param) { update_to_current_time(); -#if NETLIST_CREATE_CSV - nl_owner().log_add(m_param_name, m_value_for_device_timer, true); -#endif + nl_owner().log_csv().log_add(m_param_name, m_value_for_device_timer, true); m_param->set(m_value_for_device_timer); } @@ -325,18 +380,14 @@ void netlist_mame_logic_input_device::write(const uint32_t val) void netlist_mame_int_input_device::device_timer(emu_timer &timer, device_timer_id id, int param) { update_to_current_time(); -#if NETLIST_CREATE_CSV - nl_owner().log_add(m_param_name, param, false); -#endif + nl_owner().log_csv().log_add(m_param_name, param, false); m_param->set(param); } void netlist_mame_logic_input_device::device_timer(emu_timer &timer, device_timer_id id, int param) { update_to_current_time(); -#if NETLIST_CREATE_CSV - nl_owner().log_add(m_param_name, param, false); -#endif + nl_owner().log_csv().log_add(m_param_name, param, false); m_param->set(param); } @@ -374,56 +425,6 @@ void netlist_mame_sub_interface::set_mult_offset(const double mult, const double m_offset = offset; } -#if NETLIST_CREATE_CSV -void netlist_mame_device::log_add(char const* param, double value, bool isfloat) -{ - // skip if no file - if (m_csv_file == nullptr) - return; - - // make a new entry - buffer_entry entry = { machine().scheduler().time(), isfloat, value, param }; - - // flush out half of the old entries if we hit the buffer limit - if (m_buffer.size() >= MAX_BUFFER_ENTRIES) - log_flush(MAX_BUFFER_ENTRIES / 2); - - // fast common case: if we go at the end, just push_back - if (m_buffer.size() == 0 || entry.time >= m_buffer.back().time) - { - m_buffer.push_back(entry); - return; - } - - // find our place in the queue - for (auto cur = m_buffer.rbegin(); cur != m_buffer.rend(); cur++) - if (entry.time >= cur->time) - { - m_buffer.insert(cur.base(), entry); - return; - } - - // if we're too early, drop this entry rather than risk putting an out-of-order - // entry after the last one we flushed -} - -void netlist_mame_device::log_flush(int count) -{ - if (m_csv_file == nullptr) - return; - if (count > m_buffer.size()) - count = m_buffer.size(); - while (count--) - { - auto &entry = m_buffer.front(); - if (entry.isfloat) - fprintf(m_csv_file, "%s,%s,%f\n", entry.time.as_string(), entry.string, entry.value); - else - fprintf(m_csv_file, "%s,%s,%d\n", entry.time.as_string(), entry.string, int(entry.value)); - m_buffer.pop_front(); - } -} -#endif netlist_mame_analog_input_device::netlist_mame_analog_input_device(const machine_config &mconfig, const char *tag, device_t *owner, const char *param_name) : device_t(mconfig, NETLIST_ANALOG_INPUT, tag, owner, 0) @@ -814,10 +815,6 @@ void netlist_mame_stream_output_device::device_start() void netlist_mame_stream_output_device::device_reset() { LOGDEVCALLS("reset %s\n", name()); -#if 0 - m_cur = 0.0; - m_last_buffer_time = netlist::netlist_time_ext::zero(); -#endif } void netlist_mame_stream_output_device::sound_update_fill(write_stream_view &target) @@ -1051,15 +1048,13 @@ void netlist_mame_device::device_start_common() m_device_reset_called = false; -#if NETLIST_CREATE_CSV std::string name = machine().system().name; name += tag(); for (int index = 0; index < name.size(); index++) if (name[index] == ':') name[index] = '_'; name += ".csv"; - m_csv_file = fopen(name.c_str(), "wb"); -#endif + log_csv().open(machine(), name); LOGDEVCALLS("device_start exit\n"); } @@ -1097,13 +1092,7 @@ void netlist_mame_device::device_stop() LOGDEVCALLS("device_stop\n"); if (m_netlist) netlist().exec().stop(); -#if NETLIST_CREATE_CSV - if (m_csv_file != nullptr) - { - log_flush(); - fclose(m_csv_file); - } -#endif + log_csv().close(); } void netlist_mame_device::device_post_load() |