2008-04-29 15:49:34 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// SSSS tt lll lll
|
|
|
|
// SS SS tt ll ll
|
|
|
|
// SS tttttt eeee ll ll aaaa
|
|
|
|
// 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
|
|
|
|
//
|
2015-12-29 19:22:46 +00:00
|
|
|
// Copyright (c) 1995-2016 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.
|
|
|
|
//
|
2009-05-13 13:55:40 +00:00
|
|
|
// $Id$
|
2008-04-29 15:49:34 +00:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include "MT24LC256.hxx"
|
|
|
|
#include "System.hxx"
|
|
|
|
#include "SaveKey.hxx"
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
|
|
|
|
const string& eepromfile)
|
2014-11-03 17:36:28 +00:00
|
|
|
: Controller(jack, event, system, Controller::SaveKey)
|
2008-04-29 15:49:34 +00:00
|
|
|
{
|
2014-11-03 17:36:28 +00:00
|
|
|
myEEPROM = make_ptr<MT24LC256>(eepromfile, system);
|
2008-04-29 15:49:34 +00:00
|
|
|
|
|
|
|
myDigitalPinState[One] = myDigitalPinState[Two] = true;
|
|
|
|
myAnalogPinValue[Five] = myAnalogPinValue[Nine] = maximumResistance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
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
|
|
|
|
case Three:
|
|
|
|
return myDigitalPinState[Three] = myEEPROM->readSDA();
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Controller::read(pin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
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
|
|
|
|
case Three:
|
2008-05-06 16:39:12 +00:00
|
|
|
myDigitalPinState[Three] = 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
|
|
|
|
case Four:
|
2008-05-06 16:39:12 +00:00
|
|
|
myDigitalPinState[Four] = value;
|
2008-04-29 15:49:34 +00:00
|
|
|
myEEPROM->writeSCL(value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-19 02:53:58 +00:00
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void SaveKey::systemCyclesReset()
|
|
|
|
{
|
|
|
|
// The EEPROM keeps track of cycle counts, and needs to know when the
|
|
|
|
// cycles are reset
|
|
|
|
myEEPROM->systemCyclesReset();
|
|
|
|
}
|