Class: D81

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

Constant Summary collapse

D81_BYTES_PER_SECTOR =

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

References:

http://www.unusedino.de/ec64/technical/formats/d81.html
0x100
D81_SECTORS_PER_TRACK =
40

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



24
25
26
# File 'lib/image_formats/D81.rb', line 24

def self.host_system
    C64
end

.possible_extensionsObject



20
21
22
# File 'lib/image_formats/D81.rb', line 20

def self.possible_extensions
    ['.d81']
end

Instance Method Details

#dir_sector_noObject

what sector does the directory start on?



47
48
49
# File 'lib/image_formats/D81.rb', line 47

def dir_sector_no
  3
end

#dir_track_noObject

what track does the directory start on?



42
43
44
# File 'lib/image_formats/D81.rb', line 42

def dir_track_no
  40
end

#end_trackObject



37
38
39
# File 'lib/image_formats/D81.rb', line 37

def end_track
  return   track_count
end

#get_sector(track_no, sector_no) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/image_formats/D81.rb', line 50

def get_sector(track_no,sector_no)    
    return nil  unless track_no.between?(1,end_track)
		return nil unless sector_no.between?(0,D81_SECTORS_PER_TRACK-1)   
    track_start=D81_BYTES_PER_SECTOR*(D81_SECTORS_PER_TRACK*(track_no-1))
    sector_start=track_start+(D81_BYTES_PER_SECTOR*sector_no)
#    puts "T %0d, S %0d, TRACK OFFSET=$%x, SECTOR OFFSET=$%x" % [track_no,sector_no,track_start,sector_start]
		file_bytes[sector_start,D81_BYTES_PER_SECTOR]
end

#sectors_in_track(track_no) ⇒ Object



28
29
30
# File 'lib/image_formats/D81.rb', line 28

def sectors_in_track(track_no)
 D81_SECTORS_PER_TRACK
end

#set_sector(track_no, sector_no, sector_contents) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/image_formats/D81.rb', line 59

def set_sector(track_no,sector_no,sector_contents)
    raise "d81 currently read only"
    raise "invalid track number #{track_no}" unless track_no.between?(1,end_track)
    raise "invalid sector number #{sector_no}" unless sector_no.between?(0,D81_SECTORS_PER_TRACK-1)
    padded_sector_contents=(sector_contents+("\000"*D81_BYTES_PER_SECTOR))[0,D81_BYTES_PER_SECTOR]
    track_start=D81_BYTES_PER_SECTOR*(D81_SECTORS_PER_TRACK*(track_no-1))
    sector_start=track_start+(D81_BYTES_PER_SECTOR*sector_no)
		file_bytes[sector_start,D81_BYTES_PER_SECTOR]=padded_sector_contents
end

#track_countObject

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



33
34
35
# File 'lib/image_formats/D81.rb', line 33

def track_count
    file_bytes.length/(D81_SECTORS_PER_TRACK*256)
end