Class: GBRb::InstructionSet::AddSpR8

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(m = 4, t = 16, immediates = 1) ⇒ AddSpR8



73
74
75
# File 'lib/gbrb/instruction_set/arithmetic.rb', line 73

def initialize m=4, t=16, immediates=1
  super
end

Instance Method Details

#call(r, mem, offset) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/gbrb/instruction_set/arithmetic.rb', line 77

def call r, mem, offset
  v = r.sp.read
  if offset > 127
    v -= ((offset ^ 0xff) + 1) & 0xff
  else
    v += offset
  end
  r.clear_zero_flag
  r.clear_add_sub_flag
  check = r.sp.read ^ offset ^ ((r.sp.read + offset)& 0xffff)
  r.sp.store v
  if check & 0x100 == 0x100
    r.set_carry_flag
  else
    r.clear_carry_flag
  end
  if check & 0x10 == 0x10
    r.set_half_carry_flag
  else
    r.clear_half_carry_flag
  end
end