openMSX
ADVram.cc
Go to the documentation of this file.
1 #include "ADVram.hh"
2 #include "VDP.hh"
3 #include "VDPVRAM.hh"
4 #include "MSXException.hh"
5 #include "serialize.hh"
6 #include <algorithm>
7 
8 namespace openmsx {
9 
11  : MSXDevice(config)
12  , vdp(nullptr)
13  , vram(nullptr)
14  , hasEnable(config.getChildDataAsBool("hasEnable", true))
15 {
16  reset(EmuTime::dummy());
17 }
18 
19 void ADVram::init()
20 {
22 
23  auto& refs = getReferences();
24  if (refs.size() != 1) {
25  throw MSXException("Invalid ADVRAM configuration: "
26  "need reference to VDP device.");
27  }
28  vdp = dynamic_cast<VDP*>(refs[0]);
29  if (!vdp) {
30  throw MSXException("Invalid ADVRAM configuration: device '",
31  refs[0]->getName(), "' is not a VDP device.");
32  }
33  vram = &vdp->getVRAM();
34  mask = std::min(vram->getSize(), 128u * 1024) - 1;
35 }
36 
37 void ADVram::reset(EmuTime::param /*time*/)
38 {
39  // TODO figure out exactly what happens during reset
40  baseAddr = 0;
41  planar = false;
42  enabled = !hasEnable;
43 }
44 
45 byte ADVram::readIO(word port, EmuTime::param /*time*/)
46 {
47  // ADVram only gets 'read's from 0x9A
48  if (hasEnable) {
49  enabled = ((port & 0x8000) != 0);
50  planar = ((port & 0x4000) != 0);
51  } else {
52  planar = ((port & 0x0100) != 0);
53  }
54  return 0xFF;
55 }
56 
57 void ADVram::writeIO(word /*port*/, byte value, EmuTime::param /*time*/)
58 {
59  // set mapper register
60  baseAddr = (value & 0x07) << 14;
61 }
62 
63 unsigned ADVram::calcAddress(word address) const
64 {
65  unsigned addr = (address & 0x3FFF) | baseAddr;
66  if (planar) {
67  addr = ((addr & 1) << 16) | (addr >> 1);
68  }
69  return addr & mask;
70 }
71 
72 byte ADVram::readMem(word address, EmuTime::param time)
73 {
74  return enabled ? vram->cpuRead(calcAddress(address), time) : 0xFF;
75 }
76 
77 void ADVram::writeMem(word address, byte value, EmuTime::param time)
78 {
79  if (enabled) {
80  vram->cpuWrite(calcAddress(address), value, time);
81  }
82 }
83 
84 template<typename Archive>
85 void ADVram::serialize(Archive& ar, unsigned /*version*/)
86 {
87  ar.template serializeBase<MSXDevice>(*this);
88  ar.serialize("baseAddr", baseAddr,
89  "enabled", enabled,
90  "planar", planar);
91 }
93 REGISTER_MSXDEVICE(ADVram, "ADVRAM");
94 
95 } // namespace openmsx
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:31
openmsx::VDPVRAM::getSize
unsigned getSize() const
Returns the size of VRAM in bytes.
Definition: VDPVRAM.hh:525
gl::min
vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:274
serialize.hh
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
VDP.hh
openmsx::ADVram::serialize
void serialize(Archive &ar, unsigned version)
Definition: ADVram.cc:85
openmsx::ADVram
Implementation of direct cpu access to VRAM.
Definition: ADVram.hh:15
openmsx::VDPVRAM::cpuRead
byte cpuRead(unsigned address, EmuTime::param time)
Read a byte from VRAM though the CPU interface.
Definition: VDPVRAM.hh:472
MSXException.hh
openmsx::MSXException
Definition: MSXException.hh:9
openmsx::ADVram::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port, change mode bits.
Definition: ADVram.cc:45
openmsx::ADVram::writeIO
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port, set mapper register.
Definition: ADVram.cc:57
openmsx::VDPVRAM::cpuWrite
void cpuWrite(unsigned address, byte value, EmuTime::param time)
Write a byte to VRAM through the CPU interface.
Definition: VDPVRAM.hh:436
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
ADVram.hh
openmsx::ADVram::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: ADVram.cc:37
openmsx::ADVram::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location in the video ram at a certain time.
Definition: ADVram.cc:72
openmsx::VDP::getVRAM
VDPVRAM & getVRAM()
Get the VRAM object for this VDP.
Definition: VDP.hh:147
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::MSXDevice::getReferences
const Devices & getReferences() const
Get the device references that are specified for this device.
Definition: MSXDevice.cc:124
openmsx::MSXDevice::getName
virtual std::string getName() const
Returns a human-readable name for this device.
Definition: MSXDevice.cc:379
openmsx::ADVram::ADVram
ADVram(const DeviceConfig &config)
Definition: ADVram.cc:10
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::MSXDevice::init
virtual void init()
Definition: MSXDevice.cc:48
VDPVRAM.hh
openmsx::ADVram::writeMem
void writeMem(word address, byte value, EmuTime::param time) override
Write a given byte at a certain time to a given location in the video ram.
Definition: ADVram.cc:77
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5