blob: 70d6ba2a5b68ff56583d6f583a1c410a604c5194 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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<std::uint8_t>(res);
}
auto controller::write(std::uint8_t const value) -> void
{
strobing_ = value & 1;
if (strobing_) { index_ = 0; }
}
} // namespace nes::ref
|