From f3a6fbd235989c5c0a89b10b3f4da5afd502a22c Mon Sep 17 00:00:00 2001
From: Volker Ruppert <Volker.Ruppert@t-online.de>
Date: Mon, 25 Nov 2013 21:07:39 +0000
Subject: [PATCH] Simplified setup of special runtime menus / dialogs - If the
 runtime flag of a bx_list_c object is set, all it's items are set up   as
 runtime options. - Set the runtime parameter for all top-level runtime-only
 lists. Setting up   each single parameter is no longer needed.

---
 bochs/config.cc                |  6 ++++--
 bochs/gui/paramtree.cc         | 15 +++++++++++++++
 bochs/gui/paramtree.h          |  3 ++-
 bochs/gui/textconfig.cc        |  2 +-
 bochs/iodev/display/vgacore.cc |  1 -
 bochs/iodev/harddrv.cc         |  9 ++++-----
 bochs/iodev/keyboard.cc        |  4 +---
 bochs/iodev/sound/sb16.cc      |  7 -------
 bochs/iodev/sound/sb16.h       |  2 +-
 bochs/iodev/usb/usb_hub.cc     | 10 +++-------
 bochs/iodev/usb/usb_msd.cc     |  3 ---
 bochs/iodev/usb/usb_ohci.cc    | 14 +++++---------
 bochs/iodev/usb/usb_uhci.cc    | 14 +++++---------
 bochs/iodev/usb/usb_xhci.cc    | 14 +++++---------
 14 files changed, 46 insertions(+), 58 deletions(-)

diff --git a/bochs/config.cc b/bochs/config.cc
index 1cb09ce5f..49b69c1c5 100644
--- a/bochs/config.cc
+++ b/bochs/config.cc
@@ -999,12 +999,11 @@ void bx_init_options()
   deplist->add(keymap);
   use_kbd_mapping->set_dependent_list(deplist);
 
-  bx_param_string_c *user_shortcut = new bx_param_string_c(keyboard,
+  new bx_param_string_c(keyboard,
       "user_shortcut",
       "Userbutton shortcut",
       "Defines the keyboard shortcut to be sent when you press the 'user' button in the headerbar.",
       "none", 20);
-  user_shortcut->set_runtime_param(1);
 
   static const char *mouse_type_list[] = {
     "none",
@@ -1599,11 +1598,14 @@ void bx_init_options()
   // runtime options
   menu = new bx_list_c(special_menus, "runtime", "Runtime options");
   bx_list_c *cdrom = new bx_list_c(menu, "cdrom", "CD-ROM options");
+  cdrom->set_runtime_param(1);
   cdrom->set_options(cdrom->SHOW_PARENT);
   usb = new bx_list_c(menu, "usb", "USB options");
+  usb->set_runtime_param(1);
   usb->set_options(usb->SHOW_PARENT | usb->USE_TAB_WINDOW);
   // misc runtime options
   misc = new bx_list_c(menu, "misc", "Misc options");
+  misc->set_runtime_param(1);
   misc->add(SIM->get_param(BXPN_VGA_UPDATE_FREQUENCY));
   misc->add(SIM->get_param(BXPN_MOUSE_ENABLED));
   misc->add(SIM->get_param(BXPN_KBD_PASTE_DELAY));
diff --git a/bochs/gui/paramtree.cc b/bochs/gui/paramtree.cc
index 7b86df9e3..67ddc7f8d 100644
--- a/bochs/gui/paramtree.cc
+++ b/bochs/gui/paramtree.cc
@@ -1023,6 +1023,9 @@ void bx_list_c::add(bx_param_c *param)
       temp = temp->next;
     temp->next = item;
   }
+  if (runtime_param) {
+    param->set_runtime_param(1);
+  }
   size++;
 }
 
@@ -1101,3 +1104,15 @@ void bx_list_c::remove(const char *name)
     }
   }
 }
+
+void bx_list_c::set_runtime_param(int val)
+{
+  bx_listitem_t *item;
+
+  runtime_param = val;
+  if (runtime_param) {
+    for (item = list; item; item = item->next) {
+      item->param->set_runtime_param(1);
+    }
+  }
+}
diff --git a/bochs/gui/paramtree.h b/bochs/gui/paramtree.h
index 610f68ca4..054a8cbe6 100644
--- a/bochs/gui/paramtree.h
+++ b/bochs/gui/paramtree.h
@@ -130,7 +130,7 @@ public:
   void set_label(const char *text);
   void set_description(const char *text);
   const char *get_label() const {return label;}
-  void set_runtime_param(int val) { runtime_param = val; }
+  virtual void set_runtime_param(int val) { runtime_param = val; }
   int get_runtime_param() { return runtime_param; }
   void set_group(const char *group);
   const char *get_group() const {return group_name;}
@@ -499,6 +499,7 @@ public:
   virtual void reset();
   virtual void clear();
   virtual void remove(const char *name);
+  virtual void set_runtime_param(int val);
 #if BX_USE_TEXTCONFIG
   virtual void text_print(FILE *);
   virtual int text_ask(FILE *fpin, FILE *fpout);
diff --git a/bochs/gui/textconfig.cc b/bochs/gui/textconfig.cc
index ef608f91d..6d06e8104 100644
--- a/bochs/gui/textconfig.cc
+++ b/bochs/gui/textconfig.cc
@@ -537,7 +537,7 @@ int bx_config_interface(int menu)
             case BX_CI_RT_LOGOPTS1: bx_log_options(0); break;
             case BX_CI_RT_LOGOPTS2: bx_log_options(1); break;
             case BX_CI_RT_INST_TR: NOT_IMPLEMENTED(choice); break;
-            case BX_CI_RT_USB: do_menu(BXPN_MENU_RUNTIME_USB); break;
+            case BX_CI_RT_USB: do_menu(BXPN_MENU_RUNTIME_CDROM); break;
             case BX_CI_RT_MISC: do_menu(BXPN_MENU_RUNTIME_MISC); break;
             case BX_CI_RT_CONT:
               SIM->update_runtime_options();
diff --git a/bochs/iodev/display/vgacore.cc b/bochs/iodev/display/vgacore.cc
index 28eb4b21f..49e554e27 100644
--- a/bochs/iodev/display/vgacore.cc
+++ b/bochs/iodev/display/vgacore.cc
@@ -266,7 +266,6 @@ void bx_vgacore_c::init_systemtimer(bx_timer_handler_t f_timer, param_event_hand
     BX_VGA_THIS timer_id = bx_virt_timer.register_timer(this, f_timer,
        BX_VGA_THIS update_interval, 1, 1, "vga");
     vga_update_freq->set_handler(f_param);
-    vga_update_freq->set_runtime_param(1);
   }
   // VGA text mode cursor blink frequency 1.875 Hz
   if (BX_VGA_THIS update_interval < 266666) {
diff --git a/bochs/iodev/harddrv.cc b/bochs/iodev/harddrv.cc
index 76c114cd0..8b80c90b2 100644
--- a/bochs/iodev/harddrv.cc
+++ b/bochs/iodev/harddrv.cc
@@ -343,13 +343,12 @@ void bx_hard_drive_c::init(void)
         }
       } else if (SIM->get_param_enum("type", base)->get() == BX_ATA_DEVICE_CDROM) {
         bx_list_c *cdrom_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_CDROM);
-        cdrom_rt->add(base);
-        base->set_options(base->SERIES_ASK | base->USE_BOX_TITLE);
-        base->set_runtime_param(1);
+        bx_list_c *menu = new bx_list_c(cdrom_rt, base->get_name(), base->get_title());
+        menu->set_options(menu->SERIES_ASK | menu->USE_BOX_TITLE);
+        menu->add(SIM->get_param("path", base));
+        menu->add(SIM->get_param("status", base));
         SIM->get_param_string("path", base)->set_handler(cdrom_path_handler);
-        SIM->get_param("path", base)->set_runtime_param(1);
         SIM->get_param_enum("status", base)->set_handler(cdrom_status_handler);
-        SIM->get_param("status", base)->set_runtime_param(1);
         BX_DEBUG(("CDROM on target %d/%d",channel,device));
         BX_HD_THIS channels[channel].drives[device].device_type = IDE_CDROM;
         BX_HD_THIS channels[channel].drives[device].cdrom.locked = 0;
diff --git a/bochs/iodev/keyboard.cc b/bochs/iodev/keyboard.cc
index 03770fcea..5e3b1c8e4 100644
--- a/bochs/iodev/keyboard.cc
+++ b/bochs/iodev/keyboard.cc
@@ -2,7 +2,7 @@
 // $Id$
 /////////////////////////////////////////////////////////////////////////
 //
-//  Copyright (C) 2002-2009  The Bochs Project
+//  Copyright (C) 2002-2013  The Bochs Project
 //
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU Lesser General Public
@@ -211,9 +211,7 @@ void bx_keyb_c::init(void)
 
   // init runtime parameter
   SIM->get_param_num(BXPN_KBD_PASTE_DELAY)->set_handler(kbd_param_handler);
-  SIM->get_param_num(BXPN_KBD_PASTE_DELAY)->set_runtime_param(1);
   SIM->get_param_num(BXPN_MOUSE_ENABLED)->set_handler(kbd_param_handler);
-  SIM->get_param_num(BXPN_MOUSE_ENABLED)->set_runtime_param(1);
 }
 
 void bx_keyb_c::reset(unsigned type)
diff --git a/bochs/iodev/sound/sb16.cc b/bochs/iodev/sound/sb16.cc
index 74a80d9b7..17d6046c6 100644
--- a/bochs/iodev/sound/sb16.cc
+++ b/bochs/iodev/sound/sb16.cc
@@ -383,7 +383,6 @@ void bx_sb16_c::init(void)
   bx_list_c *misc_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_MISC);
   bx_list_c *menu = new bx_list_c(misc_rt, "sb16", "SB16 Runtime Options");
   menu->set_options(menu->SHOW_PARENT | menu->USE_BOX_TITLE);
-  menu->set_runtime_param(1);
 
   menu->add(SIM->get_param("wavemode", base));
   menu->add(SIM->get_param("wave", base));
@@ -392,17 +391,11 @@ void bx_sb16_c::init(void)
   menu->add(SIM->get_param("dmatimer", base));
   menu->add(SIM->get_param("loglevel", base));
   SIM->get_param_enum("wavemode", base)->set_handler(sb16_param_handler);
-  SIM->get_param_enum("wavemode", base)->set_runtime_param(1);
   SIM->get_param_string("wave", base)->set_handler(sb16_param_string_handler);
-  SIM->get_param_string("wave", base)->set_runtime_param(1);
   SIM->get_param_num("midimode", base)->set_handler(sb16_param_handler);
-  SIM->get_param_num("midimode", base)->set_runtime_param(1);
   SIM->get_param_string("midi", base)->set_handler(sb16_param_string_handler);
-  SIM->get_param_string("midi", base)->set_runtime_param(1);
   SIM->get_param_num("dmatimer", base)->set_handler(sb16_param_handler);
-  SIM->get_param_num("dmatimer", base)->set_runtime_param(1);
   SIM->get_param_num("loglevel", base)->set_handler(sb16_param_handler);
-  SIM->get_param_num("loglevel", base)->set_runtime_param(1);
   // register handler for correct sb16 parameter handling after runtime config
   SIM->register_runtime_config_handler(this, runtime_config_handler);
   BX_SB16_THIS midi_changed = 0;
diff --git a/bochs/iodev/sound/sb16.h b/bochs/iodev/sound/sb16.h
index c69b327d2..64571c52b 100644
--- a/bochs/iodev/sound/sb16.h
+++ b/bochs/iodev/sound/sb16.h
@@ -2,7 +2,7 @@
 // $Id$
 /////////////////////////////////////////////////////////////////////////
 //
-//  Copyright (C) 2001-2011  The Bochs Project
+//  Copyright (C) 2001-2013  The Bochs Project
 //
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU Lesser General Public
diff --git a/bochs/iodev/usb/usb_hub.cc b/bochs/iodev/usb/usb_hub.cc
index b6def0b66..f58e96fde 100644
--- a/bochs/iodev/usb/usb_hub.cc
+++ b/bochs/iodev/usb/usb_hub.cc
@@ -5,7 +5,7 @@
 // USB hub emulation support (ported from QEMU)
 //
 // Copyright (C) 2005       Fabrice Bellard
-// Copyright (C) 2009-2012  The Bochs Project
+// Copyright (C) 2009-2013  The Bochs Project
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal
@@ -172,7 +172,7 @@ usb_hub_device_c::usb_hub_device_c(Bit8u ports)
   char pname[10];
   char label[32];
   bx_list_c *port;
-  bx_param_string_c *device, *options;
+  bx_param_string_c *device;
 
   d.type = USB_DEV_TYPE_HUB;
   d.maxspeed = USB_SPEED_FULL;
@@ -195,19 +195,15 @@ usb_hub_device_c::usb_hub_device_c(Bit8u ports)
   sprintf(label, "External Hub #%d Configuration", hub_count);
   hub.config = new bx_list_c(usb_rt, pname, label);
   hub.config->set_options(bx_list_c::SHOW_PARENT);
-  hub.config->set_runtime_param(1);
   hub.config->set_device_param(this);
   for(i = 0; i < hub.n_ports; i++) {
     sprintf(pname, "port%d", i+1);
     sprintf(label, "Port #%d Configuration", i+1);
     port = new bx_list_c(hub.config, pname, label);
     port->set_options(port->SERIES_ASK | port->USE_BOX_TITLE);
-    port->set_runtime_param(1);
     device = new bx_param_string_c(port, "device", "Device", "", "", BX_PATHNAME_LEN);
     device->set_handler(hub_param_handler);
-    device->set_runtime_param(1);
-    options = new bx_param_string_c(port, "options", "Options", "", "", BX_PATHNAME_LEN);
-    options->set_runtime_param(1);
+    new bx_param_string_c(port, "options", "Options", "", "", BX_PATHNAME_LEN);
   }
 #if BX_WITH_WX
   bx_list_c *usb = (bx_list_c*)SIM->get_param("ports.usb");
diff --git a/bochs/iodev/usb/usb_msd.cc b/bochs/iodev/usb/usb_msd.cc
index 13ec53266..bb8b64546 100644
--- a/bochs/iodev/usb/usb_msd.cc
+++ b/bochs/iodev/usb/usb_msd.cc
@@ -171,12 +171,10 @@ usb_msd_device_c::usb_msd_device_c(usbdev_type type, const char *filename)
     sprintf(label, "USB CD-ROM #%d Configuration", usb_cdrom_count);
     s.config = new bx_list_c(usb_rt, pname, label);
     s.config->set_options(bx_list_c::SERIES_ASK | bx_list_c::USE_BOX_TITLE);
-    s.config->set_runtime_param(1);
     s.config->set_device_param(this);
     path = new bx_param_string_c(s.config, "path", "Path", "", "", BX_PATHNAME_LEN);
     path->set(s.fname);
     path->set_handler(cd_param_string_handler);
-    path->set_runtime_param(1);
     status = new bx_param_enum_c(s.config,
       "status",
       "Status",
@@ -185,7 +183,6 @@ usb_msd_device_c::usb_msd_device_c(usbdev_type type, const char *filename)
       BX_EJECTED,
       BX_EJECTED);
     status->set_handler(cd_param_handler);
-    status->set_runtime_param(1);
     status->set_ask_format("Is the device inserted or ejected? [%s] ");
 #if BX_WITH_WX
     bx_list_c *usb = (bx_list_c*)SIM->get_param("ports.usb");
diff --git a/bochs/iodev/usb/usb_ohci.cc b/bochs/iodev/usb/usb_ohci.cc
index 5a260f4ee..a7e3d5ee4 100644
--- a/bochs/iodev/usb/usb_ohci.cc
+++ b/bochs/iodev/usb/usb_ohci.cc
@@ -3,7 +3,7 @@
 /////////////////////////////////////////////////////////////////////////
 //
 //  Copyright (C) 2009       Benjamin D Lunt (fys at frontiernet net)
-//                2009-2012  The Bochs Project
+//                2009-2013  The Bochs Project
 //
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU Lesser General Public
@@ -160,7 +160,7 @@ void bx_usb_ohci_c::init(void)
   unsigned i;
   char pname[6];
   bx_list_c *ohci, *port;
-  bx_param_string_c *device, *options;
+  bx_param_string_c *device;
 
   // Read in values from config interface
   ohci = (bx_list_c*) SIM->get_param(BXPN_USB_OHCI);
@@ -196,18 +196,14 @@ void bx_usb_ohci_c::init(void)
   BX_OHCI_THIS hub.statusbar_id = bx_gui->register_statusitem("OHCI", 1);
 
   bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB);
-  ohci->set_options(ohci->SHOW_PARENT);
-  ohci->set_runtime_param(1);
-  usb_rt->add(ohci);
+  bx_list_c *ohci_rt = new bx_list_c(usb_rt, "ohci", "OHCI Runtime Options");
+  ohci_rt->set_options(ohci_rt->SHOW_PARENT);
   for (i=0; i<BX_N_USB_OHCI_PORTS; i++) {
     sprintf(pname, "port%d", i+1);
     port = (bx_list_c*)SIM->get_param(pname, ohci);
-    port->set_runtime_param(1);
+    ohci_rt->add(port);
     device = (bx_param_string_c*)port->get_by_name("device");
     device->set_handler(usb_param_handler);
-    device->set_runtime_param(1);
-    options = (bx_param_string_c*)port->get_by_name("options");
-    options->set_runtime_param(1);
     BX_OHCI_THIS hub.usb_port[i].device = NULL;
     BX_OHCI_THIS hub.usb_port[i].HcRhPortStatus.ccs = 0;
     BX_OHCI_THIS hub.usb_port[i].HcRhPortStatus.csc = 0;
diff --git a/bochs/iodev/usb/usb_uhci.cc b/bochs/iodev/usb/usb_uhci.cc
index a069ae184..9f861fbd2 100644
--- a/bochs/iodev/usb/usb_uhci.cc
+++ b/bochs/iodev/usb/usb_uhci.cc
@@ -3,7 +3,7 @@
 /////////////////////////////////////////////////////////////////////////
 //
 //  Copyright (C) 2009       Benjamin D Lunt (fys at frontiernet net)
-//                2009-2012  The Bochs Project
+//                2009-2013  The Bochs Project
 //
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU Lesser General Public
@@ -147,7 +147,7 @@ void bx_usb_uhci_c::init(void)
   unsigned i;
   char pname[6];
   bx_list_c *uhci, *port;
-  bx_param_string_c *device, *options;
+  bx_param_string_c *device;
 
   // Read in values from config interface
   uhci = (bx_list_c*) SIM->get_param(BXPN_USB_UHCI);
@@ -184,18 +184,14 @@ void bx_usb_uhci_c::init(void)
   BX_UHCI_THIS hub.statusbar_id = bx_gui->register_statusitem("UHCI", 1);
 
   bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB);
-  uhci->set_options(uhci->SHOW_PARENT);
-  uhci->set_runtime_param(1);
-  usb_rt->add(uhci);
+  bx_list_c *uhci_rt = new bx_list_c(usb_rt, "uhci", "UHCI Runtime Options");
+  uhci_rt->set_options(uhci_rt->SHOW_PARENT);
   for (i=0; i<BX_N_USB_UHCI_PORTS; i++) {
     sprintf(pname, "port%d", i+1);
     port = (bx_list_c*)SIM->get_param(pname, uhci);
-    port->set_runtime_param(1);
+    uhci_rt->add(port);
     device = (bx_param_string_c*)port->get_by_name("device");
     device->set_handler(usb_param_handler);
-    device->set_runtime_param(1);
-    options = (bx_param_string_c*)port->get_by_name("options");
-    options->set_runtime_param(1);
     BX_UHCI_THIS hub.usb_port[i].device = NULL;
   }
 
diff --git a/bochs/iodev/usb/usb_xhci.cc b/bochs/iodev/usb/usb_xhci.cc
index 170afc112..d37a98281 100644
--- a/bochs/iodev/usb/usb_xhci.cc
+++ b/bochs/iodev/usb/usb_xhci.cc
@@ -3,7 +3,7 @@
 /////////////////////////////////////////////////////////////////////////
 //
 //  Copyright (C) 2010-2011  Benjamin D Lunt (fys [at] fysnet [dot] net)
-//                2011-2012  The Bochs Project
+//                2011-2013  The Bochs Project
 //
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU Lesser General Public
@@ -190,9 +190,8 @@ void bx_usb_xhci_c::init(void)
   BX_XHCI_THIS hub.statusbar_id = bx_gui->register_statusitem("xHCI", 1);
 
   bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB);
-  xhci->set_options(xhci->SHOW_PARENT | xhci->USE_BOX_TITLE);
-  xhci->set_runtime_param(1);
-  usb_rt->add(xhci);
+  bx_list_c *xhci_rt = new bx_list_c(usb_rt, "xhci", "xHCI Runtime Options");
+  xhci_rt->set_options(xhci_rt->SHOW_PARENT | xhci_rt->USE_BOX_TITLE);
   for (i=0; i<USB_XHCI_PORTS; i++) {
     // check to see if the speed matches the port given
 //    if (((get_speed(i) <= SPEED_HI)    && (port_speed_allowed[i] != USB2)) ||
@@ -200,12 +199,9 @@ void bx_usb_xhci_c::init(void)
 //        BX_PANIC(("Speed of port given in Bochsrc.txt file doesn't match controllers' port's speed."));
     sprintf(pname, "port%d", i+1);
     port = (bx_list_c*)SIM->get_param(pname, xhci);
-    port->set_runtime_param(1);
+    xhci_rt->add(port);
     device = (bx_param_string_c*)port->get_by_name("device"); 
-    device->set_handler(usb_param_handler); 
-    device->set_runtime_param(1); 
-    options = (bx_param_string_c*)port->get_by_name("options"); 
-    options->set_runtime_param(1); 
+    device->set_handler(usb_param_handler);
     BX_XHCI_THIS hub.usb_port[i].device = NULL;
     BX_XHCI_THIS hub.usb_port[i].portsc.ccs = 0;
     BX_XHCI_THIS hub.usb_port[i].portsc.csc = 0;