|
| 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-2026 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 "CartEFF.hxx" |
| 19 | + |
| 20 | +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 21 | +CartridgeEFF::CartridgeEFF(const ByteBuffer& image, size_t size, |
| 22 | + string_view md5, const Settings& settings, |
| 23 | + size_t bsSize) |
| 24 | + : CartridgeEF(image, size, md5, settings, bsSize), |
| 25 | + myEEPROM{nullptr} |
| 26 | +{ |
| 27 | + myRamSize = 0; |
| 28 | + myRamBankCount = 0; |
| 29 | + myRAM = nullptr; |
| 30 | +} |
| 31 | + |
| 32 | +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 33 | +bool CartridgeEFF::checkSwitchBank(uInt16 address, uInt8) |
| 34 | +{ |
| 35 | + address &= ROM_MASK; |
| 36 | + |
| 37 | + // Switch banks if necessary |
| 38 | + if((address >= 0x0FE0) && (address <= 0x0FEF)) |
| 39 | + { |
| 40 | + bank(address - 0x0FE0); |
| 41 | + return true; |
| 42 | + } |
| 43 | + return false; |
| 44 | +} |
| 45 | + |
| 46 | +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 47 | +int CartridgeEFF::descriptionLines() |
| 48 | +{ |
| 49 | + return 24; // this can be pretty verbose |
| 50 | +} |
| 51 | + |
| 52 | +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 53 | +string CartridgeEFF::ramDescription() |
| 54 | +{ |
| 55 | + ostringstream info; |
| 56 | + |
| 57 | + info << (myRamSize / 1024) << "kiB EEPROM\n" |
| 58 | + << "i²c serial interface @ $FFF0 - $FFF3\n" |
| 59 | + << "i²c read port @ $FFF4 ($FFF5)\n"; |
| 60 | + |
| 61 | + return info.str(); |
| 62 | +} |
| 63 | + |
| 64 | +uInt8 CartridgeEFF::peek(uInt16 address) |
| 65 | +{ |
| 66 | + const uInt16 romAddress = address & ROM_MASK; |
| 67 | + if ((address & 0x1000) && (romAddress >= 0x0FF0) && (romAddress <= 0x0FF4)) |
| 68 | + { |
| 69 | + switch (romAddress) { |
| 70 | + case 0x0ff0: |
| 71 | + setI2CClock(false); |
| 72 | + break; |
| 73 | + case 0x0ff1: |
| 74 | + setI2CClock(true); |
| 75 | + break; |
| 76 | + case 0x0ff2: |
| 77 | + setI2CData(false); |
| 78 | + break; |
| 79 | + case 0x0ff3: |
| 80 | + setI2CData(true); |
| 81 | + break; |
| 82 | + case 0x0ff4: |
| 83 | + return readI2C(); |
| 84 | + }; |
| 85 | + } |
| 86 | + return CartridgeEF::peek(address); |
| 87 | +} |
| 88 | + |
| 89 | +bool CartridgeEFF::poke(uInt16 address, uInt8 value) |
| 90 | +{ |
| 91 | + const uInt16 romAddress = address & ROM_MASK; |
| 92 | + if ((address & 0x1000) && (romAddress >= 0x0FF0) && (romAddress <= 0x0FF3)) |
| 93 | + { |
| 94 | + switch (romAddress) { |
| 95 | + case 0x0ff0: |
| 96 | + setI2CClock(false); |
| 97 | + setI2CClock(false); |
| 98 | + return false; |
| 99 | + |
| 100 | + case 0x0ff1: |
| 101 | + setI2CClock(true); |
| 102 | + setI2CClock(true); |
| 103 | + return false; |
| 104 | + |
| 105 | + case 0x0ff2: |
| 106 | + setI2CData(false); |
| 107 | + setI2CData(false); |
| 108 | + return false; |
| 109 | + |
| 110 | + case 0x0ff3: |
| 111 | + setI2CData(true); |
| 112 | + setI2CData(true); |
| 113 | + return false; |
| 114 | + }; |
| 115 | + } |
| 116 | + return CartridgeEF::poke(address, value); |
| 117 | +} |
| 118 | + |
| 119 | +void CartridgeEFF::setI2CClock(bool value) { |
| 120 | + myI2CClock = value; |
| 121 | + if (myEEPROM) |
| 122 | + myEEPROM->writeSCL(myI2CClock); |
| 123 | + else |
| 124 | + cerr << " (No EEPROM)\n"; |
| 125 | +} |
| 126 | + |
| 127 | +void CartridgeEFF::setI2CData(bool value) { |
| 128 | + myI2CData = value; |
| 129 | + if (myEEPROM) |
| 130 | + myEEPROM->writeSDA(myI2CData); |
| 131 | + else |
| 132 | + cerr << " (No EEPROM)\n"; |
| 133 | +} |
| 134 | + |
| 135 | +uInt8 CartridgeEFF::readI2C() { |
| 136 | + const bool sda = myEEPROM->readSDA(); |
| 137 | + return myImage[0x0ff4 + (sda ? 1 : 0)]; |
| 138 | +} |
| 139 | + |
| 140 | +void CartridgeEFF::setNVRamFile(string_view pathname) |
| 141 | +{ |
| 142 | + myEEPROMFile = std::string(pathname) + std::string("_eeprom.dat"); |
| 143 | + if (mySystem) |
| 144 | + myEEPROM = make_unique<MT24LC16B>(FSNode(myEEPROMFile), (const System&)mySystem, nullptr); |
| 145 | + else |
| 146 | + cerr << "ERROR asked to set up eeprom before cartridge installed in system\n"; |
| 147 | +} |
0 commit comments