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
)
44 PLUGINLIB_EXIT_INIT_ATEXIT(atexit_cleanup
);
49 rb
->lcd_setfont(FONT_SYSFIXED
);
51 rb
->lcd_set_backdrop(NULL
);
53 rb
->lcd_clear_display();
56 rb
->viewport_set_defaults(&vp
[i
], i
);
58 story_name
= parameter
;
59 strcpy(save_name
, story_name
);
60 ext
= rb
->strrchr(save_name
, '.');
63 strcpy(auxilary_name
, save_name
);
64 strcpy(script_name
, save_name
);
65 strcpy(command_name
, save_name
);
66 rb
->strlcat(save_name
, ".sav", MAX_PATH
);
67 rb
->strlcat(auxilary_name
, ".aux", MAX_PATH
);
68 rb
->strlcat(script_name
, ".scr", MAX_PATH
);
69 rb
->strlcat(command_name
, ".rec", MAX_PATH
);
88 MENUITEM_STRINGLIST(ingame_menu
, "Frotz", NULL
, "Resume", "Undo", "Restart",
89 "Toggle input recording", "Play back input",
90 "Debug options", "Exit");
94 switch (rb
->do_menu(&ingame_menu
, NULL
, vp
, true))
103 return ZC_HKEY_RESTART
;
105 return ZC_HKEY_RECORD
;
107 return ZC_HKEY_PLAYBACK
;
109 return ZC_HKEY_DEBUG
;
115 const struct button_mapping
* plugin_contexts
[]={pla_main_ctx
};
121 dumb_show_screen(false);
125 action
= pluginlib_getaction(TIMEOUT_BLOCK
, plugin_contexts
,
126 ARRAYLEN(plugin_contexts
));
139 zchar
do_input(int timeout
, bool show_cursor
)
145 dumb_show_screen(show_cursor
);
147 /* Convert timeout (tenths of a second) to ticks */
149 timeout
= (timeout
* HZ
) / 10;
151 timeout
= TIMEOUT_BLOCK
;
153 timeout_at
= *rb
->current_tick
+ timeout
;
157 action
= pluginlib_getaction(timeout
, plugin_contexts
,
158 ARRAYLEN(plugin_contexts
));
166 if (menu_ret
!= ZC_BAD
)
168 timeout_at
= *rb
->current_tick
+ timeout
;
178 if (timeout
!= TIMEOUT_BLOCK
&&
179 !TIME_BEFORE(*rb
->current_tick
, timeout_at
))
185 zchar
os_read_key(int timeout
, bool show_cursor
)
194 zkey
= do_input(timeout
, show_cursor
);
199 r
= rb
->kbd_input(inputbuf
, 5);
200 rb
->lcd_setfont(FONT_SYSFIXED
);
204 rb
->utf8decode(inputbuf
, &key
);
205 if (key
> 0 && key
< 256)
211 zchar
os_read_line(int max
, zchar
*buf
, int timeout
, int width
, int continued
)
223 zkey
= do_input(timeout
, true);
229 strcpy(inputbuf
, buf
);
230 r
= rb
->kbd_input(inputbuf
, 256);
231 rb
->lcd_setfont(FONT_SYSFIXED
);
239 in
= rb
->utf8decode(in
, &key
);
240 if (key
> 0 && key
< 256)
247 os_display_string(buf
);
253 bool read_yes_or_no(const char *s
)
255 char message_line
[50];
256 const char *message_lines
[] = {message_line
};
257 const struct text_message message
= {message_lines
, 1};
259 rb
->strlcpy(message_line
, s
, 49);
260 rb
->strcat(message_line
, "?");
262 if (rb
->gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_YES
)
268 zchar
os_read_mouse(void)
273 int os_read_file_name(char *file_name
, const char *default_name
, int flag
)
276 strcpy(file_name
, default_name
);
280 void os_beep(int volume
)
282 rb
->splashf(HZ
/2, "[%s-PITCHED BEEP]", (volume
==1) ? "HIGH" : "LOW");
285 static unsigned char unget_buf
;
286 static int unget_file
;
288 int frotz_ungetc(int c
, int f
)
295 int frotz_fgetc(int f
)
303 if (rb
->read(f
, &cb
, 1) != 1)
308 int frotz_fputc(int c
, int f
)
310 unsigned char cb
= c
;
311 if (rb
->write(f
, &cb
, 1) != 1)