From 924201f69482773b3c5e0ece5371ace96db86abd Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Fri, 13 Mar 2015 21:28:40 +0000 Subject: [PATCH] Added capability to handle floating point values with save/restore. Improved OPL3 save/restore support. --- bochs/gui/paramtree.cc | 15 ++++++++++++++- bochs/gui/paramtree.h | 9 +++++++-- bochs/gui/siminterface.cc | 14 ++++++++++++-- bochs/iodev/sound/opl.cc | 17 ++++++++++++++++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/bochs/gui/paramtree.cc b/bochs/gui/paramtree.cc index 3148f1e18..44308fbe3 100644 --- a/bochs/gui/paramtree.cc +++ b/bochs/gui/paramtree.cc @@ -2,7 +2,7 @@ // $Id$ ///////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2010-2014 The Bochs Project +// Copyright (C) 2010-2015 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 @@ -433,6 +433,19 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent, } } +// Double (floating point) +bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent, + const char *name, + double *ptr_to_real_val) +: bx_param_num_c(parent, name, NULL, NULL, BX_MIN_BIT64U, BX_MAX_BIT64U, 0, 1) +{ + this->varsize = 64; + this->lowbit = 0; + this->mask = BX_MAX_BIT64U; + val.pdouble = ptr_to_real_val; + this->base = BASE_DOUBLE; +} + Bit64s bx_shadow_num_c::get64() { Bit64u current = 0; diff --git a/bochs/gui/paramtree.h b/bochs/gui/paramtree.h index 054a8cbe6..04e4e74b0 100644 --- a/bochs/gui/paramtree.h +++ b/bochs/gui/paramtree.h @@ -2,7 +2,7 @@ // $Id$ ///////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2010-2013 The Bochs Project +// Copyright (C) 2010-2015 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 @@ -89,6 +89,7 @@ public: #define BASE_DEC 10 #define BASE_HEX 16 +#define BASE_DOUBLE 64 class BOCHSAPI bx_param_c : public bx_object_c { BOCHSAPI_CYGONLY static const char *default_text_format; @@ -168,7 +169,8 @@ protected: Bit64s *p64bit; // used by bx_shadow_num_c Bit32s *p32bit; // used by bx_shadow_num_c Bit16s *p16bit; // used by bx_shadow_num_c - Bit8s *p8bit; // used by bx_shadow_num_c + Bit8s *p8bit; // used by bx_shadow_num_c + double *pdouble; // used by bx_shadow_num_c bx_bool *pbool; // used by bx_shadow_bool_c } val; param_event_handler handler; @@ -271,6 +273,9 @@ public: int base = BASE_DEC, Bit8u highbit = 7, Bit8u lowbit = 0); + bx_shadow_num_c(bx_param_c *parent, + const char *name, + double *ptr_to_real_val); virtual Bit64s get64(); virtual void set(Bit64s val); virtual void reset(); diff --git a/bochs/gui/siminterface.cc b/bochs/gui/siminterface.cc index 5f184171b..43e2be2d7 100644 --- a/bochs/gui/siminterface.cc +++ b/bochs/gui/siminterface.cc @@ -1183,6 +1183,8 @@ bx_bool bx_real_sim_c::restore_bochs_param(bx_list_c *root, const char *sr_path, char *ret, *ptr; int i, j, p; unsigned n; + double fvalue; + Bit64u value; bx_param_c *param = NULL; FILE *fp, *fp2; @@ -1224,7 +1226,11 @@ bx_bool bx_real_sim_c::restore_bochs_param(bx_list_c *root, const char *sr_path, } switch (param->get_type()) { case BXT_PARAM_NUM: - if ((ptr[0] == '0') && (ptr[1] == 'x')) { + if (((bx_param_num_c*)param)->get_base() == BASE_DOUBLE) { + fvalue = strtod(ptr, NULL); + memcpy(&value, &fvalue, sizeof(double)); + ((bx_param_num_c*)param)->set(value); + } else if ((ptr[0] == '0') && (ptr[1] == 'x')) { ((bx_param_num_c*)param)->set(strtoull(ptr, NULL, 16)); } else { ((bx_param_num_c*)param)->set(strtoull(ptr, NULL, 10)); @@ -1318,6 +1324,7 @@ bx_bool bx_real_sim_c::save_sr_param(FILE *fp, bx_param_c *node, const char *sr_ { int i; Bit64s value; + double fvalue; char pname[BX_PATHNAME_LEN], tmpstr[BX_PATHNAME_LEN]; FILE *fp2; @@ -1331,7 +1338,10 @@ bx_bool bx_real_sim_c::save_sr_param(FILE *fp, bx_param_c *node, const char *sr_ switch (node->get_type()) { case BXT_PARAM_NUM: value = ((bx_param_num_c*)node)->get64(); - if (((bx_param_num_c*)node)->get_base() == BASE_DEC) { + if (((bx_param_num_c*)node)->get_base() == BASE_DOUBLE) { + memcpy(&fvalue, &value, sizeof(double)); + fprintf(fp, "%f\n", fvalue); + } else if (((bx_param_num_c*)node)->get_base() == BASE_DEC) { if (((bx_param_num_c*)node)->get_min() >= BX_MIN_BIT64U) { if ((Bit64u)((bx_param_num_c*)node)->get_max() > BX_MAX_BIT32U) { fprintf(fp, FMT_LL"u\n", value); diff --git a/bochs/iodev/sound/opl.cc b/bochs/iodev/sound/opl.cc index 0616dd87d..da3faa499 100644 --- a/bochs/iodev/sound/opl.cc +++ b/bochs/iodev/sound/opl.cc @@ -1539,24 +1539,39 @@ void adlib_register_state(bx_list_c *parent) new bx_shadow_num_c(opX, "tcount", &op[i].tcount); new bx_shadow_num_c(opX, "wfpos", &op[i].wfpos); new bx_shadow_num_c(opX, "tinc", &op[i].tinc); + new bx_shadow_num_c(opX, "amp", &op[i].amp); + new bx_shadow_num_c(opX, "step_amp", &op[i].step_amp); + new bx_shadow_num_c(opX, "vol", &op[i].vol); + new bx_shadow_num_c(opX, "sustain_level", &op[i].sustain_level); new bx_shadow_num_c(opX, "mfbi", &op[i].mfbi); + new bx_shadow_num_c(opX, "a0", &op[i].a0); + new bx_shadow_num_c(opX, "a1", &op[i].a1); + new bx_shadow_num_c(opX, "a2", &op[i].a2); + new bx_shadow_num_c(opX, "a3", &op[i].a3); + new bx_shadow_num_c(opX, "decaymul", &op[i].decaymul); + new bx_shadow_num_c(opX, "releasemul", &op[i].releasemul); new bx_shadow_num_c(opX, "op_state", &op[i].op_state); new bx_shadow_num_c(opX, "toff", &op[i].toff); new bx_shadow_num_c(opX, "freq_high", &op[i].freq_high); + // TODO: cur_wform new bx_shadow_num_c(opX, "cur_wmask", &op[i].cur_wmask); new bx_shadow_num_c(opX, "act_state", &op[i].act_state); new bx_shadow_bool_c(opX, "sys_keep", &op[i].sus_keep); new bx_shadow_bool_c(opX, "vibrato", &op[i].vibrato); new bx_shadow_bool_c(opX, "tremolo", &op[i].tremolo); new bx_shadow_num_c(opX, "generator_pos", &op[i].generator_pos); + new bx_shadow_num_c(opX, "cur_env_step", &op[i].cur_env_step); + new bx_shadow_num_c(opX, "env_step_a", &op[i].env_step_a); + new bx_shadow_num_c(opX, "env_step_d", &op[i].env_step_d); + new bx_shadow_num_c(opX, "env_step_r", &op[i].env_step_r); new bx_shadow_num_c(opX, "step_skip_pos_a", &op[i].step_skip_pos_a); + new bx_shadow_num_c(opX, "env_step_skip_a", &op[i].env_step_skip_a); #if defined(OPLTYPE_IS_OPL3) new bx_shadow_bool_c(opX, "is_4op", &op[i].is_4op); new bx_shadow_bool_c(opX, "is_4op_attached", &op[i].is_4op_attached); new bx_shadow_num_c(opX, "left_pan", &op[i].left_pan); new bx_shadow_num_c(opX, "right_pan", &op[i].right_pan); #endif - // TODO: add more internal settings (other variable types) } }