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