Class: GBRb::CPU::Ld
- Inherits:
-
Instruction
- Object
- Instruction
- GBRb::CPU::Ld
- Defined in:
- lib/gbrb/cpu/instruction.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Instruction
Instance Method Summary collapse
- #call(r, mem, v = nil) ⇒ Object
-
#initialize(destination, target, m = 1, t = 4, indirect_dest = false, indirect_target = false, immediates = 0, offset = 0x00) ⇒ Ld
constructor
A new instance of Ld.
Methods inherited from Instruction
Constructor Details
#initialize(destination, target, m = 1, t = 4, indirect_dest = false, indirect_target = false, immediates = 0, offset = 0x00) ⇒ Ld
Returns a new instance of Ld.
123 124 125 126 127 128 129 130 131 |
# File 'lib/gbrb/cpu/instruction.rb', line 123 def initialize destination, target, m=1, t=4, indirect_dest=false, indirect_target=false, immediates=0, offset=0x00 super m, t, immediates @destination = destination @target = target @indirect_dest = indirect_dest @indirect_target = indirect_target @offset = offset end |
Instance Method Details
#call(r, mem, v = nil) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/gbrb/cpu/instruction.rb', line 133 def call r, mem, v=nil if not v v = r.public_send(@target.to_sym).read end if @indirect_target v = mem.read_byte(v + @offset) target_reg = r.public_send(@destination.to_sym) if @indirect_target == :increment target_reg.store target_reg.read + 1 elsif @indirect_target == :decrement target_reg.store target_reg.read - 1 end end if @indirect_dest if @indirect_dest == :immediate if @target.to_s.chars.length == 2 mem.write_word(v + @offset, r.public_send(@target.to_sym).read) else mem.write_byte(v + @offset, r.public_send(@target.to_sym).read) end else reg = r.public_send(@destination.to_sym) mem.write_byte(reg.read + @offset, v) if @indirect_dest == :increment reg.store reg.read + 1 elsif @indirect_dest == :decrement reg.store reg.read - 1 end end else r.public_send(@destination.to_sym).store v end end |