Module: Badline::Addressable

Includes:
IntegerHelper
Included in:
AddressBus, CIA, Memory, SID, VIC, VIC::Bank
Defined in:
lib/badline/addressable.rb

Defined Under Namespace

Classes: OutOfBoundsError, ReadOnlyMemoryError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IntegerHelper

#bcd, #bcd_to_i, #format16, #format8, #high_byte, #low_byte, #signed_int8, #uint16

Instance Attribute Details

#endObject (readonly)

Returns the value of attribute end.



10
11
12
# File 'lib/badline/addressable.rb', line 10

def end
  @end
end

#lengthObject (readonly)

Returns the value of attribute length.



10
11
12
# File 'lib/badline/addressable.rb', line 10

def length
  @length
end

#startObject (readonly)

Returns the value of attribute start.



10
11
12
# File 'lib/badline/addressable.rb', line 10

def start
  @start
end

Instance Method Details

#[](addr) ⇒ Object



44
45
46
# File 'lib/badline/addressable.rb', line 44

def [](addr)
  peek(addr)
end

#[]=(addr, value) ⇒ Object



48
49
50
# File 'lib/badline/addressable.rb', line 48

def []=(addr, value)
  poke(addr, value)
end

#addressable_at(start = 0, length: 2**16) ⇒ Object



12
13
14
15
16
# File 'lib/badline/addressable.rb', line 12

def addressable_at(start = 0, length: 2**16)
  @start = start
  @length = length
  @end = start + length
end

#in_range?(addr) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/badline/addressable.rb', line 22

def in_range?(addr)
  addr >= @start && addr < @end
end

#peek(_addr) ⇒ Object

Raises:

  • (NoMethodError)


26
27
28
# File 'lib/badline/addressable.rb', line 26

def peek(_addr)
  raise NoMethodError
end

#peek16(addr) ⇒ Object



30
31
32
# File 'lib/badline/addressable.rb', line 30

def peek16(addr)
  uint16(peek(addr), peek(addr + 1))
end

#poke(_addr, _value) ⇒ Object

Raises:

  • (NoMethodError)


34
35
36
# File 'lib/badline/addressable.rb', line 34

def poke(_addr, _value)
  raise NoMethodError
end

#poke16(addr, value) ⇒ Object



38
39
40
41
42
# File 'lib/badline/addressable.rb', line 38

def poke16(addr, value)
  poke(addr, low_byte(value))
  poke(addr + 1, high_byte(value))
  value
end

#rangeObject



18
19
20
# File 'lib/badline/addressable.rb', line 18

def range
  start..(start + (length - 1))
end