Jump to content

Component: File Access (File ): Difference between revisions

From Flowcode Help
No edit summary
m Text replacement - "width="90%" style="background-color:#D8C9D8; color:#4B008D;"" to "width="90%" class="mtx-class-macrohead""
 
(11 intermediate revisions by 3 users not shown)
Line 16: Line 16:


==Component Source Code==
==Component Source Code==
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_File.fcsx FC_Comp_Source_File.fcsx]


Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_File.fcsx FC_Comp_Source_File.fcsx]
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_File.fcsx FC_Comp_Source_File.fcsx]
Line 27: Line 29:




''No detailed description exists yet for this component''
==Examples==




Line 56: Line 45:




''No detailed description exists yet for this component''


Simple example App Developer file used with [[Component:_CSV_Read/Write_(File)|CVS Read/Write]] component to generate a two column CSV file that can be loaded into Microsoft Excel or LibreOffice Math.


''<span style="color:red;">No additional examples</span>''
For an embedded CSV read write see the [[Component:_Embed_File_(File)|File component]]


CSV Component used with App Developer -> File component: {{Fcfile|CSVTestAD.fcsx|CSV Test AD}}


==Macro reference==
==Macro reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===AppendByteToFile===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadStringFromFile'''
| width="90%" class="mtx-class-macrohead" | '''AppendByteToFile'''
|-
| colspan="2" | Reads a string from the currently open file. Auto increments the position in the file. An empty string signifies the end of the file has been reached.&nbsp;
|-
|-
| colspan="2" | Adds a single byte to the end of the currently open file, useful for inserting the value 0 into binary file types. Returns 0 for success.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | NumBytes
|-
| colspan="2" | Maximum number of bytes to attempt to read&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | EndChar
| width="90%" | Data
|-
|-
| colspan="2" | Ends the string if the value specified is found, default is 0&nbsp;
| colspan="2" | Data to append to the end of the file&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''MoveToNextFileSector'''
|-
| colspan="2" | Attempts to move to the next sector in the file. When reading a file you would leave force next sector set to 0. When writing a file you would  leave force next sector set to 1 to allow new sectors to be created as the file grows. Returns 0 for success&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Force_Next_Sector
|-
| colspan="2" | 0 = Don't add new sector, 1 = Add new sector if we are at the end of the file&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
Line 104: Line 74:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===AppendStringToFile===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WriteByteToBuffer'''
| width="90%" class="mtx-class-macrohead" | '''AppendStringToFile'''
|-
|-
| colspan="2" | Writes a single byte to the current 512 byte local sector buffer.&nbsp;
| colspan="2" | Adds the contents of the data string parameter to the end of the currently open file. Returns 0 for success.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Address
| width="90%" | Data_String
|-
| colspan="2" | Address Range 0 - 511&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Data
|-
| colspan="2" | Data Byte to write to the buffer&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AppendByteToFile'''
|-
| colspan="2" | Adds a single byte to the end of the currently open file, useful for inserting the value 0 into binary file types. Returns 0 for success.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Data
|-
|-
| colspan="2" | Data to append to the end of the file&nbsp;
| colspan="2" | Data to append to the end of the file&nbsp;
Line 145: Line 93:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===CloseFile===
|-
{| class="mtx-class-macrotable wikitable"
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadFileSector'''
|-
| colspan="2" | Overwrites local buffer with the current file sector from the disk. Used to restore the local sector buffer with the actual sector stored on the card. Return = 0 : Local buffer refreshed with current card sector  Return > 0 : Error&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CloseFile'''
| width="90%" class="mtx-class-macrohead" | '''CloseFile'''
|-
|-
| colspan="2" | Closes the currently opened file, releasing the file handle and allowing other applications to edit the file.&nbsp;
| colspan="2" | Closes the currently opened file, releasing the file handle and allowing other applications to edit the file.&nbsp;
Line 171: Line 107:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===CreateFile===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByteFromFile'''
| width="90%" class="mtx-class-macrohead" | '''CreateFile'''
|-
|-
| colspan="2" | Reads a byte from the currently open file. Auto increments the position in the file. A return value of 0 may signify the end of the file has been reached (depending on the contents of the file).&nbsp;
| colspan="2" | Creates a file in the current folder location on the card. Default = Root Returns 0 for success File must be opened using "Open_File" after creation before writing any data.&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''DeleteFile'''
|-
| colspan="2" | Searches for and deletes a file in the current folder location on the card. Default = Root Returns 0 for success.&nbsp;
|-
|-
|-
|-
Line 202: Line 126:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===DeleteFile===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByteFromIndex'''
| width="90%" class="mtx-class-macrohead" | '''DeleteFile'''
|-
|-
| colspan="2" | Reads an arbitrary byte of data from the current open file. Return = Data byte read from the local sector buffer.  Experimental and potentially slow if navigating backwards through the file.&nbsp;
| colspan="2" | Searches for and deletes a file in the current folder location on the card. Default = Root Returns 0 for success.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Address
| width="90%" | Filename
|-
|-
| colspan="2" | Contains the position of the byte to be read from the file&nbsp;
| colspan="2" | 8.3 format filename e.g."file.txt"&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
Line 220: Line 145:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===Initialise===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CreateFile'''
| width="90%" class="mtx-class-macrohead" | '''Initialise'''
|-
|-
| colspan="2" | Creates a file in the current folder location on the card. Default = Root Returns 0 for success File must be opened using "Open_File" after creation before writing any data.&nbsp;
| colspan="2" | Attempts to communicate with the SD card and if successful sets up the file system. Returns 0 for success. &nbsp;
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Filename
|-
| colspan="2" | 8.3 format filename e.g."file.txt"&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
Line 238: Line 159:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===MoveToNextFileSector===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ScanCurrentFolder'''
| width="90%" class="mtx-class-macrohead" | '''MoveToNextFileSector'''
|-
|-
| colspan="2" | Method for retreiving file or folder names for the card to allow for dynamic file opening or playback. Does not currently simulate. 0 - Filetype found and stored into string array, 1 - End of folder reached, 2 - Filetype mismatch 3 - Empty&nbsp;
| colspan="2" | Attempts to move to the next sector in the file. When reading a file you would leave force next sector set to 0. When writing a file you would  leave force next sector set to 1 to allow new sectors to be created as the file grows. Returns 0 for success&nbsp;
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Current_Idx
|-
| colspan="2" | Contains the current pointer in the directory table. Values from 0 to 511 to completley search the current folder for a files or folders&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Scan_Type
| width="90%" | Force_Next_Sector
|-
|-
| colspan="2" | Sets the scan to search for Files or Folders. 0 = Scan for files, 1 = Scan for folders&nbsp;
| colspan="2" | 0 = Don't add new sector, 1 = Add new sector if we are at the end of the file&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
Line 261: Line 178:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===OpenFile===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByteFromScan'''
| width="90%" class="mtx-class-macrohead" | '''OpenFile'''
|-
|-
| colspan="2" | Returns a byte of the name of the file or folder retreived from the Scan_Current_folder function. Return = ASCII byte at position Idx from the folder name or file name at position Current_Idx in the directory&nbsp;
| colspan="2" | Searches for and opens a file for reading or writing from within the current directory on the disk. Returns 0 for success.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | idx
| width="90%" | Filename
|-
|-
| colspan="2" | 0 - 11 for a file, 0 - 7 for a folder&nbsp;
| colspan="2" | 8.3 filename of the file we are trying to open e.g. "file.txt"&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
Line 279: Line 197:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===OpenFolder===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''OpenFolder'''
| width="90%" class="mtx-class-macrohead" | '''OpenFolder'''
|-
|-
| colspan="2" | ".." - Jumps up a directory, if at root then remains in root "root" - Jumps directly back to the root directory "foldername" - Opens folder named foldername&nbsp;
| colspan="2" | ".." - Jumps up a directory, if at root then remains in root "root" - Jumps directly back to the root directory "foldername" - Opens folder named foldername&nbsp;
Line 297: Line 216:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ReadByteFromBuffer===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByteFromBuffer'''
| width="90%" class="mtx-class-macrohead" | '''ReadByteFromBuffer'''
|-
|-
| colspan="2" | Reads a byte of data from the local sector buffer. Return = Data byte read from the local sector buffer. &nbsp;
| colspan="2" | Reads a byte of data from the local sector buffer. Return = Data byte read from the local sector buffer. &nbsp;
Line 315: Line 235:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ReadByteFromFile===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadFileLength'''
| width="90%" class="mtx-class-macrohead" | '''ReadByteFromFile'''
|-
|-
| colspan="2" | Returns the number of bytes in the current sector that are used by the current open file. Return = 512 - Sector is filled with file data Return < 512 - Last sector of the file, Retval specifies how many bytes of data are remaining in the sector&nbsp;
| colspan="2" | Reads a byte from the currently open file. Auto increments the position in the file. A return value of 0 may signify the end of the file has been reached (depending on the contents of the file).&nbsp;
|-
|-
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s16-icon.png]] - INT
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ReadByteFromIndex===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''OpenFile'''
| width="90%" class="mtx-class-macrohead" | '''ReadByteFromIndex'''
|-
|-
| colspan="2" | Searches for and opens a file for reading or writing from within the current directory on the disk. Returns 0 for success.&nbsp;
| colspan="2" | Reads an arbitrary byte of data from the current open file.  Return = Data byte read from the local sector buffer.   Experimental and potentially slow if navigating backwards through the file.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG
| width="90%" | Filename
| width="90%" | Address
|-
|-
| colspan="2" | 8.3 filename of the file we are trying to open e.g. "file.txt"&nbsp;
| colspan="2" | Contains the position of the byte to be read from the file&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
Line 346: Line 268:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ReadByteFromScan===
{| class="mtx-class-macrotable wikitable"
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" class="mtx-class-macrohead" | '''ReadByteFromScan'''
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| colspan="2" | Returns a byte of the name of the file or folder retreived from the Scan_Current_folder function. Return = ASCII byte at position Idx from the folder name or file name at position Current_Idx in the directory&nbsp;
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WriteFileSector'''
|-
|-
| colspan="2" | Overwrites the current sector on the memory card with the contents of the local sector buffer. See write_byte_to_buffer function. Return = 0 - File sector written successfully. Return > 0 - File sector write error&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | idx
|-
| colspan="2" | 0 - 11 for a file, 0 - 7 for a folder&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
Line 359: Line 287:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ReadFileLength===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetFileIndex'''
| width="90%" class="mtx-class-macrohead" | '''ReadFileLength'''
|-
|-
| colspan="2" | Sets the current file index and used to switch between several open file streams. Default = 0. &nbsp;
| colspan="2" | Returns the number of bytes in the current sector that are used by the current open file. Return = 512 - Sector is filled with file data Return < 512 - Last sector of the file, Retval specifies how many bytes of data are remaining in the sector&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s16-icon.png]] - INT
| width="90%" | File_Index
|-
| colspan="2" | File index ranges from 0 to (Max Concurrent Files - 1)&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ReadFileSector===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AppendStringToFile'''
| width="90%" class="mtx-class-macrohead" | '''ReadFileSector'''
|-
|-
| colspan="2" | Adds the contents of the data string parameter to the end of the currently open file. Returns 0 for success.&nbsp;
| colspan="2" | Overwrites local buffer with the current file sector from the disk. Used to restore the local sector buffer with the actual sector stored on the card. Return = 0 : Local buffer refreshed with current card sector  Return > 0 : Error&nbsp;
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Data_String
|-
| colspan="2" | Data to append to the end of the file&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
Line 395: Line 315:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ReadFileSize===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadFileSize'''
| width="90%" class="mtx-class-macrohead" | '''ReadFileSize'''
|-
|-
| colspan="2" | Reads the entire size of the current file in bytes.&nbsp;
| colspan="2" | Reads the entire size of the current file in bytes.&nbsp;
Line 408: Line 329:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ReadStringFromFile===
|-
{| class="mtx-class-macrotable wikitable"
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetTimeAndDate'''
|-
| colspan="2" | Sets the current time and date.  Time = (Hour << 11) + (Min << 5) + (Sec >> 1) Date = (YearFrom1980 << 9) + (Month << 5) + (Day) Additional details can be found here: http://www.maverick-os.dk/FileSystemFormats/FAT16_FileSystem.html#TimeFormat&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Time
|-
| colspan="2" | Sets the current Time in FAT Time format hhhhhmmmmmmsssss - S=Secs/2&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Date
|-
| colspan="2" | Sets the current Date in FAT Date format yyyyyyymmmmddddd - Y=Years since 1980&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
|-
| colspan="2" | Attempts to communicate with the SD card and if successful sets up the file system. Returns 0 for success. &nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
 
 
==Property reference==
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''
| width="90%" class="mtx-class-macrohead" | '''ReadStringFromFile'''
|-
|-
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| width="90%" | Max Concurrent Files
|-
| colspan="2" | Specifies how many concurrent files can be opened at any one time. Use the SetFileIndex macro to switch between concurrent files.&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="90%" | End Of File
|-
| colspan="2" | Specifies the way the ReadByteFromFile function indicates the end of a file. 8 Bit mode - End of the file is represented by the value 0, read multiple times to confirm that the 0 is not simply data. 16 Bit mode - End of file is represented by the value 512 allowing the values 0 - 255 to represent valid data.&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-type-20-icon.png]]
| width="90%" | Root Directory
|-
| colspan="2" | Directory flagged as root for simulation Default: $(srcdir) is the current project source directory.  Modern windows systems do not like you writing files to a hard drive root directory so a directory off the root is advised.&nbsp;
|}==Macro reference==
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadStringFromFile'''
|-
|-
| colspan="2" | Reads a string from the currently open file. Auto increments the position in the file. An empty string signifies the end of the file has been reached.&nbsp;
| colspan="2" | Reads a string from the currently open file. Auto increments the position in the file. An empty string signifies the end of the file has been reached.&nbsp;
Line 493: Line 353:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ScanCurrentFolder===
|-
{| class="mtx-class-macrotable wikitable"
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''MoveToNextFileSector'''
|-
| colspan="2" | Attempts to move to the next sector in the file. When reading a file you would leave force next sector set to 0. When writing a file you would  leave force next sector set to 1 to allow new sectors to be created as the file grows. Returns 0 for success&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Force_Next_Sector
|-
| colspan="2" | 0 = Don't add new sector, 1 = Add new sector if we are at the end of the file&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WriteByteToBuffer'''
|-
| colspan="2" | Writes a single byte to the current 512 byte local sector buffer.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Address
|-
| colspan="2" | Address Range 0 - 511&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Data
|-
| colspan="2" | Data Byte to write to the buffer&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AppendByteToFile'''
|-
| colspan="2" | Adds a single byte to the end of the currently open file, useful for inserting the value 0 into binary file types. Returns 0 for success.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Data
|-
| colspan="2" | Data to append to the end of the file&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadFileSector'''
|-
| colspan="2" | Overwrites local buffer with the current file sector from the disk. Used to restore the local sector buffer with the actual sector stored on the card. Return = 0 : Local buffer refreshed with current card sector  Return > 0 : Error&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CloseFile'''
|-
| colspan="2" | Closes the currently opened file, releasing the file handle and allowing other applications to edit the file.&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByteFromFile'''
|-
| colspan="2" | Reads a byte from the currently open file. Auto increments the position in the file. A return value of 0 may signify the end of the file has been reached (depending on the contents of the file).&nbsp;
|-
|-
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" class="mtx-class-macrohead" | '''ScanCurrentFolder'''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''DeleteFile'''
|-
| colspan="2" | Searches for and deletes a file in the current folder location on the card. Default = Root Returns 0 for success.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Filename
|-
| colspan="2" | 8.3 format filename e.g."file.txt"&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByteFromIndex'''
|-
| colspan="2" | Reads an arbitrary byte of data from the current open file.  Return = Data byte read from the local sector buffer.  Experimental and potentially slow if navigating backwards through the file.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG
| width="90%" | Address
|-
| colspan="2" | Contains the position of the byte to be read from the file&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CreateFile'''
|-
| colspan="2" | Creates a file in the current folder location on the card. Default = Root Returns 0 for success File must be opened using "Open_File" after creation before writing any data.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Filename
|-
| colspan="2" | 8.3 format filename e.g."file.txt"&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ScanCurrentFolder'''
|-
|-
| colspan="2" | Method for retreiving file or folder names for the card to allow for dynamic file opening or playback. Does not currently simulate. 0 - Filetype found and stored into string array, 1 - End of folder reached, 2 - Filetype mismatch 3 - Empty&nbsp;
| colspan="2" | Method for retreiving file or folder names for the card to allow for dynamic file opening or playback. Does not currently simulate. 0 - Filetype found and stored into string array, 1 - End of folder reached, 2 - Filetype mismatch 3 - Empty&nbsp;
Line 668: Line 377:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===SetFileIndex===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByteFromScan'''
| width="90%" class="mtx-class-macrohead" | '''SetFileIndex'''
|-
| colspan="2" | Returns a byte of the name of the file or folder retreived from the Scan_Current_folder function. Return = ASCII byte at position Idx from the folder name or file name at position Current_Idx in the directory&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | idx
|-
| colspan="2" | 0 - 11 for a file, 0 - 7 for a folder&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''OpenFolder'''
|-
| colspan="2" | ".." - Jumps up a directory, if at root then remains in root "root" - Jumps directly back to the root directory "foldername" - Opens folder named foldername&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Folder_Name
|-
| colspan="2" | &nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByteFromBuffer'''
|-
| colspan="2" | Reads a byte of data from the local sector buffer. Return = Data byte read from the local sector buffer. &nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Address
|-
| colspan="2" | 0 - 511 - Contains the position of the byte to be read&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadFileLength'''
|-
| colspan="2" | Returns the number of bytes in the current sector that are used by the current open file. Return = 512 - Sector is filled with file data Return < 512 - Last sector of the file, Retval specifies how many bytes of data are remaining in the sector&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s16-icon.png]] - INT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''OpenFile'''
|-
| colspan="2" | Searches for and opens a file for reading or writing from within the current directory on the disk. Returns 0 for success.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Filename
|-
| colspan="2" | 8.3 filename of the file we are trying to open e.g. "file.txt"&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WriteFileSector'''
|-
| colspan="2" | Overwrites the current sector on the memory card with the contents of the local sector buffer. See write_byte_to_buffer function. Return = 0 - File sector written successfully. Return > 0 - File sector write error&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetFileIndex'''
|-
|-
| colspan="2" | Sets the current file index and used to switch between several open file streams.  Default = 0. &nbsp;
| colspan="2" | Sets the current file index and used to switch between several open file streams.  Default = 0. &nbsp;
Line 784: Line 396:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===SetTimeAndDate===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AppendStringToFile'''
| width="90%" class="mtx-class-macrohead" | '''SetTimeAndDate'''
|-
|-
| colspan="2" | Adds the contents of the data string parameter to the end of the currently open file. Returns 0 for success.&nbsp;
| colspan="2" | Sets the current time and date.  Time = (Hour << 11) + (Min << 5) + (Sec >> 1) Date = (YearFrom1980 << 9) + (Month << 5) + (Day) Additional details can be found here: http://www.maverick-os.dk/FileSystemFormats/FAT16_FileSystem.html#TimeFormat&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Data_String
| width="90%" | Time
|-
|-
| colspan="2" | Data to append to the end of the file&nbsp;
| colspan="2" | Sets the current Time in FAT Time format hhhhhmmmmmmsssss - S=Secs/2&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" | Date
|}
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| colspan="2" | Sets the current Date in FAT Date format yyyyyyymmmmddddd - Y=Years since 1980&nbsp;
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadFileSize'''
|-
|-
| colspan="2" | Reads the entire size of the current file in bytes.&nbsp;
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u32-icon.png]] - ULONG
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===WriteByteToBuffer===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetTimeAndDate'''
| width="90%" class="mtx-class-macrohead" | '''WriteByteToBuffer'''
|-
|-
| colspan="2" | Sets the current time and date. Time = (Hour << 11) + (Min << 5) + (Sec >> 1) Date = (YearFrom1980 << 9) + (Month << 5) + (Day) Additional details can be found here: http://www.maverick-os.dk/FileSystemFormats/FAT16_FileSystem.html#TimeFormat&nbsp;
| colspan="2" | Writes a single byte to the current 512 byte local sector buffer.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Time
| width="90%" | Address
|-
|-
| colspan="2" | Sets the current Time in FAT Time format hhhhhmmmmmmsssss - S=Secs/2&nbsp;
| colspan="2" | Address Range 0 - 511&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Date
| width="90%" | Data
|-
|-
| colspan="2" | Sets the current Date in FAT Date format yyyyyyymmmmddddd - Y=Years since 1980&nbsp;
| colspan="2" | Data Byte to write to the buffer&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
Line 838: Line 444:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===WriteFileSector===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
| width="90%" class="mtx-class-macrohead" | '''WriteFileSector'''
|-
|-
| colspan="2" | Attempts to communicate with the SD card and if successful sets up the file system. Returns 0 for success. &nbsp;
| colspan="2" | Overwrites the current sector on the memory card with the contents of the local sector buffer. See write_byte_to_buffer function. Return = 0 - File sector written successfully. Return > 0 - File sector write error&nbsp;
|-
|-
|-
|-
Line 849: Line 456:
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




==Property reference==
==Property reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''  
| width="90%" class="mtx-class-macrohead" | '''Properties'''  
|-
|-
|-
|-

Latest revision as of 14:22, 13 July 2026

Author Matrix TSL
Version 1.0
Category File


File Access component

File component allowing access to read and write files on the local Windows file system. Only available in simulation runtime mode, cannot be downloaded to hardware. Compatible with File (SD Card) embedded component.

Component Source Code

Please click here to download the component source project: FC_Comp_Source_File.fcsx

Please click here to view the component source code (Beta): FC_Comp_Source_File.fcsx

Detailed description

No detailed description exists yet for this component

Simple example App Developer file used with CVS Read/Write component to generate a two column CSV file that can be loaded into Microsoft Excel or LibreOffice Math.

For an embedded CSV read write see the File component

CSV Component used with App Developer -> File component: CSV Test AD

Macro reference

AppendByteToFile

AppendByteToFile
Adds a single byte to the end of the currently open file, useful for inserting the value 0 into binary file types. Returns 0 for success. 
- BYTE Data
Data to append to the end of the file 
- BYTE Return


AppendStringToFile

AppendStringToFile
Adds the contents of the data string parameter to the end of the currently open file. Returns 0 for success. 
- STRING Data_String
Data to append to the end of the file 
- BYTE Return


CloseFile

CloseFile
Closes the currently opened file, releasing the file handle and allowing other applications to edit the file. 
- VOID Return


CreateFile

CreateFile
Creates a file in the current folder location on the card. Default = Root Returns 0 for success File must be opened using "Open_File" after creation before writing any data. 
- STRING Filename
8.3 format filename e.g."file.txt" 
- BYTE Return


DeleteFile

DeleteFile
Searches for and deletes a file in the current folder location on the card. Default = Root Returns 0 for success. 
- STRING Filename
8.3 format filename e.g."file.txt" 
- BYTE Return


Initialise

Initialise
Attempts to communicate with the SD card and if successful sets up the file system. Returns 0 for success.  
- BYTE Return


MoveToNextFileSector

MoveToNextFileSector
Attempts to move to the next sector in the file. When reading a file you would leave force next sector set to 0. When writing a file you would leave force next sector set to 1 to allow new sectors to be created as the file grows. Returns 0 for success 
- BYTE Force_Next_Sector
0 = Don't add new sector, 1 = Add new sector if we are at the end of the file 
- BYTE Return


OpenFile

OpenFile
Searches for and opens a file for reading or writing from within the current directory on the disk. Returns 0 for success. 
- STRING Filename
8.3 filename of the file we are trying to open e.g. "file.txt" 
- BYTE Return


OpenFolder

OpenFolder
".." - Jumps up a directory, if at root then remains in root "root" - Jumps directly back to the root directory "foldername" - Opens folder named foldername 
- STRING Folder_Name
 
- BYTE Return


ReadByteFromBuffer

ReadByteFromBuffer
Reads a byte of data from the local sector buffer. Return = Data byte read from the local sector buffer.  
- UINT Address
0 - 511 - Contains the position of the byte to be read 
- BYTE Return


ReadByteFromFile

ReadByteFromFile
Reads a byte from the currently open file. Auto increments the position in the file. A return value of 0 may signify the end of the file has been reached (depending on the contents of the file). 
- UINT Return


ReadByteFromIndex

ReadByteFromIndex
Reads an arbitrary byte of data from the current open file. Return = Data byte read from the local sector buffer. Experimental and potentially slow if navigating backwards through the file. 
- ULONG Address
Contains the position of the byte to be read from the file 
- BYTE Return


ReadByteFromScan

ReadByteFromScan
Returns a byte of the name of the file or folder retreived from the Scan_Current_folder function. Return = ASCII byte at position Idx from the folder name or file name at position Current_Idx in the directory 
- BYTE idx
0 - 11 for a file, 0 - 7 for a folder 
- BYTE Return


ReadFileLength

ReadFileLength
Returns the number of bytes in the current sector that are used by the current open file. Return = 512 - Sector is filled with file data Return < 512 - Last sector of the file, Retval specifies how many bytes of data are remaining in the sector 
- INT Return


ReadFileSector

ReadFileSector
Overwrites local buffer with the current file sector from the disk. Used to restore the local sector buffer with the actual sector stored on the card. Return = 0 : Local buffer refreshed with current card sector Return > 0 : Error 
- BYTE Return


ReadFileSize

ReadFileSize
Reads the entire size of the current file in bytes. 
- ULONG Return


ReadStringFromFile

ReadStringFromFile
Reads a string from the currently open file. Auto increments the position in the file. An empty string signifies the end of the file has been reached. 
- UINT NumBytes
Maximum number of bytes to attempt to read 
- BYTE EndChar
Ends the string if the value specified is found, default is 0 
- STRING Return


ScanCurrentFolder

ScanCurrentFolder
Method for retreiving file or folder names for the card to allow for dynamic file opening or playback. Does not currently simulate. 0 - Filetype found and stored into string array, 1 - End of folder reached, 2 - Filetype mismatch 3 - Empty 
- UINT Current_Idx
Contains the current pointer in the directory table. Values from 0 to 511 to completley search the current folder for a files or folders 
- BYTE Scan_Type
Sets the scan to search for Files or Folders. 0 = Scan for files, 1 = Scan for folders 
- BYTE Return


SetFileIndex

SetFileIndex
Sets the current file index and used to switch between several open file streams. Default = 0.  
- BYTE File_Index
File index ranges from 0 to (Max Concurrent Files - 1) 
- VOID Return


SetTimeAndDate

SetTimeAndDate
Sets the current time and date. Time = (Hour << 11) + (Min << 5) + (Sec >> 1) Date = (YearFrom1980 << 9) + (Month << 5) + (Day) Additional details can be found here: http://www.maverick-os.dk/FileSystemFormats/FAT16_FileSystem.html#TimeFormat 
- UINT Time
Sets the current Time in FAT Time format hhhhhmmmmmmsssss - S=Secs/2 
- UINT Date
Sets the current Date in FAT Date format yyyyyyymmmmddddd - Y=Years since 1980 
- VOID Return


WriteByteToBuffer

WriteByteToBuffer
Writes a single byte to the current 512 byte local sector buffer. 
- UINT Address
Address Range 0 - 511 
- BYTE Data
Data Byte to write to the buffer 
- VOID Return


WriteFileSector

WriteFileSector
Overwrites the current sector on the memory card with the contents of the local sector buffer. See write_byte_to_buffer function. Return = 0 - File sector written successfully. Return > 0 - File sector write error 
- BYTE Return


Property reference

Properties
Max Concurrent Files
Specifies how many concurrent files can be opened at any one time. Use the SetFileIndex macro to switch between concurrent files. 
End Of File
Specifies the way the ReadByteFromFile function indicates the end of a file. 8 Bit mode - End of the file is represented by the value 0, read multiple times to confirm that the 0 is not simply data. 16 Bit mode - End of file is represented by the value 512 allowing the values 0 - 255 to represent valid data. 
Root Directory
Directory flagged as root for simulation Default: $(srcdir) is the current project source directory. Modern windows systems do not like you writing files to a hard drive root directory so a directory off the root is advised.