Class: Rubyboy::Joypad
- Inherits:
-
Object
- Object
- Rubyboy::Joypad
- Defined in:
- lib/rubyboy/joypad.rb
Instance Method Summary collapse
- #action_button(button) ⇒ Object
- #direction_button(button) ⇒ Object
-
#initialize(interupt) ⇒ Joypad
constructor
A new instance of Joypad.
- #read_byte(addr) ⇒ Object
- #write_byte(addr, value) ⇒ Object
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 = | 0xf0 @interupt.request(:joypad) if < 0b1111 end |
#direction_button(button) ⇒ Object
29 30 31 32 33 |
# File 'lib/rubyboy/joypad.rb', line 29 def () @direction = | 0xf0 @interupt.request(:joypad) if < 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 |