Class: DOSDisk
Constant Summary
Constants inherited from DSK
Instance Method Summary collapse
- #dump_catalog ⇒ Object
-
#initialize(file_bytes) ⇒ DOSDisk
constructor
A new instance of DOSDisk.
-
#read_vtoc ⇒ Object
reads the VTOC, and populate the “files” array with files.
Methods inherited from DSK
#disassemble_sector, #dump_disk, #dump_sector, #files, #get_sector, #is_dos33?, is_dsk_file?, #is_nadol?, read
Constructor Details
#initialize(file_bytes) ⇒ DOSDisk
Returns a new instance of DOSDisk.
94 95 96 97 |
# File 'lib/DOSDisk.rb', line 94 def initialize(file_bytes) super(file_bytes) self.read_vtoc end |
Instance Method Details
#dump_catalog ⇒ Object
87 88 89 90 91 |
# File 'lib/DOSDisk.rb', line 87 def dump_catalog files.each_value { |file| puts "#{file.locked ? '*':' '}#{file.file_type} #{sprintf('%03X',file.sector_count)} #{file.filename}" } end |
#read_vtoc ⇒ Object
reads the VTOC, and populate the “files” array with files
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/DOSDisk.rb', line 100 def read_vtoc vtoc_sector=get_sector(17,0) catalog_sector=get_sector(vtoc_sector[01],vtoc_sector[02]) done=false while !done break if catalog_sector.nil? (0..6).each {|file_number| file_descriptive_entry_start=11+file_number*35 file_descriptive_entry=catalog_sector[file_descriptive_entry_start..file_descriptive_entry_start+35] break if (file_descriptive_entry[0]==0xFF) # skip deleted files filename="" file_descriptive_entry[3..32].to_s.each_byte{|b| filename+=(b.%128).chr} filename.sub!(/ *$/,"") #strip off trailing spaces locked=(file_descriptive_entry[2]>=0x80) sector_count=file_descriptive_entry[0x21]+file_descriptive_entry[0x22]*256 file_type_code=file_descriptive_entry[2]%0x80 if (sector_count>0) then contents="" ts_list_track_no=file_descriptive_entry[0] ts_list_sector_no=file_descriptive_entry[1] while (ts_list_track_no>0) && (ts_list_track_no<=0X22) && (ts_list_sector_no<=0x0f) ts_list_sector=get_sector(ts_list_track_no,ts_list_sector_no) ts_list_track_no=ts_list_sector[1] ts_list_sector_no=ts_list_sector[2] 0x0C.step(0xff,2) {|i| data_track_no=ts_list_sector[i] data_sector_no=ts_list_sector[i+1] if (data_track_no>0) && (data_track_no<=0X22) && (data_sector_no<=0x0f) then contents+=get_sector(data_track_no,data_sector_no) end } end if contents.length>0 then @files[filename]= case file_type_code when 0x00 then TextFile.new(filename,locked,sector_count,contents) when 0x01 then SCAsmFile.can_be_scasm_file?(contents)? SCAsmFile.new(filename,locked,sector_count,contents): IntegerBasicFile.new(filename,locked,sector_count,contents) when 0x02 then AppleSoftFile.new(filename,locked,sector_count,contents) when 0x04 then BinaryFile.new(filename,locked,sector_count,contents) # when 0x08 then "S" #S type file # when 0x10 then "R" #RELOCATABLE object module file # when 0x20 then "a" #?? # when 0x40 then "b" #?? else DOSFile.new(filename,locked,sector_count,contents,sprintf("$%02X",file_type_code)) end end end } next_track=catalog_sector[1] next_sector=catalog_sector[2] if (next_track==0) &&( next_sector==0) then done=true else catalog_sector=get_sector(next_track,next_sector) end end end |