1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 Torne Wuff
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "dumb_frotz.h"
23 #include "lib/pluginlib_exit.h"
24 #include "lib/pluginlib_actions.h"
28 extern int frotz_main(void);
29 extern bool hot_key_quit(void);
32 extern char save_name
[], auxilary_name
[], script_name
[], command_name
[];
33 extern int story_fp
, sfp
, rfp
, pfp
;
35 static struct viewport vp
[NB_SCREENS
];
37 static void atexit_cleanup(void);
39 enum plugin_status
plugin_start(const void* parameter
)
43 atexit(atexit_cleanup
);
48 rb
->lcd_setfont(FONT_SYSFIXED
);
50 rb
->lcd_set_backdrop(NULL
);
52 rb
->lcd_clear_display();
55 rb
->viewport_set_defaults(&vp
[i
], i
);
57 story_name
= parameter
;
58 strcpy(save_name
, story_name
);
59 ext
= rb
->strrchr(save_name
, '.');
62 strcpy(auxilary_name
, save_name
);
63 strcpy(script_name
, save_name
);
64 strcpy(command_name
, save_name
);
65 rb
->strlcat(save_name
, ".sav", MAX_PATH
);
66 rb
->strlcat(auxilary_name
, ".aux", MAX_PATH
);
67 rb
->strlcat(script_name
, ".scr", MAX_PATH
);
68 rb
->strlcat(command_name
, ".rec", MAX_PATH
);
87 MENUITEM_STRINGLIST(ingame_menu
, "Frotz", NULL
, "Resume", "Undo", "Restart",
88 "Toggle input recording", "Play back input",
89 "Debug options", "Exit");
93 switch (rb
->do_menu(&ingame_menu
, NULL
, vp
, true))
102 return ZC_HKEY_RESTART
;
104 return ZC_HKEY_RECORD
;
106 return ZC_HKEY_PLAYBACK
;
108 return ZC_HKEY_DEBUG
;
114 const struct button_mapping
* plugin_contexts
[]={pla_main_ctx
};
120 dumb_show_screen(false);
124 action
= pluginlib_getaction(TIMEOUT_BLOCK
, plugin_contexts
,
125 ARRAYLEN(plugin_contexts
));
138 zchar
do_input(int timeout
, bool show_cursor
)
144 dumb_show_screen(show_cursor
);
146 /* Convert timeout (tenths of a second) to ticks */
148 timeout
= (timeout
* HZ
) / 10;
150 timeout
= TIMEOUT_BLOCK
;
152 timeout_at
= *rb
->current_tick
+ timeout
;
156 action
= pluginlib_getaction(timeout
, plugin_contexts
,
157 ARRAYLEN(plugin_contexts
));
165 if (menu_ret
!= ZC_BAD
)
167 timeout_at
= *rb
->current_tick
+ timeout
;
177 if (timeout
!= TIMEOUT_BLOCK
&&
178 !TIME_BEFORE(*rb
->current_tick
, timeout_at
))
184 zchar
os_read_key(int timeout
, bool show_cursor
)
193 zkey
= do_input(timeout
, show_cursor
);
198 r
= rb
->kbd_input(inputbuf
, 5);
199 rb
->lcd_setfont(FONT_SYSFIXED
);
203 rb
->utf8decode(inputbuf
, &key
);
204 if (key
> 0 && key
< 256)
210 zchar
os_read_line(int max
, zchar
*buf
, int timeout
, int width
, int continued
)
222 zkey
= do_input(timeout
, true);
228 strcpy(inputbuf
, buf
);
229 r
= rb
->kbd_input(inputbuf
, 256);
230 rb
->lcd_setfont(FONT_SYSFIXED
);
238 in
= rb
->utf8decode(in
, &key
);
239 if (key
> 0 && key
< 256)
246 os_display_string(buf
);
252 bool read_yes_or_no(const char *s
)
254 char message_line
[50];
255 const char *message_lines
[] = {message_line
};
256 const struct text_message message
= {message_lines
, 1};
258 rb
->strlcpy(message_line
, s
, 49);
259 rb
->strcat(message_line
, "?");
261 if (rb
->gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
267 zchar
os_read_mouse(void)
272 int os_read_file_name(char *file_name
, const char *default_name
, int flag
)
275 strcpy(file_name
, default_name
);
279 void os_beep(int volume
)
281 rb
->splashf(HZ
/2, "[%s-PITCHED BEEP]", (volume
==1) ? "HIGH" : "LOW");
284 static unsigned char unget_buf
;
285 static int unget_file
;
287 int frotz_ungetc(int c
, int f
)
294 int frotz_fgetc(int f
)
302 if (rb
->read(f
, &cb
, 1) != 1)
307 int frotz_fputc(int c
, int f
)
309 unsigned char cb
= c
;
310 if (rb
->write(f
, &cb
, 1) != 1)