From a7fc82cbea7b9fb20b4a4971a17a709e0713a4d5 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Wed, 29 Mar 2017 20:14:43 +0200 Subject: [PATCH] Position readout for players. --- src/debugger/TIADebug.cxx | 10 +++--- src/emucore/tia/Player.cxx | 9 +++++ src/emucore/tia/Player.hxx | 11 +++++- src/emucore/tia/PositioningProvider.hxx | 45 +++++++++++++++++++++++++ src/emucore/tia/TIA.cxx | 3 ++ src/emucore/tia/TIA.hxx | 12 +++++-- 6 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 src/emucore/tia/PositioningProvider.hxx diff --git a/src/debugger/TIADebug.cxx b/src/debugger/TIADebug.cxx index 6de2a4d39..b561cb299 100644 --- a/src/debugger/TIADebug.cxx +++ b/src/debugger/TIADebug.cxx @@ -552,10 +552,9 @@ uInt8 TIADebug::posP0(int newVal) #if 0 // FIXME if(newVal > -1) myTIA.myPOSP0 = newVal; - - return myTIA.myPOSP0; #endif -return 0; + + return myTIA.myPlayer0.getPosition(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -564,10 +563,9 @@ uInt8 TIADebug::posP1(int newVal) #if 0 // FIXME if(newVal > -1) myTIA.myPOSP1 = newVal; - - return myTIA.myPOSP1; #endif -return 0; + + return myTIA.myPlayer1.getPosition(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/tia/Player.cxx b/src/emucore/tia/Player.cxx index c5d995dd5..21ed1cd53 100644 --- a/src/emucore/tia/Player.cxx +++ b/src/emucore/tia/Player.cxx @@ -363,6 +363,15 @@ void Player::applyColors() myColor = myDebugEnabled ? myDebugColor : myObjectColor; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 Player::getPosition() const +{ + const uInt8 shift = myDivider == 1 ? 0 : 1; + + // Mind the sign of renderCounterOffset: it's defined negative above + return (316 - myCounter - Count::renderCounterOffset + shift + myPositioningProvider->getPosition()) % 160; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Player::save(Serializer& out) const { diff --git a/src/emucore/tia/Player.hxx b/src/emucore/tia/Player.hxx index 59991c8cd..264425718 100644 --- a/src/emucore/tia/Player.hxx +++ b/src/emucore/tia/Player.hxx @@ -18,8 +18,9 @@ #ifndef TIA_PLAYER #define TIA_PLAYER -#include "Serializable.hxx" #include "bspf.hxx" +#include "Serializable.hxx" +#include "PositioningProvider.hxx" class Player : public Serializable { @@ -28,6 +29,10 @@ class Player : public Serializable public: + void setPositioningProvider(PositioningProvider* positioningProvider) { + myPositioningProvider = positioningProvider; + } + void reset(); void grp(uInt8 value); @@ -68,6 +73,8 @@ class Player : public Serializable uInt8 getRespClock() const; + uInt8 getPosition() const; + /** Serializable methods (see that class for more information). */ @@ -118,6 +125,8 @@ class Player : public Serializable bool myIsReflected; bool myIsDelaying; + PositioningProvider *myPositioningProvider; + private: Player(const Player&) = delete; Player(Player&&) = delete; diff --git a/src/emucore/tia/PositioningProvider.hxx b/src/emucore/tia/PositioningProvider.hxx new file mode 100644 index 000000000..55e987016 --- /dev/null +++ b/src/emucore/tia/PositioningProvider.hxx @@ -0,0 +1,45 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2017 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef TIA_POSITIONING_PROVIDER +#define TIA_POSITIONING_PROVIDER + +#include "bspf.hxx" + +/** + This is an abstract interface class that provides a subset of TIA + functionality for sprite positioning while avoiding circular dependencies + between TIA and sprites. + + @author Christian Speckner (DirtyHairy) and Stephen Anthony +*/ +class PositioningProvider +{ + public: + + /** + Get the current x value + */ + virtual uInt8 getPosition() = 0; + + protected: + + ~PositioningProvider() = default; + +}; + +#endif // TIA_POSITIONING_PROVIDER \ No newline at end of file diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 2b36cac00..640247bc2 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -95,6 +95,9 @@ TIA::TIA(Console& console, Sound& sound, Settings& settings) myTIAPinsDriven = mySettings.getBool("tiadriven"); + myPlayer0.setPositioningProvider(this); + myPlayer1.setPositioningProvider(this); + reset(); } diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index a48b5bb86..be47fde59 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -35,6 +35,7 @@ #include "Ball.hxx" #include "LatchedInput.hxx" #include "PaddleReader.hxx" +#include "PositioningProvider.hxx" /** This class is a device that emulates the Television Interface Adaptor @@ -49,7 +50,7 @@ @author Christian Speckner (DirtyHairy) and Stephen Anthony */ -class TIA : public Device +class TIA : public Device, public PositioningProvider { public: friend class TIADebug; @@ -308,9 +309,16 @@ class TIA : public Device */ void updateScanlineByTrace(int target); - // Retrieve the last value written to a certain register + /** + Retrieve the last value written to a certain register + */ uInt8 lastValueWrittenToRegister(uInt8 reg) const; + /** + Get the current x value + */ + virtual uInt8 getPosition() {return (myHctr < 68) ? 0 : (myHctr - 68 - myXDelta);} + /** Save the current state of this device to the given Serializer.