Class: Rubyboy::Joypad

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyboy/joypad.rb

Instance Method Summary collapse

Constructor Details

#initialize(interupt) ⇒ Joypad

Returns a new instance of Joypad.



5
6
7
8
9
10
# File 'lib/rubyboy/joypad.rb', line 5

def initialize(interupt)
  @mode = 0xcf
  @action = 0xff
  @direction = 0xff
  @interupt = interupt
end

Instance Method Details

#action_button(button) ⇒ Object



35
36
37
38
39
# File 'lib/rubyboy/joypad.rb', line 35

def action_button(button)
  @action = button | 0xf0

  @interupt.request(:joypad) if button < 0b1111
end

#direction_button(button) ⇒ Object



29
30
31
32
33
# File 'lib/rubyboy/joypad.rb', line 29

def direction_button(button)
  @direction = button | 0xf0

  @interupt.request(:joypad) if button < 0b1111
end

#read_byte(addr) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/rubyboy/joypad.rb', line 12

def read_byte(addr)
  raise "not implemented: write_byte #{addr}" unless addr == 0xff00

  res = @mode | 0xcf
  res &= @direction if @mode[4] == 0
  res &= @action if @mode[5] == 0

  res
end

#write_byte(addr, value) ⇒ Object



22
23
24
25
26
27
# File 'lib/rubyboy/joypad.rb', line 22

def write_byte(addr, value)
  raise "not implemented: write_byte #{addr}" unless addr == 0xff00

  @mode = value & 0x30
  @mode |= 0xc0
end