Class: GBRb::CPU::Jump

Inherits:
Instruction show all
Defined in:
lib/gbrb/cpu/instruction.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.



202
203
204
205
206
# File 'lib/gbrb/cpu/instruction.rb', line 202

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

Instance Method Details

#call(r, mem, offset) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/gbrb/cpu/instruction.rb', line 208

def call r, mem, offset
  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
    if @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
  end
end