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