Fixed parameter handler issues found with runtime changes while cdrom tray locked.

- bx_param_num_c: set the value returned from the handler.
- bx_param_string_c: set the new value after processing the handler.
- harddrv param handler: check lock state of cdrom and modify value if true.
This commit is contained in:
Volker Ruppert 2015-08-10 18:44:16 +00:00
parent 8a1e31ef08
commit 16fb8317bd
2 changed files with 20 additions and 7 deletions

View File

@ -232,8 +232,7 @@ void bx_param_num_c::set(Bit64s newval)
{
if (handler) {
// the handler can override the new value and/or perform some side effect
val.number = newval;
(*handler)(this, 1, newval);
val.number = (*handler)(this, 1, newval);
} else {
// just set the value. This code does not check max/min.
val.number = newval;
@ -790,17 +789,20 @@ void bx_param_string_c::set(const char *buf)
if (options & RAW_BYTES) {
memcpy(oldval, val, maxsize);
memcpy(val, buf, maxsize);
} else {
strncpy(oldval, val, maxsize);
oldval[maxsize - 1] = 0;
strncpy(val, buf, maxsize);
val[maxsize - 1] = 0;
}
if (handler) {
// the handler can return a different char* to be copied into the value
buf = (*handler)(this, 1, oldval, buf, -1);
}
if (options & RAW_BYTES) {
memcpy(val, buf, maxsize);
} else {
strncpy(val, buf, maxsize);
val[maxsize - 1] = 0;
}
delete [] oldval;
if (dependent_list != NULL) update_dependents();
}

View File

@ -3543,7 +3543,13 @@ Bit64s bx_hard_drive_c::cdrom_status_handler(bx_param_c *param, int set, Bit64s
int handle = get_device_handle_from_param(param);
if (handle >= 0) {
if (!strcmp(param->get_name(), "status")) {
BX_HD_THIS channels[handle/2].drives[handle%2].status_changed = 1;
bx_bool locked = BX_HD_THIS channels[handle/2].drives[handle%2].cdrom.locked;
if ((val == 1) || !locked) {
BX_HD_THIS channels[handle/2].drives[handle%2].status_changed = 1;
} else if (locked) {
BX_ERROR(("cdrom tray locked: eject failed"));
return BX_INSERTED;
}
}
} else {
BX_PANIC(("cdrom_status_handler called with unexpected parameter '%s'", param->get_name()));
@ -3562,7 +3568,12 @@ const char *bx_hard_drive_c::cdrom_path_handler(bx_param_string_c *param, int se
int handle = get_device_handle_from_param(param);
if (handle >= 0) {
if (!strcmp(param->get_name(), "path")) {
BX_HD_THIS channels[handle/2].drives[handle%2].status_changed = 1;
if (!BX_HD_THIS channels[handle/2].drives[handle%2].cdrom.locked) {
BX_HD_THIS channels[handle/2].drives[handle%2].status_changed = 1;
} else {
val = oldval;
BX_ERROR(("cdrom tray locked: path change failed"));
}
}
} else {
BX_PANIC(("cdrom_path_handler called with unexpected parameter '%s'", param->get_name()));