Class: GBRb::CPU::ConcatenatedRegister

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(high, low) ⇒ ConcatenatedRegister

Returns a new instance of ConcatenatedRegister.



5
6
7
8
9
# File 'lib/gbrb/cpu/concatenated_register.rb', line 5

def initialize high, low
  @high = high
  @low = low
  @bits = @high.bits + @low.bits
end

Instance Attribute Details

#bitsObject (readonly)

Returns the value of attribute bits.



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

def bits
  @bits
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
# File 'lib/gbrb/cpu/concatenated_register.rb', line 25

def == other
  other.read == read && other.bits == bits
end

#clearObject



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

def clear
  @high.clear
  @low.clear
end

#half_maskObject



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

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

#maskObject



29
30
31
# File 'lib/gbrb/cpu/concatenated_register.rb', line 29

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

#readObject



17
18
19
# File 'lib/gbrb/cpu/concatenated_register.rb', line 17

def read
  @low.read + (@high.read << @high.bits)
end

#store(value) ⇒ Object



11
12
13
14
15
# File 'lib/gbrb/cpu/concatenated_register.rb', line 11

def store value
  value &= mask - 1
  @high.store value >> @high.bits
  @low.store value << @low.bits >> @low.bits
end

#zero?Boolean

Returns:



21
22
23
# File 'lib/gbrb/cpu/concatenated_register.rb', line 21

def zero?
  @low.zero? && @high.zero?
end