Class: Amaterasu::GameBoy::Cpu::Instructions::CbRes
- Includes:
- Utils::BitOps
- Defined in:
- lib/amaterasu/game_boy/cpu/instructions/cb_res.rb,
sig/akane/game_boy/cpu/instructions/cb_res.rbs
Overview
Holds the logic of all the RES instructions.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#build_logic(bit_pos, target) ⇒ Proc
Logic to be executed by the Cpu.
-
#initialize(cpu:, bit_pos:, target:) ⇒ CbRes
constructor
Creates a new CbRes object containing the mnemonic (String) and logic (Proc).
Methods included from Utils::BitOps
bit, clear_bit, #self?.bit, #self?.clear_bit, #self?.set_bit, set_bit
Methods inherited from Base
Constructor Details
#initialize(cpu:, bit_pos:, target:) ⇒ CbRes
Creates a new CbRes object containing the mnemonic (String) and logic (Proc).
12 13 14 15 16 17 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_res.rb', line 12 def initialize(cpu:, bit_pos:, target:) super(cpu:) @mnemonic = "RES #{bit_pos}, #{format_operand(target)}" @logic = build_logic(bit_pos, target) end |
Instance Method Details
#build_logic(bit_pos, target) ⇒ Proc
Returns Logic to be executed by the Cpu.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_res.rb', line 26 def build_logic(bit_pos, target) case target when :a then -> { @registers.a = clear_bit(@registers.a, bit_pos) } when :b then -> { @registers.b = clear_bit(@registers.b, bit_pos) } when :c then -> { @registers.c = clear_bit(@registers.c, bit_pos) } when :d then -> { @registers.d = clear_bit(@registers.d, bit_pos) } when :e then -> { @registers.e = clear_bit(@registers.e, bit_pos) } when :h then -> { @registers.h = clear_bit(@registers.h, bit_pos) } when :l then -> { @registers.l = clear_bit(@registers.l, bit_pos) } when :mem_hl lambda do value_at_mem_hl = @cpu.bus_read(address: @registers.hl) result = clear_bit(value_at_mem_hl, bit_pos) @cpu.bus_write(address: @registers.hl, value: result) end else raise ArgumentError, 'Unknown CbRes target' end end |