openMSX
RomMitsubishiMLTS2.cc
Go to the documentation of this file.
1 #include "RomMitsubishiMLTS2.hh"
2 #include "CacheLine.hh"
3 #include "serialize.hh"
4 
5 #include <iostream>
6 
7 namespace openmsx {
8 
10  : Rom8kBBlocks(config, std::move(rom_))
11  , ram(config, getName() + " RAM", "ML-TS2 RAM", 0x2000)
12 {
13  reset(EmuTime::dummy());
14 }
15 
16 void RomMitsubishiMLTS2::reset(EmuTime::param /*time*/)
17 {
18  setRom(2, 0);
19 }
20 
21 void RomMitsubishiMLTS2::writeMem(word address, byte value, EmuTime::param /*time*/)
22 {
23  // TODO What are these 4 registers? Are there any more?
24  // Is there any mirroring going on?
25  if (address == 0x7f00) {
26  // TODO
27  } else if (address == 0x7f01) {
28  // TODO
29  } else if (address == 0x7f02) {
30  // TODO
31  } else if (address == 0x7f03) {
32  // TODO
33  } else if (address == 0x7FC0) {
34  byte bank = ((value & 0x10) >> 2) | // transform bit-pattern
35  ((value & 0x04) >> 1) | // ...a.b.c
36  ((value & 0x01) >> 0); // into 00000abc
37  std::cerr << "Setting MLTS2 mapper page 1 to bank " << int(bank) << '\n';
38  setRom(2, bank);
39  } else if ((0x6000 <= address) && (address < 0x8000)) {
40  ram[address & 0x1FFF] = value;
41  }
42 }
43 
44 byte RomMitsubishiMLTS2::readMem(word address, EmuTime::param time)
45 {
46  return peekMem(address, time);
47 }
48 
49 byte RomMitsubishiMLTS2::peekMem(word address, EmuTime::param time) const
50 {
51  // TODO What are these 4 registers? Are there any more?
52  // Is there any mirroring going on?
53  // Is the bank select register readable? (0x7fc0)
54  if (address == 0x7f00) {
55  return 0xff; // TODO
56  } else if (address == 0x7f01) {
57  return 0xff; // TODO
58  } else if (address == 0x7f02) {
59  return 0xff; // TODO
60  } else if (address == 0x7f03) {
61  return 0xff; // TODO
62  } else if ((0x6000 <= address) && (address < 0x8000)) {
63  return ram[address & 0x1FFF];
64  } else {
65  return Rom8kBBlocks::peekMem(address, time);
66  }
67 }
68 
69 const byte* RomMitsubishiMLTS2::getReadCacheLine(word address) const
70 {
71  if (address == (0x7FC0 & CacheLine::HIGH)) return nullptr;
72  if ((0x6000 <= address) && (address < 0x8000)) {
73  return &ram[address & 0x1FFF];
74  }
75  return Rom8kBBlocks::getReadCacheLine(address);
76 }
77 
79 {
80  if (address == (0x7FC0 & CacheLine::HIGH)) return nullptr;
81  if ((0x6000 <= address) && (address < 0x8000)) {
82  return const_cast<byte*>(&ram[address & 0x1FFF]);
83  }
84  return unmappedWrite;
85 }
86 
87 template<typename Archive>
88 void RomMitsubishiMLTS2::serialize(Archive& ar, unsigned /*version*/)
89 {
90  ar.template serializeBase<Rom8kBBlocks>(*this);
91 }
93 REGISTER_MSXDEVICE(RomMitsubishiMLTS2, "RomMitsubishiMLTS2");
94 
95 } // namespace openmsx
openmsx::RomBlocks::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:59
openmsx::RomMitsubishiMLTS2::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomMitsubishiMLTS2.cc:16
serialize.hh
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MSXDevice::unmappedWrite
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
openmsx::RomMitsubishiMLTS2
Definition: RomMitsubishiMLTS2.hh:15
openmsx::RomMitsubishiMLTS2::RomMitsubishiMLTS2
RomMitsubishiMLTS2(const DeviceConfig &config, Rom &&rom)
Definition: RomMitsubishiMLTS2.cc:9
openmsx::RomMitsubishiMLTS2::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: RomMitsubishiMLTS2.cc:21
openmsx::CacheLine::HIGH
constexpr unsigned HIGH
Definition: CacheLine.hh:10
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:740
openmsx::RomMitsubishiMLTS2::getWriteCacheLine
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomMitsubishiMLTS2.cc:78
openmsx::RomBlocks::getReadCacheLine
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomBlocks.cc:71
openmsx::RomBlocks::setRom
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:104
openmsx::RomMitsubishiMLTS2::serialize
void serialize(Archive &ar, unsigned version)
Definition: RomMitsubishiMLTS2.cc:88
openmsx::RomBlocks
Definition: RomBlocks.hh:14
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
CacheLine.hh
openmsx::Rom
Definition: Rom.hh:21
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::RomMitsubishiMLTS2::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomMitsubishiMLTS2.cc:49
openmsx::RomMitsubishiMLTS2::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomMitsubishiMLTS2.cc:44
RomMitsubishiMLTS2.hh
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::RomMitsubishiMLTS2::getReadCacheLine
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomMitsubishiMLTS2.cc:69