lib/DOSDisk.rb in dsktool-0.4.2 vs lib/DOSDisk.rb in dsktool-0.5.1
- old
+ new
@@ -82,26 +82,30 @@
# 10-FF Up to 120 more track and sector pairs
class DOSDisk < DSK
+ attr_accessor :vtoc_track_no,:vtoc_sector_no
def dump_catalog
s=""
files.keys.sort.each { |file_name|
file=files[file_name]
s<< "#{file.locked ? '*':' '}#{file.file_type} #{sprintf('%04d',file.contents.length)} #{file.filename}\n"
}
s
end
def file_system
- :dos
+ return :dos if (vtoc_track_no==0x11) && (vtoc_sector_no==0)
+ :modified_dos
end
- def initialize(file_bytes,sector_order)
+ def initialize(file_bytes,sector_order,vtoc_track_no=0x11,vtoc_sector_no=0)
super(file_bytes,sector_order)
+ @vtoc_track_no=vtoc_track_no
+ @vtoc_sector_no=vtoc_sector_no
self.read_vtoc
end
#default file type is TextFile
#Tokenisation not currently implemented
@@ -130,19 +134,19 @@
#reads the VTOC, and populate the "files" array with files
def read_vtoc
@files={}
- vtoc_sector=get_sector(17,0)
+ vtoc_sector=get_sector(vtoc_track_no,vtoc_sector_no)
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]
+ file_descriptive_entry=catalog_sector[file_descriptive_entry_start,36]
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.gsub!(/ *$/,"") #strip off trailing spaces
filename.tr!("\x00-\x1f","\x40-\x5f") #convert non-printable chars to corresponding uppercase letter
@@ -200,11 +204,11 @@
end
end
#iterate through the CATALOG to find either the named file or (if nil is passed in) an empty slot
def find_catalog_slot(filename)
- vtoc_sector=get_sector(17,0)
+ vtoc_sector=get_sector(vtoc_track_no,vtoc_sector_no)
catalog_filename=DOSFile.catalog_filename(filename.upcase) unless filename.nil?
catalog_track_no=vtoc_sector[01]
catalog_sector_no=vtoc_sector[02]
while (catalog_track_no+catalog_sector_no>0) do
@@ -226,11 +230,11 @@
#iterate through the sector usage bitmap, return a list of [track,sector] for sectors marked available
def free_sector_list
end_of_sector_usage_bitmap=(track_count*4+0x38)-1
- sector_usage_bitmap=get_sector(0x11,0)[0x38..end_of_sector_usage_bitmap]
+ sector_usage_bitmap=get_sector(vtoc_track_no,vtoc_sector_no)[0x38..end_of_sector_usage_bitmap]
free_sectors=[]
#skip track 0 - even if sectors there are unused, we can't include them in a catalog or track/sector list
(1..track_count-1).each do |track|
track_bitmap_lo=sector_usage_bitmap[track*4+1]
track_bitmap_hi=sector_usage_bitmap[track*4]
@@ -266,11 +270,11 @@
#if file not in catalog, do nothing
return if this_files_catalog_slot.nil?
file_descriptive_entry=get_sector(this_files_catalog_slot.track_no,this_files_catalog_slot.sector_no)[this_files_catalog_slot.offset..this_files_catalog_slot.offset+0x22]
#mark sector as free in sector usage list
- sector_usage_bitmap_sector=get_sector(0x11,0)
+ sector_usage_bitmap_sector=get_sector(vtoc_track_no,vtoc_sector_no)
sectors_to_mark_available=get_track_sector_list(file_descriptive_entry[0x00],file_descriptive_entry[0x01])
sectors_to_mark_available<<DSKTrackSector.new(file_descriptive_entry[0x01],file_descriptive_entry[0x00])
sectors_to_mark_available.each do |ts|
offset_of_byte_containing_this_sector=0x38+(ts.track_no*4)
@@ -279,11 +283,11 @@
end
byte_containing_this_sector=sector_usage_bitmap_sector[offset_of_byte_containing_this_sector]
byte_containing_this_sector=byte_containing_this_sector|(2**(ts.sector_no%8))
sector_usage_bitmap_sector[offset_of_byte_containing_this_sector]=byte_containing_this_sector
end
- set_sector(0x11,0,sector_usage_bitmap_sector)
+ set_sector(vtoc_track_no,vtoc_sector_no,sector_usage_bitmap_sector)
#mark slot as available in catalog
catalog_sector=get_sector(this_files_catalog_slot.track_no,this_files_catalog_slot.sector_no)
catalog_sector[this_files_catalog_slot.offset+0x20]=catalog_sector[this_files_catalog_slot.offset] #save the current "first track no" in last byte of filename
catalog_sector[this_files_catalog_slot.offset]=0xFF
@@ -293,20 +297,20 @@
def set_sector(track,sector,contents)
super(track,sector,contents)
#now mark sector as used in sector usage list
- if ((track!=0x11) || (sector!=00)) then #don't bother marking the VTOC sectors used
- sector_usage_bitmap_sector=get_sector(0x11,0)
+ if ((track!=vtoc_track_no) || (sector!=vtoc_sector_no)) then #don't bother marking the VTOC sectors used
+ sector_usage_bitmap_sector=get_sector(vtoc_track_no,vtoc_sector_no)
offset_of_byte_containing_this_sector=0x38+(track*4)
if sector<8 then
offset_of_byte_containing_this_sector+=1
end
byte_containing_this_sector=sector_usage_bitmap_sector[offset_of_byte_containing_this_sector]
byte_containing_this_sector=byte_containing_this_sector&(0xff-(2**(sector%8)))
sector_usage_bitmap_sector[offset_of_byte_containing_this_sector]=byte_containing_this_sector
- set_sector(0x11,0,sector_usage_bitmap_sector)
+ set_sector(vtoc_track_no,vtoc_sector_no,sector_usage_bitmap_sector)
end
end
def add_file(file)
@@ -338,10 +342,10 @@
(0..sectors_needed-2).each do |sector_in_file|
sector_to_use=free_sectors[sector_in_file+1]
track_sector_list[(sector_in_file*2)+0x0C]=sector_to_use.track_no
track_sector_list[(sector_in_file*2)+0X0D]=sector_to_use.sector_no
- sector_contents=file.contents[(sector_in_file*256)..(sector_in_file*256)+255] || ""
+ sector_contents=file.contents[(sector_in_file*256),256] || ""
set_sector(sector_to_use.track_no,sector_to_use.sector_no,sector_contents)
end
#write the track/sector list
set_sector(track_sector_list_sector.track_no,track_sector_list_sector.sector_no,track_sector_list)