OXYGENHUB
◆ main openmsx / src / video / ADVram.hh
2.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef ADVRAM_HH
2
#define ADVRAM_HH
3
4
#include "MSXDevice.hh"
5
6
namespace openmsx {
7
8
class VDP;
9
class VDPVRAM;
10
11
/** Implementation of direct cpu access to VRAM.  ADVram (Accesso
12
  * Direito à Vram is a rare hardware modification that allows the
13
  * CPU to access the video ram in the same way as ordinary ram.
14
  */
15
class ADVram final : public MSXDevice
16
{
17
public:
18
	explicit ADVram(const DeviceConfig& config);
19
20
	/** This method is called on reset.  Reset the mapper register and
21
	 * the planar bit, if the device is configured with an enable bit
22
	 * then that bit is reset as well.
23
	 */
24
	void reset(EmuTime time) override;
25
26
	/** Read a byte from an IO port, change mode bits.  The planar bit
27
	 * and possibly the enable bit are set according to address lines
28
	 * that are normally ignored for IO reads.  Returns 255.
29
	 */
30
	[[nodiscard]] uint8_t readIO(uint16_t port, EmuTime time) override;
31
	// default peekIO() implementation is ok.
32
33
	/** Write a byte to a given IO port, set mapper register.  */
34
	void writeIO(uint16_t port, uint8_t value, EmuTime time) override;
35
36
	/** Read a byte from a location in the video ram at a certain
37
	 * time.  If the device is enabled then the value returned comes
38
	 * from the video ram, otherwise it returns 255.
39
	 */
40
	[[nodiscard]] uint8_t readMem(uint16_t address, EmuTime time) override;
41
42
	/** Write a given byte at a certain time to a given location in
43
	 * the video ram.  If the device is enabled then the write is
44
	 * redirected to the video ram, if it is not, nothing happens.
45
	 */
46
	void writeMem(uint16_t address, uint8_t value, EmuTime time) override;
47
48
	template<typename Archive>
49
	void serialize(Archive& ar, unsigned version);
50
51
private:
52
	void init() override;
53
	[[nodiscard]] inline unsigned calcAddress(uint16_t address) const;
54
55
private:
56
	VDP* vdp = nullptr;
57
	VDPVRAM* vram = nullptr;
58
	/** Bit mask applied to logical addresses, reflects vram size.  */
59
	/*const*/ unsigned mask;
60
	/** Base address of selected page in vram.  */
61
	unsigned baseAddr;
62
	/** True if ADVram device is enabled.  */
63
	bool enabled;
64
	/** True if ADVram device can be switched on or off by performing
65
		IO-reads.  */
66
	const bool hasEnable;
67
	/** True if address bits are shuffled as is appropriate for screen
68
		7 and higher.  */
69
	bool planar;
70
};
71
72
} // namespace openmsx
73
74
#endif // ADVRAM_HH