/*------------------------------------------------- * render_load_png - load a PNG file into a * bitmap * -------------------------------------------------*/ public static bool render_load_png(out bitmap_argb32 bitmap, emu_file file, string dirname, string filename, bool load_as_alpha_to_existing = false) { bitmap = new bitmap_argb32(); // deallocate if we're not overlaying alpha if (!load_as_alpha_to_existing) { bitmap.reset(); } // open the file string fname; if (dirname != null) { fname = dirname + global_object.PATH_SEPARATOR + filename; } else { fname = filename; } osd_file.error filerr = file.open(fname); if (filerr != osd_file.error.NONE) { return(false); } throw new emu_unimplemented(); }
//------------------------------------------------- // nvram_write - called to write NVRAM to the // .nv file //------------------------------------------------- void device_nvram_interface_nvram_write(emu_file file) { throw new emu_unimplemented(); #if false file.write(&m_rom_data[0], SIZE_DATA); #endif }
//------------------------------------------------- // read_flac_sample - read a FLAC file as a sample //------------------------------------------------- static bool read_flac_sample(emu_file file, sample_t sample) { // seek back to the start of the file file.seek(0, SEEK_SET); // create the FLAC decoder and fill in the sample data flac_decoder decoder = new flac_decoder(file.core_file_get()); sample.frequency = decoder.sample_rate(); // error if more than 1 channel or not 16bpp if (decoder.channels() != 1) { return(false); } if (decoder.bits_per_sample() != 16) { return(false); } // resize the array and read sample.data.resize(decoder.total_samples()); if (!decoder.decode_interleaved(sample.data, (uint32_t)sample.data.Count)) { return(false); } // finish up and clean up decoder.finish(); return(true); }
//------------------------------------------------- // nvram_write - called to write NVRAM to the // .nv file //------------------------------------------------- protected override void nvram_write(emu_file file) { throw new emu_unimplemented(); #if false file.write(&m_rom_data[0], SIZE_DATA); #endif }
//void render_line_to_quad(const render_bounds *bounds, float width, float length_extension, render_bounds *bounds0, render_bounds *bounds1); /*------------------------------------------------- * render_load_jpeg - load a JPG file into a * bitmap * -------------------------------------------------*/ public static void render_load_jpeg(out bitmap_argb32 bitmap, emu_file file, string dirname, string filename) { bitmap = new bitmap_argb32(); // deallocate previous bitmap bitmap.reset(); // define file's full name string fname; if (dirname == null) { fname = filename; } else { fname = dirname + global_object.PATH_SEPARATOR + filename; } if (file.open(fname) != osd_file.error.NONE) { return; } throw new emu_unimplemented(); }
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); } }
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); } }
// dynamic control //void set_frequency(UINT8 channel, UINT32 frequency); //void set_volume(UINT8 channel, float volume); // helpers //------------------------------------------------- // read_sample - read a WAV or FLAC file as a // sample //------------------------------------------------- static bool read_sample(emu_file file, sample_t sample) { // read the core header and make sure it's a proper file MemoryU8 buf = new MemoryU8(4, true); //uint8_t buf[4]; uint32_t offset = file.read(new Pointer <uint8_t>(buf), 4); if (offset < 4) { osd_printf_warning("Unable to read {0}, 0-byte file?\n", file.filename()); return(false); } // look for the appropriate RIFF tag if (buf[0] == 'R' && buf[1] == 'I' && buf[2] == 'F' && buf[3] == 'F') // memcmp(&buf[0], "RIFF", 4) == 0) { return(read_wav_sample(file, sample)); } else if (buf[0] == 'f' && buf[1] == 'L' && buf[2] == 'a' && buf[3] == 'C') // memcmp(&buf[0], "fLaC", 4) == 0) { return(read_flac_sample(file, sample)); } // if nothing appropriate, emit a warning osd_printf_warning("Unable to read {0}, corrupt file?\n", file.filename()); return(false); }
public static void load_translation(emu_options m_options) { util.unload_translation(); string name = m_options.language(); if (name.empty()) { return; } strreplace(ref name, " ", "_"); strreplace(ref name, "(", ""); strreplace(ref name, ")", ""); emu_file file = new emu_file(m_options.language_path(), OPEN_FLAG_READ); if (file.open(name + PATH_SEPARATOR + "strings.mo")) { osd_printf_error("Error opening translation file {0}\n", name); return; } osd_printf_verbose("Loading translation file {0}\n", file.fullpath()); util.load_translation(file.core_file_get()); }
//------------------------------------------------- // 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); }
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 }
// 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(); }
//------------------------------------------------- // 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); }
// 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(); } }
/*------------------------------------------------- * 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); }
protected override void nvram_write(emu_file file) { ((nvram_device)device()).device_nvram_interface_nvram_write(file); }
//------------------------------------------------- // 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(); } } }
protected virtual void device_nvram_interface_nvram_write(emu_file file) { throw new emu_unimplemented(); }
std.error_condition open_next(emu_file file, string extension, uint32_t index = 0) { throw new emu_unimplemented(); }
// snapshots //bool snap_native() const { return m_snap_native; } //render_target &snapshot_target() { return *m_snap_target; } //------------------------------------------------- // save_snapshot - save a snapshot to the given // file handle //------------------------------------------------- void save_snapshot(screen_device screen, emu_file file) { throw new emu_unimplemented(); }
//------------------------------------------------- // 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(); } }
protected abstract void nvram_read(emu_file file);
protected abstract void nvram_write(emu_file file);
// internal helpers //------------------------------------------------- // read_wav_sample - read a WAV file as a sample //------------------------------------------------- static bool read_wav_sample(emu_file file, sample_t sample) { // we already read the opening 'RIFF' tag uint32_t offset = 4; // get the total size uint32_t filesize; MemoryU8 filesizeBuffer = new MemoryU8(4, true); offset += file.read(new Pointer <uint8_t>(filesizeBuffer), 4); if (offset < 8) { osd_printf_warning("Unexpected size offset {0} ({1})\n", offset, file.filename()); return(false); } filesize = filesizeBuffer.GetUInt32(); filesize = little_endianize_int32(filesize); // read the RIFF file type and make sure it's a WAVE file MemoryU8 buf = new MemoryU8(32, true); //char [] buf = new char[32]; offset += file.read(new Pointer <uint8_t>(buf), 4); if (offset < 12) { osd_printf_warning("Unexpected WAVE offset {0} ({1})\n", offset, file.filename()); return(false); } if (!(buf[0] == 'W' && buf[1] == 'A' && buf[2] == 'V' && buf[3] == 'E')) // memcmp(&buf[0], "WAVE", 4) != 0) { osd_printf_warning("Could not find WAVE header ({0})\n", file.filename()); return(false); } // seek until we find a format tag uint32_t length; MemoryU8 lengthBuffer = new MemoryU8(4, true); while (true) { offset += file.read(new Pointer <uint8_t>(buf), 4); offset += file.read(new Pointer <uint8_t>(lengthBuffer), 4); length = lengthBuffer.GetUInt32(); length = little_endianize_int32(length); if (buf[0] == 'f' && buf[1] == 'm' && buf[2] == 't' && buf[3] == ' ') //if (memcmp(&buf[0], "fmt ", 4) == 0) { break; } // seek to the next block file.seek(length, SEEK_CUR); offset += length; if (offset >= filesize) { osd_printf_warning("Could not find fmt tag ({0})\n", file.filename()); return(false); } } // read the format -- make sure it is PCM uint16_t temp16; MemoryU8 temp16Buffer = new MemoryU8(2, true); offset += file.read(new Pointer <uint8_t>(temp16Buffer), 2); temp16 = temp16Buffer.GetUInt16(); temp16 = little_endianize_int16(temp16); if (temp16 != 1) { osd_printf_warning("unsupported format {0} - only PCM is supported ({1})\n", temp16, file.filename()); return(false); } // number of channels -- only mono is supported offset += file.read(new Pointer <uint8_t>(temp16Buffer), 2); temp16 = temp16Buffer.GetUInt16(); temp16 = little_endianize_int16(temp16); if (temp16 != 1) { osd_printf_warning("unsupported number of channels {0} - only mono is supported ({1})\n", temp16, file.filename()); return(false); } // sample rate uint32_t rate; MemoryU8 rateBuffer = new MemoryU8(4, true); offset += file.read(new Pointer <uint8_t>(rateBuffer), 4); rate = rateBuffer.GetUInt32(); rate = little_endianize_int32(rate); // bytes/second and block alignment are ignored offset += file.read(new Pointer <uint8_t>(buf), 6); // bits/sample uint16_t bits; MemoryU8 bitsBuffer = new MemoryU8(2, true); offset += file.read(new Pointer <uint8_t>(bitsBuffer), 2); bits = bitsBuffer.GetUInt16(); bits = little_endianize_int16(bits); if (bits != 8 && bits != 16) { osd_printf_warning("unsupported bits/sample {0} - only 8 and 16 are supported ({1})\n", bits, file.filename()); return(false); } // seek past any extra data file.seek(length - 16, SEEK_CUR); offset += length - 16; // seek until we find a data tag while (true) { offset += file.read(new Pointer <uint8_t>(buf), 4); offset += file.read(new Pointer <uint8_t>(lengthBuffer), 4); length = lengthBuffer.GetUInt32(); length = little_endianize_int32(length); if (buf[0] == 'd' && buf[1] == 'a' && buf[2] == 't' && buf[3] == 'a') //if (memcmp(&buf[0], "data", 4) == 0) { break; } // seek to the next block file.seek(length, SEEK_CUR); offset += length; if (offset >= filesize) { osd_printf_warning("Could not find data tag ({0})\n", file.filename()); return(false); } } // if there was a 0 length data block, we're done if (length == 0) { osd_printf_warning("empty data block ({0})\n", file.filename()); return(false); } // fill in the sample data sample.frequency = rate; // read the data in if (bits == 8) { sample.data.resize(length); MemoryU8 sample_data_8bit = new MemoryU8((int)length, true); file.read(new Pointer <uint8_t>(sample_data_8bit), length); // convert 8-bit data to signed samples Pointer <uint8_t> tempptr = new Pointer <uint8_t>(sample_data_8bit); //uint8_t *tempptr = reinterpret_cast<uint8_t *>(&sample.data[0]); for (int sindex = (int)length - 1; sindex >= 0; sindex--) { sample.data[sindex] = (int16_t)((uint8_t)(tempptr[sindex] ^ 0x80) * 256); } } else { // 16-bit data is fine as-is sample.data.resize(length / 2); MemoryU8 sample_data_8bit = new MemoryU8((int)length, true); file.read(new Pointer <uint8_t>(sample_data_8bit), length); // swap high/low on big-endian systems if (ENDIANNESS_NATIVE != ENDIANNESS_LITTLE) { for (uint32_t sindex = 0; sindex < length / 2; sindex++) { sample.data[sindex] = (int16_t)little_endianize_int16(sample_data_8bit.GetUInt16((int)sindex)); //sample.data[sindex]); } } } return(true); }
// 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); }