$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) $:.unshift(File.dirname(__FILE__+"\\..")) unless $:.include?(File.dirname(__FILE__+"\\..")) || $:.include?(File.expand_path(File.dirname(__FILE__+"\\.."))) require 'ImageFormat' #Atari ATR format - http://pages.suddenlink.net/wa5bdu/readme.txt class Atr < ImageFormat ATR_HEADER_LENGTH=0x10 ATR_SECTORS_PER_TRACK=18 def self.possible_extensions ['.atr'] end is_valid_image_if lambda { file_system_image.file_bytes[0,2]==[0x96,0x02] } def self.host_system Atari800 end #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 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 # how many tracks could be interpreted by this image format? def track_count (@file_bytes.length-ATR_HEADER_LENGTH)/(@sector_size*ATR_SECTORS_PER_TRACK) end # how many sectors could be interpreted by this image format? def sector_count (@file_bytes.length-ATR_HEADER_LENGTH)/(@sector_size) end #we ignore the track no, but keep the paramater for compatability with other image formats 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 def initialize(file_bytes) @file_bytes=file_bytes @sector_size=file_bytes[4,2].unpack("v")[0] end end # == Author # Jonno Downes (jonno@jamtronix.com) # # == Copyright # Copyright (c) 2007 Jonno Downes (jonno@jamtronix.com) # #Permission is hereby granted, free of charge, to any person obtaining #a copy of this software and associated documentation files (the #"Software"), to deal in the Software without restriction, including #without limitation the rights to use, copy, modify, merge, publish, #distribute, sublicense, and/or sell copies of the Software, and to #permit persons to whom the Software is furnished to do so, subject to #the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.