Debian Codegraph @

garglk/cheapglk/gi_dispa.c

raw symbols SCIP
1 /* gi_dispa.c: Dispatch layer for Glk API, version 0.7.6.
2 Designed by Andrew Plotkin <[email protected]>
3 http://eblong.com/zarf/glk/
4
5 This file is copyright 1998-2025 by Andrew Plotkin. It is
6 distributed under the MIT license; see the "LICENSE" file.
7 */
8
9 /* This code should be linked into every Glk library, without change.
10 Get the latest version from the URL above. */
11
12 #include "glk.h"
13 #include "gi_dispa.h"
14
15 #ifndef NULL
16 #define NULL 0
17 #endif
18
19 #define NUMCLASSES \
20 (sizeof(class_table) / sizeof(gidispatch_intconst_t))
21
22 #define NUMINTCONSTANTS \
23 (sizeof(intconstant_table) / sizeof(gidispatch_intconst_t))
24
25 #define NUMFUNCTIONS \
26 (sizeof(function_table) / sizeof(gidispatch_function_t))
27
28 /* The constants in this table must be ordered alphabetically. */
29 static gidispatch_intconst_t class_table[] = {
30 { "fileref", (2) }, /* "Qc" */
31 { "schannel", (3) }, /* "Qd" */
32 { "stream", (1) }, /* "Qb" */
33 { "window", (0) }, /* "Qa" */
34 };
35
36 /* The constants in this table must be ordered alphabetically. */
37 static gidispatch_intconst_t intconstant_table[] = {
38 { "evtype_Arrange", (5) },
39 { "evtype_CharInput", (2) },
40 { "evtype_Hyperlink", (8) },
41 { "evtype_LineInput", (3) },
42 { "evtype_MouseInput", (4) },
43 { "evtype_None", (0) },
44 { "evtype_Redraw", (6) },
45 { "evtype_SoundNotify", (7) },
46 { "evtype_Timer", (1) },
47 { "evtype_VolumeNotify", (9) },
48
49 { "filemode_Read", (0x02) },
50 { "filemode_ReadWrite", (0x03) },
51 { "filemode_Write", (0x01) },
52 { "filemode_WriteAppend", (0x05) },
53
54 { "fileusage_BinaryMode", (0x000) },
55 { "fileusage_Data", (0x00) },
56 { "fileusage_InputRecord", (0x03) },
57 { "fileusage_SavedGame", (0x01) },
58 { "fileusage_TextMode", (0x100) },
59 { "fileusage_Transcript", (0x02) },
60 { "fileusage_TypeMask", (0x0f) },
61
62 { "gestalt_CharInput", (1) },
63 { "gestalt_CharOutput", (3) },
64 { "gestalt_CharOutput_ApproxPrint", (1) },
65 { "gestalt_CharOutput_CannotPrint", (0) },
66 { "gestalt_CharOutput_ExactPrint", (2) },
67 { "gestalt_DateTime", (20) },
68 { "gestalt_DrawImage", (7) },
69 { "gestalt_DrawImageScale", (24) },
70 #ifdef GARGLK
71 { "gestalt_GarglkText", (0x1100) },
72 #endif
73 { "gestalt_Graphics", (6) },
74 { "gestalt_GraphicsCharInput", (23) },
75 { "gestalt_GraphicsTransparency", (14) },
76 { "gestalt_HyperlinkInput", (12) },
77 { "gestalt_Hyperlinks", (11) },
78 { "gestalt_LineInput", (2) },
79 { "gestalt_LineInputEcho", (17) },
80 { "gestalt_LineTerminatorKey", (19) },
81 { "gestalt_LineTerminators", (18) },
82 { "gestalt_MouseInput", (4) },
83 { "gestalt_ResourceStream", (22) },
84 { "gestalt_Sound", (8) },
85 { "gestalt_Sound2", (21) },
86 { "gestalt_SoundMusic", (13) },
87 { "gestalt_SoundNotify", (10) },
88 { "gestalt_SoundVolume", (9) },
89 { "gestalt_Timer", (5) },
90 { "gestalt_Unicode", (15) },
91 { "gestalt_UnicodeNorm", (16) },
92 { "gestalt_Version", (0) },
93
94 { "imagealign_InlineCenter", (0x03) },
95 { "imagealign_InlineDown", (0x02) },
96 { "imagealign_InlineUp", (0x01) },
97 { "imagealign_MarginLeft", (0x04) },
98 { "imagealign_MarginRight", (0x05) },
99
100 { "imagerule_AspectRatio", (0x0C) },
101 { "imagerule_HeightFixed", (0x08) },
102 { "imagerule_HeightMask", (0x0C) },
103 { "imagerule_HeightOrig", (0x04) },
104 { "imagerule_WidthFixed", (0x02) },
105 { "imagerule_WidthMask", (0x03) },
106 { "imagerule_WidthOrig", (0x01) },
107 { "imagerule_WidthRatio", (0x03) },
108
109 { "keycode_Delete", (0xfffffff9) },
110 { "keycode_Down", (0xfffffffb) },
111 { "keycode_End", (0xfffffff3) },
112 { "keycode_Escape", (0xfffffff8) },
113 { "keycode_Func1", (0xffffffef) },
114 { "keycode_Func10", (0xffffffe6) },
115 { "keycode_Func11", (0xffffffe5) },
116 { "keycode_Func12", (0xffffffe4) },
117 { "keycode_Func2", (0xffffffee) },
118 { "keycode_Func3", (0xffffffed) },
119 { "keycode_Func4", (0xffffffec) },
120 { "keycode_Func5", (0xffffffeb) },
121 { "keycode_Func6", (0xffffffea) },
122 { "keycode_Func7", (0xffffffe9) },
123 { "keycode_Func8", (0xffffffe8) },
124 { "keycode_Func9", (0xffffffe7) },
125 { "keycode_Home", (0xfffffff4) },
126 { "keycode_Left", (0xfffffffe) },
127 { "keycode_MAXVAL", (28) },
128 { "keycode_PageDown", (0xfffffff5) },
129 { "keycode_PageUp", (0xfffffff6) },
130 { "keycode_Return", (0xfffffffa) },
131 { "keycode_Right", (0xfffffffd) },
132 { "keycode_Tab", (0xfffffff7) },
133 { "keycode_Unknown", (0xffffffff) },
134 { "keycode_Up", (0xfffffffc) },
135
136 { "seekmode_Current", (1) },
137 { "seekmode_End", (2) },
138 { "seekmode_Start", (0) },
139
140 { "style_Alert", (5) },
141 { "style_BlockQuote", (7) },
142 { "style_Emphasized", (1) },
143 { "style_Header", (3) },
144 { "style_Input", (8) },
145 { "style_NUMSTYLES", (11) },
146 { "style_Normal", (0) },
147 { "style_Note", (6) },
148 { "style_Preformatted", (2) },
149 { "style_Subheader", (4) },
150 { "style_User1", (9) },
151 { "style_User2", (10) },
152 { "stylehint_BackColor", (8) },
153 { "stylehint_Indentation", (0) },
154 { "stylehint_Justification", (2) },
155 { "stylehint_NUMHINTS", (10) },
156 { "stylehint_Oblique", (5) },
157 { "stylehint_ParaIndentation", (1) },
158 { "stylehint_Proportional", (6) },
159 { "stylehint_ReverseColor", (9) },
160 { "stylehint_Size", (3) },
161 { "stylehint_TextColor", (7) },
162 { "stylehint_Weight", (4) },
163 { "stylehint_just_Centered", (2) },
164 { "stylehint_just_LeftFlush", (0) },
165 { "stylehint_just_LeftRight", (1) },
166 { "stylehint_just_RightFlush", (3) },
167
168 { "winmethod_Above", (0x02) },
169 { "winmethod_Below", (0x03) },
170 { "winmethod_Border", (0x000) },
171 { "winmethod_BorderMask", (0x100) },
172 { "winmethod_DirMask", (0x0f) },
173 { "winmethod_DivisionMask", (0xf0) },
174 { "winmethod_Fixed", (0x10) },
175 { "winmethod_Left", (0x00) },
176 { "winmethod_NoBorder", (0x100) },
177 { "winmethod_Proportional", (0x20) },
178 { "winmethod_Right", (0x01) },
179
180 { "wintype_AllTypes", (0) },
181 { "wintype_Blank", (2) },
182 { "wintype_Graphics", (5) },
183 { "wintype_Pair", (1) },
184 { "wintype_TextBuffer", (3) },
185 { "wintype_TextGrid", (4) },
186 };
187
188 /* The functions in this table must be ordered by id. */
189 static gidispatch_function_t function_table[] = {
190 { 0x0001, glk_exit, "exit" },
191 { 0x0002, glk_set_interrupt_handler, "set_interrupt_handler" },
192 { 0x0003, glk_tick, "tick" },
193 { 0x0004, glk_gestalt, "gestalt" },
194 { 0x0005, glk_gestalt_ext, "gestalt_ext" },
195 { 0x0020, glk_window_iterate, "window_iterate" },
196 { 0x0021, glk_window_get_rock, "window_get_rock" },
197 { 0x0022, glk_window_get_root, "window_get_root" },
198 { 0x0023, glk_window_open, "window_open" },
199 { 0x0024, glk_window_close, "window_close" },
200 { 0x0025, glk_window_get_size, "window_get_size" },
201 { 0x0026, glk_window_set_arrangement, "window_set_arrangement" },
202 { 0x0027, glk_window_get_arrangement, "window_get_arrangement" },
203 { 0x0028, glk_window_get_type, "window_get_type" },
204 { 0x0029, glk_window_get_parent, "window_get_parent" },
205 { 0x002A, glk_window_clear, "window_clear" },
206 { 0x002B, glk_window_move_cursor, "window_move_cursor" },
207 { 0x002C, glk_window_get_stream, "window_get_stream" },
208 { 0x002D, glk_window_set_echo_stream, "window_set_echo_stream" },
209 { 0x002E, glk_window_get_echo_stream, "window_get_echo_stream" },
210 { 0x002F, glk_set_window, "set_window" },
211 { 0x0030, glk_window_get_sibling, "window_get_sibling" },
212 { 0x0040, glk_stream_iterate, "stream_iterate" },
213 { 0x0041, glk_stream_get_rock, "stream_get_rock" },
214 { 0x0042, glk_stream_open_file, "stream_open_file" },
215 { 0x0043, glk_stream_open_memory, "stream_open_memory" },
216 { 0x0044, glk_stream_close, "stream_close" },
217 { 0x0045, glk_stream_set_position, "stream_set_position" },
218 { 0x0046, glk_stream_get_position, "stream_get_position" },
219 { 0x0047, glk_stream_set_current, "stream_set_current" },
220 { 0x0048, glk_stream_get_current, "stream_get_current" },
221 #ifdef GLK_MODULE_RESOURCE_STREAM
222 { 0x0049, glk_stream_open_resource, "stream_open_resource" },
223 #endif /* GLK_MODULE_RESOURCE_STREAM */
224 { 0x0060, glk_fileref_create_temp, "fileref_create_temp" },
225 { 0x0061, glk_fileref_create_by_name, "fileref_create_by_name" },
226 { 0x0062, glk_fileref_create_by_prompt, "fileref_create_by_prompt" },
227 { 0x0063, glk_fileref_destroy, "fileref_destroy" },
228 { 0x0064, glk_fileref_iterate, "fileref_iterate" },
229 { 0x0065, glk_fileref_get_rock, "fileref_get_rock" },
230 { 0x0066, glk_fileref_delete_file, "fileref_delete_file" },
231 { 0x0067, glk_fileref_does_file_exist, "fileref_does_file_exist" },
232 { 0x0068, glk_fileref_create_from_fileref, "fileref_create_from_fileref" },
233 { 0x0080, glk_put_char, "put_char" },
234 { 0x0081, glk_put_char_stream, "put_char_stream" },
235 { 0x0082, glk_put_string, "put_string" },
236 { 0x0083, glk_put_string_stream, "put_string_stream" },
237 { 0x0084, glk_put_buffer, "put_buffer" },
238 { 0x0085, glk_put_buffer_stream, "put_buffer_stream" },
239 { 0x0086, glk_set_style, "set_style" },
240 { 0x0087, glk_set_style_stream, "set_style_stream" },
241 { 0x0090, glk_get_char_stream, "get_char_stream" },
242 { 0x0091, glk_get_line_stream, "get_line_stream" },
243 { 0x0092, glk_get_buffer_stream, "get_buffer_stream" },
244 { 0x00A0, glk_char_to_lower, "char_to_lower" },
245 { 0x00A1, glk_char_to_upper, "char_to_upper" },
246 { 0x00B0, glk_stylehint_set, "stylehint_set" },
247 { 0x00B1, glk_stylehint_clear, "stylehint_clear" },
248 { 0x00B2, glk_style_distinguish, "style_distinguish" },
249 { 0x00B3, glk_style_measure, "style_measure" },
250 { 0x00C0, glk_select, "select" },
251 { 0x00C1, glk_select_poll, "select_poll" },
252 { 0x00D0, glk_request_line_event, "request_line_event" },
253 { 0x00D1, glk_cancel_line_event, "cancel_line_event" },
254 { 0x00D2, glk_request_char_event, "request_char_event" },
255 { 0x00D3, glk_cancel_char_event, "cancel_char_event" },
256 { 0x00D4, glk_request_mouse_event, "request_mouse_event" },
257 { 0x00D5, glk_cancel_mouse_event, "cancel_mouse_event" },
258 { 0x00D6, glk_request_timer_events, "request_timer_events" },
259 #ifdef GLK_MODULE_IMAGE
260 { 0x00E0, glk_image_get_info, "image_get_info" },
261 { 0x00E1, glk_image_draw, "image_draw" },
262 { 0x00E2, glk_image_draw_scaled, "image_draw_scaled" },
263 { 0x00E8, glk_window_flow_break, "window_flow_break" },
264 { 0x00E9, glk_window_erase_rect, "window_erase_rect" },
265 { 0x00EA, glk_window_fill_rect, "window_fill_rect" },
266 { 0x00EB, glk_window_set_background_color, "window_set_background_color" },
267 #ifdef GLK_MODULE_IMAGE2
268 { 0x00EC, glk_image_draw_scaled_ext, "image_draw_scaled_ext" },
269 #endif /* GLK_MODULE_IMAGE2 */
270 #endif /* GLK_MODULE_IMAGE */
271 #ifdef GLK_MODULE_SOUND
272 { 0x00F0, glk_schannel_iterate, "schannel_iterate" },
273 { 0x00F1, glk_schannel_get_rock, "schannel_get_rock" },
274 { 0x00F2, glk_schannel_create, "schannel_create" },
275 { 0x00F3, glk_schannel_destroy, "schannel_destroy" },
276 #ifdef GLK_MODULE_SOUND2
277 { 0x00F4, glk_schannel_create_ext, "schannel_create_ext" },
278 { 0x00F7, glk_schannel_play_multi, "schannel_play_multi" },
279 #endif /* GLK_MODULE_SOUND2 */
280 { 0x00F8, glk_schannel_play, "schannel_play" },
281 { 0x00F9, glk_schannel_play_ext, "schannel_play_ext" },
282 { 0x00FA, glk_schannel_stop, "schannel_stop" },
283 { 0x00FB, glk_schannel_set_volume, "schannel_set_volume" },
284 { 0x00FC, glk_sound_load_hint, "sound_load_hint" },
285 #ifdef GLK_MODULE_SOUND2
286 { 0x00FD, glk_schannel_set_volume_ext, "schannel_set_volume_ext" },
287 { 0x00FE, glk_schannel_pause, "schannel_pause" },
288 { 0x00FF, glk_schannel_unpause, "schannel_unpause" },
289 #endif /* GLK_MODULE_SOUND2 */
290 #endif /* GLK_MODULE_SOUND */
291 #ifdef GLK_MODULE_HYPERLINKS
292 { 0x0100, glk_set_hyperlink, "set_hyperlink" },
293 { 0x0101, glk_set_hyperlink_stream, "set_hyperlink_stream" },
294 { 0x0102, glk_request_hyperlink_event, "request_hyperlink_event" },
295 { 0x0103, glk_cancel_hyperlink_event, "cancel_hyperlink_event" },
296 #endif /* GLK_MODULE_HYPERLINKS */
297 #ifdef GLK_MODULE_UNICODE
298 { 0x0120, glk_buffer_to_lower_case_uni, "buffer_to_lower_case_uni" },
299 { 0x0121, glk_buffer_to_upper_case_uni, "buffer_to_upper_case_uni" },
300 { 0x0122, glk_buffer_to_title_case_uni, "buffer_to_title_case_uni" },
301 #ifdef GLK_MODULE_UNICODE_NORM
302 { 0x0123, glk_buffer_canon_decompose_uni, "buffer_canon_decompose_uni" },
303 { 0x0124, glk_buffer_canon_normalize_uni, "buffer_canon_normalize_uni" },
304 #endif /* GLK_MODULE_UNICODE_NORM */
305 { 0x0128, glk_put_char_uni, "put_char_uni" },
306 { 0x0129, glk_put_string_uni, "put_string_uni" },
307 { 0x012A, glk_put_buffer_uni, "put_buffer_uni" },
308 { 0x012B, glk_put_char_stream_uni, "put_char_stream_uni" },
309 { 0x012C, glk_put_string_stream_uni, "put_string_stream_uni" },
310 { 0x012D, glk_put_buffer_stream_uni, "put_buffer_stream_uni" },
311 { 0x0130, glk_get_char_stream_uni, "get_char_stream_uni" },
312 { 0x0131, glk_get_buffer_stream_uni, "get_buffer_stream_uni" },
313 { 0x0132, glk_get_line_stream_uni, "get_line_stream_uni" },
314 { 0x0138, glk_stream_open_file_uni, "stream_open_file_uni" },
315 { 0x0139, glk_stream_open_memory_uni, "stream_open_memory_uni" },
316 #ifdef GLK_MODULE_RESOURCE_STREAM
317 { 0x013A, glk_stream_open_resource_uni, "stream_open_resource_uni" },
318 #endif /* GLK_MODULE_RESOURCE_STREAM */
319 { 0x0140, glk_request_char_event_uni, "request_char_event_uni" },
320 { 0x0141, glk_request_line_event_uni, "request_line_event_uni" },
321 #endif /* GLK_MODULE_UNICODE */
322 #ifdef GLK_MODULE_LINE_ECHO
323 { 0x0150, glk_set_echo_line_event, "set_echo_line_event" },
324 #endif /* GLK_MODULE_LINE_ECHO */
325 #ifdef GLK_MODULE_LINE_TERMINATORS
326 { 0x0151, glk_set_terminators_line_event, "set_terminators_line_event" },
327 #endif /* GLK_MODULE_LINE_TERMINATORS */
328 #ifdef GLK_MODULE_DATETIME
329 { 0x0160, glk_current_time, "current_time" },
330 { 0x0161, glk_current_simple_time, "current_simple_time" },
331 { 0x0168, glk_time_to_date_utc, "time_to_date_utc" },
332 { 0x0169, glk_time_to_date_local, "time_to_date_local" },
333 { 0x016A, glk_simple_time_to_date_utc, "simple_time_to_date_utc" },
334 { 0x016B, glk_simple_time_to_date_local, "simple_time_to_date_local" },
335 { 0x016C, glk_date_to_time_utc, "date_to_time_utc" },
336 { 0x016D, glk_date_to_time_local, "date_to_time_local" },
337 { 0x016E, glk_date_to_simple_time_utc, "date_to_simple_time_utc" },
338 { 0x016F, glk_date_to_simple_time_local, "date_to_simple_time_local" },
339 #endif /* GLK_MODULE_DATETIME */
340 #ifdef GLK_MODULE_GARGLKTEXT
341 { 0x1100, garglk_set_zcolors, "garglk_set_zcolors" },
342 { 0x1101, garglk_set_zcolors_stream, "garglk_set_zcolors_stream" },
343 { 0x1102, garglk_set_reversevideo, "garglk_set_reversevideo" },
344 { 0x1103, garglk_set_reversevideo_stream, "garglk_set_reversevideo_stream" },
345 #endif /* GLK_MODULE_GARGLKTEXT */
346 };
347
348 glui32 gidispatch_count_classes()
349 {
350 return NUMCLASSES;
351 }
352
353 gidispatch_intconst_t *gidispatch_get_class(glui32 index)
354 {
355 if (index >= NUMCLASSES)
356 return NULL;
357 return &(class_table[index]);
358 }
359
360 glui32 gidispatch_count_intconst()
361 {
362 return NUMINTCONSTANTS;
363 }
364
365 gidispatch_intconst_t *gidispatch_get_intconst(glui32 index)
366 {
367 if (index >= NUMINTCONSTANTS)
368 return NULL;
369 return &(intconstant_table[index]);
370 }
371
372 glui32 gidispatch_count_functions()
373 {
374 return NUMFUNCTIONS;
375 }
376
377 gidispatch_function_t *gidispatch_get_function(glui32 index)
378 {
379 if (index >= NUMFUNCTIONS)
380 return NULL;
381 return &(function_table[index]);
382 }
383
384 gidispatch_function_t *gidispatch_get_function_by_id(glui32 id)
385 {
386 int top, bot, val;
387 gidispatch_function_t *func;
388
389 bot = 0;
390 top = NUMFUNCTIONS;
391
392 while (1) {
393 val = (top+bot) / 2;
394 func = &(function_table[val]);
395 if (func->id == id)
396 return func;
397 if (bot >= top-1)
398 break;
399 if (func->id < id) {
400 bot = val+1;
401 }
402 else {
403 top = val;
404 }
405 }
406
407 return NULL;
408 }
409
410 char *gidispatch_prototype(glui32 funcnum)
411 {
412 switch (funcnum) {
413 case 0x0001: /* exit */
414 return "0:";
415 case 0x0002: /* set_interrupt_handler */
416 /* cannot be invoked through dispatch layer */
417 return NULL;
418 case 0x0003: /* tick */
419 return "0:";
420 case 0x0004: /* gestalt */
421 return "3IuIu:Iu";
422 case 0x0005: /* gestalt_ext */
423 return "4IuIu&#Iu:Iu";
424 case 0x0020: /* window_iterate */
425 return "3Qa<Iu:Qa";
426 case 0x0021: /* window_get_rock */
427 return "2Qa:Iu";
428 case 0x0022: /* window_get_root */
429 return "1:Qa";
430 case 0x0023: /* window_open */
431 return "6QaIuIuIuIu:Qa";
432 case 0x0024: /* window_close */
433 return "2Qa<[2IuIu]:";
434 case 0x0025: /* window_get_size */
435 return "3Qa<Iu<Iu:";
436 case 0x0026: /* window_set_arrangement */
437 return "4QaIuIuQa:";
438 case 0x0027: /* window_get_arrangement */
439 return "4Qa<Iu<Iu<Qa:";
440 case 0x0028: /* window_get_type */
441 return "2Qa:Iu";
442 case 0x0029: /* window_get_parent */
443 return "2Qa:Qa";
444 case 0x002A: /* window_clear */
445 return "1Qa:";
446 case 0x002B: /* window_move_cursor */
447 return "3QaIuIu:";
448 case 0x002C: /* window_get_stream */
449 return "2Qa:Qb";
450 case 0x002D: /* window_set_echo_stream */
451 return "2QaQb:";
452 case 0x002E: /* window_get_echo_stream */
453 return "2Qa:Qb";
454 case 0x002F: /* set_window */
455 return "1Qa:";
456 case 0x0030: /* window_get_sibling */
457 return "2Qa:Qa";
458 case 0x0040: /* stream_iterate */
459 return "3Qb<Iu:Qb";
460 case 0x0041: /* stream_get_rock */
461 return "2Qb:Iu";
462 case 0x0042: /* stream_open_file */
463 return "4QcIuIu:Qb";
464 case 0x0043: /* stream_open_memory */
465 return "4&#!CnIuIu:Qb";
466 case 0x0044: /* stream_close */
467 return "2Qb<[2IuIu]:";
468 case 0x0045: /* stream_set_position */
469 return "3QbIsIu:";
470 case 0x0046: /* stream_get_position */
471 return "2Qb:Iu";
472 case 0x0047: /* stream_set_current */
473 return "1Qb:";
474 case 0x0048: /* stream_get_current */
475 return "1:Qb";
476 case 0x0060: /* fileref_create_temp */
477 return "3IuIu:Qc";
478 case 0x0061: /* fileref_create_by_name */
479 return "4IuSIu:Qc";
480 case 0x0062: /* fileref_create_by_prompt */
481 return "4IuIuIu:Qc";
482 case 0x0063: /* fileref_destroy */
483 return "1Qc:";
484 case 0x0064: /* fileref_iterate */
485 return "3Qc<Iu:Qc";
486 case 0x0065: /* fileref_get_rock */
487 return "2Qc:Iu";
488 case 0x0066: /* fileref_delete_file */
489 return "1Qc:";
490 case 0x0067: /* fileref_does_file_exist */
491 return "2Qc:Iu";
492 case 0x0068: /* fileref_create_from_fileref */
493 return "4IuQcIu:Qc";
494 case 0x0080: /* put_char */
495 return "1Cu:";
496 case 0x0081: /* put_char_stream */
497 return "2QbCu:";
498 case 0x0082: /* put_string */
499 return "1S:";
500 case 0x0083: /* put_string_stream */
501 return "2QbS:";
502 case 0x0084: /* put_buffer */
503 return "1>+#Cn:";
504 case 0x0085: /* put_buffer_stream */
505 return "2Qb>+#Cn:";
506 case 0x0086: /* set_style */
507 return "1Iu:";
508 case 0x0087: /* set_style_stream */
509 return "2QbIu:";
510 case 0x0090: /* get_char_stream */
511 return "2Qb:Is";
512 case 0x0091: /* get_line_stream */
513 return "3Qb<+#Cn:Iu";
514 case 0x0092: /* get_buffer_stream */
515 return "3Qb<+#Cn:Iu";
516 case 0x00A0: /* char_to_lower */
517 return "2Cu:Cu";
518 case 0x00A1: /* char_to_upper */
519 return "2Cu:Cu";
520 case 0x00B0: /* stylehint_set */
521 return "4IuIuIuIs:";
522 case 0x00B1: /* stylehint_clear */
523 return "3IuIuIu:";
524 case 0x00B2: /* style_distinguish */
525 return "4QaIuIu:Iu";
526 case 0x00B3: /* style_measure */
527 return "5QaIuIu<Iu:Iu";
528 case 0x00C0: /* select */
529 return "1<+[4IuQaIuIu]:";
530 case 0x00C1: /* select_poll */
531 return "1<+[4IuQaIuIu]:";
532 case 0x00D0: /* request_line_event */
533 return "3Qa&+#!CnIu:";
534 case 0x00D1: /* cancel_line_event */
535 return "2Qa<[4IuQaIuIu]:";
536 case 0x00D2: /* request_char_event */
537 return "1Qa:";
538 case 0x00D3: /* cancel_char_event */
539 return "1Qa:";
540 case 0x00D4: /* request_mouse_event */
541 return "1Qa:";
542 case 0x00D5: /* cancel_mouse_event */
543 return "1Qa:";
544 case 0x00D6: /* request_timer_events */
545 return "1Iu:";
546
547 #ifdef GLK_MODULE_IMAGE
548 case 0x00E0: /* image_get_info */
549 return "4Iu<Iu<Iu:Iu";
550 case 0x00E1: /* image_draw */
551 return "5QaIuIsIs:Iu";
552 case 0x00E2: /* image_draw_scaled */
553 return "7QaIuIsIsIuIu:Iu";
554 case 0x00E8: /* window_flow_break */
555 return "1Qa:";
556 case 0x00E9: /* window_erase_rect */
557 return "5QaIsIsIuIu:";
558 case 0x00EA: /* window_fill_rect */
559 return "6QaIuIsIsIuIu:";
560 case 0x00EB: /* window_set_background_color */
561 return "2QaIu:";
562 #ifdef GLK_MODULE_IMAGE2
563 case 0x00EC: /* image_draw_scaled_ext */
564 return "9QaIuIsIsIuIuIuIu:Iu";
565 #endif /* GLK_MODULE_IMAGE2 */
566 #endif /* GLK_MODULE_IMAGE */
567
568 #ifdef GLK_MODULE_SOUND
569 case 0x00F0: /* schannel_iterate */
570 return "3Qd<Iu:Qd";
571 case 0x00F1: /* schannel_get_rock */
572 return "2Qd:Iu";
573 case 0x00F2: /* schannel_create */
574 return "2Iu:Qd";
575 case 0x00F3: /* schannel_destroy */
576 return "1Qd:";
577 case 0x00F8: /* schannel_play */
578 return "3QdIu:Iu";
579 case 0x00F9: /* schannel_play_ext */
580 return "5QdIuIuIu:Iu";
581 case 0x00FA: /* schannel_stop */
582 return "1Qd:";
583 case 0x00FB: /* schannel_set_volume */
584 return "2QdIu:";
585 case 0x00FC: /* sound_load_hint */
586 return "2IuIu:";
587
588 #ifdef GLK_MODULE_SOUND2
589 case 0x00F4: /* schannel_create_ext */
590 return "3IuIu:Qd";
591 case 0x00F7: /* schannel_play_multi */
592 return "4>+#Qd>+#IuIu:Iu";
593 case 0x00FD: /* schannel_set_volume_ext */
594 return "4QdIuIuIu:";
595 case 0x00FE: /* schannel_pause */
596 return "1Qd:";
597 case 0x00FF: /* schannel_unpause */
598 return "1Qd:";
599 #endif /* GLK_MODULE_SOUND2 */
600 #endif /* GLK_MODULE_SOUND */
601
602 #ifdef GLK_MODULE_HYPERLINKS
603 case 0x0100: /* set_hyperlink */
604 return "1Iu:";
605 case 0x0101: /* set_hyperlink_stream */
606 return "2QbIu:";
607 case 0x0102: /* request_hyperlink_event */
608 return "1Qa:";
609 case 0x0103: /* cancel_hyperlink_event */
610 return "1Qa:";
611 #endif /* GLK_MODULE_HYPERLINKS */
612
613 #ifdef GLK_MODULE_UNICODE
614 case 0x0120: /* buffer_to_lower_case_uni */
615 return "3&+#IuIu:Iu";
616 case 0x0121: /* buffer_to_upper_case_uni */
617 return "3&+#IuIu:Iu";
618 case 0x0122: /* buffer_to_title_case_uni */
619 return "4&+#IuIuIu:Iu";
620 case 0x0128: /* put_char_uni */
621 return "1Iu:";
622 case 0x0129: /* put_string_uni */
623 return "1U:";
624 case 0x012A: /* put_buffer_uni */
625 return "1>+#Iu:";
626 case 0x012B: /* put_char_stream_uni */
627 return "2QbIu:";
628 case 0x012C: /* put_string_stream_uni */
629 return "2QbU:";
630 case 0x012D: /* put_buffer_stream_uni */
631 return "2Qb>+#Iu:";
632 case 0x0130: /* get_char_stream_uni */
633 return "2Qb:Is";
634 case 0x0131: /* get_buffer_stream_uni */
635 return "3Qb<+#Iu:Iu";
636 case 0x0132: /* get_line_stream_uni */
637 return "3Qb<+#Iu:Iu";
638 case 0x0138: /* stream_open_file_uni */
639 return "4QcIuIu:Qb";
640 case 0x0139: /* stream_open_memory_uni */
641 return "4&#!IuIuIu:Qb";
642 case 0x0140: /* request_char_event_uni */
643 return "1Qa:";
644 case 0x0141: /* request_line_event_uni */
645 return "3Qa&+#!IuIu:";
646 #endif /* GLK_MODULE_UNICODE */
647
648 #ifdef GLK_MODULE_UNICODE_NORM
649 case 0x0123: /* buffer_canon_decompose_uni */
650 return "3&+#IuIu:Iu";
651 case 0x0124: /* buffer_canon_normalize_uni */
652 return "3&+#IuIu:Iu";
653 #endif /* GLK_MODULE_UNICODE_NORM */
654
655 #ifdef GLK_MODULE_LINE_ECHO
656 case 0x0150: /* set_echo_line_event */
657 return "2QaIu:";
658 #endif /* GLK_MODULE_LINE_ECHO */
659
660 #ifdef GLK_MODULE_LINE_TERMINATORS
661 case 0x0151: /* set_terminators_line_event */
662 return "2Qa>#Iu:";
663 #endif /* GLK_MODULE_LINE_TERMINATORS */
664
665 #ifdef GLK_MODULE_DATETIME
666 case 0x0160: /* current_time */
667 return "1<+[3IsIuIs]:";
668 case 0x0161: /* current_simple_time */
669 return "2Iu:Is";
670 case 0x0168: /* time_to_date_utc */
671 return "2>+[3IsIuIs]<+[8IsIsIsIsIsIsIsIs]:";
672 case 0x0169: /* time_to_date_local */
673 return "2>+[3IsIuIs]<+[8IsIsIsIsIsIsIsIs]:";
674 case 0x016A: /* simple_time_to_date_utc */
675 return "3IsIu<+[8IsIsIsIsIsIsIsIs]:";
676 case 0x016B: /* simple_time_to_date_local */
677 return "3IsIu<+[8IsIsIsIsIsIsIsIs]:";
678 case 0x016C: /* date_to_time_utc */
679 return "2>+[8IsIsIsIsIsIsIsIs]<+[3IsIuIs]:";
680 case 0x016D: /* date_to_time_local */
681 return "2>+[8IsIsIsIsIsIsIsIs]<+[3IsIuIs]:";
682 case 0x016E: /* date_to_simple_time_utc */
683 return "3>+[8IsIsIsIsIsIsIsIs]Iu:Is";
684 case 0x016F: /* date_to_simple_time_local */
685 return "3>+[8IsIsIsIsIsIsIsIs]Iu:Is";
686 #endif /* GLK_MODULE_DATETIME */
687
688 #ifdef GLK_MODULE_RESOURCE_STREAM
689 case 0x0049: /* stream_open_resource */
690 return "3IuIu:Qb";
691 case 0x013A: /* stream_open_resource_uni */
692 return "3IuIu:Qb";
693 #endif /* GLK_MODULE_RESOURCE_STREAM */
694
695 #ifdef GLK_EXTEND_PROTOTYPE
696 GLK_EXTEND_PROTOTYPE
697 #endif /* GLK_EXTEND_PROTOTYPE */
698
699 #ifdef GLK_MODULE_GARGLKTEXT
700 case 0x1100: /* garglk_set_zcolors */
701 return "2IuIu:";
702 case 0x1101: /* garglk_set_zcolors_stream */
703 return "3QbIuIu:";
704 case 0x1102: /* garglk_set_reversevideo */
705 return "1Iu:";
706 case 0x1103: /* garglk_set_reversevideo_stream */
707 return "2QbIu:";
708 #endif /* GLK_MODULE_GARGLKTEXT */
709
710 default:
711 return NULL;
712 }
713 }
714
715 void gidispatch_call(glui32 funcnum, glui32 numargs, gluniversal_t *arglist)
716 {
717 switch (funcnum) {
718 case 0x0001: /* exit */
719 glk_exit();
720 break;
721 case 0x0002: /* set_interrupt_handler */
722 /* cannot be invoked through dispatch layer */
723 break;
724 case 0x0003: /* tick */
725 glk_tick();
726 break;
727 case 0x0004: /* gestalt */
728 arglist[3].uint = glk_gestalt(arglist[0].uint, arglist[1].uint);
729 break;
730 case 0x0005: /* gestalt_ext */
731 if (arglist[2].ptrflag) {
732 arglist[6].uint = glk_gestalt_ext(arglist[0].uint, arglist[1].uint,
733 arglist[3].array, arglist[4].uint);
734 }
735 else {
736 arglist[4].uint = glk_gestalt_ext(arglist[0].uint, arglist[1].uint,
737 NULL, 0);
738 }
739 break;
740 case 0x0020: /* window_iterate */
741 if (arglist[1].ptrflag)
742 arglist[4].opaqueref = glk_window_iterate(arglist[0].opaqueref, &arglist[2].uint);
743 else
744 arglist[3].opaqueref = glk_window_iterate(arglist[0].opaqueref, NULL);
745 break;
746 case 0x0021: /* window_get_rock */
747 arglist[2].uint = glk_window_get_rock(arglist[0].opaqueref);
748 break;
749 case 0x0022: /* window_get_root */
750 arglist[1].opaqueref = glk_window_get_root();
751 break;
752 case 0x0023: /* window_open */
753 arglist[6].opaqueref = glk_window_open(arglist[0].opaqueref, arglist[1].uint,
754 arglist[2].uint, arglist[3].uint, arglist[4].uint);
755 break;
756 case 0x0024: /* window_close */
757 if (arglist[1].ptrflag) {
758 stream_result_t dat;
759 glk_window_close(arglist[0].opaqueref, &dat);
760 arglist[2].uint = dat.readcount;
761 arglist[3].uint = dat.writecount;
762 }
763 else {
764 glk_window_close(arglist[0].opaqueref, NULL);
765 }
766 break;
767 case 0x0025: /* window_get_size */
768 {
769 int ix = 1;
770 glui32 *ptr1, *ptr2;
771 if (!arglist[ix].ptrflag) {
772 ptr1 = NULL;
773 }
774 else {
775 ix++;
776 ptr1 = &(arglist[ix].uint);
777 }
778 ix++;
779 if (!arglist[ix].ptrflag) {
780 ptr2 = NULL;
781 }
782 else {
783 ix++;
784 ptr2 = &(arglist[ix].uint);
785 }
786 ix++;
787 glk_window_get_size(arglist[0].opaqueref, ptr1, ptr2);
788 }
789 break;
790 case 0x0026: /* window_set_arrangement */
791 glk_window_set_arrangement(arglist[0].opaqueref, arglist[1].uint,
792 arglist[2].uint, arglist[3].opaqueref);
793 break;
794 case 0x0027: /* window_get_arrangement */
795 {
796 int ix = 1;
797 glui32 *ptr1, *ptr2;
798 winid_t *ptr3;
799 if (!arglist[ix].ptrflag) {
800 ptr1 = NULL;
801 }
802 else {
803 ix++;
804 ptr1 = &(arglist[ix].uint);
805 }
806 ix++;
807 if (!arglist[ix].ptrflag) {
808 ptr2 = NULL;
809 }
810 else {
811 ix++;
812 ptr2 = &(arglist[ix].uint);
813 }
814 ix++;
815 if (!arglist[ix].ptrflag) {
816 ptr3 = NULL;
817 }
818 else {
819 ix++;
820 ptr3 = (winid_t *)(&(arglist[ix].opaqueref));
821 }
822 ix++;
823 glk_window_get_arrangement(arglist[0].opaqueref, ptr1, ptr2, ptr3);
824 }
825 break;
826 case 0x0028: /* window_get_type */
827 arglist[2].uint = glk_window_get_type(arglist[0].opaqueref);
828 break;
829 case 0x0029: /* window_get_parent */
830 arglist[2].opaqueref = glk_window_get_parent(arglist[0].opaqueref);
831 break;
832 case 0x002A: /* window_clear */
833 glk_window_clear(arglist[0].opaqueref);
834 break;
835 case 0x002B: /* window_move_cursor */
836 glk_window_move_cursor(arglist[0].opaqueref, arglist[1].uint,
837 arglist[2].uint);
838 break;
839 case 0x002C: /* window_get_stream */
840 arglist[2].opaqueref = glk_window_get_stream(arglist[0].opaqueref);
841 break;
842 case 0x002D: /* window_set_echo_stream */
843 glk_window_set_echo_stream(arglist[0].opaqueref, arglist[1].opaqueref);
844 break;
845 case 0x002E: /* window_get_echo_stream */
846 arglist[2].opaqueref = glk_window_get_echo_stream(arglist[0].opaqueref);
847 break;
848 case 0x002F: /* set_window */
849 glk_set_window(arglist[0].opaqueref);
850 break;
851 case 0x0030: /* window_get_sibling */
852 arglist[2].opaqueref = glk_window_get_sibling(arglist[0].opaqueref);
853 break;
854 case 0x0040: /* stream_iterate */
855 if (arglist[1].ptrflag)
856 arglist[4].opaqueref = glk_stream_iterate(arglist[0].opaqueref, &arglist[2].uint);
857 else
858 arglist[3].opaqueref = glk_stream_iterate(arglist[0].opaqueref, NULL);
859 break;
860 case 0x0041: /* stream_get_rock */
861 arglist[2].uint = glk_stream_get_rock(arglist[0].opaqueref);
862 break;
863 case 0x0042: /* stream_open_file */
864 arglist[4].opaqueref = glk_stream_open_file(arglist[0].opaqueref, arglist[1].uint,
865 arglist[2].uint);
866 break;
867 case 0x0043: /* stream_open_memory */
868 if (arglist[0].ptrflag)
869 arglist[6].opaqueref = glk_stream_open_memory(arglist[1].array,
870 arglist[2].uint, arglist[3].uint, arglist[4].uint);
871 else
872 arglist[4].opaqueref = glk_stream_open_memory(NULL,
873 0, arglist[1].uint, arglist[2].uint);
874 break;
875 case 0x0044: /* stream_close */
876 if (arglist[1].ptrflag) {
877 stream_result_t dat;
878 glk_stream_close(arglist[0].opaqueref, &dat);
879 arglist[2].uint = dat.readcount;
880 arglist[3].uint = dat.writecount;
881 }
882 else {
883 glk_stream_close(arglist[0].opaqueref, NULL);
884 }
885 break;
886 case 0x0045: /* stream_set_position */
887 glk_stream_set_position(arglist[0].opaqueref, arglist[1].sint,
888 arglist[2].uint);
889 break;
890 case 0x0046: /* stream_get_position */
891 arglist[2].uint = glk_stream_get_position(arglist[0].opaqueref);
892 break;
893 case 0x0047: /* stream_set_current */
894 glk_stream_set_current(arglist[0].opaqueref);
895 break;
896 case 0x0048: /* stream_get_current */
897 arglist[1].opaqueref = glk_stream_get_current();
898 break;
899 case 0x0060: /* fileref_create_temp */
900 arglist[3].opaqueref = glk_fileref_create_temp(arglist[0].uint,
901 arglist[1].uint);
902 break;
903 case 0x0061: /* fileref_create_by_name */
904 arglist[4].opaqueref = glk_fileref_create_by_name(arglist[0].uint,
905 arglist[1].charstr, arglist[2].uint);
906 break;
907 case 0x0062: /* fileref_create_by_prompt */
908 arglist[4].opaqueref = glk_fileref_create_by_prompt(arglist[0].uint,
909 arglist[1].uint, arglist[2].uint);
910 break;
911 case 0x0063: /* fileref_destroy */
912 glk_fileref_destroy(arglist[0].opaqueref);
913 break;
914 case 0x0064: /* fileref_iterate */
915 if (arglist[1].ptrflag)
916 arglist[4].opaqueref = glk_fileref_iterate(arglist[0].opaqueref, &arglist[2].uint);
917 else
918 arglist[3].opaqueref = glk_fileref_iterate(arglist[0].opaqueref, NULL);
919 break;
920 case 0x0065: /* fileref_get_rock */
921 arglist[2].uint = glk_fileref_get_rock(arglist[0].opaqueref);
922 break;
923 case 0x0066: /* fileref_delete_file */
924 glk_fileref_delete_file(arglist[0].opaqueref);
925 break;
926 case 0x0067: /* fileref_does_file_exist */
927 arglist[2].uint = glk_fileref_does_file_exist(arglist[0].opaqueref);
928 break;
929 case 0x0068: /* fileref_create_from_fileref */
930 arglist[4].opaqueref = glk_fileref_create_from_fileref(arglist[0].uint,
931 arglist[1].opaqueref, arglist[2].uint);
932 break;
933 case 0x0080: /* put_char */
934 glk_put_char(arglist[0].uch);
935 break;
936 case 0x0081: /* put_char_stream */
937 glk_put_char_stream(arglist[0].opaqueref, arglist[1].uch);
938 break;
939 case 0x0082: /* put_string */
940 glk_put_string(arglist[0].charstr);
941 break;
942 case 0x0083: /* put_string_stream */
943 glk_put_string_stream(arglist[0].opaqueref, arglist[1].charstr);
944 break;
945 case 0x0084: /* put_buffer */
946 if (arglist[0].ptrflag)
947 glk_put_buffer(arglist[1].array, arglist[2].uint);
948 else
949 glk_put_buffer(NULL, 0);
950 break;
951 case 0x0085: /* put_buffer_stream */
952 if (arglist[1].ptrflag)
953 glk_put_buffer_stream(arglist[0].opaqueref,
954 arglist[2].array, arglist[3].uint);
955 else
956 glk_put_buffer_stream(arglist[0].opaqueref,
957 NULL, 0);
958 break;
959 case 0x0086: /* set_style */
960 glk_set_style(arglist[0].uint);
961 break;
962 case 0x0087: /* set_style_stream */
963 glk_set_style_stream(arglist[0].opaqueref, arglist[1].uint);
964 break;
965 case 0x0090: /* get_char_stream */
966 arglist[2].sint = glk_get_char_stream(arglist[0].opaqueref);
967 break;
968 case 0x0091: /* get_line_stream */
969 if (arglist[1].ptrflag)
970 arglist[5].uint = glk_get_line_stream(arglist[0].opaqueref,
971 arglist[2].array, arglist[3].uint);
972 else
973 arglist[3].uint = glk_get_line_stream(arglist[0].opaqueref,
974 NULL, 0);
975 break;
976 case 0x0092: /* get_buffer_stream */
977 if (arglist[1].ptrflag)
978 arglist[5].uint = glk_get_buffer_stream(arglist[0].opaqueref,
979 arglist[2].array, arglist[3].uint);
980 else
981 arglist[3].uint = glk_get_buffer_stream(arglist[0].opaqueref,
982 NULL, 0);
983 break;
984 case 0x00A0: /* char_to_lower */
985 arglist[2].uch = glk_char_to_lower(arglist[0].uch);
986 break;
987 case 0x00A1: /* char_to_upper */
988 arglist[2].uch = glk_char_to_upper(arglist[0].uch);
989 break;
990 case 0x00B0: /* stylehint_set */
991 glk_stylehint_set(arglist[0].uint, arglist[1].uint,
992 arglist[2].uint, arglist[3].sint);
993 break;
994 case 0x00B1: /* stylehint_clear */
995 glk_stylehint_clear(arglist[0].uint, arglist[1].uint,
996 arglist[2].uint);
997 break;
998 case 0x00B2: /* style_distinguish */
999 arglist[4].uint = glk_style_distinguish(arglist[0].opaqueref, arglist[1].uint,
1000 arglist[2].uint);
1001 break;
1002 case 0x00B3: /* style_measure */
1003 if (arglist[3].ptrflag)
1004 arglist[6].uint = glk_style_measure(arglist[0].opaqueref, arglist[1].uint,
1005 arglist[2].uint, &(arglist[4].uint));
1006 else
1007 arglist[5].uint = glk_style_measure(arglist[0].opaqueref, arglist[1].uint,
1008 arglist[2].uint, NULL);
1009 break;
1010 case 0x00C0: /* select */
1011 if (arglist[0].ptrflag) {
1012 event_t dat;
1013 glk_select(&dat);
1014 arglist[1].uint = dat.type;
1015 arglist[2].opaqueref = dat.win;
1016 arglist[3].uint = dat.val1;
1017 arglist[4].uint = dat.val2;
1018 }
1019 else {
1020 glk_select(NULL);
1021 }
1022 break;
1023 case 0x00C1: /* select_poll */
1024 if (arglist[0].ptrflag) {
1025 event_t dat;
1026 glk_select_poll(&dat);
1027 arglist[1].uint = dat.type;
1028 arglist[2].opaqueref = dat.win;
1029 arglist[3].uint = dat.val1;
1030 arglist[4].uint = dat.val2;
1031 }
1032 else {
1033 glk_select_poll(NULL);
1034 }
1035 break;
1036 case 0x00D0: /* request_line_event */
1037 if (arglist[1].ptrflag)
1038 glk_request_line_event(arglist[0].opaqueref, arglist[2].array,
1039 arglist[3].uint, arglist[4].uint);
1040 else
1041 glk_request_line_event(arglist[0].opaqueref, NULL,
1042 0, arglist[2].uint);
1043 break;
1044 case 0x00D1: /* cancel_line_event */
1045 if (arglist[1].ptrflag) {
1046 event_t dat;
1047 glk_cancel_line_event(arglist[0].opaqueref, &dat);
1048 arglist[2].uint = dat.type;
1049 arglist[3].opaqueref = dat.win;
1050 arglist[4].uint = dat.val1;
1051 arglist[5].uint = dat.val2;
1052 }
1053 else {
1054 glk_cancel_line_event(arglist[0].opaqueref, NULL);
1055 }
1056 break;
1057 case 0x00D2: /* request_char_event */
1058 glk_request_char_event(arglist[0].opaqueref);
1059 break;
1060 case 0x00D3: /* cancel_char_event */
1061 glk_cancel_char_event(arglist[0].opaqueref);
1062 break;
1063 case 0x00D4: /* request_mouse_event */
1064 glk_request_mouse_event(arglist[0].opaqueref);
1065 break;
1066 case 0x00D5: /* cancel_mouse_event */
1067 glk_cancel_mouse_event(arglist[0].opaqueref);
1068 break;
1069 case 0x00D6: /* request_timer_events */
1070 glk_request_timer_events(arglist[0].uint);
1071 break;
1072
1073 #ifdef GLK_MODULE_IMAGE
1074 case 0x00E0: /* image_get_info */
1075 {
1076 int ix = 1;
1077 glui32 *ptr1, *ptr2;
1078 if (!arglist[ix].ptrflag) {
1079 ptr1 = NULL;
1080 }
1081 else {
1082 ix++;
1083 ptr1 = &(arglist[ix].uint);
1084 }
1085 ix++;
1086 if (!arglist[ix].ptrflag) {
1087 ptr2 = NULL;
1088 }
1089 else {
1090 ix++;
1091 ptr2 = &(arglist[ix].uint);
1092 }
1093 ix++;
1094 ix++;
1095 arglist[ix].uint = glk_image_get_info(arglist[0].uint, ptr1, ptr2);
1096 }
1097 break;
1098 case 0x00E1: /* image_draw */
1099 arglist[5].uint = glk_image_draw(arglist[0].opaqueref,
1100 arglist[1].uint,
1101 arglist[2].sint, arglist[3].sint);
1102 break;
1103 case 0x00E2: /* image_draw_scaled */
1104 arglist[7].uint = glk_image_draw_scaled(arglist[0].opaqueref,
1105 arglist[1].uint,
1106 arglist[2].sint, arglist[3].sint,
1107 arglist[4].uint, arglist[5].uint);
1108 break;
1109 case 0x00E8: /* window_flow_break */
1110 glk_window_flow_break(arglist[0].opaqueref);
1111 break;
1112 case 0x00E9: /* window_erase_rect */
1113 glk_window_erase_rect(arglist[0].opaqueref,
1114 arglist[1].sint, arglist[2].sint,
1115 arglist[3].uint, arglist[4].uint);
1116 break;
1117 case 0x00EA: /* window_fill_rect */
1118 glk_window_fill_rect(arglist[0].opaqueref, arglist[1].uint,
1119 arglist[2].sint, arglist[3].sint,
1120 arglist[4].uint, arglist[5].uint);
1121 break;
1122 case 0x00EB: /* window_set_background_color */
1123 glk_window_set_background_color(arglist[0].opaqueref, arglist[1].uint);
1124 break;
1125
1126 #ifdef GLK_MODULE_IMAGE2
1127 case 0x00EC: /* image_draw_scaled_ext */
1128 arglist[9].uint = glk_image_draw_scaled_ext(arglist[0].opaqueref,
1129 arglist[1].uint,
1130 arglist[2].sint, arglist[3].sint,
1131 arglist[4].uint, arglist[5].uint,
1132 arglist[6].uint, arglist[7].uint);
1133 break;
1134 #endif /* GLK_MODULE_IMAGE2 */
1135
1136 #endif /* GLK_MODULE_IMAGE */
1137
1138 #ifdef GLK_MODULE_SOUND
1139 case 0x00F0: /* schannel_iterate */
1140 if (arglist[1].ptrflag)
1141 arglist[4].opaqueref = glk_schannel_iterate(arglist[0].opaqueref, &arglist[2].uint);
1142 else
1143 arglist[3].opaqueref = glk_schannel_iterate(arglist[0].opaqueref, NULL);
1144 break;
1145 case 0x00F1: /* schannel_get_rock */
1146 arglist[2].uint = glk_schannel_get_rock(arglist[0].opaqueref);
1147 break;
1148 case 0x00F2: /* schannel_create */
1149 arglist[2].opaqueref = glk_schannel_create(arglist[0].uint);
1150 break;
1151 case 0x00F3: /* schannel_destroy */
1152 glk_schannel_destroy(arglist[0].opaqueref);
1153 break;
1154 case 0x00F8: /* schannel_play */
1155 arglist[3].uint = glk_schannel_play(arglist[0].opaqueref, arglist[1].uint);
1156 break;
1157 case 0x00F9: /* schannel_play_ext */
1158 arglist[5].uint = glk_schannel_play_ext(arglist[0].opaqueref,
1159 arglist[1].uint, arglist[2].uint, arglist[3].uint);
1160 break;
1161 case 0x00FA: /* schannel_stop */
1162 glk_schannel_stop(arglist[0].opaqueref);
1163 break;
1164 case 0x00FB: /* schannel_set_volume */
1165 glk_schannel_set_volume(arglist[0].opaqueref, arglist[1].uint);
1166 break;
1167 case 0x00FC: /* sound_load_hint */
1168 glk_sound_load_hint(arglist[0].uint, arglist[1].uint);
1169 break;
1170
1171 #ifdef GLK_MODULE_SOUND2
1172 case 0x00F4: /* schannel_create_ext */
1173 arglist[3].opaqueref = glk_schannel_create_ext(arglist[0].uint, arglist[1].uint);
1174 break;
1175 case 0x00F7: /* schannel_play_multi */
1176 if (arglist[0].ptrflag && arglist[3].ptrflag)
1177 arglist[8].uint = glk_schannel_play_multi(arglist[1].array, arglist[2].uint, arglist[4].array, arglist[5].uint, arglist[6].uint);
1178 else if (arglist[0].ptrflag)
1179 arglist[6].uint = glk_schannel_play_multi(arglist[1].array, arglist[2].uint, NULL, 0, arglist[4].uint);
1180 else if (arglist[1].ptrflag)
1181 arglist[6].uint = glk_schannel_play_multi(NULL, 0, arglist[2].array, arglist[3].uint, arglist[4].uint);
1182 else
1183 arglist[4].uint = glk_schannel_play_multi(NULL, 0, NULL, 0, arglist[2].uint);
1184 break;
1185 case 0x00FD: /* schannel_set_volume_ext */
1186 glk_schannel_set_volume_ext(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint, arglist[3].uint);
1187 break;
1188 case 0x00FE: /* schannel_pause */
1189 glk_schannel_pause(arglist[0].opaqueref);
1190 break;
1191 case 0x00FF: /* schannel_unpause */
1192 glk_schannel_unpause(arglist[0].opaqueref);
1193 break;
1194 #endif /* GLK_MODULE_SOUND2 */
1195 #endif /* GLK_MODULE_SOUND */
1196
1197 #ifdef GLK_MODULE_HYPERLINKS
1198 case 0x0100: /* set_hyperlink */
1199 glk_set_hyperlink(arglist[0].uint);
1200 break;
1201 case 0x0101: /* set_hyperlink_stream */
1202 glk_set_hyperlink_stream(arglist[0].opaqueref, arglist[1].uint);
1203 break;
1204 case 0x0102: /* request_hyperlink_event */
1205 glk_request_hyperlink_event(arglist[0].opaqueref);
1206 break;
1207 case 0x0103: /* cancel_hyperlink_event */
1208 glk_cancel_hyperlink_event(arglist[0].opaqueref);
1209 break;
1210 #endif /* GLK_MODULE_HYPERLINKS */
1211
1212 #ifdef GLK_MODULE_UNICODE
1213 case 0x0120: /* buffer_to_lower_case_uni */
1214 if (arglist[0].ptrflag)
1215 arglist[5].uint = glk_buffer_to_lower_case_uni(arglist[1].array, arglist[2].uint, arglist[3].uint);
1216 else
1217 arglist[3].uint = glk_buffer_to_lower_case_uni(NULL, 0, arglist[1].uint);
1218 break;
1219 case 0x0121: /* buffer_to_upper_case_uni */
1220 if (arglist[0].ptrflag)
1221 arglist[5].uint = glk_buffer_to_upper_case_uni(arglist[1].array, arglist[2].uint, arglist[3].uint);
1222 else
1223 arglist[3].uint = glk_buffer_to_upper_case_uni(NULL, 0, arglist[1].uint);
1224 break;
1225 case 0x0122: /* buffer_to_title_case_uni */
1226 if (arglist[0].ptrflag)
1227 arglist[6].uint = glk_buffer_to_title_case_uni(arglist[1].array, arglist[2].uint, arglist[3].uint, arglist[4].uint);
1228 else
1229 arglist[4].uint = glk_buffer_to_title_case_uni(NULL, 0, arglist[1].uint, arglist[2].uint);
1230 break;
1231 case 0x0128: /* put_char_uni */
1232 glk_put_char_uni(arglist[0].uint);
1233 break;
1234 case 0x0129: /* put_string_uni */
1235 glk_put_string_uni(arglist[0].unicharstr);
1236 break;
1237 case 0x012A: /* put_buffer_uni */
1238 if (arglist[0].ptrflag)
1239 glk_put_buffer_uni(arglist[1].array, arglist[2].uint);
1240 else
1241 glk_put_buffer_uni(NULL, 0);
1242 break;
1243 case 0x012B: /* put_char_stream_uni */
1244 glk_put_char_stream_uni(arglist[0].opaqueref, arglist[1].uint);
1245 break;
1246 case 0x012C: /* put_string_stream_uni */
1247 glk_put_string_stream_uni(arglist[0].opaqueref, arglist[1].unicharstr);
1248 break;
1249 case 0x012D: /* put_buffer_stream_uni */
1250 if (arglist[1].ptrflag)
1251 glk_put_buffer_stream_uni(arglist[0].opaqueref,
1252 arglist[2].array, arglist[3].uint);
1253 else
1254 glk_put_buffer_stream_uni(arglist[0].opaqueref,
1255 NULL, 0);
1256 break;
1257 case 0x0130: /* get_char_stream_uni */
1258 arglist[2].sint = glk_get_char_stream_uni(arglist[0].opaqueref);
1259 break;
1260 case 0x0131: /* get_buffer_stream_uni */
1261 if (arglist[1].ptrflag)
1262 arglist[5].uint = glk_get_buffer_stream_uni(arglist[0].opaqueref,
1263 arglist[2].array, arglist[3].uint);
1264 else
1265 arglist[3].uint = glk_get_buffer_stream_uni(arglist[0].opaqueref,
1266 NULL, 0);
1267 break;
1268 case 0x0132: /* get_line_stream_uni */
1269 if (arglist[1].ptrflag)
1270 arglist[5].uint = glk_get_line_stream_uni(arglist[0].opaqueref,
1271 arglist[2].array, arglist[3].uint);
1272 else
1273 arglist[3].uint = glk_get_line_stream_uni(arglist[0].opaqueref,
1274 NULL, 0);
1275 break;
1276 case 0x0138: /* stream_open_file_uni */
1277 arglist[4].opaqueref = glk_stream_open_file_uni(arglist[0].opaqueref, arglist[1].uint,
1278 arglist[2].uint);
1279 break;
1280 case 0x0139: /* stream_open_memory_uni */
1281 if (arglist[0].ptrflag)
1282 arglist[6].opaqueref = glk_stream_open_memory_uni(arglist[1].array,
1283 arglist[2].uint, arglist[3].uint, arglist[4].uint);
1284 else
1285 arglist[4].opaqueref = glk_stream_open_memory_uni(NULL,
1286 0, arglist[1].uint, arglist[2].uint);
1287 break;
1288 case 0x0140: /* request_char_event_uni */
1289 glk_request_char_event_uni(arglist[0].opaqueref);
1290 break;
1291 case 0x0141: /* request_line_event_uni */
1292 if (arglist[1].ptrflag)
1293 glk_request_line_event_uni(arglist[0].opaqueref, arglist[2].array,
1294 arglist[3].uint, arglist[4].uint);
1295 else
1296 glk_request_line_event_uni(arglist[0].opaqueref, NULL,
1297 0, arglist[2].uint);
1298 break;
1299 #endif /* GLK_MODULE_UNICODE */
1300
1301 #ifdef GLK_MODULE_UNICODE_NORM
1302 case 0x0123: /* buffer_canon_decompose_uni */
1303 if (arglist[0].ptrflag)
1304 arglist[5].uint = glk_buffer_canon_decompose_uni(arglist[1].array, arglist[2].uint, arglist[3].uint);
1305 else
1306 arglist[3].uint = glk_buffer_canon_decompose_uni(NULL, 0, arglist[1].uint);
1307 break;
1308 case 0x0124: /* buffer_canon_normalize_uni */
1309 if (arglist[0].ptrflag)
1310 arglist[5].uint = glk_buffer_canon_normalize_uni(arglist[1].array, arglist[2].uint, arglist[3].uint);
1311 else
1312 arglist[3].uint = glk_buffer_canon_normalize_uni(NULL, 0, arglist[1].uint);
1313 break;
1314 #endif /* GLK_MODULE_UNICODE_NORM */
1315
1316 #ifdef GLK_MODULE_LINE_ECHO
1317 case 0x0150: /* set_echo_line_event */
1318 glk_set_echo_line_event(arglist[0].opaqueref, arglist[1].uint);
1319 break;
1320 #endif /* GLK_MODULE_LINE_ECHO */
1321
1322 #ifdef GLK_MODULE_LINE_TERMINATORS
1323 case 0x0151: /* set_terminators_line_event */
1324 if (arglist[1].ptrflag)
1325 glk_set_terminators_line_event(arglist[0].opaqueref,
1326 arglist[2].array, arglist[3].uint);
1327 else
1328 glk_set_terminators_line_event(arglist[0].opaqueref,
1329 NULL, 0);
1330 break;
1331 #endif /* GLK_MODULE_LINE_TERMINATORS */
1332
1333 #ifdef GLK_MODULE_DATETIME
1334 case 0x0160: /* current_time */
1335 if (arglist[0].ptrflag) {
1336 glktimeval_t dat;
1337 glk_current_time(&dat);
1338 arglist[1].sint = dat.high_sec;
1339 arglist[2].uint = dat.low_sec;
1340 arglist[3].sint = dat.microsec;
1341 }
1342 else {
1343 glk_current_time(NULL);
1344 }
1345 break;
1346 case 0x0161: /* current_simple_time */
1347 arglist[2].sint = glk_current_simple_time(arglist[0].uint);
1348 break;
1349 case 0x0168: /* time_to_date_utc */ {
1350 glktimeval_t timeval;
1351 glktimeval_t *timeptr = NULL;
1352 glkdate_t date;
1353 glkdate_t *dateptr = NULL;
1354 int ix = 0;
1355 if (arglist[ix++].ptrflag) {
1356 timeptr = &timeval;
1357 timeval.high_sec = arglist[ix++].sint;
1358 timeval.low_sec = arglist[ix++].uint;
1359 timeval.microsec = arglist[ix++].sint;
1360 }
1361 if (arglist[ix++].ptrflag) {
1362 dateptr = &date;
1363 }
1364 glk_time_to_date_utc(timeptr, dateptr);
1365 if (dateptr) {
1366 arglist[ix++].sint = date.year;
1367 arglist[ix++].sint = date.month;
1368 arglist[ix++].sint = date.day;
1369 arglist[ix++].sint = date.weekday;
1370 arglist[ix++].sint = date.hour;
1371 arglist[ix++].sint = date.minute;
1372 arglist[ix++].sint = date.second;
1373 arglist[ix++].sint = date.microsec;
1374 }
1375 }
1376 break;
1377 case 0x0169: /* time_to_date_local */ {
1378 glktimeval_t timeval;
1379 glktimeval_t *timeptr = NULL;
1380 glkdate_t date;
1381 glkdate_t *dateptr = NULL;
1382 int ix = 0;
1383 if (arglist[ix++].ptrflag) {
1384 timeptr = &timeval;
1385 timeval.high_sec = arglist[ix++].sint;
1386 timeval.low_sec = arglist[ix++].uint;
1387 timeval.microsec = arglist[ix++].sint;
1388 }
1389 if (arglist[ix++].ptrflag) {
1390 dateptr = &date;
1391 }
1392 glk_time_to_date_local(timeptr, dateptr);
1393 if (dateptr) {
1394 arglist[ix++].sint = date.year;
1395 arglist[ix++].sint = date.month;
1396 arglist[ix++].sint = date.day;
1397 arglist[ix++].sint = date.weekday;
1398 arglist[ix++].sint = date.hour;
1399 arglist[ix++].sint = date.minute;
1400 arglist[ix++].sint = date.second;
1401 arglist[ix++].sint = date.microsec;
1402 }
1403 }
1404 break;
1405 case 0x016A: /* simple_time_to_date_utc */ {
1406 glkdate_t date;
1407 glkdate_t *dateptr = NULL;
1408 int ix = 2;
1409 if (arglist[ix++].ptrflag) {
1410 dateptr = &date;
1411 }
1412 glk_simple_time_to_date_utc(arglist[0].sint, arglist[1].uint, dateptr);
1413 if (dateptr) {
1414 arglist[ix++].sint = date.year;
1415 arglist[ix++].sint = date.month;
1416 arglist[ix++].sint = date.day;
1417 arglist[ix++].sint = date.weekday;
1418 arglist[ix++].sint = date.hour;
1419 arglist[ix++].sint = date.minute;
1420 arglist[ix++].sint = date.second;
1421 arglist[ix++].sint = date.microsec;
1422 }
1423 }
1424 break;
1425 case 0x016B: /* simple_time_to_date_local */ {
1426 glkdate_t date;
1427 glkdate_t *dateptr = NULL;
1428 int ix = 2;
1429 if (arglist[ix++].ptrflag) {
1430 dateptr = &date;
1431 }
1432 glk_simple_time_to_date_local(arglist[0].sint, arglist[1].uint, dateptr);
1433 if (dateptr) {
1434 arglist[ix++].sint = date.year;
1435 arglist[ix++].sint = date.month;
1436 arglist[ix++].sint = date.day;
1437 arglist[ix++].sint = date.weekday;
1438 arglist[ix++].sint = date.hour;
1439 arglist[ix++].sint = date.minute;
1440 arglist[ix++].sint = date.second;
1441 arglist[ix++].sint = date.microsec;
1442 }
1443 }
1444 break;
1445 case 0x016C: /* date_to_time_utc */ {
1446 glkdate_t date;
1447 glkdate_t *dateptr = NULL;
1448 glktimeval_t timeval;
1449 glktimeval_t *timeptr = NULL;
1450 int ix = 0;
1451 if (arglist[ix++].ptrflag) {
1452 dateptr = &date;
1453 date.year = arglist[ix++].sint;
1454 date.month = arglist[ix++].sint;
1455 date.day = arglist[ix++].sint;
1456 date.weekday = arglist[ix++].sint;
1457 date.hour = arglist[ix++].sint;
1458 date.minute = arglist[ix++].sint;
1459 date.second = arglist[ix++].sint;
1460 date.microsec = arglist[ix++].sint;
1461 }
1462 if (arglist[ix++].ptrflag) {
1463 timeptr = &timeval;
1464 }
1465 glk_date_to_time_utc(dateptr, timeptr);
1466 if (timeptr) {
1467 arglist[ix++].sint = timeval.high_sec;
1468 arglist[ix++].uint = timeval.low_sec;
1469 arglist[ix++].sint = timeval.microsec;
1470 }
1471 }
1472 break;
1473 case 0x016D: /* date_to_time_local */ {
1474 glkdate_t date;
1475 glkdate_t *dateptr = NULL;
1476 glktimeval_t timeval;
1477 glktimeval_t *timeptr = NULL;
1478 int ix = 0;
1479 if (arglist[ix++].ptrflag) {
1480 dateptr = &date;
1481 date.year = arglist[ix++].sint;
1482 date.month = arglist[ix++].sint;
1483 date.day = arglist[ix++].sint;
1484 date.weekday = arglist[ix++].sint;
1485 date.hour = arglist[ix++].sint;
1486 date.minute = arglist[ix++].sint;
1487 date.second = arglist[ix++].sint;
1488 date.microsec = arglist[ix++].sint;
1489 }
1490 if (arglist[ix++].ptrflag) {
1491 timeptr = &timeval;
1492 }
1493 glk_date_to_time_local(dateptr, timeptr);
1494 if (timeptr) {
1495 arglist[ix++].sint = timeval.high_sec;
1496 arglist[ix++].uint = timeval.low_sec;
1497 arglist[ix++].sint = timeval.microsec;
1498 }
1499 }
1500 break;
1501 case 0x016E: /* date_to_simple_time_utc */ {
1502 glkdate_t date;
1503 glkdate_t *dateptr = NULL;
1504 int ix = 0;
1505 if (arglist[ix++].ptrflag) {
1506 dateptr = &date;
1507 date.year = arglist[ix++].sint;
1508 date.month = arglist[ix++].sint;
1509 date.day = arglist[ix++].sint;
1510 date.weekday = arglist[ix++].sint;
1511 date.hour = arglist[ix++].sint;
1512 date.minute = arglist[ix++].sint;
1513 date.second = arglist[ix++].sint;
1514 date.microsec = arglist[ix++].sint;
1515 }
1516 arglist[ix+2].sint = glk_date_to_simple_time_utc(dateptr, arglist[ix].uint);
1517 }
1518 break;
1519 case 0x016F: /* date_to_simple_time_local */ {
1520 glkdate_t date;
1521 glkdate_t *dateptr = NULL;
1522 int ix = 0;
1523 if (arglist[ix++].ptrflag) {
1524 dateptr = &date;
1525 date.year = arglist[ix++].sint;
1526 date.month = arglist[ix++].sint;
1527 date.day = arglist[ix++].sint;
1528 date.weekday = arglist[ix++].sint;
1529 date.hour = arglist[ix++].sint;
1530 date.minute = arglist[ix++].sint;
1531 date.second = arglist[ix++].sint;
1532 date.microsec = arglist[ix++].sint;
1533 }
1534 arglist[ix+2].sint = glk_date_to_simple_time_local(dateptr, arglist[ix].uint);
1535 }
1536 break;
1537 #endif /* GLK_MODULE_DATETIME */
1538
1539 #ifdef GLK_MODULE_RESOURCE_STREAM
1540 case 0x0049: /* stream_open_resource */
1541 arglist[3].opaqueref = glk_stream_open_resource(arglist[0].uint, arglist[1].uint);
1542 break;
1543 case 0x013A: /* stream_open_resource_uni */
1544 arglist[3].opaqueref = glk_stream_open_resource_uni(arglist[0].uint, arglist[1].uint);
1545 break;
1546 #endif /* GLK_MODULE_RESOURCE_STREAM */
1547
1548 #ifdef GLK_EXTEND_CALL
1549 GLK_EXTEND_CALL
1550 #endif /* GLK_EXTEND_CALL */
1551
1552 #ifdef GLK_MODULE_GARGLKTEXT
1553 case 0x1100: /* garglk_set_zcolors */
1554 garglk_set_zcolors( arglist[0].uint, arglist[1].uint );
1555 break;
1556 case 0x1101: /* garglk_set_zcolors_stream */
1557 garglk_set_zcolors_stream( arglist[0].opaqueref, arglist[1].uint, arglist[2].uint );
1558 break;
1559 case 0x1102: /* garglk_set_reversevideo */
1560 garglk_set_reversevideo( arglist[0].uint );
1561 break;
1562 case 0x1103: /* garglk_set_reversevideo_stream */
1563 garglk_set_reversevideo_stream( arglist[0].opaqueref, arglist[1].uint );
1564 break;
1565 #endif /* GLK_MODULE_GARGLKTEXT */
1566
1567 default:
1568 /* do nothing */
1569 break;
1570 }
1571 }
1572
1573 #ifdef GI_DISPA_GAME_ID_AVAILABLE
1574
1575 static char *(*game_id_hook)(void) = NULL;
1576
1577 /* Set a function for getting a game ID string. The Glk library may
1578 call the supplied function when creating files, so that the files
1579 can be put in a game-specific location.
1580
1581 The function must have the form: char *func(void);
1582
1583 It should return NULL or a pointer to a (null-terminated) string.
1584 (The string will be copied, so it may be in a temporary buffer.)
1585 */
1586 void gidispatch_set_game_id_hook(char *(*hook)(void))
1587 {
1588 game_id_hook = hook;
1589 }
1590
1591 /* Retrieve a game ID string for the current game.
1592
1593 If not NULL, this string may be in a temporary buffer, so the caller
1594 must copy it!
1595 */
1596 char *gidispatch_get_game_id(void)
1597 {
1598 if (!game_id_hook)
1599 return NULL;
1600 return game_id_hook();
1601 }
1602
1603 #endif /* GI_DISPA_GAME_ID_AVAILABLE */