Class: D64::Sector

Inherits:
Object
  • Object
show all
Defined in:
lib/d64/sector.rb

Direct Known Subclasses

BlockMap

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image, block, bytes) ⇒ Sector

Returns a new instance of Sector.



5
6
7
8
9
# File 'lib/d64/sector.rb', line 5

def initialize(image, block, bytes)
  @image = image
  @block = block
  @bytes = bytes
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/d64/sector.rb', line 3

def block
  @block
end

#bytesObject (readonly)

Returns the value of attribute bytes.



3
4
5
# File 'lib/d64/sector.rb', line 3

def bytes
  @bytes
end

#imageObject (readonly)

Returns the value of attribute image.



3
4
5
# File 'lib/d64/sector.rb', line 3

def image
  @image
end

Instance Method Details

#chainObject



28
29
30
31
32
33
34
# File 'lib/d64/sector.rb', line 28

def chain
  list = [self]
  while list.last.next
    list << list.last.next
  end
  list
end

#commitObject



54
55
56
# File 'lib/d64/sector.rb', line 54

def commit
  image.commit_sector(self)
end

#copy_content_from(other, opts = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/d64/sector.rb', line 36

def copy_content_from(other, opts = {})
  puts "Copying content from #{other.name_pos} to #{name_pos}." if ENV['DEBUG']
  first = (opts[:include_link] ? 0 : 2)
  if block.track == 18 && block.sector == 0 && !opts[:include_bam]
    @bytes[first..3] = other.bytes[first..3]
    @bytes[0x90..-1] = other.bytes[0x90..-1]
  else
    @bytes[first..-1] = other.bytes[first..-1]
  end
  commit
end

#dumpObject



58
59
60
61
62
63
64
# File 'lib/d64/sector.rb', line 58

def dump
  puts 8.times.map { |i|
    ('%05X  %s ' % [Image.offset(block) + 32 * i, pos]) <<
      (' %02X' * 32 % @bytes[32 * i, 32]) <<
      (' %32s' % bytes_string(@bytes[32 * i, 32]))
  }.join("\n")
end


48
49
50
51
52
# File 'lib/d64/sector.rb', line 48

def link_to(other, opts = {})
  puts "Linking #{name_pos} to #{other.name_pos}." if ENV['DEBUG']
  @bytes[0, 2] = [other.block.track, other.block.sector]
  commit
end

#name_posObject



19
20
21
# File 'lib/d64/sector.rb', line 19

def name_pos
  '[%s %02d:%02d]' % [image.name, block.track, block.sector]
end

#nextObject



23
24
25
26
# File 'lib/d64/sector.rb', line 23

def next
  tn, sn = @bytes[0, 2]
  image.sector([tn, sn]) if tn > 0
end

#posObject



15
16
17
# File 'lib/d64/sector.rb', line 15

def pos
  '[%02d:%02d]' % [block.track, block.sector]
end

#to_sObject



11
12
13
# File 'lib/d64/sector.rb', line 11

def to_s
  "<D64::Sector:#{object_id.to_s(16)} t=#{@block.track} s=#{@block.sector}>"
end