From 0f24863561b7c609395b59ab73e634509d3111d8 Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Thu, 23 Jan 2025 22:10:55 +0100 Subject: copy reference implementation --- lib/nes/ref/controller.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/nes/ref/controller.cc (limited to 'lib/nes/ref/controller.cc') diff --git a/lib/nes/ref/controller.cc b/lib/nes/ref/controller.cc new file mode 100644 index 0000000..70d6ba2 --- /dev/null +++ b/lib/nes/ref/controller.cc @@ -0,0 +1,18 @@ +#include "nes/ref/controller.hh" + +namespace nes::ref +{ + auto controller::read() -> std::uint8_t + { + auto const res = index_ < 8 ? (pressed_.get_raw_value() >> index_) & 1 : 0; + index_ += 1; + if (strobing_) { index_ = 0; } + return static_cast(res); + } + + auto controller::write(std::uint8_t const value) -> void + { + strobing_ = value & 1; + if (strobing_) { index_ = 0; } + } +} // namespace nes::ref \ No newline at end of file -- cgit v1.3.1