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 "LatchedInput.hxx" |
19 | |
20 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
21 | LatchedInput::LatchedInput() |
22 | { |
23 | reset(); |
24 | } |
25 | |
26 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
27 | void LatchedInput::reset() |
28 | { |
29 | myModeLatched = false; |
30 | myLatchedValue = 0; |
31 | } |
32 | |
33 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
34 | void LatchedInput::vblank(uInt8 value) |
35 | { |
36 | if (value & 0x40) |
37 | myModeLatched = true; |
38 | else { |
39 | myModeLatched = false; |
40 | myLatchedValue = 0x80; |
41 | } |
42 | } |
43 | |
44 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
45 | uInt8 LatchedInput::inpt(bool pinState) |
46 | { |
47 | uInt8 value = pinState ? 0 : 0x80; |
48 | |
49 | if (myModeLatched) { |
50 | myLatchedValue &= value; |
51 | value = myLatchedValue; |
52 | } |
53 | |
54 | return value; |
55 | } |
56 | |
57 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
58 | bool LatchedInput::save(Serializer& out) const |
59 | { |
60 | try |
61 | { |
62 | out.putBool(myModeLatched); |
63 | out.putByte(myLatchedValue); |
64 | } |
65 | catch(...) |
66 | { |
67 | cerr << "ERROR: TIA_LatchedInput::save" << endl; |
68 | return false; |
69 | } |
70 | |
71 | return true; |
72 | } |
73 | |
74 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
75 | bool LatchedInput::load(Serializer& in) |
76 | { |
77 | try |
78 | { |
79 | myModeLatched = in.getBool(); |
80 | myLatchedValue = in.getByte(); |
81 | } |
82 | catch(...) |
83 | { |
84 | cerr << "ERROR: TIA_LatchedInput::load" << endl; |
85 | return false; |
86 | } |
87 | |
88 | return true; |
89 | } |
90 | |