Exemple #1
0
static void op_MOD_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                       exec_state_t *NOTUSED(es), command_state_t *cs) {
    int16_t a = cs_pop(cs);
    int16_t b = cs_pop(cs);
    int16_t out = b != 0 ? a % b : 0;
    cs_push(cs, out);
}
Exemple #2
0
static void op_MUL_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                       exec_state_t *NOTUSED(es), command_state_t *cs) {
    int32_t r = cs_pop(cs);
    r *= cs_pop(cs);
    if (r > INT16_MAX) r = INT16_MAX;
    if (r < INT16_MIN) r = INT16_MIN;
    cs_push(cs, (int16_t)r);
}
Exemple #3
0
static void op_TI_IN_MAP_get(const void *NOTUSED(data), scene_state_t *ss,
                             exec_state_t *NOTUSED(es), command_state_t *cs) {
    uint8_t output = cs_pop(cs);
    int16_t bottom = cs_pop(cs);
    int16_t top = cs_pop(cs);
    TXSend(TI, TI_IN_TOP, output, top, true);
    TXSend(TI, TI_IN_BOT, output, bottom, true);
}
Exemple #4
0
static void op_MAX_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                       exec_state_t *NOTUSED(es), command_state_t *cs) {
    int16_t a, b;
    a = cs_pop(cs);
    b = cs_pop(cs);
    if (a > b)
        cs_push(cs, a);
    else
        cs_push(cs, b);
}
Exemple #5
0
static void mod_L_func(scene_state_t *ss, exec_state_t *es, command_state_t *cs,
                       tele_command_t *sub_command) {
    int16_t a = cs_pop(cs);
    int16_t b = cs_pop(cs);
    int16_t loop_size = a < b ? b - a : a - b;

    for (int16_t i = 0; i <= loop_size; i++) {
        ss->variables.i = a < b ? a + i : a - i;
        process(es, sub_command);
    }
}
Exemple #6
0
static void op_LIM_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                       exec_state_t *NOTUSED(es), command_state_t *cs) {
    int16_t a, b, i;
    i = cs_pop(cs);
    a = cs_pop(cs);
    b = cs_pop(cs);
    if (i < a)
        cs_push(cs, a);
    else if (i > b)
        cs_push(cs, b);
    else
        cs_push(cs, i);
}
Exemple #7
0
static void op_M_set(const void *NOTUSED(data), scene_state_t *ss,
                     exec_state_t *NOTUSED(es), command_state_t *cs) {
    int16_t m = cs_pop(cs);
    if (m < METRO_MIN_MS) m = METRO_MIN_MS;
    ss->variables.m = m;
    tele_metro_updated();
}
Exemple #8
0
static void op_RAND_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                        exec_state_t *NOTUSED(es), command_state_t *cs) {
    int16_t a = cs_pop(cs);
    if (a == -1)
        cs_push(cs, 0);
    else
        cs_push(cs, rand() % (a + 1));
}
Exemple #9
0
static void mod_IF_func(scene_state_t *NOTUSED(ss), exec_state_t *es,
                        command_state_t *cs, tele_command_t *sub_command) {
    es->if_else_condition = false;
    if (cs_pop(cs)) {
        es->if_else_condition = true;
        process(es, sub_command);
    }
}
Exemple #10
0
static void op_WRAP_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                        exec_state_t *NOTUSED(es), command_state_t *cs) {
    int16_t a, b, i, c;
    i = cs_pop(cs);
    a = cs_pop(cs);
    b = cs_pop(cs);
    if (a < b) {
        c = b - a + 1;
        while (i >= b) i -= c;
        while (i < a) i += c;
    }
    else {
        c = a - b + 1;
        while (i >= a) i -= c;
        while (i < b) i += c;
    }
    cs_push(cs, i);
}
Exemple #11
0
static void op_TI_INIT_get(const void *NOTUSED(data), scene_state_t *ss,
                           exec_state_t *NOTUSED(es), command_state_t *cs) {
    uint8_t end = cs_pop(cs) * 4;
    uint8_t start = end - 3;
    uint8_t i;
    for (i = start; i <= end; i++) {
        PRMInit(i);
        INInit(i);
    }
}
Exemple #12
0
static void op_RRAND_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                         exec_state_t *NOTUSED(es), command_state_t *cs) {
    int16_t a, b, min, max, range;
    a = cs_pop(cs);
    b = cs_pop(cs);
    if (a < b) {
        min = a;
        max = b;
    }
    else {
        min = b;
        max = a;
    }
    range = max - min + 1;
    if (range == 0)
        cs_push(cs, a);
    else
        cs_push(cs, rand() % range + min);
}
Exemple #13
0
static void op_poke_seed_i16(const void *data, scene_state_t *ss,
                             exec_state_t *NOTUSED(es), command_state_t *cs) {
    int16_t s = cs_pop(cs);

    char *base = (char *)ss;
    size_t offset = (size_t)data;
    tele_rand_t *ptr = (tele_rand_t *)(base + offset);

    ptr->seed = s;
    random_seed(&ptr->rand, ptr->seed);
}
Exemple #14
0
static void op_SEED_set(const void *NOTUSED(data), scene_state_t *ss,
                        exec_state_t *NOTUSED(es), command_state_t *cs) {
    uint16_t s = cs_pop(cs);

    for (u8 i = 0; i < RAND_STATES_COUNT; i++) {
        tele_rand_t *r = &ss->rand_states.a[i];
        r->seed = s;
        random_seed(&r->rand, r->seed);
    }

    ss->variables.seed = s;
}
Exemple #15
0
static void op_QT_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                      exec_state_t *NOTUSED(es), command_state_t *cs) {
    // this rounds negative numbers rather than quantize (choose closer)
    int16_t a, b, c, d, e;
    b = cs_pop(cs);
    a = cs_pop(cs);

    if (a == 0) {
        cs_push(cs, 0);
        return;
    }

    c = b / a;
    d = c * a;
    e = (c + 1) * a;

    if (abs(b - d) < abs(b - e))
        cs_push(cs, d);
    else
        cs_push(cs, e);
}
Exemple #16
0
void TXReceive(uint8_t model, command_state_t *cs, uint8_t mode, bool shift) {
    // zero-index the output
    uint8_t input = cs_pop(cs) - 1;
    // send the port, device and address
    uint8_t port = input & 3;
    uint8_t device = input >> 2;
    uint8_t address = model + device;
    // inputs are numbered 0-7 for each device - shift is for the second half
    // mode pushes it up so it can read quantized values and note numbers
    port += (shift ? 4 : 0) + (mode << 3);
    // tell the device what value you are going to query
    uint8_t buffer[2];
    buffer[0] = port;
    tele_ii_tx(address, buffer, 1);
    // now read the value
    buffer[0] = 0;
    buffer[1] = 0;
    tele_ii_rx(address, buffer, 2);
    int16_t value = (buffer[0] << 8) + buffer[1];
    cs_push(cs, value);
}
Exemple #17
0
static void op_FLIP_set(const void *NOTUSED(data), scene_state_t *ss,
                        exec_state_t *NOTUSED(es), command_state_t *cs) {
    ss->variables.flip = cs_pop(cs) != 0;
}
Exemple #18
0
void TXDeviceSet(uint8_t model, uint8_t command, command_state_t *cs) {
    uint8_t output = DeviceToOutput(cs_pop(cs));
    int16_t value = cs_pop(cs);
    TXSend(model, command, output, value, true);
}
Exemple #19
0
void* 
resolve_thread( void *data )
{
	method_list_t 		*m_list;
	mc_t 				*mc;
	cs_t				*cs;
	method_prototype 	method;
	char				*cs_dboid;
	resolve_function 	res_func;
	ev_queue_t			*res_queue;
	png_t 				*conf;
	gen_t 				*g;
	obj_t 				*obj;
	
	conf = (png_t*) data;
	res_queue = &conf->res_queue;
	m_list = conf->m_list;
	
	/* Set default resolve function */
	res_func = &resolve;
	
	printf( "[Resolve Thread] Started.\n" );
	
	while( 1 )
	{
		/* locks the signal variable and wait */
		/*
		pthread_mutex_lock( conf->resolve_sig_lock );
		pthread_cond_wait( conf->resolve_sig, conf->resolve_sig_lock  );
		pthread_mutex_unlock( conf->resolve_sig_lock );
		*/
		
		ev_queue_listen( res_queue );
		
		/* Get what conflict set that send the signal */
		cs_dboid = ev_queue_pop( res_queue );
		
		cs = cs_list_find( &((png_t*)data)->cs_list, cs_dboid );
		
		/* Fetch a generation that needs to be resolved */
		g = cs_pop( cs );
		if( g != NULL )
		{
			/* Fetch the object from the storage */
			imdb_fetch( &conf->stable_db, "obj", (void*)&obj );
			
			/* Perform some conflict resolution */
			mc = res_func( g );
			
			/* Fetch the function pointer */
			method = method_list_find( m_list, mc->method_name );
			
			/* Perform the method on the object */
			method( obj, mc->params, mc->num_param );
			
			/* Put the object back */
			imdb_store( &conf->stable_db, "obj", obj, sizeof( obj_t ) );
			
			printf( "Conflict resolved generation %d\n", g->num );
			
			gen_free( g );

			free( obj );
		}		
	}
	
	return NULL;
}
Exemple #20
0
static void op_EZ_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                      exec_state_t *NOTUSED(es), command_state_t *cs) {
    cs_push(cs, cs_pop(cs) == 0);
}
Exemple #21
0
static void op_AVG_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                       exec_state_t *NOTUSED(es), command_state_t *cs) {
    int32_t ret = (((int32_t)cs_pop(cs) * 2) + ((int32_t)cs_pop(cs) * 2)) / 2;
    if (ret % 2) ret += 1;
    cs_push(cs, (int16_t)(ret / 2));
}
Exemple #22
0
static void op_TO_TR_INIT_get(const void *NOTUSED(data), scene_state_t *ss,
                              exec_state_t *NOTUSED(es), command_state_t *cs) {
    TXCmd(TO, TO_TR_INIT, cs_pop(cs));
}
Exemple #23
0
static void op_TO_M_SYNC_get(const void *NOTUSED(data), scene_state_t *ss,
                             exec_state_t *NOTUSED(es), command_state_t *cs) {
    TXCmd(TO, TO_M_SYNC, DeviceToOutput(cs_pop(cs)));
}
Exemple #24
0
static void op_TI_RESET_get(const void *NOTUSED(data), scene_state_t *ss,
                            exec_state_t *NOTUSED(es), command_state_t *cs) {
    TXCmd(TI, TI_RESET, DeviceToOutput(cs_pop(cs)));
}
Exemple #25
0
static void op_R_MAX_set(const void *NOTUSED(data), scene_state_t *ss,
                         exec_state_t *NOTUSED(es), command_state_t *cs) {
    ss->variables.r_max = cs_pop(cs);
}
Exemple #26
0
static void op_TI_IN_INIT_get(const void *NOTUSED(data), scene_state_t *ss,
                              exec_state_t *NOTUSED(es), command_state_t *cs) {
    INInit(cs_pop(cs));
}
Exemple #27
0
void cs_clear(CharStack *st){
    while(st->curr > 0){
        cs_pop(st);
    }
}
Exemple #28
0
static void op_I_set(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
                     exec_state_t *es, command_state_t *cs) {
    es_variables(es)->i = cs_pop(cs);
}
Exemple #29
0
static void op_LAST_get(const void *NOTUSED(data), scene_state_t *ss,
                        exec_state_t *NOTUSED(es), command_state_t *cs) {
    int16_t script_number = cs_pop(cs) - 1;
    int16_t last = ss_get_script_last(ss, script_number);
    cs_push(cs, last);
}
Exemple #30
0
static void op_DRUNK_set(const void *NOTUSED(data), scene_state_t *ss,
                         exec_state_t *NOTUSED(es), command_state_t *cs) {
    ss->variables.drunk = cs_pop(cs);
}