2001-12-27 19:54:36 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
2009-01-01 18:13:40 +00:00
|
|
|
// Copyright (c) 1995-2009 by Bradford W. Mott and the Stella team
|
2001-12-27 19:54:36 +00:00
|
|
|
//
|
|
|
|
// See the file "license" for information on usage and redistribution of
|
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//
|
2009-03-16 00:23:42 +00:00
|
|
|
// $Id: Control.hxx,v 1.19 2009-03-16 00:23:42 stephena Exp $
|
2001-12-27 19:54:36 +00:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#ifndef CONTROLLER_HXX
|
|
|
|
#define CONTROLLER_HXX
|
|
|
|
|
|
|
|
class Controller;
|
|
|
|
class Event;
|
2007-02-22 02:15:46 +00:00
|
|
|
class System;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
OK, another huge commit. I need to commit this now, because things are
starting to go out of sync on my development machines. OK, where to
begin ...
Changed state file format, so older state files will no longer work. The
changes aren't finalized yet, so expect more breakage.
Added getByte() and putByte() methods to serialized data, resulting in
smaller state files (previously, 1-byte values were stored as 4-byte ints).
Totally reworked controller handling code. Controller state is now
explicitly set with an ::update() method, making it easier to serialize.
Some work is still required on the serialization stuff for more advanced
controllers.
Added a 'Serializable' interface to all carts, device, controllers, etc
that can be (de)serialized. This fixes a long-standing design issue
which I personally caused many years ago.
Console switches state (SWCHB register) is now saved to state files.
Added beginnings of movie support. Basically, this saves an initial
state file, and thereafter continuously saves controller and console
switches state. Support is still somewhat rough and there's no UI for
it, but it does successfully save and later load/play state movies.
Removed specific events for driving controllers, and have them use
joystick events instead. This has the nice side effect that
joystick direction remapping 'just works' for driving controllers too.
Fixed issues with paddle emulation seen in 'Night Driver' ROM. Related
to this, removed a hack wrt paddles when grabmouse is enabled. There's
still some work to do when using the mouse to emulate paddles, but the
Stelladaptor and real paddles work fine.
Added beginnings of TrackBall CX-22 controller emulation. It doesn't
actually do anything yet, but the class is there :)
Probably some other stuff that I'm forgetting ...
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1385 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2007-10-03 21:41:19 +00:00
|
|
|
#include "Serializable.hxx"
|
2001-12-27 19:54:36 +00:00
|
|
|
#include "bspf.hxx"
|
|
|
|
|
|
|
|
/**
|
|
|
|
A controller is a device that plugs into either the left or right
|
|
|
|
controller jack of the Video Computer System (VCS). The pins of
|
|
|
|
the controller jacks are mapped as follows:
|
|
|
|
|
|
|
|
-------------
|
|
|
|
\ 1 2 3 4 5 /
|
|
|
|
\ 6 7 8 9 /
|
|
|
|
---------
|
|
|
|
|
|
|
|
Left Controller Right Controller
|
|
|
|
|
|
|
|
pin 1 D4 PIA SWCHA D0 PIA SWCHA
|
|
|
|
pin 2 D5 PIA SWCHA D1 PIA SWCHA
|
|
|
|
pin 3 D6 PIA SWCHA D2 PIA SWCHA
|
|
|
|
pin 4 D7 PIA SWCHA D3 PIA SWCHA
|
|
|
|
pin 5 D7 TIA INPT1 (Dumped) D7 TIA INPT3 (Dumped)
|
|
|
|
pin 6 D7 TIA INPT4 (Latched) D7 TIA INPT5 (Latched)
|
|
|
|
pin 7 +5 +5
|
|
|
|
pin 8 GND GND
|
|
|
|
pin 9 D7 TIA INPT0 (Dumped) D7 TIA INPT2 (Dumped)
|
|
|
|
|
|
|
|
Each of the pins connected to the PIA can be configured as an
|
|
|
|
input or output pin. The "dumped" TIA pins are used to charge
|
|
|
|
a capacitor. A potentiometer is sometimes connected to these
|
|
|
|
pins for analog input.
|
|
|
|
|
2007-01-05 17:54:23 +00:00
|
|
|
This is a base class for all controllers. It provides a view
|
|
|
|
of the controller from the perspective of the controller's jack.
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
@author Bradford W. Mott
|
2009-03-16 00:23:42 +00:00
|
|
|
@version $Id: Control.hxx,v 1.19 2009-03-16 00:23:42 stephena Exp $
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
OK, another huge commit. I need to commit this now, because things are
starting to go out of sync on my development machines. OK, where to
begin ...
Changed state file format, so older state files will no longer work. The
changes aren't finalized yet, so expect more breakage.
Added getByte() and putByte() methods to serialized data, resulting in
smaller state files (previously, 1-byte values were stored as 4-byte ints).
Totally reworked controller handling code. Controller state is now
explicitly set with an ::update() method, making it easier to serialize.
Some work is still required on the serialization stuff for more advanced
controllers.
Added a 'Serializable' interface to all carts, device, controllers, etc
that can be (de)serialized. This fixes a long-standing design issue
which I personally caused many years ago.
Console switches state (SWCHB register) is now saved to state files.
Added beginnings of movie support. Basically, this saves an initial
state file, and thereafter continuously saves controller and console
switches state. Support is still somewhat rough and there's no UI for
it, but it does successfully save and later load/play state movies.
Removed specific events for driving controllers, and have them use
joystick events instead. This has the nice side effect that
joystick direction remapping 'just works' for driving controllers too.
Fixed issues with paddle emulation seen in 'Night Driver' ROM. Related
to this, removed a hack wrt paddles when grabmouse is enabled. There's
still some work to do when using the mouse to emulate paddles, but the
Stelladaptor and real paddles work fine.
Added beginnings of TrackBall CX-22 controller emulation. It doesn't
actually do anything yet, but the class is there :)
Probably some other stuff that I'm forgetting ...
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1385 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2007-10-03 21:41:19 +00:00
|
|
|
class Controller : public Serializable
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2008-05-15 15:07:29 +00:00
|
|
|
/**
|
|
|
|
Riot debug class needs special access to the underlying controller state
|
|
|
|
*/
|
|
|
|
friend class RiotDebug;
|
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Enumeration of the controller jacks
|
|
|
|
*/
|
|
|
|
enum Jack
|
|
|
|
{
|
|
|
|
Left, Right
|
|
|
|
};
|
|
|
|
|
2005-11-12 22:04:57 +00:00
|
|
|
/**
|
|
|
|
Enumeration of the controller types
|
|
|
|
*/
|
|
|
|
enum Type
|
|
|
|
{
|
2007-01-05 17:54:23 +00:00
|
|
|
BoosterGrip, Driving, Keyboard, Paddles, Joystick,
|
2009-03-16 00:23:42 +00:00
|
|
|
TrackBall22, TrackBall80, AmigaMouse, AtariVox, SaveKey,
|
|
|
|
KidVid
|
2005-11-12 22:04:57 +00:00
|
|
|
};
|
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create a new controller plugged into the specified jack
|
|
|
|
|
2008-04-13 23:43:14 +00:00
|
|
|
@param jack The jack the controller is plugged into
|
|
|
|
@param event The event object to use for events
|
|
|
|
@param type The type for this controller
|
|
|
|
@param system The system using this controller
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
2008-04-13 23:43:14 +00:00
|
|
|
Controller(Jack jack, const Event& event, const System& system,
|
|
|
|
Type type);
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor
|
|
|
|
*/
|
|
|
|
virtual ~Controller();
|
|
|
|
|
2005-11-12 22:59:20 +00:00
|
|
|
/**
|
|
|
|
Returns the type of this controller.
|
|
|
|
*/
|
OK, another huge commit. I need to commit this now, because things are
starting to go out of sync on my development machines. OK, where to
begin ...
Changed state file format, so older state files will no longer work. The
changes aren't finalized yet, so expect more breakage.
Added getByte() and putByte() methods to serialized data, resulting in
smaller state files (previously, 1-byte values were stored as 4-byte ints).
Totally reworked controller handling code. Controller state is now
explicitly set with an ::update() method, making it easier to serialize.
Some work is still required on the serialization stuff for more advanced
controllers.
Added a 'Serializable' interface to all carts, device, controllers, etc
that can be (de)serialized. This fixes a long-standing design issue
which I personally caused many years ago.
Console switches state (SWCHB register) is now saved to state files.
Added beginnings of movie support. Basically, this saves an initial
state file, and thereafter continuously saves controller and console
switches state. Support is still somewhat rough and there's no UI for
it, but it does successfully save and later load/play state movies.
Removed specific events for driving controllers, and have them use
joystick events instead. This has the nice side effect that
joystick direction remapping 'just works' for driving controllers too.
Fixed issues with paddle emulation seen in 'Night Driver' ROM. Related
to this, removed a hack wrt paddles when grabmouse is enabled. There's
still some work to do when using the mouse to emulate paddles, but the
Stelladaptor and real paddles work fine.
Added beginnings of TrackBall CX-22 controller emulation. It doesn't
actually do anything yet, but the class is there :)
Probably some other stuff that I'm forgetting ...
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1385 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2007-10-03 21:41:19 +00:00
|
|
|
const Type type() const;
|
2005-11-12 22:59:20 +00:00
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Enumeration of the digital pins of a controller port
|
|
|
|
*/
|
|
|
|
enum DigitalPin
|
|
|
|
{
|
|
|
|
One, Two, Three, Four, Six
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enumeration of the analog pins of a controller port
|
|
|
|
*/
|
|
|
|
enum AnalogPin
|
|
|
|
{
|
|
|
|
Five, Nine
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Read the value of the specified digital pin for this controller.
|
|
|
|
|
|
|
|
@param pin The pin of the controller jack to read
|
|
|
|
@return The state of the pin
|
|
|
|
*/
|
2008-04-13 23:43:14 +00:00
|
|
|
virtual bool read(DigitalPin pin);
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Read the resistance at the specified analog pin for this controller.
|
|
|
|
The returned value is the resistance measured in ohms.
|
|
|
|
|
|
|
|
@param pin The pin of the controller jack to read
|
|
|
|
@return The resistance at the specified pin
|
|
|
|
*/
|
2008-04-13 23:43:14 +00:00
|
|
|
virtual Int32 read(AnalogPin pin);
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Write the given value to the specified digital pin for this
|
|
|
|
controller. Writing is only allowed to the pins associated
|
|
|
|
with the PIA. Therefore you cannot write to pin six.
|
|
|
|
|
|
|
|
@param pin The pin of the controller jack to write to
|
|
|
|
@param value The value to write to the pin
|
|
|
|
*/
|
OK, another huge commit. I need to commit this now, because things are
starting to go out of sync on my development machines. OK, where to
begin ...
Changed state file format, so older state files will no longer work. The
changes aren't finalized yet, so expect more breakage.
Added getByte() and putByte() methods to serialized data, resulting in
smaller state files (previously, 1-byte values were stored as 4-byte ints).
Totally reworked controller handling code. Controller state is now
explicitly set with an ::update() method, making it easier to serialize.
Some work is still required on the serialization stuff for more advanced
controllers.
Added a 'Serializable' interface to all carts, device, controllers, etc
that can be (de)serialized. This fixes a long-standing design issue
which I personally caused many years ago.
Console switches state (SWCHB register) is now saved to state files.
Added beginnings of movie support. Basically, this saves an initial
state file, and thereafter continuously saves controller and console
switches state. Support is still somewhat rough and there's no UI for
it, but it does successfully save and later load/play state movies.
Removed specific events for driving controllers, and have them use
joystick events instead. This has the nice side effect that
joystick direction remapping 'just works' for driving controllers too.
Fixed issues with paddle emulation seen in 'Night Driver' ROM. Related
to this, removed a hack wrt paddles when grabmouse is enabled. There's
still some work to do when using the mouse to emulate paddles, but the
Stelladaptor and real paddles work fine.
Added beginnings of TrackBall CX-22 controller emulation. It doesn't
actually do anything yet, but the class is there :)
Probably some other stuff that I'm forgetting ...
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1385 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2007-10-03 21:41:19 +00:00
|
|
|
virtual void write(DigitalPin pin, bool value) { };
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update the entire digital and analog pin state according to the
|
|
|
|
events currently set.
|
|
|
|
*/
|
|
|
|
virtual void update() = 0;
|
|
|
|
|
2008-05-19 02:53:58 +00:00
|
|
|
/**
|
|
|
|
Notification method invoked by the system right before the
|
|
|
|
system resets its cycle counter to zero. It may be necessary
|
|
|
|
to override this method for devices that remember cycle counts.
|
|
|
|
*/
|
|
|
|
virtual void systemCyclesReset() { };
|
|
|
|
|
OK, another huge commit. I need to commit this now, because things are
starting to go out of sync on my development machines. OK, where to
begin ...
Changed state file format, so older state files will no longer work. The
changes aren't finalized yet, so expect more breakage.
Added getByte() and putByte() methods to serialized data, resulting in
smaller state files (previously, 1-byte values were stored as 4-byte ints).
Totally reworked controller handling code. Controller state is now
explicitly set with an ::update() method, making it easier to serialize.
Some work is still required on the serialization stuff for more advanced
controllers.
Added a 'Serializable' interface to all carts, device, controllers, etc
that can be (de)serialized. This fixes a long-standing design issue
which I personally caused many years ago.
Console switches state (SWCHB register) is now saved to state files.
Added beginnings of movie support. Basically, this saves an initial
state file, and thereafter continuously saves controller and console
switches state. Support is still somewhat rough and there's no UI for
it, but it does successfully save and later load/play state movies.
Removed specific events for driving controllers, and have them use
joystick events instead. This has the nice side effect that
joystick direction remapping 'just works' for driving controllers too.
Fixed issues with paddle emulation seen in 'Night Driver' ROM. Related
to this, removed a hack wrt paddles when grabmouse is enabled. There's
still some work to do when using the mouse to emulate paddles, but the
Stelladaptor and real paddles work fine.
Added beginnings of TrackBall CX-22 controller emulation. It doesn't
actually do anything yet, but the class is there :)
Probably some other stuff that I'm forgetting ...
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1385 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2007-10-03 21:41:19 +00:00
|
|
|
/**
|
|
|
|
Saves the current state of this controller to the given Serializer.
|
|
|
|
|
|
|
|
@param out The serializer device to save to.
|
|
|
|
@return The result of the save. True on success, false on failure.
|
|
|
|
*/
|
|
|
|
virtual bool save(Serializer& out) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Loads the current state of this controller from the given Deserializer.
|
|
|
|
|
|
|
|
@param in The deserializer device to load from.
|
|
|
|
@return The result of the load. True on success, false on failure.
|
|
|
|
*/
|
|
|
|
virtual bool load(Deserializer& in);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the name of this controller.
|
|
|
|
*/
|
|
|
|
virtual string name() const;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2008-04-11 17:56:35 +00:00
|
|
|
/**
|
|
|
|
Returns more detailed information about this controller.
|
|
|
|
*/
|
|
|
|
virtual string about() const;
|
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
public:
|
|
|
|
/// Constant which represents maximum resistance for analog pins
|
|
|
|
static const Int32 maximumResistance;
|
|
|
|
|
|
|
|
/// Constant which represents minimum resistance for analog pins
|
|
|
|
static const Int32 minimumResistance;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Specifies which jack the controller is plugged in
|
|
|
|
const Jack myJack;
|
|
|
|
|
|
|
|
/// Reference to the event object this controller uses
|
|
|
|
const Event& myEvent;
|
|
|
|
|
2008-04-13 23:43:14 +00:00
|
|
|
/// Pointer to the System object (used for timing purposes)
|
|
|
|
const System& mySystem;
|
|
|
|
|
2005-11-12 22:59:20 +00:00
|
|
|
/// Specifies which type of controller this is (defined by child classes)
|
2007-01-05 17:54:23 +00:00
|
|
|
const Type myType;
|
2005-11-12 22:59:20 +00:00
|
|
|
|
OK, another huge commit. I need to commit this now, because things are
starting to go out of sync on my development machines. OK, where to
begin ...
Changed state file format, so older state files will no longer work. The
changes aren't finalized yet, so expect more breakage.
Added getByte() and putByte() methods to serialized data, resulting in
smaller state files (previously, 1-byte values were stored as 4-byte ints).
Totally reworked controller handling code. Controller state is now
explicitly set with an ::update() method, making it easier to serialize.
Some work is still required on the serialization stuff for more advanced
controllers.
Added a 'Serializable' interface to all carts, device, controllers, etc
that can be (de)serialized. This fixes a long-standing design issue
which I personally caused many years ago.
Console switches state (SWCHB register) is now saved to state files.
Added beginnings of movie support. Basically, this saves an initial
state file, and thereafter continuously saves controller and console
switches state. Support is still somewhat rough and there's no UI for
it, but it does successfully save and later load/play state movies.
Removed specific events for driving controllers, and have them use
joystick events instead. This has the nice side effect that
joystick direction remapping 'just works' for driving controllers too.
Fixed issues with paddle emulation seen in 'Night Driver' ROM. Related
to this, removed a hack wrt paddles when grabmouse is enabled. There's
still some work to do when using the mouse to emulate paddles, but the
Stelladaptor and real paddles work fine.
Added beginnings of TrackBall CX-22 controller emulation. It doesn't
actually do anything yet, but the class is there :)
Probably some other stuff that I'm forgetting ...
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1385 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2007-10-03 21:41:19 +00:00
|
|
|
/// Specifies the name of this controller based on type
|
|
|
|
string myName;
|
|
|
|
|
|
|
|
/// The boolean value on each digital pin
|
|
|
|
bool myDigitalPinState[5];
|
|
|
|
|
|
|
|
/// The analog value on each analog pin
|
|
|
|
Int32 myAnalogPinValue[2];
|
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
protected:
|
|
|
|
// Copy constructor isn't supported by controllers so make it private
|
|
|
|
Controller(const Controller&);
|
|
|
|
|
|
|
|
// Assignment operator isn't supported by controllers so make it private
|
|
|
|
Controller& operator = (const Controller&);
|
|
|
|
};
|
|
|
|
|
2005-11-12 22:59:20 +00:00
|
|
|
#endif
|