| 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 DRIVING_HXX | 
|---|
| 19 | #define DRIVING_HXX | 
|---|
| 20 |  | 
|---|
| 21 | #include "Control.hxx" | 
|---|
| 22 | #include "Event.hxx" | 
|---|
| 23 |  | 
|---|
| 24 | /** | 
|---|
| 25 | The standard Atari 2600 Indy 500 driving controller. | 
|---|
| 26 |  | 
|---|
| 27 | @author  Bradford W. Mott | 
|---|
| 28 | */ | 
|---|
| 29 | class Driving : public Controller | 
|---|
| 30 | { | 
|---|
| 31 | public: | 
|---|
| 32 | /** | 
|---|
| 33 | Create a new Indy 500 driving controller plugged into | 
|---|
| 34 | 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 | Driving(Jack jack, const Event& event, const System& system); | 
|---|
| 41 | virtual ~Driving() = 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 "Driving"; } | 
|---|
| 54 |  | 
|---|
| 55 | /** | 
|---|
| 56 | Answers whether the controller is intrinsically an analog controller. | 
|---|
| 57 | */ | 
|---|
| 58 | bool isAnalog() const override { return true; } | 
|---|
| 59 |  | 
|---|
| 60 | /** | 
|---|
| 61 | Determines how this controller will treat values received from the | 
|---|
| 62 | X/Y axis and left/right buttons of the mouse.  Since not all controllers | 
|---|
| 63 | use the mouse the same way (or at all), it's up to the specific class to | 
|---|
| 64 | decide how to use this data. | 
|---|
| 65 |  | 
|---|
| 66 | In the current implementation, the left button is tied to the X axis, | 
|---|
| 67 | and the right one tied to the Y axis. | 
|---|
| 68 |  | 
|---|
| 69 | @param xtype  The controller to use for x-axis data | 
|---|
| 70 | @param xid    The controller ID to use for x-axis data (-1 for no id) | 
|---|
| 71 | @param ytype  The controller to use for y-axis data | 
|---|
| 72 | @param yid    The controller ID to use for y-axis data (-1 for no id) | 
|---|
| 73 |  | 
|---|
| 74 | @return  Whether the controller supports using the mouse | 
|---|
| 75 | */ | 
|---|
| 76 | bool setMouseControl( | 
|---|
| 77 | Controller::Type xtype, int xid, Controller::Type ytype, int yid) override; | 
|---|
| 78 |  | 
|---|
| 79 | private: | 
|---|
| 80 | // Counter to iterate through the gray codes | 
|---|
| 81 | uInt32 myCounter; | 
|---|
| 82 |  | 
|---|
| 83 | // Index into the gray code table | 
|---|
| 84 | uInt32 myGrayIndex; | 
|---|
| 85 |  | 
|---|
| 86 | // Y axis value from last yaxis event that was used to generate a new | 
|---|
| 87 | // gray code | 
|---|
| 88 | int myLastYaxis; | 
|---|
| 89 |  | 
|---|
| 90 | // Pre-compute the events we care about based on given port | 
|---|
| 91 | // This will eliminate test for left or right port in update() | 
|---|
| 92 | Event::Type myCWEvent, myCCWEvent, myFireEvent, | 
|---|
| 93 | myXAxisValue, myYAxisValue; | 
|---|
| 94 |  | 
|---|
| 95 | // Controller to emulate in normal mouse axis mode | 
|---|
| 96 | int myControlID; | 
|---|
| 97 |  | 
|---|
| 98 | // Controllers to emulate in 'specific' mouse axis mode | 
|---|
| 99 | int myControlIDX, myControlIDY; | 
|---|
| 100 |  | 
|---|
| 101 | private: | 
|---|
| 102 | // Following constructors and assignment operators not supported | 
|---|
| 103 | Driving() = delete; | 
|---|
| 104 | Driving(const Driving&) = delete; | 
|---|
| 105 | Driving(Driving&&) = delete; | 
|---|
| 106 | Driving& operator=(const Driving&) = delete; | 
|---|
| 107 | Driving& operator=(Driving&&) = delete; | 
|---|
| 108 | }; | 
|---|
| 109 |  | 
|---|
| 110 | #endif | 
|---|
| 111 |  | 
|---|