1
/* vi: set ts=2 shiftwidth=2 expandtab:
3
* Copyright (C) 2003-2008 Simon Baldwin and Mark J. Tilford
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of version 2 of the GNU General Public License
7
* as published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23
* o This module represents just about the simplest platform input/output
24
* code possible for SCARE. Actually, it could be simplified still further
25
* by abandoning attempts to word wrap at 78 columns of text, and by
26
* ignoring all tags altogether, though this may stop some games playing
27
* quite like they should.
29
* o Feel free to use this code as a starting point for a platform port.
41
enum { FALSE = 0, TRUE = !FALSE };
43
static sc_char line_buffer[79];
44
static sc_int line_length = 0;
46
static const sc_char *game_file;
60
fwrite (line_buffer, 1, line_length, stdout);
71
const sc_char *line_break;
73
line_buffer[line_length] = '\0';
74
line_break = strrchr (line_buffer, ' ');
77
fwrite (line_buffer, 1, line_break - line_buffer, stdout);
78
memmove (line_buffer, line_break + 1, strlen (line_break) + 1);
79
line_length = strlen (line_buffer);
88
append_character (sc_char c)
97
line_buffer[line_length++] = c;
98
if (line_length >= (sc_int) sizeof (line_buffer) - 1)
110
* os_print_string_debug()
113
os_print_tag (sc_int tag, const sc_char *argument)
116
const sc_char *unused;
122
for (index_ = 0; index_ < 25; index_++)
123
append_character ('\n');
128
case SC_TAG_ENDCENTER:
129
case SC_TAG_ENDRIGHT:
131
append_character ('\n');
139
fgets (dummy, sizeof (dummy), stdin);
146
os_print_string (const sc_char *string)
150
for (index_ = 0; string[index_] != '\0'; index_++)
152
if (string[index_] == '\t')
153
os_print_string (" ");
155
append_character (string[index_]);
160
os_print_string_debug (const sc_char *string)
162
os_print_string (string);
172
os_play_sound (const sc_char *filepath,
173
sc_int offset, sc_int length, sc_bool is_looping)
175
const sc_char *unused1;
176
sc_int unused2, unused3;
181
unused4 = is_looping;
190
os_show_graphic (const sc_char *filepath, sc_int offset, sc_int length)
192
#ifdef LINUX_GRAPHICS
193
const sc_char *unused1;
196
if (length > 0 && strlen (game_file) < 768)
198
sc_char buffer[1024];
201
"dd if=%s ibs=1c skip=%ld count=%ld obs=100k"
202
" of=/tmp/scare.jpg 2>/dev/null", game_file, offset, length);
204
system ("xv /tmp/scare.jpg >/dev/null 2>&1 &");
205
system ("( sleep 10; rm /tmp/scare.jpg ) >/dev/null 2>&1 &");
208
const sc_char *unused1;
209
sc_int unused2, unused3;
219
* os_read_line_debug()
222
os_read_line (sc_char *buffer, sc_int length)
230
fgets (buffer, length, stdin);
235
os_read_line_debug (sc_char *buffer, sc_int length)
241
printf ("[SCARE debug]");
242
return os_read_line (buffer, length);
250
os_confirm (sc_int type)
254
if (type == SC_CONF_SAVE)
259
return type == SC_CONF_QUIT;
263
printf ("Do you really want to ");
269
case SC_CONF_RESTART:
272
case SC_CONF_RESTORE:
275
case SC_CONF_VIEW_HINTS:
276
printf ("view hints");
284
fgets (buffer, sizeof (buffer), stdin);
286
while (toupper (buffer[0]) != 'Y' && toupper (buffer[0]) != 'N');
288
return toupper (buffer[0]) == 'Y';
299
os_open_file (sc_bool is_save)
308
printf ("Enter saved game to %s: ", is_save ? "save" : "load");
310
fgets (path, sizeof (path), stdin);
311
if (path[strlen (path) - 1] == '\n')
312
path[strlen (path) - 1] = '\0';
316
stream = fopen (path, "rb");
320
printf ("File already exists.\n");
323
stream = fopen (path, "wb");
326
stream = fopen (path, "rb");
330
printf ("Error opening file.\n");
337
os_read_file (void *opaque, sc_byte *buffer, sc_int length)
339
FILE *stream = (FILE *) opaque;
342
bytes = fread (buffer, 1, length, stream);
344
fprintf (stderr, "Read error: %s\n", strerror (errno));
350
os_write_file (void *opaque, const sc_byte *buffer, sc_int length)
352
FILE *stream = (FILE *) opaque;
354
fwrite (buffer, 1, length, stream);
356
fprintf (stderr, "Write error: %s\n", strerror (errno));
360
os_close_file (void *opaque)
362
FILE *stream = (FILE *) opaque;
372
os_display_hints (sc_game game_)
375
assert (game_ == game);
378
for (hint = sc_get_first_game_hint (game);
379
hint; hint = sc_get_next_game_hint (game, hint))
381
const sc_char *hint_text;
383
printf ("%s\n", sc_get_game_hint_question (game, hint));
385
hint_text = sc_get_game_subtle_hint (game, hint);
387
printf ("- %s\n", hint_text);
389
hint_text = sc_get_game_unsubtle_hint (game, hint);
391
printf ("- %s\n", hint_text);
400
main (int argc, const char *argv[])
403
const char *trace_flags, *locale;
404
assert (argc > 0 && argv);
408
fprintf (stderr, "Usage: %s taf_file\n", argv[0]);
412
stream = fopen (argv[1], "rb");
415
fprintf (stderr, "%s: %s: %s\n", argv[0], argv[1], strerror (errno));
419
trace_flags = getenv ("SC_TRACE_FLAGS");
421
sc_set_trace_flags (strtoul (trace_flags, NULL, 0));
423
locale = getenv ("SC_LOCALE");
425
sc_set_locale (locale);
427
printf ("Loading game...\n");
428
game = sc_game_from_stream (stream);
432
"%s: %s: Not a loadable Adrift game\n", argv[0], argv[1]);
438
if (getenv ("SC_DEBUGGER_ENABLED"))
439
sc_set_game_debugger_enabled (game, TRUE);
440
if (getenv ("SC_STABLE_RANDOM_ENABLED"))
442
sc_set_portable_random (TRUE);
443
sc_reseed_random_sequence (1);
448
sc_interpret_game (game);