/* Original code (c) Acorn Computers Ltd, 1992-3 */

/* $Id: h.interface 3.1 93/03/09 23:32:18 brian Exp $ */
#ifndef __interface_h
#define __interface_h

#ifndef _kernel_HOST_UNDEFINED
#include "kernel.h"
#endif

typedef int YesNoAnswer;
#define No (0)
#define Yes (!No)

typedef int FileSwitchHandle;
typedef int FileSystemHandle;

typedef union Information_Fields
{
        struct
        {
                char                    *load_address;
                char                    *execute_address;
        }       load_exec;
        struct
        {
                int                     part_1;
                int                     part_2;
        }       date_type;
}       Information_Fields;

typedef enum FSEntry_Open_Reason
{
        FSEntry_Open_Reason_OpenRead = 0,
        FSEntry_Open_Reason_CreateUpdate = 1,
        FSEntry_Open_Reason_Update = 2
}       FSEntry_Open_Reason;

#define InformationWord_WritePermitted                  0x80000000
#define InformationWord_ReadPermitted                   0x40000000
#define InformationWord_ObjectIsDirectory               0x20000000
#define InformationWord_UnbufferedOS_GBPBSupported      0x10000000
#define InformationWord_StreamIsInteractive             0x08000000

typedef union FSEntry_Open_Parameter
{
        struct  open_definition
        {
                FSEntry_Open_Reason     reason;
                char                    *filename;
                int                     padding_1;
                FileSwitchHandle        handle;
                int                     padding_4;
                int                     padding_5;
                char                    *special_field;
        }       open_definition;
        struct  open_result
        {
                int                     information_word;
                FileSystemHandle        handle;
                int                     buffer_size;
                int                     file_extent;
                int                     allocated_space;
        }       open_result;
}       FSEntry_Open_Parameter;
typedef _kernel_oserror *(FSEntry_Open_Function)( FSEntry_Open_Parameter * );

typedef union FSEntry_GetBytes_Parameter
{
        struct
        {
                int                     filler;
                FileSystemHandle        handle;
                char                    *destination_start;
                int                     bytes_to_read;
                int                     file_offset_to_get_data_from;
        }       getbytes_definition;
        struct
        {
                int                     byte_got;
                YesNoAnswer             got_the_byte;
        }       getbytes_result;
}       FSEntry_GetBytes_Parameter;
typedef _kernel_oserror *(FSEntry_GetBytes_Function)( FSEntry_GetBytes_Parameter * );

typedef struct FSEntry_PutBytes_Parameter
{
        char                            byte_to_put;
        char                            filler_1;
        char                            filler_2;
        char                            filler_3;
        FileSystemHandle                handle;
        char                            *source_start;
        int                             bytes_to_write;
        int                             file_offset_to_put_data_to;
}       FSEntry_PutBytes_Parameter;
typedef _kernel_oserror *(FSEntry_PutBytes_Function)( FSEntry_PutBytes_Parameter * );

typedef enum FSEntry_Args_Reason
{
        FSEntry_Args_Reason_ReadSequentialFilePointer = 0,
        FSEntry_Args_Reason_WriteSequentialFilePointer = 1,
        FSEntry_Args_Reason_ReadFileExtent = 2,
        FSEntry_Args_Reason_WriteFileExtent = 3,
        FSEntry_Args_Reason_ReadSizeAllocatedToFile = 4,
        FSEntry_Args_Reason_EOFCheck = 5,
        FSEntry_Args_Reason_FlushFileBuffer = 6,
        FSEntry_Args_Reason_EnsureFileSize = 7,
        FSEntry_Args_Reason_WriteZerosToFile = 8,
        FSEntry_Args_Reason_ReadFileDateStamp = 9,
        FSEntry_Args_Reason_InformOfNewImageStamp = 10
}       FSEntry_Args_Reason;

typedef struct FSEntry_Args_Parameter
{
        FSEntry_Args_Reason             reason;
        union
        {
                FileSystemHandle        handle;
                YesNoAnswer             Not_Yet_EOF;
        }       _;
        union
        {
                int                     sequential_pointer;
                int                     extent;
                int                     allocation_size;
                Information_Fields      info;
                struct
                {
                        int             start;
                        int             number;
                }       write_zeros;
                int                     new_image_stamp;
        }       arg;
}       FSEntry_Args_Parameter;
typedef _kernel_oserror *(FSEntry_Args_Function)( FSEntry_Args_Parameter * );

typedef struct FSEntry_Close_Parameter
{
        int                             padding;
        FileSystemHandle                handle;
        Information_Fields              info;
}       FSEntry_Close_Parameter;
typedef _kernel_oserror *(FSEntry_Close_Function)( FSEntry_Close_Parameter * );

typedef enum FSEntry_File_Reason
{
        FSEntry_File_Reason_LoadFile = 0xff,
        FSEntry_File_Reason_SaveFile = 0,
        FSEntry_File_Reason_WriteCatalogueInformation = 1,
        FSEntry_File_Reason_WriteLoadAddress = 2,
        FSEntry_File_Reason_WriteExecutionAddress = 3,
        FSEntry_File_Reason_WriteAttributes = 4,
        FSEntry_File_Reason_ReadCatalogueInformation = 5,
        FSEntry_File_Reason_DeleteObject = 6,
        FSEntry_File_Reason_CreateFile = 7,
        FSEntry_File_Reason_CreateDirectory = 8,
        FSEntry_File_Reason_ReadCatalogueInformationNoLength = 9,
        FSEntry_File_Reason_ReadBlockSize = 10
}       FSEntry_File_Reason;

typedef struct FSEntry_File_Parameter
{
        FSEntry_File_Reason             reason;
        char                            *name;
        Information_Fields              info;
        union
        {
                struct
                {
                        int             length;
                        int             attributes;
                }       info;
                struct
                {
                        char            *start;
                        char            *end;
                }       location;
        }       extras;
        char                            *special_field;
}       FSEntry_File_Parameter;
typedef _kernel_oserror *(FSEntry_File_Function)( FSEntry_File_Parameter * );

typedef enum FSEntry_Func_Reason
{
        FSEntry_Func_Reason_SetCurrentDirectory = 0,
        FSEntry_Func_Reason_SetLibraryDirectory = 1,
        FSEntry_Func_Reason_CatalogueDirectory = 2,
        FSEntry_Func_Reason_ExamineCurrentDirectory = 3,
        FSEntry_Func_Reason_CatalogueLibraryDirectory = 4,
        FSEntry_Func_Reason_ExamineLibraryDirectory = 5,
        FSEntry_Func_Reason_ExamineObjects = 6,
        FSEntry_Func_Reason_SetFilingSystemOptions = 7,
        FSEntry_Func_Reason_RenameObject = 8,
        FSEntry_Func_Reason_AccessObjects = 9,
        FSEntry_Func_Reason_BootFilingSystem = 10,
        FSEntry_Func_Reason_ReadNameAndBootOptionOfDisc = 11,
        FSEntry_Func_Reason_ReadCurrentDirectoryNameAndPrivilegeByte = 12,
        FSEntry_Func_Reason_ReadLibraryDirectoryNameAndPrivilegeByte = 13,
        FSEntry_Func_Reason_ReadDirectoryEntries = 14,
        FSEntry_Func_Reason_ReadDirectoriesAndInformation = 15,
        FSEntry_Func_Reason_ShutDown = 16,
        FSEntry_Func_Reason_PrintStartUpBanner = 17,
        FSEntry_Func_Reason_SetDirectoryContexts = 18,
        FSEntry_Func_Reason_ReadDirectoryEntriesAndInformation = 19,
        FSEntry_Func_Reason_OutputFullInformationOnObjects = 20,
        FSEntry_Func_Reason_NotificationOfNewImage = 21,
        FSEntry_Func_Reason_NotificationOfImageAboutToBeClosed = 22,
        FSEntry_Func_Reason_CanonicaliseSpecialFieldAndDiscName = 23,
        FSEntry_Func_Reason_ResolveWildcard = 24,
        FSEntry_Func_Reason_ReadDefectList = 25,
        FSEntry_Func_Reason_AddADefect = 26,
        FSEntry_Func_Reason_ReadBootOption = 27,
        FSEntry_Func_Reason_WriteBootOption = 28,
        FSEntry_Func_Reason_ReadUsedSpaceMap = 29,
        FSEntry_Func_Reason_ReadFreeSpace = 30,
        FSEntry_Func_Reason_NameImage = 31,
        FSEntry_Func_Reason_StampImage = 32,
        FSEntry_Func_Reason_GetUsageOfOffset = 33
}       FSEntry_Func_Reason;

typedef struct FSEntry_Func_Parameter
{
        FSEntry_Func_Reason             reason;
        union
        {
                char                    *name_1;
                FileSystemHandle        csd;
                YesNoAnswer             rename_invalid;
        }       first_parameter;
        union
        {
                char                    *name_2;
                int                     parameter;
                char                    *access_string;
                char                    *destination_address;
                FileSystemHandle        urd;
        }       second_parameter;
        union
        {
                int                     read_number;
                FileSystemHandle        library;
        }       third_parameter;
        int                             read_offset;
        int                             buffer_length;
        char                            *special_field_1;
        char                            *special_field_2;
}       FSEntry_Func_Parameter;
typedef _kernel_oserror *(FSEntry_Func_Function)( FSEntry_Func_Parameter * );

typedef enum FSEntry_GBPB_Reason
{
        FSEntry_GBPB_Reason_PutMultipleBytesHere = 1,
        FSEntry_GBPB_Reason_PutMultipleBytes = 2,
        FSEntry_GBPB_Reason_GetMultipleBytesHere = 3,
        FSEntry_GBPB_Reason_GetMultipleBytes = 4
}       FSEntry_GBPB_Reason;

typedef struct FSEntry_GBPB_Parameter
{
        FSEntry_GBPB_Reason             reason;
        FileSystemHandle                handle;
        char                            *address;
        int                             number;
        int                             sequential_file_pointer;
}       FSEntry_GBPB_Parameter;
typedef _kernel_oserror *(FSEntry_GBPB_Function)( FSEntry_GBPB_Parameter * );

typedef enum FSEntry_Free_Reason
{
        FSEntry_Free_Reason_NoOp = 0,
        FSEntry_Free_Reason_GetDeviceName = 1,
        FSEntry_Free_Reason_GetFreeSpace = 2,
        FSEntry_Free_Reason_CompareDevice = 3
}       FSEntry_Free_Reason;

typedef struct FSEntry_Free_Parameter
{
        FSEntry_Free_Reason             reason;
        int                             FS_number;
        union {
                char    *name;
                int     *buffer;
                } third_parameter;
        char *                          device_id;
        int                             dummy;  
        int                             dummy2;
        char *                          special_field;
}       FSEntry_Free_Parameter;

/*
 * Assembler routines that provide FS interface
 */

extern void veneer_fsentry_open( void );
extern void veneer_fsentry_getbytes( void );
extern void veneer_fsentry_putbytes( void );
extern void veneer_fsentry_args( void );
extern void veneer_fsentry_close( void );
extern void veneer_fsentry_file( void );
extern void veneer_fsentry_func( void );
extern void veneer_fsentry_gbpb( void );
extern void veneer_fsentry_free( void );

/*
 * Routines called by FS interface
 */

extern  _kernel_oserror *fsentry_open( FSEntry_Open_Parameter * );
extern  _kernel_oserror *fsentry_getbytes( FSEntry_GetBytes_Parameter * );
extern  _kernel_oserror *fsentry_putbytes( FSEntry_PutBytes_Parameter * );
extern  _kernel_oserror *fsentry_args( FSEntry_Args_Parameter * );
extern  _kernel_oserror *fsentry_close( FSEntry_Close_Parameter * );
extern  _kernel_oserror *fsentry_file( FSEntry_File_Parameter * );
extern  _kernel_oserror *fsentry_func( FSEntry_Func_Parameter * );
extern  _kernel_oserror *fsentry_gbpb( FSEntry_GBPB_Parameter * );
extern  _kernel_oserror *fsentry_free( FSEntry_Free_Parameter * );

extern const int *Image_RO_Base;

#define Information_Block_Size          11

#endif
