2
* osbeos.c -- copyright (c) 2000 by Christopher Tate, all rights reserved.
4
* Please see the accompanying license file, LICENSE.TXT, for information
5
* on using and copying this software.
8
// Just the parts of osbeos.cpp that are superceded by HTML Tads
10
// appctx.h needs size_t to be defined
17
void set_cbreak_mode (int mode);
19
/* write a string to the main console */
20
void os_printz(const char *str)
25
/* write a non-null-terminated string to the console */
26
void os_print(const char *str, size_t len)
28
if (os_get_status() == 0) // discard non-main-window
30
printf("%.*s", (int)len, str);
34
/* display a string in the score area in the status line. These stubs are only for non-HTML tads */
35
void os_strsc(const char* /*p*/)
37
// no status line; ignore
40
/* set the status line mode */
41
// global state: are we updating the status line, or the main text of the game log?
42
static int gStatusMode = 0;
44
void os_status(int stat)
49
/* get the status line mode */
55
/* set the score value */
56
void os_score(int /*cur*/, int /*turncount*/)
58
// no status line; ignore
61
/* clear the screen */
64
// !!! don't do anything for now
67
/* flush any buffered display output */
74
* Get highlighting character code. This returns a character code to
75
* write to the display in order to activate a highlighting mode: mode 1
76
* = turn on boldface, mode 2 = turn off boldface. A return value of
77
* zero indicates that highlighting is not supported; otherwise, the
78
* return value is the character to write to the display to activate the
81
int os_hilite(int /*mode*/)
83
return 0; // !!! no hilighting for now
87
* os_plain() - Use plain ascii mode for the display. If possible and
88
* necessary, turn off any text formatting effects, such as cursor
89
* positioning, highlighting, or coloring. If this routine is called,
90
* the terminal should be treated as a simple text stream; users might
91
* wish to use this mode for things like text-to-speech converters.
93
* Purely graphical implementations that cannot offer a textual mode
94
* (such as Mac OS or Windows) can ignore this setting.
96
* If this routine is to be called, it must be called BEFORE os_init().
97
* The implementation should set a flag so that os_init() will know to
98
* set up the terminal for plain text output.
102
* some platforms (e.g. Mac OS) define this to be a null macro, so don't
103
* define a prototype in those cases
108
#endif // #ifndef os_plain
111
* Set the game title. The output layer calls this routine when a game
112
* sets its title (via an HTML <title> tag, for example). If it's
113
* convenient to do so, the OS layer can use this string to set a window
114
* caption, or whatever else makes sense on each system. Most
115
* character-mode implementations will provide an empty implementation,
116
* since there's not usually any standard way to show the current
117
* application title on a character-mode display.
119
void os_set_title(const char */*title*/)
121
// don't bother on BeOS in a Terminal
124
/* These terminal-based input functions are only for non-HTML tads */
125
unsigned char *os_gets(unsigned char *buf, size_t bufl)
127
fgets((char*) buf, bufl, stdin);
129
// postprocess the string to handle editing characters, etc.
130
char* newbuf = (char*) malloc(bufl);
131
memcpy(newbuf, buf, bufl);
133
char* p = (char*) buf;
139
case 0x08: // backspace
143
case 0x15: // control-U == kill entire line
147
case '\r': // end of line
158
memcpy(buf, newbuf, bufl);
164
* Read a character from the keyboard. For extended keystrokes, this
165
* function returns zero, and then returns the CMD_xxx code for the
166
* extended keystroke on the next call. For example, if the user
167
* presses the up-arrow key, the first call to os_getc() should return
168
* 0, and the next call should return CMD_UP. Refer to the CMD_xxx
171
* os_getc() should return a high-level, translated command code for
172
* command editing. This means that, where a functional interpretation
173
* of a key and the raw key-cap interpretation both exist as CMD_xxx
174
* codes, the functional interpretation should be returned. For
175
* example, on Unix, Ctrl-E is conventionally used in command editing to
176
* move to the end of the line, following Emacs key bindings. Hence,
177
* os_getc() should return CMD_END for this keystroke, rather than
178
* (CMD_CTRL + 'E' - 'A'), because CMD_END is the high-level command
179
* code for the operation.
181
* The translation ability of this function allows for system-dependent
182
* key mappings to functional meanings.
186
return os_getc_raw();
190
* Read a character from the keyboard, following the same protocol as
191
* os_getc() for CMD_xxx codes (i.e., when an extended keystroke is
192
* encountered, os_getc_raw() returns zero, then returns the CMD_xxx
193
* code on the subsequent call).
195
* This function differs from os_getc() in that this function returns
196
* the low-level, untranslated key code. This means that, when a
197
* functional interpretation of a key and the raw key-cap interpretation
198
* both exist as CMD_xxx codes, this function returns the key-cap
199
* interpretation. For the Unix Ctrl-E example in the comments
200
* describing os_getc() above, this function should return 5 (the ASCII
201
* code for Ctrl-E), because the CMD_CTRL interpretation is the
202
* low-level key code.
204
* This function should return all control keys using their ASCII
205
* control codes, whenever possible. Similarly, this function should
206
* return ASCII 27 for the Escape key, if possible.
208
int os_getc_raw(void)
216
/* wait for a character to become available from the keyboard */
223
* Get an input event. The event types are shown above. If use_timeout
224
* is false, this routine should simply wait until one of the events it
225
* recognizes occurs, then return the appropriate information on the
226
* event. If use_timeout is true, this routine should return
227
* OS_EVT_TIMEOUT after the given number of milliseconds elapses if no
228
* event occurs first.
230
* This function is not obligated to obey the timeout. If a timeout is
231
* specified and it is not possible to obey the timeout, the function
232
* should simply return OS_EVT_NOTIMEOUT. The trivial implementation
233
* thus checks for a timeout, returns an error if specified, and
234
* otherwise simply waits for the user to press a key.
236
int os_get_event(unsigned long /*timeout_in_milliseconds*/, int use_timeout, os_event_info_t *info)
238
/* if there's a timeout, return an error indicating we don't allow it */
240
return OS_EVT_NOTIMEOUT;
242
/* get a key the normal way */
243
info->key[0] = os_getc();
245
/* if it's an extended key, get the other key */
246
if (info->key[0] == 0)
247
info->key[1] = os_getc();
249
/* return the keyboard event */
253
/* pause prior to exit */
254
void os_expause(void)
256
os_printz("(Strike any key to exit...)");
263
* Check for user break (control-C, etc) - returns true if a break is
264
* pending, false if not. If this returns true, it should "consume" the
265
* pending break (probably by simply clearing the OS code's internal
266
* break-pending flag).
273
/* ------------------------------------------------------------------------*/
275
* Translate a character from the HTML 4 Unicode character set to the
276
* current character set used for display. Takes an HTML 4 character
277
* code and returns the appropriate local character code.
279
* The result buffer should be filled in with a null-terminated string
280
* that should be used to represent the character. Multi-character
281
* results are possible, which may be useful for certain approximations
282
* (such as using "(c)" for the copyright symbol).
284
* Note that we only define this prototype if this symbol isn't already
285
* defined as a macro, which may be the case on some platforms.
286
* Alternatively, if the function is already defined (for example, as an
287
* inline function), the defining code can define OS_XLAT_HTML4_DEFINED,
288
* in which case we'll also omit this prototype.
290
* Important: this routine provides the *default* mapping that is used
291
* when no external character mapping file is present, and for any named
292
* entities not defined in the mapping file. Any entities in the
293
* mapping file, if used, will override this routine.
295
* A trivial implementation of this routine (that simply returns a
296
* one-character result consisting of the original input character,
297
* truncated to eight bits if necessary) can be used if you want to
298
* require an external mapping file to be used for any game that
299
* includes HTML character entities. The DOS version implements this
300
* routine so that games will still look reasonable when played with no
301
* mapping file present, but other systems are not required to do this.
303
#ifndef os_xlat_html4
304
# ifndef OS_XLAT_HTML4_DEFINED
305
void os_xlat_html4(unsigned int html4_char,
306
char *result, size_t result_buf_len)
308
// This routine actually translates a Unicode-16 character to an appropriate
309
// implementation-defined string. On BeOS, this just means translating it to
310
// UTF-8, which is supported by the sprintf() routine's "wide char" formatting.
311
snprintf(result, result_buf_len, "%lc", html4_char);