// // load // void Load_ConfigFile(void) { Set_ErrorLog(); // set up the error log f_config = fopen(CONFIG_FILE_NAME, "r"); if (f_config == NULL) { Add_ErrorLog(ID_FILE_NOT_FOUND); // create a new file config.ini Rewrite_File(); //Read_ConfigFile(f_newfile); // Note: I left the comment above // because you may need it later // right now, the code writes a file // based on the default values // then closes the new file // // Another approach might be to write // the new file and then reread the new // file and check the variables // it is really a matter of // "if there are bugs then check here" // Check_Errors(); return; } // end of the function Read_ConfigFile(f_config); fclose(f_config); Check_Errors(); } // end of the function
int main (int argc, char *argv[]) { int i; const char *commandLine_File = NULL; GtkWidget *pVBox; GtkWidget *pMenuBar; GtkWidget *pMenu, *pSubMenu; GtkWidget *pMenuItem, *pSubMenuItem; GtkAccelGroup * accel_group; if(argc == 2) commandLine_File = argv[1]; #ifdef DEBUG LogStart(); #endif gtk_init(&argc, &argv); SDL_Init(SDL_INIT_VIDEO); desmume_init(); dTools_running = (BOOL*)malloc(sizeof(BOOL) * dTools_list_size); for(i=0; i<dTools_list_size; i++) dTools_running[i]=FALSE; CONFIG_FILE = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL); Read_ConfigFile(); /* Creation de la fenetre */ pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(pWindow), "Desmume"); gtk_window_set_policy (GTK_WINDOW (pWindow), FALSE, FALSE, FALSE); gtk_window_set_icon(GTK_WINDOW (pWindow), gdk_pixbuf_new_from_xpm_data(DeSmuME_xpm)); g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(G_OBJECT(pWindow), "key_press_event", G_CALLBACK(Key_Press), NULL); g_signal_connect(G_OBJECT(pWindow), "key_release_event", G_CALLBACK(Key_Release), NULL); /* Creation de la GtkVBox */ pVBox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(pWindow), pVBox); accel_group = gtk_accel_group_new(); action_group = gtk_action_group_new("dui"); gtk_action_group_add_actions(action_group, action_entries, sizeof(action_entries) / sizeof(GtkActionEntry), pWindow); { GList * list = gtk_action_group_list_actions(action_group); g_list_foreach(list, dui_set_accel_group, accel_group); } gtk_window_add_accel_group(GTK_WINDOW(pWindow), accel_group); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "pause"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "reset"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "printscreen"), FALSE); /**** Creation du menu ****/ pMenuBar = gtk_menu_bar_new(); /** Menu "Fichier" **/ pMenu = gtk_menu_new(); gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "open"))); gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "printscreen"))); gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "quit"))); pMenuItem = gtk_menu_item_new_with_label("File"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu); gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); /** Menu "Emulation" **/ GtkWidget *mEmulation; GtkWidget *mFrameskip; GtkWidget *mFrameskip_Radio[MAX_FRAMESKIP]; GtkWidget *mGraphics; GtkWidget *mSize; GtkWidget *mSize_Radio[MAX_SCREENCOEFF]; GtkWidget *mLayers; GtkWidget *mLayers_Radio[10]; mEmulation = gtk_menu_new(); pMenuItem = gtk_menu_item_new_with_label("Emulation"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mEmulation); gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); gtk_container_add(GTK_CONTAINER(mEmulation), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "run"))); gtk_container_add(GTK_CONTAINER(mEmulation), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "pause"))); gtk_container_add(GTK_CONTAINER(mEmulation), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "reset"))); mFrameskip = gtk_menu_new(); pMenuItem = gtk_menu_item_new_with_label("Frameskip"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mFrameskip); gtk_menu_shell_append(GTK_MENU_SHELL(mEmulation), pMenuItem); for(i = 0; i < MAX_FRAMESKIP; i++) { char frameskipRadio_buf[16]; sprintf(frameskipRadio_buf, "%d", i); if(i>0) mFrameskip_Radio[i] = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(mFrameskip_Radio[i-1]), frameskipRadio_buf); else mFrameskip_Radio[i] = gtk_radio_menu_item_new_with_label(NULL, frameskipRadio_buf); g_signal_connect(G_OBJECT(mFrameskip_Radio[i]), "activate", G_CALLBACK(Modify_Frameskip), GINT_TO_POINTER(i)); gtk_menu_shell_append(GTK_MENU_SHELL(mFrameskip), mFrameskip_Radio[i]); } gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mFrameskip_Radio[0]), TRUE); mGraphics = gtk_menu_new(); pMenuItem = gtk_menu_item_new_with_label("Graphics"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mGraphics); gtk_menu_shell_append(GTK_MENU_SHELL(mEmulation), pMenuItem); // TODO: Un jour, peut être... >< mSize = gtk_menu_new(); pMenuItem = gtk_menu_item_new_with_label("Size"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mSize); gtk_menu_shell_append(GTK_MENU_SHELL(mGraphics), pMenuItem); for(i = 1; i < MAX_SCREENCOEFF; i++) { char sizeRadio_buf[16]; sprintf(sizeRadio_buf, "x%d", i); if(i>1) mSize_Radio[i] = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(mSize_Radio[i-1]), sizeRadio_buf); else mSize_Radio[i] = gtk_radio_menu_item_new_with_label(NULL, sizeRadio_buf); g_signal_connect(G_OBJECT(mSize_Radio[i]), "activate", G_CALLBACK(Modify_ScreenCoeff), GINT_TO_POINTER(i)); gtk_menu_shell_append(GTK_MENU_SHELL(mSize), mSize_Radio[i]); } gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mFrameskip_Radio[0]), TRUE); mLayers = gtk_menu_new(); pMenuItem = gtk_menu_item_new_with_label("Layers"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mLayers); gtk_menu_shell_append(GTK_MENU_SHELL(mGraphics), pMenuItem); for(i = 0; i < 10; i++) { mLayers_Radio[i] = gtk_check_menu_item_new_with_label(Layers_Menu[i]); g_signal_connect(G_OBJECT(mLayers_Radio[i]), "activate", G_CALLBACK(Modify_Layer), (void*)Layers_Menu[i]); gtk_menu_shell_append(GTK_MENU_SHELL(mLayers), mLayers_Radio[i]); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mLayers_Radio[i]), TRUE); } /** Menu "Options" **/ GtkWidget *mConfig = gtk_menu_new(); pMenuItem = gtk_menu_item_new_with_label("Config"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mConfig); gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); pMenuItem = gtk_menu_item_new_with_label("Edit controls"); g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(Edit_Controls), (GtkWidget*) pWindow); gtk_menu_shell_append(GTK_MENU_SHELL(mConfig), pMenuItem); #if 0 GtkWidget *mFirmware; mFirmware = gtk_menu_new(); pMenuItem = gtk_menu_item_new_with_label("Firmware"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mFirmware); gtk_menu_shell_append(GTK_MENU_SHELL(mConfig), pMenuItem); pMenuItem = gtk_menu_item_new_with_label("Select..."); g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(SelectFirmwareFile), (gpointer)0); gtk_menu_shell_append(GTK_MENU_SHELL(mFirmware), pMenuItem); pMenuItem = gtk_menu_item_new_with_label("Config"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mConfig); gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); #endif /** Menu "Outils" **/ pMenu = gtk_menu_new(); for(i = 0; i < dTools_list_size; i++) { pMenuItem = gtk_menu_item_new_with_label(dTools_list[i]->name); g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(Start_dTool), GINT_TO_POINTER(i)); gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); } pMenuItem = gtk_menu_item_new_with_label("Tools"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu); gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); /** Menu "?" **/ pMenu = gtk_menu_new(); #if ((GTK_MAJOR_VERSION >= 2) && (GTK_MINOR_VERSION >= 6)) pMenuItem = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT,NULL); #else pMenuItem = gtk_menu_item_new_with_label("About"); #endif g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(About), (GtkWidget*) pWindow); gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); pMenuItem = gtk_menu_item_new_with_label("?"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu); gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); /* Ajout du menu a la fenetre */ gtk_box_pack_start(GTK_BOX(pVBox), pMenuBar, FALSE, FALSE, 0); /* Création de la Toolbar */ pToolbar = gtk_toolbar_new(); gtk_box_pack_start(GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0); gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "open"))), -1); gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "run"))), -1); gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "pause"))), -1); gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "quit"))), -1); /* Création de l'endroit pour l'affichage des écrans */ pDrawingArea= gtk_drawing_area_new(); gtk_drawing_area_size(GTK_DRAWING_AREA(pDrawingArea), 256, 384); gtk_widget_set_usize (pDrawingArea, 256, 384); gtk_widget_set_events(pDrawingArea, GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK ); g_signal_connect(G_OBJECT(pDrawingArea), "button_press_event", G_CALLBACK(Stylus_Press), NULL); g_signal_connect(G_OBJECT(pDrawingArea), "button_release_event", G_CALLBACK(Stylus_Release), NULL); g_signal_connect(G_OBJECT(pDrawingArea), "motion_notify_event", G_CALLBACK(Stylus_Move), NULL); g_signal_connect( G_OBJECT(pDrawingArea), "realize", G_CALLBACK(Draw), NULL ) ; g_signal_connect( G_OBJECT(pDrawingArea), "expose_event", G_CALLBACK(gtkFloatExposeEvent), NULL ) ; gtk_box_pack_start(GTK_BOX(pVBox), pDrawingArea, FALSE, FALSE, 0); /* Création de la barre d'état */ pStatusBar = gtk_statusbar_new(); pStatusBar_Ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(pStatusBar), "Global"); pStatusBar_Change("Desmume"); gtk_box_pack_end(GTK_BOX(pVBox), pStatusBar, FALSE, FALSE, 0); gtk_widget_show_all(pWindow); //LoadFirmware("fw.bin"); /* Vérifie la ligne de commandes */ if(commandLine_File) { if(Open(commandLine_File) >= 0) { Launch(); } else { GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Unable to load :\n%s", commandLine_File); gtk_dialog_run(GTK_DIALOG(pDialog)); gtk_widget_destroy(pDialog); } } /* Boucle principale */ // gtk_idle_add(&EmuLoop, pWindow); // g_idle_add(&EmuLoop, pWindow); gtk_main(); desmume_free(); #ifdef DEBUG LogStop(); #endif SDL_Quit(); Write_ConfigFile(); return EXIT_SUCCESS; }
static int common_gtk_glade_main( struct configured_features *my_config) { SDL_TimerID limiter_timer; gdbstub_handle_t arm9_gdb_stub; gdbstub_handle_t arm7_gdb_stub; struct armcpu_memory_iface *arm9_memio = &arm9_base_memory_iface; struct armcpu_memory_iface *arm7_memio = &arm7_base_memory_iface; struct armcpu_ctrl_iface *arm9_ctrl_iface; struct armcpu_ctrl_iface *arm7_ctrl_iface; #ifdef GTKGLEXT_AVAILABLE // check if you have GTHREAD when running configure script //g_thread_init(NULL); register_gl_fun(my_gl_Begin,my_gl_End); #endif #ifdef DEBUG LogStart(); #endif init_keyvals(); if ( my_config->arm9_gdb_port != 0) { arm9_gdb_stub = createStub_gdb( my_config->arm9_gdb_port, &arm9_memio, &arm9_base_memory_iface); if ( arm9_gdb_stub == NULL) { g_print( "Failed to create ARM9 gdbstub on port %d\n", my_config->arm9_gdb_port); return -1; } } if ( my_config->arm7_gdb_port != 0) { arm7_gdb_stub = createStub_gdb( my_config->arm7_gdb_port, &arm7_memio, &arm7_base_memory_iface); if ( arm7_gdb_stub == NULL) { g_print( "Failed to create ARM7 gdbstub on port %d\n", my_config->arm7_gdb_port); return -1; } } if(SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO) == -1) { fprintf(stderr, "Error trying to initialize SDL: %s\n", SDL_GetError()); return 1; } desmume_init( arm9_memio, &arm9_ctrl_iface, arm7_memio, &arm7_ctrl_iface); /* * Activate the GDB stubs * This has to come after the NDS_Init (called in desmume_init) * where the cpus are set up. */ if ( my_config->arm9_gdb_port != 0) { activateStub_gdb( arm9_gdb_stub, arm9_ctrl_iface); } if ( my_config->arm7_gdb_port != 0) { activateStub_gdb( arm7_gdb_stub, arm7_ctrl_iface); } /* Initialize joysticks */ if(!init_joy()) return 1; CONFIG_FILE = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL); Read_ConfigFile(); /* load the interface */ xml = glade_xml_new(get_ui_file("DeSmuMe.glade"), NULL, NULL); xml_tools = glade_xml_new(get_ui_file("DeSmuMe_Dtools.glade"), NULL, NULL); pWindow = glade_xml_get_widget(xml, "wMainW"); pDrawingArea = glade_xml_get_widget(xml, "wDraw_Main"); pDrawingArea2 = glade_xml_get_widget(xml, "wDraw_Sub"); /* connect the signals in the interface */ glade_xml_signal_autoconnect_StringObject(xml); glade_xml_signal_autoconnect_StringObject(xml_tools); init_GL_capabilities( my_config->software_colour_convert); /* check command line file */ if( my_config->nds_file) { if(desmume_open( my_config->nds_file) >= 0) { desmume_resume(); enable_rom_features(); } else { GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Unable to load :\n%s", my_config->nds_file); gtk_dialog_run(GTK_DIALOG(pDialog)); gtk_widget_destroy(pDialog); } } gtk_widget_show(pDrawingArea); gtk_widget_show(pDrawingArea2); { int use_null_3d = my_config->disable_3d; #ifdef GTKGLEXT_AVAILABLE if ( !use_null_3d) { /* setup the gdk 3D emulation */ if ( init_opengl_gdk_3Demu()) { NDS_3D_SetDriver(1); if (!gpu3D->NDS_3D_Init()) { fprintf( stderr, "Failed to initialise openGL 3D emulation; " "removing 3D support\n"); use_null_3d = 1; } } else { fprintf( stderr, "Failed to setup openGL 3D emulation; " "removing 3D support\n"); use_null_3d = 1; } } #endif if ( use_null_3d) { NDS_3D_SetDriver ( 0); gpu3D->NDS_3D_Init(); } } // on_menu_tileview_activate(NULL,NULL); /* setup the frame limiter and indicate if it is disabled */ glade_fps_limiter_disabled = my_config->disable_limiter; if ( !glade_fps_limiter_disabled) { /* create the semaphore used for fps limiting */ glade_fps_limiter_semaphore = SDL_CreateSemaphore( 1); /* start a SDL timer for every FPS_LIMITER_FRAME_PERIOD * frames to keep us at 60 fps */ limiter_timer = SDL_AddTimer( 16 * FPS_LIMITER_FRAME_PERIOD, glade_fps_limiter_fn, glade_fps_limiter_semaphore); if ( limiter_timer == NULL) { fprintf( stderr, "Error trying to start FPS limiter timer: %s\n", SDL_GetError()); SDL_DestroySemaphore( glade_fps_limiter_semaphore); glade_fps_limiter_disabled = 1; } } /* start event loop */ gtk_main(); desmume_free(); if ( !glade_fps_limiter_disabled) { /* tidy up the FPS limiter timer and semaphore */ SDL_RemoveTimer( limiter_timer); SDL_DestroySemaphore( glade_fps_limiter_semaphore); } #ifdef DEBUG LogStop(); #endif /* Unload joystick */ uninit_joy(); SDL_Quit(); Write_ConfigFile(); return EXIT_SUCCESS; }