Class: GBRb::CPU::ConcatenatedRegister
- Inherits:
-
Object
- Object
- GBRb::CPU::ConcatenatedRegister
- Defined in:
- lib/gbrb/cpu/concatenated_register.rb
Instance Attribute Summary collapse
-
#bits ⇒ Object
readonly
Returns the value of attribute bits.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #clear ⇒ Object
- #half_mask ⇒ Object
-
#initialize(high, low) ⇒ ConcatenatedRegister
constructor
A new instance of ConcatenatedRegister.
- #mask ⇒ Object
- #read ⇒ Object
- #store(value) ⇒ Object
- #zero? ⇒ Boolean
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
#bits ⇒ Object (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 |
#clear ⇒ Object
37 38 39 40 |
# File 'lib/gbrb/cpu/concatenated_register.rb', line 37 def clear @high.clear @low.clear end |
#half_mask ⇒ Object
33 34 35 |
# File 'lib/gbrb/cpu/concatenated_register.rb', line 33 def half_mask @half_mask ||= 0x10 ** (@bits/8) end |
#mask ⇒ Object
29 30 31 |
# File 'lib/gbrb/cpu/concatenated_register.rb', line 29 def mask @mask ||= 0x10 ** (@bits/4) end |
#read ⇒ Object
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
21 22 23 |
# File 'lib/gbrb/cpu/concatenated_register.rb', line 21 def zero? @low.zero? && @high.zero? end |