diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-01-23 22:02:11 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-01-23 22:02:11 +0100 |
| commit | b1d1573702f21e3104606d6ade5f5d39ec86a33a (patch) | |
| tree | d703be130a5d6f9ff2626313d3380ed34de44dd7 /lib/nes/controller.cc | |
| parent | 6512dd599d13035f6a90b2009344e02c488f5aae (diff) | |
restructure project
Diffstat (limited to 'lib/nes/controller.cc')
| -rw-r--r-- | lib/nes/controller.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/nes/controller.cc b/lib/nes/controller.cc new file mode 100644 index 0000000..d9d6946 --- /dev/null +++ b/lib/nes/controller.cc @@ -0,0 +1,18 @@ +#include "nes/controller.hh" + +namespace nes +{ + 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<std::uint8_t>(res); + } + + auto controller::write(std::uint8_t const value) -> void + { + strobing_ = value & 1; + if (strobing_) { index_ = 0; } + } +} // namespace nes
\ No newline at end of file |
