From ce7113b34a808ef8136114881f9d19ce857d13bc Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 12 Nov 2018 11:51:49 -0800 Subject: GLK: FROTZ: Added OS read line and character methods --- engines/gargoyle/frotz/glk_interface.cpp | 90 ++++++++++++++++++++++++++++ engines/gargoyle/frotz/glk_interface.h | 18 ++++++ engines/gargoyle/frotz/processor.h | 10 ++++ engines/gargoyle/frotz/processor_streams.cpp | 11 ++-- 4 files changed, 124 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/gargoyle/frotz/glk_interface.cpp b/engines/gargoyle/frotz/glk_interface.cpp index c536a48df5..c376dc0056 100644 --- a/engines/gargoyle/frotz/glk_interface.cpp +++ b/engines/gargoyle/frotz/glk_interface.cpp @@ -404,5 +404,95 @@ void GlkInterface::gos_cancel_pending_line() { gos_linepending = 0; } +zchar GlkInterface::os_read_key(int timeout, bool show_cursor) { + event_t ev; + winid_t win = gos_curwin ? gos_curwin : gos_lower; + + if (gos_linepending) + gos_cancel_pending_line(); + + glk_request_char_event_uni(win); + if (timeout != 0) + glk_request_timer_events(timeout * 100); + + while (!shouldQuit()) { + glk_select(&ev); + if (ev.type == evtype_Arrange) { + gos_update_height(); + gos_update_width(); + } else if (ev.type == evtype_Timer) { + glk_cancel_char_event(win); + glk_request_timer_events(0); + return ZC_TIME_OUT; + } else if (ev.type == evtype_CharInput) + break; + } + if (shouldQuit()) + return 0; + + glk_request_timer_events(0); + + if (gos_upper && mach_status_ht < curr_status_ht) + reset_status_ht(); + curr_status_ht = 0; + + switch (ev.val1) { + case keycode_Escape: return ZC_ESCAPE; + case keycode_PageUp: return ZC_ARROW_MIN; + case keycode_PageDown: return ZC_ARROW_MAX; + case keycode_Left: return ZC_ARROW_LEFT; + case keycode_Right: return ZC_ARROW_RIGHT; + case keycode_Up: return ZC_ARROW_UP; + case keycode_Down: return ZC_ARROW_DOWN; + case keycode_Return: return ZC_RETURN; + case keycode_Delete: return ZC_BACKSPACE; + case keycode_Tab: return ZC_INDENT; + default: + return ev.val1; + } +} + +zchar GlkInterface::os_read_line(int max, zchar *buf, int timeout, int width, int continued) { + event_t ev; + winid_t win = gos_curwin ? gos_curwin : gos_lower; + + if (!continued && gos_linepending) + gos_cancel_pending_line(); + + if (!continued || !gos_linepending) { + glk_request_line_event_uni(win, buf, max, os_string_length(buf)); + if (timeout != 0) + glk_request_timer_events(timeout * 100); + } + + gos_linepending = 0; + + while (!shouldQuit()) { + glk_select(&ev); + if (ev.type == evtype_Arrange) { + gos_update_height(); + gos_update_width(); + } else if (ev.type == evtype_Timer) { + gos_linewin = win; + gos_linepending = 1; + gos_linebuf = buf; + return ZC_TIME_OUT; + } else if (ev.type == evtype_LineInput) { + break; + } + } + if (shouldQuit()) + return 0; + + glk_request_timer_events(0); + buf[ev.val1] = '\0'; + + if (gos_upper && mach_status_ht < curr_status_ht) + reset_status_ht(); + curr_status_ht = 0; + + return ZC_RETURN; +} + } // End of namespace Scott } // End of namespace Gargoyle diff --git a/engines/gargoyle/frotz/glk_interface.h b/engines/gargoyle/frotz/glk_interface.h index aeb33a8aa1..5393c5de10 100644 --- a/engines/gargoyle/frotz/glk_interface.h +++ b/engines/gargoyle/frotz/glk_interface.h @@ -159,6 +159,24 @@ protected: // Not implemented return 0; } + + void os_scrollback_char(zchar z) { + // Not implemented + } + + void os_scrollback_erase(int amount) { + // Not implemented + } + + /** + * Waits for a keypress + */ + zchar os_read_key(int timeout, bool show_cursor); + + /** + * Waits for the user to type an input line + */ + zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued); public: /** * Constructor diff --git a/engines/gargoyle/frotz/processor.h b/engines/gargoyle/frotz/processor.h index 0a9d0efcdf..6a28121512 100644 --- a/engines/gargoyle/frotz/processor.h +++ b/engines/gargoyle/frotz/processor.h @@ -308,6 +308,16 @@ private: * @{ */ + /** + * Waits for the user to type an input line + */ + zchar console_read_input(int max, zchar *buf, zword timeout, bool continued); + + /** + * Waits for a keypress + */ + zchar console_read_key(zword timeout); + /** * Write a single character to the scrollback buffer. * diff --git a/engines/gargoyle/frotz/processor_streams.cpp b/engines/gargoyle/frotz/processor_streams.cpp index 97784c8423..d75819e661 100644 --- a/engines/gargoyle/frotz/processor_streams.cpp +++ b/engines/gargoyle/frotz/processor_streams.cpp @@ -25,12 +25,13 @@ namespace Gargoyle { namespace Frotz { -// TODO: Implement method stubs -static void os_scrollback_char(zchar) {} -static void os_scrollback_erase(zword) {} -static zchar console_read_key(zword) { return 0; } -static zchar console_read_input(uint, zchar *, uint, bool) { return 0; } +zchar Processor::console_read_input(int max, zchar *buf, zword timeout, bool continued) { + return os_read_line(max, buf, timeout, max, continued); +} +zchar Processor::console_read_key(zword timeout) { + return os_read_key(timeout, 0); +} void Processor::scrollback_char(zchar c) { if (c == ZC_INDENT) -- cgit v1.2.3