Class: GBRb::InstructionSet::Sra

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, indirect = false, m = 1, t = 4) ⇒ Sra

Returns a new instance of Sra.



152
153
154
155
156
# File 'lib/gbrb/instruction_set/rotate.rb', line 152

def initialize target, indirect=false, m=1, t=4
  super m, t
  @target = target
  @indirect = indirect
end

Instance Method Details

#call(r, mem) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/gbrb/instruction_set/rotate.rb', line 158

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

  v & 0b01 == 0b01 ? r.set_carry_flag : r.clear_carry_flag
  v = ((v >> 1) | (v & 0x80)) & 0xff
  v == 0 ? r.set_zero_flag : r.clear_zero_flag
  r.clear_add_sub_flag
  r.clear_half_carry_flag

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