From 6e51d951efef791d66ddd72843dd0a1bafaee1da Mon Sep 17 00:00:00 2001 From: stephena Date: Tue, 29 Apr 2008 15:49:34 +0000 Subject: [PATCH] Oops, forgot to include the SaveKey class. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1490 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/emucore/SaveKey.cxx | 94 ++++++++++++++++++++++++++++++++++ stella/src/emucore/SaveKey.hxx | 85 ++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 stella/src/emucore/SaveKey.cxx create mode 100644 stella/src/emucore/SaveKey.hxx diff --git a/stella/src/emucore/SaveKey.cxx b/stella/src/emucore/SaveKey.cxx new file mode 100644 index 000000000..42fc8bacb --- /dev/null +++ b/stella/src/emucore/SaveKey.cxx @@ -0,0 +1,94 @@ +//============================================================================ +// +// 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 +// +// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: SaveKey.cxx,v 1.1 2008-04-29 15:49:34 stephena Exp $ +//============================================================================ + +#include "MT24LC256.hxx" +#include "System.hxx" +#include "SaveKey.hxx" + +#define DEBUG_SAVEKEY 0 + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SaveKey::SaveKey(Jack jack, const Event& event, const System& system, + const string& eepromfile) + : Controller(jack, event, system, Controller::SaveKey), + myEEPROM(NULL) +{ + myEEPROM = new MT24LC256(eepromfile, system); + + myDigitalPinState[One] = myDigitalPinState[Two] = true; + myAnalogPinValue[Five] = myAnalogPinValue[Nine] = maximumResistance; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SaveKey::~SaveKey() +{ + delete myEEPROM; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +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: + if(DEBUG_SAVEKEY) + cerr << "SaveKey: value " + << value + << " written to SDA line at cycle " + << mySystem.cycles() + << endl; + myEEPROM->writeSDA(value); + break; + + // Pin 4: EEPROM SCL + // output clock data to the 24LC256 EEPROM using the I2C protocol + case Four: + if(DEBUG_SAVEKEY) + cerr << "SaveKey: value " + << value + << " written to SCLK line at cycle " + << mySystem.cycles() + << endl; + myEEPROM->writeSCL(value); + break; + + default: + break; + } +} diff --git a/stella/src/emucore/SaveKey.hxx b/stella/src/emucore/SaveKey.hxx new file mode 100644 index 000000000..205fa1c38 --- /dev/null +++ b/stella/src/emucore/SaveKey.hxx @@ -0,0 +1,85 @@ +//============================================================================ +// +// 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 +// +// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: SaveKey.hxx,v 1.1 2008-04-29 15:49:34 stephena Exp $ +//============================================================================ + +#ifndef SAVEKEY_HXX +#define SAVEKEY_HXX + +class MT24LC256; + +#include "Control.hxx" + +/** + Richard Hutchinson's SaveKey "controller", consisting of a 32KB EEPROM + accessible using the I2C protocol. + + This code owes a great debt to Alex Herbert's AtariVox documentation and + driver code. + + @author Stephen Anthony + @version $Id: SaveKey.hxx,v 1.1 2008-04-29 15:49:34 stephena Exp $ +*/ +class SaveKey : public Controller +{ + public: + /** + Create a new AtariVox controller plugged into the specified jack + + @param jack The jack the controller is plugged into + @param event The event object to use for events + @param system The system using this controller + @param eepromfile The file containing the EEPROM data + */ + SaveKey(Jack jack, const Event& event, const System& system, + const string& eepromfile); + + /** + Destructor + */ + virtual ~SaveKey(); + + public: + /** + Read the value of the specified digital pin for this controller. + + @param pin The pin of the controller jack to read + @return The state of the pin + */ + virtual bool read(DigitalPin pin); + + /** + Write the given value to the specified digital pin for this + controller. Writing is only allowed to the pins associated + with the PIA. Therefore you cannot write to pin six. + + @param pin The pin of the controller jack to write to + @param value The value to write to the pin + */ + virtual void write(DigitalPin pin, bool value); + + /** + Update the entire digital and analog pin state according to the + events currently set. + */ + virtual void update() { } + + private: + // The EEPROM used in the SaveKey + MT24LC256* myEEPROM; +}; + +#endif