doc/classes/AppleDos.src/M000251.html in ripxplore-0.13.0 vs doc/classes/AppleDos.src/M000251.html in ripxplore-0.14.0
- old
+ new
@@ -3,26 +3,96 @@
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
- <title>catalog_filename (AppleDos)</title>
+ <title>add_file (AppleDos)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File lib/file_systems/AppleDos.rb, line 258</span>
-<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">catalog_filename</span>(<span class="ruby-identifier">filename</span>)
- <span class="ruby-identifier">s</span>=<span class="ruby-value str">""</span>
- <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">29</span>
- <span class="ruby-identifier">c</span>=(<span class="ruby-identifier">filename</span>[<span class="ruby-identifier">i</span>])
- <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">then</span>
- <span class="ruby-identifier">c</span>=<span class="ruby-value">0x</span><span class="ruby-constant">A0</span>
- <span class="ruby-keyword kw">else</span>
- <span class="ruby-identifier">c</span>=(<span class="ruby-identifier">c</span><span class="ruby-operator">|</span><span class="ruby-value">0x80</span>)
- <span class="ruby-keyword kw">end</span>
- <span class="ruby-identifier">s</span><span class="ruby-operator">+=</span><span class="ruby-identifier">c</span>.<span class="ruby-identifier">chr</span>
- <span class="ruby-keyword kw">end</span>
- <span class="ruby-identifier">s</span>
+ <pre><span class="ruby-comment cmt"># File lib/file_systems/AppleDos.rb, line 173</span>
+<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">add_file</span>(<span class="ruby-identifier">file_system_image</span>,<span class="ruby-identifier">native_filetype_class</span>,<span class="ruby-identifier">filename</span>,<span class="ruby-identifier">file_contents</span>,<span class="ruby-identifier">file_type</span>=<span class="ruby-keyword kw">nil</span>,<span class="ruby-identifier">aux_code</span>=<span class="ruby-keyword kw">nil</span>)
+ <span class="ruby-comment cmt">#make sure the file type is supported on DOS 3.3!
</span>
+ <span class="ruby-identifier">raise</span> <span class="ruby-node">"#{native_filetype_class} not supported on Apple DOS 3.3 file system"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">native_filetype_class</span>.<span class="ruby-identifier">file_system_file_types</span>[<span class="ruby-keyword kw">self</span>].<span class="ruby-identifier">nil?</span>
+ <span class="ruby-identifier">expected_file_type</span>=<span class="ruby-identifier">native_filetype_class</span>.<span class="ruby-identifier">file_system_file_types</span>[<span class="ruby-keyword kw">self</span>]
+ <span class="ruby-identifier">file_type</span>=<span class="ruby-identifier">expected_file_type</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">file_type</span>.<span class="ruby-identifier">nil?</span>
+ <span class="ruby-identifier">raise</span> <span class="ruby-node">"inconsistent file_type (should be #{expected_file_type} but was #{file_type})"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">expected_file_type</span><span class="ruby-operator">==</span><span class="ruby-identifier">file_type</span>
+ <span class="ruby-identifier">native_file</span>=<span class="ruby-identifier">native_filetype_class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">file_system_image</span>,<span class="ruby-identifier">filename</span>,<span class="ruby-identifier">file_contents</span>,<span class="ruby-identifier">file_type</span>,<span class="ruby-identifier">aux_code</span>)
+ <span class="ruby-identifier">raise</span> <span class="ruby-node">"couldn't make #{native_filetype_class}"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">native_file</span>.<span class="ruby-identifier">nil?</span>
+ <span class="ruby-comment cmt">#if this file exists, delete it first
</span>
+ <span class="ruby-identifier">file_system_image</span>.<span class="ruby-identifier">delete_file</span>(<span class="ruby-identifier">filename</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">file_system_image</span>.<span class="ruby-identifier">files</span>[<span class="ruby-identifier">filename</span>].<span class="ruby-identifier">nil?</span>
+ <span class="ruby-identifier">catalog_slot</span>=<span class="ruby-identifier">find_catalog_slot</span>(<span class="ruby-identifier">file_system_image</span>,<span class="ruby-keyword kw">nil</span>)
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">"CATALOG IS FULL!"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">catalog_slot</span>.<span class="ruby-identifier">nil?</span>
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">"invalid catalog slot "</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">catalog_slot</span>[<span class="ruby-value">2</span>].<span class="ruby-identifier">nil?</span>
+ <span class="ruby-identifier">free_sectors</span>=<span class="ruby-identifier">free_sector_list</span>(<span class="ruby-identifier">file_system_image</span>)
+ <span class="ruby-identifier">sectors_needed</span>=<span class="ruby-value">1</span><span class="ruby-operator">+</span>(<span class="ruby-value">255</span><span class="ruby-operator">+</span><span class="ruby-identifier">file_contents</span>.<span class="ruby-identifier">length</span>)<span class="ruby-operator">/</span><span class="ruby-value">256</span>
+ <span class="ruby-identifier">raise</span> <span class="ruby-node">"not enough free space - #{sectors_needed} sectors needed, #{free_sectors.length} available "</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">sectors_needed</span><span class="ruby-operator"><=</span><span class="ruby-identifier">free_sectors</span>.<span class="ruby-identifier">length</span>
+ <span class="ruby-comment cmt">#TODO - allow files of more than 122 sectors
</span>
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">"only files up to 122 sectors currently supported "</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sectors_needed</span><span class="ruby-operator">></span><span class="ruby-value">122</span>
+ <span class="ruby-comment cmt">#TRACK/SECTOR LIST FORMAT (from Beneath Apple DOS p 4-6)
</span>
+ <span class="ruby-comment cmt"># 00 Not used
</span>
+ <span class="ruby-comment cmt"># 01 Track number of next T/S list of one is needed or zero if no more t/s list
</span>
+ <span class="ruby-comment cmt"># 02 Sector number of next T/S list (if one is present)
</span>
+ <span class="ruby-comment cmt"># 03-04 Not used
</span>
+ <span class="ruby-comment cmt"># 05-06 Sector offset in file of the first sector described by this list
</span>
+ <span class="ruby-comment cmt"># 07-oB Not used
</span>
+ <span class="ruby-comment cmt"># 0C-0D Track and sector of first data sector or zeros
</span>
+ <span class="ruby-comment cmt"># 0E-0F Track and sector of second data sector or zeros
</span>
+ <span class="ruby-comment cmt"># 10-FF Up to 120 more track and sector pairs
</span>
+ <span class="ruby-identifier">track_sector_list</span>=<span class="ruby-value str">"\0"</span><span class="ruby-operator">*</span><span class="ruby-value">256</span>
+ <span class="ruby-identifier">track_sector_list_sector</span>=<span class="ruby-identifier">free_sectors</span>[<span class="ruby-value">0</span>]
+ (<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">sectors_needed</span><span class="ruby-operator">-</span><span class="ruby-value">2</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sector_in_file</span><span class="ruby-operator">|</span>
+ <span class="ruby-identifier">sector_to_use</span>=<span class="ruby-identifier">free_sectors</span>[<span class="ruby-identifier">sector_in_file</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>]
+ <span class="ruby-identifier">track_sector_list</span>[(<span class="ruby-identifier">sector_in_file</span><span class="ruby-operator">*</span><span class="ruby-value">2</span>)<span class="ruby-operator">+</span><span class="ruby-value">0x0</span><span class="ruby-constant">C</span>]=<span class="ruby-identifier">sector_to_use</span>[<span class="ruby-value">0</span>]
+ <span class="ruby-identifier">track_sector_list</span>[(<span class="ruby-identifier">sector_in_file</span><span class="ruby-operator">*</span><span class="ruby-value">2</span>)<span class="ruby-operator">+</span><span class="ruby-value">0</span><span class="ruby-constant">X0D</span>]=<span class="ruby-identifier">sector_to_use</span>[<span class="ruby-value">1</span>]
+ <span class="ruby-identifier">sector_contents</span>=<span class="ruby-identifier">file_contents</span>[(<span class="ruby-identifier">sector_in_file</span><span class="ruby-operator">*</span><span class="ruby-value">256</span>),<span class="ruby-value">256</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">""</span>
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">set_sector</span>(<span class="ruby-identifier">file_system_image</span>,<span class="ruby-identifier">sector_to_use</span>[<span class="ruby-value">0</span>],<span class="ruby-identifier">sector_to_use</span>[<span class="ruby-value">1</span>],<span class="ruby-identifier">sector_contents</span>)
+ <span class="ruby-keyword kw">end</span>
+ <span class="ruby-comment cmt">#write the track/sector list
</span>
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">set_sector</span>(<span class="ruby-identifier">file_system_image</span>,<span class="ruby-identifier">track_sector_list_sector</span>[<span class="ruby-value">0</span>],<span class="ruby-identifier">track_sector_list_sector</span>[<span class="ruby-value">1</span>],<span class="ruby-identifier">track_sector_list</span>)
+
+ <span class="ruby-comment cmt">#update the catalog file descriptive entry
</span>
+ <span class="ruby-comment cmt">#FILE DESCRIPTIVE ENTRY (from Beneath Apple DOS p 4-6)
</span>
+ <span class="ruby-comment cmt"># 00 Track of first track/sector list sector, if this is a deleted file this contains FF
</span>
+ <span class="ruby-comment cmt"># and the original track number is copied to the last byte of the file name (BYTE 20)
</span>
+ <span class="ruby-comment cmt"># If this byte contains a 00, the entry is assumed to never have been used and is
</span>
+ <span class="ruby-comment cmt"># available for use. (This means track 0 can never be used for data even if the DOS image
</span>
+ <span class="ruby-comment cmt"># is 'wiped' from the disk)
</span>
+ <span class="ruby-comment cmt">#
</span>
+ <span class="ruby-comment cmt"># 01 Sector of first track/sector list sector
</span>
+ <span class="ruby-comment cmt"># 02 File type and flags:
</span>
+ <span class="ruby-comment cmt"># 80+file type - file is locked
</span>
+ <span class="ruby-comment cmt"># 00+file type - file is not locked
</span>
+ <span class="ruby-comment cmt">#
</span>
+ <span class="ruby-comment cmt"># 00 - TEXT file
</span>
+ <span class="ruby-comment cmt"># 01 - INTEGER BASIC file
</span>
+ <span class="ruby-comment cmt"># 02 - APPLESOFT BASIC file
</span>
+ <span class="ruby-comment cmt"># 04 - BINARY file
</span>
+ <span class="ruby-comment cmt"># 08 - S type file
</span>
+ <span class="ruby-comment cmt"># 10 - RELOCATABLE object module file
</span>
+ <span class="ruby-comment cmt"># 20 - a type file
</span>
+ <span class="ruby-comment cmt"># 40 - b type file
</span>
+ <span class="ruby-comment cmt">#
</span>
+ <span class="ruby-comment cmt"># 03-20 File Name (30 characters)
</span>
+ <span class="ruby-comment cmt"># 21-22 Length of file in sectors (LO/HI format)
</span>
+
+ <span class="ruby-identifier">catalog_sector</span>=<span class="ruby-identifier">file_system_image</span>.<span class="ruby-identifier">get_sector</span>(<span class="ruby-identifier">catalog_slot</span>[<span class="ruby-value">0</span>],<span class="ruby-identifier">catalog_slot</span>[<span class="ruby-value">1</span>])
+ <span class="ruby-identifier">raise</span> <span class="ruby-node">"invalid catalog track #{catalog_slot[0]},sector #{catalog_slot[1]}"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">catalog_sector</span>.<span class="ruby-identifier">nil?</span>
+ <span class="ruby-identifier">file_descriptive_entry</span>=<span class="ruby-value str">"\0"</span><span class="ruby-operator">*</span><span class="ruby-value">0x23</span>
+ <span class="ruby-identifier">file_descriptive_entry</span>[<span class="ruby-value">0</span>]=<span class="ruby-identifier">track_sector_list_sector</span>[<span class="ruby-value">0</span>]
+ <span class="ruby-identifier">file_descriptive_entry</span>[<span class="ruby-value">1</span>]=<span class="ruby-identifier">track_sector_list_sector</span>[<span class="ruby-value">1</span>]
+ <span class="ruby-identifier">file_descriptive_entry</span>[<span class="ruby-value">2</span>]=<span class="ruby-identifier">file_type</span>
+ <span class="ruby-identifier">file_descriptive_entry</span>[<span class="ruby-value">3</span><span class="ruby-operator">..</span><span class="ruby-value">0x20</span>]=<span class="ruby-identifier">catalog_filename</span>(<span class="ruby-identifier">filename</span>)
+ <span class="ruby-identifier">file_descriptive_entry</span>[<span class="ruby-value">0x21</span>]=(<span class="ruby-identifier">sectors_needed</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>)<span class="ruby-operator">%</span><span class="ruby-value">256</span>
+ <span class="ruby-identifier">file_descriptive_entry</span>[<span class="ruby-value">0x22</span>]=(<span class="ruby-identifier">sectors_needed</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>)<span class="ruby-operator">/</span><span class="ruby-value">256</span>
+
+ <span class="ruby-identifier">catalog_sector</span>[<span class="ruby-identifier">catalog_slot</span>[<span class="ruby-value">2</span>],<span class="ruby-value">0x23</span>]=<span class="ruby-identifier">file_descriptive_entry</span>
+
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">set_sector</span>(<span class="ruby-identifier">file_system_image</span>,<span class="ruby-identifier">catalog_slot</span>[<span class="ruby-value">0</span>],<span class="ruby-identifier">catalog_slot</span>[<span class="ruby-value">1</span>],<span class="ruby-identifier">catalog_sector</span>)
+
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">"catalog not updated correctly!"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">find_catalog_slot</span>(<span class="ruby-identifier">file_system_image</span>,<span class="ruby-identifier">filename</span>).<span class="ruby-identifier">nil?</span>
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">"error: file should now be in catalog"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">files</span>(<span class="ruby-identifier">file_system_image</span>)[<span class="ruby-identifier">filename</span>].<span class="ruby-identifier">nil?</span>
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">native_file</span>
<span class="ruby-keyword kw">end</span></pre>
</body>
</html>
\ No newline at end of file