Position readout for players.

This commit is contained in:
Christian Speckner 2017-03-29 20:14:43 +02:00
parent f1eb76303c
commit a7fc82cbea
6 changed files with 81 additions and 9 deletions

View File

@ -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();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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
{

View File

@ -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;

View File

@ -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

View File

@ -95,6 +95,9 @@ TIA::TIA(Console& console, Sound& sound, Settings& settings)
myTIAPinsDriven = mySettings.getBool("tiadriven");
myPlayer0.setPositioningProvider(this);
myPlayer1.setPositioningProvider(this);
reset();
}

View File

@ -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.