Class: Amaterasu::GameBoy::Cpu::Instructions::Pop
- Defined in:
- lib/amaterasu/game_boy/cpu/instructions/pop.rb,
sig/akane/game_boy/cpu/instructions/pop.rbs
Overview
Holds the logic of all the POP instructions.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#build_logic(reg16) ⇒ Proc
Returns a Proc object to be executed by the CPU at runtime.
-
#initialize(cpu:, reg16:) ⇒ Pop
constructor
Creates a Pop instruction object with a mnemonic and logic to be executed.
Methods inherited from Base
Constructor Details
#initialize(cpu:, reg16:) ⇒ Pop
Creates a Pop instruction object with a mnemonic and logic to be executed.
10 11 12 13 14 15 |
# File 'lib/amaterasu/game_boy/cpu/instructions/pop.rb', line 10 def initialize(cpu:, reg16:) super(cpu:) @mnemonic = "POP #{format_operand(reg16)}" @logic = build_logic(reg16) end |
Instance Method Details
#build_logic(reg16) ⇒ Proc
Returns a Proc object to be executed by the CPU at runtime.
M-cycle 1: Fetches opcode. M-cycle 2: Gets the reg16 lsb from the stack. M-cycle 3: Gets the reg16 msb from the stack. Assigns the 16-bit value to a given reg16 (same cycle).
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/amaterasu/game_boy/cpu/instructions/pop.rb', line 25 def build_logic(reg16) case reg16 when :bc then -> { @registers.bc = @cpu.stack_pop } when :de then -> { @registers.de = @cpu.stack_pop } when :hl then -> { @registers.hl = @cpu.stack_pop } when :af then -> { @registers.af = @cpu.stack_pop } else raise ArgumentError, 'Unknown Pop reg16' end end |