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 #include "MT24LC256.hxx"
19 #include "OSystem.hxx"
20 #include "System.hxx"
21 #include "SaveKey.hxx"
22
23 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SaveKey(Jack jack,const Event & event,const System & system,const FilesystemNode & eepromfile,const onMessageCallback & callback,Type type)24 SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
25 const FilesystemNode& eepromfile, const onMessageCallback& callback,
26 Type type)
27 : Controller(jack, event, system, type),
28 myEEPROM{make_unique<MT24LC256>(eepromfile, system, callback)}
29 {
30 setPin(DigitalPin::One, true);
31 setPin(DigitalPin::Two, true);
32 }
33
34 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SaveKey(Jack jack,const Event & event,const System & system,const FilesystemNode & eepromfile,const onMessageCallback & callback)35 SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
36 const FilesystemNode& eepromfile, const onMessageCallback& callback)
37 : SaveKey(jack, event, system, eepromfile, callback, Controller::Type::SaveKey)
38 {
39 }
40
41 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
~SaveKey()42 SaveKey::~SaveKey()
43 {
44 }
45
46 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
read(DigitalPin pin)47 bool SaveKey::read(DigitalPin pin)
48 {
49 // We need to override the Controller::read() method, since the timing
50 // of the actual read is important for the EEPROM (we can't just read
51 // 60 times per second in the ::update() method)
52 switch(pin)
53 {
54 // Pin 3: EEPROM SDA
55 // input data from the 24LC256 EEPROM using the I2C protocol
56 case DigitalPin::Three:
57 return setPin(pin, myEEPROM->readSDA());
58
59 default:
60 return Controller::read(pin);
61 }
62 }
63
64 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
write(DigitalPin pin,bool value)65 void SaveKey::write(DigitalPin pin, bool value)
66 {
67 // Change the pin state based on value
68 switch(pin)
69 {
70 // Pin 3: EEPROM SDA
71 // output data to the 24LC256 EEPROM using the I2C protocol
72 case DigitalPin::Three:
73 setPin(pin, value);
74 myEEPROM->writeSDA(value);
75 break;
76
77 // Pin 4: EEPROM SCL
78 // output clock data to the 24LC256 EEPROM using the I2C protocol
79 case DigitalPin::Four:
80 setPin(pin, value);
81 myEEPROM->writeSCL(value);
82 break;
83
84 default:
85 break;
86 }
87 }
88
89 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
reset()90 void SaveKey::reset()
91 {
92 myEEPROM->systemReset();
93 }
94
95 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
close()96 void SaveKey::close()
97 {
98 myEEPROM.reset();
99 }
100
101 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
eraseAll()102 void SaveKey::eraseAll()
103 {
104 myEEPROM->eraseAll();
105 }
106
107 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
eraseCurrent()108 void SaveKey::eraseCurrent()
109 {
110 myEEPROM->eraseCurrent();
111 }
112
113 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
isPageUsed(const uInt32 page) const114 bool SaveKey::isPageUsed(const uInt32 page) const
115 {
116 return myEEPROM->isPageUsed(page);
117 }
118