1 /* input.c - High level input functions
2 * Copyright (c) 1995-1997 Stefan Jokisch
4 * Changes for Rockbox copyright 2009 Torne Wuff
6 * This file is part of Frotz.
8 * Frotz is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Frotz is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
25 extern int save_undo (void);
27 extern zchar
stream_read_key (zword
, zword
, bool);
28 extern zchar
stream_read_input (int, zchar
*, zword
, zword
, bool, bool);
30 extern void tokenise_line (zword
, zword
, zword
, bool);
35 * Check if the given key is an input terminator.
39 bool is_terminator (zchar key
)
42 if (key
== ZC_TIME_OUT
)
46 if (key
>= ZC_HKEY_MIN
&& key
<= ZC_HKEY_MAX
)
49 if (h_terminating_keys
!= 0)
51 if (key
>= ZC_ARROW_MIN
&& key
<= ZC_MENU_CLICK
) {
53 zword addr
= h_terminating_keys
;
58 if (c
== 255 || key
== translate_from_zscii (c
))
70 * z_make_menu, add or remove a menu and branch if successful.
72 * zargs[0] = number of menu
73 * zargs[1] = table of menu entries or 0 to remove menu
77 void z_make_menu (void)
80 /* This opcode was only used for the Macintosh version of Journey.
81 It controls menus with numbers greater than 2 (menus 0, 1 and 2
82 are system menus). Frotz doesn't implement menus yet. */
88 extern bool read_yes_or_no (const char *s
);
93 * Read a string from the current input stream.
97 void read_string (int max
, zchar
*buffer
)
105 key
= stream_read_input (max
, buffer
, 0, 0, FALSE
, FALSE
);
107 } while (key
!= ZC_RETURN
);
114 * Ask the user to type in a number and return it.
118 int read_number (void)
124 read_string (5, buffer
);
126 for (i
= 0; buffer
[i
] != 0; i
++)
127 if (buffer
[i
] >= '0' && buffer
[i
] <= '9')
128 value
= 10 * value
+ buffer
[i
] - '0';
135 * z_read, read a line of input and (in V5+) store the terminating key.
137 * zargs[0] = address of text buffer
138 * zargs[1] = address of token buffer
139 * zargs[2] = timeout in tenths of a second (optional)
140 * zargs[3] = packed address of routine to be called on timeout
146 zchar buffer
[INPUT_BUFFER_SIZE
];
153 /* Supply default arguments */
158 /* Get maximum input size */
167 if (max
>= INPUT_BUFFER_SIZE
)
168 max
= INPUT_BUFFER_SIZE
- 1;
170 /* Get initial input size */
172 if (h_version
>= V5
) {
174 LOW_BYTE (addr
, size
)
177 /* Copy initial input to local buffer */
179 for (i
= 0; i
< size
; i
++) {
182 buffer
[i
] = translate_from_zscii (c
);
187 /* Draw status line for V1 to V3 games */
192 /* Read input from current input stream */
194 key
= stream_read_input (
195 max
, buffer
, /* buffer and size */
196 zargs
[2], /* timeout value */
197 zargs
[3], /* timeout routine */
198 TRUE
, /* enable hot keys */
199 h_version
== V6
); /* no script in V6 */
204 /* Perform save_undo for V1 to V4 games */
209 /* Copy local buffer back to dynamic memory */
211 for (i
= 0; buffer
[i
] != 0; i
++) {
213 if (key
== ZC_RETURN
) {
215 if (buffer
[i
] >= 'A' && buffer
[i
] <= 'Z')
216 buffer
[i
] += 'a' - 'A';
217 if (buffer
[i
] >= 0xc0 && buffer
[i
] <= 0xde && buffer
[i
] != 0xd7)
222 storeb ((zword
) (zargs
[0] + ((h_version
<= V4
) ? 1 : 2) + i
), translate_to_zscii (buffer
[i
]));
226 /* Add null character (V1-V4) or write input length into 2nd byte */
229 storeb ((zword
) (zargs
[0] + 1 + i
), 0);
231 storeb ((zword
) (zargs
[0] + 1), i
);
233 /* Tokenise line if a token buffer is present */
235 if (key
== ZC_RETURN
&& zargs
[1] != 0)
236 tokenise_line (zargs
[0], zargs
[1], 0, FALSE
);
241 store (translate_to_zscii (key
));
246 * z_read_char, read and store a key.
248 * zargs[0] = input device (must be 1)
249 * zargs[1] = timeout in tenths of a second (optional)
250 * zargs[2] = packed address of routine to be called on timeout
254 void z_read_char (void)
258 /* Supply default arguments */
263 /* Read input from the current input stream */
265 key
= stream_read_key (
266 zargs
[1], /* timeout value */
267 zargs
[2], /* timeout routine */
268 TRUE
); /* enable hot keys */
275 store (translate_to_zscii (key
));
280 * z_read_mouse, write the current mouse status into a table.
282 * zargs[0] = address of table
286 void z_read_mouse (void)
290 /* Read the mouse position and which buttons are down */
292 btn
= os_read_mouse ();
293 hx_mouse_y
= mouse_y
;
294 hx_mouse_x
= mouse_x
;
296 storew ((zword
) (zargs
[0] + 0), hx_mouse_y
);
297 storew ((zword
) (zargs
[0] + 2), hx_mouse_x
);
298 storew ((zword
) (zargs
[0] + 4), btn
); /* mouse button bits */
299 storew ((zword
) (zargs
[0] + 6), 0); /* menu selection */