- gradually moving toward a set_parameter(param,val) style interface

instead of a set_vga_update_interval(val) style.
This commit is contained in:
Bryce Denney 2001-06-15 23:52:34 +00:00
parent cee98e0033
commit 945b295c4d
3 changed files with 230 additions and 80 deletions

View File

@ -1,6 +1,6 @@
/*
* gui/control.cc
* $Id: control.cc,v 1.17 2001-06-13 15:52:04 bdenney Exp $
* $Id: control.cc,v 1.18 2001-06-15 23:52:34 bdenney Exp $
*
* This is code for a text-mode control panel. Note that this file
* does NOT include bochs.h. Instead, it does all of its contact with
@ -413,9 +413,9 @@ void build_runtime_options_prompt (char *format, char *buf, int size)
cdromop.dev, cdromop.present?"":"not ",
cdromop.inserted?"inserted":"ejected");
snprintf (buf, size, format, buffer[0], buffer[1], buffer[2],
SIM->getips (),
SIM->get_vga_update_interval (),
SIM->get_mouse_enabled () ? "enabled" : "disabled");
SIM->ips->get (),
SIM->vga_update_interval->get (),
SIM->mouse_enabled->get () ? "enabled" : "disabled");
}
// return value of bx_control_panel:
@ -482,7 +482,7 @@ int bx_control_panel (int menu)
if (SIM->get_vga_path (vgapath, CPANEL_PATH_LEN) < 0)
strcpy (vgapath, "none");
sprintf (prompt, startup_mem_options_prompt,
SIM->get_mem_size (),
SIM->memsize->get (),
vgapath, rompath,
SIM->get_rom_address ());
if (ask_int (prompt, 0, 4, 0, &choice) < 0) return -1;
@ -499,11 +499,11 @@ int bx_control_panel (int menu)
case BX_CPANEL_START_OPTS_INTERFACE:
{
char prompt[1024];
int interval = SIM->get_vga_update_interval ();
int interval = SIM->vga_update_interval->get ();
sprintf (prompt, startup_interface_options,
interval,
SIM->get_mouse_enabled () ? "enabled" : "disabled",
SIM->getips (),
SIM->mouse_enabled->get () ? "enabled" : "disabled",
SIM->ips->get (),
SIM->get_private_colormap () ? "enabled" : "disabled");
if (ask_int (prompt, 0, 4, 0, &choice) < 0) return -1;
switch (choice) {
@ -670,32 +670,32 @@ void bx_boot_from ()
void bx_edit_mem ()
{
int newval, oldval = SIM->get_mem_size ();
int newval, oldval = SIM->memsize->get ();
if (ask_int ("How much memory (megabytes) in the simulated machine? [%d] ", 1, 1<<30, oldval, &newval) < 0)
return;
SIM->set_mem_size (newval);
SIM->memsize->set (newval);
}
void bx_ips_change ()
{
char prompt[1024];
int oldips = SIM->getips ();
int oldips = SIM->ips->get ();
sprintf (prompt, "Type a new value for ips: [%d] ", oldips);
int newips;
if (ask_int (prompt, 1, 1<<30, oldips, &newips) < 0)
return;
SIM->setips (newips);
SIM->ips->set (newips);
}
void bx_vga_update_interval ()
{
char prompt[1024];
int old = SIM->get_vga_update_interval ();
int old = SIM->vga_update_interval->get ();
sprintf (prompt, "Type a new value for VGA update interval: [%d] ", old);
int newinterval;
if (ask_int (prompt, 1, 1<<30, old, &newinterval) < 0)
return;
SIM->set_vga_update_interval (newinterval);
SIM->vga_update_interval->set (newinterval);
}
static void bx_print_log_action_table ()
@ -761,10 +761,10 @@ void bx_log_options (int individual)
void bx_mouse_enable ()
{
int newval, oldval = SIM->get_mouse_enabled ();
int newval, oldval = SIM->mouse_enabled->get ();
if (ask_yn ("Enable the mouse? [%s] ", oldval, &newval) < 0) return;
if (newval == oldval) return;
SIM->set_mouse_enabled (newval);
SIM->mouse_enabled->set (newval);
}
int bx_read_rc (char *rc)

View File

@ -1,6 +1,6 @@
/*
* gui/siminterface.cc
* $Id: siminterface.cc,v 1.12 2001-06-13 13:36:12 bdenney Exp $
* $Id: siminterface.cc,v 1.13 2001-06-15 23:52:34 bdenney Exp $
*
* Defines the actual link between bx_simulator_interface_c methods
* and the simulator. This file includes bochs.h because it needs
@ -25,10 +25,6 @@ class bx_real_sim_c : public bx_simulator_interface_c {
#define NOTIFY_TYPE_STRING
public:
bx_real_sim_c ();
virtual int getips ();
virtual void setips (int ips);
virtual int get_vga_update_interval ();
virtual void set_vga_update_interval (unsigned interval);
virtual int get_n_log_modules ();
virtual char *get_prefix (int mod);
virtual int get_log_action (int mod, int level);
@ -37,8 +33,6 @@ public:
virtual char *get_log_level_name (int level);
virtual int get_max_log_level ();
virtual void quit_sim (int clean);
virtual int get_mouse_enabled ();
virtual void set_mouse_enabled (int en);
virtual int get_default_rc (char *path, int len);
virtual int read_rc (char *path);
virtual int write_rc (char *path, int overwrite);
@ -55,8 +49,6 @@ public:
virtual char *get_floppy_type_name (int type);
virtual int get_boot_hard_disk ();
virtual int set_boot_hard_disk (int val);
virtual int get_mem_size ();
virtual int set_mem_size (int megs);
virtual int get_rom_path (char *buf, int len);
virtual int set_rom_path (char *path);
virtual int get_vga_path (char *buf, int len);
@ -72,6 +64,48 @@ public:
virtual int log_msg_2 (char *prefix, int *level, char *msg, int len);
};
Bit32s
multipurpose_handler (bx_param_c *param, int set, Bit32s val)
{
/* this function handles change events on several parameters */
switch (param->get_id ()) {
case BXP_IPS:
if (set)
return (bx_options.ips = val);
else
return bx_options.ips;
case BXP_VGA_UPDATE_INTERVAL:
if (set) {
bx_options.vga_update_interval = val;
if (SIM->get_init_done ())
bx_vga.set_update_interval (val);
return val;
} else {
return bx_options.vga_update_interval;
}
case BXP_MOUSE_ENABLED:
if (set) {
bx_options.mouse_enabled = val;
if (SIM->get_init_done ())
bx_gui.gui_set_mouse_enable (val!=0);
return val;
} else {
return bx_gui.gui_get_mouse_enable ();
}
case BXP_MEM_SIZE:
/* for simple stuff like mem size, you only need this handler because
the memory expects to find the value in bx_options.memory.megs.
If instead it looked for the value here in SIM->memsize, then
no handler is necessary. */
if (set)
return (bx_options.memory.megs = val);
else
return bx_options.memory.megs;
default:
BX_PANIC (("multipurpose_handler called with unknown parameter"));
}
}
void init_siminterface ()
{
siminterface_log = new logfunctions ();
@ -79,6 +113,14 @@ void init_siminterface ()
siminterface_log->settype(CTRLLOG);
if (SIM == NULL)
SIM = new bx_real_sim_c();
SIM->ips = new bx_param_num_c (BXP_IPS, "ips", "Emulated instructions per second, used to calibrate bochs emulated\ntime with wall clock time.", 1, 1<<31, 500000);
SIM->ips->set_handler (multipurpose_handler);
SIM->vga_update_interval = new bx_param_num_c (BXP_VGA_UPDATE_INTERVAL, "vga_update_interval", "Number of microseconds between VGA updates", 1, 1<<31, 30000);
SIM->vga_update_interval->set_handler (multipurpose_handler);
SIM->mouse_enabled = new bx_param_num_c (BXP_MOUSE_ENABLED, "mouse_enabled", "Controls whether the mouse sends events to bochs", 0, 1, 0);
SIM->mouse_enabled->set_handler (multipurpose_handler);
SIM->memsize = new bx_param_num_c (BXP_MEM_SIZE, "megs", "Amount of RAM in megabytes", 1, 1<<31, 4);
SIM->memsize->set_handler (multipurpose_handler);
}
bx_simulator_interface_c::bx_simulator_interface_c ()
@ -91,19 +133,6 @@ bx_real_sim_c::bx_real_sim_c ()
callback = NULL;
}
int
bx_real_sim_c::getips ()
{
return bx_options.ips;
}
void
bx_real_sim_c::setips (int ips)
{
BX_ERROR (("Changing ips during simulation doesn't really work yet. We need to reschedule the timers or something."));
bx_options.ips = ips;
}
int
bx_real_sim_c::get_n_log_modules ()
{
@ -156,28 +185,6 @@ bx_real_sim_c::quit_sim (int clean) {
::exit (0);
}
int
bx_real_sim_c::get_vga_update_interval () {
return bx_options.vga_update_interval;
}
void
bx_real_sim_c::set_vga_update_interval (unsigned interval) {
bx_options.vga_update_interval = interval;
if (get_init_done ())
bx_vga.set_update_interval (interval);
}
int bx_real_sim_c::get_mouse_enabled () {
return bx_gui.gui_get_mouse_enable ();
}
void bx_real_sim_c::set_mouse_enabled (int en) {
bx_options.mouse_enabled = en;
if (get_init_done ())
bx_gui.gui_set_mouse_enable (en!=0);
}
int
bx_real_sim_c::get_default_rc (char *path, int len)
{
@ -315,17 +322,6 @@ bx_real_sim_c::set_boot_hard_disk (int val)
return 0;
}
int
bx_real_sim_c::get_mem_size () {
return bx_options.memory.megs;
}
int
bx_real_sim_c::set_mem_size (int megs) {
bx_options.memory.megs = megs;
return 0;
}
int
bx_real_sim_c::get_rom_path (char *buf, int len)
{
@ -436,4 +432,86 @@ bx_real_sim_c::log_msg_2 (char *prefix, int *level, char *msg, int len)
return 0;
}
/////////////////////////////////////////////////////////////////////////
// new stuff
bx_object_c::bx_object_c (bx_id id)
{
this->id = id;
this->type = BXT_OBJECT;
}
void
bx_object_c::set_type (Bit8u type)
{
this->type = type;
}
bx_param_c::bx_param_c (bx_id id, char *name, char *description)
: bx_object_c (id)
{
set_type (BXT_PARAM);
this->name = name;
this->description = description;
}
bx_param_num_c::bx_param_num_c (bx_id id,
char *name,
char *description,
Bit32s min, Bit32s max, Bit32s initial_val)
: bx_param_c (id, name, description)
{
set_type (BXT_PARAM_NUM);
this->min = min;
this->max = max;
this->initial_val = initial_val;
this->val = initial_val;
this->handler = NULL;
}
void
bx_param_num_c::reset ()
{
this->val = initial_val;
}
Bit32s
bx_param_num_c::get ()
{
int retval = val;
if (handler) {
retval = (*handler)(this, 0, val);
}
return retval;
}
Bit32s
bx_param_num_c::set (Bit32s newval)
{
if (handler)
val = (*handler)(this, 1, newval);
else
val = newval;
return newval;
}
bx_node_c::bx_node_c (bx_id id)
: bx_object_c (id)
{
set_type (BXT_NODE);
car = NULL;
cdr = NULL;
}
bx_node_c::bx_node_c (bx_id id, bx_object_c *car, bx_object_c *cdr)
: bx_object_c (id)
{
set_type (BXT_NODE);
this->car = car;
this->cdr = cdr;
}
#endif // if BX_USE_CONTROL_PANEL==1

View File

@ -1,6 +1,6 @@
/*
* gui/siminterface.h
* $Id: siminterface.h,v 1.8 2001-06-11 20:48:12 bdenney Exp $
* $Id: siminterface.h,v 1.9 2001-06-15 23:52:34 bdenney Exp $
*
* Interface to the simulator, currently only used by control.cc.
* The base class bx_simulator_interface_c, contains only virtual functions
@ -48,6 +48,82 @@ struct bx_cdrom_options
int inserted;
};
/* what do I want to know about an integer parameter?
* id number (comes from enum)
* string name
* description
* minimum and maximum allowed value
* default value
* what about behavior? getValue method and setValue method?
*/
typedef enum {
BXP_IPS = 101,
BXP_VGA_UPDATE_INTERVAL,
BXP_MOUSE_ENABLED,
BXP_MEM_SIZE
} bx_id;
typedef enum {
BXT_OBJECT,
BXT_NODE,
BXT_PARAM,
BXT_PARAM_NUM
} bx_objtype;
class bx_object_c {
private:
bx_id id;
Bit8u type;
protected:
void set_type (Bit8u type);
public:
bx_object_c (bx_id id);
bx_id get_id () { return id; }
Bit8u get_type () { return type; }
};
class bx_param_c : public bx_object_c {
private:
char *name;
char *description;
public:
bx_param_c (bx_id id,
char *name,
char *description);
char *get_name () { return name; }
char *get_description () { return description; }
void reset () {}
};
// make it only handle ints for now
typedef Bit32s (*param_event_handler)(class bx_param_c *, int set, Bit32s val);
class bx_param_num_c : public bx_param_c {
Bit32s min, max, val, initial_val;
param_event_handler handler;
public:
bx_param_num_c (bx_id id,
char *name,
char *description,
Bit32s min, Bit32s max, Bit32s initial_val);
void reset ();
void set_handler (param_event_handler handler) { this->handler = handler; }
Bit32s get ();
Bit32s set (Bit32s val);
};
class bx_node_c : public bx_object_c {
private:
bx_object_c *car, *cdr;
public:
bx_node_c (bx_id id);
bx_node_c (bx_id id, bx_object_c *car, bx_object_c *cdr);
bx_object_c *setcar (bx_object_c *ptr);
bx_object_c *setcdr (bx_object_c *ptr);
bx_object_c *getcar () { return car; }
bx_object_c *getcdr () { return cdr; }
};
class bx_simulator_interface_c {
int init_done;
@ -56,10 +132,10 @@ public:
int get_init_done () { return init_done; }
int set_init_done (int n) { init_done = n; return 0;}
virtual int getips () {return -1;}
virtual void setips (int ips) {}
virtual int get_vga_update_interval () {return -1;}
virtual void set_vga_update_interval (unsigned interval) {}
bx_param_num_c *ips;
bx_param_num_c *vga_update_interval;
bx_param_num_c *mouse_enabled;
bx_param_num_c *memsize;
virtual int get_n_log_modules () {return -1;}
virtual char *get_prefix (int mod) {return 0;}
virtual int get_log_action (int mod, int level) {return -1;}
@ -68,8 +144,6 @@ public:
virtual char *get_log_level_name (int level) {return 0;}
virtual int get_max_log_level () {return -1;}
virtual void quit_sim (int clean) {}
virtual int get_mouse_enabled () {return -1;}
virtual void set_mouse_enabled (int en) {}
virtual int get_default_rc (char *path, int len) {return -1;}
virtual int read_rc (char *path) {return -1;}
virtual int write_rc (char *rc, int overwrite) {return -1;}
@ -86,8 +160,6 @@ public:
virtual char *get_floppy_type_name (int type) {return NULL;}
virtual int get_boot_hard_disk () {return -1;}
virtual int set_boot_hard_disk (int val) {return -1;}
virtual int get_mem_size () {return -1;}
virtual int set_mem_size (int megs) {return -1;}
virtual int get_rom_path (char *buf, int len) {return -1;}
virtual int set_rom_path (char *path) {return -1;}
virtual int get_vga_path (char *buf, int len) {return -1;}