OXYGENHUB
◆ main openmsx / src / video / v9990 / V9990VRAM.cc
1.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "V9990.hh"
2
3
#include "V9990VRAM.hh"
4
5
#include "serialize.hh"
6
7
#include <algorithm>
8
9
namespace openmsx {
10
11
V9990VRAM::V9990VRAM(V9990& vdp_, EmuTime /*time*/)
12
	: vdp(vdp_)
13
	, data(vdp.getDeviceConfig2(), vdp.getName() + " VRAM",
14
	       "V9990 Video RAM", VRAM_SIZE)
15
{
16
}
17
18
void V9990VRAM::clear()
19
{
20
	// Initialize memory. Alternate 0x00/0xff every 512 bytes.
21
	std::span s = data.getWriteBackdoor();
22
	assert((s.size() % 1024) == 0);
23
	while (!s.empty()) {
24
		std::ranges::fill(s.subspan(  0, 512), 0x00);
25
		std::ranges::fill(s.subspan(512, 512), 0xff);
26
		s = s.subspan(1024);
27
	}
28
}
29
30
unsigned V9990VRAM::mapAddress(unsigned address) const
31
{
32
	address &= 0x7FFFF; // change to assert?
33
	switch (vdp.getDisplayMode()) {
34
	case V9990DisplayMode::P1:
35
		return transformP1(address);
36
	case V9990DisplayMode::P2:
37
		return transformP2(address);
38
	default /* Bx */:
39
		return transformBx(address);
40
	}
41
}
42
43
uint8_t V9990VRAM::readVRAMCPU(unsigned address, EmuTime time)
44
{
45
	// note: used for both normal and debug read
46
	sync(time);
47
	return data[mapAddress(address)];
48
}
49
50
void V9990VRAM::writeVRAMCPU(unsigned address, uint8_t value, EmuTime time)
51
{
52
	sync(time);
53
	data.write(mapAddress(address), value);
54
}
55
56
template<typename Archive>
57
void V9990VRAM::serialize(Archive& ar, unsigned /*version*/)
58
{
59
	ar.serialize("data", data);
60
}
61
INSTANTIATE_SERIALIZE_METHODS(V9990VRAM);
62
63
} // namespace openmsx