Class: Amaterasu::GameBoy::Cpu::Instructions::Or
- Defined in:
- lib/amaterasu/game_boy/cpu/instructions/or.rb,
sig/akane/game_boy/cpu/instructions/or.rbs
Overview
Handles the logic related to all possible OR instructions
- OR A, r8
- OR A, [HL]
- OR A, n8
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#build_logic(source) ⇒ Proc
Builds the logic for all OR instructions.
-
#initialize(cpu:, source:) ⇒ Or
constructor
A new instance of Or.
-
#or_a(value) ⇒ void
Performs a Bitwise OR between a given value and the A register.
Methods inherited from Base
Constructor Details
#initialize(cpu:, source:) ⇒ Or
Returns a new instance of Or.
15 16 17 18 19 20 |
# File 'lib/amaterasu/game_boy/cpu/instructions/or.rb', line 15 def initialize(cpu:, source:) super(cpu:) @mnemonic = "OR A, #{source}" @logic = build_logic(source) end |
Instance Method Details
#build_logic(source) ⇒ Proc
Builds the logic for all OR instructions. Returns a lambda object to be called by the CPU.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/amaterasu/game_boy/cpu/instructions/or.rb', line 26 def build_logic(source) case source when :a then -> { or_a(@registers.a) } when :b then -> { or_a(@registers.b) } when :c then -> { or_a(@registers.c) } when :d then -> { or_a(@registers.d) } when :e then -> { or_a(@registers.e) } when :h then -> { or_a(@registers.h) } when :l then -> { or_a(@registers.l) } when :mem_hl then -> { or_a(@cpu.bus_read(address: @registers.hl)) } when :imm8 then -> { or_a(@cpu.fetch_next_byte) } else raise ArgumentError, 'Unknown Or source' end end |
#or_a(value) ⇒ void
This method returns an undefined value.
Performs a Bitwise OR between a given value and the A register.
44 45 46 47 48 49 50 51 |
# File 'lib/amaterasu/game_boy/cpu/instructions/or.rb', line 44 def or_a(value) result = @registers.a | value @registers.clear_flags @registers.z_flag = result.nobits?(0xFF) @registers.a = result end |