Class: GBRb::CPU::RegisterEnsemble

Inherits:
Object
  • Object
show all
Defined in:
lib/gbrb/cpu/register_ensemble.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegisterEnsemble

Returns a new instance of RegisterEnsemble.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gbrb/cpu/register_ensemble.rb', line 10

def initialize
  @a = Register.new
  @b = Register.new
  @c = Register.new
  @d = Register.new
  @e = Register.new
  @h = Register.new
  @l = Register.new

  @f = FlagsRegister.new

  @pc = Register.new(0x0000, 16)
  @sp = Register.new(0x0000, 16)

  @m = Register.new
  @t = Register.new

  @bc = ConcatenatedRegister.new @b, @c
  @de = ConcatenatedRegister.new @d, @e
  @hl = ConcatenatedRegister.new @h, @l
  @af = ConcatenatedRegister.new @a, @f
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gbrb/cpu/register_ensemble.rb', line 41

def method_missing m, *a, &b
  case m
  when /\Aset_.*_flag\z/
    f.public_send m
  when /\Aclear_.*_flag\z/
    f.public_send m
  when /\A.*_flag\?\z/
    f.public_send m
  else
    super m, a, b
  end
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def a
  @a
end

#afObject

Returns the value of attribute af.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def af
  @af
end

#bObject

Returns the value of attribute b.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def b
  @b
end

#bcObject

Returns the value of attribute bc.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def bc
  @bc
end

#cObject

Returns the value of attribute c.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def c
  @c
end

#dObject

Returns the value of attribute d.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def d
  @d
end

#deObject

Returns the value of attribute de.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def de
  @de
end

#eObject

Returns the value of attribute e.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def e
  @e
end

#fObject

Returns the value of attribute f.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def f
  @f
end

#hObject

Returns the value of attribute h.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def h
  @h
end

#hlObject

Returns the value of attribute hl.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def hl
  @hl
end

#lObject

Returns the value of attribute l.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def l
  @l
end

#mObject

Returns the value of attribute m.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def m
  @m
end

#pcObject

Returns the value of attribute pc.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def pc
  @pc
end

#spObject

Returns the value of attribute sp.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def sp
  @sp
end

#tObject

Returns the value of attribute t.



8
9
10
# File 'lib/gbrb/cpu/register_ensemble.rb', line 8

def t
  @t
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
# File 'lib/gbrb/cpu/register_ensemble.rb', line 37

def == other
  register_list.inject(true){|result, el| result && public_send(el) == other.public_send(el)}
end

#each(&block) ⇒ Object



33
34
35
# File 'lib/gbrb/cpu/register_ensemble.rb', line 33

def each &block
  [@pc, @sp, @a, @b, @c, @d, @e, @h, @l, @f].each &block
end