diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-01-29 14:49:20 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-01-29 14:49:20 +0100 |
| commit | 5959349f341a2380c0c3f41ec40a1e8e0d969d00 (patch) | |
| tree | 8b36ba3f8cade68562af1dfdcea8b42160619975 /lib/nes/sys/controller.cc | |
| parent | 1d32f7561305d6c86b1c80858bc73d55b1c6c402 (diff) | |
refactor: move emulation logic into sys
Diffstat (limited to 'lib/nes/sys/controller.cc')
| -rw-r--r-- | lib/nes/sys/controller.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/nes/sys/controller.cc b/lib/nes/sys/controller.cc new file mode 100644 index 0000000..910ef57 --- /dev/null +++ b/lib/nes/sys/controller.cc @@ -0,0 +1,18 @@ +#include "nes/sys/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 |
