Example #1
0
void main(){
	unsigned long buf,sp;
	unsigned char data,x,y,ch;
#ifdef PARITYCHECK
	unsigned char parity;
	int tmp;
#endif
//	char str[7];
	prescaler_init();
	init_mc();
	spi_init();
	lcd_init();
	ch=x=y=0;
	lcd_goto(0);
	lcd_puts("initializing...");
	init_lut();
	lcd_clrscr();
	lcd_goto(0);
	while(1){
state1:
		if(SPSR&(1<<SPIF)){
			buf=SPDR;
			if(!(buf&1)){
				buf=buf>>1;	//throw out start bit.
				goto state2;
			}
		}
Example #2
0
static void *linuxraw_input_init(void)
{
   // only work on terminals
   if (!isatty(0))
      return NULL;

   linuxraw_input_t *linuxraw = (linuxraw_input_t*)calloc(1, sizeof(*linuxraw));
   if (!linuxraw)
      return NULL;

   if (oldKbmd == 0xffff)
   {
      tcgetattr(0, &oldTerm);
      newTerm = oldTerm;
      newTerm.c_lflag &= ~(ECHO | ICANON | ISIG);
      newTerm.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
      newTerm.c_cc[VMIN] = 0;
      newTerm.c_cc[VTIME] = 0;

      if (ioctl(0, KDGKBMODE, &oldKbmd) != 0)
         return NULL;
   }

   tcsetattr(0, TCSAFLUSH, &newTerm);

   if (ioctl(0, KDSKBMODE, K_MEDIUMRAW) != 0)
   {
      linuxraw_resetKbmd();
      return NULL;
   }

   struct sigaction sa;
   sa.sa_handler = linuxraw_exitGracefully;
   sa.sa_flags = SA_RESTART | SA_RESETHAND;
   sigemptyset(&sa.sa_mask);
   // trap some standard termination codes so we can restore the keyboard before we lose control
   sigaction(SIGABRT, &sa, NULL);
   sigaction(SIGBUS, &sa, NULL);
   sigaction(SIGFPE, &sa, NULL);
   sigaction(SIGILL, &sa, NULL);
   sigaction(SIGQUIT, &sa, NULL);
   sigaction(SIGSEGV, &sa, NULL);

   atexit(linuxraw_resetKbmd);

   linuxraw->sdl = (sdl_input_t*)input_sdl.init();
   if (!linuxraw->sdl)
   {
      linuxraw_resetKbmd();
      free(linuxraw);
      return NULL;
   }

   init_lut();

   linuxraw->sdl->use_keyboard = false;
   return linuxraw;
}
Example #3
0
static void *linuxraw_input_init(void)
{
   // only work on terminals
   if (!isatty(0))
      return NULL;

   if (driver.stdin_claimed)
   {
      RARCH_WARN("stdin is already used for ROM loading. Cannot use stdin for input.\n");
      return NULL;
   }

   linuxraw_input_t *linuxraw = (linuxraw_input_t*)calloc(1, sizeof(*linuxraw));
   if (!linuxraw)
      return NULL;

   if (oldKbmd == 0xffff)
   {
      tcgetattr(0, &oldTerm);
      newTerm = oldTerm;
      newTerm.c_lflag &= ~(ECHO | ICANON | ISIG);
      newTerm.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
      newTerm.c_cc[VMIN] = 0;
      newTerm.c_cc[VTIME] = 0;

      if (ioctl(0, KDGKBMODE, &oldKbmd) != 0)
         return NULL;
   }

   tcsetattr(0, TCSAFLUSH, &newTerm);

   if (ioctl(0, KDSKBMODE, K_MEDIUMRAW) != 0)
   {
      linuxraw_resetKbmd();
      return NULL;
   }

   struct sigaction sa;
   sa.sa_handler = linuxraw_exitGracefully;
   sa.sa_flags = SA_RESTART | SA_RESETHAND;
   sigemptyset(&sa.sa_mask);
   // trap some standard termination codes so we can restore the keyboard before we lose control
   sigaction(SIGABRT, &sa, NULL);
   sigaction(SIGBUS, &sa, NULL);
   sigaction(SIGFPE, &sa, NULL);
   sigaction(SIGILL, &sa, NULL);
   sigaction(SIGQUIT, &sa, NULL);
   sigaction(SIGSEGV, &sa, NULL);

   atexit(linuxraw_resetKbmd);

   linuxraw->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
   init_lut();

   driver.stdin_claimed = true; // We need to disable use of stdin command interface if stdin is supposed to be used for input.
   return linuxraw;
}
Example #4
0
static bool gfx_ctx_init(void)
{
   if (g_inited)
      return false;

   static const int visual_attribs[] = {
      GLX_X_RENDERABLE     , True,
      GLX_DRAWABLE_TYPE    , GLX_WINDOW_BIT,
      GLX_RENDER_TYPE      , GLX_RGBA_BIT,
      GLX_DOUBLEBUFFER     , True,
      GLX_RED_SIZE         , 8,
      GLX_GREEN_SIZE       , 8,
      GLX_BLUE_SIZE        , 8,
      GLX_ALPHA_SIZE       , 8,
      GLX_DEPTH_SIZE       , 0,
      GLX_STENCIL_SIZE     , 0,
      None
   };

   GLXFBConfig *fbcs = NULL;

   g_quit = 0;

   init_lut();

   g_dpy = XOpenDisplay(NULL);
   if (!g_dpy)
      goto error;

   // GLX 1.3+ required.
   int major, minor;
   glXQueryVersion(g_dpy, &major, &minor);
   if (major < 1 || (major == 1 && minor < 3))
      goto error;

   int nelements;
   fbcs = glXChooseFBConfig(g_dpy, DefaultScreen(g_dpy),
         visual_attribs, &nelements);

   if (!fbcs)
      goto error;

   if (!nelements)
   {
      XFree(fbcs);
      goto error;
   }

   g_fbc = fbcs[0];
   XFree(fbcs);

   return true;

error:
   gfx_ctx_destroy();
   return false;
}
Example #5
0
static void *sdl_input_init(void)
{
   init_lut();
   sdl_input_t *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
   if (!sdl)
      return NULL;

   sdl->joypad = input_joypad_init_first();
   return sdl;
}
Example #6
0
static void *sdl_input_init(void)
{
   init_lut();
   sdl_input_t *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
   if (!sdl)
      return NULL;

#ifdef HAVE_DINPUT
   sdl->di = sdl_dinput_init();
   if (!sdl->di)
   {
      free(sdl);
      RARCH_ERR("Failed to init SDL/DInput.\n");
      return NULL;
   }
#else
   if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
      return NULL;

   SDL_JoystickEventState(SDL_IGNORE);
   sdl->num_joysticks = SDL_NumJoysticks();

   for (unsigned i = 0; i < MAX_PLAYERS; i++)
   {
      if (g_settings.input.joypad_map[i] < 0)
         continue;

      unsigned port = g_settings.input.joypad_map[i];

      if (sdl->num_joysticks <= port)
         continue;

      sdl->joysticks[i] = SDL_JoystickOpen(port);
      if (!sdl->joysticks[i])
      {
         RARCH_ERR("Couldn't open SDL joystick #%u on SNES port %u\n", port, i + 1);
         free(sdl);
         SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
         return NULL;
      }

      RARCH_LOG("Opened Joystick: %s (#%u) on port %u\n", 
            SDL_JoystickName(port), port, i + 1);

      sdl->num_axes[i] = SDL_JoystickNumAxes(sdl->joysticks[i]);
      sdl->num_buttons[i] = SDL_JoystickNumButtons(sdl->joysticks[i]);
      sdl->num_hats[i] = SDL_JoystickNumHats(sdl->joysticks[i]);
      RARCH_LOG("Joypad has: %u axes, %u buttons, %u hats.\n",
            sdl->num_axes[i], sdl->num_buttons[i], sdl->num_hats[i]);
   }
#endif

   sdl->use_keyboard = true;
   return sdl;
}
Example #7
0
int main(int argc, char *argv[])
{
	struct kingrid_info data;
	freenect_context *kn;
	freenect_device *kn_dev;
	int rows = 40, cols = 96; // terminal size
	int opt;

	sigdata = &data;
	data.out_of_range = 0;
	data.done = 0;
	data.divisions = 6;
	data.boxwidth = 10;
	data.histrows = 8;
	data.frame = 0;
	data.zmin = 0.5;
	data.zmax = 5.0;
	data.disp_mode = STATS;

	if(getenv("LINES")) {
		rows = atoi(getenv("LINES"));
	}
	if(getenv("COLUMNS")) {
		cols = atoi(getenv("COLUMNS"));
	}

	// Handle command-line options
	while((opt = getopt(argc, argv, "shag:z:Z:")) != -1) {
		switch(opt) {
			case 's':
				// Stats mode
				data.disp_mode = STATS;
				break;
			case 'h':
				// Histogram mode
				data.disp_mode = HISTOGRAM;
				break;
			case 'a':
				// ASCII art mode
				data.disp_mode = ASCII;
				break;
			case 'g':
				// Grid divisions
				data.divisions = atoi(optarg);
				break;
			case 'z':
				// Near clipping
				data.zmin = atof(optarg);
				break;
			case 'Z':
				// Far clipping
				data.zmax = atof(optarg);
				break;
			default:
				fprintf(stderr, "Usage: %s -[sha] [-g divisions] [-zZ distance]\n", argv[0]);
				fprintf(stderr, "Use up to one of:\n");
				fprintf(stderr, "\ts - Stats mode (default)\n");
				fprintf(stderr, "\th - Histogram mode\n");
				fprintf(stderr, "\ta - ASCII art mode\n");
				fprintf(stderr, "Use any of:\n");
				fprintf(stderr, "\tg - Set grid divisions for both dimensions\n");
				fprintf(stderr, "\tz - Set near clipping plane in meters for ASCII art mode (default 0.5)\n");
				fprintf(stderr, "\tZ - Set far clipping plane in meters for ASCII art mode (default 5.0)\n");
				return -1;
		}
	}

	data.boxwidth = (cols - 1) / data.divisions - 3;
	if(data.boxwidth < 10) {
		data.boxwidth = 10;
	}
	data.histrows = (rows - 2) / data.divisions - 1;
	
	init_lut(data.depth_lut);

	if(signal(SIGINT, intr) == SIG_ERR ||
			signal(SIGTERM, intr) == SIG_ERR) {
		ERROR_OUT("Error setting signal handlers\n");
		return -1;
	}

	if(freenect_init(&kn, NULL) < 0) {
		ERROR_OUT("libfreenect init failed.\n");
		return -1;
	}

	INFO_OUT("Found %d Kinect devices.\n", freenect_num_devices(kn));

	if(freenect_num_devices(kn) == 0) {
		ERROR_OUT("No Kinect devices present.\n");
		return -1;
	}

	if(freenect_open_device(kn, &kn_dev, 0)) {
		ERROR_OUT("Error opening Kinect #0.\n");
		return -1;
	}

	freenect_set_user(kn_dev, &data);
	freenect_set_tilt_degs(kn_dev, -5);
	freenect_set_led(kn_dev, LED_GREEN);
	freenect_set_depth_callback(kn_dev, depth);
	freenect_set_depth_format(kn_dev, FREENECT_DEPTH_11BIT);

	freenect_start_depth(kn_dev);

	int last_oor = data.out_of_range;
	while(!data.done && freenect_process_events(kn) >= 0) {
		if(last_oor != data.out_of_range) {
			freenect_set_led(kn_dev, data.out_of_range ? LED_BLINK_RED_YELLOW : LED_GREEN);
			last_oor = data.out_of_range;
		}
	}

	freenect_stop_depth(kn_dev);
	freenect_set_led(kn_dev, LED_OFF);
	freenect_close_device(kn_dev);
	freenect_shutdown(kn);

	return 0;
}
Example #8
0
void
life_cycle(field_struct *p_field_data)
{
  int x, y;
  int maxx = (*p_field_data).maxx;
  int maxy = (*p_field_data).maxy;

  int lut_lines = 0;
  int lut_cols = 0;
  int line = 0;
  int col = 0;

  lut_lines = (*p_field_data).maxy / YBLOCKD + 1;
  lut_cols = (*p_field_data).maxx / XBLOCKD + 1;

  /*robaccia per evitare il bordo sup-sin XD*/
 
  for(line = 0; line < 1; line++) {
    for(col = 0; col < 1; col++) {
     if((*p_field_data).field_lut[0][0] > 0) {
	
	for(y = 1; y < YBLOCKD; ++y) {
	  for(x = 1; x < XBLOCKD; ++x) {
	    if((*p_field_data).current_field[y][x] % 10 != 0) {
	      
	      (*p_field_data).current_field[y - 1][x - 1] += 10;
	      
	      (*p_field_data).current_field[y][x - 1] += 10;
	      
	      (*p_field_data).current_field[y + 1][x - 1] += 10;
	      
	      (*p_field_data).current_field[y + 1][x] += 10;
	      
	      (*p_field_data).current_field[y + 1][x + 1] += 10;
	      
	      (*p_field_data).current_field[y][x + 1] += 10;
	      
	      (*p_field_data).current_field[y - 1][x + 1] += 10;
	      
	      (*p_field_data).current_field[y - 1][x] += 10;
	    }
	  }
	}
      }
    }
  }
  for(line = 0; line < 1; line++) {
    for(col = 1; col < lut_cols; col++) {
     if((*p_field_data).field_lut[line][col] > 0) {
	
	for(y = 1; y < YBLOCKD; ++y) {
	  for(x = col * XBLOCKD; x < col * XBLOCKD + XBLOCKD && x < maxx - 1; ++x) {
	    if((*p_field_data).current_field[y][x] % 10 != 0) {
	      
	      (*p_field_data).current_field[y - 1][x - 1] += 10;
	      
	      (*p_field_data).current_field[y][x - 1] += 10;
	      
	      (*p_field_data).current_field[y + 1][x - 1] += 10;
	      
	      (*p_field_data).current_field[y + 1][x] += 10;
	      
	      (*p_field_data).current_field[y + 1][x + 1] += 10;
	      
	      (*p_field_data).current_field[y][x + 1] += 10;
	      
	      (*p_field_data).current_field[y - 1][x + 1] += 10;
	      
	      (*p_field_data).current_field[y - 1][x] += 10;
	    }
	  }
	}
      }
    }
  }
for(line = 1; line < lut_lines; line++) {
  col = 0;
  if((*p_field_data).field_lut[line][col] > 0) {
    
    for(y = line * YBLOCKD; y < line * YBLOCKD + YBLOCKD && y < maxy - 1; ++y) {
      for(x = 1; x < XBLOCKD; ++x) {
	if((*p_field_data).current_field[y][x] % 10 != 0) {
	  
	  (*p_field_data).current_field[y - 1][x - 1] += 10;
	  
	  (*p_field_data).current_field[y][x - 1] += 10;
	  
	  (*p_field_data).current_field[y + 1][x - 1] += 10;
	  
	  (*p_field_data).current_field[y + 1][x] += 10;
	  
	  (*p_field_data).current_field[y + 1][x + 1] += 10;
	  
	  (*p_field_data).current_field[y][x + 1] += 10;
	  
	  (*p_field_data).current_field[y - 1][x + 1] += 10;
	      
	  (*p_field_data).current_field[y - 1][x] += 10;
	}
      }
    }
  }
 }
 

  for(line = 1; line < lut_lines; line++) {
    for(col = 1; col < lut_cols; col++) {
      if((*p_field_data).field_lut[line][col] > 0) {
	
	for(y = line * YBLOCKD; y < maxy -1 && y < (line * YBLOCKD + YBLOCKD); ++y) {
	  for(x = col * XBLOCKD; x < maxx -1 && x < (col * XBLOCKD + XBLOCKD); ++x) {
	    if((*p_field_data).current_field[y][x] % 10 != 0) {
	      
	      (*p_field_data).current_field[y - 1][x - 1] += 10;
	      
	      (*p_field_data).current_field[y][x - 1] += 10;
	      
	      (*p_field_data).current_field[y + 1][x - 1] += 10;
	      
	      (*p_field_data).current_field[y + 1][x] += 10;
	      
	      (*p_field_data).current_field[y + 1][x + 1] += 10;
	      
	      (*p_field_data).current_field[y][x + 1] += 10;
	      
	      (*p_field_data).current_field[y - 1][x + 1] += 10;
	      
	      (*p_field_data).current_field[y - 1][x] += 10;
	    }
	  }
	}
      }
    }
  }

  init_lut(p_field_data);

  for(y = 0; y < maxy; ++y) {
    for(x = 0; x < maxx; ++x) {
      
      if((*p_field_data).current_field[y][x] == 21 || 
	 (*p_field_data).current_field[y][x] == 31 ||
	 (*p_field_data).current_field[y][x] == 30) {
	(*p_field_data).current_field[y][x] = 1;
	lut_up(x, y, p_field_data);
      } else {
	(*p_field_data).current_field[y][x] = 0;
      }
      
    }
  }
      
}
Example #9
0
// ./next_gen "# of permutations" stem0 stem1 stem2 ...
int main(int argc, unsigned char **argv) {
  char phrase[59] = "I would much rather hear more about your whittling project";
  unsigned int permutations = atou((char *)argv[1]);

  sseK00_19 = _mm_set1_epi32(0x5a827999);
  sseK20_39 = _mm_set1_epi32(0x6ed9eba1);
  sseK40_59 = _mm_set1_epi32(0x8f1bbcdc);
  sseK60_79 = _mm_set1_epi32(0xca62c1d6);

  best_stem  = malloc(sizeof(char) * 5);

  shortest_d = 180;

  // Get finished context for phrase
  SHA_CTX *phrase_ctx = malloc(sizeof(SHA_CTX));
  sha1_full(phrase_ctx, phrase);

  // Load prefixes
  unsigned char **prefixes = malloc(sizeof(char *) * PREFIX_COUNT);
  int p = 0;
  for(p = 0;p < PREFIX_COUNT;p++) 
    prefixes[p] = argv[2 + p];

  // Get chaining contexts for suffixes
  SHA_CTX *prefix_ctxs = malloc(sizeof(SHA_CTX) * PREFIX_COUNT);
  for(p = 0;p < PREFIX_COUNT;p++) 
    sha1_partial(&prefix_ctxs[p], prefixes[p]);

  struct vector_ctx *vc = malloc(sizeof(struct vector_ctx) * PREFIX_COUNT/4);
  struct vector_ctx *vc_ptr = vc;

  SHA_CTX *prefix_ptr = prefix_ctxs;
  for(p = 0;p < PREFIX_COUNT;p+=4) {
    vectorize_prefixes(vc_ptr, prefix_ptr);

    prefix_ptr += 4;
    vc_ptr += 1;
  }


  // Allocate memory for expanded message template
  uint32_t *w = malloc(sizeof(uint32_t) * 80);
  
  int w_i = 0;

  // We only hash suffixes that are 5 bytes long
  
  // w[0] prefix_stem
  // w[1] current final char + some other stuff and zeros
  // w[2]-w[14]
  // Expanded message blocks 2-14 are always 0x0000000...
  for(w_i = 2;w_i < 15;w_i++)
    w[w_i] = 0;

  // w[15] is the size of the message
  w[15] = 552;
  // w[16] - stem constant - W13 ^ W8 ^ W2 ^ W0  => W0 <<< 1
  // w[17] - changing lots
  // w[18] - constant
  w[18] = ROTATE(w[15], 1);
  // w[19] - stem constant
  // w[20] - changing lots 


  uint32_t *stem_w = malloc(sizeof(uint32_t) * 80);
  uint32_t *stem_x = malloc(sizeof(uint32_t) * 80);

  init_lut();

  struct vector_ctx *my_vc = malloc(sizeof(struct vector_ctx) * PREFIX_COUNT/2);
  int i = 0;
  char suffix_stem[5] = "!!!!";
  for(i = 0;i < permutations;i++) {
    memcpy(stem_w, w, 80 * sizeof(uint32_t));
    memcpy(my_vc, vc, sizeof(struct vector_ctx) * PREFIX_COUNT/2);

    int dist = shortest_distance(phrase_ctx, my_vc, suffix_stem, stem_w, stem_x);

    next_stem(suffix_stem);
  }

  free(vc);
  free(my_vc);
  free(w);
  free(stem_w);
  free(stem_x);

  // Print shortest_distance and the 5 char ending.
  printf("%d,%s,%d\n", shortest_d, best_stem, best_last+33);
}
Example #10
0
void log_to_linear_node_t::do_process( const image::const_image_view_t& src, const image::image_view_t& dst, const render::render_context_t& context)
{
    if( get_value<int>( param( "convert")))
    {
        switch( get_value<int>( param( "method")))
        {
        case cineon_conv:
        {
            IECore::LinearToCineonDataConversion<float,boost::uint16_t> conv( get_value<float>( param( "cin_gamma")),
                    get_value<float>( param( "cin_white")),
                    get_value<float>( param( "cin_black")));

            boost::scoped_array<boost::uint16_t> lut( new boost::uint16_t[1<<16]);
            init_lut( lut.get(), conv);

            //cineon_linear_to_log_fun f( conv);
            cineon_linear_to_log_lut_fun f( lut.get());
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;

        case redlog_conv:
        {
            IECore::LinearToCineonDataConversion<float,boost::uint16_t> conv( 1.02f, 1023, 0);

            boost::scoped_array<boost::uint16_t> lut( new boost::uint16_t[1<<16]);
            init_lut( lut.get(), conv);

            //cineon_linear_to_log_fun f( conv);
            cineon_linear_to_log_lut_fun f( lut.get());
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;

        case exrdpx_conv:
        {
            exrdpx_linear_to_log_fun f;
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;
        }
    }
    else
    {
        switch( get_value<int>( param( "method")))
        {
        case cineon_conv:
        {
            IECore::CineonToLinearDataConversion<boost::uint16_t, float> conv( get_value<float>( param( "cin_gamma")),
                    get_value<float>( param( "cin_white")),
                    get_value<float>( param( "cin_black")));
            cineon_log_to_linear_fun f( conv);
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;

        case redlog_conv:
        {
            IECore::CineonToLinearDataConversion<boost::uint16_t, float> conv( 1.02f, 1023, 0);
            cineon_log_to_linear_fun f( conv);
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;

        case exrdpx_conv:
        {
            exrdpx_log_to_linear_fun f;
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;
        }
    }
}