public void save_settings() { // loop over all registrants and call their init function foreach (var type in m_typelist) { type.save(config_type.INIT, null); } // save the defaults file emu_file file = new emu_file(machine().options().cfg_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); std.error_condition filerr = file.open("default.cfg"); if (!filerr) { save_xml(file, config_type.DEFAULT); } // finally, save the system-specific file filerr = file.open(machine().basename() + ".cfg"); if (!filerr) { save_xml(file, config_type.SYSTEM); } file.close(); // loop over all registrants and call their final function foreach (var type in m_typelist) { type.save(config_type.FINAL, null); } }
std.vector <KeyValuePair <string, categoryindex> > m_ini_index; //std::vector<std::pair<std::string, categoryindex> > m_ini_index; // construction/destruction //------------------------------------------------- // ctor //------------------------------------------------- public inifile_manager(ui_options moptions) { m_options = moptions; m_ini_index = new std.vector <KeyValuePair <string, categoryindex> >(); // scan directories and create index file_enumerator path = new file_enumerator(m_options.categoryini_path()); for (osd.directory.entry dir = path.next(); dir != null; dir = path.next()) { string name = dir.name; if (core_filename_ends_with(name, ".ini")) { emu_file file = new emu_file(m_options.categoryini_path(), OPEN_FLAG_READ); if (file.open(name) == osd_file.error.NONE) { init_category(name, file); file.close(); } } } //std::stable_sort(m_ini_index.begin(), m_ini_index.end());//, [] (auto const &x, auto const &y) { return 0 > core_stricmp(x.first.c_str(), y.first.c_str()); }); m_ini_index.Sort((x, y) => { return(core_stricmp(x.Key.c_str(), y.Key.c_str())); }); }
public void save_settings() { /* loop over all registrants and call their init function */ foreach (var type in m_typelist) { type.save(config_type.INIT, null); } /* save the defaults file */ emu_file file = new emu_file(machine().options().cfg_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); osd_file.error filerr = file.open("default.cfg"); if (filerr == osd_file.error.NONE) { save_xml(file, config_type.DEFAULT); } /* finally, save the game-specific file */ filerr = file.open(machine().basename(), ".cfg"); if (filerr == osd_file.error.NONE) { save_xml(file, config_type.GAME); } file.close(); /* loop over all registrants and call their final function */ foreach (var type in m_typelist) { type.save(config_type.FINAL, null); } }
//------------------------------------------------- // load_samples - load all the samples in our // attached interface // Returns true when all samples were successfully read, else false //------------------------------------------------- bool load_samples() { bool ok = true; // if the user doesn't want to use samples, bail if (!machine().options().samples()) { return(false); } // iterate over ourself string basename = machine().basename(); samples_iterator iter = new samples_iterator(this); string altbasename = iter.altbasename(); // pre-size the array m_sample.resize((size_t)iter.count()); // load the samples int index = 0; for (string samplename = iter.first(); samplename != null; index++, samplename = iter.next()) { // attempt to open as FLAC first emu_file file = new emu_file(machine().options().sample_path(), OPEN_FLAG_READ); std.error_condition filerr = file.open(util.string_format("{0}" + PATH_SEPARATOR + "{1}.flac", basename, samplename)); if (filerr && !string.IsNullOrEmpty(altbasename)) { filerr = file.open(util.string_format("{0}" + PATH_SEPARATOR + "{1}.flac", altbasename, samplename)); } // if not, try as WAV if (filerr) { filerr = file.open(util.string_format("{0}" + PATH_SEPARATOR + "{1}.wav", basename, samplename)); } if (filerr && !string.IsNullOrEmpty(altbasename)) { filerr = file.open(util.string_format("{0}" + PATH_SEPARATOR + "{1}.wav", altbasename, samplename)); } // if opened, read it if (!filerr) { read_sample(file, m_sample[index]); } else { logerror("Error opening sample '{0}' ({1}:{2} {3})\n", samplename, filerr.category().name(), filerr.value(), filerr.message()); ok = false; } file.close(); } return(ok); }
//------------------------------------------------- // load_samples - load all the samples in our // attached interface // Returns true when all samples were successfully read, else false //------------------------------------------------- bool load_samples() { bool ok = true; // if the user doesn't want to use samples, bail if (!machine().options().samples()) { return(false); } // iterate over ourself string basename = machine().basename(); samples_iterator iter = new samples_iterator(this); string altbasename = iter.altbasename(); // pre-size the array m_sample.resize(iter.count()); // load the samples int index = 0; for (string samplename = iter.first(); samplename != null; index++, samplename = iter.next()) { // attempt to open as FLAC first emu_file file = new emu_file(machine().options().sample_path(), OPEN_FLAG_READ); osd_file.error filerr = file.open(basename, PATH_SEPARATOR, samplename, ".flac"); if (filerr != osd_file.error.NONE && altbasename != null) { filerr = file.open(altbasename, PATH_SEPARATOR, samplename, ".flac"); } // if not, try as WAV if (filerr != osd_file.error.NONE) { filerr = file.open(basename, PATH_SEPARATOR, samplename, ".wav"); } if (filerr != osd_file.error.NONE && altbasename != null) { filerr = file.open(altbasename, PATH_SEPARATOR, samplename, ".wav"); } // if opened, read it if (filerr == osd_file.error.NONE) { read_sample(file, m_sample[index]); } else if (filerr == osd_file.error.NOT_FOUND) { logerror("{0}: Sample '{1}' NOT FOUND\n", tag(), samplename); ok = false; } file.close(); } return(ok); }
// load games from category public void load_ini_category(UInt32 file, UInt32 category, std.unordered_set <game_driver> result) { string filename = m_ini_index[(int)file].Key; emu_file fp = new emu_file(m_options.categoryini_path(), OPEN_FLAG_READ); if (fp.open(filename) != osd_file.error.NONE) { osd_printf_error("Failed to open category file {0} for reading\n", filename.c_str()); return; } Int64 offset = m_ini_index[(int)file].Value[(int)category].Value; if (fp.seek(offset, emu_file.SEEK_SET) != 0 || (fp.tell() != (UInt64)offset)) { fp.close(); osd_printf_error("Failed to seek to category offset in file {0}\n", filename.c_str()); return; } string rbuf; // char rbuf[MAX_CHAR_INFO]; while (fp.gets(out rbuf, utils_global.MAX_CHAR_INFO) != null && !string.IsNullOrEmpty(rbuf) && ('[' != rbuf[0])) { //var tail = std::find_if(std::begin(rbuf), std::prev(std::end(rbuf)));//, [] (char ch) { return !ch || ('\r' == ch) || ('\n' == ch); }); //*tail = '\0'; var tail = rbuf.IndexOfAny("\r\n".ToCharArray()); rbuf = rbuf.Substring(tail); int dfind = driver_list.find(rbuf); if (0 <= dfind) { result.emplace(driver_list.driver(dfind)); } } fp.close(); }
public static void load_translation(emu_options m_options) { g_translation.Clear(); emu_file file = new emu_file(m_options.language_path(), global_object.OPEN_FLAG_READ); var name = m_options.language(); name = name.Replace(" ", "_"); name = name.Replace("(", ""); name = name.Replace(")", ""); if (file.open(name, global_object.PATH_SEPARATOR + "strings.mo") == osd_file.error.NONE) { uint64_t size = file.size(); RawBuffer buffer = new RawBuffer(4 * (int)size / 4 + 1); //uint32_t *buffer = global_alloc_array(uint32_t, size / 4 + 1); file.read(new ListBytesPointer(buffer), (UInt32)size); file.close(); if (buffer.get_uint32(0) != MO_MAGIC && buffer.get_uint32(0) != MO_MAGIC_REVERSED) { buffer = null; //global_free_array(buffer); return; } if (buffer.get_uint32(0) == MO_MAGIC_REVERSED) { for (var i = 0; i < ((int)size / 4) + 1; ++i) { buffer.set_uint32(i, endianchange(buffer[i])); } } uint32_t number_of_strings = buffer.get_uint32(2); uint32_t original_table_offset = buffer.get_uint32(3) >> 2; uint32_t translation_table_offset = buffer.get_uint32(4) >> 2; RawBuffer data = buffer; //const char *data = reinterpret_cast<const char*>(buffer); for (var i = 1; i < number_of_strings; ++i) { string original = "TODO original"; //(const char *)data + buffer[original_table_offset + 2 * i + 1]; string translation = "TODO translation"; //(const char *)data + buffer[translation_table_offset + 2 * i + 1]; g_translation.emplace(original, translation); } buffer = null; //global_free_array(buffer); } }
// internal helpers //------------------------------------------------- // audit_one_rom - validate a single ROM entry //------------------------------------------------- audit_record audit_one_rom(ListPointer <rom_entry> rom) //(const rom_entry *rom) { // allocate and append a new record audit_record record = m_record_list.emplace_back(new audit_record(rom, audit_record.media_type.MEDIA_ROM)).Value; //audit_record &record = *m_record_list.emplace(m_record_list.end(), *rom, media_type::ROM); // see if we have a CRC and extract it if so UInt32 crc; bool has_crc = record.expected_hashes().crc(out crc); // find the file and checksum it, getting the file length along the way emu_file file = new emu_file(m_enumerator.options().media_path(), osdcore_global.OPEN_FLAG_READ | osdcore_global.OPEN_FLAG_NO_PRELOAD); file.set_restrict_to_mediapath(true); path_iterator path = new path_iterator(m_searchpath); string curpath; while (path.next(out curpath, record.name())) { // open the file if we can osd_file.error filerr; if (has_crc) { filerr = file.open(curpath, crc); } else { filerr = file.open(curpath); } // if it worked, get the actual length and hashes, then stop if (filerr == osd_file.error.NONE) { record.set_actual(file.hashes(m_validation), file.size()); break; } } file.close(); // compute the final status compute_status(record, rom[0], record.actual_length() != 0); return(record); }
//------------------------------------------------- // load_cached_bdf - attempt to load a cached // version of the BDF font 'filename'; if that // fails, fall back on the regular BDF loader // and create a new cached version //------------------------------------------------- bool load_cached_bdf(string filename) { std.error_condition filerr; u32 chunk; u64 bytes; // first try to open the BDF itself emu_file file = new emu_file(manager().machine().options().font_path(), OPEN_FLAG_READ); filerr = file.open(filename); if (filerr) { return(false); } file.close(); throw new emu_unimplemented(); #if false #endif }
// INI parsing helper //------------------------------------------------- // parse_one_ini - parse a single INI file //------------------------------------------------- static void parse_one_ini(emu_options options, string basename, int priority, ref string error_stream) { // don't parse if it has been disabled if (!options.read_config()) { return; } // open the file; if we fail, that's ok emu_file file = new emu_file(options.ini_path(), OPEN_FLAG_READ); osd_printf_verbose("Attempting load of {0}.ini\n", basename); osd_file.error filerr = file.open(basename, ".ini"); if (filerr != osd_file.error.NONE) { return; } // parse the file osd_printf_verbose("Parsing {0}.ini\n", basename); try { options.parse_ini_file(file.core_file_get(), priority, priority < OPTION_PRIORITY_DRIVER_INI, false); } catch (options_exception ex) { if (error_stream != null) { error_stream += string.Format("While parsing {0}:\n{1}\n", file.fullpath(), ex.message()); } return; } finally { file.close(); } }
//------------------------------------------------- // audit_one_rom - validate a single ROM entry //------------------------------------------------- audit_record audit_one_rom(std.vector <string> searchpath, Pointer <rom_entry> rom) //audit_record &audit_one_rom(const std::vector<std::string> &searchpath, const rom_entry *rom); { // allocate and append a new record audit_record record = m_record_list.emplace_back(new audit_record(rom, media_type.ROM)).Value; //audit_record &record = *m_record_list.emplace(m_record_list.end(), *rom, media_type::ROM); // see if we have a CRC and extract it if so uint32_t crc; bool has_crc = record.expected_hashes().crc(out crc); // find the file and checksum it, getting the file length along the way emu_file file = new emu_file(m_enumerator.options().media_path(), searchpath, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD); file.set_restrict_to_mediapath(1); // open the file if we can std.error_condition filerr; if (has_crc) { filerr = file.open(record.name(), crc); } else { filerr = file.open(record.name()); } // if it worked, get the actual length and hashes, then stop if (!filerr) { record.set_actual(file.hashes(m_validation), file.size()); } file.close(); // compute the final status compute_status(record, rom.op, record.actual_length() != 0); return(record); }
/*------------------------------------------------- * write_config - emit current option statuses as * INI files * -------------------------------------------------*/ int write_config(emu_options options, string filename, game_driver gamedrv) { string buffer; int retval = 1; if (gamedrv != null) { buffer = string.Format("{0}.ini", gamedrv.name); filename = buffer; } emu_file file = new emu_file(options.ini_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE); osd_file.error filerr = file.open(filename); if (filerr == osd_file.error.NONE) { string inistring = options.output_ini(); file.puts(inistring); retval = 0; } file.close(); return(retval); }
/*------------------------------------------------- * write_config - emit current option statuses as * INI files * -------------------------------------------------*/ int write_config(emu_options options, string filename, game_driver gamedrv) { string buffer; int retval = 1; if (gamedrv != null) { sprintf(out buffer, "{0}.ini", gamedrv.name); filename = buffer; } emu_file file = new emu_file(options.ini_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE); std.error_condition filerr = file.open(filename); if (!filerr) { string inistring = options.output_ini(); file.puts(inistring); retval = 0; } file.close(); return(retval); }
//------------------------------------------------- // audit_samples - validate the samples for the // currently-enumerated driver //------------------------------------------------- public summary audit_samples() { // start fresh m_record_list.clear(); int required = 0; int found = 0; // iterate over sample entries foreach (samples_device device in new samples_device_iterator(m_enumerator.config().root_device())) { // by default we just search using the driver name string searchpath = m_enumerator.driver().name; // add the alternate path if present samples_iterator samplesiter = new samples_iterator(device); if (samplesiter.altbasename() != null) { searchpath += ";" + samplesiter.altbasename(); } // iterate over samples in this entry for (string samplename = samplesiter.first(); samplename != null; samplename = samplesiter.next()) { required++; // create a new record audit_record record = m_record_list.emplace_back(new audit_record(samplename, audit_record.media_type.MEDIA_SAMPLE)).Value; //audit_record &record = *m_record_list.emplace(m_record_list.end(), samplename, media_type::SAMPLE); // look for the files emu_file file = new emu_file(m_enumerator.options().sample_path(), osdcore_global.OPEN_FLAG_READ | osdcore_global.OPEN_FLAG_NO_PRELOAD); path_iterator path = new path_iterator(searchpath); string curpath; while (path.next(out curpath, samplename)) { // attempt to access the file (.flac) or (.wav) osd_file.error filerr = file.open(curpath, ".flac"); if (filerr != osd_file.error.NONE) { filerr = file.open(curpath, ".wav"); } if (filerr == osd_file.error.NONE) { record.set_status(audit_record.audit_status.STATUS_GOOD, audit_record.audit_substatus.SUBSTATUS_GOOD); found++; } else { record.set_status(audit_record.audit_status.STATUS_NOT_FOUND, audit_record.audit_substatus.SUBSTATUS_NOT_FOUND); } } file.close(); } } if (found == 0 && required > 0) { m_record_list.clear(); return(summary.NOTFOUND); } // return a summary string unused = ""; return(summarize(m_enumerator.driver().name, ref unused)); }
public void start_luaengine() { if (options().plugins()) { path_iterator iter = new path_iterator(options().plugins_path()); string pluginpath; while (iter.next(out pluginpath)) { m_plugins.parse_json(pluginpath); } string [] include = options().plugin() == null ? new string[0] : options().plugin().Split(','); // split(options().plugin(),','); string [] exclude = options().no_plugin() == null ? new string[0] : options().no_plugin().Split(','); { // parse the file // attempt to open the output file emu_file file = new emu_file(options().ini_path(), OPEN_FLAG_READ); if (file.open("plugin.ini") == osd_file.error.NONE) { try { m_plugins.parse_ini_file(file.core_file_get(), mame_options.OPTION_PRIORITY_MAME_INI, mame_options.OPTION_PRIORITY_MAME_INI < mame_options.OPTION_PRIORITY_DRIVER_INI, false); } catch (options_exception) { osd_printf_error("**Error loading plugin.ini**\n"); } file.close(); } } foreach (var curentry in m_plugins.entries()) { if (curentry.type() != core_options.option_type.HEADER) { if (Array.Exists(include, s => s == curentry.name())) // std::find(include.begin(), include.end(), curentry.name()) != include.end()) { m_plugins.set_value(curentry.name(), "1", emu_options.OPTION_PRIORITY_CMDLINE); } if (Array.Exists(exclude, s => s == curentry.name())) // std::find(exclude.begin(), exclude.end(), curentry.name()) != exclude.end()) { m_plugins.set_value(curentry.name(), "0", emu_options.OPTION_PRIORITY_CMDLINE); } } } } if (options().console()) { m_plugins.set_value("console", "1", emu_options.OPTION_PRIORITY_CMDLINE); if (m_plugins.exists(emu_options.OPTION_CONSOLE)) { m_plugins.set_value(emu_options.OPTION_CONSOLE, "1", emu_options.OPTION_PRIORITY_CMDLINE); } else { fatalerror("Console plugin not found.\n"); } } m_lua.initialize(); { emu_file file = new emu_file(options().plugins_path(), OPEN_FLAG_READ); osd_file.error filerr = file.open("boot.lua"); if (filerr == osd_file.error.NONE) { string exppath; osdcore_global.m_osdcore.osd_subst_env(out exppath, file.fullpath()); m_lua.load_script(file.fullpath()); file.close(); } } }
// updates //void animate(u16 auto_time); //void draw(render_container &container, u8 fade); // private helpers //------------------------------------------------- // create_bitmap - create the rendering // structures for the given player //------------------------------------------------- void create_bitmap() { rgb_t color = m_player < (int)std.size(crosshair_colors) ? crosshair_colors[m_player] : rgb_t.white(); // if we have a bitmap and texture for this player, kill it if (m_bitmap == null) { m_bitmap = new bitmap_argb32(); m_texture = m_machine.render().texture_alloc(render_texture.hq_scale); } else { m_bitmap.reset(); } emu_file crossfile = new emu_file(m_machine.options().crosshair_path(), OPEN_FLAG_READ); if (!m_name.empty()) { // look for user specified file if (!crossfile.open(m_name + ".png")) { render_load_png(out m_bitmap, crossfile.core_file_get()); crossfile.close(); } } else { // look for default cross?.png in crsshair/game dir string filename = util.string_format("cross{0}.png", m_player + 1); if (!crossfile.open(m_machine.system().name + (PATH_SEPARATOR + filename))) { render_load_png(out m_bitmap, crossfile.core_file_get()); crossfile.close(); } // look for default cross?.png in crsshair dir if (!m_bitmap.valid() && !crossfile.open(filename)) { render_load_png(out m_bitmap, crossfile.core_file_get()); crossfile.close(); } } /* if that didn't work, use the built-in one */ if (!m_bitmap.valid()) { /* allocate a blank bitmap to start with */ m_bitmap.allocate(CROSSHAIR_RAW_SIZE, CROSSHAIR_RAW_SIZE); m_bitmap.fill(new rgb_t(0x00, 0xff, 0xff, 0xff)); /* extract the raw source data to it */ for (int y = 0; y < CROSSHAIR_RAW_SIZE / 2; y++) { /* assume it is mirrored vertically */ PointerU32 dest0 = m_bitmap.pix(y); //u32 *dest0 = &m_bitmap->pix(y); PointerU32 dest1 = m_bitmap.pix(CROSSHAIR_RAW_SIZE - 1 - y); //u32 *dest1 = &m_bitmap->pix(CROSSHAIR_RAW_SIZE - 1 - y); /* extract to two rows simultaneously */ for (int x = 0; x < CROSSHAIR_RAW_SIZE; x++) { if (((crosshair_raw_top[y * CROSSHAIR_RAW_ROWBYTES + x / 8] << (x % 8)) & 0x80) != 0) { dest0[x] = dest1[x] = new rgb_t(0xff, 0x00, 0x00, 0x00) | color; } } } } /* reference the new bitmap */ m_texture.set_bitmap(m_bitmap, m_bitmap.cliprect(), texture_format.TEXFORMAT_ARGB32); }
void render_font_command_glyph() { // FIXME: this is copy/pasta from the BDC loading, and it shouldn't be injected into every font emu_file file = new emu_file(OPEN_FLAG_READ); if (!file.open_ram(new MemoryU8(font_uicmd14), (u32)font_uicmd14.Length)) { // get the file size, read the header, and check that it looks good u64 filesize = file.size(); bdc_header header = new bdc_header(); if (!header.read(file)) { osd_printf_warning("render_font::render_font_command_glyph: error reading BDC header\n"); file.close(); return; } else if (!header.check_magic() || (bdc_header.MAJVERSION != header.get_major_version()) || (bdc_header.MINVERSION != header.get_minor_version())) { LOG("render_font::render_font_command_glyph: incompatible BDC file\n"); file.close(); return; } // get global properties from the header m_height_cmd = header.get_height(); m_yoffs_cmd = header.get_y_offset(); u32 numchars = header.get_glyph_count(); if ((file.tell() + ((u64)numchars * bdc_table_entry.size())) > filesize) { LOG("render_font::render_font_command_glyph: BDC file is too small to hold glyph table\n"); file.close(); return; } // now read the rest of the data u64 remaining = filesize - file.tell(); //try { m_rawdata_cmd.resize(remaining); } //catch (...) //{ // global.osd_printf_error("render_font::render_font_command_glyph: allocation error\n"); //} for (u64 bytes_read = 0; remaining > bytes_read;) { u32 chunk = (u32)std.min(u32.MaxValue, remaining); if (file.read(new Pointer <u8>(m_rawdata_cmd, (int)bytes_read), chunk) != chunk) { osd_printf_error("render_font::render_font_command_glyph: error reading BDC data\n"); m_rawdata_cmd.clear(); file.close(); return; } bytes_read += chunk; } file.close(); // extract the data from the data size_t offset = (size_t)numchars * bdc_table_entry.size(); bdc_table_entry entry = new bdc_table_entry(m_rawdata_cmd.empty() ? null : new Pointer <u8>(m_rawdata_cmd)); for (unsigned chindex = 0; chindex < numchars; chindex++, entry = entry.get_next()) { // if we don't have a subtable yet, make one int chnum = (int)entry.get_encoding(); LOG("render_font::render_font_command_glyph: loading character {0}\n", chnum); if (m_glyphs_cmd[chnum / 256] == null) { //try { m_glyphs_cmd[chnum / 256] = new List <glyph>(256); // new glyph[256]; for (int i = 0; i < 256; i++) { m_glyphs_cmd[chnum / 256].Add(new glyph()); } } //catch (...) //{ // osd_printf_error("render_font::render_font_command_glyph: allocation error\n"); // m_rawdata_cmd.clear(); // return; //} } // fill in the entry glyph gl = m_glyphs_cmd[chnum / 256][chnum % 256]; gl.width = entry.get_x_advance(); gl.xoffs = entry.get_bb_x_offset(); gl.yoffs = entry.get_bb_y_offset(); gl.bmwidth = entry.get_bb_width(); gl.bmheight = entry.get_bb_height(); gl.rawdata = new Pointer <u8>(m_rawdata_cmd, (int)offset); // advance the offset past the character offset += (size_t)((gl.bmwidth * gl.bmheight + 7) / 8); if (m_rawdata_cmd.size() < offset) { osd_printf_verbose("render_font::render_font_command_glyph: BDC file too small to hold all glyphs\n"); m_rawdata_cmd.clear(); return; } } } }
std.vector <u8> m_rawdata_cmd = new std.vector <u8>(); //std::vector<char> m_rawdata_cmd; // pointer to the raw data for the font // construction/destruction //------------------------------------------------- // render_font - constructor //------------------------------------------------- public render_font(render_manager manager, string filename) { m_manager = manager; m_format = format.UNKNOWN; m_height = 0; m_yoffs = 0; m_defchar = -1; m_scale = 1.0f; m_rawsize = 0; m_osdfont = null; m_height_cmd = 0; m_yoffs_cmd = 0; //memset(m_glyphs, 0, sizeof(m_glyphs)); for (int i = 0; i < m_glyphs.Length; i++) { m_glyphs[i] = new List <glyph>(); } //memset(m_glyphs_cmd, 0, sizeof(m_glyphs_cmd)); //for (int i = 0; i < m_glyphs_cmd.Length; i++) // m_glyphs_cmd[i] = new List<glyph>(); // if this is an OSD font, we're done if (filename != null) { m_osdfont = manager.machine().osd().font_alloc(); if (m_osdfont != null && m_osdfont.open(manager.machine().options().font_path(), filename, out m_height)) { m_scale = 1.0f / (float)m_height; m_format = format.OSD; //mamep: allocate command glyph font render_font_command_glyph(); return; } m_osdfont = null; // m_osdfont.reset(); } // if the filename is 'default' default to 'ui.bdf' for backwards compatibility if (filename != null && core_stricmp(filename, "default") == 0) { filename = "ui.bdf"; } // attempt to load an external BDF font first if (filename != null && load_cached_bdf(filename)) { //mamep: allocate command glyph font render_font_command_glyph(); return; } // load the compiled in data instead emu_file ramfile = new emu_file(OPEN_FLAG_READ); std.error_condition filerr = ramfile.open_ram(new MemoryU8(font_uismall), (u32)font_uismall.Length);//, sizeof(font_uismall)); if (!filerr) { load_cached(ramfile, 0, 0); } ramfile.close(); render_font_command_glyph(); }
//------------------------------------------------- // recompute_speed - recompute the current // overall speed; we assume this is called only // if we did not skip a frame //------------------------------------------------- void recompute_speed(attotime emutime) { // if we don't have a starting time yet, or if we're paused, reset our starting point if (m_speed_last_realtime == 0 || machine().paused()) { m_speed_last_realtime = m_osdcore.osd_ticks(); m_speed_last_emutime = emutime; } // if it has been more than the update interval, update the time attotime delta_emutime = emutime - m_speed_last_emutime; if (delta_emutime > new attotime(0, ATTOSECONDS_PER_SPEED_UPDATE)) { // convert from ticks to attoseconds osd_ticks_t realtime = m_osdcore.osd_ticks(); osd_ticks_t delta_realtime = realtime - m_speed_last_realtime; osd_ticks_t tps = m_osdcore.osd_ticks_per_second(); m_speed_percent = delta_emutime.as_double() * (double)tps / (double)delta_realtime; // remember the last times m_speed_last_realtime = realtime; m_speed_last_emutime = emutime; // if we're throttled, this time period counts for overall speed; otherwise, we reset the counter if (!m_fastforward) { m_overall_valid_counter++; } else { m_overall_valid_counter = 0; } // if we've had at least 4 consecutive valid periods, accumulate stats if (m_overall_valid_counter >= 4) { m_overall_real_ticks += delta_realtime; while (m_overall_real_ticks >= tps) { m_overall_real_ticks -= tps; m_overall_real_seconds++; } m_overall_emutime += delta_emutime; } } // if we're past the "time-to-execute" requested, signal an exit if (m_seconds_to_run != 0 && emutime.seconds() >= m_seconds_to_run) { // create a final screenshot emu_file file = new emu_file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); std.error_condition filerr = open_next(file, "png"); if (!filerr) { save_snapshot(null, file); } file.close(); //printf("Scheduled exit at %f\n", emutime.as_double()); // schedule our demise machine().schedule_exit(); } }
// construction/destruction //------------------------------------------------- // ctor //------------------------------------------------- public favorite_manager(ui_options options) { m_options = options; m_favorites = new favorites_set(); m_sorted = new sorted_favorites(); m_need_sort = true; emu_file file = new emu_file(m_options.ui_path(), OPEN_FLAG_READ); if (file.open(FAVORITE_FILENAME) == osd_file.error.NONE) { string readbuf; file.gets(out readbuf, 1024); while (readbuf[0] == '[') { file.gets(out readbuf, 1024); } while (file.gets(out readbuf, 1024) != null) { ui_software_info tmpmatches = new ui_software_info(); tmpmatches.shortname = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.longname = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.parentname = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.year = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.publisher = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.supported = Convert.ToByte(readbuf); file.gets(out readbuf, 1024); tmpmatches.part = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); utils_global.chartrimcarriage(readbuf); var dx = driver_list.find(readbuf); if (0 > dx) { continue; } tmpmatches.driver = driver_list.driver(dx); file.gets(out readbuf, 1024); tmpmatches.listname = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.interface_ = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.instance = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.startempty = Convert.ToByte(readbuf); file.gets(out readbuf, 1024); tmpmatches.parentlongname = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.usage = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.devicetype = utils_global.chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.available = Convert.ToInt32(readbuf) != 0; m_favorites.emplace(tmpmatches); } file.close(); } }
// construction/destruction //------------------------------------------------- // ctor //------------------------------------------------- public favorite_manager(ui_options options) { m_options = options; m_favorites = new favorites_set(); m_sorted = new sorted_favorites(); m_need_sort = true; emu_file file = new emu_file(m_options.ui_path(), OPEN_FLAG_READ); if (!file.open(FAVORITE_FILENAME)) { string readbuf; //char readbuf[1024]; file.gets(out readbuf, 1024); while (readbuf[0] == '[') { file.gets(out readbuf, 1024); } while (file.gets(out readbuf, 1024) != null) { ui_software_info tmpmatches = new ui_software_info(); tmpmatches.shortname = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.longname = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.parentname = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.year = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.publisher = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.supported = (software_support)std.atoi(readbuf); file.gets(out readbuf, 1024); tmpmatches.part = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); chartrimcarriage(readbuf); var dx = driver_list.find(readbuf); if (0 > dx) { continue; } tmpmatches.driver = driver_list.driver((size_t)dx); file.gets(out readbuf, 1024); tmpmatches.listname = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.interface_ = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.instance = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.startempty = (uint8_t)std.atoi(readbuf); file.gets(out readbuf, 1024); tmpmatches.parentlongname = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); //tmpmatches.usage = chartrimcarriage(readbuf); TODO: recover multi-line info file.gets(out readbuf, 1024); tmpmatches.devicetype = chartrimcarriage(readbuf); file.gets(out readbuf, 1024); tmpmatches.available = std.atoi(readbuf) != 0; // need to populate this, it isn't displayed anywhere else tmpmatches.infotext = tmpmatches.infotext.append_(tmpmatches.longname); tmpmatches.infotext = tmpmatches.infotext.append_(1, '\n'); tmpmatches.infotext = tmpmatches.infotext.append_(__("swlist-info", "Software list/item")); tmpmatches.infotext = tmpmatches.infotext.append_(1, '\n'); tmpmatches.infotext = tmpmatches.infotext.append_(tmpmatches.listname); tmpmatches.infotext = tmpmatches.infotext.append_(1, ':'); tmpmatches.infotext = tmpmatches.infotext.append_(tmpmatches.shortname); m_favorites.emplace(tmpmatches); } file.close(); } }
// updates //void animate(u16 auto_time); //void draw(render_container &container, u8 fade); // private helpers //------------------------------------------------- // create_bitmap - create the rendering // structures for the given player //------------------------------------------------- void create_bitmap() { int x; int y; rgb_t color = m_player < crosshair_colors.Length ? crosshair_colors[m_player] : rgb_t.white(); // if we have a bitmap and texture for this player, kill it if (m_bitmap == null) { m_bitmap = new bitmap_argb32(); m_texture = m_machine.render().texture_alloc(render_texture.hq_scale); } emu_file crossfile = new emu_file(m_machine.options().crosshair_path(), OPEN_FLAG_READ); if (!m_name.empty()) { // look for user specified file string filename = m_name + ".png"; render_load_png(out m_bitmap, crossfile, null, filename.c_str()); } else { // look for default cross?.png in crsshair/game dir string filename = string.Format("cross{0}.png", m_player + 1); render_load_png(out m_bitmap, crossfile, m_machine.system().name, filename.c_str()); // look for default cross?.png in crsshair dir if (!m_bitmap.valid()) { render_load_png(out m_bitmap, crossfile, null, filename.c_str()); } } crossfile.close(); /* if that didn't work, use the built-in one */ if (!m_bitmap.valid()) { /* allocate a blank bitmap to start with */ m_bitmap.allocate(CROSSHAIR_RAW_SIZE, CROSSHAIR_RAW_SIZE); m_bitmap.fill(new rgb_t(0x00, 0xff, 0xff, 0xff)); /* extract the raw source data to it */ for (y = 0; y < CROSSHAIR_RAW_SIZE / 2; y++) { /* assume it is mirrored vertically */ //u32 *dest0 = &m_bitmap->pix32(y); RawBuffer dest0Buf; UInt32 dest0Offset = m_bitmap.pix32(out dest0Buf, y); //u32 *dest1 = &m_bitmap->pix32(CROSSHAIR_RAW_SIZE - 1 - y); RawBuffer dest1Buf; UInt32 dest1Offset = m_bitmap.pix32(out dest1Buf, CROSSHAIR_RAW_SIZE - 1 - y); /* extract to two rows simultaneously */ for (x = 0; x < CROSSHAIR_RAW_SIZE; x++) { if (((crosshair_raw_top[y * CROSSHAIR_RAW_ROWBYTES + x / 8] << (x % 8)) & 0x80) != 0) { //dest0[x] = dest1[x] = new rgb_t(0xff,0x00,0x00,0x00) | color; dest0Buf.set_uint32((int)dest0Offset + x, new rgb_t(0xff, 0x00, 0x00, 0x00) | color); dest1Buf.set_uint32((int)dest1Offset + x, new rgb_t(0xff, 0x00, 0x00, 0x00) | color); } } } } /* reference the new bitmap */ m_texture.set_bitmap(m_bitmap, m_bitmap.cliprect(), texture_format.TEXFORMAT_ARGB32); }
/************************************* * * Settings save/load frontend * *************************************/ public bool load_settings() { // loop over all registrants and call their init function foreach (var type in m_typelist) { type.load(config_type.INIT, config_level.DEFAULT, null); } // now load the controller file string controller = machine().options().ctrlr(); if (!string.IsNullOrEmpty(controller)) { // open the config file emu_file file = new emu_file(machine().options().ctrlr_path(), OPEN_FLAG_READ); osd_printf_verbose("Attempting to parse: {0}.cfg\n", controller); std.error_condition filerr = file.open(controller + ".cfg"); if (filerr) { throw new emu_fatalerror("Could not open controller file {0}.cfg ({1}:{2} {3})", controller, filerr.category().name(), filerr.value(), filerr.message()); } // load the XML if (!load_xml(file, config_type.CONTROLLER)) { throw new emu_fatalerror("Could not load controller file {0}.cfg", controller); } file.close(); } bool loaded; { // next load the defaults file emu_file file = new emu_file(machine().options().cfg_directory(), OPEN_FLAG_READ); std.error_condition filerr = file.open("default.cfg"); osd_printf_verbose("Attempting to parse: default.cfg\n"); if (!filerr) { load_xml(file, config_type.DEFAULT); } // finally, load the game-specific file filerr = file.open(machine().basename() + ".cfg"); osd_printf_verbose("Attempting to parse: {0}.cfg\n", machine().basename()); loaded = !filerr && load_xml(file, config_type.SYSTEM); file.close(); } // loop over all registrants and call their final function foreach (var type in m_typelist) { type.load(config_type.FINAL, config_level.DEFAULT, null); } // if we didn't find a saved config, return false so the main core knows that it // is the first time the game is run and it should display the disclaimer. return(loaded); }
//------------------------------------------------- // start_luaengine //------------------------------------------------- public void start_luaengine() { if (options().plugins()) { //throw new emu_unimplemented(); #if false // scan all plugin directories path_iterator iter = new path_iterator(options().plugins_path()); string pluginpath; while (iter.next(out pluginpath)) { // user may specify environment variables; subsitute them m_osdcore.osd_subst_env(out pluginpath, pluginpath); // and then scan the directory recursively m_plugins.scan_directory(pluginpath, true); } { // parse the file // attempt to open the output file emu_file file = new emu_file(options().ini_path(), OPEN_FLAG_READ); if (file.open("plugin.ini") == osd_file.error.NONE) { try { m_plugins.parse_ini_file(file.core_file_get()); //(util::core_file&)file } catch (options_exception) { osd_printf_error("**Error loading plugin.ini**\n"); } file.close(); } } // process includes foreach (string incl in split(options().plugin(), ',')) { plugin_options::plugin *p = m_plugins->find(incl); if (!p) { fatalerror("Fatal error: Could not load plugin: %s\n", incl); } p.m_start = true; } // process excludes foreach (string excl in split(options().no_plugin(), ',')) { plugin_options::plugin *p = m_plugins->find(excl); if (!p) { fatalerror("Fatal error: Unknown plugin: %s\n", excl); } p.m_start = false; } #endif } // we have a special way to open the console plugin if (options().console()) { plugin_options.plugin p = m_plugins.find(OPTION_CONSOLE); if (p == null) { fatalerror("Fatal error: Console plugin not found.\n"); } p.m_start = true; } m_lua.initialize(); { emu_file file = new emu_file(options().plugins_path(), OPEN_FLAG_READ); std.error_condition filerr = file.open("boot.lua"); if (!filerr) { string exppath; m_osdcore.osd_subst_env(out exppath, file.fullpath()); m_lua.load_script(file.fullpath()); file.close(); } } }
/************************************* * * Settings save/load frontend * *************************************/ public int load_settings() { string controller = machine().options().ctrlr(); int loaded = 0; /* loop over all registrants and call their init function */ foreach (var type in m_typelist) { type.load(config_type.INIT, null); } /* now load the controller file */ if (!string.IsNullOrEmpty(controller)) { /* open the config file */ emu_file file = new emu_file(machine().options().ctrlr_path(), OPEN_FLAG_READ); osd_printf_verbose("Attempting to parse: {0}.cfg\n", controller); osd_file.error filerr = file.open(controller, ".cfg"); if (filerr != osd_file.error.NONE) { throw new emu_fatalerror("Could not load controller file {0}.cfg", controller); } /* load the XML */ if (load_xml(file, config_type.CONTROLLER) == 0) { throw new emu_fatalerror("Could not load controller file {0}.cfg", controller); } file.close(); } { /* next load the defaults file */ emu_file file = new emu_file(machine().options().cfg_directory(), OPEN_FLAG_READ); osd_file.error filerr = file.open("default.cfg"); osd_printf_verbose("Attempting to parse: default.cfg\n"); if (filerr == osd_file.error.NONE) { load_xml(file, config_type.DEFAULT); } /* finally, load the game-specific file */ filerr = file.open(machine().basename(), ".cfg"); osd_printf_verbose("Attempting to parse: {0}.cfg\n", machine().basename()); if (filerr == osd_file.error.NONE) { loaded = load_xml(file, config_type.GAME); } file.close(); } /* loop over all registrants and call their final function */ foreach (var type in m_typelist) { type.load(config_type.FINAL, null); } /* if we didn't find a saved config, return 0 so the main core knows that it */ /* is the first time the game is run and it should display the disclaimer. */ return(loaded); }