Class: A2Dsk

Inherits:
ImageFormat show all
Defined in:
lib/image_formats/A2Dsk.rb

Overview

A2 DSK with “physical” ordering

Direct Known Subclasses

A2DskDosOrder, A2DskPhysicalOrder

Instance Attribute Summary

Attributes inherited from ImageFormat

#file_bytes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ImageFormat

all_image_formats, all_possible_extensions, code_for_tests, #compatability_score, #end_track, #host_system, #initialize, is_valid_image_if, possible_file_systems, #start_track, #to_s, #track_list

Methods included from SubclassTracking

extended

Constructor Details

This class inherits a constructor from ImageFormat

Class Method Details

.host_systemObject



16
17
18
# File 'lib/image_formats/A2Dsk.rb', line 16

def A2Dsk.host_system
    Apple2
end

.interleaveObject

to be overriden in each subclass with a table showing what order logical sectors are stored



21
22
23
# File 'lib/image_formats/A2Dsk.rb', line 21

def A2Dsk.interleave
  nil
end

.possible_extensionsObject



12
13
14
# File 'lib/image_formats/A2Dsk.rb', line 12

def A2Dsk.possible_extensions
    ['.dsk','.do','.po']
end

Instance Method Details

#get_sector(track, sector) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/image_formats/A2Dsk.rb', line 33

def get_sector(track,sector)
  return nil if self.class.interleave.nil?
  return nil unless sector.between?(0,0x0F)
  physical_sector=self.class.interleave[sector]
  start_byte=track*16*256+physical_sector*256
  file_bytes[start_byte,256]
end

#sectors_in_track(track_no) ⇒ Object



25
26
27
# File 'lib/image_formats/A2Dsk.rb', line 25

def sectors_in_track(track_no)
  (0..0x0f).collect
end

#set_sector(track, sector, sector_contents) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/image_formats/A2Dsk.rb', line 41

def set_sector(track,sector,sector_contents)
  raise "attempt to set_sector failed as no interleave defined" if self.class.interleave.nil?
  raise "invalid sector number " unless sector.between?(0,0x0F)
  physical_sector=self.class.interleave[sector]
  padded_sector_contents=(sector_contents+("\000"*256))[0,256]
  start_byte=track*16*256+physical_sector*256
  file_bytes[start_byte,256]=padded_sector_contents
end

#track_countObject



29
30
31
# File 'lib/image_formats/A2Dsk.rb', line 29

def track_count
  file_bytes.length/4096
end