4 /* glk.h: Header file for Glk API, version 0.7.4.
5 Designed by Andrew Plotkin <erkyrath@eblong.com>
6 http://eblong.com/zarf/glk/
8 This file is copyright 1998-2012 by Andrew Plotkin. You may copy,
9 distribute, and incorporate it into your own programs, by any means
10 and under any conditions, as long as you do not modify it. You may
11 also modify this file, incorporate it into your own programs,
12 and distribute the modified version, as long as you retain a notice
13 in your program or documentation which mentions my name and the URL
17 /* If your system does not have <stdint.h>, you'll have to remove this
18 include line. Then edit the definition of glui32 to make sure it's
19 really a 32-bit unsigned integer type, and glsi32 to make sure
20 it's really a 32-bit signed integer type. If they're not, horrible
21 things will happen. */
23 typedef uint32_t glui32;
24 typedef int32_t glsi32;
26 /* These are the compile-time conditionals that reveal various Glk optional
27 modules. Note that if GLK_MODULE_SOUND2 is defined, GLK_MODULE_SOUND
29 #define GLK_MODULE_LINE_ECHO
30 #define GLK_MODULE_LINE_TERMINATORS
31 #define GLK_MODULE_UNICODE
32 #define GLK_MODULE_UNICODE_NORM
33 #define GLK_MODULE_IMAGE
34 #define GLK_MODULE_SOUND
35 #define GLK_MODULE_SOUND2
36 #define GLK_MODULE_HYPERLINKS
37 #define GLK_MODULE_DATETIME
38 #define GLK_MODULE_RESOURCE_STREAM
40 /* These types are opaque object identifiers. They're pointers to opaque
41 C structures, which are defined differently by each library. */
42 typedef struct glk_window_struct *winid_t;
43 typedef struct glk_stream_struct *strid_t;
44 typedef struct glk_fileref_struct *frefid_t;
45 typedef struct glk_schannel_struct *schanid_t;
47 #define gestalt_Version (0)
48 #define gestalt_CharInput (1)
49 #define gestalt_LineInput (2)
50 #define gestalt_CharOutput (3)
51 #define gestalt_CharOutput_CannotPrint (0)
52 #define gestalt_CharOutput_ApproxPrint (1)
53 #define gestalt_CharOutput_ExactPrint (2)
54 #define gestalt_MouseInput (4)
55 #define gestalt_Timer (5)
56 #define gestalt_Graphics (6)
57 #define gestalt_DrawImage (7)
58 #define gestalt_Sound (8)
59 #define gestalt_SoundVolume (9)
60 #define gestalt_SoundNotify (10)
61 #define gestalt_Hyperlinks (11)
62 #define gestalt_HyperlinkInput (12)
63 #define gestalt_SoundMusic (13)
64 #define gestalt_GraphicsTransparency (14)
65 #define gestalt_Unicode (15)
66 #define gestalt_UnicodeNorm (16)
67 #define gestalt_LineInputEcho (17)
68 #define gestalt_LineTerminators (18)
69 #define gestalt_LineTerminatorKey (19)
70 #define gestalt_DateTime (20)
71 #define gestalt_Sound2 (21)
72 #define gestalt_ResourceStream (22)
74 #define evtype_None (0)
75 #define evtype_Timer (1)
76 #define evtype_CharInput (2)
77 #define evtype_LineInput (3)
78 #define evtype_MouseInput (4)
79 #define evtype_Arrange (5)
80 #define evtype_Redraw (6)
81 #define evtype_SoundNotify (7)
82 #define evtype_Hyperlink (8)
83 #define evtype_VolumeNotify (9)
85 typedef struct event_struct {
91 #define keycode_Unknown (0xffffffff)
92 #define keycode_Left (0xfffffffe)
93 #define keycode_Right (0xfffffffd)
94 #define keycode_Up (0xfffffffc)
95 #define keycode_Down (0xfffffffb)
96 #define keycode_Return (0xfffffffa)
97 #define keycode_Delete (0xfffffff9)
98 #define keycode_Escape (0xfffffff8)
99 #define keycode_Tab (0xfffffff7)
100 #define keycode_PageUp (0xfffffff6)
101 #define keycode_PageDown (0xfffffff5)
102 #define keycode_Home (0xfffffff4)
103 #define keycode_End (0xfffffff3)
104 #define keycode_Func1 (0xffffffef)
105 #define keycode_Func2 (0xffffffee)
106 #define keycode_Func3 (0xffffffed)
107 #define keycode_Func4 (0xffffffec)
108 #define keycode_Func5 (0xffffffeb)
109 #define keycode_Func6 (0xffffffea)
110 #define keycode_Func7 (0xffffffe9)
111 #define keycode_Func8 (0xffffffe8)
112 #define keycode_Func9 (0xffffffe7)
113 #define keycode_Func10 (0xffffffe6)
114 #define keycode_Func11 (0xffffffe5)
115 #define keycode_Func12 (0xffffffe4)
116 /* The last keycode is always (0x100000000 - keycode_MAXVAL) */
117 #define keycode_MAXVAL (28)
119 #define style_Normal (0)
120 #define style_Emphasized (1)
121 #define style_Preformatted (2)
122 #define style_Header (3)
123 #define style_Subheader (4)
124 #define style_Alert (5)
125 #define style_Note (6)
126 #define style_BlockQuote (7)
127 #define style_Input (8)
128 #define style_User1 (9)
129 #define style_User2 (10)
130 #define style_NUMSTYLES (11)
132 typedef struct stream_result_struct {
137 #define wintype_AllTypes (0)
138 #define wintype_Pair (1)
139 #define wintype_Blank (2)
140 #define wintype_TextBuffer (3)
141 #define wintype_TextGrid (4)
142 #define wintype_Graphics (5)
144 #define winmethod_Left (0x00)
145 #define winmethod_Right (0x01)
146 #define winmethod_Above (0x02)
147 #define winmethod_Below (0x03)
148 #define winmethod_DirMask (0x0f)
150 #define winmethod_Fixed (0x10)
151 #define winmethod_Proportional (0x20)
152 #define winmethod_DivisionMask (0xf0)
154 #define winmethod_Border (0x000)
155 #define winmethod_NoBorder (0x100)
156 #define winmethod_BorderMask (0x100)
158 #define fileusage_Data (0x00)
159 #define fileusage_SavedGame (0x01)
160 #define fileusage_Transcript (0x02)
161 #define fileusage_InputRecord (0x03)
162 #define fileusage_TypeMask (0x0f)
164 #define fileusage_TextMode (0x100)
165 #define fileusage_BinaryMode (0x000)
167 #define filemode_Write (0x01)
168 #define filemode_Read (0x02)
169 #define filemode_ReadWrite (0x03)
170 #define filemode_WriteAppend (0x05)
172 #define seekmode_Start (0)
173 #define seekmode_Current (1)
174 #define seekmode_End (2)
176 #define stylehint_Indentation (0)
177 #define stylehint_ParaIndentation (1)
178 #define stylehint_Justification (2)
179 #define stylehint_Size (3)
180 #define stylehint_Weight (4)
181 #define stylehint_Oblique (5)
182 #define stylehint_Proportional (6)
183 #define stylehint_TextColor (7)
184 #define stylehint_BackColor (8)
185 #define stylehint_ReverseColor (9)
186 #define stylehint_NUMHINTS (10)
188 #define stylehint_just_LeftFlush (0)
189 #define stylehint_just_LeftRight (1)
190 #define stylehint_just_Centered (2)
191 #define stylehint_just_RightFlush (3)
193 /* glk_main() is the top-level function which you define. The Glk library
195 extern void glk_main(void);
197 extern void glk_exit(void);
198 extern void glk_set_interrupt_handler(void (*func)(void));
199 extern void glk_tick(void);
201 extern glui32 glk_gestalt(glui32 sel, glui32 val);
202 extern glui32 glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr,
205 extern unsigned char glk_char_to_lower(unsigned char ch);
206 extern unsigned char glk_char_to_upper(unsigned char ch);
208 extern winid_t glk_window_get_root(void);
209 extern winid_t glk_window_open(winid_t split, glui32 method, glui32 size,
210 glui32 wintype, glui32 rock);
211 extern void glk_window_close(winid_t win, stream_result_t *result);
212 extern void glk_window_get_size(winid_t win, glui32 *widthptr,
214 extern void glk_window_set_arrangement(winid_t win, glui32 method,
215 glui32 size, winid_t keywin);
216 extern void glk_window_get_arrangement(winid_t win, glui32 *methodptr,
217 glui32 *sizeptr, winid_t *keywinptr);
218 extern winid_t glk_window_iterate(winid_t win, glui32 *rockptr);
219 extern glui32 glk_window_get_rock(winid_t win);
220 extern glui32 glk_window_get_type(winid_t win);
221 extern winid_t glk_window_get_parent(winid_t win);
222 extern winid_t glk_window_get_sibling(winid_t win);
223 extern void glk_window_clear(winid_t win);
224 extern void glk_window_move_cursor(winid_t win, glui32 xpos, glui32 ypos);
226 extern strid_t glk_window_get_stream(winid_t win);
227 extern void glk_window_set_echo_stream(winid_t win, strid_t str);
228 extern strid_t glk_window_get_echo_stream(winid_t win);
229 extern void glk_set_window(winid_t win);
231 extern strid_t glk_stream_open_file(frefid_t fileref, glui32 fmode,
233 extern strid_t glk_stream_open_memory(char *buf, glui32 buflen, glui32 fmode,
235 extern void glk_stream_close(strid_t str, stream_result_t *result);
236 extern strid_t glk_stream_iterate(strid_t str, glui32 *rockptr);
237 extern glui32 glk_stream_get_rock(strid_t str);
238 extern void glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekmode);
239 extern glui32 glk_stream_get_position(strid_t str);
240 extern void glk_stream_set_current(strid_t str);
241 extern strid_t glk_stream_get_current(void);
243 extern void glk_put_char(unsigned char ch);
244 extern void glk_put_char_stream(strid_t str, unsigned char ch);
245 extern void glk_put_string(char *s);
246 extern void glk_put_string_stream(strid_t str, char *s);
247 extern void glk_put_buffer(char *buf, glui32 len);
248 extern void glk_put_buffer_stream(strid_t str, char *buf, glui32 len);
249 extern void glk_set_style(glui32 styl);
250 extern void glk_set_style_stream(strid_t str, glui32 styl);
252 extern glsi32 glk_get_char_stream(strid_t str);
253 extern glui32 glk_get_line_stream(strid_t str, char *buf, glui32 len);
254 extern glui32 glk_get_buffer_stream(strid_t str, char *buf, glui32 len);
256 extern void glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint,
258 extern void glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint);
259 extern glui32 glk_style_distinguish(winid_t win, glui32 styl1, glui32 styl2);
260 extern glui32 glk_style_measure(winid_t win, glui32 styl, glui32 hint,
263 extern frefid_t glk_fileref_create_temp(glui32 usage, glui32 rock);
264 extern frefid_t glk_fileref_create_by_name(glui32 usage, char *name,
266 extern frefid_t glk_fileref_create_by_prompt(glui32 usage, glui32 fmode,
268 extern frefid_t glk_fileref_create_from_fileref(glui32 usage, frefid_t fref,
270 extern void glk_fileref_destroy(frefid_t fref);
271 extern frefid_t glk_fileref_iterate(frefid_t fref, glui32 *rockptr);
272 extern glui32 glk_fileref_get_rock(frefid_t fref);
273 extern void glk_fileref_delete_file(frefid_t fref);
274 extern glui32 glk_fileref_does_file_exist(frefid_t fref);
276 extern void glk_select(event_t *event);
277 extern void glk_select_poll(event_t *event);
279 extern void glk_request_timer_events(glui32 millisecs);
281 extern void glk_request_line_event(winid_t win, char *buf, glui32 maxlen,
283 extern void glk_request_char_event(winid_t win);
284 extern void glk_request_mouse_event(winid_t win);
286 extern void glk_cancel_line_event(winid_t win, event_t *event);
287 extern void glk_cancel_char_event(winid_t win);
288 extern void glk_cancel_mouse_event(winid_t win);
290 #ifdef GLK_MODULE_LINE_ECHO
291 extern void glk_set_echo_line_event(winid_t win, glui32 val);
292 #endif /* GLK_MODULE_LINE_ECHO */
294 #ifdef GLK_MODULE_LINE_TERMINATORS
295 extern void glk_set_terminators_line_event(winid_t win, glui32 *keycodes,
297 #endif /* GLK_MODULE_LINE_TERMINATORS */
299 #ifdef GLK_MODULE_UNICODE
301 extern glui32 glk_buffer_to_lower_case_uni(glui32 *buf, glui32 len,
303 extern glui32 glk_buffer_to_upper_case_uni(glui32 *buf, glui32 len,
305 extern glui32 glk_buffer_to_title_case_uni(glui32 *buf, glui32 len,
306 glui32 numchars, glui32 lowerrest);
308 extern void glk_put_char_uni(glui32 ch);
309 extern void glk_put_string_uni(glui32 *s);
310 extern void glk_put_buffer_uni(glui32 *buf, glui32 len);
311 extern void glk_put_char_stream_uni(strid_t str, glui32 ch);
312 extern void glk_put_string_stream_uni(strid_t str, glui32 *s);
313 extern void glk_put_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len);
315 extern glsi32 glk_get_char_stream_uni(strid_t str);
316 extern glui32 glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len);
317 extern glui32 glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len);
319 extern strid_t glk_stream_open_file_uni(frefid_t fileref, glui32 fmode,
321 extern strid_t glk_stream_open_memory_uni(glui32 *buf, glui32 buflen,
322 glui32 fmode, glui32 rock);
324 extern void glk_request_char_event_uni(winid_t win);
325 extern void glk_request_line_event_uni(winid_t win, glui32 *buf,
326 glui32 maxlen, glui32 initlen);
328 #endif /* GLK_MODULE_UNICODE */
330 #ifdef GLK_MODULE_UNICODE_NORM
332 extern glui32 glk_buffer_canon_decompose_uni(glui32 *buf, glui32 len,
334 extern glui32 glk_buffer_canon_normalize_uni(glui32 *buf, glui32 len,
337 #endif /* GLK_MODULE_UNICODE_NORM */
339 #ifdef GLK_MODULE_IMAGE
341 #define imagealign_InlineUp (0x01)
342 #define imagealign_InlineDown (0x02)
343 #define imagealign_InlineCenter (0x03)
344 #define imagealign_MarginLeft (0x04)
345 #define imagealign_MarginRight (0x05)
347 extern glui32 glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2);
348 extern glui32 glk_image_draw_scaled(winid_t win, glui32 image,
349 glsi32 val1, glsi32 val2, glui32 width, glui32 height);
350 extern glui32 glk_image_get_info(glui32 image, glui32 *width, glui32 *height);
352 extern void glk_window_flow_break(winid_t win);
354 extern void glk_window_erase_rect(winid_t win,
355 glsi32 left, glsi32 top, glui32 width, glui32 height);
356 extern void glk_window_fill_rect(winid_t win, glui32 color,
357 glsi32 left, glsi32 top, glui32 width, glui32 height);
358 extern void glk_window_set_background_color(winid_t win, glui32 color);
360 #endif /* GLK_MODULE_IMAGE */
362 #ifdef GLK_MODULE_SOUND
364 extern schanid_t glk_schannel_create(glui32 rock);
365 extern void glk_schannel_destroy(schanid_t chan);
366 extern schanid_t glk_schannel_iterate(schanid_t chan, glui32 *rockptr);
367 extern glui32 glk_schannel_get_rock(schanid_t chan);
369 extern glui32 glk_schannel_play(schanid_t chan, glui32 snd);
370 extern glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats,
372 extern void glk_schannel_stop(schanid_t chan);
373 extern void glk_schannel_set_volume(schanid_t chan, glui32 vol);
375 extern void glk_sound_load_hint(glui32 snd, glui32 flag);
377 #ifdef GLK_MODULE_SOUND2
378 /* Note that this section is nested inside the #ifdef GLK_MODULE_SOUND.
379 GLK_MODULE_SOUND must be defined if GLK_MODULE_SOUND2 is. */
381 extern schanid_t glk_schannel_create_ext(glui32 rock, glui32 volume);
382 extern glui32 glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount,
383 glui32 *sndarray, glui32 soundcount, glui32 notify);
384 extern void glk_schannel_pause(schanid_t chan);
385 extern void glk_schannel_unpause(schanid_t chan);
386 extern void glk_schannel_set_volume_ext(schanid_t chan, glui32 vol,
387 glui32 duration, glui32 notify);
389 #endif /* GLK_MODULE_SOUND2 */
390 #endif /* GLK_MODULE_SOUND */
392 #ifdef GLK_MODULE_HYPERLINKS
394 extern void glk_set_hyperlink(glui32 linkval);
395 extern void glk_set_hyperlink_stream(strid_t str, glui32 linkval);
396 extern void glk_request_hyperlink_event(winid_t win);
397 extern void glk_cancel_hyperlink_event(winid_t win);
399 #endif /* GLK_MODULE_HYPERLINKS */
401 #ifdef GLK_MODULE_DATETIME
403 typedef struct glktimeval_struct {
409 typedef struct glkdate_struct {
410 glsi32 year; /* full (four-digit) year */
411 glsi32 month; /* 1-12, 1 is January */
412 glsi32 day; /* 1-31 */
413 glsi32 weekday; /* 0-6, 0 is Sunday */
414 glsi32 hour; /* 0-23 */
415 glsi32 minute; /* 0-59 */
416 glsi32 second; /* 0-59, maybe 60 during a leap second */
417 glsi32 microsec; /* 0-999999 */
420 extern void glk_current_time(glktimeval_t *time);
421 extern glsi32 glk_current_simple_time(glui32 factor);
422 extern void glk_time_to_date_utc(glktimeval_t *time, glkdate_t *date);
423 extern void glk_time_to_date_local(glktimeval_t *time, glkdate_t *date);
424 extern void glk_simple_time_to_date_utc(glsi32 time, glui32 factor,
426 extern void glk_simple_time_to_date_local(glsi32 time, glui32 factor,
428 extern void glk_date_to_time_utc(glkdate_t *date, glktimeval_t *time);
429 extern void glk_date_to_time_local(glkdate_t *date, glktimeval_t *time);
430 extern glsi32 glk_date_to_simple_time_utc(glkdate_t *date, glui32 factor);
431 extern glsi32 glk_date_to_simple_time_local(glkdate_t *date, glui32 factor);
433 #endif /* GLK_MODULE_DATETIME */
435 #ifdef GLK_MODULE_RESOURCE_STREAM
437 extern strid_t glk_stream_open_resource(glui32 filenum, glui32 rock);
438 extern strid_t glk_stream_open_resource_uni(glui32 filenum, glui32 rock);
440 #endif /* GLK_MODULE_RESOURCE_STREAM */