From e18474a5e9aaa489a893a96b677e61a074c75d9d Mon Sep 17 00:00:00 2001
From: thrust26 <tjentzsch@yahoo.de>
Date: Thu, 23 Nov 2017 11:35:28 +0100
Subject: [PATCH] frame stats added to Developer Setting ("dev.stats" now)

---
 src/common/StateManager.cxx |  3 ++-
 src/emucore/Console.cxx     |  3 ++-
 src/emucore/FrameBuffer.cxx |  6 +++---
 src/emucore/Settings.cxx    |  4 ++--
 src/gui/DeveloperDialog.cxx | 43 +++++++++++++++++++++++--------------
 src/gui/DeveloperDialog.hxx |  2 ++
 6 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/src/common/StateManager.cxx b/src/common/StateManager.cxx
index f41d940d7..3e55b1807 100644
--- a/src/common/StateManager.cxx
+++ b/src/common/StateManager.cxx
@@ -354,8 +354,9 @@ bool StateManager::saveState(Serializer& out)
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 void StateManager::reset()
 {
-  myActiveMode = Mode::Off;
   myRewindManager->clear();
+  myActiveMode = myOSystem.settings().getBool("dev.rewind") ? Mode::Rewind : Mode::Off;
+
 #if 0
   myCurrentSlot = 0;
 
diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx
index 0b5023f1f..6f419c326 100644
--- a/src/emucore/Console.cxx
+++ b/src/emucore/Console.cxx
@@ -528,7 +528,8 @@ FBInitStatus Console::initializeVideo(bool full)
     if(fbstatus != kSuccess)
       return fbstatus;
 
-    myOSystem.frameBuffer().showFrameStats(myOSystem.settings().getBool("stats"));
+    myOSystem.frameBuffer().showFrameStats(myOSystem.settings().getBool("dev.settings") &&
+                                           myOSystem.settings().getBool("dev.stats"));
     generateColorLossPalette();
   }
   setPalette(myOSystem.settings().getString("palette"));
diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx
index 5f460b316..eacc3fac9 100644
--- a/src/emucore/FrameBuffer.cxx
+++ b/src/emucore/FrameBuffer.cxx
@@ -368,13 +368,13 @@ void FrameBuffer::showMessage(const string& message, MessagePosition position,
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 void FrameBuffer::toggleFrameStats()
 {
-  showFrameStats(!myOSystem.settings().getBool("stats"));
+  showFrameStats(!myOSystem.settings().getBool("dev.stats"));
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 void FrameBuffer::showFrameStats(bool enable)
 {
-  myOSystem.settings().setValue("stats", enable);
+  myOSystem.settings().setValue("dev.stats", enable);
   myStatsMsg.enabled = enable;
 }
 
@@ -384,7 +384,7 @@ void FrameBuffer::enableMessages(bool enable)
   if(enable)
   {
     // Only re-enable frame stats if they were already enabled before
-    myStatsMsg.enabled = myOSystem.settings().getBool("stats");
+    myStatsMsg.enabled = myOSystem.settings().getBool("dev.stats");
   }
   else
   {
diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx
index f3e413cdc..cbfe15fee 100644
--- a/src/emucore/Settings.cxx
+++ b/src/emucore/Settings.cxx
@@ -128,7 +128,6 @@ Settings::Settings(OSystem& osystem)
   setInternal("loglevel", "1");
   setInternal("logtoconsole", "0");
   setInternal("avoxport", "");
-  setInternal("stats", "false");
   setInternal("fastscbios", "true");
   setInternal("threads", "false");
   setExternal("romloadcount", "0");
@@ -147,6 +146,7 @@ Settings::Settings(OSystem& osystem)
 
   // developer settings
   setInternal("dev.settings", "false");
+  setInternal("dev.stats", "false");
   setInternal("dev.bankrandom", "true");
   setInternal("dev.ramrandom", "true");
   setInternal("dev.cpurandom", "SAXYP");
@@ -441,7 +441,6 @@ void Settings::usage() const
     << "  -saport       <lr|rl>        How to assign virtual ports to multiple Stelladaptor/2600-daptors\n"
     << "  -ctrlcombo    <1|0>          Use key combos involving the Control key (Control-Q for quit may be disabled!)\n"
     << "  -autoslot     <1|0>          Automatically switch to next save slot when state saving\n"
-    << "  -stats        <1|0>          Overlay console info during emulation\n"
     << "  -fastscbios   <1|0>          Disable Supercharger BIOS progress loading bars\n"
     << "  -threads      <1|0>          Whether to using multi-threading during emulation\n"
     << "  -snapsavedir  <path>         The directory to save snapshot files to\n"
@@ -513,6 +512,7 @@ void Settings::usage() const
   #endif
 
     << "  -dev.console      <2600|7800>    Select console for B/W and Pause key handling\n"
+    << "  -dev.stats        <1|0>          Overlay console info during emulation\n"
     << "  -dev.tiadriven    <1|0>          Drive unused TIA pins randomly on a read/peek\n"
     << "  -dev.cpurandom    <1|0>          Randomize the contents of CPU registers on reset\n"
     << "  -dev.ramrandom    <1|0>          Randomize the contents of RAM on reset\n"
diff --git a/src/gui/DeveloperDialog.cxx b/src/gui/DeveloperDialog.cxx
index 201c74c13..b2df3ddb7 100644
--- a/src/gui/DeveloperDialog.cxx
+++ b/src/gui/DeveloperDialog.cxx
@@ -54,7 +54,7 @@ DeveloperDialog::DeveloperDialog(OSystem& osystem, DialogContainer& parent,
 
   // Set real dimensions
   _w = std::min(51 * fontWidth + 10, max_w);
-  _h = std::min(14 * (lineHeight + 4) + 14, max_h);
+  _h = std::min(15 * (lineHeight + 4) + 14, max_h);
 
   WidgetArray wid;
 
@@ -102,6 +102,11 @@ void DeveloperDialog::addEmulationTab(const GUI::Font& font)
   wid.push_back(myDevSettings);
   ypos += lineHeight + VGAP;
 
+
+  myFrameStats = new CheckboxWidget(myTab, font, HBORDER + INDENT * 1, ypos, "Show frame statistics", kFrameStats);
+  wid.push_back(myFrameStats);
+  ypos += lineHeight + VGAP;
+
   // 2600/7800 mode
   items.clear();
   VarList::push_back(items, "Atari 2600", "2600");
@@ -118,7 +123,7 @@ void DeveloperDialog::addEmulationTab(const GUI::Font& font)
   wid.push_back(myLoadingROMLabel);
   ypos += lineHeight + VGAP;
 
-  myRandomBank = new CheckboxWidget(myTab, font, HBORDER + INDENT * 2, ypos + 1, "Random startup bank (TODO)");
+  myRandomBank = new CheckboxWidget(myTab, font, HBORDER + INDENT * 2, ypos + 1, "Random startup bank");
   wid.push_back(myRandomBank);
   ypos += lineHeight + VGAP;
 
@@ -151,17 +156,22 @@ void DeveloperDialog::addEmulationTab(const GUI::Font& font)
   wid.push_back(myThumbException);*/
   //ypos += (lineHeight + VGAP) * 2;
 
+  // debug colors
+  myDebugColors = new CheckboxWidget(myTab, font, HBORDER + INDENT * 1, ypos + 1, "Debug colors");
+  wid.push_back(myDebugColors);
+  ypos += lineHeight + VGAP;
+
   myColorLoss = new CheckboxWidget(myTab, font, HBORDER + INDENT*1, ypos + 1, "PAL color-loss");
   wid.push_back(myColorLoss);
   ypos += lineHeight + VGAP;
 
   // TV jitter effect
-  myTVJitter = new CheckboxWidget(myTab, font, HBORDER + INDENT*1, ypos + 1, "Jitter/Roll Effect", kTVJitter);
+  myTVJitter = new CheckboxWidget(myTab, font, HBORDER + INDENT*1, ypos + 1, "Jitter/Roll effect", kTVJitter);
   wid.push_back(myTVJitter);
   myTVJitterRec = new SliderWidget(myTab, font,
                                    myTVJitter->getRight()+ 16, ypos - 1,
-                                   8 * fontWidth, lineHeight, "Recovery ",
-                                   font.getStringWidth("Recovery "), kTVJitterChanged);
+                                   8 * fontWidth, lineHeight, "recovery ",
+                                   font.getStringWidth("recovery "), kTVJitterChanged);
   myTVJitterRec->setMinValue(1); myTVJitterRec->setMaxValue(20);
   wid.push_back(myTVJitterRec);
 
@@ -172,11 +182,6 @@ void DeveloperDialog::addEmulationTab(const GUI::Font& font)
   wid.push_back(myTVJitterRecLabel);
   ypos += lineHeight + VGAP;
 
-  // debug colors
-  myDebugColors = new CheckboxWidget(myTab, font, HBORDER + INDENT*1, ypos + 1, "Debug Colors");
-  wid.push_back(myDebugColors);
-  ypos += lineHeight + VGAP;
-
   // How to handle undriven TIA pins
   myUndrivenPins = new CheckboxWidget(myTab, font, HBORDER + INDENT*1, ypos + 1,
                                       "Drive unused TIA pins randomly on a read/peek");
@@ -207,13 +212,13 @@ void DeveloperDialog::addStatesTab(const GUI::Font& font)
   wid.push_back(myDevSettings1);
   ypos += lineHeight + VGAP*4;*/
 
-  myContinuousRewind = new CheckboxWidget(myTab, font, HBORDER, ypos + 1, "Continuous Rewind", kRewind);
+  myContinuousRewind = new CheckboxWidget(myTab, font, HBORDER, ypos + 1, "Continuous rewind", kRewind);
   wid.push_back(myContinuousRewind);
   ypos += lineHeight + VGAP;
 
   int sWidth = font.getMaxCharWidth() * 8;
   myStateSize = new SliderWidget(myTab, font, HBORDER + INDENT, ypos - 1, sWidth, lineHeight,
-                                 "Buffer Size (*) ", 0, kSizeChanged);
+                                 "Buffer size (*) ", 0, kSizeChanged);
   myStateSize->setMinValue(100);
   myStateSize->setMaxValue(1000);
   myStateSize->setStepValue(100);
@@ -274,7 +279,7 @@ void DeveloperDialog::addDebuggerTab(const GUI::Font& font)
   pwidth = font.getStringWidth("Medium");
   myDebuggerFontSize =
     new PopUpWidget(myTab, font, HBORDER, ypos + 1, pwidth, lineHeight, items,
-                    "Font Size  ", 0, kDFontSizeChanged);
+                    "Font size  ", 0, kDFontSizeChanged);
   wid.push_back(myDebuggerFontSize);
   ypos += lineHeight + 4;
 
@@ -287,7 +292,7 @@ void DeveloperDialog::addDebuggerTab(const GUI::Font& font)
   pwidth = font.getStringWidth("Bold non-labels only");
   myDebuggerFontStyle =
     new PopUpWidget(myTab, font, HBORDER, ypos + 1, pwidth, lineHeight, items,
-                    "Font Style ", 0);
+                    "Font style ", 0);
   wid.push_back(myDebuggerFontStyle);
 
   ypos += lineHeight + VGAP * 4;
@@ -295,7 +300,7 @@ void DeveloperDialog::addDebuggerTab(const GUI::Font& font)
   pwidth = font.getMaxCharWidth() * 8;
   // Debugger width and height
   myDebuggerWidthSlider = new SliderWidget(myTab, font, xpos, ypos-1, pwidth,
-                                           lineHeight, "Debugger Width  ",
+                                           lineHeight, "Debugger width  ",
                                            0, kDWidthChanged);
   myDebuggerWidthSlider->setMinValue(DebuggerDialog::kSmallFontMinW);
   myDebuggerWidthSlider->setMaxValue(ds.w);
@@ -309,7 +314,7 @@ void DeveloperDialog::addDebuggerTab(const GUI::Font& font)
   ypos += lineHeight + VGAP;
 
   myDebuggerHeightSlider = new SliderWidget(myTab, font, xpos, ypos-1, pwidth,
-                                            lineHeight, "Debugger Height ",
+                                            lineHeight, "Debugger height ",
                                             0, kDHeightChanged);
   myDebuggerHeightSlider->setMinValue(DebuggerDialog::kSmallFontMinH);
   myDebuggerHeightSlider->setMaxValue(ds.h);
@@ -371,6 +376,7 @@ void DeveloperDialog::loadConfig()
 {
   myDevSettings->setState(instance().settings().getBool("dev.settings"));
 
+  myFrameStats->setState(instance().settings().getBool("dev.stats"));
   myConsole->setSelectedIndex(instance().settings().getString("dev.console") == "7800" ? 1 : 0);
   myRandomBank->setState(instance().settings().getBool("dev.bankrandom"));
   myRandomizeRAM->setState(instance().settings().getBool("dev.ramrandom"));
@@ -439,6 +445,9 @@ void DeveloperDialog::saveConfig()
   bool devSettings = myDevSettings->getState();
   instance().settings().setValue("dev.settings", devSettings);
 
+  instance().settings().setValue("dev.stats", myFrameStats->getState());
+  instance().frameBuffer().showFrameStats(myFrameStats->getState());
+
   bool is7800 = myConsole->getSelected() == 1;
   instance().settings().setValue("dev.console", is7800 ? "7800" : "2600");
 
@@ -545,6 +554,7 @@ void DeveloperDialog::setDefaults()
   switch(myTab->getActiveTab())
   {
     case 0:
+      myFrameStats->setState(true);
       myConsole->setSelectedIndex(0);
       myRandomBank->setState(true);
       myRandomizeRAM->setState(true);
@@ -683,6 +693,7 @@ void DeveloperDialog::handleDeveloperOptions()
 {
   bool enable = myDevSettings->getState();
 
+  myFrameStats->setEnabled(enable);
   myConsole->setEnabled(enable);
   // CPU
   myLoadingROMLabel->setEnabled(enable);
diff --git a/src/gui/DeveloperDialog.hxx b/src/gui/DeveloperDialog.hxx
index 23e9c20bd..c0000d05c 100644
--- a/src/gui/DeveloperDialog.hxx
+++ b/src/gui/DeveloperDialog.hxx
@@ -53,6 +53,7 @@ class DeveloperDialog : public Dialog
     enum
     {
       kDevSettings      = 'DVst',
+      kFrameStats       = 'DVfs',
       kConsole          = 'DVco',
       kRandRAMID        = 'DVrm',
       kRandCPUID        = 'DVcp',
@@ -84,6 +85,7 @@ class DeveloperDialog : public Dialog
     TabWidget* myTab;
     // Emulator
     CheckboxWidget*   myDevSettings;
+    CheckboxWidget*   myFrameStats;
     PopUpWidget*      myConsole;
     StaticTextWidget* myLoadingROMLabel;
     CheckboxWidget*   myRandomBank;