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