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 
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
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:98
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
STL namespace.
constexpr unsigned HIGH
Definition: CacheLine.hh:10
void serialize(Archive &ar, unsigned version)
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
RomMitsubishiMLTS2(const DeviceConfig &config, Rom &&rom)
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.
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
void reset(EmuTime::param time) override
This method is called on reset.
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:53
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading...
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:65
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:275
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:589
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...