Class: GBRb::InstructionSet::Ldh

Inherits:
Instruction show all
Defined in:
lib/gbrb/instruction_set/ld.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(destination, target, indirect_dest, indirect_target, m = 3, t = 12, immediates = 1) ⇒ Ldh

Returns a new instance of Ldh.



202
203
204
205
206
207
208
209
210
# File 'lib/gbrb/instruction_set/ld.rb', line 202

def initialize destination, target, indirect_dest, indirect_target, m=3, t=12, immediates=1
  super m, t, immediates

  @destination = destination
  @target = target
  @indirect_dest = indirect_dest
  @indirect_target = indirect_target
  @offset = 0xff00
end

Instance Method Details

#call(r, mem, address) ⇒ Object



212
213
214
215
216
217
218
219
220
# File 'lib/gbrb/instruction_set/ld.rb', line 212

def call r, mem, address
  if @indirect_dest
    value = r.public_send(@target.to_sym).read
    mem.write_byte address + @offset, value
  elsif @indirect_target
    value = mem.read_byte address + @offset
    r.public_send(@destination.to_sym).store value
  end
end