Class: GBRb::InstructionSet::Arithmetic
- Inherits:
-
Instruction
- Object
- Instruction
- GBRb::InstructionSet::Arithmetic
- Defined in:
- lib/gbrb/instruction_set/arithmetic.rb
Instance Attribute Summary
Attributes inherited from Instruction
Instance Method Summary collapse
- #call(r, mem, right_value) ⇒ Object
- #carry?(left, right, mask) ⇒ Boolean
-
#initialize(target, m, t, indirect, immediates = 0) ⇒ Arithmetic
constructor
A new instance of Arithmetic.
Methods inherited from Instruction
Constructor Details
#initialize(target, m, t, indirect, immediates = 0) ⇒ Arithmetic
Returns a new instance of Arithmetic.
5 6 7 8 9 |
# File 'lib/gbrb/instruction_set/arithmetic.rb', line 5 def initialize target, m, t, indirect, immediates=0 super m, t, immediates @target = target @indirect = indirect end |
Instance Method Details
#call(r, mem, right_value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gbrb/instruction_set/arithmetic.rb', line 15 def call r, mem, right_value right_value ||= r.public_send(@target.to_sym).read right_value = mem.read_byte(right_value) if @indirect a_value = r.a.read if carry? a_value, right_value, r.a.half_mask r.set_half_carry_flag else r.clear_half_carry_flag end if carry? a_value, right_value, r.a.mask r.set_carry_flag else r.clear_carry_flag end a_value = a_value.public_send(@op, right_value) & 0xff r.a.store a_value unless @skip_store a_value == 0x00 ? r.set_zero_flag : r.clear_zero_flag end |
#carry?(left, right, mask) ⇒ Boolean
11 12 13 |
# File 'lib/gbrb/instruction_set/arithmetic.rb', line 11 def carry? left, right, mask (mask-1 & left).public_send(@op, mask-1 & right) & mask == mask end |