Sim68K File I/O


TRAP #15 is used for I/O.  Put the task number in D0.

The success of the file handling calls is returned in D0.W as follows:
    0 = success
    1 = EOF encountered
    2 = Error
    3 = File is Read Only (Task 51 & 59 only)

    A maximum of 8 files may be open at any one time. 

 Task

 50

 Close all files. It is recommended to use this at the start of any program using file handling.

 51

 Open existing file.
     Pre: (A1) null terminated file name.
     Post: D1.L contains the File-ID (FID).

 52

 Open new file..
    As above except the file is created if not found.
    If the file exists it will be overwritten.

 53

 Read file
    Pre: File-ID in D1.L as returned from 51 or 52,
           (A1) buffer address,
           D2.L number of bytes to read.
    Post: D2.L holds number of bytes actually read,
    EOF may cause a shortened read.

 54

 Write file
    As above except D2.L holds number of bytes to write (unaltered upon return).

 55

 Position file
    Sets the file position where the next read/write will take place. Files begin at byte 0.
    Pre: File-ID in D1.L as returned from 51 or 52,
           D2.L the file position to be set.

 56

 Close file
    Pre: File-ID in D1.L as returned from 51 or 52.

 57

 Delete file. 
    Pre: (A1) null terminated file name.

 58  Display File Dialog. 
    Pre:  D1 = 0 to display 'Open' dialog
            D1 = 1 to display 'Save' dialog
            (A1) Points to a null terminated string that will be used as the request title string (max 256)
                   or A1 = $00000000 to use the default 'Open' or 'Save' depending on D1
            (A2) Points to a null terminated string (max 256) containing semicolon separated list of file extensions
                   for use in dialog, e.g. '*.txt;*.pcb',0 or A2 = $00000000 for all file types.
            (A3) Points to a buffer of sufficient size (max 256) to hold the zero terminated full file path and name.
                  On calling, if this contains a file path and name this will be used as the original file path and name.
                  If the user exits via the cancel button this buffer will remain unchanged.
    Post: D1 = 0 if user cancelled or just closed
             D1 = 1 if user hit open/save
 59  File operations.
     Pre: (A1) null terminated file name.
            D1.L = 0 does file exist?
     Post: D0.W 0 = file exists
                       2 = Error
                       3 = file exists and is Read Only
    Other values of D1 reserved for future use.