From 0556090a099690d77894113d85a4bf3267f94300 Mon Sep 17 00:00:00 2001
From: Stephen Anthony <sa666666@gmail.com>
Date: Mon, 16 Dec 2019 23:26:57 -0330
Subject: [PATCH] First pass at converting part of 'ystart' to 'vcenter'.

The logic here is somewhat convoluted.  I suggest renaming 'ystart' to 'startline',
and having it internal to TIA only.  The 'vcenter' option will then modify that value
from certain default constants (for NTSC and PAL).
---
 src/common/PKeyboardHandler.cxx |  4 ++--
 src/emucore/Console.cxx         |  8 ++++----
 src/emucore/Console.hxx         |  4 ++--
 src/emucore/Event.hxx           |  4 +---
 src/emucore/EventHandler.cxx    | 14 +++++++-------
 src/emucore/OSystem.cxx         |  2 +-
 src/emucore/Props.cxx           |  8 ++++----
 src/emucore/Props.hxx           |  2 +-
 src/gui/GameInfoDialog.cxx      | 14 ++++++++------
 src/gui/GameInfoDialog.hxx      |  2 +-
 src/tools/PropSet.pm            |  4 ++--
 11 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx
index 456d50eb1..cedda0655 100644
--- a/src/common/PKeyboardHandler.cxx
+++ b/src/common/PKeyboardHandler.cxx
@@ -431,8 +431,8 @@ PhysicalKeyboardHandler::EventMappingArray PhysicalKeyboardHandler::DefaultCommo
 
   {Event::VidmodeDecrease,          KBDK_MINUS, MOD3},
   {Event::VidmodeIncrease,          KBDK_EQUALS, MOD3},
-  {Event::YStartDecrease,           KBDK_PAGEDOWN, MOD3},
-  {Event::YStartIncrease,           KBDK_PAGEUP, MOD3},
+  {Event::VCenterDecrease,          KBDK_PAGEDOWN, MOD3},
+  {Event::VCenterIncrease,          KBDK_PAGEUP, MOD3},
   {Event::VolumeDecrease,           KBDK_LEFTBRACKET, MOD3},
   {Event::VolumeIncrease,           KBDK_RIGHTBRACKET, MOD3},
   {Event::SoundToggle,              KBDK_RIGHTBRACKET, KBDM_CTRL},
diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx
index e2e6f184e..e3557fe1d 100644
--- a/src/emucore/Console.cxx
+++ b/src/emucore/Console.cxx
@@ -151,7 +151,7 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& cart,
     }
   }
 
-  if (atoi(myProperties.get(PropType::Display_YStart).c_str()) == 0) {
+  if (atoi(myProperties.get(PropType::Display_VCenter).c_str()) == 0) {
     autodetectYStart();
   }
 
@@ -679,7 +679,7 @@ void Console::fry() const
 }
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-void Console::changeYStart(int direction)
+void Console::changeVerticalCenter(int direction)
 {
   uInt32 ystart = myTIA->ystart();
 
@@ -711,7 +711,7 @@ void Console::changeYStart(int direction)
   ostringstream ss;
   ss << ystart;
 
-  myProperties.set(PropType::Display_YStart, ss.str());
+  myProperties.set(PropType::Display_VCenter, ss.str());
   if (ystart != myTIA->ystart()) myTIA->setYStart(ystart);
 
   // use vertical center instead of y-start for display
@@ -743,7 +743,7 @@ void Console::updateYStart(uInt32 ystart)
 void Console::setTIAProperties()
 {
   // FIXME - ystart is probably disappearing soon, or at least autodetection is
-  uInt32 ystart = atoi(myProperties.get(PropType::Display_YStart).c_str());
+  uInt32 ystart = atoi(myProperties.get(PropType::Display_VCenter).c_str());
   if(ystart != 0)
     ystart = BSPF::clamp(ystart, 0u, TIAConstants::maxYStart);
   else {
diff --git a/src/emucore/Console.hxx b/src/emucore/Console.hxx
index 9d59b4b81..d1b79ee1f 100644
--- a/src/emucore/Console.hxx
+++ b/src/emucore/Console.hxx
@@ -256,11 +256,11 @@ class Console : public Serializable, public ConsoleIO
     void fry() const;
 
     /**
-      Change the "Display.YStart" variable.
+      Change the "Display.VCenter" variable.
 
       @param direction +1 indicates increase, -1 indicates decrease.
     */
-    void changeYStart(int direction);
+    void changeVerticalCenter(int direction);
 
     /**
       Returns the current framerate.
diff --git a/src/emucore/Event.hxx b/src/emucore/Event.hxx
index 8b0073286..033849dfe 100644
--- a/src/emucore/Event.hxx
+++ b/src/emucore/Event.hxx
@@ -83,7 +83,7 @@ class Event
       ToggleFullScreen,
       VidmodeStd, VidmodeRGB, VidmodeSVideo, VidModeComposite, VidModeBad, VidModeCustom,
       PreviousAttribute, NextAttribute, DecreaseAttribute, IncreaseAttribute,
-      ScanlinesDecrease, ScanlinesIncrease,
+      ScanlinesDecrease, ScanlinesIncrease, VCenterDecrease, VCenterIncrease,
 
       ToggleP0Collision, ToggleP0Bit, ToggleP1Collision, ToggleP1Bit,
       ToggleM0Collision, ToggleM0Bit, ToggleM1Collision, ToggleM1Bit,
@@ -120,8 +120,6 @@ class Event
       CompuMateQuote, CompuMateBackspace, CompuMateEquals, CompuMatePlus,
       CompuMateSlash,
 
-      YStartDecrease, YStartIncrease,
-
       LastType
     };
 
diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx
index c8fe185ed..b3306fd0e 100644
--- a/src/emucore/EventHandler.cxx
+++ b/src/emucore/EventHandler.cxx
@@ -419,12 +419,12 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated)
       if(pressed) myOSystem.frameBuffer().changeVidMode(+1);
       return;
 
-    case Event::YStartDecrease:
-      if (pressed) myOSystem.console().changeYStart(-1);
+    case Event::VCenterDecrease:
+      if (pressed) myOSystem.console().changeVerticalCenter(-1);
       return;
 
-    case Event::YStartIncrease:
-      if (pressed) myOSystem.console().changeYStart(+1);
+    case Event::VCenterIncrease:
+      if (pressed) myOSystem.console().changeVerticalCenter(+1);
       return;
 
     case Event::ToggleFullScreen:
@@ -1830,8 +1830,8 @@ EventHandler::EmulActionList EventHandler::ourEmulActionList = { {
   { Event::ToggleFullScreen,        "Toggle fullscreen",                     "" },
   { Event::OverscanDecrease,        "Decrease overscan in fullscreen mode",  "" },
   { Event::OverscanIncrease,        "Increase overscan in fullscreen mode",  "" },
-  { Event::YStartIncrease,          "Move display up",                       "" },
-  { Event::YStartDecrease,          "Move display down",                     "" },
+  { Event::VCenterIncrease,         "Move display up",                       "" },
+  { Event::VCenterDecrease,         "Move display down",                     "" },
   { Event::FormatDecrease,          "Decrease display format",               "" },
   { Event::FormatIncrease,          "Increase display format",               "" },
   { Event::TogglePalette,           "Switch palette (Standard/Z26/User)",    "" },
@@ -1959,7 +1959,7 @@ const Event::EventSet EventHandler::AudioVideoEvents = {
   Event::ScanlinesDecrease, Event::ScanlinesIncrease,
   Event::PhosphorDecrease, Event::PhosphorIncrease, Event::TogglePhosphor,
   Event::FormatDecrease, Event::FormatIncrease,
-  Event::YStartDecrease, Event::YStartIncrease,
+  Event::VCenterDecrease, Event::VCenterIncrease,
   Event::OverscanDecrease, Event::OverscanIncrease,
   Event::TogglePalette,
 };
diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx
index b1b9997ba..4faa95c47 100644
--- a/src/emucore/OSystem.cxx
+++ b/src/emucore/OSystem.cxx
@@ -587,7 +587,7 @@ unique_ptr<Console> OSystem::openConsole(const FilesystemNode& romfile, string&
     CMDLINE_PROPS_UPDATE("rd", PropType::Console_RightDiff);
     CMDLINE_PROPS_UPDATE("tv", PropType::Console_TVType);
     CMDLINE_PROPS_UPDATE("format", PropType::Display_Format);
-    CMDLINE_PROPS_UPDATE("ystart", PropType::Display_YStart);
+    CMDLINE_PROPS_UPDATE("ystart", PropType::Display_VCenter); // TODO (SA): change option
     CMDLINE_PROPS_UPDATE("pp", PropType::Display_Phosphor);
     CMDLINE_PROPS_UPDATE("ppblend", PropType::Display_PPBlend);
 
diff --git a/src/emucore/Props.cxx b/src/emucore/Props.cxx
index 1ab74542c..fdf6d4385 100644
--- a/src/emucore/Props.cxx
+++ b/src/emucore/Props.cxx
@@ -253,7 +253,7 @@ void Properties::print() const
        << get(PropType::Controller_SwapPaddles) << "|"
        << get(PropType::Controller_MouseAxis)   << "|"
        << get(PropType::Display_Format)         << "|"
-       << get(PropType::Display_YStart)         << "|"
+       << get(PropType::Display_VCenter)        << "|"
        << get(PropType::Display_Phosphor)       << "|"
        << get(PropType::Display_PPBlend)
        << endl;
@@ -298,7 +298,7 @@ void Properties::printHeader()
        << "Controller_SwapPaddles|"
        << "Controller_MouseAxis|"
        << "Display_Format|"
-       << "Display_YStart|"
+       << "Display_VCenter|"
        << "Display_Phosphor|"
        << "Display_PPBlend"
        << endl;
@@ -325,7 +325,7 @@ string Properties::ourDefaultProperties[static_cast<uInt8>(PropType::NumTypes)]
   "NO",     // Controller.SwapPaddles
   "AUTO",   // Controller.MouseAxis
   "AUTO",   // Display.Format
-  "0",      // Display.YStart
+  "0",      // Display.VCenter
   "NO",     // Display.Phosphor
   "0"       // Display.PPBlend
 };
@@ -351,7 +351,7 @@ const char* const Properties::ourPropertyNames[static_cast<uInt8>(PropType::NumT
   "Controller.SwapPaddles",
   "Controller.MouseAxis",
   "Display.Format",
-  "Display.YStart",
+  "Display.VCenter",
   "Display.Phosphor",
   "Display.PPBlend"
 };
diff --git a/src/emucore/Props.hxx b/src/emucore/Props.hxx
index 77e3a198d..76ae85952 100644
--- a/src/emucore/Props.hxx
+++ b/src/emucore/Props.hxx
@@ -39,7 +39,7 @@ enum class PropType : uInt8 {
   Controller_SwapPaddles,
   Controller_MouseAxis,
   Display_Format,
-  Display_YStart,
+  Display_VCenter,
   Display_Phosphor,
   Display_PPBlend,
   NumTypes
diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx
index 281f66102..ae9e60804 100644
--- a/src/gui/GameInfoDialog.cxx
+++ b/src/gui/GameInfoDialog.cxx
@@ -137,7 +137,8 @@ GameInfoDialog::GameInfoDialog(
   ypos += lineHeight + VGAP;
   t = new StaticTextWidget(myTab, font, HBORDER, ypos + 1, "V-Center ");
   myVCenter = new SliderWidget(myTab, font, t->getRight() + 2, ypos,
-                              "", 0, kYStartChanged, 7 * fontWidth, "px");
+                              "", 0, kVCenterChanged, 7 * fontWidth, "px");
+// TODO (SA):check relationship of ystart and vcenter
   myVCenter->setMinValue(TIAConstants::minYStart - TIAConstants::defaultYStart);
   myVCenter->setMaxValue(TIAConstants::maxYStart - TIAConstants::defaultYStart);
   myVCenter->setTickmarkIntervals(4);
@@ -456,11 +457,12 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props)
   const string& blend = props.get(PropType::Display_PPBlend);
   myPPBlend->setValue(atoi(blend.c_str()));
 
-  // set vertical center (y-start)
-  int vCenter = atoi(props.get(PropType::Display_YStart).c_str());
+  // set vertical center
+  int vCenter = atoi(props.get(PropType::Display_VCenter).c_str());
   if (vCenter)
   {
     // convert y-start into v-center
+    // TODO (SA): fix this
     vCenter = TIAConstants::defaultYStart - vCenter;
     myVCenter->setValueLabel(vCenter);
   }
@@ -548,9 +550,9 @@ void GameInfoDialog::saveConfig()
                        myPPBlend->getValueLabel());
   int vCenter = myVCenter->getValue();
   if (vCenter)
-    // convert v-center into y-start
+    // convert v-center into y-start TODO (SA): fix this
     vCenter = TIAConstants::defaultYStart - vCenter;
-  myGameProperties.set(PropType::Display_YStart, std::to_string(vCenter));
+  myGameProperties.set(PropType::Display_VCenter, std::to_string(vCenter));
   myGameProperties.set(PropType::Cart_Sound, mySound->getState() ? "STEREO" : "MONO");
 
   // Console properties
@@ -792,7 +794,7 @@ void GameInfoDialog::handleCommand(CommandSender* sender, int cmd,
         myPPBlend->setValueUnit("%");
       break;
 
-    case kYStartChanged:
+    case kVCenterChanged:
       if (myVCenter->getValue() == 0)
       {
         myVCenter->setValueLabel("Default");
diff --git a/src/gui/GameInfoDialog.hxx b/src/gui/GameInfoDialog.hxx
index 75ac75511..a12c387e8 100644
--- a/src/gui/GameInfoDialog.hxx
+++ b/src/gui/GameInfoDialog.hxx
@@ -103,7 +103,7 @@ class GameInfoDialog : public Dialog, public CommandSender
     EditTextWidget*   myNote;
 
     enum {
-      kYStartChanged   = 'YSch',
+      kVCenterChanged  = 'Vcch',
       kPhosphorChanged = 'PPch',
       kPPBlendChanged  = 'PBch',
       kLeftCChanged    = 'LCch',
diff --git a/src/tools/PropSet.pm b/src/tools/PropSet.pm
index 313042471..26e57a09e 100755
--- a/src/tools/PropSet.pm
+++ b/src/tools/PropSet.pm
@@ -21,7 +21,7 @@ my %prop_type = (
   "Controller.SwapPaddles"  => 15,
   "Controller.MouseAxis"    => 16,
   "Display.Format"          => 17,
-  "Display.YStart"          => 18,
+  "Display.VCenter"         => 18,
   "Display.Phosphor"        => 19,
   "Display.PPBlend"         => 20
 );
@@ -44,7 +44,7 @@ my @prop_type_as_string = (
   "Controller.SwapPaddles",
   "Controller.MouseAxis",
   "Display.Format",
-  "Display.YStart",
+  "Display.VCenter",
   "Display.Phosphor",
   "Display.PPBlend"
 );