openMSX
ESE_RAM.cc
Go to the documentation of this file.
1 /*
2  * MEGA-SCSI and ESE-RAM cartridge:
3  * The mapping does SRAM and MB89352A(MEGA-SCSI) to ASCII8 or
4  * an interchangeable bank controller.
5  * The rest of this documentation is only about ESE-RAM specifically.
6  *
7  * Specification:
8  * SRAM(MegaROM) controller: ASCII8 type
9  * SRAM capacity : 128, 256, 512 and 1024KB
10  *
11  * Bank changing address:
12  * bank 4(0x4000-0x5fff): 0x6000 - 0x67FF (0x6000 used)
13  * bank 6(0x6000-0x7fff): 0x6800 - 0x6FFF (0x6800 used)
14  * bank 8(0x8000-0x9fff): 0x7000 - 0x77FF (0x7000 used)
15  * bank A(0xa000-0xbfff): 0x7800 - 0x7FFF (0x7800 used)
16  *
17  * ESE-RAM Bank Map:
18  * BANK 00H-7FH (read only)
19  * BANK 80H-FFH (write and read. mirror of 00H-7FH)
20  */
21 
22 #include "ESE_RAM.hh"
23 #include "MSXException.hh"
24 #include "one_of.hh"
25 #include "serialize.hh"
26 #include <cassert>
27 
28 namespace openmsx {
29 
30 unsigned ESE_RAM::getSramSize() const
31 {
32  unsigned sramSize = getDeviceConfig().getChildDataAsInt("sramsize", 256); // size in kb
33  if (sramSize != one_of(1024u, 512u, 256u, 128u)) {
34  throw MSXException(
35  "SRAM size for ", getName(),
36  " should be 128, 256, 512 or 1024kB and not ",
37  sramSize, "kB!");
38  }
39  return sramSize * 1024; // in bytes
40 }
41 
43  : MSXDevice(config)
44  , sram(getName() + " SRAM", getSramSize(), config)
45  , romBlockDebug(*this, mapped, 0x4000, 0x8000, 13)
46  , blockMask((sram.getSize() / 8192) - 1)
47 {
48  reset(EmuTime::dummy());
49 }
50 
51 void ESE_RAM::reset(EmuTime::param /*time*/)
52 {
53  for (int i = 0; i < 4; ++i) {
54  setSRAM(i, 0);
55  }
56 }
57 
58 byte ESE_RAM::readMem(word address, EmuTime::param /*time*/)
59 {
60  byte result;
61  if ((0x4000 <= address) && (address < 0xC000)) {
62  unsigned page = (address / 8192) - 2;
63  word addr = address & 0x1FFF;
64  result = sram[8192 * mapped[page] + addr];
65  } else {
66  result = 0xFF;
67  }
68  return result;
69 }
70 
71 const byte* ESE_RAM::getReadCacheLine(word address) const
72 {
73  if ((0x4000 <= address) && (address < 0xC000)) {
74  unsigned page = (address / 8192) - 2;
75  address &= 0x1FFF;
76  return &sram[8192 * mapped[page] + address];
77  } else {
78  return unmappedRead;
79  }
80 }
81 
82 void ESE_RAM::writeMem(word address, byte value, EmuTime::param /*time*/)
83 {
84  if ((0x6000 <= address) && (address < 0x8000)) {
85  byte region = ((address >> 11) & 3);
86  setSRAM(region, value);
87  } else if ((0x4000 <= address) && (address < 0xC000)) {
88  unsigned page = (address / 8192) - 2;
89  address &= 0x1FFF;
90  if (isWriteable[page]) {
91  sram.write(8192 * mapped[page] + address, value);
92  }
93  }
94 }
95 
96 byte* ESE_RAM::getWriteCacheLine(word address) const
97 {
98  if ((0x6000 <= address) && (address < 0x8000)) {
99  return nullptr;
100  } else if ((0x4000 <= address) && (address < 0xC000)) {
101  unsigned page = (address / 8192) - 2;
102  if (isWriteable[page]) {
103  return nullptr;
104  }
105  }
106  return unmappedWrite;
107 }
108 
109 void ESE_RAM::setSRAM(unsigned region, byte block)
110 {
111  invalidateDeviceRWCache(region * 0x2000 + 0x4000, 0x2000);
112  assert(region < 4);
113  isWriteable[region] = (block & 0x80) != 0;
114  mapped[region] = block & blockMask;
115 }
116 
117 template<typename Archive>
118 void ESE_RAM::serialize(Archive& ar, unsigned /*version*/)
119 {
120  ar.template serializeBase<MSXDevice>(*this);
121  ar.serialize("SRAM", sram,
122  "isWriteable", isWriteable,
123  "mapped", mapped);
124 }
127 
128 } // namespace openmsx
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
one_of.hh
serialize.hh
openmsx::ESE_RAM::serialize
void serialize(Archive &ar, unsigned version)
Definition: ESE_RAM.cc:118
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MSXDevice::unmappedWrite
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
openmsx::ESE_RAM::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: ESE_RAM.cc:51
MSXException.hh
openmsx::ESE_RAM::writeMem
void writeMem(word address, byte value, EmuTime::param time) override
Write a given byte to a given location at a certain time to this device.
Definition: ESE_RAM.cc:82
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::ESE_RAM
Definition: ESE_RAM.hh:11
openmsx::ESE_RAM::getWriteCacheLine
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: ESE_RAM.cc:96
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:740
one_of
Definition: one_of.hh:7
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::SRAM::write
void write(unsigned addr, byte value)
Definition: SRAM.cc:67
openmsx::MSXDevice::invalidateDeviceRWCache
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
Definition: MSXDevice.hh:208
openmsx::ESE_RAM::ESE_RAM
ESE_RAM(const DeviceConfig &config)
Definition: ESE_RAM.cc:42
openmsx::MSXDevice::getName
virtual std::string getName() const
Returns a human-readable name for this device.
Definition: MSXDevice.cc:381
openmsx::MSXDevice::unmappedRead
static byte unmappedRead[0x10000]
Definition: MSXDevice.hh:300
openmsx::ESE_RAM::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: ESE_RAM.cc:58
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::ESE_RAM::getReadCacheLine
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: ESE_RAM.cc:71
openmsx::XMLElement::getChildDataAsInt
int getChildDataAsInt(std::string_view childName, int defaultValue=0) const
Definition: XMLElement.cc:185
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
ESE_RAM.hh
openmsx::MSXDevice::getDeviceConfig
const XMLElement & getDeviceConfig() const
Get the configuration section for this device.
Definition: MSXDevice.hh:230