Ejemplo n.º 1
0
int
main(int argc, char **argv) {
    if(argc != 2)
        errx(EXIT_FAILURE, "no input files");

    pthread_mutex_init(&mutex_update_image, NULL);

    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_t inotify_thread;
    if(pthread_create(&inotify_thread, &attr, monitor_file, argv[1]))
        err(EXIT_FAILURE, "pthread_create");

    font_init();
    screen_init();
    update_image(argv[1]);

    for(;;) {
        handle_events();
        draw();
    }

    SDL_Quit();

    return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
bool init_button(button_t *btn, widget_t *parent,
    const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
{
	widget_init(&btn->widget, parent);

	btn->widget.destroy = button_destroy;
	btn->widget.reconfigure = button_reconfigure;
	btn->widget.rearrange = button_rearrange;
	btn->widget.repaint = button_repaint;
	btn->widget.handle_keyboard_event = button_handle_keyboard_event;
	btn->widget.handle_position_event = button_handle_position_event;

	source_init(&btn->background);
	source_set_color(&btn->background, background);
	source_init(&btn->foreground);
	source_set_color(&btn->foreground, foreground);

	if (caption == NULL) {
		btn->caption = NULL;
	} else {
		btn->caption = str_dup(caption);
	}
	font_init(&btn->font, FONT_DECODER_EMBEDDED, NULL, points);

	sysarg_t cpt_width;
	sysarg_t cpt_height;
	font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height);
	btn->widget.width_min = cpt_width + 8;
	btn->widget.height_min = cpt_height + 8;
	btn->widget.width_ideal = cpt_width + 28;
	btn->widget.height_ideal = cpt_height + 8;

	return true;
}
Ejemplo n.º 3
0
Archivo: ui.c Proyecto: jjgod/legend
int ui_init()
{
    int width, height;

    font_init();

    width = config_get_int("width");
    height = config_get_int("height");

    SDL_putenv("SDL_VIDEO_WINDOW_POS=center");

    if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        return -1;
    }

    atexit(SDL_Quit);

    screen = SDL_SetVideoMode(width, height, 32,
                              SDL_HWSURFACE | SDL_DOUBLEBUF);
    if (screen == NULL)
    {
        fprintf(stderr, "Unable to set %dx%d video: %s\n",
                width, height, SDL_GetError());
        return -1;
    }

    scripting_init_ui();
    SDL_Flip(screen);

    return 0;
}
Ejemplo n.º 4
0
void
grub_font_loader_init (void)
{
  /* Only initialize font loader once.  */
  if (font_loader_initialized)
    return;

  /* Make glyph for unknown glyph.  */
  unknown_glyph = grub_malloc (sizeof (struct grub_font_glyph)
			       + sizeof (unknown_glyph_bitmap));
  if (!unknown_glyph)
    return;

  unknown_glyph->width = 8;
  unknown_glyph->height = 16;
  unknown_glyph->offset_x = 0;
  unknown_glyph->offset_y = -3;
  unknown_glyph->device_width = 8;
  grub_memcpy (unknown_glyph->bitmap,
	       unknown_glyph_bitmap, sizeof (unknown_glyph_bitmap));

  /* Initialize the null font.  */
  font_init (&null_font);
  /* FIXME: Fix this slightly improper cast.  */
  null_font.name = (char *) "<No Font>";
  null_font.ascent = unknown_glyph->height - 3;
  null_font.descent = 3;
  null_font.max_char_width = unknown_glyph->width;
  null_font.max_char_height = unknown_glyph->height;

  font_loader_initialized = 1;
}
Ejemplo n.º 5
0
int start() {
	unsigned short character = 0x00;
	int ipc_status;
	message msg;
	int irq_set_kb = kb_subscribe_int();
	int irq_set_timer = timer_subscribe_int();
	int irq_set_mouse = mouse_subscribe_int();
	int r;
	unsigned char packet[3];
	unsigned short counter = 0;

	space_invaders_font = font_init("spaceinvader_font_transparent.bmp");
	srand(1);
	options_load();
	mouse_init();
	init_state();
	highscore_load();
	vg_init(VBE_VIDEO_MODE);

	while (1) { //TODO change condition
		/* Get a request message. */
		if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
			printf("driver_receive failed with: %d", r);
			continue;
		}
		if (is_ipc_notify(ipc_status)) { /* received notification */
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE: /* hardware interrupt notification */
				if (msg.NOTIFY_ARG & irq_set_kb) { /* keyboard interrupt */
					character = kb_int_handler();
					if (character != KB_2BYTE_SCODE)
						kb_event_handler(character);
				}
				if (msg.NOTIFY_ARG & irq_set_mouse){ /* mouse interrupt */
					mouse_int_handler(counter, packet);
					if(packet[0] != MOUSE_ACK && (packet[0] & BIT(3)))
						counter++;
					if(counter == 3){
						counter = 0;
						mouse_event_handler(packet);
					}

				}
				if (msg.NOTIFY_ARG & irq_set_timer){ /* timer interrupt */
					timer_int_handler();
				}
				break;
			default:
				break; /* no other notifications expected: do nothing */
			}
		}
		else { /* received a standard message, not a notification */
			/* no standard messages expected: do nothing */
		}
	}

	return 0;
}
Ejemplo n.º 6
0
bool font_reload()
{
	if (!initilized) return 0;
	
	whitefont.free();
	greenfont.free();
	bluefont.free();
	shadowfont.free();
	
	return font_init();
}
Ejemplo n.º 7
0
static void video_mode_cancel(UNUSED void*ign)
{
	if (video_revert_driver) {
		video_setup(video_revert_driver);
		video_startup();
	}
	video_fullscreen(video_revert_fs);
	palette_apply();
	font_init();
	config_set_page();
	status.flags |= NEED_UPDATE;
}
Ejemplo n.º 8
0
int main(void)
{
	u8 key,fontok=0; 
   	Stm32_Clock_Init(9);	//系统时钟设置
	delay_init(72);			//延时初始化
	uart_init(72,115200); 	//串口1初始化 
	LCD_Init();				//初始化液晶 
	LED_Init();         	//LED初始化	 
	KEY_Init();				//按键初始化	 
	usmart_dev.init(72);	//usmart初始化	
 	USART2_Init(36,115200);	//初始化串口2 
	TP_Init();				//初始化触摸屏
	mem_init(SRAMIN);		//初始化内部内存池	    
 	exfuns_init();			//为fatfs相关变量申请内存  
  	f_mount(0,fs[0]); 		//挂载SD卡 
	key=KEY_Scan(0);  
	if(key==KEY_RIGHT)		//强制校准
	{
		LCD_Clear(WHITE);	//清屏
		TP_Adjust();  		//屏幕校准 
		TP_Save_Adjdata();	  
		LCD_Clear(WHITE);	//清屏
	}
	fontok=font_init();		//检查字库是否OK
	if(fontok||key==KEY_DOWN)//需要更新字库				 
	{
		LCD_Clear(WHITE);		   	//清屏
 		POINT_COLOR=RED;			//设置字体为红色	   	   	  
		LCD_ShowString(60,50,200,16,16,"ALIENTEK STM32");
		while(SD_Initialize())		//检测SD卡
		{
			LCD_ShowString(60,70,200,16,16,"SD Card Failed!");
			delay_ms(200);
			LCD_Fill(60,70,200+60,70+16,WHITE);
			delay_ms(200);		    
		}								 						    
		LCD_ShowString(60,70,200,16,16,"SD Card OK");
		LCD_ShowString(60,90,200,16,16,"Font Updating...");
		key=update_font(20,110,16,0);//从SD卡更新
		while(key)//更新失败		
		{			 		  
			LCD_ShowString(60,110,200,16,16,"Font Update Failed!");
			delay_ms(200);
			LCD_Fill(20,110,200+20,110+16,WHITE);
			delay_ms(200);		       
		} 		  
		LCD_ShowString(60,110,200,16,16,"Font Update Success!");
		delay_ms(1500);	
		LCD_Clear(WHITE);//清屏	       
	}  
	sim900a_test();
}
Ejemplo n.º 9
0
void Sys_Init(void)
{
	u8 key,fontok=0;  
	Stm32_Clock_Init(9);	//系统时钟设置
	delay_init(72);			//延时初始化
	uart_init(72,115200); 	//串口1初始化 
	LCD_Init();				//初始化液晶 
	LED_Init();         	//LED初始化	 
	KEY_Init();				//按键初始化	 	
 	USART2_Init(36,115200);	//初始化串口2 
	mem_init();		        //初始化内部内存池	    
 	exfuns_init();			//为fatfs相关变量申请内存  
    f_mount(fs[0],"0:",1); 	//挂载SD卡  
	key = KEY_Scan(0);  
	fontok = font_init();		//检查字库是否OK
	if(fontok||key == KEY1_PRES)//需要更新字库 (KEY1按下或字库丢失)				 
	{
		LCD_Clear(WHITE);		   	//清屏
 		POINT_COLOR=RED;			//设置字体为红色	   	   	  
		LCD_ShowString(70,50,200,16,16,"GSM  TEST");
		while(SD_Initialize())		//检测SD卡
		{
			LCD_ShowString(60,70,200,16,16,"SD Card Failed!");
			delay_ms(200);
			LCD_Fill(60,70,200+60,70+16,WHITE);
			delay_ms(200);		    
		}								 						    
		LCD_ShowString(60,70,200,16,16,"SD Card OK");
		LCD_ShowString(60,90,200,16,16,"Font Updating...");
		key = update_font(20,110,16);    //更新字库
		while(key)  //更新失败		
		{			 		  
			LCD_ShowString(60,110,200,16,16,"Font Update Failed!");
			delay_ms(200);
			LCD_Fill(20,110,200+20,110+16,WHITE);
			delay_ms(200);		       
		} 		  
		LCD_ShowString(60,110,200,16,16,"Font Update Success!");
		delay_ms(1500);	
		LCD_Clear(WHITE);//清屏	       
	} 
}
Ejemplo n.º 10
0
Archivo: fonts.c Proyecto: UraKn0x/gbdk
void main(void)
{
    font_t ibm_font, italic_font, min_font;
    int i;

    /* First, init the font system */
    font_init();

    /* Load all the fonts that we can */
    ibm_font = font_load(font_ibm);  /* 96 tiles */
    italic_font = font_load(font_italic);   /* 93 tiles */
    
    /* Load this one with dk grey background and white foreground */
    color(WHITE, DKGREY, SOLID);
    
    min_font = font_load(font_min);

    /* Turn scrolling off (why not?) */
    mode(get_mode() | M_NO_SCROLL);

    /* Print some text! */
    
    /* IBM font */
    font_set(ibm_font);
    printf("Font demo.\n\n");

    printf("IBM Font #!?123\n");

    /* In italic */
    font_set(italic_font);
    for (i=1; i!=5; i++) {
	printf("In italics, line %u\n", i);
    }

    /* With a minimal, colour changed font */
    font_set(min_font);
    printf("Minimal 36 tile font\n");

    /* Done */
    font_set(ibm_font);
    printf("\nDone!");
}
Ejemplo n.º 11
0
int
main(int argc, char *argv[]) {
    XEvent event;
    uint32_t timestamp = 0;
    init_x();
    font_init();

    ejoy2d_win_init(argc, argv);

    for (;;) {
        
        while(XPending(g_X.display) > 0) {  
            XNextEvent(g_X.display, &event);
            if (XFilterEvent(&event,None))
                continue;
            switch (event.type) {
            case Expose:
                if (event.xexpose.count==0)
                    update_frame();
                break;
            case ButtonPress:
                ejoy2d_win_touch(event.xbutton.x, event.xbutton.y, TOUCH_BEGIN);
                break;
            case ButtonRelease:
                ejoy2d_win_touch(event.xbutton.x,event.xbutton.y,TOUCH_END);
                break;
            case MotionNotify:
                ejoy2d_win_touch(event.xbutton.x,event.xbutton.y,TOUCH_MOVE);
                break;
            }
        }

        uint32_t old = timestamp;
        timestamp= _gettime();
        if (timestamp - old >= UPDATE_INTERVAL) {
            ejoy2d_win_update();
            update_frame();
        }
        else
            usleep(1000);
    }
}
Ejemplo n.º 12
0
/*------------------------------------------------------------
 * Function Name  : All_Init
 * Description    : 全局初始化
 * Input          : None
 * Output         : None
 * Return         : None
 *------------------------------------------------------------*/
void All_Init( void )
{			
	NVIC_Configuration();		/* 配置优先级分组   		*/
	bsp_InitTimer();			/* 定时器初始化 			*/
	key_init();					/* 按键初始化 			*/
	print_init();				/* 打印机初始化 			*/
	uart1_init(38400);			/* 通讯串口初始化 		*/
	rtc_init();					/* 时钟初始化 			*/
	lcd_init();					/* LCD初始化				*/
	font_init();				/* 字体初始化 			*/
	SysTick_Init();				/* 滴答定时器初始化		*/
	bsp_InitSFlash();			/* 外置 FLASH 初始化  	*/
 	USB_Init();					/* USB初始化				*/			
 	Ethernet_Init();			/* LWIP初始化			*/
	
	#ifdef ENABLE_BEEP
		BEEP_START();
	#endif
	
	SetPage(SYS_INIT);
}
Ejemplo n.º 13
0
void system_init(void)
{
	init_tft(); // initialiser xps_tft
	init_interrupt_controller();
	system_enable_caches();
	microblaze_enable_interrupts();
	system_init_network();

	clear_screen(); // effacer la page vidéo avec du noir
	font_init(XPAR_FLASH_MEM0_BASEADDR, TFT_FB_ADDR);

	sound_init();
	htmlParserInit();

	connection_set_HTML_handler(DM_parseHTMLPage);
	connection_set_WAV_handler(wav_parse);
	//connection_set_BMP_handler(BMP_html_parser_handler);

	history_init();
	DM_init();
	command_line_init();
}
Ejemplo n.º 14
0
Archivo: main.c Proyecto: odrevet/GE
int main(int argc, char** argv)
{
  SDL_Surface *screen=NULL;
  srand(time(NULL));

  int flags = 0;

  sdl_init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
  sound_init();
  font_init();

  freopen ("res/logs/out.txt", "w", stdout);
  freopen ("res/logs/err.txt", "w", stderr);

  SDL_WM_SetCaption("RPG", NULL);

  // make sure SDL cleans up before exit
  atexit(SDL_Quit);
  SDL_ShowCursor(SDL_DISABLE);
  
  flags = SDL_DOUBLEBUF | SDL_HWSURFACE;
  // create a new window
  screen = sdl_set_video(SCREEN_WIDTH, SCREEN_HEIGHT, 16, flags);
  backbuffer = SDL_DisplayFormat(screen);

  game* p_game = NULL;

  switch(state_main_menu(screen, p_game)){
  case GAME_OVER:
    state_game_over(screen, p_game);
    break;
  default:
    break;
  }

  SDL_Quit();
  return EXIT_SUCCESS;
}
Ejemplo n.º 15
0
static void change_video_settings(void)
{
	const char *new_video_driver;
	int new_fs_flag;

	if (widgets_config[11].d.togglebutton.state) {
		new_video_driver = "sdl";
	} else if (widgets_config[12].d.togglebutton.state) {
		new_video_driver = "yuv";
	} else if (widgets_config[13].d.togglebutton.state) {
		new_video_driver = "gl";
	} else if (widgets_config[14].d.togglebutton.state) {
		new_video_driver = "directdraw";
	} else {
		new_video_driver = "sdl";
	}

	if (widgets_config[9].d.togglebutton.state) {
		new_fs_flag = 1;
	} else {
		new_fs_flag = 0;
	}

	if (!strcasecmp(new_video_driver, video_driver_name())
	&& new_fs_flag == video_is_fullscreen()) {
		return;
	}

	video_change_dialog();
	if (strcasecmp(new_video_driver, video_driver_name())) {
		video_setup(new_video_driver);
		video_startup();
	}
	if (new_fs_flag != video_is_fullscreen())
		video_fullscreen(new_fs_flag);
	palette_apply();
	font_init();
}
Ejemplo n.º 16
0
int main() {

    /* initialize the font */
    font_init();

    /* initialize timer */
    timer_init();

    /* allocate a window */
    win = window_alloc("Qonsole", /* title */
                       font_width*80, /* width */
                       font_height*25, /* height */
                       -1,             /* x (random) */
                       -1,             /* y (random) */
                       0xFF000000, /* bg color */
                       "/usr/share/icons/qonsole16.png" /* iconfile */);

    /* initialize window event handlers */
    win->press = pstty_press;

    /* initialize pstty */
    pstty_init();

    /* execute the shell */
    exec_shell("/bin/rash");

    /* set receiver */
    set_receiver(pstty_event);

    /* loop */
    gui_loop();

    /* done */
    return 0;

}
Ejemplo n.º 17
0
int main(int argc, char *argv[])
{
bool inhibit_loadfade = false;
bool error = false;
bool freshstart;
	
	SetLogFilename("debug.txt");
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
	{
		staterr("ack, sdl_init failed: %s.", SDL_GetError());
		return 1;
	}
	atexit(SDL_Quit);
	
	// start up inputs first thing because settings_load may remap them
	input_init();
	
	// load settings, or at least get the defaults,
	// so we know the initial screen resolution.
	settings_load();
	
	if (Graphics::init(settings->resolution)) { staterr("Failed to initialize graphics."); return 1; }
	if (font_init()) { staterr("Failed to load font."); return 1; }
	
	//speed_test();
	//return 1;
	
	#ifdef CONFIG_DATA_EXTRACTOR
	if (!settings->files_extracted)
	{
		if (extract_main())
		{
			Graphics::close();
			font_close();
			return 0;
		}
		else
		{
			settings->files_extracted = true;
			settings_save();
		}
	}
	#endif
	
	if (check_data_exists())
	{
		return 1;
	}
	
	Graphics::ShowLoadingScreen();
	if (sound_init()) { fatal("Failed to initialize sound."); return 1; }
	if (trig_init()) { fatal("Failed trig module init."); return 1; }
	
	if (tsc_init()) { fatal("Failed to initialize script engine."); return 1; }
	if (textbox.Init()) { fatal("Failed to initialize textboxes."); return 1; }
	if (Carets::init()) { fatal("Failed to initialize carets."); return 1; }
	
	if (game.init()) return 1;
	game.setmode(GM_NORMAL);
	// set null stage just to have something to do while we go to intro
	game.switchstage.mapno = 0;
	
	//#define REPLAY
	#ifdef REPLAY
		game.switchstage.mapno = START_REPLAY;
		//Replay::set_ffwd(6000);
		//Replay::set_stopat(3500);
		game.switchstage.param = 1;
	#else
		//game.switchstage.mapno = LOAD_GAME;
		//game.pause(GP_OPTIONS);
		
		if (settings->skip_intro && file_exists(GetProfileName(settings->last_save_slot)))
			game.switchstage.mapno = LOAD_GAME;
		else
			game.setmode(GM_INTRO);
	#endif
	
	// for debug
	if (game.paused) { game.switchstage.mapno = 0; game.switchstage.eventonentry = 0; }
	if (game.switchstage.mapno == LOAD_GAME) inhibit_loadfade = true;
	
	game.running = true;
	freshstart = true;
	
	stat("Entering main loop...");
	#ifdef __SDLSHIM__
		set_console_visible(false);
	#endif
	
	//speed_test();
	//return 1;
	
	while(game.running)
	{
		// SSS/SPS persists across stage transitions until explicitly
		// stopped, or you die & reload. It seems a bit risky to me,
		// but that's the spec.
		if (game.switchstage.mapno >= MAPNO_SPECIALS)
		{
			StopLoopSounds();
		}
		
		// enter next stage, whatever it may be
		if (game.switchstage.mapno == LOAD_GAME || \
			game.switchstage.mapno == LOAD_GAME_FROM_MENU)
		{
			if (game.switchstage.mapno == LOAD_GAME_FROM_MENU)
				freshstart = true;
			
			stat("= Loading game =");
			if (game_load(settings->last_save_slot))
			{
				fatal("savefile error");
				goto ingame_error;
			}
			
			Replay::OnGameStarting();
			
			if (!inhibit_loadfade) fade.Start(FADE_IN, FADE_CENTER);
			else inhibit_loadfade = false;
		}
		else if (game.switchstage.mapno == START_REPLAY)
		{
			stat(">> beginning replay '%s'", GetReplayName(game.switchstage.param));
			
			StopScripts();
			if (Replay::begin_playback(GetReplayName(game.switchstage.param)))
			{
				fatal("error starting playback");
				goto ingame_error;
			}
		}
		else
		{
			if (game.switchstage.mapno == NEW_GAME || \
				game.switchstage.mapno == NEW_GAME_FROM_MENU)
			{
				bool show_intro = (game.switchstage.mapno == NEW_GAME_FROM_MENU);
				InitNewGame(show_intro);
			}
			
			// slide weapon bar on first intro to Start Point
			if (game.switchstage.mapno == STAGE_START_POINT && \
				game.switchstage.eventonentry == 91)
			{
				freshstart = true;
			}
			
			// switch maps
			if (load_stage(game.switchstage.mapno)) goto ingame_error;
			
			player->x = (game.switchstage.playerx * TILE_W) << CSF;
			player->y = (game.switchstage.playery * TILE_H) << CSF;
		}
		
		// start the level
		if (game.initlevel()) return 1;
		
		if (freshstart)
			weapon_introslide();
		
		gameloop();
		game.stageboss.OnMapExit();
		freshstart = false;
	}
	
shutdown: ;
	Replay::close();
	game.close();
	Carets::close();
	
	Graphics::close();
	input_close();
	font_close();
	sound_close();
	tsc_close();
	textbox.Deinit();
	return error;
	
ingame_error: ;
	stat("");
	stat(" ************************************************");
	stat(" * An in-game error occurred. Game shutting down.");
	stat(" ************************************************");
	error = true;
	goto shutdown;
}
 int main(void)
 { 
	u8 res;
 	DIR picdir;	 		//图片目录
	FILINFO picfileinfo;//文件信息
	u8 *fn;   			//长文件名
	u8 *pname;			//带路径的文件名
	u16 totpicnum; 		//图片文件总数
	u16 curindex;		//图片当前索引
	u8 key;				//键值
	u8 pause=0;			//暂停标记
	u8 t;
	u16 temp;
	u16 *picindextbl;	//图片索引表 		  	    
	delay_init();	    	 //延时函数初始化
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2
	uart_init(9600);	 	//串口初始化为9600			 
	LCD_Init();			//初始化液晶 
	LED_Init();         //LED初始化	 
	KEY_Init();			//按键初始化	  													    
	usmart_dev.init(72);//usmart初始化	
 	mem_init();			//初始化内部内存池	
 	exfuns_init();		//为fatfs相关变量申请内存  
  	f_mount(fs[0],"0:",1);	//挂载SD卡 
 	f_mount(fs[1],"1:",1); 	//挂载FLASH.	  
	POINT_COLOR=RED;      
 	while(font_init()) 	//检查字库
	{	    
		LCD_ShowString(60,50,200,16,16,"Font Error!");
		delay_ms(200);				  
		LCD_Fill(60,50,240,66,WHITE);//清除显示	     
		delay_ms(200);				  
	}  	 
 	Show_Str(60,50,200,16,"Mini STM32开发板",16,0);				    	 
	Show_Str(60,70,200,16,"图片显示程序",16,0);				    	 
	Show_Str(60,90,200,16,"KEY0:NEXT KEY1:PREV",16,0);				    	 
	Show_Str(60,110,200,16,"WK_UP:PAUSE",16,0);				    	 
	Show_Str(60,130,200,16,"正点原子@ALIENTEK",16,0);				    	 
	Show_Str(60,150,200,16,"2014年3月14日",16,0);
 	while(f_opendir(&picdir,"0:/PICTURE"))//打开图片文件夹
 	{	    
		Show_Str(60,170,240,16,"PICTURE文件夹错误!",16,0);
		delay_ms(200);				  
		LCD_Fill(60,170,240,186,WHITE);//清除显示	     
		delay_ms(200);				  
	}  
	totpicnum=pic_get_tnum("0:/PICTURE"); //得到总有效文件数
  	while(totpicnum==NULL)//图片文件为0		
 	{	    
		Show_Str(60,170,240,16,"没有图片文件!",16,0);
		delay_ms(200);				  
		LCD_Fill(60,170,240,186,WHITE);//清除显示	     
		delay_ms(200);				  
	}
  	picfileinfo.lfsize=_MAX_LFN*2+1;						//长文件名最大长度
	picfileinfo.lfname=mymalloc(picfileinfo.lfsize);	//为长文件缓存区分配内存
 	pname=mymalloc(picfileinfo.lfsize);				//为带路径的文件名分配内存
 	picindextbl=mymalloc(2*totpicnum);				//申请2*totpicnum个字节的内存,用于存放图片索引
 	while(picfileinfo.lfname==NULL||pname==NULL||picindextbl==NULL)//内存分配出错
 	{	    
		Show_Str(60,170,240,16,"内存分配失败!",16,0);
		delay_ms(200);				  
		LCD_Fill(60,170,240,186,WHITE);//清除显示	     
		delay_ms(200);				  
	}  	
	//记录索引
    res=f_opendir(&picdir,"0:/PICTURE"); //打开目录
	if(res==FR_OK)
	{
		curindex=0;//当前索引为0
		while(1)//全部查询一遍
		{
			temp=picdir.index;								//记录当前index
	        res=f_readdir(&picdir,&picfileinfo);       		//读取目录下的一个文件
	        if(res!=FR_OK||picfileinfo.fname[0]==0)break;	//错误了/到末尾了,退出		  
     		fn=(u8*)(*picfileinfo.lfname?picfileinfo.lfname:picfileinfo.fname);			 
			res=f_typetell(fn);	
			if((res&0XF0)==0X50)//取高四位,看看是不是图片文件	
			{
				picindextbl[curindex]=temp;//记录索引
				curindex++;
			}	    
		} 
	}   
	Show_Str(60,170,240,16,"开始显示...",16,0); 
	delay_ms(1500);
	piclib_init();										//初始化画图	   	   
	curindex=0;											//从0开始显示
   	res=f_opendir(&picdir,(const TCHAR*)"0:/PICTURE"); 	//打开目录
	while(res==FR_OK)//打开成功
	{	
		dir_sdi(&picdir,picindextbl[curindex]);			//改变当前目录索引	   
        res=f_readdir(&picdir,&picfileinfo);       		//读取目录下的一个文件
        if(res!=FR_OK||picfileinfo.fname[0]==0)break;	//错误了/到末尾了,退出
     	fn=(u8*)(*picfileinfo.lfname?picfileinfo.lfname:picfileinfo.fname);			 
		strcpy((char*)pname,"0:/PICTURE/");				//复制路径(目录)
		strcat((char*)pname,(const char*)fn);  			//将文件名接在后面
 		LCD_Clear(BLACK);
 		ai_load_picfile(pname,0,0,lcddev.width,lcddev.height,1);//显示图片    
		Show_Str(2,2,240,16,pname,16,1); 				//显示图片名字
		t=0;
		while(1) 
		{
			key=KEY_Scan(0);		//扫描按键
			if(t>250)key=1;			//模拟一次按下KEY0    
			if((t%20)==0)LED0=!LED0;//LED0闪烁,提示程序正在运行.
			if(key==KEY1_PRES)		//上一张
			{
				if(curindex)curindex--;
				else curindex=totpicnum-1;
				break;
			}else if(key==KEY0_PRES)//下一张
			{
				curindex++;		   	
				if(curindex>=totpicnum)curindex=0;//到末尾的时候,自动从头开始
				break;
			}else if(key==WKUP_PRES)
			{
				pause=!pause;
				LED1=!pause; 	//暂停的时候LED1亮.  
			}
			if(pause==0)t++;
			delay_ms(10); 
		}					    
		res=0;  
	} 											  
	myfree(picfileinfo.lfname);	//释放内存			    
	myfree(pname);				//释放内存			    
	myfree(picindextbl);		//释放内存			    
}
 int main(void)
 { 
	u32 fontcnt;		  
	u8 i,j;
	u8 fontx[2];//gbk码
	u8 key,t;			 
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2 
	delay_init();	    	 //延时函数初始化	  
	uart_init(9600);	 	//串口初始化为9600			 
	LCD_Init();			//初始化液晶 
	LED_Init();         //LED初始化	 													    
	KEY_Init();				//按键初始化	  													    
	usmart_dev.init(72);	//usmart初始化	
 	mem_init();				//初始化内存池	    
 	exfuns_init();			//为fatfs相关变量申请内存  
  f_mount(fs[0],"0:",1); 	//挂载SD卡 
 	f_mount(fs[1],"1:",1); 	//挂载FLASH.
	while(font_init()) 	//检查字库
	{
UPD:    
		LCD_Clear(WHITE);		   	//清屏
 		POINT_COLOR=RED;			//设置字体为红色	   	   	  
		LCD_ShowString(60,50,200,16,16,"mini STM32");
		while(SD_Initialize())		//检测SD卡
		{
			LCD_ShowString(60,70,200,16,16,"SD Card Failed!");
			delay_ms(200);
			LCD_Fill(60,70,200+60,70+16,WHITE);
			delay_ms(200);		    
		}								 						    
		LCD_ShowString(60,70,200,16,16,"SD Card OK");
		LCD_ShowString(60,90,200,16,16,"Font Updating...");
	 	key=update_font(20,110,16);//更新字库
		while(key)//更新失败		
		{			 		  
			LCD_ShowString(60,110,200,16,16,"Font Update Failed!");
			delay_ms(200);
			LCD_Fill(20,110,200+20,110+16,WHITE);
			delay_ms(200);		       
		} 		  
		LCD_ShowString(60,110,200,16,16,"Font Update Success!");
		delay_ms(1500);	
		LCD_Clear(WHITE);//清屏	       
	}  
	POINT_COLOR=RED;       
	Show_Str(60,50,200,16,"Mini STM32开发板",16,0);				    	 
	Show_Str(60,70,200,16,"GBK字库测试程序",16,0);				    	 
	Show_Str(60,90,200,16,"正点原子@ALIENTEK",16,0);				    	 
	Show_Str(60,110,200,16,"2014年1月3日",16,0);
	Show_Str(60,130,200,16,"按KEY0,更新字库",16,0);
 	POINT_COLOR=BLUE;  
	Show_Str(60,150,200,16,"内码高字节:",16,0);				    	 
	Show_Str(60,170,200,16,"内码低字节:",16,0);				    	 
	Show_Str(60,190,200,16,"汉字计数器:",16,0);

	Show_Str(60,220,200,24,"对应汉字为:",24,0); 
	Show_Str(60,244,200,16,"对应汉字(16*16)为:",16,0);			 
	Show_Str(60,260,200,12,"对应汉字(12*12)为:",12,0);			 
	while(1)
	{
		fontcnt=0;
		for(i=0x81;i<0xff;i++)
		{		
			fontx[0]=i;
			LCD_ShowNum(148,150,i,3,16);		//显示内码高字节    
			for(j=0x40;j<0xfe;j++)
			{
				if(j==0x7f)continue;
				fontcnt++;
				LCD_ShowNum(148,170,j,3,16);	//显示内码低字节	 
				LCD_ShowNum(148,190,fontcnt,5,16);//汉字计数显示	 
			 	fontx[1]=j;
				Show_Font(60+132,220,fontx,24,0);	  
				Show_Font(60+144,244,fontx,16,0);	  		 		 
				Show_Font(60+108,260,fontx,12,0);	  		 		 
				t=200;
				while(t--)//延时,同时扫描按键
				{
					delay_ms(1);
					key=KEY_Scan(0);
					if(key==KEY0_PRES)goto UPD;
				}
				LED0=!LED0;
			}   
		}	
	} 
}
Ejemplo n.º 20
0
static void conf_change_font_cp() {
    font_init();
    font_set(conf.font_cp);
}
void main(void)
{
    unsigned char* loadbuffer;
    int buffer_size;
    int rc;
    int(*kernel_entry)(void);

    /* Make sure interrupts are disabled */
    set_irq_level(IRQ_DISABLED);
    set_fiq_status(FIQ_DISABLED);
    system_init();
    kernel_init();
    
    /* Now enable interrupts */
    set_irq_level(IRQ_ENABLED);
    set_fiq_status(FIQ_ENABLED);

    lcd_init();
    backlight_init();
    font_init();
    button_init();
    usb_init();
    
    
    power_init();
//    enable_irq();
//    enable_fiq();

    adc_init();

    lcd_setfont(FONT_SYSFIXED);

    /* Show debug messages if button is pressed */
//    if(button_read_device())
        verbose = true;

    printf("Rockbox boot loader");
    printf("Version %s", rbversion);

    /* Enter USB mode without USB thread */
    if(usb_detect() == USB_INSERTED)
    {
        const char msg[] = "Bootloader USB mode";
        reset_screen();
        lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                    (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
        lcd_update();

        ide_power_enable(true);
        storage_enable(false);
        sleep(HZ/20);
        usb_enable(true);

        while (usb_detect() == USB_INSERTED)
        {
            storage_spin(); /* Prevent the drive from spinning down */
            sleep(HZ);
        }

        usb_enable(false);

        reset_screen();
        lcd_update();
    }
    
    sleep(50);

    printf("ATA");
    rc = storage_init();
    if(rc)
    {
        reset_screen();
        error(EATA, rc, true);
    }

    printf("filesystem");
    filesystem_init();

    printf("mount");
    rc = disk_mount_all();
    if (rc<=0)
    {
        error(EDISK,rc, true);
    }

    printf("Loading firmware");

    loadbuffer = (unsigned char*) 0x00900000;
    buffer_size = (unsigned char*)0x01900000 - loadbuffer;

    rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
    if(rc <= EFILE_EMPTY)
        error(EBOOTFILE, rc, true);

    kernel_entry = (void*) loadbuffer;
    rc = kernel_entry();

    /* Should not get here! */
    return rc;
}
Ejemplo n.º 22
0
int main(void)
{
    u32 fontcnt;
    u8 i,j;
    u8 fontx[2];//gbk码
    u8 key,t;

    delay_init();	    	 //延时函数初始化
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
    uart_init(115200);	 	//串口初始化为115200
    usmart_dev.init(72);		//初始化USMART
    LED_Init();		  			//初始化与LED连接的硬件接口
    KEY_Init();					//初始化按键
    LCD_Init();			   		//初始化LCD
    W25QXX_Init();				//初始化W25Q128
    my_mem_init(SRAMIN);		//初始化内部内存池
    exfuns_init();				//为fatfs相关变量申请内存
    f_mount(fs[0],"0:",1); 		//挂载SD卡
    f_mount(fs[1],"1:",1); 		//挂载FLASH.
    while(font_init()) 			//检查字库
    {
        LCD_Clear(WHITE);		   	//清屏
        POINT_COLOR=RED;			//设置字体为红色
        LCD_ShowString(30,50,200,16,16,"WarShip STM32");
        while(SD_Init())			//检测SD卡
        {
            LCD_ShowString(30,70,200,16,16,"SD Card Failed!");
            delay_ms(200);
            LCD_Fill(30,70,200+30,70+16,WHITE);
            delay_ms(200);
        }
        LCD_ShowString(30,70,200,16,16,"SD Card OK");
        LCD_ShowString(30,90,200,16,16,"Font Updating...");
        key=update_font(20,110,16,"0:");//更新字库
        while(key)//更新失败
        {
            LCD_ShowString(30,110,200,16,16,"Font Update Failed!");
            delay_ms(200);
            LCD_Fill(20,110,200+20,110+16,WHITE);
            delay_ms(200);
        }
        LCD_ShowString(30,110,200,16,16,"Font Update Success!   ");
        delay_ms(1500);
        LCD_Clear(WHITE);//清屏
    }
    POINT_COLOR = MAGENTA;
    Show_Str(20,20,200,24,"第十一届全国电子",24,0);
    Show_Str(80,50,200,24,"设计大赛",24,0);

    POINT_COLOR = BLUE;
    Show_Str(60,80,200,24,"武昌首义学院",24,0);
    Show_Str(30,130,200,24,"参赛题目课题:",24,0);
    Show_Str(45,160,200,24,"旋转倒立摆",24,0);

    Show_Str(30,210,200,24,"参赛者:李观称",24,0);
    Show_Str(45,240,200,24,"赖丽清,张建",24,0);

    while(1)
    {
        fontcnt=0;
        for(i=0x81; i<0xff; i++)
        {
            fontx[0]=i;
//			LCD_ShowNum(118,150,i,3,16);		//显示内码高字节
            for(j=0x40; j<0xfe; j++)
            {
                if(j==0x7f)continue;
                fontcnt++;
//				LCD_ShowNum(118,170,j,3,16);	//显示内码低字节
//				LCD_ShowNum(118,190,fontcnt,5,16);//汉字计数显示
//			 	fontx[1]=j;
//				Show_Font(30+132,220,fontx,24,0);
//				Show_Font(30+144,244,fontx,16,0);
//				Show_Font(30+108,260,fontx,12,0);
                t=200;
                while(t--)//延时,同时扫描按键
                {
                    delay_ms(1);
                }
                LED0=!LED0;
            }
        }
    }
}
Ejemplo n.º 23
0
int main( int argc, char *arvg[] ) {
	int quit = 0;
	int config_status = 0;
	int event;

#ifdef __WIN32__
	freopen( "cabrio.out", "w", stdout );
	freopen( "cabrio.err", "w", stderr );
#endif

	config_status = config_open( NULL );
	if( config_status == -1 )
		return -1;

	if( sdl_init() != 0 )
		bail();

	if( ogl_init() != 0 )
		bail();
	
	/* Clear the screen as soon as we can. This avoids graphics
	 * glitches which can occur with some SDL implementations. */
	ogl_clear();
	sdl_swap();

	if( event_init() != 0 )
		bail();

	if( font_init() != 0 )
		bail();

	if( config_status == 1 ) {
		/* Config file didn't exist, so run the setup utility */
		if( setup() != 0 )
			return -1;
		config_update();
		if( config_create() != 0 )
			return -1;
	}

	location_init();

	/* If config or location results in a new font, it'll be loaded here. */
	font_free();
	font_init();

	/* Large game lists take a while to initialise,
	 * so show the background while we wait... */
	bg_init();
	bg_clear();
	bg_draw();
	sdl_swap();

	if( platform_init() != 0 )
		bail();

	if( category_init() != 0 )
		bail();

	if( game_sel_init() != 0 )
		bail();

	if( hint_init() != 0 )
		bail();

	if( snap_init() != 0 )
		bail();
	
	if( game_list_create() != 0 )
		bail();

	if( menu_init() != 0 )
		bail();

	if( submenu_init() != 0 )
		bail();

	sound_init();
	video_init();
	
	event_flush();

	if( !config_get()->iface.theme.menu.auto_hide )
		menu_show();
		
	focus_set( FOCUS_GAMESEL );

	while( !quit ) {
		ogl_clear();
		bg_draw();
		snap_draw();
		if (!config_get()->iface.hide_buttons)
			hint_draw();
		menu_draw();
		submenu_draw();
		game_sel_draw();
		sdl_swap();
		if (Mix_PlayingMusic() != 1 && config_get()->iface.theme_sound && reader_running == 0) 
			playmusic();
		if (( event = event_poll() )) {
			if( supress_wait == 0 ) {
				if( event == EVENT_QUIT ) {
					quit = 1;
				}
				else {
					supress();
					event_process( event );
				}
			}
		}
		if( supress_wait > 0 )
			supress_wait--;
		
		sdl_frame_delay();
	}
	clean_up();
	return 0;
}
Ejemplo n.º 24
0
void* main(void)
{
    int i;
    int rc;
    int fd;
    char buffer[80];
    unsigned char* framebuffer = (unsigned char*)0x11e00000;

#if 0
    lcd_init();
    font_init();

    printf("Hello World!");
#endif

    i=storage_init();

    disk_init();
    rc = disk_mount_all();

#if 0
    /* Dump the flash */
    fd=open("/flash.bin",O_CREAT|O_RDWR, 0666);
    write(fd,(char*)0,1024*1024);
    close(fd);
#endif

#if 1
    /* Dump what may be the framebuffer */
    fd=open("/framebuffer.bin",O_CREAT|O_RDWR|O_TRUNC, 0666);
    write(fd,framebuffer,220*176*4);
    close(fd);
#endif


    fd=open("/gpio.txt",O_CREAT|O_RDWR|O_TRUNC, 0666);
    unsigned int gpio_a = GPIOA_INPUT_VAL;
    unsigned int gpio_b = GPIOB_INPUT_VAL;
    unsigned int gpio_c = GPIOC_INPUT_VAL;
    unsigned int gpio_d = GPIOD_INPUT_VAL;
    unsigned int gpio_e = GPIOE_INPUT_VAL;
    unsigned int gpio_f = GPIOF_INPUT_VAL;
    unsigned int gpio_g = GPIOG_INPUT_VAL;
    unsigned int gpio_h = GPIOH_INPUT_VAL;
    unsigned int gpio_i = GPIOI_INPUT_VAL;
    unsigned int gpio_j = GPIOJ_INPUT_VAL;
    unsigned int gpio_k = GPIOK_INPUT_VAL;
    unsigned int gpio_l = GPIOL_INPUT_VAL;

    snprintf(buffer, sizeof(buffer), "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",gpio_a,gpio_b,gpio_c,gpio_d,gpio_e,gpio_f,gpio_g,gpio_h,gpio_i,gpio_j,gpio_k,gpio_l);
    write(fd,buffer,strlen(buffer)+1);
    close(fd);

    /* Wait for FFWD button to be pressed */
    while((GPIOA_INPUT_VAL & 0x04) != 0);


    /* Now reboot */
    DEV_RS |= 0x4;

    return 0;
}
Ejemplo n.º 25
0
/* Load a font and add it to the beginning of the global font list.
   Returns 0 upon success, nonzero upon failure.  */
grub_font_t
grub_font_load (const char *filename)
{
  grub_file_t file = 0;
  struct font_file_section section;
  char magic[4];
  grub_font_t font = 0;

#if FONT_DEBUG >= 1
  grub_dprintf ("font", "add_font(%s)\n", filename);
#endif

  if (filename[0] == '(' || filename[0] == '/' || filename[0] == '+')
    file = grub_buffile_open (filename, 1024);
  else
    {
      const char *prefix = grub_env_get ("prefix");
      char *fullname, *ptr;
      if (!prefix)
	{
	  grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
		      "prefix");
	  goto fail;
	}
      fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1
			      + sizeof ("/fonts/") + sizeof (".pf2"));
      if (!fullname)
	goto fail;
      ptr = grub_stpcpy (fullname, prefix);
      ptr = grub_stpcpy (ptr, "/fonts/");
      ptr = grub_stpcpy (ptr, filename);
      ptr = grub_stpcpy (ptr, ".pf2");
      *ptr = 0;
      file = grub_buffile_open (fullname, 1024);
      grub_free (fullname);
    }
  if (!file)
    goto fail;

#if FONT_DEBUG >= 3
  grub_dprintf ("font", "file opened\n");
#endif

  /* Read the FILE section.  It indicates the file format.  */
  if (open_section (file, &section) != 0)
    goto fail;

#if FONT_DEBUG >= 3
  grub_dprintf ("font", "opened FILE section\n");
#endif
  if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FILE,
		   sizeof (FONT_FORMAT_SECTION_NAMES_FILE) - 1) != 0)
    {
      grub_error (GRUB_ERR_BAD_FONT,
		  "font file format error: 1st section must be FILE");
      goto fail;
    }

#if FONT_DEBUG >= 3
  grub_dprintf ("font", "section name ok\n");
#endif
  if (section.length != 4)
    {
      grub_error (GRUB_ERR_BAD_FONT,
		  "font file format error (file type ID length is %d "
		  "but should be 4)", section.length);
      goto fail;
    }

#if FONT_DEBUG >= 3
  grub_dprintf ("font", "section length ok\n");
#endif
  /* Check the file format type code.  */
  if (grub_file_read (file, magic, 4) != 4)
    goto fail;

#if FONT_DEBUG >= 3
  grub_dprintf ("font", "read magic ok\n");
#endif

  if (grub_memcmp (magic, FONT_FORMAT_PFF2_MAGIC, 4) != 0)
    {
      grub_error (GRUB_ERR_BAD_FONT, "invalid font magic %x %x %x %x",
		  magic[0], magic[1], magic[2], magic[3]);
      goto fail;
    }

#if FONT_DEBUG >= 3
  grub_dprintf ("font", "compare magic ok\n");
#endif

  /* Allocate the font object.  */
  font = (grub_font_t) grub_zalloc (sizeof (struct grub_font));
  if (!font)
    goto fail;

  font_init (font);
  font->file = file;

#if FONT_DEBUG >= 3
  grub_dprintf ("font", "allocate font ok; loading font info\n");
#endif

  /* Load the font information.  */
  while (1)
    {
      if (open_section (file, &section) != 0)
	{
	  if (section.eof)
	    break;		/* Done reading the font file.  */
	  else
	    goto fail;
	}

#if FONT_DEBUG >= 2
      grub_dprintf ("font", "opened section %c%c%c%c ok\n",
		   section.name[0], section.name[1],
		   section.name[2], section.name[3]);
#endif

      if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME,
		       sizeof (FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0)
	{
	  font->name = read_section_as_string (&section);
	  if (!font->name)
	    goto fail;
	}
      else if (grub_memcmp (section.name,
			    FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
			    sizeof (FONT_FORMAT_SECTION_NAMES_POINT_SIZE) -
			    1) == 0)
	{
	  if (read_section_as_short (&section, &font->point_size) != 0)
	    goto fail;
	}
      else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_WEIGHT,
			    sizeof (FONT_FORMAT_SECTION_NAMES_WEIGHT) - 1)
	       == 0)
	{
	  char *wt;
	  wt = read_section_as_string (&section);
	  if (!wt)
	    continue;
	  /* Convert the weight string 'normal' or 'bold' into a number.  */
	  if (grub_strcmp (wt, "normal") == 0)
	    font->weight = FONT_WEIGHT_NORMAL;
	  else if (grub_strcmp (wt, "bold") == 0)
	    font->weight = FONT_WEIGHT_BOLD;
	  grub_free (wt);
	}
      else if (grub_memcmp (section.name,
			    FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
			    sizeof (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH)
			    - 1) == 0)
	{
	  if (read_section_as_short (&section, &font->max_char_width) != 0)
	    goto fail;
	}
      else if (grub_memcmp (section.name,
			    FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
			    sizeof (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT)
			    - 1) == 0)
	{
	  if (read_section_as_short (&section, &font->max_char_height) != 0)
	    goto fail;
	}
      else if (grub_memcmp (section.name,
			    FONT_FORMAT_SECTION_NAMES_ASCENT,
			    sizeof (FONT_FORMAT_SECTION_NAMES_ASCENT) - 1)
	       == 0)
	{
	  if (read_section_as_short (&section, &font->ascent) != 0)
	    goto fail;
	}
      else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DESCENT,
			    sizeof (FONT_FORMAT_SECTION_NAMES_DESCENT) - 1)
	       == 0)
	{
	  if (read_section_as_short (&section, &font->descent) != 0)
	    goto fail;
	}
      else if (grub_memcmp (section.name,
			    FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
			    sizeof (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) -
			    1) == 0)
	{
	  if (load_font_index (file, section.length, font) != 0)
	    goto fail;
	}
      else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DATA,
			    sizeof (FONT_FORMAT_SECTION_NAMES_DATA) - 1) == 0)
	{
	  /* When the DATA section marker is reached, we stop reading.  */
	  break;
	}
      else
	{
	  /* Unhandled section type, simply skip past it.  */
#if FONT_DEBUG >= 3
	  grub_dprintf ("font", "Unhandled section type, skipping.\n");
#endif
	  grub_off_t section_end = grub_file_tell (file) + section.length;
	  if ((int) grub_file_seek (file, section_end) == -1)
	    goto fail;
	}
    }

  if (!font->name)
    {
      grub_dprintf ("font", "Font has no name.\n");
      font->name = grub_strdup ("Unknown");
    }

#if FONT_DEBUG >= 1
  grub_dprintf ("font", "Loaded font `%s'.\n"
	       "Ascent=%d Descent=%d MaxW=%d MaxH=%d Number of characters=%d.\n",
	       font->name,
	       font->ascent, font->descent,
	       font->max_char_width, font->max_char_height, font->num_chars);
#endif

  if (font->max_char_width == 0
      || font->max_char_height == 0
      || font->num_chars == 0
      || font->char_index == 0 || font->ascent == 0 || font->descent == 0)
    {
      grub_error (GRUB_ERR_BAD_FONT,
		  "invalid font file: missing some required data");
      goto fail;
    }

  /* Add the font to the global font registry.  */
  if (register_font (font) != 0)
    goto fail;

  return font;

fail:
  if (file)
    grub_file_close (file);
  if (font)
    font->file = 0;

  free_font (font);
  return 0;
}
Ejemplo n.º 26
0
Archivo: main.c Proyecto: odrevet/GE
int main(int argc, char** argv)
{
    SDL_Surface *screen=NULL;

    srand(time(NULL));

    sdl_init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
    sound_init();
    font_init();

    #ifdef GEKKO
	if (!fatInitDefault()) {
		printf("fatInitDefault failure: terminating\n");
		exit(EXIT_FAILURE);
	}
    freopen("sd:/apps/bomberguy/out.txt", "w", stdout);
    freopen("sd:/apps/bomberguy/err.txt", "w", stderr);
    #endif

    // make sure SDL cleans up before exit
    atexit(SDL_Quit);
    SDL_ShowCursor(SDL_DISABLE);

    SDL_WM_SetCaption("bomberguy", NULL);

    // create a new window
    screen = sdl_set_video(SCREEN_WIDTH, SCREEN_HEIGHT, 16, SDL_HWSURFACE);

    if ( !screen )
    {
        fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
        exit(EXIT_FAILURE);
    }

    backbuffer = SDL_DisplayFormat(screen);

    //load ressources
    ressource* res_bomb = malloc(sizeof(ressource));
    image* img_bomb = image_load("./res/bomb.png");
    res_bomb->name = strdup("bomb");
    res_bomb->data = img_bomb;
    image_set_transp_color(img_bomb, 255, 0, 255);
    images = res_add(images, res_bomb);

    ressource* res_flame = malloc(sizeof(ressource));
    image* img_flame = image_load("./res/flame.png");
    image_set_transp_color(img_flame, 255, 0, 255);
    res_flame->name = strdup("flame");
    res_flame->data = img_flame;
    images = res_add(images, res_flame);

    ressource* res_block = malloc(sizeof(ressource));
    image* img_block = image_load("./res/block_classic.png");
    image_set_transp_color(img_block, 255, 0, 255);
    res_block->name = strdup("block");
    res_block->data = img_block;
    images = res_add(images, res_block);

    //Some game default parameters
    g_game.block_fill = 0.65;
    g_game.time = 180;
    g_game.unit_nb = 2;
    unit_init(g_game.v_unit, UNIT_MAX);

    SDL_EnableKeyRepeat(10,10);

    state_main_menu(screen);

    SDL_Quit();
    return EXIT_SUCCESS;
}
Ejemplo n.º 27
0
void main(void)
{
    unsigned char* loadbuffer;
    int buffer_size;
    int rc;
    int(*kernel_entry)(void);

    system_init();
    kernel_init(); /* Need the kernel to sleep */

    enable_interrupt(IRQ_FIQ_STATUS);

    lcd_init();
    backlight_init();
    button_init();
    font_init();
    adc_init();

    lcd_setfont(FONT_SYSFIXED);
    
    /* These checks should only run if the bootloader is flashed */
    if(GSTATUS3&0x02)
    {
        GSTATUS3&=0xFFFFFFFD;
        if(!(GPGDAT&BUTTON_POWER) && charger_inserted())
        {
            while(!(GPGDAT&BUTTON_POWER) && charger_inserted())
            {
                char msg[20];
                if(charging_state())
                {
                    snprintf(msg,sizeof(msg),"Charging");
                }
                else
                {
                    snprintf(msg,sizeof(msg),"Charge Complete");
                }
                reset_screen();
                lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                        (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
                lcd_update();
                
#if defined(HAVE_RTC_ALARM)            
                /* Check if the alarm went off while charging */
                if(rtc_check_alarm_flag())
                {
                    GSTATUS3=1; /* Normally this is set in crt0.s */
                    break;
                }
#endif
            }
            if(!(GPGDAT&BUTTON_POWER) 
#if defined(HAVE_RTC_ALARM)
                && !GSTATUS3
#endif
                )
            {
                shutdown();
            }
        }

        if(button_hold())
        {
            const char msg[] = "HOLD is enabled";
            reset_screen();
            lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                        (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
            lcd_update();
            
            sleep(2*HZ);
            
            shutdown();
        }
    }

    power_init();
    usb_init();

    /* Enter USB mode without USB thread */
    if(usb_detect() == USB_INSERTED)
    {
        const char msg[] = "Bootloader USB mode";
        reset_screen();
        lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                    (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
        lcd_update();

        storage_enable(false);
        sleep(HZ/20);
        usb_enable(true);

        while (usb_detect() == USB_INSERTED)
            sleep(HZ);

        usb_enable(false);

        reset_screen();
        lcd_update();
    }
    
    reset_screen();

    /* Show debug messages if button is pressed */
    if(button_read_device()&BUTTON_A)
        verbose = true;

    printf("Rockbox boot loader");
    printf("Version %s", rbversion);

    sleep(50); /* ATA seems to error without this pause */

    rc = storage_init();
    if(rc)
    {
        reset_screen();
        error(EATA, rc, true);
    }

    filesystem_init();

    rc = disk_mount_all();
    if (rc<=0)
    {
        error(EDISK, rc, true);
    }

    printf("Loading firmware");

    /* Flush out anything pending first */
    commit_discard_idcache();

    loadbuffer = (unsigned char*) 0x31000000;
    buffer_size = (unsigned char*)0x31400000 - loadbuffer;

    rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
    if(rc <= EFILE_EMPTY)
        error(EBOOTFILE, rc, true);

    storage_close();
    system_prepare_fw_start();

    commit_discard_idcache();
    kernel_entry = (void*) loadbuffer;
    rc = kernel_entry();

#if 0
    /* Halt */
    while (1)
        core_idle();
#else
    /* Return and restart */
#endif
}
Ejemplo n.º 28
0
int main(int argc, char **argv)
{
  int err;
#ifdef __APPLE__
  char *cfrespath;
  CFBundleRef mainBundle;
  CFURLRef res;
  CFStringRef respathref;
#endif

  // load config file from user's homedir
  dotfile_load();

  // calculate tables for supersaw
  calc_supersaw_tables();

  // init data on all pages to defaults
  synth_init();
  patch_init();
  pattern_init();
  sequencer_init();

  // init glut
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowSize(DS_WIDTH,DS_HEIGHT);
  glutCreateWindow("komposter");
  glutIgnoreKeyRepeat(1);
  
  

#ifdef __APPLE__
  // get application bundle base path
  mainBundle=CFBundleGetMainBundle();
  res=CFBundleCopyBundleURL(mainBundle);
  respathref=CFURLCopyFileSystemPath(res, 0);
  cfrespath=(char*)CFStringGetCStringPtr(respathref, kCFStringEncodingISOLatin1);
  if (!cfrespath) {
    cfrespath=malloc(512);
    CFStringGetCString(respathref, cfrespath, 511, kCFStringEncodingISOLatin1);
    strncpy(respath, cfrespath, 511);
    free(cfrespath);
  } else {
    strncpy(respath, cfrespath, 511);  
  }
  strncat(respath, "/Contents/Resources/", 511); // append the resource dir
#else
#ifdef RESOURCEPATH
	if(is_dir(RESOURCEPATH))
	{
		strncpy(respath, RESOURCEPATH, 511);
	}
	else
	{
		fprintf(stderr, "'%s' not found, trying relative path\n", RESOURCEPATH);
		strncpy(respath, "resources/", 511);
	}
#else
  strncpy(respath, "resources/", 512);
#endif
#endif
  printf("Resource path is %s\n", respath);

  // init freetype
  err=font_init();
  if (!err) {
    printf("Error initializing Freetype!\n");
    return 0;
  }

  // set glut callbacks
  glutKeyboardFunc(keyboardfunc);
  glutKeyboardUpFunc(keyboardupfunc);
  glutMouseFunc(mouse_clickfunc);
  glutMotionFunc(mouse_dragfunc);
  glutSpecialFunc(specialkeyfunc);
  glutPassiveMotionFunc(mouse_hoverfunc);

  // init memory manager
  kmm_init();

  // set up screen and fire up the update timer
  cpage=MAIN_PAGE4;
  glutDisplayFunc(display);
  glutTimerFunc(20, update, 1);
  dialog_open(&about_draw, &about_hover, &about_click);

  // start audio and opengl mainloop
  atexit(cleanup);
  if (!audio_initialize()) {
    printf("Failed to initialize audio playback - sound is disabled.\n");
  } else {
    err = pthread_create(&audiothread, NULL, audio_playback, (void *)NULL);
  }
  err = pthread_create(&renderthread, NULL, audio_renderer, (void *)NULL);
  glutMainLoop();
  return 0;
}
Ejemplo n.º 29
0
void
gui_init(event_bus *eb, mouse_state *ms, int w, int h)
{
	// set up globals
	gui_eventbus 	= eb;
	gui_w 			= w;
	gui_h			= h;
	gui_mousestate 	= ms;
	gui_aspectratio = (double)w/(double)h;
	gui_mousex = gui_aspectratio*(double)gui_mousestate->x/(double)gui_w;
	gui_mousey = 1.0-(double)gui_mousestate->y/(double)gui_h;
	
	gui_dials = calloc(SDR_NUMDIALS, sizeof(float));
	
	// Set GUI colours
	color **cols = malloc(sizeof(color*)*6);
	cols[0] = color_new3(0.02, 0.18, 0.3);
	cols[1] = color_new3(0.8, 0.3, 0.1);
	cols[2] = color_new3(0.95, 0.95, 0.9);
	cols[3] = color_new3(0.08, 0.1, 0.1);
	cols[4] = color_new3(0.016, 0.2, 0.2);
	cols[5] = color_new3(0, 0, 0);
	gui_colors = color_newpack(cols, 6);
	
	// Set up GUI
	gui_fontinfo = font_init("extremeradcool", gui_colors->colors[2]);
	
	
	gui_div *dddials[SDR_NUMDIALS];
	gui_contenttype ddtypes[SDR_NUMDIALS];
	vec2 ddpos[SDR_NUMDIALS];
	void (*ddevents[SDR_NUMDIALS])(void *) = {
		_updatedial0,
		_updatedial1,
		_updatedial2,
		_updatedial3,
		_updatedial4,
		_updatedial5,
		_updatedial6
	};
	static char ddnames[SDR_NUMDIALS][32] = {
		"Oftenality",
		"Affection",
		"Spiralitude",
		"Boxulation",
		"Nonstraightness",
		"Wanderlust",
		"Zoom"
	};
	
	for(int i=0; i<SDR_NUMDIALS; i++) {
		gui_textbox *text = 
			gui_textbox_init(
				ddnames[i],
				gui_fontinfo,
				0.035, 
				0.0, 0.0
			);
		text->bounds->visible = 0;
		gui_slider *slider = 
			gui_slider_initwithe(
				0.5, 0.01, 
				GUI_SLIDER_HORZ,
				bus_newevent(gui_eventbus),
				ddevents[i]
			);
		dddials[i] = gui_div_initwith(
			GUI_DIV_HORZ,
			gui_container_initwith(1, 1,
				text,
				GUI_CONTENTTYPE_TEXTBOX,
				0, 0.5),
			gui_container_initwith(1, 1,
				slider,
				GUI_CONTENTTYPE_SLIDER,
				0.1, 0.1
			)
		);	
		dddials[i]->visible = 0;
		ddtypes[i] = GUI_CONTENTTYPE_DIV;
		ddpos[i].x = 0.5;
		ddpos[i].y = 0.5;
	}
	
	gui_container *dialdiv = 
		gui_container_initmany(
			1, 1,
			GUI_DIV_HORZ,
			(void **)dddials,
			ddtypes,
			ddpos,
			SDR_NUMDIALS
		);
	
	gui_container *buttondiv = 
		gui_container_initwith(1, 1,
			gui_div_initwith(
				GUI_DIV_VERT,
				gui_container_initwith(1, 1,
					gui_button_initwithfe(
						"Reset", gui_fontinfo,
						bus_newevent(gui_eventbus), NULL, _resettexture,
						0.03
					),
					GUI_CONTENTTYPE_BUTTON,
					0.5, 0.5
				),
				gui_container_initwith(1, 1,
					gui_button_initwithfe(
						"Quit", gui_fontinfo,
						bus_newevent(gui_eventbus), NULL, _quitthisshit,
						0.03
					),
					GUI_CONTENTTYPE_BUTTON,
					0.5, 0.5
				)
			),
			GUI_CONTENTTYPE_DIV,
			0.5, 0.5
		);
		((gui_div *)(buttondiv->content))->visible = 0;
		
	gui_container *rightpane = 
		gui_container_initwith(1, 1,
			gui_div_initwith(GUI_DIV_HORZ,
				dialdiv,
				buttondiv
			),
			GUI_CONTENTTYPE_DIV,
			0, 0.1
		);
		
	gui_message = malloc(512);
	sprintf(gui_message, "aass");
	
	gui_container *leftpane =
		gui_container_initwith(1, 1,
					// gui_textbox_init(
						// gui_message,
						// gui_fontinfo,
						// 0.02,
						// 1.0, 0.1
					// ),
					NULL,
					GUI_CONTENTTYPE_NULL,
					0.0, 0.0
				);
	leftpane->visible = 1;
				
	gui_maingui =
		gui_container_initwith(gui_aspectratio, 1.0,
			gui_div_initwith(GUI_DIV_VERT,
				leftpane,
				rightpane
			),
			GUI_CONTENTTYPE_DIV,
			0.8, 0.9
		);

//	pc = gui_container_init(gui_aspectratio, 0.5);
	
	bus_subscribe(eb, mouse_event_up, (void *)gui_mouseupevent);
	bus_subscribe(eb, mouse_event_move, (void *)gui_mousemoveevent);
}
Ejemplo n.º 30
0
int init(const platform_env_t* env)
{
    paused = 0;

    LOGI("Environment:\n  Platform: %d\n  Assets: %s\n  Shared: %s\n  Config: %s\n  Tmp: %s\n",
         env->platform,
         env->assets_dir,
         env->shared_dir,
         env->config_dir,
         env->tmp_dir);

    io_driver_t* assets = NULL;
    io_driver_t* config = NULL;
    io_driver_t* tmp = NULL;
    io_driver_t* shared = NULL;
    if (io_init(&io) != 0 ||
#ifdef ANDROID
            io_driver_apk_init(&assets, env->platform_specific) != 0 ||
#else
            io_driver_fs_init(&assets, env->assets_dir) != 0 ||
#endif
            io_driver_fs_init(&config, env->config_dir) != 0 ||
            io_driver_fs_init(&shared, env->shared_dir) != 0 ||
            io_driver_fs_init(&tmp, env->tmp_dir) != 0 ||
            io_bind(io, "/config", config) ||
            io_bind(io, "/tmp", tmp) ||
            io_bind(io, "/shared", shared) ||
            io_bind(io, "/assets", assets)
       )
    {
        LOGE("Error initializing I/O system");
        return -1;
    }
    io_set_working_dir(io, "/assets");
    io_set_default(io);

    if (gfx_init(&gfx) != 0)
    {
        LOGE("Error initializing GFX system");
        return -1;
    }

    font_info_t info =
    {
        .name = "fonts/default.ttf",
        .face_index = 0,
        .width = 0,
        .height = 14 * 64,
        .dpi_x = 0,
        .dpi_y = 72,
    };
    if (font_init(&font, &info, NULL) != 0)
    {
        LOGE("Error loading font");
        return -1;
    }

    info.height = 22 * 64;
    if (font_init(&big_font, &info, NULL) != 0)
    {
        LOGE("Error loading font");
        return -1;
    }

    if (atlases_load(&atlases, "atlases.dat") != 0)
    {
        LOGE("Error loading atlases metadata");
        return -1;
    }

    if (sprites_load(&sprites, "sprites.dat") != 0)
    {
        LOGE("Error loading sprites metadata");
        return -1;
    }

    stats_load(&global_stats, "/config/player.dat");

    if (am_init(&am, achievements_get_all(), achievements_get_count(), achievement_progress, achievement_unlocked))
    {
        LOGE("Unable to initialize achievements manager");
        return -1;
    }
    achievements_context.am = am;
    am_load(am, "/config/achievements.dat");

    timestamp_set(&timer);
    timestamp_set(&fps_timer);

    push_screen(SCREEN_MAIN_MENU);

    return 0;
}

void shutdown()
{
    LOGI("shutdown");
    atlases_free(atlases);
    sprites_free(sprites);
    font_free(font);
    font_free(big_font);
    gfx_free(gfx);

    stats_dump(&global_stats);
    stats_save(&global_stats, "/config/player.dat");
    stats_free(&global_stats);

    if (am != NULL)
    {
        am_save(am, "/config/achievements.dat");
        am_dump(am);
        am_free(am);
        am = NULL;
    }

    io_free(io);
    io = NULL;

    atlases = NULL;
    sprites = NULL;
    font = NULL;
    big_font = NULL;
    gfx = NULL;
}