/***************************************
 * file - Standard File Functions for  *
 *        all Commodore 8 bit machines *
 ***************************************/

/* Device IDs */
enum {KEYBRD, CASST1, MODEM1, SCREEN,
      PRNTR1, PRNTR2, PRNTR3, PRNTR4,
      DRIVE1, DRIVE2, DRIVE3, DRIVE4,
      DRIVE5, DRIVE6, DRIVE7, DRIVE8};

#define MWRITE $80 //Open File for Write
#define MREAD  $00 //Open File for Read

#define MRELCT $00 //Relocate (Load at Specified Address)
#define MABSLT $80 //Absolute (Load at Address in File Header)


/* RS-232 Errors */

/* Other Errors */
#define ERRFNA $FF //Error - Function Not Available

/* Zero Page System Variables *
 * for diagnostic purposes    *
 * Names subject to change    */
char fsiost; //Kernal I/O Status Word
char fsnofl; //Number of Open I/O Files
char fslfno; //Current Logical File Number
char fsdvno; //Current Device Number
char fssadr; //Current Secondary Address
char fsfnlo,fsfnhi; //Pointer: Current Filename
char fsfnln; //Length of Current Filename
char fsrcvb; //Serial Bus Received Byte

/* System Variables */
char fsbufr[]; //String Concatenation Buffer
char fscntr; //Directory Entry Count

/* File Load                    *
 *   Loads File into Memory     *
 * Args: md - Mode | DriveID    *
 ^       &n - Filename          *
 * Returns: Error Code (0=None) *
 *          Load Address        */
char fload();

/* File Save                    *
 *   Save File from Memory      *
 * Args: md - Mode | driveid    *
 ^       &n - Filename          *
 * Returns: Error Code (0=None) */
char fsave();

/* File Open                              *
 *   Opens File Specified by Name         *
 * Args: m  - mode | driveid              *
 *       &f - string containing filename  *
 * Returns: file pointer if successful    *
            0 if an error occurs          */
char fopen();

/* File Close                             *
 *   Closes File Opened to File Pointer   *
 * Args: fp - file pointer                */
char fclose();

/* End of File                       *
 *   Check for End of File Condition *
 * Args: fp - file pointer           *
 * Returns: EOF Indicator            *
 *          (0 if not at end of file *
 *           255 if not implemented  *
             or non-zero EOF value)  */
char feof();

/* File Error                              *
 *   Check File Error Indicator            *
 * Args: fp - file pointer                 *
 *       &s - string for error text        *
 * Returns: platform specific error number *
 *          (0 if no error                 *
 *           255 if not implemented)       */
char ferror();

/* Flush File Buffer                       *
 *   Flush File Output Buffer              *
 * Args: fp - file pointer                 *
 * Returns: platform specific error number *
 *          (0 if no error)                */
char fflush();

/* Read Character from File                *
 * Args: fp - file pointer                 *
 * Returns: ASCII value of character,      *
 *          platform specific error number *
 *          (0 if no error                 *
 *           255 if not implemented)       */
char fgetc();

/* Load to Memory from File              *
 * Args: md - mode + device#             *
 *       &f - string containing filename *
 * Requires: setdst();                   *
 * Returns: platform specific error      *
 *          (0 if no error               *
 *           255 if not implemented)     *
 *          end address of load          */
char fload();

/* Write Character to File            *
 * Args: fp - file pointer            *
 *       c - ASCII character to write *
 * Returns: platform specific error   *
 *          (0 if no error            *
 *           255 if not implemented)  */
char fputc(); 

/* Read String from File               *
 *   Buffers up to 128 characters      *
 *   until C/R is pressed              *
 * Args: fp - file pointer             *
 *       &s - string read from file    *
 * Returns: number of characters read, *
 *          platform specific error    *
 *          (0 if no error             *
 *           255 if not implemented)   */
char fgets(); 

/* Write String to File               *
 *   Writes up to 128 characters of a *
 *   null terminated string           *
 * Args: fp - file pointer            *
 *       &s - string to print from    *
 * Returns: platform specific error   *
 *          (0 if no error            *
 *           255 if not implemented)  */
char fputs();

/* Write Line to File                     *
 *   Write String to File followed by C/R *
 * Args: fp - file pointer                *
 *       &s - string to print from        *
 * Returns: ending position in string     *
 *          255 if error during write     */
char fputln();

/* Read Bytes from File              *
 *   Reads until EOF is reached      *
 * Args: fp - file pointer           *
 *       n - number of bytes to read *
 * Requires: setdst();               *
 * Returns: number of bytes read,    *
 *          platform specific error  *
 *          (0 if no error           *
 *           255 if not implemented) */
char fread(); 

/* Save Memory to File                   *
 * Args: d - device#                     *
 *       &f - string containing filename *
 * Requires: setsrc(); setdst();         *
 * Returns: platform specific error      *
 *          (0 if no error               *
 *           255 if not implemented)     */
char fload();

/* Verify File against Memory            *
 * Args: md - mode + device#             *
 *       &f - string containing filename *
 * Requires: setdst();                   *
 * Returns: platform specific error      *
 *          (0 if no error               *
 *           255 if not implemented)     *
 *          end address of verify        */
char fload();

/* Write Bytes to File                *
 * Args: fp - file pointer            *
 *       n - number of bytes to write *
 * Requires: setdst();               *
 * Returns: number of bytes written,  *
 *          platform specific error   *
 *          (0 if no error            *
 *           255 if not implemented)  */
char fwrite();
