Class: Amaterasu::GameBoy::Cpu::Instructions::Xor
- Defined in:
- lib/amaterasu/game_boy/cpu/instructions/xor.rb,
sig/akane/game_boy/cpu/instructions/xor.rbs
Overview
Handles the logic related to all possible XOR instructions
- XOR A, r8
- XOR A, [HL]
- XOR A, n8
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #build_logic(source) ⇒ Proc
- #define_mnemonic(source) ⇒ String
-
#initialize(cpu:, source:) ⇒ Xor
constructor
A new instance of Xor.
- #xor_a(value) ⇒ void
Methods inherited from Base
Constructor Details
#initialize(cpu:, source:) ⇒ Xor
Returns a new instance of Xor.
15 16 17 18 19 20 |
# File 'lib/amaterasu/game_boy/cpu/instructions/xor.rb', line 15 def initialize(cpu:, source:) super(cpu:) @mnemonic = define_mnemonic(source) @logic = build_logic(source) end |
Instance Method Details
#build_logic(source) ⇒ Proc
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/amaterasu/game_boy/cpu/instructions/xor.rb', line 32 def build_logic(source) case source when :a then -> { xor_a(@registers.a) } when :b then -> { xor_a(@registers.b) } when :c then -> { xor_a(@registers.c) } when :d then -> { xor_a(@registers.d) } when :e then -> { xor_a(@registers.e) } when :h then -> { xor_a(@registers.h) } when :l then -> { xor_a(@registers.l) } when :mem_hl then -> { xor_a(@cpu.bus_read(address: @registers.hl)) } when :imm8 then -> { xor_a(@cpu.fetch_next_byte) } else raise ArgumentError, 'Unknown Xor source' end end |
#define_mnemonic(source) ⇒ String
24 25 26 27 28 29 30 |
# File 'lib/amaterasu/game_boy/cpu/instructions/xor.rb', line 24 def define_mnemonic(source) case source when :mem_hl then 'XOR A, [HL]' when :imm8 then 'XOR A, n8' else "XOR A, #{source.upcase}" end end |
#xor_a(value) ⇒ void
This method returns an undefined value.
48 49 50 51 52 53 54 55 |
# File 'lib/amaterasu/game_boy/cpu/instructions/xor.rb', line 48 def xor_a(value) result = @registers.a ^ value @registers.clear_flags @registers.z_flag = result.nobits?(0xFF) @registers.a = result end |