2008-04-29 15:49:34 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
2016-12-30 00:00:30 +00:00
|
|
|
// SSSS tt lll lll
|
|
|
|
// SS SS tt ll ll
|
|
|
|
// SS tttttt eeee ll ll aaaa
|
2008-04-29 15:49:34 +00:00
|
|
|
// SSSS tt ee ee ll ll aa
|
|
|
|
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
|
|
|
// SS SS tt ee ll ll aa aa
|
|
|
|
// SSSS ttt eeeee llll llll aaaaa
|
|
|
|
//
|
2019-12-31 17:18:56 +00:00
|
|
|
// Copyright (c) 1995-2020 by Bradford W. Mott, Stephen Anthony
|
2010-04-10 21:37:23 +00:00
|
|
|
// and the Stella Team
|
2008-04-29 15:49:34 +00:00
|
|
|
//
|
2010-01-10 03:23:32 +00:00
|
|
|
// See the file "License.txt" for information on usage and redistribution of
|
2008-04-29 15:49:34 +00:00
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//============================================================================
|
|
|
|
|
2017-11-20 18:57:05 +00:00
|
|
|
#include "MT24LC256.hxx"
|
2019-02-27 21:39:09 +00:00
|
|
|
#include "OSystem.hxx"
|
2008-04-29 15:49:34 +00:00
|
|
|
#include "System.hxx"
|
|
|
|
#include "SaveKey.hxx"
|
|
|
|
|
2017-10-03 14:33:33 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-03-04 01:33:44 +00:00
|
|
|
SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
|
2019-12-25 01:41:36 +00:00
|
|
|
const string& eepromfile, const onMessageCallback& callback,
|
|
|
|
Type type)
|
2019-12-29 22:06:56 +00:00
|
|
|
: Controller(jack, event, system, type),
|
|
|
|
myEEPROM(make_unique<MT24LC256>(eepromfile, system, callback))
|
2017-10-03 14:33:33 +00:00
|
|
|
{
|
2019-03-29 23:17:24 +00:00
|
|
|
setPin(DigitalPin::One, true);
|
|
|
|
setPin(DigitalPin::Two, true);
|
2017-10-03 14:33:33 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:49:34 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-03-04 01:33:44 +00:00
|
|
|
SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
|
2019-12-25 01:41:36 +00:00
|
|
|
const string& eepromfile, const onMessageCallback& callback)
|
2019-03-29 23:17:24 +00:00
|
|
|
: SaveKey(jack, event, system, eepromfile, callback, Controller::Type::SaveKey)
|
2008-04-29 15:49:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-20 18:57:05 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
SaveKey::~SaveKey()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-29 15:49:34 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool SaveKey::read(DigitalPin pin)
|
|
|
|
{
|
|
|
|
// We need to override the Controller::read() method, since the timing
|
|
|
|
// of the actual read is important for the EEPROM (we can't just read
|
|
|
|
// 60 times per second in the ::update() method)
|
|
|
|
switch(pin)
|
|
|
|
{
|
|
|
|
// Pin 3: EEPROM SDA
|
|
|
|
// input data from the 24LC256 EEPROM using the I2C protocol
|
2019-03-29 23:17:24 +00:00
|
|
|
case DigitalPin::Three:
|
|
|
|
return setPin(pin, myEEPROM->readSDA());
|
2008-04-29 15:49:34 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return Controller::read(pin);
|
2017-10-02 22:27:21 +00:00
|
|
|
}
|
2008-04-29 15:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void SaveKey::write(DigitalPin pin, bool value)
|
|
|
|
{
|
|
|
|
// Change the pin state based on value
|
|
|
|
switch(pin)
|
|
|
|
{
|
|
|
|
// Pin 3: EEPROM SDA
|
|
|
|
// output data to the 24LC256 EEPROM using the I2C protocol
|
2019-03-29 23:17:24 +00:00
|
|
|
case DigitalPin::Three:
|
|
|
|
setPin(pin, value);
|
2008-04-29 15:49:34 +00:00
|
|
|
myEEPROM->writeSDA(value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Pin 4: EEPROM SCL
|
|
|
|
// output clock data to the 24LC256 EEPROM using the I2C protocol
|
2019-03-29 23:17:24 +00:00
|
|
|
case DigitalPin::Four:
|
|
|
|
setPin(pin, value);
|
2008-04-29 15:49:34 +00:00
|
|
|
myEEPROM->writeSCL(value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-01-23 18:16:09 +00:00
|
|
|
}
|
2017-10-05 23:27:02 +00:00
|
|
|
}
|
2017-11-20 18:57:05 +00:00
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void SaveKey::reset()
|
|
|
|
{
|
|
|
|
myEEPROM->systemReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void SaveKey::close()
|
|
|
|
{
|
|
|
|
myEEPROM.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void SaveKey::eraseAll()
|
|
|
|
{
|
|
|
|
myEEPROM->eraseAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void SaveKey::eraseCurrent()
|
|
|
|
{
|
|
|
|
myEEPROM->eraseCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool SaveKey::isPageUsed(const uInt32 page) const
|
|
|
|
{
|
|
|
|
return myEEPROM->isPageUsed(page);
|
|
|
|
}
|