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 "CompuMate.hxx" |
19 | |
20 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
21 | CompuMate::CompuMate(const Console& console, const Event& event, |
22 | const System& system) |
23 | : myConsole(console), |
24 | myColumn(0), |
25 | myEvent(event) |
26 | { |
27 | // These controller pointers will be retrieved by the Console, which will |
28 | // also take ownership of them |
29 | myLeftController = make_unique<CMControl>(*this, Controller::Jack::Left, event, system); |
30 | myRightController = make_unique<CMControl>(*this, Controller::Jack::Right, event, system); |
31 | |
32 | myLeftController->setPin(Controller::AnalogPin::Nine, Controller::MAX_RESISTANCE); |
33 | myLeftController->setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
34 | myRightController->setPin(Controller::AnalogPin::Nine, Controller::MIN_RESISTANCE); |
35 | myRightController->setPin(Controller::AnalogPin::Five, Controller::MAX_RESISTANCE); |
36 | } |
37 | |
38 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
39 | void CompuMate::update() |
40 | { |
41 | // Handle SWCHA changes - the following comes almost directly from z26 |
42 | Controller& lp = myConsole.leftController(); |
43 | Controller& rp = myConsole.rightController(); |
44 | |
45 | lp.setPin(Controller::AnalogPin::Nine, Controller::MAX_RESISTANCE); |
46 | lp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
47 | lp.setPin(Controller::DigitalPin::Six, true); |
48 | rp.setPin(Controller::AnalogPin::Nine, Controller::MIN_RESISTANCE); |
49 | rp.setPin(Controller::AnalogPin::Five, Controller::MAX_RESISTANCE); |
50 | rp.setPin(Controller::DigitalPin::Six, true); |
51 | |
52 | if (myEvent.get(Event::CompuMateShift)) |
53 | rp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
54 | if (myEvent.get(Event::CompuMateFunc)) |
55 | lp.setPin(Controller::AnalogPin::Nine, Controller::MIN_RESISTANCE); |
56 | |
57 | rp.setPin(Controller::DigitalPin::Three, true); |
58 | rp.setPin(Controller::DigitalPin::Four, true); |
59 | |
60 | switch(myColumn) // This is updated inside CartCM class |
61 | { |
62 | case 0: |
63 | if (myEvent.get(Event::CompuMate7)) lp.setPin(Controller::DigitalPin::Six, false); |
64 | if (myEvent.get(Event::CompuMateU)) rp.setPin(Controller::DigitalPin::Three, false); |
65 | if (myEvent.get(Event::CompuMateJ)) rp.setPin(Controller::DigitalPin::Six, false); |
66 | if (myEvent.get(Event::CompuMateM)) rp.setPin(Controller::DigitalPin::Four, false); |
67 | break; |
68 | case 1: |
69 | if (myEvent.get(Event::CompuMate6)) lp.setPin(Controller::DigitalPin::Six, false); |
70 | // Emulate the '?' character (Shift-6) with the actual question key |
71 | if (myEvent.get(Event::CompuMateQuestion)) |
72 | { |
73 | rp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
74 | lp.setPin(Controller::DigitalPin::Six, false); |
75 | } |
76 | if (myEvent.get(Event::CompuMateY)) rp.setPin(Controller::DigitalPin::Three, false); |
77 | if (myEvent.get(Event::CompuMateH)) rp.setPin(Controller::DigitalPin::Six, false); |
78 | if (myEvent.get(Event::CompuMateN)) rp.setPin(Controller::DigitalPin::Four, false); |
79 | break; |
80 | case 2: |
81 | if (myEvent.get(Event::CompuMate8)) lp.setPin(Controller::DigitalPin::Six, false); |
82 | // Emulate the '[' character (Shift-8) with the actual key |
83 | if (myEvent.get(Event::CompuMateLeftBracket)) |
84 | { |
85 | rp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
86 | lp.setPin(Controller::DigitalPin::Six, false); |
87 | } |
88 | if (myEvent.get(Event::CompuMateI)) rp.setPin(Controller::DigitalPin::Three, false); |
89 | if (myEvent.get(Event::CompuMateK)) rp.setPin(Controller::DigitalPin::Six, false); |
90 | if (myEvent.get(Event::CompuMateComma)) rp.setPin(Controller::DigitalPin::Four, false); |
91 | break; |
92 | case 3: |
93 | if (myEvent.get(Event::CompuMate2)) lp.setPin(Controller::DigitalPin::Six, false); |
94 | // Emulate the '-' character (Shift-2) with the actual minus key |
95 | if (myEvent.get(Event::CompuMateMinus)) |
96 | { |
97 | rp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
98 | lp.setPin(Controller::DigitalPin::Six, false); |
99 | } |
100 | if (myEvent.get(Event::CompuMateW)) rp.setPin(Controller::DigitalPin::Three, false); |
101 | if (myEvent.get(Event::CompuMateS)) rp.setPin(Controller::DigitalPin::Six, false); |
102 | if (myEvent.get(Event::CompuMateX)) rp.setPin(Controller::DigitalPin::Four, false); |
103 | break; |
104 | case 4: |
105 | if (myEvent.get(Event::CompuMate3)) lp.setPin(Controller::DigitalPin::Six, false); |
106 | if (myEvent.get(Event::CompuMateE)) rp.setPin(Controller::DigitalPin::Three, false); |
107 | if (myEvent.get(Event::CompuMateD)) rp.setPin(Controller::DigitalPin::Six, false); |
108 | if (myEvent.get(Event::CompuMateC)) rp.setPin(Controller::DigitalPin::Four, false); |
109 | break; |
110 | case 5: |
111 | if (myEvent.get(Event::CompuMate0)) lp.setPin(Controller::DigitalPin::Six, false); |
112 | // Emulate the quote character (Shift-0) with the actual quote key |
113 | if (myEvent.get(Event::CompuMateQuote)) |
114 | { |
115 | rp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
116 | lp.setPin(Controller::DigitalPin::Six, false); |
117 | } |
118 | if (myEvent.get(Event::CompuMateP)) rp.setPin(Controller::DigitalPin::Three, false); |
119 | if (myEvent.get(Event::CompuMateEnter)) rp.setPin(Controller::DigitalPin::Six, false); |
120 | if (myEvent.get(Event::CompuMateSpace)) rp.setPin(Controller::DigitalPin::Four, false); |
121 | // Emulate Ctrl-space (aka backspace) with the actual Backspace key |
122 | if (myEvent.get(Event::CompuMateBackspace)) |
123 | { |
124 | lp.setPin(Controller::AnalogPin::Nine, Controller::MIN_RESISTANCE); |
125 | rp.setPin(Controller::DigitalPin::Four, false); |
126 | } |
127 | break; |
128 | case 6: |
129 | if (myEvent.get(Event::CompuMate9)) lp.setPin(Controller::DigitalPin::Six, false); |
130 | // Emulate the ']' character (Shift-9) with the actual key |
131 | if (myEvent.get(Event::CompuMateRightBracket)) |
132 | { |
133 | rp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
134 | lp.setPin(Controller::DigitalPin::Six, false); |
135 | } |
136 | if (myEvent.get(Event::CompuMateO)) rp.setPin(Controller::DigitalPin::Three, false); |
137 | if (myEvent.get(Event::CompuMateL)) rp.setPin(Controller::DigitalPin::Six, false); |
138 | if (myEvent.get(Event::CompuMatePeriod)) rp.setPin(Controller::DigitalPin::Four, false); |
139 | break; |
140 | case 7: |
141 | if (myEvent.get(Event::CompuMate5)) lp.setPin(Controller::DigitalPin::Six, false); |
142 | // Emulate the '=' character (Shift-5) with the actual equals key |
143 | if (myEvent.get(Event::CompuMateEquals)) |
144 | { |
145 | rp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
146 | lp.setPin(Controller::DigitalPin::Six, false); |
147 | } |
148 | if (myEvent.get(Event::CompuMateT)) rp.setPin(Controller::DigitalPin::Three, false); |
149 | if (myEvent.get(Event::CompuMateG)) rp.setPin(Controller::DigitalPin::Six, false); |
150 | if (myEvent.get(Event::CompuMateB)) rp.setPin(Controller::DigitalPin::Four, false); |
151 | break; |
152 | case 8: |
153 | if (myEvent.get(Event::CompuMate1)) lp.setPin(Controller::DigitalPin::Six, false); |
154 | // Emulate the '+' character (Shift-1) with the actual plus key (Shift-=) |
155 | if (myEvent.get(Event::CompuMatePlus)) |
156 | { |
157 | rp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
158 | lp.setPin(Controller::DigitalPin::Six, false); |
159 | } |
160 | if (myEvent.get(Event::CompuMateQ)) rp.setPin(Controller::DigitalPin::Three, false); |
161 | if (myEvent.get(Event::CompuMateA)) rp.setPin(Controller::DigitalPin::Six, false); |
162 | if (myEvent.get(Event::CompuMateZ)) rp.setPin(Controller::DigitalPin::Four, false); |
163 | break; |
164 | case 9: |
165 | if (myEvent.get(Event::CompuMate4)) lp.setPin(Controller::DigitalPin::Six, false); |
166 | // Emulate the '/' character (Shift-4) with the actual slash key |
167 | if (myEvent.get(Event::CompuMateSlash)) |
168 | { |
169 | rp.setPin(Controller::AnalogPin::Five, Controller::MIN_RESISTANCE); |
170 | lp.setPin(Controller::DigitalPin::Six, false); |
171 | } |
172 | if (myEvent.get(Event::CompuMateR)) rp.setPin(Controller::DigitalPin::Three, false); |
173 | if (myEvent.get(Event::CompuMateF)) rp.setPin(Controller::DigitalPin::Six, false); |
174 | if (myEvent.get(Event::CompuMateV)) rp.setPin(Controller::DigitalPin::Four, false); |
175 | break; |
176 | default: |
177 | break; |
178 | } |
179 | } |
180 | |