openMSX
RomMSXtra.cc
Go to the documentation of this file.
1 #include "RomMSXtra.hh"
2 #include "serialize.hh"
3 
4 namespace openmsx {
5 
6 RomMSXtra::RomMSXtra(const DeviceConfig& config, Rom&& rom_)
7  : MSXRom(config, std::move(rom_))
8  , ram(config, getName() + " RAM", "MSXtra RAM", 0x0800)
9 {
10  for (int i = 0; i < 0x800; ++i) {
11  ram[i] = (i & 1) ? 0x5a : 0xa5;
12  }
13 }
14 
15 byte RomMSXtra::readMem(word address, EmuTime::param /*time*/)
16 {
17  if ((0x4000 <= address) && (address < 0x6000)) {
18  return rom[address & 0x1fff];
19  } else if ((0x6000 <= address) && (address < 0x8000)) {
20  return ram[address & 0x07ff];
21  } else {
22  return 0xff;
23  }
24 }
25 
26 const byte* RomMSXtra::getReadCacheLine(word address) const
27 {
28  if ((0x4000 <= address) && (address < 0x6000)) {
29  return &rom[address & 0x1fff];
30  } else if ((0x6000 <= address) && (address < 0x8000)) {
31  return &ram[address & 0x07ff];
32  } else {
33  return unmappedRead;
34  }
35 }
36 
37 // default peekMem() implementation is OK
38 
39 void RomMSXtra::writeMem(word address, byte value, EmuTime::param /*time*/)
40 {
41  if ((0x6000 <= address) && (address < 0x8000)) {
42  ram[address & 0x07ff] = value;
43  }
44 }
45 
46 byte* RomMSXtra::getWriteCacheLine(word address) const
47 {
48  if ((0x6000 <= address) && (address < 0x8000)) {
49  return const_cast<byte*>(&ram[address & 0x07ff]);
50  } else {
51  return unmappedWrite;
52  }
53 }
54 
55 template<typename Archive>
56 void RomMSXtra::serialize(Archive& ar, unsigned /*version*/)
57 {
58  // skip MSXRom base class
59  ar.template serializeBase<MSXDevice>(*this);
60  ar.serialize("ram", ram);
61 }
64 
65 } // namespace openmsx
openmsx::RomMSXtra::RomMSXtra
RomMSXtra(const DeviceConfig &config, Rom &&rom)
Definition: RomMSXtra.cc:6
serialize.hh
openmsx::RomMSXtra::getReadCacheLine
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomMSXtra.cc:26
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MSXDevice::unmappedWrite
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MSXRom
Definition: MSXRom.hh:10
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:740
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::RomMSXtra::getWriteCacheLine
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomMSXtra.cc:46
openmsx::MSXRom::rom
Rom rom
Definition: MSXRom.hh:20
openmsx::RomMSXtra::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomMSXtra.cc:15
openmsx::Rom
Definition: Rom.hh:21
openmsx::RomMSXtra
Definition: RomMSXtra.hh:10
openmsx::MSXDevice::unmappedRead
static byte unmappedRead[0x10000]
Definition: MSXDevice.hh:300
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
RomMSXtra.hh
openmsx::RomMSXtra::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: RomMSXtra.cc:39
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::RomMSXtra::serialize
void serialize(Archive &ar, unsigned version)
Definition: RomMSXtra.cc:56