Class: Amaterasu::GameBoy::Cpu::Instructions::Base

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

Overview

Defines the mnemonic, bytes and logic for the NOP instruction.

Direct Known Subclasses

Adc, Add16, Add8, And, Call, CbBit, CbRes, CbRl, CbRlc, CbRr, CbRrc, CbSet, CbSla, CbSra, CbSrl, CbSwap, Cp, Daa, Dec, Di, Ei, Halt, Inc, Jp, Jr, Ld16, Ld8, Ldh, Misc, Nop, Or, Pop, Push, Ret, Rotate, Rst, Sbc, Stop, Sub, Xor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cpu:) ⇒ Base

Returns a new instance of Base.

Parameters:



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

def initialize(cpu:)
  @cpu = cpu
  @registers = cpu.registers
end

Instance Attribute Details

#mnemonicString (readonly)

Returns the value of attribute mnemonic.

Returns:

  • (String)


9
10
11
# File 'lib/amaterasu/game_boy/cpu/instructions/base.rb', line 9

def mnemonic
  @mnemonic
end

Instance Method Details

#executevoid

This method returns an undefined value.



16
17
18
# File 'lib/amaterasu/game_boy/cpu/instructions/base.rb', line 16

def execute
  @logic.call
end

#format_operand(operand) ⇒ String

Parameters:

  • (Symbol ?operand)

Returns:

  • (String)


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/amaterasu/game_boy/cpu/instructions/base.rb', line 22

def format_operand(operand)
  return ''      if operand.nil?
  return 'n8'    if operand == :imm8
  return 'n16'   if operand == :imm16
  return '[HL]'  if operand == :mem_hl
  return '[HL+]' if operand == :mem_hli
  return '[HL-]' if operand == :mem_hld
  return '[C]'   if operand == :mem_c
  return '[a8]'  if operand == :mem_unsig8

  operand.to_s.upcase
end