class Rnes::Keypad
Constants
- KEY_MAP
Public Class Methods
new()
click to toggle source
# File lib/rnes/keypad.rb, line 14 def initialize @buffer = 0 @copy = 0 @index = 0 end
Public Instance Methods
check()
click to toggle source
# File lib/rnes/keypad.rb, line 20 def check character = ::STDIN.read_nonblock(1) index = KEY_MAP[character] if index @buffer |= 1 << index end rescue ::EOFError # Rescue on no STDIN environment (e.g. CircleCI). rescue ::IO::WaitReadable # Rescue on no data in STDIN buffer. end
read()
click to toggle source
@return [Integer]
# File lib/rnes/keypad.rb, line 33 def read value = @copy[@index] @index = (@index + 1) % 0x10 value end
write(value)
click to toggle source
@param [Integer] value
# File lib/rnes/keypad.rb, line 40 def write(value) if value[0] == 1 @set = true elsif @set @set = false @copy = @buffer @buffer = 0 @index = 0 end end