# File lib/NADOLDisk.rb, line 153
 def add_file(file)
   raise "only NADOLFiles may be added to NADOL format disks!" unless file.kind_of?(NADOLFile)
   
  delete_file(file.filename) unless files[file.filename].nil?
  catalog_slot=find_catalog_slot(nil)
  raise "CATALOG IS FULL!" if catalog_slot.nil?
  
  free_sectors=free_sector_list
    
  sectors_needed=1+file.length_in_sectors
  raise "not enough free space - #{sectors_needed} sectors needed, #{free_sector_list.length} available " unless sectors_needed<=free_sectors.length
  
  #for each sector in the file, copy it to disk and then record it in the track/sector list
  track_sector_list="\0"*256
  track_sector_list_sector=free_sectors[0]
  (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]=sector_to_use.track_no
    track_sector_list[(sector_in_file*2)+1]=sector_to_use.sector_no
    sector_contents=file.contents[(sector_in_file*256)..(sector_in_file*256)+255] || ""
    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)
  
  #update the catalog
  catalog_sector=get_sector(catalog_slot.track_no,catalog_slot.sector_no)
  catalog_sector[catalog_slot.offset..catalog_slot.offset+0x0B]=file.catalog_filename
  catalog_sector[catalog_slot.offset+0x0C]=file.contents.length % 0x100
  catalog_sector[catalog_slot.offset+0x0D]=file.contents.length / 0x100
  catalog_sector[catalog_slot.offset+0x0E]=track_sector_list_sector.track_no
  catalog_sector[catalog_slot.offset+0x0F]=track_sector_list_sector.sector_no
  set_sector(catalog_slot.track_no,catalog_slot.sector_no,catalog_sector)
  
  raise "catalog not updated correctly!" if find_catalog_slot(file.filename).nil?
  #reread the catalog to populate the files list
  read_catalog
 end