Class: D64

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

Direct Known Subclasses

G64

Constant Summary collapse

D64_BYTES_PER_SECTOR =

For manipulating D64 files, as used by many C64 emulators.

References:

http://www.unusedino.de/ec64/technical/formats/d64.html
http://www.baltissen.org/newhtm/1541c.htm
http://www.scribd.com/doc/40438/The-Commodore-1541-Disk-Drive-Users-Guide
256
@@sectors_in_track =
[]
@@offset_of_track =
[]

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, #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



35
36
37
# File 'lib/image_formats/D64.rb', line 35

def self.host_system
    C64
end

.possible_extensionsObject



31
32
33
# File 'lib/image_formats/D64.rb', line 31

def self.possible_extensions
    ['.d64']
end

Instance Method Details

#dir_sector_noObject

what sector does the directory start on?



62
63
64
# File 'lib/image_formats/D64.rb', line 62

def dir_sector_no
  1
end

#dir_track_noObject

what track does the directory start on?



57
58
59
# File 'lib/image_formats/D64.rb', line 57

def dir_track_no
  18
end

#end_trackObject



52
53
54
# File 'lib/image_formats/D64.rb', line 52

def end_track
  return   track_count
end

#get_sector(track_no, sector_no) ⇒ Object



66
67
68
69
70
71
# File 'lib/image_formats/D64.rb', line 66

def get_sector(track_no,sector_no)
    return nil if @@sectors_in_track[track_no].nil?
		return nil unless sector_no.between?(0,@@sectors_in_track[track_no]-1)
		start_byte=@@offset_of_track[track_no]+(D64_BYTES_PER_SECTOR*(sector_no))    
		file_bytes[start_byte,D64_BYTES_PER_SECTOR]
end

#sectors_in_track(track_no) ⇒ Object



39
40
41
# File 'lib/image_formats/D64.rb', line 39

def sectors_in_track(track_no)
 (0..@@sectors_in_track[track_no]-1).collect
end

#set_sector(track_no, sector_no, sector_contents) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/image_formats/D64.rb', line 73

def set_sector(track_no,sector_no,sector_contents)
    raise "invalid track number #{track_no}" if @@sectors_in_track[track_no].nil?
    raise "invalid sector number #{sector_no}" unless sector_no.between?(0,@@sectors_in_track[track_no]-1)
    padded_sector_contents=(sector_contents+("\000"*D64_BYTES_PER_SECTOR))[0,D64_BYTES_PER_SECTOR]
		start_byte=@@offset_of_track[track_no]+(D64_BYTES_PER_SECTOR*(sector_no))    
		file_bytes[start_byte,D64_BYTES_PER_SECTOR]=padded_sector_contents
end

#track_countObject

for a given byte stream, how many tracks could be interpreted by this image format?



44
45
46
47
48
49
50
# File 'lib/image_formats/D64.rb', line 44

def track_count
  track_count=0
  1.upto(@@offset_of_track.length-1) do |t|
     track_count=t if file_bytes.length>@@offset_of_track[t]
  end
  track_count
end