Class: Amaterasu::GameBoy::Cpu::Instructions::CbRr
- Includes:
- Utils::BitOps
- Defined in:
- lib/amaterasu/game_boy/cpu/instructions/cb_rr.rb,
sig/akane/game_boy/cpu/instructions/cb_rr.rbs
Overview
Holds the logic of all the RR (Rotate Right Through Carry) instructions.
- RR r8
- RR [HL]
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #build_logic(target) ⇒ Proc
-
#initialize(cpu:, target:) ⇒ CbRr
constructor
A new instance of CbRr.
-
#rr_mem_hl ⇒ void
Takes 2 extra cycles due to the Bus read and write operations.
-
#rr_reg8(reg8_value) ⇒ void
[C] -> [7][6][5][4][3][2][1][0] -> [C] [C][7][6][5][4][3][2][1] -> [0].
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:, target:) ⇒ CbRr
14 15 16 17 18 19 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_rr.rb', line 14 def initialize(cpu:, target:) super(cpu:) @mnemonic = "RR #{format_operand(target)}" @logic = build_logic(target) end |
Instance Method Details
#build_logic(target) ⇒ Proc
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_rr.rb', line 23 def build_logic(target) case target when :b then -> { @registers.b = rr_reg8(@registers.b) } when :c then -> { @registers.c = rr_reg8(@registers.c) } when :d then -> { @registers.d = rr_reg8(@registers.d) } when :e then -> { @registers.e = rr_reg8(@registers.e) } when :h then -> { @registers.h = rr_reg8(@registers.h) } when :l then -> { @registers.l = rr_reg8(@registers.l) } when :mem_hl then -> { rr_mem_hl } when :a then -> { @registers.a = rr_reg8(@registers.a) } else raise ArgumentError, 'Unknown CbRr target' end end |
#rr_mem_hl ⇒ void
This method returns an undefined value.
Takes 2 extra cycles due to the Bus read and write operations.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_rr.rb', line 54 def rr_mem_hl value_at_mem_hl = @cpu.bus_read(address: @registers.hl) carry_in = @registers.c_flag old_bit0 = bit(value_at_mem_hl, 0) result = (carry_in << 7) | (value_at_mem_hl >> 1) @registers.clear_flags @registers.z_flag = result.nobits?(0xFF) @registers.c_flag = old_bit0 == 1 @cpu.bus_write(address: @registers.hl, value: result) end |
#rr_reg8(reg8_value) ⇒ void
This method returns an undefined value.
[C] -> [7][6][5][4][3][2][1][0] -> [C] [C][7][6][5][4][3][2][1] -> [0]
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_rr.rb', line 41 def rr_reg8(reg8_value) carry_in = @registers.c_flag old_bit0 = bit(reg8_value, 0) result = (carry_in << 7) | (reg8_value >> 1) @registers.clear_flags @registers.z_flag = result.nobits?(0xFF) @registers.c_flag = old_bit0 == 1 result end |