Class: ProDOSDisk
Overview
for now, assumes ‘ProDOS order’
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
-
#volume_name ⇒ Object
Returns the value of attribute volume_name.
Attributes inherited from DSK
#file_bytes, #sector_order, #source_filename, #track_count
Instance Method Summary collapse
-
#dump_block(block_no) ⇒ Object
concatenate all the blocks in the volume directory Volume Directory format is: (from “Beneath Apple ProDOS pp 4-10 - 4-12) FOR VOLUMES $00 STORAGE_TYPE/NAME_LENGTH $01-$0F FILE_NAME $10 RESERVED $11-$12 RESERVED $13-$14 RESERVED $15-$17 RESERVED $18-$1B CREATION $1C VERSION $1D MIN_VERSION $1E ACCESS $1F ENTRY_LENGTH $20 ENTRIES_PER_BLOCK $21-$22 FILE_COUNT $23-$24 BIT_MAP_POINTER $25-$26 TOTAL_BLOCKS.
- #dump_catalog ⇒ Object
- #file_system ⇒ Object
-
#initialize(file_bytes, sector_order) ⇒ ProDOSDisk
constructor
A new instance of ProDOSDisk.
-
#last_block ⇒ Object
what is the last block on this disk?.
- #read_catalog(starting_block = 2, dir_path = "") ⇒ Object
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) ⇒ ProDOSDisk
Returns a new instance of ProDOSDisk.
23 24 25 26 |
# File 'lib/ProDOSDisk.rb', line 23 def initialize(file_bytes,sector_order) super(file_bytes,sector_order) self.read_catalog end |
Instance Attribute Details
#volume_name ⇒ Object
Returns the value of attribute volume_name.
8 9 10 |
# File 'lib/ProDOSDisk.rb', line 8 def volume_name @volume_name end |
Instance Method Details
#dump_block(block_no) ⇒ Object
concatenate all the blocks in the volume directory Volume Directory format is: (from “Beneath Apple ProDOS pp 4-10 - 4-12) FOR VOLUMES $00 STORAGE_TYPE/NAME_LENGTH $01-$0F FILE_NAME $10 RESERVED $11-$12 RESERVED $13-$14 RESERVED $15-$17 RESERVED $18-$1B CREATION $1C VERSION $1D MIN_VERSION $1E ACCESS $1F ENTRY_LENGTH $20 ENTRIES_PER_BLOCK $21-$22 FILE_COUNT $23-$24 BIT_MAP_POINTER $25-$26 TOTAL_BLOCKS
FOR FILES $00 STORAGE_TYPE/NAME_LENGTH $01-$0F FILE_NAME $10 FILE_TYPE $11-$12 KEY_POINTER $13-$14 BLOCKS_USED $15-$17 EOF $18-$1B CREATION $1C VERSION $1D MIN_VERSION $1E ACCESS $1F-$20 AUX_TYPE $21-$24 LAST_MOD $25-$26 HEADER_POINTER
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ProDOSDisk.rb', line 67 def dump_block(block_no) s=hline s<<sprintf("BLOCK %03d\n",block_no) s<< "\t" block_data=get_block(block_no) (0..15).each {|x| s<<sprintf("%02X ",x) } s<<"\n" s<<hline (0..31).each {|line_number| lhs="" rhs="" start_byte=line_number*16 line=block_data[start_byte..start_byte+15] line.each_byte {|byte| lhs<< sprintf("%02X ", byte) rhs<< (byte%128).chr.sub(/[\x00-\x1f]/,'.') } s<<sprintf("%03X\t%s %s\n",start_byte,lhs,rhs) } s end |
#dump_catalog ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/ProDOSDisk.rb', line 14 def dump_catalog s="" files.keys.sort.each { |file_name| file=files[file_name] s<< "#{sprintf('% 6d',file.contents.length)}\t #{file.file_type} : $#{sprintf '%X',file.aux_type}\t#{file_name}\n" } s end |
#file_system ⇒ Object
28 29 30 |
# File 'lib/ProDOSDisk.rb', line 28 def file_system :prodos end |
#last_block ⇒ Object
what is the last block on this disk?
11 12 13 |
# File 'lib/ProDOSDisk.rb', line 11 def last_block (self.track_count*8)-1 end |
#read_catalog(starting_block = 2, dir_path = "") ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 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 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ProDOSDisk.rb', line 89 def read_catalog(starting_block=2,dir_path="") next_block_no=starting_block while (next_block_no!=0) block=get_block(next_block_no) offset=4 while (offset<(0x200-0x27)) directory_entry=block[offset..offset+0x27] storage_type=directory_entry[0]>>4 name_length=directory_entry[0]%0x10 name=directory_entry[1..name_length] file_type=directory_entry[0x10] key_pointer=directory_entry[0x11]+directory_entry[0x12]*0x100 blocks_used=directory_entry[0x13]+directory_entry[0x14]*0x100 file_length=directory_entry[0x15]+directory_entry[0x16]*0x100+directory_entry[0x17]*0x10000 aux_type=directory_entry[0x1f]+directory_entry[0x20]*0x100 case storage_type when 0x00 then #nop when 0x01 then #it's a seedling file_contents=get_block(key_pointer) files[name]=ProDOSFile.new(name,file_contents,file_type,aux_type) when 0x02 then #it's a sapling block_list=[] index_block=get_block(key_pointer) 0.upto((file_length/0x200)) do |i| block_list<<index_block[i]+(index_block[i+0x100]*0x100) end file_contents="" block_list.each do |next_block_no| if next_block_no==0 then file_contents+="\x00"*0x200 elsif next_block_no>self.last_block then STDERR<<"file #{name} attempted to read bad block # #{next_block_no}\n" file_contents+="\x00"*0x200 else file_contents+=get_block(next_block_no) end end file_contents=file_contents[0..file_length-1] files["#{dir_path}#{name}"]=ProDOSFile.new(name,file_contents,file_type,aux_type) when 0x03 then #it's a tree master_index_block=get_block(key_pointer) block_list=[] number_of_index_entries=1+(file_length/0x200) number_of_index_blocks=1+(number_of_index_entries/0x100) number_of_index_entries_in_last_block=number_of_index_entries-(number_of_index_blocks-1)*0x100 0.upto(number_of_index_blocks-1) do |i| index_block_no=master_index_block[i]+master_index_block[i+0x100]*0x100 index_block=get_block(index_block_no) if i==number_of_index_blocks-1 then entries_in_this_index_block=number_of_index_entries_in_last_block else entries_in_this_index_block=256 end 0.upto(entries_in_this_index_block-1) do |j| block_list<<index_block[j]+(index_block[j+0x100]*0x100) end end file_contents="" block_list.each do |next_block_no| if next_block_no==0 then file_contents+="\x00"*0x200 else file_contents+=get_block(next_block_no) end end file_contents=file_contents[0..file_length-1] files["#{dir_path}#{name}"]=ProDOSFile.new(name,file_contents,file_type,aux_type) when 0x0D then #it's a subdirectory pointer read_catalog(key_pointer,"#{dir_path}#{name}/") when 0x0E then #it's a subdirectory header #do nothing when 0x0F then #it's a volume @volume_name=name else # raise "unknown storage_type #{sprintf '%02X',storage_type}" puts "skipping unknown storage_type #{sprintf '%02X',storage_type} for #{dir_path}#{name}" end offset+=0x27 end next_block_no=block[2]+block[3]*256 end end |