Update to Blorb protocol 1.5
[projects/chimara/chimara.git] / libchimara / gi_blorb.h
1 #ifndef _GI_BLORB_H
2 #define _GI_BLORB_H
3
4 /* gi_blorb.h: Blorb library layer for Glk API.
5     gi_blorb version 1.5.
6     Designed by Andrew Plotkin <erkyrath@eblong.com>
7     http://eblong.com/zarf/glk/
8
9     This file is copyright 1998-2012 by Andrew Plotkin. You may copy,
10     distribute, and incorporate it into your own programs, by any means
11     and under any conditions, as long as you do not modify it. You may
12     also modify this file, incorporate it into your own programs,
13     and distribute the modified version, as long as you retain a notice
14     in your program or documentation which mentions my name and the URL
15     shown above.
16 */
17
18 /* Error type and error codes */
19 typedef glui32 giblorb_err_t;
20 #define giblorb_err_None (0)
21 #define giblorb_err_CompileTime (1)
22 #define giblorb_err_Alloc (2)
23 #define giblorb_err_Read (3)
24 #define giblorb_err_NotAMap (4)
25 #define giblorb_err_Format (5)
26 #define giblorb_err_NotFound (6)
27
28 /* Methods for loading a chunk */
29 #define giblorb_method_DontLoad (0)
30 #define giblorb_method_Memory (1)
31 #define giblorb_method_FilePos (2)
32
33 /* Four-byte constants */
34
35 #define giblorb_make_id(c1, c2, c3, c4)  \
36     (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4))
37
38 #define giblorb_ID_Exec      (giblorb_make_id('E', 'x', 'e', 'c'))
39 #define giblorb_ID_Snd       (giblorb_make_id('S', 'n', 'd', ' '))
40 #define giblorb_ID_Pict      (giblorb_make_id('P', 'i', 'c', 't'))
41 #define giblorb_ID_Data      (giblorb_make_id('D', 'a', 't', 'a'))
42 #define giblorb_ID_Copyright (giblorb_make_id('(', 'c', ')', ' '))
43 #define giblorb_ID_AUTH      (giblorb_make_id('A', 'U', 'T', 'H'))
44 #define giblorb_ID_ANNO      (giblorb_make_id('A', 'N', 'N', 'O'))
45 #define giblorb_ID_TEXT      (giblorb_make_id('T', 'E', 'X', 'T'))
46 #define giblorb_ID_BINA      (giblorb_make_id('B', 'I', 'N', 'A'))
47
48 /* giblorb_map_t: Holds the complete description of an open Blorb 
49     file. This type is opaque for normal interpreter use. */
50 typedef struct giblorb_map_struct giblorb_map_t;
51
52 /* giblorb_result_t: Result when you try to load a chunk. */
53 typedef struct giblorb_result_struct {
54     glui32 chunknum; /* The chunk number (for use in 
55         giblorb_unload_chunk(), etc.) */
56     union {
57         void *ptr; /* A pointer to the data (if you used 
58             giblorb_method_Memory) */
59         glui32 startpos; /* The position in the file (if you 
60             used giblorb_method_FilePos) */
61     } data;
62     glui32 length; /* The length of the data */
63     glui32 chunktype; /* The type of the chunk. */
64 } giblorb_result_t;
65
66 extern giblorb_err_t giblorb_create_map(strid_t file, 
67     giblorb_map_t **newmap);
68 extern giblorb_err_t giblorb_destroy_map(giblorb_map_t *map);
69
70 extern giblorb_err_t giblorb_load_chunk_by_type(giblorb_map_t *map, 
71     glui32 method, giblorb_result_t *res, glui32 chunktype, 
72     glui32 count);
73 extern giblorb_err_t giblorb_load_chunk_by_number(giblorb_map_t *map, 
74     glui32 method, giblorb_result_t *res, glui32 chunknum);
75 extern giblorb_err_t giblorb_unload_chunk(giblorb_map_t *map, 
76     glui32 chunknum);
77
78 extern giblorb_err_t giblorb_load_resource(giblorb_map_t *map, 
79     glui32 method, giblorb_result_t *res, glui32 usage, 
80     glui32 resnum);
81 extern giblorb_err_t giblorb_count_resources(giblorb_map_t *map, 
82     glui32 usage, glui32 *num, glui32 *min, glui32 *max);
83
84 /* The following functions are part of the Glk library itself, not 
85     the Blorb layer (whose code is in gi_blorb.c). These functions 
86     are necessarily implemented in platform-dependent code. 
87 */
88 extern giblorb_err_t giblorb_set_resource_map(strid_t file);
89 extern giblorb_map_t *giblorb_get_resource_map(void);
90
91 #endif /* _GI_BLORB_H */