コード例 #1
0
ファイル: xavix.cpp プロジェクト: MASHinfo/mame
inline uint8_t xavix_state::get_next_byte()
{
	uint8_t dat = 0;
	for (int i = 0; i < 8; i++)
	{
		dat |= (get_next_bit() << i);
	}
	return dat;
}
コード例 #2
0
int read_length(byte_buffer *b, ushort bits) {
    int i;
    uchar bytes[4];
    memset(bytes, 0, 4);

    for (i = 0; i < bits; ++i) {
        if (get_next_bit(b)) {
            set_bit(bytes+(i/8), i%8);
        }
    }
    return *((int *)bytes);
}
コード例 #3
0
ファイル: buffer.c プロジェクト: cmyatt/Huffman-Compression
uchar get_next_byte(byte_buffer *b) {
    if (b->current_byte > b->capacity) return -1;
    
    int i;
    uchar byte = 0;

    for (i = 0; i < 8; ++i) {
        if (get_next_bit(b) == 1) {
            set_bit(&byte, i);
        }
    }
    return byte;
}
コード例 #4
0
ファイル: gpio.c プロジェクト: Basavaraja-MS/ec_local
void __keep gpio_interrupt(void)
{
	int bit;
	/* process only GPIO EXTINTs (EXTINT0..15) not other EXTINTs */
	uint32_t pending = STM32_EXTI_PR & 0xFFFF;
	uint8_t signal;

	STM32_EXTI_PR = pending;

	while (pending) {
		bit = get_next_bit(&pending);
		signal = exti_events[bit];
		if (signal < GPIO_IH_COUNT)
			gpio_irq_handlers[signal](signal);
	}
}
コード例 #5
0
ファイル: c2040fdc.c プロジェクト: macressler/mame
void c2040_fdc_t::live_run(const attotime &limit)
{
	if(cur_live.state == IDLE || cur_live.next_state != -1)
		return;

	for(;;) {
		switch(cur_live.state) {
		case RUNNING: {
			bool syncpoint = false;

			if (cur_live.tm > limit)
				return;

			int bit = get_next_bit(cur_live.tm, limit);
			if(bit < 0)
				return;

			int cell_counter = cur_live.cell_counter;

			if (bit) {
				cur_live.cycle_counter = cur_live.ds;
				cur_live.cell_counter = 0;
			} else {
				cur_live.cycle_counter++;
			}

			if (cur_live.cycle_counter == 16) {
				cur_live.cycle_counter = cur_live.ds;

				cur_live.cell_counter++;
				cur_live.cell_counter &= 0xf;
			}

			if (!BIT(cell_counter, 1) && BIT(cur_live.cell_counter, 1)) {
				// read bit
				cur_live.shift_reg <<= 1;
				cur_live.shift_reg |= !(BIT(cur_live.cell_counter, 3) || BIT(cur_live.cell_counter, 2));
				cur_live.shift_reg &= 0x3ff;

				if (LOG) logerror("%s read bit %u (%u) >> %03x, rw=%u mode=%u\n", cur_live.tm.as_string(), cur_live.bit_counter,
					!(BIT(cur_live.cell_counter, 3) || BIT(cur_live.cell_counter, 2)), cur_live.shift_reg, cur_live.rw_sel, cur_live.mode_sel);

				// write bit
				if (!cur_live.rw_sel) { // TODO WPS
					write_next_bit(BIT(cur_live.shift_reg_write, 9), limit);
				}

				syncpoint = true;
			}

			int sync = !((cur_live.shift_reg == 0x3ff) && cur_live.rw_sel);

			if (!sync) {
				cur_live.bit_counter = 0;
			} else if (!BIT(cell_counter, 1) && BIT(cur_live.cell_counter, 1) && cur_live.sync) {
				cur_live.bit_counter++;
				if (cur_live.bit_counter == 10) {
					cur_live.bit_counter = 0;
				}
			}

			// update GCR
			if (cur_live.rw_sel) {
				cur_live.i = (cur_live.rw_sel << 10) | cur_live.shift_reg;
			} else {
				cur_live.i = (cur_live.rw_sel << 10) | ((cur_live.pi & 0xf0) << 1) | (cur_live.mode_sel << 4) | (cur_live.pi & 0x0f);
			}

			cur_live.e = m_gcr_rom->base()[cur_live.i];

			int ready = !(BIT(cell_counter, 1) && !BIT(cur_live.cell_counter, 1) && (cur_live.bit_counter == 9));

			if (!ready) {
				// load write shift register
				cur_live.shift_reg_write = GCR_ENCODE(cur_live.e, cur_live.i);

				if (LOG) logerror("%s load write shift register %03x\n",cur_live.tm.as_string(),cur_live.shift_reg_write);
			} else if (BIT(cell_counter, 1) && !BIT(cur_live.cell_counter, 1)) {
				// clock write shift register
				cur_live.shift_reg_write <<= 1;
				cur_live.shift_reg_write &= 0x3ff;

				if (LOG) logerror("%s write shift << %03x\n",cur_live.tm.as_string(),cur_live.shift_reg_write);
			}

			int error = !(BIT(cur_live.e, 3) || ready);

			if (ready != cur_live.ready) {
				if (LOG) logerror("%s READY %u\n", cur_live.tm.as_string(),ready);
				cur_live.ready = ready;
				syncpoint = true;
			}

			if (sync != cur_live.sync) {
				if (LOG) logerror("%s SYNC %u\n", cur_live.tm.as_string(),sync);
				cur_live.sync = sync;
				syncpoint = true;
			}

			if (error != cur_live.error) {
				cur_live.error = error;
				syncpoint = true;
			}

			if (syncpoint) {
				commit(cur_live.tm);

				cur_live.tm += m_period;
				live_delay(RUNNING_SYNCPOINT);
				return;
			}

			cur_live.tm += m_period;
			break;
		}

		case RUNNING_SYNCPOINT: {
			m_write_ready(cur_live.ready);
			m_write_sync(cur_live.sync);
			m_write_error(cur_live.error);

			cur_live.state = RUNNING;
			checkpoint();
			break;
		}
		}
	}
}
コード例 #6
0
ファイル: 64h156.c プロジェクト: ef1105/mameplus
void c64h156_device::live_run(const attotime &limit)
{
	if(cur_live.state == IDLE || cur_live.next_state != -1)
		return;

	for(;;) {
		switch(cur_live.state) {
		case RUNNING: {
			bool syncpoint = false;

			if (cur_live.tm > limit)
				return;

			int bit = get_next_bit(cur_live.tm, limit);
			if(bit < 0)
				return;

			int cell_counter = cur_live.cell_counter;

			if (bit) {
				cur_live.cycle_counter = cur_live.ds;
				cur_live.cell_counter = 0;
			} else {
				cur_live.cycle_counter++;
			}

			if (cur_live.cycle_counter == 16) {
				cur_live.cycle_counter = cur_live.ds;

				cur_live.cell_counter++;
				cur_live.cell_counter &= 0xf;
			}

			if (!BIT(cell_counter, 1) && BIT(cur_live.cell_counter, 1)) {
				// read bit
				cur_live.shift_reg <<= 1;
				cur_live.shift_reg |= !(BIT(cur_live.cell_counter, 3) || BIT(cur_live.cell_counter, 2));
				cur_live.shift_reg &= 0x3ff;

				if (LOG) logerror("%s read bit %u (%u) >> %03x, oe=%u soe=%u sync=%u byte=%u\n", cur_live.tm.as_string(), cur_live.bit_counter,
					!(BIT(cur_live.cell_counter, 3) || BIT(cur_live.cell_counter, 2)), cur_live.shift_reg, cur_live.oe, cur_live.soe, cur_live.sync, cur_live.byte);

				syncpoint = true;
			}

			if (BIT(cell_counter, 1) && !BIT(cur_live.cell_counter, 1) && !cur_live.oe) {
				write_next_bit(BIT(cur_live.shift_reg_write, 7), limit);
			}

			int sync = !((cur_live.shift_reg == 0x3ff) && cur_live.oe);

			if (!sync) {
				cur_live.bit_counter = 8;
			} else if (!BIT(cell_counter, 1) && BIT(cur_live.cell_counter, 1) && cur_live.sync) {
				cur_live.bit_counter++;
				cur_live.bit_counter &= 0xf;
			}

			int byte = !(((cur_live.bit_counter & 7) == 7) && cur_live.soe && !(cur_live.cell_counter & 2));
			int load = !(((cur_live.bit_counter & 7) == 7) && ((cur_live.cell_counter & 3) == 3));

			if (!load) {
				if (cur_live.oe) {
					cur_live.shift_reg_write = cur_live.shift_reg;
					if (LOG) logerror("%s load write shift register from read shift register %02x\n",cur_live.tm.as_string(),cur_live.shift_reg_write);
				} else {
					cur_live.shift_reg_write = cur_live.yb;
					if (LOG) logerror("%s load write shift register from YB %02x\n",cur_live.tm.as_string(),cur_live.shift_reg_write);
				}
			} else if (!BIT(cell_counter, 1) && BIT(cur_live.cell_counter, 1)) {
				cur_live.shift_reg_write <<= 1;
				cur_live.shift_reg_write &= 0xff;
				if (LOG) logerror("%s shift write register << %02x\n", cur_live.tm.as_string(), cur_live.shift_reg_write);
			}

			// update signals
			if (byte != cur_live.byte) {
				if (!byte || !cur_live.accl) {
					if (LOG) logerror("%s BYTE %u\n", cur_live.tm.as_string(),byte);
					cur_live.byte = byte;
					syncpoint = true;
				}
				if (!byte) {
					cur_live.accl_yb = cur_live.shift_reg & 0xff;
				}
			}

			if (sync != cur_live.sync) {
				if (LOG) logerror("%s SYNC %u\n", cur_live.tm.as_string(),sync);
				cur_live.sync = sync;
				syncpoint = true;
			}

			if (syncpoint) {
				commit(cur_live.tm);

				cur_live.tm += m_period;
				live_delay(RUNNING_SYNCPOINT);
				return;
			}

			cur_live.tm += m_period;
			break;
		}

		case RUNNING_SYNCPOINT: {
			m_write_sync(cur_live.sync);
			m_write_byte(cur_live.byte);

			cur_live.state = RUNNING;
			checkpoint();
			break;
		}
		}
	}
}
コード例 #7
0
ファイル: decoder.c プロジェクト: yfang1644/DSP55X
/***************************************************************************
 Function:    decode_vector_quantized_mlt_indices

 Syntax:      void decode_vector_quantized_mlt_indices(Bit_Obj  *bitobj,
                                                       Int16   *decoder_region_standard_deviation,
                                                       Int16   *decoder_power_categories,
                                                       Int16   *decoder_mlt_coefs)
              inputs:    Bit_Obj  *bitobj
                         Rand_Obj *randobj
                         Int16   *decoder_region_standard_deviation
                         Int16   *decoder_power_categories

              outputs:   Int16   *decoder_mlt_coefs


 Description: Decode MLT coefficients

 Design Notes:

 WMOPS:     7kHz |    24kbit    |    32kbit
          -------|--------------|----------------
            AVG  |    0.60      |    0.72
          -------|--------------|----------------
            MAX  |    0.67      |    0.76
          -------|--------------|----------------
				
           14kHz |    24kbit    |    32kbit      |     48kbit
          -------|--------------|----------------|----------------
            AVG  |    0.77      |    0.98        |     1.28
          -------|--------------|----------------|----------------
            MAX  |    1.05      |    1.18        |     1.36
          -------|--------------|----------------|----------------
				
***************************************************************************/
void decode_vector_quantized_mlt_indices(Bit_Obj  *bitobj,
                                         Int16   *decoder_region_standard_deviation,
					                     Int16   *decoder_power_categories,
					                     Int16   *decoder_mlt_coefs)
{
    Int16 standard_deviation;
    Int16 *decoder_mlt_ptr;
    Int16 *raw_mlt_ptr;
    Int16 decoder_mlt_value;
    Int16 noifill[2];
    Int16 noise_fill_factor[3] = {5793,8192,23170};
    Int16 region;
    Int16 category;
    Int16 j, n;
    Int16 k[MAX_VECTOR_DIMENSION];
    Int16 vec_dim;
    Int16 num_vecs;
    Int16 index;
    Int16 signs_index;
    Int16 bit;
    Int16 num_sign_bits;
    Int16 ran_out_of_bits_flag = 0;
    Int16 *decoder_table_ptr;
    Int16 random_word;

    Int16 temp;
    Int32 acca;

	raw_mlt_ptr = decoder_mlt_coefs;
    for (region = 0; region < NUMBER_OF_REGIONS; region++) 
    {
        category = decoder_power_categories[region];
        decoder_mlt_ptr = raw_mlt_ptr;
        standard_deviation = decoder_region_standard_deviation[region];

        if (category < 7)
        {
            /* Get the proper table of decoder tables, vec_dim, and num_vecs for the cat */
            decoder_table_ptr = (Int16 *) table_of_decoder_tables[category];
            vec_dim = vector_dimension[category];
            num_vecs = number_of_vectors[category];

            for (n = 0; n < num_vecs; n++)
            {
                index = 0;

                /* get index */
                do
                {
                    if (bitobj->number_of_bits_left <= 0) 
                    {
                        ran_out_of_bits_flag = 1;
    	                break;
    	            }

    	            get_next_bit(bitobj);

                    temp = index << 1;
                    index = decoder_table_ptr[temp + bitobj->next_bit];

	                bitobj->number_of_bits_left--;
                } while (index > 0);

                if (ran_out_of_bits_flag != 0)
	                break;

                index = negate(index);

                /* convert index into array used to access the centroid table */
                /* get the number of sign bits in the index */
                num_sign_bits = index_to_array(index, k, category);

	            if (bitobj->number_of_bits_left >= num_sign_bits)
                {
                    if (num_sign_bits != 0) 
                    {
	                    signs_index = 0;
                        for (j = 0; j < num_sign_bits; j++) 
                        {
	                        get_next_bit(bitobj);
       	                    signs_index <<= 1;
		                    signs_index += bitobj->next_bit;
                            bitobj->number_of_bits_left--;
                        }
	                    temp = num_sign_bits - 1;
                        bit = 1 << temp;
	                }

                    for (j = 0; j < vec_dim; j++)
                    {
	                    acca = (Int32)standard_deviation * (Int32)mlt_quant_centroid[category][k[j]];
                        acca = acca >> 12;
                        decoder_mlt_value = (Int16)acca;

                        if (decoder_mlt_value != 0)
                        {
                            if ((signs_index & bit) == 0)
		                        decoder_mlt_value = negate(decoder_mlt_value);
		                    bit = bit >> 1;
	                    }
                        *decoder_mlt_ptr++ = decoder_mlt_value;
	                }
	            }
	            else
                {
	                ran_out_of_bits_flag = 1;
	                break;
	            }
	        }
            /* If ran out of bits during decoding do noise fill for remaining regions. */
            /* DEBUG!! - For now also redo all of last region with all noise fill. */
            if (ran_out_of_bits_flag != 0)
            {
        	    temp = add(region, 1);
                for (j = temp; j < NUMBER_OF_REGIONS; j++)
                {
                    decoder_power_categories[j] = 7;
                }
        	    category = 7;
        	}
        }
コード例 #8
0
ファイル: decoder.c プロジェクト: yfang1644/DSP55X
/***************************************************************************
 Function:    decode_envelope

 Syntax:      void decode_envelope(Bit_Obj *bitobj,
                                   Int16  *decoder_region_standard_deviation,
                                   Int16  *absolute_region_power_index,
                                   Int16  *p_mag_shift)

              inputs:   Bit_Obj *bitobj

              outputs:  Int16  *decoder_region_standard_deviation
                        Int16  *absolute_region_power_index
                        Int16  *p_mag_shift


 Description: Recover differential_region_power_index from code bits

 Design Notes:

 WMOPS:     7kHz |    24kbit    |    32kbit
          -------|--------------|----------------
            AVG  |     0.04     |    0.04
          -------|--------------|----------------
            MAX  |     0.05     |    0.05
          -------|--------------|----------------
				
           14kHz |    24kbit    |    32kbit      |     48kbit
          -------|--------------|----------------|----------------
            AVG  |     0.08     |    0.08        |     0.08
          -------|--------------|----------------|----------------
            MAX  |     0.10     |    0.10        |     0.10
          -------|--------------|----------------|----------------
				
***************************************************************************/
void decode_envelope(Bit_Obj *bitobj,
                     Int16  *decoder_region_standard_deviation,
		             Int16  *absolute_region_power_index,
		             Int16  *p_mag_shift)
{
    Int16 region;
    Int16 i;
    Int16 index = 0;
    Int16 max_index = 0;

    Int16 temp;
    Int32 acca;

    /* get 5 bits from the current code word */
    for (i = 0; i < 5; i++)
    {
        get_next_bit(bitobj);
        index = index << 1;
        index = index + bitobj->next_bit;
    }
    bitobj->number_of_bits_left = bitobj->number_of_bits_left - 5;

    /* ESF_ADJUSTMENT_TO_RMS_INDEX compensates for the current (9/30/96)
        IMLT being scaled to high by the ninth power of sqrt(2). */

    absolute_region_power_index[0] = index - ESF_ADJUSTMENT_TO_RMS_INDEX;
    /* Reconstruct absolute_region_power_index[] from differential_region_power_index[]. */

    i = absolute_region_power_index[0] + REGION_POWER_TABLE_NUM_NEGATIVES;
    if (i > max_index)
        max_index = i;

    temp = int_region_standard_deviation_table[i];
    /* obtain differential_region_power_index */
    for (region = 1; region < NUMBER_OF_REGIONS; region++) 
    {
        index = 0;
        do
        {
            get_next_bit(bitobj);
            i = bitobj->next_bit;
	        index = differential_region_power_decoder_tree[region][index][i];

            bitobj->number_of_bits_left--;
        } while (index > 0);

        acca = (Int32)absolute_region_power_index[region-1] - (Int32)index;
        acca = acca + DRP_DIFF_MIN;
        absolute_region_power_index[region] = (Int16)acca;

    /* DEBUG!!!! - This integer method jointly computes the mag_shift
       and the standard deviations already mag_shift compensated. It
       relies on REGION_POWER_STEPSIZE_DB being exactly 3.010299957 db
       or a square root of 2 chnage in standard deviation. If
       REGION_POWER_STEPSIZE_DB changes, this software must be
       reworked. */

        i = absolute_region_power_index[region] + REGION_POWER_TABLE_NUM_NEGATIVES;
        if (i > max_index)
            max_index = i;

        temp = add(temp, int_region_standard_deviation_table[i]);
    }

    i = 9;

    while ((i >= 0) && ((temp >= 8) || (max_index > 28)))
    {
        i--;
        temp = temp >> 1;
        max_index = max_index - 2;
    }

    *p_mag_shift = i;

    /* pointer arithmetic */
    temp = (Int16 )(REGION_POWER_TABLE_NUM_NEGATIVES + (*p_mag_shift * 2));

    for (region = 0; region < NUMBER_OF_REGIONS; region++) 
    {
        i = absolute_region_power_index[region] + temp;
        decoder_region_standard_deviation[region] = int_region_standard_deviation_table[i];
    }
}