1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//============================================================================
//
// 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-2007 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Paddles.cxx,v 1.8 2007/01/05 17:54:23 stephena Exp $
//============================================================================
#include "Event.hxx"
#include "Paddles.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Paddles::Paddles(Jack jack, const Event& event, bool swap)
: Controller(jack, event, Controller::Paddles)
{
// Swap the paddle events, from paddle 0 <=> 1 and paddle 2 <=> 3
if(!swap)
{
// Pin Three
myPinEvents[0][0] = Event::PaddleOneFire;
myPinEvents[0][1] = Event::PaddleThreeFire;
// Pin Four
myPinEvents[1][0] = Event::PaddleZeroFire;
myPinEvents[1][1] = Event::PaddleTwoFire;
// Pin Five
myPinEvents[2][0] = Event::PaddleOneResistance;
myPinEvents[2][1] = Event::PaddleThreeResistance;
// Pin Nine
myPinEvents[3][0] = Event::PaddleZeroResistance;
myPinEvents[3][1] = Event::PaddleTwoResistance;
}
else
{
// Pin Three (swapped)
myPinEvents[0][0] = Event::PaddleZeroFire;
myPinEvents[0][1] = Event::PaddleTwoFire;
// Pin Four (swapped)
myPinEvents[1][0] = Event::PaddleOneFire;
myPinEvents[1][1] = Event::PaddleThreeFire;
// Pin Five (swapped)
myPinEvents[2][0] = Event::PaddleZeroResistance;
myPinEvents[2][1] = Event::PaddleTwoResistance;
// Pin Nine (swapped)
myPinEvents[3][0] = Event::PaddleOneResistance;
myPinEvents[3][1] = Event::PaddleThreeResistance;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Paddles::~Paddles()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Paddles::read(DigitalPin pin)
{
switch(pin)
{
case Three:
return (myJack == Left) ? (myEvent.get(myPinEvents[0][0]) == 0) :
(myEvent.get(myPinEvents[0][1]) == 0);
case Four:
return (myJack == Left) ? (myEvent.get(myPinEvents[1][0]) == 0) :
(myEvent.get(myPinEvents[1][1]) == 0);
default:
// Other pins are not connected (floating high)
return true;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Int32 Paddles::read(AnalogPin pin)
{
switch(pin)
{
case Five:
return (myJack == Left) ? myEvent.get(myPinEvents[2][0]) :
myEvent.get(myPinEvents[2][1]);
case Nine:
return (myJack == Left) ? myEvent.get(myPinEvents[3][0]) :
myEvent.get(myPinEvents[3][1]);
default:
return maximumResistance;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Paddles::write(DigitalPin, bool)
{
// Writing doesn't do anything to the paddles...
}