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 "Keyboard.hxx" |
20 | |
21 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
22 | Keyboard::Keyboard(Jack jack, const Event& event, const System& system) |
23 | : Controller(jack, event, system, Controller::Type::Keyboard) |
24 | { |
25 | if(myJack == Jack::Left) |
26 | { |
27 | myOneEvent = Event::KeyboardZero1; |
28 | myTwoEvent = Event::KeyboardZero2; |
29 | myThreeEvent = Event::KeyboardZero3; |
30 | myFourEvent = Event::KeyboardZero4; |
31 | myFiveEvent = Event::KeyboardZero5; |
32 | mySixEvent = Event::KeyboardZero6; |
33 | mySevenEvent = Event::KeyboardZero7; |
34 | myEightEvent = Event::KeyboardZero8; |
35 | myNineEvent = Event::KeyboardZero9; |
36 | myStarEvent = Event::KeyboardZeroStar; |
37 | myZeroEvent = Event::KeyboardZero0; |
38 | myPoundEvent = Event::KeyboardZeroPound; |
39 | } |
40 | else |
41 | { |
42 | myOneEvent = Event::KeyboardOne1; |
43 | myTwoEvent = Event::KeyboardOne2; |
44 | myThreeEvent = Event::KeyboardOne3; |
45 | myFourEvent = Event::KeyboardOne4; |
46 | myFiveEvent = Event::KeyboardOne5; |
47 | mySixEvent = Event::KeyboardOne6; |
48 | mySevenEvent = Event::KeyboardOne7; |
49 | myEightEvent = Event::KeyboardOne8; |
50 | myNineEvent = Event::KeyboardOne9; |
51 | myStarEvent = Event::KeyboardOneStar; |
52 | myZeroEvent = Event::KeyboardOne0; |
53 | myPoundEvent = Event::KeyboardOnePound; |
54 | } |
55 | } |
56 | |
57 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
58 | void Keyboard::write(DigitalPin pin, bool value) |
59 | { |
60 | setPin(pin, value); |
61 | |
62 | // Set defaults |
63 | setPin(DigitalPin::Six, true); |
64 | Int32 resistanceFive = MIN_RESISTANCE; |
65 | Int32 resistanceNine = MIN_RESISTANCE; |
66 | |
67 | // Now scan the rows and columns |
68 | if(!getPin(DigitalPin::Four)) |
69 | { |
70 | setPin(DigitalPin::Six, myEvent.get(myPoundEvent) == 0); |
71 | if(myEvent.get(myZeroEvent) != 0) resistanceFive = MAX_RESISTANCE; |
72 | if(myEvent.get(myStarEvent) != 0) resistanceNine = MAX_RESISTANCE; |
73 | } |
74 | if(!getPin(DigitalPin::Three)) |
75 | { |
76 | setPin(DigitalPin::Six, myEvent.get(myNineEvent) == 0); |
77 | if(myEvent.get(myEightEvent) != 0) resistanceFive = MAX_RESISTANCE; |
78 | if(myEvent.get(mySevenEvent) != 0) resistanceNine = MAX_RESISTANCE; |
79 | } |
80 | if(!getPin(DigitalPin::Two)) |
81 | { |
82 | setPin(DigitalPin::Six, myEvent.get(mySixEvent) == 0); |
83 | if(myEvent.get(myFiveEvent) != 0) resistanceFive = MAX_RESISTANCE; |
84 | if(myEvent.get(myFourEvent) != 0) resistanceNine = MAX_RESISTANCE; |
85 | } |
86 | if(!getPin(DigitalPin::One)) |
87 | { |
88 | setPin(DigitalPin::Six, myEvent.get(myThreeEvent) == 0); |
89 | if(myEvent.get(myTwoEvent) != 0) resistanceFive = MAX_RESISTANCE; |
90 | if(myEvent.get(myOneEvent) != 0) resistanceNine = MAX_RESISTANCE; |
91 | } |
92 | |
93 | if(resistanceFive != read(AnalogPin::Five)) |
94 | setPin(AnalogPin::Five, resistanceFive); |
95 | if(resistanceNine != read(AnalogPin::Nine)) |
96 | setPin(AnalogPin::Nine, resistanceNine); |
97 | } |
98 | |