Exemple #1
0
        //-------------------------------------------------
        //  audit_one_disk - validate a single disk entry
        //-------------------------------------------------
        audit_record audit_one_disk(ListPointer <rom_entry> rom, string locationtag = null)  //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_DISK)).Value;  //audit_record &record = *m_record_list.emplace(m_record_list.end(), *rom, media_type::DISK);

            // open the disk
            chd_file  source = new chd_file();
            chd_error err    = (chd_error)romload_global.open_disk_image(m_enumerator.options(), m_enumerator.driver(), rom[0], source, locationtag);

            // if we succeeded, get the hashes
            if (err == chd_error.CHDERR_NONE)
            {
                util.hash_collection hashes = new util.hash_collection();

                // if there's a SHA1 hash, add them to the output hash
                if (source.sha1() != null)
                {
                    hashes.add_sha1(source.sha1());
                }

                // update the actual values
                record.set_actual(hashes);
            }

            // compute the final status
            compute_status(record, rom[0], err == chd_error.CHDERR_NONE);
            return(record);
        }
Exemple #2
0
        //-------------------------------------------------
        //  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(total_colors + 2);
                ListPointer <rgb_t> pentable = new ListPointer <rgb_t>(m_pen_array); //pen_t *pentable = &m_pen_array[0];
                m_pens = new ListPointer <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)i);          //pentable[i] = i;
                }
            }
            break;

            case bitmap_format.BITMAP_FORMAT_RGB32:
                m_pens = new ListPointer <rgb_t>(m_palette.entry_list_adjusted());     // reinterpret_cast<const pen_t *>(m_palette.entry_list_adjusted());
                break;

            default:
                m_pens = null;
                break;
            }
        }
Exemple #3
0
        //-------------------------------------------------
        //  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;
        }
Exemple #4
0
        public static void wav_add_data_16(wav_file wav, ListPointer <int16_t> data, int samples)  //wav_file *wav, int16_t *data, int samples)
        {
            if (wav == null || samples == 0)
            {
                return;
            }

            throw new emu_unimplemented();
        }
Exemple #5
0
        //-------------------------------------------------
        //  audit_device - audit the device
        //-------------------------------------------------
        public summary audit_device(device_t device, string validation = AUDIT_VALIDATE_FULL)
        {
            // start fresh
            m_record_list.clear();

            // store validation for later
            m_validation = validation;
            m_searchpath = device.shortname();

            int found    = 0;
            int required = 0;

            // now iterate over regions and ROMs within
            for (ListPointer <rom_entry> region = romload_global.rom_first_region(device); region != null; region = romload_global.rom_next_region(region))
            {
                for (ListPointer <rom_entry> rom = romload_global.rom_first_file(region); rom != null; rom = romload_global.rom_next_file(rom))
                {
                    util.hash_collection hashes = new util.hash_collection(romload_global.ROM_GETHASHDATA(rom[0]));

                    // count the number of files with hashes
                    if (!hashes.flag(util.hash_collection.FLAG_NO_DUMP) && !romload_global.ROM_ISOPTIONAL(rom[0]))
                    {
                        required++;
                    }

                    // audit a file
                    audit_record record = null;
                    if (romload_global.ROMREGION_ISROMDATA(region[0]))
                    {
                        record = audit_one_rom(rom);
                    }
                    // audit a disk
                    else if (romload_global.ROMREGION_ISDISKDATA(region[0]))
                    {
                        record = audit_one_disk(rom);
                    }

                    // count the number of files that are found.
                    if (record != null && (record.status() == audit_record.audit_status.STATUS_GOOD || record.status() == audit_record.audit_status.STATUS_FOUND_INVALID))
                    {
                        found++;
                    }
                }
            }

            if (found == 0 && required > 0)
            {
                m_record_list.clear();
                return(summary.NOTFOUND);
            }

            // return a summary
            string unused = "";

            return(summarize(device.shortname(), ref unused));
        }
Exemple #6
0
        /* generate sound by oversampling */
        public uint32_t namco_update_one(ListPointer <stream_sample_t> buffer, int length, ListPointer <int16_t> wave, uint32_t counter, uint32_t freq)  //uint32_t namco_audio_device::namco_update_one(stream_sample_t *buffer, int length, const int16_t *wave, uint32_t counter, uint32_t freq)
        {
            while (length-- > 0)
            {
                buffer[0] = wave[WAVEFORM_POSITION((int)counter)];  // *buffer++ += wave[WAVEFORM_POSITION(counter)];
                buffer++;
                counter += freq;
            }

            return(counter);
        }
Exemple #7
0
        void stream_generate(sound_stream stream, ListPointer <stream_sample_t> [] inputs, ListPointer <stream_sample_t> [] outputs, int samples)
        {
            ListPointer <stream_sample_t> ptr = new ListPointer <stream_sample_t>(outputs[0]);  //stream_sample_t *ptr = outputs[0];
            int samplenum = samples;

            while (samplenum-- > 0)
            {
                ptr[0] = m_data;
                ptr++;
            }
        }
Exemple #8
0
        // finder
        public override bool findit(bool isvalidation = false)
        {
            if (isvalidation)
            {
                return(true);
            }

            assert(!this.resolved);
            this.resolved = true;
            target        = find_memshare(0, out m_bytes, Required); // reinterpret_cast<_PointerType *>(this.find_memshare(m_width, m_bytes, _Required));
            return(report_missing(this.target != null, "shared pointer", Required));
        }
Exemple #9
0
 // construction/destruction
 //-------------------------------------------------
 //  device_palette_interface - constructor
 //-------------------------------------------------
 public device_palette_interface(machine_config mconfig, device_t device)
     : base(device, "palette")
 {
     m_palette       = null;
     m_pens          = null;
     m_format        = bitmap_format.BITMAP_FORMAT_RGB32;
     m_shadow_table  = null;
     m_shadow_group  = 0;
     m_hilight_group = 0;
     m_white_pen     = 0;
     m_black_pen     = 0;
 }
Exemple #10
0
        public override void update_audio_stream(ListPointer<Int16> buffer, int samples_this_frame)  //const int16_t *buffer, int samples_this_frame) = 0;
        {
            base.update_audio_stream(buffer, samples_this_frame);

            if (audioUpdateCount++ % 10 == 0)
                osd_printf_info("osd_interface.update_audio_stream() - {0} - samples: {1}\n", audioUpdateCount, samples_this_frame);

            lock (osdlock_audio)
            {
                for (int i = 0; i < samples_this_frame; i++)
                    m_audiobuffer.Enqueue(buffer[i]);
            }
        }
Exemple #11
0
        //-------------------------------------------------
        //  find_shared_device - return the source that
        //  shares a media entry with the same hashes
        //-------------------------------------------------
        device_t find_shared_device(device_t device, string name, util.hash_collection romhashes, UInt64 romlength)
        {
            bool dumped = !romhashes.flag(util.hash_collection.FLAG_NO_DUMP);

            // special case for non-root devices
            device_t highest_device = null;

            if (device.owner() != null)
            {
                for (ListPointer <rom_entry> region = romload_global.rom_first_region(device); region != null; region = romload_global.rom_next_region(region))
                {
                    for (ListPointer <rom_entry> rom = romload_global.rom_first_file(region); rom != null; rom = romload_global.rom_next_file(rom))
                    {
                        if (romload_global.ROM_GETLENGTH(rom[0]) == romlength)
                        {
                            util.hash_collection hashes = new util.hash_collection(romload_global.ROM_GETHASHDATA(rom[0]));
                            if ((dumped && hashes == romhashes) || (!dumped && romload_global.ROM_GETNAME(rom[0]) == name))
                            {
                                highest_device = device;
                            }
                        }
                    }
                }
            }
            else
            {
                // iterate up the parent chain
                for (int drvindex = driver_enumerator.find(m_enumerator.driver().parent); drvindex != -1; drvindex = driver_enumerator.find(driver_enumerator.driver(drvindex).parent))
                {
                    foreach (device_t scandevice in new device_iterator(m_enumerator.config(drvindex).root_device()))
                    {
                        for (ListPointer <rom_entry> region = romload_global.rom_first_region(scandevice); region != null; region = romload_global.rom_next_region(region))
                        {
                            for (ListPointer <rom_entry> rom = romload_global.rom_first_file(region); rom != null; rom = romload_global.rom_next_file(rom))
                            {
                                if (romload_global.ROM_GETLENGTH(rom[0]) == romlength)
                                {
                                    util.hash_collection hashes = new util.hash_collection(romload_global.ROM_GETHASHDATA(rom[0]));
                                    if ((dumped && hashes == romhashes) || (!dumped && romload_global.ROM_GETNAME(rom[0]) == name))
                                    {
                                        highest_device = scandevice;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(highest_device);
        }
Exemple #12
0
        device_t m_shared_device;                                      /* device that shares the rom */


        // construction/destruction
        //-------------------------------------------------
        //  audit_record - constructor
        //-------------------------------------------------
        public audit_record(ListPointer <rom_entry> media, media_type type)
        {
            m_next          = null;
            m_type          = type;
            m_status        = audit_status.STATUS_ERROR;
            m_substatus     = audit_substatus.SUBSTATUS_ERROR;
            m_name          = romload_global.ROM_GETNAME(media[0]);
            m_explength     = romload_global.rom_file_size(media);
            m_length        = 0;
            m_shared_device = null;


            m_exphashes.from_internal_string(romload_global.ROM_GETHASHDATA(media[0]));
        }
Exemple #13
0
 void FindPlayableCards()
 {
     playable = new List <ListPointer>();
     if (hand.Count > 0)
     {
         SortPlayable(hand);
     }
     else if (visible.Count > 0)
     {
         SortPlayable(visible);
     }
     else
     {
         playable = ListPointer.AllPointers(hidden);
     }
 }
Exemple #14
0
        //-------------------------------------------------
        //  generate_samples - generate the requested
        //  number of samples for a stream, making sure
        //  all inputs have the appropriate number of
        //  samples generated
        //-------------------------------------------------
        void generate_samples(int samples)
        {
            ListPointer <stream_sample_t> [] inputs  = null; //stream_sample_t **inputs = nullptr;
            ListPointer <stream_sample_t> [] outputs = null; //stream_sample_t **outputs = nullptr;

            sound_global.VPRINTF("generate_samples({0}, {1})\n", this, samples);
            assert(samples > 0);

            // ensure all inputs are up to date and generate resampled data
            for (int inputnum = 0; inputnum < m_input.size(); inputnum++)
            {
                // update the stream to the current time
                stream_input input = m_input[inputnum];
                if (input.m_source != null)
                {
                    input.m_source.m_stream.update();
                }

                // generate the resampled data
                m_input_array[inputnum] = generate_resampled_data(input, (UInt32)samples);
            }

            if (!m_input.empty())
            {
                inputs = m_input_array;
            }

            // loop over all outputs and compute the output pointer
            for (int outputnum = 0; outputnum < m_output.size(); outputnum++)
            {
                stream_output output = m_output[outputnum];
                m_output_array[outputnum] = new ListPointer <stream_sample_t>(output.m_buffer, m_output_sampindex - m_output_base_sampindex);  // m_output_array[outputnum] = &output.m_buffer[m_output_sampindex - m_output_base_sampindex];
            }

            if (!m_output.empty())
            {
                outputs = m_output_array;
            }

            // run the callback
            sound_global.VPRINTF("  callback({0}, {1})\n", this, samples);
            m_callback(this, inputs, outputs, samples);
            sound_global.VPRINTF("  callback done\n");
        }
Exemple #15
0
        // 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);
        }
Exemple #16
0
        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();
        }
Exemple #17
0
        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();
        }
Exemple #18
0
        // device_sound_interface overrides
        //-------------------------------------------------
        //  sound_stream_update - handle a stream update
        //-------------------------------------------------
        public override void sound_stream_update(sound_stream stream, ListPointer <stream_sample_t> [] inputs, ListPointer <stream_sample_t> [] outputs, int samples)
        {
            msm5205_device pokey = (msm5205_device)device();

            ListPointer <stream_sample_t> buffer = outputs[0];

            /* if this voice is active */
            if (pokey.signal != 0)
            {
                short val = (short)(pokey.signal * 16);
                while (samples != 0)
                {
                    buffer[0] = val;  //*buffer++ = val;
                    buffer++;
                    samples--;
                }
            }
            else
            {
                memset(buffer, 0, (UInt32)samples);  //memset(buffer, 0, samples * sizeof(*buffer));
            }
        }
Exemple #19
0
        public void transpen(bitmap_rgb32 dest, rectangle cliprect,
                             u32 code, u32 color, int flipx, int flipy, s32 destx, s32 desty,
                             u32 trans_pen)
        {
            // special case invalid pens to opaque
            if (trans_pen > 0xff)
            {
                opaque(dest, cliprect, code, color, flipx, flipy, destx, desty);
                return;
            }

            // use pen usage to optimize
            code %= elements();
            if (has_pen_usage())
            {
                // fully transparent; do nothing
                UInt32 usage = pen_usage(code);
                if ((usage & ~(1 << (int)trans_pen)) == 0)
                {
                    return;
                }

                // fully opaque; draw as such
                if ((usage & (1 << (int)trans_pen)) == 0)
                {
                    opaque(dest, cliprect, code, color, flipx, flipy, destx, desty);
                    return;
                }
            }

            // render
            ListPointer <rgb_t> paldata = new ListPointer <rgb_t>(m_palette.pens(), (int)(colorbase() + granularity() * (color % colors())));  //const pen_t *paldata = m_palette.pens() + colorbase() + granularity() * (color % colors());
            //DECLARE_NO_PRIORITY;
            bitmap_t priority = drawgfxm_global.drawgfx_dummy_priority_bitmap;

            //DRAWGFX_CORE(u32, PIXEL_OP_REMAP_TRANSPEN, NO_PRIORITY);
            drawgfxm_global.DRAWGFX_CORE <u32, drawgfxm_global.NO_PRIORITY>(drawgfxm_global.PIXEL_OP_REMAP_TRANSPEN, cliprect, destx, desty, width(), height(), flipx, flipy, rowbytes(), get_data, code, dest, priority, color, trans_pen, paldata, 2);
        }
Exemple #20
0
        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();
        }
Exemple #21
0
        //DISCRETE_CLASS_DESTRUCTOR(_name)                                    \
        //~discrete_dsd_555_astbl_node() { }


        // discrete_base_node

        //DISCRETE_RESET(dsd_555_astbl)
        public override void reset()
        {
            discrete_555_desc info = (discrete_555_desc)this.custom_data();  //DISCRETE_DECLARE_INFO(discrete_555_desc)

            m_use_ctrlv   = (this.input_is_node() >> 4) & 1;
            m_output_type = info.options & DISC_555_OUT_MASK;

            /* Use the defaults or supplied values. */
            m_v_out_high = (info.v_out_high == DEFAULT_555_HIGH) ? info.v_pos - 1.2 : info.v_out_high;

            /* setup v_charge or node */
            m_v_charge_node = m_device.node_output_ptr((int)info.v_charge);
            if (m_v_charge_node == null)
            {
                m_v_charge = (info.v_charge == DEFAULT_555_CHARGE) ? info.v_pos : info.v_charge;

                if ((info.options & DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE) != 0)
                {
                    m_v_charge -= 0.5;
                }
            }

            if ((DSD_555_ASTBL__CTRLV != -1) && m_use_ctrlv == 0)
            {
                /* Setup based on supplied Control Voltage static value */
                m_threshold = DSD_555_ASTBL__CTRLV;
                m_trigger   = DSD_555_ASTBL__CTRLV / 2.0;
            }
            else
            {
                /* Setup based on v_pos power source */
                m_threshold = info.v_pos * 2.0 / 3.0;
                m_trigger   = info.v_pos / 3.0;
            }

            /* optimization if none of the values are nodes */
            m_has_rc_nodes = 0;
            if ((this.input_is_node() & DSD_555_ASTBL_RC_MASK) != 0)
            {
                m_has_rc_nodes = 1;
            }
            else
            {
                m_t_rc_bleed     = DSD_555_ASTBL_T_RC_BLEED;
                m_exp_bleed      = RC_CHARGE_EXP(m_t_rc_bleed);
                m_t_rc_charge    = DSD_555_ASTBL_T_RC_CHARGE(info);
                m_exp_charge     = RC_CHARGE_EXP(m_t_rc_charge);
                m_t_rc_discharge = DSD_555_ASTBL_T_RC_DISCHARGE;
                m_exp_discharge  = RC_CHARGE_EXP(m_t_rc_discharge);
            }

            m_output_is_ac = info.options & DISC_555_OUT_AC;
            /* Calculate DC shift needed to make squarewave waveform AC */
            m_ac_shift = (m_output_is_ac != 0) ? -m_v_out_high / 2.0 : 0;

            m_flip_flop   = 1;
            m_cap_voltage = 0;

            /* Step to set the output */
            this.step();
        }
Exemple #22
0
        // device_sound_interface overrides
        //-------------------------------------------------
        //  sound_stream_update - handle a stream update
        //-------------------------------------------------
        public override void sound_stream_update(sound_stream stream, ListPointer <stream_sample_t> [] inputs, ListPointer <stream_sample_t> [] outputs, int samples)
        {
            ay8910_device ay8910 = (ay8910_device)device();

            ListPointer <stream_sample_t> [] buf = new ListPointer <stream_sample_t> [ay8910_device.NUM_CHANNELS];  //stream_sample_t *buf[NUM_CHANNELS];
            int chan;

            buf[0] = new ListPointer <stream_sample_t>(outputs[0]);
            buf[1] = null;
            buf[2] = null;
            if (ay8910.m_streams == ay8910_device.NUM_CHANNELS)
            {
                buf[1] = outputs[1];
                buf[2] = outputs[2];
            }

            /* hack to prevent us from hanging when starting filtered outputs */
            if (ay8910.m_ready == 0)
            {
                for (chan = 0; chan < ay8910_device.NUM_CHANNELS; chan++)
                {
                    if (buf[chan] != null)
                    {
                        memset(buf[chan], 0, (UInt32)samples);  //memset(buf[chan], 0, samples * sizeof_(*buf[chan]));
                    }
                }
            }

            /* The 8910 has three outputs, each output is the mix of one of the three */
            /* tone generators and of the (single) noise generator. The two are mixed */
            /* BEFORE going into the DAC. The formula to mix each channel is: */
            /* (ToneOn | ToneDisable) & (NoiseOn | NoiseDisable). */
            /* Note that this means that if both tone and noise are disabled, the output */
            /* is 1, not 0, and can be modulated changing the volume. */

            /* buffering loop */
            while (samples != 0)
            {
                for (chan = 0; chan < ay8910_device.NUM_CHANNELS; chan++)
                {
                    ay8910.m_count[chan]++;
                    if (ay8910.m_count[chan] >= ay8910.TONE_PERIOD(chan))
                    {
                        ay8910.m_output[chan] ^= 1;
                        ay8910.m_count[chan]   = 0;
                    }
                }

                ay8910.m_count_noise++;
                if (ay8910.m_count_noise >= ay8910.NOISE_PERIOD())
                {
                    /* toggle the prescaler output. Noise is no different to
                     * channels.
                     */
                    ay8910.m_count_noise     = 0;
                    ay8910.m_prescale_noise ^= 1;

                    if (ay8910.m_prescale_noise != 0)
                    {
                        /* The Random Number Generator of the 8910 is a 17-bit shift */
                        /* register. The input to the shift register is bit0 XOR bit3 */
                        /* (bit0 is the output). This was verified on AY-3-8910 and YM2149 chips. */

                        ay8910.m_rng  ^= (((ay8910.m_rng & 1) ^ ((ay8910.m_rng >> 3) & 1)) << 17);
                        ay8910.m_rng >>= 1;
                    }
                }

                for (chan = 0; chan < ay8910_device.NUM_CHANNELS; chan++)
                {
                    ay8910.m_vol_enabled[chan] = (byte)((ay8910.m_output[chan] | ay8910.TONE_ENABLEQ(chan)) & (ay8910.NOISE_OUTPUT() | ay8910.NOISE_ENABLEQ(chan)));
                }

                /* update envelope */
                if (ay8910.m_holding == 0)
                {
                    ay8910.m_count_env++;
                    if (ay8910.m_count_env >= ay8910.ENVELOPE_PERIOD() * ay8910.m_step)
                    {
                        ay8910.m_count_env = 0;
                        ay8910.m_env_step--;

                        /* check envelope current position */
                        if (ay8910.m_env_step < 0)
                        {
                            if (ay8910.m_hold != 0)
                            {
                                if (ay8910.m_alternate != 0)
                                {
                                    ay8910.m_attack ^= ay8910.m_env_step_mask;
                                }
                                ay8910.m_holding  = 1;
                                ay8910.m_env_step = 0;
                            }
                            else
                            {
                                /* if CountEnv has looped an odd number of times (usually 1), */
                                /* invert the output. */
                                if (ay8910.m_alternate != 0 && (ay8910.m_env_step & (ay8910.m_env_step_mask + 1)) != 0)
                                {
                                    ay8910.m_attack ^= ay8910.m_env_step_mask;
                                }

                                ay8910.m_env_step &= (sbyte)ay8910.m_env_step_mask;
                            }
                        }
                    }
                }
                ay8910.m_env_volume = (UInt32)(ay8910.m_env_step ^ ay8910.m_attack);

                if (ay8910.m_streams == 3)
                {
                    for (chan = 0; chan < ay8910_device.NUM_CHANNELS; chan++)
                    {
                        if (ay8910.TONE_ENVELOPE(chan) != 0)
                        {
                            if (ay8910.type() == ay8914_device.AY8914)                                                                                                  // AY8914 Has a two bit tone_envelope field
                            {
                                buf[chan][0] = ay8910.m_env_table[chan, ay8910.m_vol_enabled[chan] != 0 ? ay8910.m_env_volume >> (3 - ay8910.TONE_ENVELOPE(chan)) : 0]; // *(buf[chan]++)
                                buf[chan]++;
                            }
                            else
                            {
                                buf[chan][0] = ay8910.m_env_table[chan, ay8910.m_vol_enabled[chan] != 0 ? ay8910.m_env_volume : 0];  // *(buf[chan]++)
                                buf[chan]++;
                            }
                        }
                        else
                        {
                            buf[chan][0] = ay8910.m_vol_table[chan, ay8910.m_vol_enabled[chan] != 0 ? ay8910.TONE_VOLUME(chan) : 0];  // *(buf[chan]++)
                            buf[chan]++;
                        }
                    }
                }
                else
                {
                    buf[0][0] = ay8910.mix_3D();  // *(buf[0]++)
                    buf[0]++;
                }

                samples--;
            }
        }
Exemple #23
0
        //-------------------------------------------------
        //  generate_resampled_data - generate the
        //  resample buffer for a given input
        //-------------------------------------------------
        ListPointer <stream_sample_t> generate_resampled_data(stream_input input, UInt32 numsamples)
        {
            // if we don't have an output to pull data from, generate silence
            ListPointer <stream_sample_t> dest = new ListPointer <stream_sample_t>(input.m_resample);  // stream_sample_t *dest = input.m_resample;

            if (input.m_source == null || input.m_source.m_stream.m_attoseconds_per_sample == 0)
            {
                memset(dest, 0, numsamples);  //memset(dest, 0, numsamples * sizeof(*dest));
                return(new ListPointer <stream_sample_t>(input.m_resample));
            }

            // grab data from the output
            stream_output output       = input.m_source;  // stream_output &output = *input.m_source;
            sound_stream  input_stream = output.m_stream; // sound_stream &input_stream = *output.m_stream;
            s64           gain         = (input.m_gain * input.m_user_gain * output.m_gain) >> 16;

            // determine the time at which the current sample begins, accounting for the
            // latency we calculated between the input and output streams
            attoseconds_t basetime = m_output_sampindex * m_attoseconds_per_sample - input.m_latency_attoseconds;

            // now convert that time into a sample in the input stream
            s32 basesample;

            if (basetime >= 0)
            {
                basesample = (int)(basetime / input_stream.m_attoseconds_per_sample);
            }
            else
            {
                basesample = (int)(-(-basetime / input_stream.m_attoseconds_per_sample) - 1);
            }

            // compute a source pointer to the first sample
            assert(basesample >= input_stream.m_output_base_sampindex);
            ListPointer <stream_sample_t> source = new ListPointer <stream_sample_t>(output.m_buffer, basesample - input_stream.m_output_base_sampindex);  // stream_sample_t *source = &output.m_buffer[basesample - input_stream.m_output_base_sampindex];

            // determine the current fraction of a sample, expressed as a fraction of FRAC_ONE
            // (Note: this formula is valid as long as input_stream.m_attoseconds_per_sample signficantly exceeds FRAC_ONE > attoseconds = 4.2E-12 s)
            u32 basefrac = (u32)((basetime - basesample * input_stream.m_attoseconds_per_sample) / ((input_stream.m_attoseconds_per_sample + FRAC_ONE - 1) >> (int)FRAC_BITS));

            assert(basefrac < FRAC_ONE);

            // compute the stepping fraction
            u32 step = (u32)(((u64)(input_stream.m_sample_rate) << (int)FRAC_BITS) / m_sample_rate);

            // if we have equal sample rates, we just need to copy
            if (step == FRAC_ONE)
            {
                while (numsamples-- != 0)
                {
                    // compute the sample
                    s64 sample = source[0];                // *source++;
                    source++;
                    dest[0] = (int)((sample * gain) >> 8); // *dest++ = (sample * gain) >> 8;
                    dest++;
                }
            }

            // input is undersampled: point sample except where our sample period covers a boundary
            else if (step < FRAC_ONE)
            {
                while (numsamples != 0)
                {
                    // fill in with point samples until we hit a boundary
                    int nextfrac;
                    while ((nextfrac = (int)(basefrac + step)) < FRAC_ONE && numsamples-- != 0)
                    {
                        dest[0] = (int)((source[0] * gain) >> 8);  // *dest++ = (source[0] * gain) >> 8;
                        dest++;
                        basefrac = (UInt32)nextfrac;
                    }

                    // if we're done, we're done
                    if ((s32)(numsamples--) < 0)
                    {
                        break;
                    }

                    // compute starting and ending fractional positions
                    int startfrac = (int)(basefrac >> (int)(FRAC_BITS - 12));
                    int endfrac   = nextfrac >> (int)(FRAC_BITS - 12);

                    // blend between the two samples accordingly
                    s64 sample = ((s64)source[0] * (0x1000 - startfrac) + (s64)source[1] * (endfrac - 0x1000)) / (endfrac - startfrac);
                    dest[0] = (int)((sample * gain) >> 8);  // *dest++ = (sample * gain) >> 8;
                    dest++;

                    // advance
                    basefrac = (UInt32)(nextfrac & FRAC_MASK);
                    source++;
                }
            }

            // input is oversampled: sum the energy
            else
            {
                // use 8 bits to allow some extra headroom
                int smallstep = (int)(step >> (int)(FRAC_BITS - 8));
                while (numsamples-- != 0)
                {
                    s64 remainder = smallstep;
                    int tpos      = 0;

                    // compute the sample
                    s64 scale  = (FRAC_ONE - basefrac) >> (int)(FRAC_BITS - 8);
                    s64 sample = (s64)source[tpos++] * scale;
                    remainder -= scale;
                    while (remainder > 0x100)
                    {
                        sample    += (Int64)source[tpos++] * (Int64)0x100;
                        remainder -= 0x100;
                    }

                    sample += (Int64)source[tpos] * remainder;
                    sample /= smallstep;

                    dest[0] = (int)((sample * gain) >> 8);  // *dest++ = (sample * gain) >> 8;
                    dest++;

                    // advance
                    basefrac += step;
                    source   += basefrac >> (int)FRAC_BITS;
                    basefrac &= FRAC_MASK;
                }
            }

            return(new ListPointer <stream_sample_t>(input.m_resample));
        }
Exemple #24
0
        // getters
        //const simple_list<audit_record> &records() const { return m_record_list; }


        // audit operations

        //-------------------------------------------------
        //  audit_media - audit the media described by the
        //  currently-enumerated driver
        //-------------------------------------------------
        public summary audit_media(string validation = AUDIT_VALIDATE_FULL)
        {
            // start fresh
            m_record_list.clear();

            // store validation for later
            m_validation = validation;

// temporary hack until romload is update: get the driver path and support it for
// all searches
            string driverpath = m_enumerator.config().root_device().searchpath();

            int found           = 0;
            int required        = 0;
            int shared_found    = 0;
            int shared_required = 0;

            // iterate over devices and regions
            foreach (device_t device in new device_iterator(m_enumerator.config().root_device()))
            {
                // determine the search path for this source and iterate through the regions
                m_searchpath = device.searchpath();

                // now iterate over regions and ROMs within
                for (ListPointer <rom_entry> region = romload_global.rom_first_region(device); region != null; region = romload_global.rom_next_region(region))
                {
// temporary hack: add the driver path & region name
                    string combinedpath = device.searchpath() + ";" + driverpath;
                    if (!string.IsNullOrEmpty(device.shortname()))
                    {
                        combinedpath += ";" + device.shortname();
                    }
                    m_searchpath = combinedpath;

                    for (ListPointer <rom_entry> rom = romload_global.rom_first_file(region); rom != null; rom = romload_global.rom_next_file(rom))
                    {
                        string name = romload_global.ROM_GETNAME(rom[0]);
                        util.hash_collection hashes        = new util.hash_collection(romload_global.ROM_GETHASHDATA(rom[0]));
                        device_t             shared_device = find_shared_device(device, name, hashes, romload_global.ROM_GETLENGTH(rom[0]));

                        // count the number of files with hashes
                        if (!hashes.flag(util.hash_collection.FLAG_NO_DUMP) && !romload_global.ROM_ISOPTIONAL(rom[0]))
                        {
                            required++;
                            if (shared_device != null)
                            {
                                shared_required++;
                            }
                        }

                        // audit a file
                        audit_record record = null;
                        if (romload_global.ROMREGION_ISROMDATA(region[0]))
                        {
                            record = audit_one_rom(rom);
                        }

                        // audit a disk
                        else if (romload_global.ROMREGION_ISDISKDATA(region[0]))
                        {
                            record = audit_one_disk(rom);
                        }

                        if (record != null)
                        {
                            // count the number of files that are found.
                            if (record.status() == audit_record.audit_status.STATUS_GOOD || (record.status() == audit_record.audit_status.STATUS_FOUND_INVALID && find_shared_device(device, name, record.actual_hashes(), record.actual_length()) == null))
                            {
                                found++;
                                if (shared_device != null)
                                {
                                    shared_found++;
                                }
                            }

                            record.set_shared_device(shared_device);
                        }
                    }
                }
            }

            // if we only find files that are in the parent & either the set has no unique files or the parent is not found, then assume we don't have the set at all
            if (found == shared_found && required > 0 && (required != shared_required || shared_found == 0))
            {
                m_record_list.clear();
                return(summary.NOTFOUND);
            }

            // return a summary
            string unused = "";

            return(summarize(m_enumerator.driver().name, ref unused));
        }
Exemple #25
0
        //-------------------------------------------------
        //  update - mix everything down to its final form
        //  and send it to the OSD layer
        //-------------------------------------------------
        void update(object o = null, s32 param = 0)  // (void *ptr = nullptr, s32 param = 0);
        {
            sound_global.VPRINTF("sound_update\n");

            profiler_global.g_profiler.start(profile_type.PROFILER_SOUND);


            // force all the speaker streams to generate the proper number of samples
            int samples_this_update = 0;

            foreach (speaker_device speaker in new speaker_device_iterator(machine().root_device()))
            {
                speaker.mix(m_leftmix, m_rightmix, ref samples_this_update, (m_muted & MUTE_REASON_SYSTEM) != 0);
            }

            // now downmix the final result
            u32 finalmix_step          = (UInt32)machine().video().speed_factor();
            u32 finalmix_offset        = 0;
            ListPointer <s16> finalmix = new ListPointer <s16>(m_finalmix);  //s16 *finalmix = &m_finalmix[0];
            int sample;

            for (sample = (int)m_finalmix_leftover; sample < samples_this_update * 1000; sample += (int)finalmix_step)
            {
                int sampindex = sample / 1000;

                // clamp the left side
                int samp = m_leftmix[sampindex];
                if (samp < -32768)
                {
                    samp = -32768;
                }
                else if (samp > 32767)
                {
                    samp = 32767;
                }

                finalmix[finalmix_offset++] = (Int16)samp;

                // clamp the right side
                samp = m_rightmix[sampindex];
                if (samp < -32768)
                {
                    samp = -32768;
                }
                else if (samp > 32767)
                {
                    samp = 32767;
                }

                finalmix[finalmix_offset++] = (Int16)samp;
            }

            m_finalmix_leftover = (UInt32)(sample - samples_this_update * 1000);

            // play the result
            if (finalmix_offset > 0)
            {
                if (m_nosound_mode == 0)
                {
                    machine().osd().update_audio_stream(finalmix, (int)(finalmix_offset / 2));
                }

                machine().osd().add_audio_to_recording(finalmix, (int)finalmix_offset / 2);
                machine().video().add_sound_to_recording(finalmix, (int)(finalmix_offset / 2));

                if (m_wavfile != null)
                {
                    wavwrite_global.wav_add_data_16(m_wavfile, finalmix, (int)finalmix_offset);
                }
            }

            // see if we ticked over to the next second
            attotime curtime     = machine().time();
            bool     second_tick = false;

            if (curtime.seconds() != m_last_update.seconds())
            {
                assert(curtime.seconds() == m_last_update.seconds() + 1);
                second_tick = true;
            }

            // iterate over all the streams and update them
            foreach (var stream in m_stream_list)
            {
                stream.update_with_accounting(second_tick);
            }

            // remember the update time
            m_last_update = curtime;

            // update sample rates if they have changed
            foreach (var stream in m_stream_list)
            {
                stream.apply_sample_rate_changes();
            }


            profiler_global.g_profiler.stop();
        }
Exemple #26
0
        //~sound_module() { }


        public abstract void update_audio_stream(bool is_throttled, ListPointer <Int16> buffer, int samples_this_frame);  //const int16_t *buffer, int samples_this_frame)
        static void Main(string[] args)
        {
            int[] arr = new int[9] {
                1, 0, 2, 3, 4, 5, 6, 7, 8
            };

            Console.WriteLine("Welcome to the 8-Puzzle AI solver!");
            Console.Write("Enter initial state of puzzle: ");
            string inititial_State = Console.ReadLine();

            if (inititial_State.Length != 9)
            {
                Console.WriteLine("Error, missing values");
            }
            else
            {
                for (int i = 0; i < 9; i++)
                {
                    arr[i] = (int)Char.GetNumericValue(inititial_State[i]);
                }



                node Leaf = new node(arr);
                Leaf.printPuzzle();
                Leaf.goalTest();

                List <node> listOfObjects = new List <node>();
                listOfObjects.Add(Leaf);
                int  flag = 0;  //to catch the goal
                node ListPointer;
                int  count       = 0;
                node goalPointer = new node(arr);
                while (flag == 0)
                {
                    ListPointer = listOfObjects[count]; //leaf at begining
                    ListPointer.Expand();
                    for (int i = 0; i < 4; i++)
                    {
                        if (ListPointer.children[i] != null)
                        {
                            if (ListPointer.children[i].goalTest())
                            {
                                flag        = 1;
                                goalPointer = ListPointer.children[i];
                                break;
                            }
                            else
                            {
                                if (duplication(listOfObjects, ListPointer.children[i].state) == false)
                                {
                                    listOfObjects.Add(ListPointer.children[i]);
                                }
                            }
                        }
                    }
                    count++;
                }
                int         flag2    = 0;
                List <node> goalList = new List <node>();
                while (flag2 == 0)
                {
                    goalList.Add(goalPointer);
                    goalPointer = goalPointer.parent;
                    if (goalPointer.parent == null)
                    {
                        flag2 = 1;
                        //goalPointer.printPuzzle();
                        break;
                    }
                }
                Console.WriteLine("Path to Solution:");
                for (int i = goalList.Count - 1; i >= 0; i--)
                {
                    goalList[i].printPuzzle();
                }

                Console.WriteLine("Number of generated states = " + node.generatedStates);
                Console.WriteLine("Number of expanded states = " + node.expandedStates);
                string end;
                Console.WriteLine("Press enter to close...");
                Console.ReadLine();
            }
        }
Exemple #28
0
        //speaker_device &front_left() { set_position(-0.2, 0.0, 1.0); return *this; }
        //speaker_device &front_right() { set_position(0.2, 0.0, 1.0); return *this; }
        //speaker_device &rear_center() { set_position(0.0, 0.0, -0.5); return *this; }
        //speaker_device &rear_left() { set_position(-0.2, 0.0, -0.5); return *this; }
        //speaker_device &rear_right() { set_position(0.2, 0.0, -0.5); return *this; }
        //speaker_device &subwoofer() { set_position(0.0, 0.0, 0.0); return *this; }


        // internally for use by the sound system
        //-------------------------------------------------
        //  mix - mix in samples from the speaker's stream
        //-------------------------------------------------
        public void mix(ListBase <s32> leftmix, ListBase <s32> rightmix, ref int samples_this_update, bool suppress)  //s32 *leftmix, s32 *rightmix, int &samples_this_update, bool suppress)
        {
            // skip if no stream
            if (m_dimixer.mixer_stream() == null)
            {
                return;
            }

            // update the stream, getting the start/end pointers around the operation
            int numsamples;
            ListPointer <stream_sample_t> stream_buf = m_dimixer.mixer_stream().output_since_last_update(0, out numsamples);

            // set or assert that all streams have the same count
            if (samples_this_update == 0)
            {
                samples_this_update = numsamples;

                // reset the mixing streams
                //memset(leftmix, 0, samples_this_update * sizeof(*leftmix));
                //memset(rightmix, 0, samples_this_update * sizeof(*rightmix));
                for (int i = 0; i < samples_this_update; i++)
                {
                    leftmix[i]  = 0;
                    rightmix[i] = 0;
                }
            }

            assert(samples_this_update == numsamples);

#if MAME_DEBUG
            // debug version: keep track of the maximum sample
            for (int sample = 0; sample < samples_this_update; sample++)
            {
                if (stream_buf[sample] > m_max_sample)
                {
                    m_max_sample = stream_buf[sample];
                }
                else if (-stream_buf[sample] > m_max_sample)
                {
                    m_max_sample = -stream_buf[sample];
                }
                if (stream_buf[sample] > 32767 || stream_buf[sample] < -32768)
                {
                    m_clipped_samples++;
                }
                m_total_samples++;
            }
#endif

            // mix if sound is enabled
            if (!suppress)
            {
                // if the speaker is centered, send to both left and right
                if (m_x == 0)
                {
                    for (int sample = 0; sample < samples_this_update; sample++)
                    {
                        leftmix[sample]  += stream_buf[sample];
                        rightmix[sample] += stream_buf[sample];
                    }
                }
                // if the speaker is to the left, send only to the left
                else if (m_x < 0)
                {
                    for (int sample = 0; sample < samples_this_update; sample++)
                    {
                        leftmix[sample] += stream_buf[sample];
                    }
                }
                // if the speaker is to the right, send only to the right
                else
                {
                    for (int sample = 0; sample < samples_this_update; sample++)
                    {
                        rightmix[sample] += stream_buf[sample];
                    }
                }
            }
        }
Exemple #29
0
 public abstract error append_sound_samples(int channel, ListPointer <int16_t> samples, uint32_t numsamples, uint32_t sampleskip);  //std::int16_t const *samples
Exemple #30
0
        // device_sound_interface overrides
        //-------------------------------------------------
        //  sound_stream_update - update a sound stream
        //-------------------------------------------------
        public override void sound_stream_update(sound_stream stream, ListPointer <stream_sample_t> [] inputs, ListPointer <stream_sample_t> [] outputs, int samples)
        {
            samples_device samplesdev = (samples_device)device();

            // find the channel with this stream
            for (int channel = 0; channel < samplesdev.m_channels; channel++)
            {
                if (stream == samplesdev.m_channel[channel].stream)
                {
                    samples_device.channel_t      chan   = samplesdev.m_channel[channel];
                    ListPointer <stream_sample_t> buffer = new ListPointer <stream_sample_t>(outputs[0]);  //stream_sample_t * buffer = outputs[0];

                    // process if we still have a source and we're not paused
                    if (chan.source != null && !chan.paused)
                    {
                        // load some info locally
                        uint32_t           pos           = chan.pos;
                        uint32_t           frac          = chan.frac;
                        uint32_t           step          = chan.step;
                        ListBase <int16_t> sample        = chan.source; //const int16_t *sample = chan.source;
                        uint32_t           sample_length = (UInt32)chan.source_length;

                        while (samples-- != 0)
                        {
                            // do a linear interp on the sample
                            int sample1  = sample[(int)pos];
                            int sample2  = sample[(int)((pos + 1) % sample_length)];
                            int fracmult = (int)(frac >> (samples_device.FRAC_BITS - 14));
                            buffer[0] = ((0x4000 - fracmult) * sample1 + fracmult * sample2) >> 14;  //*buffer++ = ((0x4000 - fracmult) * sample1 + fracmult * sample2) >> 14;
                            buffer++;

                            // advance
                            frac += step;
                            pos  += frac >> samples_device.FRAC_BITS;
                            frac  = frac & ((1 << samples_device.FRAC_BITS) - 1);

                            // handle looping/ending
                            if (pos >= sample_length)
                            {
                                if (chan.loop)
                                {
                                    pos %= sample_length;
                                }
                                else
                                {
                                    chan.source     = null;
                                    chan.source_num = -1;
                                    if (samples > 0)
                                    {
                                        memset(buffer, 0, (UInt32)samples);  //memset(buffer, 0, samples * sizeof(*buffer));
                                    }
                                    break;
                                }
                            }
                        }

                        // push position back out
                        chan.pos  = pos;
                        chan.frac = frac;
                    }
                    else
                    {
                        memset(buffer, 0, (UInt32)samples);  //memset(buffer, 0, samples * sizeof(*buffer));
                    }

                    break;
                }
            }
        }