void nvram_save(running_machine &machine) { if (machine.config().m_nvram_handler != NULL) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); if (file.open(nvram_filename(machine,filename), ".nv") == FILERR_NONE) { (*machine.config().m_nvram_handler)(machine, &file, TRUE); file.close(); } } device_nvram_interface *nvram = NULL; if (machine.devicelist().first(nvram)) { for (bool gotone = (nvram != NULL); gotone; gotone = nvram->next(nvram)) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); if (file.open(nvram_filename(nvram->device(),filename)) == FILERR_NONE) { nvram->nvram_save(file); file.close(); } } } }
int memcard_create(running_machine &machine, int index, int overwrite) { char name[16]; /* create a name */ memcard_name(index, name); /* if we can't overwrite, fail if the file already exists */ astring fname(machine.basename(), PATH_SEPARATOR, name); if (!overwrite) { emu_file testfile(machine.options().memcard_directory(), OPEN_FLAG_READ); if (testfile.open(fname) == FILERR_NONE) return 1; } /* create a new file */ emu_file file(machine.options().memcard_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); file_error filerr = file.open(fname); if (filerr != FILERR_NONE) return 1; /* initialize and then save the card */ if (machine.config().m_memcard_handler) (*machine.config().m_memcard_handler)(machine, file, MEMCARD_CREATE); /* close the file */ return 0; }
void nvram_load(running_machine &machine) { if (machine.config().m_nvram_handler != NULL) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); if (file.open(nvram_filename(filename, machine.root_device()), ".nv") == FILERR_NONE) { (*machine.config().m_nvram_handler)(machine, &file, FALSE); file.close(); } else { (*machine.config().m_nvram_handler)(machine, NULL, FALSE); } } nvram_interface_iterator iter(machine.root_device()); for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next()) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); if (file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE) { nvram->nvram_load(file); file.close(); } else nvram->nvram_reset(); } }
void memcard_eject(running_machine &machine) { generic_machine_private *state = machine.generic_machine_data; char name[16]; /* if no card is preset, just ignore */ if (state->memcard_inserted == -1) return; /* create a name */ memcard_name(state->memcard_inserted, name); /* open the file; if we can't, it's an error */ emu_file file(machine.options().memcard_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); file_error filerr = file.open(machine.basename(), PATH_SEPARATOR, name); if (filerr != FILERR_NONE) return; /* initialize and then load the card */ if (machine.config().m_memcard_handler) (*machine.config().m_memcard_handler)(machine, file, MEMCARD_EJECT); /* close the file */ state->memcard_inserted = -1; }
void nvram_save(running_machine &machine) { if (machine.config().m_nvram_handler != NULL) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); if (file.open(nvram_filename(filename, machine.root_device()), ".nv") == FILERR_NONE) { (*machine.config().m_nvram_handler)(machine, &file, TRUE); file.close(); } } nvram_interface_iterator iter(machine.root_device()); for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next()) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); if (file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE) { nvram->nvram_save(file); file.close(); } } }
int memcard_insert(running_machine &machine, int index) { generic_machine_private *state = machine.generic_machine_data; char name[16]; /* if a card is already inserted, eject it first */ if (state->memcard_inserted != -1) memcard_eject(machine); assert(state->memcard_inserted == -1); /* create a name */ memcard_name(index, name); /* open the file; if we can't, it's an error */ emu_file file(machine.options().memcard_directory(), OPEN_FLAG_READ); file_error filerr = file.open(machine.basename(), PATH_SEPARATOR, name); if (filerr != FILERR_NONE) return 1; /* initialize and then load the card */ if (machine.config().m_memcard_handler) (*machine.config().m_memcard_handler)(machine, file, MEMCARD_INSERT); /* close the file */ state->memcard_inserted = index; return 0; }
static void watchdog_internal_reset(running_machine &machine) { /* set up the watchdog timer; only start off enabled if explicitly configured */ watchdog_enabled = (machine.config().m_watchdog_vblank_count != 0 || machine.config().m_watchdog_time != attotime::zero); watchdog_reset(machine); watchdog_enabled = TRUE; }
void nvram_load(running_machine &machine) { int overrideNVram = 0; if(netCommon) { if(nvram_size(machine)>=32*1024*1024) { overrideNVram=1; ui_popup_time(3, "The NVRAM for this game is too big, not loading NVRAM."); } } if (machine.config().m_nvram_handler != NULL) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); if (!overrideNVram && file.open(nvram_filename(filename, machine.root_device()), ".nv") == FILERR_NONE) { (*machine.config().m_nvram_handler)(machine, &file, FALSE); file.close(); } else { (*machine.config().m_nvram_handler)(machine, NULL, FALSE); } } nvram_interface_iterator iter(machine.root_device()); for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next()) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); if (file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); if (!overrideNVram && file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE) { nvram->nvram_load(file); file.close(); } else { nvram->nvram_reset(); } } else nvram->nvram_reset(); } }
rom_load_manager::rom_load_manager(running_machine &machine) : m_machine(machine) { /* figure out which BIOS we are using */ device_iterator deviter(machine.config().root_device()); for (device_t *device = deviter.first(); device != nullptr; device = deviter.next()) { if (device->rom_region()) { std::string specbios; if (device->owner() == nullptr) { specbios.assign(machine.options().bios()); } else { specbios = machine.options().sub_value(std::string(device->owner()->tag()).c_str()+1,"bios"); if (specbios.empty()) { specbios = device->default_bios_tag(); } } determine_bios_rom(device, specbios.c_str()); } } /* count the total number of ROMs */ count_roms(); /* reset the disk list */ m_chd_list.clear(); /* process the ROM entries we were passed */ process_region_list(); /* display the results and exit */ display_rom_load_results(FALSE); }
void generic_machine_init(running_machine &machine) { generic_machine_private *state; int counternum; /* allocate our state */ machine.generic_machine_data = auto_alloc_clear(machine, generic_machine_private); state = machine.generic_machine_data; /* reset coin counters */ for (counternum = 0; counternum < COIN_COUNTERS; counternum++) { state->lastcoin[counternum] = 0; state->coinlockedout[counternum] = 0; } /* register coin save state */ machine.save().save_item(NAME(state->coin_count)); machine.save().save_item(NAME(state->coinlockedout)); machine.save().save_item(NAME(state->lastcoin)); /* reset memory card info */ state->memcard_inserted = -1; /* register for configuration */ config_register(machine, "counters", config_saveload_delegate(FUNC(counters_load), &machine), config_saveload_delegate(FUNC(counters_save), &machine)); /* for memory cards, request save state and an exit callback */ if (machine.config().m_memcard_handler != NULL) { machine.save().save_item(NAME(state->memcard_inserted)); machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(memcard_eject), &machine)); } }
void nvram_load(running_machine &machine) { if (machine.config().m_nvram_handler != NULL) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); if (file.open(nvram_filename(machine,filename),".nv") == FILERR_NONE) { (*machine.config().m_nvram_handler)(machine, &file, FALSE); file.close(); } else { (*machine.config().m_nvram_handler)(machine, NULL, FALSE); } } device_nvram_interface *nvram = NULL; if (machine.devicelist().first(nvram)) { for (bool gotone = (nvram != NULL); gotone; gotone = nvram->next(nvram)) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); if (file.open(nvram_filename(nvram->device(),filename)) == FILERR_NONE) { nvram->nvram_load(file); file.close(); } else { nvram->nvram_reset(); } } } }
void watchdog_reset(running_machine &machine) { /* if we're not enabled, skip it */ if (!watchdog_enabled) watchdog_timer->adjust(attotime::never); /* VBLANK-based watchdog? */ else if (machine.config().m_watchdog_vblank_count != 0) { watchdog_counter = machine.config().m_watchdog_vblank_count; /* register a VBLANK callback for the primary screen */ if (machine.primary_screen != NULL) machine.primary_screen->register_vblank_callback(vblank_state_delegate(FUNC(on_vblank), &machine)); } /* timer-based watchdog? */ else if (machine.config().m_watchdog_time != attotime::zero) watchdog_timer->adjust(machine.config().m_watchdog_time); /* default to an obscene amount of time (3 seconds) */ else watchdog_timer->adjust(attotime::from_seconds(3)); }
void nvram_save(running_machine &machine) { static bool first=true; if(netCommon) { if(nvram_size(machine)>=32*1024*1024) { if(first) { ui_popup_time(3, "The NVRAM for this game is too big, not saving NVRAM."); first = false; } return; } } if (machine.config().m_nvram_handler != NULL) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); if (file.open(nvram_filename(filename, machine.root_device()), ".nv") == FILERR_NONE) { (*machine.config().m_nvram_handler)(machine, &file, TRUE); file.close(); } } nvram_interface_iterator iter(machine.root_device()); for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next()) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); if (file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE) { nvram->nvram_save(file); file.close(); } } }
void generic_machine_init(running_machine &machine) { generic_machine_private *state; int counternum; /* allocate our state */ machine.generic_machine_data = auto_alloc_clear(machine, generic_machine_private); state = machine.generic_machine_data; /* reset coin counters */ for (counternum = 0; counternum < COIN_COUNTERS; counternum++) { state->lastcoin[counternum] = 0; state->coinlockedout[counternum] = 0; } // map devices to the interrupt state memset(state->interrupt_device, 0, sizeof(state->interrupt_device)); device_execute_interface *exec = NULL; int index = 0; for (bool gotone = machine.devicelist().first(exec); gotone && index < ARRAY_LENGTH(state->interrupt_device); gotone = exec->next(exec)) state->interrupt_device[index++] = &exec->device(); /* register coin save state */ machine.save().save_item(NAME(state->coin_count)); machine.save().save_item(NAME(state->coinlockedout)); machine.save().save_item(NAME(state->lastcoin)); /* reset memory card info */ state->memcard_inserted = -1; /* register a reset callback and save state for interrupt enable */ machine.add_notifier(MACHINE_NOTIFY_RESET, machine_notify_delegate(FUNC(interrupt_reset), &machine)); machine.save().save_item(NAME(state->interrupt_enable)); /* register for configuration */ config_register(machine, "counters", config_saveload_delegate(FUNC(counters_load), &machine), config_saveload_delegate(FUNC(counters_save), &machine)); /* for memory cards, request save state and an exit callback */ if (machine.config().m_memcard_handler != NULL) { state_save_register_global(machine, state->memcard_inserted); machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(memcard_eject), &machine)); } }
ui_menu_device_config::ui_menu_device_config(running_machine &machine, render_container *container, device_slot_interface *slot, device_slot_option *option) : ui_menu(machine, container) { astring tmp_tag; tmp_tag.cpy(slot->device().tag()).cat(":").cat(option->name()); m_option = option; m_owner = slot; m_mounted = false; device_iterator deviter(machine.config().root_device()); for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) { if (strcmp(device->tag(), tmp_tag.cstr()) == 0) { m_mounted = true; break; } } }
ui_menu_control_device_image::ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *_image) : ui_menu(machine, container), submenu_result(0), create_ok(false), create_confirmed(false) { image = _image; sld = nullptr; if (image->software_list_name()) { software_list_device_iterator iter(machine.config().root_device()); for (software_list_device *swlist = iter.first(); swlist != nullptr; swlist = iter.next()) { if (strcmp(swlist->list_name(),image->software_list_name())==0) sld = swlist; } } swi = image->software_entry(); swp = image->part_entry(); if(swi) { state = START_OTHER_PART; current_directory.assign(image->working_directory()); } else { state = START_FILE; /* if the image exists, set the working directory to the parent directory */ if (image->exists()) { current_file.assign(image->filename()); zippath_parent(current_directory, current_file.c_str()); } else current_directory.assign(image->working_directory()); /* check to see if the path exists; if not clear it */ if (zippath_opendir(current_directory.c_str(), nullptr) != osd_file::error::NONE) current_directory.clear(); } }
ui_menu_control_device_image::ui_menu_control_device_image(running_machine &machine, render_container *container, device_image_interface *_image) : ui_menu(machine, container) { image = _image; sld = 0; if (image->software_list_name()) { software_list_device_iterator iter(machine.config().root_device()); for (software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) { if (strcmp(swlist->list_name(),image->software_list_name())==0) sld = swlist; } } swi = image->software_entry(); swp = image->part_entry(); if(swi) { state = START_OTHER_PART; current_directory.cpy(image->working_directory()); } else { state = START_FILE; /* if the image exists, set the working directory to the parent directory */ if (image->exists()) { current_file.cpy(image->filename()); zippath_parent(current_directory, current_file); } else current_directory.cpy(image->working_directory()); /* check to see if the path exists; if not clear it */ if (zippath_opendir(current_directory, NULL) != FILERR_NONE) current_directory.reset(); } }
int nvram_size(running_machine &machine) { int retval=0; if (machine.config().m_nvram_handler != NULL) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); if (file.open(nvram_filename(filename, machine.root_device()),".nv") == FILERR_NONE) { retval += file.size(); } } nvram_interface_iterator iter(machine.root_device()); for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next()) { astring filename; emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); if (file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE) { retval += file.size(); } } return retval; }
void favorite_manager::add_favorite(running_machine &machine) { apply_running_machine( machine, [this, &machine] (game_driver const &driver, device_image_interface *imagedev, software_info const *software, bool &done) { if (imagedev) { // creating this is fairly expensive, but we'll assume this usually succeeds ui_software_info info; software_part const *const part(imagedev->part_entry()); assert(software); assert(part); // start with simple stuff that can just be copied info.shortname = software->shortname(); info.longname = imagedev->longname(); info.parentname = software->parentname(); info.year = imagedev->year(); info.publisher = imagedev->manufacturer(); info.supported = imagedev->supported(); info.part = part->name(); info.driver = &driver; info.listname = imagedev->software_list_name(); info.interface = part->interface(); info.instance = imagedev->instance_name(); info.startempty = 0; info.devicetype = strensure(imagedev->image_type_name()); info.available = true; // look up the parent in the list if necessary (eugh, O(n) walk) if (!info.parentname.empty()) { auto const listdev = software_list_device::find_by_name(machine.config(), info.listname); assert(listdev); for (software_info const &other : listdev->get_info()) { if (other.shortname() == info.parentname) { info.parentlongname = other.longname(); break; } } } // fill in with the first usage entry we find for (feature_list_item const &feature : software->other_info()) { if (feature.name() == "usage") { info.usage = feature.value(); break; } } // hooray for move semantics! add_impl(std::move(info)); } else { add_impl(driver); } }); }