Class: GBRb::CPU::Register
- Inherits:
-
Object
- Object
- GBRb::CPU::Register
- Defined in:
- lib/gbrb/cpu/register.rb
Direct Known Subclasses
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(value = 0x00, bits = 8) ⇒ Register
constructor
A new instance of Register.
- #mask ⇒ Object
- #read ⇒ Object
- #store(value) ⇒ Object
- #zero? ⇒ Boolean
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
#bits ⇒ Object (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 |
#clear ⇒ Object
22 23 24 |
# File 'lib/gbrb/cpu/register.rb', line 22 def clear store 0x00 end |
#half_mask ⇒ Object
38 39 40 |
# File 'lib/gbrb/cpu/register.rb', line 38 def half_mask @half_mask ||= 0x10 ** (@bits/8) end |
#mask ⇒ Object
34 35 36 |
# File 'lib/gbrb/cpu/register.rb', line 34 def mask @mask ||= 0x10 ** (@bits/4 ) end |
#read ⇒ Object
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
26 27 28 |
# File 'lib/gbrb/cpu/register.rb', line 26 def zero? @value.zero? end |