Class: Amaterasu::GameBoy::Cpu::Instructions::Rst

Inherits:
Base
  • Object
show all
Defined in:
lib/amaterasu/game_boy/cpu/instructions/rst.rb,
sig/akane/game_boy/cpu/instructions/rst.rbs

Overview

Holds the logic of all the RST instructions.

Instance Attribute Summary

Attributes inherited from Base

#mnemonic

Instance Method Summary collapse

Methods inherited from Base

#execute, #format_operand

Constructor Details

#initialize(cpu:, vector:) ⇒ Rst

Creates a Call instruction object with a mnemonic and logic to be executed.

Parameters:

  • cpu: (Cpu)
  • vector: (Integer)


10
11
12
13
14
15
# File 'lib/amaterasu/game_boy/cpu/instructions/rst.rb', line 10

def initialize(cpu:, vector:)
  super(cpu:)

  @mnemonic = "RST $#{format('%02X', vector)}"
  @logic    = -> { rst(vector) }
end

Instance Method Details

#rst(vector) ⇒ void

This method returns an undefined value.

This is essentially a CALL, but jumps to a fixed address vector.

M-cycle 1: Fetches opcode. M-cycle 2: Stores the msb of the PC into the Stack. M-cycle 3: Stores the lsb of the PC into the Stack. M-cycle 4: Jumps to a fixed address vector.

Parameters:

  • vector (Integer)


25
26
27
28
# File 'lib/amaterasu/game_boy/cpu/instructions/rst.rb', line 25

def rst(vector)
  @cpu.stack_push(value: @registers.pc)
  @cpu.jump_to(address: vector)
end