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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//============================================================================
//
// 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: Control.hxx,v 1.9 2007/02/22 02:15:46 stephena Exp $
//============================================================================
#ifndef CONTROLLER_HXX
#define CONTROLLER_HXX
class Controller;
class Event;
class System;
#include "m6502/src/bspf/src/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.
This is a base class for all controllers. It provides a view
of the controller from the perspective of the controller's jack.
@author Bradford W. Mott
@version $Id: Control.hxx,v 1.9 2007/02/22 02:15:46 stephena Exp $
*/
class Controller
{
public:
/**
Enumeration of the controller jacks
*/
enum Jack
{
Left, Right
};
/**
Enumeration of the controller types
*/
enum Type
{
BoosterGrip, Driving, Keyboard, Paddles, Joystick,
TrakBall, AtariVox
};
public:
/**
Create a new controller plugged into the specified jack
@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
*/
Controller(Jack jack, const Event& event, Type type);
/**
Destructor
*/
virtual ~Controller();
/**
Returns the type of this controller.
*/
Type type();
/**
Inform this controller about the current System.
*/
void setSystem(System* system) { mySystem = system; }
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
*/
virtual bool read(DigitalPin pin) = 0;
/**
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
*/
virtual Int32 read(AnalogPin pin) = 0;
/**
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
*/
virtual void write(DigitalPin pin, bool value) = 0;
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;
/// Specifies which type of controller this is (defined by child classes)
const Type myType;
/// Pointer to the System object (used for timing purposes)
System* mySystem;
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&);
};
#endif