diff --git a/bochs/config.cc b/bochs/config.cc index 5448de96e..667b1d08b 100644 --- a/bochs/config.cc +++ b/bochs/config.cc @@ -43,6 +43,7 @@ #endif +const char **display_library_list; int bochsrc_include_level = 0; #define LOG_THIS genlog-> @@ -227,22 +228,12 @@ void bx_init_usb_options(const char *usb_name, const char *pname, int maxports) void bx_plugin_ctrl_init() { bx_list_c *base = (bx_list_c*) SIM->get_param(BXPN_PLUGIN_CTRL); -#if !BX_PLUGINS - int i = 0; - while (strcmp(bx_builtin_plugins[i].name, "NULL")) { - if (bx_builtin_plugins[i].type == PLUGTYPE_OPTIONAL) { - new bx_param_bool_c(base, bx_builtin_plugins[i].name, "", "", 0); - } - i++; - } -#else const char *name; - int count = bx_get_plugins_count(PLUGTYPE_OPTIONAL); + int count = PLUG_get_plugins_count(PLUGTYPE_OPTIONAL); for (int i = 0; i < count; i++) { - name = bx_get_plugin_name(PLUGTYPE_OPTIONAL, i); + name = PLUG_get_plugin_name(PLUGTYPE_OPTIONAL, i); new bx_param_bool_c(base, name, "", "", 0); } -#endif } void bx_plugin_ctrl_reset(bool init_done) @@ -275,6 +266,28 @@ bool bx_opt_plugin_available(const char *plugname) return (((bx_list_c*)SIM->get_param(BXPN_PLUGIN_CTRL))->get_by_name(plugname) != NULL); } +void bx_init_displaylib_list() +{ + Bit8u i, count = 0; + + count = PLUG_get_plugins_count(PLUGTYPE_GUI); + display_library_list = (const char**) malloc((count + 1) * sizeof(char*)); + for (i = 0; i < count; i++) { + display_library_list[i] = PLUG_get_plugin_name(PLUGTYPE_GUI, i); + } + display_library_list[count] = NULL; + // move default display library to the top of the list + if (strcmp(display_library_list[0], BX_DEFAULT_DISPLAY_LIBRARY)) { + for (i = 1; i < count; i++) { + if (!strcmp(display_library_list[i], BX_DEFAULT_DISPLAY_LIBRARY)) { + display_library_list[i] = display_library_list[0]; + display_library_list[0] = BX_DEFAULT_DISPLAY_LIBRARY; + break; + } + } + } +} + void bx_init_options() { int i; @@ -902,49 +915,7 @@ void bx_init_options() // display subtree bx_list_c *display = new bx_list_c(root_param, "display", "Bochs Display & Interface Options"); - // this is a list of gui libraries that are known to be available at - // compile time. The one that is listed first will be the default, - // which is used unless the user overrides it on the command line or - // in a configuration file. - static const char *display_library_list[] = { -#if BX_WITH_X11 - "x", -#endif -#if BX_WITH_WIN32 - "win32", -#endif -#if BX_WITH_CARBON - "carbon", -#endif -#if BX_WITH_MACOS - "macos", -#endif -#if BX_WITH_AMIGAOS - "amigaos", -#endif -#if BX_WITH_SDL - "sdl", -#endif -#if BX_WITH_SDL2 - "sdl2", -#endif -#if BX_WITH_TERM - "term", -#endif -#if BX_WITH_RFB - "rfb", -#endif -#if BX_WITH_VNCSRV - "vncsrv", -#endif -#if BX_WITH_WX - "wx", -#endif -#if BX_WITH_NOGUI - "nogui", -#endif - NULL - }; + bx_init_displaylib_list(); bx_param_enum_c *sel_displaylib = new bx_param_enum_c(display, "display_library", "VGA Display Library", "Select VGA Display Library", diff --git a/bochs/plugin.cc b/bochs/plugin.cc index dccf6c101..d65f1df2e 100644 --- a/bochs/plugin.cc +++ b/bochs/plugin.cc @@ -1091,6 +1091,35 @@ plugin_t bx_builtin_plugins[] = { {"NULL", PLUGTYPE_GUI, NULL, 0} }; +Bit8u bx_get_plugins_count_np(plugintype_t type) +{ + int i = 0; + Bit8u count = 0; + + while (strcmp(bx_builtin_plugins[i].name, "NULL")) { + if (type == bx_builtin_plugins[i].type) + count++; + i++; + } + return count; +} + +const char* bx_get_plugin_name_np(plugintype_t type, Bit8u index) +{ + int i = 0; + Bit8u count = 0; + + while (strcmp(bx_builtin_plugins[i].name, "NULL")) { + if (type == bx_builtin_plugins[i].type) { + if (count == index) + return bx_builtin_plugins[i].name; + count++; + } + i++; + } + return NULL; +} + int bx_load_plugin_np(const char *name, plugintype_t type) { int i = 0; diff --git a/bochs/plugin.h b/bochs/plugin.h index 522ca780f..665e5a048 100644 --- a/bochs/plugin.h +++ b/bochs/plugin.h @@ -113,10 +113,13 @@ extern "C" { // When plugins are off, PLUG_load_plugin will call the plugin_entry function // directly. #define PLUG_load_plugin(name,type) {lib##name##_plugin_entry(NULL,type,1);} +#define PLUG_unload_plugin(name) {lib##name##_plugin_entry(NULL,type,0);} +// Builtin plugins macros +#define PLUG_get_plugins_count(a) bx_get_plugins_count_np(a) +#define PLUG_get_plugin_name(a,b) bx_get_plugin_name_np(a,b) #define PLUG_load_gui_plugin(name) bx_load_plugin_np(name,PLUGTYPE_GUI) #define PLUG_load_opt_plugin(name) bx_load_plugin_np(name,PLUGTYPE_OPTIONAL) #define PLUG_load_vga_plugin(name) bx_load_plugin_np(name,PLUGTYPE_VGA) -#define PLUG_unload_plugin(name) {lib##name##_plugin_entry(NULL,type,0);} #define PLUG_unload_opt_plugin(name) bx_unload_opt_plugin(name,1) #define DEV_register_ioread_handler(b,c,d,e,f) bx_devices.register_io_read_handler(b,c,d,e,f) @@ -350,6 +353,8 @@ extern void bx_plugins_after_restore_state(void); #if !BX_PLUGINS extern plugin_t bx_builtin_plugins[]; +Bit8u bx_get_plugins_count_np(plugintype_t type); +const char* bx_get_plugin_name_np(plugintype_t type, Bit8u index); int bx_load_plugin_np(const char *name, plugintype_t type); int bx_unload_opt_plugin(const char *name, bool devflag); #endif