$:.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' class D64 < ImageFormat # # 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 # D64_BYTES_PER_SECTOR=256 @@sectors_in_track=[] @@offset_of_track=[] 1.upto(17) {|t| @@sectors_in_track[t]=21} 18.upto(24) {|t| @@sectors_in_track[t]=19} 25.upto(30) {|t| @@sectors_in_track[t]=18} 31.upto(40) {|t| @@sectors_in_track[t]=17} @@offset_of_track[1]=0 1.upto(39) {|t| @@offset_of_track[t+1]=@@offset_of_track[t]+(@@sectors_in_track[t]*D64_BYTES_PER_SECTOR)} def self.possible_extensions ['.d64'] end def self.host_system C64 end def sectors_in_track(track_no) (0..@@sectors_in_track[track_no]-1).collect end #for a given byte stream, how many tracks could be interpreted by this image format? 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 def end_track return track_count end 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 end # == Author # Jonno Downes (jonno@jamtronix.com) # # == Copyright # Copyright (c) 2008 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.