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#ifndef SAVEKEY_HXX
19#define SAVEKEY_HXX
20
21class MT24LC256;
22class OSystem;
23
24#include "Control.hxx"
25
26/**
27 Richard Hutchinson's SaveKey "controller", consisting of a 32KB EEPROM
28 accessible using the I2C protocol.
29
30 This code owes a great debt to Alex Herbert's AtariVox documentation and
31 driver code.
32
33 @author Stephen Anthony
34*/
35class SaveKey : public Controller
36{
37 public:
38 /**
39 Create a new SaveKey controller plugged into the specified jack
40
41 @param jack The jack the controller is plugged into
42 @param event The event object to use for events
43 @param system The system using this controller
44 @param eepromfile The file containing the EEPROM data
45 @param callback Called to pass messages back to the parent controller
46 */
47 SaveKey(Jack jack, const Event& event, const System& system,
48 const string& eepromfile, onMessageCallback callback);
49 virtual ~SaveKey();
50
51 protected:
52 /**
53 Delegating constructor currently used by both this class and classes
54 that inherit from SaveKey (currently, AtariVox)
55 */
56 SaveKey(Jack jack, const Event& event, const System& system,
57 const string& eepromfile, onMessageCallback callback, Type type);
58
59 public:
60 using Controller::read;
61
62 /**
63 Read the value of the specified digital pin for this controller.
64
65 @param pin The pin of the controller jack to read
66 @return The state of the pin
67 */
68 bool read(DigitalPin pin) override;
69
70 /**
71 Write the given value to the specified digital pin for this
72 controller. Writing is only allowed to the pins associated
73 with the PIA. Therefore you cannot write to pin six.
74
75 @param pin The pin of the controller jack to write to
76 @param value The value to write to the pin
77 */
78 void write(DigitalPin pin, bool value) override;
79
80 /**
81 Update the entire digital and analog pin state according to the
82 events currently set.
83 */
84 void update() override { }
85
86 /**
87 Returns the name of this controller.
88 */
89 string name() const override { return "SaveKey"; }
90
91 /**
92 Notification method invoked by the system after its reset method has
93 been called. It may be necessary to override this method for
94 controllers that need to know a reset has occurred.
95 */
96 void reset() override;
97
98 /**
99 Force the EEPROM object to cleanup
100 */
101 void close() override;
102
103 /** Erase entire EEPROM to known state ($FF) */
104 void eraseAll();
105
106 /** Erase the pages used by the current ROM to known state ($FF) */
107 void eraseCurrent();
108
109 /** Returns true if the page is used by the current ROM */
110 bool isPageUsed(const uInt32 page) const;
111
112 private:
113 // The EEPROM used in the SaveKey
114 unique_ptr<MT24LC256> myEEPROM;
115
116 private:
117 // Following constructors and assignment operators not supported
118 SaveKey() = delete;
119 SaveKey(const SaveKey&) = delete;
120 SaveKey(SaveKey&&) = delete;
121 SaveKey& operator=(const SaveKey&) = delete;
122 SaveKey& operator=(SaveKey&&) = delete;
123};
124
125#endif
126