Class: Amaterasu::GameBoy::Cpu::Instructions::CbSrl
- Includes:
- Utils::BitOps
- Defined in:
- lib/amaterasu/game_boy/cpu/instructions/cb_srl.rb,
sig/akane/game_boy/cpu/instructions/cb_srl.rbs
Overview
Holds the logic of all the SRL instructions.
- SRL r8
- SRL [HL]
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #build_logic(target) ⇒ Proc
-
#initialize(cpu:, target:) ⇒ CbSrl
constructor
A new instance of CbSrl.
-
#srl_mem_hl ⇒ void
Takes 2 extra cycles due to the Bus read and write operations.
-
#srl_reg8(reg8) ⇒ void
Shift Right Logically.
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:) ⇒ CbSrl
Returns a new instance of CbSrl.
14 15 16 17 18 19 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_srl.rb', line 14 def initialize(cpu:, target:) super(cpu:) @mnemonic = "SRL #{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_srl.rb', line 23 def build_logic(target) case target when :b then -> { @registers.b = srl_reg8(@registers.b) } when :c then -> { @registers.c = srl_reg8(@registers.c) } when :d then -> { @registers.d = srl_reg8(@registers.d) } when :e then -> { @registers.e = srl_reg8(@registers.e) } when :h then -> { @registers.h = srl_reg8(@registers.h) } when :l then -> { @registers.l = srl_reg8(@registers.l) } when :mem_hl then -> { srl_mem_hl } when :a then -> { @registers.a = srl_reg8(@registers.a) } else raise ArgumentError, 'Unknown CbSrl target' end end |
#srl_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 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_srl.rb', line 54 def srl_mem_hl byte = @cpu.bus_read(address: @registers.hl) old_bit0 = bit(byte, 0) result = byte >> 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 |
#srl_reg8(reg8) ⇒ void
This method returns an undefined value.
Shift Right Logically.
0 -> [7][6][5][4][3][2][1][0] -> C
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/amaterasu/game_boy/cpu/instructions/cb_srl.rb', line 42 def srl_reg8(reg8) old_bit0 = bit(reg8, 0) result = reg8 >> 1 @registers.clear_flags @registers.z_flag = result.nobits?(0xFF) @registers.c_flag = old_bit0 == 1 result end |