Example #1
0
        static int make_mixer_table(int voices)
        {
            int count = voices * 128;
            int i;
            int gain = 16;

            /* allocate memory */
            mixer_table = new _ShortPtr(256 * voices * sizeof(short));

            /* find the middle of the table */
            mixer_lookup = new _ShortPtr(mixer_table, (128 * voices) * 2);

            /* fill in the table - 16 bit case */
            for (i = 0; i < count; i++)
            {
                int val = i * gain * 16 / voices;
                if (val > 32767) val = 32767;
                mixer_lookup.write16(i, (ushort)val);
                mixer_lookup.write16(-i, (ushort)-val);
            }

            return 0;
        }
Example #2
0
        public static void overlay_draw(osd_bitmap dest, artwork overlay)
        {
            int i, j;
            int height, width;
            osd_bitmap o = null;
            int black;

            o = overlay._artwork;
            height = overlay._artwork.height;
            width = overlay._artwork.width;
            black = Machine.pens[0];

            if (dest.depth == 8)
            {
                _BytePtr dst, ovr;

                for (j = 0; j < height; j++)
                {
                    dst = new _BytePtr(dest.line[j]);
                    ovr = new _BytePtr(o.line[j]);
                    for (i = 0; i < width; i++)
                    {
                        if (dst[0] != black)
                            dst[0] = ovr[0];
                        dst.offset++;
                        ovr.offset++;
                    }
                }
            }
            else
            {
                _ShortPtr dst, ovr;

                for (j = 0; j < height; j++)
                {
                    dst = new _ShortPtr(dest.line[j]);
                    ovr = new _ShortPtr(o.line[j]);
                    for (i = 0; i < width; i++)
                    {
                        if (dst.read16(0) != black)
                            dst.write16(0, ovr.read16(0));
                        dst.offset += 2;
                        ovr.offset += 2;
                    }
                }
            }
        }
Example #3
0
        public static void fillbitmap(osd_bitmap dest, int pen, rectangle clip)
        {
            FuncDict["fillbitmap"] = "fillbitmap";
            rectangle myclip = new rectangle();

            if ((Machine.orientation & ORIENTATION_SWAP_XY) != 0)
            {
                if (clip != null)
                {
                    myclip.min_x = clip.min_y;
                    myclip.max_x = clip.max_y;
                    myclip.min_y = clip.min_x;
                    myclip.max_y = clip.max_x;
                    clip = myclip;
                }
            }
            if ((Machine.orientation & ORIENTATION_FLIP_X) != 0)
            {
                if (clip != null)
                {
                    int temp = clip.min_x;
                    myclip.min_x = dest.width - 1 - clip.max_x;
                    myclip.max_x = dest.width - 1 - temp;
                    myclip.min_y = clip.min_y;
                    myclip.max_y = clip.max_y;
                    clip = myclip;
                }
            }
            if ((Machine.orientation & ORIENTATION_FLIP_Y) != 0)
            {
                if (clip != null)
                {
                    myclip.min_x = clip.min_x;
                    myclip.max_x = clip.max_x;
                    int temp = clip.min_y;
                    myclip.min_y = dest.height - 1 - clip.max_y;
                    myclip.max_y = dest.height - 1 - temp;
                    clip = myclip;
                }
            }

            int sx = 0;
            int ex = dest.width - 1;
            int sy = 0;
            int ey = dest.height - 1;

            if (clip != null && sx < clip.min_x) sx = clip.min_x;
            if (clip != null && ex > clip.max_x) ex = clip.max_x;
            if (sx > ex) return;
            if (clip != null && sy < clip.min_y) sy = clip.min_y;
            if (clip != null && ey > clip.max_y) ey = clip.max_y;
            if (sy > ey) return;

            osd_mark_dirty(sx, sy, ex, ey, 0);	/* ASG 971011 */

            /* ASG 980211 */
            if (dest.depth == 16)
            {
                if ((pen >> 8) == (pen & 0xff))
                {
                    for (int y = sy; y <= ey; y++)
                    {
                        for (int k = 0; k < (ex - sx + 1) * 2; k++)
                            dest.line[y][sx * 2 + k] = (byte)(pen & 0xff);
                    }
                    //memset(&dest.line[y][sx*2],pen&0xff,(ex-sx+1)*2);
                }
                else
                {
                    _ShortPtr sp = new _ShortPtr(dest.line[sy]);
                    int x;

                    for (x = sx; x <= ex; x++)
                        sp.write16(x, (ushort)pen);
                    sp.offset += sx * 2;
                    for (int y = sy + 1; y <= ey; y++)
                    {
                        Buffer.BlockCopy(sp.buffer, sp.offset, dest.line[y].buffer, sx * 2, (ex - sx + 1) * 2);
                    }
                    //memcpy(&dest.line[y][sx*2],sp,(ex-sx+1)*2);
                }
            }
            else
            {
                for (int y = sy; y <= ey; y++)
                {
                    for (int k = 0; k < ex - sx + 1; k++) dest.line[y][sx + k] = (byte)pen;
                }
            }
        }
Example #4
0
        void apply_RC_filter(int channel, _ShortPtr buf, int len, int sample_rate)
        {
            if (c[channel] == 0) return;	/* filter disabled */

            float R1 = r1[channel];
            float R2 = r2[channel];
            float R3 = r3[channel];
            float C = (float)(c[channel] * 1E-12);	/* convert pF to F */

            /* Cut Frequency = 1/(2*Pi*Req*C) */

            float Req = (R1 * (R2 + R3)) / (R1 + R2 + R3);

            int K = (int)(0x10000 * Math.Exp(-1 / (Req * C) / sample_rate));

            buf.write16(0, (ushort)(buf.read16(0) + (memory[channel] - buf.read16(0)) * K / 0x10000));

            for (int i = 1; i < len; i++)
                buf.write16(i, (ushort)(buf.read16(i) + (buf.read16(i - 1) - buf.read16(i)) * K / 0x10000));

            memory[channel] = buf.read16(len - 1);
        }
Example #5
0
        public static void tms5220_update(int ch, _ShortPtr buffer, int length)
        {
            short[] sample_data = new short[MAX_SAMPLE_CHUNK];
            ShortSubArray curr_data = new ShortSubArray(sample_data);
            short prev = last_sample, curr = curr_sample;
            uint final_pos;
            uint new_samples;

            /* finish off the current sample */
            if (source_pos > 0)
            {
                /* interpolate */
                while (length > 0 && source_pos < FRAC_ONE)
                {
                    buffer.write16(0, (ushort)((((int)prev * (FRAC_ONE - source_pos)) + ((int)curr * source_pos)) >> FRAC_BITS));
                    buffer.offset += 2;
                    source_pos += source_step;
                    length--;
                }

                /* if we're over, continue; otherwise, we're done */
                if (source_pos >= FRAC_ONE)
                    source_pos -= FRAC_ONE;
                else
                    return;
            }

            /* compute how many new samples we need */
            final_pos = (uint)(source_pos + length * source_step);
            new_samples = (final_pos + FRAC_ONE - 1) >> FRAC_BITS;
            if (new_samples > MAX_SAMPLE_CHUNK)
                new_samples = MAX_SAMPLE_CHUNK;

            /* generate them into our buffer */
            tms5220_process(sample_data, new_samples);
            prev = curr;
            curr = curr_data[0]; curr_data.offset++;

            /* then sample-rate convert with linear interpolation */
            while (length > 0)
            {
                /* interpolate */
                while (length > 0 && source_pos < FRAC_ONE)
                {
                    buffer.write16(0, (ushort)((((int)prev * (FRAC_ONE - source_pos)) + ((int)curr * source_pos)) >> FRAC_BITS));
                    source_pos += source_step;
                    length--;
                }

                /* if we're over, grab the next samples */
                if (source_pos >= FRAC_ONE)
                {
                    source_pos -= FRAC_ONE;
                    prev = curr;
                    curr = curr_data[0]; curr_data.offset++;
                }
            }

            /* remember the last samples */
            last_sample = prev;
            curr_sample = curr;
        }
Example #6
0
        static void draw_tile(osd_bitmap pixmap, int col, int row, int tile_width, int tile_height, _BytePtr pendata, UShortSubArray paldata, byte flags)
        {
            int x, sx = tile_width * col;
            int sy, y1, y2, dy;
            int pi = 0;
            if (Machine.scrbitmap.depth == 16)
            {
                if ((flags & TILE_FLIPY) != 0)
                {
                    y1 = tile_height * row + tile_height - 1;
                    y2 = y1 - tile_height;
                    dy = -1;
                }
                else
                {
                    y1 = tile_height * row;
                    y2 = y1 + tile_height;
                    dy = 1;
                }

                if ((flags & TILE_FLIPX) != 0)
                {
                    tile_width--;
                    for (sy = y1; sy != y2; sy += dy)
                    {
                        _ShortPtr dest = new _ShortPtr(pixmap.line[sy], sx);
                        for (x = tile_width; x >= 0; x--)
                        {
                            dest.write16(x, paldata[pendata[pi++]]);
                        }
                    }
                }
                else
                {
                    for (sy = y1; sy != y2; sy += dy)
                    {
                        _ShortPtr dest = new _ShortPtr(pixmap.line[sy], sx);
                        for (x = 0; x < tile_width; x++)
                        {
                            dest.write16(x, paldata[pendata[pi++]]);
                        }
                    }
                }
            }
            else
            {
                if ((flags & TILE_FLIPY) != 0)
                {
                    y1 = tile_height * row + tile_height - 1;
                    y2 = y1 - tile_height;
                    dy = -1;
                }
                else
                {
                    y1 = tile_height * row;
                    y2 = y1 + tile_height;
                    dy = 1;
                }

                if ((flags & TILE_FLIPX) != 0)
                {
                    tile_width--;
                    for (sy = y1; sy != y2; sy += dy)
                    {
                        _BytePtr dest = new _BytePtr(pixmap.line[sy], sx);
                        for (x = tile_width; x >= 0; x--)
                        { dest[x] = (byte)paldata[pendata[pi++]]; }
                    }
                }
                else
                {
                    for (sy = y1; sy != y2; sy += dy)
                    {
                        _BytePtr dest = new _BytePtr(pixmap.line[sy], sx);
                        for (x = 0; x < tile_width; x++)
                        { dest[x] = (byte)paldata[pendata[pi++]]; }
                    }
                }
            }
        }
Example #7
0
        public static void YM2203UpdateOne(int num, _ShortPtr buffer, int length)
        {
            YM2203 F2203 = (FM2203[num]);
            FM_OPN OPN = (FM2203[num].OPN);
            int i;
            FM_CH ch;
            _ShortPtr buf = new _ShortPtr(buffer);

            cur_chip = F2203;
            State = F2203.OPN.ST;
            cch[0] = F2203.CH[0];
            cch[1] = F2203.CH[1];
            cch[2] = F2203.CH[2];
#if FM_LFO_SUPPORT
            /* LFO */
            lfo_amd = 0;
            lfo_pmd = 0;
#endif
            /* frequency counter channel A */
            CALC_FCOUNT(cch[0]);
            /* frequency counter channel B */
            CALC_FCOUNT(cch[1]);
            /* frequency counter channel C */
            if ((State.mode & 0xc0) != 0)
            {
                /* 3SLOT MODE */
                if (cch[2].SLOT[SLOT1].Incr == unchecked((uint)-1))
                {
                    /* 3 slot mode */
                    CALC_FCSLOT(cch[2].SLOT[SLOT1], (int)OPN.SL3.fc[1], OPN.SL3.kcode[1]);
                    CALC_FCSLOT(cch[2].SLOT[SLOT2], (int)OPN.SL3.fc[2], OPN.SL3.kcode[2]);
                    CALC_FCSLOT(cch[2].SLOT[SLOT3], (int)OPN.SL3.fc[0], OPN.SL3.kcode[0]);
                    CALC_FCSLOT(cch[2].SLOT[SLOT4], (int)cch[2].fc, cch[2].kcode);
                }
            }
            else CALC_FCOUNT(cch[2]);

            for (i = 0; i < length; i++)
            {
                /*            channel A         channel B         channel C      */
                out_ch[OUTD_CENTER] = 0;
                /* calcrate FM */
                //for( ch=cch[0] ; ch <= cch[2] ; ch++)
                for (int kk = 0; kk < 2; kk++)

                    FM_CALC_CH(cch[kk]);
                /* limit check */
                Limit(ref out_ch[OUTD_CENTER], FM_MAXOUT, FM_MINOUT);
                /* store to sound buffer */
                buf.write16(i, (ushort)(out_ch[OUTD_CENTER] >> FM_OUTSB));
                /* timer controll */
                INTERNAL_TIMER_A(State, cch[2]);
            }
            INTERNAL_TIMER_B(State, length);
        }
Example #8
0
        public static void adpcm_update(int num, _ShortPtr buffer, int length)
        {
            ADPCMVoice voice = _adpcm[num];
            _ShortPtr sample_data = new _ShortPtr(MAX_SAMPLE_CHUNK * 2), curr_data = new _ShortPtr(sample_data);
            short prev = voice.last_sample, curr = voice.curr_sample;
            uint final_pos;
            uint new_samples;

            /* finish off the current sample */
            if (voice.source_pos > 0)
            {
                /* interpolate */
                while (length > 0 && voice.source_pos < FRAC_ONE)
                {
                    buffer.write16(0, (ushort)((((int)prev * (FRAC_ONE - voice.source_pos)) + ((int)curr * voice.source_pos)) >> FRAC_BITS));
                    buffer.offset += 2;
                    voice.source_pos += voice.source_step;
                    length--;
                }

                /* if we're over, continue; otherwise, we're done */
                if (voice.source_pos >= FRAC_ONE)
                    voice.source_pos -= FRAC_ONE;
                else
                    return;
            }

            /* compute how many new samples we need */
            final_pos = (uint)(voice.source_pos + length * voice.source_step);
            new_samples = (final_pos + FRAC_ONE - 1) >> FRAC_BITS;
            if (new_samples > MAX_SAMPLE_CHUNK)
                new_samples = MAX_SAMPLE_CHUNK;

            /* generate them into our buffer */
            generate_adpcm(voice, sample_data, (int)new_samples);
            prev = curr;
            curr = (short)curr_data.read16(0); curr_data.offset += 2;

            /* then sample-rate convert with linear interpolation */
            while (length > 0)
            {
                /* interpolate */
                while (length > 0 && voice.source_pos < FRAC_ONE)
                {
                    buffer.write16(0, (ushort)((((int)prev * (FRAC_ONE - voice.source_pos)) + ((int)curr * voice.source_pos)) >> FRAC_BITS));
                    buffer.offset += 2;
                    voice.source_pos += voice.source_step;
                    length--;
                }

                /* if we're over, grab the next samples */
                if (voice.source_pos >= FRAC_ONE)
                {
                    voice.source_pos -= FRAC_ONE;
                    prev = curr;
                    curr = (short)curr_data.read16(0); curr_data.offset += 2;
                }
            }

            /* remember the last samples */
            voice.last_sample = prev;
            voice.curr_sample = curr;
        }
Example #9
0
        static void generate_adpcm(ADPCMVoice voice, _ShortPtr buffer, int samples)
        {
            /* if this voice is active */
            if (voice.playing != 0)
            {
                _BytePtr _base = voice._base;
                int sample = (int)voice.sample;
                int signal = (int)voice.signal;
                int count = (int)voice.count;
                int step = (int)voice.step;
                int val;

                /* loop while we still have samples to generate */
                while (samples != 0)
                {
                    /* compute the new amplitude and update the current step */
                    val = _base[sample / 2] >> (((sample & 1) << 2) ^ 4);
                    signal += diff_lookup[step * 16 + (val & 15)];

                    /* clamp to the maximum */
                    if (signal > 2047)
                        signal = 2047;
                    else if (signal < -2048)
                        signal = -2048;

                    /* adjust the step size and clamp */
                    step += index_shift[val & 7];
                    if (step > 48)
                        step = 48;
                    else if (step < 0)
                        step = 0;

                    /* output to the buffer, scaling by the volume */
                    buffer.write16(0, (ushort)(signal * voice.volume / 16));
                    buffer.offset += 2;
                    samples--;

                    /* next! */
                    if (++sample > count)
                    {
                        voice.playing = 0;
                        break;
                    }
                }

                /* update the parameters */
                voice.sample = (uint)sample;
                voice.signal = (uint)signal;
                voice.step = (uint)step;
            }

            /* fill the rest with silence */
            while (samples-- != 0)
            {
                buffer.write16(0, 0);
                buffer.offset += 2;
            }
        }
Example #10
0
        static void pokey_update(int chip, _ShortPtr buffer, int length)
        {
            uint sum = 0;
            if (_pokey[chip].output[CHAN1] != 0)
                sum += _pokey[chip].volume[CHAN1];
            if (_pokey[chip].output[CHAN2] != 0)
                sum += _pokey[chip].volume[CHAN2];
            if (_pokey[chip].output[CHAN3] != 0)
                sum += _pokey[chip].volume[CHAN3];
            if (_pokey[chip].output[CHAN4] != 0)
                sum += _pokey[chip].volume[CHAN4];
            while (length > 0)
            {
                uint _event = _pokey[chip].samplepos_whole;
                uint channel = unchecked((uint)-1);
                if (_pokey[chip].counter[CHAN1] < _event)
                {
                    _event = (uint)_pokey[chip].counter[CHAN1];
                    channel = CHAN1;
                }
                if (_pokey[chip].counter[CHAN2] < _event)
                {
                    _event = (uint)_pokey[chip].counter[CHAN2];
                    channel = CHAN2;
                }
                if (_pokey[chip].counter[CHAN3] < _event)
                {
                    _event = (uint)_pokey[chip].counter[CHAN3];
                    channel = CHAN3;
                }
                if (_pokey[chip].counter[CHAN4] < _event)
                {
                    _event = (uint)_pokey[chip].counter[CHAN4];
                    channel = CHAN4;
                }
                if (channel == unchecked((uint)-1))
                {
                    _pokey[chip].counter[CHAN1] -= (int)_event;
                    _pokey[chip].counter[CHAN2] -= (int)_event;
                    _pokey[chip].counter[CHAN3] -= (int)_event;
                    _pokey[chip].counter[CHAN4] -= (int)_event;
                    _pokey[chip].samplepos_whole -= _event;
                    _pokey[chip].polyadjust += _event;

                    /* adjust the sample position */
                    _pokey[chip].samplepos_fract += _pokey[chip].samplerate_24_8;
                    if ((_pokey[chip].samplepos_fract & 0xffffff00) != 0)
                    {
                        _pokey[chip].samplepos_whole += _pokey[chip].samplepos_fract >> 8;
                        _pokey[chip].samplepos_fract &= 0x000000ff;
                    }
                    /* store sum of output signals into the buffer */
                    buffer.write16(0, (ushort)((sum > 65535) ? 0x7fff : sum - 0x8000));
                    buffer.offset += 2;
                    length--;
                }
                else
                {
                    int toggle = 0;
                    _pokey[chip].counter[CHAN1] -= (int)_event;
                    _pokey[chip].counter[CHAN2] -= (int)_event;
                    _pokey[chip].counter[CHAN3] -= (int)_event;
                    _pokey[chip].counter[CHAN4] -= (int)_event;
                    _pokey[chip].samplepos_whole -= _event;
                    _pokey[chip].polyadjust += _event;
                    /* reset the channel counter */
                    if (_pokey[chip].audible[channel])
                        _pokey[chip].counter[channel] = _pokey[chip].divisor[channel];
                    else
                        _pokey[chip].counter[channel] = 0x7fffffff;
                    _pokey[chip].p4 = (_pokey[chip].p4 + _pokey[chip].polyadjust) % 0x0000f;
                    _pokey[chip].p5 = (_pokey[chip].p5 + _pokey[chip].polyadjust) % 0x0001f;
                    _pokey[chip].p9 = (_pokey[chip].p9 + _pokey[chip].polyadjust) % 0x001ff;
                    _pokey[chip].p17 = (_pokey[chip].p17 + _pokey[chip].polyadjust) % 0x1ffff;
                    _pokey[chip].polyadjust = 0;
                    if ((_pokey[chip].AUDC[channel] & NOTPOLY5) != 0 || poly5[_pokey[chip].p5] != 0)
                    {
                        if ((_pokey[chip].AUDC[channel] & PURE) != 0)
                            toggle = 1;
                        else
                            if ((_pokey[chip].AUDC[channel] & POLY4) != 0)
                                toggle = _pokey[chip].output[channel] == (poly4[_pokey[chip].p4] == 0 ? 1 : 0) ? 1 : 0;
                            else
                                if ((_pokey[chip].AUDCTL & POLY9) != 0)
                                    toggle = _pokey[chip].output[channel] == (poly9[_pokey[chip].p9] == 0 ? 1 : 0) ? 1 : 0;
                                else
                                    toggle = _pokey[chip].output[channel] == (poly17[_pokey[chip].p17] == 0 ? 1 : 0) ? 1 : 0;
                    }
                    if (toggle != 0)
                    {
                        if (_pokey[chip].audible[channel])
                        {
                            if (_pokey[chip].output[channel] != 0)
                                sum -= _pokey[chip].volume[channel];
                            else
                                sum += _pokey[chip].volume[channel];
                        }
                        _pokey[chip].output[channel] ^= 1;
                    }
                    /* is this a filtering channel (3/4) and is the filter active? */
                    if ((_pokey[chip].AUDCTL & ((CH1_FILTER | CH2_FILTER) & (0x10 >> (int)channel))) != 0)
                    {
                        if (_pokey[chip].output[channel] != 0)
                        {
                            _pokey[chip].output[channel - 2] = 0;
                            if (_pokey[chip].audible[channel])
                                sum -= _pokey[chip].volume[channel - 2];
                        }
                    }
                }
            }
            Mame.Timer.timer_reset(_pokey[chip].rtimer, Mame.Timer.TIME_NEVER);
        }
Example #11
0
        static void SN76496Update(int chip, _ShortPtr buffer, int length)
        {
            _SN76496 R = sn[chip];

            /* If the volume is 0, increase the counter */
            for (int i = 0; i < 4; i++)
            {
                if (R.Volume[i] == 0)
                {
                    /* note that I do count += length, NOT count = length + 1. You might think */
                    /* it's the same since the volume is 0, but doing the latter could cause */
                    /* interferencies when the program is rapidly modulating the volume. */
                    if (R.Count[i] <= length * STEP) R.Count[i] += length * STEP;
                }
            }

            while (length > 0)
            {
                int[] vol = new int[4];
                uint _out;
                int left;


                /* vol[] keeps track of how long each square wave stays */
                /* in the 1 position during the sample period. */
                vol[0] = vol[1] = vol[2] = vol[3] = 0;

                for (int i = 0; i < 3; i++)
                {
                    if (R.Output[i] != 0) vol[i] += R.Count[i];
                    R.Count[i] -= STEP;
                    /* Period[i] is the half period of the square wave. Here, in each */
                    /* loop I add Period[i] twice, so that at the end of the loop the */
                    /* square wave is in the same status (0 or 1) it was at the start. */
                    /* vol[i] is also incremented by Period[i], since the wave has been 1 */
                    /* exactly half of the time, regardless of the initial position. */
                    /* If we exit the loop in the middle, Output[i] has to be inverted */
                    /* and vol[i] incremented only if the exit status of the square */
                    /* wave is 1. */
                    while (R.Count[i] <= 0)
                    {
                        R.Count[i] += R.Period[i];
                        if (R.Count[i] > 0)
                        {
                            R.Output[i] ^= 1;
                            if (R.Output[i] != 0) vol[i] += R.Period[i];
                            break;
                        }
                        R.Count[i] += R.Period[i];
                        vol[i] += R.Period[i];
                    }
                    if (R.Output[i] != 0) vol[i] -= R.Count[i];
                }

                left = STEP;
                do
                {
                    int nextevent;


                    if (R.Count[3] < left) nextevent = R.Count[3];
                    else nextevent = left;

                    if (R.Output[3] != 0) vol[3] += R.Count[3];
                    R.Count[3] -= nextevent;
                    if (R.Count[3] <= 0)
                    {
                        if ((R.RNG & 1) != 0) R.RNG ^= (uint)R.NoiseFB;
                        R.RNG >>= 1;
                        R.Output[3] = (int)R.RNG & 1;
                        R.Count[3] += R.Period[3];
                        if (R.Output[3] != 0) vol[3] += R.Period[3];
                    }
                    if (R.Output[3] != 0) vol[3] -= R.Count[3];

                    left -= nextevent;
                } while (left > 0);

                _out = (uint)(vol[0] * R.Volume[0] + vol[1] * R.Volume[1] +
                        vol[2] * R.Volume[2] + vol[3] * R.Volume[3]);

                if (_out > MAX_OUTPUT * STEP) _out = MAX_OUTPUT * STEP;

                buffer.write16(0, (ushort)(_out / STEP));
                buffer.offset += 2;

                length--;
            }
        }
Example #12
0
        static void MSM5205_update(int chip, _ShortPtr buffer, int length)
        {
            MSM5205Voice voice = msm5205[chip];

            /* if this voice is active */
            if (voice.signal != 0)
            {
                short val = (short)(voice.signal * 16);
                int i = 0;
                while (length != 0)
                {
                    buffer.write16(i++, (ushort)val);
                    length--;
                }
            }
            else
                Array.Clear(buffer.buffer, buffer.offset, length);
        }
Example #13
0
 static void DAC_update(int num, _ShortPtr buffer, int length)
 {
     int _out = output[num];
     int bi = 0;
     while (length-- != 0) buffer.write16(bi++, (ushort)_out);
 }
Example #14
0
        static void vlm5030_update_callback(int num, _ShortPtr buffer, int length)
        {
            int buf_count = 0;
            int interp_effect;

            /* running */
            if (phase == PH_RUN)
            {
                /* playing speech */
                while (length > 0)
                {
                    int current_val;

                    /* check new interpolator or  new frame */
                    if (sample_count == 0)
                    {
                        sample_count = IP_SIZE;
                        /* interpolator changes */
                        if (interp_count == 0)
                        {
                            /* change to new frame */
                            interp_count = parse_frame(); /* with change phase */
                            if (interp_count == 0)
                            {
                                sample_count = 160; /* end -> stop time */
                                phase = PH_STOP;
                                goto phase_stop; /* continue to stop phase */
                            }
                            /* Set old target as new start of frame */
                            current_energy = old_energy;
                            current_pitch = old_pitch;
                            //memcpy(current_k, old_k, sizeof(current_k));
                            Array.Copy(old_k, current_k, current_k.Length);
                            /* is this a zero energy frame? */
                            if (current_energy == 0)
                            {
                                /*printf("processing frame: zero energy\n");*/
                                target_energy = 0;
                                target_pitch = current_pitch;
                                //memcpy(target_k, current_k, sizeof(target_k));
                                Array.Copy(current_k, target_k, target_k.Length);
                            }
                            else
                            {
                                /*printf("processing frame: Normal\n");*/
                                /*printf("*** Energy = %d\n",current_energy);*/
                                /*printf("proc: %d %d\n",last_fbuf_head,fbuf_head);*/
                                target_energy = new_energy;
                                target_pitch = new_pitch;
                                //memcpy(target_k, new_k, sizeof(target_k));
                                Array.Copy(new_k, target_k, target_k.Length);
                            }
                        }
                        /* next interpolator */
                        /* Update values based on step values */
                        /*printf("\n");*/
                        interp_effect = (int)(interp_coeff[(FR_SIZE - 1) - (interp_count % FR_SIZE)]);

                        current_energy +=(ushort)( (target_energy - current_energy) / interp_effect);
                        if (old_pitch != 0)
                            current_pitch += (ushort)((target_pitch - current_pitch) / interp_effect);
                        /*printf("*** Energy = %d\n",current_energy);*/
                        current_k[0] += (target_k[0] - current_k[0]) / interp_effect;
                        current_k[1] += (target_k[1] - current_k[1]) / interp_effect;
                        current_k[2] += (target_k[2] - current_k[2]) / interp_effect;
                        current_k[3] += (target_k[3] - current_k[3]) / interp_effect;
                        current_k[4] += (target_k[4] - current_k[4]) / interp_effect;
                        current_k[5] += (target_k[5] - current_k[5]) / interp_effect;
                        current_k[6] += (target_k[6] - current_k[6]) / interp_effect;
                        current_k[7] += (target_k[7] - current_k[7]) / interp_effect;
                        current_k[8] += (target_k[8] - current_k[8]) / interp_effect;
                        current_k[9] += (target_k[9] - current_k[9]) / interp_effect;
                        interp_count--;
                    }
                    /* calcrate digital filter */
                    if (old_energy == 0)
                    {
                        /* generate silent samples here */
                        current_val = 0x00;
                    }
                    else if (old_pitch == 0)
                    {
                        /* generate unvoiced samples here */
                        int randvol = (Mame.rand() % 10);
                        current_val = (randvol * current_energy) / 10;
                    }
                    else
                    {
                        /* generate voiced samples here */
                        if (pitch_count < chirptable.Length)
                            current_val = (chirptable[pitch_count] * current_energy) / 256;
                        else
                            current_val = 0x00;
                    }

                    /* Lattice filter here */
                    u[10] = current_val;
                    u[9] = u[10] - ((current_k[9] * x[9]) / 32768);
                    u[8] = u[9] - ((current_k[8] * x[8]) / 32768);
                    u[7] = u[8] - ((current_k[7] * x[7]) / 32768);
                    u[6] = u[7] - ((current_k[6] * x[6]) / 32768);
                    u[5] = u[6] - ((current_k[5] * x[5]) / 32768);
                    u[4] = u[5] - ((current_k[4] * x[4]) / 32768);
                    u[3] = u[4] - ((current_k[3] * x[3]) / 32768);
                    u[2] = u[3] - ((current_k[2] * x[2]) / 32768);
                    u[1] = u[2] - ((current_k[1] * x[1]) / 32768);
                    u[0] = u[1] - ((current_k[0] * x[0]) / 32768);

                    x[9] = x[8] + ((current_k[8] * u[8]) / 32768);
                    x[8] = x[7] + ((current_k[7] * u[7]) / 32768);
                    x[7] = x[6] + ((current_k[6] * u[6]) / 32768);
                    x[6] = x[5] + ((current_k[5] * u[5]) / 32768);
                    x[5] = x[4] + ((current_k[4] * u[4]) / 32768);
                    x[4] = x[3] + ((current_k[3] * u[3]) / 32768);
                    x[3] = x[2] + ((current_k[2] * u[2]) / 32768);
                    x[2] = x[1] + ((current_k[1] * u[1]) / 32768);
                    x[1] = x[0] + ((current_k[0] * u[0]) / 32768);
                    x[0] = u[0];
                    /* clipping, buffering */
                    if (u[0] > 511)
                        buffer.write16(buf_count,  127 << 8);
                    else if (u[0] < -512)
                        buffer.write16(buf_count, unchecked( (ushort)(-128 << 8)));
                    else
                        buffer.write16(buf_count,  (ushort)(u[0] << 6));
                    buf_count++;

                    /* sample count */
                    sample_count--;
                    /* pitch */
                    pitch_count++;
                    if (pitch_count >= current_pitch)
                        pitch_count = 0;
                    /* size */
                    length--;
                }
                /*		return;*/
            }
        /* stop phase */
        phase_stop:
            switch (phase)
            {
                case PH_SETUP:
                    sample_count -= length;
                    if (sample_count <= 0)
                    {
                        Mame.printf("VLM5030 BSY=H\n");
                        /* pin_BSY = 1; */
                        phase = PH_WAIT;
                    }
                    break;
                case PH_STOP:
                    sample_count -= length;
                    if (sample_count <= 0)
                    {
                        Mame.printf("VLM5030 BSY=L\n");
                        pin_BSY = 0;
                        phase = PH_IDLE;
                    }
                    break;
            }
            /* silent buffering */
            while (length > 0)
            {
                buffer.write16(buf_count++, 0x00);
                length--;
            }
        }
Example #15
0
        public static void drawgfxzoom(osd_bitmap dest_bmp, GfxElement gfx, uint code, uint color, bool flipx, bool flipy, int sx, int sy, rectangle clip, int transparency, int transparent_color, int scalex, int scaley)
        {
            FuncDict["drawgfxzoom"] = "drawgfxzoom";
            rectangle myclip = new rectangle();


            /* only support TRANSPARENCY_PEN and TRANSPARENCY_COLOR */
            if (transparency != TRANSPARENCY_PEN && transparency != TRANSPARENCY_COLOR)
                return;

            if (transparency == TRANSPARENCY_COLOR)
                transparent_color = Machine.pens[transparent_color];


            /*
            scalex and scaley are 16.16 fixed point numbers
            1<<15 : shrink to 50%
            1<<16 : uniform scale
            1<<17 : double to 200%
            */


            if ((Machine.orientation & ORIENTATION_SWAP_XY) != 0)
            {
                int temp;

                temp = sx;
                sx = sy;
                sy = temp;

                var tempb = flipx;
                flipx = flipy;
                flipy = tempb;

                temp = scalex;
                scalex = scaley;
                scaley = temp;

                if (clip != null)
                {
                    /* clip and myclip might be the same, so we need a temporary storage */
                    temp = clip.min_x;
                    myclip.min_x = clip.min_y;
                    myclip.min_y = temp;
                    temp = clip.max_x;
                    myclip.max_x = clip.max_y;
                    myclip.max_y = temp;
                    clip = myclip;
                }
            }
            if ((Machine.orientation & ORIENTATION_FLIP_X) != 0)
            {
                sx = dest_bmp.width - ((gfx.width * scalex + 0x7fff) >> 16) - sx;
                if (clip != null)
                {
                    int temp;


                    /* clip and myclip might be the same, so we need a temporary storage */
                    temp = clip.min_x;
                    myclip.min_x = dest_bmp.width - 1 - clip.max_x;
                    myclip.max_x = dest_bmp.width - 1 - temp;
                    myclip.min_y = clip.min_y;
                    myclip.max_y = clip.max_y;
                    clip = myclip;
                }
#if !PREROTATE_GFX
                flipx = !flipx;
#endif
            }
            if ((Machine.orientation & ORIENTATION_FLIP_Y) != 0)
            {
                sy = dest_bmp.height - ((gfx.height * scaley + 0x7fff) >> 16) - sy;
                if (clip != null)
                {
                    int temp;


                    myclip.min_x = clip.min_x;
                    myclip.max_x = clip.max_x;
                    /* clip and myclip might be the same, so we need a temporary storage */
                    temp = clip.min_y;
                    myclip.min_y = dest_bmp.height - 1 - clip.max_y;
                    myclip.max_y = dest_bmp.height - 1 - temp;
                    clip = myclip;
                }
#if !PREROTATE_GFX
                flipy = !flipy;
#endif
            }

            /* KW 991012 -- Added code to force clip to bitmap boundary */
            if (clip != null)
            {
                myclip.min_x = clip.min_x;
                myclip.max_x = clip.max_x;
                myclip.min_y = clip.min_y;
                myclip.max_y = clip.max_y;

                if (myclip.min_x < 0) myclip.min_x = 0;
                if (myclip.max_x >= dest_bmp.width) myclip.max_x = dest_bmp.width - 1;
                if (myclip.min_y < 0) myclip.min_y = 0;
                if (myclip.max_y >= dest_bmp.height) myclip.max_y = dest_bmp.height - 1;

                clip = myclip;
            }


            /* ASG 980209 -- added 16-bit version */
            if (dest_bmp.depth != 16)
            {
                if (gfx != null && gfx.colortable != null)
                {
                    UShortSubArray pal = new UShortSubArray(gfx.colortable, (int)(gfx.color_granularity * (color % gfx.total_colors))); /* ASG 980209 */
                    int source_base = (int)((code % gfx.total_elements) * gfx.height);

                    int sprite_screen_height = (scaley * gfx.height + 0x8000) >> 16;
                    int sprite_screen_width = (scalex * gfx.width + 0x8000) >> 16;

                    /* compute sprite increment per screen pixel */
                    int dx = (gfx.width << 16) / sprite_screen_width;
                    int dy = (gfx.height << 16) / sprite_screen_height;

                    int ex = sx + sprite_screen_width;
                    int ey = sy + sprite_screen_height;

                    int x_index_base;
                    int y_index;

                    if (flipx)
                    {
                        x_index_base = (sprite_screen_width - 1) * dx;
                        dx = -dx;
                    }
                    else
                    {
                        x_index_base = 0;
                    }

                    if (flipy)
                    {
                        y_index = (sprite_screen_height - 1) * dy;
                        dy = -dy;
                    }
                    else
                    {
                        y_index = 0;
                    }

                    if (clip != null)
                    {
                        if (sx < clip.min_x)
                        { /* clip left */
                            int pixels = clip.min_x - sx;
                            sx += pixels;
                            x_index_base += pixels * dx;
                        }
                        if (sy < clip.min_y)
                        { /* clip top */
                            int pixels = clip.min_y - sy;
                            sy += pixels;
                            y_index += pixels * dy;
                        }
                        /* NS 980211 - fixed incorrect clipping */
                        if (ex > clip.max_x + 1)
                        { /* clip right */
                            int pixels = ex - clip.max_x - 1;
                            ex -= pixels;
                        }
                        if (ey > clip.max_y + 1)
                        { /* clip bottom */
                            int pixels = ey - clip.max_y - 1;
                            ey -= pixels;
                        }
                    }

                    if (ex > sx)
                    { /* skip if inner loop doesn't draw anything */
                        int y;

                        /* case 1: TRANSPARENCY_PEN */
                        if (transparency == TRANSPARENCY_PEN)
                        {
                            for (y = sy; y < ey; y++)
                            {
                                _BytePtr source = new _BytePtr(gfx.gfxdata, (source_base + (y_index >> 16)) * gfx.line_modulo);
                                _BytePtr dest = dest_bmp.line[y];

                                int x, x_index = x_index_base;
                                for (x = sx; x < ex; x++)
                                {
                                    int c = source[x_index >> 16];
                                    if (c != transparent_color) dest[x] = (byte)pal[c];
                                    x_index += dx;
                                }

                                y_index += dy;
                            }
                        }

                        /* case 2: TRANSPARENCY_COLOR */
                        else if (transparency == TRANSPARENCY_COLOR)
                        {
                            for (y = sy; y < ey; y++)
                            {
                                _BytePtr source = new _BytePtr(gfx.gfxdata, (source_base + (y_index >> 16)) * gfx.line_modulo);
                                _BytePtr dest = dest_bmp.line[y];

                                int x, x_index = x_index_base;
                                for (x = sx; x < ex; x++)
                                {
                                    int c = pal[source[x_index >> 16]];
                                    if (c != transparent_color) dest[x] = (byte)c;
                                    x_index += dx;
                                }

                                y_index += dy;
                            }
                        }
                    }

                }
            }

            /* ASG 980209 -- new 16-bit part */
            else
            {
                if (gfx != null && gfx.colortable != null)
                {
                    UShortSubArray pal = new UShortSubArray(gfx.colortable, (int)(gfx.color_granularity * (color % gfx.total_colors))); /* ASG 980209 */
                    int source_base = (int)((code % gfx.total_elements) * gfx.height);

                    int sprite_screen_height = (scaley * gfx.height + 0x8000) >> 16;
                    int sprite_screen_width = (scalex * gfx.width + 0x8000) >> 16;

                    /* compute sprite increment per screen pixel */
                    int dx = (gfx.width << 16) / sprite_screen_width;
                    int dy = (gfx.height << 16) / sprite_screen_height;

                    int ex = sx + sprite_screen_width;
                    int ey = sy + sprite_screen_height;

                    int x_index_base;
                    int y_index;

                    if (flipx)
                    {
                        x_index_base = (sprite_screen_width - 1) * dx;
                        dx = -dx;
                    }
                    else
                    {
                        x_index_base = 0;
                    }

                    if (flipy)
                    {
                        y_index = (sprite_screen_height - 1) * dy;
                        dy = -dy;
                    }
                    else
                    {
                        y_index = 0;
                    }

                    if (clip != null)
                    {
                        if (sx < clip.min_x)
                        { /* clip left */
                            int pixels = clip.min_x - sx;
                            sx += pixels;
                            x_index_base += pixels * dx;
                        }
                        if (sy < clip.min_y)
                        { /* clip top */
                            int pixels = clip.min_y - sy;
                            sy += pixels;
                            y_index += pixels * dy;
                        }
                        /* NS 980211 - fixed incorrect clipping */
                        if (ex > clip.max_x + 1)
                        { /* clip right */
                            int pixels = ex - clip.max_x - 1;
                            ex -= pixels;
                        }
                        if (ey > clip.max_y + 1)
                        { /* clip bottom */
                            int pixels = ey - clip.max_y - 1;
                            ey -= pixels;
                        }
                    }

                    if (ex > sx)
                    { /* skip if inner loop doesn't draw anything */
                        int y;

                        /* case 1: TRANSPARENCY_PEN */
                        if (transparency == TRANSPARENCY_PEN)
                        {
                            for (y = sy; y < ey; y++)
                            {
                                _BytePtr source = new _BytePtr(gfx.gfxdata, (source_base + (y_index >> 16)) * gfx.line_modulo);
                                _ShortPtr dest = new _ShortPtr(dest_bmp.line[y]);

                                int x, x_index = x_index_base;
                                for (x = sx; x < ex; x++)
                                {
                                    int c = source[x_index >> 16];
                                    if (c != transparent_color) dest[x] = (byte)pal[c];
                                    x_index += dx;
                                }

                                y_index += dy;
                            }
                        }

                        /* case 2: TRANSPARENCY_COLOR */
                        else if (transparency == TRANSPARENCY_COLOR)
                        {
                            for (y = sy; y < ey; y++)
                            {
                                _BytePtr source = new _BytePtr(gfx.gfxdata, (source_base + (y_index >> 16)) * gfx.line_modulo);
                                _ShortPtr dest = new _ShortPtr(dest_bmp.line[y]);

                                int x, x_index = x_index_base;
                                for (x = sx; x < ex; x++)
                                {
                                    int c = pal[source[x_index >> 16]];
                                    if (c != transparent_color) dest.write16(x, (ushort)c);
                                    x_index += dx;
                                }

                                y_index += dy;
                            }
                        }
                    }
                }
            }
        }
Example #16
0
        void namco_update_mono(int ch, _ShortPtr buffer, int length)
        {
            _ShortPtr mix;

            /* if no sound, we're done */
            if (!sound_enable)
            {
                Array.Clear(buffer.buffer, buffer.offset, length*2);
                return;
            }

            /* zap the contents of the mixer buffer */
            Array.Clear(mixer_buffer.buffer, mixer_buffer.offset, length * 2);

            /* loop over each voice and add its contribution */
            
            for (int voice=0;voice<last_channel;voice++)//; voice < last_channel; voice++)
            {
                int f = channel_list[voice].frequency;
                int v = channel_list[voice].volume[0];

                mix = new _ShortPtr(mixer_buffer);

                if (channel_list[voice].noise_sw != 0)
                {
                    /* only update if we have non-zero volume and frequency */
                    if (v != 0 && (f & 0xff) != 0)
                    {
                        float fbase = (float)sample_rate / (float)namco_clock;
                        int delta = (int)((float)((f & 0xff) << 4) * fbase);
                        int c = channel_list[voice].noise_counter;

                        /* add our contribution */
                        for (int i = 0; i < length; i++)
                        {
                            int noise_data;
                            int cnt;

                            if (channel_list[voice].noise_state != 0)
                                noise_data = 0x07;
                            else
                                noise_data = -0x07;
                            mix.write16(0, (ushort)((short)mix.read16(0) + noise_data * (v >> 1)));
                            mix.offset += 2;

                            c += delta;
                            cnt = (c >> 12);
                            c &= (1 << 12) - 1;
                            for (; cnt > 0; cnt--)
                            {
                                if (((channel_list[voice].noise_seed + 1) & 2) != 0) channel_list[voice].noise_state ^= 1;
                                if ((channel_list[voice].noise_seed & 1) != 0) channel_list[voice].noise_seed ^= 0x28000;
                                channel_list[voice].noise_seed >>= 1;
                            }
                        }

                        /* update the counter for this voice */
                        channel_list[voice].noise_counter = c;
                    }
                }
                else
                {
                    /* only update if we have non-zero volume and frequency */
                    if (v != 0 && f != 0)
                    {                        
                        int c = channel_list[voice].counter;

                        /* add our contribution */
                        for (int i = 0; i < length; i++)
                        {
                            c += f;
                            int offs = (c >> 15) & 0x1f;
                            //ushort currentmix = mix.read16(0);
                            if (samples_per_byte == 1)	/* use only low 4 bits */
                            {
                                mix.write16(0, (ushort)((short)mix.read16(0) + ((channel_list[voice].wave[offs] & 0x0f) - 8) * v));
                                mix.offset += 2;
                            }
                            else	/* use full byte, first the high 4 bits, then the low 4 bits */
                            {
                                if ((offs & 1) != 0)
                                {
                                    mix.write16(0, (ushort)((short)mix.read16(0) + ((channel_list[voice].wave[offs >> 1] & 0x0f) - 8) * v));
                                    mix.offset += 2;
                                }
                                else
                                {
                                    mix.write16(0, (ushort)((short)mix.read16(0) + (((channel_list[voice].wave[offs >> 1] >> 4) & 0x0f) - 8) * v));
                                    mix.offset += 2;
                                }
                            }
                        }

                        /* update the counter for this voice */
                        channel_list[voice].counter = c;
                    }
                }
            }

            /* mix it down */
            mix = new _ShortPtr(mixer_buffer);
            for (int i = 0; i < length; i++)
            {
                buffer.write16(0, (ushort)mixer_lookup[mixer_lookup_middle+(short)mix.read16(0)]);
                buffer.offset += 2;
                mix.offset += 2;
            }
        }
Example #17
0
        static void blockmove_opaque16(_BytePtr srcdata, int srcwidth, int srcheight, int srcmodulo, _ShortPtr dstdata, int dstmodulo, UShortSubArray paldata)
        {
            //blockmove_opaque8(srcdata, srcwidth, srcheight, srcmodulo, (_BytePtr)dstdata, dstmodulo, paldata);
            //return;
            int end;
            srcmodulo -= srcwidth;
            dstmodulo -= srcwidth;
            while (srcheight != 0)
            {
                end = dstdata.offset + srcwidth;
                while (dstdata.offset <= end - 8)
                {
                    dstdata.write16(0, paldata[srcdata[0]]);
                    dstdata.write16(1, paldata[srcdata[1]]);
                    dstdata.write16(2, paldata[srcdata[2]]);
                    dstdata.write16(3, paldata[srcdata[3]]);
                    dstdata.write16(4, paldata[srcdata[4]]);
                    dstdata.write16(5, paldata[srcdata[5]]);
                    dstdata.write16(6, paldata[srcdata[6]]);
                    dstdata.write16(7, paldata[srcdata[7]]);
                    dstdata.offset += 8 * 2;
                    srcdata.offset++;
                }
                while (dstdata.offset < end)
                {
                    dstdata.write16(0, paldata[srcdata[0]]);
                    srcdata.offset++;
                    dstdata.offset += 2;
                }
                srcdata.inc(srcmodulo);
                dstdata.inc(dstmodulo);
                srcheight--;
            }

        }
Example #18
0
        static void K005289_update(int ch, _ShortPtr buffer, int length)
        {
            _ShortPtr mix;

            /* zap the contents of the mixer buffer */
            Array.Clear(mixer_buffer.buffer, mixer_buffer.offset, length * sizeof(short));
            //memset(mixer_buffer, 0, length * sizeof(INT16));

            int v = channel_list[0].volume;
            int f = channel_list[0].frequency;
            if (v != 0 && f != 0)
            {
                _BytePtr w = channel_list[0].wave;
                int c = channel_list[0].counter;

                mix = new _ShortPtr(mixer_buffer);

                /* add our contribution */
                for (int i = 0; i < length; i++)
                {
                    int offs;

                    c += (int)((((float)mclock / (float)(f * 16)) * (float)(1 << FREQBASEBITS)) / (float)(rate / 32));
                    offs = (c >> 16) & 0x1f;
                    ushort _w = mix.read16(0);
                    mix.write16(0, (ushort)(_w + (short)(((w[offs] & 0x0f) - 8) * v)));
                }

                /* update the counter for this voice */
                channel_list[0].counter = c;
            }

            v = channel_list[1].volume;
            f = channel_list[1].frequency;
            if (v != 0 && f != 0)
            {
                _BytePtr w = channel_list[1].wave;
                int c = channel_list[1].counter;

                mix = mixer_buffer;

                /* add our contribution */
                for (int i = 0; i < length; i++)
                {
                    int offs;

                    c += (int)((((float)mclock / (float)(f * 16)) * (float)(1 << FREQBASEBITS)) / (float)(rate / 32));
                    offs = (c >> 16) & 0x1f;
                    ushort _w = mix.read16(0);
                    mix.write16(0, (ushort)(_w + (short)(((w[offs] & 0x0f) - 8) * v)));
                }

                /* update the counter for this voice */
                channel_list[1].counter = c;
            }

            /* mix it down */
            mix = new _ShortPtr(mixer_buffer);
            for (int i = 0; i < length; i++)
            {
                buffer.write16(0, (ushort)mixer_lookup.read16((short)mix.read16(0)));
                buffer.offset += 2;
                mix.offset += 2;
            }
        }