Class: GBRb::InstructionSet::Rl

Inherits:
Instruction show all
Defined in:
lib/gbrb/instruction_set/rotate.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, carry = false, indirect = false, m = 1, t = 4, zero = true) ⇒ Rl

Returns a new instance of Rl.



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

def initialize target, carry=false, indirect=false, m=1, t=4, zero=true
  super m, t
  @target = target.to_sym
  @carry = carry
  @indirect = indirect
  @zero_check = zero
end

Instance Method Details

#call(r, mem) ⇒ Object



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
39
40
41
42
43
44
45
# File 'lib/gbrb/instruction_set/rotate.rb', line 14

def call r, mem
  if @indirect
    address = r.public_send(@target).read
    v = mem.read_byte(address) << 1
  else
    v = r.public_send(@target).read << 1
  end

  carry_in = if @carry
               v & 0x100 == 0x100 ? 1 : 0
             else
               r.carry_flag? ? 1 : 0
             end

  v += carry_in

  if @indirect
    mem.write_byte(address, v)
  else
    r.public_send(@target).store v
  end

  r.clear_add_sub_flag
  r.clear_half_carry_flag
  if @zero_check
    v & 0xff == 0 ? r.set_zero_flag : r.clear_zero_flag
  else
    r.clear_zero_flag
  end
  carry_out = v >> 8
  carry_out == 1 ? r.set_carry_flag : r.clear_carry_flag
end