Class: GBRb::InstructionSet::Inc

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(register, m = 1, t = 4, flags = true, indirect = false) ⇒ Inc

Returns a new instance of Inc.



160
161
162
163
164
165
166
167
# File 'lib/gbrb/instruction_set/arithmetic.rb', line 160

def initialize register, m=1, t=4, flags=true, indirect=false
  super m, t

  @register = register
  @flags = flags
  @op = :+
  @indirect = indirect
end

Instance Method Details

#call(r, mem) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/gbrb/instruction_set/arithmetic.rb', line 169

def call r, mem
  reg = r.public_send(@register.to_sym)
  tmp = reg.read
  if @indirect
    v = mem.read_byte(tmp) + 1
    mem.write_byte(tmp, v)
    tmp = v
    reg = r.h
  else
    reg.store tmp + 1
  end
  if @flags
    r.clear_add_sub_flag
    if @indirect
      (tmp & 0xff == 0x00) ? r.set_zero_flag : r.clear_zero_flag
      if carry? tmp - 1, 0x01, r.h.half_mask
        r.set_half_carry_flag
      else
        r.clear_half_carry_flag
      end
    else
      reg.zero? ? r.set_zero_flag : r.clear_zero_flag
      if carry? tmp, 0x01, reg.half_mask
        r.set_half_carry_flag
      else
        r.clear_half_carry_flag
      end
    end
  end
end