OXYGENHUB
◆ main openmsx / src / memory / MusicalMemoryMapper.hh
1.8 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef MUSICALMEMORYMAPPER_HH
2
#define MUSICALMEMORYMAPPER_HH
3
4
#include "MSXMemoryMapperBase.hh"
5
#include "SN76489.hh"
6
7
namespace openmsx {
8
9
/** Memory mapper which also controls an SN76489AN sound chip.
10
  *
11
  * http://map.grauw.nl/resources/sound/musical-memory-mapper.pdf
12
  */
13
class MusicalMemoryMapper final : public MSXMemoryMapperBase
14
{
15
public:
16
	explicit MusicalMemoryMapper(const DeviceConfig& config);
17
18
	void reset(EmuTime time) override;
19
	[[nodiscard]] byte readIO(uint16_t port, EmuTime time) override;
20
	[[nodiscard]] byte peekIO(uint16_t port, EmuTime time) const override;
21
	void writeIO(uint16_t port, byte value, EmuTime time) override;
22
	[[nodiscard]] byte peekMem(uint16_t address, EmuTime time) const override;
23
	[[nodiscard]] byte readMem(uint16_t address, EmuTime time) override;
24
	void writeMem(uint16_t address, byte value, EmuTime time) override;
25
	[[nodiscard]] const byte* getReadCacheLine(uint16_t start) const override;
26
	[[nodiscard]] byte* getWriteCacheLine(uint16_t start) override;
27
28
	template<typename Archive>
29
	void serialize(Archive& ar, unsigned version);
30
31
private:
32
	/** Attempts to read a register at the given address.
33
	  * Returns the register value, or -1 if no register exists at the given
34
	  * address or register access is disabled.
35
	  */
36
	[[nodiscard]] int readReg(uint16_t address) const;
37
38
	/** Returns true iff a mapper or control register is accessible in the
39
	  * 256-byte block containing the given address.
40
	  */
41
	[[nodiscard]] bool registerAccessAt(uint16_t address) const;
42
43
	/** Returns true iff the page at the given address is currently write
44
	  * protected.
45
	  */
46
	[[nodiscard]] bool writeProtected(uint16_t address) const {
47
		unsigned page = address >> 14;
48
		return (controlReg & (1 << page)) != 0;
49
	}
50
51
	void updateControlReg(byte value);
52
53
private:
54
	SN76489 sn76489;
55
	byte controlReg = 0;
56
};
57
58
} // namespace openmsx
59
60
#endif