Class: D64::Sector
- Inherits:
-
Object
- Object
- D64::Sector
- Defined in:
- lib/d64/sector.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
Instance Method Summary collapse
- #chain ⇒ Object
- #commit ⇒ Object
- #copy_content_from(other, opts = {}) ⇒ Object
- #dump ⇒ Object
-
#initialize(image, block, bytes) ⇒ Sector
constructor
A new instance of Sector.
- #link_to(other, opts = {}) ⇒ Object
- #name_pos ⇒ Object
- #next ⇒ Object
- #pos ⇒ Object
- #to_s ⇒ Object
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
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/d64/sector.rb', line 3 def block @block end |
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
3 4 5 |
# File 'lib/d64/sector.rb', line 3 def bytes @bytes end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
3 4 5 |
# File 'lib/d64/sector.rb', line 3 def image @image end |
Instance Method Details
#chain ⇒ Object
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 |
#commit ⇒ Object
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 |
#dump ⇒ Object
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 |
#link_to(other, opts = {}) ⇒ Object
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_pos ⇒ Object
19 20 21 |
# File 'lib/d64/sector.rb', line 19 def name_pos '[%s %02d:%02d]' % [image.name, block.track, block.sector] end |
#next ⇒ Object
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 |
#pos ⇒ Object
15 16 17 |
# File 'lib/d64/sector.rb', line 15 def pos '[%02d:%02d]' % [block.track, block.sector] end |
#to_s ⇒ Object
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 |