summaryrefslogtreecommitdiff
path: root/lib/nes/mapper.hh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nes/mapper.hh')
-rw-r--r--lib/nes/mapper.hh56
1 files changed, 12 insertions, 44 deletions
diff --git a/lib/nes/mapper.hh b/lib/nes/mapper.hh
index f2873a6..7e41b23 100644
--- a/lib/nes/mapper.hh
+++ b/lib/nes/mapper.hh
@@ -1,6 +1,7 @@
#pragma once
#include "nes/util/address.hh"
+#include "nes/util/status.hh"
namespace nes
{
@@ -8,57 +9,24 @@ namespace nes
class mapper
{
- using read_cpu_func = std::uint8_t(mapper::*)(address);
- using write_cpu_func = void(mapper::*)(address, std::uint8_t);
- using read_ppu_func = std::uint8_t(mapper::*)(address, std::uint8_t const* vram);
- using write_ppu_func = void(mapper::*)(address, std::uint8_t* vram, std::uint8_t);
-
- cartridge& cartridge_;
- read_cpu_func read_cpu_;
- write_cpu_func write_cpu_;
- read_ppu_func read_ppu_;
- write_ppu_func write_ppu_;
-
public:
- static auto select(cartridge&) -> mapper;
+ static auto invalid() -> mapper&;
+ static auto get(std::uint8_t number) -> mapper&;
+
+ virtual ~mapper() = default;
mapper(mapper const&) = delete;
mapper(mapper&&) = delete;
auto operator=(mapper const&) -> mapper& = delete;
auto operator=(mapper&&) -> mapper& = delete;
- auto read_cpu(address const addr) -> std::uint8_t
- {
- return (this->*read_cpu_)(addr);
- }
-
- auto write_cpu(address const addr, std::uint8_t const value) -> void
- {
- (this->*write_cpu_)(addr, value);
- }
-
- auto read_ppu(address const addr, std::uint8_t const* vram) -> std::uint8_t
- {
- return (this->*read_ppu_)(addr, vram);
- }
-
- auto write_ppu(address const addr, std::uint8_t* vram, std::uint8_t const value) -> void
- {
- (this->*write_ppu_)(addr, vram, value);
- }
-
- private:
- explicit mapper(
- cartridge& cartridge,
- read_cpu_func read_cpu, write_cpu_func write_cpu,
- read_ppu_func read_ppu, write_ppu_func write_ppu);
-
- // Implementations
+ virtual auto validate(cartridge&) -> status = 0;
+ virtual auto read_cpu(address, cartridge&) -> std::uint8_t = 0;
+ virtual auto write_cpu(address, std::uint8_t, cartridge&) -> void = 0;
+ virtual auto read_ppu(address, cartridge&, std::uint8_t const* vram) -> std::uint8_t = 0;
+ virtual auto write_ppu(address, std::uint8_t, cartridge&, std::uint8_t* vram) -> void = 0;
- auto nrom_read_cpu(address) -> std::uint8_t;
- auto nrom_write_cpu(address, std::uint8_t) -> void;
- auto nrom_read_ppu(address, std::uint8_t const* vram) -> std::uint8_t;
- auto nrom_write_ppu(address, std::uint8_t* vram, std::uint8_t) -> void;
- auto nrom_mirrored_vram_address(address) const -> unsigned;
+ protected:
+ explicit mapper() = default;
};
} // namespace nes \ No newline at end of file