Class: Atr

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

Overview

Constant Summary collapse

ATR_HEADER_LENGTH =
0x10
ATR_SECTORS_PER_TRACK =
18

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, is_valid_image_if, possible_file_systems, #start_track, #to_s, #track_list

Methods included from SubclassTracking

extended

Constructor Details

#initialize(file_bytes) ⇒ Atr

Returns a new instance of Atr.



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

def initialize(file_bytes)
  @file_bytes=file_bytes
  @sector_size=file_bytes[4,2].unpack("v")[0]
end

Class Method Details

.host_systemObject



23
24
25
# File 'lib/image_formats/Atr.rb', line 23

def self.host_system
    Atari800
end

.possible_extensionsObject



15
16
17
# File 'lib/image_formats/Atr.rb', line 15

def self.possible_extensions
    ['.atr']
end

Instance Method Details

#get_sector(track_no, sector_no) ⇒ Object

we ignore the track no, but keep the paramater for compatability with other image formats



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

def get_sector(track_no,sector_no)   
	offset_of_sector=(sector_no-1)*@sector_size+ATR_HEADER_LENGTH
	return @file_bytes[offset_of_sector,@sector_size]
end

#sector_countObject

how many sectors could be interpreted by this image format?



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

def sector_count
  (@file_bytes.length-ATR_HEADER_LENGTH)/(@sector_size)
end

#sectors_in_track(track_no) ⇒ Object

Atari disks actually don’t use tracks, just a single flat list of sectors however for ease of use with utilities that assume there are tracks & sectors we will assign 18 sectors per track



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

def sectors_in_track(track_no)
  first_sector=track_no*ATR_SECTORS_PER_TRACK
  (first_sector..first_sector+ATR_SECTORS_PER_TRACK-1).collect
end

#track_countObject

how many tracks could be interpreted by this image format?



36
37
38
# File 'lib/image_formats/Atr.rb', line 36

def track_count
  (@file_bytes.length-ATR_HEADER_LENGTH)/(@sector_size*ATR_SECTORS_PER_TRACK)
end