OXYGENHUB
◆ main openmsx / src / video / v9990 / V9990VRAM.hh
2.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef V9990VRAM_HH
2
#define V9990VRAM_HH
3
4
#include "V9990CmdEngine.hh"
5
6
#include "EmuTime.hh"
7
#include "TrackedRam.hh"
8
9
#include <cstdint>
10
11
namespace openmsx {
12
13
class V9990;
14
15
/** Video RAM for the V9990.
16
  */
17
class V9990VRAM
18
{
19
public:
20
	/** VRAM Size
21
	  */
22
	static constexpr unsigned VRAM_SIZE = 512 * 1024; // 512kB
23
24
	/** Construct V9990 VRAM.
25
	  * @param vdp The V9990 vdp this VRAM belongs to
26
	  * @param time  Moment in time to create the VRAM
27
	  */
28
	V9990VRAM(V9990& vdp, EmuTime time);
29
30
	void clear();
31
32
	/** Update VRAM state to specified moment in time.
33
	  * @param time Moment in emulated time to synchronize VRAM to
34
	  */
35
	void sync(EmuTime time) {
36
		cmdEngine->sync(time);
37
	}
38
39
	[[nodiscard]] static unsigned transformBx(unsigned address) {
40
		return ((address & 1) << 18) | ((address & 0x7FFFE) >> 1);
41
	}
42
	[[nodiscard]] static unsigned transformP1(unsigned address) {
43
		return address;
44
	}
45
	[[nodiscard]] static unsigned transformP2(unsigned address) {
46
		// Verified on a real Graphics9000
47
		if (address < 0x78000) {
48
			return transformBx(address);
49
		} else if (address < 0x7C000) {
50
			return address - 0x3C000;
51
		} else {
52
			return address;
53
		}
54
	}
55
56
	[[nodiscard]] uint8_t readVRAMBx(unsigned address) const {
57
		return data[transformBx(address)];
58
	}
59
	[[nodiscard]] uint8_t readVRAMP1(unsigned address) const {
60
		return data[transformP1(address)];
61
	}
62
	[[nodiscard]] uint8_t readVRAMP2(unsigned address) const {
63
		return data[transformP2(address)];
64
	}
65
66
	void writeVRAMBx(unsigned address, uint8_t value) {
67
		data.write(transformBx(address), value);
68
	}
69
	void writeVRAMP1(unsigned address, uint8_t value) {
70
		data.write(transformP1(address), value);
71
	}
72
	void writeVRAMP2(unsigned address, uint8_t value) {
73
		data.write(transformP2(address), value);
74
	}
75
76
	[[nodiscard]] uint8_t readVRAMDirect(unsigned address) const {
77
		return data[address];
78
	}
79
	void writeVRAMDirect(unsigned address, uint8_t value) {
80
		data.write(address, value);
81
	}
82
83
	[[nodiscard]] uint8_t readVRAMCPU(unsigned address, EmuTime time);
84
	void writeVRAMCPU(unsigned address, uint8_t val, EmuTime time);
85
86
	void setCmdEngine(V9990CmdEngine& cmdEngine_) { cmdEngine = &cmdEngine_; }
87
88
	template<typename Archive>
89
	void serialize(Archive& ar, unsigned version);
90
91
private:
92
	[[nodiscard]] unsigned mapAddress(unsigned address) const;
93
94
private:
95
	/** V9990 VDP this VRAM belongs to.
96
	  */
97
	V9990& vdp;
98
99
	V9990CmdEngine* cmdEngine = nullptr;
100
101
	/** V9990 VRAM data.
102
	  */
103
	TrackedRam data;
104
};
105
106
} // namespace openmsx
107
108
#endif