Class: GBRb::InstructionSet::Bit

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

Returns a new instance of Bit.



44
45
46
47
48
49
50
# File 'lib/gbrb/instruction_set/bitwise.rb', line 44

def initialize bit, target, indirect=false, m=2, t=8
  super m,t
  @target = target
  @bit = bit
  @indirect = indirect
  @mask = 1 << @bit
end

Instance Method Details

#call(r, mem) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gbrb/instruction_set/bitwise.rb', line 52

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

  v & @mask != @mask ? r.set_zero_flag : r.clear_zero_flag
  r.set_half_carry_flag
  r.clear_add_sub_flag
end