Class: Amaterasu::GameBoy::Cpu::Instructions::Misc

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

Overview

Holds the logic for CPL, SCF and CCF instructions.

Instance Attribute Summary

Attributes inherited from Base

#mnemonic

Instance Method Summary collapse

Methods inherited from Base

#execute, #format_operand

Constructor Details

#initialize(cpu:, operation:) ⇒ Misc

Returns a new instance of Misc.

Parameters:

  • cpu: (Cpu)
  • operation: (Symbol)


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

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

  @mnemonic = format_operand(operation)
  @logic    = build_logic(operation)
end

Instance Method Details

#build_logic(operation) ⇒ Proc

Parameters:

  • operation (Symbol)

Returns:

  • (Proc)


18
19
20
21
22
23
24
25
26
# File 'lib/amaterasu/game_boy/cpu/instructions/misc.rb', line 18

def build_logic(operation)
  case operation
  when :cpl then -> { cpl }
  when :scf then -> { scf }
  when :ccf then -> { ccf }
  else
    raise ArgumentError, 'Unknown Misc operation'
  end
end

#ccfvoid

This method returns an undefined value.

Complement the Carry flag.



36
37
38
39
40
# File 'lib/amaterasu/game_boy/cpu/instructions/misc.rb', line 36

def ccf
  @registers.n_flag = false
  @registers.h_flag = false
  @registers.c_flag = @registers.c_flag.zero?
end

#cplvoid

This method returns an undefined value.

Complement the value from the A register.



43
44
45
46
47
48
# File 'lib/amaterasu/game_boy/cpu/instructions/misc.rb', line 43

def cpl
  @registers.a = ~@registers.a

  @registers.n_flag = true
  @registers.h_flag = true
end

#scfvoid

This method returns an undefined value.

Set Carry flag.



29
30
31
32
33
# File 'lib/amaterasu/game_boy/cpu/instructions/misc.rb', line 29

def scf
  @registers.n_flag = false
  @registers.h_flag = false
  @registers.c_flag = true
end