Exemplo n.º 1
0
Arquivo: sgen.c Projeto: bmc0/dsp
void sgen_run_generator(struct sgen_generator *g, struct codec *c, sample_t *buf, ssize_t frames)
{
	sample_t s;
	double t;
	ssize_t i, k, samples;
	switch (g->type) {
	case SGEN_TYPE_DELTA:
		if (g->offset >= 0) {
			if (g->offset < frames)
				for (i = 0; i < c->channels; ++i)
					if (GET_BIT(g->channel_selector, i))
						buf[g->offset * c->channels + i] += 1.0;
			g->offset -= frames;
		}
		break;
	case SGEN_TYPE_SINE:
		samples = frames * c->channels;
		for (i = 0; i < samples; i += c->channels) {
			t = (double) g->pos / c->fs;
			if (g->v != 0.0)
				s = sin(g->freq0 / g->v * (exp(t * g->v) - 1.0));
			else
				s = sin(g->freq0 * t);
			for (k = 0; k < c->channels; ++k)
				if (GET_BIT(g->channel_selector, k))
					buf[i + k] += s;
			++g->pos;
		}
		break;
	}
}
Exemplo n.º 2
0
/*
 * Boot module scope
 */
int
app_preload(struct app_t *app, int argc, char **argv)
{
	struct module_t *module = app->data;
	struct app_opt_t *app_opt;

	if(NULL == module)
		return E_MOD;

	app_opt = app->opts;
	log(app->ctx,1,"app preload: %s\n", module->name);

	/* Must be boot type */
	if(!GET_BIT(module->type, M_BOOT))
		return E_CONF;

	if(!GET_BIT(module->type, M_EMBED))
		log(app->ctx, 1, "Warn: app module not embedded!\n");

	app->ctx->boot->module = module;

	if(module->preload(app->ctx, app->ctx->boot))
		return E_CONF;

	/* Now register app and we are ready to go */
	if(!register_app(app->ctx, app))
		return E_CONF;

	return E_NONE;
}
Exemplo n.º 3
0
/**
 * Calculates the heuristic score for the AI
 */
heuristic_t calculate_heuristics(int isItSelfTurn) {
    // Turn bonus
    heuristic_t score = (isItSelfTurn << 3) - (isItSelfTurn << 1) - 3; //isItSelfTurn*6-3

    // Material + king bonus
    score += population_score();

    // Runaway man
    /*score += ((0x00000010 & (gamestate.self & (~gamestate.kings))) && !(0x00000001 & gamestate.occupied)) * 47;
    score -= ((0x01000000 & (gamestate.other & (~gamestate.kings))) && !(0x30000000 & gamestate.occupied)) * 47;
    score += ((0x00000020 & (gamestate.self & (~gamestate.kings))) && !(0x00000003 & gamestate.occupied)) * 47;
    score -= ((0x02000000 & (gamestate.other & (~gamestate.kings))) && !(0x60000000 & gamestate.occupied)) * 47;
    score += ((0x00000040 & (gamestate.self & (~gamestate.kings))) && !(0x00000006 & gamestate.occupied)) * 47;
    score -= ((0x04000000 & (gamestate.other & (~gamestate.kings))) && !(0xC0000000 & gamestate.occupied)) * 47;
    score += ((0x00000080 & (gamestate.self & (~gamestate.kings))) && !(0x0000000C & gamestate.occupied)) * 47;
    score -= ((0x08000000 & (gamestate.other & (~gamestate.kings))) && !(0x80000000 & gamestate.occupied)) * 47;
    score += ((0x00000100 & (gamestate.self & (~gamestate.kings))) && !(0x00000011 & gamestate.occupied)) * 44;
    score -= ((0x00100000 & (gamestate.other & (~gamestate.kings))) && !(0x31000000 & gamestate.occupied)) * 44;
    score += ((0x00000200 & (gamestate.self & (~gamestate.kings))) && !(0x00000067 & gamestate.occupied)) * 44;
    score -= ((0x00200000 & (gamestate.other & (~gamestate.kings))) && !(0x73000000 & gamestate.occupied)) * 44;
    score += ((0x00000400 & (gamestate.self & (~gamestate.kings))) && !(0x000000CE & gamestate.occupied)) * 44;
    score -= ((0x00400000 & (gamestate.other & (~gamestate.kings))) && !(0xE6000000 & gamestate.occupied)) * 44;
    score += ((0x00000800 & (gamestate.self & (~gamestate.kings))) && !(0x0000008C & gamestate.occupied)) * 44;
    score -= ((0x00800000 & (gamestate.other & (~gamestate.kings))) && !(0x88000000 & gamestate.occupied)) * 44;*/

    // Back row bonus
    score += population_count(0xF0000000 & gamestate.occupied) * 7;
    score -= population_count(0x0000000F & gamestate.occupied) * 7;

    // Dog hole penalty
    score += (GET_BIT(gamestate.other, 27) && GET_BIT(gamestate.self, 31)) * 10;
    score -= (GET_BIT(gamestate.self, 4) && GET_BIT(gamestate.other, 0)) * 10;

    return score;
}
Exemplo n.º 4
0
void compress_effect_run(struct effect *e, ssize_t *frames, sample_t *ibuf, sample_t *obuf)
{
    ssize_t i, k, samples = *frames * e->ostream.channels;
    sample_t s, gain_target;
    struct compress_state *state = (struct compress_state *) e->data;
    for (i = 0; i < samples; i += e->ostream.channels) {
        s = 0;
        for (k = 0; k < e->ostream.channels; ++k)
            if (GET_BIT(e->channel_selector, k))
                s = MAXIMUM(fabs(ibuf[i + k]), s);
        if (s > state->thresh)
            gain_target = pow(10, (state->thresh_db - (20 * log10(s))) * state->ratio / 20);
        else
            gain_target = 1.0;
        if (state->gain > gain_target) {
            state->gain *= state->attack;
            if (state->gain < gain_target)
                state->gain = gain_target;
        }
        else if (state->gain < gain_target) {
            state->gain *= state->release;
            if (state->gain > gain_target)
                state->gain = gain_target;
        }
        for (k = 0; k < e->ostream.channels; ++k) {
            if (GET_BIT(e->channel_selector, k))
                obuf[i + k] = ibuf[i + k] * state->gain;
            else
                obuf[i + k] = ibuf[i + k];
        }
    }
}
Exemplo n.º 5
0
void controlBrakePostfire(int hasEventFlags, int craneKnownFlags, 
        int cranePresentFlags) {

    switch(state) {
        case READY : {
            if(GET_BIT(craneKnownFlags, TRIGGERBIT)) {
                if(GET_BIT(cranePresentFlags, TRIGGERBIT)) {
                    state = RUNNING;
                }
            }
        } break;

        case RUNNING : {
            if(GET_BIT(hasEventFlags, SHUTDOWNBIT)) {
                initControlBrake();
                break;
            }

            if(GET_BIT(craneKnownFlags, EMSTOPMERGERBIT)) {
                if(GET_BIT(cranePresentFlags, EMSTOPMERGERBIT)) {
                    initControlBrake();
                }
            }
        } break;
    }
}
Exemplo n.º 6
0
int key_pressed(r,c) {
	if (!GET_BIT(PINC, r)) {
		if (!GET_BIT(PORTC, c))
		return 1;
	}
	return 0;
}
Exemplo n.º 7
0
Board captureLine(Board b, int moveIndex, int player, short dX, short dY) {
	Board bc = b;
	while ( 1 ) {
		// Left side out of bounds
		if( dX < 0 && moveIndex % 8 == 0) {
			return b;
		}
		// Right side out of bounds
		if ( dX > 0 && moveIndex % 8 == 7) {
			return b;
		}
		moveIndex += dX + dY * 8;
		// Upper edge & lower edge out of bounds
		if ( moveIndex < 0 || moveIndex > 63 ) {
			return b;
		}
		else if ( ! GET_BIT(b.mask, moveIndex) ) {
			return b;
		}
		else if ( GET_BIT(b.owner, moveIndex) ^ player){
			bc.owner = TOGGLE_BIT(bc.owner, moveIndex);
		}
		else {
			return bc;
		}
	}
	return b; // Never reached, included for compiler warnings
}
Exemplo n.º 8
0
/* returns 0 if bmsk and src dont match, 1 if they do */
int
convCmp_bitMask(Byte bmsk, Byte src, int istart, int iend)
{
    int ret = 1;
    if (!iend) {
        /* if there's only one index number to check (iend = 0) */
	if (GET_BIT(bmsk, 0) != GET_BIT(src, istart)) {
	    return 0;
	}
        else {
            return 1;
	}
    }
    /* if there's a group of index numbers to check */
    else {
	int i, x;
        for (i = istart, x = 0; i < iend; i++, x++) {
            if (GET_BIT(src, i) != GET_BIT(bmsk, x)) {
                ret = 0;
                break;
            }
        }
    }
    return ret;
}
Exemplo n.º 9
0
_Bool pressed(int col, int row)
{
	CLR_BIT(PORTC, col);
	_Bool buttonPressed = !GET_BIT(PINC, col) && !GET_BIT(PINC, row);
	
	return !GET_BIT(PINC, col) && !GET_BIT(PINC, row);
}
Exemplo n.º 10
0
/*
 * Boot.
 * Squat app/module is using it
 */
struct ctx_t *
app_boot(struct ctx_t *cur, void *a, void *args)
{
	app_getopt *opts = args;
	struct app_t *app = a;
	struct cfg_t *cfg;

	if(NULL == cur)
	{
		if(app->ctx)
			log(app->ctx, 1, "Alredy got app->ctx!\n");

		app->ctx = ctx_new(CTX_STDERR|CTX_BOOT);

		if (NULL == app->ctx)
			return NULL;
	}
	else
		app->ctx = cur;

	cfg = app->ctx->cfg;
	set_early_log(app->ctx);

	/* Ok we really really need this very early */
	if(NULL == sys_create(app->ctx, "api", T_HASH))
		return NULL;

	/*if(NULL == sys_create(app->ctx, "parser", T_STORE))
		return NULL;*/

	log(app->ctx, 0, "app boot: %s\n", app->name);

	/*
	 * Default handler is sig_run
	 * sig_run is responsible of traversing ctx/scope
	 * and run all handlers that are registered
	 */
	/*signal(SIGINT, sig_run);
	signal(SIGHUP, sig_run);
	signal(SIGTERM, sig_run);
	signal(SIGSEGV, sig_run);
	signal(SIGBUS, sig_run);*/

	/* reset to default boot options */
	if(GET_BIT(app->type, APP_DAEMON))
		cfg->basic->daemon = 1;

	if(GET_BIT(app->type, APP_LOG))
		cfg->basic->prio = 1;

	/* cfg */
	cfg->basic->argc = opts->argc;
	cfg->basic->argv = opts->argv;

	optind = 1;
	return app->ctx;
}
static void rewrite_source(struct radeon_compiler * c,
		struct rc_instruction * inst, unsigned src)
{
	struct rc_swizzle_split split;
	unsigned int tempreg = rc_find_free_temporary(c);
	unsigned int usemask;

	usemask = 0;
	for(unsigned int chan = 0; chan < 4; ++chan) {
		if (GET_SWZ(inst->U.I.SrcReg[src].Swizzle, chan) != RC_SWIZZLE_UNUSED)
			usemask |= 1 << chan;
	}

	c->SwizzleCaps->Split(inst->U.I.SrcReg[src], usemask, &split);

	for(unsigned int phase = 0; phase < split.NumPhases; ++phase) {
		struct rc_instruction * mov = rc_insert_new_instruction(c, inst->Prev);
		unsigned int phase_refmask;
		unsigned int masked_negate;

		mov->U.I.Opcode = RC_OPCODE_MOV;
		mov->U.I.DstReg.File = RC_FILE_TEMPORARY;
		mov->U.I.DstReg.Index = tempreg;
		mov->U.I.DstReg.WriteMask = split.Phase[phase];
		mov->U.I.SrcReg[0] = inst->U.I.SrcReg[src];
		mov->U.I.PreSub = inst->U.I.PreSub;

		phase_refmask = 0;
		for(unsigned int chan = 0; chan < 4; ++chan) {
			if (!GET_BIT(split.Phase[phase], chan))
				SET_SWZ(mov->U.I.SrcReg[0].Swizzle, chan, RC_SWIZZLE_UNUSED);
			else
				phase_refmask |= 1 << GET_SWZ(mov->U.I.SrcReg[0].Swizzle, chan);
		}

		phase_refmask &= RC_MASK_XYZW;

		masked_negate = split.Phase[phase] & mov->U.I.SrcReg[0].Negate;
		if (masked_negate == 0)
			mov->U.I.SrcReg[0].Negate = 0;
		else if (masked_negate == split.Phase[phase])
			mov->U.I.SrcReg[0].Negate = RC_MASK_XYZW;

	}

	inst->U.I.SrcReg[src].File = RC_FILE_TEMPORARY;
	inst->U.I.SrcReg[src].Index = tempreg;
	inst->U.I.SrcReg[src].Swizzle = 0;
	inst->U.I.SrcReg[src].Negate = RC_MASK_NONE;
	inst->U.I.SrcReg[src].Abs = 0;
	for(unsigned int chan = 0; chan < 4; ++chan) {
		SET_SWZ(inst->U.I.SrcReg[src].Swizzle, chan,
				GET_BIT(usemask, chan) ? chan : RC_SWIZZLE_UNUSED);
	}
}
Exemplo n.º 12
0
void perm_to_str(int perm, char str[4])
{
    strcpy(str, "rwx");

    if(GET_BIT(perm, 2) == 0)
        str[0] = '-';

    if(GET_BIT(perm, 1) == 0)
        str[1] = '-';

    if(GET_BIT(perm, 0) == 0)
        str[2] = '-';
}
Exemplo n.º 13
0
int read_pagemap(char * path_buf, unsigned long virt_addr){
   printf("Big endian? %d\n", is_bigendian());
   f = fopen(path_buf, "rb");
   if(!f){
      printf("Error! Cannot open %s\n", path_buf);
      return -1;
   }
   
   //Shifting by virt-addr-offset number of bytes
   //and multiplying by the size of an address (the size of an entry in pagemap file)
   file_offset = virt_addr / getpagesize() * PAGEMAP_ENTRY;
   printf("Vaddr: 0x%lx, Page_size: %d, Entry_size: %d\n", virt_addr, getpagesize(), PAGEMAP_ENTRY);
   printf("Reading %s at 0x%llx\n", path_buf, (unsigned long long) file_offset);
   status = fseek(f, file_offset, SEEK_SET);
   if(status){
      perror("Failed to do fseek!");
      return -1;
   }
   errno = 0;
   read_val = 0;
   unsigned char c_buf[PAGEMAP_ENTRY];
   for(i=0; i < PAGEMAP_ENTRY; i++){
      c = getc(f);
      if(c==EOF){
         printf("\nReached end of the file\n");
         return 0;
      }
      if(is_bigendian())
           c_buf[i] = c;
      else
           c_buf[PAGEMAP_ENTRY - i - 1] = c;
      printf("[%d]0x%x ", i, c);
   }
   for(i=0; i < PAGEMAP_ENTRY; i++){
      //printf("%d ",c_buf[i]);
      read_val = (read_val << 8) + c_buf[i];
   }
   printf("\n");
   printf("Result: 0x%llx\n", (unsigned long long) read_val);
   //if(GET_BIT(read_val, 63))
   if(GET_BIT(read_val, 63))
      printf("PFN: 0x%llx\n",(unsigned long long) GET_PFN(read_val));
   else
      printf("Page not present\n");
   if(GET_BIT(read_val, 62))
      printf("Page swapped\n");
   fclose(f);
   return 0;
}
Exemplo n.º 14
0
static void plot_rfi(rfi * plotrfi, float top, int numint, int numchan,
                     float T, float lof, float hif)
{
   int ii;
   float period, perioderr, dy = 0.035, *temparr;
   float tr[6] = { -0.5, 1.0, 0.0, -0.5, 0.0, 1.0 };
   char temp[40];

   if (plotrfi->freq_avg == 0.0)
      period = 0.0;
   else
      period = 1000.0 / plotrfi->freq_avg;
   if (plotrfi->freq_var == 0.0)        /* Why are these zero? */
      perioderr = 0.0;
   else
      perioderr = 1000.0 * sqrt(plotrfi->freq_var) /
          (plotrfi->freq_avg * plotrfi->freq_avg);
   cpgsvp(0.0, 1.0, 0.0, 1.0);
   cpgswin(0.0, 1.0, 0.0, 1.0);
   cpgnice_output_2(temp, plotrfi->freq_avg, sqrt(plotrfi->freq_var), 0);
   cpgptxt(0.03, top - 0.6 * dy, 0.0, 0.0, temp);
   cpgnice_output_2(temp, period, perioderr, 0);
   cpgptxt(0.12, top - 0.6 * dy, 0.0, 0.0, temp);
   sprintf(temp, "%-5.2f", plotrfi->sigma_avg);
   cpgptxt(0.21, top - 0.6 * dy, 0.0, 0.0, temp);
   sprintf(temp, "%d", plotrfi->numobs);
   cpgptxt(0.27, top - 0.6 * dy, 0.0, 0.0, temp);
   ii = (numint > numchan) ? numint : numchan;
   temparr = gen_fvect(ii);
   for (ii = 0; ii < numchan; ii++)
      temparr[ii] = GET_BIT(plotrfi->chans, ii);
   cpgsvp(0.33, 0.64, top - dy, top);
   cpgswin(0.0, numchan, 0.0, 1.0);
   cpgimag(temparr, numchan, 1, 1, numchan, 1, 1, 0.0, 1.0, tr);
   cpgswin(0.0, numchan, 0.0, 1.0);
   cpgbox("BST", 0.0, 0, "BC", 0.0, 0);
   cpgswin(lof, hif, 0.0, 1.0);
   cpgbox("CST", 0.0, 0, "", 0.0, 0);
   for (ii = 0; ii < numint; ii++)
      temparr[ii] = GET_BIT(plotrfi->times, ii);
   cpgsvp(0.65, 0.96, top - dy, top);
   cpgswin(0.0, numint, 0.0, 1.0);
   cpgimag(temparr, numint, 1, 1, numint, 1, 1, 0.0, 1.0, tr);
   cpgswin(0.0, numint, 0.0, 1.0);
   cpgbox("BST", 0.0, 0, "BC", 0.0, 0);
   cpgswin(0.0, T, 0.0, 1.0);
   cpgbox("CST", 0.0, 0, "", 0.0, 0);
   vect_free(temparr);
}
Exemplo n.º 15
0
int preprocess_it(Instruction *out, Emulator *emul)
{
	char msk = (char) out->ext.plages[0].value;
	int mask=0, sign=0, thn=out->ext.plages[1].value, els=0;
	int i, k;
	char cond0 = GET_BIT(thn, 0);


	for (k = 0; k < 4; k++) // trouve le premier bit à 1
	{
		if(GET_BIT(msk, k) == (1 << k) )
			break;
	}



	for (i = 3; i > k; i--)
	{
		if( GET_BIT(msk, i) == (cond0 << i) )
		{
			strcat(out->name_out, "T");
			sign += (sign << 1) + 1;
		}
		else
		{
			strcat(out->name_out, "E");
			sign <<= 1;
		}
	}

	strcat(out->name_out, " ");
	strcat(out->name_out, emul->dic->states_tab[thn]);


	mask = (1 << (4 - k)) - 1; // mask au format de la fonction process_state
	sign += (sign << 1) + 1; // la première condition est forcément Then

	// printf("k = %u\tmask = %s\n", k, int_to_bin(mask, 4));

	if( (thn & 1) == 0 )
		els = thn + 1;
	else
		els = thn - 1;

	set_it_state(&emul->it_state, mask, sign, thn, els);

	return 0;
}
// Encodes a frame according to the following rule:
// First byte : Start sequence = 1111 1111 (0xFF)
// Second byte : Total size of the encoded frame
// The starting sequence cannot be repeated in the rest of the encoded frame, so
// a 0 (zero) is interleaved every 7 consecutive 1s (ex: 1111 1111 is encoded to 1111 1110 1000)
uint8_t * DataLinkLayer::frame_encode(Frame * frame, uint8_t * size) {
    uint8_t * data = (uint8_t *) frame;
    uint32_t consecutive_ones = 0;
    uint32_t total_extra_bits = 0;
    uint32_t bit_number = 0;

    // Calculate the necessary extra bits to encode the frame
    for(int i = 0; i < sizeof(*frame) * 8; i++) {
        if (GET_BIT(data, i)) {
            consecutive_ones++;
            if (consecutive_ones == 8) {
                total_extra_bits++;
                consecutive_ones = 1;
            }
        } else {
            consecutive_ones = 0;
        }
    }

    // Allocate the necessary space for the encoded frame
    // The size the total size of the frame plus the necessary bytes for the extra bits
    uint32_t alloc_size = sizeof(*frame) + (total_extra_bits ? (total_extra_bits / 8) + 1 : 0);
    uint8_t * result = (uint8_t *) calloc(alloc_size + 2, sizeof(uint8_t));

    // Set the frame start byte
    *result = FRAME_START_BYTE;
    // Set the total allocation size
    *(result + 1) = alloc_size;
    consecutive_ones = 0;

    // Encodes the frame interleaving a zero every 7 consecutive ones
    for(int i = 0; i < sizeof(*frame) * 8; i++, bit_number++) {
        uint8_t current_bit = GET_BIT(data, i);
        if (current_bit) {
            consecutive_ones++;
            if (consecutive_ones == 8) {
                bit_number++;
                consecutive_ones = 1;
            }
        } else {
            consecutive_ones = 0;
        }
        *(result + 2 + (bit_number / 8)) |= (current_bit << (8 - (bit_number % 8) - 1));
    }

    *size = alloc_size + 2;
    return result;
}
Exemplo n.º 17
0
static void reads_normal(struct rc_instruction * fullinst, rc_read_write_fn cb, void * userdata)
{
	struct rc_sub_instruction * inst = &fullinst->U.I;
	const struct rc_opcode_info * opcode = rc_get_opcode_info(inst->Opcode);

	for(unsigned int src = 0; src < opcode->NumSrcRegs; ++src) {
		unsigned int refmask = 0;

		if (inst->SrcReg[src].File == RC_FILE_NONE)
			return;

		for(unsigned int chan = 0; chan < 4; ++chan)
			refmask |= 1 << GET_SWZ(inst->SrcReg[src].Swizzle, chan);

		refmask &= RC_MASK_XYZW;

		for(unsigned int chan = 0; chan < 4; ++chan) {
			if (GET_BIT(refmask, chan)) {
				cb(userdata, fullinst, inst->SrcReg[src].File, inst->SrcReg[src].Index, chan);
			}
		}

		if (refmask && inst->SrcReg[src].RelAddr)
			cb(userdata, fullinst, RC_FILE_ADDRESS, 0, RC_MASK_X);
	}
}
Exemplo n.º 18
0
status_t
submit_tx_command(bt_usb_dev* bdev, snet_buffer* snbuf)
{
	uint8 bRequestType = bdev->ctrl_req;
	uint8 bRequest = 0;
	uint16 wIndex = 0;
	uint16 value = 0;
	uint16 wLength = B_HOST_TO_LENDIAN_INT16(snb_size(snbuf));
	status_t error;

	if (!GET_BIT(bdev->state, RUNNING)) {
		return B_DEV_NOT_READY;
	}

	// set cookie
	snb_set_cookie(snbuf, bdev);

	debugf("@%p\n", snb_get(snbuf));

	error = usb->queue_request(bdev->dev, bRequestType, bRequest,
		value, wIndex, wLength,	snb_get(snbuf),
#ifndef HAIKU_TARGET_PLATFORM_HAIKU
		wLength,
#endif
		command_complete, (void*) snbuf);

	if (error != B_OK) {
		bdev->stat.rejectedTX++;
	} else {
		bdev->stat.acceptedTX++;
	}

	return error;
}
Exemplo n.º 19
0
status_t
submit_tx_acl(bt_usb_dev* bdev, net_buffer* nbuf)
{
	status_t error;

	// set cookie
	SET_DEVICE(nbuf, bdev->hdev);

	if (!GET_BIT(bdev->state, RUNNING)) {
		return B_DEV_NOT_READY;
	}
	/*
	debugf("### Outgoing ACL: len = %ld\n", nbuf->size);
	for (uint32 index = 0 ; index < nbuf->size; index++ ) {
		dprintf("%x:",((uint8*)nb_get_whole_buffer(nbuf))[index]);
	}
	*/

	error = usb->queue_bulk(bdev->bulk_out_ep->handle, nb_get_whole_buffer(nbuf),
		nbuf->size, acl_tx_complete, (void*)nbuf);

	if (error != B_OK) {
		bdev->stat.rejectedTX++;
	} else {
		bdev->stat.acceptedTX++;
	}

	return error;
}
Exemplo n.º 20
0
void place_string_on_output_window(char *str, int len)
{
    if(GET_BIT(options, FULLSCREEN)) {
        scroll_output_window();
    }

    cursor_output_window();
    write_string(str, len);
    ++last_output_row;

    if(!GET_BIT(options, FULLSCREEN)) {
        scroll_output_window();
    }

    add_refresh_line(str, len);
}
Exemplo n.º 21
0
/**********************************************************************************
函数功能:点亮或者熄灭某一个显示标志
入口:    Flag----1:显示;0:熄灭
出口:    1---------有此设备;0------找不到设备
**********************************************************************************/
INT8U SetOrClr_COM4(INT16U Seg,INT8U Com,INT8U Type,INT8U ClrOrSet)
{
   
  if((Seg<=MAX_SEG)&&(Com<=MAX_COL))
  {
    Com=MAX_COL-Com;
    if(Seg%2 EQ 0)       //高4位
        Com+=MAX_COL+1;
      
    if(ClrOrSet)
    {
      if(GET_BIT(Show_Lcd_Ram[Seg/2],Com))  //检查内存是否已经置位或者 seg/com配置表错误
      return 0;
      
      Show_Lcd_Flag=1;       
      
      SET_BIT(Show_Lcd_Ram[Seg/2],Com);
      return 1;
    }
    else
    {        
      CLR_BIT(Show_Lcd_Ram[Seg/2],Com);
      return 1;
    }  
  }
  return 0;
}
Exemplo n.º 22
0
/*
 * Determines if there is any nodes on the buffer that can be taken for
 * processing. A partial node is not valid since all output is newline
 * terminated.
 */
int have_buffer(BufferInfo *infoptr)
{
    static long last_check = -1;

    if(!infoptr) {
        return FALSE;
    }

    if((infoptr->tail == infoptr->head) && infoptr->partial) {
        if(GET_BIT(options, PARTIAL_LINES)) {
            if(last_check == -1) {
                last_check = time(0);
            }
            else if(last_check < (time(0) /* - 1 */)) {
                infoptr->partial = FALSE;
                infoptr->is_partial = TRUE;
                last_check = -1;

                return TRUE;
            }
        }

        return FALSE;
    }

    if(infoptr->head) {
        last_check = -1;

        return TRUE;
    }

    return FALSE;
}
Exemplo n.º 23
0
int main(void){

	DDRA = 0xFF; //set all pins of port A to output
	DDRC = 0x00; //set all pins of port C to input

	while(1)
	{
		int one = 1;
		int count = 0;
		int i = 0;
		while(i < 8)
		{
			int temp = GET_BIT(PINC,i);
			if(temp != 0)
			{
				count++;
			}
			++i;
		}
		if ((count % 2) != 0)
		{
			CLR_BIT(PORTA, 1);
			one = SET_BIT(PORTA, 0);
		}
		else 
		{
				CLR_BIT(PORTA, 0);
			one = SET_BIT(PORTA, 1);
		}
		count = 0;
	}

return 0;
	
}
static int kernel_call_dispatch(struct proc * caller, message *msg)
{
  int result = OK;
  int call_nr;
  
#if DEBUG_IPC_HOOK
	hook_ipc_msgkcall(msg, caller);
#endif
  call_nr = msg->m_type - KERNEL_CALL;

  /* See if the caller made a valid request and try to handle it. */
  if (call_nr < 0 || call_nr >= NR_SYS_CALLS) {	/* check call number */
	  printf("SYSTEM: illegal request %d from %d.\n",
			  call_nr,msg->m_source);
	  result = EBADREQUEST;			/* illegal message type */
  }
  else if (!GET_BIT(priv(caller)->s_k_call_mask, call_nr)) {
	  printf("SYSTEM: denied request %d from %d.\n",
			  call_nr,msg->m_source);
	  result = ECALLDENIED;			/* illegal message type */
  } else {
	  /* handle the system call */
	  if (call_vec[call_nr])
		  result = (*call_vec[call_nr])(caller, msg);
	  else {
		  printf("Unused kernel call %d from %d\n",
				  call_nr, caller->p_endpoint);
		  result = EBADREQUEST;
	  }
  }

  return result;
}
Exemplo n.º 25
0
int mrpc_bitmap_acquire_bit(struct mrpc_bitmap *bitmap)
{
	uint64_t *map;
	int i;
	int n;
	int bitmap_size;

	ff_assert(bitmap->size > 0);
	ff_assert(bitmap->last_free_bit < bitmap->size);

	map = bitmap->map;
	n = bitmap->last_free_bit;
	bitmap_size = bitmap->size;
	for (i = 0; i < bitmap_size; i++)
	{
		if (GET_BIT(map, n) == 0)
		{
			SET_BIT(map, n);
			bitmap->last_free_bit = n;
			break;
		}
		n++;
		if (n == bitmap_size)
		{
			n = 0;
		}
	}
	if (i == bitmap_size)
	{
		ff_log_debug(L"all bits are occupied in the bitmap=%p", bitmap);
		n = -1;
	}
	return n;
}
Exemplo n.º 26
0
void huffmanDecode(FILE *in, FILE *out, CODIFICATION_ARRAY_ELEMENT *treeArray, SYMBOL eof) {
	uint8_t feof = 0;
	unsigned int index = 0;
	for(unsigned int i = 0 ; !feof ; i++) {
		BYTE buffer;
		fread(&buffer, 1, 1, in);
		for(unsigned int j = 0 ; j < BYTE_BIT ; j++) {
			index <<= 1;
			if((GET_BIT(&buffer, j)) == 0)
				index += 1;
			else
				index += 2;

			if(treeArray[index].used) {
				if(treeArray[index].symbol == eof) {
					feof = 1;
					return;
				}
				else
					fwrite(&treeArray[index].symbol, SIZEOF_SYMBOL, 1, out);
				index = 0;
			}
		}
	}
}
Exemplo n.º 27
0
/**
 * Make a transition from <currentState> to the next state for a bit vector encoded
 * as a single integer (max. 64 genes).
 * <currentState> is a binary-coded integer with <numberOfGenes> used bits.
 * <fixedGenes> is an array of values specifying whether gene <i> is fixed (0 or 1) or not (-1).
 * <inputGenes> provides the input genes for all transition functions and can be split up
 * for a single function according to <inputGenePositions>.
 * <transitionFunctions> provides the truth tables for all transition functions and can be split up
 * for a single function according to <transitionFunctionPositions>.
 *
 * The return value is the next state, encoded in a single integer.
 */
unsigned long long stateTransition_singleInt(unsigned long long currentState, TruthTableBooleanNetwork * net)
{
	unsigned int i = 0, k = 0, idx = 0;

  unsigned long long nextState = 0;

	for (i = 1; i <= net->numGenes; ++i)
	{
		if (net->fixedGenes[i-1] == -1)
		// the gene is not fixed
		{
			unsigned long long inputdec = 0;

			for (k = net->inputGenePositions[i-1]; k < net->inputGenePositions[i]; k++)
			{
				if (net->inputGenes[k])
				// if the input of the function is not 0 (constant gene), take input bit
				{
					unsigned int gene = net->inputGenes[k] - 1;
					unsigned int bit;

					if (net->fixedGenes[gene] == -1)
						bit = (GET_BIT(currentState,
							     net->nonFixedGeneBits[gene]));
					else
						// fixed genes are not encoded in the states
						// => take them from fixedGenes vector
						bit = net->fixedGenes[gene];
					inputdec |= bit	<< (net->inputGenePositions[i] - k - 1);
				}
			}
			// determine transition function
			int transition = net->transitionFunctions[net->transitionFunctionPositions[i-1] + inputdec];

			if(transition != -1)
				// apply transition function
				nextState |= (transition << idx);
			else
				// this is a dummy function for a constant gene
				// => value does not change
				nextState |= (GET_BIT(currentState,
															idx) << idx);
			++idx;
		}
	}
	return nextState;
}
Exemplo n.º 28
0
/*
 * Calculate the cpu speed based on the PLL, if the PLL
 * is not being used, this function will return 0
 */
unsigned long
a7hal_clock_getFreq (int noRAM)
{
  unsigned int freq = 0;
#if defined(A7VE) || defined(A7VC) || defined(A7VT) || defined(A7VL)
  unsigned long feedbackDivider;
  unsigned long outputDivider;
  unsigned long referenceDivider;
#else
  unsigned int scale;
#endif

  if (GET_BIT (SYS_CLOCK_CONTROL_REG, CLK_SEL_BIT))
    {
      if (GET_BIT (SYS_CLOCK_CONTROL_REG, PLL_SEL_BIT))
	{
#if defined(A7VE) || defined(A7VC) || defined(A7VT) || defined(A7VL)
	  feedbackDivider = GET_FIELD (SYS_PLL_CONTROL_REG,
				       PLL_CLKF_FIELD, NBITS_PLL_CLKF) + 1;

	  outputDivider = GET_FIELD (SYS_PLL_CONTROL_REG,
				     PLL_CLKOD_FIELD, NBITS_PLL_CLKOD) + 1;

	  referenceDivider = GET_FIELD (SYS_PLL_CONTROL_REG,
					PLL_CLKR_FIELD, NBITS_PLL_CLKR) + 1;


          /*
           * Is the input to the PLL the 32KHz xtal or the external osc.
           */
          if ( GET_BIT( SYS_PLL_CONTROL_REG, PLL_REFSEL_BIT ) )
          {
            freq = ( CONFIG_OSC_FREQ * feedbackDivider ) /
                ( referenceDivider * outputDivider );
          }
          else
          {
              freq = ( 32768 * feedbackDivider ) /
                  ( referenceDivider * outputDivider );
          }

#else
	  freq = 32768 * GET_FIELD (SYS_CLOCK_CONTROL_REG,
				    PLL_DIV_FIELD, NBITS_PLL_DIV);
	  scale =
	    GET_FIELD (SYS_CLOCK_CONTROL_REG, PLL_SCALE_FIELD,
		       NBITS_PLL_SCALE);
	  while (scale)
	    {
	      freq >>= 1;
	      scale >>= 1;
	    }
#endif
	}
      else
	{
	  freq = CONFIG_OSC_FREQ;
	}
    }
Exemplo n.º 29
0
void mrpc_bitmap_release_bit(struct mrpc_bitmap *bitmap, int n)
{
	ff_assert(bitmap->size > 0);
	ff_assert(n < bitmap->size);
	ff_assert(GET_BIT(bitmap->map, n) == 1);

	CLEAR_BIT(bitmap->map, n);
}
Exemplo n.º 30
0
int GetNextTweet(DatabaseItr* itr, Tweet* dest)
{
    do {
        if(ReadTweet(itr->data, dest) < 0) return -1;
    } while(GET_BIT(dest->flags, ACTIVE_BIT) == 0);

    return 0;
}