Class: Rubyboy::Interrupt

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

Constant Summary collapse

INTERRUPTS =
{
  vblank: 0,
  lcd: 1,
  timer: 2,
  serial: 3,
  joypad: 4
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeInterrupt

Returns a new instance of Interrupt.



13
14
15
16
# File 'lib/rubyboy/interrupt.rb', line 13

def initialize
  @ie = 0
  @if = 0
end

Instance Method Details

#interruptsObject



36
37
38
# File 'lib/rubyboy/interrupt.rb', line 36

def interrupts
  @if & @ie & 0x1f
end

#read_byte(addr) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/rubyboy/interrupt.rb', line 18

def read_byte(addr)
  case addr
  when 0xff0f
    @if
  when 0xffff
    @ie
  end
end

#request(interrupt) ⇒ Object



40
41
42
# File 'lib/rubyboy/interrupt.rb', line 40

def request(interrupt)
  @if |= (1 << INTERRUPTS[interrupt])
end

#reset_flag(i) ⇒ Object



44
45
46
# File 'lib/rubyboy/interrupt.rb', line 44

def reset_flag(i)
  @if &= (~(1 << i)) & 0xff
end

#write_byte(addr, value) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/rubyboy/interrupt.rb', line 27

def write_byte(addr, value)
  case addr
  when 0xff0f
    @if = value
  when 0xffff
    @ie = value
  end
end