Class: Amaterasu::GameBoy::Cpu::Instructions::Push
- Defined in:
- lib/amaterasu/game_boy/cpu/instructions/push.rb,
sig/akane/game_boy/cpu/instructions/push.rbs
Overview
Holds the logic of all the PUSH 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:) ⇒ Push
constructor
Creates a Push instruction object with a mnemonic and logic to be executed.
-
#push(reg16) ⇒ void
M-cycle 1: Fetches opcode.
Methods inherited from Base
Constructor Details
#initialize(cpu:, reg16:) ⇒ Push
Creates a Push instruction object with a mnemonic and logic to be executed.
10 11 12 13 14 15 |
# File 'lib/amaterasu/game_boy/cpu/instructions/push.rb', line 10 def initialize(cpu:, reg16:) super(cpu:) @mnemonic = "PUSH #{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.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/amaterasu/game_boy/cpu/instructions/push.rb', line 20 def build_logic(reg16) case reg16 when :bc then -> { push(@registers.bc) } when :de then -> { push(@registers.de) } when :hl then -> { push(@registers.hl) } when :af then -> { push(@registers.af) } else raise ArgumentError, 'Unknown Push reg16' end end |
#push(reg16) ⇒ void
This method returns an undefined value.
M-cycle 1: Fetches opcode. M-cycle 2: Internal processing (dead cycle). M-cycle 3: Writes msb from reg16 into the stack. M-cycle 4: Writes lsb from reg16 into the stack.
35 36 37 38 |
# File 'lib/amaterasu/game_boy/cpu/instructions/push.rb', line 35 def push(reg16) @cpu.internal_processing @cpu.stack_push(value: reg16) end |