Class: Amaterasu::GameBoy::Cpu::Instructions::CbBit
- Includes:
- Utils::BitOps
- Defined in:
- lib/amaterasu/game_boy/cpu/instructions/cb_bit.rb,
sig/akane/game_boy/cpu/instructions/cb_bit.rbs
Overview
Holds the logic of all the BIT instructions.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#bit_test(bit_pos, target_value) ⇒ void
Checks the bit value from a given target at a given position [0-7].
- #build_logic(bit_pos, target) ⇒ Proc
-
#initialize(cpu:, bit_pos:, target:) ⇒ CbBit
constructor
A new instance of CbBit.
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:) ⇒ CbBit
Returns a new instance of CbBit.
11 12 13 14 15 16 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_bit.rb', line 11 def initialize(cpu:, bit_pos:, target:) super(cpu:) @mnemonic = "BIT #{bit_pos}, #{format_operand(target)}" @logic = build_logic(bit_pos, target) end |
Instance Method Details
#bit_test(bit_pos, target_value) ⇒ void
This method returns an undefined value.
Checks the bit value from a given target at a given position [0-7].
- Sets the zero flag if bit tested is 0, otherwise clears the flag.
- Subtraction flag is always cleared.
- Half Carry flag is always set.
- Carry flag is untouched.
41 42 43 44 45 46 47 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_bit.rb', line 41 def bit_test(bit_pos, target_value) bit_value = bit(target_value, bit_pos) @registers.z_flag = bit_value.zero? @registers.n_flag = false @registers.h_flag = true end |
#build_logic(bit_pos, target) ⇒ Proc
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_bit.rb', line 20 def build_logic(bit_pos, target) case target when :b then -> { bit_test(bit_pos, @registers.b) } when :c then -> { bit_test(bit_pos, @registers.c) } when :d then -> { bit_test(bit_pos, @registers.d) } when :e then -> { bit_test(bit_pos, @registers.e) } when :h then -> { bit_test(bit_pos, @registers.h) } when :l then -> { bit_test(bit_pos, @registers.l) } when :mem_hl then -> { bit_test(bit_pos, @cpu.bus_read(address: @registers.hl)) } when :a then -> { bit_test(bit_pos, @registers.a) } else raise ArgumentError, 'Unknown CbBit target' end end |