//------------------------------------------------- // load_zipped_file - load a ZIPped file //------------------------------------------------- std.error_condition load_zipped_file() { assert(m_file == null); assert(m_zipdata.empty()); assert(m_zipfile != null); // allocate some memory m_zipdata.resize(m_ziplength); // read the data into our buffer and return var ziperr = m_zipfile.decompress(m_zipdata, (uint32_t)m_zipdata.size()); if (ziperr) { m_zipdata.clear(); return(ziperr); } // convert to RAM file std.error_condition filerr = util.core_file.open_ram(m_zipdata, m_zipdata.size(), m_openflags, out m_file); if (filerr) { m_zipdata.clear(); return(filerr); } // close out the ZIP file m_zipfile.Dispose(); m_zipfile = null; return(new std.error_condition()); }
// address translation //bool translate(int spacenum, int intention, offs_t &address) { return memory_translate(spacenum, intention, address); } // deliberately ambiguous functions; if you have the memory interface // just use it //device_memory_interface &memory() { return *this; } // setup functions - these are called in sequence for all device_memory_interface by the memory manager //template <typename Space> public void allocate(address_space Space, memory_manager manager, int spacenum) { assert((0 <= spacenum) && (max_space_count() > spacenum)); m_addrspace.resize(std.max(m_addrspace.size(), (size_t)spacenum + 1)); assert(m_addrspace[spacenum] == null); m_addrspace[spacenum] = Space; //std::make_unique<Space>(manager, *this, spacenum, space_config(spacenum)->addr_width()); }
//------------------------------------------------- // allocate_color_tables - allocate memory for // pen and color tables //------------------------------------------------- void allocate_color_tables() { int total_colors = m_palette.num_colors() * m_palette.num_groups(); // allocate memory for the pen table switch (m_format) { case bitmap_format.BITMAP_FORMAT_IND16: // create a dummy 1:1 mapping { m_pen_array.resize((size_t)total_colors + 2); Pointer <rgb_t> pentable = new Pointer <rgb_t>(m_pen_array); //pen_t *pentable = &m_pen_array[0]; m_pens = new Pointer <rgb_t>(m_pen_array); //m_pens = &m_pen_array[0]; for (int i = 0; i < total_colors + 2; i++) { pentable[i] = new rgb_t((uint32_t)i); //pentable[i] = i; } } break; case bitmap_format.BITMAP_FORMAT_RGB32: m_pens = new Pointer <rgb_t>(m_palette.entry_list_adjusted()); // reinterpret_cast<const pen_t *>(m_palette.entry_list_adjusted()); break; default: m_pens = null; break; } }
//------------------------------------------------- // interface_pre_start - work to be done prior to // actually starting a device //------------------------------------------------- public override void interface_pre_start() { // allocate the palette u32 numentries = palette_entries(); allocate_palette(numentries); allocate_color_tables(); allocate_shadow_tables(); // allocate indirection tables int indirect_colors = (int)palette_indirect_entries(); if (indirect_colors > 0) { m_indirect_colors.resize(indirect_colors); for (int color = 0; color < indirect_colors; color++) { // alpha = 0 ensures change is detected the first time set_indirect_color() is called m_indirect_colors[color] = rgb_t.transparent(); } m_indirect_pens.resize((int)numentries); for (int pen = 0; pen < numentries; pen++) { m_indirect_pens[pen] = (UInt16)(pen % indirect_colors); } } }
ioport_charqueue_empty_delegate m_charqueue_empty; // character queue empty callback // construction/destruction //------------------------------------------------- // natural_keyboard - constructor //------------------------------------------------- public natural_keyboard(running_machine machine) { m_machine = machine; m_have_charkeys = false; m_in_use = false; m_bufbegin = 0; m_bufend = 0; m_current_code = null; m_fieldnum = 0; m_status_keydown = false; m_last_cr = false; m_timer = null; m_current_rate = attotime.zero; m_queue_chars = null; m_accept_char = null; m_charqueue_empty = null; // try building a list of keycodes; if none are available, don't bother build_codes(); if (!m_keyboards.empty()) { m_buffer.resize(KEY_BUFFER_SIZE); m_timer = machine.scheduler().timer_alloc(timer); } // retrieve option setting set_in_use(machine.options().natural_keyboard()); }
//------------------------------------------------- // 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); }
// configuration helpers //template <typename T, typename U, typename Ret, typename... Params> //std::enable_if_t<is_related_device<T, U>::value> set_addrmap(int spacenum, T &obj, Ret (U::*func)(Params...)) { set_addrmap(spacenum, address_map_constructor(func, obj.tag(), &downcast<U &>(obj))); } //template <typename T, typename U, typename Ret, typename... Params> //std::enable_if_t<is_related_interface<T, U>::value> set_addrmap(int spacenum, T &obj, Ret (U::*func)(Params...)) { set_addrmap(spacenum, address_map_constructor(func, obj.device().tag(), &downcast<U &>(obj))); } //template <typename T, typename U, typename Ret, typename... Params> //std::enable_if_t<is_unrelated_device<T, U>::value> set_addrmap(int spacenum, T &obj, Ret (U::*func)(Params...)) { set_addrmap(spacenum, address_map_constructor(func, obj.tag(), &dynamic_cast<U &>(obj))); } //template <typename T, typename U, typename Ret, typename... Params> //std::enable_if_t<is_unrelated_interface<T, U>::value> set_addrmap(int spacenum, T &obj, Ret (U::*func)(Params...)) { set_addrmap(spacenum, address_map_constructor(func, obj.device().tag(), &dynamic_cast<U &>(obj))); } //template <typename T, typename Ret, typename... Params> //std::enable_if_t<is_related_class<device_t, T>::value> set_addrmap(int spacenum, Ret (T::*func)(Params...)); //template <typename T, typename Ret, typename... Params> //std::enable_if_t<!is_related_class<device_t, T>::value> set_addrmap(int spacenum, Ret (T::*func)(Params...)); //------------------------------------------------- // set_addrmap - connect an address map to a device //------------------------------------------------- public void set_addrmap(int spacenum, address_map_constructor map) { if (spacenum >= (int)(m_address_map.size())) { m_address_map.resize(spacenum + 1, null); } m_address_map[spacenum] = map; }
//------------------------------------------------- // allocate_shadow_tables - allocate memory for // shadow tables //------------------------------------------------- void allocate_shadow_tables() { int numentries = m_palette.num_colors(); // if we have shadows, allocate shadow tables if (m_shadow_group != 0) { m_shadow_array.resize(65536); // palettized mode gets a single 64k table in slots 0 and 2 if (m_format == bitmap_format.BITMAP_FORMAT_IND16) { m_shadow_tables[2].base_ = new ListPointer <pen_t>(m_shadow_array, 0); //m_shadow_tables[0].base = m_shadow_tables[2].base = &m_shadow_array[0]; m_shadow_tables[0].base_ = new ListPointer <pen_t>(m_shadow_array, 0); for (int i = 0; i < 65536; i++) { m_shadow_array[i] = (i < numentries) ? (pen_t)(i + numentries) : (pen_t)i; } } // RGB mode gets two 32k tables in slots 0 and 2 else { m_shadow_tables[0].base_ = new ListPointer <pen_t>(m_shadow_array, 0); m_shadow_tables[2].base_ = new ListPointer <pen_t>(m_shadow_array, 32768); configure_rgb_shadows(0, PALETTE_DEFAULT_SHADOW_FACTOR); } } // if we have hilights, allocate shadow tables if (m_hilight_group != 0) { m_hilight_array.resize(65536); // palettized mode gets a single 64k table in slots 1 and 3 if (m_format == bitmap_format.BITMAP_FORMAT_IND16) { m_shadow_tables[3].base_ = new ListPointer <pen_t>(m_hilight_array, 0); //m_shadow_tables[1].base_ = m_shadow_tables[3].base_ = &m_hilight_array[0]; m_shadow_tables[1].base_ = new ListPointer <pen_t>(m_hilight_array, 0); for (int i = 0; i < 65536; i++) { m_hilight_array[i] = (i < numentries) ? (pen_t)(i + 2 * numentries) : (pen_t)i; } } // RGB mode gets two 32k tables in slots 1 and 3 else { m_shadow_tables[1].base_ = new ListPointer <pen_t>(m_hilight_array, 0); m_shadow_tables[3].base_ = new ListPointer <pen_t>(m_hilight_array, 32768); configure_rgb_shadows(1, PALETTE_DEFAULT_HIGHLIGHT_FACTOR); } } // set the default table m_shadow_table = m_shadow_tables[0] != null ? new ListPointer <pen_t>(m_shadow_tables[0].base_) : 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(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); }
// configuration helpers //template <typename T, typename U, typename Ret, typename... Params> //std::enable_if_t<is_related_device<T, U>::value> set_addrmap(int spacenum, T &obj, Ret (U::*func)(Params...)) { set_addrmap(spacenum, address_map_constructor(func, obj.tag(), &downcast<U &>(obj))); } //template <typename T, typename U, typename Ret, typename... Params> //std::enable_if_t<is_related_interface<T, U>::value> set_addrmap(int spacenum, T &obj, Ret (U::*func)(Params...)) { set_addrmap(spacenum, address_map_constructor(func, obj.device().tag(), &downcast<U &>(obj))); } //template <typename T, typename U, typename Ret, typename... Params> //std::enable_if_t<is_unrelated_device<T, U>::value> set_addrmap(int spacenum, T &obj, Ret (U::*func)(Params...)) { set_addrmap(spacenum, address_map_constructor(func, obj.tag(), &dynamic_cast<U &>(obj))); } //template <typename T, typename U, typename Ret, typename... Params> //std::enable_if_t<is_unrelated_interface<T, U>::value> set_addrmap(int spacenum, T &obj, Ret (U::*func)(Params...)) { set_addrmap(spacenum, address_map_constructor(func, obj.device().tag(), &dynamic_cast<U &>(obj))); } //template <typename T, typename Ret, typename... Params> //void set_addrmap(int spacenum, Ret (T::*func)(Params...)); //------------------------------------------------- // set_addrmap - connect an address map to a device //------------------------------------------------- public void set_addrmap(int spacenum, address_map_constructor map) { assert(0 <= spacenum); if (spacenum >= (int)(m_address_map.size())) { m_address_map.resize((size_t)spacenum + 1); } m_address_map[spacenum] = map; }
// construction public ymfm_saved_state(std.vector <uint8_t> buffer, bool saving) { m_buffer = buffer; m_offset = saving ? -1 : 0; if (saving) { buffer.resize(0); } }
// optional operation overrides //virtual bool memory_translate(int spacenum, int intention, offs_t &address); // interface-level overrides //------------------------------------------------- // interface_config_complete - perform final // memory configuration setup //------------------------------------------------- public override void interface_config_complete() { space_config_vector r = memory_space_config(); foreach (var entry in r) { if (entry.Key >= (int)(m_address_config.size())) { m_address_config.resize(entry.Key + 1); } m_address_config[entry.Key] = entry.Value; } }
// optional operation overrides //virtual bool memory_translate(int spacenum, int intention, offs_t &address); // interface-level overrides //------------------------------------------------- // interface_config_complete - perform final // memory configuration setup //------------------------------------------------- public override void interface_config_complete() { space_config_vector r = memory_space_config(); foreach (var entry in r) { if (entry.first >= (int)(m_address_config.size())) { m_address_config.resize((size_t)entry.first + 1); } m_address_config[entry.first] = entry.second; } }
machine_config_cache m_config; //mutable machine_config_cache m_config; // construction/destruction //------------------------------------------------- // driver_enumerator - constructor //------------------------------------------------- public driver_enumerator(emu_options options) : base() { m_current = -1; m_filtered_count = 0; m_options = options; m_included = new std.vector <bool>(); m_included.resize(drivlist_global.s_driver_count); m_config = new util.lru_cache_map <int, machine_config>(CONFIG_CACHE_COUNT); include_all(); }
machine_config_cache m_config; //mutable machine_config_cache m_config; // construction/destruction //------------------------------------------------- // driver_enumerator - constructor //------------------------------------------------- public driver_enumerator(emu_options options) : base() { m_current = -1; m_filtered_count = 0; m_options = options; m_included = new std.vector <bool>(); m_included.resize(s_driver_count); m_config = new machine_config_cache(CONFIG_CACHE_COUNT); include_all(); }
//------------------------------------------------- // line::truncate //------------------------------------------------- public void truncate(UInt32 position) { assert(position <= m_characters.size()); // are we actually truncating? if (position < m_characters.size()) { // set the width as appropriate m_width = m_characters[(int)position].xoffset; // and resize the array m_characters.resize((int)position); } }
//------------------------------------------------- // resize - resize the dirty array and mark all // dirty //------------------------------------------------- public void resize(uint32_t colors) { // resize to the correct number of dwords and mark all entries dirty UInt32 dirty_dwords = (colors + 31) / 32; m_dirty.resize((int)dirty_dwords, (UInt32)0xff); // mark all entries dirty m_dirty[dirty_dwords - 1] &= (UInt32)((1 << ((int)colors % 32)) - 1); // set min/max m_mindirty = 0; m_maxdirty = colors - 1; }
//------------------------------------------------- // interface_post_start - work to be done after // actually starting a device //------------------------------------------------- public override void interface_post_start() { // set up save/restore of the palette m_save_pen.resize(m_palette.num_colors()); m_save_contrast.resize(m_palette.num_colors()); device().save_item(m_save_pen, "m_save_pen"); device().save_item(m_save_contrast, "m_save_contrast"); // save indirection tables if we have them if (m_indirect_colors.size() > 0) { device().save_item(m_indirect_colors, "m_indirect_colors"); device().save_item(m_indirect_pens, "m_indirect_pens"); } }
//------------------------------------------------- // resize - resize the dirty array and mark all // dirty //------------------------------------------------- public void resize(uint32_t colors) { // resize to the correct number of dwords and mark all entries dirty uint32_t dirty_dwords = (colors + 31) / 32; m_dirty.resize(dirty_dwords); std.fill(m_dirty, uint32_t.MaxValue); //std::fill(m_dirty.begin(), m_dirty.end(), ~uint32_t(0)); // mark all entries dirty m_dirty[dirty_dwords - 1] &= (1U << ((int)colors % 32)) - 1; // set min/max m_mindirty = 0; m_maxdirty = colors - 1; }
//------------------------------------------------- // interface_post_start - work to be done after // actually starting a device //------------------------------------------------- public override void interface_post_start() { // set up save/restore of the palette m_save_pen.resize((size_t)m_palette.num_colors()); m_save_contrast.resize((size_t)m_palette.num_colors()); device().save_item(NAME(new { m_save_pen })); device().save_item(NAME(new { m_save_contrast })); // save indirection tables if we have them if (m_indirect_colors.size() > 0) { device().save_item(NAME(new { m_indirect_colors })); device().save_item(NAME(new { m_indirect_pens })); } }
public static void wav_add_data_16lr(wav_file wav, ListPointer <int16_t> left, ListPointer <int16_t> right, int samples) //wav_file *wav, int16_t *left, int16_t *right, int samples) { std.vector <int16_t> temp = new std.vector <int16_t>(); int i; if (wav == null || samples == 0) { return; } /* resize dynamic array */ temp.resize(samples * 2); /* interleave */ for (i = 0; i < samples * 2; i++) { temp[i] = (i & 1) != 0 ? right[i / 2] : left[i / 2]; } throw new emu_unimplemented(); }
public static void wav_add_data_32(wav_file wav, ListPointer <int32_t> data, int samples, int shift) //wav_file *wav, int32_t *data, int samples, int shift) { std.vector <int16_t> temp = new std.vector <int16_t>(); int i; if (wav == null || samples == 0) { return; } /* resize dynamic array */ temp.resize(samples); /* clamp */ for (i = 0; i < samples; i++) { int val = data[i] >> shift; temp[i] = (Int16)((val < -32768) ? -32768 : (val > 32767) ? 32767 : val); } throw new emu_unimplemented(); }
// optional operation overrides //------------------------------------------------- // interface_pre_start - perform startup prior // to the device startup //------------------------------------------------- public override void interface_pre_start() { // call our parent base.interface_pre_start(); // no inputs? that's weird if (m_auto_allocated_inputs == 0) { device().logerror("Warning: mixer \"{0}\" has no inputs\n", device().tag()); return; } // generate the output map m_outputmap.resize((size_t)m_auto_allocated_inputs); // iterate through all routes that point to us and note their mixer output foreach (device_sound_interface sound in new sound_interface_enumerator(device().machine().root_device())) { foreach (sound_route route in sound.routes()) { // see if we are the target of this route device_t target_device = route.m_base.subdevice(route.m_target); if (target_device == device() && route.m_input < m_auto_allocated_inputs) { int count = (route.m_output == ALL_OUTPUTS) ? sound.outputs() : 1; for (int output = 0; output < count; output++) { m_outputmap[(int)(route.m_input + output)] = (u8)route.m_mixoutput; } } } } // keep a small buffer handy for tracking cleared buffers m_output_clear.resize(m_outputs); // allocate the mixer stream m_mixer_stream = stream_alloc(m_auto_allocated_inputs, m_outputs, (u32)device().machine().sample_rate(), sound_stream_flags.STREAM_DEFAULT_FLAGS); }
/* compute all values */ public static void compute_res_net_all(out std.vector <rgb_t> rgb, ListBytesPointer prom, res_net_decode_info rdi, res_net_info di) //std::vector<rgb_t> &rgb, const u8 *prom, const res_net_decode_info &rdi, const res_net_info &di); { u8 r; u8 g; u8 b; int i; int j; int k; rgb = new std.vector <rgb_t>(); rgb.resize(rdi.end - rdi.start + 1); for (i = rdi.start; i <= rdi.end; i++) { u8 [] t = new u8[3] { 0, 0, 0 }; int s; for (j = 0; j < rdi.numcomp; j++) { for (k = 0; k < 3; k++) { s = rdi.shift[3 * j + k]; if (s > 0) { t[k] = (u8)(t[k] | ((prom[i + rdi.offset[3 * j + k]] >> s) & rdi.mask[3 * j + k])); } else { t[k] = (u8)(t[k] | ((prom[i + rdi.offset[3 * j + k]] << (0 - s)) & rdi.mask[3 * j + k])); } } } r = (u8)compute_res_net(t[0], RES_NET_CHAN_RED, di); g = (u8)compute_res_net(t[1], RES_NET_CHAN_GREEN, di); b = (u8)compute_res_net(t[2], RES_NET_CHAN_BLUE, di); rgb[i - rdi.start] = new rgb_t(r, g, b); } }
public static void wav_add_data_32lr(wav_file wav, ListPointer <int32_t> left, ListPointer <int32_t> right, int samples, int shift) //wav_file *wav, int32_t *left, int32_t *right, int samples, int shift) { std.vector <int16_t> temp = new std.vector <int16_t>(); int i; if (wav == null || samples == 0) { return; } /* resize dynamic array */ temp.resize(samples); /* interleave */ for (i = 0; i < samples * 2; i++) { int val = (i & 1) != 0 ? right[i / 2] : left[i / 2]; val >>= shift; temp[i] = (Int16)((val < -32768) ? -32768 : (val > 32767) ? 32767 : val); } throw new emu_unimplemented(); }
// device-level overrides //------------------------------------------------- // device_start - handle device startup //------------------------------------------------- protected override void device_start() { m_disound = GetClassInterface <device_sound_interface_namco>(); // read audio samples load_samples(); // allocate channels m_channel.resize(m_channels); for (int channel = 0; channel < m_channels; channel++) { // initialize channel channel_t chan = m_channel[channel]; chan.stream = m_disound.stream_alloc(0, 1, machine().sample_rate()); chan.source = null; chan.source_num = -1; chan.step = 0; chan.loop = false; chan.paused = false; // register with the save state system save_item(chan.source_length, "chan.source_length", channel); save_item(chan.source_num, "chan.source_num", channel); save_item(chan.pos, "chan.pos", channel); save_item(chan.frac, "chan.frac", channel); save_item(chan.step, "chan.step", channel); save_item(chan.loop, "chan.loop", channel); save_item(chan.paused, "chan.paused", channel); } // initialize any custom handlers //m_samples_start_cb.bind_relative_to(owner()); if (m_samples_start_cb != null) { m_samples_start_cb(); } }
// optional operation overrides //------------------------------------------------- // interface_pre_start - perform startup prior // to the device startup //------------------------------------------------- public override void interface_pre_start() { // call our parent base.interface_pre_start(); // no inputs? that's weird if (m_auto_allocated_inputs == 0) { device().logerror("Warning: mixer \"{0}\" has no inputs\n", device().tag()); return; } // generate the output map m_outputmap.resize(m_auto_allocated_inputs); // iterate through all routes that point to us and note their mixer output foreach (device_sound_interface sound in new sound_interface_iterator(device().machine().root_device())) { foreach (sound_route route in sound.routes()) { // see if we are the target of this route device_t target_device = route.m_base.get().subdevice(route.m_target.c_str()); if ((target_device == device()) && (route.m_input < m_auto_allocated_inputs)) { int count = (route.m_output == ALL_OUTPUTS) ? sound.outputs() : 1; for (int output = 0; output < count; output++) { m_outputmap[(int)(route.m_input + output)] = (byte)route.m_mixoutput; } } } } // allocate the mixer stream m_mixer_stream = stream_alloc(m_auto_allocated_inputs, m_outputs, device().machine().sample_rate()); }
// device-level overrides //------------------------------------------------- // device_start - handle device startup //------------------------------------------------- protected override void device_start() { m_disound = GetClassInterface <device_sound_interface_samples>(); // read audio samples load_samples(); // allocate channels m_channel.resize(m_channels); for (int channel = 0; channel < m_channels; channel++) { // initialize channel channel_t chan = m_channel[channel]; chan.stream = m_disound.stream_alloc(0, 1, SAMPLE_RATE_OUTPUT_ADAPTIVE); chan.source = null; chan.source_num = -1; chan.pos = 0; chan.loop = false; chan.paused = false; // register with the save state system save_item(NAME(new { chan.source_num }), channel); save_item(NAME(new { chan.source_len }), channel); save_item(NAME(new { chan.pos }), channel); save_item(NAME(new { chan.loop }), channel); save_item(NAME(new { chan.paused }), channel); } // initialize any custom handlers //m_samples_start_cb.resolve(); if (m_samples_start_cb != null) { m_samples_start_cb(); } }
// decoding //------------------------------------------------- // decode_gfx - parse gfx decode info and // create gfx elements //------------------------------------------------- void decode_gfx(gfx_decode_entry [] gfxdecodeinfo) { // skip if nothing to do if (gfxdecodeinfo == null) { return; } // local variables to hold mutable copies of gfx layout data gfx_layout glcopy; std.vector <u32> extxoffs = new std.vector <u32>(0); std.vector <u32> extyoffs = new std.vector <u32>(0); // loop over all elements for (u8 curgfx = 0; curgfx < digfx_global.MAX_GFX_ELEMENTS && curgfx < gfxdecodeinfo.Length && gfxdecodeinfo[curgfx].gfxlayout != null; curgfx++) { gfx_decode_entry gfx = gfxdecodeinfo[curgfx]; // extract the scale factors and xormask u32 xscale = GFXENTRY_GETXSCALE(gfx.flags); u32 yscale = GFXENTRY_GETYSCALE(gfx.flags); u32 xormask = GFXENTRY_ISREVERSE(gfx.flags) ? 7U : 0U; // resolve the region u32 region_length; ListBytesPointer region_base; //const u8 *region_base; u8 region_width; endianness_t region_endianness; if (gfx.memory_region != null) { device_t basedevice = (GFXENTRY_ISDEVICE(gfx.flags)) ? device() : device().owner(); if (GFXENTRY_ISRAM(gfx.flags)) { memory_share share = basedevice.memshare(gfx.memory_region); //assert(share != NULL); region_length = (UInt32)(8 * share.bytes()); region_base = share.ptr(); //region_base = reinterpret_cast<u8 *>(share->ptr()); region_width = share.bytewidth(); region_endianness = share.endianness(); } else { memory_region region = basedevice.memregion(gfx.memory_region); //assert(region != NULL); region_length = 8 * region.bytes(); region_base = new ListBytesPointer(region.base_(), 0); //region_base = region->base(); region_width = region.bytewidth(); region_endianness = region.endianness(); } } else { region_length = 0; region_base = null; region_width = 1; region_endianness = ENDIANNESS_NATIVE; } if (region_endianness != ENDIANNESS_NATIVE) { switch (region_width) { case 2: xormask |= 0x08; break; case 4: xormask |= 0x18; break; case 8: xormask |= 0x38; break; } } // copy the layout into our temporary variable glcopy = new gfx_layout(gfx.gfxlayout); //memcpy(&glcopy, gfx.gfxlayout, sizeof(gfx_layout)); // if the character count is a region fraction, compute the effective total if (IS_FRAC(glcopy.total)) { //assert(region_length != 0); glcopy.total = region_length / glcopy.charincrement * FRAC_NUM(glcopy.total) / FRAC_DEN(glcopy.total); } // for non-raw graphics, decode the X and Y offsets if (glcopy.planeoffset[0] != digfx_global.GFX_RAW) { // copy the X and Y offsets into our temporary arrays extxoffs.resize((int)(glcopy.width * xscale)); extyoffs.resize((int)(glcopy.height * yscale)); //memcpy(&extxoffs[0], (glcopy.extxoffs != null) ? glcopy.extxoffs : glcopy.xoffset, glcopy.width * sizeof(UInt32)); //memcpy(&extyoffs[0], (glcopy.extyoffs != null) ? glcopy.extyoffs : glcopy.yoffset, glcopy.height * sizeof(UInt32)); for (int i = 0; i < glcopy.width; i++) { extxoffs[i] = glcopy.extxoffs != null ? glcopy.extxoffs[i] : glcopy.xoffset[i]; } for (int i = 0; i < glcopy.height; i++) { extyoffs[i] = glcopy.extyoffs != null ? glcopy.extyoffs[i] : glcopy.yoffset[i]; } // always use the extended offsets here glcopy.extxoffs = extxoffs; glcopy.extyoffs = extyoffs; // expand X and Y by the scale factors if (xscale > 1) { glcopy.width *= (UInt16)xscale; for (int j = glcopy.width - 1; j >= 0; j--) { extxoffs[j] = extxoffs[(int)(j / xscale)]; } } if (yscale > 1) { glcopy.height *= (UInt16)yscale; for (int j = glcopy.height - 1; j >= 0; j--) { extyoffs[j] = extyoffs[(int)(j / yscale)]; } } // loop over all the planes, converting fractions for (int j = 0; j < glcopy.planes; j++) { u32 value1 = glcopy.planeoffset[j]; if (IS_FRAC(value1)) { //assert(region_length != 0); glcopy.planeoffset[j] = FRAC_OFFSET(value1) + region_length * FRAC_NUM(value1) / FRAC_DEN(value1); } } // loop over all the X/Y offsets, converting fractions for (int j = 0; j < glcopy.width; j++) { u32 value2 = extxoffs[j]; if (digfx_global.IS_FRAC(value2)) { //assert(region_length != 0); extxoffs[j] = FRAC_OFFSET(value2) + region_length * FRAC_NUM(value2) / FRAC_DEN(value2); } } for (int j = 0; j < glcopy.height; j++) { u32 value3 = extyoffs[j]; if (IS_FRAC(value3)) { //assert(region_length != 0); extyoffs[j] = FRAC_OFFSET(value3) + region_length * FRAC_NUM(value3) / FRAC_DEN(value3); } } } // otherwise, just use the line modulo else { int base_ = (int)gfx.start; int end = (int)(region_length / 8); int linemod = (int)glcopy.yoffset[0]; while (glcopy.total > 0) { int elementbase = (int)(base_ + (glcopy.total - 1) * glcopy.charincrement / 8); int lastpixelbase = elementbase + glcopy.height * linemod / 8 - 1; if (lastpixelbase < end) { break; } glcopy.total--; } } // allocate the graphics //m_gfx[curgfx] = new gfx_element(m_palette, glcopy, region_base != null ? region_base + gfx.start : null, xormask, gfx.total_color_codes, gfx.color_codes_start); m_gfx[curgfx] = new gfx_element(m_paletteDevice.target.palette_interface, glcopy, region_base != null ? new ListBytesPointer(region_base, (int)gfx.start) : null, xormask, gfx.total_color_codes, gfx.color_codes_start); } m_decoded = true; }
void compress() { var zero = plib.constants <NT, NT_OPS> .zero(); var one = plib.constants <NT, NT_OPS> .one(); unsigned ptr = 0; var n = m_precompiled.size(); for (; ptr < n;) { switch (m_precompiled[ptr].cmd()) { case rpn_cmd.ADD: compress_OP(ref ptr, ref n, 1, ops.add(compress_ST2(ptr), compress_ST1(ptr))); break; //OP(ADD, 1, ST2 + ST1) case rpn_cmd.MULT: compress_OP(ref ptr, ref n, 1, ops.multiply(compress_ST2(ptr), compress_ST1(ptr))); break; //OP(MULT, 1, ST2 * ST1) case rpn_cmd.SUB: compress_OP(ref ptr, ref n, 1, ops.subtract(compress_ST2(ptr), compress_ST1(ptr))); break; //OP(SUB, 1, ST2 - ST1) case rpn_cmd.DIV: compress_OP(ref ptr, ref n, 1, ops.divide(compress_ST2(ptr), compress_ST1(ptr))); break; //OP(DIV, 1, ST2 / ST1) case rpn_cmd.EQ: compress_OP(ref ptr, ref n, 1, ops.equals(compress_ST2(ptr), compress_ST1(ptr)) ? one : zero); break; //OP(EQ, 1, ST2 == ST1 ? one : zero) case rpn_cmd.NE: compress_OP(ref ptr, ref n, 1, ops.not_equals(compress_ST2(ptr), compress_ST1(ptr)) ? one : zero); break; //OP(NE, 1, ST2 != ST1 ? one : zero) case rpn_cmd.GT: compress_OP(ref ptr, ref n, 1, ops.greater_than(compress_ST2(ptr), compress_ST1(ptr)) ? one : zero); break; //OP(GT, 1, ST2 > ST1 ? one : zero) case rpn_cmd.LT: compress_OP(ref ptr, ref n, 1, ops.less_than(compress_ST2(ptr), compress_ST1(ptr)) ? one : zero); break; //OP(LT, 1, ST2 < ST1 ? one : zero) case rpn_cmd.LE: compress_OP(ref ptr, ref n, 1, ops.less_than_or_equal(compress_ST2(ptr), compress_ST1(ptr)) ? one : zero); break; //OP(LE, 1, ST2 <= ST1 ? one : zero) case rpn_cmd.GE: compress_OP(ref ptr, ref n, 1, ops.greater_than_or_equal(compress_ST2(ptr), compress_ST1(ptr)) ? one : zero); break; //OP(GE, 1, ST2 >= ST1 ? one : zero) case rpn_cmd.IF: compress_OP(ref ptr, ref n, 2, ops.not_equals(compress_ST2(ptr), zero) ? compress_ST1(ptr) : compress_ST0(ptr)); break; //OP(IF, 2, (ST2 != zero) ? ST1 : ST0) case rpn_cmd.NEG: compress_OP(ref ptr, ref n, 0, ops.neg(compress_ST2(ptr))); break; //OP(NEG, 0, -ST2) case rpn_cmd.POW: compress_OP(ref ptr, ref n, 1, ops.pow(compress_ST2(ptr), compress_ST1(ptr))); break; //OP(POW, 1, plib::pow(ST2, ST1)) case rpn_cmd.LOG: compress_OP(ref ptr, ref n, 0, ops.log(compress_ST2(ptr))); break; //OP(LOG, 0, plib::log(ST2)) case rpn_cmd.SIN: compress_OP(ref ptr, ref n, 0, ops.sin(compress_ST2(ptr))); break; //OP(SIN, 0, plib::sin(ST2)) case rpn_cmd.COS: compress_OP(ref ptr, ref n, 0, ops.cos(compress_ST2(ptr))); break; //OP(COS, 0, plib::cos(ST2)) case rpn_cmd.MAX: compress_OP(ref ptr, ref n, 1, ops.max(compress_ST2(ptr), compress_ST1(ptr))); break; //OP(MAX, 1, std::max(ST2, ST1)) case rpn_cmd.MIN: compress_OP(ref ptr, ref n, 1, ops.min(compress_ST2(ptr), compress_ST1(ptr))); break; //OP(MIN, 1, std::min(ST2, ST1)) case rpn_cmd.TRUNC: compress_OP(ref ptr, ref n, 0, ops.trunc(compress_ST2(ptr))); break; //OP(TRUNC, 0, plib::trunc(ST2)) case rpn_cmd.RAND: compress_OP0(ref ptr, lfsr_random(ref m_lfsr)); break; //OP0(RAND, lfsr_random<value_type>(m_lfsr)) case rpn_cmd.PUSH_INPUT: compress_OP0(ref ptr, default); break; //OP0(PUSH_INPUT, values[rc.index()]) case rpn_cmd.PUSH_CONST: compress_OP0(ref ptr, default); break; //OP0(PUSH_CONST, rc.value()) // please compiler case rpn_cmd.LP: case rpn_cmd.RP: break; } } //printf("func %lld %lld\n", m_precompiled.size(), n); m_precompiled.resize(n); }