Class: GBRb::InstructionSet::Jump

Inherits:
Instruction show all
Defined in:
lib/gbrb/instruction_set/jump.rb

Instance Attribute Summary

Attributes inherited from Instruction

#i, #m, #t

Instance Method Summary collapse

Methods inherited from Instruction

#carry?, #immediate_count

Constructor Details

#initialize(condition, m = 2, t_high = 12, t_low = 8, immediates = 1) ⇒ Jump

Returns a new instance of Jump.



5
6
7
8
9
10
11
# File 'lib/gbrb/instruction_set/jump.rb', line 5

def initialize condition, m=2, t_high=12, t_low=8, immediates=1
  super m, t_low, immediates
  @m_low = m
  @t_high = t_high
  @t_low = t_low
  @condition = condition.downcase.to_sym
end

Instance Method Details

#call(r, mem, offset = 0x00) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gbrb/instruction_set/jump.rb', line 13

def call r, mem, offset=0x00
  do_it = case @condition
          when :c
            r.carry_flag?
          when :none
            true
          when :nc
            not r.carry_flag?
          when :nz
            not r.zero_flag?
          when :z
            r.zero_flag?
          else
            false
          end

  if do_it
    @t = @t_high
    @m = @t_high / 4
    if @immediates == 0
      r.pc.store r.hl.read
    elsif @immediates == 1
      sign = (offset >> 7 == 1) ? :- : :+
      offset = ((offset ^ 0xff) + 1) & 0xff if sign == :-
      r.pc.store r.pc.read.public_send(sign, offset)
    else
      r.pc.store offset
    end
  else
    @t = @t_low
    @m = @m_low
  end
end