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-2014 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 // $Id: MindLink.cxx 2838 2014-01-17 23:34:03Z stephena $
18 //============================================================================
19 
20 #include "Event.hxx"
21 #include "MindLink.hxx"
22 
23 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MindLink(Jack jack,const Event & event,const System & system)24 MindLink::MindLink(Jack jack, const Event& event, const System& system)
25   : Controller(jack, event, system, Controller::MindLink),
26     myMindlinkPos(0x2800),
27     myMindlinkShift(1),
28     myMouseEnabled(false)
29 {
30   myDigitalPinState[One]   = true;
31   myDigitalPinState[Two]   = true;
32   myDigitalPinState[Three] = true;
33   myDigitalPinState[Four]  = true;
34 
35   // Analog pins are never used by the MindLink
36   myAnalogPinValue[Five] = myAnalogPinValue[Nine] = maximumResistance;
37 }
38 
39 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
~MindLink()40 MindLink::~MindLink()
41 {
42 }
43 
44 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
update()45 void MindLink::update()
46 {
47   myDigitalPinState[One]   =
48   myDigitalPinState[Two]   =
49   myDigitalPinState[Three] =
50   myDigitalPinState[Four]  = true;
51 
52   if(!myMouseEnabled)
53     return;
54 
55   myMindlinkPos = (myMindlinkPos & 0x3fffffff) +
56                   (myEvent.get(Event::MouseAxisXValue) << 3);
57   if(myMindlinkPos < 0x2800)
58     myMindlinkPos = 0x2800;
59   if(myMindlinkPos >= 0x3800)
60     myMindlinkPos = 0x3800;
61 
62   myMindlinkShift = 1;
63   nextMindlinkBit();
64 
65   if(myEvent.get(Event::MouseButtonLeftValue) ||
66      myEvent.get(Event::MouseButtonRightValue))
67     myMindlinkPos |= 0x4000;  // this bit starts a game
68 }
69 
70 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nextMindlinkBit()71 void MindLink::nextMindlinkBit()
72 {
73   if(myDigitalPinState[One])
74   {
75     myDigitalPinState[Three] = false;
76     myDigitalPinState[Four]  = false;
77     if(myMindlinkPos & myMindlinkShift)
78       myDigitalPinState[Four] = true;
79     myMindlinkShift <<= 1;
80 	}
81 }
82 
83 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
setMouseControl(Controller::Type xtype,int xid,Controller::Type ytype,int yid)84 bool MindLink::setMouseControl(
85     Controller::Type xtype, int xid, Controller::Type ytype, int yid)
86 {
87   // Currently, the mindlink takes full control of the mouse, but only ever
88   // uses the x-axis, and both mouse buttons for the single mindlink button
89   // As well, there's no separate setting for x and y axis, so any
90   // combination of Controller and id is valid
91   myMouseEnabled = (xtype == myType || ytype == myType) &&
92                    (xid != -1 || yid != -1);
93   return true;
94 }
95