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 | #include "Event.hxx" |
19 | #include "Genesis.hxx" |
20 | |
21 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
22 | Genesis::Genesis(Jack jack, const Event& event, const System& system) |
23 | : Controller(jack, event, system, Controller::Type::Genesis), |
24 | myControlID(-1) |
25 | { |
26 | if(myJack == Jack::Left) |
27 | { |
28 | myUpEvent = Event::JoystickZeroUp; |
29 | myDownEvent = Event::JoystickZeroDown; |
30 | myLeftEvent = Event::JoystickZeroLeft; |
31 | myRightEvent = Event::JoystickZeroRight; |
32 | myFire1Event = Event::JoystickZeroFire; |
33 | myFire2Event = Event::JoystickZeroFire5; |
34 | } |
35 | else |
36 | { |
37 | myUpEvent = Event::JoystickOneUp; |
38 | myDownEvent = Event::JoystickOneDown; |
39 | myLeftEvent = Event::JoystickOneLeft; |
40 | myRightEvent = Event::JoystickOneRight; |
41 | myFire1Event = Event::JoystickOneFire; |
42 | myFire2Event = Event::JoystickOneFire5; |
43 | } |
44 | |
45 | setPin(AnalogPin::Five, MIN_RESISTANCE); |
46 | setPin(AnalogPin::Nine, MIN_RESISTANCE); |
47 | } |
48 | |
49 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
50 | void Genesis::update() |
51 | { |
52 | // Digital events (from keyboard or joystick hats & buttons) |
53 | setPin(DigitalPin::One, myEvent.get(myUpEvent) == 0); |
54 | setPin(DigitalPin::Two, myEvent.get(myDownEvent) == 0); |
55 | setPin(DigitalPin::Three, myEvent.get(myLeftEvent) == 0); |
56 | setPin(DigitalPin::Four, myEvent.get(myRightEvent) == 0); |
57 | setPin(DigitalPin::Six, myEvent.get(myFire1Event) == 0); |
58 | |
59 | // The Genesis has one more button (C) that can be read by the 2600 |
60 | // However, it seems to work opposite to the BoosterGrip controller, |
61 | // in that the logic is inverted |
62 | setPin(AnalogPin::Five, |
63 | (myEvent.get(myFire2Event) == 0) ? MIN_RESISTANCE : MAX_RESISTANCE |
64 | ); |
65 | |
66 | // Mouse motion and button events |
67 | if(myControlID > -1) |
68 | { |
69 | // The following code was taken from z26 |
70 | #define MJ_Threshold 2 |
71 | int mousex = myEvent.get(Event::MouseAxisXValue), |
72 | mousey = myEvent.get(Event::MouseAxisYValue); |
73 | if(mousex || mousey) |
74 | { |
75 | if((!(abs(mousey) > abs(mousex) << 1)) && (abs(mousex) >= MJ_Threshold)) |
76 | { |
77 | if(mousex < 0) |
78 | setPin(DigitalPin::Three, false); |
79 | else if(mousex > 0) |
80 | setPin(DigitalPin::Four, false); |
81 | } |
82 | |
83 | if((!(abs(mousex) > abs(mousey) << 1)) && (abs(mousey) >= MJ_Threshold)) |
84 | { |
85 | if(mousey < 0) |
86 | setPin(DigitalPin::One, false); |
87 | else if(mousey > 0) |
88 | setPin(DigitalPin::Two, false); |
89 | } |
90 | } |
91 | // Get mouse button state |
92 | if(myEvent.get(Event::MouseButtonLeftValue)) |
93 | setPin(DigitalPin::Six, false); |
94 | if(myEvent.get(Event::MouseButtonRightValue)) |
95 | setPin(AnalogPin::Five, MAX_RESISTANCE); |
96 | } |
97 | } |
98 | |
99 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
100 | bool Genesis::setMouseControl( |
101 | Controller::Type xtype, int xid, Controller::Type ytype, int yid) |
102 | { |
103 | // Currently, the Genesis controller takes full control of the mouse, using |
104 | // both axes for its two degrees of movement, and the left/right buttons for |
105 | // 'B' and 'C', respectively |
106 | if(xtype == Controller::Type::Genesis && ytype == Controller::Type::Genesis && xid == yid) |
107 | { |
108 | myControlID = ((myJack == Jack::Left && xid == 0) || |
109 | (myJack == Jack::Right && xid == 1) |
110 | ) ? xid : -1; |
111 | } |
112 | else |
113 | myControlID = -1; |
114 | |
115 | return true; |
116 | } |
117 | |