示例#1
0
void			draw_text(const char* s,
				  unsigned int x, unsigned int y,
				  t_color fg, t_color bg)
{
  char		c;
  char		ch;
  char		p;
  unsigned int	i;
  unsigned int	j;
  unsigned int	pos;
  unsigned int	strp = 0;

  for (; *s; s++, strp++)
    {
      c = *s;

      for (i = 0; i < 8; ++i)
	for (j = 0; j < 8; ++j)
	  {
	    ch = font[c * 8 + i];
	    p = bit_on(ch, j) ? fg : bg;

	    pos = ((y + i) * GRAPHIC_WIDTH) +
	      (strp * 8 + x) + j;
	    if (!((bg == (unsigned int) -1) && (p == -1)))
	      offbuffer[pos] = p;
	  }
    }
}
示例#2
0
文件: set-test.c 项目: noelaye/siggen
main ()
{
	int		i;
	bit_set	a,b,c,d;

	a = create_bit_set (35);
	b = create_bit_set (35);
	c = create_bit_set (35);
	d = create_bit_set (35);

	for (i = 0; i < 35; i++){
		bit_on (a,i);
		bit_on (b,2*(i/2));
		bit_on (c,i);
		bit_on (d,2*(i/2));
	}
	printf ("a == b %d  a sub b %d  b sub a %d\n",
		bit_set_equal (a,b),is_subset(a,b),is_subset(b,a));
	printf ("a == c %d  a sub c %d  c sub a %d\n",
		bit_set_equal (a,c),is_subset(a,c),is_subset(c,a));
	printf ("a == d %d  a sub d %d  d sub a %d\n",
		bit_set_equal (a,d),is_subset(a,d),is_subset(d,a));
	printf ("b == c %d  b sub c %d  c sub b %d\n",
		bit_set_equal (b,c),is_subset(b,c),is_subset(c,b));
	printf ("b == d %d  b sub d %d  d sub b %d\n",
		bit_set_equal (b,d),is_subset(b,d),is_subset(d,b));
	printf ("c == d %d  c sub d %d  d sub c %d\n",
		bit_set_equal (c,d),is_subset(c,d),is_subset(d,c));

	bit_off (d,6);
	bit_off (c,7);

	printf ("\n\na == b %d  a sub b %d  b sub a %d\n",
		bit_set_equal (a,b),is_subset(a,b),is_subset(b,a));
	printf ("a == c %d  a sub c %d  c sub a %d\n",
		bit_set_equal (a,c),is_subset(a,c),is_subset(c,a));
	printf ("a == d %d  a sub d %d  d sub a %d\n",
		bit_set_equal (a,d),is_subset(a,d),is_subset(d,a));
	printf ("b == c %d  b sub c %d  c sub b %d\n",
		bit_set_equal (b,c),is_subset(b,c),is_subset(c,b));
	printf ("b == d %d  b sub d %d  d sub b %d\n",
		bit_set_equal (b,d),is_subset(b,d),is_subset(d,b));
	printf ("c == d %d  c sub d %d  d sub c %d\n",
		bit_set_equal (c,d),is_subset(c,d),is_subset(d,c));
}
示例#3
0
文件: lamp.c 项目: Dmilo/freewpc
void lamp_flash_on (lampnum_t lamp)
{
	if (!bit_test (lamp_flash_matrix, lamp))
	{
		/* Enable flashing on this lamp */
		bit_on (lamp_flash_matrix, lamp);

		/* Set the initial flash state of the lamp to match that of all
		other lamps that are flashing.  If any of the flashing lamps
		are on now, then this one should be on, too.  Otherwise, leave
		it off. */
		disable_interrupts ();
		if (!bit_test_all_off (lamp_flash_matrix_now))
			bit_on (lamp_flash_matrix_now, lamp);
		else
			bit_off (lamp_flash_matrix_now, lamp);
		enable_interrupts ();
	}
}
示例#4
0
/** Add a new entry to the switch queue. */
void switch_queue_add (const switchnum_t sw)
{
	if (switch_queue_top < switch_queue + MAX_QUEUED_SWITCHES)
	{
		dbprintf ("adding %d to queue\n", sw);
		switch_queue_top->id = sw;
		switch_queue_top->timer = switch_lookup(sw)->debounce;
		bit_on (sw_queued, sw);
		switch_queue_top++;
	}
}
示例#5
0
文件: lamp.c 项目: Dmilo/freewpc
/*
 * The leff_ functions below are used to set/clear/toggle/test
 * bits from a lamp effect function.  Otherwise they work
 * identically to the lamp_ versions.
 */
void leff_on (lampnum_t lamp)
{
#ifdef PARANOID
	if (bit_test (leff_free_set, lamp))
	{
		dbprintf ("unallocated lamp on %d\n", lamp);
		return;
	}
#endif
	bit_on (leff_data_set, lamp);
}
int main(void) {
	int quiz1 = 0xFFFFFFFF;
	const int student_size = 27;

	// Deliberately(有意地) starts at 1
	bool has_passed_quiz[student_size + 1];

	for (int index = 1; index <= student_size; ++index) {
		has_passed_quiz[index] = bit_on(quiz1, index);
	}

	return 0;
}
示例#7
0
文件: descs.c 项目: gfto/libtsfuncs
void ts_descriptor_dump(uint8_t *desc_data, int desc_data_len) {
	char *pad  = "        * ";
	uint8_t *data = desc_data;
	int data_len = desc_data_len;
	while (data_len >= 2) {
		int i;
		uint8_t tag         = data[0];
		uint8_t this_length = data[1];

//		ts_LOGf("%sDescriptor tag: 0x%02x (%d) size: %d\n", padA, tag, tag, this_length);

		data     += 2;
		data_len -= 2;

		if (this_length > data_len) {
			// Not much we can do - try giving up?
			ts_LOGf("%s!!! Descriptor 0x%02x says length %d, but only %d bytes left\n", pad, tag, this_length, data_len);
			return;
		}

		switch (tag) {
			case  2: { // Video stream descriptor
				char *dump = ts_hex_dump(data, this_length, 0);
				ts_LOGf("%sTag 0x%02x (%02d), sz: %d, Video stream descriptor: %s\n", pad, tag, tag, this_length, dump);
				free(dump);
				struct {
					uint8_t multiple_frame_rate_flag     : 1,
					        frame_rate_code              : 4,
					        mpeg1_only_flag              : 1,
					        constraint_parameter_flag    : 1,
					        still_picture_flag           : 1;
					uint8_t profile_and_level_indication;
					uint8_t chroma_format                : 2,
					        frame_rate_extension_flag    : 1,
					        reserved                     : 5;
					uint8_t escape:1, profile:3, level:4;
				} vs;
				if (this_length >= 1) {
					vs.multiple_frame_rate_flag     = bit_on(data[0], bit_8);
					vs.frame_rate_code              = (data[0] &~ 0x80) >> 3; // 1xxxx111
					vs.mpeg1_only_flag              = bit_on(data[0], bit_3);
					vs.constraint_parameter_flag    = bit_on(data[0], bit_2);
					vs.still_picture_flag           = bit_on(data[0], bit_1);
					ts_LOGf("%s  - multiple_frame_rate_flag     : %d\n", pad, vs.multiple_frame_rate_flag);
					ts_LOGf("%s  - frame_rate_code              : %d (%s)\n", pad, vs.frame_rate_code,
						vs.frame_rate_code == 0 ? "forbidden" :
						vs.frame_rate_code == 1 ? "23.976" :
						vs.frame_rate_code == 2 ? "24.00" :
						vs.frame_rate_code == 3 ? "25.00" :
						vs.frame_rate_code == 4 ? "29.97" :
						vs.frame_rate_code == 5 ? "30.00" :
						vs.frame_rate_code == 6 ? "50.00" :
						vs.frame_rate_code == 7 ? "59.94" :
						vs.frame_rate_code == 8 ? "60.00" : "reserved"
					);
					ts_LOGf("%s  - mpeg1_only_flag              : %d\n", pad, vs.mpeg1_only_flag);
					ts_LOGf("%s  - constraint_parameter_flag    : %d\n", pad, vs.constraint_parameter_flag);
					ts_LOGf("%s  - still_picture_flag           : %d\n", pad, vs.still_picture_flag);
				}
				if (this_length >= 2 && vs.mpeg1_only_flag == 0) {
					vs.profile_and_level_indication = data[1];
					vs.chroma_format                = data[2] >> 6;				// xx111111
					vs.frame_rate_extension_flag    = bit_on(data[2], bit_6);	// 11x11111
					vs.reserved                     = data[2] &~ 0xE0;			// 111xxxxx
					vs.profile                      = (vs.profile_and_level_indication &~ 0x8f) >> 4;	// x111xxxx
					vs.level                        =  vs.profile_and_level_indication &~ 0xf0;			// xxxx1111
					ts_LOGf("%s  - profile_and_level_indication : 0x%02x, Profile: %d (%s), Level: %d (%s)\n", pad,
						vs.profile_and_level_indication,

						vs.profile,
						vs.profile == 1 ? "High"               :
						vs.profile == 2 ? "Spatially Scalable" :
						vs.profile == 3 ? "SNR Scalable"       :
						vs.profile == 4 ? "Main"               :
						vs.profile == 5 ? "Simple"             : "Reserved",

						vs.level,
						vs.level == 4  ? "High"      :
						vs.level == 6  ? "High 1440" :
						vs.level == 8  ? "Main"      :
						vs.level == 10 ? "Low"       : "Reserved"
					);
					ts_LOGf("%s  - chroma_format                : %d (%s)\n", pad, vs.chroma_format,
						vs.chroma_format == 0 ? "reserved" :
						vs.chroma_format == 1 ? "4:2:0" :
						vs.chroma_format == 2 ? "4:2:2" :
						vs.chroma_format == 3 ? "4:4:4" : "unknown"
					);
					ts_LOGf("%s  - frame_rate_extension_flag    : %d\n", pad, vs.frame_rate_extension_flag);
					ts_LOGf("%s  - reserved                     : 0x%x\n", pad, vs.reserved);
				}
				break;
			}
			case  3: { // Audio stream descriptor
				char *dump = ts_hex_dump(data, this_length, 0);
				ts_LOGf("%sTag 0x%02x (%02d), sz: %d, Audio stream descriptor: %s\n", pad, tag, tag, this_length, dump);
				free(dump);
				struct {
					uint8_t free_format_flag : 1,
					        ID               : 1,
					        layer            : 2,
					        vbr_flag         : 1,
					        reserved         : 3;
				} as;
				if (this_length >= 1) {
					as.free_format_flag = bit_on(data[0], bit_8);
					as.ID               = bit_on(data[0], bit_7);
					as.layer            = (data[0] &~ 0xcf) >> 4;	// 11xx1111
					as.vbr_flag         = bit_on(data[0], bit_4);
					as.reserved         = data[0] &~ 0xf0;			// 1111xxxx
					ts_LOGf("%s  - free_format_flag : %d\n", pad, as.free_format_flag);
					ts_LOGf("%s  - ID               : %d (%s)\n", pad, as.ID, as.ID ? "MPEG Audio" : "Other");
					ts_LOGf("%s  - layer            : %d (%s)\n", pad, as.layer,
						as.layer == 0 ? "reserved" :
						as.layer == 1 ? "Layer III" :
						as.layer == 2 ? "Layer II" :
						as.layer == 3 ? "Layer I" : "reserved"
					);
					ts_LOGf("%s  - vbr_audio_flag   : %d\n", pad, as.vbr_flag);
					ts_LOGf("%s  - reserved         : 0x%x\n", pad, as.reserved);
				}
				break;
			}
示例#8
0
文件: leff.c 项目: Dmilo/freewpc
/**
 * Free a single lamp from a quick leff.
 */
void leff_quick_free (lampnum_t lamp)
{
	bit_on (leff_free_set, lamp);
}
示例#9
0
void radio_on_receive(Radio * radio)
{
	if(radio->transmitting || !radio->callback_receive)
		return;

	radio_time time = radio->microseconds();
	radio_time duration = time - radio->last_time;
	radio->last_time = time;

	if(time < radio->last_time) {
		reset_receiver(radio);
		return;
	}

	if(duration < 300) {
		reset_receiver(radio);
		return;
	}

	if(!radio->receiving) {
		radio->receiving = 1;
		radio->delay = duration /* sync */ / 31;
		radio->delay_tolerance = radio->delay * radio->tolerance * 0.01;
		radio->bit_count = 0;
		radio->received_bytes_count = 0;
	}

	if(between(duration, radio->delay, 3 * radio->delay, radio->delay_tolerance)) {
		if(byte_odd(radio->change_count)) {
			if(radio->received_bytes_count >= radio->buffer_size) {
				// Overflow
				// Realloc on simple uc would result in memory fragmentation
				// and freeze
				radio->received_bytes_count = 0;
				reset_receiver(radio);
				return;
			}

			if(received_one(radio, duration))
				bit_on(&radio->received_message[radio->received_bytes_count],
				       7 - radio->bit_count++);
			else if(received_zero(radio, duration))
				bit_off(&radio->received_message[radio->received_bytes_count],
				        7 - radio->bit_count++);
			else {
				reset_receiver(radio);
				return;
			}

			if(radio->bit_count == 8) {
				radio->bit_count = 0;
				radio->received_bytes_count++;
			}
		}
	} else if(radio->change_count > 1) {
		reset_receiver(radio);
		return;
	}

	radio->change_count++;
}
示例#10
0
文件: lamp.c 项目: Dmilo/freewpc
/*
 * Lamp manipulation routines
 *
 * These control the main lamp matrix and also the flash
 * matrix.  They can be modified at any time without the
 * need for allocation.
 *
 */
void lamp_on (lampnum_t lamp)
{
	bit_on (lamp_matrix, lamp);
}