1//============================================================================
2//
3// SSSS tt lll lll
4// SS SS tt ll ll
5// SS tttttt eeee ll ll aaaa
6// SSSS tt ee ee ll ll aa
7// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8// SS SS tt ee ll ll aa aa
9// SSSS ttt eeeee llll llll aaaaa
10//
11// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
12// and the Stella Team
13//
14// See the file "License.txt" for information on usage and redistribution of
15// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16//============================================================================
17
18#ifndef JOYSTICK_HXX
19#define JOYSTICK_HXX
20
21#include "bspf.hxx"
22#include "Control.hxx"
23#include "Event.hxx"
24
25/**
26 The standard Atari 2600 joystick controller.
27
28 @author Bradford W. Mott
29*/
30class Joystick : public Controller
31{
32 public:
33 /**
34 Create a new joystick controller plugged into the specified jack
35
36 @param jack The jack the controller is plugged into
37 @param event The event object to use for events
38 @param system The system using this controller
39 */
40 Joystick(Jack jack, const Event& event, const System& system);
41 virtual ~Joystick() = default;
42
43 public:
44 /**
45 Update the entire digital and analog pin state according to the
46 events currently set.
47 */
48 void update() override;
49
50 /**
51 Returns the name of this controller.
52 */
53 string name() const override { return "Joystick"; }
54
55 /**
56 Determines how this controller will treat values received from the
57 X/Y axis and left/right buttons of the mouse. Since not all controllers
58 use the mouse the same way (or at all), it's up to the specific class to
59 decide how to use this data.
60
61 In the current implementation, the left button is tied to the X axis,
62 and the right one tied to the Y axis.
63
64 @param xtype The controller to use for x-axis data
65 @param xid The controller ID to use for x-axis data (-1 for no id)
66 @param ytype The controller to use for y-axis data
67 @param yid The controller ID to use for y-axis data (-1 for no id)
68
69 @return Whether the controller supports using the mouse
70 */
71 bool setMouseControl(
72 Controller::Type xtype, int xid, Controller::Type ytype, int yid) override;
73
74 /**
75 Sets the deadzone amount for real analog joysticks.
76 Technically, this isn't really used by the Joystick class at all,
77 but it seemed like the best place to put it.
78 */
79 static void setDeadZone(int deadzone);
80 inline static int deadzone() { return _DEAD_ZONE; }
81
82 private:
83 // Pre-compute the events we care about based on given port
84 // This will eliminate test for left or right port in update()
85 Event::Type myUpEvent, myDownEvent, myLeftEvent, myRightEvent,
86 myXAxisValue, myYAxisValue, myFireEvent;
87
88 // Controller to emulate in normal mouse axis mode
89 int myControlID;
90
91 static int _DEAD_ZONE;
92
93 private:
94 // Following constructors and assignment operators not supported
95 Joystick() = delete;
96 Joystick(const Joystick&) = delete;
97 Joystick(Joystick&&) = delete;
98 Joystick& operator=(const Joystick&) = delete;
99 Joystick& operator=(Joystick&&) = delete;
100};
101
102#endif
103