[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bochs-cvs
Subject:    [Bochs-cvs] [12816] trunk/bochs/iodev/usb
From:       vruppert () users ! sourceforge ! net
Date:       2015-08-30 8:37:27
Message-ID: E1ZVy7H-0002F9-40 () sfs-ml-3 ! v29 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 12816
Author:   vruppert
Date:     2015-08-30 08:37:27 +0000 (Sun, 30 Aug 2015)
Log Message:
-----------
Added framework for USB floppy media change support based on the USB cdrom
code (not yet functional).
Minor related changes in the USB cdrom code.

Modified Paths:
--------------
    trunk/bochs/iodev/usb/usb_cbi.cc
    trunk/bochs/iodev/usb/usb_cbi.h
    trunk/bochs/iodev/usb/usb_msd.cc

Modified: trunk/bochs/iodev/usb/usb_cbi.cc
===================================================================
--- trunk/bochs/iodev/usb/usb_cbi.cc	2015-08-29 14:02:13 UTC (rev 12815)
+++ trunk/bochs/iodev/usb/usb_cbi.cc	2015-08-30 08:37:27 UTC (rev 12816)
@@ -276,10 +276,19 @@
   0x00, 0x00, 0x00  // reserved
 };
 
+void usb_cbi_restore_handler(void *dev, bx_list_c *conf);
+
+static int usb_floppy_count = 0;
+
 usb_cbi_device_c::usb_cbi_device_c(const char *filename)
 {
+  char pname[10];
+  char label[32];
   char tmpfname[BX_PATHNAME_LEN];
   char *ptr1, *ptr2;
+  bx_param_string_c *path;
+  bx_param_bool_c *readonly;
+  bx_param_enum_c *status;
 
   d.type = USB_DEV_TYPE_FLOPPY;
   d.maxspeed = USB_SPEED_FULL;
@@ -301,9 +310,38 @@
       BX_PANIC(("USB floppy only supports image modes 'flat' and 'vvfat'"));
     }
   }
-
   s.dev_buffer = NULL;
-  s.statusbar_id = -1;
+  s.statusbar_id = bx_gui->register_statusitem("USB-FD", 1);
+// config options
+  bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB);
+  sprintf(pname, "floppy%d", ++usb_floppy_count);
+  sprintf(label, "USB floppy #%d Configuration", usb_floppy_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_device_param(this);
+  path = new bx_param_string_c(s.config, "path", "Path", "", "", BX_PATHNAME_LEN);
+  path->set(s.fname);
+  path->set_handler(floppy_path_handler);
+  readonly = new bx_param_bool_c(s.config,
+    "readonly",
+    "Write Protection",
+    "Floppy media write protection",
+    0);
+  readonly->set_handler(floppy_param_handler);
+  readonly->set_ask_format("Is media write protected? [%s] ");
+  status = new bx_param_enum_c(s.config,
+    "status",
+    "Status",
+    "Floppy media status (inserted / ejected)",
+    media_status_names,
+    BX_INSERTED,
+    BX_EJECTED);
+  status->set_handler(floppy_param_handler);
+  status->set_ask_format("Is the device inserted or ejected? [%s] ");
+  if (SIM->is_wx_selected()) {
+    bx_list_c *usb = (bx_list_c*)SIM->get_param("ports.usb");
+    usb->add(s.config);
+  }
 
   put("usb_cbi", "USBCBI");
 }
@@ -317,12 +355,19 @@
     if (s.inserted) s.hdimage->close();
     delete s.hdimage;
   }
+  if (SIM->is_wx_selected()) {
+    bx_list_c *usb = (bx_list_c*)SIM->get_param("ports.usb");
+    usb->remove(s.config->get_name());
+  }
+  bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB);
+  usb_rt->remove(s.config->get_name());
 }
 
 bx_bool usb_cbi_device_c::set_option(const char *option)
 {
   if (!strncmp(option, "write_protected:", 16)) {
     s.wp = atol(&option[16]);
+    SIM->get_param_bool("readonly", s.config)->set(s.wp);
     return 1;
   } else if (!strncmp(option, "model:", 6)) {
     if (!strcmp(option+6, "teac")) {
@@ -343,6 +388,7 @@
       BX_ERROR(("could not open floppy image file '%s'", s.fname));
     } else {
       s.inserted = 1;
+      SIM->get_param_enum("status", s.config)->set(BX_INSERTED);
     }
   }
   if (s.inserted) {
@@ -353,9 +399,9 @@
   d.connected = 1;
   s.dev_buffer = new Bit8u[CBI_MAX_SECTORS * 512];
 
-  s.statusbar_id = bx_gui->register_statusitem("USB-FD", 1);
   s.did_inquiry_fail = 0;
   s.fail_count = 0;
+  s.status_changed = 0;
 
   return 1;
 }
@@ -382,6 +428,11 @@
 void usb_cbi_device_c::register_state_specific(bx_list_c *parent)
 {
   bx_list_c *list = new bx_list_c(parent, "s", "UFI/CBI Floppy Disk State");
+  bx_list_c *rt_config = new bx_list_c(list, "rt_config");
+  rt_config->add(s.config->get_by_name("path"));
+  rt_config->add(s.config->get_by_name("readonly"));
+  rt_config->add(s.config->get_by_name("status"));
+  rt_config->set_restore_handler(this, usb_cbi_restore_handler);
   new bx_shadow_num_c(list, "usb_len", &s.usb_len);
   new bx_shadow_num_c(list, "data_len", &s.data_len);
   new bx_shadow_num_c(list, "sector_count", &s.sector_count);
@@ -904,4 +955,60 @@
   s.packet = NULL;
 }
 
+void usb_cbi_device_c::runtime_config(void)
+{
+  if (s.status_changed) {
+    // TODO
+    s.status_changed = 0;
+  }
+}
+
+#undef LOG_THIS
+#define LOG_THIS floppy->
+
+// USB floppy runtime parameter handlers
+const char *usb_cbi_device_c::floppy_path_handler(bx_param_string_c *param, int set,
+                                                  const char *oldval, const char *val, int maxlen)
+{
+  usb_cbi_device_c *floppy;
+
+  if (set) {
+    if (strlen(val) < 1) {
+      val = "none";
+    }
+    floppy = (usb_cbi_device_c*) param->get_parent()->get_device_param();
+    if (floppy != NULL) {
+      floppy->s.status_changed = 1;
+    } else {
+      BX_PANIC(("floppy_path_handler: floppy not found"));
+    }
+  }
+  return val;
+}
+
+Bit64s usb_cbi_device_c::floppy_param_handler(bx_param_c *param, int set, Bit64s val)
+{
+  usb_cbi_device_c *floppy;
+
+  if (set) {
+    floppy = (usb_cbi_device_c*) param->get_parent()->get_device_param();
+    if (floppy != NULL) {
+      floppy->s.status_changed = 1;
+    } else {
+      BX_PANIC(("floppy_status_handler: floppy not found"));
+    }
+  }
+  return val;
+}
+
+void usb_cbi_restore_handler(void *dev, bx_list_c *conf)
+{
+  ((usb_cbi_device_c*)dev)->restore_handler(conf);
+}
+
+void usb_cbi_device_c::restore_handler(bx_list_c *conf)
+{
+  runtime_config();
+}
+
 #endif // BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB

Modified: trunk/bochs/iodev/usb/usb_cbi.h
===================================================================
--- trunk/bochs/iodev/usb/usb_cbi.h	2015-08-29 14:02:13 UTC (rev 12815)
+++ trunk/bochs/iodev/usb/usb_cbi.h	2015-08-30 08:37:27 UTC (rev 12816)
@@ -55,6 +55,8 @@
   virtual bx_bool init();
   virtual bx_bool set_option(const char *option);
   virtual const char* get_info();
+  virtual void runtime_config(void);
+  void restore_handler(bx_list_c *conf);
 
   virtual void handle_reset();
   virtual int handle_control(int request, int value, int index, int length, Bit8u *data);
@@ -77,6 +79,7 @@
     device_image_t *hdimage;
     USBPacket *packet;
     const char *fname;
+    bx_list_c *config;
     char info_txt[BX_PATHNAME_LEN];
     Bit8u cur_command;
     int fail_count;
@@ -85,7 +88,12 @@
     bx_bool wp;     // 0 = not write_protected, 1 = write_protected
     bx_bool model;  // 0 = bochs, 1 = teac
     int statusbar_id;
+    bx_bool status_changed;
   } s;
+
+  static const char *floppy_path_handler(bx_param_string_c *param, int set,
+                                         const char *oldval, const char *val, int maxlen);
+  static Bit64s floppy_param_handler(bx_param_c *param, int set, Bit64s val);
 };
 
 #endif

Modified: trunk/bochs/iodev/usb/usb_msd.cc
===================================================================
--- trunk/bochs/iodev/usb/usb_msd.cc	2015-08-29 14:02:13 UTC (rev 12815)
+++ trunk/bochs/iodev/usb/usb_msd.cc	2015-08-30 08:37:27 UTC (rev 12816)
@@ -385,6 +385,7 @@
   s.scsi_dev->register_state(s.sr_list, "scsidev");
   s.mode = USB_MSDM_CBW;
   d.connected = 1;
+  s.status_changed = 0;
   return 1;
 }
 
@@ -903,9 +904,9 @@
 #undef LOG_THIS
 #define LOG_THIS cdrom->
 
-// USB hub runtime parameter handlers
+// USB cdrom runtime parameter handlers
 const char *usb_msd_device_c::cdrom_path_handler(bx_param_string_c *param, int set,
-                                                      const char *oldval, const char *val, int maxlen)
+                                                 const char *oldval, const char *val, int maxlen)
 {
   usb_msd_device_c *cdrom;
 


------------------------------------------------------------------------------
_______________________________________________
Bochs-cvs mailing list
Bochs-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bochs-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic