mirror of https://github.com/stella-emu/stella.git
- Added Driving Controllers to the list of devices supported by the
Stelladaptor. - Thanks for Mark Grebe for this code. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@255 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
c9f9448e77
commit
4c15baa3b1
File diff suppressed because it is too large
Load Diff
|
@ -1,128 +1,136 @@
|
|||
//============================================================================
|
||||
//
|
||||
// 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-1998 by Bradford W. Mott
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: Driving.cxx,v 1.2 2004-05-28 19:08:12 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <assert.h>
|
||||
#include "Event.hxx"
|
||||
#include "Driving.hxx"
|
||||
#include "System.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Driving::Driving(Jack jack, const Event& event)
|
||||
: Controller(jack, event)
|
||||
{
|
||||
myCounter = 0;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Driving::~Driving()
|
||||
{
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool Driving::read(DigitalPin pin)
|
||||
{
|
||||
// Gray codes for clockwise rotation
|
||||
static const uInt8 clockwise[] = { 0x03, 0x01, 0x00, 0x02 };
|
||||
|
||||
// Gray codes for counter-clockwise rotation
|
||||
static const uInt8 counterclockwise[] = { 0x03, 0x02, 0x00, 0x01 };
|
||||
|
||||
// Delay used for moving through the gray code tables
|
||||
const uInt32 delay = 20;
|
||||
|
||||
switch(pin)
|
||||
{
|
||||
case One:
|
||||
++myCounter;
|
||||
|
||||
if(myJack == Left)
|
||||
{
|
||||
if(myEvent.get(Event::DrivingZeroCounterClockwise) != 0)
|
||||
{
|
||||
return (counterclockwise[(myCounter / delay) & 0x03] & 0x01) != 0;
|
||||
}
|
||||
else if(myEvent.get(Event::DrivingZeroClockwise) != 0)
|
||||
{
|
||||
return (clockwise[(myCounter / delay) & 0x03] & 0x01) != 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(myEvent.get(Event::DrivingOneCounterClockwise) != 0)
|
||||
{
|
||||
return (counterclockwise[(myCounter / delay) & 0x03] & 0x01) != 0;
|
||||
}
|
||||
else if(myEvent.get(Event::DrivingOneClockwise) != 0)
|
||||
{
|
||||
return (clockwise[(myCounter / delay) & 0x03] & 0x01) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
case Two:
|
||||
if(myJack == Left)
|
||||
{
|
||||
if(myEvent.get(Event::DrivingZeroCounterClockwise) != 0)
|
||||
{
|
||||
return (counterclockwise[(myCounter / delay) & 0x03] & 0x02) != 0;
|
||||
}
|
||||
else if(myEvent.get(Event::DrivingZeroClockwise) != 0)
|
||||
{
|
||||
return (clockwise[(myCounter / delay) & 0x03] & 0x02) != 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(myEvent.get(Event::DrivingOneCounterClockwise) != 0)
|
||||
{
|
||||
return (counterclockwise[(myCounter / delay) & 0x03] & 0x02) != 0;
|
||||
}
|
||||
else if(myEvent.get(Event::DrivingOneClockwise) != 0)
|
||||
{
|
||||
return (clockwise[(myCounter / delay) & 0x03] & 0x02) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
case Three:
|
||||
return true;
|
||||
|
||||
case Four:
|
||||
return true;
|
||||
|
||||
case Six:
|
||||
return (myJack == Left) ? (myEvent.get(Event::DrivingZeroFire) == 0) :
|
||||
(myEvent.get(Event::DrivingOneFire) == 0);
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Int32 Driving::read(AnalogPin)
|
||||
{
|
||||
// Analog pins are not connect in driving controller so we have
|
||||
// infinite resistance
|
||||
return maximumResistance;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void Driving::write(DigitalPin, bool)
|
||||
{
|
||||
// Writing doesn't do anything to the driving controller...
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
//
|
||||
// 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-1998 by Bradford W. Mott
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: Driving.cxx,v 1.3 2004-06-04 12:22:12 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <assert.h>
|
||||
#include "Event.hxx"
|
||||
#include "Driving.hxx"
|
||||
#include "System.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Driving::Driving(Jack jack, const Event& event)
|
||||
: Controller(jack, event)
|
||||
{
|
||||
myCounter = 0;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Driving::~Driving()
|
||||
{
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool Driving::read(DigitalPin pin)
|
||||
{
|
||||
// Gray codes for clockwise rotation
|
||||
static const uInt8 clockwise[] = { 0x03, 0x01, 0x00, 0x02 };
|
||||
|
||||
// Gray codes for counter-clockwise rotation
|
||||
static const uInt8 counterclockwise[] = { 0x03, 0x02, 0x00, 0x01 };
|
||||
|
||||
// Delay used for moving through the gray code tables
|
||||
const uInt32 delay = 20;
|
||||
|
||||
switch(pin)
|
||||
{
|
||||
case One:
|
||||
++myCounter;
|
||||
|
||||
if(myJack == Left)
|
||||
{
|
||||
if(myEvent.get(Event::DrivingZeroCounterClockwise) != 0)
|
||||
{
|
||||
return (counterclockwise[(myCounter / delay) & 0x03] & 0x01) != 0;
|
||||
}
|
||||
else if(myEvent.get(Event::DrivingZeroClockwise) != 0)
|
||||
{
|
||||
return (clockwise[(myCounter / delay) & 0x03] & 0x01) != 0;
|
||||
}
|
||||
else
|
||||
return(myEvent.get(Event::DrivingZeroValue) & 0x01);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(myEvent.get(Event::DrivingOneCounterClockwise) != 0)
|
||||
{
|
||||
return (counterclockwise[(myCounter / delay) & 0x03] & 0x01) != 0;
|
||||
}
|
||||
else if(myEvent.get(Event::DrivingOneClockwise) != 0)
|
||||
{
|
||||
return (clockwise[(myCounter / delay) & 0x03] & 0x01) != 0;
|
||||
}
|
||||
else
|
||||
return(myEvent.get(Event::DrivingOneValue) & 0x01);
|
||||
}
|
||||
|
||||
case Two:
|
||||
if(myJack == Left)
|
||||
{
|
||||
if(myEvent.get(Event::DrivingZeroCounterClockwise) != 0)
|
||||
{
|
||||
return (counterclockwise[(myCounter / delay) & 0x03] & 0x02) != 0;
|
||||
}
|
||||
else if(myEvent.get(Event::DrivingZeroClockwise) != 0)
|
||||
{
|
||||
return (clockwise[(myCounter / delay) & 0x03] & 0x02) != 0;
|
||||
}
|
||||
else
|
||||
return(myEvent.get(Event::DrivingZeroValue) & 0x02);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(myEvent.get(Event::DrivingOneCounterClockwise) != 0)
|
||||
{
|
||||
return (counterclockwise[(myCounter / delay) & 0x03] & 0x02) != 0;
|
||||
}
|
||||
else if(myEvent.get(Event::DrivingOneClockwise) != 0)
|
||||
{
|
||||
return (clockwise[(myCounter / delay) & 0x03] & 0x02) != 0;
|
||||
}
|
||||
else
|
||||
return(myEvent.get(Event::DrivingOneValue) & 0x02);
|
||||
}
|
||||
|
||||
case Three:
|
||||
return true;
|
||||
|
||||
case Four:
|
||||
return true;
|
||||
|
||||
case Six:
|
||||
return (myJack == Left) ? (myEvent.get(Event::DrivingZeroFire) == 0) :
|
||||
(myEvent.get(Event::DrivingOneFire) == 0);
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Int32 Driving::read(AnalogPin)
|
||||
{
|
||||
// Analog pins are not connect in driving controller so we have
|
||||
// infinite resistance
|
||||
return maximumResistance;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void Driving::write(DigitalPin, bool)
|
||||
{
|
||||
// Writing doesn't do anything to the driving controller...
|
||||
}
|
||||
|
||||
|
|
|
@ -1,105 +1,107 @@
|
|||
//============================================================================
|
||||
//
|
||||
// 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-1998 by Bradford W. Mott
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: Event.hxx,v 1.4 2003-09-25 16:20:34 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef EVENT_HXX
|
||||
#define EVENT_HXX
|
||||
|
||||
class Event;
|
||||
|
||||
#include "bspf.hxx"
|
||||
|
||||
/**
|
||||
@author Bradford W. Mott
|
||||
@version $Id: Event.hxx,v 1.4 2003-09-25 16:20:34 stephena Exp $
|
||||
*/
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Enumeration of console and controller event types
|
||||
*/
|
||||
enum Type
|
||||
{
|
||||
NoType,
|
||||
ConsoleOn, ConsoleOff, ConsoleColor, ConsoleBlackWhite,
|
||||
ConsoleLeftDifficultyA, ConsoleLeftDifficultyB,
|
||||
ConsoleRightDifficultyA, ConsoleRightDifficultyB,
|
||||
ConsoleSelect, ConsoleReset,
|
||||
|
||||
JoystickZeroUp, JoystickZeroDown, JoystickZeroLeft,
|
||||
JoystickZeroRight, JoystickZeroFire,
|
||||
JoystickOneUp, JoystickOneDown, JoystickOneLeft,
|
||||
JoystickOneRight, JoystickOneFire,
|
||||
|
||||
BoosterGripZeroTrigger, BoosterGripZeroBooster,
|
||||
BoosterGripOneTrigger, BoosterGripOneBooster,
|
||||
|
||||
PaddleZeroResistance, PaddleZeroFire,
|
||||
PaddleOneResistance, PaddleOneFire,
|
||||
PaddleTwoResistance, PaddleTwoFire,
|
||||
PaddleThreeResistance, PaddleThreeFire,
|
||||
|
||||
KeyboardZero1, KeyboardZero2, KeyboardZero3,
|
||||
KeyboardZero4, KeyboardZero5, KeyboardZero6,
|
||||
KeyboardZero7, KeyboardZero8, KeyboardZero9,
|
||||
KeyboardZeroStar, KeyboardZero0, KeyboardZeroPound,
|
||||
|
||||
KeyboardOne1, KeyboardOne2, KeyboardOne3,
|
||||
KeyboardOne4, KeyboardOne5, KeyboardOne6,
|
||||
KeyboardOne7, KeyboardOne8, KeyboardOne9,
|
||||
KeyboardOneStar, KeyboardOne0, KeyboardOnePound,
|
||||
|
||||
DrivingZeroClockwise, DrivingZeroCounterClockwise, DrivingZeroFire,
|
||||
DrivingOneClockwise, DrivingOneCounterClockwise, DrivingOneFire,
|
||||
|
||||
ChangeState, LoadState, SaveState, TakeSnapshot, Pause, Quit,
|
||||
|
||||
LastType
|
||||
};
|
||||
|
||||
public:
|
||||
/**
|
||||
Create a new event object
|
||||
*/
|
||||
Event();
|
||||
|
||||
/**
|
||||
Destructor
|
||||
*/
|
||||
virtual ~Event();
|
||||
|
||||
public:
|
||||
/**
|
||||
Get the value associated with the event of the specified type
|
||||
*/
|
||||
virtual Int32 get(Type type) const;
|
||||
|
||||
/**
|
||||
Set the value associated with the event of the specified type
|
||||
*/
|
||||
virtual void set(Type type, Int32 value);
|
||||
|
||||
protected:
|
||||
// Number of event types there are
|
||||
const Int32 myNumberOfTypes;
|
||||
|
||||
// Array of values associated with each event type
|
||||
Int32 myValues[LastType];
|
||||
};
|
||||
#endif
|
||||
|
||||
//============================================================================
|
||||
//
|
||||
// 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-1998 by Bradford W. Mott
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: Event.hxx,v 1.5 2004-06-04 12:22:12 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef EVENT_HXX
|
||||
#define EVENT_HXX
|
||||
|
||||
class Event;
|
||||
|
||||
#include "bspf.hxx"
|
||||
|
||||
/**
|
||||
@author Bradford W. Mott
|
||||
@version $Id: Event.hxx,v 1.5 2004-06-04 12:22:12 stephena Exp $
|
||||
*/
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Enumeration of console and controller event types
|
||||
*/
|
||||
enum Type
|
||||
{
|
||||
NoType,
|
||||
ConsoleOn, ConsoleOff, ConsoleColor, ConsoleBlackWhite,
|
||||
ConsoleLeftDifficultyA, ConsoleLeftDifficultyB,
|
||||
ConsoleRightDifficultyA, ConsoleRightDifficultyB,
|
||||
ConsoleSelect, ConsoleReset,
|
||||
|
||||
JoystickZeroUp, JoystickZeroDown, JoystickZeroLeft,
|
||||
JoystickZeroRight, JoystickZeroFire,
|
||||
JoystickOneUp, JoystickOneDown, JoystickOneLeft,
|
||||
JoystickOneRight, JoystickOneFire,
|
||||
|
||||
BoosterGripZeroTrigger, BoosterGripZeroBooster,
|
||||
BoosterGripOneTrigger, BoosterGripOneBooster,
|
||||
|
||||
PaddleZeroResistance, PaddleZeroFire,
|
||||
PaddleOneResistance, PaddleOneFire,
|
||||
PaddleTwoResistance, PaddleTwoFire,
|
||||
PaddleThreeResistance, PaddleThreeFire,
|
||||
|
||||
KeyboardZero1, KeyboardZero2, KeyboardZero3,
|
||||
KeyboardZero4, KeyboardZero5, KeyboardZero6,
|
||||
KeyboardZero7, KeyboardZero8, KeyboardZero9,
|
||||
KeyboardZeroStar, KeyboardZero0, KeyboardZeroPound,
|
||||
|
||||
KeyboardOne1, KeyboardOne2, KeyboardOne3,
|
||||
KeyboardOne4, KeyboardOne5, KeyboardOne6,
|
||||
KeyboardOne7, KeyboardOne8, KeyboardOne9,
|
||||
KeyboardOneStar, KeyboardOne0, KeyboardOnePound,
|
||||
|
||||
DrivingZeroClockwise, DrivingZeroCounterClockwise, DrivingZeroValue,
|
||||
DrivingZeroFire,
|
||||
DrivingOneClockwise, DrivingOneCounterClockwise, DrivingOneValue,
|
||||
DrivingOneFire,
|
||||
|
||||
ChangeState, LoadState, SaveState, TakeSnapshot, Pause, Quit,
|
||||
|
||||
LastType
|
||||
};
|
||||
|
||||
public:
|
||||
/**
|
||||
Create a new event object
|
||||
*/
|
||||
Event();
|
||||
|
||||
/**
|
||||
Destructor
|
||||
*/
|
||||
virtual ~Event();
|
||||
|
||||
public:
|
||||
/**
|
||||
Get the value associated with the event of the specified type
|
||||
*/
|
||||
virtual Int32 get(Type type) const;
|
||||
|
||||
/**
|
||||
Set the value associated with the event of the specified type
|
||||
*/
|
||||
virtual void set(Type type, Int32 value);
|
||||
|
||||
protected:
|
||||
// Number of event types there are
|
||||
const Int32 myNumberOfTypes;
|
||||
|
||||
// Array of values associated with each event type
|
||||
Int32 myValues[LastType];
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue