diff options
Diffstat (limited to 'src/emu/machine.cpp')
-rw-r--r-- | src/emu/machine.cpp | 150 |
1 files changed, 49 insertions, 101 deletions
diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp index 346f907c0a7..c2f0a2c85e3 100644 --- a/src/emu/machine.cpp +++ b/src/emu/machine.cpp @@ -115,13 +115,13 @@ osd_interface &running_machine::osd() const //------------------------------------------------- running_machine::running_machine(const machine_config &_config, machine_manager &manager) - : firstcpu(NULL), - primary_screen(NULL), + : firstcpu(nullptr), + primary_screen(nullptr), debug_flags(0), - romload_data(NULL), - ui_input_data(NULL), - debugcpu_data(NULL), - generic_machine_data(NULL), + romload_data(nullptr), + ui_input_data(nullptr), + debugcpu_data(nullptr), + generic_machine_data(nullptr), m_config(_config), m_system(_config.gamedrv()), m_manager(manager), @@ -129,14 +129,14 @@ running_machine::running_machine(const machine_config &_config, machine_manager m_paused(false), m_hard_reset_pending(false), m_exit_pending(false), - m_soft_reset_timer(NULL), + m_soft_reset_timer(nullptr), m_rand_seed(0x9d14abd7), m_ui_active(_config.options().ui_active()), m_basename(_config.gamedrv().name), m_sample_rate(_config.options().sample_rate()), m_saveload_schedule(SLS_NONE), m_saveload_schedule_time(attotime::zero), - m_saveload_searchpath(NULL), + m_saveload_searchpath(nullptr), m_save(*this), m_memory(*this), @@ -148,12 +148,12 @@ running_machine::running_machine(const machine_config &_config, machine_manager // set the machine on all devices device_iterator iter(root_device()); - for (device_t *device = iter.first(); device != NULL; device = iter.next()) + for (device_t *device = iter.first(); device != nullptr; device = iter.next()) device->set_machine(*this); // find devices - for (device_t *device = iter.first(); device != NULL; device = iter.next()) - if (dynamic_cast<cpu_device *>(device) != NULL) + for (device_t *device = iter.first(); device != nullptr; device = iter.next()) + if (dynamic_cast<cpu_device *>(device) != nullptr) { firstcpu = downcast<cpu_device *>(device); break; @@ -185,10 +185,10 @@ running_machine::~running_machine() const char *running_machine::describe_context() { device_execute_interface *executing = m_scheduler.currently_executing(); - if (executing != NULL) + if (executing != nullptr) { cpu_device *cpu = dynamic_cast<cpu_device *>(&executing->device()); - if (cpu != NULL) + if (cpu != nullptr) strprintf(m_context, "'%s' (%s)", cpu->tag(), core_i64_format(cpu->pc(), cpu->space(AS_PROGRAM).logaddrchars(), cpu->is_octal())); } else @@ -218,9 +218,9 @@ void running_machine::start() { // initialize basic can't-fail systems here config_init(*this); - m_input.reset(global_alloc(input_manager(*this))); + m_input = std::make_unique<input_manager>(*this); output_init(*this); - m_render.reset(global_alloc(render_manager(*this))); + m_render = std::make_unique<render_manager>(*this); generic_machine_init(*this); // allocate a soft_reset timer @@ -230,8 +230,8 @@ void running_machine::start() m_manager.osd().init(*this); // create the video manager - m_video.reset(global_alloc(video_manager(*this))); - m_ui.reset(global_alloc(ui_manager(*this))); + m_video = std::make_unique<video_manager>(*this); + m_ui = std::make_unique<ui_manager>(*this); // initialize the base time (needed for doing record/playback) ::time(&m_base_time); @@ -247,7 +247,7 @@ void running_machine::start() ui_input_init(*this); // initialize the streams engine before the sound devices start - m_sound.reset(global_alloc(sound_manager(*this))); + m_sound = std::make_unique<sound_manager>(*this); // first load ROMs, then populate memory, and finally initialize CPUs // these operations must proceed in this order @@ -257,7 +257,7 @@ void running_machine::start() // initialize the watchdog m_watchdog_counter = 0; m_watchdog_timer = m_scheduler.timer_alloc(timer_expired_delegate(FUNC(running_machine::watchdog_fired), this)); - if (config().m_watchdog_vblank_count != 0 && primary_screen != NULL) + if (config().m_watchdog_vblank_count != 0 && primary_screen != nullptr) primary_screen->register_vblank_callback(vblank_state_delegate(FUNC(running_machine::watchdog_vblank), this)); save().save_item(NAME(m_watchdog_enabled)); save().save_item(NAME(m_watchdog_counter)); @@ -267,7 +267,7 @@ void running_machine::start() // initialize image devices image_init(*this); - m_tilemap.reset(global_alloc(tilemap_manager(*this))); + m_tilemap = std::make_unique<tilemap_manager>(*this); crosshair_init(*this); network_init(*this); @@ -299,7 +299,7 @@ void running_machine::start() schedule_load("auto"); // set up the cheat engine - m_cheat.reset(global_alloc(cheat_manager(*this))); + m_cheat = std::make_unique<cheat_manager>(*this); // allocate autoboot timer m_autoboot_timer = scheduler().timer_alloc(timer_expired_delegate(FUNC(running_machine::autoboot_callback), this)); @@ -309,24 +309,6 @@ void running_machine::start() //------------------------------------------------- -// add_dynamic_device - dynamically add a device -//------------------------------------------------- - -device_t &running_machine::add_dynamic_device(device_t &owner, device_type type, const char *tag, UINT32 clock) -{ - // add the device in a standard manner - device_t *device = const_cast<machine_config &>(m_config).device_add(&owner, tag, type, clock); - - // notify this device and all its subdevices that they are now configured - device_iterator iter(root_device()); - for (device_t *dev = iter.first(); dev != NULL; dev = iter.next()) - if (!dev->configured()) - dev->config_complete(); - return *device; -} - - -//------------------------------------------------- // run - execute the machine //------------------------------------------------- @@ -343,7 +325,7 @@ int running_machine::run(bool firstrun) // if we have a logfile, set up the callback if (options().log() && &system() != &GAME_NAME(___empty)) { - m_logfile.reset(global_alloc(emu_file(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS))); + m_logfile = std::make_unique<emu_file>(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); file_error filerr = m_logfile->open("error.log"); assert_always(filerr == FILERR_NONE, "unable to open log file"); add_logerror_callback(logfile_callback); @@ -372,11 +354,6 @@ int running_machine::run(bool firstrun) // perform a soft reset -- this takes us to the running phase soft_reset(); -#ifdef MAME_DEBUG - g_tagmap_finds = 0; - if (strcmp(config().m_gamedrv.name, "___empty") != 0) - g_tagmap_counter_enabled = true; -#endif // handle initial load if (m_saveload_schedule != SLS_NONE) handle_saveload(); @@ -410,15 +387,6 @@ int running_machine::run(bool firstrun) // and out via the exit phase m_current_phase = MACHINE_PHASE_EXIT; -#ifdef MAME_DEBUG - if (g_tagmap_counter_enabled) - { - g_tagmap_counter_enabled = false; - if (*(options().command()) == 0) - osd_printf_info("%d tagmap lookups\n", g_tagmap_finds); - } -#endif - // save the NVRAM and configuration sound().ui_mute(true); nvram_save(); @@ -461,15 +429,6 @@ int running_machine::run(bool firstrun) // in case we got here via exception m_current_phase = MACHINE_PHASE_EXIT; -#ifdef MAME_DEBUG - if (g_tagmap_counter_enabled) - { - g_tagmap_counter_enabled = false; - if (*(options().command()) == 0) - osd_printf_info("%d tagmap lookups\n", g_tagmap_finds); - } -#endif - // call all exit callbacks registered call_notifiers(MACHINE_NOTIFY_EXIT); zip_file_cache_clear(); @@ -491,15 +450,6 @@ void running_machine::schedule_exit() // if we're executing, abort out immediately m_scheduler.eat_all_cycles(); -#ifdef MAME_DEBUG - if (g_tagmap_counter_enabled) - { - g_tagmap_counter_enabled = false; - if (*(options().command()) == 0) - osd_printf_info("%d tagmap lookups\n", g_tagmap_finds); - } -#endif - // if we're autosaving on exit, schedule a save as well if (options().autosave() && (m_system.flags & MACHINE_SUPPORTS_SAVE) && this->time() > attotime::zero) schedule_save("auto"); @@ -548,7 +498,7 @@ void running_machine::schedule_soft_reset() std::string running_machine::get_statename(const char *option) { std::string statename_str(""); - if (option == NULL || option[0] == 0) + if (option == nullptr || option[0] == 0) statename_str.assign("%g"); else statename_str.assign(option); @@ -596,7 +546,7 @@ std::string running_machine::get_statename(const char *option) // verify that there is such a device for this system image_interface_iterator iter(root_device()); - for (device_image_interface *image = iter.first(); image != NULL; image = iter.next()) + for (device_image_interface *image = iter.first(); image != nullptr; image = iter.next()) { // get the device name std::string tempdevname(image->brief_instance_name()); @@ -605,7 +555,7 @@ std::string running_machine::get_statename(const char *option) if (devname_str.compare(tempdevname) == 0) { // verify that such a device has an image mounted - if (image->basename_noext() != NULL) + if (image->basename_noext() != nullptr) { std::string filename(image->basename_noext()); @@ -642,7 +592,7 @@ void running_machine::set_saveload_filename(const char *filename) // free any existing request and allocate a copy of the requested name if (osd_is_absolute_path(filename)) { - m_saveload_searchpath = NULL; + m_saveload_searchpath = nullptr; m_saveload_pending_file.assign(filename); } else @@ -786,11 +736,11 @@ void running_machine::add_notifier(machine_notification event, machine_notify_de // exit notifiers are added to the head, and executed in reverse order if (event == MACHINE_NOTIFY_EXIT) - m_notifier_list[event].prepend(*global_alloc(notifier_callback_item(callback))); + m_notifier_list[event].push_front(std::make_unique<notifier_callback_item>(callback)); // all other notifiers are added to the tail, and executed in the order registered else - m_notifier_list[event].append(*global_alloc(notifier_callback_item(callback))); + m_notifier_list[event].push_back(std::make_unique<notifier_callback_item>(callback)); } @@ -802,7 +752,7 @@ void running_machine::add_notifier(machine_notification event, machine_notify_de void running_machine::add_logerror_callback(logerror_callback callback) { assert_always(m_current_phase == MACHINE_PHASE_INIT, "Can only call add_logerror_callback at init time!"); - m_logerror_list.append(*global_alloc(logerror_callback_item(callback))); + m_logerror_list.push_back(std::make_unique<logerror_callback_item>(callback)); } /*------------------------------------------------- @@ -812,7 +762,7 @@ void running_machine::add_logerror_callback(logerror_callback callback) void running_machine::popmessage(const char *format, ...) const { // if the format is NULL, it is a signal to clear the popmessage - if (format == NULL) + if (format == nullptr) ui().popup_time(0, " "); // otherwise, generate the buffer and call the UI to display the message @@ -853,7 +803,7 @@ void running_machine::logerror(const char *format, ...) const void running_machine::vlogerror(const char *format, va_list args) const { // process only if there is a target - if (m_logerror_list.first() != NULL) + if (!m_logerror_list.empty()) { g_profiler.start(PROFILER_LOGERROR); @@ -861,8 +811,8 @@ void running_machine::vlogerror(const char *format, va_list args) const vsnprintf(giant_string_buffer, ARRAY_LENGTH(giant_string_buffer), format, args); // log to all callbacks - for (logerror_callback_item *cb = m_logerror_list.first(); cb != NULL; cb = cb->next()) - (*cb->m_func)(*this, giant_string_buffer); + for (auto& cb : m_logerror_list) + (cb->m_func)(*this, giant_string_buffer); g_profiler.stop(); } @@ -913,7 +863,7 @@ UINT32 running_machine::rand() void running_machine::call_notifiers(machine_notification which) { - for (notifier_callback_item *cb = m_notifier_list[which].first(); cb != NULL; cb = cb->next()) + for (auto& cb : m_notifier_list[which]) cb->m_func(); } @@ -996,7 +946,7 @@ void running_machine::handle_saveload() // unschedule the operation cancel: m_saveload_pending_file.clear(); - m_saveload_searchpath = NULL; + m_saveload_searchpath = nullptr; m_saveload_schedule = SLS_NONE; } @@ -1112,7 +1062,7 @@ void running_machine::watchdog_vblank(screen_device &screen, bool vblank_state) void running_machine::logfile_callback(const running_machine &machine, const char *buffer) { - if (machine.m_logfile != NULL) + if (machine.m_logfile != nullptr) machine.m_logfile->puts(buffer); } @@ -1130,14 +1080,14 @@ void running_machine::start_all_devices() // iterate over all devices int failed_starts = 0; device_iterator iter(root_device()); - for (device_t *device = iter.first(); device != NULL; device = iter.next()) + for (device_t *device = iter.first(); device != nullptr; device = iter.next()) if (!device->started()) { // attempt to start the device, catching any expected exceptions try { // if the device doesn't have a machine yet, set it first - if (device->m_machine == NULL) + if (device->m_machine == nullptr) device->set_machine(*this); // now start the device @@ -1188,7 +1138,7 @@ void running_machine::stop_all_devices() // iterate over devices and stop them device_iterator iter(root_device()); - for (device_t *device = iter.first(); device != NULL; device = iter.next()) + for (device_t *device = iter.first(); device != nullptr; device = iter.next()) device->stop(); } @@ -1201,7 +1151,7 @@ void running_machine::stop_all_devices() void running_machine::presave_all_devices() { device_iterator iter(root_device()); - for (device_t *device = iter.first(); device != NULL; device = iter.next()) + for (device_t *device = iter.first(); device != nullptr; device = iter.next()) device->pre_save(); } @@ -1214,7 +1164,7 @@ void running_machine::presave_all_devices() void running_machine::postload_all_devices() { device_iterator iter(root_device()); - for (device_t *device = iter.first(); device != NULL; device = iter.next()) + for (device_t *device = iter.first(); device != nullptr; device = iter.next()) device->post_load(); } @@ -1228,14 +1178,14 @@ const char *running_machine::image_parent_basename(device_t *device) device_t *dev = device; while(dev != &root_device()) { - device_image_interface *intf = NULL; - if (dev!=NULL && dev->interface(intf)) + device_image_interface *intf = nullptr; + if (dev!=nullptr && dev->interface(intf)) { return intf->basename_noext(); } dev = dev->owner(); } - return NULL; + return nullptr; } /*------------------------------------------------- @@ -1255,7 +1205,7 @@ std::string &running_machine::nvram_filename(std::string &result, device_t &devi { // add per software nvrams into one folder const char *software = image_parent_basename(&device); - if (software!=NULL && strlen(software)>0) + if (software!=nullptr && strlen(software)>0) { result.append(PATH_SEPARATOR).append(software); } @@ -1274,7 +1224,7 @@ std::string &running_machine::nvram_filename(std::string &result, device_t &devi void running_machine::nvram_load() { nvram_interface_iterator iter(root_device()); - for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next()) + for (device_nvram_interface *nvram = iter.first(); nvram != nullptr; nvram = iter.next()) { std::string filename; emu_file file(options().nvram_directory(), OPEN_FLAG_READ); @@ -1296,7 +1246,7 @@ void running_machine::nvram_load() void running_machine::nvram_save() { nvram_interface_iterator iter(root_device()); - for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next()) + for (device_nvram_interface *nvram = iter.first(); nvram != nullptr; nvram = iter.next()) { std::string filename; emu_file file(options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); @@ -1316,8 +1266,7 @@ void running_machine::nvram_save() //------------------------------------------------- running_machine::notifier_callback_item::notifier_callback_item(machine_notify_delegate func) - : m_next(NULL), - m_func(func) + : m_func(std::move(func)) { } @@ -1327,8 +1276,7 @@ running_machine::notifier_callback_item::notifier_callback_item(machine_notify_d //------------------------------------------------- running_machine::logerror_callback_item::logerror_callback_item(logerror_callback func) - : m_next(NULL), - m_func(func) + : m_func(func) { } |