#ifndef osgbpb_H
#define osgbpb_H

/*OSLib---efficient, type-safe, transparent, extensible,\n"
   register-safe A P I coverage of RISC O S*/
/*Copyright  1994 Jonathan Coxhead*/

/*
      OSLib is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 1, or (at your option)
   any later version.

      OSLib is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
   along with this programme; if not, write to the Free Software
   Foundation, Inc, 675 Mass Ave, Cambridge, MA 02139, U S A.
*/

#ifndef types_H
   #include "types.h"
#endif

#ifndef fileswitch_H
   #include "fileswitch.h"
#endif

#ifndef os_H
   #include "os.h"
#endif

#define OSGBPB_WriteAt 0x1
#define OSGBPB_Write 0x2
#define OSGBPB_ReadAt 0x3
#define OSGBPB_Read 0x4
#define OSGBPB_ReadDiscName 0x5
#define OSGBPB_ReadCSDName 0x6
#define OSGBPB_ReadLibName 0x7
#define OSGBPB_CSDEntries 0x8
#define OSGBPB_DirEntries 0x9
#define OSGBPB_DirEntriesBriefInfo 0xA
#define OSGBPB_DirEntriesInternalInfo 0xB
#define OSGBPB_DirEntriesFullInfo 0xC

typedef struct osgbpb_name osgbpb_name;
typedef struct osgbpb_disc_name osgbpb_disc_name;
typedef struct osgbpb_dir_name osgbpb_dir_name;
typedef struct osgbpb_name_list osgbpb_name_list;
typedef struct osgbpb_brief_info osgbpb_brief_info;
typedef struct osgbpb_internal_info osgbpb_internal_info;
typedef struct osgbpb_full_info osgbpb_full_info;
typedef struct osgbpb_string_list osgbpb_string_list;
typedef struct osgbpb_brief_info_list osgbpb_brief_info_list;
typedef struct osgbpb_internal_info_list osgbpb_internal_info_list;
typedef struct osgbpb_full_info_list osgbpb_full_info_list;

/*Type definitions*/
struct osgbpb_name
   {  byte count;
      char (c) [UNKNOWN];
   };

#define osgbpb_NAME(N) \
      struct \
         {  byte count; \
            char (c) [N]; \
         }

#define osgbpb_SIZEOF_NAME(N) \
      (offsetof (osgbpb_name, c) + (N)*sizeof ((osgbpb_name *) NULL)->c)

struct osgbpb_disc_name
   {  osgbpb_name name;
      byte boot_option;
   };

struct osgbpb_dir_name
   {  byte reserved;
      osgbpb_name name;
      byte privilege;
   };

struct osgbpb_name_list
   {  osgbpb_name (names) [UNKNOWN];
   };

struct osgbpb_brief_info
   {  int load_addr;
      int exec_addr;
      int size;
      int attr;
      int obj_type;
      char (name) [UNKNOWN];
   };

#define osgbpb_BRIEF_INFO(N) \
      struct \
         {  int load_addr; \
            int exec_addr; \
            int size; \
            int attr; \
            int obj_type; \
            char (name) [N]; \
         }

#define osgbpb_SIZEOF_BRIEF_INFO(N) \
      (offsetof (osgbpb_brief_info, name) + (N)*sizeof ((osgbpb_brief_info *) NULL)->name)

struct osgbpb_internal_info
   {  int load_addr;
      int exec_addr;
      int size;
      int attr;
      int obj_type;
      int sin;
      os_t stamp;
      char (name) [UNKNOWN];
   };

#define osgbpb_INTERNAL_INFO(N) \
      struct \
         {  int load_addr; \
            int exec_addr; \
            int size; \
            int attr; \
            int obj_type; \
            int sin; \
            os_t stamp; \
            char (name) [N]; \
         }

#define osgbpb_SIZEOF_INTERNAL_INFO(N) \
      (offsetof (osgbpb_internal_info, name) + (N)*sizeof ((osgbpb_internal_info *) NULL)->name)

struct osgbpb_full_info
   {  int load_addr;
      int exec_addr;
      int size;
      int attr;
      int obj_type;
      int file_type;
      char (name) [UNKNOWN];
   };

#define osgbpb_FULL_INFO(N) \
      struct \
         {  int load_addr; \
            int exec_addr; \
            int size; \
            int attr; \
            int obj_type; \
            int file_type; \
            char (name) [N]; \
         }

#define osgbpb_SIZEOF_FULL_INFO(N) \
      (offsetof (osgbpb_full_info, name) + (N)*sizeof ((osgbpb_full_info *) NULL)->name)

struct osgbpb_string_list
   {  char (names) [UNKNOWN];
   };

struct osgbpb_brief_info_list
   {  osgbpb_brief_info (info) [UNKNOWN];
   };

struct osgbpb_internal_info_list
   {  osgbpb_internal_info (info) [UNKNOWN];
   };

struct osgbpb_full_info_list
   {  osgbpb_full_info (info) [UNKNOWN];
   };

#define osgbpb_PRIVILEGE_OWNER ((byte) 0)
#define osgbpb_PRIVILEGE_PUBLIC ((byte) 255)
#define osgbpb_NO_MORE (-1)

#define xosgbpb_write(file, data, size, un) \
   _swix (OS_GBPB, _IN (0) | _IN (1) | _IN (2) | _IN (3), \
         OSGBPB_Write, (os_f) (file), (byte *) (data), (int) (size))

#define xosgbpb_dir_entries(dir_name, name_list, count, context, size, entries, read_count, context_out) \
   _swix (OS_GBPB,  _IN (0) | _IN (1) | _IN (2) | _IN (3) | _IN (4) | _IN (5) | _IN (6) | _OUT (3) | _OUT (4), \
         OSGBPB_DirEntries, (char *) (dir_name), (osgbpb_string_list *) (name_list), (int) (count), \
         (int) (context), (int) (size), (char *) (entries), (int *) (read_count), (int *) (context_out))

#endif
