Class: GBRb::CPU::Register

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

Direct Known Subclasses

FlagsRegister

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = 0x00, bits = 8) ⇒ Register

Returns a new instance of Register.



5
6
7
8
9
10
11
12
# File 'lib/gbrb/cpu/register.rb', line 5

def initialize value=0x00, bits=8
  if bits == 8 or bits == 16
    @bits = bits
  else
    raise ArgumentError
  end
  store value
end

Instance Attribute Details

#bitsObject (readonly)

Returns the value of attribute bits.



42
43
44
# File 'lib/gbrb/cpu/register.rb', line 42

def bits
  @bits
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
# File 'lib/gbrb/cpu/register.rb', line 30

def == other
  other.read == @value and other.bits == bits
end

#clearObject



22
23
24
# File 'lib/gbrb/cpu/register.rb', line 22

def clear
  store 0x00
end

#half_maskObject



38
39
40
# File 'lib/gbrb/cpu/register.rb', line 38

def half_mask
  @half_mask ||= 0x10 ** (@bits/8)
end

#maskObject



34
35
36
# File 'lib/gbrb/cpu/register.rb', line 34

def mask
  @mask ||= 0x10 ** (@bits/4 )
end

#readObject



14
15
16
# File 'lib/gbrb/cpu/register.rb', line 14

def read
  @value
end

#store(value) ⇒ Object



18
19
20
# File 'lib/gbrb/cpu/register.rb', line 18

def store value
  @value = value & (mask - 1)
end

#zero?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/gbrb/cpu/register.rb', line 26

def zero?
  @value.zero?
end