openMSX
V9990VRAM.cc
Go to the documentation of this file.
1 #include "V9990.hh"
2 #include "V9990VRAM.hh"
3 #include "serialize.hh"
4 #include <cstring>
5 
6 namespace openmsx {
7 
8 V9990VRAM::V9990VRAM(V9990& vdp_, EmuTime::param /*time*/)
9  : vdp(vdp_), cmdEngine(nullptr)
10  , data(vdp.getDeviceConfig2(), vdp.getName() + " VRAM",
11  "V9990 Video RAM", VRAM_SIZE)
12 {
13 }
14 
16 {
17  // Initialize memory. Alternate 0x00/0xff every 512 bytes.
18  auto size = data.getSize();
19  assert((size % 1024) == 0);
20  auto* d = data.getWriteBackdoor();
21  auto* e = d + size;
22  while (d != e) {
23  memset(d, 0x00, 512); d += 512;
24  memset(d, 0xff, 512); d += 512;
25  }
26 }
27 
28 unsigned V9990VRAM::mapAddress(unsigned address)
29 {
30  address &= 0x7FFFF; // change to assert?
31  switch (vdp.getDisplayMode()) {
32  case P1:
33  return transformP1(address);
34  case P2:
35  return transformP2(address);
36  default /* Bx */:
37  return transformBx(address);
38  }
39 }
40 
41 byte V9990VRAM::readVRAMCPU(unsigned address, EmuTime::param time)
42 {
43  // note: used for both normal and debug read
44  sync(time);
45  return data[mapAddress(address)];
46 }
47 
48 void V9990VRAM::writeVRAMCPU(unsigned address, byte value, EmuTime::param time)
49 {
50  sync(time);
51  data.write(mapAddress(address), value);
52 }
53 
54 template<typename Archive>
55 void V9990VRAM::serialize(Archive& ar, unsigned /*version*/)
56 {
57  ar.serialize("data", data);
58 }
60 
61 } // namespace openmsx
bool getEnum() const noexcept
Definition: EnumSetting.hh:96
V9990VRAM(V9990 &vdp, EmuTime::param time)
Construct V9990 VRAM.
Definition: V9990VRAM.cc:8
void writeVRAMCPU(unsigned address, byte val, EmuTime::param time)
Definition: V9990VRAM.cc:48
byte readVRAMCPU(unsigned address, EmuTime::param time)
Definition: V9990VRAM.cc:41
V9990DisplayMode getDisplayMode() const
Return the current display mode.
Definition: V9990.hh:190
static unsigned transformP1(unsigned address)
Definition: V9990VRAM.hh:40
static unsigned transformP2(unsigned address)
Definition: V9990VRAM.hh:43
static unsigned transformBx(unsigned address)
Definition: V9990VRAM.hh:37
Video RAM for the V9990.
Definition: V9990VRAM.hh:15
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
void serialize(Archive &ar, unsigned version)
Definition: V9990VRAM.cc:55