Class: PascalDisk

Inherits:
DSK
  • Object
show all
Defined in:
lib/PascalDisk.rb

Constant Summary

Constants inherited from DSK

DSK::DSK_FILE_LENGTH, DSK::DSK_IMAGE_EXTENSIONS, DSK::FILE_SYSTEMS, DSK::INTERLEAVES, DSK::NIB_FILE_LENGTH, DSK::SECTOR_ORDERS

Instance Attribute Summary collapse

Attributes inherited from DSK

#file_bytes, #sector_order, #source_filename, #track_count

Instance Method Summary collapse

Methods inherited from DSK

#add_file, #best_subclass, create_new, #delete_file, #disassemble_sector, #dump_sector, #files, #free_sector_list, #get_block, #get_sector, #hex_dump, #is_cpm?, #is_dos33?, is_dsk_file?, #is_modified_dos?, #is_nadol?, #is_pascal?, #is_prodos?, #make_file, read, #save_as, #set_boot_track, #set_sector

Constructor Details

#initialize(file_bytes, sector_order) ⇒ PascalDisk

Returns a new instance of PascalDisk.



42
43
44
45
# File 'lib/PascalDisk.rb', line 42

def initialize(file_bytes,sector_order)    
	super(file_bytes,sector_order)
	self.read_catalog
end

Instance Attribute Details

#volume_nameObject

Returns the value of attribute volume_name.



30
31
32
# File 'lib/PascalDisk.rb', line 30

def volume_name
  @volume_name
end

Instance Method Details

#dump_catalogObject



32
33
34
35
36
37
38
39
# File 'lib/PascalDisk.rb', line 32

def dump_catalog
	s=""
	files.keys.sort.each { |file_name|		
		file=files[file_name]	
		s<< "#{sprintf('% 6d',file.contents.length)}\t #{file.file_type}\t#{file.filename}\n"
	}
	s
end

#file_systemObject



47
48
49
# File 'lib/PascalDisk.rb', line 47

def file_system
	:pascal
end

#read_catalogObject

reads the catalog, and populate the “files” array with files



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/PascalDisk.rb', line 52

def read_catalog
       catalog=get_block(2)
       #we've read the first block in the catalog, now read the rest
       catalog_size=catalog[2]
       3.upto(catalog_size-1) do |i|
         catalog<<get_block(i)
       end
#	06	VOLUME NAME LENGTH (1 byte)
#	07..0D	VOLUME NAME (17 bytes)
#	0E..0F 	VOLUME SIZE (WORD)
#	10 	NUMBER OF FILES (BYTE)
       volume_name_length=catalog[6]
       self.volume_name=catalog[7..6+volume_name_length]
       files_in_volume=catalog[0x10]
       #read in all the files
       
#	00..01 	FIRST BLOCK (word)	
#	02..03 	LAST BLOCK+1 (word)
#	04 	FILE TYPE (byte) =  untypedfile,xdskfile,codefile,textfile,infofile,datafile,graffile,fotofile,securdir
#	05 	STATUS (byte)
#	06	FILENAME LENGTH (1 byte)
#	07..15	FILENAME (15 bytes)
#	16..17 	BYTES IN LAST BLOCK (word)
#	18.1A	FILE ACCESS DATE
       1.upto(files_in_volume) do |file_no|
         file_record=catalog[file_no*0x1a..(file_no*0x1a+0x19)]
         first_block=file_record[0]+file_record[1]*0x100
         first_block_in_next_file=file_record[2]+file_record[3]*0x100
         last_block=first_block_in_next_file-1
         file_type=file_record[4]
         file_name_length=file_record[6]
         file_name=file_record[7..6+file_name_length]
         bytes_in_last_block=file_record[0x16]+file_record[0x17]*0x100
         file_contents=""
         first_block.upto(last_block) do |block_no|
           this_block=get_block(block_no)
           if block_no==last_block then
             file_contents<<this_block[0..bytes_in_last_block-1]
           else
             file_contents<<this_block 
           end
         files[file_name]=PascalFile.new(file_name,file_contents,file_type)
       end        
     end
end