Class: GBRb::InstructionSet::Call

Inherits:
Instruction show all
Defined in:
lib/gbrb/instruction_set/call.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 = 3, t_high = 24, t_low = 12, immediates = 2) ⇒ Call

Returns a new instance of Call.



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

def initialize condition, m=3, t_high=24, t_low=12, immediates=2
  @condition = condition
  @t_high = t_high
  @t_low = t_low
  @m_low = m
  super m, t_low, immediates
end

Instance Method Details

#call(r, mem, addr) ⇒ 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
# File 'lib/gbrb/instruction_set/call.rb', line 13

def call r, mem, addr
  condition_met = case @condition
                  when :c
                    r.carry_flag?
                  when :nc
                    not r.carry_flag?
                  when :nz
                    not r.zero_flag?
                  when :z
                    r.zero_flag?
                  when :none
                    true
                  else
                    false
                  end
  if condition_met
    r.sp.store r.sp.read - 2
    mem.write_word(r.sp.read, r.pc.read)
    r.pc.store addr
    @t = @t_high
    @m = @t_high / 4
  else
    @t = @t_low
    @m = @m_low
  end
end