summaryrefslogtreecommitdiff
path: root/src/nes/mapper.hh
blob: 0aec2ac6f2b789d35940fa4727bd9d33d6be816f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include "nes/util/address.hh"

namespace nes
{
	class cartridge;

	class mapper
	{
		using read_func = std::uint8_t(mapper::*)(address);
		using write_func = void(mapper::*)(address, std::uint8_t);

		cartridge& cartridge_;
		read_func read_;
		write_func write_;

	public:
		static auto select(cartridge&) -> mapper;

		mapper(mapper const&) = delete;
		mapper(mapper&&) = delete;
		auto operator=(mapper const&) -> mapper& = delete;
		auto operator=(mapper&&) -> mapper& = delete;

		auto read(address const addr) -> std::uint8_t
		{
			return (this->*read_)(addr);
		}

		auto write(address const addr, std::uint8_t const value) -> void
		{
			(this->*write_)(addr, value);
		}

	private:
		explicit mapper(cartridge& cartridge, read_func read, write_func write);

		// Implementations

		auto nrom_read(address) -> std::uint8_t;
		auto nrom_write(address, std::uint8_t) -> void;
	};
} // namespace nes