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
6namespace openmsx {
7
8V9990VRAM::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
28unsigned 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
41byte 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
48void V9990VRAM::writeVRAMCPU(unsigned address, byte value, EmuTime::param time)
49{
50 sync(time);
51 data.write(mapAddress(address), value);
52}
53
54template<typename Archive>
55void V9990VRAM::serialize(Archive& ar, unsigned /*version*/)
56{
57 ar.serialize("data", data);
58}
60
61} // namespace openmsx
void write(unsigned addr, byte value)
Definition: TrackedRam.hh:38
byte * getWriteBackdoor()
Definition: TrackedRam.hh:52
unsigned getSize() const
Definition: TrackedRam.hh:20
Video RAM for the V9990.
Definition: V9990VRAM.hh:16
void writeVRAMCPU(unsigned address, byte val, EmuTime::param time)
Definition: V9990VRAM.cc:48
V9990VRAM(V9990 &vdp, EmuTime::param time)
Construct V9990 VRAM.
Definition: V9990VRAM.cc:8
void serialize(Archive &ar, unsigned version)
Definition: V9990VRAM.cc:55
void sync(EmuTime::param time)
Update VRAM state to specified moment in time.
Definition: V9990VRAM.hh:33
byte readVRAMCPU(unsigned address, EmuTime::param time)
Definition: V9990VRAM.cc:41
static unsigned transformP2(unsigned address)
Definition: V9990VRAM.hh:43
static unsigned transformBx(unsigned address)
Definition: V9990VRAM.hh:37
static unsigned transformP1(unsigned address)
Definition: V9990VRAM.hh:40
Implementation of the Yamaha V9990 VDP as used in the GFX9000 cartridge by Sunrise.
Definition: V9990.hh:32
V9990DisplayMode getDisplayMode() const
Return the current display mode.
Definition: V9990.hh:192
constexpr double e
Definition: Math.hh:18
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:727
This file implemented 3 utility functions:
Definition: Autofire.cc:9
size_t size(std::string_view utf8)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1009