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 #ifndef TIA_ANALOG_READOUT 19 #define TIA_ANALOG_READOUT 20 21 #include "bspf.hxx" 22 #include "Serializable.hxx" 23 #include "ConsoleTiming.hxx" 24 25 class AnalogReadout : public Serializable 26 { 27 public: 28 29 enum class ConnectionType : uInt8 { 30 ground = 0, vcc = 1, disconnected = 2 31 }; 32 33 struct Connection { 34 ConnectionType type; 35 uInt32 resistance; 36 37 bool save(Serializer& out) const; 38 bool load(Serializer& in); 39 40 friend bool operator==(const AnalogReadout::Connection& c1, const AnalogReadout::Connection& c2); 41 }; 42 43 public: 44 45 AnalogReadout(); 46 47 void reset(uInt64 timestamp); 48 49 void vblank(uInt8 value, uInt64 timestamp); vblankDumped() const50 bool vblankDumped() const { return myIsDumped; } 51 52 uInt8 inpt(uInt64 timestamp); 53 54 void update(Connection connection, uInt64 timestamp, ConsoleTiming consoleTiming); 55 56 /** 57 Serializable methods (see that class for more information). 58 */ 59 bool save(Serializer& out) const override; 60 bool load(Serializer& in) override; 61 62 public: 63 64 static Connection connectToGround(uInt32 resistance = 0); 65 66 static Connection connectToVcc(uInt32 resistance = 0); 67 68 static Connection disconnect(); 69 70 private: 71 72 void setConsoleTiming(ConsoleTiming timing); 73 74 void updateCharge(uInt64 timestamp); 75 76 private: 77 78 double myUThresh{0.0}; 79 double myU{0.0}; 80 81 Connection myConnection{ConnectionType::disconnected, 0}; 82 uInt64 myTimestamp{0}; 83 84 ConsoleTiming myConsoleTiming; 85 double myClockFreq{0.0}; 86 87 bool myIsDumped{false}; 88 89 static constexpr double 90 R0 = 1.8e3, 91 C = 68e-9, 92 R_POT = 1e6, 93 R_DUMP = 50, 94 U_SUPP = 5; 95 96 static constexpr double TRIPPOINT_LINES = 379; 97 98 private: 99 AnalogReadout(const AnalogReadout&) = delete; 100 AnalogReadout(AnalogReadout&&) = delete; 101 AnalogReadout& operator=(const AnalogReadout&) = delete; 102 AnalogReadout& operator=(AnalogReadout&&) = delete; 103 }; 104 105 bool operator==(const AnalogReadout::Connection& c1, const AnalogReadout::Connection& c2); 106 bool operator!=(const AnalogReadout::Connection& c1, const AnalogReadout::Connection& c2); 107 108 #endif // TIA_ANALOG_READOUT 109