def read_vtoc
@files={}
vtoc_sector=get_sector(17,0)
catalog_sector=get_sector(vtoc_sector[01],vtoc_sector[02])
done=false
visited_sectors={}
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)
filename=""
file_descriptive_entry[3..32].to_s.each_byte{|b| filename+=(b.%128).chr}
filename.gsub!(/ *$/,"")
filename.tr!("\x00-\x1f","\x40-\x5f")
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,contents,locked)
when 0x01 then SCAsmFile.can_be_scasm_file?(contents)? SCAsmFile.new(filename,contents,locked): IntegerBasicFile.new(filename,contents,locked)
when 0x02 then AppleSoftFile.new(filename,contents,locked)
when 0x04 then BinaryFile.new(filename,contents,locked)
else DOSFile.new(filename,contents,locked,file_type_code)
end
end
end
}
next_track=catalog_sector[1]
next_sector=catalog_sector[2]%0x10
if (next_track==0) &&( next_sector==0) then
done=true
else
s="#{next_track}/#{next_sector}"
if (!visited_sectors[s].nil?) then
done=true
end
visited_sectors[s]=true
catalog_sector=get_sector(next_track,next_sector)
end
end
end