⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesys_8c-source.html

📁 MP3播放器源代码, VS1003B
💻 HTML
📖 第 1 页 / 共 5 页
字号:
00452     }<span class="keywordflow">else</span>{ <span class="comment">//FAT32</span>00453       next.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o4">Fat32Table</a>[entryNumber]&amp;0x0fffffff;00454     }00455     <span class="comment">/* next.l is the FAT entry (next cluster number) */</span>00456     00457     00458     ConsoleWrite(<span class="stringliteral">"\rFragment start: cluster "</span>);00459     ConsolePutUInt(<span class="keyword">this</span>.l);00460     ConsoleWrite(<span class="stringliteral">"sector "</span>);00461     ConsolePutUInt(<a class="code" href="filesys_8c.html#a6">fragment</a>[c].start);00462 00463     <span class="keywordflow">while</span> (next.<a class="code" href="unionAddress.html#o0">l</a>==(<span class="keyword">this</span>.l+1)){00464       <span class="comment">//Not a fragment break -- continue to next entry </span>00465 00466       <span class="comment">//in this temp.l is used only to allow compiler memory spilling to temp</span>00467       <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o2">l</a> = <a class="code" href="filesys_8c.html#a6">fragment</a>[c].<a class="code" href="structfragmentEntry.html#o1">length</a>;00468       <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o2">l</a> += <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;00469       <a class="code" href="filesys_8c.html#a6">fragment</a>[c].<a class="code" href="structfragmentEntry.html#o1">length</a> = <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o2">l</a>;00470 00471       entryNumber++;00472 00473       <span class="comment">// --- Check for a page break</span>00474       <span class="keywordflow">if</span> (entryNumber==0){ <span class="comment">//entryNumber has rolled over!!!! (8bit char)</span>00475         <span class="comment">//FAT16 table page border is reached</span>00476         fatSector.<a class="code" href="unionAddress.html#o0">l</a>++; <span class="comment">//Advance to next page;</span>00477         entryNumber=0;00478         <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(fatSector.<a class="code" href="unionAddress.html#o0">l</a>);00479       }00480       <span class="keywordflow">if</span> (<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a> &amp;&amp; (entryNumber==128)){00481         <span class="comment">//FAT32 table page border is reached</span>00482         fatSector.<a class="code" href="unionAddress.html#o0">l</a>++;00483         entryNumber=0;00484         <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(fatSector.<a class="code" href="unionAddress.html#o0">l</a>);00485       }00486       00487       <span class="comment">// --- Advance to next cluster</span>00488       <span class="keyword">this</span>.l = next.<a class="code" href="unionAddress.html#o0">l</a>;00489       00490       <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){00491         <span class="comment">//FAT16 get next cluster n</span>00492         next.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o3">Fat16Table</a>[entryNumber];       00493         <span class="keywordflow">if</span> ((next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o1">b1</a>==0xff)&amp;&amp;(next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a>==0xff)){00494           <span class="comment">//FAT16 end-of-file</span>00495           next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a> = 0xff; <span class="comment">//mark end-of-file (FAT32 compatible)</span>00496         }00497       }<span class="keywordflow">else</span>{00498         <span class="comment">//FAT32 get next cluster n</span>00499         next.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o4">Fat32Table</a>[entryNumber];00500       }00501     }<span class="comment">//This repeats until there is a discontinuity</span>00502     00503     <span class="comment">/* next.l now has the cluster entry for last cluster in fragment</span>00504 <span class="comment">       it has a high value if eof (see FAT spec) */</span>00505 00506     00507     ConsoleWrite(<span class="stringliteral">"Size: "</span>);00508     ConsolePutUInt(<a class="code" href="filesys_8c.html#a6">fragment</a>[c].length);00509     ConsoleWrite(<span class="stringliteral">"sectors."</span>);00510 00511     <span class="comment">//EOF test</span>00512     <span class="keywordflow">if</span> ((next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a>&amp;0x08) <span class="comment">//Quick test</span>00513         &amp;&amp; ((next.<a class="code" href="unionAddress.html#o0">l</a>&gt;0x0ffffff0) | !<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>)){ <span class="comment">//Complete test</span>00514       <span class="comment">//EOF</span>00515       ConsoleWrite(<span class="stringliteral">" &lt;EOF&gt;\r"</span>);00516       <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a> = 0xff;00517     }<span class="keywordflow">else</span>{00518       00519       <span class="comment">//Determine next physical sector for next fragment</span>00520       <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = next.<a class="code" href="unionAddress.html#o0">l</a>;00521       <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> *= <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;00522       <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> += <a class="code" href="filesys_8c.html#a4">dataStart</a>;00523     }00524     00525     c++; <span class="comment">//Advance to next fragment number</span>00526     00527     <span class="keywordflow">if</span> (c==<a class="code" href="filesys_8c.html#a0">MAX_NUMBER_FRAGMENTS</a>){00528       <span class="comment">//End of RAM space allocated for fragment table</span>00529       <span class="comment">//Force end-of-file</span>00530       <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a>=0xff;00531     }00532     00533   }<span class="comment">//break or continue to next cluster</span>00534   00535   <span class="keywordflow">return</span> c; <span class="comment">//Return number of fragments;</span>00536 }00537 00538 00539 <a name="l00541"></a><a class="code" href="filesys_8c.html#a20">00541</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="filesys_8c.html#a20">LoadNextSector</a>(){00542   <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="filesys_8c.html#a18">GetNextSector</a>(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>);00543   <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o1">b1</a> &amp; 0x80){00545     <span class="keywordflow">return</span> 0x0d; <span class="comment">/*EOF*/</span>00546   }00547   <span class="keywordflow">if</span> (<a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>)){00548     <span class="keywordflow">return</span> 0x0d; <span class="comment">/*EOF*/</span>00549   }00550   <span class="keywordflow">return</span> 0; <span class="comment">/* All OK return */</span>00551 }00552   <a name="l00561"></a><a class="code" href="filesys_8h.html#a9">00561</a> <a class="code" href="board_8h.html#a47">Public</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="filesys_8c.html#a21">FGetChar</a>(){00562 00563   <span class="keywordflow">if</span> (!<a class="code" href="filesys_8c.html#a7">fileSize</a>) <span class="keywordflow">return</span> 0; <span class="comment">//return 0 for end-of-file</span>00564 00565   <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>==0){00566     <span class="comment">/* A file has been opened but not read from yet, so read the first</span>00567 <span class="comment">       sector. */</span>00568     <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>);00569     <a class="code" href="buffer_8c.html#a1">dataBufPtr</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o1">raw</a>.<a class="code" href="structDiskBlock_1_1Raw.html#o0">buf</a>;00570   }00571 00572   <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>&gt;<a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o1">raw</a>.<a class="code" href="structDiskBlock_1_1Raw.html#o0">buf</a>+511){00573     <span class="comment">/* An end of sector has been reached, read the next sector */</span>    00574     <span class="keywordflow">if</span> (<a class="code" href="filesys_8c.html#a20">LoadNextSector</a>()){00575       <span class="comment">/* Error, end-of-file according to FAT records */</span>00576       <span class="keywordflow">return</span> 0; <span class="comment">/* must return something */</span>00577     }00578     <a class="code" href="buffer_8c.html#a1">dataBufPtr</a>=<a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o1">raw</a>.<a class="code" href="structDiskBlock_1_1Raw.html#o0">buf</a>;00579   }00580 00581   <span class="comment">/* Everything should now be ok for reading a byte. */</span>00582 00583   <a class="code" href="filesys_8c.html#a7">fileSize</a>--;00584   <span class="keywordflow">return</span> (*<a class="code" href="buffer_8c.html#a1">dataBufPtr</a>++);00585 }00586 00587 00588 <a name="l00610"></a><a class="code" href="filesys_8h.html#a8">00610</a> <a class="code" href="board_8h.html#a47">Public</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="filesys_8h.html#a8">OpenFile</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> fileNumber){00611   <span class="keywordtype">char</span> tempc;00612 00613   ConsoleWrite(<span class="stringliteral">"\rFilesystem: Looking for file "</span>);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -