Class: GBRb::InstructionSet::AddHl

Inherits:
Instruction show all
Defined in:
lib/gbrb/instruction_set/arithmetic.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(target, m = 2, t = 8) ⇒ AddHl

Returns a new instance of AddHl.



48
49
50
51
52
# File 'lib/gbrb/instruction_set/arithmetic.rb', line 48

def initialize target, m=2, t=8
  super m, t
  @target = target.to_sym
  @op = :+
end

Instance Method Details

#call(r, mem) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gbrb/instruction_set/arithmetic.rb', line 54

def call r, mem
  left = r.hl.read
  right = r.public_send(@target).read
  r.hl.store left + right
  if r.hl.read < left + right
    r.set_carry_flag
  else
    r.clear_carry_flag
  end
  if carry? left, right, r.hl.half_mask
    r.set_half_carry_flag
  else
    r.clear_half_carry_flag
  end
  r.clear_add_sub_flag
end