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-2021 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 "MindLink.hxx"
20 
21 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MindLink(Jack jack,const Event & event,const System & system)22 MindLink::MindLink(Jack jack, const Event& event, const System& system)
23   : Controller(jack, event, system, Controller::Type::MindLink)
24 {
25 }
26 
27 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
update()28 void MindLink::update()
29 {
30   setPin(DigitalPin::One, true);
31   setPin(DigitalPin::Two, true);
32   setPin(DigitalPin::Three, true);
33   setPin(DigitalPin::Four, true);
34 
35   if(!myMouseEnabled)
36     return;
37 
38   myMindlinkPos = BSPF::clamp((myMindlinkPos & ~CALIBRATE_FLAG) +
39                               myEvent.get(Event::MouseAxisXMove) * MOUSE_SENSITIVITY,
40                               MIN_POS, MAX_POS);
41 
42   if(myEvent.get(Event::MouseButtonLeftValue) ||
43      myEvent.get(Event::MouseButtonRightValue))
44     myMindlinkPos = CALIBRATE_FLAG; // flag starts game & calibates
45 
46   myMindlinkShift = 1; // start transfer with least significant bit
47   nextMindlinkBit();
48 }
49 
50 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nextMindlinkBit()51 void MindLink::nextMindlinkBit()
52 {
53   if(getPin(DigitalPin::One))
54   {
55     setPin(DigitalPin::Three, false);
56     setPin(DigitalPin::Four, false);
57     if(myMindlinkPos & myMindlinkShift)
58       setPin(DigitalPin::Four, true);
59     myMindlinkShift <<= 1; // next bit
60   }
61 }
62 
63 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
setMouseControl(Controller::Type xtype,int xid,Controller::Type ytype,int yid)64 bool MindLink::setMouseControl(
65     Controller::Type xtype, int xid, Controller::Type ytype, int yid)
66 {
67   // Currently, the mindlink takes full control of the mouse, but only ever
68   // uses the x-axis, and both mouse buttons for the single mindlink button
69   // As well, there's no separate setting for x and y axis, so any
70   // combination of Controller and id is valid
71   myMouseEnabled = (xtype == myType || ytype == myType) &&
72                    (xid != -1 || yid != -1);
73   return true;
74 }
75 
76