openMSX
RomDooly.cc
Go to the documentation of this file.
1 //
2 // Agigongnyong Dooly
3 //
4 
5 #include "RomDooly.hh"
6 #include "CacheLine.hh"
7 #include "serialize.hh"
8 
9 namespace openmsx {
10 
11 RomDooly::RomDooly(const DeviceConfig& config, Rom&& rom_)
12  : MSXRom(config, std::move(rom_))
13  , romBlockDebug(*this, &conversion, 0x4000, 0x8000, 15)
14 {
15  conversion = 0;
16 }
17 
18 void RomDooly::reset(EmuTime::param /*time*/)
19 {
20  conversion = 0;
21 }
22 
23 byte RomDooly::peekMem(word address, EmuTime::param /*time*/) const
24 {
25  if ((0x4000 <= address) && (address < 0xc000)) {
26  byte value = rom[address - 0x4000];
27  switch (conversion) {
28  case 0:
29  return value;
30  case 1:
31  return (value & 0xf8) | (value << 2 & 0x04) | (value >> 1 & 0x03);
32  case 4:
33  return (value & 0xf8) | (value >> 2 & 0x01) | (value << 1 & 0x06);
34  case 2:
35  case 5:
36  case 6:
37  switch (value & 0x07) {
38  case 1:
39  case 2:
40  case 4:
41  return value & 0xf8;
42  case 3:
43  case 5:
44  case 6:
45  if (conversion == 2) return (value & 0xf8) | (((value << 2 & 0x04) | (value >> 1 & 0x03)) ^ 0x07);
46  if (conversion == 5) return value ^ 0x07;
47  if (conversion == 6) return (value & 0xf8) | (((value >> 2 & 0x01) | (value << 1 & 0x06)) ^ 0x07);
48  [[fallthrough]];
49  default:
50  return value;
51  }
52  default:
53  return value | 0x07;
54  }
55  }
56  return 0xff;
57 }
58 
59 byte RomDooly::readMem(word address, EmuTime::param time)
60 {
61  return peekMem(address, time);
62 }
63 
64 void RomDooly::writeMem(word address, byte value, EmuTime::param /*time*/)
65 {
66  if ((0x4000 <= address) && (address < 0xc000)) {
67  conversion = value & 0x07;
68  }
69 }
70 
71 byte* RomDooly::getWriteCacheLine(word address) const
72 {
73  if (((0x4000 & CacheLine::HIGH) <= address) && (address < (0xc000 & CacheLine::HIGH))) {
74  return nullptr;
75  } else {
76  return unmappedWrite;
77  }
78 }
79 
80 template<typename Archive>
81 void RomDooly::serialize(Archive& ar, unsigned /*version*/)
82 {
83  ar.template serializeBase<MSXDevice>(*this);
84  ar.serialize("conversion", conversion);
85 }
88 
89 } // namespace openmsx
openmsx::RomDooly::RomDooly
RomDooly(const DeviceConfig &config, Rom &&rom)
Definition: RomDooly.cc:11
serialize.hh
openmsx::RomDooly::getWriteCacheLine
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomDooly.cc:71
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MSXDevice::unmappedWrite
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
RomDooly.hh
openmsx::CacheLine::HIGH
constexpr unsigned HIGH
Definition: CacheLine.hh:10
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MSXRom
Definition: MSXRom.hh:10
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
CacheLine.hh
openmsx::MSXRom::rom
Rom rom
Definition: MSXRom.hh:20
openmsx::Rom
Definition: Rom.hh:21
openmsx::RomDooly::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomDooly.cc:23
openmsx::RomDooly
Definition: RomDooly.hh:10
openmsx::RomDooly::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: RomDooly.cc:64
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::RomDooly::serialize
void serialize(Archive &ar, unsigned version)
Definition: RomDooly.cc:81
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::RomDooly::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomDooly.cc:18
openmsx::RomDooly::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomDooly.cc:59