2008-04-13 15:05:59 +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-13 15:05:59 +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
|
|
|
|
//
|
2016-12-30 00:00:30 +00:00
|
|
|
// Copyright (c) 1995-2017 by Bradford W. Mott, Stephen Anthony
|
2010-04-10 21:37:23 +00:00
|
|
|
// and the Stella Team
|
2008-04-13 15:05:59 +00:00
|
|
|
//
|
2010-01-10 03:23:32 +00:00
|
|
|
// See the file "License.txt" for information on usage and redistribution of
|
2008-04-13 15:05:59 +00:00
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#ifndef MT24LC256_HXX
|
|
|
|
#define MT24LC256_HXX
|
|
|
|
|
|
|
|
class Controller;
|
2008-04-13 23:43:14 +00:00
|
|
|
class System;
|
2008-04-13 15:05:59 +00:00
|
|
|
|
|
|
|
#include "bspf.hxx"
|
|
|
|
|
|
|
|
/**
|
|
|
|
Emulates a Microchip Technology Inc. 24LC256, a 32KB Serial Electrically
|
|
|
|
Erasable PROM accessed using the I2C protocol. Thanks to J. Payson
|
|
|
|
(aka Supercat) for the bulk of this code.
|
|
|
|
|
|
|
|
@author Stephen Anthony & J. Payson
|
|
|
|
*/
|
|
|
|
class MT24LC256
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create a new 24LC256 with its data stored in the given file
|
|
|
|
|
2008-04-13 23:43:14 +00:00
|
|
|
@param filename Data file containing the EEPROM data
|
|
|
|
@param system The system using the controller of this device
|
2008-04-13 15:05:59 +00:00
|
|
|
*/
|
2008-04-13 23:43:14 +00:00
|
|
|
MT24LC256(const string& filename, const System& system);
|
2014-09-29 20:39:28 +00:00
|
|
|
~MT24LC256();
|
2008-04-13 15:05:59 +00:00
|
|
|
|
2017-10-01 07:52:39 +00:00
|
|
|
private:
|
|
|
|
// Sizes of the EEPROM
|
|
|
|
static constexpr uInt32 FLASH_SIZE = 32 * 1024;
|
2017-10-01 18:53:53 +00:00
|
|
|
|
2008-04-13 15:05:59 +00:00
|
|
|
public:
|
2017-10-01 07:52:39 +00:00
|
|
|
static constexpr uInt32 PAGE_SIZE = 64;
|
|
|
|
static constexpr uInt32 PAGE_NUM = FLASH_SIZE / PAGE_SIZE;
|
|
|
|
|
2008-04-13 15:05:59 +00:00
|
|
|
/** Read boolean data from the SDA line */
|
2015-08-09 18:07:04 +00:00
|
|
|
bool readSDA() const { return jpee_mdat && jpee_sdat; }
|
2008-04-13 15:05:59 +00:00
|
|
|
|
|
|
|
/** Write boolean data to the SDA and SCL lines */
|
|
|
|
void writeSDA(bool state);
|
|
|
|
void writeSCL(bool state);
|
|
|
|
|
2017-09-08 13:59:30 +00:00
|
|
|
/** Called when the system is being reset */
|
|
|
|
void systemReset();
|
|
|
|
|
2014-06-29 23:25:53 +00:00
|
|
|
/** Erase entire EEPROM to known state ($FF) */
|
2017-09-29 18:12:41 +00:00
|
|
|
void eraseAll();
|
|
|
|
|
|
|
|
/** Erase the pages used by the current ROM to known state ($FF) */
|
|
|
|
void eraseCurrent();
|
|
|
|
|
2017-10-01 10:00:07 +00:00
|
|
|
/** Returns true if the page is used by the current ROM */
|
2017-10-01 18:53:53 +00:00
|
|
|
bool isPageUsed(uInt32 page) const;
|
2014-06-29 23:25:53 +00:00
|
|
|
|
2008-04-13 15:05:59 +00:00
|
|
|
private:
|
|
|
|
// I2C access code provided by Supercat
|
|
|
|
void jpee_init();
|
|
|
|
void jpee_data_start();
|
|
|
|
void jpee_data_stop();
|
|
|
|
void jpee_clock_fall();
|
2008-04-13 23:43:14 +00:00
|
|
|
int jpee_logproc(char const *st);
|
|
|
|
bool jpee_timercheck(int mode);
|
2008-04-13 15:05:59 +00:00
|
|
|
|
2008-05-06 16:39:12 +00:00
|
|
|
void update();
|
|
|
|
|
2008-04-13 15:05:59 +00:00
|
|
|
private:
|
2017-09-29 18:12:41 +00:00
|
|
|
// Inital state value of flash EEPROM
|
2017-10-01 18:53:53 +00:00
|
|
|
static constexpr uInt8 INIT_VALUE = 0xff;
|
2017-09-29 18:12:41 +00:00
|
|
|
|
2008-04-13 23:43:14 +00:00
|
|
|
// The system of the parent controller
|
|
|
|
const System& mySystem;
|
2008-04-13 15:05:59 +00:00
|
|
|
|
|
|
|
// The EEPROM data
|
2017-09-29 18:12:41 +00:00
|
|
|
uInt8 myData[FLASH_SIZE];
|
|
|
|
|
|
|
|
// Track which pages are used
|
|
|
|
bool myPageHit[PAGE_NUM];
|
2008-04-13 15:05:59 +00:00
|
|
|
|
2008-05-06 16:39:12 +00:00
|
|
|
// Cached state of the SDA and SCL pins on the last write
|
|
|
|
bool mySDA, mySCL;
|
|
|
|
|
Success at last!!! I finally have the AVox and SaveKey EEPROM emulation
working. After about a week of banging my head against the wall, I
happened to try another test ROM, and everything worked. So it seems
that the SaveKey test ROM from Thomas J. (with the optimized I2C
macros) isn't working correctly, or I miscompiled it or something.
All other ROMs I've tested work fine, including MGD, Fall Down,
Stratogems Deluxe, Go Fish, etc. Thomas, if you're reading this, could
we try to figure out what's going on here??
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1500 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2008-05-10 22:21:09 +00:00
|
|
|
// Indicates that a timer has been set and hasn't expired yet
|
|
|
|
bool myTimerActive;
|
|
|
|
|
2008-04-13 23:43:14 +00:00
|
|
|
// Indicates when the timer was set
|
2017-09-08 13:59:30 +00:00
|
|
|
uInt64 myCyclesWhenTimerSet;
|
2008-04-13 23:43:14 +00:00
|
|
|
|
2008-05-06 16:39:12 +00:00
|
|
|
// Indicates when the SDA and SCL pins were set/written
|
2017-09-08 13:59:30 +00:00
|
|
|
uInt64 myCyclesWhenSDASet, myCyclesWhenSCLSet;
|
2008-05-06 16:39:12 +00:00
|
|
|
|
2008-04-13 15:05:59 +00:00
|
|
|
// The file containing the EEPROM data
|
|
|
|
string myDataFile;
|
|
|
|
|
2008-05-11 21:18:35 +00:00
|
|
|
// Indicates if a valid EEPROM data file exists/was successfully loaded
|
|
|
|
bool myDataFileExists;
|
|
|
|
|
|
|
|
// Indicates if the EEPROM has changed since class invocation
|
|
|
|
bool myDataChanged;
|
|
|
|
|
2008-04-13 15:05:59 +00:00
|
|
|
// Required for I2C functionality
|
2014-11-17 14:17:19 +00:00
|
|
|
Int32 jpee_mdat, jpee_sdat, jpee_mclk;
|
|
|
|
Int32 jpee_sizemask, jpee_pagemask, jpee_smallmode, jpee_logmode;
|
|
|
|
Int32 jpee_pptr, jpee_state, jpee_nb;
|
|
|
|
uInt32 jpee_address, jpee_ad_known;
|
2008-04-13 15:05:59 +00:00
|
|
|
uInt8 jpee_packet[70];
|
|
|
|
|
|
|
|
private:
|
2015-04-26 19:02:42 +00:00
|
|
|
// Following constructors and assignment operators not supported
|
|
|
|
MT24LC256() = delete;
|
|
|
|
MT24LC256(const MT24LC256&) = delete;
|
|
|
|
MT24LC256(MT24LC256&&) = delete;
|
|
|
|
MT24LC256& operator=(const MT24LC256&) = delete;
|
|
|
|
MT24LC256& operator=(MT24LC256&&) = delete;
|
2008-04-13 15:05:59 +00:00
|
|
|
};
|
|
|
|
|
2009-01-26 21:08:07 +00:00
|
|
|
#endif
|